Skip to content

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

Closed
anthonykim1 wants to merge 18 commits into
microsoft:mainfrom
anthonykim1:anthonykim1/streamBuiltInShellTool2
Closed

Stream built-in shell output over AHP terminal channel#327090
anthonykim1 wants to merge 18 commits into
microsoft:mainfrom
anthonykim1:anthonykim1/streamBuiltInShellTool2

Conversation

@anthonykim1

@anthonykim1 anthonykim1 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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

Adopts the terminal completion model from microsoft/agent-host-protocol#352 and supersedes the cumulative-Text approach from #326291.

  • Re-vendor the pending AHP contract: remove terminalComplete, move exitCode/preview/truncated onto the terminal block as result, and add isPty to terminal tool results and terminal state.
  • Stream public Copilot SDK tool.execution_partial_result events into output-only AHP terminal channels for runtime-executed shell tools, while leaving client-hosted PTY terminals on their existing path.
  • Treat partial output as cumulative runtime snapshots: append only the unseen suffix while the snapshot grows, then clear and replay it when truncation rewrites the snapshot.
  • Create the output channel before publishing its terminal block, including commands with no partial events; seed final preview data, persist the exit result, and keep background channels open until shell_completed supplies the real exit code.
  • Attach non-PTY channels to chat through a read-only output source without creating an ITerminalInstance, adding a root terminal entry, opening a bottom-panel terminal, or exposing terminal Focus/Show actions.
  • Render plain-text output in the existing detached xterm, normalize LF to CRLF only in the Agent Host output adapter, and serialize append/reset writes so streaming output is neither duplicated nor stale.
  • Preserve live auto-expansion and running/completed command decorations for output-only tools while leaving the existing PTY decoration path unchanged.
  • Reconstruct history with a stable non-PTY terminal URI and structured result, while retaining a structural fallback for old persisted terminalComplete blocks.
  • Re-apply the local CompletionItem.label extension from Config-action slash commands for Copilot agent-host chat inputs #326807 after protocol generation. The generated snapshot still needs a final .ahp-version sync after Add isPty and fold TerminalComplete into ToolResultTerminalContent agent-host-protocol#352 lands.

Inspirations from:

anthonykim1 and others added 18 commits July 16, 2026 23:04
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 23, 2026 06:25

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 cumulative shell output from Copilot SDK bash and powershell calls into running Agent Host tool invocations.

Changes:

  • Emits content-change actions for tracked shell partial results.
  • Preserves non-text tool content and ignores irrelevant events.
  • Adds focused unit coverage.
Show a summary per file
File Description
copilotAgentSession.ts Forwards tracked shell output snapshots.
copilotAgentSession.test.ts Tests cumulative, untracked, and non-shell events.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Medium

@anthonykim1 anthonykim1 changed the title Stream output for SDK built-in shell tool in agent host Copilot Stream built-in shell output over AHP terminal channel Jul 23, 2026
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.

Allow streaming of command output

2 participants