Skip to content

Present cd dir separate to command#287909

Merged
Tyriar merged 4 commits into
mainfrom
tyriar/277507
Jan 16, 2026
Merged

Present cd dir separate to command#287909
Tyriar merged 4 commits into
mainfrom
tyriar/277507

Conversation

@Tyriar
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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'));

@Tyriar Tyriar marked this pull request as ready for review January 16, 2026 11:42
@Tyriar Tyriar enabled auto-merge January 16, 2026 11:42
@Tyriar Tyriar merged commit f461960 into main Jan 16, 2026
22 checks passed
@Tyriar Tyriar deleted the tyriar/277507 branch January 16, 2026 11:59
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Mar 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

3 participants