From 719f7f99347cb8e01347fdfb4a6f146ea256e8d6 Mon Sep 17 00:00:00 2001 From: amosblomqvist Date: Wed, 30 Sep 2026 04:04:29 +0300 Subject: [PATCH] rendering arc: the imp node becomes the argument's geometry, not a fake proposition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Owner-approved brief (orchestrator): the canvas stops drawing implication nodes as first-class nodes and starts drawing them as what they are — the point where co-premise lines converge. - deriveView (core/graph.ts): single-premise chains collapse to ONE direct premise->conclusion arrow — no imp node minted (a chain is always N-in/ 1-out; one premise is the degenerate case). Multi-premise chains keep the imp node + fan. Dangling guard unchanged. - physics (core/layout.ts createGraphSimulation): per-link rest length — a link touching an arg_-prefixed endpoint gets HALF the base link distance, default or user-tuned alike; everything else about imp-node physics citizenship unchanged. - canvas (components/graph-canvas.ts): imp nodes are PURE GEOMETRY — invisible (no disc, no label) and unpickable (excluded from pickAt's hit-test projection). Edges INTO an imp node: headless, shaft runs to its CENTER (toRadius 0, no head triangle). Edges OUT: shaft starts at the center (fromRadius 0), arrowhead lands on the conclusion's disc edge. Single-premise direct arrows render as today's plain arrows. - comment repairs (same commit): the two stale double-shaft claims (CanvasEdge doc + the draw-pass block) rewritten to the truth — plain single shafts; bundles are headless converging lines + one arrowed out-edge; no double-shaft glyph exists anywhere. - tests (+9): deriveView pins (single-premise collapse, multi-premise fan, shared-conclusion distinctness, dangling drop); imp-link half- distance settle pins; arrowGeometry zero-radius laws + isImpNodeId pin; graph.test.ts's snapshot invariant now counts only MULTI-premise live chains (its fixture's single-premise chains mint zero imp nodes); layout settle fixture updated for the collapse. --- components/graph-canvas.ts | 57 +++++++++++++++++-------- src/core/graph.ts | 28 ++++++++---- src/core/layout.ts | 20 ++++++++- tests/graph-canvas.test.ts | 21 +++++++++ tests/graph.test.ts | 87 +++++++++++++++++++++++++++++++++----- tests/layout.test.ts | 34 +++++++++++++-- 6 files changed, 206 insertions(+), 41 deletions(-) diff --git a/components/graph-canvas.ts b/components/graph-canvas.ts index 5092e34..e648b23 100644 --- a/components/graph-canvas.ts +++ b/components/graph-canvas.ts @@ -86,14 +86,23 @@ export interface CanvasNode { } /** One directed edge of the DERIVED view (chains-primary, 2026-09-30): - * premise → implication node → conclusion, UNTYPED — every arrow is an - * implication, so every arrow renders the double-shaft glyph (⟹) + - * arrowhead (DECIDED 2026-09-14, docs/vision-edge-glyph.md). */ + * premise → implication node → conclusion, UNTYPED, all PLAIN + * single-shaft arrows — there is no double-shaft glyph anywhere + * (the 2026-09-14 ruling died with typed edges). An argument renders + * as its geometry: co-premise lines converge HEADLESS onto the + * implication point, one arrowed line leaves it; a single-premise + * argument is one ordinary arrow (see deriveView). */ export interface CanvasEdge { from: string; to: string; } +/** Implication-node ids (the mint law: newGraphChainId in core/graph.ts). + * On the canvas an imp node is PURE GEOMETRY (owner, rendering arc + * 2026-09-30): invisible — no disc, no label — and UNPICKABLE, + * excluded from every hit-test path. Exported for the test pin. */ +export const isImpNodeId = (id: string): boolean => id.startsWith("arg_"); + /** One cluster region: member node ids + the LLM-coined label (or null). */ export interface CanvasCluster { id: string; @@ -1048,6 +1057,7 @@ export class GraphCanvasRenderer { const projected: { id: string; x: number; y: number }[] = []; for (const n of this.data.nodes) { if (this.visible && !this.visible.has(n.id)) continue; + if (isImpNodeId(n.id)) continue; // pure geometry — never picked projected.push({ id: n.id, x: n.x * k + tx, y: n.y * k + ty }); } const hit = pickNearest(projected, px, py, maxDist); @@ -1218,21 +1228,24 @@ export class GraphCanvasRenderer { const visible = this.visible; const isVisible = (id: string) => !visible || visible.has(id); - // Node discs: one Path2D, one fill() per frame. + // Node discs: one Path2D, one fill() per frame. Implication nodes + // are pure geometry — never a disc, never a label, never picked. const nodesPath = new Path2D(); for (const n of data.nodes) { - if (!isVisible(n.id)) continue; + if (!isVisible(n.id) || isImpNodeId(n.id)) continue; nodesPath.moveTo(n.x + nodeR, n.y); nodesPath.arc(n.x, n.y, nodeR, 0, Math.PI * 2); } this.nodesPath = nodesPath; - // Edge shafts + arrowheads: tip lands on the target disc edge. Both - // relation types draw the same arrow for now — the double-shaft - // glyph was rejected (2026-09-15); differentiation is pending a new - // approach. Two owner rulings 2026-09-29: the supports draw toggle - // CHAINS-PRIMARY (2026-09-30): one path family — every derived arrow - // is an implication, double-shafted + arrowheaded uniformly. + // Edge shafts + arrowheads (rendering arc, owner 2026-09-30): all + // arrows are PLAIN single shafts — the old double-shaft glyph is + // gone entirely. An argument's geometry: lines INTO an implication + // node are HEADLESS and run all the way to the imp node's CENTER + // (co-premise lines converge to a point); the line OUT of it starts + // at the center and its arrowhead lands on the conclusion's disc + // edge. Single-premise arguments arrive here as ordinary + // proposition→proposition edges and draw exactly like any arrow. const arrowLen = settings.arrowLength; const shafts = new Path2D(); const heads = new Path2D(); @@ -1241,14 +1254,22 @@ export class GraphCanvasRenderer { const a = this.nodeById.get(e.from); const b = this.nodeById.get(e.to); if (!a || !b) continue; - const g = arrowGeometry(a, b, nodeR, nodeR, arrowLen); + const intoImp = isImpNodeId(e.to); + const outOfImp = isImpNodeId(e.from); + const g = arrowGeometry(a, b, outOfImp ? 0 : nodeR, intoImp ? 0 : nodeR, arrowLen); if (!g) continue; shafts.moveTo(g.shaftFrom.x, g.shaftFrom.y); - shafts.lineTo(g.shaftTo.x, g.shaftTo.y); - heads.moveTo(g.tip.x, g.tip.y); - heads.lineTo(g.left.x, g.left.y); - heads.lineTo(g.right.x, g.right.y); - heads.closePath(); + if (intoImp) { + // toRadius 0 put the tip AT the imp node's center: the + // headless shaft terminates there (no head triangle). + shafts.lineTo(g.tip.x, g.tip.y); + } else { + shafts.lineTo(g.shaftTo.x, g.shaftTo.y); + heads.moveTo(g.tip.x, g.tip.y); + heads.lineTo(g.left.x, g.left.y); + heads.lineTo(g.right.x, g.right.y); + heads.closePath(); + } } this.shaftsPath = shafts; this.headsPath = heads; @@ -1266,7 +1287,7 @@ export class GraphCanvasRenderer { ctx.font = this.worldLabelFont; const maxW = LABEL_MAX_WIDTH * (settings.labelSize / LABEL_SIZE); for (const n of data.nodes) { - if (isVisible(n.id)) this.labelLines.set(n.id, wrapLabel(ctx, n.label, maxW)); + if (isVisible(n.id) && !isImpNodeId(n.id)) this.labelLines.set(n.id, wrapLabel(ctx, n.label, maxW)); } ctx.font = prevFont; } diff --git a/src/core/graph.ts b/src/core/graph.ts index 4c8066d..bb14669 100644 --- a/src/core/graph.ts +++ b/src/core/graph.ts @@ -303,15 +303,19 @@ export function getGraph(graphStore: Pick = {}; for (const node of graph.nodes) names[node.id] = { name: node.name }; @@ -320,6 +324,12 @@ export function deriveView(graph: DerivedGraph): { nodes: GraphNode[]; edges: Gr const edges: GraphEdge[] = []; for (const chain of graph.chains) { if (!live.has(chain.conclusion) || !chain.premises.every((premise) => live.has(premise))) continue; + // Single premise: the argument IS a plain arrow — no geometry + // point needed (the 1-in/1-out collapse; rendering arc, owner). + if (chain.premises.length === 1) { + edges.push({ from: chain.premises[0]!, to: chain.conclusion }); + continue; + } impNodes.push({ id: chain.id, name: "⟹", diff --git a/src/core/layout.ts b/src/core/layout.ts index f244623..5d6e9eb 100644 --- a/src/core/layout.ts +++ b/src/core/layout.ts @@ -196,6 +196,14 @@ export interface LayoutEdge { } export const LINK_DISTANCE = 40; +/** Implication-node id prefix (the mint law lives in core/graph.ts's + * newGraphChainId). Layout-side: links TOUCHING an imp node get HALF + * the base rest length — the argument's geometry (a converging point) + * sits tight against its premises/conclusion instead of spread like a + * real proposition citizen (owner ruling, rendering arc 2026-09-30). */ +const IMP_ID_PREFIX = "arg_"; +const impLinkId = (v: string | number | { id: string }): string => + typeof v === "object" ? v.id : String(v); export const CHARGE_STRENGTH = -240; // 2026-09-17: −120 → −240 (user: repulsion default too weak); the default is shared with render-settings (gm-centered in CHARGE_RANGE). /** Per-tick anchor re-blend: fraction of an anchored node's displacement * from its previous position that SURVIVES each tick. 0.85 = gentle @@ -238,6 +246,7 @@ export function createGraphSimulation( degree.set(e.to, (degree.get(e.to) ?? 0) + 1); } const linkStrength = options.linkStrength ?? 1; + const linkDistance = options.linkDistance ?? LINK_DISTANCE; const sim = forceSimulation(nodes) .force( @@ -246,7 +255,16 @@ export function createGraphSimulation( edges.map((e) => ({ source: e.from, target: e.to })), ) .id((d) => d.id) - .distance(options.linkDistance ?? LINK_DISTANCE) + // Per-link rest length (rendering arc, owner 2026-09-30): a + // link touching an implication node (arg_-prefixed id — the + // string form pre-init, the node ref after) gets HALF the + // base distance, default or user-tuned alike. + .distance( + (l) => + impLinkId(l.source).startsWith(IMP_ID_PREFIX) || impLinkId(l.target).startsWith(IMP_ID_PREFIX) + ? linkDistance / 2 + : linkDistance, + ) .strength( (l) => (linkStrength * 1) / diff --git a/tests/graph-canvas.test.ts b/tests/graph-canvas.test.ts index 53d93bc..45ac28a 100644 --- a/tests/graph-canvas.test.ts +++ b/tests/graph-canvas.test.ts @@ -14,6 +14,7 @@ import { describe, it, it as test } from "node:test"; import { applyClusterLabels, arrowGeometry, + isImpNodeId, boxBlurRound, fitTransform, labelAlpha, @@ -148,6 +149,26 @@ describe("arrowGeometry", () => { test("null for coincident endpoints (never a NaN arrow)", () => { assert.equal(arrowGeometry({ x: 5, y: 5 }, { x: 5, y: 5 }, 6, 6, 5), null); }); + + // The rendering arc's geometry laws (owner, 2026-09-30): an edge INTO + // an imp point is drawn with toRadius 0 (headless, terminates at the + // center); an edge OUT of one with fromRadius 0 (starts at the center). + test("toRadius 0 — the tip lands exactly at the target CENTER (headless convergence)", () => { + const g = arrowGeometry({ x: 0, y: 0 }, { x: 100, y: 0 }, 6, 0, 5)!; + assert.ok(Math.abs(g.tip.x - 100) < 1e-9 && Math.abs(g.tip.y) < 1e-9, "tip = the center, past which no shaft draws"); + }); + + test("fromRadius 0 — the shaft starts exactly at the source CENTER", () => { + const g = arrowGeometry({ x: 0, y: 0 }, { x: 100, y: 0 }, 0, 6, 5)!; + assert.ok(Math.abs(g.shaftFrom.x) < 1e-9 && Math.abs(g.shaftFrom.y) < 1e-9, "shaftFrom = the center"); + }); +}); + +describe("isImpNodeId (the pure-geometry law, rendering arc 2026-09-30)", () => { + test("arg_-prefixed ids are geometry; proposition ids are citizens", () => { + assert.equal(isImpNodeId("arg_123af5a046ba"), true); + assert.equal(isImpNodeId("n_abc123"), false); + }); }); diff --git a/tests/graph.test.ts b/tests/graph.test.ts index 6e333a9..fa29b48 100644 --- a/tests/graph.test.ts +++ b/tests/graph.test.ts @@ -19,11 +19,11 @@ import assert from "node:assert/strict"; import * as fs from "node:fs"; import { after, describe, it } from "node:test"; -import type { AuditVerdicts, SessionFindings } from "../src/core/contracts.ts"; +import type { AuditVerdicts, GraphChain, GraphNode, SessionFindings } from "../src/core/contracts.ts"; import type { QuestionAnswerData } from "../src/core/question-core.ts"; import type { LhMessage } from "../src/core/native-messages.ts"; import { projectView as projectNative } from "../src/core/view.ts"; -import { getGraph, graphSnapshot, mergeFindings, type GraphDeps } from "../src/core/graph.ts"; +import { deriveView, getGraph, graphSnapshot, mergeFindings, type GraphDeps } from "../src/core/graph.ts"; import { coverageSlots } from "../src/core/coverage.ts"; import { graphStore } from "../src/store/graph.ts"; import { chatStore } from "../src/store/chats.ts"; @@ -459,18 +459,22 @@ describe("the merger (mergeFindings)", () => { assert.equal(mine!.label, "/vault/cluster notes.md", "a notes file is a birth-session — the label is its path"); // Chains-primary split (owner, 2026-09-30): `nodes` is the canvas - // image (propositions + derived implication nodes), `propositions` - // is the stored truth alone — the chain table's input. The store is - // shared across this suite, so assert the INVARIANT, not counts: - // image = truth + one imp node per fully-live stored chain, and the - // truth never carries an arg_ id. + // image, `propositions` the stored truth alone (the chain table's + // input). The store is shared across this suite, so assert the + // INVARIANT, not counts — and since the rendering arc + // (2026-09-30), only MULTI-premise live chains mint imp nodes + // (this fixture's two single-premise chains collapse to direct + // arrows — zero imp nodes here). const stored = graphStore.readChains(); const live = new Set(snap.propositions.map((n) => n.id)); - const liveChains = stored.filter((c) => live.has(c.conclusion) && c.premises.every((p) => live.has(p))); + const impChains = stored.filter( + (c) => c.premises.length >= 2 && live.has(c.conclusion) && c.premises.every((p) => live.has(p)), + ); assert.ok(snap.propositions.every((n) => !n.id.startsWith("arg_")), "the stored-truth list never carries imp nodes"); - assert.equal(snap.nodes.length, snap.propositions.length + liveChains.length, "image = truth + one imp node per live chain"); + assert.equal(snap.nodes.length, snap.propositions.length + impChains.length, "image = truth + one imp node per MULTI-premise live chain"); const imp = snap.nodes.filter((n) => n.id.startsWith("arg_")); - assert.ok(imp.length === liveChains.length && imp.every((n) => snap.propositions.every((p) => p.id !== n.id)), "the extra nodes are exactly the derived implication nodes"); + assert.ok(imp.length === impChains.length && imp.every((n) => snap.propositions.every((p) => p.id !== n.id)), "the extra nodes are exactly the derived implication nodes"); + assert.equal(imp.length, 0, "this fixture's chains are single-premise — all collapsed to direct arrows"); }); it("derives the sessions index in graphSnapshot", () => { @@ -996,3 +1000,66 @@ describe("session coverage read (extraction-UX redesign, 2026-09-24)", () => { assert.equal(sessionCoverage("chat_never_was"), null); }); }); + +// ─── deriveView (the rendering arc, owner 2026-09-30) ──────────────────────── + +describe("deriveView (the argument's geometry)", () => { + const prop = (id: string): GraphNode => ({ + id, + name: id.toUpperCase(), + statement: `${id} statement`, + aliases: [], + createdAt: "2026-09-30T00:00:00.000Z", + provenance: [], + }); + const chain = (id: string, premises: string[], conclusion: string): GraphChain => ({ + id, + premises, + conclusion, + provenance: [], + createdAt: "2026-09-30T00:00:00.000Z", + }); + + it("a SINGLE-premise chain collapses to ONE direct arrow — no imp node", () => { + const view = deriveView({ nodes: [prop("a"), prop("b")], chains: [chain("arg_ab", ["a"], "b")] }); + assert.deepEqual(view.nodes.map((n) => n.id), ["a", "b"], "no arg_ node minted"); + assert.deepEqual(view.edges, [{ from: "a", to: "b" }], "the argument IS a plain arrow"); + }); + + it("a MULTI-premise chain keeps the imp node + fan (premises in, conclusion out)", () => { + const view = deriveView({ + nodes: [prop("a"), prop("b"), prop("c")], + chains: [chain("arg_ab", ["a", "b"], "c")], + }); + assert.deepEqual(view.nodes.map((n) => n.id).sort(), ["a", "arg_ab", "b", "c"]); + assert.deepEqual( + [...view.edges].sort((x, y) => (x.from < y.from ? -1 : x.from > y.from ? 1 : x.to < y.to ? -1 : 1)), + [ + { from: "a", to: "arg_ab" }, + { from: "arg_ab", to: "c" }, + { from: "b", to: "arg_ab" }, + ], + ); + const imp = view.nodes.find((n) => n.id === "arg_ab")!; + assert.equal(imp.name, "\u27f9"); + }); + + it("two chains SHARING a conclusion stay distinct — two geometry points, never a unioned fan", () => { + const view = deriveView({ + nodes: [prop("a"), prop("b"), prop("c"), prop("d"), prop("e")], + chains: [chain("arg_e1", ["a", "b"], "e"), chain("arg_e2", ["c", "d"], "e")], + }); + assert.deepEqual( + view.nodes.map((n) => n.id).sort(), + ["a", "arg_e1", "arg_e2", "b", "c", "d", "e"], + ); + assert.ok(view.edges.some((x) => x.from === "arg_e1" && x.to === "e")); + assert.ok(view.edges.some((x) => x.from === "arg_e2" && x.to === "e")); + }); + + it("dangling chains drop (missing member — the honest belt)", () => { + const view = deriveView({ nodes: [prop("a")], chains: [chain("arg_ghost", ["a"], "gone"), chain("arg_gone", ["ghost"], "a")] }); + assert.deepEqual(view.nodes.map((n) => n.id), ["a"]); + assert.deepEqual(view.edges, []); + }); +}); diff --git a/tests/layout.test.ts b/tests/layout.test.ts index 6c3294e..2e8a755 100644 --- a/tests/layout.test.ts +++ b/tests/layout.test.ts @@ -106,16 +106,18 @@ describe("incrementalLayout", () => { describe("settleGraphLayout", () => { it("dedupes repeated node lines, runs, and writes the whole ledger", () => { const written: Record[] = []; - const lines = [node("a"), node("b"), node("a")]; // "a" appended twice + const lines = [node("a"), node("b"), node("c"), node("d"), node("a")]; // "a" appended twice const store = { readNodes: () => lines.map((l) => ({ ...l })), - readChains: () => [chain("arg_ab", ["a"], "b")], + readChains: () => [chain("arg_ab", ["a"], "b"), chain("arg_bcd", ["b", "c"], "d")], readPositions: () => ({} as Record), writePositions: (p: Record) => void written.push(p), }; settleGraphLayout(store); assert.equal(written.length, 1); - assert.deepEqual(Object.keys(written[0]!).sort(), ["a", "arg_ab", "b"], "one position per unique node AND the derived implication node"); + // arg_ab is single-premise → collapsed to a direct arrow, NO imp + // node; arg_bcd is multi-premise → its imp node joins the layout. + assert.deepEqual(Object.keys(written[0]!).sort(), ["a", "arg_bcd", "b", "c", "d"], "positions for the unique nodes and ONLY the multi-premise chain's imp node"); }); it("does nothing on an empty graph", () => { @@ -129,6 +131,32 @@ describe("settleGraphLayout", () => { assert.equal(written.length, 0); }); }); +describe("imp-link half distance (rendering arc, owner 2026-09-30)", () => { + const settle = (from: string, to: string, linkDistance: number) => { + const nodes = [{ id: from, x: 0, y: 0 }, { id: to, x: 500, y: 0 }]; + const sim = createGraphSimulation(nodes, [{ from, to }], { + linkDistance, + chargeStrength: 0, // springs only — the rest length IS the equilibrium + gravity: { x: 0, y: 0, strength: 0 }, + }); + for (let i = 0; i < 300; i++) sim.tick(); + const [a, b] = sim.nodes() as unknown as { id: string; x: number; y: number }[]; + assert.ok(a && b, "both nodes present"); + return Math.abs(b.x - a.x); + }; + + it("a plain proposition link settles at the full rest length (tuned or default)", () => { + assert.ok(Math.abs(settle("a", "b", 100) - 100) < 2, "plain link ≈ 100"); + }); + + it("a link TOUCHING an implication node gets HALF the rest length", () => { + // into the imp point (premise → arg_x) + assert.ok(Math.abs(settle("a", "arg_x", 100) - 50) < 2, "into-imp link ≈ 50"); + // out of it (arg_x → conclusion) + assert.ok(Math.abs(settle("arg_x", "b", 100) - 50) < 2, "out-of-imp link ≈ 50"); + }); +}); + describe("clusterPull (the centroid force)", () => { it("compacts each cluster toward its OWN centroid; strength 0 = off", () => { // Two loose chains, far apart, edges only WITHIN each chain.