@seanhogg/builderforce-memory 2026.10.71 → 2026.10.72

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 (188) hide show
  1. package/dist/knowledge/coChange.d.ts +3 -1
  2. package/dist/knowledge/coChange.d.ts.map +1 -1
  3. package/dist/knowledge/coChange.js +24 -12
  4. package/dist/knowledge/coChange.js.map +1 -1
  5. package/dist/knowledge/extractFile.d.ts +10 -0
  6. package/dist/knowledge/extractFile.d.ts.map +1 -1
  7. package/dist/knowledge/extractFile.js +16 -5
  8. package/dist/knowledge/extractFile.js.map +1 -1
  9. package/dist/knowledge/extractJob.d.ts +18 -1
  10. package/dist/knowledge/extractJob.d.ts.map +1 -1
  11. package/dist/knowledge/extractJob.js +10 -4
  12. package/dist/knowledge/extractJob.js.map +1 -1
  13. package/dist/knowledge/facts/extractorVersion.d.ts +45 -0
  14. package/dist/knowledge/facts/extractorVersion.d.ts.map +1 -0
  15. package/dist/knowledge/facts/extractorVersion.js +56 -0
  16. package/dist/knowledge/facts/extractorVersion.js.map +1 -0
  17. package/dist/knowledge/facts/fileFacts.d.ts +166 -0
  18. package/dist/knowledge/facts/fileFacts.d.ts.map +1 -0
  19. package/dist/knowledge/facts/fileFacts.js +156 -0
  20. package/dist/knowledge/facts/fileFacts.js.map +1 -0
  21. package/dist/knowledge/findings.d.ts +17 -14
  22. package/dist/knowledge/findings.d.ts.map +1 -1
  23. package/dist/knowledge/findings.js +29 -129
  24. package/dist/knowledge/findings.js.map +1 -1
  25. package/dist/knowledge/index.d.ts +13 -1
  26. package/dist/knowledge/index.d.ts.map +1 -1
  27. package/dist/knowledge/index.js +8 -1
  28. package/dist/knowledge/index.js.map +1 -1
  29. package/dist/knowledge/model.d.ts +6 -0
  30. package/dist/knowledge/model.d.ts.map +1 -1
  31. package/dist/knowledge/owedFiles.d.ts +14 -4
  32. package/dist/knowledge/owedFiles.d.ts.map +1 -1
  33. package/dist/knowledge/owedFiles.js +30 -8
  34. package/dist/knowledge/owedFiles.js.map +1 -1
  35. package/dist/knowledge/plan.d.ts +10 -1
  36. package/dist/knowledge/plan.d.ts.map +1 -1
  37. package/dist/knowledge/plan.js +9 -4
  38. package/dist/knowledge/plan.js.map +1 -1
  39. package/dist/knowledge/review.js +1 -0
  40. package/dist/knowledge/review.js.map +1 -1
  41. package/dist/knowledge/reviewContext.d.ts.map +1 -1
  42. package/dist/knowledge/reviewContext.js +5 -2
  43. package/dist/knowledge/reviewContext.js.map +1 -1
  44. package/dist/knowledge/reviewFinish.d.ts.map +1 -1
  45. package/dist/knowledge/reviewFinish.js +3 -1
  46. package/dist/knowledge/reviewFinish.js.map +1 -1
  47. package/dist/knowledge/reviewModel.d.ts +12 -0
  48. package/dist/knowledge/reviewModel.d.ts.map +1 -1
  49. package/dist/knowledge/reviewPrefetch.d.ts +2 -0
  50. package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
  51. package/dist/knowledge/reviewPrefetch.js +1 -0
  52. package/dist/knowledge/reviewPrefetch.js.map +1 -1
  53. package/dist/knowledge/rules/cloneGroup.d.ts +10 -0
  54. package/dist/knowledge/rules/cloneGroup.d.ts.map +1 -0
  55. package/dist/knowledge/rules/cloneGroup.js +46 -0
  56. package/dist/knowledge/rules/cloneGroup.js.map +1 -0
  57. package/dist/knowledge/rules/components.d.ts +8 -0
  58. package/dist/knowledge/rules/components.d.ts.map +1 -0
  59. package/dist/knowledge/rules/components.js +34 -0
  60. package/dist/knowledge/rules/components.js.map +1 -0
  61. package/dist/knowledge/rules/cycle.d.ts +7 -0
  62. package/dist/knowledge/rules/cycle.d.ts.map +1 -0
  63. package/dist/knowledge/rules/cycle.js +18 -0
  64. package/dist/knowledge/rules/cycle.js.map +1 -0
  65. package/dist/knowledge/rules/duplicateCopy.d.ts +7 -0
  66. package/dist/knowledge/rules/duplicateCopy.d.ts.map +1 -0
  67. package/dist/knowledge/rules/duplicateCopy.js +18 -0
  68. package/dist/knowledge/rules/duplicateCopy.js.map +1 -0
  69. package/dist/knowledge/rules/evaluateRules.d.ts +60 -0
  70. package/dist/knowledge/rules/evaluateRules.d.ts.map +1 -0
  71. package/dist/knowledge/rules/evaluateRules.js +164 -0
  72. package/dist/knowledge/rules/evaluateRules.js.map +1 -0
  73. package/dist/knowledge/rules/factGraph.d.ts +51 -0
  74. package/dist/knowledge/rules/factGraph.d.ts.map +1 -0
  75. package/dist/knowledge/rules/factGraph.js +77 -0
  76. package/dist/knowledge/rules/factGraph.js.map +1 -0
  77. package/dist/knowledge/rules/factRule.d.ts +56 -0
  78. package/dist/knowledge/rules/factRule.d.ts.map +1 -0
  79. package/dist/knowledge/rules/factRule.js +46 -0
  80. package/dist/knowledge/rules/factRule.js.map +1 -0
  81. package/dist/knowledge/rules/godModule.d.ts +8 -0
  82. package/dist/knowledge/rules/godModule.d.ts.map +1 -0
  83. package/dist/knowledge/rules/godModule.js +16 -0
  84. package/dist/knowledge/rules/godModule.js.map +1 -0
  85. package/dist/knowledge/rules/knowledgeInput.d.ts +35 -0
  86. package/dist/knowledge/rules/knowledgeInput.d.ts.map +1 -0
  87. package/dist/knowledge/rules/knowledgeInput.js +33 -0
  88. package/dist/knowledge/rules/knowledgeInput.js.map +1 -0
  89. package/dist/knowledge/rules/nearDuplicate.d.ts +7 -0
  90. package/dist/knowledge/rules/nearDuplicate.d.ts.map +1 -0
  91. package/dist/knowledge/rules/nearDuplicate.js +20 -0
  92. package/dist/knowledge/rules/nearDuplicate.js.map +1 -0
  93. package/dist/knowledge/rules/partitionViolation.d.ts +10 -0
  94. package/dist/knowledge/rules/partitionViolation.d.ts.map +1 -0
  95. package/dist/knowledge/rules/partitionViolation.js +27 -0
  96. package/dist/knowledge/rules/partitionViolation.js.map +1 -0
  97. package/dist/knowledge/rules/possibleSame.d.ts +7 -0
  98. package/dist/knowledge/rules/possibleSame.d.ts.map +1 -0
  99. package/dist/knowledge/rules/possibleSame.js +15 -0
  100. package/dist/knowledge/rules/possibleSame.js.map +1 -0
  101. package/dist/knowledge/rules/stale.d.ts +7 -0
  102. package/dist/knowledge/rules/stale.d.ts.map +1 -0
  103. package/dist/knowledge/rules/stale.js +28 -0
  104. package/dist/knowledge/rules/stale.js.map +1 -0
  105. package/dist/knowledge/rules/unpartitioned.d.ts +7 -0
  106. package/dist/knowledge/rules/unpartitioned.d.ts.map +1 -0
  107. package/dist/knowledge/rules/unpartitioned.js +26 -0
  108. package/dist/knowledge/rules/unpartitioned.js.map +1 -0
  109. package/dist/knowledge/sources.d.ts +13 -0
  110. package/dist/knowledge/sources.d.ts.map +1 -1
  111. package/dist/knowledge/sources.js +14 -0
  112. package/dist/knowledge/sources.js.map +1 -1
  113. package/dist/retrieval/knowledge-index/sha256.d.ts.map +1 -1
  114. package/dist/retrieval/knowledge-index/sha256.js +2 -2
  115. package/dist/retrieval/knowledge-index/sha256.js.map +1 -1
  116. package/dist/stats/distributions.d.ts +17 -1
  117. package/dist/stats/distributions.d.ts.map +1 -1
  118. package/dist/stats/distributions.js +26 -1
  119. package/dist/stats/distributions.js.map +1 -1
  120. package/dist/stats/fitting.d.ts.map +1 -1
  121. package/dist/stats/fitting.js +1 -6
  122. package/dist/stats/fitting.js.map +1 -1
  123. package/dist/stats/index.d.ts +10 -3
  124. package/dist/stats/index.d.ts.map +1 -1
  125. package/dist/stats/index.js +10 -3
  126. package/dist/stats/index.js.map +1 -1
  127. package/dist/stats/logistic.d.ts +30 -0
  128. package/dist/stats/logistic.d.ts.map +1 -0
  129. package/dist/stats/logistic.js +43 -0
  130. package/dist/stats/logistic.js.map +1 -0
  131. package/dist/stats/multivariate.d.ts +8 -13
  132. package/dist/stats/multivariate.d.ts.map +1 -1
  133. package/dist/stats/multivariate.js +7 -53
  134. package/dist/stats/multivariate.js.map +1 -1
  135. package/dist/stats/policies.d.ts.map +1 -1
  136. package/dist/stats/policies.js +4 -22
  137. package/dist/stats/policies.js.map +1 -1
  138. package/package.json +4 -3
  139. package/src/contract/exports.snapshot.json +37 -1
  140. package/src/contract/regression.extractorKey.test.ts +202 -0
  141. package/src/contract/regression.statsEngineFree.test.ts +70 -0
  142. package/src/contract/regression.thompsonDeterminism.test.ts +23 -0
  143. package/src/contract/types.contract.test.ts +59 -2
  144. package/src/knowledge/coChange.test.ts +15 -2
  145. package/src/knowledge/coChange.ts +22 -10
  146. package/src/knowledge/extractFile.ts +27 -5
  147. package/src/knowledge/extractJob.ts +24 -5
  148. package/src/knowledge/facts/extractorVersion.ts +73 -0
  149. package/src/knowledge/facts/fileFacts.test.ts +157 -0
  150. package/src/knowledge/facts/fileFacts.ts +305 -0
  151. package/src/knowledge/findings.ts +30 -127
  152. package/src/knowledge/index.ts +19 -0
  153. package/src/knowledge/model.ts +6 -0
  154. package/src/knowledge/owedFiles.ts +36 -8
  155. package/src/knowledge/plan.ts +16 -4
  156. package/src/knowledge/review.ts +1 -0
  157. package/src/knowledge/reviewContext.ts +5 -2
  158. package/src/knowledge/reviewFinish.ts +3 -1
  159. package/src/knowledge/reviewModel.ts +12 -0
  160. package/src/knowledge/reviewPrefetch.ts +3 -0
  161. package/src/knowledge/rules/cloneGroup.ts +45 -0
  162. package/src/knowledge/rules/components.ts +31 -0
  163. package/src/knowledge/rules/cycle.ts +20 -0
  164. package/src/knowledge/rules/duplicateCopy.ts +22 -0
  165. package/src/knowledge/rules/evaluateRules.test.ts +172 -0
  166. package/src/knowledge/rules/evaluateRules.ts +186 -0
  167. package/src/knowledge/rules/factGraph.oracle.test.ts +174 -0
  168. package/src/knowledge/rules/factGraph.ts +107 -0
  169. package/src/knowledge/rules/factRule.ts +74 -0
  170. package/src/knowledge/rules/godModule.ts +18 -0
  171. package/src/knowledge/rules/knowledgeInput.ts +60 -0
  172. package/src/knowledge/rules/knowledgeRules.test.ts +78 -0
  173. package/src/knowledge/rules/nearDuplicate.ts +22 -0
  174. package/src/knowledge/rules/partitionViolation.ts +31 -0
  175. package/src/knowledge/rules/possibleSame.ts +17 -0
  176. package/src/knowledge/rules/rules.testkit.test-util.ts +78 -0
  177. package/src/knowledge/rules/stale.ts +31 -0
  178. package/src/knowledge/rules/unpartitioned.ts +27 -0
  179. package/src/knowledge/sources.ts +16 -0
  180. package/src/retrieval/knowledge-index/sha256.test.ts +25 -0
  181. package/src/retrieval/knowledge-index/sha256.ts +2 -1
  182. package/src/stats/distributions.ts +29 -2
  183. package/src/stats/fitting.ts +1 -6
  184. package/src/stats/index.ts +12 -2
  185. package/src/stats/logistic.test.ts +89 -0
  186. package/src/stats/logistic.ts +49 -0
  187. package/src/stats/multivariate.ts +8 -59
  188. package/src/stats/policies.ts +4 -24
