Skip to content

[UX] oclite: Tool completion should overwrite start line — fix for parallel tools #81

@randomm

Description

@randomm

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:

  1. Maintain a lineCount variable incremented on every \n written
  2. On tool_start: store toolLineMap.set(toolKey, lineCount)
  3. On tool_end: calculate linesBack = lineCount - toolLineMap.get(toolKey)
  4. Use \x1b[${linesBack}A\r\x1b[2K to move up the correct number of lines
  5. After overwriting, use \x1b[${linesBack}B to 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 typecheck passes
  • bun test passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions