Skip to content

Conversation

@Tyriar
Copy link
Member

@Tyriar Tyriar commented Jan 14, 2026

Fixes #277507

@Tyriar Tyriar added this to the January 2026 milestone Jan 14, 2026
@Tyriar Tyriar self-assigned this Jan 14, 2026
Copilot AI review requested due to automatic review settings January 14, 2026 23:38
Copy link
Contributor

Copilot AI left a 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 extractCdPrefix function
  • 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.length characters, but this doesn't account for the separator (&& or ; ) between the cd command and the suffix. If the command is cd /path && npm install, this would capture cd /path && instead of cd /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 /d command with a semicolon separator on PowerShell. The regex supports both && and ; separators, but only the && case is tested for cd /d. Add a test case like cd /d C:\\path; npm test to 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'));

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)
Copy link

Copilot AI Jan 14, 2026

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
Suggested change
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

Copilot uses AI. Check for mistakes.
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.

Extract cd prefixes in terminal tool and present separately

2 participants