File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -16,6 +16,17 @@ import { AuthCommand, AuthLoginCommand } from "./cli/cmd/auth"
1616import { UpgradeCommand } from "./cli/cmd/upgrade"
1717import { Provider } from "./provider/provider"
1818import { 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
2031const cli = yargs ( hideBin ( process . argv ) )
2132 . scriptName ( "opencode" )
You can’t perform that action at this time.
0 commit comments