Skip to content

Stream built-in shell output over AHP terminal channel#327067

Merged
anthonykim1 merged 20 commits into
mainfrom
anthonykim1/shellOutputStreaming
Jul 23, 2026
Merged

Stream built-in shell output over AHP terminal channel#327067
anthonykim1 merged 20 commits into
mainfrom
anthonykim1/shellOutputStreaming

Conversation

@anthonykim1

@anthonykim1 anthonykim1 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Related: microsoft/agent-host-protocol#352
Resolves: #324825
Part of: #323399

  • Adopt the terminal completion model from Add isPty and fold TerminalComplete into ToolResultTerminalContent agent-host-protocol#352: move command exitCode/preview/truncated onto the terminal result and distinguish PTY-backed terminals from plain-text output channels with isPty.
  • Stream public Copilot SDK tool.execution_partial_result events from runtime-executed shell tools into output-only AHP terminal channels, while keeping client-hosted PTY terminals on their existing path.
  • Treat partial output as cumulative runtime snapshots: append only the unseen suffix while a snapshot grows, then clear and replay it when runtime truncation rewrites the snapshot.
  • Create an output channel on the first partial result or when foreground shell completion supplies retained output or exit metadata. Leave background shell handoff and completions with neither output nor exit metadata out of the inline terminal path.
  • Prefer structured SDK shell_exit metadata for the command result. When the external SDK bridge removes that block, use the runtime's trailing shell-completion marker as a scoped non-PTY fallback for the exit code and retained preview.
  • Attach output-only channels to chat through a read-only output source without creating an ITerminalInstance, adding a root terminal entry, opening a panel terminal, or exposing terminal Focus/Show actions.
  • Render the plain-text stream in the existing detached xterm, normalize line endings only in the Agent Host output adapter, and serialize snapshot writes so growing or rewritten output is not duplicated or stale.
  • Preserve live auto-expansion and running/completed decorations for output-only tools. Existing Local harness and Agent Host PTY terminal behavior remain on the original path unless isPty === false.
  • Scope output-channel URIs by Agent Host session and tool call, and reconstruct completed history from the terminal's structured result.
  • Re-vendor the generated protocol snapshot after Add isPty and fold TerminalComplete into ToolResultTerminalContent agent-host-protocol#352 lands and use its final commit for .ahp-version.

Inspirations from:

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5083fb1f-34d7-44bf-82a1-c4582e57683b
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5083fb1f-34d7-44bf-82a1-c4582e57683b
…t over the terminal channel

- Re-vendor agent-host-protocol: terminalComplete removed, exitCode/preview/truncated fold into terminal.result (TerminalCommandResult), isPty added to ToolResultTerminalContent and TerminalState
- shell_exit now lands on the tool call's terminal block; history replay synthesizes a non-pty block keyed by toolCallId
- Stream tool.execution_partial_result into an output-only agenthost-terminal channel (isPty false) instead of replacing Text content
- Normalize LF to CRLF in AgentHostPty when the channel is plain text
- Re-apply local CompletionItem.label extension clobbered by the protocol sync (still needs upstreaming)
The runtime emits cumulative plain-text snapshots (ANSI-stripped, throttled)
that are capped to the leading ~10KB with a growing truncation marker, so a
length-based delta goes stale once output exceeds the cap. Track the last
emitted snapshot and prefix-check it: extend in place while the snapshot
grows, reset the channel and rewrite when it was rewritten.
Pty-backed channels already carry CRLF because the pty converts output line
endings; do the same for output-only channels at the point data enters the
channel, so terminal frontends render both identically and AgentHostPty
needs no isPty-specific handling. Reverts the client-side normalization.
Copilot AI review requested due to automatic review settings July 22, 2026 23:25
@anthonykim1 anthonykim1 self-assigned this Jul 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Streams Copilot built-in shell output through AHP output-only terminal channels while adopting the updated terminal protocol and SDK.

Changes:

  • Adds non-PTY terminal streaming, replay, reset, and completion handling.
  • Moves shell results onto terminal content blocks and updates rendering/tests.
  • Updates the Copilot SDK and excludes unused Koffi native packages.
