feat: probe/teach agent split — explicit phase markers, position-only plan map
Diagnosis (2026-09-11 user testing, minimal-effort GLM): sessions stuck on 'plan' forever. Two causes: (1) the three-phase view read the stored tree's currentNodeId, which nothing ever writes post author-once (2026-09-03) — a structural dead seam; (2) the teacher stochastically left quiz.nodeId untagged, and done-by-quiz-result semantics would have falsely completed nodes anyway. The redesign (docs/probe-teach-split.md) abolishes derived occupancy in favor of explicit events: - Two agents over one transcript: createProberAgent (quiz without a nodeId field, ask, probe_done) and createTeacherAgent (full toolset, plan_init onward). The chat-handler construction branch keys on a probe_done part in the transcript. MODELS.prober added. - probe_done: server-side seam tool — carries the learner assessment (strands + free-form edge read), refuses while a question is open or the probe is already concluded, and queues a handoff steer through the generalized wake pipeline (steers now dedupe by id, not jobId; job finalization only for job steers). The teacher auto-wakes and authors the plan; the learner sees the assessment via the probe-done card. - phases: probe ends at a concluded probe_done, plan ends at a successful plan_init — strictly sequential, no skipping, no legacy compatibility (data wiped at the pivot per doctrine). - Plan map = position, not completion: derivePlanStatuses reads only tagged quiz CALLS (state/outcome feed nothing); current = latest tagged node with consecutive duplicates collapsed, visited = earlier distinct stays (a revisit stays in both — current wins at render). PlanTree is structure-only; currentNodeId/doneNodeIds and the dead mutation helpers are gone. No fallback current. - Prompts split per agent (prompts/prober/, prompts/teacher/ over the trimmed shared base); graph-context injection removed entirely (shelved, docs/probe-teach-split.md §5); knowledge-graph context no longer reaches either agent. - Plan blocks are full-only snapshots at plan_init (neighborhood machinery retired; the persistent DAG window is the future UI wave); usage capture unchanged. Gates: tsc clean, 294/294 tests (phases/plan-tree/plan-blocks/question- tools rewritten to the new semantics; probe-done + handoff-wake tests added), lint, build. Live GLM smoke PASS: prober concluded with an honest assessment, teacher auto-woke, authored a 10-node plan with the block attached, then tagged checks on slope-instinct → secant derived current/ visited exactly as designed; grading honest both ways (driver off-by-one proved a wrong answer grades false).
This commit is contained in:
+7
-101
@@ -28,7 +28,7 @@ export class PlanTreeError extends Error {
|
||||
|
||||
/** An empty, never-stored tree used as the seed before plan_init runs. */
|
||||
export function emptyTree(): PlanTree {
|
||||
return { nodes: [], edges: [], currentNodeId: null, doneNodeIds: [], version: 0 };
|
||||
return { nodes: [], edges: [], version: 0 };
|
||||
}
|
||||
|
||||
// ─── validation helpers ──────────────────────────────────────────────────────
|
||||
@@ -122,105 +122,11 @@ export function createTree(nodes: PlanNode[], edges: PlanEdge[]): PlanTree {
|
||||
assertValidEdge(e.from, e.to, nodes, accepted);
|
||||
accepted.push({ from: e.from, to: e.to });
|
||||
}
|
||||
return { nodes: nodes.map((n) => ({ ...n })), edges: accepted, currentNodeId: null, doneNodeIds: [], version: 1 };
|
||||
return { nodes: nodes.map((n) => ({ ...n })), edges: accepted, version: 1 };
|
||||
}
|
||||
|
||||
/** Add a node, optionally creating edges parent → new node for each id in `parents`. */
|
||||
export function addNode(tree: PlanTree, node: PlanNode, parents?: string[]): PlanTree {
|
||||
assertValidNode(node);
|
||||
if (tree.nodes.some((n) => n.id === node.id)) {
|
||||
throw new PlanTreeError(`Duplicate node id "${node.id}" — a node with that id already exists in the tree.`);
|
||||
}
|
||||
const parentList = parents ?? [];
|
||||
if (parentList.includes(node.id)) {
|
||||
throw new PlanTreeError(`Node "${node.id}" can't list itself as a parent.`);
|
||||
}
|
||||
const newEdges: PlanEdge[] = [];
|
||||
for (const parent of parentList) {
|
||||
// Validates existence (including the new node itself as `to`),
|
||||
// self-loop, duplicate (against tree edges plus the new edges being
|
||||
// added), and acyclicity.
|
||||
assertValidEdge(parent, node.id, [...tree.nodes, node], [...tree.edges, ...newEdges]);
|
||||
newEdges.push({ from: parent, to: node.id });
|
||||
}
|
||||
return {
|
||||
...tree,
|
||||
nodes: [...tree.nodes, { ...node }],
|
||||
edges: [...tree.edges, ...newEdges],
|
||||
version: tree.version + 1,
|
||||
};
|
||||
}
|
||||
|
||||
/** Update a node's title and/or summary. The id must exist; ids are immutable. */
|
||||
export function updateNode(tree: PlanTree, id: string, patch: { title?: string; summary?: string }): PlanTree {
|
||||
const index = tree.nodes.findIndex((n) => n.id === id);
|
||||
if (index === -1) {
|
||||
throw new PlanTreeError(`Cannot update node "${id}" — it is not in the tree.`);
|
||||
}
|
||||
const current = tree.nodes[index]!;
|
||||
const next: PlanNode = { ...current };
|
||||
if (patch.title !== undefined) next.title = patch.title;
|
||||
if (patch.summary !== undefined) next.summary = patch.summary;
|
||||
assertValidNode(next);
|
||||
const nodes = tree.nodes.slice();
|
||||
nodes[index] = next;
|
||||
return { ...tree, nodes, version: tree.version + 1 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a node and cascade: every edge touching it (both directions),
|
||||
* currentNodeId (→ null if it pointed here), and its doneNodeIds entry.
|
||||
*/
|
||||
export function removeNode(tree: PlanTree, id: string): PlanTree {
|
||||
if (!tree.nodes.some((n) => n.id === id)) {
|
||||
throw new PlanTreeError(`Cannot remove node "${id}" — it is not in the tree.`);
|
||||
}
|
||||
return {
|
||||
...tree,
|
||||
nodes: tree.nodes.filter((n) => n.id !== id),
|
||||
edges: tree.edges.filter((e) => e.from !== id && e.to !== id),
|
||||
currentNodeId: tree.currentNodeId === id ? null : tree.currentNodeId,
|
||||
doneNodeIds: tree.doneNodeIds.filter((d) => d !== id),
|
||||
version: tree.version + 1,
|
||||
};
|
||||
}
|
||||
|
||||
/** Add a `requires` edge from → to. Rejects self-loops, duplicates, and cycles. */
|
||||
export function addEdge(tree: PlanTree, from: string, to: string): PlanTree {
|
||||
assertValidEdge(from, to, tree.nodes, tree.edges);
|
||||
return { ...tree, edges: [...tree.edges, { from, to }], version: tree.version + 1 };
|
||||
}
|
||||
|
||||
/** Remove an existing edge. Removing a nonexistent edge is an error. */
|
||||
export function removeEdge(tree: PlanTree, from: string, to: string): PlanTree {
|
||||
const index = tree.edges.findIndex((e) => e.from === from && e.to === to);
|
||||
if (index === -1) {
|
||||
throw new PlanTreeError(`Cannot remove edge "${from}" → "${to}" — no such edge exists.`);
|
||||
}
|
||||
return { ...tree, edges: tree.edges.filter((e) => e.from !== from || e.to !== to), version: tree.version + 1 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Set currentNodeId ("where we are"). Requires the node exists. Does NOT
|
||||
* touch doneNodeIds. Setting the already-current node is a true no-op (no
|
||||
* version bump).
|
||||
*/
|
||||
export function setCurrent(tree: PlanTree, id: string): PlanTree {
|
||||
if (!tree.nodes.some((n) => n.id === id)) {
|
||||
throw new PlanTreeError(`Cannot set current node "${id}" — it is not in the tree.`);
|
||||
}
|
||||
if (tree.currentNodeId === id) return tree;
|
||||
return { ...tree, currentNodeId: id, version: tree.version + 1 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a node done. Requires the node exists; idempotent — marking an
|
||||
* already-done node is a true no-op (no version bump).
|
||||
*/
|
||||
export function markDone(tree: PlanTree, id: string): PlanTree {
|
||||
if (!tree.nodes.some((n) => n.id === id)) {
|
||||
throw new PlanTreeError(`Cannot mark node "${id}" done — it is not in the tree.`);
|
||||
}
|
||||
if (tree.doneNodeIds.includes(id)) return tree;
|
||||
return { ...tree, doneNodeIds: [...tree.doneNodeIds, id], version: tree.version + 1 };
|
||||
}
|
||||
// The per-node mutation ops (addNode/updateNode/removeNode/addEdge/removeEdge/
|
||||
// setCurrent/markDone) were deleted with the author-once protocol
|
||||
// (2026-09-03) and their dead exports removed with the 2026-09-11 pivot: the
|
||||
// tree carries structure ONLY — no progress fields exist to mutate
|
||||
// (docs/probe-teach-split.md §3). Restructuring is a plan_init rewrite.
|
||||
|
||||
Reference in New Issue
Block a user