forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Problem
When tools run in parallel, the completion line (✓) appears as a NEW line instead of overwriting the start line (◇). This creates noisy output:
◇ bash remory search "architecture"
◇ bash remory search "workflow"
◇ bash remory search "testing"
✓ bash ← should overwrite line 1, appears as new line
✓ bash ← should overwrite line 2, appears as new line
✓ bash ← only this overwrites line 3 (immediately previous)
Root Cause
The code uses a single lastChunkWasToolStart boolean flag. With parallel tools, each new tool_start overwrites this flag, losing the association between tool_end and its original start line.
The \x1b[1A escape sequence only moves up 1 line — but with parallel tools, the correct start line may be N lines back.
Fix: Map-Based Line Tracking
Replace the single flag with a Map that tracks each tools output position:
- Maintain a
lineCountvariable incremented on every\nwritten - On
tool_start: storetoolLineMap.set(toolKey, lineCount) - On
tool_end: calculatelinesBack = lineCount - toolLineMap.get(toolKey) - Use
\x1b[${linesBack}A\r\x1b[2Kto move up the correct number of lines - After overwriting, use
\x1b[${linesBack}Bto move back down
The tool key should be the part ID or a combination of tool name + arguments that uniquely identifies the tool invocation.
Edge Cases
- Tool summary longer than terminal width (line wraps) — truncate to prevent
- Tool_end arrives after other text output (not just more tool_starts) — need to track ALL output lines, not just tool lines
- Tool key collisions — use unique part IDs from the streaming chunks
Acceptance Criteria
- Parallel tool completions overwrite their start lines
- Sequential tool completions still work
- No visual corruption when tools have different line counts between start/end
- Tool lines truncated to terminal width (prevent wrapping)
-
bun run typecheckpasses -
bun testpasses
Metadata
Metadata
Assignees
Labels
No labels