feat(auto-update-checker): improve local dev version display

- Add getLocalDevPath() and getLocalDevVersion() functions
- Improve getCachedVersion() with fallback to bundled package.json
- Display correct version in startup toast for local dev mode

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2025-12-14 17:48:41 +09:00
parent 3dea568007
commit 3adedca810
3 changed files with 50 additions and 22 deletions

View File

@@ -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(),

View File

@@ -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<string | null> {

View File

@@ -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
}