Skip to content

Conversation

@meganrogge
Copy link
Contributor

@meganrogge meganrogge commented Oct 31, 2025

fixes #274311
fixes #274179

This PR implements a mechanism to pre-assign command IDs for terminal commands executed by chat agent tools, enabling better tracking and linking of commands between the renderer and ptyHost. The system generates a custom command ID early in the process flow and propagates it through the execution pipeline.

Key changes:

  • Introduced terminalCommandId field to IChatTerminalToolInvocationData for pre-assigned command IDs
  • Added setNextCommandId method throughout the terminal process chain (from ITerminalInstance to ITerminalChildProcess)
  • Updated execution strategies to pass the command ID when executing terminal commands
  • Modified command detection to use pre-assigned IDs when available
  • Refactored output collection to use the pre-assigned command ID for lookup
  • Removes stored command ids from chat service

Copilot AI and others added 5 commits October 31, 2025 01:38
- Added terminalCommandUri?: UriComponents field to the interface
- Fixes TypeScript compilation errors in chatTerminalToolProgressPart and runInTerminalTool

Co-authored-by: meganrogge <[email protected]>
- Removed _updateTerminalCommandMetadata and all its calls
- Use getTerminalInstanceByToolSessionId instead of terminalCommandUri for getting terminal instance
- Remove _getTerminalResource method from chatTerminalToolProgressPart
- Remove terminalCommandUri field from IChatTerminalToolInvocationData
- Output HTML is now retrieved dynamically via _collectOutput when needed
- Simplifies code by 66 lines while maintaining functionality

Co-authored-by: meganrogge <[email protected]>
- Updated registerTerminalInstanceWithToolSession to accept optional terminalCommandId
- Store pre-assigned command ID immediately instead of waiting for onCommandFinished
- Pass terminalCommandId from RunInTerminalTool to terminalChatService
- Centralizes command ID management in terminalChatService for better consistency

Co-authored-by: meganrogge <[email protected]>
Copilot AI review requested due to automatic review settings October 31, 2025 19:37
@meganrogge meganrogge requested a review from Tyriar October 31, 2025 19:46
@meganrogge meganrogge added this to the October 2025 milestone Oct 31, 2025
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 a mechanism to pre-assign command IDs for terminal commands executed by chat agent tools, enabling better tracking and linking of commands between the renderer and ptyHost. The system generates a custom command ID early in the process flow and propagates it through the execution pipeline.

Key changes:

  • Introduced terminalCommandId field to IChatTerminalToolInvocationData for pre-assigned command IDs
  • Added setNextCommandId method throughout the terminal process chain (from ITerminalInstance to ITerminalChildProcess)
  • Updated execution strategies to pass the command ID when executing terminal commands
  • Modified command detection to use pre-assigned IDs when available
  • Refactored output collection to use the pre-assigned command ID for lookup

Reviewed Changes

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

Show a summary per file
File Description
src/vs/workbench/contrib/chat/common/chatService.ts Added terminalCommandId field to terminal tool invocation data, replacing terminalCommandUri
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts Generated and propagated custom command ID through tool execution flow; removed _updateTerminalCommandMetadata
src/vs/workbench/contrib/terminal/browser/terminal.ts Added commandId parameter to runCommand and registerTerminalInstanceWithToolSession methods
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Implemented command ID pre-assignment before command execution
src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatService.ts Updated to handle pre-assigned command IDs and fixed persistent process ID access
src/vs/workbench/contrib/chat/browser/chatContentParts/toolInvocationParts/chatTerminalToolProgressPart.ts Refactored to use command ID for output lookup; streamlined action creation
src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts Changed getCommandOutputAsHtml return type to include truncation status
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/*.ts Added commandId parameter to execute strategy interface and implementations
src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts Implemented setNextCommandId and logic to use pre-assigned IDs
src/vs/platform/terminal/common/capabilities/commandDetection/terminalCommand.ts Changed command ID from required to optional
src/vs/platform/terminal/node/ptyService.ts Added setNextCommandId to pty service chain
src/vs/workbench/services/terminal/common/embedderTerminalService.ts Added no-op setNextCommandId implementation
Multiple test files Added setNextCommandId stub implementations to test mocks
Comments suppressed due to low confidence (1)

src/vs/workbench/contrib/chat/browser/chatContentParts/toolInvocationParts/chatTerminalToolProgressPart.ts:444

  • The explicit return; on line 444 is unnecessary and inconsistent. The function already returns undefined implicitly when no other return path is taken. Remove line 444 for cleaner code.
		const commandId = this._terminalChatService.getTerminalCommandIdByToolSessionId(this._terminalData.terminalToolSessionId);
		if (commandId) {
			return commands.find(c => c.id === commandId);
		}
		return;

@meganrogge meganrogge enabled auto-merge (squash) October 31, 2025 20:27
@meganrogge meganrogge merged commit ff488e3 into main Oct 31, 2025
28 checks passed
@meganrogge meganrogge deleted the merogge/persist-command branch October 31, 2025 21:48
Comment on lines +143 to +145
async setNextCommandId(commandLine: string, commandId: string): Promise<void> {
// No-op
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't great that there are a bunch of no-op ones. That's due to being on ITerminalChildProcess?

Could we put it on IPtyService instead?

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.

Focus terminal button doesn't work after reloading window Link run in terminal session with command ID

4 participants