Skip to content

Add live-streaming tool boxes with per-call state#4

Merged
s2x merged 1 commit into
mainfrom
feat/streamed-tool-boxes
May 21, 2026
Merged

Add live-streaming tool boxes with per-call state#4
s2x merged 1 commit into
mainfrom
feat/streamed-tool-boxes

Conversation

@s2x
Copy link
Copy Markdown
Contributor

@s2x s2x commented May 21, 2026

Summary

  • Tool execution renders as a Unicode box: ┌─ ⚡ bash ─ <cmd> on start, │ <line> per streamed line, └─ ✓/✗ bash (1.2s, N lines) on end
  • Live line-by-line streaming via tool_execution_update snapshots (delta-decoded, line-buffered)
  • Parallel tool calls handled correctly: per-toolCallId state map + FIFO queue — one box streams live, others flush in order when their predecessor closes
  • Full output, no truncation; toolcall_end rendering dropped (execution box covers it)

Test Plan

  • go test -race ./... — 41/41 pass, race-free
  • golangci-lint run — clean
  • E2E: pi-stream -t bash "run two bash commands: echo hello then echo world" — two clean sequential boxes
  • E2E: pi-stream -t bash "seq 1 5 with 0.3s sleep" — lines appear progressively inside box

Tool execution is now rendered as a Unicode box that opens on
tool_execution_start and streams stdout line-by-line as pi emits
tool_execution_update snapshots. The box closes on end with a
green ✓ / red ✗ status, elapsed time, and line count.

Parallel tool calls (model issues multiple bash calls in one turn)
are handled via a per-toolCallId state map and a FIFO queue: only
one box streams live at a time; others accumulate output silently
and flush in order when their predecessor closes.

- event: add ToolCallID field (toolCallId from pi's RPC events)
- render: replace single-box state with tools map + activeID/queue
  - ToolExecStart(id, name, args) opens or queues a box
  - ToolExecUpdate(id, snapshot) delta-streams complete lines
  - ToolExecEnd(id, isErr, fullText) closes box, promotes next
  - full output — no truncation
- cli: wire tool_execution_update; drop toolcall_end render
  (execution box makes it redundant)
- ansi: swap BoldBlue/BoldYellow for BoldCyan/DimCyan/BoldGreen/BoldRed
@s2x s2x merged commit ed2bc3d into main May 21, 2026
8 checks passed
@s2x s2x deleted the feat/streamed-tool-boxes branch May 21, 2026 07:42
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.

1 participant