@facthouse/mcp 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +12 -12
  2. package/dist/cli/inspect-html.d.ts.map +1 -1
  3. package/dist/cli/inspect-html.js +14 -2
  4. package/dist/cli/inspect-html.js.map +1 -1
  5. package/dist/cli/inspect-payload.d.ts +21 -0
  6. package/dist/cli/inspect-payload.d.ts.map +1 -1
  7. package/dist/cli/inspect-payload.js +58 -2
  8. package/dist/cli/inspect-payload.js.map +1 -1
  9. package/dist/cli/inspect.d.ts.map +1 -1
  10. package/dist/cli/inspect.js +3 -0
  11. package/dist/cli/inspect.js.map +1 -1
  12. package/dist/cli/query.d.ts.map +1 -1
  13. package/dist/cli/query.js +4 -0
  14. package/dist/cli/query.js.map +1 -1
  15. package/dist/cli/run.d.ts.map +1 -1
  16. package/dist/cli/run.js +3 -0
  17. package/dist/cli/run.js.map +1 -1
  18. package/dist/db/fact-relations.d.ts +67 -0
  19. package/dist/db/fact-relations.d.ts.map +1 -0
  20. package/dist/db/fact-relations.js +106 -0
  21. package/dist/db/fact-relations.js.map +1 -0
  22. package/dist/db/postgres-schema.js +22 -0
  23. package/dist/db/postgres-schema.js.map +1 -1
  24. package/dist/db/postgres.d.ts.map +1 -1
  25. package/dist/db/postgres.js +2 -0
  26. package/dist/db/postgres.js.map +1 -1
  27. package/dist/db/schema-version.d.ts +1 -1
  28. package/dist/db/schema-version.js +1 -1
  29. package/dist/db/schema.d.ts.map +1 -1
  30. package/dist/db/schema.js +36 -0
  31. package/dist/db/schema.js.map +1 -1
  32. package/dist/db/sessions.d.ts +9 -0
  33. package/dist/db/sessions.d.ts.map +1 -1
  34. package/dist/db/sessions.js +23 -0
  35. package/dist/db/sessions.js.map +1 -1
  36. package/dist/intelligence/cli.d.ts.map +1 -1
  37. package/dist/intelligence/cli.js +13 -8
  38. package/dist/intelligence/cli.js.map +1 -1
  39. package/dist/intelligence/consolidate.d.ts +14 -0
  40. package/dist/intelligence/consolidate.d.ts.map +1 -1
  41. package/dist/intelligence/consolidate.js +286 -26
  42. package/dist/intelligence/consolidate.js.map +1 -1
  43. package/dist/intelligence/heuristic.d.ts +4 -0
  44. package/dist/intelligence/heuristic.d.ts.map +1 -1
  45. package/dist/intelligence/heuristic.js +40 -11
  46. package/dist/intelligence/heuristic.js.map +1 -1
  47. package/dist/intelligence/http.d.ts.map +1 -1
  48. package/dist/intelligence/http.js +14 -8
  49. package/dist/intelligence/http.js.map +1 -1
  50. package/dist/intelligence/sampling.d.ts.map +1 -1
  51. package/dist/intelligence/sampling.js +20 -11
  52. package/dist/intelligence/sampling.js.map +1 -1
  53. package/dist/intelligence/supersession.d.ts +46 -0
  54. package/dist/intelligence/supersession.d.ts.map +1 -0
  55. package/dist/intelligence/supersession.js +56 -0
  56. package/dist/intelligence/supersession.js.map +1 -0
  57. package/dist/intelligence/types.d.ts +23 -3
  58. package/dist/intelligence/types.d.ts.map +1 -1
  59. package/dist/search/entity.d.ts.map +1 -1
  60. package/dist/search/entity.js +10 -2
  61. package/dist/search/entity.js.map +1 -1
  62. package/dist/search/index.d.ts.map +1 -1
  63. package/dist/search/index.js +8 -0
  64. package/dist/search/index.js.map +1 -1
  65. package/dist/sources/resolve.d.ts +26 -0
  66. package/dist/sources/resolve.d.ts.map +1 -1
  67. package/dist/sources/resolve.js +55 -0
  68. package/dist/sources/resolve.js.map +1 -1
  69. package/dist/tools/fact-manager.d.ts +27 -0
  70. package/dist/tools/fact-manager.d.ts.map +1 -1
  71. package/dist/tools/fact-manager.js +31 -17
  72. package/dist/tools/fact-manager.js.map +1 -1
  73. package/dist/types/data.d.ts +29 -0
  74. package/dist/types/data.d.ts.map +1 -1
  75. package/dist/types/data.js +21 -0
  76. package/dist/types/data.js.map +1 -1
  77. package/package.json +1 -1
