Skip to content

Commit aa85bc8

Browse files
Chris Hassonhassoncs
authored andcommitted
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: Kilo-Org/kilocode#712
1 parent cc0f9e3 commit aa85bc8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.changeset/lemon-grapes-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kilo-code": patch
3+
---
4+
5+
Fix 'failure to apply changes to files' when Git diff views are open

src/core/environment/getEnvironmentDetails.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
5858
const maxTabs = maxOpenTabsContext ?? 20
5959
const openTabPaths = vscode.window.tabGroups.all
6060
.flatMap((group) => group.tabs)
61-
.map((tab) => (tab.input as vscode.TabInputText)?.uri?.fsPath)
61+
.filter((tab) => tab.input instanceof vscode.TabInputText)
62+
.map((tab) => (tab.input as vscode.TabInputText).uri.fsPath)
6263
.filter(Boolean)
6364
.map((absolutePath) => path.relative(cline.cwd, absolutePath).toPosix())
6465
.slice(0, maxTabs)

0 commit comments

Comments
 (0)