Merge branch 'main' into feat/suggest-code-review

This commit is contained in:
Marian Alexandru Alecu
2026-04-15 12:48:31 +03:00
committed by GitHub
27 changed files with 334 additions and 23 deletions
+1
View File
@@ -8,3 +8,4 @@ export const GlobalBus = new EventEmitter<{
},
]
}>()
GlobalBus.setMaxListeners(50) // kilocode_change — surface warning if SSE listeners accumulate
@@ -1,6 +1,5 @@
// kilocode_change - new file
import { $ } from "bun"
import { createTwoFilesPatch } from "diff"
import fs from "node:fs/promises"
import path from "node:path"
import z from "zod"
@@ -245,7 +244,7 @@ export namespace WorktreeDiff {
const additions = meta.status === "added" && meta.additions === 0 && !meta.tracked ? lines(after) : meta.additions
return {
file: meta.file,
patch: createTwoFilesPatch(meta.file, meta.file, before, after),
patch: "",
before,
after,
additions,
+14 -1
View File
@@ -70,14 +70,27 @@ export const EventRoutes = () =>
stream.onAbort(stop)
// kilocode_change start
// On Windows, stream.onAbort() may never fire after a client disconnects
// (delayed TCP RST detection via IOCP). Without this try/catch, the
// GlobalBus listener, heartbeat interval, and AsyncQueue stay alive
// indefinitely for each dead connection — leaking memory on every
// SSE reconnect. Catching write errors lets us clean up eagerly.
try {
for await (const data of q) {
if (data === null) return
await stream.writeSSE({ data })
try {
await stream.writeSSE({ data })
} catch {
log.info("event write failed, cleaning up dead stream")
stop()
return
}
}
} finally {
stop()
}
// kilocode_change end
})
},
)
+14 -1
View File
@@ -56,14 +56,27 @@ async function streamEvents(c: Context, subscribe: (q: AsyncQueue<string | null>
stream.onAbort(stop)
// kilocode_change start
// On Windows, stream.onAbort() may never fire after a client disconnects
// (delayed TCP RST detection via IOCP). Without this try/catch, the
// GlobalBus listener, heartbeat interval, and AsyncQueue stay alive
// indefinitely for each dead connection — leaking memory on every
// SSE reconnect. Catching write errors lets us clean up eagerly.
try {
for await (const data of q) {
if (data === null) return
await stream.writeSSE({ data })
try {
await stream.writeSSE({ data })
} catch {
log.info("global event write failed, cleaning up dead stream")
stop()
return
}
}
} finally {
stop()
}
// kilocode_change end
})
}
@@ -1,6 +1,7 @@
import { test, expect, describe } from "bun:test"
import { $ } from "bun"
import { tmpdir } from "../fixture/fixture"
import { WorktreeDiff } from "../../src/kilocode/review/worktree-diff"
import path from "path"
/**
@@ -145,6 +146,19 @@ describe("worktree diff git commands", () => {
expect(allFiles).toContain("new-file.py")
})
test("worktree detail does not include unused patch content", async () => {
await using tmp = await setupRepo()
const dir = tmp.path
await Bun.write(path.join(dir, "existing.txt"), "hello\nmodified\n")
const detail = await WorktreeDiff.detail({ dir, base: "HEAD", file: "existing.txt" })
expect(detail?.patch).toBe("")
expect(detail?.before).toBe("hello\n")
expect(detail?.after).toBe("hello\nmodified\n")
})
test("worktree scenario: branch with no new commits, only untracked files", async () => {
// This is the exact scenario from the screenshot:
// - Worktree created from main