Plan: coming back to the session - a turn recap, acting on a queued step where it appears, and a working line that says what is happening

Closes: #352 (turn recap), #353 (act on a queued step from the transcript), #354 (the working line). Branches: feat/turn-recap, feat/act-on-queued, feat/working-line, one MR each. Status: Done (2026-10-07) — all three units shipped

Erratum (2026-10-07): a test run is any && / || / ; segment of the first line that starts with a runner (after npx, pnpm exec or environment assignments), not only the first word: commands here usually begin cd <dir> &&.

Erratum (2026-10-07): every verdict that reports a queued step still waiting carries its id, not only `queueForHuman’s: the four in `authorize.ts’s reply path (no reply yet, no judge, a failed judge, a judge that needs more) too, found by the contract test.

Erratum (2026-10-07): the trace line’s hint reads · queued as /pending #<id>, not waiting on you: a saved line cannot see the step settle, so the hint states what stays true.

TL;DR

What you see today when you come back after an autonomous run, and what each unit changes:

Moment today after

The turn ended while you were away

A long transcript; you scroll to find what changed and what was refused.

One card at the end of the turn: recap · 4 files · 11 commands · tests passed · 1 queued · commit 3f241e5 · 6 m 12 s · $0.84, expandable to the lists. Only when the turn did enough to need one.

A step is waiting on you

Its line sits in the trace lane; you type /pending, find it, act.

Its line reads … · waiting on you, /pending #7; in fullscreen a click opens the overlay on that step. alt+a / alt+d approve or deny the newest waiting step from anywhere, and the notice names what they did.

A turn is running

pi’s working text ("Thinking…" and the like).

running pnpm test · 42 s · 2 helpers · +$0.12, updated as tools start and end; back to pi’s own text when the turn ends.

Every unit uses hooks pi already gives an extension (evidence below): tool_result, tool_execution_start/end, agent_start/end, appendEntry + registerEntryRenderer (an entry the model never sees), MouseRegion in the transcript (pi’s own thinking toggle is one), registerShortcut, setWorkingMessage.

Design

Unit one: the turn recap

Where. packages/pi-modes/recap.ts (new): a TurnLedger fed during a turn and a renderer for the card; wired in session-wiring.ts beside the title hooks, and in judge-wiring.ts:992 where traces are appended (the appendTrace there also feeds the ledger).

What the ledger records, from agent_start to agent_end. - Files: the path of every edit and write tool result that is not an error, de-duplicated, relative to the cwd. - Commands: every shell tool result (RecentCommands already names the shell tools, recent-commands.ts:40), with its first line. A command whose first word is a test runner (vitest, pytest, go test, pnpm test, npm test, cargo test, node --test; a constant list) is a test run, passed or failed by isError. Commits and MRs: a shell result whose output has [<branch> <sha>] (git’s commit line) or land: !<n> (our land step) - both regexes, not parsing. - Refusals and queued steps: every non-allow trace record appended in the turn, counted by decision (deny, defer), and the queued ones (source: "pending") by number. - Helpers: the helperFinished reports ({agent, tokens, usd, exact}) that the subagent wiring sends to the mode controller (mode-controller.ts:57; index.ts:104 passes modes.helperFinished as the wiring’s helperFinished). index.ts passes a function that calls both the controller’s and the ledger’s, so neither changes. - Time: agent_end minus agent_start. Cost: sessionSpendUsd over the session’s entries at end minus at start (spend-cap.ts:44, the figure the spend cap reads), shown as +$x.xx.

When a card is written. At agent_end, if the turn ran at least RECAP_MIN_TOOL_CALLS = 3 tool calls or lasted at least RECAP_MIN_MS = 20 s. A short exchange gets no card; an autonomous run does. pi.appendEntry(RECAP_ENTRY, record) - a custom entry, which pi keeps out of the model’s context (docs, "Durable data excluded from model context"), so the recap costs no tokens and cannot steer the agent.

How it reads. Collapsed, one line in the trace lane’s style: recap · 4 files · 11 commands · tests passed · 1 denied · 1 queued · commit 3f241e5 · MR !280 · 6 m 12 s · +$0.84, each part present only when non-zero. Expanded (pi’s ctrl+o), the lists: the files, the commands (first lines, in order), the test runs with pass/fail, the refusals' reasons, the helpers. Rendered by registerEntryRenderer(RECAP_ENTRY, …) beside the trace renderers (trace-renderers.ts:49).

