@seanhogg/builderforce-memory 2026.10.80 → 2026.10.81
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.
- package/dist/knowledge/build.d.ts.map +1 -1
- package/dist/knowledge/build.js +40 -3
- package/dist/knowledge/build.js.map +1 -1
- package/dist/knowledge/cooperative.d.ts +51 -0
- package/dist/knowledge/cooperative.d.ts.map +1 -0
- package/dist/knowledge/cooperative.js +58 -0
- package/dist/knowledge/cooperative.js.map +1 -0
- package/dist/knowledge/ignoreMatcher.d.ts +25 -0
- package/dist/knowledge/ignoreMatcher.d.ts.map +1 -0
- package/dist/knowledge/ignoreMatcher.js +121 -0
- package/dist/knowledge/ignoreMatcher.js.map +1 -0
- package/dist/knowledge/index.d.ts +4 -0
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +3 -0
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/plan.d.ts +6 -0
- package/dist/knowledge/plan.d.ts.map +1 -1
- package/dist/knowledge/plan.js +17 -1
- package/dist/knowledge/plan.js.map +1 -1
- package/dist/knowledge/reviewAnalyse.d.ts.map +1 -1
- package/dist/knowledge/reviewAnalyse.js +6 -1
- package/dist/knowledge/reviewAnalyse.js.map +1 -1
- package/dist/knowledge/reviewFinish.d.ts.map +1 -1
- package/dist/knowledge/reviewFinish.js +7 -1
- package/dist/knowledge/reviewFinish.js.map +1 -1
- package/dist/knowledge/reviewModel.d.ts +10 -0
- package/dist/knowledge/reviewModel.d.ts.map +1 -1
- package/dist/knowledge/rules/factStore.d.ts.map +1 -1
- package/dist/knowledge/rules/factStore.js +24 -1
- package/dist/knowledge/rules/factStore.js.map +1 -1
- package/dist/knowledge/rules/fixpointRules.d.ts +68 -0
- package/dist/knowledge/rules/fixpointRules.d.ts.map +1 -0
- package/dist/knowledge/rules/fixpointRules.js +0 -0
- package/dist/knowledge/rules/fixpointRules.js.map +1 -0
- package/dist/knowledge/sources.d.ts +9 -9
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +11 -50
- package/dist/knowledge/sources.js.map +1 -1
- package/dist/knowledge/statManifest.d.ts +89 -0
- package/dist/knowledge/statManifest.d.ts.map +1 -0
- package/dist/knowledge/statManifest.js +125 -0
- package/dist/knowledge/statManifest.js.map +1 -0
- package/dist/stats/estimators.d.ts +8 -1
- package/dist/stats/estimators.d.ts.map +1 -1
- package/dist/stats/estimators.js +18 -7
- package/dist/stats/estimators.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/exports.snapshot.json +11 -0
- package/src/contract/regression.assets.test.ts +2 -2
- package/src/contract/regression.factStoreBatchedLoad.test.ts +62 -0
- package/src/contract/regression.ignoreMatcher.test.ts +116 -0
- package/src/knowledge/build.ts +32 -3
- package/src/knowledge/cooperative.test.ts +57 -0
- package/src/knowledge/cooperative.ts +76 -0
- package/src/knowledge/docs.test.ts +30 -0
- package/src/knowledge/ignoreMatcher.ts +143 -0
- package/src/knowledge/index.ts +7 -0
- package/src/knowledge/plan.ts +20 -1
- package/src/knowledge/reviewAnalyse.ts +6 -1
- package/src/knowledge/reviewFinish.ts +7 -1
- package/src/knowledge/reviewModel.ts +6 -0
- package/src/knowledge/rules/factStore.ts +22 -1
- package/src/knowledge/rules/fixpointRules.test.ts +94 -0
- package/src/knowledge/rules/fixpointRules.ts +0 -0
- package/src/knowledge/sources.ts +12 -46
- package/src/knowledge/statManifest.test.ts +122 -0
- package/src/knowledge/statManifest.ts +176 -0
- package/src/stats/estimators.ts +18 -7
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/contract/regression.ignoreMatcher.test.ts — the memoized `ignoreMatcher` answers exactly as the algorithm it replaced.
|
|
3
|
+
*
|
|
4
|
+
* Before: for every path the matcher built every ancestor folder and tested EVERY rule against every ancestor (and the
|
|
5
|
+
* path): O(files × rules × depth) regex tests on the VS Code extension host's main thread, which a 34k-file multi-repo
|
|
6
|
+
* tree (every nested `.gitignore` adds its rules) stalled for seconds. The reference below IS that algorithm, kept
|
|
7
|
+
* verbatim, and is the oracle over a randomized tree with many nested `.gitignore` bases.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { ignoreMatcher } from '../knowledge/sources.js';
|
|
11
|
+
import { matchGlob } from '../knowledge/partitions.js';
|
|
12
|
+
|
|
13
|
+
const DEFAULT_IGNORES = ['.git/', 'node_modules/', '.builderforce/', '.gitignore', '*.lock'];
|
|
14
|
+
|
|
15
|
+
/** The matcher as it was before the memoization (sources.ts, 2026-11-14), verbatim. */
|
|
16
|
+
function referenceMatcher(texts: ReadonlyArray<string | { text: string; base: string }>): (path: string) => boolean {
|
|
17
|
+
const rules: Array<{ glob: string; negate: boolean; dirOnly: boolean }> = [];
|
|
18
|
+
const lines = [
|
|
19
|
+
...DEFAULT_IGNORES.map((line) => ({ line, base: '' })),
|
|
20
|
+
...texts.flatMap((t) => {
|
|
21
|
+
const { text, base } = typeof t === 'string' ? { text: t, base: '' } : t;
|
|
22
|
+
return text.split(/\r?\n/).map((line) => ({ line, base }));
|
|
23
|
+
}),
|
|
24
|
+
];
|
|
25
|
+
for (const { line, base } of lines) {
|
|
26
|
+
let p = line.replace(/\s+$/, '');
|
|
27
|
+
if (!p || p.startsWith('#')) continue;
|
|
28
|
+
const negate = p.startsWith('!');
|
|
29
|
+
if (negate) p = p.slice(1);
|
|
30
|
+
const dirOnly = p.endsWith('/');
|
|
31
|
+
if (dirOnly) p = p.slice(0, -1);
|
|
32
|
+
const anchored = p.includes('/');
|
|
33
|
+
p = p.replace(/^\//, '');
|
|
34
|
+
const prefix = base ? `${base}/` : '';
|
|
35
|
+
if (p) rules.push({ glob: anchored ? `${prefix}${p}` : `${prefix}**/${p}`, negate, dirOnly });
|
|
36
|
+
}
|
|
37
|
+
return (path) => {
|
|
38
|
+
const segments = path.split('/');
|
|
39
|
+
const dirs = segments.slice(0, -1).map((_, i) => segments.slice(0, i + 1).join('/'));
|
|
40
|
+
let ignored = false;
|
|
41
|
+
for (const r of rules) {
|
|
42
|
+
const hit = (r.dirOnly ? dirs : [...dirs, path]).some((c) => matchGlob(c, r.glob));
|
|
43
|
+
if (hit) ignored = !r.negate;
|
|
44
|
+
}
|
|
45
|
+
return ignored;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A small deterministic PRNG (mulberry32), so a failure reproduces. */
|
|
50
|
+
function rng(seed: number): () => number {
|
|
51
|
+
let a = seed >>> 0;
|
|
52
|
+
return () => {
|
|
53
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
54
|
+
let t = a;
|
|
55
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
56
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
57
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const SEGMENTS = ['src', 'lib', 'dist', 'build', 'out', 'node_modules', 'docs', 'test', 'tmp', 'cache', 'a', 'b', 'repo1', 'repo2', 'pkg', '.git', 'vendor', 'gen'];
|
|
62
|
+
const FILES = ['index.ts', 'a.md', 'b.js', 'yarn.lock', '.gitignore', 'x.log', 'notes.txt', 'keep.log', 'main.min.js', 'copy*.txt', 'data.json'];
|
|
63
|
+
const PATTERNS = [
|
|
64
|
+
'dist/', 'build', '*.log', '!keep.log', '/out', 'tmp/', '*.min.js', 'cache/**', '!src/keep.log', 'docs/*.md', '!docs/',
|
|
65
|
+
'gen/**/*.ts', '**/vendor', 'a/b', '!a', '*.json', '# a comment', '', 'test/', '!test/index.ts', 'copy\\*.txt', '{a,b}.md',
|
|
66
|
+
'lib/?.js', '!yarn.lock', 'node_modules/', '/src/*.ts', 'pkg/**/b.js',
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
function randomTree(seed: number, opts: { paths: number; bases: number; rulesPerBase: number }) {
|
|
70
|
+
const next = rng(seed);
|
|
71
|
+
const pick = <T>(xs: readonly T[]): T => xs[Math.floor(next() * xs.length)]!;
|
|
72
|
+
const dir = (depth: number) => Array.from({ length: depth }, () => pick(SEGMENTS)).join('/');
|
|
73
|
+
const texts: Array<{ text: string; base: string }> = [];
|
|
74
|
+
for (let i = 0; i < opts.bases; i++) {
|
|
75
|
+
const base = i === 0 ? '' : dir(1 + Math.floor(next() * 4));
|
|
76
|
+
const text = Array.from({ length: opts.rulesPerBase }, () => pick(PATTERNS)).join(i % 2 ? '\r\n' : '\n');
|
|
77
|
+
texts.push({ text, base });
|
|
78
|
+
}
|
|
79
|
+
const paths = Array.from({ length: opts.paths }, () => {
|
|
80
|
+
const depth = Math.floor(next() * 7);
|
|
81
|
+
return depth === 0 ? pick(FILES) : `${dir(depth)}/${pick(FILES)}`;
|
|
82
|
+
});
|
|
83
|
+
return { texts, paths };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
describe('regression: ignoreMatcher memoization', () => {
|
|
87
|
+
it('regression: answers exactly as the unmemoized matcher over a randomized tree with many nested .gitignore bases', () => {
|
|
88
|
+
for (const seed of [1, 2, 3, 42, 1337]) {
|
|
89
|
+
const { texts, paths } = randomTree(seed, { paths: 2000, bases: 40, rulesPerBase: 8 });
|
|
90
|
+
const fast = ignoreMatcher(texts);
|
|
91
|
+
const ref = referenceMatcher(texts);
|
|
92
|
+
const mismatches = paths.filter((p) => fast(p) !== ref(p));
|
|
93
|
+
expect(mismatches).toEqual([]);
|
|
94
|
+
// Both outcomes occur, so the comparison is not vacuous.
|
|
95
|
+
expect(new Set(paths.map(ref)).size).toBe(2);
|
|
96
|
+
// Asking again (served from the folder memo) changes nothing.
|
|
97
|
+
expect(paths.filter((p) => fast(p) !== ref(p))).toEqual([]);
|
|
98
|
+
}
|
|
99
|
+
// Plain string texts (base ''), and degenerate paths.
|
|
100
|
+
const plain = ['dist/\n!keep.log', '*.log'];
|
|
101
|
+
const paths = ['dist/a.log', 'src/keep.log', 'a/dist/x.ts', 'x.log', 'dist', 'keep.log', '', '/abs/x.log', 'a//b.log'];
|
|
102
|
+
expect(paths.map(ignoreMatcher(plain))).toEqual(paths.map(referenceMatcher(plain)));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('perf guard: 30k paths × 300 rules finishes well within a few seconds', () => {
|
|
106
|
+
const { texts, paths } = randomTree(7, { paths: 30_000, bases: 60, rulesPerBase: 5 }); // ≈300 rules with the defaults
|
|
107
|
+
const fast = ignoreMatcher(texts);
|
|
108
|
+
const start = performance.now();
|
|
109
|
+
let ignored = 0;
|
|
110
|
+
for (const p of paths) if (fast(p)) ignored++;
|
|
111
|
+
const ms = performance.now() - start;
|
|
112
|
+
expect(ignored).toBeGreaterThan(0);
|
|
113
|
+
// Measured 2026-11-14 on this shape (folders nearly all distinct, the memo's worst case): the reference ≈4.6 s, this ≈0.2 s.
|
|
114
|
+
expect(ms).toBeLessThan(2000);
|
|
115
|
+
});
|
|
116
|
+
});
|
package/src/knowledge/build.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
} from './refs.js';
|
|
37
37
|
import { buildOutline } from './outline.js';
|
|
38
38
|
import { truncateGraph } from './truncate.js';
|
|
39
|
+
import { LINKABLE_DOC_EXT } from './sources.js';
|
|
39
40
|
|
|
40
41
|
export const DEFAULT_MAX_NODES = 400;
|
|
41
42
|
export const MAX_NODES_CAP = 2000;
|
|
@@ -268,19 +269,47 @@ function repointByName(e: KEdge, rootId: string, resolve: (name: string) => stri
|
|
|
268
269
|
return fileRefOf(e.from) === to ? null : { ...edge, to };
|
|
269
270
|
}
|
|
270
271
|
|
|
271
|
-
/**
|
|
272
|
+
/**
|
|
273
|
+
* A missing `src:` endpoint becomes a `missing` placeholder (a broken link); a missing fact drops the edge.
|
|
274
|
+
* A `links` target with no file of its own name is resolved against the files present NOW — an extensionless
|
|
275
|
+
* document target may name a sibling file like `troubleshooting.md`: an extract is cached, so it must record
|
|
276
|
+
* the written target, but whether the file exists is decided here. (The docs pack's broken-link rule only
|
|
277
|
+
* judges extensionless/document targets, so those are the only ones resolved.)
|
|
278
|
+
*/
|
|
272
279
|
function closeEndpoints(g: GraphBuilder): void {
|
|
280
|
+
const byFolderExt = new Map<string, NodeRef>();
|
|
281
|
+
for (const n of g.nodes.values()) {
|
|
282
|
+
if (n.kind !== 'file') continue;
|
|
283
|
+
const path = pathOfRef(n.ref);
|
|
284
|
+
if (path === undefined || path.startsWith('../')) continue;
|
|
285
|
+
const slash = path.lastIndexOf('/');
|
|
286
|
+
const folder = slash === -1 ? '' : path.slice(0, slash + 1);
|
|
287
|
+
const dot = path.lastIndexOf('.');
|
|
288
|
+
if (dot === -1 || dot < slash + 1) continue;
|
|
289
|
+
for (const ext of LINKABLE_DOC_EXT) {
|
|
290
|
+
if (ext === path.slice(dot + 1).toLowerCase()) { byFolderExt.set(folder + path.slice(slash + 1, dot), n.ref); break; }
|
|
291
|
+
}
|
|
292
|
+
}
|
|
273
293
|
for (const [id, e] of [...g.edges.entries()].sort((a, b) => compareStr(a[0], b[0]))) {
|
|
274
|
-
const
|
|
294
|
+
const { from } = e;
|
|
295
|
+
let { to } = e;
|
|
296
|
+
// An extensionless `links` target may name an existing sibling document; otherwise a placeholder is fabricated below.
|
|
297
|
+
if (e.kind === 'links' && !g.nodes.has(to)) {
|
|
298
|
+
const path = pathOfRef(to);
|
|
299
|
+
const resolved = path === undefined ? undefined : byFolderExt.get(path);
|
|
300
|
+
if (resolved !== undefined) to = resolved;
|
|
301
|
+
}
|
|
302
|
+
const ends = [from, to].filter((end) => !g.nodes.has(end));
|
|
275
303
|
if (ends.some((end) => pathOfRef(end) === undefined)) { g.edges.delete(id); continue; }
|
|
276
304
|
for (const end of ends) {
|
|
277
305
|
const path = pathOfRef(end)!;
|
|
278
|
-
const other = g.nodes.get(end ===
|
|
306
|
+
const other = g.nodes.get(end === from ? to : from);
|
|
279
307
|
g.node({
|
|
280
308
|
ref: end, kind: 'missing', label: basenameOf(path) || path, pack: other?.pack ?? FALLBACK_PACK_ID,
|
|
281
309
|
importance: 0, origin: 'extracted', badges: { missing: 1 },
|
|
282
310
|
});
|
|
283
311
|
}
|
|
312
|
+
if (to !== e.to) g.edges.set(id, { ...e, to });
|
|
284
313
|
}
|
|
285
314
|
}
|
|
286
315
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/cooperative.test.ts — the yield is chosen once, in order setImmediate > scheduler.yield > MessageChannel >
|
|
3
|
+
* setTimeout, from functions captured at pick time (fake timers installed later never reach it).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { jest } from '@jest/globals';
|
|
7
|
+
import { cooperativeBudget, pickYield, yieldToEventLoop, type YieldHost } from './cooperative.js';
|
|
8
|
+
|
|
9
|
+
/** A MessageChannel stand-in that delivers on a real immediate, and counts posts. */
|
|
10
|
+
function fakeChannel(posts: { n: number }): YieldHost['MessageChannel'] {
|
|
11
|
+
return class {
|
|
12
|
+
port1: { onmessage: ((ev: unknown) => void) | null } = { onmessage: null };
|
|
13
|
+
port2 = { postMessage: (_: unknown) => { posts.n++; setImmediate(() => this.port1.onmessage?.({})); } };
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('cooperative yield selection', () => {
|
|
18
|
+
it('prefers setImmediate, then scheduler.yield, then MessageChannel, then setTimeout', () => {
|
|
19
|
+
const timeout = (fn: () => void) => setTimeout(fn, 0);
|
|
20
|
+
const posts = { n: 0 };
|
|
21
|
+
const all: YieldHost = { setImmediate, scheduler: { yield: async () => undefined }, MessageChannel: fakeChannel(posts), setTimeout: timeout };
|
|
22
|
+
expect(pickYield(all).kind).toBe('setImmediate');
|
|
23
|
+
expect(pickYield({ ...all, setImmediate: undefined }).kind).toBe('scheduler.yield');
|
|
24
|
+
expect(pickYield({ ...all, setImmediate: undefined, scheduler: {} }).kind).toBe('MessageChannel');
|
|
25
|
+
expect(pickYield({ setTimeout: timeout }).kind).toBe('setTimeout');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('the MessageChannel fallback resolves each yield, in order', async () => {
|
|
29
|
+
const posts = { n: 0 };
|
|
30
|
+
const { yield: y } = pickYield({ MessageChannel: fakeChannel(posts) });
|
|
31
|
+
const order: number[] = [];
|
|
32
|
+
await Promise.all([y().then(() => order.push(1)), y().then(() => order.push(2))]);
|
|
33
|
+
expect(order).toEqual([1, 2]);
|
|
34
|
+
expect(posts.n).toBe(2);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('the setTimeout fallback is captured at pick time: replacing the host timer afterwards does not reach it', async () => {
|
|
38
|
+
let used = 0;
|
|
39
|
+
const host: YieldHost = { setTimeout: (fn) => { used++; return setTimeout(fn, 0); } };
|
|
40
|
+
const { yield: y } = pickYield(host);
|
|
41
|
+
host.setTimeout = () => { throw new Error('a later (fake) timer was used'); };
|
|
42
|
+
await y();
|
|
43
|
+
expect(used).toBe(1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('fake timers installed after load do not stall the module yield or the budget', async () => {
|
|
47
|
+
jest.useFakeTimers();
|
|
48
|
+
try {
|
|
49
|
+
await yieldToEventLoop();
|
|
50
|
+
const budget = cooperativeBudget(0);
|
|
51
|
+
expect(budget.due()).toBe(true);
|
|
52
|
+
await budget.pause();
|
|
53
|
+
} finally {
|
|
54
|
+
jest.useRealTimers();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/cooperative.ts — THE cooperative-yield helper of long synchronous loops (the plan's walk, the fact store's load).
|
|
3
|
+
*
|
|
4
|
+
* A host may run a review on its UI thread (the VS Code extension host does): a loop over tens of thousands of files must
|
|
5
|
+
* hand the event loop back every few milliseconds or the host stalls. {@link cooperativeBudget} times the work since the
|
|
6
|
+
* last yield and {@link yieldToEventLoop} returns to the event loop (a macrotask, so I/O and input run in between).
|
|
7
|
+
*
|
|
8
|
+
* Portable: `setImmediate`, `scheduler.yield`, a `MessageChannel` or `setTimeout(0)` ({@link pickYield}) and
|
|
9
|
+
* `performance.now()` — Node, browsers and Workers alike. All are captured when the module loads, so a test's fake timers
|
|
10
|
+
* never stall a yield.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Default work budget between two yields, in ms. */
|
|
14
|
+
export const COOPERATIVE_BUDGET_MS = 12;
|
|
15
|
+
|
|
16
|
+
/** The host globals the yield may use. */
|
|
17
|
+
export interface YieldHost {
|
|
18
|
+
setImmediate?: (fn: () => void) => unknown;
|
|
19
|
+
scheduler?: { yield?: () => Promise<void> };
|
|
20
|
+
MessageChannel?: new () => { port1: { onmessage: ((ev: unknown) => void) | null }; port2: { postMessage(msg: unknown): void } };
|
|
21
|
+
setTimeout?: (fn: () => void, ms?: number) => unknown;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type YieldKind = 'setImmediate' | 'scheduler.yield' | 'MessageChannel' | 'setTimeout';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* THE choice of how to return to the event loop, made ONCE (at module load for `globalThis`): `setImmediate` (Node), else
|
|
28
|
+
* `scheduler.yield` (Chromium), else a `MessageChannel` message (browsers, Workers — a hidden tab throttles `setTimeout(0)` to
|
|
29
|
+
* ≥ 1 s, a message is not throttled), else `setTimeout(0)`. Every function is captured here, so fake timers installed later
|
|
30
|
+
* never reach it.
|
|
31
|
+
*/
|
|
32
|
+
export function pickYield(host: YieldHost): { kind: YieldKind; yield: () => Promise<void> } {
|
|
33
|
+
const immediate = host.setImmediate;
|
|
34
|
+
if (typeof immediate === 'function') return { kind: 'setImmediate', yield: () => new Promise((r) => { immediate.call(host, r); }) };
|
|
35
|
+
const scheduler = host.scheduler;
|
|
36
|
+
const schedulerYield = scheduler?.yield;
|
|
37
|
+
if (typeof schedulerYield === 'function') return { kind: 'scheduler.yield', yield: () => schedulerYield.call(scheduler) };
|
|
38
|
+
if (typeof host.MessageChannel === 'function') {
|
|
39
|
+
const channel = new host.MessageChannel();
|
|
40
|
+
const waiting: Array<() => void> = [];
|
|
41
|
+
channel.port1.onmessage = () => { waiting.shift()?.(); };
|
|
42
|
+
return { kind: 'MessageChannel', yield: () => new Promise((r) => { waiting.push(r); channel.port2.postMessage(0); }) };
|
|
43
|
+
}
|
|
44
|
+
const timeout = host.setTimeout;
|
|
45
|
+
if (typeof timeout === 'function') return { kind: 'setTimeout', yield: () => new Promise((r) => { timeout.call(host, r, 0); }) };
|
|
46
|
+
// No timer at all: a resolved promise still lets other microtasks run.
|
|
47
|
+
return { kind: 'setTimeout', yield: () => Promise.resolve() };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const g = globalThis as YieldHost & { performance?: { now(): number } };
|
|
51
|
+
const picked = pickYield(g);
|
|
52
|
+
const clock: () => number = g.performance && typeof g.performance.now === 'function' ? g.performance.now.bind(g.performance) : Date.now;
|
|
53
|
+
|
|
54
|
+
/** Returns to the event loop once (one macrotask). */
|
|
55
|
+
export function yieldToEventLoop(): Promise<void> {
|
|
56
|
+
return picked.yield();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface CooperativeBudget {
|
|
60
|
+
/** Whether the work since the last yield exceeded the budget (cheap: one clock read). */
|
|
61
|
+
due(): boolean;
|
|
62
|
+
/** Yields to the event loop and restarts the budget. */
|
|
63
|
+
pause(): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A work budget: `if (budget.due()) await budget.pause();` inside a long loop. */
|
|
67
|
+
export function cooperativeBudget(budgetMs = COOPERATIVE_BUDGET_MS): CooperativeBudget {
|
|
68
|
+
let since = clock();
|
|
69
|
+
return {
|
|
70
|
+
due: () => clock() - since >= budgetMs,
|
|
71
|
+
pause: async () => {
|
|
72
|
+
await yieldToEventLoop();
|
|
73
|
+
since = clock();
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -119,3 +119,33 @@ describe('docs findings and cards', () => {
|
|
|
119
119
|
expect(setup.hash).toMatch(/^[0-9a-f]{64}$/);
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
|
+
|
|
123
|
+
describe('extensionless link resolution (build time)', () => {
|
|
124
|
+
const LINK_FILES: Record<string, string> = {
|
|
125
|
+
'gateway/index.md': '# Gateway\n\nSee [trouble](/gateway/troubleshooting), [rel](./authentication) and [gone](/gateway/nope).\n',
|
|
126
|
+
'gateway/troubleshooting.md': '# Trouble\n\nx\n',
|
|
127
|
+
'gateway/authentication.md': '# Auth\n\ny\n',
|
|
128
|
+
};
|
|
129
|
+
const linkSource = (path: string): SourceDocument =>
|
|
130
|
+
asPathSource({ id: path, tenantId: 't', content: { kind: 'text', text: LINK_FILES[path]! } }, path, `h:${path}`);
|
|
131
|
+
const linkExtract = (path: string): Extracted => {
|
|
132
|
+
const src = linkSource(path);
|
|
133
|
+
return markdownParser.extract!(src, markdownParser.parse(src), ctx);
|
|
134
|
+
};
|
|
135
|
+
const lg = buildGraph({ rootId: ROOT, extracted: Object.keys(LINK_FILES).map(linkExtract), facts: [], relations: [], packs: [DOCS_PACK] });
|
|
136
|
+
|
|
137
|
+
it('resolves an extensionless link to the existing sibling document, not a missing placeholder', () => {
|
|
138
|
+
expect(lg.nodes.some((n) => n.kind === 'missing' && n.ref === ref('gateway/troubleshooting'))).toBe(false);
|
|
139
|
+
expect(lg.nodes.some((n) => n.kind === 'missing' && n.ref === ref('gateway/authentication'))).toBe(false);
|
|
140
|
+
// the links edge now targets the real .md file node, in the same folder as the written target
|
|
141
|
+
expect(lg.edges.some((e) => e.kind === 'links' && e.to === ref('gateway/troubleshooting.md'))).toBe(true);
|
|
142
|
+
expect(lg.edges.some((e) => e.kind === 'links' && e.to === ref('gateway/authentication.md'))).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('still reports a link with no matching file as broken', () => {
|
|
146
|
+
expect(lg.nodes.find((n) => n.ref === ref('gateway/nope'))?.kind).toBe('missing');
|
|
147
|
+
const broken = lg.findings.filter((f) => f.kind === 'broken-link');
|
|
148
|
+
expect(broken).toHaveLength(1);
|
|
149
|
+
expect(broken[0]!.nodes).toEqual([ref('gateway/index.md'), ref('gateway/nope')]);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/ignoreMatcher.ts — THE `.gitignore`-style matcher of a review (plan.ts asks it about every listed file).
|
|
3
|
+
*
|
|
4
|
+
* Semantics (unchanged since it lived in sources.ts): `#` comments, `!` negation, a trailing `/` for directories only, a
|
|
5
|
+
* `/` elsewhere anchors the pattern (to its base), otherwise any depth. A path's CANDIDATES are its ancestor folders, plus
|
|
6
|
+
* the path itself for a rule that is not directory-only; the LAST rule that matches any candidate decides (a negation
|
|
7
|
+
* re-includes). Unlike git, a negation may re-include a file under an excluded folder.
|
|
8
|
+
*
|
|
9
|
+
* Cost: "the last rule that matches any candidate" is the largest index of a matching rule over the candidates, and the
|
|
10
|
+
* candidates of a path are its parent folder's candidates plus one more. So the matcher keeps, per folder, the largest
|
|
11
|
+
* index of a rule matching that folder or an ancestor, and the rules whose literal prefix can still match below it
|
|
12
|
+
* ({@link IGNORE_DIR_CACHE_LIMIT} folders at most). It tests only those rules ABOVE the index — each folder once per walk,
|
|
13
|
+
* each file only against its folder's remaining non-directory rules — and a literal prefix/suffix check skips the regex for
|
|
14
|
+
* a candidate that cannot match (a nested `.gitignore`'s rules all start with `base/`). Same answers as testing every rule
|
|
15
|
+
* against every candidate (regression.ignoreMatcher.test.ts).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { globToRegExp } from './partitions.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Always ignored: VCS internals, installed dependencies, builderforce config, and lockfiles (`yarn.lock`, `Cargo.lock` …): generated,
|
|
22
|
+
* huge, and plain text — extracted they would cost judgement calls for nothing; they were never stored (once skipped as binary).
|
|
23
|
+
* A `.builderforce/ignore` rule can still re-include one (`!yarn.lock`).
|
|
24
|
+
*/
|
|
25
|
+
const DEFAULT_IGNORES = ['.git/', 'node_modules/', '.builderforce/', '.gitignore', '*.lock'];
|
|
26
|
+
|
|
27
|
+
/** How many folders' answers a matcher remembers; past it the memo starts over (answers stay exact, only work repeats). */
|
|
28
|
+
const IGNORE_DIR_CACHE_LIMIT = 100_000;
|
|
29
|
+
|
|
30
|
+
interface IgnoreRule {
|
|
31
|
+
glob: string;
|
|
32
|
+
negate: boolean;
|
|
33
|
+
dirOnly: boolean;
|
|
34
|
+
/** The literal text every match starts with / ends with ('' when the glob starts / ends with a wildcard). */
|
|
35
|
+
prefix: string;
|
|
36
|
+
suffix: string;
|
|
37
|
+
re: RegExp;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Characters with a meaning in a glob (partitions.ts globToRegExp): everything else is literal. */
|
|
41
|
+
const SPECIAL = new Set(['*', '?', '{', '}', '\\']);
|
|
42
|
+
|
|
43
|
+
function literalPrefix(glob: string): string {
|
|
44
|
+
let i = 0;
|
|
45
|
+
while (i < glob.length && !SPECIAL.has(glob[i]!)) i++;
|
|
46
|
+
return glob.slice(0, i);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function literalSuffix(glob: string): string {
|
|
50
|
+
let i = glob.length;
|
|
51
|
+
while (i > 0 && !SPECIAL.has(glob[i - 1]!)) i--;
|
|
52
|
+
// `**/` may match nothing (`**/x` matches `x`), so the slash after a `**` is not a required literal.
|
|
53
|
+
if (glob[i] === '/' && glob.slice(i - 2, i) === '**') i++;
|
|
54
|
+
return glob.slice(i);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* What the matcher remembers of a folder: `top`, the largest index of a rule matching the folder or an ancestor (-1: none),
|
|
59
|
+
* and `live`, the indices (ascending) of the rules that can still match the folder's descendants — those whose literal
|
|
60
|
+
* prefix agrees with `folder/` (a nested `.gitignore`'s rules drop out everywhere outside its base).
|
|
61
|
+
*/
|
|
62
|
+
interface DirEntry {
|
|
63
|
+
top: number;
|
|
64
|
+
live: readonly number[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const matches = (r: IgnoreRule, candidate: string): boolean =>
|
|
68
|
+
candidate.startsWith(r.prefix) && candidate.endsWith(r.suffix) && r.re.test(candidate);
|
|
69
|
+
|
|
70
|
+
/** The rules of the ignore texts, in precedence order (the defaults first). */
|
|
71
|
+
function parseRules(texts: ReadonlyArray<string | { text: string; base: string }>): IgnoreRule[] {
|
|
72
|
+
const rules: IgnoreRule[] = [];
|
|
73
|
+
const lines = [
|
|
74
|
+
...DEFAULT_IGNORES.map((line) => ({ line, base: '' })),
|
|
75
|
+
...texts.flatMap((t) => {
|
|
76
|
+
const { text, base } = typeof t === 'string' ? { text: t, base: '' } : t;
|
|
77
|
+
return text.split(/\r?\n/).map((line) => ({ line, base }));
|
|
78
|
+
}),
|
|
79
|
+
];
|
|
80
|
+
for (const { line, base } of lines) {
|
|
81
|
+
let p = line.replace(/\s+$/, '');
|
|
82
|
+
if (!p || p.startsWith('#')) continue;
|
|
83
|
+
const negate = p.startsWith('!');
|
|
84
|
+
if (negate) p = p.slice(1);
|
|
85
|
+
const dirOnly = p.endsWith('/');
|
|
86
|
+
if (dirOnly) p = p.slice(0, -1);
|
|
87
|
+
const anchored = p.includes('/');
|
|
88
|
+
p = p.replace(/^\//, '');
|
|
89
|
+
// A nested `.gitignore` scopes its patterns to its own folder.
|
|
90
|
+
const prefix = base ? `${base}/` : '';
|
|
91
|
+
if (!p) continue;
|
|
92
|
+
const glob = anchored ? `${prefix}${p}` : `${prefix}**/${p}`;
|
|
93
|
+
rules.push({ glob, negate, dirOnly, prefix: literalPrefix(glob), suffix: literalSuffix(glob), re: globToRegExp(glob) });
|
|
94
|
+
}
|
|
95
|
+
return rules;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A `.gitignore`-style matcher: `#` comments, `!` negation (last match wins), a trailing
|
|
100
|
+
* `/` for directories only, a `/` elsewhere anchors to the root, otherwise any depth.
|
|
101
|
+
*/
|
|
102
|
+
export function ignoreMatcher(texts: ReadonlyArray<string | { text: string; base: string }>): (path: string) => boolean {
|
|
103
|
+
const rules = parseRules(texts);
|
|
104
|
+
const root: DirEntry = { top: -1, live: rules.map((_, i) => i) };
|
|
105
|
+
const dirs = new Map<string, DirEntry>();
|
|
106
|
+
|
|
107
|
+
/** The largest index above `floor` among `live` of a rule (all, or only non-directory ones) matching `candidate`, else `floor`. */
|
|
108
|
+
const topAbove = (candidate: string, live: readonly number[], floor: number, dirOnlyToo: boolean): number => {
|
|
109
|
+
for (let k = live.length - 1; k >= 0; k--) {
|
|
110
|
+
const i = live[k]!;
|
|
111
|
+
if (i <= floor) break;
|
|
112
|
+
const r = rules[i]!;
|
|
113
|
+
if ((dirOnlyToo || !r.dirOnly) && matches(r, candidate)) return i;
|
|
114
|
+
}
|
|
115
|
+
return floor;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** The entry of `dir`, from its parent's: the rules that can still match below it are those whose literal prefix agrees with `dir/`. */
|
|
119
|
+
const entryOf = (dir: string, parent: DirEntry): DirEntry => {
|
|
120
|
+
const top = topAbove(dir, parent.live, parent.top, true);
|
|
121
|
+
const below = `${dir}/`;
|
|
122
|
+
const live = parent.live.filter((i) => { const p = rules[i]!.prefix; return p.startsWith(below) || below.startsWith(p); });
|
|
123
|
+
return { top, live: live.length === parent.live.length ? parent.live : live };
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return (path) => {
|
|
127
|
+
const segments = path.split('/');
|
|
128
|
+
let entry = root;
|
|
129
|
+
let dir = '';
|
|
130
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
131
|
+
dir = i === 0 ? segments[0]! : `${dir}/${segments[i]!}`;
|
|
132
|
+
let next = dirs.get(dir);
|
|
133
|
+
if (!next) {
|
|
134
|
+
next = entryOf(dir, entry);
|
|
135
|
+
if (dirs.size >= IGNORE_DIR_CACHE_LIMIT) dirs.clear();
|
|
136
|
+
dirs.set(dir, next);
|
|
137
|
+
}
|
|
138
|
+
entry = next;
|
|
139
|
+
}
|
|
140
|
+
const top = topAbove(path, entry.live, entry.top, false);
|
|
141
|
+
return top >= 0 && !rules[top]!.negate;
|
|
142
|
+
};
|
|
143
|
+
}
|
package/src/knowledge/index.ts
CHANGED
|
@@ -66,6 +66,8 @@ export { defineRule, DEFAULT_RULE_HOPS, MAX_RULE_HOPS } from './rules/factRule.j
|
|
|
66
66
|
export type { FactRule, RuleInput, RuleScope } from './rules/factRule.js';
|
|
67
67
|
export { evaluateRules, importNeighbours, derivedRowKey } from './rules/evaluateRules.js';
|
|
68
68
|
export type { RuleWorld, DerivedRow, DerivedRows, RuleTraceEntry, RuleEvaluation } from './rules/evaluateRules.js';
|
|
69
|
+
export { evaluateRulesFixpoint, isRowSourceInput, MAX_FIXPOINT_ITERATIONS } from './rules/fixpointRules.js';
|
|
70
|
+
export type { FixpointResult, RowSourceInput } from './rules/fixpointRules.js';
|
|
69
71
|
export { emptyFactGraph, updateFactGraph, buildFactGraph, factGraphDump, FACT_GRAPH_DUMP_VERSION } from './rules/factGraph.js';
|
|
70
72
|
export type { FactGraph, FactManifestEntry, FactChange, FactGraphOptions, FactGraphUpdate } from './rules/factGraph.js';
|
|
71
73
|
export { knowledgeFacts, knowledgeInputHash, runKnowledgeRules, packOfRef, KNOWLEDGE_INPUT } from './rules/knowledgeInput.js';
|
|
@@ -107,6 +109,11 @@ export type { ExtractorState } from './owedFiles.js';
|
|
|
107
109
|
export { contentHash, CONTENT_HASH_RULE, BASELINE_CONTENT_HASH_RULE, contentHashRuleOf } from './contentHash.js';
|
|
108
110
|
export { merkleTree, changedPaths, canonicalListing } from './merkle.js';
|
|
109
111
|
export type { MerkleTree, MerkleEntry, MerkleKind, ListingSkipReason } from './merkle.js';
|
|
112
|
+
// PRD 41 §B2 steps 1–2: the stat prefilter (size + mtimeNs + fileId, BigInt) with git's racy-file rule.
|
|
113
|
+
export {
|
|
114
|
+
RACY_WINDOW_MS, statManifestKey, statMatches, isRacy, prefilterStats, createStatPrefilter, loadStatManifest, saveStatManifest,
|
|
115
|
+
} from './statManifest.js';
|
|
116
|
+
export type { StatRecord, StatManifestEntry, PrefilterDecision } from './statManifest.js';
|
|
110
117
|
export { normalizePath, isRootFilePath } from './refs.js';
|
|
111
118
|
export { reviewDirectory, assertStoredBatch } from './review.js';
|
|
112
119
|
export { orderForJudging } from './judgePriority.js';
|
package/src/knowledge/plan.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
isAssetPath, isDocumentPath, manifestMap, resolveDocument, stubSource,
|
|
19
19
|
} from './sources.js';
|
|
20
20
|
import { compareStr, FALLBACK_PACK_ID, sortBy } from './refs.js';
|
|
21
|
+
import { cooperativeBudget } from './cooperative.js';
|
|
21
22
|
|
|
22
23
|
/** ≈ bytes per judged section, for the estimate (the plan does not read changed files). */
|
|
23
24
|
export const AVG_SECTION_BYTES = 1500;
|
|
@@ -94,6 +95,12 @@ export interface PlanDetail {
|
|
|
94
95
|
carried: string[];
|
|
95
96
|
/** The directory Merkle tree over `files` (PRD 41 §B2 step 4): `plan.merkleRoot` is its root. Optional so a hand-built detail stays valid. */
|
|
96
97
|
merkle?: MerkleTree;
|
|
98
|
+
/**
|
|
99
|
+
* Bumped whenever the manifest or PlanDetail shape changes (PRD 41 §B8: a result built from a mixed generation is
|
|
100
|
+
* discarded). The plan digest (`ReviewReport.digest`) includes it, so a shape change moves every scope's digest and
|
|
101
|
+
* the two sides of a run delta never compare across a shape change.
|
|
102
|
+
*/
|
|
103
|
+
planShapeVersion: number;
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
/** The ONE classification of a listed file: did its content move, is it owed, is it re-processed. */
|
|
@@ -119,11 +126,17 @@ export async function planDetail(
|
|
|
119
126
|
opts: PlanOptions = {},
|
|
120
127
|
): Promise<PlanDetail> {
|
|
121
128
|
const maxBytes = opts.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES;
|
|
129
|
+
// A host may plan on its UI thread over tens of thousands of files: every long loop hands the event loop back (cooperative.ts).
|
|
130
|
+
const budget = cooperativeBudget();
|
|
122
131
|
const listed: Array<{ path: string; hash: string; size: number }> = [];
|
|
123
|
-
for await (const entry of source.list())
|
|
132
|
+
for await (const entry of source.list()) {
|
|
133
|
+
listed.push(entry);
|
|
134
|
+
if (budget.due()) await budget.pause();
|
|
135
|
+
}
|
|
124
136
|
// The ONE normalization (POSIX, NFC) — so plan paths are Merkle paths — and a listing that cannot break the plan: invalid and
|
|
125
137
|
// colliding paths are skipped with a reason (merkle.ts canonicalListing), never thrown.
|
|
126
138
|
const listing = canonicalListing(listed);
|
|
139
|
+
if (budget.due()) await budget.pause();
|
|
127
140
|
const entries = sortBy(listing.kept, (e) => e.path);
|
|
128
141
|
const listedOf = new Map(entries.filter((e) => e.listedPath !== undefined).map((e) => [e.path, e.listedPath!] as const));
|
|
129
142
|
|
|
@@ -153,6 +166,7 @@ export async function planDetail(
|
|
|
153
166
|
let estimatedSections = 0;
|
|
154
167
|
let compareSections = 0;
|
|
155
168
|
for (const e of entries) {
|
|
169
|
+
if (budget.due()) await budget.pause();
|
|
156
170
|
if (ignored(e.path)) { skipped.push({ path: e.path, reason: 'ignored' }); continue; }
|
|
157
171
|
const document = isDocumentPath(e.path) ? resolveDocument(composed, e.path) : undefined;
|
|
158
172
|
// An asset is never read, so the size cap does not apply: it is planned, hashed and diffed, and costs no model call.
|
|
@@ -196,7 +210,9 @@ export async function planDetail(
|
|
|
196
210
|
const awaiting = compares ? (await manifestMap(manifest, compareManifestKey(source.rootId))).size : 0;
|
|
197
211
|
const compareCalls = compares ? Math.ceil((compareSections + awaiting) / SECTIONS_PER_COMPARE) : 0;
|
|
198
212
|
const sortedByPack = Object.fromEntries(Object.keys(byPack).sort(compareStr).map((k) => [k, byPack[k]!]));
|
|
213
|
+
if (budget.due()) await budget.pause();
|
|
199
214
|
const merkle = merkleTree(files);
|
|
215
|
+
const planShapeVersion = 2; // 2 (2026-11-14, PRD 41 B2): the plan gained the stat-manifest identity; bump on any PlanDetail/manifest-shape change
|
|
200
216
|
return {
|
|
201
217
|
plan: {
|
|
202
218
|
rootId: source.rootId,
|
|
@@ -215,6 +231,7 @@ export async function planDetail(
|
|
|
215
231
|
extractor,
|
|
216
232
|
carried: carriedOwed(extractor, prior, files.map((f) => f.path)),
|
|
217
233
|
merkle,
|
|
234
|
+
planShapeVersion,
|
|
218
235
|
};
|
|
219
236
|
}
|
|
220
237
|
|
|
@@ -244,5 +261,7 @@ export async function refreshPlan(detail: PlanDetail, manifest: IngestManifest,
|
|
|
244
261
|
extractor,
|
|
245
262
|
carried: carriedOwed(extractor, prior, files.map((f) => f.path)),
|
|
246
263
|
...(detail.merkle ? { merkle: detail.merkle } : {}),
|
|
264
|
+
// *Continue* is the same manifest generation: the shape of what it continues is the shape it had.
|
|
265
|
+
planShapeVersion: detail.planShapeVersion,
|
|
247
266
|
};
|
|
248
267
|
}
|
|
@@ -38,7 +38,12 @@ export async function runAnalyzers(c: ReviewContext): Promise<void> {
|
|
|
38
38
|
try {
|
|
39
39
|
return await p.analyzers!.analyse(c.rootId, signal, onProgress);
|
|
40
40
|
} catch (error) {
|
|
41
|
-
|
|
41
|
+
// Never silent, never zero-findings: the run records the failure AND flags the pack's analysis as not
|
|
42
|
+
// measured, so the compare marks its findings `not_comparable` (`analyzer-failed:<id>`) instead of
|
|
43
|
+
// presenting a missing run as a fix (PRD 41 §8 Part B, §C9).
|
|
44
|
+
const reason = reasonOf(error);
|
|
45
|
+
c.report.failures.push({ kind: 'analyzer', path: analyzerFailurePath(p.id), phase: 'analyse', reason });
|
|
46
|
+
(c.report.analyzerStatus ??= []).push({ id: p.id, status: 'failed', reason });
|
|
42
47
|
return [];
|
|
43
48
|
} finally { settled = true; }
|
|
44
49
|
}),
|
|
@@ -47,7 +47,13 @@ export async function finishReview(c: ReviewContext, flush: () => Promise<void>)
|
|
|
47
47
|
report.judged = c.batch.judged;
|
|
48
48
|
report.unjudged = c.batch.unjudged;
|
|
49
49
|
report.invalidJudgements = c.batch.invalid;
|
|
50
|
-
|
|
50
|
+
// The digest covers the root, the packs, the files manifest AND the plan/manifest shape version (PRD 41 §B8.4): a shape
|
|
51
|
+
// change moves every scope's digest, so two sides of a run delta never compare across one.
|
|
52
|
+
report.digest = sha256Hex(canonicalJson({
|
|
53
|
+
rootId: c.rootId, packs: c.packIds,
|
|
54
|
+
files: [...c.filesNow].sort((a, b) => compareStr(a[0], b[0])),
|
|
55
|
+
planShapeVersion: c.detail.planShapeVersion ?? 1,
|
|
56
|
+
}));
|
|
51
57
|
await saveManifestMap(manifest, filesManifestKey(c.rootId), c.filesNow);
|
|
52
58
|
await saveManifestMap(manifest, judgedManifestKey(c.rootId), c.judgedNow);
|
|
53
59
|
// After every run: today's version and every file still owed a re-extraction — the unfinished ones,
|
|
@@ -99,6 +99,12 @@ export interface ReviewReport {
|
|
|
99
99
|
awaitingJudgeCount?: number;
|
|
100
100
|
/** Pass 2 (`only`): files of the slice judged to completion. */
|
|
101
101
|
judgedFiles?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Analyzers that did not complete (PRD 41 §8, C9): status `'failed'` when it ran and errored, `'not_measured'` when it did
|
|
104
|
+
* not run at all. A failed analyzer is NEVER presented as zero findings — the compare marks that tool's findings
|
|
105
|
+
* `not_comparable` (reason `analyzer-failed:<tool>`) rather than resolving them.
|
|
106
|
+
*/
|
|
107
|
+
analyzerStatus?: Array<{ id: string; status: 'failed' | 'not_measured'; reason?: string }>;
|
|
102
108
|
/** Judging was stopped for this run after consecutive provider failures (A10 rule 9); the files stay owed. */
|
|
103
109
|
judgeStopped?: string;
|
|
104
110
|
aborted: boolean;
|