Skip to content

Commit 8c53e42

Browse files
committed
fix: PATCH /config writes to correct project config file
Config.update() was writing to config.json which is never read by the config loader. Now writes to opencode.jsonc or opencode.json (whichever exists), matching the files the loader actually reads. Mirrors the existing globalConfigFile() pattern. Fixes anomalyco#4194 Fixes anomalyco#6984
1 parent b551195 commit 8c53e42

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎packages/opencode/src/config/config.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,12 +1355,22 @@ export namespace Config {
13551355
}
13561356

13571357
export async function update(config: Info) {
1358-
const filepath = path.join(Instance.directory, "config.json")
1358+
const filepath = projectConfigFile()
13591359
const existing = await loadFile(filepath)
13601360
await Bun.write(filepath, JSON.stringify(mergeDeep(existing, config), null, 2))
13611361
await Instance.dispose()
13621362
}
13631363

1364+
function projectConfigFile() {
1365+
const candidates = ["opencode.jsonc", "opencode.json"].map((file) =>
1366+
path.join(Instance.directory, file),
1367+
)
1368+
for (const file of candidates) {
1369+
if (existsSync(file)) return file
1370+
}
1371+
return candidates[1]
1372+
}
1373+
13641374
function globalConfigFile() {
13651375
const candidates = ["opencode.jsonc", "opencode.json", "config.json"].map((file) =>
13661376
path.join(Global.Path.config, file),

‎packages/opencode/test/config/config.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ test("updates config and writes to file", async () => {
549549
const newConfig = { model: "updated/model" }
550550
await Config.update(newConfig as any)
551551

552-
const writtenConfig = JSON.parse(await Bun.file(path.join(tmp.path, "config.json")).text())
552+
const writtenConfig = JSON.parse(await Bun.file(path.join(tmp.path, "opencode.json")).text())
553553
expect(writtenConfig.model).toBe("updated/model")
554554
},
555555
})

0 commit comments

Comments
 (0)