@seanhogg/builderforce-memory 2026.10.32 → 2026.10.33
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/index.d.ts +2 -1
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/judge.d.ts +14 -1
- package/dist/knowledge/judge.d.ts.map +1 -1
- package/dist/knowledge/judge.js +26 -3
- package/dist/knowledge/judge.js.map +1 -1
- package/dist/knowledge/owedFiles.d.ts +68 -0
- package/dist/knowledge/owedFiles.d.ts.map +1 -0
- package/dist/knowledge/owedFiles.js +86 -0
- package/dist/knowledge/owedFiles.js.map +1 -0
- package/dist/knowledge/plan.d.ts +22 -3
- package/dist/knowledge/plan.d.ts.map +1 -1
- package/dist/knowledge/plan.js +43 -18
- package/dist/knowledge/plan.js.map +1 -1
- package/dist/knowledge/review.d.ts +3 -1
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +43 -13
- package/dist/knowledge/review.js.map +1 -1
- package/dist/knowledge/reviewCompare.d.ts +6 -5
- package/dist/knowledge/reviewCompare.d.ts.map +1 -1
- package/dist/knowledge/reviewCompare.js +27 -16
- package/dist/knowledge/reviewCompare.js.map +1 -1
- package/dist/knowledge/reviewModel.d.ts +8 -2
- package/dist/knowledge/reviewModel.d.ts.map +1 -1
- package/dist/knowledge/sources.d.ts +5 -7
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +5 -12
- package/dist/knowledge/sources.js.map +1 -1
- package/package.json +3 -3
- package/src/knowledge/index.ts +3 -1
- package/src/knowledge/judge.clamp.test.ts +61 -0
- package/src/knowledge/judge.ts +27 -3
- package/src/knowledge/owedFiles.ts +108 -0
- package/src/knowledge/plan.ts +61 -19
- package/src/knowledge/review.estimate.test.ts +112 -0
- package/src/knowledge/review.owed.test.ts +379 -0
- package/src/knowledge/review.ts +39 -14
- package/src/knowledge/review.upgrade.test.ts +86 -21
- package/src/knowledge/reviewCompare.ts +26 -14
- package/src/knowledge/reviewModel.ts +8 -2
- package/src/knowledge/sources.ts +5 -14
- package/src/knowledge/testkit.test-util.ts +24 -1
|
@@ -9,24 +9,19 @@ import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
|
9
9
|
import { hashText } from '../ingest/hash.js';
|
|
10
10
|
import { markdownParser } from '../ingest/parsers.js';
|
|
11
11
|
import { buildGraph, graphDigest } from './build.js';
|
|
12
|
-
import type { ExtractContext,
|
|
12
|
+
import type { ExtractContext, KnowledgePack } from './model.js';
|
|
13
13
|
import { DOCS_PACK } from './packs/docs.js';
|
|
14
14
|
import { planReview } from './plan.js';
|
|
15
15
|
import { reviewDirectory } from './review.js';
|
|
16
16
|
import { MAX_AWAITING_CLAIMS, saveAwaiting, type PendingClaims } from './reviewCompare.js';
|
|
17
17
|
import {
|
|
18
18
|
asPathSource, compareManifestKey, EXTRACTOR_VERSION, extractorManifestKey, filesManifestKey, judgedManifestKey, manifestMap,
|
|
19
|
-
resolveRelativePath,
|
|
19
|
+
resolveRelativePath,
|
|
20
20
|
} from './sources.js';
|
|
21
21
|
import {
|
|
22
|
-
edge, extractedOf, fakeJudge, fileNode, memSource, memStore, ref, ROOT,
|
|
22
|
+
args, edge, extractedOf, fakeJudge, FILES, fileNode, memSource, memStore, quietPack, ref, ROOT, similar, stateOf,
|
|
23
23
|
} from './testkit.test-util.js';
|
|
24
|
-
import { canonicalJson, srcRef } from './refs.js';
|
|
25
|
-
|
|
26
|
-
const args = (source: SpySource, store = memStore(), manifest = new InMemoryIngestManifest(), extra: Partial<ReviewArgs> = {}): ReviewArgs =>
|
|
27
|
-
({ source, store, manifest, packs: [DOCS_PACK], budget: { modelCalls: 200, ms: 60_000 }, ...extra });
|
|
28
|
-
|
|
29
|
-
const FILES = { 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n', 'c.md': '# C\ngamma\n' };
|
|
24
|
+
import { canonicalJson, factRef, srcRef } from './refs.js';
|
|
30
25
|
|
|
31
26
|
describe('the extractor version has its own manifest entry', () => {
|
|
32
27
|
it('the files manifest keeps the key consumers read', () => {
|
|
@@ -34,12 +29,12 @@ describe('the extractor version has its own manifest entry', () => {
|
|
|
34
29
|
expect(extractorManifestKey(ROOT)).toBe(`knowledge:${ROOT}:extractor`);
|
|
35
30
|
});
|
|
36
31
|
|
|
37
|
-
it('an old manifest (files, no version entry) re-extracts once, still detects removals, and
|
|
32
|
+
it('an old manifest (files, no version entry) re-extracts once, still detects removals, and re-anchors unchanged sections', async () => {
|
|
38
33
|
const source = memSource({ ...FILES });
|
|
39
34
|
const store = memStore();
|
|
40
35
|
const manifest = new InMemoryIngestManifest();
|
|
41
36
|
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
42
|
-
expect(await
|
|
37
|
+
expect(await stateOf(manifest)).toEqual({ version: EXTRACTOR_VERSION, owed: [] });
|
|
43
38
|
expect((await manifest.get(filesManifestKey(ROOT)))!.map((f) => f.id)).toEqual(['a.md', 'b.md', 'c.md']);
|
|
44
39
|
|
|
45
40
|
delete source.files['b.md'];
|
|
@@ -51,24 +46,29 @@ describe('the extractor version has its own manifest entry', () => {
|
|
|
51
46
|
const old = await planReview(source, manifest, [DOCS_PACK]);
|
|
52
47
|
expect(old.removed).toEqual(['b.md']);
|
|
53
48
|
expect(old.changed).toEqual(['a.md', 'c.md']);
|
|
54
|
-
expect(old.estimatedModelCalls).toBe(withVersion.estimatedModelCalls);
|
|
55
49
|
|
|
56
50
|
const judge = fakeJudge();
|
|
57
51
|
const report = await reviewDirectory(args(source, store, manifest, { judgement: judge }));
|
|
58
52
|
expect(report.extracted).toBe(2);
|
|
59
53
|
expect(judge.requests.filter((r) => r.kind === 'extract')).toHaveLength(1); // c.md only; a.md is re-anchored
|
|
60
54
|
expect([...(await manifestMap(manifest, filesManifestKey(ROOT))).keys()]).toEqual(['a.md', 'c.md']);
|
|
61
|
-
expect(await
|
|
55
|
+
expect(await stateOf(manifest)).toEqual({ version: EXTRACTOR_VERSION, owed: [] });
|
|
62
56
|
expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual([]);
|
|
63
57
|
});
|
|
64
58
|
|
|
65
|
-
it('an aborted run
|
|
59
|
+
it('an aborted upgrade run records the version and owes the files it never reached', async () => {
|
|
60
|
+
const source = memSource({ ...FILES });
|
|
61
|
+
const store = memStore();
|
|
62
|
+
const manifest = new InMemoryIngestManifest();
|
|
63
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
64
|
+
await manifest.delete(extractorManifestKey(ROOT));
|
|
65
|
+
|
|
66
66
|
const controller = new AbortController();
|
|
67
67
|
controller.abort();
|
|
68
|
-
const
|
|
69
|
-
const report = await reviewDirectory(args(memSource({ ...FILES }), memStore(), manifest, { signal: controller.signal }));
|
|
68
|
+
const report = await reviewDirectory(args(source, store, manifest, { signal: controller.signal }));
|
|
70
69
|
expect(report.aborted).toBe(true);
|
|
71
|
-
expect(await
|
|
70
|
+
expect(await stateOf(manifest)).toEqual({ version: EXTRACTOR_VERSION, owed: ['a.md', 'b.md', 'c.md'] });
|
|
71
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual(['a.md', 'b.md', 'c.md']);
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
74
|
|
|
@@ -139,28 +139,93 @@ describe('bookkeeping of removed and binary files', () => {
|
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
describe('the compare phase', () => {
|
|
142
|
-
it('keeps
|
|
142
|
+
it('keeps the claims awaiting when the host has no similar port, so a later run with one can compare them', async () => {
|
|
143
143
|
const manifest = new InMemoryIngestManifest();
|
|
144
144
|
await reviewDirectory(args(memSource({ ...FILES }), memStore(), manifest, { judgement: fakeJudge() }));
|
|
145
|
-
expect((await manifestMap(manifest, compareManifestKey(ROOT))).size).
|
|
145
|
+
expect((await manifestMap(manifest, compareManifestKey(ROOT))).size).toBeGreaterThan(0);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('an extracted-only run (no judgement port) leaves the awaiting set intact', async () => {
|
|
149
|
+
const source = memSource({ ...FILES });
|
|
150
|
+
const store = memStore();
|
|
151
|
+
const manifest = new InMemoryIngestManifest();
|
|
152
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
153
|
+
const before = await manifest.get(compareManifestKey(ROOT));
|
|
154
|
+
expect(before!.length).toBeGreaterThan(0);
|
|
155
|
+
|
|
156
|
+
await reviewDirectory(args(source, store, manifest));
|
|
157
|
+
expect(await manifest.get(compareManifestKey(ROOT))).toEqual(before);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('a pack that does not ask for contradictions never touches the awaiting set', async () => {
|
|
161
|
+
const source = memSource({ ...FILES });
|
|
162
|
+
const store = memStore();
|
|
163
|
+
const manifest = new InMemoryIngestManifest();
|
|
164
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
165
|
+
const before = JSON.stringify(await manifest.get(compareManifestKey(ROOT)));
|
|
166
|
+
expect(before).not.toBe('[]');
|
|
167
|
+
|
|
168
|
+
// A new claim exists after this run, yet nothing is saved for it: no pack waits on a compare.
|
|
169
|
+
source.files['a.md'] = '# A\nalphabet\n';
|
|
170
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge(), packs: [quietPack] }));
|
|
171
|
+
expect((await store.facts({ rootId: ROOT })).some((f) => f.content.startsWith('Lease ends alphabet'))).toBe(true);
|
|
172
|
+
expect(JSON.stringify(await manifest.get(compareManifestKey(ROOT)))).toBe(before);
|
|
146
173
|
});
|
|
147
174
|
|
|
148
175
|
it('bounds the awaiting set to the most recent claims', async () => {
|
|
149
176
|
const manifest = new InMemoryIngestManifest();
|
|
150
177
|
const pending: PendingClaims = new Map();
|
|
151
178
|
for (let i = 0; i < MAX_AWAITING_CLAIMS + 50; i++) pending.set(`fact:claim:${String(i).padStart(5, '0')}`, { text: 't', hash: 'h' });
|
|
152
|
-
await saveAwaiting(manifest, ROOT, pending, undefined
|
|
179
|
+
await saveAwaiting(manifest, ROOT, pending, undefined);
|
|
153
180
|
const kept = [...(await manifestMap(manifest, compareManifestKey(ROOT))).keys()];
|
|
154
181
|
expect(kept).toHaveLength(MAX_AWAITING_CLAIMS);
|
|
155
182
|
expect(kept).toContain(`fact:claim:${String(MAX_AWAITING_CLAIMS + 49).padStart(5, '0')}`);
|
|
156
183
|
expect(kept).not.toContain('fact:claim:00000');
|
|
157
184
|
});
|
|
158
185
|
|
|
186
|
+
it('only a pack that asks for contradictions puts its claims up for comparison', async () => {
|
|
187
|
+
const notes: KnowledgePack = {
|
|
188
|
+
id: 'notes',
|
|
189
|
+
parsers: [{ ...markdownParser, id: 'notes-md', accepts: (s) => s.id.endsWith('.txt') }],
|
|
190
|
+
judgement: { nodeKinds: ['section'], claims: true, entities: true, contradictions: false },
|
|
191
|
+
};
|
|
192
|
+
const store = memStore();
|
|
193
|
+
const manifest = new InMemoryIngestManifest();
|
|
194
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'n.txt': '# N\nnotes\n' });
|
|
195
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge(), packs: [notes, DOCS_PACK] }));
|
|
196
|
+
|
|
197
|
+
const claimRef = async (text: string) => {
|
|
198
|
+
const fact = (await store.facts({ rootId: ROOT })).find((f) => f.content.startsWith(text));
|
|
199
|
+
expect(fact).toBeDefined(); // judged either way
|
|
200
|
+
return factRef(fact!.key);
|
|
201
|
+
};
|
|
202
|
+
const awaiting = [...(await manifestMap(manifest, compareManifestKey(ROOT))).keys()];
|
|
203
|
+
expect(awaiting).toEqual([await claimRef('Lease ends alpha')]);
|
|
204
|
+
expect(awaiting).not.toContain(await claimRef('Lease ends notes'));
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('hands the similar port the texts of the pending claims, as the compare reads them', async () => {
|
|
208
|
+
const calls: Array<{ ids: string[]; texts: ReadonlyMap<string, string> | undefined }> = [];
|
|
209
|
+
const spy = async (ids: string[], texts?: ReadonlyMap<string, string>) => {
|
|
210
|
+
calls.push({ ids, texts });
|
|
211
|
+
return similar(ids);
|
|
212
|
+
};
|
|
213
|
+
const judge = fakeJudge();
|
|
214
|
+
await reviewDirectory(args(memSource({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' }), memStore(), new InMemoryIngestManifest(), {
|
|
215
|
+
judgement: judge, similar: spy,
|
|
216
|
+
}));
|
|
217
|
+
expect(calls).toHaveLength(1);
|
|
218
|
+
expect(calls[0]!.ids).toHaveLength(2);
|
|
219
|
+
expect([...calls[0]!.texts!.keys()].sort()).toEqual(calls[0]!.ids);
|
|
220
|
+
expect([...calls[0]!.texts!.values()].sort()).toEqual(['Lease ends alpha', 'Lease ends beta']);
|
|
221
|
+
// The same texts the compare call carries.
|
|
222
|
+
expect(judge.requests.find((r) => r.kind === 'compare')!.items.map((i) => i.text).sort()).toEqual(['Lease ends alpha', 'Lease ends beta']);
|
|
223
|
+
});
|
|
224
|
+
|
|
159
225
|
it('compares a claim left awaiting by its claim text, the form a first run uses', async () => {
|
|
160
226
|
const source = memSource({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' });
|
|
161
227
|
const store = memStore();
|
|
162
228
|
const manifest = new InMemoryIngestManifest();
|
|
163
|
-
const similar = async (ids: string[]) => (ids.length >= 2 ? [{ a: ids[0]!, b: ids[1]!, similarity: 0.95 }] : []);
|
|
164
229
|
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge(), similar, budget: { modelCalls: 2, ms: 60_000 } }));
|
|
165
230
|
const judge = fakeJudge();
|
|
166
231
|
await reviewDirectory(args(source, store, manifest, { judgement: judge, similar }));
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type { IngestManifest } from '../ingest/types.js';
|
|
9
9
|
import { claimTextOf, compareClaims, type CompareOutcome, type JudgeBudget, type JudgedBatch } from './judge.js';
|
|
10
10
|
import type { NodeRef, ReviewArgs, StoredFact } from './model.js';
|
|
11
|
-
import { compareManifestKey
|
|
11
|
+
import { compareManifestKey } from './sources.js';
|
|
12
12
|
import { compareStr, factKeyOf } from './refs.js';
|
|
13
13
|
|
|
14
14
|
/** At most this many claims wait for *Continue*; beyond it the oldest are dropped (the set stays bounded). */
|
|
@@ -17,10 +17,23 @@ export const MAX_AWAITING_CLAIMS = 2000;
|
|
|
17
17
|
/** A claim awaiting comparison: its text and the content hash it was judged from. */
|
|
18
18
|
export type PendingClaims = Map<string, { text: string; hash: string }>;
|
|
19
19
|
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* The compare manifest persists age with each entry — `hash` is `<age>:<fileHash>`, age 0 the
|
|
22
|
+
* oldest — because a host manifest may hand entries back in id order. An entry without an age
|
|
23
|
+
* (written before ages were kept) reads as the oldest.
|
|
24
|
+
*/
|
|
25
|
+
const ageOf = (hash: string): number => {
|
|
26
|
+
const sep = hash.indexOf(':');
|
|
27
|
+
const age = sep < 0 ? NaN : Number(hash.slice(0, sep));
|
|
28
|
+
return Number.isFinite(age) ? age : -1;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Claims a previous run left awaiting comparison, oldest first, read back from their stored facts (a gone fact drops out). */
|
|
21
32
|
export async function pendingClaims(manifest: IngestManifest, rootId: string, facts: ReadonlyMap<string, StoredFact>): Promise<PendingClaims> {
|
|
22
33
|
const out: PendingClaims = new Map();
|
|
23
|
-
|
|
34
|
+
const stored = (await manifest.get(compareManifestKey(rootId))) ?? [];
|
|
35
|
+
const oldestFirst = [...stored].sort((a, b) => ageOf(a.hash) - ageOf(b.hash) || compareStr(a.id, b.id));
|
|
36
|
+
for (const { id: ref } of oldestFirst) {
|
|
24
37
|
const fact = facts.get(factKeyOf(ref as NodeRef) ?? '');
|
|
25
38
|
if (fact?.key.startsWith('claim:')) out.set(ref, { text: claimTextOf(fact.content), hash: fact.fileAnchors[0]?.contentHash ?? '' });
|
|
26
39
|
}
|
|
@@ -37,7 +50,7 @@ export async function compareNew(a: {
|
|
|
37
50
|
}): Promise<CompareOutcome | undefined> {
|
|
38
51
|
const { args, pending } = a;
|
|
39
52
|
if (!args.judgement || !args.similar || pending.size === 0) return undefined;
|
|
40
|
-
const pairs = await args.similar([...pending.keys()].sort(compareStr));
|
|
53
|
+
const pairs = await args.similar([...pending.keys()].sort(compareStr), new Map([...pending].map(([ref, c]) => [ref, c.text] as const)));
|
|
41
54
|
const claims: PendingClaims = new Map(pending);
|
|
42
55
|
for (const p of pairs) {
|
|
43
56
|
for (const id of [p.a, p.b]) {
|
|
@@ -52,17 +65,16 @@ export async function compareNew(a: {
|
|
|
52
65
|
|
|
53
66
|
/**
|
|
54
67
|
* Persists the claims still awaiting comparison, capped at {@link MAX_AWAITING_CLAIMS} (the
|
|
55
|
-
* most recent: a previous run's first, this run's last
|
|
56
|
-
*
|
|
57
|
-
*
|
|
68
|
+
* most recent: a previous run's first, this run's last — and the order survives the reload,
|
|
69
|
+
* see {@link pendingClaims}). Call it only when a pack asks for contradictions; an `outcome`
|
|
70
|
+
* undefined means the compare did not run (no ports, an abort before it), so every pending
|
|
71
|
+
* claim is kept, whereas after a compare only the pairs it skipped still wait.
|
|
58
72
|
*/
|
|
59
73
|
export async function saveAwaiting(
|
|
60
|
-
manifest: IngestManifest, rootId: string, pending: PendingClaims, outcome: CompareOutcome | undefined,
|
|
74
|
+
manifest: IngestManifest, rootId: string, pending: PendingClaims, outcome: CompareOutcome | undefined,
|
|
61
75
|
): Promise<void> {
|
|
62
|
-
const awaiting
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
const kept = awaiting.size > MAX_AWAITING_CLAIMS ? new Map([...awaiting].slice(-MAX_AWAITING_CLAIMS)) : awaiting;
|
|
67
|
-
await saveManifestMap(manifest, compareManifestKey(rootId), kept);
|
|
76
|
+
const awaiting: Array<[string, string]> = [];
|
|
77
|
+
for (const [ref, c] of pending) if (!outcome || outcome.skipped.has(ref)) awaiting.push([ref, c.hash]);
|
|
78
|
+
const kept = awaiting.slice(-MAX_AWAITING_CLAIMS);
|
|
79
|
+
await manifest.set(compareManifestKey(rootId), kept.map(([id, hash], age) => ({ id, hash: `${age}:${hash}` })));
|
|
68
80
|
}
|
|
@@ -63,8 +63,14 @@ export interface ReviewArgs {
|
|
|
63
63
|
packs: KnowledgePack[];
|
|
64
64
|
manifest: IngestManifest;
|
|
65
65
|
judgement?: JudgementPort;
|
|
66
|
-
/**
|
|
67
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Near-duplicate claim pairs to compare / possible-same entities; from the knowledge index.
|
|
68
|
+
* Called with the pending claim refs (sorted) and, as an optional second argument, each
|
|
69
|
+
* ref's claim text (`subject predicate object`, the form the compare uses) — so a host
|
|
70
|
+
* need not re-read every fact to recover what the review already holds. A port that takes
|
|
71
|
+
* only `ids` keeps working.
|
|
72
|
+
*/
|
|
73
|
+
similar?: (ids: string[], texts?: ReadonlyMap<string, string>) => Promise<SimilarPair[]>;
|
|
68
74
|
budget: { modelCalls: number; ms: number };
|
|
69
75
|
/** *Continue*: the plan the person confirmed. Reused without a re-walk; `changed` is re-read from the manifest. */
|
|
70
76
|
plan?: PlanDetail;
|
package/src/knowledge/sources.ts
CHANGED
|
@@ -16,8 +16,9 @@ export const DEFAULT_MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
|
16
16
|
/**
|
|
17
17
|
* Version of the extractors' output. Bump it whenever an extractor emits different nodes,
|
|
18
18
|
* edges or keys for the same text: cached `Extracted` of another version is ignored, and a
|
|
19
|
-
* review that finds a different version in {@link extractorManifestKey}
|
|
20
|
-
*
|
|
19
|
+
* review that finds a different version in {@link extractorManifestKey} owes every file one
|
|
20
|
+
* re-extraction (judged sections with unchanged text are re-anchored, not judged again; see
|
|
21
|
+
* owedFiles.ts for how an unfinished one is carried to the next review).
|
|
21
22
|
*/
|
|
22
23
|
export const EXTRACTOR_VERSION = 1;
|
|
23
24
|
/** Always ignored: VCS internals, installed dependencies, builderforce config. */
|
|
@@ -195,11 +196,11 @@ export function ignoreSourcesOf(paths: readonly string[]): Array<{ path: string;
|
|
|
195
196
|
|
|
196
197
|
/** Manifest entry holding `{ id: path, hash }` for every reviewed file of a root. */
|
|
197
198
|
export const filesManifestKey = (rootId: string): string => `knowledge:${rootId}`;
|
|
198
|
-
/** Manifest entry holding
|
|
199
|
+
/** Manifest entry holding the extractor version the files were last reviewed with, and the files still owed a re-extraction (owedFiles.ts). */
|
|
199
200
|
export const extractorManifestKey = (rootId: string): string => `knowledge:${rootId}:extractor`;
|
|
200
201
|
/** Manifest entry holding `{ id: sectionRef, hash: textHash }` for every judged section. */
|
|
201
202
|
export const judgedManifestKey = (rootId: string): string => `knowledge:${rootId}:judged`;
|
|
202
|
-
/** Manifest entry holding `{ id: claimRef, hash: fileHash }` for every claim still awaiting comparison. */
|
|
203
|
+
/** Manifest entry holding `{ id: claimRef, hash: '<age>:<fileHash>' }` for every claim still awaiting comparison (age 0 = oldest). */
|
|
203
204
|
export const compareManifestKey = (rootId: string): string => `knowledge:${rootId}:compare`;
|
|
204
205
|
|
|
205
206
|
export async function manifestMap(manifest: IngestManifest, key: string): Promise<Map<string, string>> {
|
|
@@ -207,16 +208,6 @@ export async function manifestMap(manifest: IngestManifest, key: string): Promis
|
|
|
207
208
|
return new Map(prior.map((f) => [f.id, f.hash] as const));
|
|
208
209
|
}
|
|
209
210
|
|
|
210
|
-
/** The extractor version a root was last fully reviewed with; undefined when never recorded (a pre-versioning manifest). */
|
|
211
|
-
export async function storedExtractorVersion(manifest: IngestManifest, rootId: string): Promise<number | undefined> {
|
|
212
|
-
const v = Number((await manifestMap(manifest, extractorManifestKey(rootId))).get('version'));
|
|
213
|
-
return Number.isFinite(v) ? v : undefined;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export async function saveExtractorVersion(manifest: IngestManifest, rootId: string): Promise<void> {
|
|
217
|
-
await manifest.set(extractorManifestKey(rootId), [{ id: 'version', hash: String(EXTRACTOR_VERSION) }]);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
211
|
export async function saveManifestMap(manifest: IngestManifest, key: string, map: ReadonlyMap<string, string>): Promise<void> {
|
|
221
212
|
const entries = [...map].sort((a, b) => compareStr(a[0], b[0])).map(([id, hash]) => ({ id, hash }));
|
|
222
213
|
await manifest.set(key, entries);
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { hashText } from '../ingest/hash.js';
|
|
7
|
+
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
7
8
|
import { buildGraph } from './build.js';
|
|
8
9
|
import type {
|
|
9
|
-
DirectorySource, Extracted, JudgementPort, JudgementRequest, JudgementResult, KEdge, KNode, KnowledgeStore, NodeRef,
|
|
10
|
+
DirectorySource, Extracted, JudgementPort, JudgementRequest, JudgementResult, KEdge, KNode, KnowledgePack, KnowledgeStore, NodeRef, ReviewArgs,
|
|
10
11
|
} from './model.js';
|
|
12
|
+
import { loadExtractorState } from './owedFiles.js';
|
|
11
13
|
import { DOCS_PACK } from './packs/docs.js';
|
|
12
14
|
import { LocalSnapshotStore, type SnapshotPersistence } from './stores/localSnapshotStore.js';
|
|
13
15
|
import { srcRef } from './refs.js';
|
|
@@ -48,6 +50,27 @@ export function memStore(): LocalSnapshotStore {
|
|
|
48
50
|
return new LocalSnapshotStore(memPersistence(), { now: () => '2026-10-28T00:00:00.000Z' });
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
/** Three one-section docs, the common fixture of the review tests. */
|
|
54
|
+
export const FILES = { 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n', 'c.md': '# C\ngamma\n' };
|
|
55
|
+
export const ALL = ['a.md', 'b.md', 'c.md'];
|
|
56
|
+
|
|
57
|
+
/** `ReviewArgs` over the docs pack with a generous budget; `extra` overrides anything. */
|
|
58
|
+
export const args = (
|
|
59
|
+
source: SpySource, store: KnowledgeStore = memStore(), manifest = new InMemoryIngestManifest(), extra: Partial<ReviewArgs> = {},
|
|
60
|
+
): ReviewArgs => ({ source, store, manifest, packs: [DOCS_PACK], budget: { modelCalls: 200, ms: 60_000 }, ...extra });
|
|
61
|
+
|
|
62
|
+
/** A root's extractor entry as `{ version, owed: sorted paths }`. */
|
|
63
|
+
export async function stateOf(manifest: InMemoryIngestManifest) {
|
|
64
|
+
const { version, owed } = await loadExtractorState(manifest, ROOT);
|
|
65
|
+
return { version, owed: [...owed.keys()].sort() };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A `similar` port that pairs the first two ids it is given (nothing to pair with fewer). */
|
|
69
|
+
export const similar = async (ids: string[]) => (ids.length >= 2 ? [{ a: ids[0]!, b: ids[1]!, similarity: 0.95 }] : []);
|
|
70
|
+
|
|
71
|
+
/** The docs pack with contradictions off: no compare phase, so no awaiting set. */
|
|
72
|
+
export const quietPack: KnowledgePack = { ...DOCS_PACK, judgement: { ...DOCS_PACK.judgement!, contradictions: false } };
|
|
73
|
+
|
|
51
74
|
/** Answers every extract with one claim + one entity, every compare with `contradicts`. */
|
|
52
75
|
export function fakeJudge(
|
|
53
76
|
shape: (req: JudgementRequest) => JudgementResult = defaultJudgement,
|