fix(cli): handle missing nested config unsets (#12727)

* fix(cli): handle missing nested config unsets

* test(cli): cover nested config unset behavior
This commit is contained in:
Marius
2026-07-31 13:41:35 +02:00
committed by GitHub
parent a1ad65e522
commit 1a340371f4
3 changed files with 45 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@kilocode/cli": patch
---
Allow clearing a nested project setting when no project config file exists yet.
@@ -82,6 +82,11 @@ export namespace KilocodeConfigWriter {
function patchJsonc(input: string, patch: unknown, parts: string[] = []): string {
if (!isRecord(patch)) {
if (patch === null) {
// jsonc-parser cannot delete a nested path when its parent is absent.
const tree = parseTree(input)
if (!tree || !findNodeAtLocation(tree, parts)) return input
}
return applyEdits(
input,
modify(input, parts, patch === null ? undefined : patch, {
@@ -103,6 +103,41 @@ describe("config overlay routes", () => {
expect(await Bun.file(target.path).text()).toContain('"model": "test/model"')
})
test("ignores a nested unset path when the project target is missing", async () => {
await using project = await tmpdir()
const response = await req(project.path, "/config/overlay", {
method: "PATCH",
headers: { "content-type": "application/json" },
body: JSON.stringify({ scope: "project", unset: [["agent", "explore", "model"]] }),
})
expect(response.status).toBe(200)
expect(await Bun.file(path.join(project.path, ".kilo", "kilo.jsonc")).exists()).toBe(false)
})
test("removes an existing nested unset path", async () => {
await using project = await tmpdir()
const file = path.join(project.path, ".kilo", "kilo.jsonc")
await Filesystem.write(
file,
'{\n "$schema": "https://app.kilo.ai/config.json",\n "indexing": {\n "enabled": false,\n "provider": "ollama",\n "ollama": { "baseUrl": "http://127.0.0.1:11434" }\n }\n}\n',
)
const response = await req(project.path, "/config/overlay", {
method: "PATCH",
headers: { "content-type": "application/json" },
body: JSON.stringify({ scope: "project", unset: [["indexing", "enabled"]] }),
})
expect(response.status).toBe(200)
const saved = (await Bun.file(file).json()) as {
indexing: { enabled?: boolean; provider: string; ollama: { baseUrl: string } }
}
expect(saved.indexing.enabled).toBeUndefined()
expect(saved.indexing.provider).toBe("ollama")
expect(saved.indexing.ollama.baseUrl).toBe("http://127.0.0.1:11434")
})
test("returns exact raw target data and a stable missing-file revision", async () => {
await using project = await tmpdir()
const first = await KilocodeConfigOverlay.target({ scope: "project", directory: project.path })