Skip to content

Fix edit tools for headless tool invocation (scenario automation)#4338

Draft
rwoll wants to merge 1 commit intomainfrom
rwoll/headless-edit-tools
Draft

Fix edit tools for headless tool invocation (scenario automation)#4338
rwoll wants to merge 1 commit intomainfrom
rwoll/headless-edit-tools

Conversation

@rwoll
Copy link
Member

@rwoll rwoll commented Mar 10, 2026

Fix edit tools for headless tool invocation (scenario automation)

Edit tools (apply_patch, create_file, replace_string) fail when invoked
via vscode.lm.invokeTool() outside a chat participant context because
resolveInput() is never called and this._promptContext?.stream is undefined.

This unblocks the vscode-copilot-evaluation tool call service mode where an
external process invokes tools via HTTP without a VS Code chat session.

Changes

For each tool, when no chat response stream is available (!hasStream):

  • apply_patch: Apply the already-built WorkspaceEdit directly via
    workspaceService.applyEdit() instead of streaming through responseStream
  • create_file: Write file directly via fileSystemService.writeFile()
  • replace_string: Build a WorkspaceEdit from the generated text edits
    and apply directly

The existing stream-based code path is completely unchanged. The !hasStream
branches return early before any stream code is reached.

Files Changed

File What Changes
src/extension/tools/node/applyPatchTool.tsx Remove stream requirement from guard; add !hasStream block that applies WorkspaceEdit directly
src/extension/tools/node/createFileTool.tsx Remove stream requirement from guard; add !hasStream block that writes file via fileSystemService
src/extension/tools/node/abstractReplaceStringTool.tsx Remove stream requirement from guard; add WorkspaceEdit import; add !hasStream block that applies text edits directly; remove overly-restrictive _promptContext check from input validation

Tests

Added 5 new headless-mode tests across 3 test files:

  • applyPatch.spec.tsx: ADD file and UPDATE file patches without stream
  • createFileTool.spec.ts (new): Create file and empty file without stream
  • replaceStringTool.spec.tsx: Replace string without stream

What's NOT changed

  • insertEditTool.tsx — requires VS Code core changes, only used by older/smaller models
  • The stream path — untouched, !hasStream blocks return early before any stream code
  • resolveInput() — unchanged, simply never called in automation mode

Fixes microsoft/vscode-copilot-evaluation#2818

Edit tools (apply_patch, create_file, replace_string) fail when invoked
via vscode.lm.invokeTool() outside a chat participant context because
resolveInput() is never called and this._promptContext?.stream is undefined.

This unblocks the vscode-copilot-evaluation tool call service mode where an
external process invokes tools via HTTP without a VS Code chat session.

For each tool, when no chat response stream is available (!hasStream):
- apply_patch: Apply the already-built WorkspaceEdit directly via
  workspaceService.applyEdit() instead of streaming through responseStream
- create_file: Write file directly via fileSystemService.writeFile()
- replace_string: Build a WorkspaceEdit from the generated text edits
  and apply directly

The existing stream-based code path is completely unchanged. The !hasStream
branches return early before any stream code is reached.

Fixes microsoft/vscode-copilot-evaluation#2818

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rwoll rwoll force-pushed the rwoll/headless-edit-tools branch from 56fad8f to 68b8c67 Compare March 10, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant