Present cd dir separate to command#287909
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements extraction and separate presentation of cd directory prefixes from terminal commands in chat tool invocations, addressing issue #277507. When AI agents generate commands like cd /path && npm install, the directory change is now extracted and displayed separately in the confirmation title, while only the actual command (npm install) is shown in the editor.
Changes:
- Extracted cd prefix parsing logic into a new reusable
extractCdPrefixfunction - Modified confirmation flow to display directory in title and command without cd prefix in editor
- Added comprehensive tests for the new extraction function
- User edits now automatically prepend the cd prefix back to maintain command correctness
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| commandLineCdPrefixRewriter.ts | Extracted cd parsing logic into new extractCdPrefix function with interface |
| runInTerminalTool.ts | Integrated cd extraction to compute confirmation display data with directory labels |
| chatService.ts | Extended terminal tool data interface to include cwd and pre-computed confirmation data |
| chatTerminalToolConfirmationSubPart.ts | Uses pre-computed confirmation data to display command without cd, prepends cd back on user edits |
| commandLineCdPrefixRewriter.test.ts | Added comprehensive test suite for extractCdPrefix function |
Comments suppressed due to low confidence (2)
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts:514
- This calculation assumes the cd prefix is exactly
commandToDisplay.length - extractedCd.command.lengthcharacters, but this doesn't account for the separator (&∨) between the cd command and the suffix. If the command iscd /path && npm install, this would capturecd /path &&instead ofcd /path &&. While this might work, it's fragile. Consider extracting the cdPrefix directly from the regex match or by using the matched groups to calculate the exact prefix.
const cdPrefix = commandToDisplay.substring(0, commandToDisplay.length - extractedCd.command.length);
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/commandLineCdPrefixRewriter.test.ts:111
- Missing test coverage for the
cd /dcommand with a semicolon separator on PowerShell. The regex supports both&∧separators, but only the&&case is tested forcd /d. Add a test case likecd /d C:\\path; npm testto ensure consistency.
test('should extract Set-Location', () => t('Set-Location C:\\path; npm test', 'C:\\path', 'npm test'));
test('should extract Set-Location -Path', () => t('Set-Location -Path C:\\path; npm test', 'C:\\path', 'npm test'));
dmitrivMS
approved these changes
Jan 16, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #277507