Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1355,12 +1355,22 @@ export namespace Config {
}

export async function update(config: Info) {
const filepath = path.join(Instance.directory, "config.json")
const filepath = projectConfigFile()
const existing = await loadFile(filepath)
await Bun.write(filepath, JSON.stringify(mergeDeep(existing, config), null, 2))
await Instance.dispose()
}

function projectConfigFile() {
const candidates = ["opencode.jsonc", "opencode.json"].map((file) =>
path.join(Instance.directory, file),
)
for (const file of candidates) {
if (existsSync(file)) return file
}
return candidates[1]
}

function globalConfigFile() {
const candidates = ["opencode.jsonc", "opencode.json", "config.json"].map((file) =>
path.join(Global.Path.config, file),
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ test("updates config and writes to file", async () => {
const newConfig = { model: "updated/model" }
await Config.update(newConfig as any)

const writtenConfig = JSON.parse(await Bun.file(path.join(tmp.path, "config.json")).text())
const writtenConfig = JSON.parse(await Bun.file(path.join(tmp.path, "opencode.json")).text())
expect(writtenConfig.model).toBe("updated/model")
},
})
Expand Down
Loading