@@ -14,6 +14,10 @@
14
14
  import { randomUUID } from "node:crypto";
15
15
  import { withTransaction } from "../db/connection.js";
16
16
  import { DEFAULT_CONFIDENCE, DEFAULT_IMPORTANCE, DEFAULT_CONFIG, } from "../types/config.js";
17
+ import { NEGATION_WORDS, SUPERSESSION_JACCARD_MIN, jaccardSimilarity, } from "./heuristic.js";
18
+ import { getProjectsForSessions } from "../db/sessions.js";
19
+ import { insertFactRelation } from "../db/fact-relations.js";
20
+ import { projectKey, projectRelation } from "../sources/resolve.js";
17
21
  import { EXTRACT_EVIDENCE_SLICE, EXTRACT_REREAD_CONFIDENCE, EXTRACT_REREAD_WINDOW, capReferents, packEventsForExtract, } from "./extract-prompt.js";
18
22
  import { lineTimeMs } from "./line-time.js";
19
23
  import { ConsolidateAbortError, isConsolidateAbort, throwIfAborted } from "./abort.js";
@@ -94,6 +98,9 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
94
98
  entitiesCreated: 0,
95
99
  entitiesLinked: 0,
96
100
  supersessions: 0,
101
+ keptAlongside: 0,
102
+ corroborations: 0,
103
+ relations: [],
97
104
  summary: null,
98
105
  openThreads: [],
99
106
  skipped: true,
@@ -170,6 +177,9 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
170
177
  entitiesCreated: 0,
171
178
  entitiesLinked: 0,
172
179
  supersessions: 0,
180
+ keptAlongside: 0,
181
+ corroborations: 0,
182
+ relations: [],
173
183
  summary: null,
174
184
  openThreads: [],
175
185
  skipped: true,
@@ -242,6 +252,9 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
242
252
  entitiesCreated: 0,
243
253
  entitiesLinked: 0,
244
254
  supersessions: 0,
255
+ keptAlongside: 0,
256
+ corroborations: 0,
257
+ relations: [],
245
258
  eventsCopied,
246
259
  eventsRemaining: await remainingEvents(),
247
260
  summary: null,
@@ -256,6 +269,7 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
256
269
  // Phase C: I→K integration pipeline (LLM calls happen here, outside transaction)
257
270
  // Build lookup map for O(1) access in Phase C and D
258
271
  const sessionFactMap = new Map(sessionFacts.map((f) => [f.id, f]));
272
+ const projectBySession = await getProjectsForSessions(db, [...new Set(sessionFacts.map((f) => f.session_id))]);
259
273
  // Step 1: Classify domains. For session_facts that carry a domain_hint
260
274
  // from extraction (set by CLI/sampling providers via subdomain_hint etc.),
261
275
  // trust that directly and don't re-call the classifier. Falls through to
@@ -323,6 +337,20 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
323
337
  if (!cached) {
324
338
  cached = await getFactsByDomain(db, domain);
325
339
  domainCache.set(domain, cached);
340
+ const missing = [];
341
+ const seen = new Set();
342
+ for (const fact of cached) {
343
+ const id = fact.session_id;
344
+ if (!id || projectBySession.has(id) || seen.has(id))
345
+ continue;
346
+ seen.add(id);
347
+ missing.push(id);
348
+ }
349
+ if (missing.length > 0) {
350
+ const more = await getProjectsForSessions(db, missing);
351
+ for (const [id, project] of more)
352
+ projectBySession.set(id, project);
353
+ }
326
354
  }
327
355
  return cached;
328
356
  };
@@ -333,11 +361,27 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
333
361
  * reconcile decision — candidate is a paraphrase / corroboration of an
334
362
  * existing fact, so instead of integrating we strengthen the existing one. */
