MCPcopy Create free account
hub / github.com/diillson/chatcli / writeRuntimeModelState

Method writeRuntimeModelState

cli/gateway_runtime_model.go:53–70  ·  view source on GitHub ↗

writeRuntimeModelState records the current provider/model so a detached gateway daemon mirrors the REPL's live choice. Called only from the interactive process (switch handlers + daemon spawn); failures are best-effort and logged, never fatal — a missing file simply means "no override".

()

Source from the content-addressed store, hash-verified

51// interactive process (switch handlers + daemon spawn); failures are best-effort
52// and logged, never fatal — a missing file simply means "no override".
53func (cli *ChatCLI) writeRuntimeModelState() {
54 if cli.Provider == "" || cli.Model == "" {
55 return
56 }
57 path := runtimeModelStatePath()
58 if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
59 cli.logger.Warn("gateway: could not create runtime-model state dir", zap.Error(err))
60 return
61 }
62 data, err := json.Marshal(runtimeModelState{Provider: cli.Provider, Model: cli.Model})
63 if err != nil {
64 cli.logger.Warn("gateway: could not marshal runtime-model state", zap.Error(err))
65 return
66 }
67 if err := os.WriteFile(path, data, 0o600); err != nil {
68 cli.logger.Warn("gateway: could not write runtime-model state", zap.Error(err))
69 }
70}
71
72// readRuntimeModelState loads the persisted snapshot. ok=false when the file is
73// absent or malformed (no override → caller keeps its current model).

Callers 3

gatewayStartDetachedMethod · 0.95
applyProviderSwitchMethod · 0.95
handleSwitchCommandMethod · 0.95

Calls 4

runtimeModelStatePathFunction · 0.85
WarnMethod · 0.80
ErrorMethod · 0.65
DirMethod · 0.45

Tested by

no test coverage detected