fix(tui): stabilize live todo panel count and anchor position

Two bugs surfaced together while the model fired the todo tool:

1. Count flickered (e.g. 3 → 1 → 3) because tool.start echoed
   args.todos as the live state. With merge=true (or any partial
   replacement) args.todos is just the items being updated, not the
   full list. Drop the early echo — tool.complete already carries the
   canonical full list from the tool result.

2. After turn end the panel jumped from under the user prompt to below
   thinking/tools because archiveDoneTodos() was pushed AFTER segments
   in finalMessages. Prepend the archive trail msg so it sits right
   after the user prompt — same visual slot the live panel occupied
   during streaming.
This commit is contained in:
Brooklyn Nicholson 2026-04-26 21:45:18 -05:00
parent b51c528613
commit c2ca02fcff
3 changed files with 15 additions and 11 deletions

View file

@ -1040,13 +1040,14 @@ def _on_tool_start(sid: str, tool_call_id: str, name: str, args: dict):
pass
session.setdefault("tool_started_at", {})[tool_call_id] = time.time()
if _tool_progress_enabled(sid):
payload = {"tool_id": tool_call_id, "name": name, "context": _tool_ctx(name, args)}
if name == "todo" and isinstance(args, dict) and isinstance(args.get("todos"), list):
payload["todos"] = args.get("todos")
# Don't echo args.todos on tool.start — for merge=true (or partial
# replacement) it's only the items being updated, not the full list,
# and would flicker the live count. tool.complete is the source of
# truth (always returns the full list from the tool result).
_emit(
"tool.start",
sid,
payload,
{"tool_id": tool_call_id, "name": name, "context": _tool_ctx(name, args)},
)