feat(todotools): todo runs loop-side on a split session, with declared halves and a loop mirror (S39)
Merged
CO
21d ago+286+286+012345678901234567890123456789-54-54-01234567890123456789
Summary
Part of #5644. On a split session todo is a loop-side tool; this declares it and its halves (#5474) and lets the loop take a todo list built outside its process.
builtin/todotools/tools/todo.ts: thetodotool is declaredruns: "brain".builtin/todotools/index.ts: every handler that reads or drives the session (session_start,session_tree,message_end,before_agent_start,before_provider_request,agent_end,session_abort,session_shutdown) isruns: "brain", so a hand's generation registers none of them.message_endadopts atodoresult of a call this instance did not execute (one produced outside this process) as the session's list and re-renders the widget. The tool records each call it runs (noteExecuted), so a result of the session's own call, which arrives only after the whole batch, is never adopted; results of other tools (a legacytodowritename included) are ignored.builtin/todotools/todo-storage.ts:getTodoStateFromToolResult()(the parsergetLatestTodoStateFromBranchEntriesalready used for tool results, now shared), exported fromstate.ts.
Fused sessions are unchanged: all handlers register as before, and the widget renders the same number of times for the session's own todo call (pinned).
Not closed here: a split session that already holds a list needs the todo call itself to run loop-side, which is #5641's per-call routing; that case is an explicit obligation there.
Tests
RED first at main: 3 of the 4 new cases failed (runs undefined; the hand generation registered all 8 handlers; the loop half ignored a foreign result), the widget pin passed. Then:
test/runtime/todo-state.test.ts: 4 passed.test/suite/todo*,test/compaction/todo*,test/suite/goal-todo*, the 2419 regression,test/extensions/runs-placement: 20 files, 311 passed.- Mutation: dropping the equality guard re-renders the widget on the session's own result and fails the pin.
Change fragment: changes/unreleased/5646.md (changelog gate PASS).
Review fold (FIX_FIRST at a2ea4dc21b)
- MEDIUM (a batch of fused todo calls flashed an older list: 5 renders instead of 3): fixed at the class, the mirror skips every result of a call this instance executed. RED first:
a fused session's batch of todo calls renders each list once and ends on the newest, as todayfailed with 5 renders; GREEN 3. - LOW (a
todowriteresult would replace the list): folded, the mirror reads onlytodoresults. RED first:the loop half ignores a result of another tool that carries a todo list.