Commit eaac664
fix(configure): patch CoDev Code's config in place, honor its env flags, validate keys via /v1/models (#265)
The hub's CoDev Code configuration stopped fitting how the agent works.
Three mismatches with codev-code main (packages/codev-gateway, the
config layer, the desktop gateway controller), each fixed here:
1. The writer whole-file-replaced ~/.config/codev/codev.json(c), carrying
only `mcp` across. CoDev Code is a standalone product now: its TUI
connects custom providers, its desktop app writes theme/keybind/
permission settings, users keep comments in codev.jsonc — and the hub
rewrites this file on every gateway-key auto-refresh and model switch,
not just at install. All of that was deleted on each run.
`configureOpenCodeKind` now PATCHes the file through jsonc-parser the
way the agent's own `Config.updateGlobal` does: `$schema` seeded only
when absent, `compaction.auto`/`reserved` set key-by-key, the CoDev
`provider.<id>` block replaced wholesale (stale models and any inline
apiKey go), everything else byte-identical. The agent's PATCH cannot
delete, so convergence after the AIGW rename is the hub's job: other
CoDev provider ids (`netgate`, `aigateway`, …) and a CoDev-authored
top-level `model` pin are removed; a user's own provider never is.
Syntax errors or a non-object root still fall back to a fresh file,
with the backup holding the original. `readPreservedMcp` is gone —
nothing needs carrying over any more.
2. `runAgent("codev")` set OPENCODE_DISABLE_AUTOUPDATE, but the fork
renamed every OPENCODE_* env var to CODEV_* (codev-code #41), so the
agent's self-updater was never disabled and raced `codevhub update`.
Both spellings are set now.
3. `validateApiKey` probed LiteLLM's /key/info at the gateway ROOT. That
root is now fronted by a web app whose catch-all answers HTTP 200 +
HTML to any bearer — verified with a bogus key — so the probe could
never return false: the launch-time refresh never fired on an expired
key and SetupApp's "reuse existing key" offered dead keys as valid.
It now lists /v1/models (authenticated by the key itself, 401s
properly) and treats a non-JSON 200 as "can't tell", never "valid".
`doctor` reports the same URL.
Verified against the real agent: patching a copy of a live codev.jsonc
that carried duplicate netgate + aigw blocks, a comment, a theme, a
custom provider and the CodeGraph mcp entry, then running `codev models`
under that HOME, lists each aigw model once plus the custom provider —
with the comment and settings intact.
Tests: writer tests now assert preservation (settings, comments, in-TUI
providers, compaction siblings, $schema), legacy-block and pin removal,
and the corrupt-file fallback; validateApiKey tests target /v1/models
and pin the HTML-200 case; run tests assert both autoupdate flags.
Claude-Session: https://claude.ai/code/session_0178nPaQqSGVe7Y1fR2ovDTK
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>1 parent e54e899 commit eaac664
10 files changed
Lines changed: 410 additions & 116 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
141 | 158 | | |
142 | 159 | | |
143 | 160 | | |
| |||
180 | 197 | | |
181 | 198 | | |
182 | 199 | | |
183 | | - | |
| 200 | + | |
184 | 201 | | |
185 | 202 | | |
186 | 203 | | |
| |||
341 | 358 | | |
342 | 359 | | |
343 | 360 | | |
344 | | - | |
| 361 | + | |
345 | 362 | | |
346 | 363 | | |
347 | 364 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
120 | 118 | | |
121 | 119 | | |
122 | 120 | | |
123 | 121 | | |
124 | | - | |
| 122 | + | |
125 | 123 | | |
126 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
133 | 140 | | |
134 | 141 | | |
135 | 142 | | |
| |||
185 | 192 | | |
186 | 193 | | |
187 | 194 | | |
188 | | - | |
189 | | - | |
190 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
191 | 200 | | |
192 | 201 | | |
193 | 202 | | |
| |||
258 | 267 | | |
259 | 268 | | |
260 | 269 | | |
261 | | - | |
262 | | - | |
| 270 | + | |
| 271 | + | |
263 | 272 | | |
264 | 273 | | |
265 | 274 | | |
| |||
0 commit comments