rendering arc: the imp node becomes the argument's geometry, not a fake proposition

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.
This commit is contained in:
amosblomqvist
2026-09-30 04:04:29 +03:00
parent 8d72de596a
commit 719f7f9934
6 changed files with 206 additions and 41 deletions
+21
View File
@@ -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);
});
});
+77 -10
View File
@@ -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, []);
});
});
+31 -3
View File
@@ -106,16 +106,18 @@ describe("incrementalLayout", () => {
describe("settleGraphLayout", () => {
it("dedupes repeated node lines, runs, and writes the whole ledger", () => {
const written: Record<string, Position>[] = [];
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<string, Position>),
writePositions: (p: Record<string, Position>) => 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.