Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/quiet-config-unset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kilocode/cli": patch
---

Allow clearing a nested project setting when no project config file exists yet.
5 changes: 5 additions & 0 deletions packages/opencode/src/kilocode/config/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
marius-kilocode marked this conversation as resolved.
}
return applyEdits(
input,
modify(input, parts, patch === null ? undefined : patch, {
Expand Down
35 changes: 35 additions & 0 deletions packages/opencode/test/kilocode/server/config-overlay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Comment thread
marius-kilocode marked this conversation as resolved.
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 })
Expand Down
Loading