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(), permission: AgentPermissionSchema.optional(),
}) })
export const AgentOverridesSchema = z export const AgentOverridesSchema = z.object({
.object({ build: AgentOverrideConfigSchema.optional(),
build: AgentOverrideConfigSchema.optional(), oracle: AgentOverrideConfigSchema.optional(),
oracle: AgentOverrideConfigSchema.optional(), librarian: AgentOverrideConfigSchema.optional(),
librarian: AgentOverrideConfigSchema.optional(), explore: AgentOverrideConfigSchema.optional(),
explore: AgentOverrideConfigSchema.optional(), "frontend-ui-ux-engineer": AgentOverrideConfigSchema.optional(),
"frontend-ui-ux-engineer": AgentOverrideConfigSchema.optional(), "document-writer": AgentOverrideConfigSchema.optional(),
"document-writer": AgentOverrideConfigSchema.optional(), "multimodal-looker": AgentOverrideConfigSchema.optional(),
"multimodal-looker": AgentOverrideConfigSchema.optional(), })
})
.partial()
export const ClaudeCodeConfigSchema = z.object({ export const ClaudeCodeConfigSchema = z.object({
mcp: z.boolean().optional(), mcp: z.boolean().optional(),

View File

@@ -11,6 +11,10 @@ import {
import { log } from "../../shared/logger" import { log } from "../../shared/logger"
export function isLocalDevMode(directory: string): boolean { 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") const projectConfig = path.join(directory, ".opencode", "opencode.json")
for (const configPath of [projectConfig, USER_OPENCODE_CONFIG]) { for (const configPath of [projectConfig, USER_OPENCODE_CONFIG]) {
@@ -22,7 +26,7 @@ export function isLocalDevMode(directory: string): boolean {
for (const entry of plugins) { for (const entry of plugins) {
if (entry.startsWith("file://") && entry.includes(PACKAGE_NAME)) { if (entry.startsWith("file://") && entry.includes(PACKAGE_NAME)) {
return true return entry.replace("file://", "")
} }
} }
} catch { } 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 { export interface PluginEntryInfo {
@@ -69,13 +88,23 @@ export function findPluginEntry(directory: string): PluginEntryInfo | null {
export function getCachedVersion(): string | null { export function getCachedVersion(): string | null {
try { try {
if (!fs.existsSync(INSTALLED_PACKAGE_JSON)) return null if (fs.existsSync(INSTALLED_PACKAGE_JSON)) {
const content = fs.readFileSync(INSTALLED_PACKAGE_JSON, "utf-8") const content = fs.readFileSync(INSTALLED_PACKAGE_JSON, "utf-8")
const pkg = JSON.parse(content) as PackageJson const pkg = JSON.parse(content) as PackageJson
return pkg.version ?? null if (pkg.version) return pkg.version
} catch { }
return null } 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> { export async function getLatestVersion(): Promise<string | null> {

View File

@@ -1,5 +1,5 @@
import type { PluginInput } from "@opencode-ai/plugin" import type { PluginInput } from "@opencode-ai/plugin"
import { checkForUpdate, getCachedVersion } from "./checker" import { checkForUpdate, getCachedVersion, getLocalDevVersion } from "./checker"
import { invalidatePackage } from "./cache" import { invalidatePackage } from "./cache"
import { PACKAGE_NAME } from "./constants" import { PACKAGE_NAME } from "./constants"
import { log } from "../../shared/logger" import { log } from "../../shared/logger"
@@ -25,7 +25,8 @@ export function createAutoUpdateCheckerHook(ctx: PluginInput, options: AutoUpdat
if (result.isLocalDev) { if (result.isLocalDev) {
log("[auto-update-checker] Skipped: local development mode") log("[auto-update-checker] Skipped: local development mode")
if (showStartupToast) { if (showStartupToast) {
await showVersionToast(ctx, getCachedVersion()) const version = getLocalDevVersion(ctx.directory) ?? getCachedVersion()
await showVersionToast(ctx, version)
} }
return return
} }