@seanhogg/builderforce-memory 2026.10.42 → 2026.10.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/knowledge/externals.d.ts +9 -0
  2. package/dist/knowledge/externals.d.ts.map +1 -0
  3. package/dist/knowledge/externals.js +8 -0
  4. package/dist/knowledge/externals.js.map +1 -0
  5. package/dist/knowledge/extractFile.d.ts +15 -0
  6. package/dist/knowledge/extractFile.d.ts.map +1 -1
  7. package/dist/knowledge/extractFile.js +40 -17
  8. package/dist/knowledge/extractFile.js.map +1 -1
  9. package/dist/knowledge/extractJob.d.ts +64 -0
  10. package/dist/knowledge/extractJob.d.ts.map +1 -0
  11. package/dist/knowledge/extractJob.js +47 -0
  12. package/dist/knowledge/extractJob.js.map +1 -0
  13. package/dist/knowledge/index.d.ts +11 -1
  14. package/dist/knowledge/index.d.ts.map +1 -1
  15. package/dist/knowledge/index.js +7 -1
  16. package/dist/knowledge/index.js.map +1 -1
  17. package/dist/knowledge/judge.d.ts +23 -5
  18. package/dist/knowledge/judge.d.ts.map +1 -1
  19. package/dist/knowledge/judge.js +14 -76
  20. package/dist/knowledge/judge.js.map +1 -1
  21. package/dist/knowledge/judgeCalls.d.ts +52 -0
  22. package/dist/knowledge/judgeCalls.d.ts.map +1 -0
  23. package/dist/knowledge/judgeCalls.js +107 -0
  24. package/dist/knowledge/judgeCalls.js.map +1 -0
  25. package/dist/knowledge/modelLimiter.d.ts +20 -0
  26. package/dist/knowledge/modelLimiter.d.ts.map +1 -0
  27. package/dist/knowledge/modelLimiter.js +63 -0
  28. package/dist/knowledge/modelLimiter.js.map +1 -0
  29. package/dist/knowledge/review.d.ts +6 -2
  30. package/dist/knowledge/review.d.ts.map +1 -1
  31. package/dist/knowledge/review.js +108 -112
  32. package/dist/knowledge/review.js.map +1 -1
  33. package/dist/knowledge/reviewJudge.d.ts +95 -0
  34. package/dist/knowledge/reviewJudge.d.ts.map +1 -0
  35. package/dist/knowledge/reviewJudge.js +119 -0
  36. package/dist/knowledge/reviewJudge.js.map +1 -0
  37. package/dist/knowledge/reviewModel.d.ts +30 -2
  38. package/dist/knowledge/reviewModel.d.ts.map +1 -1
  39. package/dist/knowledge/reviewPrefetch.d.ts +53 -0
  40. package/dist/knowledge/reviewPrefetch.d.ts.map +1 -0
  41. package/dist/knowledge/reviewPrefetch.js +65 -0
  42. package/dist/knowledge/reviewPrefetch.js.map +1 -0
  43. package/dist/knowledge/reviewRun.d.ts +70 -0
  44. package/dist/knowledge/reviewRun.d.ts.map +1 -0
  45. package/dist/knowledge/reviewRun.js +88 -0
  46. package/dist/knowledge/reviewRun.js.map +1 -0
  47. package/dist/knowledge/reviewRunModel.d.ts +35 -0
  48. package/dist/knowledge/reviewRunModel.d.ts.map +1 -0
  49. package/dist/knowledge/reviewRunModel.js +27 -0
  50. package/dist/knowledge/reviewRunModel.js.map +1 -0
  51. package/package.json +3 -3
  52. package/src/knowledge/externals.test.ts +21 -0
  53. package/src/knowledge/externals.ts +10 -0
  54. package/src/knowledge/extractFile.ts +49 -17
  55. package/src/knowledge/extractJob.ts +91 -0
  56. package/src/knowledge/index.ts +11 -1
  57. package/src/knowledge/judge.ts +24 -70
  58. package/src/knowledge/judgeCalls.ts +136 -0
  59. package/src/knowledge/modelLimiter.test.ts +68 -0
  60. package/src/knowledge/modelLimiter.ts +68 -0
  61. package/src/knowledge/review.failures.test.ts +277 -0
  62. package/src/knowledge/review.ordered.test.ts +114 -0
  63. package/src/knowledge/review.ts +102 -100
  64. package/src/knowledge/reviewJudge.ts +155 -0
  65. package/src/knowledge/reviewModel.ts +30 -2
  66. package/src/knowledge/reviewPrefetch.ts +86 -0
  67. package/src/knowledge/reviewRun.test.ts +96 -0
  68. package/src/knowledge/reviewRun.ts +137 -0
  69. package/src/knowledge/reviewRunModel.ts +53 -0
