-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Present cd dir separate to command #287909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'));
...minalContrib/chatAgentTools/browser/tools/commandLineRewriter/commandLineCdPrefixRewriter.ts
Outdated
Show resolved
Hide resolved
| let confirmationTitle: string; | ||
| if (extractedCd && cwd) { | ||
| // Construct the full directory path using the cwd's scheme/authority | ||
| const directoryUri = extractedCd.directory.startsWith('/') || /^[a-zA-Z]:/.test(extractedCd.directory) |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to determine if a path is absolute is incomplete. On Windows, paths starting with \ (like \path) are absolute, but this check only looks for drive letters. On POSIX systems, this would incorrectly treat a path starting with a drive letter pattern as absolute. Consider using platform-specific logic or existing VS Code path utilities to correctly determine absolute vs relative paths.
This issue also appears in the following locations of the same file:
- line 514
| const directoryUri = extractedCd.directory.startsWith('/') || /^[a-zA-Z]:/.test(extractedCd.directory) | |
| const isAbsoluteDirectory = os === OperatingSystem.Windows | |
| ? (/^[a-zA-Z]:[\\/]/.test(extractedCd.directory) || extractedCd.directory.startsWith('\\')) | |
| : extractedCd.directory.startsWith('/'); | |
| const directoryUri = isAbsoluteDirectory |
Fixes #277507