From aa85bc8e3c6a6bb843d79e42aa23142b3ba3eb1c Mon Sep 17 00:00:00 2001 From: Chris Hasson Date: Tue, 29 Jul 2025 12:01:03 +0200 Subject: [PATCH 1/2] fix(environment): Filter out non-text tab inputs ## Bug Description Multi-file edit operations (`apply_diff` tool) would fail consistently when Git diff views were open in VSCode. The failure occurred before reaching the diff view opening code, indicating the issue was not with tab management as initially suspected. ## Root Cause The bug was caused by **environment context contamination** in `src/core/environment/getEnvironmentDetails.ts`. When Git diff views are open, the environment details gathering code was incorrectly processing non-text tabs: 1. **Improper type casting**: Line 68 used `(tab.input as vscode.TabInputText)?.uri?.fsPath` without filtering, casting all tab inputs as `TabInputText` regardless of their actual type 2. **Processing incompatible tab types**: Git diff tabs have input types like `TabInputTextDiff`, not `TabInputText` 3. **Malformed environment data**: This resulted in unexpected/malformed data being included in the environment context sent to the AI 4. **AI parsing interference**: The contaminated context affected how the AI parsed multi-file `apply_diff` requests, causing them to fail ## Fix Added proper tab type filtering before processing: ```typescript // Before (BROKEN) .map((tab) => (tab.input as vscode.TabInputText)?.uri?.fsPath) // After (FIXED) .filter((tab) => tab.input instanceof vscode.TabInputText) .map((tab) => (tab.input as vscode.TabInputText).uri.fsPath) ``` This matches the correct pattern already used in other parts of the codebase like `DiffViewProvider.ts` and `WorkspaceTracker.ts`. ## Impact - Multi-file edits now work reliably when Git diff views are open - Environment context data is properly filtered and type-safe - Consistent tab processing across the codebase Fixes: https://github.com/Kilo-Org/kilocode/issues/712 --- .changeset/lemon-grapes-bake.md | 5 +++++ src/core/environment/getEnvironmentDetails.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/lemon-grapes-bake.md diff --git a/.changeset/lemon-grapes-bake.md b/.changeset/lemon-grapes-bake.md new file mode 100644 index 00000000000..4f360ed5a76 --- /dev/null +++ b/.changeset/lemon-grapes-bake.md @@ -0,0 +1,5 @@ +--- +"kilo-code": patch +--- + +Fix 'failure to apply changes to files' when Git diff views are open diff --git a/src/core/environment/getEnvironmentDetails.ts b/src/core/environment/getEnvironmentDetails.ts index b83b37c75bb..5a0a15962cd 100644 --- a/src/core/environment/getEnvironmentDetails.ts +++ b/src/core/environment/getEnvironmentDetails.ts @@ -58,7 +58,8 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo const maxTabs = maxOpenTabsContext ?? 20 const openTabPaths = vscode.window.tabGroups.all .flatMap((group) => group.tabs) - .map((tab) => (tab.input as vscode.TabInputText)?.uri?.fsPath) + .filter((tab) => tab.input instanceof vscode.TabInputText) + .map((tab) => (tab.input as vscode.TabInputText).uri.fsPath) .filter(Boolean) .map((absolutePath) => path.relative(cline.cwd, absolutePath).toPosix()) .slice(0, maxTabs) From ee83429df8ec5155749dcc31e230a1de11916738 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Tue, 29 Jul 2025 10:12:53 -0400 Subject: [PATCH 2/2] Delete .changeset/lemon-grapes-bake.md --- .changeset/lemon-grapes-bake.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .changeset/lemon-grapes-bake.md diff --git a/.changeset/lemon-grapes-bake.md b/.changeset/lemon-grapes-bake.md deleted file mode 100644 index 4f360ed5a76..00000000000 --- a/.changeset/lemon-grapes-bake.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"kilo-code": patch ---- - -Fix 'failure to apply changes to files' when Git diff views are open