From 873bdafef2f3120f497902a06201a8d7969d595a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Tue, 11 Nov 2025 19:02:07 +0100 Subject: [PATCH 1/5] fix: Config.update to use actual user configuration file --- packages/opencode/src/config/config.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index eaac1dd4f304..9853811486a3 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -775,7 +775,21 @@ export namespace Config { } export async function update(config: Info) { - const filepath = path.join(Instance.directory, "config.json") + let filepath = path.join(Instance.directory, "opencode.json") + for ( + const file of [ + "opencode.json", + "opencode.jsonc", + path.join(".opencode", "opencode.json"), + path.join(".opencode", "opencode.jsonc"), + ] + ) { + const fullPath = path.join(Instance.directory, file) + if (await Bun.file(fullPath).exists()) { + filepath = fullPath + break + } + } const existing = await loadFile(filepath) await Bun.write(filepath, JSON.stringify(mergeDeep(existing, config), null, 2)) await Instance.dispose() From ea3b05ce3578c18566ff29a9f5846b0d6c491e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Tue, 11 Nov 2025 19:02:42 +0100 Subject: [PATCH 2/5] fix: Fix state disposal --- packages/opencode/src/project/state.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opencode/src/project/state.ts b/packages/opencode/src/project/state.ts index 5846bf85686d..a9dc8adcd2be 100644 --- a/packages/opencode/src/project/state.ts +++ b/packages/opencode/src/project/state.ts @@ -57,7 +57,7 @@ export namespace State { tasks.push(task) } - entries.delete(key) + recordsByKey.delete(key) await Promise.all(tasks) disposalFinished = true log.info("state disposal completed", { key }) From 6776422eed8d797a596b6d3a6c8b17caf6e905b4 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 11 Nov 2025 18:09:10 +0000 Subject: [PATCH 3/5] chore: format code --- packages/opencode/src/config/config.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index 9853811486a3..ac50a5e721f9 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -776,14 +776,12 @@ export namespace Config { export async function update(config: Info) { let filepath = path.join(Instance.directory, "opencode.json") - for ( - const file of [ - "opencode.json", - "opencode.jsonc", - path.join(".opencode", "opencode.json"), - path.join(".opencode", "opencode.jsonc"), - ] - ) { + for (const file of [ + "opencode.json", + "opencode.jsonc", + path.join(".opencode", "opencode.json"), + path.join(".opencode", "opencode.jsonc"), + ]) { const fullPath = path.join(Instance.directory, file) if (await Bun.file(fullPath).exists()) { filepath = fullPath From ee8743ca94064db04eb0cbfe8ab04b68c90beb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Tue, 11 Nov 2025 19:36:13 +0100 Subject: [PATCH 4/5] test: Fix config update tests --- packages/opencode/test/config/config.test.ts | 45 +++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts index 967972842f5c..015d1976beb2 100644 --- a/packages/opencode/test/config/config.test.ts +++ b/packages/opencode/test/config/config.test.ts @@ -1,4 +1,4 @@ -import { test, expect } from "bun:test" +import { test, expect, describe } from "bun:test" import { Config } from "../../src/config/config" import { Instance } from "../../src/project/instance" import { tmpdir } from "../fixture/fixture" @@ -327,17 +327,40 @@ Test agent prompt`, }) }) -test("updates config and writes to file", async () => { - await using tmp = await tmpdir() - await Instance.provide({ - directory: tmp.path, - fn: async () => { - const newConfig = { model: "updated/model" } - await Config.update(newConfig as any) +describe("updates config and writes to file", async () => { + test("should correctly pick existing file to overwrite", async () => { + await using tmp = await tmpdir() + await Instance.provide({ + directory: tmp.path, + fn: async () => { + const files = [ + path.join(tmp.path, "opencode.jsonc"), + path.join(tmp.path, ".opencode", "opencode.json"), + ] + const oldConfig = { $schema: "https://opencode.ai/config.json", model: "old/model" } + await Bun.write(files[0], JSON.stringify(oldConfig, null, 2)) + await Bun.write(files[1], JSON.stringify(oldConfig, null, 2)) - const writtenConfig = JSON.parse(await Bun.file(path.join(tmp.path, "config.json")).text()) - expect(writtenConfig.model).toBe("updated/model") - }, + const newConfig = { $schema: "https://opencode.ai/config.json", model: "updated/model" } + await Config.update(newConfig as any) + + const writtenConfig = JSON.parse(await Bun.file(files[0]).text()) + expect(writtenConfig.model).toBe("updated/model") + }, + }) + }) + test("should create new config file if missing", async () => { + await using tmp = await tmpdir() + await Instance.provide({ + directory: tmp.path, + fn: async () => { + const newConfig = { model: "updated/model" } + await Config.update(newConfig as any) + + const writtenConfig = JSON.parse(await Bun.file(path.join(tmp.path, "opencode.json")).text()) + expect(writtenConfig.model).toBe("updated/model") + }, + }) }) }) From 745d313f147cbbbd3cc12d6f15b34c92a03d9f85 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 11 Nov 2025 18:37:52 +0000 Subject: [PATCH 5/5] chore: format code --- packages/opencode/test/config/config.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts index 015d1976beb2..5f406b1ff57d 100644 --- a/packages/opencode/test/config/config.test.ts +++ b/packages/opencode/test/config/config.test.ts @@ -333,10 +333,7 @@ describe("updates config and writes to file", async () => { await Instance.provide({ directory: tmp.path, fn: async () => { - const files = [ - path.join(tmp.path, "opencode.jsonc"), - path.join(tmp.path, ".opencode", "opencode.json"), - ] + const files = [path.join(tmp.path, "opencode.jsonc"), path.join(tmp.path, ".opencode", "opencode.json")] const oldConfig = { $schema: "https://opencode.ai/config.json", model: "old/model" } await Bun.write(files[0], JSON.stringify(oldConfig, null, 2)) await Bun.write(files[1], JSON.stringify(oldConfig, null, 2))