Skip to content

Improve interactive terminal input handling#308855

Merged
meganrogge merged 9 commits intomainfrom
merogge/input-rules
Apr 9, 2026
Merged

Improve interactive terminal input handling#308855
meganrogge merged 9 commits intomainfrom
merogge/input-rules

Conversation

@meganrogge
Copy link
Copy Markdown
Collaborator

@meganrogge meganrogge commented Apr 9, 2026

When a terminal command waits for interactive input (e.g. npm init), the agent would sometimes respond with a text message suggesting the user interact directly, or batch all answers into a single send. This PR fixes that across sync, async, and background notification paths.

Also:

  • Shows "Pressed Enter in terminal" instead of "Sent " for empty input in send_to_terminal
  • Documents that command can be empty/whitespace to press Enter
  • Deduplicates rapid onDidDetectInputNeeded steering messages (same output within 5s)

Copilot AI review requested due to automatic review settings April 9, 2026 18:49
@meganrogge meganrogge self-assigned this Apr 9, 2026
@meganrogge meganrogge added this to the 1.116.0 milestone Apr 9, 2026
@meganrogge meganrogge enabled auto-merge (squash) April 9, 2026 18:50
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

Improves the terminal chat agent’s handling of interactive prompts by steering the model to send one prompt answer at a time (including “press Enter” sends) and by adding explicit guidance/notifications for input-needed cases across sync/async/background flows.

Changes:

  • Update SendToTerminal UI messages to treat empty/whitespace sends as “Press Enter” rather than a command send.
  • Expand RunInTerminal model guidance to require one-answer-per-prompt behavior (ask via vscode_askQuestions when not auto-approved).
  • Add a background “input needed” steering notification when the output monitor detects an interactive prompt in a background terminal.
Show a summary per file
File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/sendToTerminalTool.ts Adds “press Enter” messaging for empty input sends and adjusts confirmation text formatting.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts Strengthens interactive-input guidance and sends a steering request when background terminals need input.

Copilot's findings

Comments suppressed due to low confidence (2)

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/sendToTerminalTool.ts:103

  • New behavior for empty input ("Pressing Enter") in prepareToolInvocation isn't covered by the existing SendToTerminalTool tests (they only assert general message presence/truncation/newline normalization). Add a unit test that passes an empty/whitespace command and asserts the progressive/past/confirmation messages match the Enter semantics, to prevent regressions in interactive prompt flows.
		const pastTenseMessage = new MarkdownString();
		if (isEmptyInput) {
			invocationMessage.appendMarkdown(localize('send.progressive.enter', "Pressing `Enter` in terminal"));
			pastTenseMessage.appendMarkdown(localize('send.past.enter', "Pressed `Enter` in terminal"));
		} else {

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts:1924

  • The new background input-needed notification path (steering request sent from _registerCompletionNotification when onDidDetectInputNeeded fires) isn't covered by the existing RunInTerminalTool tests. Consider adding a focused test that stubs IChatService.sendRequest, triggers onDidDetectInputNeeded, and asserts a single steering request is queued, so future refactors don't break interactive input handling for background terminals.
			// When the output monitor detects the terminal is waiting for input,
			// send a steering message so the agent handles it via send_to_terminal.
			store.add(outputMonitor.onDidDetectInputNeeded(() => {
				const execution = RunInTerminalTool._activeExecutions.get(termId);
				if (!execution) {
					return;
				}
				const currentOutput = execution.getOutput();
				const isAutoApproved = isSessionAutoApproveLevel(chatSessionResource, this._configurationService, this._chatWidgetService, this._chatService);
				const inputAction = isAutoApproved
					? `Determine the best answer for the current prompt from context and immediately call ${TerminalToolId.SendToTerminal} with id "${termId}" to send ONLY that one answer. Then call ${TerminalToolId.GetTerminalOutput} to read the next prompt. Repeat one prompt at a time until the command finishes. Do NOT send multiple answers at once. Do NOT ask the user or respond with a text message.`
					: `You MUST call the vscode_askQuestions tool to ask the user what values to provide. Do NOT respond with a text message asking the user — use the tool. Then send ONLY the answer for the current prompt using ${TerminalToolId.SendToTerminal} with id "${termId}", call ${TerminalToolId.GetTerminalOutput} to read the next prompt, and repeat one prompt at a time.`;
				const message = `[Terminal ${termId} notification: command is waiting for input. ${inputAction}]\nTerminal output:\n${currentOutput}`;

				this._logService.debug(`RunInTerminalTool: Input needed in background terminal ${termId}, notifying chat session`);

				this._chatService.sendRequest(chatSessionResource, message, {
					queue: ChatRequestQueueKind.Steering,
					isSystemInitiated: true,
  • Files reviewed: 2/2 changed files
  • Comments generated: 2

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Screenshot Changes

Base: 5ed47665 Current: 7bd08951

Changed (1)

agentSessionsViewer/ApprovalRowLongLabel/Light
Before After
before after

@meganrogge meganrogge merged commit fc5edfe into main Apr 9, 2026
26 checks passed
@meganrogge meganrogge deleted the merogge/input-rules branch April 9, 2026 20:17
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.

3 participants