@seanhogg/builderforce-memory 2026.10.53 → 2026.10.54
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/backfillNoExtract.d.ts +2 -2
- package/dist/knowledge/backfillNoExtract.js +2 -2
- package/dist/knowledge/extractFile.d.ts.map +1 -1
- package/dist/knowledge/extractFile.js +11 -4
- package/dist/knowledge/extractFile.js.map +1 -1
- package/dist/knowledge/extractJob.d.ts +11 -0
- package/dist/knowledge/extractJob.d.ts.map +1 -1
- package/dist/knowledge/extractJob.js +10 -0
- package/dist/knowledge/extractJob.js.map +1 -1
- package/dist/knowledge/index.d.ts +1 -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/owedFiles.d.ts +8 -1
- package/dist/knowledge/owedFiles.d.ts.map +1 -1
- package/dist/knowledge/owedFiles.js +11 -2
- package/dist/knowledge/owedFiles.js.map +1 -1
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +10 -15
- package/dist/knowledge/review.js.map +1 -1
- package/dist/knowledge/reviewFailure.d.ts +37 -0
- package/dist/knowledge/reviewFailure.d.ts.map +1 -0
- package/dist/knowledge/reviewFailure.js +37 -0
- package/dist/knowledge/reviewFailure.js.map +1 -0
- package/dist/knowledge/reviewPrefetch.d.ts +2 -2
- package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.js +6 -6
- package/dist/knowledge/reviewPrefetch.js.map +1 -1
- package/package.json +3 -3
- package/src/contract/exports.snapshot.json +1 -0
- package/src/contract/regression.recheck.test.ts +228 -0
- package/src/contract/regression.review.test.ts +1 -143
- package/src/contract/types.contract.test.ts +2 -1
- package/src/knowledge/backfillNoExtract.ts +2 -2
- package/src/knowledge/extractFile.ts +6 -4
- package/src/knowledge/extractJob.ts +11 -0
- package/src/knowledge/index.ts +1 -1
- package/src/knowledge/owedFiles.ts +12 -2
- package/src/knowledge/review.ts +10 -10
- package/src/knowledge/reviewFailure.ts +51 -0
- package/src/knowledge/reviewPrefetch.ts +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewPrefetch.d.ts","sourceRoot":"","sources":["../../src/knowledge/reviewPrefetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"reviewPrefetch.d.ts","sourceRoot":"","sources":["../../src/knowledge/reviewPrefetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAiB,kBAAkB,EAAiB,MAAM,iBAAiB,CAAC;AAInF,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAEhE,2FAA2F;AAC3F,MAAM,MAAM,QAAQ,GAAG,CACjB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,CAAC,EAAE,cAAc,CAAC;IAAC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
|
|
12
|
-
import { BinaryContent } from './extractJob.js';
|
|
12
|
+
import { BinaryContent, CHANGED_SINCE_PLAN, ExtractFailed } from './extractJob.js';
|
|
13
13
|
import { judgesPack } from './reviewJudge.js';
|
|
14
|
-
import { createDeadlines
|
|
14
|
+
import { createDeadlines } from './jobDeadline.js';
|
|
15
15
|
import { createModelLimiter } from './modelLimiter.js';
|
|
16
16
|
import { Lanes, reasonOf } from './reviewRunModel.js';
|
|
17
17
|
import { isBinaryText } from './sources.js';
|
|
@@ -26,8 +26,7 @@ export function extractStepOf(path, job) {
|
|
|
26
26
|
case 'extracted': return { ...base, outcome: job.extraction.cached ? 'cached' : 'ok' };
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
export const CHANGED_SINCE_PLAN = 'changed since plan';
|
|
29
|
+
export { CHANGED_SINCE_PLAN };
|
|
31
30
|
/** Per-job ceilings of the extract path (PRD 41 A10 rule 2). */
|
|
32
31
|
export const DEFAULT_READ_TIMEOUT_MS = 5_000;
|
|
33
32
|
export const DEFAULT_EXTRACT_TIMEOUT_MS = 10_000;
|
|
@@ -87,8 +86,9 @@ export function createPrefetch(c) {
|
|
|
87
86
|
catch (error) {
|
|
88
87
|
if (error instanceof BinaryContent)
|
|
89
88
|
return { kind: 'binary' };
|
|
90
|
-
//
|
|
91
|
-
|
|
89
|
+
// Transient UNLESS proven final: only the parser or extractor throwing on these bytes (ExtractFailed) is. A read, a timeout, a crashed or
|
|
90
|
+
// disposed worker, a failing store, a stop: all say nothing final about the file.
|
|
91
|
+
return { kind: 'failed', reason: reasonOf(error), ...(error instanceof ExtractFailed && !c.signal.aborted ? {} : { transient: true }) };
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
return async (f) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewPrefetch.js","sourceRoot":"","sources":["../../src/knowledge/reviewPrefetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO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EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACtC,MAAM,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAc,CAAC;QAChF,uKAAuK;QACvK,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC;YAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;QAC9F,OAAO,GAAG,CAAC;IACf,CAAC,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seanhogg/builderforce-memory",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.54",
|
|
4
4
|
"description": "BuilderForce Agent Memory — runtime layer. SSM execution, Transformer orchestration, online distillation, enterprise RAG (ingestion pipelines, vector-store adapters, tenant/ACL-scoped hybrid retrieval), multi-agent graph orchestration, LLM telemetry and cost accounting, persistent agent memory, and token-saving agent-run memory (code maps, a prompt-cache-safe working memory, chunked transcript windowing) for BuilderForce.ai agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
},
|
|
118
118
|
"homepage": "https://github.com/SeanHogg/builderforce-memory/tree/main/packages/memory#readme",
|
|
119
119
|
"peerDependencies": {
|
|
120
|
-
"@seanhogg/builderforce-memory-engine": "^2026.10.
|
|
120
|
+
"@seanhogg/builderforce-memory-engine": "^2026.10.54"
|
|
121
121
|
},
|
|
122
122
|
"devDependencies": {
|
|
123
123
|
"@jest/globals": "^29.7.0",
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"ts-jest": "^29.2.0",
|
|
132
132
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
133
133
|
"typescript-7": "npm:typescript@^7.0.2",
|
|
134
|
-
"@seanhogg/builderforce-memory-engine": "2026.10.
|
|
134
|
+
"@seanhogg/builderforce-memory-engine": "2026.10.54"
|
|
135
135
|
},
|
|
136
136
|
"jest": {
|
|
137
137
|
"preset": "ts-jest/presets/default-esm",
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/contract/regression.recheck.test.ts — the re-check channel between a replica and the review, each bug pinned by one test named
|
|
3
|
+
* `regression: <what broke>`: a replica that holds a file back asks the next review about its hash; the review answers only when the work is done.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { hashText } from '../ingest/hash.js';
|
|
7
|
+
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
8
|
+
import { ExtractFailed, type ExtractPool } from '../knowledge/extractJob.js';
|
|
9
|
+
import { DOCS_PACK } from '../knowledge/packs/docs.js';
|
|
10
|
+
import type { KnowledgePack } from '../knowledge/model.js';
|
|
11
|
+
import { reviewDirectory } from '../knowledge/review.js';
|
|
12
|
+
import { filesManifestKey, saveManifestMap } from '../knowledge/sources.js';
|
|
13
|
+
import { args, memSource, memStore, ROOT, stateOf, type SpySource } from '../knowledge/testkit.test-util.js';
|
|
14
|
+
|
|
15
|
+
describe('regression: a root reviewed before binary files were recorded is settled by its next review, without reading a file', () => {
|
|
16
|
+
const text = '# A\nalpha\n';
|
|
17
|
+
|
|
18
|
+
it('regression: a binary-by-extension file the manifest names, with no stored body, gets a stored [] and no file is read', async () => {
|
|
19
|
+
const source = memSource({ 'a.md': text, 'img.png': 'x' });
|
|
20
|
+
const manifest = new InMemoryIngestManifest();
|
|
21
|
+
await saveManifestMap(manifest, filesManifestKey(ROOT), new Map([['img.png', 'imghash']]));
|
|
22
|
+
const store = memStore();
|
|
23
|
+
await reviewDirectory(args(source, store, manifest));
|
|
24
|
+
expect(await store.getExtracted('imghash')).toEqual([]);
|
|
25
|
+
expect(source.reads).not.toContain('img.png');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('regression: the review reads ONLY the files a replica asked to re-check: a NUL-binary gets [], a text file is extracted, the set is cleared', async () => {
|
|
29
|
+
const binary = 'bin\u0000ary';
|
|
30
|
+
const files = { 'blob.txt': binary, 'a.md': text, 'b.md': '# B\nbeta\n' };
|
|
31
|
+
const manifest = new InMemoryIngestManifest();
|
|
32
|
+
await reviewDirectory(args(memSource(files), memStore(), manifest));
|
|
33
|
+
const legacy = memStore(); // a root reviewed before: the manifest names the files, this store holds no bodies
|
|
34
|
+
await legacy.markRecheck([hashText(binary), hashText(text)]);
|
|
35
|
+
|
|
36
|
+
const source = memSource(files);
|
|
37
|
+
await reviewDirectory(args(source, legacy, manifest));
|
|
38
|
+
expect(new Set(source.reads)).toEqual(new Set(['blob.txt', 'a.md'])); // b.md was never named
|
|
39
|
+
expect(await legacy.getExtracted(hashText(binary))).toEqual([]);
|
|
40
|
+
expect((await legacy.getExtracted(hashText(text)))!.length).toBeGreaterThan(0);
|
|
41
|
+
expect(await legacy.getExtracted(hashText(files['b.md']))).toBeUndefined();
|
|
42
|
+
expect(await legacy.recheckHashes()).toEqual([]);
|
|
43
|
+
|
|
44
|
+
source.reads.length = 0;
|
|
45
|
+
await reviewDirectory(args(source, legacy, manifest)); // the set is empty now: nothing is read
|
|
46
|
+
expect(source.reads).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('regression: a re-checked hash only a SKIPPED manifest entry carries (here: ignored) is settled with [] and cleared, never left to loop', async () => {
|
|
50
|
+
const manifest = new InMemoryIngestManifest();
|
|
51
|
+
await saveManifestMap(manifest, filesManifestKey(ROOT), new Map([['skip.md', 'skiphash']]));
|
|
52
|
+
const legacy = memStore();
|
|
53
|
+
await legacy.markRecheck(['skiphash', 'gonehash']);
|
|
54
|
+
await reviewDirectory(args(memSource({ '.gitignore': 'skip.md\n', 'skip.md': '# S\nskipped\n', 'a.md': text }), legacy, manifest));
|
|
55
|
+
expect(await legacy.getExtracted('skiphash')).toEqual([]); // no review will ever extract an ignored file
|
|
56
|
+
expect(await legacy.getExtracted('gonehash')).toBeUndefined(); // carried by nothing: nothing to store
|
|
57
|
+
expect(await legacy.recheckHashes()).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('regression: a file whose read fails gets a terminal [] under the hash the manifest holds, so it is never held back forever (and a later read replaces it)', async () => {
|
|
61
|
+
const manifest = new InMemoryIngestManifest();
|
|
62
|
+
await saveManifestMap(manifest, filesManifestKey(ROOT), new Map([['locked.md', 'oldhash']]));
|
|
63
|
+
const store = memStore();
|
|
64
|
+
const inner = memSource({ 'locked.md': '# L\nlocked\n' });
|
|
65
|
+
const locked = { ...inner, read: async () => { throw new Error('EBUSY'); } };
|
|
66
|
+
const report = await reviewDirectory(args(locked as never, store, manifest));
|
|
67
|
+
expect(report.readErrors).toBe(1);
|
|
68
|
+
expect(await store.getExtracted('oldhash')).toEqual([]);
|
|
69
|
+
// The file becomes readable at a new hash: the real body is stored under it, and the terminal answer for the old hash stays harmless.
|
|
70
|
+
await reviewDirectory(args(inner, store, manifest));
|
|
71
|
+
expect((await store.getExtracted(hashText('# L\nlocked\n')))!.length).toBeGreaterThan(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/** A source whose `a.md` read is observed: `onRead(n)` runs on its n-th read and may throw. */
|
|
76
|
+
const watched = (onRead: (n: number) => void): SpySource => {
|
|
77
|
+
const inner = memSource({ 'a.md': text });
|
|
78
|
+
let n = 0;
|
|
79
|
+
return { ...inner, read: async (p: string) => { if (p === 'a.md') onRead(++n); return inner.read(p); } } as SpySource;
|
|
80
|
+
};
|
|
81
|
+
const legacyStore = async (manifest: InMemoryIngestManifest) => {
|
|
82
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), memStore(), manifest));
|
|
83
|
+
const legacy = memStore(); // the manifest names a.md; this store holds no body for it
|
|
84
|
+
await legacy.markRecheck([hashText(text)]);
|
|
85
|
+
return legacy;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
it('regression: a review stopped mid-way (after the backfill queued the file) keeps the re-check request and records no terminal [], and a complete one clears it', async () => {
|
|
89
|
+
const manifest = new InMemoryIngestManifest();
|
|
90
|
+
const legacy = await legacyStore(manifest);
|
|
91
|
+
const stop = new AbortController();
|
|
92
|
+
// Read 1 is the backfill's, read 2 is the review's: the run is stopped there and the read rejects.
|
|
93
|
+
const source = watched((n) => { if (n === 2) { stop.abort(); throw new Error('aborted'); } });
|
|
94
|
+
await reviewDirectory(args(source, legacy, manifest, { signal: stop.signal })).catch(() => undefined);
|
|
95
|
+
expect(await legacy.recheckHashes()).toEqual([hashText(text)]);
|
|
96
|
+
expect(await legacy.getExtracted(hashText(text))).toBeUndefined();
|
|
97
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest));
|
|
98
|
+
expect(await legacy.recheckHashes()).toEqual([]);
|
|
99
|
+
expect((await legacy.getExtracted(hashText(text)))!.length).toBeGreaterThan(0);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('regression: a read error at the manifest\'s own bytes keeps the request and makes the file owed; the next review stores the body', async () => {
|
|
103
|
+
const manifest = new InMemoryIngestManifest();
|
|
104
|
+
const legacy = await legacyStore(manifest);
|
|
105
|
+
const report = await reviewDirectory(args(watched(() => { throw new Error('EBUSY'); }), legacy, manifest));
|
|
106
|
+
expect(report.readErrors).toBe(1);
|
|
107
|
+
expect(await legacy.getExtracted(hashText(text))).toBeUndefined(); // not a terminal answer: the bytes may be readable next time
|
|
108
|
+
expect(await legacy.recheckHashes()).toEqual([hashText(text)]);
|
|
109
|
+
expect((await stateOf(manifest)).owed).toContain('a.md');
|
|
110
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest)); // a normal review: it is owed, so it is retried
|
|
111
|
+
expect((await legacy.getExtracted(hashText(text)))!.length).toBeGreaterThan(0);
|
|
112
|
+
expect(await legacy.recheckHashes()).toEqual([]);
|
|
113
|
+
expect((await stateOf(manifest)).owed).toEqual([]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('regression: a PROVEN-final extraction failure (the parser threw) at the same bytes gets a terminal [] and settles the request', async () => {
|
|
117
|
+
const manifest = new InMemoryIngestManifest();
|
|
118
|
+
const legacy = await legacyStore(manifest);
|
|
119
|
+
const exploding: ExtractPool = async () => { throw new ExtractFailed('parser exploded'); }; // proven final: the parser itself threw
|
|
120
|
+
const report = await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest, { extractPool: exploding, deferRead: true }));
|
|
121
|
+
expect(report.extractErrors).toBe(1);
|
|
122
|
+
expect(await legacy.getExtracted(hashText(text))).toEqual([]);
|
|
123
|
+
expect(await legacy.recheckHashes()).toEqual([]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('regression: the body is stored BEFORE the request is cleared (a store that observes the put still sees the request)', async () => {
|
|
127
|
+
const manifest = new InMemoryIngestManifest();
|
|
128
|
+
const legacy = await legacyStore(manifest);
|
|
129
|
+
let sawRequest: boolean | undefined;
|
|
130
|
+
const put = legacy.putExtracted.bind(legacy);
|
|
131
|
+
legacy.putExtracted = async (h, e) => { sawRequest ??= await legacy.hasRecheck(h); await put(h, e); };
|
|
132
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest));
|
|
133
|
+
expect(sawRequest).toBe(true);
|
|
134
|
+
expect(await legacy.recheckHashes()).toEqual([]);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
/** The request is kept, the file is owed, and nothing terminal is stored: the failure said nothing final about the file. */
|
|
139
|
+
const expectTransient = async (legacy: ReturnType<typeof memStore>, manifest: InMemoryIngestManifest): Promise<void> => {
|
|
140
|
+
expect(await legacy.getExtracted(hashText(text))).toBeUndefined();
|
|
141
|
+
expect(await legacy.recheckHashes()).toEqual([hashText(text)]);
|
|
142
|
+
expect((await stateOf(manifest)).owed).toContain('a.md');
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
it('regression: a deferRead pool whose read fails (EBUSY) at the manifest\'s bytes is transient, not a terminal []', async () => {
|
|
146
|
+
const manifest = new InMemoryIngestManifest();
|
|
147
|
+
const legacy = await legacyStore(manifest);
|
|
148
|
+
const busy: ExtractPool = async () => { throw new Error('EBUSY: resource busy or locked'); };
|
|
149
|
+
const report = await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest, { extractPool: busy, deferRead: true }));
|
|
150
|
+
expect(report.extractErrors).toBe(1);
|
|
151
|
+
await expectTransient(legacy, manifest);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('regression: a pool that times out (plain Error "timeout") is transient', async () => {
|
|
155
|
+
const manifest = new InMemoryIngestManifest();
|
|
156
|
+
const legacy = await legacyStore(manifest);
|
|
157
|
+
const stuck: ExtractPool = async () => { throw new Error('timeout'); };
|
|
158
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest, { extractPool: stuck, deferRead: true }));
|
|
159
|
+
await expectTransient(legacy, manifest);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('regression: an in-thread read that does not match the planned hash (changed since plan) at the same hash is transient', async () => {
|
|
163
|
+
const manifest = new InMemoryIngestManifest();
|
|
164
|
+
const legacy = await legacyStore(manifest);
|
|
165
|
+
const drifting = { ...memSource({ 'a.md': text }), hashOf: () => 'some-other-hash' } as SpySource;
|
|
166
|
+
const report = await reviewDirectory(args(drifting, legacy, manifest));
|
|
167
|
+
expect(report.failures).toEqual([{ path: 'a.md', phase: 'extract', reason: 'changed since plan' }]);
|
|
168
|
+
await expectTransient(legacy, manifest);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('regression: an extraction past its ceiling (a slow pool under a tiny extractMs) is transient', async () => {
|
|
172
|
+
const manifest = new InMemoryIngestManifest();
|
|
173
|
+
const legacy = await legacyStore(manifest);
|
|
174
|
+
const slow: ExtractPool = () => new Promise(() => undefined);
|
|
175
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest, { extractPool: slow, deferRead: true, timeouts: { extractMs: 5 } }));
|
|
176
|
+
await expectTransient(legacy, manifest);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('regression: the third transient failure in a row at the same hash is recorded as final', async () => {
|
|
180
|
+
const manifest = new InMemoryIngestManifest();
|
|
181
|
+
const legacy = await legacyStore(manifest);
|
|
182
|
+
const busy: ExtractPool = async () => { throw new Error('EBUSY'); };
|
|
183
|
+
const run = () => reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest, { extractPool: busy, deferRead: true }));
|
|
184
|
+
await run();
|
|
185
|
+
await run();
|
|
186
|
+
await expectTransient(legacy, manifest); // two in a row: still asked for
|
|
187
|
+
await run();
|
|
188
|
+
expect(await legacy.getExtracted(hashText(text))).toEqual([]); // the third: final
|
|
189
|
+
expect(await legacy.recheckHashes()).toEqual([]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('regression: a forced review whose read fails keeps the request (the backfill does not clear a changed file\'s hash)', async () => {
|
|
193
|
+
const manifest = new InMemoryIngestManifest();
|
|
194
|
+
const legacy = await legacyStore(manifest);
|
|
195
|
+
const failing = { ...memSource({ 'a.md': text }), read: async () => { throw new Error('EBUSY'); } } as SpySource;
|
|
196
|
+
await reviewDirectory(args(failing, legacy, manifest, { force: true }));
|
|
197
|
+
expect(await legacy.recheckHashes()).toEqual([hashText(text)]);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('regression: a file the packs accept at plan time but not once read (job "none") is recorded as nothing-to-extract and its request is answered', async () => {
|
|
201
|
+
const picky: KnowledgePack = { ...DOCS_PACK, parsers: [{ ...DOCS_PACK.parsers[0]!, accepts: (s) => s.content.kind === 'text' && s.content.text === '' }] };
|
|
202
|
+
const manifest = new InMemoryIngestManifest();
|
|
203
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), memStore(), manifest, { packs: [picky] }));
|
|
204
|
+
const legacy = memStore();
|
|
205
|
+
await legacy.markRecheck([hashText(text)]);
|
|
206
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest, { packs: [picky], force: true }));
|
|
207
|
+
expect(await legacy.getExtracted(hashText(text))).toEqual([]);
|
|
208
|
+
expect(await legacy.recheckHashes()).toEqual([]);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('regression: an unchanged text file with no stored body is NOT given [] (it is "not extracted yet")', async () => {
|
|
212
|
+
const manifest = new InMemoryIngestManifest();
|
|
213
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), memStore(), manifest));
|
|
214
|
+
const legacy = memStore();
|
|
215
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest));
|
|
216
|
+
expect(await legacy.getExtracted(hashText(text))).toBeUndefined();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('regression: a healthy root performs no extra reads on an incremental review', async () => {
|
|
220
|
+
const source = memSource({ 'a.md': text, 'blob.txt': 'bin\u0000ary' });
|
|
221
|
+
const manifest = new InMemoryIngestManifest();
|
|
222
|
+
const store = memStore();
|
|
223
|
+
await reviewDirectory(args(source, store, manifest));
|
|
224
|
+
source.reads.length = 0;
|
|
225
|
+
await reviewDirectory(args(source, store, manifest));
|
|
226
|
+
expect(source.reads).toEqual([]);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
@@ -15,7 +15,7 @@ import { planReview } from '../knowledge/plan.js';
|
|
|
15
15
|
import { srcRef } from '../knowledge/refs.js';
|
|
16
16
|
import { reviewDirectory } from '../knowledge/review.js';
|
|
17
17
|
import { applyRunEvent, failuresOf, failureTotal, REVIEW_RUN_FAILURE_CHUNK, startRun } from '../knowledge/reviewRun.js';
|
|
18
|
-
import { extractorManifestKey, filesManifestKey, judgedManifestKey, manifestMap
|
|
18
|
+
import { extractorManifestKey, filesManifestKey, judgedManifestKey, manifestMap } from '../knowledge/sources.js';
|
|
19
19
|
import {
|
|
20
20
|
ALL, args, fakeJudge, FILES, memSource, memStore, quietPack, ROOT, stateOf, type SpySource,
|
|
21
21
|
} from '../knowledge/testkit.test-util.js';
|
|
@@ -262,145 +262,3 @@ describe('regression: a file with nothing to extract is told apart from one not
|
|
|
262
262
|
expect(await store.getExtracted(hashText(text))).toEqual(before);
|
|
263
263
|
});
|
|
264
264
|
});
|
|
265
|
-
|
|
266
|
-
describe('regression: a root reviewed before binary files were recorded is settled by its next review, without reading a file', () => {
|
|
267
|
-
const text = '# A\nalpha\n';
|
|
268
|
-
|
|
269
|
-
it('regression: a binary-by-extension file the manifest names, with no stored body, gets a stored [] and no file is read', async () => {
|
|
270
|
-
const source = memSource({ 'a.md': text, 'img.png': 'x' });
|
|
271
|
-
const manifest = new InMemoryIngestManifest();
|
|
272
|
-
await saveManifestMap(manifest, filesManifestKey(ROOT), new Map([['img.png', 'imghash']]));
|
|
273
|
-
const store = memStore();
|
|
274
|
-
await reviewDirectory(args(source, store, manifest));
|
|
275
|
-
expect(await store.getExtracted('imghash')).toEqual([]);
|
|
276
|
-
expect(source.reads).not.toContain('img.png');
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('regression: the review reads ONLY the files a replica asked to re-check: a NUL-binary gets [], a text file is extracted, the set is cleared', async () => {
|
|
280
|
-
const binary = 'bin\u0000ary';
|
|
281
|
-
const files = { 'blob.txt': binary, 'a.md': text, 'b.md': '# B\nbeta\n' };
|
|
282
|
-
const manifest = new InMemoryIngestManifest();
|
|
283
|
-
await reviewDirectory(args(memSource(files), memStore(), manifest));
|
|
284
|
-
const legacy = memStore(); // a root reviewed before: the manifest names the files, this store holds no bodies
|
|
285
|
-
await legacy.markRecheck([hashText(binary), hashText(text)]);
|
|
286
|
-
|
|
287
|
-
const source = memSource(files);
|
|
288
|
-
await reviewDirectory(args(source, legacy, manifest));
|
|
289
|
-
expect(new Set(source.reads)).toEqual(new Set(['blob.txt', 'a.md'])); // b.md was never named
|
|
290
|
-
expect(await legacy.getExtracted(hashText(binary))).toEqual([]);
|
|
291
|
-
expect((await legacy.getExtracted(hashText(text)))!.length).toBeGreaterThan(0);
|
|
292
|
-
expect(await legacy.getExtracted(hashText(files['b.md']))).toBeUndefined();
|
|
293
|
-
expect(await legacy.recheckHashes()).toEqual([]);
|
|
294
|
-
|
|
295
|
-
source.reads.length = 0;
|
|
296
|
-
await reviewDirectory(args(source, legacy, manifest)); // the set is empty now: nothing is read
|
|
297
|
-
expect(source.reads).toEqual([]);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it('regression: a re-checked hash only a SKIPPED manifest entry carries (here: ignored) is settled with [] and cleared, never left to loop', async () => {
|
|
301
|
-
const manifest = new InMemoryIngestManifest();
|
|
302
|
-
await saveManifestMap(manifest, filesManifestKey(ROOT), new Map([['skip.md', 'skiphash']]));
|
|
303
|
-
const legacy = memStore();
|
|
304
|
-
await legacy.markRecheck(['skiphash', 'gonehash']);
|
|
305
|
-
await reviewDirectory(args(memSource({ '.gitignore': 'skip.md\n', 'skip.md': '# S\nskipped\n', 'a.md': text }), legacy, manifest));
|
|
306
|
-
expect(await legacy.getExtracted('skiphash')).toEqual([]); // no review will ever extract an ignored file
|
|
307
|
-
expect(await legacy.getExtracted('gonehash')).toBeUndefined(); // carried by nothing: nothing to store
|
|
308
|
-
expect(await legacy.recheckHashes()).toEqual([]);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('regression: a file whose read fails gets a terminal [] under the hash the manifest holds, so it is never held back forever (and a later read replaces it)', async () => {
|
|
312
|
-
const manifest = new InMemoryIngestManifest();
|
|
313
|
-
await saveManifestMap(manifest, filesManifestKey(ROOT), new Map([['locked.md', 'oldhash']]));
|
|
314
|
-
const store = memStore();
|
|
315
|
-
const inner = memSource({ 'locked.md': '# L\nlocked\n' });
|
|
316
|
-
const locked = { ...inner, read: async () => { throw new Error('EBUSY'); } };
|
|
317
|
-
const report = await reviewDirectory(args(locked as never, store, manifest));
|
|
318
|
-
expect(report.readErrors).toBe(1);
|
|
319
|
-
expect(await store.getExtracted('oldhash')).toEqual([]);
|
|
320
|
-
// The file becomes readable at a new hash: the real body is stored under it, and the terminal answer for the old hash stays harmless.
|
|
321
|
-
await reviewDirectory(args(inner, store, manifest));
|
|
322
|
-
expect((await store.getExtracted(hashText('# L\nlocked\n')))!.length).toBeGreaterThan(0);
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
/** A source whose `a.md` read is observed: `onRead(n)` runs on its n-th read and may throw. */
|
|
327
|
-
const watched = (onRead: (n: number) => void): SpySource => {
|
|
328
|
-
const inner = memSource({ 'a.md': text });
|
|
329
|
-
let n = 0;
|
|
330
|
-
return { ...inner, read: async (p: string) => { if (p === 'a.md') onRead(++n); return inner.read(p); } } as SpySource;
|
|
331
|
-
};
|
|
332
|
-
const legacyStore = async (manifest: InMemoryIngestManifest) => {
|
|
333
|
-
await reviewDirectory(args(memSource({ 'a.md': text }), memStore(), manifest));
|
|
334
|
-
const legacy = memStore(); // the manifest names a.md; this store holds no body for it
|
|
335
|
-
await legacy.markRecheck([hashText(text)]);
|
|
336
|
-
return legacy;
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
it('regression: a review stopped mid-way (after the backfill queued the file) keeps the re-check request and records no terminal [], and a complete one clears it', async () => {
|
|
340
|
-
const manifest = new InMemoryIngestManifest();
|
|
341
|
-
const legacy = await legacyStore(manifest);
|
|
342
|
-
const stop = new AbortController();
|
|
343
|
-
// Read 1 is the backfill's, read 2 is the review's: the run is stopped there and the read rejects.
|
|
344
|
-
const source = watched((n) => { if (n === 2) { stop.abort(); throw new Error('aborted'); } });
|
|
345
|
-
await reviewDirectory(args(source, legacy, manifest, { signal: stop.signal })).catch(() => undefined);
|
|
346
|
-
expect(await legacy.recheckHashes()).toEqual([hashText(text)]);
|
|
347
|
-
expect(await legacy.getExtracted(hashText(text))).toBeUndefined();
|
|
348
|
-
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest));
|
|
349
|
-
expect(await legacy.recheckHashes()).toEqual([]);
|
|
350
|
-
expect((await legacy.getExtracted(hashText(text)))!.length).toBeGreaterThan(0);
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
it('regression: a read error at the manifest\'s own bytes keeps the request and makes the file owed; the next review stores the body', async () => {
|
|
354
|
-
const manifest = new InMemoryIngestManifest();
|
|
355
|
-
const legacy = await legacyStore(manifest);
|
|
356
|
-
const report = await reviewDirectory(args(watched(() => { throw new Error('EBUSY'); }), legacy, manifest));
|
|
357
|
-
expect(report.readErrors).toBe(1);
|
|
358
|
-
expect(await legacy.getExtracted(hashText(text))).toBeUndefined(); // not a terminal answer: the bytes may be readable next time
|
|
359
|
-
expect(await legacy.recheckHashes()).toEqual([hashText(text)]);
|
|
360
|
-
expect((await stateOf(manifest)).owed).toContain('a.md');
|
|
361
|
-
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest)); // a normal review: it is owed, so it is retried
|
|
362
|
-
expect((await legacy.getExtracted(hashText(text)))!.length).toBeGreaterThan(0);
|
|
363
|
-
expect(await legacy.recheckHashes()).toEqual([]);
|
|
364
|
-
expect((await stateOf(manifest)).owed).toEqual([]);
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
it('regression: a deterministic extraction failure at the same bytes gets a terminal [] and settles the request', async () => {
|
|
368
|
-
const manifest = new InMemoryIngestManifest();
|
|
369
|
-
const legacy = await legacyStore(manifest);
|
|
370
|
-
const exploding: ExtractPool = async () => { throw new Error('parse exploded'); };
|
|
371
|
-
const report = await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest, { extractPool: exploding, deferRead: true }));
|
|
372
|
-
expect(report.extractErrors).toBe(1);
|
|
373
|
-
expect(await legacy.getExtracted(hashText(text))).toEqual([]);
|
|
374
|
-
expect(await legacy.recheckHashes()).toEqual([]);
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
it('regression: the body is stored BEFORE the request is cleared (a store that observes the put still sees the request)', async () => {
|
|
378
|
-
const manifest = new InMemoryIngestManifest();
|
|
379
|
-
const legacy = await legacyStore(manifest);
|
|
380
|
-
let sawRequest: boolean | undefined;
|
|
381
|
-
const put = legacy.putExtracted.bind(legacy);
|
|
382
|
-
legacy.putExtracted = async (h, e) => { sawRequest ??= await legacy.hasRecheck(h); await put(h, e); };
|
|
383
|
-
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest));
|
|
384
|
-
expect(sawRequest).toBe(true);
|
|
385
|
-
expect(await legacy.recheckHashes()).toEqual([]);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
it('regression: an unchanged text file with no stored body is NOT given [] (it is "not extracted yet")', async () => {
|
|
390
|
-
const manifest = new InMemoryIngestManifest();
|
|
391
|
-
await reviewDirectory(args(memSource({ 'a.md': text }), memStore(), manifest));
|
|
392
|
-
const legacy = memStore();
|
|
393
|
-
await reviewDirectory(args(memSource({ 'a.md': text }), legacy, manifest));
|
|
394
|
-
expect(await legacy.getExtracted(hashText(text))).toBeUndefined();
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it('regression: a healthy root performs no extra reads on an incremental review', async () => {
|
|
398
|
-
const source = memSource({ 'a.md': text, 'blob.txt': 'bin\u0000ary' });
|
|
399
|
-
const manifest = new InMemoryIngestManifest();
|
|
400
|
-
const store = memStore();
|
|
401
|
-
await reviewDirectory(args(source, store, manifest));
|
|
402
|
-
source.reads.length = 0;
|
|
403
|
-
await reviewDirectory(args(source, store, manifest));
|
|
404
|
-
expect(source.reads).toEqual([]);
|
|
405
|
-
});
|
|
406
|
-
});
|
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
OutlineFile, ReviewFailure, ReviewFailureChunks, ReviewPhase, ReviewReport, ReviewRun, ReviewRunPhase, ReviewStep, ScopeRecord,
|
|
18
18
|
StoredFact, StoredRelation, ExtractedLogPersistence, KnowledgeSnapshot, LocalSnapshotStoreOptions, SnapshotPersistence,
|
|
19
19
|
} from '../knowledge/index.js';
|
|
20
|
-
import { failuresOf, failureTotal, LocalSnapshotStore, localSnapshotStore } from '../knowledge/index.js';
|
|
20
|
+
import { ExtractFailed, failuresOf, failureTotal, LocalSnapshotStore, localSnapshotStore } from '../knowledge/index.js';
|
|
21
21
|
|
|
22
22
|
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
|
|
23
23
|
type Expect<T extends true> = T;
|
|
@@ -89,6 +89,7 @@ export const jobWithNeither: ExtractJob = { ...base };
|
|
|
89
89
|
export type ExtractJob_readByPool_shape = Expect<Equal<NonNullable<Extract<ExtractJob, { readByPool: unknown }>['readByPool']>, { path: string; hash: string }>>;
|
|
90
90
|
export const resultShape = { binary: true, extracted: [anExtract], sections: someSections } satisfies ExtractJobResult;
|
|
91
91
|
export type ExtractJobResult_fields = Expect<Equal<ExtractJobResult, { binary?: true; extracted: Extracted[]; sections?: ParsedSection[] }>>;
|
|
92
|
+
// ExtractFailed: the marker of a PROVEN-final extraction failure (the parser or extractor threw); every other failure is transient.export type ExtractFailed_is_an_Error = Expect<Equal<InstanceType<typeof ExtractFailed> extends Error ? true : false, true>>;export type ExtractFailed_constructor = Expect<Equal<ConstructorParameters<typeof ExtractFailed>, [message: string, options?: { cause?: unknown }]>>;
|
|
92
93
|
|
|
93
94
|
/* ── KnowledgeStore: the port hosts implement ──────────────────────────────────────────────────────────────── */
|
|
94
95
|
export type KnowledgeStore_methods = Expect<Equal<
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* - binary by CONTENT (a NUL): unknowable without reading. A replica that holds a file back, or is told by the server that a
|
|
12
12
|
* body is missing, calls `store.markRecheck(hashes)`; the review reads ONLY the unchanged planned files with those hashes.
|
|
13
13
|
* Binary → `[]`. Anything else (text, a document) → queued for extraction this run (`changed`). A hash only a SKIPPED
|
|
14
|
-
* prior entry carries is never extracted by any review: `[]`. Hashes settled HERE are cleared here
|
|
15
|
-
* once its body
|
|
14
|
+
* prior entry carries is never extracted by any review: `[]`. Hashes settled HERE are cleared here. A queued one (or one whose read
|
|
15
|
+
* threw here) is cleared by the review only once its body is stored or a FINAL failure is recorded; a transient failure or a stop keeps the request.
|
|
16
16
|
*
|
|
17
17
|
* A healthy root has no body missing and an empty recheck set: it reads nothing and costs only in-memory lookups.
|
|
18
18
|
*/
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import type { ParsedSection, SourceDocument } from '../ingest/types.js';
|
|
10
10
|
import type { Extracted, KnowledgePack, KnowledgeParser, KnowledgeStore, NodeRef } from './model.js';
|
|
11
|
-
import { BinaryContent, jobOf, runExtractor, type ExtractPool } from './extractJob.js';
|
|
11
|
+
import { BinaryContent, CHANGED_SINCE_PLAN, ExtractFailed, jobOf, runExtractor, type ExtractPool } from './extractJob.js';
|
|
12
12
|
import { srcRef } from './refs.js';
|
|
13
13
|
import { entityName, knownKeysOf, resolveEntities } from './resolve.js';
|
|
14
14
|
import { asPathSource, composePacks, EXTRACTOR_VERSION, resolveRelativePath, stubSource, type ComposedPacks } from './sources.js';
|
|
@@ -88,7 +88,9 @@ export async function extractFileDetailed(a: ExtractFileArgs): Promise<FileExtra
|
|
|
88
88
|
const ref = srcRef(a.rootId, a.path);
|
|
89
89
|
// With a pool the main thread never parses: the worker returns the sections when the file will be judged.
|
|
90
90
|
const wants = !!a.pool && !!a.wantsSections?.(hit.pack);
|
|
91
|
-
|
|
91
|
+
// The parser and the extractor run in this thread only without a pool; their errors are the PROVEN-final failures (ExtractFailed).
|
|
92
|
+
const proven = <T>(work: () => T): T => { try { return work(); } catch (error) { throw new ExtractFailed(error instanceof Error ? error.message : String(error), { cause: error }); } };
|
|
93
|
+
let sections: ParsedSection[] = a.pool ? [] : proven(() => hit.parser.parse(src));
|
|
92
94
|
const tLookup = Date.now();
|
|
93
95
|
const cached = await a.store.getExtracted?.(a.hash);
|
|
94
96
|
const lookupMs = Date.now() - tLookup;
|
|
@@ -117,14 +119,14 @@ export async function extractFileDetailed(a: ExtractFileArgs): Promise<FileExtra
|
|
|
117
119
|
const mine = out.extracted.find((e) => e.sourceRef === ref);
|
|
118
120
|
if (!mine) throw new Error(`extract pool returned no extract for ${a.path}`);
|
|
119
121
|
// The pool read other bytes than the plan hashed: nothing is stored under the planned hash.
|
|
120
|
-
if (mine.sourceHash !== a.hash) throw new Error(
|
|
122
|
+
if (mine.sourceHash !== a.hash) throw new Error(CHANGED_SINCE_PLAN); // transient: the bytes may settle
|
|
121
123
|
if (wants) {
|
|
122
124
|
if (!out.sections) throw new Error(`extract pool returned no sections for ${a.path}`);
|
|
123
125
|
sections = out.sections;
|
|
124
126
|
}
|
|
125
127
|
extracted = mine;
|
|
126
128
|
} else {
|
|
127
|
-
extracted = runExtractor(hit, src, sections, { rootId: a.rootId, knownKeys, resolvePath: resolveRelativePath }, a);
|
|
129
|
+
extracted = proven(() => runExtractor(hit, src, sections, { rootId: a.rootId, knownKeys, resolvePath: resolveRelativePath }, a));
|
|
128
130
|
}
|
|
129
131
|
if (a.writeCache !== false) await putExtract(a.store, a.hash, extracted, cached ?? []);
|
|
130
132
|
return { extracted, parser: hit.parser, pack: hit.pack, sections, cached: false };
|
|
@@ -40,6 +40,17 @@ export type ExtractJobSource =
|
|
|
40
40
|
|
|
41
41
|
export type ExtractJob = ExtractJobBase & ExtractJobSource;
|
|
42
42
|
|
|
43
|
+
/** The planned bytes are not the bytes read: nothing is stored under the planned hash. Always TRANSIENT (the bytes may settle). */
|
|
44
|
+
export const CHANGED_SINCE_PLAN = 'changed since plan';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A failure PROVEN final: the parser or extractor itself threw on these bytes (in-thread, or a pool's worker reporting it). Every other
|
|
48
|
+
* failure (a read, a timeout, a crashed or disposed worker, a failing store, a changed-since-plan) is transient: the file may extract next time.
|
|
49
|
+
*/
|
|
50
|
+
export class ExtractFailed extends Error {
|
|
51
|
+
constructor(message: string, options?: { cause?: unknown }) { super(message); this.name = 'ExtractFailed'; if (options?.cause !== undefined) (this as { cause?: unknown }).cause = options.cause; }
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
/** Thrown by the extract stage when the pool found the file binary; the review records a `skipped` step. */
|
|
44
55
|
export class BinaryContent extends Error {
|
|
45
56
|
constructor() { super('binary'); this.name = 'BinaryContent'; }
|
package/src/knowledge/index.ts
CHANGED
|
@@ -49,7 +49,7 @@ export { orderForJudging } from './judgePriority.js';
|
|
|
49
49
|
export type { JudgeSignals } from './judgePriority.js';
|
|
50
50
|
export { extractFile, extractFileDetailed, knownKeysOfEntities } from './extractFile.js';
|
|
51
51
|
export type { ExtractFileArgs, FileExtraction } from './extractFile.js';
|
|
52
|
-
export { extractJob, jobOf } from './extractJob.js';
|
|
52
|
+
export { ExtractFailed, extractJob, jobOf } from './extractJob.js';
|
|
53
53
|
export type { ExtractJob, ExtractJobResult, ExtractPool } from './extractJob.js';
|
|
54
54
|
export { putExtract, putNoExtract } from './extractFile.js';
|
|
55
55
|
export { createModelLimiter, isRateLimit } from './modelLimiter.js';
|