diff --git a/src/config/schema.ts b/src/config/schema.ts index d945ad2..fea8c32 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -74,17 +74,15 @@ export const AgentOverrideConfigSchema = z.object({ permission: AgentPermissionSchema.optional(), }) -export const AgentOverridesSchema = z - .object({ - build: AgentOverrideConfigSchema.optional(), - oracle: AgentOverrideConfigSchema.optional(), - librarian: AgentOverrideConfigSchema.optional(), - explore: AgentOverrideConfigSchema.optional(), - "frontend-ui-ux-engineer": AgentOverrideConfigSchema.optional(), - "document-writer": AgentOverrideConfigSchema.optional(), - "multimodal-looker": AgentOverrideConfigSchema.optional(), - }) - .partial() +export const AgentOverridesSchema = z.object({ + build: AgentOverrideConfigSchema.optional(), + oracle: AgentOverrideConfigSchema.optional(), + librarian: AgentOverrideConfigSchema.optional(), + explore: AgentOverrideConfigSchema.optional(), + "frontend-ui-ux-engineer": AgentOverrideConfigSchema.optional(), + "document-writer": AgentOverrideConfigSchema.optional(), + "multimodal-looker": AgentOverrideConfigSchema.optional(), +}) export const ClaudeCodeConfigSchema = z.object({ mcp: z.boolean().optional(), diff --git a/src/hooks/auto-update-checker/checker.ts b/src/hooks/auto-update-checker/checker.ts index 1b2d6a1..b2bee3e 100644 --- a/src/hooks/auto-update-checker/checker.ts +++ b/src/hooks/auto-update-checker/checker.ts @@ -11,6 +11,10 @@ import { import { log } from "../../shared/logger" export function isLocalDevMode(directory: string): boolean { + return getLocalDevPath(directory) !== null +} + +export function getLocalDevPath(directory: string): string | null { const projectConfig = path.join(directory, ".opencode", "opencode.json") for (const configPath of [projectConfig, USER_OPENCODE_CONFIG]) { @@ -22,7 +26,7 @@ export function isLocalDevMode(directory: string): boolean { for (const entry of plugins) { if (entry.startsWith("file://") && entry.includes(PACKAGE_NAME)) { - return true + return entry.replace("file://", "") } } } catch { @@ -30,7 +34,22 @@ export function isLocalDevMode(directory: string): boolean { } } - return false + return null +} + +export function getLocalDevVersion(directory: string): string | null { + const localPath = getLocalDevPath(directory) + if (!localPath) return null + + try { + const pkgPath = path.join(localPath, "package.json") + if (!fs.existsSync(pkgPath)) return null + const content = fs.readFileSync(pkgPath, "utf-8") + const pkg = JSON.parse(content) as PackageJson + return pkg.version ?? null + } catch { + return null + } } export interface PluginEntryInfo { @@ -69,13 +88,23 @@ export function findPluginEntry(directory: string): PluginEntryInfo | null { export function getCachedVersion(): string | null { try { - if (!fs.existsSync(INSTALLED_PACKAGE_JSON)) return null - const content = fs.readFileSync(INSTALLED_PACKAGE_JSON, "utf-8") - const pkg = JSON.parse(content) as PackageJson - return pkg.version ?? null - } catch { - return null - } + if (fs.existsSync(INSTALLED_PACKAGE_JSON)) { + const content = fs.readFileSync(INSTALLED_PACKAGE_JSON, "utf-8") + const pkg = JSON.parse(content) as PackageJson + if (pkg.version) return pkg.version + } + } catch {} + + try { + const pkgPath = path.resolve(import.meta.dirname, "..", "..", "..", "package.json") + if (fs.existsSync(pkgPath)) { + const content = fs.readFileSync(pkgPath, "utf-8") + const pkg = JSON.parse(content) as PackageJson + if (pkg.version) return pkg.version + } + } catch {} + + return null } export async function getLatestVersion(): Promise { diff --git a/src/hooks/auto-update-checker/index.ts b/src/hooks/auto-update-checker/index.ts index 01e750f..2ad05e5 100644 --- a/src/hooks/auto-update-checker/index.ts +++ b/src/hooks/auto-update-checker/index.ts @@ -1,5 +1,5 @@ import type { PluginInput } from "@opencode-ai/plugin" -import { checkForUpdate, getCachedVersion } from "./checker" +import { checkForUpdate, getCachedVersion, getLocalDevVersion } from "./checker" import { invalidatePackage } from "./cache" import { PACKAGE_NAME } from "./constants" import { log } from "../../shared/logger" @@ -25,7 +25,8 @@ export function createAutoUpdateCheckerHook(ctx: PluginInput, options: AutoUpdat if (result.isLocalDev) { log("[auto-update-checker] Skipped: local development mode") if (showStartupToast) { - await showVersionToast(ctx, getCachedVersion()) + const version = getLocalDevVersion(ctx.directory) ?? getCachedVersion() + await showVersionToast(ctx, version) } return }