diff options
| author | Dax Raad <[email protected]> | 2025-06-17 01:05:05 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-06-17 01:05:05 -0400 |
| commit | 3fe163416d689011b831b08df27c27db73b9a0ef (patch) | |
| tree | d8b97a8cfe8dc0246e7985f49902585bf1e71c1c | |
| parent | d054f88130b64cc3a6bbcc41795873b0e47dcce5 (diff) | |
| download | opencode-3fe163416d689011b831b08df27c27db73b9a0ef.tar.gz opencode-3fe163416d689011b831b08df27c27db73b9a0ef.zip | |
autoupgrade
| -rw-r--r-- | packages/opencode/src/global/config.ts | 25 | ||||
| -rw-r--r-- | packages/opencode/src/index.ts | 11 |
2 files changed, 35 insertions, 1 deletions
diff --git a/packages/opencode/src/global/config.ts b/packages/opencode/src/global/config.ts index 133cd3814..ebfd67719 100644 --- a/packages/opencode/src/global/config.ts +++ b/packages/opencode/src/global/config.ts @@ -1 +1,24 @@ -export namespace GlobalConfig {} +import { z } from "zod" +import { Global } from "." +import { lazy } from "../util/lazy" +import path from "path" + +export namespace GlobalConfig { + export const Info = z.object({ + autoupdate: z.boolean().optional(), + provider: z.string().optional(), + model: z.string().optional(), + }) + export type Info = z.infer<typeof Info> + + export const get = lazy(async () => { + const toml = await import(path.join(Global.Path.config, "config"), { + with: { + type: "toml", + }, + }) + .then((mod) => mod.default) + .catch(() => ({})) + return Info.parse(toml) + }) +} diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts index c446b2033..1995f2ebe 100644 --- a/packages/opencode/src/index.ts +++ b/packages/opencode/src/index.ts @@ -16,6 +16,17 @@ import { AuthCommand, AuthLoginCommand } from "./cli/cmd/auth" import { UpgradeCommand } from "./cli/cmd/upgrade" import { Provider } from "./provider/provider" import { UI } from "./cli/ui" +import { GlobalConfig } from "./global/config" +import { Installation } from "./installation" +;(async () => { + if (Installation.VERSION === "dev") return + const config = await GlobalConfig.get() + if (config.autoupdate === false) return + const latest = await Installation.latest() + if (Installation.VERSION === latest) return + const method = await Installation.method() + await Installation.upgrade(method, latest).catch(() => {}) +})() const cli = yargs(hideBin(process.argv)) .scriptName("opencode") |
