@seanhogg/builderforce-memory 2026.10.58 → 2026.10.60

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 (104) 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 +25 -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.map +1 -1
  20. package/dist/knowledge/extractFile.js +4 -3
  21. package/dist/knowledge/extractFile.js.map +1 -1
  22. package/dist/knowledge/findings.js +4 -4
  23. package/dist/knowledge/findings.js.map +1 -1
  24. package/dist/knowledge/importance.d.ts +5 -0
  25. package/dist/knowledge/importance.d.ts.map +1 -1
  26. package/dist/knowledge/importance.js +7 -0
  27. package/dist/knowledge/importance.js.map +1 -1
  28. package/dist/knowledge/index.d.ts +3 -3
  29. package/dist/knowledge/index.d.ts.map +1 -1
  30. package/dist/knowledge/index.js +2 -2
  31. package/dist/knowledge/index.js.map +1 -1
  32. package/dist/knowledge/model.d.ts +11 -3
  33. package/dist/knowledge/model.d.ts.map +1 -1
  34. package/dist/knowledge/outline.d.ts.map +1 -1
  35. package/dist/knowledge/outline.js +4 -2
  36. package/dist/knowledge/outline.js.map +1 -1
  37. package/dist/knowledge/owedFiles.d.ts +26 -4
  38. package/dist/knowledge/owedFiles.d.ts.map +1 -1
  39. package/dist/knowledge/owedFiles.js +58 -8
  40. package/dist/knowledge/owedFiles.js.map +1 -1
  41. package/dist/knowledge/plan.d.ts +8 -2
  42. package/dist/knowledge/plan.d.ts.map +1 -1
  43. package/dist/knowledge/plan.js +17 -9
  44. package/dist/knowledge/plan.js.map +1 -1
  45. package/dist/knowledge/refs.d.ts +2 -0
  46. package/dist/knowledge/refs.d.ts.map +1 -1
  47. package/dist/knowledge/refs.js +2 -0
  48. package/dist/knowledge/refs.js.map +1 -1
  49. package/dist/knowledge/resolve.d.ts.map +1 -1
  50. package/dist/knowledge/resolve.js +2 -2
  51. package/dist/knowledge/resolve.js.map +1 -1
  52. package/dist/knowledge/review.d.ts +2 -1
  53. package/dist/knowledge/review.d.ts.map +1 -1
  54. package/dist/knowledge/review.js +44 -10
  55. package/dist/knowledge/review.js.map +1 -1
  56. package/dist/knowledge/reviewModel.d.ts +7 -1
  57. package/dist/knowledge/reviewModel.d.ts.map +1 -1
  58. package/dist/knowledge/reviewPrefetch.d.ts +10 -2
  59. package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
  60. package/dist/knowledge/reviewPrefetch.js +4 -0
  61. package/dist/knowledge/reviewPrefetch.js.map +1 -1
  62. package/dist/knowledge/reviewRun.js +1 -1
  63. package/dist/knowledge/reviewRun.js.map +1 -1
  64. package/dist/knowledge/reviewRunModel.d.ts +2 -2
  65. package/dist/knowledge/reviewRunModel.d.ts.map +1 -1
  66. package/dist/knowledge/sources.d.ts +16 -2
  67. package/dist/knowledge/sources.d.ts.map +1 -1
  68. package/dist/knowledge/sources.js +40 -7
  69. package/dist/knowledge/sources.js.map +1 -1
  70. package/dist/knowledge/truncate.d.ts.map +1 -1
  71. package/dist/knowledge/truncate.js +6 -5
  72. package/dist/knowledge/truncate.js.map +1 -1
  73. package/package.json +3 -3
  74. package/src/contract/exports.snapshot.json +2 -0
  75. package/src/contract/regression.assets.test.ts +206 -0
  76. package/src/contract/regression.recheck.test.ts +5 -5
  77. package/src/contract/regression.review.test.ts +184 -5
  78. package/src/contract/types.contract.test.ts +2 -2
  79. package/src/ingest/docsExtract.ts +9 -4
  80. package/src/ingest/parserSupport.ts +3 -3
  81. package/src/knowledge/assetFile.ts +34 -0
  82. package/src/knowledge/backfillNoExtract.ts +29 -35
  83. package/src/knowledge/build.ts +10 -5
  84. package/src/knowledge/docs.test.ts +5 -2
  85. package/src/knowledge/extractFile.ts +4 -3
  86. package/src/knowledge/findings.ts +4 -4
  87. package/src/knowledge/importance.ts +8 -0
  88. package/src/knowledge/index.ts +3 -3
  89. package/src/knowledge/model.ts +8 -3
  90. package/src/knowledge/outline.ts +4 -2
  91. package/src/knowledge/owedFiles.ts +59 -7
  92. package/src/knowledge/plan.ts +25 -9
  93. package/src/knowledge/refs.ts +3 -0
  94. package/src/knowledge/resolve.ts +2 -2
  95. package/src/knowledge/review.fixes.test.ts +3 -2
  96. package/src/knowledge/review.gaps.test.ts +5 -3
  97. package/src/knowledge/review.test.ts +4 -2
  98. package/src/knowledge/review.ts +38 -13
  99. package/src/knowledge/reviewModel.ts +7 -1
  100. package/src/knowledge/reviewPrefetch.ts +10 -2
  101. package/src/knowledge/reviewRun.ts +1 -1
  102. package/src/knowledge/reviewRunModel.ts +2 -2
  103. package/src/knowledge/sources.ts +44 -8
  104. package/src/knowledge/truncate.ts +6 -5
