@seanhogg/builderforce-memory 2026.10.68 → 2026.10.70

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/dist/knowledge/build.d.ts.map +1 -1
  2. package/dist/knowledge/build.js +7 -2
  3. package/dist/knowledge/build.js.map +1 -1
  4. package/dist/knowledge/comparability.d.ts +3 -1
  5. package/dist/knowledge/comparability.d.ts.map +1 -1
  6. package/dist/knowledge/comparability.js +2 -1
  7. package/dist/knowledge/comparability.js.map +1 -1
  8. package/dist/knowledge/index.d.ts +3 -2
  9. package/dist/knowledge/index.d.ts.map +1 -1
  10. package/dist/knowledge/index.js +2 -1
  11. package/dist/knowledge/index.js.map +1 -1
  12. package/dist/knowledge/model.d.ts +17 -1
  13. package/dist/knowledge/model.d.ts.map +1 -1
  14. package/dist/knowledge/pack/encode.d.ts +2 -1
  15. package/dist/knowledge/pack/encode.d.ts.map +1 -1
  16. package/dist/knowledge/pack/encode.js +2 -1
  17. package/dist/knowledge/pack/encode.js.map +1 -1
  18. package/dist/knowledge/pack/extrDiff.d.ts.map +1 -1
  19. package/dist/knowledge/pack/extrDiff.js +4 -1
  20. package/dist/knowledge/pack/extrDiff.js.map +1 -1
  21. package/dist/knowledge/pack/sections/columns.d.ts +15 -2
  22. package/dist/knowledge/pack/sections/columns.d.ts.map +1 -1
  23. package/dist/knowledge/pack/sections/columns.js +16 -1
  24. package/dist/knowledge/pack/sections/columns.js.map +1 -1
  25. package/dist/knowledge/pack/sections/extrLists.js +2 -2
  26. package/dist/knowledge/pack/sections/extrLists.js.map +1 -1
  27. package/dist/knowledge/pack/sections/facts.d.ts.map +1 -1
  28. package/dist/knowledge/pack/sections/facts.js +2 -2
  29. package/dist/knowledge/pack/sections/facts.js.map +1 -1
  30. package/dist/knowledge/pack/sections/index.d.ts +1 -0
  31. package/dist/knowledge/pack/sections/index.d.ts.map +1 -1
  32. package/dist/knowledge/pack/sections/index.js +3 -1
  33. package/dist/knowledge/pack/sections/index.js.map +1 -1
  34. package/dist/knowledge/pack/sections/rows.d.ts +1 -0
  35. package/dist/knowledge/pack/sections/rows.d.ts.map +1 -1
  36. package/dist/knowledge/pack/sections/rows.js +1 -1
  37. package/dist/knowledge/pack/sections/rows.js.map +1 -1
  38. package/dist/knowledge/pack/sections/sites.d.ts +24 -0
  39. package/dist/knowledge/pack/sections/sites.d.ts.map +1 -0
  40. package/dist/knowledge/pack/sections/sites.js +96 -0
  41. package/dist/knowledge/pack/sections/sites.js.map +1 -0
  42. package/dist/knowledge/pack/types.d.ts +2 -2
  43. package/dist/knowledge/pack/types.d.ts.map +1 -1
  44. package/dist/knowledge/sources.d.ts +1 -1
  45. package/dist/knowledge/sources.d.ts.map +1 -1
  46. package/dist/knowledge/sources.js +2 -1
  47. package/dist/knowledge/sources.js.map +1 -1
  48. package/dist/knowledge/symbolEdges.d.ts +39 -0
  49. package/dist/knowledge/symbolEdges.d.ts.map +1 -0
  50. package/dist/knowledge/symbolEdges.js +71 -0
  51. package/dist/knowledge/symbolEdges.js.map +1 -0
  52. package/dist/knowledge/truncate.d.ts.map +1 -1
  53. package/dist/knowledge/truncate.js +4 -0
  54. package/dist/knowledge/truncate.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/contract/exports.snapshot.json +7 -0
  57. package/src/contract/regression.analysisTruncated.test.ts +32 -0
  58. package/src/contract/regression.symbolEdges.test.ts +323 -0
  59. package/src/contract/symbolEdges.golden.json +345 -0
  60. package/src/contract/types.contract.test.ts +15 -2
  61. package/src/knowledge/build.ts +7 -2
  62. package/src/knowledge/comparability.analysis.test.ts +16 -1
  63. package/src/knowledge/comparability.ts +4 -1
  64. package/src/knowledge/index.ts +6 -2
  65. package/src/knowledge/model.ts +18 -1
  66. package/src/knowledge/pack/encode.ts +2 -1
  67. package/src/knowledge/pack/extrDiff.ts +4 -1
  68. package/src/knowledge/pack/sections/columns.ts +16 -1
  69. package/src/knowledge/pack/sections/extrLists.ts +2 -2
  70. package/src/knowledge/pack/sections/facts.ts +2 -2
  71. package/src/knowledge/pack/sections/index.ts +3 -1
  72. package/src/knowledge/pack/sections/rows.ts +1 -1
  73. package/src/knowledge/pack/sections/sites.ts +87 -0
  74. package/src/knowledge/pack/types.ts +2 -2
  75. package/src/knowledge/sources.ts +2 -1
  76. package/src/knowledge/symbolEdges.ts +72 -0
  77. package/src/knowledge/truncate.ts +3 -1
