@seanhogg/builderforce-memory 2026.10.59 → 2026.10.62

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 (105) hide show
  1. package/README.md +3 -3
  2. package/dist/ingest/docsExtract.d.ts.map +1 -1
  3. package/dist/ingest/docsExtract.js +8 -4
  4. package/dist/ingest/docsExtract.js.map +1 -1
  5. package/dist/ingest/parserSupport.d.ts +2 -2
  6. package/dist/ingest/parserSupport.js +3 -3
  7. package/dist/ingest/parserSupport.js.map +1 -1
  8. package/dist/knowledge/assetFile.d.ts +27 -0
  9. package/dist/knowledge/assetFile.d.ts.map +1 -0
  10. package/dist/knowledge/assetFile.js +31 -0
  11. package/dist/knowledge/assetFile.js.map +1 -0
  12. package/dist/knowledge/backfillNoExtract.d.ts +11 -13
  13. package/dist/knowledge/backfillNoExtract.d.ts.map +1 -1
  14. package/dist/knowledge/backfillNoExtract.js +34 -43
  15. package/dist/knowledge/backfillNoExtract.js.map +1 -1
  16. package/dist/knowledge/build.d.ts.map +1 -1
  17. package/dist/knowledge/build.js +11 -7
  18. package/dist/knowledge/build.js.map +1 -1
  19. package/dist/knowledge/extractFile.d.ts +2 -0
  20. package/dist/knowledge/extractFile.d.ts.map +1 -1
  21. package/dist/knowledge/extractFile.js +6 -5
  22. package/dist/knowledge/extractFile.js.map +1 -1
  23. package/dist/knowledge/extractJob.d.ts +3 -1
  24. package/dist/knowledge/extractJob.d.ts.map +1 -1
  25. package/dist/knowledge/extractJob.js +1 -1
  26. package/dist/knowledge/extractJob.js.map +1 -1
  27. package/dist/knowledge/findings.js +4 -4
  28. package/dist/knowledge/findings.js.map +1 -1
  29. package/dist/knowledge/importance.d.ts +5 -0
  30. package/dist/knowledge/importance.d.ts.map +1 -1
  31. package/dist/knowledge/importance.js +7 -0
  32. package/dist/knowledge/importance.js.map +1 -1
  33. package/dist/knowledge/index.d.ts +2 -2
  34. package/dist/knowledge/index.d.ts.map +1 -1
  35. package/dist/knowledge/index.js +2 -2
  36. package/dist/knowledge/index.js.map +1 -1
  37. package/dist/knowledge/model.d.ts +3 -1
  38. package/dist/knowledge/model.d.ts.map +1 -1
  39. package/dist/knowledge/outline.d.ts.map +1 -1
  40. package/dist/knowledge/outline.js +4 -2
  41. package/dist/knowledge/outline.js.map +1 -1
  42. package/dist/knowledge/owedFiles.d.ts +28 -4
  43. package/dist/knowledge/owedFiles.d.ts.map +1 -1
  44. package/dist/knowledge/owedFiles.js +60 -8
  45. package/dist/knowledge/owedFiles.js.map +1 -1
  46. package/dist/knowledge/plan.d.ts +11 -2
  47. package/dist/knowledge/plan.d.ts.map +1 -1
  48. package/dist/knowledge/plan.js +24 -9
  49. package/dist/knowledge/plan.js.map +1 -1
  50. package/dist/knowledge/refs.d.ts +2 -0
  51. package/dist/knowledge/refs.d.ts.map +1 -1
  52. package/dist/knowledge/refs.js +2 -0
  53. package/dist/knowledge/refs.js.map +1 -1
  54. package/dist/knowledge/resolve.d.ts.map +1 -1
  55. package/dist/knowledge/resolve.js +2 -2
  56. package/dist/knowledge/resolve.js.map +1 -1
  57. package/dist/knowledge/review.d.ts.map +1 -1
  58. package/dist/knowledge/review.js +8 -5
  59. package/dist/knowledge/review.js.map +1 -1
  60. package/dist/knowledge/reviewModel.d.ts +17 -2
  61. package/dist/knowledge/reviewModel.d.ts.map +1 -1
  62. package/dist/knowledge/reviewPrefetch.d.ts +10 -2
  63. package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
  64. package/dist/knowledge/reviewPrefetch.js +15 -5
  65. package/dist/knowledge/reviewPrefetch.js.map +1 -1
  66. package/dist/knowledge/reviewRunModel.d.ts +1 -1
  67. package/dist/knowledge/sources.d.ts +17 -2
  68. package/dist/knowledge/sources.d.ts.map +1 -1
  69. package/dist/knowledge/sources.js +42 -7
  70. package/dist/knowledge/sources.js.map +1 -1
  71. package/dist/knowledge/truncate.d.ts.map +1 -1
  72. package/dist/knowledge/truncate.js +6 -5
  73. package/dist/knowledge/truncate.js.map +1 -1
  74. package/package.json +3 -3
  75. package/src/contract/exports.snapshot.json +2 -0
  76. package/src/contract/regression.assets.test.ts +246 -0
  77. package/src/contract/regression.recheck.test.ts +5 -5
  78. package/src/contract/regression.review.test.ts +185 -5
  79. package/src/contract/types.contract.test.ts +16 -3
  80. package/src/ingest/docsExtract.ts +9 -4
  81. package/src/ingest/parserSupport.ts +3 -3
  82. package/src/knowledge/assetFile.ts +34 -0
  83. package/src/knowledge/backfillNoExtract.ts +29 -35
  84. package/src/knowledge/build.ts +10 -5
  85. package/src/knowledge/docs.test.ts +5 -2
  86. package/src/knowledge/extractFile.ts +8 -5
  87. package/src/knowledge/extractJob.ts +3 -3
  88. package/src/knowledge/findings.ts +4 -4
  89. package/src/knowledge/importance.ts +8 -0
  90. package/src/knowledge/index.ts +2 -2
  91. package/src/knowledge/model.ts +3 -1
  92. package/src/knowledge/outline.ts +4 -2
  93. package/src/knowledge/owedFiles.ts +62 -7
  94. package/src/knowledge/plan.ts +34 -9
  95. package/src/knowledge/refs.ts +3 -0
  96. package/src/knowledge/resolve.ts +2 -2
  97. package/src/knowledge/review.fixes.test.ts +3 -2
  98. package/src/knowledge/review.gaps.test.ts +5 -3
  99. package/src/knowledge/review.test.ts +4 -2
  100. package/src/knowledge/review.ts +10 -7
  101. package/src/knowledge/reviewModel.ts +17 -2
  102. package/src/knowledge/reviewPrefetch.ts +21 -7
  103. package/src/knowledge/reviewRunModel.ts +1 -1
  104. package/src/knowledge/sources.ts +46 -8
  105. package/src/knowledge/truncate.ts +6 -5