@@ -4,7 +4,8 @@
4
4
  *
5
5
  * plan (walk + manifest diff) → per changed file: read · parse (the ONE ParserRegistry,
6
6
  * composed from the packs) · extract (cached by content hash) · judge (changed sections
7
- * of judged kinds, within budget) · write · markStale → analyzers → compare near-duplicate
7
+ * of judged kinds, within budget) · write · markStale → retire · analyse (analyzers, own `analyse`
8
+ * progress phase) → compare near-duplicate
8
9
  * claims → manifest + scope digest. Claims whose compare pairs were skipped wait in the
9
10
  * compare manifest for *Continue*.
10
11
  * Read + extract are prefetched with bounded concurrency (`args.concurrency`; through `args.extractPool`
@@ -27,7 +28,7 @@
27
28
  */
28
29
 
29
30
  import { sha256Hex } from '../retrieval/knowledge-index/sha256.js';
30
- import type { ReviewArgs, ReviewReport, ScopeRecord, StoredFact, StoredRelation } from './model.js';
31
+ import type { AnalyzerProgress, ReviewArgs, ReviewReport, ScopeRecord, StoredFact, StoredRelation } from './model.js';
31
32
  import { owedAfterRun, owedCalls, saveExtractorState } from './owedFiles.js';
32
33
  import { planDetail, refreshPlan } from './plan.js';
33
34
  import { composePacks, filesManifestKey, judgedManifestKey, manifestMap, saveManifestMap } from './sources.js';
@@ -42,7 +43,8 @@ import {
42
43
  import { createModelLimiter } from './modelLimiter.js';
43
44
  import { JudgeBreaker } from './judgeCalls.js';
44
45
  import { applyJudge, judgesPack, splitSections, startJudge, type JudgeJob } from './reviewJudge.js';
45
- import { createPrefetch, type Prefetch } from './reviewPrefetch.js';
46
+ import { createPrefetch, type Prefetch, type PrefetchFile } from './reviewPrefetch.js';
47
+ import { putAsset } from './assetFile.js';
46
48
  import { Lanes } from './reviewRunModel.js';
47
49
  import { compareNew, pendingClaims, saveAwaiting } from './reviewCompare.js';
48
50
  import { factsWithoutAnchor, StoredIndex } from './reviewStored.js';
@@ -66,7 +68,7 @@ function readAheadOf(args: ReviewArgs, concurrency: number): number {
66
68
 
67
69
  /** One changed file between dispatch and the ordered writer: what its prefetch found and its judging in flight. */
68
70
  interface Slot {
69
- f: { path: string; hash: string };
71
+ f: PrefetchFile;
70
72
  i: number;
71
73
  job: Prefetch;
72
74
  judge: JudgeJob | undefined;
@@ -120,13 +122,13 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
120
122
  const judgedPrior = await manifestMap(manifest, judgedManifestKey(rootId));
121
123
  const judgedNow = new Map(judgedPrior);
122
124
  const filesNow = new Map(detail.prior);
123
- // 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).
124
126
  const asked = (await store.recheckHashes?.()) ?? [];
125
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.
126
128
  const preChanged = detail.files.filter((f) => f.changed && (!args.only || args.only.includes(f.path)));
127
129
  const preload = [...new Set([...preChanged.map((f) => f.hash), ...backfillCandidates(detail, asked)])];
128
130
  if (preload.length > 0) await store.preloadExtracted?.(preload);
129
- await backfillNoExtract({ store, source, detail, asked, only: args.only, signal });
131
+ await backfillNoExtract({ store, detail, asked, only: args.only, signal });
130
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.
131
133
  const askedSet = new Set(asked);
132
134
  const settledRecheck = async (hash: string): Promise<void> => { if (askedSet.has(hash)) await store.clearRecheck?.([hash]); };
@@ -222,11 +224,13 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
222
224
  return true;
223
225
  }
224
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.
225
229
  // Recorded, so a file found binary on read is not re-read by every later review.
226
- if (job.kind === 'binary') {
230
+ if (job.kind === 'binary' || job.kind === 'asset') {
227
231
  filesNow.set(f.path, f.hash);
228
232
  finished.add(f.path);
229
- 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);
230
234
  await settledRecheck(f.hash);
231
235
  await store.markStale(scope, srcRef(rootId, f.path), f.hash);
232
236
  report.staleMarked += 1;
@@ -317,22 +321,43 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
317
321
 
318
322
  // Pass 2 (`only`) is judging alone: the map pass already retired the removed files and ran the analyzers.
319
323
  if (!report.aborted && !args.only) {
324
+ // The last file is written: leave "write" now, the analyzers below can take minutes.
325
+ // Opened as 0/1 (not 0/0, which would close the row at once) so the row stays active until the final event below.
326
+ progress({ phase: 'analyse', done: 0, total: 1 });
320
327
  await retire(detail.plan.removed);
321
328
  // Analyzers run in parallel and a failing one never aborts the review — its extracted
322
329
  // output is simply not stored (the file-level facts above are already durable), so a
323
- // single bad pack cannot sink the whole run.
330
+ // single bad pack cannot sink the whole run. Each pack's latest count is kept and summed; only `done` is
331
+ // monotonic (a total may grow as a pack discovers more work). A callback after its pack settled is dropped.
332
+ const latest = new Map<number, AnalyzerProgress>();
333
+ const sum = () => {
334
+ let done = 0; let total = 0;
335
+ for (const v of latest.values()) { done += v.done; total += v.total; }
336
+ return { done, total: Math.max(1, total) };
337
+ };
324
338
  const analysed = await Promise.all(
325
- packs.filter((p) => p.analyzers).map(async (p) => {
326
- try { return await p.analyzers!.analyse(rootId, signal); } catch { return []; }
339
+ packs.filter((p) => p.analyzers).map(async (p, k) => {
340
+ let settled = false;
341
+ const onProgress = (a: AnalyzerProgress) => {
342
+ if (settled) return;
343
+ latest.set(k, { done: a.done, total: a.total });
344
+ progress({ phase: 'analyse', ...sum(), ...(a.path !== undefined ? { path: a.path } : {}) });
345
+ };
346
+ try { return await p.analyzers!.analyse(rootId, signal, onProgress); } catch { return []; } finally { settled = true; }
327
347
  }),
328
348
  );
349
+ // Close the row whatever the analyzers reported (none, short, or a throw).
350
+ const closing = Math.max(1, sum().total);
351
+ progress({ phase: 'analyse', done: closing, total: closing });
352
+ // A Stop during the analyzers ends the run like one during the write loop (`runSignal` no longer follows `signal` here).
353
+ report.aborted ||= runSignal.aborted || !!signal?.aborted;
329
354
  for (const packResults of analysed) {
330
355
  for (const ex of packResults) {
331
356
  await store.putExtracted?.(ex.sourceHash, [ex]);
332
357
  report.extracted += 1;
333
358
  }
334
359
  }
335
- progress({ phase: 'resolve', done: 0, total: newClaims.size });
360
+ if (!report.aborted) progress({ phase: 'resolve', done: 0, total: newClaims.size });
336
361
  }
337
362
 
338
363
  // The compare phase needs a pack asking for it AND both ports.
@@ -373,7 +398,7 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
373
398
  // content-changed or not, and the owed paths the plan did not list that the manifest still holds.
374
399
  await saveExtractorState(manifest, rootId, owedAfterRun({
375
400
  state: detail.extractor, changed, prior: detail.prior, finished, carried: detail.carried, live: filesNow, measured, unreadable,
376
- }), failures);
401
+ }), failures, detail.extractor.documentsNow);
377
402
  await write(report.aborted ? scopeRecord : { ...scopeRecord, lastDigest: report.digest, lastReviewedAt: new Date(now()).toISOString() });
378
403
  report.durationMs = now() - started;
379
404
  progress({ phase: 'done', done: work.length, total: work.length });
@@ -30,10 +30,16 @@ export interface ReviewPlan {
30
30
  rootId: string;
31
31
  files: number;
32
32
  byPack: Record<string, number>;
33
+ /**
34
+ * Files in `files` that are assets (binary, never read): stored as a file node with `mediaType` and `size`, not counted in `byPack`.
35
+ * `files` includes them (the plan diffs them like any file), so a host's ETA and "files to read" figures subtract `assets`
36
+ * (absent on a plan from an older host or built by hand: read it as 0).
37
+ */
38
+ assets?: number;
33
39
  unchanged: number;
34
40
  changed: string[];
35
41
  removed: string[];
36
- skipped: Array<{ path: string; reason: 'ignored' | 'binary' | 'too-large' | 'no-pack' }>;
42
+ skipped: Array<{ path: string; reason: 'ignored' | 'too-large' | 'no-pack' }>;
37
43
  /** ≈ judgement calls for changed files (sections of judged kinds). */
38
44
  estimatedModelCalls: number;
39
45
  /** 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,7 +67,10 @@ 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);
@@ -76,9 +82,11 @@ export function createPrefetch(c: PrefetchContext): (f: { path: string; hash: st
76
82
  const wantsSections = (pack: KnowledgePack) => !c.args.mechanical && judgesPack(c.args.judgement, pack);
77
83
  const byPool = !!c.args.extractPool && !!c.args.deferRead;
78
84
 
79
- const run = async (f: { path: string; hash: string }, parts: NonNullable<ReviewStep['parts']>, held: { lane: number }): Promise<Outcome> => {
85
+ const run = async (f: PrefetchFile, parts: NonNullable<ReviewStep['parts']>, held: { lane: number }): Promise<Outcome> => {
80
86
  // 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
87
  if (c.signal.aborted) return { kind: 'failed', reason: reasonOf(c.signal.reason), transient: true };
88
+ // The plan decided it (isAssetPath): no read, no extract slot.
89
+ if (f.asset) return { kind: 'asset' };
82
90
  let doc: SourceDocument | undefined;
83
91
  const t0 = Date.now();
84
92
  if (!byPool) {
@@ -82,7 +82,7 @@ function withProgress(phases: ReviewRunPhase[], p: ReviewProgress, at: number):
82
82
  return phases.map((x, j) => (j === i ? next : x));
83
83
  }
84
84
 
85
- const PHASE_ORDER: readonly ReviewPhase[] = ['plan', 'extract', 'resolve', 'judge', 'compare', 'write', 'index', 'mapped', 'done'];
85
+ const PHASE_ORDER: readonly ReviewPhase[] = ['plan', 'extract', 'resolve', 'judge', 'compare', 'write', 'analyse', 'index', 'mapped', 'done'];
86
86
 
87
87
  /** Lanes are keyed by phase and id: extract workers and judge lanes are different workers. */
88
88
  function withLane(lanes: ReviewRunLane[], step: ReviewStep): ReviewRunLane[] {
@@ -4,13 +4,13 @@
4
4
  */
5
5
 
6
6
  /** `mapped` (PRD 41 A10): the mechanical pass is over and the map is complete; judging, if any is owed, follows. */
7
- export type ReviewPhase = 'plan' | 'extract' | 'resolve' | 'judge' | 'compare' | 'write' | 'index' | 'mapped' | 'done';
7
+ export type ReviewPhase = 'plan' | 'extract' | 'resolve' | 'judge' | 'compare' | 'write' | 'analyse' | 'index' | 'mapped' | 'done';
8
8
 
9
9
  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,7 +7,7 @@
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
 
@@ -20,9 +20,13 @@ export const DEFAULT_MAX_FILE_BYTES = 2 * 1024 * 1024;
20
20
  * re-extraction (judged sections with unchanged text are re-anchored, not judged again; see
21
21
  * owedFiles.ts for how an unfinished one is carried to the next review).
22
22
  */
23
- export const EXTRACTOR_VERSION = 3;
24
- /** Always ignored: VCS internals, installed dependencies, builderforce config. */
25
- const DEFAULT_IGNORES = ['.git/', 'node_modules/', '.builderforce/', '.gitignore'];
23
+ export const EXTRACTOR_VERSION = 4;
24
+ /**
25
+ * Always ignored: VCS internals, installed dependencies, builderforce config, and lockfiles (`yarn.lock`, `Cargo.lock` …): generated,
26
+ * huge, and plain text — extracted they would cost judgement calls for nothing; they were never stored (once skipped as binary).
27
+ * A `.builderforce/ignore` rule can still re-include one (`!yarn.lock`).
28
+ */
29
+ const DEFAULT_IGNORES = ['.git/', 'node_modules/', '.builderforce/', '.gitignore', '*.lock'];
26
30
 
27
31
  const MEDIA_TYPES: Record<string, string> = {
28
32
  md: 'text/markdown', markdown: 'text/markdown', mdx: 'text/markdown',
@@ -38,9 +42,20 @@ const MEDIA_TYPES: Record<string, string> = {
38
42
  odt: 'application/vnd.oasis.opendocument.text',
39
43
  ods: 'application/vnd.oasis.opendocument.spreadsheet',
40
44
  odp: 'application/vnd.oasis.opendocument.presentation',
45
+ // Assets (BINARY_EXT below): standard IANA types. A binary extension with none here is `application/octet-stream`.
46
+ png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', bmp: 'image/bmp',
47
+ ico: 'image/vnd.microsoft.icon', icns: 'image/icns', tif: 'image/tiff', tiff: 'image/tiff', psd: 'image/vnd.adobe.photoshop',
48
+ avif: 'image/avif', heic: 'image/heic', svg: 'image/svg+xml',
49
+ mp3: 'audio/mpeg', wav: 'audio/wav', flac: 'audio/flac', ogg: 'audio/ogg', m4a: 'audio/mp4',
50
+ mp4: 'video/mp4', mov: 'video/quicktime', avi: 'video/x-msvideo', mkv: 'video/x-matroska', webm: 'video/webm',
51
+ zip: 'application/zip', gz: 'application/gzip', tgz: 'application/gzip', bz2: 'application/x-bzip2', xz: 'application/x-xz',
52
+ '7z': 'application/x-7z-compressed', rar: 'application/vnd.rar', tar: 'application/x-tar',
53
+ jar: 'application/java-archive', war: 'application/java-archive', wasm: 'application/wasm',
54
+ ttf: 'font/ttf', otf: 'font/otf', woff: 'font/woff', woff2: 'font/woff2', eot: 'application/vnd.ms-fontobject',
55
+ sqlite: 'application/vnd.sqlite3', exe: 'application/vnd.microsoft.portable-executable', dll: 'application/vnd.microsoft.portable-executable',
41
56
  };
42
57
 
43
- /** Binary documents whose text a HOST extractor may supply (§4.5); otherwise skipped as binary. */
58
+ /** Binary documents whose text a HOST extractor may supply (§4.5); otherwise stored as an asset (never read). */
44
59
  const DOCUMENT_EXT = new Set(['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']);
45
60
 
46
61
  const BINARY_EXT = new Set([
@@ -49,26 +64,39 @@ const BINARY_EXT = new Set([
49
64
  'zip', 'gz', 'tgz', 'bz2', 'xz', '7z', 'rar', 'tar', 'jar', 'war',
50
65
  'exe', 'dll', 'so', 'dylib', 'bin', 'o', 'a', 'class', 'wasm', 'node', 'pyc',
51
66
  'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp',
52
- 'ttf', 'otf', 'woff', 'woff2', 'eot', 'sqlite', 'db', 'vsix', 'lock',
67
+ 'ttf', 'otf', 'woff', 'woff2', 'eot', 'sqlite', 'db', 'vsix',
53
68
  ]);
54
69
 
55
70
  /** Shell and batch scripts are code, never documents (their `[[ … ]]` tests are not links). */
56
71
  const SCRIPT_EXT = new Set(['sh', 'bash', 'zsh', 'ps1', 'bat', 'cmd']);
57
72
 
58
- const extOf = (path: string): string => {
73
+ export const extOf = (path: string): string => {
59
74
  const m = /\.([A-Za-z0-9]+)$/.exec(path);
60
75
  return m ? m[1]!.toLowerCase() : '';
61
76
  };
62
77
 
78
+ /** The ONE media-type lookup: the table, else `application/octet-stream` for a binary extension, else `text/plain`. */
63
79
  export function mediaTypeOfPath(path: string): string {
64
- return MEDIA_TYPES[extOf(path)] ?? 'text/plain';
80
+ const ext = extOf(path);
81
+ return MEDIA_TYPES[ext] ?? (BINARY_EXT.has(ext) ? 'application/octet-stream' : 'text/plain');
65
82
  }
66
83
 
84
+ /** 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. */
85
+ export const isAssetExtract = (e: Extracted): boolean => e.nodes.some((n) => n.badges?.['asset'] !== undefined);
86
+
67
87
  /** By extension — the plan never reads a file to decide. (pdf/office text needs a host extractor.) */
68
88
  export function isBinaryPath(path: string): boolean {
69
89
  return BINARY_EXT.has(extOf(path));
70
90
  }
71
91
 
92
+ /**
93
+ * The ONE decision "this listed file is an asset": binary by extension and not claimed as a document by a host parser.
94
+ * An asset is planned, hashed and diffed like any file but never read, extracted or judged (assetFile.ts writes its node).
95
+ */
96
+ export function isAssetPath(path: string, claimedAsDocument: boolean): boolean {
97
+ return isBinaryPath(path) && !claimedAsDocument;
98
+ }
99
+
72
100
  export function isDocumentPath(path: string): boolean {
73
101
  return DOCUMENT_EXT.has(extOf(path));
74
102
  }
@@ -83,6 +111,14 @@ export function resolveDocument(composed: ComposedPacks, path: string): ReturnTy
83
111
  return composed.resolve(stubSource(path));
84
112
  }
85
113
 
114
+ /**
115
+ * The document extensions (pdf/office) some composed pack's parser claims, sorted and comma-joined (`-` for none). A document is an
116
+ * 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).
117
+ */
118
+ export function claimedDocumentExts(composed: ComposedPacks): string {
119
+ return [...DOCUMENT_EXT].filter((ext) => resolveDocument(composed, `x.${ext}`)).sort(compareStr).join(',') || '-';
120
+ }
121
+
86
122
  /** A NUL in the first 8 KB means binary, whatever the extension said. */
87
123
  export function isBinaryText(text: string): boolean {
88
124
  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 },