Skip to content

CLI terminal command handling to remove cd#4034

Open
DonJayamanne wants to merge 1 commit intomainfrom
don/wrong-coyote
Open

CLI terminal command handling to remove cd#4034
DonJayamanne wants to merge 1 commit intomainfrom
don/wrong-coyote

Conversation

@DonJayamanne
Copy link
Collaborator

@DonJayamanne DonJayamanne commented Feb 26, 2026

@DonJayamanne DonJayamanne self-assigned this Feb 26, 2026
@DonJayamanne DonJayamanne marked this pull request as ready for review February 27, 2026 22:28
Copilot AI review requested due to automatic review settings February 27, 2026 22:28
@vs-code-engineering vs-code-engineering bot added this to the February 2026 milestone Feb 27, 2026
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

Adjusts how Copilot CLI shell commands are presented to users by stripping redundant cd <workingDirectory> && (and PowerShell equivalents) when the cd target matches the known working directory, aligning with vscode#297967.

Changes:

  • Exported and reused getCdPresentationOverrides to derive a user-friendly command line without a redundant cd prefix.
  • Updated Copilot CLI tool-invocation formatting to apply the cd-stripping presentation logic.
  • Added/updated unit tests to cover bash vs PowerShell patterns and workingDirectory matching behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/extension/agents/copilotcli/node/permissionHelpers.ts Uses getCdPresentationOverrides to present a stripped command in terminal permission confirmations (with OS defaulting).
src/extension/agents/copilotcli/node/test/permissionHelpers.spec.ts Adds coverage for stripping/keeping cd/Set-Location prefixes based on workingDirectory and Windows mode.
src/extension/agents/copilotcli/common/copilotCLITools.ts Exports getCdPresentationOverrides and applies it while formatting shell tool invocation data.
src/extension/agents/copilotcli/common/test/copilotCLITools.spec.ts Updates expectations around command-line data when cd stripping applies.
Comments suppressed due to low confidence (4)

src/extension/agents/copilotcli/common/test/copilotCLITools.spec.ts:601

  • This assertion assumes commandLine.original is stripped, but ChatTerminalToolInvocationData documents stripping via presentationOverrides while keeping original intact. Update this test to reflect the corrected behavior (full command in original, stripped command in presentationOverrides).

			const data = completed.toolSpecificData as any;
			expect(data.commandLine.original).toBe('make build');
			expect(data.presentationOverrides).toEqual({ commandLine: 'make build' });
			expect(data.state.exitCode).toBe(0);

src/extension/agents/copilotcli/common/copilotCLITools.ts:836

  • On Windows, isEqual here is case-sensitive (it’s bound to extUri), so cd C:\Workspace vs workingDirectory c:\workspace won’t match and the cd prefix won’t be stripped. Since this is file-path matching, consider using a casing-insensitive comparison (e.g. extUriBiasedIgnorePathCase.isEqual) or otherwise normalizing drive-letter/path casing before comparing.
export function getCdPresentationOverrides(commandLine: string, isPowershell: boolean, workingDirectory?: URI): { commandLine: string } | undefined {
	const cdPrefix = extractCdPrefix(commandLine, isPowershell);
	if (!cdPrefix || !workingDirectory) {
		return undefined;
	}
	const cdUri = URI.file(cdPrefix.directory);
	if (isEqual(cdUri, workingDirectory)) {
		return { commandLine: cdPrefix.command };

src/extension/agents/copilotcli/common/copilotCLITools.ts:853

  • ChatTerminalToolInvocationData.commandLine.original is documented as the original/executed command, while presentationOverrides.commandLine is the UI-only stripped form. Overwriting original with the stripped command breaks that contract and can lose the real command for auditing/fallback UI. Keep commandLine.original as command (full input) and only set presentationOverrides when the cd prefix matches.

This issue also appears on line 863 of the same file.

	const presentationOverrides = getCdPresentationOverrides(command, isPowershell, workingDirectory);
	invocation.invocationMessage = args.description ? new MarkdownString(args.description) : '';
	invocation.toolSpecificData = {
		commandLine: {
			original: presentationOverrides?.commandLine ?? command
		},
		language: isPowershell ? 'powershell' : 'bash',
		presentationOverrides
	} as ChatTerminalToolInvocationData;

src/extension/agents/copilotcli/common/copilotCLITools.ts:869

  • Same issue on completion: commandLine.original should remain toolCall.arguments.command and not be replaced by the presentation override. Use presentationOverrides.commandLine for the stripped display value only.
	const presentationOverrides = getCdPresentationOverrides(toolCall.arguments.command, isPowershell, workingDirectory);
	const toolSpecificData: ChatTerminalToolInvocationData = {
		commandLine: {
			original: presentationOverrides?.commandLine ?? toolCall.arguments.command
		},
		language: isPowershell ? 'powershell' : 'bash',
		presentationOverrides,

@DonJayamanne DonJayamanne added this pull request to the merge queue Feb 27, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Feb 27, 2026
@rzhao271 rzhao271 modified the milestones: February 2026, March 2026 Feb 27, 2026
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.

Unwanted CD prefix in terminal commands for CLI

4 participants