335
363
  const enrichments = [];
336
- // Intra-batch dedup: track normalised content already queued for integration.
337
- // Without this, two session_facts with identical content from different sessions
338
- // both pass same-session hash dedup and both pass reconcile (neither has a integrated
339
- // twin yet), producing duplicate rows in the facts table.
340
- const seenBatchContent = new Set();
364
+ // Intra-batch dedup. The value is the session fact that will receive the
365
+ // one K. A later twin recorded in a different project does not get a
366
+ // second K; the winner is explicit-first, then earliest created_at.
367
+ // That choice does not reorder `classified`.
368
+ const seenBatchContent = new Map();
369
+ const batchTwins = [];
370
+ const absorbedTwins = [];
371
+ const projectOf = (sessionId) => {
372
+ if (!sessionId)
373
+ return null;
374
+ return projectBySession.get(sessionId) ?? null;
375
+ };
376
+ const preferRestatementWinner = (current, incumbent) => {
377
+ const currentExplicit = current.source_origin === "explicit";
378
+ const incumbentExplicit = incumbent.source_origin === "explicit";
379
+ if (currentExplicit !== incumbentExplicit)
380
+ return currentExplicit ? current : incumbent;
381
+ if (current.created_at < incumbent.created_at)
382
+ return current;
383
+ return incumbent;
384
+ };
341
385
  let integrateDone = 0;