Show a summary per file
File Description
src/vs/workbench/contrib/terminal/browser/agentHostTerminalService.ts Configures xterm for plain-text channels.
src/vs/workbench/contrib/terminal/browser/agentHostPty.ts Tracks non-PTY channel state.
src/vs/workbench/contrib/chat/test/browser/agentSessions/stateToProgressAdapter.test.ts Updates terminal-result restoration tests.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/stateToProgressAdapter.ts Reads completion data from terminal blocks.
src/vs/platform/agentHost/test/node/testAgentHostTerminalManager.ts Extends the terminal manager test double.
src/vs/platform/agentHost/test/node/mapSessionEvents.test.ts Tests shell-result folding and replay.
src/vs/platform/agentHost/test/node/copilotShellTools.test.ts Updates the terminal manager stub.
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts Tests runtime output streaming and resets.
src/vs/platform/agentHost/test/node/copilotAgent.test.ts Updates the terminal manager stub.
src/vs/platform/agentHost/test/node/agentHostTerminalManager.test.ts Tests output-only terminal channels.
src/vs/platform/agentHost/node/copilot/mapSessionEvents.ts Maps SDK shell exits to terminal results.
src/vs/platform/agentHost/node/copilot/copilotSystemNotification.ts Adapts to updated SDK types.
src/vs/platform/agentHost/node/copilot/copilotNonPtyShellTerminals.ts Implements cumulative output streaming.
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts Connects partial shell results to channels.
src/vs/platform/agentHost/node/agentHostTerminalManager.ts Manages output-only terminal resources.
src/vs/platform/agentHost/common/state/sessionState.ts Re-exports the new result type.
src/vs/platform/agentHost/common/state/protocol/channels-terminal/state.ts Adds terminal PTY metadata.
src/vs/platform/agentHost/common/state/protocol/channels-session/commands.ts Re-vendors session protocol documentation.
src/vs/platform/agentHost/common/state/protocol/channels-chat/state.ts Folds completion data into terminal content.
src/vs/platform/agentHost/common/state/protocol/.ahp-version Updates the protocol source pin.
remote/package.json Updates the remote SDK dependency policy.
remote/package-lock.json Locks remote SDK and Koffi dependencies.
package.json Updates the root SDK dependency policy.
package-lock.json Locks root SDK and Koffi dependencies.
build/.moduleignore Excludes unused Koffi native packages.

Review details

  • Files reviewed: 19/19 changed files
  • Comments generated: 3
  • Review effort level: Medium

Comment thread src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts Outdated
Comment thread src/vs/platform/agentHost/common/state/protocol/.ahp-version Outdated
@anthonykim1 anthonykim1 added this to the 1.131.0 milestone Jul 23, 2026
@anthonykim1
anthonykim1 marked this pull request as ready for review July 23, 2026 07:23
*/
insertText: string;

/**

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@DonJayamanne Copilot is telling me #326807 hand-wrote this file and its now getting replaced with the new .ahp-version bc they dont seem to be in upstream ahp.

Dont think there would be regression since label was on attachment.label though. Please can you double check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Files impacted (generated by copilot)

• The completion cleanup affects four files:

  - src/vs/platform/agentHost/common/state/protocol/channels-session/commands.ts:284 —
    regenerated; removes handwritten CompletionItem.label.

  - src/vs/platform/agentHost/node/copilot/copilotSlashCommandCompletionProvider.ts:200 — puts
    and sorts the display label using attachment.label.

  - src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/
    agentHostSessionHandler.ts:888 — maps attachment.label into the workbench completion item.

  - src/vs/workbench/contrib/chat/test/browser/agentSessions/
    agentHostChatContribution.test.ts:9658 — verifies a visible label is preserved when
    insertText is empty

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, thats weird, I see, the model must have made this change :(
I'll take a look

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Feel free to merge your PR, i'll have a look at this once its merged.
There's no point blocking your PR

@anthonykim1
anthonykim1 enabled auto-merge (squash) July 23, 2026 07:44
@anthonykim1
anthonykim1 disabled auto-merge July 23, 2026 07:46
@anthonykim1
anthonykim1 merged commit 5d10c1e into main Jul 23, 2026
29 checks passed
@anthonykim1
anthonykim1 deleted the anthonykim1/shellOutputStreaming branch July 23, 2026 14:38
@anthonykim1

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Allow streaming of command output

4 participants