feat(linkedin-studio): SB-S3b — supersede arm in the consolidation engine [skip-docs]

The engine can now RETIRE a fact via an operator-gated, explicitly-signalled
temporal-update supersede — completing the consolidation motor's one S2 TODO
("no supersede in S2 — that's S3"). A `supersedes` signal on a candidate retires
the stale fact (re-minted to an archival id, status: superseded, REPLACED IN
PLACE, retained as audit) and installs the new winner under the canonical key-id,
so mintEntityId(key) always points at the live fact.

- consolidate.ts: Candidate.supersedes? + ProfileDiff.supersedes (SupersedeOp
  carries the full winner fact, so applyDiff stays a pure projector). proposeDiff
  value-guarded routing fork (routes only when the target holds a DIFFERENT value —
  else a re-sent signal would self-supersede every run) + intra-batch
  first-supersede-wins guard. applyDiff replace-in-place + value-matched state-check
  (oldId present, active, value===oldValue) → idempotent re-apply + stale-diff safe;
  superseded facts never bumped/promoted (supersede wins). Decay excludes superseded.
  archivalId seeded with the pre-archival id (collision-free).
- cli.ts: renderDiffMd `## Supersessions (old → new)` (rendered last, only when
  present → zero-supersession diffs stay byte-identical); validateCandidates optional
  single-line `supersedes`; `--gather` profileFacts filtered to active (superseded
  archival facts never re-presented as live context).
- Tests: +12 brain (consolidate 10 + consolidate-cli 2). TDD: RED (6 fail) → GREEN
  (94/94). BRAIN_TESTS_FLOOR 82->94; ASSERT_BASELINE_FLOOR unchanged at 80 (no new
  test-runner.sh section). Gate 95/0/0.
- Docs: consolidation-loop.md rule table + honest-limit reconciled (the operator
  gate is the only classification net); engine docstring updated.

All 13 success criteria deterministically tested (unlike S3a, no behavioural-only
SC). READ-only gate unchanged — brain consolidate --apply --confirm stays the sole
profile.md writer. Scope held: scripts/brain/ only; temporal-update only
(condition-dependent/distractor deferred).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RigJBiRFNtFZKCz21qNbQ4
This commit is contained in:
Kjell Tore Guttormsen 2026-06-23 19:58:09 +02:00
commit 585f972a05
6 changed files with 267 additions and 19 deletions

View file

@ -94,4 +94,36 @@ describe("brain consolidate CLI (SC5)", () => {
assert.equal(runCli(root, ["ingest", "--file", f]).code, 0);
assert.equal(runCli(root, ["published", "list"]).code, 0);
});
const supCand = { key: "topic", value: "AI governance", provenance: "published", source: "manual", observed_date: "2026-06-24", supersedes: "topic" };
test("S3b-SC6 — Supersessions section renders one line per entry; a plain diff renders none; gated apply writes superseded", () => {
// plain propose → NO Supersessions section (byte-identity decoy)
runCli(root, ["consolidate", "--propose", "--candidates", candidatesFile(root, [validCand])]);
assert.ok(!readFileSync(pendingMd(root), "utf8").includes("## Supersessions"), "no section when 0 supersessions");
// apply to seed the active fact, then propose a supersede of it
runCli(root, ["consolidate", "--apply", "--diff", pendingJson(root), "--confirm"]);
runCli(root, ["consolidate", "--propose", "--candidates", candidatesFile(root, [supCand])]);
const md = readFileSync(pendingMd(root), "utf8");
assert.match(md, /## Supersessions/, "section rendered when a supersession exists");
assert.match(md, /AI safety.*→.*AI governance/, "old → new line rendered");
const diff = JSON.parse(readFileSync(pendingJson(root), "utf8"));
assert.equal(diff.supersedes.length, 1, "one supersede op in the JSON");
// the gated apply writes the superseded status to profile.md
runCli(root, ["consolidate", "--apply", "--diff", pendingJson(root), "--confirm"]);
assert.match(readFileSync(profilePath(root), "utf8"), /superseded/, "apply writes the superseded status");
});
test("S3b-SC10 — --gather excludes superseded facts from profileFacts", () => {
runCli(root, ["consolidate", "--propose", "--candidates", candidatesFile(root, [validCand])]);
runCli(root, ["consolidate", "--apply", "--diff", pendingJson(root), "--confirm"]);
runCli(root, ["consolidate", "--propose", "--candidates", candidatesFile(root, [supCand])]);
runCli(root, ["consolidate", "--apply", "--diff", pendingJson(root), "--confirm"]);
// profile now holds an archival "AI safety" (superseded) + winner "AI governance" (active)
const { stdout } = runCli(root, ["consolidate", "--gather", "--json"]);
const out = JSON.parse(stdout);
const values = out.profileFacts.map((f: any) => f.value);
assert.ok(values.includes("AI governance"), "active winner present in gather");
assert.ok(!out.profileFacts.some((f: any) => f.status === "superseded"), "no superseded fact leaks into gather");
});
});