Skip to content

Commit 3fe1634

Browse files
committed
autoupgrade
1 parent d054f88 commit 3fe1634

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
export namespace GlobalConfig {}
1+
import { z } from "zod"
2+
import { Global } from "."
3+
import { lazy } from "../util/lazy"
4+
import path from "path"
5+
6+
export namespace GlobalConfig {
7+
export const Info = z.object({
8+
autoupdate: z.boolean().optional(),
9+
provider: z.string().optional(),
10+
model: z.string().optional(),
11+
})
12+
export type Info = z.infer<typeof Info>
13+
14+
export const get = lazy(async () => {
15+
const toml = await import(path.join(Global.Path.config, "config"), {
16+
with: {
17+
type: "toml",
18+
},
19+
})
20+
.then((mod) => mod.default)
21+
.catch(() => ({}))
22+
return Info.parse(toml)
23+
})
24+
}

packages/opencode/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ import { AuthCommand, AuthLoginCommand } from "./cli/cmd/auth"
1616
import { UpgradeCommand } from "./cli/cmd/upgrade"
1717
import { Provider } from "./provider/provider"
1818
import { UI } from "./cli/ui"
19+
import { GlobalConfig } from "./global/config"
20+
import { Installation } from "./installation"
21+
;(async () => {
22+
if (Installation.VERSION === "dev") return
23+
const config = await GlobalConfig.get()
24+
if (config.autoupdate === false) return
25+
const latest = await Installation.latest()
26+
if (Installation.VERSION === latest) return
27+
const method = await Installation.method()
28+
await Installation.upgrade(method, latest).catch(() => {})
29+
})()
1930

2031
const cli = yargs(hideBin(process.argv))
2132
.scriptName("opencode")

0 commit comments

Comments
 (0)