diff --git a/.changeset/large-worktree-diffs.md b/.changeset/large-worktree-diffs.md deleted file mode 100644 index 72bdbbcdde..0000000000 --- a/.changeset/large-worktree-diffs.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@kilocode/cli": patch ---- - -Reduce Agent Manager memory usage when viewing large worktree diffs. diff --git a/packages/kilo-docs/source-links.md b/packages/kilo-docs/source-links.md index 03b016912c..6ba0ad51c3 100644 --- a/packages/kilo-docs/source-links.md +++ b/packages/kilo-docs/source-links.md @@ -1,7 +1,7 @@ # Source Code Links - + - @@ -55,8 +55,6 @@ - -- - - - diff --git a/packages/kilo-vscode/src/review-utils.ts b/packages/kilo-vscode/src/review-utils.ts index 6dadb3b0a6..e5c56a3b28 100644 --- a/packages/kilo-vscode/src/review-utils.ts +++ b/packages/kilo-vscode/src/review-utils.ts @@ -42,19 +42,6 @@ export async function resolveLocalDiffTarget( return { directory: root, baseBranch: base } } -/** - * Produces a lightweight hash key for a list of file diffs. - * - * Intentionally excludes `diff.patch` — the extension never renders the - * unified-diff patch string (VS Code's native diff editor uses before/after - * file contents instead). Including it would pull in multi-MB payloads - * generated by opencode's `context: MAX_SAFE_INTEGER` setting, inflating - * memory for no benefit. The remaining fields (file, status, additions, - * deletions, tracked, generatedLike, summarized, stamp) are sufficient to - * detect when the diff list has meaningfully changed. - * - * See: https://github.com/Kilo-Org/kilocode/issues/8951 - */ export function hashFileDiffs( diffs: Array< SnapshotFileDiff & { @@ -67,6 +54,7 @@ export function hashFileDiffs( ): string { return diffs .map((diff) => { + const content = diff.summarized ? "" : diff.patch return [ diff.file, diff.status, @@ -76,6 +64,7 @@ export function hashFileDiffs( diff.generatedLike ? "generated" : "source", diff.summarized ? "summary" : "detail", diff.stamp ?? "", + content, ].join(":") }) .join("|") diff --git a/packages/opencode/src/kilocode/review/worktree-diff.ts b/packages/opencode/src/kilocode/review/worktree-diff.ts index 2d85677c9a..3bccf81c79 100644 --- a/packages/opencode/src/kilocode/review/worktree-diff.ts +++ b/packages/opencode/src/kilocode/review/worktree-diff.ts @@ -1,5 +1,6 @@ // 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" @@ -244,7 +245,7 @@ export namespace WorktreeDiff { const additions = meta.status === "added" && meta.additions === 0 && !meta.tracked ? lines(after) : meta.additions return { file: meta.file, - patch: "", + patch: createTwoFilesPatch(meta.file, meta.file, before, after), before, after, additions, diff --git a/packages/opencode/test/kilocode/worktree-diff.test.ts b/packages/opencode/test/kilocode/worktree-diff.test.ts index cb6d08794a..9a284a3add 100644 --- a/packages/opencode/test/kilocode/worktree-diff.test.ts +++ b/packages/opencode/test/kilocode/worktree-diff.test.ts @@ -1,7 +1,6 @@ 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" /** @@ -146,19 +145,6 @@ 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