Skip to content

Conversation

@Tyriar
Copy link
Member

@Tyriar Tyriar commented Jan 16, 2026

Fixes #287772

image

@Tyriar Tyriar added this to the January 2026 milestone Jan 16, 2026
@Tyriar Tyriar self-assigned this Jan 16, 2026
Copilot AI review requested due to automatic review settings January 16, 2026 13:50
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 adds special formatting for Python commands executed via python -c "..." syntax in terminal tool confirmations. Instead of showing the full shell command with escaped quotes, the UI now displays just the Python code with proper syntax highlighting, making it easier for users to understand what will be executed.

Changes:

  • Added extractPythonCommand function to parse and extract Python code from python -c commands with proper quote unescaping for different shells (bash vs PowerShell)
  • Added presentationOverrides to the terminal tool data model to support alternative display formatting without changing the actual command that runs
  • Modified UI components (confirmation and progress parts) to use presentationOverrides when available, including making the editor read-only when displaying extracted Python code

Reviewed changes

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

Show a summary per file
File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalHelpers.ts Implements the extractPythonCommand function with shell-aware quote unescaping
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts Integrates Python command extraction into the tool preparation flow and updates confirmation titles
src/vs/workbench/contrib/chat/common/chatService/chatService.ts Adds presentationOverrides interface to the terminal tool invocation data model
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolProgressPart.ts Uses presentationOverrides for displaying command with appropriate language in the progress part
src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolConfirmationSubPart.ts Uses presentationOverrides for confirmation display and makes editor read-only when showing extracted Python
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/runInTerminalHelpers.test.ts Comprehensive test suite for extractPythonCommand covering various quote styles, shells, and edge cases
Comments suppressed due to low confidence (3)

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalHelpers.ts:80

  • Similar to the double quote regex, this pattern uses a greedy .+ which will fail with trailing content and doesn't handle absolute paths to python executables. Consider using a non-greedy match and allowing for paths.
	const singleQuoteMatch = commandLine.match(/^python(?:3)?\s+-c\s+'(?<python>.+)'$/s);

src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolConfirmationSubPart.ts:193

  • When presentationOverrides is set and the editor is read-only, this edit handler should not prepend the cdPrefix since the displayed content is the extracted Python code, not the actual command with cd prefix. The cdPrefix logic only makes sense when displaying the actual shell command. This could lead to incorrect command reconstruction.
				terminalData.commandLine.userEdited = cdPrefix + currentValue;

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalHelpers.ts:82

  • The .trim() operation removes leading/trailing whitespace from the Python code. However, in Python, leading whitespace is significant for indentation. While trailing whitespace is generally fine to trim, leading whitespace should be preserved as it may be intentional. Consider only using .trimEnd() or handling this more carefully.
		return singleQuoteMatch.groups.python.trim();

@Tyriar Tyriar marked this pull request as ready for review January 16, 2026 14:30
@Tyriar Tyriar enabled auto-merge January 16, 2026 14:30
dmitrivMS
dmitrivMS previously approved these changes Jan 16, 2026
@Tyriar Tyriar merged commit 3df70f3 into main Jan 16, 2026
22 checks passed
@Tyriar Tyriar deleted the tyriar/287772_py branch January 16, 2026 17:47
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.

Present python commands in confirmation with syntax highlighting

3 participants