Config. recap?: boolean, default true, validated with check.boolean.

Unit two: act on a queued step where it appears

The id travels with the trace. queueForHuman (judge-wiring.ts:644) knows the queue entry; the verdict it returns gains pendingId: entry.id (an optional field on the attributed verdict type it already returns), and traceVerdict (judge-wiring.ts:897) carries it into TraceRecord (trace.ts:44) as pendingId?: number. Nothing else about the record changes; existing records have no id and render as today.

The line. renderTrace (trace-renderers.ts:38), for a record with a pendingId, appends · waiting on you, /pending #<id> to the collapsed head and returns the Text wrapped in pi-tui’s MouseRegion: a left click calls act(pendingId). registerTraceRenderers gains that act callback (optional; a host that registers without one gets plain text).

What a click does. act(id) opens the pending overlay from #341 (pending-pane.ts, showPendingPane) with that step preselected - showPendingPane gains an optional selectedId. From there the person chooses, and the pick goes through pendingCommand exactly as before. If the step has settled since, the overlay shows what still waits, or pendingCommand’s "Nothing is waiting on you." The click never acts by itself: it opens the same deliberate pane. In regular mode the click does nothing (pi routes the mouse only in fullscreen); the text still names the `/pending #<id> to type.

The shortcuts. pi.registerShortcut("alt+a", …) and "alt+d": approve or deny the NEWEST waiting step, through pendingCommand(deps, tell, "approve #<id>", ctx) with the registering context. Nothing waiting: the "Nothing is waiting on you." notice. The acted step is named in the notice pendingCommand already shows ("Approved: bash: …"), so a blind press is told what it did. Config: shortcuts?: { approvePending?: string | null; denyPending?: string | null }, defaults "alt+a" / "alt+d", null to unbind (a terminal may own a key); validated as strings.

What does not change. A rule deny stays final: it has no pendingId and no click. The queue, its ids, the audit record: untouched.

Unit three: the working line

Where. packages/pi-modes/working-line.ts (new), wired in session-wiring.ts beside the title hooks: it needs the same agent_start / agent_end and ctx.

