Second thought
The program computes the next phase from the book’s evidence, and Jev, TypeSafe’s typed-decision model, only judges whether that reading is right. Its advice is short and arrives only when it changes what the agent does next.
What it runs on, and what Jev sees and judges
Inside an open loop, pi/second-thought.ts asks Jev through pi’s classifier registry to check the phase machine.
It asks when a run settles and the loop book gained an evidence entry since the last judgment, and at a close declaration.
Without a TypeSafe key it does nothing, and outside a loop it never runs.
In a subagent session (PI_SUBAGENT_ID from pi-herdr-agents, or PI_SUBAGENT_CHILD from pi-subagents) it registers nothing, since the agent that spawned it judges the result.
Jev sees the kind, intent, anchor, diff summary (≤1200 chars), phase (current, next, missing), verify state, the open todos by id and subject, the task list, and friction (a child’s under its name).
It judges only whether to advance, go back, or ask-user, plus done, the review tier still needed, and quality.
Phase completion comes from the program’s evidence alone.
A new judgment is triggered only by evidence entries or by a new open todo without a followup. A child’s result counts as evidence; task, link, base, and watch records do not.
The advisory: when it speaks, when it continues the run, and when it repeats nothing
The advisory is next: <phase> (<missing>) plus Jev’s concerns, with no scores.
It is sent only when Jev has a concern, todos are open without a followup, or the run continues.
It stays silent when Jev agrees with nothing to add, and the verdict is still recorded in the session.
At close it carries concerns only.
Away from close it also names the loop’s open todos that have no valid metadata.followup: the first three, subjects cut to 60 characters, then +N more.
It asks the agent to continue each, complete it, or set that followup.
The run continues once, when Jev agrees to advance and the next phase is a verify, review, or fix, or when such todos are open and Jev’s move is not ask-user.
In that last case the advisory tells the agent to ask the user instead.
An advisory with the same Jev move, next phase, assessment findings, and open todo ids as the last one is not repeated.
Jev’s move is part of that key, so a turn to back or ask-user on new evidence is advised even when the rest repeats.
A full rating after a clean review that follows the last change is not a concern.
When it stays quiet: waiting runs, children, and units
A run that called MonitorCreate, LoopCreate, or goal_wait, or a subagent tool whose child the book has not linked yet, is waiting and is not judged.
While a child the loop started has no result and its host does not report it gone, the loop is neither judged nor continued.
A child that finished exits before its result is delivered, so a gone child whose session file was written within the last 30 seconds still counts as out. A dispatch with accept waits while the host reruns its check, so its grace grows by the check’s timeoutSec (600 seconds by default).
With two or more units the quiet is per unit.
The notice judges, speaks, and continues for the first unit that waits on the coordinator: started, not done, nothing of its own out, and its step not asked since that unit’s last evidence.
It names every other such unit on its own next: line, and asks a unit again only when its step or evidence changes.
What the notice judged and said is kept in the book (notice entries), so a /reload or a session that adopts the book does not repeat it.