@@ -6,6 +6,8 @@ import type { IngestManifest, SourceDocument } from '../ingest/types.js';
6
6
  import type { SimilarPair } from '../retrieval/knowledge-index/types.js';
7
7
  import type { JudgementPort, KnowledgePack, KnowledgeStore } from './model.js';
8
8
  import type { PlanDetail } from './plan.js';
9
+ import type { ExtractPool } from './extractJob.js';
10
+ import type { ReviewFailure, ReviewPhase, ReviewStep } from './reviewRunModel.js';
9
11
  /** Where files come from: one adapter per host. */
10
12
  export interface DirectorySource {
11
13
  rootId: string;
@@ -33,7 +35,7 @@ export interface ReviewPlan {
33
35
  estimatedModelCalls: number;
34
36
  }
35
37
  export interface ReviewProgress {
36
- phase: 'plan' | 'extract' | 'resolve' | 'judge' | 'write' | 'index' | 'done';
38
+ phase: ReviewPhase;
37
39
  done: number;
38
40
  total: number;
39
41
  path?: string;
@@ -55,6 +57,10 @@ export interface ReviewReport {
55
57
  * the next fresh plan's `removed`.
56
58
  */
57
59
  readErrors: number;
60
+ /** Files whose extraction threw: handled like a read error (knowledge and manifest hash kept, retried next review). */
61
+ extractErrors: number;
62
+ /** Every file this run could not finish (read, extract, judge), with why. */
63
+ failures: ReviewFailure[];
58
64
  aborted: boolean;
59
65
  durationMs: number;
60
66
  }
@@ -81,8 +87,30 @@ export interface ReviewArgs {
81
87
  /** *Re-review all*: every file is reviewed whatever its hash (see `PlanOptions.force`). Ignored with `plan`. */
82
88
  force?: boolean;
83
89
  signal?: AbortSignal;
84
- /** Files read + extracted ahead of judging (1..32, default 8). Judge/write stay in file order. */
90
+ /**
91
+ * Files read + extracted ahead of judging (1..32, default 8). With an `extractPool` this is the pool's width.
92
+ * Writes always stay in file order.
93
+ */
85
94
  concurrency?: number;
95
+ /**
96
+ * Files judged at once (1..16, default 4, never wider than the read-ahead). One ordered writer applies the
97
+ * results in plan order, so the stored bytes equal those of `concurrency: 1, judgeConcurrency: 1`.
98
+ */
99
+ judgeConcurrency?: number;
100
+ /**
101
+ * The most model calls in flight across ALL files of the review (default 6): `judgeConcurrency` parallelizes
102
+ * files without multiplying the provider's load. A rate-limit answer halves it (minimum 1); it grows back by 1
103
+ * per 20 successful calls.
104
+ */
105
+ maxModelCalls?: number;
106
+ /**
107
+ * Extracts a changed file whose extract is not cached — e.g. a `worker_threads` pool. Default: in-thread.
108
+ * With a pool the main thread never parses; the pool returns a file's sections when it will be judged.
109
+ * A result without the file's exact `sourceRef` fails that file's extraction (prior knowledge kept).
110
+ */
111
+ extractPool?: ExtractPool;
112
+ /** One event per file per phase, as it happens (PRD 41 A8). */
113
+ onStep?(step: ReviewStep): void;
86
114
  onProgress?(p: ReviewProgress): void;
87
115
  }
88
116
  //# sourceMappingURL=reviewModel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reviewModel.d.ts","sourceRoot":"","sources":["../../src/knowledge/reviewModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,IAAI,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpE,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC5C,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MA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;IACjB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,cAAc,CAAC;IACtB,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACzF,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,mHAAmH;IACnH,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,gHAAgH;IAChH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,+DAA+D;IAC/D,MAAM,CAAC,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IAChC,UAAU,CAAC,CAAC,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CACxC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * knowledge/reviewPrefetch.ts — the read + extract stage of a review (PRD 38 §4.3, PRD 41 A8).
3
+ *
4
+ * `createPrefetch` returns the per-file job `prefetchOrdered` runs ahead of the consumer: read,
5
+ * binary check, extract (the content-hash cache is READ here; through `args.extractPool` on a miss when
6
+ * the host supplies one). A job never throws — it settles to a {@link Prefetch}, and a failure carries
7
+ * its reason so the review can keep the file's prior knowledge and retry it next time. It never WRITES
8
+ * the extract cache: the review's ordered writer does, so the cache matches a sequential run. Each job
9
+ * holds one lane (0..width-1) and emits its `extract` step the moment it settles.
10
+ */
11
+ import type { SourceDocument } from '../ingest/types.js';
12
+ import type { KnowledgePack, KnowledgeStore, NodeRef, ReviewArgs } from './model.js';
13
+ import { type FileExtraction } from './extractFile.js';
14
+ import { type ReviewStep } from './reviewRunModel.js';
15
+ import { type ComposedPacks } from './sources.js';
16
+ /** What the prefetch stage learned about one file. `failed` and `read-error` carry why. */
17
+ export type Prefetch = ({
18
+ kind: 'read-error';
19
+ reason: string;
20
+ } | {
21
+ kind: 'binary';
22
+ } | {
23
+ kind: 'none';
24
+ } | {
25
+ kind: 'extracted';
26
+ doc: SourceDocument;
27
+ extraction: FileExtraction;
28
+ } | {
29
+ kind: 'failed';
30
+ reason: string;
31
+ }) & {
32
+ ms: number;
33
+ lane: number;
34
+ };
35
+ export interface PrefetchContext {
36
+ args: ReviewArgs;
37
+ /** The run's signal (the caller's, plus the run's own stop on a thrown error). */
38
+ signal: AbortSignal;
39
+ rootId: string;
40
+ packs: readonly KnowledgePack[];
41
+ store: KnowledgeStore;
42
+ composed: ComposedPacks;
43
+ knownKeys: ReadonlyMap<string, NodeRef>;
44
+ /** Lanes = the read-ahead width. */
45
+ width: number;
46
+ }
47
+ /** The extract step event of a settled job. */
48
+ export declare function extractStepOf(path: string, job: Prefetch): ReviewStep;
49
+ export declare function createPrefetch(c: PrefetchContext): (f: {
50
+ path: string;
51
+ hash: string;
52
+ }) => Promise<Prefetch>;
53
+ //# sourceMappingURL=reviewPrefetch.d.ts.map
@@ -0,0 +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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MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,QAAQ,CAAC,CA8B3G"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * knowledge/reviewPrefetch.ts — the read + extract stage of a review (PRD 38 §4.3, PRD 41 A8).
3
+ *
4
+ * `createPrefetch` returns the per-file job `prefetchOrdered` runs ahead of the consumer: read,
5
+ * binary check, extract (the content-hash cache is READ here; through `args.extractPool` on a miss when
6
+ * the host supplies one). A job never throws — it settles to a {@link Prefetch}, and a failure carries
7
+ * its reason so the review can keep the file's prior knowledge and retry it next time. It never WRITES
8
+ * the extract cache: the review's ordered writer does, so the cache matches a sequential run. Each job
9
+ * holds one lane (0..width-1) and emits its `extract` step the moment it settles.
10
+ */
11
+ import { extractFileDetailed } from './extractFile.js';
12
+ import { judgesPack } from './reviewJudge.js';
13
+ import { Lanes, reasonOf } from './reviewRunModel.js';
14
+ import { isBinaryText } from './sources.js';
15
+ /** The extract step event of a settled job. */
16
+ export function extractStepOf(path, job) {
17
+ const base = { path, phase: 'extract', ms: job.ms, lane: job.lane };
18
+ switch (job.kind) {
19
+ case 'read-error': return { ...base, outcome: 'failed', reason: `read: ${job.reason}` };
20
+ case 'failed': return { ...base, outcome: 'failed', reason: job.reason };
21
+ case 'binary': return { ...base, outcome: 'skipped', reason: 'binary' };
22
+ case 'none': return { ...base, outcome: 'skipped', reason: 'no-pack' };
23
+ case 'extracted': return { ...base, outcome: job.extraction.cached ? 'cached' : 'ok' };
24
+ }
25
+ }
26
+ export function createPrefetch(c) {
27
+ const lanes = new Lanes(c.width);
28
+ const wantsSections = (pack) => judgesPack(c.args.judgement, pack);
29
+ const run = async (f) => {
30
+ let doc;
31
+ try {
32
+ doc = await c.args.source.read(f.path);
33
+ }
34
+ catch (error) {
35
+ return { kind: 'read-error', reason: reasonOf(error) };
36
+ }
37
+ try {
38
+ if (doc.content.kind === 'text' && isBinaryText(doc.content.text))
39
+ return { kind: 'binary' };
40
+ const extraction = await extractFileDetailed({
41
+ rootId: c.rootId, path: f.path, hash: f.hash, doc, packs: c.packs, store: c.store, composed: c.composed,
42
+ knownKeys: c.knownKeys, writeCache: false,
43
+ ...(c.args.extractPool ? { pool: c.args.extractPool, signal: c.signal, wantsSections } : {}),
44
+ });
45
+ return extraction ? { kind: 'extracted', doc, extraction } : { kind: 'none' };
46
+ }
47
+ catch (error) {
48
+ return { kind: 'failed', reason: reasonOf(error) };
49
+ }
50
+ };
51
+ return async (f) => {
52
+ const lane = lanes.take();
53
+ const t0 = Date.now();
54
+ try {
55
+ const out = await run(f);
56
+ const job = { ...out, ms: Date.now() - t0, lane };
57
+ c.args.onStep?.(extractStepOf(f.path, job));
58
+ return job;
59
+ }
60
+ finally {
61
+ lanes.free(lane);
62
+ }
63
+ };
64
+ }
65
+ //# sourceMappingURL=reviewPrefetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewPrefetch.js","sourceRoot":"","sources":["../../src/knowledge/reviewPrefetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,mBAAmB,EAAuB,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAmB,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAsB,MAAM,cAAc,CAAC;AA2BhE,+CAA+C;AAC/C,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,GAAa;IACrD,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,SAAkB,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;IAC7E,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,YAAY,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,GAA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,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,IAAI,EAAc,CAAC;YAC9D,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;YAC5C,OAAO,GAAG,CAAC;QACf,CAAC;gBAAS,CAAC;YACP,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * knowledge/reviewRun.ts — the PURE recorder of a review run (PRD 41 A8): fold the events a review
3
+ * emits (`onProgress`, `onStep`, the end) into a {@link ReviewRun} a host can persist and a view can
4
+ * draw — phase timeline, worker lanes, the last steps, every failure, the rate and ETA.
5
+ *
6
+ * No clock, no I/O: every function takes the time it should use, so the reducer is deterministic and a
7
+ * stored run replays the same. The host owns persistence (last N runs per root) and throttling.
8
+ */
9
+ import type { ReviewProgress, ReviewReport } from './reviewModel.js';
10
+ import type { ReviewFailure, ReviewPhase, ReviewStep } from './reviewRunModel.js';
11
+ export type ReviewRunKind = 'review' | 're-review' | 'seed';
12
+ export type ReviewRunOutcome = 'done' | 'stopped' | 'failed';
13
+ /** How many of the latest steps a run keeps (failures are kept whole). */
14
+ export declare const REVIEW_RUN_STEP_RING = 200;
15
+ export interface ReviewRunPhase {
16
+ phase: ReviewPhase;
17
+ startedAt: number;
18
+ endedAt?: number;
19
+ /** Items reached: files for extract · judge · write (the review's progress `done` is a 0-based index), else as reported. */
20
+ done: number;
21
+ total: number;
22
+ }
23
+ /** One worker of a phase (extraction workers, judge lanes): the file it is on (or last was on), files finished and time spent busy. */
24
+ export interface ReviewRunLane {
25
+ phase: ReviewPhase;
26
+ id: number;
27
+ path?: string;
28
+ done: number;
29
+ busyMs: number;
30
+ }
31
+ export interface ReviewRun {
32
+ id: string;
33
+ root: string;
34
+ kind: ReviewRunKind;
35
+ startedAt: number;
36
+ endedAt?: number;
37
+ /** The time of the latest event: the clock {@link runRate} measures an unfinished phase against. */
38
+ updatedAt: number;
39
+ phases: ReviewRunPhase[];
40
+ lanes: ReviewRunLane[];
41
+ /** The last {@link REVIEW_RUN_STEP_RING} steps, oldest first. */
42
+ steps: ReviewStep[];
43
+ failures: ReviewFailure[];
44
+ outcome?: ReviewRunOutcome;
45
+ report?: ReviewReport;
46
+ }
47
+ export type ReviewRunEvent = {
48
+ type: 'progress';
49
+ progress: ReviewProgress;
50
+ } | {
51
+ type: 'step';
52
+ step: ReviewStep;
53
+ } | {
54
+ type: 'end';
55
+ outcome: ReviewRunOutcome;
56
+ report?: ReviewReport;
57
+ };
58
+ export declare function startRun(a: {
59
+ id: string;
60
+ root: string;
61
+ kind: ReviewRunKind;
62
+ at: number;
63
+ }): ReviewRun;
64
+ /** Folds one event into the run; the input run is never mutated. */
65
+ export declare function applyRunEvent(run: ReviewRun, event: ReviewRunEvent, at: number): ReviewRun;
66
+ /** Items per second a phase has sustained so far; 0 when it has not started or no time has passed. */
67
+ export declare function runRate(run: ReviewRun, phase: ReviewPhase): number;
68
+ /** Milliseconds until a phase finishes at its measured rate; 0 when it is complete, undefined when it cannot be told. */
69
+ export declare function runEta(run: ReviewRun, phase: ReviewPhase): number | undefined;
70
+ //# sourceMappingURL=reviewRun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewRun.d.ts","sourceRoot":"","sources":["../../src/knowledge/reviewRun.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAElF,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;AAC5D,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE7D,0EA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E;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,aAAa,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAEpG;AAgCD,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAuB1F;AAID,sGAAsG;AACtG,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAKlE;AAED,yHAAyH;AACzH,wBAAgB,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAO7E"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * knowledge/reviewRun.ts — the PURE recorder of a review run (PRD 41 A8): fold the events a review
3
+ * emits (`onProgress`, `onStep`, the end) into a {@link ReviewRun} a host can persist and a view can
4
+ * draw — phase timeline, worker lanes, the last steps, every failure, the rate and ETA.
5
+ *
6
+ * No clock, no I/O: every function takes the time it should use, so the reducer is deterministic and a
7
+ * stored run replays the same. The host owns persistence (last N runs per root) and throttling.
8
+ */
9
+ /** How many of the latest steps a run keeps (failures are kept whole). */
10
+ export const REVIEW_RUN_STEP_RING = 200;
11
+ export function startRun(a) {
12
+ return { id: a.id, root: a.root, kind: a.kind, startedAt: a.at, updatedAt: a.at, phases: [], lanes: [], steps: [], failures: [] };
13
+ }
14
+ /** Phases whose progress `done` is the index of the file being reached. */
15
+ const PER_FILE = new Set(['extract', 'judge', 'write']);
16
+ function withProgress(phases, p, at) {
17
+ const done = PER_FILE.has(p.phase) ? p.done + 1 : p.done;
18
+ const i = phases.findIndex((x) => x.phase === p.phase);
19
+ const prior = i < 0 ? undefined : phases[i];
20
+ const next = {
21
+ phase: p.phase, startedAt: prior?.startedAt ?? at, done: Math.max(prior?.done ?? 0, done), total: p.total,
22
+ };
23
+ // Once ended it stays ended (a stale or repeated event never reopens it) unless the total grew past what is done.
24
+ if (p.phase === 'done' || next.done >= next.total)
25
+ next.endedAt = prior?.endedAt ?? at;
26
+ if (i < 0)
27
+ return [...phases, next];
28
+ return phases.map((x, j) => (j === i ? next : x));
29
+ }
30
+ const PHASE_ORDER = ['plan', 'extract', 'resolve', 'judge', 'compare', 'write', 'index', 'done'];
31
+ /** Lanes are keyed by phase and id: extract workers and judge lanes are different workers. */
32
+ function withLane(lanes, step) {
33
+ if (step.lane === undefined)
34
+ return lanes;
35
+ const same = (l) => l.phase === step.phase && l.id === step.lane;
36
+ const prior = lanes.find(same);
37
+ const next = {
38
+ phase: step.phase, id: step.lane, path: step.path, done: (prior?.done ?? 0) + 1, busyMs: (prior?.busyMs ?? 0) + step.ms,
39
+ };
40
+ return [...lanes.filter((l) => !same(l)), next]
41
+ .sort((a, b) => PHASE_ORDER.indexOf(a.phase) - PHASE_ORDER.indexOf(b.phase) || a.id - b.id);
42
+ }
43
+ /** Folds one event into the run; the input run is never mutated. */
44
+ export function applyRunEvent(run, event, at) {
45
+ const base = { ...run, updatedAt: at };
46
+ switch (event.type) {
47
+ case 'progress': {
48
+ const phases = withProgress(run.phases, event.progress, at);
49
+ // A new phase reached: the plan is over (it is never revisited).
50
+ return { ...base, phases: phases.map((p) => (p.phase === 'plan' && p.endedAt === undefined ? { ...p, endedAt: at } : p)) };
51
+ }
52
+ case 'step': {
53
+ const s = event.step;
54
+ return {
55
+ ...base,
56
+ lanes: withLane(run.lanes, s),
57
+ steps: [...run.steps, s].slice(-REVIEW_RUN_STEP_RING),
58
+ failures: s.outcome === 'failed' ? [...run.failures, { path: s.path, phase: s.phase, reason: s.reason ?? 'failed' }] : run.failures,
59
+ };
60
+ }
61
+ case 'end':
62
+ return {
63
+ ...base, endedAt: at, outcome: event.outcome, ...(event.report ? { report: event.report } : {}),
64
+ phases: run.phases.map((p) => (p.endedAt === undefined ? { ...p, endedAt: at } : p)),
65
+ };
66
+ }
67
+ }
68
+ const phaseOf = (run, phase) => run.phases.find((p) => p.phase === phase);
69
+ /** Items per second a phase has sustained so far; 0 when it has not started or no time has passed. */
70
+ export function runRate(run, phase) {
71
+ const p = phaseOf(run, phase);
72
+ if (!p)
73
+ return 0;
74
+ const ms = (p.endedAt ?? run.endedAt ?? run.updatedAt) - p.startedAt;
75
+ return ms > 0 && p.done > 0 ? (p.done * 1000) / ms : 0;
76
+ }
77
+ /** Milliseconds until a phase finishes at its measured rate; 0 when it is complete, undefined when it cannot be told. */
78
+ export function runEta(run, phase) {
79
+ const p = phaseOf(run, phase);
80
+ if (!p)
81
+ return undefined;
82
+ const remaining = p.total - p.done;
83
+ if (remaining <= 0)
84
+ return 0;
85
+ const rate = runRate(run, phase);
86
+ return rate > 0 ? Math.round((remaining / rate) * 1000) : undefined;
87
+ }
88
+ //# sourceMappingURL=reviewRun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewRun.js","sourceRoot":"","sources":["../../src/knowledge/reviewRun.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AA0CxC,MAAM,UAAU,QAAQ,CAAC,CAAgE;IACrF,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AACtI,CAAC;AAED,2EAA2E;AAC3E,MAAM,QAAQ,GAA6B,IAAI,GAAG,CAAc,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/F,SAAS,YAAY,CAAC,M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,SAAS,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACjC,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACxE,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * knowledge/reviewRunModel.ts — the vocabulary of a watchable review (PRD 41 A8): phases, the
3
+ * per-file step events a review emits, and the failures it records instead of throwing.
4
+ */
5
+ export type ReviewPhase = 'plan' | 'extract' | 'resolve' | 'judge' | 'compare' | 'write' | 'index' | 'done';
6
+ export type ReviewStepOutcome = 'ok' | 'cached' | 'skipped' | 'failed';
7
+ /**
8
+ * One file in one phase. `cached` = reused prior knowledge or an extract-cache hit; `skipped` = binary
9
+ * or too large; `failed` carries `reason`. `lane` is the worker/lane id (0..width-1) where known.
10
+ */
11
+ export interface ReviewStep {
12
+ path: string;
13
+ phase: ReviewPhase;
14
+ ms: number;
15
+ outcome: ReviewStepOutcome;
16
+ reason?: string;
17
+ lane?: number;
18
+ }
19
+ /** A file a review could not finish: its prior knowledge and manifest hash are kept, so the next review retries it. */
20
+ export interface ReviewFailure {
21
+ path: string;
22
+ phase: ReviewPhase;
23
+ reason: string;
24
+ }
25
+ /** Lane ids 0..width-1 for in-flight work: `take` the lowest free one, `free` it when the work settles. */
26
+ export declare class Lanes {
27
+ private readonly busy;
28
+ private readonly width;
29
+ constructor(width: number);
30
+ take(): number;
31
+ free(id: number): void;
32
+ }
33
+ /** A thrown value as a short, single-line reason. */
34
+ export declare const reasonOf: (error: unknown) => string;
35
+ //# sourceMappingURL=reviewRunModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewRunModel.d.ts","sourceRoot":"","sources":["../../src/knowledge/reviewRunModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAE5G,MAAM,MAAM,iBAAiB,GAAG,IAAI,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEvE;;;GAGG;AACH,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,iBAAiB,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,uHAAuH;AACvH,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,2GAA2G;AAC3G,qBAAa,KAAK;IACd,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B,YAAY,KAAK,EAAE,MAAM,EAAyB;IAElD,IAAI,IAAI,MAAM,CAOb;IAED,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAA0B;CACnD;AAED,qDAAqD;AACrD,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,MAGzC,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * knowledge/reviewRunModel.ts — the vocabulary of a watchable review (PRD 41 A8): phases, the
3
+ * per-file step events a review emits, and the failures it records instead of throwing.
4
+ */
5
+ /** Lane ids 0..width-1 for in-flight work: `take` the lowest free one, `free` it when the work settles. */
6
+ export class Lanes {
7
+ busy = new Set();
8
+ width;
9
+ constructor(width) { this.width = width; }
10
+ take() {
11
+ // More work in flight than lanes means the stage that bounds it is broken: say so, never share a lane.
12
+ if (this.busy.size >= this.width)
13
+ throw new Error(`Lanes: invariant violated — all ${this.width} lanes are busy`);
14
+ let id = 0;
15
+ while (this.busy.has(id))
16
+ id += 1;
17
+ this.busy.add(id);
18
+ return id;
19
+ }
20
+ free(id) { this.busy.delete(id); }
21
+ }
22
+ /** A thrown value as a short, single-line reason. */
23
+ export const reasonOf = (error) => {
24
+ const text = error instanceof Error ? error.message : String(error);
25
+ return text.split(/\r?\n/)[0].slice(0, 300) || 'unknown error';
26
+ };
27
+ //# sourceMappingURL=reviewRunModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewRunModel.js","sourceRoot":"","sources":["../../src/knowledge/reviewRunModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0BH,2GAA2G;AAC3G,MAAM,OAAO,KAAK;IACG,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IACzB,KAAK,CAAS;IAE/B,YAAY,KAAa,IAAI,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;IAElD,IAAI;QACA,uGAAuG;QACvG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,CAAC,KAAK,iBAAiB,CAAC,CAAC;QAClH,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,EAAE,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClB,OAAO,EAAE,CAAC;IACd,CAAC;IAED,IAAI,CAAC,EAAU,IAAU,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACnD;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAU,EAAE;IAC/C,MAAM,IAAI,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,eAAe,CAAC;AACpE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seanhogg/builderforce-memory",
3
- "version": "2026.10.42",
3
+ "version": "2026.10.44",
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",
@@ -113,7 +113,7 @@
113
113
  },
114
114
  "homepage": "https://github.com/SeanHogg/builderforce-memory/tree/main/packages/memory#readme",
115
115
  "peerDependencies": {
116
- "@seanhogg/builderforce-memory-engine": "^2026.10.42"
116
+ "@seanhogg/builderforce-memory-engine": "^2026.10.44"
117
117
  },
118
118
  "devDependencies": {
119
119
  "@jest/globals": "^29.7.0",
@@ -127,7 +127,7 @@
127
127
  "ts-jest": "^29.2.0",
128
128
  "typescript": "npm:@typescript/typescript6@^6.0.2",
129
129
  "typescript-7": "npm:typescript@^7.0.2",
130
- "@seanhogg/builderforce-memory-engine": "2026.10.42"
130
+ "@seanhogg/builderforce-memory-engine": "2026.10.44"
131
131
  },
132
132
  "jest": {
133
133
  "preset": "ts-jest/presets/default-esm",
@@ -0,0 +1,21 @@
1
+ /**
2
+ * src/knowledge/externals.test.ts
3
+ * The external-service ids: one list, unique, lower-case words, and exported from the knowledge index.
4
+ */
5
+
6
+ import { describe, expect, it } from '@jest/globals';
7
+ import { EXTERNAL_SERVICE_IDS as FROM_INDEX } from './index.js';
8
+ import { EXTERNAL_SERVICE_IDS, type ExternalServiceId } from './externals.js';
9
+
10
+ describe('EXTERNAL_SERVICE_IDS', () => {
11
+ it('lists each service once, as a short lower-case word (they ride in a comma-joined badge)', () => {
12
+ expect(new Set(EXTERNAL_SERVICE_IDS).size).toBe(EXTERNAL_SERVICE_IDS.length);
13
+ for (const id of EXTERNAL_SERVICE_IDS) expect(id).toMatch(/^[a-z]+$/);
14
+ });
15
+
16
+ it('is the list the knowledge index re-exports, and its type is its members', () => {
17
+ expect(FROM_INDEX).toBe(EXTERNAL_SERVICE_IDS);
18
+ const id: ExternalServiceId = 'postgres';
19
+ expect(EXTERNAL_SERVICE_IDS).toContain(id);
20
+ });
21
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * knowledge/externals.ts — the ids of the outside services a code file can be said to import
3
+ * (the `externals` badge). The module-specifier patterns that decide an id live with the code pack
4
+ * that writes the badge; the ids live HERE so the writer (the pack) and every reader (the map that
5
+ * names a line's end) type against one list.
6
+ */
7
+
8
+ export const EXTERNAL_SERVICE_IDS = ['postgres', 'kv', 'llm', 'github', 'stripe', 'mail', 'slack', 'oauth'] as const;
9
+
10
+ export type ExternalServiceId = (typeof EXTERNAL_SERVICE_IDS)[number];
@@ -7,8 +7,9 @@
7
7
  */
8
8
 
9
9
  import type { ParsedSection, SourceDocument } from '../ingest/types.js';
10
- import type { ExtractContext, Extracted, KnowledgePack, KnowledgeParser, KnowledgeStore, NodeRef } from './model.js';
11
- import { basenameOf, srcRef } from './refs.js';
10
+ import type { Extracted, KnowledgePack, KnowledgeParser, KnowledgeStore, NodeRef } from './model.js';
11
+ import { jobOf, runExtractor, type ExtractPool } from './extractJob.js';
12
+ import { srcRef } from './refs.js';
12
13
  import { entityName, knownKeysOf, resolveEntities } from './resolve.js';
13
14
  import { asPathSource, composePacks, EXTRACTOR_VERSION, resolveRelativePath, type ComposedPacks } from './sources.js';
14
15
 
@@ -30,6 +31,16 @@ export interface ExtractFileArgs {
30
31
  composed?: ComposedPacks;
31
32
  /** Already known entity keys (a review reads them once); default: the store's `ent:` facts. */
32
33
  knownKeys?: ReadonlyMap<string, NodeRef>;
34
+ /**
35
+ * A host's extraction pool (PRD 41 A8): a cache miss is extracted by `pool(job, signal)` instead of in
36
+ * this thread, which then never parses. The extract cache is still read and written here.
37
+ */
38
+ pool?: ExtractPool;
39
+ signal?: AbortSignal;
40
+ /** With a `pool`: whether the file's pack judges it, i.e. the worker must return its sections (default: never). */
41
+ wantsSections?: (pack: KnowledgePack) => boolean;
42
+ /** Leave the extract cache write to the caller (the review writes it in plan order); default: write it. */
43
+ writeCache?: boolean;
33
44
  }
34
45
 
35
46
  export interface FileExtraction {
@@ -38,6 +49,14 @@ export interface FileExtraction {
38
49
  pack: KnowledgePack;
39
50
  /** The parser's sections of the file (the review judges these). */
40
51
  sections: ParsedSection[];
52
+ /** The extract came from the content-hash cache — nothing was extracted. */
53
+ cached: boolean;
54
+ }
55
+
56
+ /** Adds `extracted` to the content-hash cache, keeping the entries of the other files that share the hash. */
57
+ export async function putExtract(store: KnowledgeStore, hash: string, extracted: Extracted, prior?: readonly Extracted[]): Promise<void> {
58
+ const cached = prior ?? (await store.getExtracted?.(hash)) ?? [];
59
+ await store.putExtracted?.(hash, [...cached.filter((e) => e.sourceRef !== extracted.sourceRef), extracted]);
41
60
  }
42
61
 
43
62
  /** Extraction plus what produced it; undefined when no pack's parser accepts the file. */
@@ -45,26 +64,39 @@ export async function extractFileDetailed(a: ExtractFileArgs): Promise<FileExtra
45
64
  const src = asPathSource(a.doc, a.path, a.hash);
46
65
  const hit = (a.composed ?? composePacks(a.packs)).resolve(src);
47
66
  if (!hit) return undefined;
48
- const sections = hit.parser.parse(src);
49
67
  const ref = srcRef(a.rootId, a.path);
68
+ // With a pool the main thread never parses: the worker returns the sections when the file will be judged.
69
+ const wants = !!a.pool && !!a.wantsSections?.(hit.pack);
70
+ let sections: ParsedSection[] = a.pool ? [] : hit.parser.parse(src);
50
71
  const cached = await a.store.getExtracted?.(a.hash);
51
72
  // A cached entry of another extractor version is ignored: its output may differ from today's.
52
73
  const found = cached?.find((e) => e.sourceRef === ref && e.extractorVersion === EXTRACTOR_VERSION);
53
- if (found) return { extracted: found, parser: hit.parser, pack: hit.pack, sections };
74
+ if (found) {
75
+ if (a.pool && wants) {
76
+ const out = await a.pool(jobOf({ rootId: a.rootId, path: a.path, hash: a.hash, doc: a.doc, knownKeys: new Map(), sectionsOnly: true }), a.signal);
77
+ if (!out.sections) throw new Error(`extract pool returned no sections for ${a.path}`);
78
+ sections = out.sections;
79
+ }
80
+ return { extracted: found, parser: hit.parser, pack: hit.pack, sections, cached: true };
81
+ }
54
82
 
55
- const ctx: ExtractContext = {
56
- rootId: a.rootId,
57
- knownKeys: a.knownKeys ?? knownKeysOfEntities((await a.store.facts({ rootId: a.rootId })).map((f) => f.key)),
58
- resolvePath: resolveRelativePath,
59
- };
60
- const extracted: Extracted = hit.parser.extract
61
- ? { ...hit.parser.extract(src, sections, ctx), sourceHash: a.hash, extractorVersion: EXTRACTOR_VERSION }
62
- : {
63
- sourceRef: ref, sourceHash: a.hash, extractorVersion: EXTRACTOR_VERSION, edges: [], keys: [{ ref, key: a.path }],
64
- nodes: [{ ref, kind: 'file', label: basenameOf(a.path), pack: hit.pack.id, importance: 0, origin: 'extracted', sourceHash: a.hash }],
65
- };
66
- await a.store.putExtracted?.(a.hash, [...(cached ?? []).filter((e) => e.sourceRef !== ref), extracted]);
67
- return { extracted, parser: hit.parser, pack: hit.pack, sections };
83
+ const knownKeys = a.knownKeys ?? knownKeysOfEntities((await a.store.facts({ rootId: a.rootId })).map((f) => f.key));
84
+ let extracted: Extracted;
85
+ if (a.pool) {
86
+ const out = await a.pool(jobOf({ rootId: a.rootId, path: a.path, hash: a.hash, doc: a.doc, knownKeys, needSections: wants }), a.signal);
87
+ // Exact match only: a result for another file, or none although the packs accept this one, is a failure.
88
+ const mine = out.extracted.find((e) => e.sourceRef === ref);
89
+ if (!mine) throw new Error(`extract pool returned no extract for ${a.path}`);
90
+ if (wants) {
91
+ if (!out.sections) throw new Error(`extract pool returned no sections for ${a.path}`);
92
+ sections = out.sections;
93
+ }
94
+ extracted = mine;
95
+ } else {
96
+ extracted = runExtractor(hit, src, sections, { rootId: a.rootId, knownKeys, resolvePath: resolveRelativePath }, a);
97
+ }
98
+ if (a.writeCache !== false) await putExtract(a.store, a.hash, extracted, cached ?? []);
99
+ return { extracted, parser: hit.parser, pack: hit.pack, sections, cached: false };
68
100
  }
69
101
 
70
102
  /**