@@ -0,0 +1,39 @@
1
+ /**
2
+ * knowledge/symbolEdges.ts — the symbol-level relationship vocabulary (PRD 43 P0b, B1a rules 9–10): what a code
3
+ * pack's extractor says between two SYMBOLS (a class, an interface, a function, a method), beside the file-level
4
+ * kinds (`references`, `contains` …). Generic: memory names the kinds and their call-site shape; which language
5
+ * construct counts as which kind is the code pack's business.
6
+ *
7
+ * extends class/interface → the base it extends
8
+ * implements class → an interface it implements
9
+ * composes class → a class it holds as a field / property / constructor parameter property (composition, aggregation)
10
+ * uses symbol → a type it names in a signature or body (none of the above)
11
+ * calls function/method → a function/method it calls; carries its call {@link CallSite}s in source order
12
+ *
13
+ * A target outside the root (a package, a file not extracted) is still a `src:` ref, so `buildGraph` closes it as a
14
+ * `missing` placeholder, exactly as an unresolved import is.
15
+ *
16
+ * Bounded: {@link dedupeSymbolEdges} keeps ONE edge per (from, to, kind) — repeated calls become extra sites on it —
17
+ * and at most {@link MAX_SYMBOL_EDGES_PER_SYMBOL} edges and {@link MAX_CALL_SITES_PER_EDGE} sites per edge.
18
+ */
19
+ import type { CallSite, KEdge } from './model.js';
20
+ export declare const SYMBOL_EDGE_KINDS: readonly ['extends', 'implements', 'composes', 'uses', 'calls'];
21
+ export type SymbolEdgeKind = (typeof SYMBOL_EDGE_KINDS)[number];
22
+ /** Edges one symbol may start (all kinds together): a generated or god function must not flood the graph. */
23
+ export declare const MAX_SYMBOL_EDGES_PER_SYMBOL = 64;
24
+ /** Call sites kept on one `calls` edge (the lowest `order`s): a call in a hot loop body is a handful of sites, not hundreds. */
25
+ export declare const MAX_CALL_SITES_PER_EDGE = 16;
26
+ export declare const isSymbolEdgeKind: (kind: string) => kind is SymbolEdgeKind;
27
+ /** Sites in source order: by `order`, then position (a well-formed list already is). */
28
+ export declare const compareCallSites: (a: CallSite, b: CallSite) => number;
29
+ /**
30
+ * ONE edge per (from, to, kind): weights take the max, sites merge (sorted by {@link compareCallSites}, capped at
31
+ * `maxSites`). Edges of a `from` past `maxPerSymbol` are dropped — the first ones kept, in input order, so an
32
+ * extractor that emits a body's relations in source order keeps the earliest. Non-symbol kinds pass through unchanged
33
+ * and uncounted. Order of the result: first appearance. Pure.
34
+ */
35
+ export declare function dedupeSymbolEdges(edges: readonly KEdge[], opts?: {
36
+ maxPerSymbol?: number;
37
+ maxSites?: number;
38
+ }): KEdge[];
39
+ //# sourceMappingURL=symbolEdges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbolEdges.d.ts","sourceRoot":"","sources":["../../src/knowledge/symbolEdges.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,iBAAiB,YAAI,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AACjG,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,6GAA6G;AAC7G,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAC9C,gIAAgI;AAChI,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,eAAO,MAAM,gBAAgB,SAAU,MAAM,KAAG,IAAI,IAAI,cAAyE,CAAC;AAElI,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,MAAO,QAAQ,KAAK,QAAQ,KAAG,MACuD,CAAC;AAEpH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,SAAS,KAAK,EAAE,EAAE,IAAI,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GACjF,KAAK,EAAE,CA4BT"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * knowledge/symbolEdges.ts — the symbol-level relationship vocabulary (PRD 43 P0b, B1a rules 9–10): what a code
3
+ * pack's extractor says between two SYMBOLS (a class, an interface, a function, a method), beside the file-level
4
+ * kinds (`references`, `contains` …). Generic: memory names the kinds and their call-site shape; which language
5
+ * construct counts as which kind is the code pack's business.
6
+ *
7
+ * extends class/interface → the base it extends
8
+ * implements class → an interface it implements
9
+ * composes class → a class it holds as a field / property / constructor parameter property (composition, aggregation)
10
+ * uses symbol → a type it names in a signature or body (none of the above)
11
+ * calls function/method → a function/method it calls; carries its call {@link CallSite}s in source order
12
+ *
13
+ * A target outside the root (a package, a file not extracted) is still a `src:` ref, so `buildGraph` closes it as a
14
+ * `missing` placeholder, exactly as an unresolved import is.
15
+ *
16
+ * Bounded: {@link dedupeSymbolEdges} keeps ONE edge per (from, to, kind) — repeated calls become extra sites on it —
17
+ * and at most {@link MAX_SYMBOL_EDGES_PER_SYMBOL} edges and {@link MAX_CALL_SITES_PER_EDGE} sites per edge.
18
+ */
19
+ export const SYMBOL_EDGE_KINDS = ['extends', 'implements', 'composes', 'uses', 'calls'];
20
+ /** Edges one symbol may start (all kinds together): a generated or god function must not flood the graph. */
21
+ export const MAX_SYMBOL_EDGES_PER_SYMBOL = 64;
22
+ /** Call sites kept on one `calls` edge (the lowest `order`s): a call in a hot loop body is a handful of sites, not hundreds. */
23
+ export const MAX_CALL_SITES_PER_EDGE = 16;
24
+ export const isSymbolEdgeKind = (kind) => SYMBOL_EDGE_KINDS.includes(kind);
25
+ /** Sites in source order: by `order`, then position (a well-formed list already is). */
26
+ export const compareCallSites = (a, b) => a.order - b.order || (a.path < b.path ? -1 : a.path > b.path ? 1 : 0) || a.line - b.line || a.column - b.column;
27
+ /**
28
+ * ONE edge per (from, to, kind): weights take the max, sites merge (sorted by {@link compareCallSites}, capped at
29
+ * `maxSites`). Edges of a `from` past `maxPerSymbol` are dropped — the first ones kept, in input order, so an
30
+ * extractor that emits a body's relations in source order keeps the earliest. Non-symbol kinds pass through unchanged
31
+ * and uncounted. Order of the result: first appearance. Pure.
32
+ */
33
+ export function dedupeSymbolEdges(edges, opts = {}) {
34
+ const maxPerSymbol = opts.maxPerSymbol ?? MAX_SYMBOL_EDGES_PER_SYMBOL;
35
+ const maxSites = opts.maxSites ?? MAX_CALL_SITES_PER_EDGE;
36
+ const out = [];
37
+ const byId = new Map();
38
+ const perFrom = new Map();
39
+ for (const e of edges) {
40
+ if (!isSymbolEdgeKind(e.kind)) {
41
+ out.push(e);
42
+ continue;
43
+ }
44
+ const id = `${e.from}\u0000${e.to}\u0000${e.kind}`;
45
+ const prior = byId.get(id);
46
+ if (prior) {
47
+ prior.weight = Math.max(prior.weight, e.weight);
48
+ if (e.sites?.length)
49
+ prior.sites = [...(prior.sites ?? []), ...e.sites];
50
+ continue;
51
+ }
52
+ const n = perFrom.get(e.from) ?? 0;
53
+ if (n >= maxPerSymbol)
54
+ continue;
55
+ perFrom.set(e.from, n + 1);
56
+ const copy = { ...e, ...(e.sites ? { sites: [...e.sites] } : {}) };
57
+ byId.set(id, copy);
58
+ out.push(copy);
59
+ }
60
+ for (const e of out) {
61
+ if (!e.sites)
62
+ continue;
63
+ if (e.sites.length === 0) {
64
+ delete e.sites;
65
+ continue;
66
+ }
67
+ e.sites = e.sites.sort(compareCallSites).slice(0, maxSites);
68
+ }
69
+ return out;
70
+ }
71
+ //# sourceMappingURL=symbolEdges.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbolEdges.js","sourceRoot":"","sources":["../../src/knowledge/symbolEdges.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU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C;YAAC,OAAO,CAAC,CAAC,KAAK,CAAC;YAAC,SAAS;QAAC,CAAC;QACvD,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"truncate.d.ts","sourceRoot":"","sources":["../../src/knowledge/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAe,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAIrF,8DAA8D;AAC9D,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC,sFAAsF;AACtF,eAAO,MAAM,eAAe,aAAa,CAAC;AAI1C,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,SAAS,OAAO,EAAE,CAAC;IAC1B,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;CAC/B;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,eAAe,GAAG;IAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAAC,KAAK,EAAE,KAAK,EAAE,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CA8E9H"}
1
+ {"version":3,"file":"truncate.d.ts","sourceRoot":"","sources":["../../src/knowledge/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAe,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAKrF,8DAA8D;AAC9D,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC,sFAAsF;AACtF,eAAO,MAAM,eAAe,aAAa,CAAC;AAI1C,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,SAAS,OAAO,EAAE,CAAC;IAC1B,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;CAC/B;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,eAAe,GAAG;IAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAAC,KAAK,EAAE,KAAK,EAAE,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CA+E9H"}
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { areaImportance, byImportanceAssetsLast } from './importance.js';
10
10
  import { aboutTargets, compareStr, FALLBACK_PACK_ID, pathOfRef, srcRef } from './refs.js';
11
+ import { isSymbolEdgeKind } from './symbolEdges.js';
11
12
  /** Hard cap on nodes, however many the keep rules ask for. */
12
13
  export const TRUNCATION_HARD_CAP = 2000;
13
14
  /** The area of folded nodes that are not under any source path (unanchored facts). */
@@ -24,7 +25,10 @@ export function truncateGraph(g, opts) {
24
25
  neighbours.set(a, (s = new Set()));
25
26
  s.add(b);
26
27
  };
28
+ // A symbol-level edge restates its file's import (the code pack's rollup): it never earns a neighbour a slot.
27
29
  for (const e of g.edges) {
30
+ if (isSymbolEdgeKind(e.kind))
31
+ continue;
28
32
  link(e.from, e.to);
29
33
  link(e.to, e.from);
30
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../src/knowledge/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAE1F,8DAA8D;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACxC,sFAAsF;AACtF,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC;AAE1C,MAAM,YAAY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,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACvD,CAAC;AAED,gEAAgE;AAChE,SAAS,UAAU,CAAC,MAAyC;IACzD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,MAAM;QAAE,IAAI,CAAC,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACrF,IAAI,IAAwB,CAAC;IAC7B,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAE;YAAE,IAAI,GAAG,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seanhogg/builderforce-memory",
3
- "version": "2026.10.68",
3
+ "version": "2026.10.70",
4
4
  "description": "BuilderForce Agent Memory — runtime layer. SSM execution, Transformer orchestration, online distillation, enterprise RAG (ingestion pipelines, vector-store adapters, tenant/ACL-scoped hybrid retrieval), multi-agent graph orchestration, LLM telemetry and cost accounting, persistent agent memory, and token-saving agent-run memory (code maps, a prompt-cache-safe working memory, chunked transcript windowing) for BuilderForce.ai agents.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -298,11 +298,13 @@
298
298
  "LINEAGE_MIN_JACCARD",
299
299
  "LINEAGE_MIN_MEMBERS",
300
300
  "LocalSnapshotStore",
301
+ "MAX_CALL_SITES_PER_EDGE",
301
302
  "MAX_CLAIM_TEXT_CHARS",
302
303
  "MAX_FINDING_NODES",
303
304
  "MAX_NODES_CAP",
304
305
  "MAX_QUOTE_CHARS",
305
306
  "MAX_QUOTE_LINES",
307
+ "MAX_SYMBOL_EDGES_PER_SYMBOL",
306
308
  "OUTLINE_BADGE_KEYS",
307
309
  "OUTLINE_FLAG_CYCLE",
308
310
  "OUTLINE_MAX_FILES",
@@ -314,6 +316,7 @@
314
316
  "REVIEW_RUN_FAILURE_CHUNK",
315
317
  "REVIEW_RUN_STEP_RING",
316
318
  "SECTION_INDEX_BADGE",
319
+ "SYMBOL_EDGE_KINDS",
317
320
  "Sha256",
318
321
  "TOP_LEVEL_FOLDER",
319
322
  "TRUNCATION_HARD_CAP",
@@ -341,6 +344,7 @@
341
344
  "communityTable",
342
345
  "comparable",
343
346
  "compareAnalysis",
347
+ "compareCallSites",
344
348
  "compareManifestKey",
345
349
  "compareStr",
346
350
  "components",
@@ -353,6 +357,7 @@
353
357
  "createKnowledgeIndex",
354
358
  "createModelLimiter",
355
359
  "crossesSystems",
360
+ "dedupeSymbolEdges",
356
361
  "defaultAnchorOf",
357
362
  "detectCommunities",
358
363
  "entityKey",
@@ -380,11 +385,13 @@
380
385
  "ignoreMatcher",
381
386
  "ignoreSourcesOf",
382
387
  "isAssetPath",
388
+ "isBinaryBytes",
383
389
  "isBinaryPath",
384
390
  "isBinaryText",
385
391
  "isDocumentPath",
386
392
  "isRateLimit",
387
393
  "isRootFilePath",
394
+ "isSymbolEdgeKind",
388
395
  "jobOf",
389
396
  "judgedManifestKey",
390
397
  "kindOfAnchor",
@@ -0,0 +1,32 @@
1
+ /**
2
+ * src/contract/regression.analysisTruncated.test.ts — a truncated code analysis is never comparable (PRD 41 B2, C9).
3
+ * Before `CodeAnalysisSnapshot.truncated` reached `analysisMeta`, a host had to wrap `compareAnalysis` to gate it; without
4
+ * the wrapper, an issue missing from a partial scan was reported as resolved.
5
+ */
6
+
7
+ import { compareAnalysis, normalizeAnalysis, isBinaryBytes, type CodeAnalysisSnapshot } from '../knowledge/index.js';
8
+
9
+ const TOOLS = [{ name: 'dependency-cruiser', version: '16.10.4' }, { name: 'jscpd', version: '4.0.5' }, { name: 'knip', version: '5.62.0' }];
10
+
11
+ const snapshot = (files: string[], truncated?: true): CodeAnalysisSnapshot => ({
12
+ version: 1, id: 'scan', capturedAt: '2026-11-10T12:00:00.000Z', source: { branch: 'main', commit: 'abc', dirty: false },
13
+ tools: TOOLS.map((t) => ({ ...t, status: 'complete' as const })),
14
+ ...normalizeAnalysis({ modules: [] }, { duplicates: [] }, { files, issues: [] }),
15
+ ...(truncated ? { truncated } : {}),
16
+ });
17
+
18
+ describe('regression: truncated code analysis', () => {
19
+ it('regression: a truncated after-side against a full baseline reported the files it never reached as resolved', () => {
20
+ const result = compareAnalysis(snapshot(['a.ts'], true), snapshot(['a.ts', 'b.ts']));
21
+ expect(result).toMatchObject({ comparable: false, reasons: ['truncated'], added: [], resolved: [] });
22
+ expect(result.unchanged.map((i) => i.id)).toEqual(['unused-file:a.ts']);
23
+ });
24
+
25
+ it('regression: the binary rule hosts restated (a NUL in the first 8192 bytes) is exported as isBinaryBytes', () => {
26
+ const edge = new Uint8Array(9000).fill(0x61);
27
+ edge[8191] = 0;
28
+ expect(isBinaryBytes(edge)).toBe(true);
29
+ edge[8191] = 0x61; edge[8192] = 0;
30
+ expect(isBinaryBytes(edge)).toBe(false);
31
+ });
32
+ });
@@ -0,0 +1,323 @@
1
+ /**
2
+ * src/contract/regression.symbolEdges.test.ts — the symbol-level edge kinds (PRD 43 P0b): `extends`, `implements`,
3
+ * `composes`, `uses`, `calls` (with call sites). One `regression:` test per kind, the pack round trip, and the
4
+ * compatibility proof in both directions:
5
+ *
6
+ * - BACKWARD: a pack written before this change (edge kinds as the 11 legacy codes, no SITE section) decodes to the
7
+ * same pack, and re-encodes to the same bytes;
8
+ * - FORWARD: a pack written now decodes under a reader of before this change — the new kinds are written as strings
9
+ * (never as codes 12+ that reader refuses) and the SITE section is a new tag that reader skips.
10
+ */
11
+
12
+ import { readFileSync } from 'node:fs';
13
+ import { join } from 'node:path';
14
+ import { readFrame, writeFrame, writeSection } from '../knowledge/pack/frame.js';
15
+ import { TAG } from '../knowledge/pack/sections/index.js';
16
+ import { EDGE_KINDS, WRITTEN_EDGE_KINDS } from '../knowledge/pack/sections/columns.js';
17
+ import { writeKeys, writeNodes } from '../knowledge/pack/sections/extrLists.js';
18
+ import { collector, readStringTable, tablesOf, writeHashTable, writeStringTable, type Tables } from '../knowledge/pack/strings.js';
19
+ import { ByteReader, ByteWriter } from '../knowledge/pack/varint.js';
20
+ import { applyEntryDiff, decodePack, diffEntry, encodePack, ZERO_DIGEST, type Pack } from '../knowledge/pack/index.js';
21
+ import { buildGraph, truncateGraph, dedupeSymbolEdges, SYMBOL_EDGE_KINDS, type CallSite, type Extracted, type KEdge, type NodeRef } from '../knowledge/index.js';
22
+
23
+ const H1 = 'a'.repeat(64), H2 = 'b'.repeat(64);
24
+ const HEAD = { rootId: 'r', baseGeneration: 0, targetDigest: ZERO_DIGEST };
25
+ const FILE = 'src:r::src/a.ts' as NodeRef;
26
+ const sym = (name: string, line: number, path = 'src/a.ts') => `src:r::${path}#${name}@${line}` as NodeRef;
27
+ const site = (line: number, column: number, order: number, path = 'src/a.ts'): CallSite => ({ path, line, column, order });
28
+
29
+ /** The 11 kinds a reader of before 2026-11-10 knows as codes (index + 1); a higher code makes it throw. */
30
+ const LEGACY_EDGE_KINDS = [
31
+ 'references', 'links', 'contains', 'mentions', 'duplicate', 'near-duplicate', 'contradicts', 'agrees', 'supersedes', 'about', 'co-changed',
32
+ ];
33
+
34
+ function extraction(edges: KEdge[]): Extracted {
35
+ return {
36
+ sourceRef: FILE, sourceHash: H1,
37
+ nodes: [{ ref: FILE, kind: 'file', label: 'a.ts', pack: 'code', importance: 0.5, origin: 'extracted', sourceHash: H1 }],
38
+ edges, keys: [{ ref: FILE, key: 'a.ts' }],
39
+ };
40
+ }
41
+ const packOf = (edges: KEdge[]): Pack => ({ ...HEAD, extracted: [{ kind: 'full', hash: H1, entries: [extraction(edges)] }] });
42
+ const edge = (from: NodeRef, to: NodeRef, kind: string, sites?: CallSite[]): KEdge =>
43
+ ({ from, to, kind, weight: 1, origin: 'extracted', ...(sites ? { sites } : {}) });
44
+
45
+ async function sectionsOf(bytes: Uint8Array): Promise<Map<number, Uint8Array>> {
46
+ const { stored } = readFrame(bytes);
47
+ const r = new ByteReader(stored);
48
+ const out = new Map<number, Uint8Array>();
49
+ while (!r.done) { const tag = r.u8(); out.set(tag, r.bytes(r.varint())); }
50
+ return out;
51
+ }
52
+ const stringsOf = (sections: Map<number, Uint8Array>): string[] => readStringTable(sections.get(TAG.STR)!, 1e5, 1e7);
53
+
54
+ async function roundTrip(pack: Pack): Promise<Pack> {
55
+ return decodePack(await encodePack(pack));
56
+ }
57
+
58
+ describe('regression: symbol-level edge kinds', () => {
59
+ it('regression: an `extends` edge (class → its base) survives the pack and is written as a string an older reader decodes', async () => {
60
+ const e = edge(sym('Repo', 3), sym('BaseRepo', 1, 'src/base.ts'), 'extends');
61
+ const back = await roundTrip(packOf([e]));
62
+ expect((back.extracted![0]!.entries[0] as Extracted).edges).toEqual([e]);
63
+ expect(stringsOf(await sectionsOf(await encodePack(packOf([e]), { deflate: false })))).toContain('extends');
64
+ });
65
+
66
+ it('regression: an `implements` edge (class → interface) survives the pack', async () => {
67
+ const e = edge(sym('Repo', 3), sym('Store', 1, 'src/store.ts'), 'implements');
68
+ expect(((await roundTrip(packOf([e]))).extracted![0]!.entries[0] as Extracted).edges).toEqual([e]);
69
+ });
70
+
71
+ it('regression: a `composes` edge (class → the class of a field) survives the pack', async () => {
72
+ const e = edge(sym('Service', 5), sym('Repo', 3), 'composes');
73
+ expect(((await roundTrip(packOf([e]))).extracted![0]!.entries[0] as Extracted).edges).toEqual([e]);
74
+ });
75
+
76
+ it('regression: a `uses` edge (symbol → a type it names) survives the pack', async () => {
77
+ const e = edge(sym('Service.load', 9), sym('Row', 1, 'src/types.ts'), 'uses');
78
+ expect(((await roundTrip(packOf([e]))).extracted![0]!.entries[0] as Extracted).edges).toEqual([e]);
79
+ });
80
+
81
+ it('regression: a `calls` edge keeps EVERY call site — repeats included — with path, line, column and order', async () => {
82
+ const sites = [site(10, 5, 0), site(12, 9, 2), site(14, 9, 3)];
83
+ const other = [site(11, 5, 1)];
84
+ const edges = [
85
+ edge(sym('Service.load', 9), sym('Repo.get', 4), 'calls', sites),
86
+ edge(sym('Service.load', 9), sym('missing', 0, 'node_modules/zod'), 'calls', other),
87
+ edge(sym('Service.load', 9), sym('Row', 1, 'src/types.ts'), 'uses'),
88
+ ];
89
+ const back = (await roundTrip(packOf(edges))).extracted![0]!.entries[0] as Extracted;
90
+ expect(back.edges).toEqual(edges);
91
+ // The caller's calls in source order: the order index interleaves the two callees.
92
+ const ordered = back.edges.flatMap((e) => (e.sites ?? []).map((s) => [s.order, e.to] as const)).sort((a, b) => a[0] - b[0]);
93
+ expect(ordered.map(([o]) => o)).toEqual([0, 1, 2, 3]);
94
+ });
95
+ });
96
+
97
+ describe('symbol edges: pack round trip', () => {
98
+ const edges = SYMBOL_EDGE_KINDS.map((kind, i) => edge(sym(`S${i}`, i + 1), sym(`T${i}`, 1, 'src/t.ts'), kind, kind === 'calls' ? [site(3, 1, 0), site(4, 7, 1)] : undefined));
99
+
100
+ it('encode → decode keeps every new kind and the call sites, deflated or plain, and re-encodes to the same bytes', async () => {
101
+ const pack = packOf([edge(FILE, 'src:r::src/t.ts' as NodeRef, 'references'), ...edges]);
102
+ for (const deflate of [true, false]) {
103
+ const bytes = await encodePack(pack, { deflate });
104
+ const back = await decodePack(bytes);
105
+ expect((back.extracted![0]!.entries[0] as Extracted).edges).toEqual(pack.extracted![0]!.entries[0]!.edges);
106
+ expect(Buffer.from(await encodePack(back, { deflate })).equals(Buffer.from(bytes))).toBe(true);
107
+ }
108
+ });
109
+
110
+ it('a diff entry carries the sites of the edges it adds', async () => {
111
+ const prior = extraction(edges.slice(0, 2));
112
+ const next: Extracted = { ...extraction([...edges.slice(0, 2), edge(sym('S9', 9), sym('T9', 2), 'calls', [site(9, 3, 0)])]), sourceHash: H2 };
113
+ const diff = diffEntry(prior, next)!;
114
+ const pack: Pack = { ...HEAD, extracted: [{ kind: 'full', hash: H1, entries: [prior] }, { kind: 'diff', hash: H2, prior: H1, entries: [diff] }] };
115
+ const back = await roundTrip(pack);
116
+ const backDiff = back.extracted!.find((x) => x.kind === 'diff')!.entries[0]!;
117
+ expect(applyEntryDiff(prior, backDiff as never)).toEqual(applyEntryDiff(prior, diff));
118
+ expect(applyEntryDiff(prior, backDiff as never).edges.at(-1)!.sites).toEqual([site(9, 3, 0)]);
119
+ });
120
+
121
+ it('regression: a malformed SITE section never rejects the pack — it decodes whole, without any sites', async () => {
122
+ const good = edge(sym('A', 1), sym('B', 2), 'calls', [site(1, 1, 0)]);
123
+ const other = edge(sym('A', 1), sym('C', 3), 'calls', [site(2, 1, 1)]);
124
+ const bytes = await encodePack(packOf([good, other]), { deflate: false });
125
+ const withSite = async (site: Uint8Array): Promise<Pack> => {
126
+ const sections = await sectionsOf(bytes);
127
+ sections.set(TAG.SITE, site);
128
+ const body = new ByteWriter();
129
+ for (const [tag, b] of sections) writeSection(body, tag, b);
130
+ const plain = body.finish();
131
+ return decodePack(writeFrame({ flags: 0, ...HEAD }, plain, plain));
132
+ };
133
+ const bad = (fill: (w: ByteWriter) => void): Uint8Array => { const w = new ByteWriter(); fill(w); return w.finish(); };
134
+ const variants = [
135
+ bad((w) => { w.varint(1); w.varint(0); w.varint(0); w.varint(7); w.varint(1); w.varint(0); w.varint(1); w.varint(1); w.varint(0); }), // no edge 7
136
+ // a VALID first group, then a repeat: nothing may be attached, not even the first
137
+ bad((w) => { w.varint(2); for (let g = 0; g < 2; g++) { w.varint(0); w.varint(0); w.varint(0); w.varint(1); w.varint(0); w.varint(1); w.varint(1); w.varint(0); } }),
138
+ bad((w) => { w.varint(1); w.varint(0); w.varint(0); w.varint(0); w.varint(0); }), // empty list
139
+ bad((w) => { w.varint(1); w.varint(0); w.varint(0); w.varint(0); w.varint(1); w.varint(99_999); w.varint(1); w.varint(1); w.varint(0); }), // bad STR index
140
+ bad((w) => { w.varint(5); }), // truncated
141
+ bad((w) => { w.varint(1); w.varint(0); w.varint(0); w.varint(0); w.varint(1); w.varint(0); w.varint(1); w.varint(1); w.varint(0); w.u8(7); }), // trailing byte
142
+ ];
143
+ for (const v of variants) {
144
+ const back = await withSite(v);
145
+ expect((back.extracted![0]!.entries[0] as Extracted).edges).toEqual([good, other].map(({ sites: _, ...e }) => e));
146
+ }
147
+ });
148
+
149
+ it('regression: an invalid site is dropped on write instead of refusing the pack', async () => {
150
+ const e = edge(sym('A', 1), sym('B', 2), 'calls', [site(1, 1, 0), { path: 'src/a.ts', line: -1, column: 1, order: 1 }, { path: 'src/a.ts', line: 2, column: 1.5, order: 2 }]);
151
+ const back = await roundTrip(packOf([e]));
152
+ expect((back.extracted![0]!.entries[0] as Extracted).edges[0]!.sites).toEqual([site(1, 1, 0)]);
153
+ const allBad = edge(sym('A', 1), sym('B', 2), 'calls', [{ path: 'src/a.ts', line: Number.NaN, column: 1, order: 0 }]);
154
+ expect((((await roundTrip(packOf([allBad]))).extracted![0]!.entries[0]) as Extracted).edges[0]!.sites).toBeUndefined();
155
+ });
156
+
157
+ it('regression: a diff where only an edge\'s sites change carries the new sites (SITE in a diff entry)', async () => {
158
+ const before = edge(sym('A.run', 3), sym('B.get', 2), 'calls', [site(4, 5, 0)]);
159
+ const afterSites = [site(4, 5, 0), site(6, 9, 2)];
160
+ const prior = extraction([edge(sym('A', 1), sym('B', 1), 'extends'), before]);
161
+ const next: Extracted = { ...extraction([edge(sym('A', 1), sym('B', 1), 'extends'), { ...before, sites: afterSites }]), sourceHash: H2 };
162
+ const diff = diffEntry(prior, next)!;
163
+ expect(diff.edges.remove).toHaveLength(1);
164
+ expect(diff.edges.add.map((a) => a.item.sites)).toEqual([afterSites]);
165
+ const back = await roundTrip({ ...HEAD, extracted: [{ kind: 'full', hash: H1, entries: [prior] }, { kind: 'diff', hash: H2, prior: H1, entries: [diff] }] });
166
+ const backDiff = back.extracted!.find((x) => x.kind === 'diff')!.entries[0]!;
167
+ expect(applyEntryDiff(prior, backDiff as never).edges).toEqual(next.edges);
168
+ });
169
+
170
+ it('regression: `sites: []` and absent `sites` are the same edge to diffEntry (no spurious remove/add)', () => {
171
+ const a = edge(sym('A', 1), sym('B', 2), 'calls');
172
+ const prior = extraction([{ ...a, sites: [] }]);
173
+ const next: Extracted = { ...extraction([a]), sourceHash: H2 };
174
+ const diff = diffEntry(prior, next)!;
175
+ expect(diff.edges).toEqual({ remove: [], add: [] });
176
+ });
177
+ });
178
+
179
+ describe('symbol edges: compatibility', () => {
180
+ it('the writer codes only the 11 legacy kinds; the reader knows the symbol kinds after them, append-only', () => {
181
+ expect(WRITTEN_EDGE_KINDS).toEqual(LEGACY_EDGE_KINDS);
182
+ expect(EDGE_KINDS.slice(0, 11)).toEqual(LEGACY_EDGE_KINDS);
183
+ expect(EDGE_KINDS.slice(11)).toEqual([...SYMBOL_EDGE_KINDS]);
184
+ });
185
+
186
+ it('BACKWARD: a pack written before this change (legacy codes, no SITE section) decodes identically and re-encodes to its bytes', async () => {
187
+ const legacy = [edge(FILE, 'src:r::src/b.ts' as NodeRef, 'references'), edge(FILE, 'src:r::src/c.ts' as NodeRef, 'co-changed'), edge(FILE, 'src:r::x' as NodeRef, 'custom-kind')];
188
+ const x = extraction(legacy);
189
+ // EXTR as a writer of before 2026-11-10 wrote it, edge columns by hand from the legacy vocabulary.
190
+ const write = (t: Tables): Uint8Array => {
191
+ const w = new ByteWriter();
192
+ w.varint(1); w.u8(0); w.varint(t.hash(H1)); w.varint(1);
193
+ w.varint(t.str(x.sourceRef)); w.varint(t.hash(x.sourceHash)); w.u8(0);
194
+ writeNodes(w, t, x.nodes);
195
+ w.varint(legacy.length);
196
+ let prev = 0;
197
+ for (const e of legacy) { const i = t.str(e.from); const d = i - prev; w.varint(d >= 0 ? d * 2 : -d * 2 - 1); prev = i; }
198
+ for (const e of legacy) w.varint(t.str(e.to));
199
+ for (const e of legacy) { const at = LEGACY_EDGE_KINDS.indexOf(e.kind); if (at >= 0) w.varint(at + 1); else { w.varint(0); w.varint(t.str(e.kind)); } }
200
+ for (const e of legacy) w.num(e.weight);
201
+ for (const _ of legacy) w.u8(0); // origin 'extracted'
202
+ for (const _ of legacy) w.varint(0); // no optional fields
203
+ writeKeys(w, t, x.keys);
204
+ return w.finish();
205
+ };
206
+ const col = collector(); write(col);
207
+ const t = tablesOf(col.strings, col.hashes);
208
+ const body = new ByteWriter();
209
+ writeSection(body, TAG.STR, writeStringTable(t.strings));
210
+ writeSection(body, TAG.HASH, writeHashTable(t.hashes));
211
+ writeSection(body, TAG.EXTR, write(t));
212
+ const plain = body.finish();
213
+ const old = writeFrame({ flags: 0, ...HEAD }, plain, plain);
214
+
215
+ const back = await decodePack(old);
216
+ expect(back).toEqual(packOf(legacy));
217
+ expect(Buffer.from(await encodePack(back, { deflate: false })).equals(Buffer.from(old))).toBe(true);
218
+ });
219
+
220
+ it('FORWARD: a pack written now holds the symbol kinds as strings and its sites in a separate tag an older reader skips', async () => {
221
+ const edges = SYMBOL_EDGE_KINDS.map((kind, i) => edge(sym(`S${i}`, i + 1), sym(`T${i}`, 1), kind, kind === 'calls' ? [site(2, 4, 0)] : undefined));
222
+ const sections = await sectionsOf(await encodePack(packOf(edges), { deflate: false }));
223
+ expect(stringsOf(sections)).toEqual(expect.arrayContaining([...SYMBOL_EDGE_KINDS]));
224
+ expect(sections.has(TAG.SITE)).toBe(true);
225
+ // An older reader skips the SITE tag it does not know: the same pack, every edge and kind, without the sites.
226
+ sections.delete(TAG.SITE);
227
+ sections.set(99, new Uint8Array([1, 2, 3])); // and any other unknown tag, as it always has
228
+ const body = new ByteWriter();
229
+ for (const [tag, b] of sections) writeSection(body, tag, b);
230
+ const plain = body.finish();
231
+ const back = await decodePack(writeFrame({ flags: 0, ...HEAD }, plain, plain));
232
+ expect((back.extracted![0]!.entries[0] as Extracted).edges).toEqual(edges.map(({ sites: _, ...e }) => e));
233
+ });
234
+ });
235
+
236
+ /**
237
+ * Goldens produced by the REAL previous release (@seanhogg/builderforce-memory@2026.10.68, installed under the alias
238
+ * `memory-prev`): a pack its writer wrote and what its reader decoded; this release's pack and what 2026.10.68's reader
239
+ * decoded from those exact bytes. Regenerate only with that script, never by hand.
240
+ */
241
+ describe('symbol edges: compatibility against the published 2026.10.68 (goldens)', () => {
242
+ interface Golden {
243
+ prevVersion: string; prevPackHex: string; prevPackDecodedByPrev: Pack;
244
+ newPack: Pack; newPackHex: string; newPackDecodedByPrev: Pack;
245
+ }
246
+ const golden = JSON.parse(readFileSync(join(process.cwd(), 'src', 'contract', 'symbolEdges.golden.json'), 'utf8')) as Golden;
247
+ const bytes = (hex: string): Uint8Array => new Uint8Array(Buffer.from(hex, 'hex'));
248
+
249
+ it('BACKWARD (real): bytes written by 2026.10.68 decode here exactly as 2026.10.68 decoded them, and re-encode to the same bytes', async () => {
250
+ expect(golden.prevVersion).toBe('2026.10.68');
251
+ const back = await decodePack(bytes(golden.prevPackHex));
252
+ expect(back).toEqual(golden.prevPackDecodedByPrev);
253
+ expect(Buffer.from(await encodePack(back, { deflate: false })).toString('hex')).toBe(golden.prevPackHex);
254
+ });
255
+
256
+ it('FORWARD (real): this release still writes the exact bytes 2026.10.68 was proven to read — every edge and kind, the sites skipped', async () => {
257
+ expect(Buffer.from(await encodePack(golden.newPack, { deflate: false })).toString('hex')).toBe(golden.newPackHex);
258
+ // What the previous reader decoded is this release's decode with the sites (an unknown tag to it) left out.
259
+ const stripSites = (p: Pack): unknown => JSON.parse(JSON.stringify(p, (k, v) => (k === 'sites' ? undefined : v)));
260
+ expect(golden.newPackDecodedByPrev).toEqual(stripSites(await decodePack(bytes(golden.newPackHex))));
261
+ // And this release reads its own golden with the sites, including the diff entry whose only change is an edge's sites.
262
+ const diff = (await decodePack(bytes(golden.newPackHex))).extracted!.find((x) => x.kind === 'diff')!.entries[0] as { edges: { add: Array<{ item: KEdge }> } };
263
+ expect(diff.edges.add[0]!.item.sites).toHaveLength(2);
264
+ });
265
+ });
266
+
267
+ describe('symbol edges in buildGraph', () => {
268
+ const file = (path: string, partition?: string): Extracted => ({
269
+ sourceRef: `src:r::${path}` as NodeRef, sourceHash: H1, keys: [],
270
+ nodes: [{ ref: `src:r::${path}` as NodeRef, kind: 'file', label: path, pack: 'p', importance: 0, origin: 'extracted', ...(partition ? { partition } : {}) }],
271
+ edges: [],
272
+ });
273
+ const pack = { id: 'p', parsers: [], partitions: { partitions: [{ id: 'ui', order: 0, match: ['ui/**'] }, { id: 'db', order: 1, match: ['db/**'] }], allow: { ui: ['db'], db: [] } } };
274
+
275
+ it('regression: a built graph keeps a calls edge\'s sites, and the symbol kinds neither re-weigh importance nor earn a layer verdict', () => {
276
+ const a = file('ui/a.ts'), b = file('db/b.ts');
277
+ const sites = [site(3, 4, 0), site(5, 4, 1)];
278
+ // db → ui is upward for an import; the same pair through `calls` is no finding and no verdict.
279
+ const base = [{ ...a }, { ...b, edges: [edge('src:r::db/b.ts' as NodeRef, 'src:r::ui/a.ts' as NodeRef, 'references')] }];
280
+ const withSymbols = [{ ...a }, { ...b, edges: [...base[1]!.edges, edge('src:r::db/b.ts' as NodeRef, 'src:r::ui/a.ts' as NodeRef, 'calls', sites)] }];
281
+ const before = buildGraph({ rootId: 'r', packs: [pack], extracted: base, facts: [], relations: [] });
282
+ const after = buildGraph({ rootId: 'r', packs: [pack], extracted: withSymbols, facts: [], relations: [] });
283
+ const calls = after.edges.find((e) => e.kind === 'calls')!;
284
+ expect(calls.sites).toEqual(sites);
285
+ expect(calls.verdict).toBeUndefined();
286
+ expect(after.nodes.map((n) => [n.ref, n.importance])).toEqual(before.nodes.map((n) => [n.ref, n.importance]));
287
+ expect(after.findings.filter((f) => f.kind === 'partition-violation')).toHaveLength(before.findings.filter((f) => f.kind === 'partition-violation').length);
288
+ });
289
+ });
290
+
291
+ describe('symbol edges in truncateGraph', () => {
292
+ it('regression: a symbol-level edge never earns a seed\'s neighbour a slot (only the import does)', () => {
293
+ const n = (path: string, importance: number) => ({ ref: `src:r::${path}` as NodeRef, kind: 'file', label: path, pack: 'p', importance, origin: 'extracted' as const });
294
+ const nodes = [n('seed.ts', 0.1), n('big.ts', 0.9), n('called.ts', 0.01), n('imported.ts', 0.02)];
295
+ const g = {
296
+ scope: { rootId: 'r', packs: ['p'], digest: 'd' }, nodes, findings: [], stats: { sources: 4, nodes: 4, edges: 2, stale: 0, truncated: false },
297
+ edges: [edge('src:r::seed.ts' as NodeRef, 'src:r::called.ts' as NodeRef, 'calls', [site(1, 1, 0)]), edge('src:r::seed.ts' as NodeRef, 'src:r::imported.ts' as NodeRef, 'references')],
298
+ } as unknown as Parameters<typeof truncateGraph>[0];
299
+ // A node that is not kept folds into an `area` node; the kept ones stay files.
300
+ const kept = truncateGraph(g, { maxNodes: 1, focus: ['src:r::seed.ts' as NodeRef], changed: [] }).nodes.filter((x) => x.kind === 'file').map((x) => x.ref);
301
+ expect(kept).toContain('src:r::imported.ts');
302
+ expect(kept).not.toContain('src:r::called.ts');
303
+ });
304
+ });
305
+
306
+ describe('dedupeSymbolEdges', () => {
307
+ it('keeps one edge per (from, to, kind), merges repeated calls into sites in source order, and caps edges per symbol and sites per edge', () => {
308
+ const a = sym('A.run', 1), b = sym('B.get', 2), c = sym('C', 3);
309
+ const out = dedupeSymbolEdges([
310
+ edge(a, b, 'calls', [site(5, 3, 2)]),
311
+ edge(a, b, 'calls', [site(4, 3, 0)]),
312
+ edge(a, c, 'uses'),
313
+ edge(a, c, 'uses'),
314
+ edge(FILE, b, 'references'),
315
+ edge(FILE, b, 'references'),
316
+ ]);
317
+ expect(out).toEqual([edge(a, b, 'calls', [site(4, 3, 0), site(5, 3, 2)]), edge(a, c, 'uses'), edge(FILE, b, 'references'), edge(FILE, b, 'references')]);
318
+ const many = Array.from({ length: 10 }, (_, i) => edge(a, sym(`T${i}`, i), 'calls', Array.from({ length: 5 }, (_, s) => site(i, s, i * 5 + s))));
319
+ const capped = dedupeSymbolEdges(many, { maxPerSymbol: 3, maxSites: 2 });
320
+ expect(capped).toHaveLength(3);
321
+ expect(capped.every((e) => e.sites!.length === 2)).toBe(true);
322
+ });
323
+ });