Graph redesign: true propositions, follows/supports, auditor-owned identity (vision §1 minimal implementation)
The minimal implementation of the 2026-09-02 graph vision (docs/vision.md §1):
- contracts/graph.ts: every node is a TRUE proposition (statement is both
rendering label and identity key; required description; no kind, no name).
Edges are follows (derivable) / supports (grounds without entailing) with
message-granular provenance points {chatId, messageId}. Events reduce to
correct/miss/dont-know plus observation (understanding notes); no taught
events, no misconception kind.
- extraction.ts: extractor is TREE-BLIND (transcript only, no plan tree) and
free-form; auditor sees findings + the current graph, owns faithfulness and
identity (link-or-create verdict per proposition, recorded as linkTo);
transcriptView tags every line with its message id (provenance anchors).
- core/graph.ts merger: applies verdicts deterministically — linkTo appends
a link line (phrasings join aliases, provenance unions; reads merge by id),
absent creates; NO string matching anywhere. Quiz events rebuilt from tool
parts with attribution-only nodeId resolution; understanding notes become
observation events (obs:<sourceId>); mapping lines are the verdict audit
trail and make re-merges idempotent.
- deriveNodeStates: transitional — latest quiz event wins (known/missed/
dont-know, else candidate); taught unreachable until the state-model
ideation lands.
- graph-context.ts + 50-graph-context.md: follows chains, hotspot grouping,
state vocabulary updated for the new event kinds.
- graph-view.tsx: node label is the statement; detail shows statement +
description.
- tests: merger verdicts (link, no-string-match, cross-chat assertions),
tree-blind pipeline end-to-end, follows vocabulary in context tests.
276/276 green.
This commit is contained in:
+16
-22
@@ -15,10 +15,9 @@
|
||||
* the block is absent (new learner).
|
||||
*
|
||||
* Selection strategy (§1 "the selection problem", simplest first): the WHOLE
|
||||
* graph while it is small; past MAX_NODES, hotspots (missed / dont-know /
|
||||
* misconception nodes) plus their 1-hop `requires` neighborhood — a live
|
||||
* misconception is always relevant context, and the frontier is where the
|
||||
* next session should probe.
|
||||
* graph while it is small; past MAX_NODES, hotspots (missed / dont-know
|
||||
* nodes) plus their 1-hop `follows` neighborhood — the frontier is where
|
||||
* the next session should probe.
|
||||
*/
|
||||
|
||||
import type { GraphEdge, GraphNode } from "./contracts.ts";
|
||||
@@ -31,22 +30,18 @@ export const GRAPH_CONTEXT_HEADER = "LEARNER KNOWLEDGE GRAPH (auto-generated)";
|
||||
/** Above this node count only hotspots + their 1-hop neighborhood are shown. */
|
||||
export const MAX_CONTEXT_NODES = 150;
|
||||
|
||||
/** Group order for node lines: diagnostic value first (vision §1 hotspots).
|
||||
* A misconception-kind node is a hotspot whatever its state — a live
|
||||
* misconception is always relevant context. */
|
||||
/** Group order for node lines: diagnostic value first (vision §1 hotspots). */
|
||||
const HOTSPOT_STATES: ReadonlySet<NodeStateClass> = new Set(["missed", "dont-know"]);
|
||||
|
||||
function groupOf(node: GraphNode, state: NodeStateClass): number {
|
||||
if (HOTSPOT_STATES.has(state) || node.kind === "misconception") return 0;
|
||||
if (HOTSPOT_STATES.has(state)) return 0;
|
||||
if (state === "known") return 1;
|
||||
if (state === "taught") return 2;
|
||||
return 3; // candidate
|
||||
return 2; // candidate
|
||||
}
|
||||
|
||||
const GROUP_LABELS = [
|
||||
"Hotspots (missed / dont-know / misconceptions) — likely misconception sites and unexplored ground:",
|
||||
"Hotspots (missed / dont-know) — likely misconception sites and unexplored ground:",
|
||||
"Known (answered correctly):",
|
||||
"Taught (lessons covered them):",
|
||||
"Candidates (never probed — assume nothing):",
|
||||
] as const;
|
||||
|
||||
@@ -76,9 +71,9 @@ export function renderGraphContext(
|
||||
truncated = true;
|
||||
const hotspots = nodes.filter((n) => isHotspot(n, stateOf(n)));
|
||||
const keep = new Set(hotspots.map((n) => n.id));
|
||||
// 1-hop requires neighborhood: prerequisites AND dependents.
|
||||
// 1-hop follows neighborhood: premises AND derivations.
|
||||
for (const edge of edges) {
|
||||
if (edge.type !== "requires") continue;
|
||||
if (edge.type !== "follows") continue;
|
||||
if (keep.has(edge.from) || keep.has(edge.to)) {
|
||||
keep.add(edge.from);
|
||||
keep.add(edge.to);
|
||||
@@ -91,7 +86,7 @@ export function renderGraphContext(
|
||||
// ── node lines, grouped/sorted by diagnostic priority ──────────────────────────
|
||||
const lines: string[] = [
|
||||
`===== ${GRAPH_CONTEXT_HEADER} =====`,
|
||||
`${truncated ? `showing ${selected.length} of ${nodes.length} nodes (hotspots + their 1-hop neighborhood)` : `${nodes.length} nodes`}, ${edges.filter((e) => e.type === "requires").length} requires edges`,
|
||||
`${truncated ? `showing ${selected.length} of ${nodes.length} nodes (hotspots + their 1-hop neighborhood)` : `${nodes.length} nodes`}, ${edges.filter((e) => e.type === "follows").length} follows edges`,
|
||||
];
|
||||
|
||||
for (const [group, label] of GROUP_LABELS.entries()) {
|
||||
@@ -101,19 +96,18 @@ export function renderGraphContext(
|
||||
if (groupNodes.length === 0) continue;
|
||||
lines.push("", label);
|
||||
for (const node of groupNodes) {
|
||||
const kind = node.kind === "misconception" ? " · misconception" : "";
|
||||
lines.push(`• [${stateOf(node)}] ${node.statement} (${node.id})${kind}`);
|
||||
lines.push(`• [${stateOf(node)}] ${node.statement} (${node.id})`);
|
||||
}
|
||||
}
|
||||
|
||||
// ── requires edges, merged into chains ──────────────────────────────────
|
||||
const byId = new Map(selected.map((n) => [n.id, n.statement]));
|
||||
const requires = edges.filter(
|
||||
(e) => e.type === "requires" && byId.has(e.from) && byId.has(e.to),
|
||||
const follows = edges.filter(
|
||||
(e) => e.type === "follows" && byId.has(e.from) && byId.has(e.to),
|
||||
);
|
||||
if (requires.length > 0) {
|
||||
lines.push("", "Requires (prerequisite → dependent):");
|
||||
for (const chain of edgeChains(requires)) {
|
||||
if (follows.length > 0) {
|
||||
lines.push("", "Follows (premise → derivation):");
|
||||
for (const chain of edgeChains(follows)) {
|
||||
lines.push(chain.map((id) => byId.get(id) ?? id).join(" → "));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user