What it shows. While a turn runs, ctx.ui.setWorkingMessage(text) with text = <activity> · <elapsed> · <helpers> · +$<spend>: - activity: on tool_execution_start, running <first line of the command> for a shell tool (cut to 48 cells, control characters dropped), reading <basename> / editing <basename> / writing <basename> for the file tools, <toolName> otherwise; on tool_execution_end, thinking. Nested calls (parentToolCallId set) do not replace the parent’s line. - elapsed: since agent_start, 42 s then 6 m 12 s, refreshed by a one-second timer that runs only during a turn (unref’d; cleared on `agent_end and shutdown). - helpers: stats.runningAgents.length when non-zero (status.ts:33). - spend: the turn’s delta of sessionSpendUsd, as the recap computes it, refreshed on each tool end (an entry read per tool, not per second).

On agent_end, setWorkingMessage() with no argument restores pi’s own text. Only with a UI (ctx.hasUI); a headless host writes nothing.

Config. workingLine?: boolean, default true.

Failure modes, named

A tool result whose shape the ledger does not know: fail-open

It counts as a tool call and nothing else; the card still appears. No throw reaches pi’s event loop: the ledger’s record catches and debug-logs.

The recap misreads a command as a test run or a commit: fail-open

The regexes are over the command’s first word and git’s own output line; a false reading mislabels one part of a card for you, and reaches no model and no decision.

A click on a settled step: silent

The overlay opens on what still waits, or the "Nothing is waiting" notice; nothing is approved by the click itself.

alt+a pressed blind: fail-open

It approves the newest waiting step, exactly as /pending approve #<id> of that step would, and the notice names the step; it is the human’s own key, as the typed command is. A terminal that owns the key never delivers it; shortcuts.approvePending: null unbinds it.

The working line’s timer when a turn never ends (a crash mid-turn): fail-closed

session_shutdown clears it, and it is `unref’d, so it can neither keep writing nor hold the process.

setWorkingMessage while pi itself changes the text: fail-open

The last writer wins: pi sets its own text at turn start, ours follows on the first tool event, and agent_end restores pi’s (a test pins that). A stale line is the worst case, never a missing one.

Decisions for the operator

  1. The recap is a transcript entry, not a notice. A notice is gone when you look up; the entry stays where the turn ended, folds like a trace line, and is never in the model’s context.

  2. A click opens the overlay; it does not approve. One accidental click in a scrolling transcript must not approve a step. The overlay is the same deliberate pane as #341; the shortcuts are the fast path, and they are keys you press on purpose.

  3. The shortcuts act on the newest step. The newest is the one the session is waiting on now; /pending and the overlay remain for choosing among several.

  4. The working line shows the turn’s spend, not the session’s. pi’s footer already shows the session total.

Scope

Units

  1. recap.ts + tests: the ledger over a scripted sequence of events (files de-duplicated and relative; test runner detection per runner, pass and fail; the commit and MR regexes on real git commit and land output; counts of deny/defer/queued; helpers; time; cost delta); the threshold (2 tool calls and 19 s: no card; 3 calls: a card; 20 s: a card); the collapsed line’s parts present only when non-zero; the expanded lists; a regression test that a malformed tool result is counted and does not throw. Wiring: a test through the real hooks, as the title’s hooks test does, that an appendEntry(RECAP_ENTRY) follows agent_end with the expected record.

  2. Act on a queued step + tests: pendingId from queueForHuman to the TraceRecord (a contract test over adjudicateAsk’s trace output on a queueing mode); `renderTrace returns a MouseRegion only with an id, a click calls act with it, a right click and a press do not; the overlay preselects the id and falls back to the first row when it is gone; the shortcuts through pendingCommand on the newest id, the empty-queue notice, null unbinding; config validation.

  3. working-line.ts + tests: the text for each tool kind and for nested calls; the elapsed format at 42 s and 6 m 12 s; helpers shown only when non-zero; the timer starts on agent_start, ticks, and is cleared on agent_end and on shutdown (fake timers); agent_end calls setWorkingMessage() with no argument; headless writes nothing.

  4. Docs and notes: on the modes page, a section for the recap and one for the working line, and the queued-line click and the shortcuts where /pending is described; on the tuning page, the recap, workingLine and shortcuts knobs; CHANGELOG Unreleased (all Added; one pi-modes minor). The plan page under the docs' plans directory with a nav entry.

  5. Live check, by the operator: an autonomous run of a few minutes ends in a card with the right counts; ctrl+o on it shows the lists; a queued step’s line opens the overlay on it; alt+a approves the newest and the notice names it; the working line follows a test run.

  6. Close: each MR carries its Closes.

Out of scope

  • Harness-aware autocomplete, OSC 8 links, the context gauge, the plan diff: already filed (#346-#349) or for the brainstorm.

  • Any change to what is queued, refused or sent to the model.

Acceptance

  • A turn with 3 tool calls (one edit, one vitest run that fails, one git commit) ends with one recap entry whose record names the file, the failed test run and the commit sha, and whose collapsed line has no queued part; a turn with 2 calls in 10 s ends with no entry; the entry never appears in the messages the model receives.

  • A queued step’s trace record carries its queue id; its rendered line names /pending #<id> and a left click on it opens the overlay with that step selected; alt+a with two steps waiting approves the newer one and the notice names it; with none, the empty-queue notice.

  • During a turn the working message reads running pnpm test · 42 s (helpers and spend when non-zero); after agent_end pi’s own text is back.

  • node tools/task.mjs validate green; consumer-sim loads.

Evidence outside the repository

Read on 2026-10-07 from the installed pi; implementation re-reads each.

pi-coding-agent/dist/core/extensions/types.d.ts: :961-977 ToolResultEvent (toolCallId, parentToolCallId?, input, content, isError); :829-836 ToolExecutionStartEvent (toolName, args, parentToolCallId?); :848-856 ToolExecutionEndEvent (isError, durationMs?); :724-727 AgentEndEvent; :86 setWorkingMessage (message?: string); :1209-1212 registerShortcut(shortcut: KeyId, {handler}); :1248 appendEntry(customType, data); :1230 registerEntryRenderer. pi-tui/dist/keys.d.ts:42 KeyId = BaseKey | ModifiedKeyId<BaseKey> (so "alt+a").

docs/extensions.md:229: pi.appendEntry() is "Durable data excluded from model context".

pi-tui/dist/index.d.ts:12 exports MouseRegion(child, onMouse); pi’s own transcript uses it for the thinking toggle (dist/modes/interactive/components/assistant-message.js:120), so a component in the transcript receives mouse events in fullscreen.

Edit this page · latest