Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 12, 2026

Summary

This PR attempts to address Issue #10622. Feedback and guidance are welcome.

Problem

When users have multiple terminal tabs open, the @terminal context mention grabs output from all terminals indiscriminately, leading to context pollution and wasted tokens from unrelated terminal sessions.

Solution

This PR adds the ability to select a specific terminal instance when using the @terminal context mention:

  1. Terminal sub-selection menu: When selecting @terminal in the context menu, users now see a sub-menu listing all available terminal instances (similar to git commit selection), plus an "All Terminals" option for the previous behavior

  2. New mention syntax: Added support for @terminal:name syntax to reference a specific terminal by name (e.g., @terminal:bash, @terminal:zsh)

  3. Specific terminal output: When using @terminal:name, only the output from that specific terminal is included in the context

Changes

  • packages/types/src/vscode-extension-host.ts: Added TerminalInfo interface and terminalSearchResults/searchTerminals message types
  • webview-ui/src/utils/context-mentions.ts: Added Terminal sub-selection in getContextMenuOptions()
  • src/core/webview/webviewMessageHandler.ts: Added searchTerminals handler to return terminal instances
  • webview-ui/src/components/chat/ChatTextArea.tsx: Added terminal fetching when Terminal type is selected
  • src/core/mentions/index.ts: Updated parseMentions and getLatestTerminalOutput to handle @terminal:name syntax

Testing

  • TypeScript builds pass
  • Existing mention tests pass
  • Manual testing recommended for UI interaction

Closes #10622


Important

Adds terminal instance selection for @terminal context mention with sub-menu and @terminal:name syntax, updating relevant code and UI components.

  • Behavior:
    • Adds terminal instance selection for @terminal context mention with a sub-menu and @terminal:name syntax.
    • Only includes output from specified terminal when using @terminal:name.
  • Code Changes:
    • vscode-extension-host.ts: Adds TerminalInfo interface and terminalSearchResults/searchTerminals message types.
    • context-mentions.ts: Updates getContextMenuOptions() to include terminal sub-selection.
    • webviewMessageHandler.ts: Adds searchTerminals handler to return terminal instances.
    • ChatTextArea.tsx: Fetches terminal instances when Terminal type is selected.
  • Testing:
    • TypeScript builds pass.
    • Existing mention tests pass.
    • Manual testing recommended for UI interaction.

This description was created by Ellipsis for a6253d6. You can customize this summary. It will automatically update as commits are pushed.

- Add TerminalInfo interface and terminalSearchResults message type
- Update context-mentions.ts to show terminal sub-selection menu
- Add searchTerminals handler in webviewMessageHandler.ts
- Update ChatTextArea.tsx to fetch terminals when Terminal type selected
- Update parseMentions to handle @Terminal:name syntax
- Update getLatestTerminalOutput to support specific terminal selection
- Update openMention to focus specific terminal when clicked

Addresses #10622
@roomote
Copy link
Contributor Author

roomote bot commented Jan 12, 2026

Rooviewer Clock   See task on Roo Cloud

Reviewed the terminal instance selection feature. Found 2 issues to address:

  • Duplicate "All Terminals" entry in context menu (webview-ui/src/utils/context-mentions.ts)
  • Race condition in terminal focusing with arbitrary 100ms delay (src/core/mentions/index.ts)

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Comment on lines +251 to +252
if (selectedType === ContextMenuOptionType.Terminal) {
const terminals = queryItems.filter((item) => item.type === ContextMenuOptionType.Terminal)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This filtering will include duplicate entries. The queryItems array already contains a default { type: Terminal, value: "terminal" } entry (added in ChatTextArea.tsx line 297), and then you prepend another "All Terminals" option with the same value. When the terminal sub-menu is displayed, users will see two items that both represent "All Terminals" - one with an explicit label and one that falls back to default rendering.

Consider filtering out the default terminal item before adding the explicit "All Terminals" option:

Suggested change
if (selectedType === ContextMenuOptionType.Terminal) {
const terminals = queryItems.filter((item) => item.type === ContextMenuOptionType.Terminal)
if (selectedType === ContextMenuOptionType.Terminal) {
const terminals = queryItems.filter(
(item) => item.type === ContextMenuOptionType.Terminal && item.value !== "terminal"
)

Fix it with Roo Code or mention @roomote and request a fix.

Comment on lines +415 to +418
// Show the terminal to make it active
targetTerminal.show()
// Small delay to ensure terminal is focused
await new Promise((resolve) => setTimeout(resolve, 100))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 100ms delay is an arbitrary heuristic that may not reliably ensure the terminal is focused before selectAll executes. Terminal.show() makes the terminal visible but doesn't guarantee it becomes the active terminal synchronously. On slower machines or busy VS Code instances, this timing may be insufficient, potentially causing content to be copied from the wrong terminal.

Consider using a polling approach with vscode.window.activeTerminal to verify the terminal is actually active, or document this as a known limitation. A more robust pattern might be:

targetTerminal.show()
const maxRetries = 10
for (let i = 0; i < maxRetries; i++) {
	if (vscode.window.activeTerminal === targetTerminal) break
	await new Promise(resolve => setTimeout(resolve, 50))
}

Fix it with Roo Code or mention @roomote and request a fix.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Ability to select specific terminal instance when using @terminal to prevent context pollution

3 participants