@@ -0,0 +1,174 @@
1
+ /**
2
+ * src/knowledge/rules/factGraph.oracle.test.ts — the determinism oracle (PRD 41 §B8.6, §8 Part B).
3
+ *
4
+ * For a fixture tree and 500 seeded sequences of edits, adds, deletes, renames and EOL rewrites, the canonical
5
+ * dump of the graph after the INCREMENTAL updates must equal a FROM-SCRATCH build of the final tree, byte for
6
+ * byte. The incremental side writes some files with CRLF (a Windows `core.autocrlf` checkout); the scratch
7
+ * side reads the same tree LF-only (a Linux checkout) — content identity is EOL-normalized (contentHash.ts),
8
+ * so the dumps still agree. The second-OS leg runs in CI; this is its same-process half.
9
+ */
10
+
11
+ import { createRng, type Rng } from '../../stats/prng.js';
12
+ import { contentHash } from '../contentHash.js';
13
+ import type { CallFact, FileFacts } from '../facts/fileFacts.js';
14
+ import { buildFactGraph, factGraphDump, updateFactGraph, type FactChange, type FactGraph } from './factGraph.js';
15
+ import { emptyFacts, FIXTURE_RULES } from './rules.testkit.test-util.js';
16
+
17
+ /** 500 by default (the §8 done-check); `FACT_ORACLE_SEQUENCES` overrides it for a CI budget. */
18
+ const SEQUENCES = Number(process.env.FACT_ORACLE_SEQUENCES) > 0 ? Math.floor(Number(process.env.FACT_ORACLE_SEQUENCES)) : 500;
19
+ const STEPS = 6;
20
+ const encoder = new TextEncoder();
21
+
22
+ /** The fixture extractor: one fact per line, EOL-insensitive (as every real extractor must be). */
23
+ function extract(text: string): FileFacts {
24
+ const facts = emptyFacts(contentHash(encoder.encode(text)));
25
+ const calls = new Map<string, CallFact>();
26
+ for (const line of text.split(/\r\n|\r|\n/)) {
27
+ const [op, a, b] = line.trim().split(/\s+/);
28
+ if (op === 'import' && a) facts.imports.push({ specifier: a, resolved: a, names: [] });
29
+ else if (op === 'export' && a) {
30
+ facts.exports.push({ name: a, kind: 'function', signatureHash: a });
31
+ facts.symbols.push({ name: a, kind: 'function' });
32
+ } else if (op === 'call' && a) {
33
+ const loop = b === 'loop';
34
+ const key = `${a}|${loop}`;
35
+ const prior = calls.get(key);
36
+ calls.set(key, prior ? { ...prior, count: prior.count + 1 } : { callee: a, enclosing: 'main', awaited: loop || undefined, inLoop: loop || undefined, count: 1 });
37
+ } else if (op === 'route' && a && b) {
38
+ facts.entryPoints.push({ kind: 'http-route', key: `GET ${a}`, symbol: 'main', guards: [], inputs: [], chain: [b] });
39
+ }
40
+ }
41
+ facts.calls.push(...calls.values());
42
+ return facts;
43
+ }
44
+
45
+ const lf = (text: string) => text.replace(/\r\n|\r/g, '\n');
46
+ const crlf = (text: string) => lf(text).replace(/\n/g, '\r\n');
47
+
48
+ const pick = <T>(rng: Rng, xs: readonly T[]): T => xs[Math.floor(rng() * xs.length)]!;
49
+ const int = (rng: Rng, n: number) => Math.floor(rng() * n);
50
+
51
+ function fixtureTree(): Map<string, string> {
52
+ return new Map([
53
+ ['src/a.ts', 'import src/b.ts\nexport a\ncall db.get loop\n'],
54
+ ['src/b.ts', 'import src/c.ts\nexport b\ncall fetch\n// note\n'],
55
+ ['src/c.ts', 'import src/b.ts\nexport c\n'],
56
+ ['src/auth.ts', 'export requireAuth\n'],
57
+ ['src/routes.ts', 'import src/a.ts\nroute /x src/auth.ts\nroute /y src/a.ts\n'],
58
+ ['src/win.ts', crlf('import src/a.ts\nexport w1\nexport w2\nexport w3\ncall kv.put loop\n')],
59
+ ['lib/u.ts', 'call helper\n'],
60
+ ]);
61
+ }
62
+
63
+ /** One random step over the working tree; returns the paths it touched. */
64
+ function step(rng: Rng, tree: Map<string, string>, n: number): string[] {
65
+ const paths = [...tree.keys()].sort();
66
+ const path = pick(rng, paths);
67
+ const text = tree.get(path)!;
68
+ const eol = text.includes('\r\n') ? '\r\n' : '\n';
69
+ const append = (line: string) => { tree.set(path, `${text}${line}${eol}`); return [path]; };
70
+ switch (int(rng, 10)) {
71
+ case 0: return append(`// comment ${n}`);
72
+ case 1: return append(`call fn${int(rng, 4)}${rng() < 0.5 ? ' loop' : ''}`);
73
+ case 2: return append(`export e${int(rng, 5)}`);
74
+ case 3: return append(`import ${pick(rng, paths)}`);
75
+ case 4: return append(`route /r${int(rng, 3)} ${pick(rng, [...paths, 'src/auth.ts'])}`);
76
+ case 5: {
77
+ const lines = text.split(eol).filter((l) => l !== '');
78
+ if (lines.length === 0) return [];
79
+ lines.splice(int(rng, lines.length), 1);
80
+ tree.set(path, lines.map((l) => `${l}${eol}`).join(''));
81
+ return [path];
82
+ }
83
+ case 6:
84
+ if (tree.size <= 3) return [];
85
+ tree.delete(path);
86
+ return [path];
87
+ case 7: {
88
+ const added = `src/new${n}.ts`;
89
+ tree.set(added, `import ${pick(rng, paths)}\nexport n${n}\ncall fn${int(rng, 4)} loop\n`);
90
+ return [added];
91
+ }
92
+ case 8: {
93
+ const to = `moved/${n}.ts`;
94
+ tree.delete(path);
95
+ tree.set(to, text);
96
+ return [path, to];
97
+ }
98
+ default:
99
+ tree.set(path, eol === '\r\n' ? lf(text) : crlf(text));
100
+ return [path];
101
+ }
102
+ }
103
+
104
+ const changesOf = (tree: ReadonlyMap<string, string>, paths: readonly string[]): FactChange[] =>
105
+ paths.map((path) => ({ path, facts: tree.has(path) ? extract(tree.get(path)!) : null }));
106
+
107
+ /** The Linux checkout of the same tree: LF only. */
108
+ const scratchOf = (tree: ReadonlyMap<string, string>) =>
109
+ factGraphDump(buildFactGraph([...tree].map(([p, t]) => [p, extract(lf(t))] as const), FIXTURE_RULES).graph);
110
+
111
+ describe('determinism oracle (B8.6): incremental dump === scratch dump', () => {
112
+ it(`holds byte for byte over ${SEQUENCES} seeded edit sequences, with CRLF files on the incremental side`, () => {
113
+ let reused = 0;
114
+ for (let seed = 0; seed < SEQUENCES; seed++) {
115
+ const rng = createRng(seed);
116
+ const tree = fixtureTree();
117
+ let graph: FactGraph = buildFactGraph([...tree].map(([p, t]) => [p, extract(t)] as const), FIXTURE_RULES).graph;
118
+ for (let n = 0; n < STEPS; n++) {
119
+ const touched = step(rng, tree, n);
120
+ const update = updateFactGraph(graph, changesOf(tree, touched), FIXTURE_RULES);
121
+ reused += update.trace.filter((t) => t.outcome === 'reused').length;
122
+ graph = update.graph;
123
+ }
124
+ const incremental = factGraphDump(graph);
125
+ const scratch = scratchOf(tree);
126
+ if (incremental !== scratch) throw new Error(`oracle failed at seed ${seed}`);
127
+ }
128
+ // The oracle exercised the incremental path, not a full recompute each step.
129
+ expect(reused).toBeGreaterThan(SEQUENCES * STEPS);
130
+ });
131
+
132
+ it('an EOL-only rewrite (autocrlf) is no change at all: every row reused, the dump unmoved', () => {
133
+ const tree = fixtureTree();
134
+ const built = buildFactGraph([...tree].map(([p, t]) => [p, extract(t)] as const), FIXTURE_RULES);
135
+ const update = updateFactGraph(built.graph, [...tree].map(([path, t]) => ({ path, facts: extract(crlf(t)) })), FIXTURE_RULES);
136
+ expect(update.changed).toEqual([]);
137
+ expect(update.trace.every((t) => t.outcome === 'reused')).toBe(true);
138
+ expect(factGraphDump(update.graph)).toBe(factGraphDump(built.graph));
139
+ });
140
+
141
+ it('a Windows (CRLF, backslashed paths) checkout and a Linux (LF) checkout build the same dump', () => {
142
+ const tree = fixtureTree();
143
+ const bs = (p: string) => p.replace(/\//g, '\\');
144
+ const windowsFacts = (t: string): FileFacts => {
145
+ const f = extract(crlf(t));
146
+ return {
147
+ ...f,
148
+ imports: f.imports.map((i) => ({ ...i, resolved: bs(i.resolved!) })),
149
+ entryPoints: f.entryPoints.map((e) => ({ ...e, chain: e.chain.map(bs) })),
150
+ };
151
+ };
152
+ const windows = factGraphDump(buildFactGraph([...tree].map(([p, t]) => [bs(p), windowsFacts(t)] as const), FIXTURE_RULES).graph);
153
+ expect(windows).toBe(scratchOf(tree));
154
+ });
155
+
156
+ it('`changed` compares against the pre-batch graph: an edit reverted in the same batch is no change', () => {
157
+ const tree = fixtureTree();
158
+ const built = buildFactGraph([...tree].map(([p, t]) => [p, extract(t)] as const), FIXTURE_RULES);
159
+ const a = tree.get('src/a.ts')!;
160
+ const update = updateFactGraph(built.graph, [
161
+ { path: 'src/a.ts', facts: extract(`${a}export z\n`) }, { path: 'src/a.ts', facts: extract(a) },
162
+ { path: 'src/tmp.ts', facts: extract('export t\n') }, { path: 'src/tmp.ts', facts: null },
163
+ ], FIXTURE_RULES);
164
+ expect(update.changed).toEqual([]);
165
+ expect(factGraphDump(update.graph)).toBe(factGraphDump(built.graph));
166
+ });
167
+
168
+ it('the dump is independent of the order files arrive in', () => {
169
+ const entries = [...fixtureTree()].map(([p, t]) => [p, extract(t)] as const);
170
+ const forward = factGraphDump(buildFactGraph(entries, FIXTURE_RULES).graph);
171
+ const reverse = factGraphDump(buildFactGraph([...entries].reverse(), FIXTURE_RULES).graph);
172
+ expect(reverse).toBe(forward);
173
+ });
174
+ });
@@ -0,0 +1,107 @@
1
+ /**
2
+ * knowledge/rules/factGraph.ts — the content-addressed fact graph in memory (PRD 41 §B1, §B8.6): the
3
+ * manifest (path → content hash, facts hash, kind hashes), the facts objects by facts hash, and the
4
+ * derived rule rows with their traces. Pure and immutable: an update returns a new graph.
5
+ *
6
+ * {@link factGraphDump} is the canonical dump the determinism oracle compares: sorted canonical JSON of
7
+ * the manifest, the referenced objects and the derived rows — never a trace outcome, a time or an order of
8
+ * arrival. An incremental graph and a from-scratch build of the same files dump to the same bytes.
9
+ * A durable host persists the same three tables behind its store; this module does no I/O.
10
+ */
11
+
12
+ import { canonicalJson, compareStr, isRootFilePath, normalizePath } from '../refs.js';
13
+ import type { Finding } from '../findingModel.js';
14
+ import { canonicalFileFacts, factKindHashes, factsHash, type FactKind, type FileFacts } from '../facts/fileFacts.js';
15
+ import type { FactRule } from './factRule.js';
16
+ import { evaluateRules, type DerivedRows, type RuleTraceEntry, type RuleWorld } from './evaluateRules.js';
17
+
18
+ export interface FactManifestEntry {
19
+ contentHash: string;
20
+ factsHash: string;
21
+ kinds: Readonly<Record<FactKind, string>>;
22
+ }
23
+
24
+ export interface FactGraph {
25
+ manifest: ReadonlyMap<string, FactManifestEntry>;
26
+ /** Facts by facts hash — only those the manifest references. */
27
+ objects: ReadonlyMap<string, FileFacts>;
28
+ derived: DerivedRows;
29
+ }
30
+
31
+ /** One file's new facts, or `null` when it was deleted. A rename is a delete plus an add. */
32
+ export interface FactChange {
33
+ path: string;
34
+ facts: FileFacts | null;
35
+ }
36
+
37
+ export type FactGraphOptions<X> = Pick<RuleWorld<X>, 'neighbours' | 'extra' | 'extraHashes'>;
38
+
39
+ export interface FactGraphUpdate {
40
+ graph: FactGraph;
41
+ trace: RuleTraceEntry[];
42
+ findings: Finding[];
43
+ /** Paths whose facts hash changed (added, edited or deleted), sorted. Empty ⇒ every rule row was reused (early cutoff). */
44
+ changed: string[];
45
+ }
46
+
47
+ /** The current dump format. */
48
+ export const FACT_GRAPH_DUMP_VERSION = 1;
49
+
50
+ export const emptyFactGraph = (): FactGraph => ({ manifest: new Map(), objects: new Map(), derived: new Map() });
51
+
52
+ /** The ONE path form of the graph (§B8.1); throws `fact_graph_bad_path` for a path outside the root. */
53
+ function pathOf(raw: string): string {
54
+ const p = normalizePath(raw);
55
+ if (!isRootFilePath(p)) throw new Error(`fact_graph_bad_path:${raw}`);
56
+ return p;
57
+ }
58
+
59
+ /**
60
+ * Applies `changes` (the last change of a path wins) and re-evaluates `rules`, reusing every derived row whose
61
+ * trace still holds. Unreferenced objects are dropped, so the graph never depends on its history.
62
+ */
63
+ export function updateFactGraph<X>(graph: FactGraph, changes: readonly FactChange[], rules: readonly FactRule<X>[], opts: FactGraphOptions<X> = {}): FactGraphUpdate {
64
+ const manifest = new Map(graph.manifest);
65
+ const objects = new Map(graph.objects);
66
+ const touched = new Set<string>();
67
+ for (const c of changes) {
68
+ const path = pathOf(c.path);
69
+ touched.add(path);
70
+ if (c.facts === null) { manifest.delete(path); continue; }
71
+ // Canonical facts are deep-frozen: the stored object can never be mutated under its hash.
72
+ const facts = canonicalFileFacts(c.facts);
73
+ const hash = factsHash(facts);
74
+ if (manifest.get(path)?.factsHash === hash) continue;
75
+ if (!objects.has(hash)) objects.set(hash, facts);
76
+ manifest.set(path, { contentHash: facts.contentHash, factsHash: hash, kinds: factKindHashes(objects.get(hash)!) });
77
+ }
78
+ // Against the PRE-batch manifest, so a path edited and reverted (or added and deleted) in one batch is no change.
79
+ const changed = [...touched].filter((p) => graph.manifest.get(p)?.factsHash !== manifest.get(p)?.factsHash);
80
+ const live = new Set([...manifest.values()].map((e) => e.factsHash));
81
+ for (const h of [...objects.keys()]) if (!live.has(h)) objects.delete(h);
82
+
83
+ const files = new Map([...manifest].map(([p, e]) => [p, objects.get(e.factsHash)!] as const));
84
+ const result = evaluateRules(rules, { files, ...opts }, graph.derived);
85
+ return {
86
+ graph: { manifest, objects, derived: result.rows },
87
+ trace: result.trace,
88
+ findings: result.findings,
89
+ changed: changed.sort(compareStr),
90
+ };
91
+ }
92
+
93
+ /** A from-scratch build: every file added to an empty graph. */
94
+ export function buildFactGraph<X>(files: Iterable<readonly [string, FileFacts]>, rules: readonly FactRule<X>[], opts: FactGraphOptions<X> = {}): FactGraphUpdate {
95
+ return updateFactGraph(emptyFactGraph(), [...files].map(([path, facts]) => ({ path, facts })), rules, opts);
96
+ }
97
+
98
+ /** The canonical dump: sorted canonical JSON of the manifest, the referenced objects and the derived rows. */
99
+ export function factGraphDump(graph: FactGraph): string {
100
+ const sortedEntries = <V>(m: ReadonlyMap<string, V>) => [...m].sort((a, b) => compareStr(a[0], b[0]));
101
+ return canonicalJson({
102
+ version: FACT_GRAPH_DUMP_VERSION,
103
+ manifest: sortedEntries(graph.manifest).map(([path, e]) => ({ path, ...e })),
104
+ objects: sortedEntries(graph.objects).map(([hash, facts]) => ({ hash, facts })),
105
+ derived: sortedEntries(graph.derived).map(([, row]) => row),
106
+ });
107
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * knowledge/rules/factRule.ts — the FactRule contract (PRD 41 §B5): derived knowledge as rules over facts.
3
+ *
4
+ * A rule declares what it READS (fact kinds, and optionally named non-fact inputs such as the knowledge
5
+ * graph), its SCOPE, and for a neighbourhood rule its HOPS. The evaluator (evaluateRules.ts) uses exactly
6
+ * those declarations as the rule's dependency trace: a rule reruns only when one of its read inputs changed
7
+ * (Build Systems à la Carte: verifying traces + early cutoff). So `derive` must read nothing else — the
8
+ * determinism oracle (factGraph.oracle.test.ts) catches a rule that does.
9
+ *
10
+ * - `file`: one evaluation per file, reading that file's facts.
11
+ * - `neighbourhood`: one per file, reading the file plus its import neighbours up to `hops` (default 1,
12
+ * max 2), plus — with `readsGuardChain` — the guard-chain files of its entry points.
13
+ * - `global`: one evaluation, reading every file.
14
+ *
15
+ * One rule per file under knowledge/rules/, registered as data (findings.ts is the generic registry).
16
+ */
17
+
18
+ import type { Finding } from '../findingModel.js';
19
+ import type { FactKind, FileFacts } from '../facts/fileFacts.js';
20
+ import { FACT_KINDS } from '../facts/fileFacts.js';
21
+
22
+ export type RuleScope = 'file' | 'neighbourhood' | 'global';
23
+
24
+ export const DEFAULT_RULE_HOPS = 1;
25
+ /** The C2 impact-set bound: a neighbourhood never reaches further than this. */
26
+ export const MAX_RULE_HOPS = 2;
27
+
28
+ /** What one evaluation of a rule sees. */
29
+ export interface RuleInput<X = Record<never, never>> {
30
+ scope: RuleScope;
31
+ /** `file` / `neighbourhood`: the file the evaluation is for. Absent for `global`. */
32
+ focus?: string;
33
+ /** The facts in scope, by root-relative path (iterate in sorted order): the focus; the focus plus its neighbourhood; every file. */
34
+ files: ReadonlyMap<string, FileFacts>;
35
+ /** The named non-fact inputs the host supplies (only those the rule declares in `extraInputs` are part of its trace). */
36
+ extra: X;
37
+ }
38
+
39
+ export interface FactRule<X = Record<never, never>> {
40
+ /** 'cycle', 'partition-violation', 'unused-export', 'io-in-loop', … */
41
+ id: string;
42
+ /** Bump whenever `derive` can return different findings for the same inputs: it is part of the cache key. */
43
+ version: number;
44
+ /** The fact kinds it consumes — its dependency trace. Empty only for a global rule reading extra inputs alone. */
45
+ reads: readonly FactKind[];
46
+ scope: RuleScope;
47
+ /** Neighbourhood rules: import hops to read around the focus (1 or 2). */
48
+ hops?: number;
49
+ /** Neighbourhood rules: also read the facts of the guard-chain files of the focus's entry points. */
50
+ readsGuardChain?: boolean;
51
+ /** Names of `extra` inputs `derive` reads; each needs a hash from the host (`RuleWorld.extraHashes`). */
52
+ extraInputs?: readonly (keyof X & string)[];
53
+ /** Pure. Findings sorted by id (the evaluator sorts again). */
54
+ derive(input: RuleInput<X>): Finding[];
55
+ }
56
+
57
+ /**
58
+ * Validates and freezes a rule: a non-empty id, an integer version ≥ 1, known `reads` — empty only for a global rule
59
+ * that reads extra inputs alone (it then sees no files) — and `hops` only on a neighbourhood rule and within
60
+ * 1..{@link MAX_RULE_HOPS}. Throws `fact_rule_invalid:<id>:<why>`.
61
+ */
62
+ export function defineRule<X = Record<never, never>>(rule: FactRule<X>): FactRule<X> {
63
+ const fail = (why: string): never => { throw new Error(`fact_rule_invalid:${rule.id}:${why}`); };
64
+ if (!rule.id) fail('id');
65
+ if (!Number.isInteger(rule.version) || rule.version < 1) fail('version');
66
+ if (rule.reads.some((k) => !FACT_KINDS.includes(k))) fail('reads');
67
+ if (rule.reads.length === 0 && (rule.scope !== 'global' || (rule.extraInputs ?? []).length === 0)) fail('reads');
68
+ if (rule.hops !== undefined) {
69
+ if (rule.scope !== 'neighbourhood') fail('hops-outside-neighbourhood');
70
+ if (!Number.isInteger(rule.hops) || rule.hops < 1 || rule.hops > MAX_RULE_HOPS) fail('hops');
71
+ }
72
+ if (rule.readsGuardChain && rule.scope !== 'neighbourhood') fail('guard-chain-outside-neighbourhood');
73
+ return Object.freeze({ ...rule, reads: Object.freeze([...new Set(rule.reads)].sort()) });
74
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * knowledge/rules/godModule.ts — `god-module` as a rule: the detector and its limits stay in
3
+ * knowledge/godModule.ts (the code pack imports the limits from there); this registers it.
4
+ * Reads the lines, exports and worst-function complexity badges of the file nodes of the knowledge input.
5
+ */
6
+
7
+ import { godModuleFindings, GOD_MODULE_KIND } from '../godModule.js';
8
+ import { defineRule } from './factRule.js';
9
+ import type { KnowledgeRuleExtra } from './knowledgeInput.js';
10
+
11
+ export const godModuleRule = defineRule<KnowledgeRuleExtra>({
12
+ id: GOD_MODULE_KIND,
13
+ version: 1,
14
+ reads: [], // the knowledge graph only (the measures are file-node badges)
15
+ scope: 'global',
16
+ extraInputs: ['knowledge'],
17
+ derive: ({ extra: { knowledge: k } }) => godModuleFindings(k.graph),
18
+ });
@@ -0,0 +1,60 @@
1
+ /**
2
+ * knowledge/rules/knowledgeInput.ts — the non-fact input of the generic finding rules ported from
3
+ * findings.ts (PRD 41 §B5): the built knowledge graph plus the partition registries and near-duplicate
4
+ * pairs. These rules are `global` with `reads: []` and `extraInputs: ['knowledge']`, so in an incremental
5
+ * evaluation they rerun exactly when {@link knowledgeInputHash} of this input moves.
6
+ */
7
+
8
+ import type { SimilarPair } from '../../retrieval/knowledge-index/types.js';
9
+ import type { Finding } from '../findingModel.js';
10
+ import type { KNode, KnowledgeGraph, NodeRef, PartitionRegistry } from '../model.js';
11
+ import { canonicalJson, compareStr, FALLBACK_PACK_ID } from '../refs.js';
12
+ import { sha256Hex } from '../../retrieval/knowledge-index/sha256.js';
13
+ import type { FactRule } from './factRule.js';
14
+
15
+ export interface KnowledgeFacts {
16
+ graph: KnowledgeGraph;
17
+ byRef: ReadonlyMap<NodeRef, KNode>;
18
+ registries: ReadonlyMap<string, PartitionRegistry>;
19
+ nearDuplicates: readonly SimilarPair[];
20
+ }
21
+
22
+ export interface KnowledgeRuleExtra {
23
+ knowledge: KnowledgeFacts;
24
+ }
25
+
26
+ /** A rule over the knowledge graph. */
27
+ export type KnowledgeRule = FactRule<KnowledgeRuleExtra>;
28
+
29
+ /** The extra input name the knowledge rules declare. */
30
+ export const KNOWLEDGE_INPUT = 'knowledge';
31
+
32
+ export function knowledgeFacts(
33
+ graph: KnowledgeGraph,
34
+ registries: ReadonlyMap<string, PartitionRegistry>,
35
+ nearDuplicates: readonly SimilarPair[] = [],
36
+ ): KnowledgeFacts {
37
+ return { graph, byRef: new Map(graph.nodes.map((n) => [n.ref, n] as const)), registries, nearDuplicates };
38
+ }
39
+
40
+ /**
41
+ * THE hash a host passes as `extraHashes.knowledge`: sha256 over the canonical JSON of the graph digest, the partition
42
+ * registries (sorted by pack) and the near-duplicate pairs (sorted). The graph digest alone misses a registry edit
43
+ * (`unpartitioned`) or pairs passed beside the graph (`possible-same`).
44
+ */
45
+ export function knowledgeInputHash(k: KnowledgeFacts): string {
46
+ return sha256Hex(canonicalJson({
47
+ digest: k.graph.scope.digest,
48
+ registries: [...k.registries].sort((a, b) => compareStr(a[0], b[0])),
49
+ nearDuplicates: k.nearDuplicates.map((p) => canonicalJson(p)).sort(compareStr),
50
+ }));
51
+ }
52
+
53
+ /** The pack of a ref's node, else the fallback pack. */
54
+ export const packOfRef = (k: KnowledgeFacts, ref: NodeRef): string => k.byRef.get(ref)?.pack ?? FALLBACK_PACK_ID;
55
+
56
+ /** Runs knowledge rules once, in registry order, non-incrementally (the `computeFindings` path). */
57
+ export function runKnowledgeRules(rules: readonly KnowledgeRule[], knowledge: KnowledgeFacts): Finding[] {
58
+ const files = new Map();
59
+ return rules.flatMap((r) => r.derive({ scope: r.scope, files, extra: { knowledge } }));
60
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * src/knowledge/rules/knowledgeRules.test.ts — the generic findings ported to one FactRule per file (PRD 41 §B5):
3
+ * the registry is well-formed, and the incremental evaluator gives the same findings as the compat facade.
4
+ */
5
+
6
+ import { GENERIC_FINDING_RULES, KNOWLEDGE_FINDING_RULES, computeFindings, genericFindings } from '../findings.js';
7
+ import type { KEdge, KNode, KnowledgeGraph, NodeRef, PartitionRegistry } from '../model.js';
8
+ import type { SimilarPair } from '../../retrieval/knowledge-index/types.js';
9
+ import { compareStr } from '../refs.js';
10
+ import { evaluateRules } from './evaluateRules.js';
11
+ import { knowledgeFacts, knowledgeInputHash, KNOWLEDGE_INPUT, type KnowledgeFacts } from './knowledgeInput.js';
12
+
13
+ const ref = (p: string) => `src:r::${p}` as NodeRef;
14
+ const node = (p: string, extra: Partial<KNode> = {}): KNode => ({ ref: ref(p), kind: 'file', label: p, pack: 'code', importance: 0, origin: 'extracted', ...extra });
15
+ const edge = (a: string, b: string, extra: Partial<KEdge>): KEdge => ({ from: ref(a), to: ref(b), kind: 'references', weight: 1, origin: 'extracted', ...extra });
16
+
17
+ const graph = (): KnowledgeGraph => ({
18
+ scope: { rootId: 'r', packs: ['code'], digest: 'd1' },
19
+ nodes: [node('a.ts', { partition: 'ui' }), node('b.ts', { partition: 'db' }), node('c.ts', { stale: true }), node('d.ts', { badges: { patterns: 'god-module', lines: 2000 } })],
20
+ edges: [
21
+ edge('a.ts', 'b.ts', { cycle: true, verdict: 'upward' }), edge('b.ts', 'a.ts', { cycle: true }),
22
+ edge('a.ts', 'c.ts', { kind: 'duplicate' }), edge('b.ts', 'd.ts', { kind: 'near-duplicate', weight: 0.91 }),
23
+ ],
24
+ findings: [],
25
+ stats: { sources: 4, nodes: 4, edges: 4, stale: 1, truncated: false },
26
+ });
27
+
28
+ describe('knowledge finding rules registry', () => {
29
+ it('one global rule per finding kind, each reading the knowledge input', () => {
30
+ const ids = KNOWLEDGE_FINDING_RULES.map((r) => r.id);
31
+ expect(new Set(ids).size).toBe(ids.length);
32
+ expect([...ids].sort(compareStr)).toEqual([
33
+ 'clone-group', 'cycle', 'duplicate-copy', 'god-module', 'near-duplicate', 'partition-violation', 'possible-same', 'stale', 'unpartitioned',
34
+ ]);
35
+ for (const r of KNOWLEDGE_FINDING_RULES) {
36
+ // They read the knowledge input alone, so they declare no fact kind (and see no files).
37
+ expect({ id: r.id, scope: r.scope, extra: r.extraInputs, reads: r.reads }).toEqual({ id: r.id, scope: 'global', extra: [KNOWLEDGE_INPUT], reads: [] });
38
+ }
39
+ expect(KNOWLEDGE_FINDING_RULES.slice(0, GENERIC_FINDING_RULES.length)).toEqual(GENERIC_FINDING_RULES);
40
+ });
41
+
42
+ it('the facade emits one finding per kind the fixture holds', () => {
43
+ const kinds = genericFindings(graph(), new Map()).map((f) => f.kind).sort(compareStr);
44
+ expect(kinds).toEqual(['clone-group', 'cycle', 'god-module', 'near-duplicate', 'partition-violation', 'stale']);
45
+ });
46
+
47
+ const worldOf = (knowledge: KnowledgeFacts) => ({ files: new Map(), extra: { knowledge }, extraHashes: { knowledge: knowledgeInputHash(knowledge) } });
48
+
49
+ it('incremental evaluation equals the facade, and reuses every rule while the knowledge input hash holds', () => {
50
+ const g = graph();
51
+ const world = worldOf(knowledgeFacts(g, new Map()));
52
+ const first = evaluateRules(KNOWLEDGE_FINDING_RULES, world);
53
+ const facade = computeFindings(g, [], new Map(), []);
54
+ expect(first.findings).toEqual([...facade].sort((a, b) => compareStr(a.id, b.id)));
55
+ const second = evaluateRules(KNOWLEDGE_FINDING_RULES, worldOf(knowledgeFacts(graph(), new Map())), first.rows);
56
+ expect(second.trace.every((t) => t.outcome === 'reused')).toBe(true);
57
+ });
58
+
59
+ it('toggling a registry `allow` (same graph digest) moves the input hash and reruns `unpartitioned`', () => {
60
+ const registry = (allow?: Record<string, string[]>): PartitionRegistry => ({ partitions: [{ id: 'ui', order: 0, match: ['**'] }], ...(allow ? { allow } : {}) });
61
+ const before = knowledgeFacts(graph(), new Map([['code', registry()]]));
62
+ const after = knowledgeFacts(graph(), new Map([['code', registry({ ui: [] })]]));
63
+ expect(knowledgeInputHash(after)).not.toBe(knowledgeInputHash(before));
64
+ const first = evaluateRules(KNOWLEDGE_FINDING_RULES, worldOf(before));
65
+ expect(first.findings.some((f) => f.kind === 'unpartitioned')).toBe(false);
66
+ const second = evaluateRules(KNOWLEDGE_FINDING_RULES, worldOf(after), first.rows);
67
+ expect(second.trace.find((t) => t.rule === 'unpartitioned')?.outcome).toBe('ran');
68
+ expect(second.findings.some((f) => f.kind === 'unpartitioned')).toBe(true);
69
+ });
70
+
71
+ it('the input hash covers near-duplicate pairs passed beside the graph, in any order', () => {
72
+ const pairs = [{ a: 'ent:code:alpha', b: 'ent:code:beta', similarity: 0.9 }, { a: 'ent:code:x', b: 'ent:code:y', similarity: 0.8 }] as SimilarPair[];
73
+ const none = knowledgeInputHash(knowledgeFacts(graph(), new Map()));
74
+ const some = knowledgeInputHash(knowledgeFacts(graph(), new Map(), pairs));
75
+ expect(some).not.toBe(none);
76
+ expect(knowledgeInputHash(knowledgeFacts(graph(), new Map(), [...pairs].reverse()))).toBe(some);
77
+ });
78
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * knowledge/rules/nearDuplicate.ts — `near-duplicate`: one finding per near-duplicate edge.
3
+ * Anchor (PRD 41 §C3): the sorted-first ref of the pair.
4
+ */
5
+
6
+ import { finding, refAnchor } from '../findingBuilder.js';
7
+ import { compareStr, round6 } from '../refs.js';
8
+ import { defineRule } from './factRule.js';
9
+ import { packOfRef, type KnowledgeRuleExtra } from './knowledgeInput.js';
10
+
11
+ export const nearDuplicateRule = defineRule<KnowledgeRuleExtra>({
12
+ id: 'near-duplicate',
13
+ version: 1,
14
+ reads: [], // the knowledge graph only
15
+ scope: 'global',
16
+ extraInputs: ['knowledge'],
17
+ derive: ({ extra: { knowledge: k } }) =>
18
+ k.graph.edges.filter((e) => e.kind === 'near-duplicate').map((e) => {
19
+ const first = compareStr(e.from, e.to) <= 0 ? e.from : e.to;
20
+ return finding('near-duplicate', packOfRef(k, e.from), [e.from, e.to], 'info', { similarity: round6(e.weight) }, undefined, refAnchor(first));
21
+ }),
22
+ });
@@ -0,0 +1,31 @@
1
+ /**
2
+ * knowledge/rules/partitionViolation.ts — `partition-violation`: an edge whose layer verdict is `upward`
3
+ * (error) or `skips` (warn). Anchor (PRD 41 §C3): the from→to layer pair at the from FILE.
4
+ */
5
+
6
+ import { finding } from '../findingBuilder.js';
7
+ import type { EdgeVerdict, Finding } from '../model.js';
8
+ import { fileRefOf } from '../refs.js';
9
+ import { defineRule } from './factRule.js';
10
+ import { packOfRef, type KnowledgeRuleExtra } from './knowledgeInput.js';
11
+
12
+ /** A partition violation's severity: an upward edge is an error, a skipped layer a warning. */
13
+ export function partitionSeverity(verdict: EdgeVerdict): Finding['severity'] {
14
+ return verdict === 'upward' ? 'error' : 'warn';
15
+ }
16
+
17
+ export const partitionViolationRule = defineRule<KnowledgeRuleExtra>({
18
+ id: 'partition-violation',
19
+ version: 1,
20
+ reads: [], // the knowledge graph only
21
+ scope: 'global',
22
+ extraInputs: ['knowledge'],
23
+ derive: ({ extra: { knowledge: k } }) =>
24
+ k.graph.edges.filter((e) => e.verdict === 'upward' || e.verdict === 'skips').map((e) => {
25
+ const from = k.byRef.get(e.from), to = k.byRef.get(e.to);
26
+ const layers = `${from?.partition ?? ''}->${to?.partition ?? ''}`;
27
+ return finding('partition-violation', packOfRef(k, e.from), [e.from, e.to], partitionSeverity(e.verdict!), {
28
+ verdict: e.verdict!, from: from?.partition ?? '', to: to?.partition ?? '', kind: e.kind,
29
+ }, undefined, { anchor: `${layers}@${fileRefOf(e.from)}`, anchorKind: 'file' });
30
+ }),
31
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * knowledge/rules/possibleSame.ts — `possible-same` as a rule: two entities the index found near-duplicate
3
+ * whose names do not normalize equal. The finding producer stays in resolve.ts beside entity resolution.
4
+ */
5
+
6
+ import { possibleSameFindings } from '../resolve.js';
7
+ import { defineRule } from './factRule.js';
8
+ import type { KnowledgeRuleExtra } from './knowledgeInput.js';
9
+
10
+ export const possibleSameRule = defineRule<KnowledgeRuleExtra>({
11
+ id: 'possible-same',
12
+ version: 1,
13
+ reads: [], // the near-duplicate pairs of the knowledge input only
14
+ scope: 'global',
15
+ extraInputs: ['knowledge'],
16
+ derive: ({ extra: { knowledge: k } }) => possibleSameFindings(k.nearDuplicates),
17
+ });