fix: verdict death — plan→teach seam inferred from first nodeId-tagged quiz

The Accept/Decline verdict gate is gone (owner ruling 2026-09-26):
presenting the plan ends the teacher's turn; the learner's next message
is a natural reply. Teaching begins at the first quiz call tagged with a
nodeId (probe quizzes carry none) — both folds (view phaseAt3, native
phaseAt3Lh) advance on the call itself, and the teach divider renders
before that whole assistant block. No backwards compat: verdict markers,
the verdict input event, optimistic appends, composer buttons, and
projection all deleted; prompts and docs rewritten to the natural flow.
This commit is contained in:
amosblomqvist
2026-09-27 00:48:46 +03:00
parent dcb839232c
commit 145b470752
17 changed files with 221 additions and 389 deletions
+57 -37
View File
@@ -1,29 +1,36 @@
/**
* Phase derivation (docs/probe-teach-split.md §4) — EXPLICIT EVENTS, never
* occupancy. The probe→teach agent split (2026-09-11) gave every phase
* boundary a transcript event:
* occupancy. The probe→teach agent split (2026-09-11) gave the first
* boundary a transcript event; the second is INFERRED (owner ruling
* 2026-09-26, the verdict death):
*
* probe — until the prober's `probe_done` call CONCLUDES (a clean
* toolResult for it; the assessment rides the call's arguments)
* plan — probe concluded, until the learner ACCEPTS the presented
* plan (the verdict marker with accepted:true — the explicit
* verdict gate; plan_init itself is only the PRESENTATION and
* moves no phase; a declined verdict stays in plan)
* teach — teaching is sanctioned
* plan — probe concluded, until teaching actually BEGINS
* teach — the first quiz tool call tagged with a `nodeId` (a question
* ABOUT a plan node — probe quizzes carry no nodeId in their
* schema, so nothing false-triggers). The CALL is the seam, not
* its answer: the block that poses the first node question is
* where teaching starts.
*
* There is no verdict gate anymore: presenting the plan ends the teacher's
* turn, and the learner's next message is a natural reply (a change
* request, or the go-ahead). The live indicator LAGS by design (owner
* accepted): "teach" shows only once the first node's question is posed.
* A teacher that never tags a quiz would sit in "plan" visually —
* off-doctrine (tagging is prompt-mandated and nodeId is call-validated).
*
* The former derived-occupancy seam (phase-of-tree via `currentNodeId`)
* is GONE: nothing ever writes currentNodeId (the stuck-on-plan bug — a
* session could never leave "plan"), and the stored tree no longer carries
* progress fields at all. No backwards compatibility: legacy sessions
* without probe_done simply read as probe (they are wiped data).
* is GONE, as is the verdict-marker fold: no backwards compatibility
* (legacy sessions are wiped data).
*
* TWO FOLDS over the same events (Wave D): `phaseAt3`/`phaseTimeline` fold
* VIEW messages (the client's dividers and dock — part shapes, pure and
* structural); `phaseAt3Lh` folds the NATIVE record (server summaries,
* tests) — probe→plan advances at the probe_done RESULT message, plan→teach
* at the verdict marker. Both are strictly sequential; the two derivations
* agree on every settled record (a result/marker message projects into the
* same view boundary).
* at the assistant message carrying the first nodeId-tagged quiz CALL.
* Both are strictly sequential; the two derivations agree on every settled
* record (a call's part projects into the same view boundary).
*
* Pure: no imports, no runtime deps — safe on server, client, and tests.
*/
@@ -33,10 +40,22 @@ export type Phase3 = "probe" | "plan" | "teach";
/**
* Minimal structural slice of a UI message for the phase scan: parts with
* a state and (for concluded calls) an output.
* a state, an input (a tool call's parsed arguments), and (for concluded
* calls) an output.
*/
export interface PhaseMessage {
parts: ReadonlyArray<{ type: string; state?: string; output?: unknown }>;
parts: ReadonlyArray<{ type: string; state?: string; input?: unknown; output?: unknown }>;
}
/** A quiz call's part input carries `nodeId` iff it is tagged (teach-only —
* the probe quiz schema has no nodeId field). */
function taggedNodeId(input: unknown): boolean {
return (
typeof input === "object" &&
input !== null &&
typeof (input as { nodeId?: unknown }).nodeId === "string" &&
(input as { nodeId: string }).nodeId.length > 0
);
}
/** The phase at `upToIndex` (inclusive; default: the last message). */
@@ -52,23 +71,18 @@ export function phaseAt3(messages: readonly PhaseMessage[], upToIndex?: number):
/** One message's advance of the phase (pure fold step). */
function advance(
phase: Phase3,
parts: ReadonlyArray<{ type: string; state?: string; output?: unknown }> | undefined,
parts: ReadonlyArray<{ type: string; state?: string; input?: unknown; output?: unknown }> | undefined,
): Phase3 {
if (!parts) return phase;
for (const part of parts) {
// STRICTLY SEQUENTIAL: probe → plan only via a concluded probe_done,
// plan → teach only via the learner's plan acceptance (data-verdict
// with accepted:true). A marker out of order advances nothing — the
// chain never skips. plan_init PRESENTS the map; only the verdict
// sanctions teaching (a decline stays in plan).
// plan → teach only via the first nodeId-tagged quiz CALL (the call,
// not its answer — an errored-and-retried call still proves teaching
// began, and the retry lands in the same group anyway).
if (phase === "probe" && part.type === "tool-probe_done" && part.state === "output-available") {
phase = "plan";
}
if (
phase === "plan" &&
part.type === "data-verdict" &&
(part as { data?: { accepted?: unknown } }).data?.accepted === true
) {
if (phase === "plan" && part.type === "tool-quiz" && taggedNodeId(part.input)) {
phase = "teach";
}
}
@@ -94,11 +108,12 @@ export function phaseTimeline(messages: readonly PhaseMessage[]): Phase3[] {
// ─── the native fold (Wave D: record-side phase over LhMessage[]) ───────────
import type { LhMessage } from "./native-messages.ts";
import type { ToolResultMessage } from "@earendil-works/pi-ai";
/** The phase at `upToIndex` (inclusive; default: the last message) of a
* NATIVE record. probe→plan advances at the probe_done call's clean
* toolResult; plan→teach at the verdict marker (details.accepted true). */
* toolResult; plan→teach at the assistant message carrying the first
* nodeId-tagged quiz CALL (mirrors the view fold — same seam, native
* shape). */
export function phaseAt3Lh(messages: readonly LhMessage[], upToIndex?: number): Phase3 {
let phase: Phase3 = "probe";
const last = Math.min(upToIndex ?? messages.length - 1, messages.length - 1);
@@ -106,7 +121,7 @@ export function phaseAt3Lh(messages: readonly LhMessage[], upToIndex?: number):
const m = messages[i]!;
const role = (m as { role?: string }).role;
if (role === "toolResult") {
const result = m as ToolResultMessage;
const result = m as { toolName?: string; isError?: boolean };
if (
phase === "probe" &&
result.toolName === "probe_done" &&
@@ -114,14 +129,19 @@ export function phaseAt3Lh(messages: readonly LhMessage[], upToIndex?: number):
) {
phase = "plan";
}
} else if (role === "custom") {
const marker = m as { customType?: string; details?: { accepted?: unknown } };
if (
phase === "plan" &&
marker.customType === "verdict" &&
marker.details?.accepted === true
) {
phase = "teach";
} else if (role === "assistant") {
const content = (m as { content?: ReadonlyArray<{ type?: string; name?: string; arguments?: unknown }> }).content ?? [];
if (phase === "plan") {
for (const block of content) {
if (
block.type === "toolCall" &&
block.name === "quiz" &&
taggedNodeId(block.arguments)
) {
phase = "teach";
break;
}
}
}
}
}