6.3 KiB
Task 01 — The live reasoning container
Phase: 161_reasoning_bubble · Source: TODO.md:3 — "The reasoning process should be one collapsible section that **stays open** during the reasoning process and shows all thinking and tool calls in order. Right now the thinking, tool calling, thinking, tool calling blocks take up a ton of space and obscure the answer. We need to condense this while still letting the user watch the thinking process happen so the latency doesn't feel super low. This new thinking/tool calling bubble should only collapse once the final response has been returned and the session has stopped."
Story: n/a
Objective
One details.reasoning container per brain message wraps the phase-158
per-run timeline live: created on the turn's first thinking/tool frame,
open until the turn settles (done / stop / failed-finalize), condensed
in a bounded 320px live window with pinned-tail follow, the summary
carrying the D6 status literals; the per-run blocks are re-anchored into
the container (their structure and open/fold behavior are unchanged).
Work
frontend/assets/app.js—createReasoningWrap()(besidecreateThinkingBlock~L1068): createElement only (innerHTML ABSENT) —details(classreasoning) +summary(classreasoning-summary,textContent = "Reasoning", the ONLY new static literal — D6) +span(classreasoning-status, empty until a frame sets it) +div(classreasoning-body); return thedetailselement. The docstring cites this phase + D1/D6.frontend/assets/app.js— module scopereasoningWrapEl = null(besidesegRuns/currentRun~L1464–1465) +ensureReasoningWrap (wrap)(get-or-create: on the turn's first thinking/tool frame —createReasoningWrap(),open = true(D1), insertedbeforewrap.querySelector(".msg-body").querySelector(".bubble"), stored inreasoningWrapEl); reset inrunTurnalongsidesegRuns = [](~L3304 — the pagehide partial reads the live container, so the module scope is readable there likesegRuns).frontend/assets/app.js— re-anchor the per-run inserts: inensureThinkingRun(~L1103) andensureToolRun(~L1122), thebody.insertBefore(block, body.querySelector(".bubble"))line becomesensureReasoningWrap(wrap).querySelector(".reasoning-body") .appendChild(block)(thewrapparam — both functions already receive it). EVERYTHING ELSE in both functions is UNCHANGED (thecloseCurrentRun()call, theopen = true, thesegRuns.push,currentRun). The container is created by the FIRST run'sensureReasoningWrapcall — no other call site.frontend/assets/app.js—settleReasoning(wrap)(besidecloseAllRuns~L1149):wrap?.querySelector("details.reasoning")?.removeAttribute("open")(idempotent; a no-op without a container — the plain-answer turn settles byte-identically). Called alongsidecloseAllRuns(wrap)at the THREE settle sites: thedonebranch (~L3570), the STOP path (~L3752),finalizeFailedTurn(~L3218). Thedeltabranch (~L3553) is UNCHANGED —closeCurrentRun()folds the active run; the container STAYS OPEN (D2 — the TODO's core contract).frontend/assets/app.js— the D6 status: in the thinking frame branch (~L3381, afterensureThinkingRun), setreasoningWrapEl?.querySelector(".reasoning-status")?.textContent = "Thinking…"; in the tool frame branch (~L3501, afterensureToolRun), set"Calling " + name + "…"(thenametheappendToolLinecall already receives — the phase-70 legacy-name mapping already produced it); at the three settle sites (alongsidesettleReasoning), set"${segRuns.length} steps"(the liveN— D6; the settle sites readsegRuns— module scope).frontend/assets/app.js— the D3 live follow: theREASONING_NEAR_BOTTOM_PX = 32constant (beside the phase-17THINKING_NEAR_BOTTOM_PX) + the follow helpers —isReasoningPinned(el)(the pre-update capture — the phase-17 pre-measure convention:el.scrollTop + el.clientHeight >= el.scrollHeight - REASONING_NEAR_BOTTOM_PX) andscrollReasoningToBottom(el)(the post-append apply:el.scrollTop = el.scrollHeight). Called from BOTH the thinking frame branch (pre: after the existingisThinkingNearBottomcapture; post: after the block re-render) and the tool frame branch (pre: beforeappendToolLine; post: after it) —el=reasoningWrapEl?.querySelector(".reasoning-body")(a no-op when absent — the plain-answer turn never creates one). The EXISTING per-blockisThinkingNearBottom(textEl)follow is UNCHANGED (harmless — task 03 makes the inner.thinking-textnon-scrollable inside the container, so it no-ops there). The phase-87armToolLineClock/settleToolLinewrap-scoped queries are DESCENDANT-scoped — UNCHANGED (they match the nested runs).tests/unit/test_reasoning_bubble.py(new) — the source-level pins:createReasoningWrap's createElement shape (thereasoning/reasoning-summary/reasoning-status/reasoning-bodyclasses, theReasoningliteral, innerHTML ABSENT),ensureReasoningWrap's get-or-create +open = true+ the reset inrunTurn, the per-run inserts append into.reasoning-body(theinsertBefore(…bubble)per-run anchor is GONE fromensureThinkingRun/ensureToolRun),settleReasoningdefined + called at the THREE settle sites and NOT at thedeltabranch, the status literals (Thinking…/Calling/steps), theREASONING_NEAR_BOTTOM_PX = 32constant + the pre/post split, and the pagehide partial's readability (the module scope reset pattern).
Testing & Quality
- Unit:
tests/unit/test_reasoning_bubble.py(above) — all pins green. - Coverage: >90% on this task's new/modified code (frontend — the
app/gate is untouched; held by the suite).
Completion Criteria
tests/unit/test_reasoning_bubble.pygreen (uv run pytest tests/unit/test_reasoning_bubble.py -v --no-cov)- the full test suite green (
uv run pytest) - no behavior change in completed work beyond the documented anchor supersession (the per-run blocks' structure + open/fold behavior is byte-identical; only their parent changed)