Skip to content

Commit 3adedca

Browse files
committed
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)
1 parent 3dea568 commit 3adedca

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

src/config/schema.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,15 @@ export const AgentOverrideConfigSchema = z.object({
7474
permission: AgentPermissionSchema.optional(),
7575
})
7676

77-
export const AgentOverridesSchema = z
78-
.object({
79-
build: AgentOverrideConfigSchema.optional(),
80-
oracle: AgentOverrideConfigSchema.optional(),
81-
librarian: AgentOverrideConfigSchema.optional(),
82-
explore: AgentOverrideConfigSchema.optional(),
83-
"frontend-ui-ux-engineer": AgentOverrideConfigSchema.optional(),
84-
"document-writer": AgentOverrideConfigSchema.optional(),
85-
"multimodal-looker": AgentOverrideConfigSchema.optional(),
86-
})
87-
.partial()
77+
export const AgentOverridesSchema = z.object({
78+
build: AgentOverrideConfigSchema.optional(),
79+
oracle: AgentOverrideConfigSchema.optional(),
80+
librarian: AgentOverrideConfigSchema.optional(),
81+
explore: AgentOverrideConfigSchema.optional(),
82+
"frontend-ui-ux-engineer": AgentOverrideConfigSchema.optional(),
83+
"document-writer": AgentOverrideConfigSchema.optional(),
84+
"multimodal-looker": AgentOverrideConfigSchema.optional(),
85+
})
8886

8987
export const ClaudeCodeConfigSchema = z.object({
9088
mcp: z.boolean().optional(),

src/hooks/auto-update-checker/checker.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import {
1111
import { log } from "../../shared/logger"
1212

1313
export function isLocalDevMode(directory: string): boolean {
14+
return getLocalDevPath(directory) !== null
15+
}
16+
17+
export function getLocalDevPath(directory: string): string | null {
1418
const projectConfig = path.join(directory, ".opencode", "opencode.json")
1519

1620
for (const configPath of [projectConfig, USER_OPENCODE_CONFIG]) {
@@ -22,15 +26,30 @@ export function isLocalDevMode(directory: string): boolean {
2226

2327
for (const entry of plugins) {
2428
if (entry.startsWith("file://") && entry.includes(PACKAGE_NAME)) {
25-
return true
29+
return entry.replace("file://", "")
2630
}
2731
}
2832
} catch {
2933
continue
3034
}
3135
}
3236

33-
return false
37+
return null
38+
}
39+
40+
export function getLocalDevVersion(directory: string): string | null {
41+
const localPath = getLocalDevPath(directory)
42+
if (!localPath) return null
43+
44+
try {
45+
const pkgPath = path.join(localPath, "package.json")
46+
if (!fs.existsSync(pkgPath)) return null
47+
const content = fs.readFileSync(pkgPath, "utf-8")
48+
const pkg = JSON.parse(content) as PackageJson
49+
return pkg.version ?? null
50+
} catch {
51+
return null
52+
}
3453
}
3554

3655
export interface PluginEntryInfo {
@@ -69,13 +88,23 @@ export function findPluginEntry(directory: string): PluginEntryInfo | null {
6988

7089
export function getCachedVersion(): string | null {
7190
try {
72-
if (!fs.existsSync(INSTALLED_PACKAGE_JSON)) return null
73-
const content = fs.readFileSync(INSTALLED_PACKAGE_JSON, "utf-8")
74-
const pkg = JSON.parse(content) as PackageJson
75-
return pkg.version ?? null
76-
} catch {
77-
return null
78-
}
91+
if (fs.existsSync(INSTALLED_PACKAGE_JSON)) {
92+
const content = fs.readFileSync(INSTALLED_PACKAGE_JSON, "utf-8")
93+
const pkg = JSON.parse(content) as PackageJson
94+
if (pkg.version) return pkg.version
95+
}
96+
} catch {}
97+
98+
try {
99+
const pkgPath = path.resolve(import.meta.dirname, "..", "..", "..", "package.json")
100+
if (fs.existsSync(pkgPath)) {
101+
const content = fs.readFileSync(pkgPath, "utf-8")
102+
const pkg = JSON.parse(content) as PackageJson
103+
if (pkg.version) return pkg.version
104+
}
105+
} catch {}
106+
107+
return null
79108
}
80109

81110
export async function getLatestVersion(): Promise<string | null> {

src/hooks/auto-update-checker/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { PluginInput } from "@opencode-ai/plugin"
2-
import { checkForUpdate, getCachedVersion } from "./checker"
2+
import { checkForUpdate, getCachedVersion, getLocalDevVersion } from "./checker"
33
import { invalidatePackage } from "./cache"
44
import { PACKAGE_NAME } from "./constants"
55
import { log } from "../../shared/logger"
@@ -25,7 +25,8 @@ export function createAutoUpdateCheckerHook(ctx: PluginInput, options: AutoUpdat
2525
if (result.isLocalDev) {
2626
log("[auto-update-checker] Skipped: local development mode")
2727
if (showStartupToast) {
28-
await showVersionToast(ctx, getCachedVersion())
28+
const version = getLocalDevVersion(ctx.directory) ?? getCachedVersion()
29+
await showVersionToast(ctx, version)
2930
}
3031
return
3132
}

0 commit comments

Comments
 (0)