342
386
  for (const cf of classified) {
343
387
  throwIfAborted(caller.abort);
@@ -347,15 +391,49 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
347
391
  // Shared normalisation with cross-batch reconcile (heuristic.ts) so
348
392
  // "I prefer coffee" vs "I prefer coffee." is consistently handled.
349
393
  const normalised = normaliseForDedup(cf.content);
350
- if (seenBatchContent.has(normalised)) {
351
- rejected++;
352
- continue;
394
+ const incumbentId = seenBatchContent.get(normalised);
395
+ let displacedId = null;
396
+ if (incumbentId) {
397
+ const incumbent = sessionFactMap.get(incumbentId);
398
+ const relation = projectRelation(projectOf(sessionFact.session_id), projectOf(incumbent?.session_id));
399
+ if (relation === "different" && incumbent && preferRestatementWinner(sessionFact, incumbent).id === sessionFact.id) {
400
+ // This fact becomes the single K. The incumbent is rejected below,
401
+ // once reconcile agrees it should be integrated.
402
+ displacedId = incumbentId;
403
+ seenBatchContent.delete(normalised);
404
+ }
405
+ else {
406
+ if (relation === "different" && incumbent) {
407
+ batchTwins.push({
408
+ winnerSessionFactId: incumbentId,
409
+ loserSessionFactId: sessionFact.id,
410
+ });
411
+ }
412
+ rejected++;
413
+ continue;
414
+ }
353
415
  }
354
416
  const domainFacts = await getDomainFacts(cf.domain);
355
417
  const decision = await intelligence.reconcile(sessionFact, domainFacts);
356
418
  integrateDone += 1;
357
419
  caller.onIntegrateProgress?.(integrateDone, classified.length);
358
420
  if (decision.kind === "noop") {
421
+ if (displacedId)
422
+ seenBatchContent.set(normalised, displacedId);
423
+ const twin = domainFacts.find((fact) => normaliseForDedup(fact.content) === normalised);
424
+ if (twin) {
425
+ const relation = projectRelation(projectOf(sessionFact.session_id), projectOf(twin.session_id));
426
+ if (relation === "different") {
427
+ absorbedTwins.push({
428
+ factId: twin.id,
429
+ sessionFactId: sessionFact.id,
430
+ verdict: relation,
431
+ factProject: projectOf(twin.session_id),
432
+ candidateProject: projectOf(sessionFact.session_id),
433
+ reason: "restatement",
434
+ });
435
+ }
436
+ }
359
437
  rejected++;
360
438
  continue;
361
439
  }
@@ -364,16 +442,36 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
364
442
  // hallucinated an id, fall through to the add path as a safer default.
365
443
  const target = domainFacts.find((f) => f.id === decision.existingFactId);
366
444
  if (target) {
445
+ if (displacedId)
446
+ seenBatchContent.set(normalised, displacedId);
367
447
  enrichments.push({
368
448
  existingFactId: decision.existingFactId,
369
449
  confidenceDelta: 0.1,
370
450
  });
451
+ absorbedTwins.push({
452
+ factId: target.id,
453
+ sessionFactId: sessionFact.id,
454
+ verdict: projectRelation(projectOf(sessionFact.session_id), projectOf(target.session_id)),
455
+ factProject: projectOf(target.session_id),
456
+ candidateProject: projectOf(sessionFact.session_id),
457
+ reason: "paraphrase (enrich)",
458
+ });
371
459
  rejected++;
372
460
  continue;
373
461
  }
374
462
  // else: hallucinated id → treat as add
375
463
  }
376
- seenBatchContent.add(normalised);
464
+ if (displacedId) {
465
+ const idx = toIntegrate.findIndex((item) => item.sessionFactId === displacedId);
466
+ if (idx >= 0)
467
+ toIntegrate.splice(idx, 1);
468
+ rejected++;
469
+ batchTwins.push({
470
+ winnerSessionFactId: sessionFact.id,
471
+ loserSessionFactId: displacedId,
472
+ });
473
+ }
474
+ seenBatchContent.set(normalised, cf.id);
377
475
  // Confidence/importance: explicit captures carry their own values; for
378
476
  // inferred facts the extraction signals are the most informative input.
379
477
  // Precedence: explicit > LLM signal > default.
@@ -421,33 +519,124 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
421
519
  // in the same batch claimed the target first. Surfaced via openThreads so
422
520
  // the user knows their contradiction signal was partially lost.
423
521
  const droppedSupersessions = [];
522
+ const pendingRelations = [];
523
+ let keptAlongside = 0;
524
+ const recordedProject = (sessionId) => {
525
+ if (!sessionId)
526
+ return null;
527
+ return projectBySession.get(sessionId) ?? null;
528
+ };
424
529
  // toIntegrate is ordered by capture time (classifyFacts preserves input order).
425
530
  // First candidate to claim an existing fact wins — temporal priority.
531
+ // The candidate pool is the domain scan. The project each fact was
532
+ // recorded in is evidence on the decision, not a filter on that pool.
426
533
  for (const item of toIntegrate) {
427
- // Supersession is domain-scoped. FTS5 is the wrong tool here: it fails
428
- // when the new fact contains negation tokens ("no longer", "stopped")
429
- // that don't appear in the old fact. Use cached domain scan instead.
534
+ const sessionFact = sessionFactMap.get(item.sessionFactId);
430
535
  const candidates = await getDomainFacts(item.domain);
431
- const candidate = { id: item.sessionFactId, content: item.content, domain: item.domain, subdomain: item.subdomain };
432
- const result = await intelligence.detectSupersession(candidate, candidates);
536
+ const factProject = recordedProject(sessionFact?.session_id);
537
+ const verdicts = new Map();
538
+ const projects = new Map();
539
+ for (const existing of candidates) {
540
+ const candidateProject = recordedProject(existing.session_id);
541
+ verdicts.set(existing.id, projectRelation(factProject, candidateProject));
542
+ projects.set(existing.id, projectKey(candidateProject));
543
+ }
544
+ const context = {
545
+ project: projectKey(factProject),
546
+ verdicts,
547
+ projects,
548
+ };
549
+ const candidate = {
550
+ id: item.sessionFactId,
551
+ content: item.content,
552
+ domain: item.domain,
553
+ subdomain: item.subdomain,
554
+ };
555
+ const result = await intelligence.detectSupersession(candidate, candidates, context);
433
556
  // Intentional: confidence is NOT compared here. A low-confidence new fact
434
557
  // with a clear negation marker ("I no longer prefer X") can supersede a
435
558
  // high-confidence prior. The negation signal is itself strong evidence
436
559
  // of a belief update; requiring confidence parity would make it impossible
437
560
  // for tentative corrections to update stale knowledge.
438
- if (result) {
439
- if (!alreadySuperseded.has(result.existingFactId)) {
440
- supersessionMap.set(item.sessionFactId, result.existingFactId);
441
- alreadySuperseded.add(result.existingFactId);
561
+ const decidedBy = context.answeredBy ?? result?.source_quality ?? null;
562
+ const proposedId = result?.existingFactId;
563
+ const proposedVerdict = proposedId ? verdicts.get(proposedId) : undefined;
564
+ if (result && proposedId) {
565
+ const basis = result.basis;
566
+ const accept = basis === "coexists" ? false
567
+ : basis === "uncertain" ? false
568
+ : proposedVerdict !== "different" ? true
569
+ : basis === "update" ? true
570
+ : NEGATION_WORDS.test(item.content);
571
+ const related = candidates.find((c) => c.id === proposedId);
572
+ const reason = result.reason.trim() !== "" ? result.reason : "no reason returned";
573
+ if (accept) {
574
+ if (!alreadySuperseded.has(proposedId)) {
575
+ supersessionMap.set(item.sessionFactId, proposedId);
576
+ alreadySuperseded.add(proposedId);
577
+ pendingRelations.push({
578
+ sessionFactId: item.sessionFactId,
579
+ kind: "supersedes",
580
+ relatedFactId: proposedId,
581
+ verdict: proposedVerdict ?? "not_comparable",
582
+ basis: basis ?? null,
583
+ reason,
584
+ decidedBy,
585
+ factProject,
586
+ candidateProject: recordedProject(related?.session_id),
587
+ });
588
+ }
589
+ else {
590
+ droppedSupersessions.push({
591
+ newContent: item.content,
592
+ targetedContent: related?.content ?? proposedId,
593
+ });
594
+ }
442
595
  }
443
596
  else {
444
- // Another candidate already claimed this target. This candidate will
445
- // integrate as a plain insert rather than a supersession — record the
446
- // conflict so it can surface in openThreads.
447
- const targeted = candidates.find((c) => c.id === result.existingFactId);
448
- droppedSupersessions.push({
449
- newContent: item.content,
450
- targetedContent: targeted?.content ?? result.existingFactId,
597
+ keptAlongside += 1;
598
+ pendingRelations.push({
599
+ sessionFactId: item.sessionFactId,
600
+ kind: "kept_alongside",
601
+ relatedFactId: proposedId,
602
+ verdict: proposedVerdict ?? "not_comparable",
603
+ basis: basis ?? null,
604
+ reason,
605
+ decidedBy,
606
+ factProject,
607
+ candidateProject: recordedProject(related?.session_id),
608
+ });
609
+ }
610
+ }
611
+ if (proposedVerdict !== "different") {
612
+ let best = null;
613
+ for (const existing of candidates) {
614
+ if (existing.id === proposedId)
615
+ continue;
616
+ if (verdicts.get(existing.id) !== "different")
617
+ continue;
618
+ const similarity = jaccardSimilarity(item.content, existing.content);
619
+ if (similarity < SUPERSESSION_JACCARD_MIN)
620
+ continue;
621
+ if (!best || similarity > best.similarity)
622
+ best = { id: existing.id, similarity };
623
+ }
624
+ if (best) {
625
+ const related = candidates.find((c) => c.id === best.id);
626
+ const pct = (best.similarity * 100).toFixed(0);
627
+ let reason = `no supersession proposed; overlap ${pct}%`;
628
+ if (NEGATION_WORDS.test(item.content))
629
+ reason += "; lexical trigger fired";
630
+ pendingRelations.push({
631
+ sessionFactId: item.sessionFactId,
632
+ kind: "overlap_noted",
633
+ relatedFactId: best.id,
634
+ verdict: "different",
635
+ basis: null,
636
+ reason,
637
+ decidedBy,
638
+ factProject,
639
+ candidateProject: recordedProject(related?.session_id),
451
640
  });
452
641
  }
453
642
  }
@@ -458,6 +647,7 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
458
647
  const writeResults = await withTransaction(db, async () => {
459
648
  let entitiesCreated = 0;
460
649
  let entitiesLinked = 0;
650
+ const factIdBySessionFact = new Map();
461
651
  // Ensure all unique domains exist once, before the per-fact loop
462
652
  const uniqueDomains = new Set(toIntegrate.map((item) => item.domain));
463
653
  for (const domain of uniqueDomains) {
@@ -523,6 +713,7 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
523
713
  valid_from: validFrom,
524
714
  });
525
715
  integratedFacts.push(integratedFact);
716
+ factIdBySessionFact.set(item.sessionFactId, integratedFact.id);
526
717
  // Link entities
527
718
  const extractedEntities = entityMap.get(item.sessionFactId);
528
719
  if (extractedEntities) {
@@ -599,6 +790,71 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
599
790
  entitiesLinked++;
600
791
  }
601
792
  }
793
+ const relations = [];
794
+ for (const rel of pendingRelations) {
795
+ const factId = factIdBySessionFact.get(rel.sessionFactId);
796
+ if (!factId)
797
+ continue;
798
+ await insertFactRelation(db, {
799
+ consolidationId,
800
+ factId,
801
+ relatedFactId: rel.relatedFactId,
802
+ sessionFactId: rel.sessionFactId,
803
+ kind: rel.kind,
804
+ contextVerdict: rel.verdict,
805
+ factProject: rel.factProject,
806
+ candidateProject: rel.candidateProject,
807
+ basis: rel.basis,
808
+ reason: rel.reason,
809
+ decidedBy: rel.decidedBy,
810
+ });
811
+ relations.push({
812
+ kind: rel.kind,
813
+ fact_id: factId,
814
+ related_fact_id: rel.relatedFactId,
815
+ context_verdict: rel.verdict,
816
+ reason: rel.reason,
817
+ });
818
+ }
819
+ const writeCorroboration = async (row) => {
820
+ await insertFactRelation(db, {
821
+ consolidationId,
822
+ factId: row.factId,
823
+ relatedFactId: null,
824
+ sessionFactId: row.sessionFactId,
825
+ kind: "corroborated_by",
826
+ contextVerdict: row.verdict,
827
+ factProject: row.factProject,
828
+ candidateProject: row.candidateProject,
829
+ basis: null,
830
+ reason: row.reason,
831
+ decidedBy: null,
832
+ });
833
+ relations.push({
834
+ kind: "corroborated_by",
835
+ fact_id: row.factId,
836
+ related_fact_id: null,
837
+ context_verdict: row.verdict,
838
+ reason: row.reason,
839
+ });
840
+ };
841
+ for (const twin of batchTwins) {
842
+ const factId = factIdBySessionFact.get(twin.winnerSessionFactId);
843
+ if (!factId)
844
+ continue;
845
+ const winner = sessionFactMap.get(twin.winnerSessionFactId);
846
+ const loser = sessionFactMap.get(twin.loserSessionFactId);
847
+ await writeCorroboration({
848
+ factId,
849
+ sessionFactId: twin.loserSessionFactId,
850
+ verdict: "different",
851
+ factProject: projectOf(winner?.session_id),
852
+ candidateProject: projectOf(loser?.session_id),
853
+ reason: "restatement",
854
+ });
855
+ }
856
+ for (const twin of absorbedTwins)
857
+ await writeCorroboration(twin);
602
858
  // Apply enrich decisions — boost existing facts' confidence (capped at 1.0)
603
859
  // for each paraphrase/corroboration the LLM identified.
604
860
  const enrichStmt = db.prepare(`UPDATE facts SET confidence = MIN(1.0, confidence + ?) WHERE id = ?`);
@@ -612,7 +868,7 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
612
868
  summary, open_threads, last_event_sequence, created_at)
613
869
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(consolidationId, recordSessionId, sessionFacts.length, toIntegrate.length, rejected, entitiesCreated, entitiesLinked, supersessionCount, null, // summary filled below
614
870
  null, effectiveWatermark, new Date().toISOString());
615
- return { entitiesCreated, entitiesLinked };
871
+ return { entitiesCreated, entitiesLinked, relations };
616
872
  });
617
873
  phaseDCommitted = true;
618
874
  // Phase E: embed the facts that just integrated, if semantic search is on.
@@ -694,6 +950,10 @@ embeddingProvider = null, steps = ALL_STEPS, caller = {}) {
694
950
  entitiesCreated: writeResults.entitiesCreated,
695
951
  entitiesLinked: writeResults.entitiesLinked,
696
952
  supersessions: supersessionCount,
953
+ keptAlongside,
954
+ corroborations: writeResults.relations.filter((row) => row.kind === "corroborated_by")
955
+ .length,
956
+ relations: writeResults.relations,
697
957
  eventsCopied,
698
958
  eventsRemaining: await remainingEvents(),
699
959
  embedding,