@@ -9,7 +9,7 @@
9
9
  import type { Finding, NodeRef } from './model.js';
10
10
  import type { SimilarPair } from '../retrieval/knowledge-index/types.js';
11
11
  import { hashText } from '../ingest/hash.js';
12
- import { compareStr, normalizeKey, round6 } from './refs.js';
12
+ import { compareStr, FALLBACK_PACK_ID, normalizeKey, round6 } from './refs.js';
13
13
 
14
14
  export { normalizeKey };
15
15
 
@@ -46,7 +46,7 @@ export function knownKeysOf(resolved: readonly ResolvedEntity[]): Map<string, No
46
46
  * `possible-same` findings from near-duplicate pairs between two DIFFERENT entities (pairs
47
47
  * already merged by key, or naming a non-entity, are not reported).
48
48
  */
49
- export function possibleSameFindings(pairs: readonly SimilarPair[], pack = 'memory'): Finding[] {
49
+ export function possibleSameFindings(pairs: readonly SimilarPair[], pack = FALLBACK_PACK_ID): Finding[] {
50
50
  const seen = new Set<string>();
51
51
  const out: Finding[] = [];
52
52
  for (const p of pairs) {
@@ -58,9 +58,10 @@ describe('binary documents', () => {
58
58
  expect(isBinaryDocumentType('application/vnd.api+json')).toBe(false);
59
59
  });
60
60
 
61
- it('a docx with no host parser is skipped as binary', async () => {
61
+ it('a docx with no host parser is planned as an asset, not skipped', async () => {
62
62
  const plan = await planReview(memSource({ 'a.docx': 'x', 'b.md': '# B\n' }), new InMemoryIngestManifest(), [DOCS_PACK]);
63
- expect(plan.skipped).toContainEqual({ path: 'a.docx', reason: 'binary' });
63
+ expect(plan.skipped.map((s) => s.path)).not.toContain('a.docx');
64
+ expect(plan.assets).toBe(1);
64
65
  });
65
66
 
66
67
  it('a host pdf pack placed AFTER the docs pack still claims the pdf', async () => {
@@ -95,10 +95,11 @@ describe('planReview — ignores and documents', () => {
95
95
  expect(plan.changed).toContain('draft.md');
96
96
  });
97
97
 
98
- it('skips pdf/office as binary unless a host parser claims the media type', async () => {
98
+ it('plans pdf/office as an asset unless a host parser claims the media type', async () => {
99
99
  const source = memSource({ 'a.pdf': 'text', 'b.md': '# B\n' });
100
- expect((await planReview(source, new InMemoryIngestManifest(), [DOCS_PACK])).skipped)
101
- .toContainEqual({ path: 'a.pdf', reason: 'binary' });
100
+ const bare = await planReview(source, new InMemoryIngestManifest(), [DOCS_PACK]);
101
+ expect(bare.skipped.map((s) => s.path)).not.toContain('a.pdf');
102
+ expect(bare.assets).toBe(1);
102
103
  const pdf: KnowledgeParser = {
103
104
  id: 'pdf-text',
104
105
  accepts: (s) => s.content.kind === 'text' && s.content.mediaType === 'application/pdf',
@@ -107,6 +108,7 @@ describe('planReview — ignores and documents', () => {
107
108
  const withPdf: KnowledgePack = { ...DOCS_PACK, parsers: [pdf, ...DOCS_PACK.parsers] };
108
109
  const plan = await planReview(source, new InMemoryIngestManifest(), [withPdf]);
109
110
  expect(plan.changed).toContain('a.pdf');
111
+ expect(plan.assets).toBe(0);
110
112
  });
111
113
  });
112
114
 
@@ -35,12 +35,14 @@ describe('planReview', () => {
35
35
  const plan = await planReview(source, manifest, [DOCS_PACK]);
36
36
  expect(source.reads).toEqual(['.gitignore']);
37
37
  expect(plan.changed).toEqual(['a.md']);
38
- expect(plan.unchanged).toBe(1);
38
+ expect(plan.unchanged).toBe(2); // b.md and the img.png asset
39
39
  expect(plan.byPack).toEqual({ docs: 2 });
40
+ expect(plan.assets).toBe(1);
40
41
  expect(plan.estimatedModelCalls).toBeGreaterThan(0);
41
42
  expect(plan.skipped).toEqual(expect.arrayContaining([
42
- { path: '.gitignore', reason: 'ignored' }, { path: 'img.png', reason: 'binary' }, { path: 'skip/x.md', reason: 'ignored' },
43
+ { path: '.gitignore', reason: 'ignored' }, { path: 'skip/x.md', reason: 'ignored' },
43
44
  ]));
45
+ expect(plan.skipped.map((s) => s.path)).not.toContain('img.png');
44
46
 
45
47
  source.reads.length = 0;
46
48
  await reviewDirectory(args(source, memStore(), manifest));
@@ -43,7 +43,8 @@ import {
43
43
  import { createModelLimiter } from './modelLimiter.js';
44
44
  import { JudgeBreaker } from './judgeCalls.js';
45
45
  import { applyJudge, judgesPack, splitSections, startJudge, type JudgeJob } from './reviewJudge.js';
46
- import { createPrefetch, type Prefetch } from './reviewPrefetch.js';
46
+ import { createPrefetch, type Prefetch, type PrefetchFile } from './reviewPrefetch.js';
47
+ import { putAsset } from './assetFile.js';
47
48
  import { Lanes } from './reviewRunModel.js';
48
49
  import { compareNew, pendingClaims, saveAwaiting } from './reviewCompare.js';
49
50
  import { factsWithoutAnchor, StoredIndex } from './reviewStored.js';
@@ -67,7 +68,7 @@ function readAheadOf(args: ReviewArgs, concurrency: number): number {
67
68
 
68
69
  /** One changed file between dispatch and the ordered writer: what its prefetch found and its judging in flight. */
69
70
  interface Slot {
70
- f: { path: string; hash: string };
71
+ f: PrefetchFile;
71
72
  i: number;
72
73
  job: Prefetch;
73
74
  judge: JudgeJob | undefined;
@@ -121,13 +122,13 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
121
122
  const judgedPrior = await manifestMap(manifest, judgedManifestKey(rootId));
122
123
  const judgedNow = new Map(judgedPrior);
123
124
  const filesNow = new Map(detail.prior);
124
- // A root reviewed before binary files were recorded: settle files with no body: binary-by-extension ones (no read), and the ones a replica asked to re-check.
125
+ // Files with no stored body: assets the manifest names (queued so their node is written, no read) and the ones a replica asked to re-check (queued; this review stores their body or asset node).
125
126
  const asked = (await store.recheckHashes?.()) ?? [];
126
127
  // ONE bulk fetch of the extract cache for the whole run instead of a round trip per file: the files this run extracts and the ones the backfill looks up.
127
128
  const preChanged = detail.files.filter((f) => f.changed && (!args.only || args.only.includes(f.path)));
128
129
  const preload = [...new Set([...preChanged.map((f) => f.hash), ...backfillCandidates(detail, asked)])];
129
130
  if (preload.length > 0) await store.preloadExtracted?.(preload);
130
- await backfillNoExtract({ store, source, detail, asked, only: args.only, signal });
131
+ await backfillNoExtract({ store, detail, asked, only: args.only, signal });
131
132
  // A re-check request is answered only when the work it asked for is done: the body stored, the binary recorded, or the failure recorded.
132
133
  const askedSet = new Set(asked);
133
134
  const settledRecheck = async (hash: string): Promise<void> => { if (askedSet.has(hash)) await store.clearRecheck?.([hash]); };
@@ -223,11 +224,13 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
223
224
  return true;
224
225
  }
225
226
  failures.delete(f.path); // it read and extracted (or was decided): the run of failures at this hash ends
227
+ // An asset (planned binary, or a text-extension file found binary on read): never extracted, but it IS a file of the root, so
228
+ // its file node is stored (assetFile.ts) — a replica tells it from "not extracted yet", and references to its path resolve.
226
229
  // Recorded, so a file found binary on read is not re-read by every later review.
227
- if (job.kind === 'binary') {
230
+ if (job.kind === 'binary' || job.kind === 'asset') {
228
231
  filesNow.set(f.path, f.hash);
229
232
  finished.add(f.path);
230
- await putNoExtract(store, f.hash); // the explicit "nothing extracted", so a replica can tell it from "not extracted yet"
233
+ await putAsset(store, rootId, f);
231
234
  await settledRecheck(f.hash);
232
235
  await store.markStale(scope, srcRef(rootId, f.path), f.hash);
233
236
  report.staleMarked += 1;
@@ -395,7 +398,7 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
395
398
  // content-changed or not, and the owed paths the plan did not list that the manifest still holds.
396
399
  await saveExtractorState(manifest, rootId, owedAfterRun({
397
400
  state: detail.extractor, changed, prior: detail.prior, finished, carried: detail.carried, live: filesNow, measured, unreadable,
398
- }), failures);
401
+ }), failures, detail.extractor.documentsNow);
399
402
  await write(report.aborted ? scopeRecord : { ...scopeRecord, lastDigest: report.digest, lastReviewedAt: new Date(now()).toISOString() });
400
403
  report.durationMs = now() - started;
401
404
  progress({ phase: 'done', done: work.length, total: work.length });
@@ -22,18 +22,33 @@ export interface DirectorySource {
22
22
  * The function that produced the `hash` of `list()` entries, over a text file's content. When given, the review hashes the
23
23
  * text it read (once) and a file whose bytes no longer match the planned hash fails with "changed since plan" and stays owed.
24
24
  * Optional: a source whose hash is not a pure function of the text (or that cannot say) is not checked in-thread.
25
+ * The `path` lets a host whose read() transforms bytes (document text) return the listing hash for that path.
26
+ * A transforming host must return the hash of the bytes it ACTUALLY read on that call, never the cached listing hash,
27
+ * or the changed-since-plan check becomes vacuous.
28
+ * A host that declares `hashOf(text)` still works: the extra argument is ignored.
25
29
  */
26
- hashOf?(text: string): string;
30
+ hashOf?(text: string, path: string): string;
31
+ /**
32
+ * The read deadline for `path`, in ms, when it differs from the default (5 s). A finite number above 0 is used for that path's read;
33
+ * anything else keeps the default. For slow transforming reads such as document extraction.
34
+ */
35
+ readTimeoutMs?(path: string): number | undefined;
27
36
  }
28
37
 
29
38
  export interface ReviewPlan {
30
39
  rootId: string;
31
40
  files: number;
32
41
  byPack: Record<string, number>;
42
+ /**
43
+ * Files in `files` that are assets (binary, never read): stored as a file node with `mediaType` and `size`, not counted in `byPack`.
44
+ * `files` includes them (the plan diffs them like any file), so a host's ETA and "files to read" figures subtract `assets`
45
+ * (absent on a plan from an older host or built by hand: read it as 0).
46
+ */
47
+ assets?: number;
33
48
  unchanged: number;
34
49
  changed: string[];
35
50
  removed: string[];
36
- skipped: Array<{ path: string; reason: 'ignored' | 'binary' | 'too-large' | 'no-pack' }>;
51
+ skipped: Array<{ path: string; reason: 'ignored' | 'too-large' | 'no-pack' }>;
37
52
  /** ≈ judgement calls for changed files (sections of judged kinds). */
38
53
  estimatedModelCalls: number;
39
54
  /** The file budget of the judge pass this run will run after the map is complete (PRD 41 A10); set by the host, so the confirm chip states it. */
@@ -23,6 +23,8 @@ import { isBinaryText, type ComposedPacks } from './sources.js';
23
23
  export type Prefetch = (
24
24
  | { kind: 'read-error'; reason: string }
25
25
  | { kind: 'binary' }
26
+ /** Planned as an asset (binary by extension): decided without a read, the review writes its file node. */
27
+ | { kind: 'asset' }
26
28
  | { kind: 'none' }
27
29
  | { kind: 'extracted'; doc?: SourceDocument; extraction: FileExtraction }
28
30
  | { kind: 'failed'; reason: string; transient?: true }
@@ -53,6 +55,7 @@ export function extractStepOf(path: string, job: Prefetch): ReviewStep {
53
55
  case 'read-error': return { ...base, outcome: 'failed', reason: `read: ${job.reason}` };
54
56
  case 'failed': return { ...base, outcome: 'failed', reason: job.reason };
55
57
  case 'binary': return { ...base, outcome: 'skipped', reason: 'binary' };
58
+ case 'asset': return { ...base, outcome: 'ok', reason: 'asset' }; // its node is written: the file is stored, just not read
56
59
  case 'none': return { ...base, outcome: 'skipped', reason: 'no-pack' };
57
60
  case 'extracted': return { ...base, outcome: job.extraction.cached ? 'cached' : 'ok' };
58
61
  }
@@ -64,25 +67,36 @@ export { CHANGED_SINCE_PLAN };
64
67
  export const DEFAULT_READ_TIMEOUT_MS = 5_000;
65
68
  export const DEFAULT_EXTRACT_TIMEOUT_MS = 10_000;
66
69
 
67
- export function createPrefetch(c: PrefetchContext): (f: { path: string; hash: string }) => Promise<Prefetch> {
70
+ /** A changed file as the prefetch sees it: a `PlannedFile`'s path, hash, size and asset flag. */
71
+ export type PrefetchFile = { path: string; hash: string; size: number; asset?: true };
72
+
73
+ export function createPrefetch(c: PrefetchContext): (f: PrefetchFile) => Promise<Prefetch> {
68
74
  // A lane is a worker: taken while the file holds an extract slot. The extract stage holds at most `extractWidth` at once, so the
69
75
  // extract deadline counts from the moment a job holds a slot, never from its wait in line (the limiter is used as a plain semaphore).
70
76
  const lanes = new Lanes(c.extractWidth ?? c.width);
71
77
  const extractSlots = createModelLimiter(c.extractWidth ?? c.width);
72
78
  const withDeadline = createDeadlines(c.signal);
73
- const readMs = c.args.timeouts?.readMs ?? DEFAULT_READ_TIMEOUT_MS;
79
+ const defaultReadMs = c.args.timeouts?.readMs ?? DEFAULT_READ_TIMEOUT_MS;
80
+ /** The source's own read deadline for `path`, when it sets a usable one (finite, above 0). */
81
+ const readOverrideOf = (path: string): number | undefined => {
82
+ const ms = c.args.source.readTimeoutMs?.(path);
83
+ return typeof ms === 'number' && Number.isFinite(ms) && ms > 0 ? ms : undefined;
84
+ };
85
+ const readMsOf = (path: string): number => readOverrideOf(path) ?? defaultReadMs;
74
86
  const extractMs = c.args.timeouts?.extractMs ?? DEFAULT_EXTRACT_TIMEOUT_MS;
75
87
  // Judging is a later pass in a mechanical review: no sections are wanted from the pool.
76
88
  const wantsSections = (pack: KnowledgePack) => !c.args.mechanical && judgesPack(c.args.judgement, pack);
77
89
  const byPool = !!c.args.extractPool && !!c.args.deferRead;
78
90
 
79
- const run = async (f: { path: string; hash: string }, parts: NonNullable<ReviewStep['parts']>, held: { lane: number }): Promise<Outcome> => {
91
+ const run = async (f: PrefetchFile, parts: NonNullable<ReviewStep['parts']>, held: { lane: number }): Promise<Outcome> => {
80
92
  // A stopped run starts nothing: a job that has not begun settles at once. Once the read has begun the job finishes (its slot wait below is signal-free for a file already read).
81
93
  if (c.signal.aborted) return { kind: 'failed', reason: reasonOf(c.signal.reason), transient: true };
94
+ // The plan decided it (isAssetPath): no read, no extract slot.
95
+ if (f.asset) return { kind: 'asset' };
82
96
  let doc: SourceDocument | undefined;
83
97
  const t0 = Date.now();
84
98
  if (!byPool) {
85
- try { doc = await withDeadline(readMs, (signal) => c.args.source.read(f.path, signal)); } catch (error) {
99
+ try { doc = await withDeadline(readMsOf(f.path), (signal) => c.args.source.read(f.path, signal)); } catch (error) {
86
100
  return { kind: 'read-error', reason: reasonOf(error) };
87
101
  }
88
102
  parts.readMs = Date.now() - t0;
@@ -91,11 +105,11 @@ export function createPrefetch(c: PrefetchContext): (f: { path: string; hash: st
91
105
  if (doc && doc.content.kind === 'text' && isBinaryText(doc.content.text)) return { kind: 'binary' };
92
106
  const extraction = await extractSlots.run(async () => {
93
107
  held.lane = lanes.take();
94
- try { return await withDeadline(extractMs, (signal) => extractFileDetailed({
108
+ try { return await withDeadline(byPool ? extractMs + (readOverrideOf(f.path) ?? 0) : extractMs,(signal) => extractFileDetailed({
95
109
  rootId: c.rootId, path: f.path, hash: f.hash, ...(doc ? { doc } : {}), packs: c.packs, store: c.store, composed: c.composed,
96
110
  knownKeys: c.knownKeys, writeCache: false,
97
111
  onTiming: (t) => { parts.lookupMs = t.lookupMs; parts.poolMs = t.poolMs; },
98
- ...(c.args.extractPool ? { pool: c.args.extractPool, signal, wantsSections, ...(byPool ? { readByPool: true } : {}) } : {}),
112
+ ...(c.args.extractPool ? { pool: c.args.extractPool, signal, wantsSections, ...(byPool ? { readByPool: true, ...(readOverrideOf(f.path) ? { readMs: readOverrideOf(f.path)! } : {}) } : {}) } : {}),
99
113
  })); } finally { lanes.free(held.lane); }
100
114
  }, byPool ? c.signal : undefined);
101
115
  if (!extraction) return { kind: 'none' };
@@ -103,7 +117,7 @@ export function createPrefetch(c: PrefetchContext): (f: { path: string; hash: st
103
117
  // stored, the bytes read must be the bytes planned: hashed once, from the text already in hand. The review writes the
104
118
  // extract cache only for an 'extracted' job, so nothing is stored under the stale hash.
105
119
  const hashOf = c.args.source.hashOf;
106
- if (hashOf && doc && doc.content.kind === 'text' && hashOf(doc.content.text) !== f.hash) return { kind: 'failed', reason: CHANGED_SINCE_PLAN, transient: true };
120
+ if (hashOf && doc && doc.content.kind === 'text' && hashOf.call(c.args.source, doc.content.text, f.path) !== f.hash) return { kind: 'failed', reason: CHANGED_SINCE_PLAN, transient: true };
107
121
  return { kind: 'extracted', ...(doc ? { doc } : {}), extraction };
108
122
  } catch (error) {
109
123
  if (error instanceof BinaryContent) return { kind: 'binary' };
@@ -10,7 +10,7 @@ export type ReviewStepOutcome = 'ok' | 'cached' | 'skipped' | 'failed';
10
10
 
11
11
  /**
12
12
  * One file in one phase. `cached` = reused prior knowledge or an extract-cache hit; `skipped` = binary
13
- * or too large; `failed` carries `reason`. `lane` is the worker/lane id (0..width-1) where known.
13
+ * on read or too large; an asset (a binary file never read) is `ok` with reason `asset`; `failed` carries `reason`. `lane` is the worker/lane id (0..width-1) where known.
14
14
  */
15
15
  export interface ReviewStep {
16
16
  path: string;
@@ -7,11 +7,12 @@
7
7
  import { htmlParser, markdownParser, ParserRegistry, plainTextParser } from '../ingest/parsers.js';
8
8
  import { isBinaryDocumentType, mediaTypeOf } from '../ingest/parserSupport.js';
9
9
  import { CONTENT_HASH_FIELD, type ChunkFingerprint, type IngestManifest, type SourceDocument } from '../ingest/types.js';
10
- import type { KnowledgePack, KnowledgeParser } from './model.js';
10
+ import type { Extracted, KnowledgePack, KnowledgeParser } from './model.js';
11
11
  import { matchGlob } from './partitions.js';
12
12
  import { compareStr, walkRelative } from './refs.js';
13
13
 
14
14
  /** Default per-file size cap (bytes). */
15
+ // Changing this cap changes which claimed documents are assets (plan.ts), so it requires an EXTRACTOR_VERSION bump.
15
16
  export const DEFAULT_MAX_FILE_BYTES = 2 * 1024 * 1024;
16
17
  /**
17
18
  * Version of the extractors' output. Bump it whenever an extractor emits different nodes,
@@ -20,9 +21,13 @@ export const DEFAULT_MAX_FILE_BYTES = 2 * 1024 * 1024;
20
21
  * re-extraction (judged sections with unchanged text are re-anchored, not judged again; see
21
22
  * owedFiles.ts for how an unfinished one is carried to the next review).
22
23
  */
23
- export const EXTRACTOR_VERSION = 3;
24
- /** Always ignored: VCS internals, installed dependencies, builderforce config. */
25
- const DEFAULT_IGNORES = ['.git/', 'node_modules/', '.builderforce/', '.gitignore'];
24
+ export const EXTRACTOR_VERSION = 4;
25
+ /**
26
+ * Always ignored: VCS internals, installed dependencies, builderforce config, and lockfiles (`yarn.lock`, `Cargo.lock` …): generated,
27
+ * huge, and plain text — extracted they would cost judgement calls for nothing; they were never stored (once skipped as binary).
28
+ * A `.builderforce/ignore` rule can still re-include one (`!yarn.lock`).
29
+ */
30
+ const DEFAULT_IGNORES = ['.git/', 'node_modules/', '.builderforce/', '.gitignore', '*.lock'];
26
31
 
27
32
  const MEDIA_TYPES: Record<string, string> = {
28
33
  md: 'text/markdown', markdown: 'text/markdown', mdx: 'text/markdown',
@@ -38,9 +43,20 @@ const MEDIA_TYPES: Record<string, string> = {
38
43
  odt: 'application/vnd.oasis.opendocument.text',
39
44
  ods: 'application/vnd.oasis.opendocument.spreadsheet',
40
45
  odp: 'application/vnd.oasis.opendocument.presentation',
46
+ // Assets (BINARY_EXT below): standard IANA types. A binary extension with none here is `application/octet-stream`.
47
+ png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', bmp: 'image/bmp',
48
+ ico: 'image/vnd.microsoft.icon', icns: 'image/icns', tif: 'image/tiff', tiff: 'image/tiff', psd: 'image/vnd.adobe.photoshop',
49
+ avif: 'image/avif', heic: 'image/heic', svg: 'image/svg+xml',
50
+ mp3: 'audio/mpeg', wav: 'audio/wav', flac: 'audio/flac', ogg: 'audio/ogg', m4a: 'audio/mp4',
51
+ mp4: 'video/mp4', mov: 'video/quicktime', avi: 'video/x-msvideo', mkv: 'video/x-matroska', webm: 'video/webm',
52
+ zip: 'application/zip', gz: 'application/gzip', tgz: 'application/gzip', bz2: 'application/x-bzip2', xz: 'application/x-xz',
53
+ '7z': 'application/x-7z-compressed', rar: 'application/vnd.rar', tar: 'application/x-tar',
54
+ jar: 'application/java-archive', war: 'application/java-archive', wasm: 'application/wasm',
55
+ ttf: 'font/ttf', otf: 'font/otf', woff: 'font/woff', woff2: 'font/woff2', eot: 'application/vnd.ms-fontobject',
56
+ sqlite: 'application/vnd.sqlite3', exe: 'application/vnd.microsoft.portable-executable', dll: 'application/vnd.microsoft.portable-executable',
41
57
  };
42
58
 
43
- /** Binary documents whose text a HOST extractor may supply (§4.5); otherwise skipped as binary. */
59
+ /** Binary documents whose text a HOST extractor may supply (§4.5); otherwise stored as an asset (never read). */
44
60
  const DOCUMENT_EXT = new Set(['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']);
45
61
 
46
62
  const BINARY_EXT = new Set([
@@ -49,26 +65,40 @@ const BINARY_EXT = new Set([
49
65
  'zip', 'gz', 'tgz', 'bz2', 'xz', '7z', 'rar', 'tar', 'jar', 'war',
50
66
  'exe', 'dll', 'so', 'dylib', 'bin', 'o', 'a', 'class', 'wasm', 'node', 'pyc',
51
67
  'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp',
52
- 'ttf', 'otf', 'woff', 'woff2', 'eot', 'sqlite', 'db', 'vsix', 'lock',
68
+ 'ttf', 'otf', 'woff', 'woff2', 'eot', 'sqlite', 'db', 'vsix',
53
69
  ]);
54
70
 
55
71
  /** Shell and batch scripts are code, never documents (their `[[ … ]]` tests are not links). */
56
72
  const SCRIPT_EXT = new Set(['sh', 'bash', 'zsh', 'ps1', 'bat', 'cmd']);
57
73
 
58
- const extOf = (path: string): string => {
74
+ export const extOf = (path: string): string => {
59
75
  const m = /\.([A-Za-z0-9]+)$/.exec(path);
60
76
  return m ? m[1]!.toLowerCase() : '';
61
77
  };
62
78
 
79
+ /** The ONE media-type lookup: the table, else `application/octet-stream` for a binary extension, else `text/plain`. */
63
80
  export function mediaTypeOfPath(path: string): string {
64
- return MEDIA_TYPES[extOf(path)] ?? 'text/plain';
81
+ const ext = extOf(path);
82
+ return MEDIA_TYPES[ext] ?? (BINARY_EXT.has(ext) ? 'application/octet-stream' : 'text/plain');
65
83
  }
66
84
 
85
+ /** Whether a cached extract is an asset's (assetFile.ts): one file node marked `badges.asset`, no text was extracted — never a hit for a file a parser now extracts. */
86
+ export const isAssetExtract = (e: Extracted): boolean => e.nodes.some((n) => n.badges?.['asset'] !== undefined);
87
+
67
88
  /** By extension — the plan never reads a file to decide. (pdf/office text needs a host extractor.) */
68
89
  export function isBinaryPath(path: string): boolean {
69
90
  return BINARY_EXT.has(extOf(path));
70
91
  }
71
92
 
93
+ /**
94
+ * The ONE decision "this listed file is an asset": binary by extension and not claimed as a document by a host parser. The plan passes
95
+ * `claimedAsDocument` false for a claimed document over the size cap (`maxFileBytes`): it stays an asset, as before host parsers existed.
96
+ * An asset is planned, hashed and diffed like any file but never read, extracted or judged (assetFile.ts writes its node).
97
+ */
98
+ export function isAssetPath(path: string, claimedAsDocument: boolean): boolean {
99
+ return isBinaryPath(path) && !claimedAsDocument;
100
+ }
101
+
72
102
  export function isDocumentPath(path: string): boolean {
73
103
  return DOCUMENT_EXT.has(extOf(path));
74
104
  }
@@ -83,6 +113,14 @@ export function resolveDocument(composed: ComposedPacks, path: string): ReturnTy
83
113
  return composed.resolve(stubSource(path));
84
114
  }
85
115
 
116
+ /**
117
+ * The document extensions (pdf/office) some composed pack's parser claims, sorted and comma-joined (`-` for none). A document is an
118
+ * asset exactly when its extension is not in this list, so this ONE string is all a root must remember about asset-ness (owedFiles.ts).
119
+ */
120
+ export function claimedDocumentExts(composed: ComposedPacks): string {
121
+ return [...DOCUMENT_EXT].filter((ext) => resolveDocument(composed, `x.${ext}`)).sort(compareStr).join(',') || '-';
122
+ }
123
+
86
124
  /** A NUL in the first 8 KB means binary, whatever the extension said. */
87
125
  export function isBinaryText(text: string): boolean {
88
126
  return text.slice(0, 8192).includes('\u0000');
@@ -8,8 +8,8 @@
8
8
  */
9
9
 
10
10
  import type { EdgeVerdict, KEdge, KNode, KnowledgeGraph, NodeRef } from './model.js';
11
- import { areaImportance, byImportance } from './importance.js';
12
- import { aboutTargets, compareStr, pathOfRef, srcRef } from './refs.js';
11
+ import { areaImportance, byImportanceAssetsLast } from './importance.js';
12
+ import { aboutTargets, compareStr, FALLBACK_PACK_ID, pathOfRef, srcRef } from './refs.js';
13
13
 
14
14
  /** Hard cap on nodes, however many the keep rules ask for. */
15
15
  export const TRUNCATION_HARD_CAP = 2000;
@@ -47,10 +47,11 @@ export function truncateGraph(g: KnowledgeGraph, opts: TruncateOptions): { nodes
47
47
  for (const s of seeds) keep(s);
48
48
  const seeded = [...kept];
49
49
  for (const s of seeded) {
50
- const around = [...(neighbours.get(s) ?? [])].map((r) => byRef.get(r)!).filter(Boolean).sort(byImportance);
50
+ // An asset beside a seed is not worth a slot (a page that references 3k icons would keep them all): it folds into its area unless it is a seed itself.
51
+ const around = [...(neighbours.get(s) ?? [])].map((r) => byRef.get(r)!).filter((n) => n && n.badges?.['asset'] === undefined).sort(byImportanceAssetsLast);
51
52
  for (const n of around) keep(n.ref);
52
53
  }
53
- for (const n of [...g.nodes].sort(byImportance).slice(0, opts.maxNodes)) keep(n.ref);
54
+ for (const n of [...g.nodes].sort(byImportanceAssetsLast).slice(0, opts.maxNodes)) keep(n.ref);
54
55
 
55
56
  // Fold the rest into areas.
56
57
  const aboutTarget = aboutTargets(g.edges);
@@ -76,7 +77,7 @@ export function truncateGraph(g: KnowledgeGraph, opts: TruncateOptions): { nodes
76
77
  const ms = members.get(area)!;
77
78
  const partition = mostCommon(ms.map((n) => n.partition));
78
79
  return {
79
- ref: area, kind: 'area', label: pathOfRef(area) ?? area, pack: mostCommon(ms.map((n) => n.pack)) ?? 'memory',
80
+ ref: area, kind: 'area', label: pathOfRef(area) ?? area, pack: mostCommon(ms.map((n) => n.pack)) ?? FALLBACK_PACK_ID,
80
81
  ...(partition !== undefined ? { partition } : {}),
81
82
  importance: imp.get(area) ?? 0, origin: 'extracted' as const,
82
83
  badges: { members: ms.length },