Fix edit tools for headless tool invocation (scenario automation)#4338
Draft
Fix edit tools for headless tool invocation (scenario automation)#4338
Conversation
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>
56fad8f to
68b8c67
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix edit tools for headless tool invocation (scenario automation)
Edit tools (
apply_patch,create_file,replace_string) fail when invokedvia
vscode.lm.invokeTool()outside a chat participant context becauseresolveInput()is never called andthis._promptContext?.streamis 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-builtWorkspaceEditdirectly viaworkspaceService.applyEdit()instead of streaming throughresponseStreamcreate_file: Write file directly viafileSystemService.writeFile()replace_string: Build aWorkspaceEditfrom the generated text editsand apply directly
The existing stream-based code path is completely unchanged. The
!hasStreambranches return early before any stream code is reached.
Files Changed
src/extension/tools/node/applyPatchTool.tsx!hasStreamblock that appliesWorkspaceEditdirectlysrc/extension/tools/node/createFileTool.tsx!hasStreamblock that writes file viafileSystemServicesrc/extension/tools/node/abstractReplaceStringTool.tsxWorkspaceEditimport; add!hasStreamblock that applies text edits directly; remove overly-restrictive_promptContextcheck from input validationTests
Added 5 new headless-mode tests across 3 test files:
applyPatch.spec.tsx: ADD file and UPDATE file patches without streamcreateFileTool.spec.ts(new): Create file and empty file without streamreplaceStringTool.spec.tsx: Replace string without streamWhat's NOT changed
insertEditTool.tsx— requires VS Code core changes, only used by older/smaller models!hasStreamblocks return early before any stream coderesolveInput()— unchanged, simply never called in automation modeFixes microsoft/vscode-copilot-evaluation#2818