@seanhogg/builderforce-memory 2026.10.59 → 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 (99) 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 +2 -2
  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 +3 -1
  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.map +1 -1
  53. package/dist/knowledge/review.js +8 -5
  54. package/dist/knowledge/review.js.map +1 -1
  55. package/dist/knowledge/reviewModel.d.ts +7 -1
  56. package/dist/knowledge/reviewModel.d.ts.map +1 -1
  57. package/dist/knowledge/reviewPrefetch.d.ts +10 -2
  58. package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
  59. package/dist/knowledge/reviewPrefetch.js +4 -0
  60. package/dist/knowledge/reviewPrefetch.js.map +1 -1
  61. package/dist/knowledge/reviewRunModel.d.ts +1 -1
  62. package/dist/knowledge/sources.d.ts +16 -2
  63. package/dist/knowledge/sources.d.ts.map +1 -1
  64. package/dist/knowledge/sources.js +40 -7
  65. package/dist/knowledge/sources.js.map +1 -1
  66. package/dist/knowledge/truncate.d.ts.map +1 -1
  67. package/dist/knowledge/truncate.js +6 -5
  68. package/dist/knowledge/truncate.js.map +1 -1
  69. package/package.json +3 -3
  70. package/src/contract/exports.snapshot.json +2 -0
  71. package/src/contract/regression.assets.test.ts +206 -0
  72. package/src/contract/regression.recheck.test.ts +5 -5
  73. package/src/contract/regression.review.test.ts +129 -5
  74. package/src/contract/types.contract.test.ts +1 -1
  75. package/src/ingest/docsExtract.ts +9 -4
  76. package/src/ingest/parserSupport.ts +3 -3
  77. package/src/knowledge/assetFile.ts +34 -0
  78. package/src/knowledge/backfillNoExtract.ts +29 -35
  79. package/src/knowledge/build.ts +10 -5
  80. package/src/knowledge/docs.test.ts +5 -2
  81. package/src/knowledge/extractFile.ts +4 -3
  82. package/src/knowledge/findings.ts +4 -4
  83. package/src/knowledge/importance.ts +8 -0
  84. package/src/knowledge/index.ts +2 -2
  85. package/src/knowledge/model.ts +3 -1
  86. package/src/knowledge/outline.ts +4 -2
  87. package/src/knowledge/owedFiles.ts +59 -7
  88. package/src/knowledge/plan.ts +25 -9
  89. package/src/knowledge/refs.ts +3 -0
  90. package/src/knowledge/resolve.ts +2 -2
  91. package/src/knowledge/review.fixes.test.ts +3 -2
  92. package/src/knowledge/review.gaps.test.ts +5 -3
  93. package/src/knowledge/review.test.ts +4 -2
  94. package/src/knowledge/review.ts +10 -7
  95. package/src/knowledge/reviewModel.ts +7 -1
  96. package/src/knowledge/reviewPrefetch.ts +10 -2
  97. package/src/knowledge/reviewRunModel.ts +1 -1
  98. package/src/knowledge/sources.ts +44 -8
  99. package/src/knowledge/truncate.ts +6 -5
@@ -26,7 +26,7 @@ describe('regression: a root reviewed before binary files were recorded is settl
26
26
  expect(source.reads).not.toContain('img.png');
27
27
  });
28
28
 
29
- it('regression: the review reads ONLY the files a replica asked to re-check: a NUL-binary gets [], a text file is extracted, the set is cleared', async () => {
29
+ it('regression: the review reads ONLY the files a replica asked to re-check: a NUL-binary gets its asset node, a text file is extracted, the set is cleared', async () => {
30
30
  const binary = 'bin\u0000ary';
31
31
  const files = { 'blob.txt': binary, 'a.md': text, 'b.md': '# B\nbeta\n' };
32
32
  const manifest = new InMemoryIngestManifest();
@@ -37,7 +37,7 @@ describe('regression: a root reviewed before binary files were recorded is settl
37
37
  const source = memSource(files);
38
38
  await reviewDirectory(args(source, legacy, manifest));
39
39
  expect(new Set(source.reads)).toEqual(new Set(['blob.txt', 'a.md'])); // b.md was never named
40
- expect(await legacy.getExtracted(hashText(binary))).toEqual([]);
40
+ expect((await legacy.getExtracted(hashText(binary)))![0]!.nodes[0]!.badges).toMatchObject({ asset: 1, size: binary.length });
41
41
  expect((await legacy.getExtracted(hashText(text)))!.length).toBeGreaterThan(0);
42
42
  expect(await legacy.getExtracted(hashText(files['b.md']))).toBeUndefined();
43
43
  expect(await legacy.recheckHashes()).toEqual([]);
@@ -86,12 +86,12 @@ describe('regression: a root reviewed before binary files were recorded is settl
86
86
  return legacy;
87
87
  };
88
88
 
89
- it('regression: a review stopped mid-way (after the backfill queued the file) keeps the re-check request and records no terminal [], and a complete one clears it', async () => {
89
+ it('regression: a review stopped mid-way (on the read of the file the backfill queued) keeps the re-check request and records no terminal [], and a complete one clears it', async () => {
90
90
  const manifest = new InMemoryIngestManifest();
91
91
  const legacy = await legacyStore(manifest);
92
92
  const stop = new AbortController();
93
- // Read 1 is the backfill's, read 2 is the review's: the run is stopped there and the read rejects.
94
- const source = watched((n) => { if (n === 2) { stop.abort(); throw new Error('aborted'); } });
93
+ // The backfill only queues the file (it reads nothing); read 1 is the review's: the run is stopped there and the read rejects.
94
+ const source = watched((n) => { if (n === 1) { stop.abort(); throw new Error('aborted'); } });
95
95
  await reviewDirectory(args(source, legacy, manifest, { signal: stop.signal })).catch(() => undefined);
96
96
  expect(await legacy.recheckHashes()).toEqual([hashText(text)]);
97
97
  expect(await legacy.getExtracted(hashText(text))).toBeUndefined();
@@ -5,20 +5,21 @@
5
5
  */
6
6
 
7
7
  import { hashText } from '../ingest/hash.js';
8
+ import { buildGraph } from '../knowledge/build.js';
8
9
  import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
9
10
  import type { ReviewProgress } from '../knowledge/model.js';
10
11
  import type { ReviewStep } from '../knowledge/reviewRunModel.js';
11
12
  import { extractJob, type ExtractJob, type ExtractPool } from '../knowledge/extractJob.js';
12
- import type { JudgementRequest, KnowledgePack, KnowledgeStore } from '../knowledge/model.js';
13
+ import type { JudgementRequest, KnowledgePack, KnowledgeParser, KnowledgeStore } from '../knowledge/model.js';
13
14
  import { DOCS_PACK } from '../knowledge/packs/docs.js';
14
15
  import { putNoExtract } from '../knowledge/extractFile.js';
15
16
  import { planReview } from '../knowledge/plan.js';
16
17
  import { srcRef } from '../knowledge/refs.js';
17
18
  import { reviewDirectory } from '../knowledge/review.js';
18
19
  import { applyRunEvent, failuresOf, failureTotal, REVIEW_RUN_FAILURE_CHUNK, startRun } from '../knowledge/reviewRun.js';
19
- import { extractorManifestKey, filesManifestKey, judgedManifestKey, manifestMap } from '../knowledge/sources.js';
20
+ import { extractorManifestKey, filesManifestKey, judgedManifestKey, manifestMap, mediaTypeOfPath } from '../knowledge/sources.js';
20
21
  import {
21
- ALL, args, fakeJudge, FILES, memSource, memStore, quietPack, ROOT, stateOf, type SpySource,
22
+ ALL, args, fakeJudge, FILES, graphOf, memSource, memStore, quietPack, ROOT, stateOf, type SpySource,
22
23
  } from '../knowledge/testkit.test-util.js';
23
24
 
24
25
  const sixFiles = () => Object.fromEntries(Array.from({ length: 6 }, (_, i) => [`d${i}.md`, `# T${i}\nbody ${i}\n`]));
@@ -292,11 +293,13 @@ describe('regression: changed since plan', () => {
292
293
  });
293
294
 
294
295
  describe('regression: a file with nothing to extract is told apart from one not extracted yet', () => {
295
- it('regression: a file found binary on read has an explicit stored [] (and a stale mark), never an absent body', async () => {
296
+ it('regression: a file found binary on read has a stored asset node (and a stale mark), never an absent body', async () => {
296
297
  const text = 'bin\u0000ary';
297
298
  const store = memStore();
298
299
  await reviewDirectory(args(memSource({ 'blob.txt': text }), store, new InMemoryIngestManifest()));
299
- expect(await store.getExtracted(hashText(text))).toEqual([]);
300
+ const stored = await store.getExtracted(hashText(text));
301
+ expect(stored).toHaveLength(1);
302
+ expect(stored![0]!.nodes).toMatchObject([{ kind: 'file', badges: { asset: 1, mediaType: 'text/plain', size: text.length } }]);
300
303
  });
301
304
 
302
305
  it('regression: a text file that is not extracted (here: its review failed) has NO stored body, so it is never mistaken for binary', async () => {
@@ -317,3 +320,124 @@ describe('regression: a file with nothing to extract is told apart from one not
317
320
  expect(await store.getExtracted(hashText(text))).toEqual(before);
318
321
  });
319
322
  });
323
+
324
+ describe('regression: a binary file is an asset with a node, not a skipped file', () => {
325
+ const PNG = 'PNGDATA';
326
+
327
+ it('regression: a .png in a reviewed directory has a file node with mediaType, size and asset, is never read, and is not in plan.skipped', async () => {
328
+ const source = memSource({ 'a.md': '# A\nalpha\n', 'icons/icon128.png': PNG });
329
+ const store = memStore();
330
+ const manifest = new InMemoryIngestManifest();
331
+ const plan = await planReview(source, manifest, [DOCS_PACK]);
332
+ expect(plan.skipped.map((s) => s.path)).not.toContain('icons/icon128.png');
333
+ expect(plan).toMatchObject({ files: 2, assets: 1, byPack: { docs: 1 }, changed: ['a.md', 'icons/icon128.png'] });
334
+
335
+ const report = await reviewDirectory(args(source, store, manifest));
336
+ expect(report.failures).toEqual([]);
337
+ expect(source.reads).not.toContain('icons/icon128.png');
338
+ const stored = await store.getExtracted(hashText(PNG));
339
+ expect(stored).toHaveLength(1);
340
+ expect(stored![0]!.nodes).toEqual([expect.objectContaining({
341
+ ref: srcRef(ROOT, 'icons/icon128.png'), kind: 'file', label: 'icon128.png',
342
+ badges: { asset: 1, mediaType: 'image/png', size: PNG.length },
343
+ })]);
344
+ expect((await manifestMap(manifest, filesManifestKey(ROOT))).get('icons/icon128.png')).toBe(hashText(PNG));
345
+
346
+ // Diffed like any file: unchanged is not reviewed again, a new byte string is.
347
+ expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual([]);
348
+ source.files['icons/icon128.png'] = 'OTHER';
349
+ expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual(['icons/icon128.png']);
350
+ });
351
+
352
+ it('regression: an asset over maxFileBytes is still an asset, and costs no model call', async () => {
353
+ const plan = await planReview(memSource({ 'big.zip': 'x'.repeat(50) }), new InMemoryIngestManifest(), [DOCS_PACK], { maxFileBytes: 10 });
354
+ expect(plan).toMatchObject({ files: 1, assets: 1, skipped: [], estimatedModelCalls: 0 });
355
+ });
356
+
357
+ it('regression: mediaTypeOfPath knows the image, font and archive types; an unknown binary extension is octet-stream; text stays text/plain', () => {
358
+ expect(mediaTypeOfPath('x.png')).toBe('image/png');
359
+ expect(mediaTypeOfPath('a/b/favicon.ICO')).toBe('image/vnd.microsoft.icon');
360
+ expect(mediaTypeOfPath('f.woff2')).toBe('font/woff2');
361
+ expect(mediaTypeOfPath('a.zip')).toBe('application/zip');
362
+ expect(mediaTypeOfPath('lib.so')).toBe('application/octet-stream');
363
+ expect(mediaTypeOfPath('notes.txt')).toBe('text/plain');
364
+ expect(mediaTypeOfPath('Makefile')).toBe('text/plain');
365
+ });
366
+
367
+ it('regression: a document linking to an asset path has a links edge to the asset node, not to a missing placeholder', async () => {
368
+ // The docs pack resolves written links; a host code pack resolves its path references through the same `ctx.resolvePath` and srcRef.
369
+ const source = memSource({ 'README.md': '# R\nSee [the logo](icons/icon128.png).\n', 'icons/icon128.png': PNG, 'other.md': '# O\n[gone](icons/gone.png)\n' });
370
+ const store = memStore();
371
+ await reviewDirectory(args(source, store, new InMemoryIngestManifest()));
372
+ const g = await graphOf(source, store);
373
+ const asset = g.nodes.find((n) => n.ref === srcRef(ROOT, 'icons/icon128.png'));
374
+ expect(asset).toMatchObject({ kind: 'file', badges: { asset: 1, mediaType: 'image/png' } });
375
+ const into = g.edges.filter((e) => e.kind === 'links' && e.to === asset!.ref);
376
+ expect(into).toHaveLength(1);
377
+ expect(into[0]!.from.startsWith(srcRef(ROOT, 'README.md'))).toBe(true); // from the file or the section holding the link
378
+ expect(g.nodes.find((n) => n.ref === srcRef(ROOT, 'icons/gone.png'))?.kind).toBe('missing'); // a truly absent target still is
379
+ });
380
+
381
+ it('regression: a markdown image ![alt](path) references its target like a link, so it lands on the asset node', async () => {
382
+ const source = memSource({ 'README.md': '# R\n![logo](icons/icon128.png) and ![ref][shot]\n\n[shot]: shots/s.png\n', 'icons/icon128.png': PNG, 'shots/s.png': 'SHOT' });
383
+ const store = memStore();
384
+ await reviewDirectory(args(source, store, new InMemoryIngestManifest()));
385
+ const g = await graphOf(source, store);
386
+ for (const p of ['icons/icon128.png', 'shots/s.png']) {
387
+ const to = srcRef(ROOT, p);
388
+ expect(g.nodes.find((n) => n.ref === to)).toMatchObject({ kind: 'file', badges: { asset: 1 } });
389
+ expect(g.edges.filter((e) => e.kind === 'links' && e.to === to)).toHaveLength(1);
390
+ }
391
+ });
392
+
393
+ it('regression: an outlined, truncated graph keeps the asset badges (asset, mediaType, size) of its files', async () => {
394
+ const files: Record<string, string> = { 'icons/icon128.png': PNG };
395
+ for (let i = 0; i < 12; i++) files[`d${i}.md`] = `# T${i}\nbody ${i}\n`;
396
+ const source = memSource(files);
397
+ const store = memStore();
398
+ await reviewDirectory(args(source, store, new InMemoryIngestManifest()));
399
+ const extracted = [];
400
+ for await (const f of source.list()) {
401
+ const hit = (await store.getExtracted(f.hash))?.find((e) => e.sourceRef === srcRef(ROOT, f.path));
402
+ if (hit) extracted.push(hit);
403
+ }
404
+ const g = buildGraph({ rootId: ROOT, extracted, packs: [DOCS_PACK], facts: [], relations: [] }, { maxNodes: 3 });
405
+ expect(g.stats.truncated).toBe(true);
406
+ const png = g.outline!.files.find((f) => f.path === 'icons/icon128.png');
407
+ expect(png?.badges).toEqual({ asset: 1, mediaType: 'image/png', size: PNG.length });
408
+ });
409
+
410
+ it('regression: an .svg stays text: its title and text become a section and its href a link; it is not an asset', async () => {
411
+ const svg = '<svg xmlns="http://www.w3.org/2000/svg"><title>Logo</title><text>Hello brand</text><a href="icons/icon128.png"><rect width="1" height="1"/></a></svg>';
412
+ const source = memSource({ 'logo.svg': svg, 'icons/icon128.png': PNG });
413
+ const store = memStore();
414
+ const manifest = new InMemoryIngestManifest();
415
+ expect((await planReview(source, manifest, [DOCS_PACK])).assets).toBe(1); // only the png
416
+ await reviewDirectory(args(source, store, manifest));
417
+ const ex = (await store.getExtracted(hashText(svg)))!.find((e) => e.sourceRef === srcRef(ROOT, 'logo.svg'))!;
418
+ expect(mediaTypeOfPath('logo.svg')).toBe('image/svg+xml');
419
+ expect(ex.nodes[0]).toMatchObject({ kind: 'file', pack: 'docs' });
420
+ expect(ex.nodes[0]!.badges?.asset).toBeUndefined();
421
+ expect(ex.nodes.some((n) => n.kind === 'section' && String(n.badges?.excerpt).includes('Hello brand'))).toBe(true);
422
+ expect(ex.edges.filter((e) => e.kind === 'links').map((e) => e.to)).toEqual([srcRef(ROOT, 'icons/icon128.png')]);
423
+ });
424
+
425
+ it('regression: a pdf with no host parser becomes an asset node; with a host parser it is still extracted', async () => {
426
+ const pdf: KnowledgeParser = {
427
+ id: 'pdf-text',
428
+ accepts: (s) => s.content.kind === 'text' && s.content.mediaType === 'application/pdf',
429
+ parse: (s) => [{ text: s.content.kind === 'text' ? s.content.text : '' }],
430
+ };
431
+ const files = { 'doc.pdf': 'pdf text' };
432
+ const bare = memStore();
433
+ const bareReport = await reviewDirectory(args(memSource({ ...files }), bare, new InMemoryIngestManifest()));
434
+ expect(bareReport.extracted).toBe(0);
435
+ expect((await bare.getExtracted(hashText('pdf text')))![0]!.nodes[0]).toMatchObject({ kind: 'file', badges: { asset: 1, mediaType: 'application/pdf' } });
436
+
437
+ const hosted = memStore();
438
+ const withPdf: KnowledgePack = { ...DOCS_PACK, parsers: [pdf, ...DOCS_PACK.parsers] };
439
+ const hostedReport = await reviewDirectory(args(memSource({ ...files }), hosted, new InMemoryIngestManifest(), { packs: [withPdf] }));
440
+ expect(hostedReport.extracted).toBe(1);
441
+ expect((await hosted.getExtracted(hashText('pdf text')))![0]!.nodes[0]!.badges?.asset).toBeUndefined();
442
+ });
443
+ });
@@ -193,7 +193,7 @@ export type KNode_system_fields = Expect<Equal<
193
193
  export type GraphSystem_fields = Expect<Equal<
194
194
  GraphSystem,
195
195
  {
196
- path: string; name: string; files: number; apps: GraphApp[]; truncated?: boolean; copyOf?: string; copySimilarity?: number;
196
+ path: string; name: string; files: number; assets?: number; apps: GraphApp[]; truncated?: boolean; copyOf?: string; copySimilarity?: number;
197
197
  copyReason?: 'no-git' | 'name-mismatch' | 'later-name'; graphRead?: { read: number; skipped: GraphReadSkip[] };
198
198
  }
199
199
  >>;
@@ -92,7 +92,8 @@ class ExtractBuilder {
92
92
  /** A `links` edge to the target, unless it is the root itself (or a folder above it). */
93
93
  link(from: NodeRef, target: string, byName?: string): void {
94
94
  const clean = target.split('#')[0]!.split('?')[0]!.trim();
95
- if (!clean || /^[a-z][a-z0-9+.-]*:/i.test(clean)) return;
95
+ // A scheme (`https:`, `data:`, `mailto:`) or a protocol-relative `//cdn/x.png` is external, never a file of the root.
96
+ if (!clean || clean.startsWith('//') || /^[a-z][a-z0-9+.-]*:/i.test(clean)) return;
96
97
  let decoded = clean;
97
98
  try { decoded = decodeURI(clean); } catch { /* keep the raw target */ }
98
99
  // Written as directory navigation (`.`, `./`, `..`, `/`, `docs/`): a folder, not a file link.
@@ -234,10 +235,11 @@ export function withoutCode(text: string, opts: { indented?: boolean } = {}): st
234
235
  return out.join('\n').replace(INLINE_CODE, ' ');
235
236
  }
236
237
 
237
- const MD_LINK = /(?<!!)\[[^\]]*\]\(\s*<?([^)\s>]+)>?(?:\s+"[^"]*")?\s*\)/g;
238
+ /** `[text](target)` and the image form `![alt](target)`: both reference the target (an image file is an asset node). */
239
+ const MD_LINK = /\[[^\]]*\]\(\s*<?([^)\s>]+)>?(?:\s+"[^"]*")?\s*\)/g;
238
240
  /** `[id]: target` definitions (reference-style links); the use is `[text][id]` or `[id][]`. */
239
241
  const MD_REF_DEF = /^ {0,3}\[([^\]]+)\]:\s*<?(\S+?)>?(?:\s+["'(].*)?[ \t\r]*$/gm;
240
- const MD_REF_USE = /(?<!!)\[([^\]]*)\]\[([^\]]*)\]/g;
242
+ const MD_REF_USE = /\[([^\]]*)\]\[([^\]]*)\]/g;
241
243
 
242
244
  /** Reference-link definitions of a whole markdown text, by lower-cased label. */
243
245
  function refDefinitions(text: string): Map<string, string> {
@@ -308,11 +310,14 @@ export function extractMarkdown(source: SourceDocument, sections: ParsedSection[
308
310
  return b.build();
309
311
  }
310
312
 
313
+ /** The first `href` / `src` / `xlink:href` of an `<a>`, `<img>`, `<source>`, `<link>` or svg `<image>` tag: a file the page references. */
314
+ const HTML_REF = /<(?:a|img|source|link|image)(?=\s)[^>]*?\s(?:xlink:)?(?:href|src)\s*=\s*["']([^"']+)["']/gi;
315
+
311
316
  export function extractHtml(source: SourceDocument, sections: ParsedSection[], ctx: Ctx): Extracted {
312
317
  const title = sections[0]?.metadata?.['htmlTitle'];
313
318
  const b = new ExtractBuilder(source, ctx, typeof title === 'string' ? title : undefined);
314
319
  if (typeof title === 'string' && title) b.key(b.fileRef, normalizeKey(title));
315
- for (const m of textOf(source).matchAll(/<a\s[^>]*href\s*=\s*["']([^"']+)["']/gi)) {
320
+ for (const m of textOf(source).matchAll(HTML_REF)) {
316
321
  if (!m[1]!.startsWith('#')) b.link(b.fileRef, m[1]!);
317
322
  }
318
323
  sections.forEach((section, index) => b.mentions(b.bodySection(index, section.text), section.text));
@@ -12,13 +12,13 @@ export const mediaTypeOf = (source: SourceDocument): string =>
12
12
  source.content.kind === 'text' ? (source.content.mediaType ?? 'text/plain').toLowerCase() : '';
13
13
 
14
14
  /**
15
- * Binary documents — pdf, legacy and OOXML/OpenDocument office files. Their bytes are not
16
- * text. The ingest pipeline's builtin parsers are unchanged (the html/xml and plain-text
15
+ * Binary documents — pdf, legacy (`vnd.ms-excel|powerpoint|word`, not other `vnd.ms-*` such as a font object) and OOXML/OpenDocument office
16
+ * files. Their bytes are not text. The ingest pipeline's builtin parsers are unchanged (the html/xml and plain-text
17
17
  * matchers still accept these types); the knowledge composition (`composePacks`) is what
18
18
  * makes the builtin docs parsers refuse them, so only a host extractor that turns them into
19
19
  * text claims them there, in any pack order.
20
20
  */
21
21
  export function isBinaryDocumentType(mediaType: string): boolean {
22
- return /^application\/(?:pdf|msword|vnd\.(?:openxmlformats-officedocument\.|ms-|oasis\.opendocument\.))/
22
+ return /^application\/(?:pdf|msword|vnd\.(?:openxmlformats-officedocument\.|ms-(?:excel|powerpoint|word)|oasis\.opendocument\.))/
23
23
  .test(mediaType.trim().toLowerCase());
24
24
  }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * knowledge/assetFile.ts — the file node of an ASSET: a binary file (image, font, archive …) that is in the
3
+ * root but has no text to extract. It is planned, hashed and diffed like any file and never read, extracted or
4
+ * judged; this module writes the ONE node that stands for it, so a reference to its path (an `<img src>`, an
5
+ * import, a link) resolves to a real node instead of a `missing` placeholder.
6
+ *
7
+ * The node is the SAME file node a text file gets (kind `file`, ref `srcRef(rootId, path)`, key = path, the
8
+ * content hash as `sourceHash`), stored in the same extract cache under the file's hash. What marks it is its
9
+ * `badges` (the node's pack-data field): `asset: 1`, `mediaType` (string) and `size` (bytes). A host that finds a
10
+ * text-extension file binary on read gets the same node, with the path-derived media type.
11
+ */
12
+
13
+ import type { Extracted, KnowledgeStore } from './model.js';
14
+ import { basenameOf, FALLBACK_PACK_ID, srcRef } from './refs.js';
15
+ import { EXTRACTOR_VERSION, mediaTypeOfPath } from './sources.js';
16
+ import { putExtract } from './extractFile.js';
17
+
18
+ /** The `Extracted` of one asset: one file node, no edges. Pure: the same inputs give the same bytes. */
19
+ export function assetExtracted(rootId: string, file: { path: string; hash: string; size: number }): Extracted {
20
+ const ref = srcRef(rootId, file.path);
21
+ return {
22
+ sourceRef: ref, sourceHash: file.hash, extractorVersion: EXTRACTOR_VERSION, edges: [], keys: [{ ref, key: file.path }],
23
+ nodes: [{
24
+ // No pack extracts an asset: it belongs to the generic pack, as a `missing` placeholder does.
25
+ ref, kind: 'file', label: basenameOf(file.path), pack: FALLBACK_PACK_ID, importance: 0, origin: 'extracted', sourceHash: file.hash,
26
+ badges: { asset: 1, mediaType: mediaTypeOfPath(file.path), size: file.size },
27
+ }],
28
+ };
29
+ }
30
+
31
+ /** Stores the asset node in the extract cache under the file's hash (the entries of other files sharing the hash are kept). */
32
+ export async function putAsset(store: KnowledgeStore, rootId: string, file: { path: string; hash: string; size: number }): Promise<void> {
33
+ await putExtract(store, file.hash, assetExtracted(rootId, file));
34
+ }
@@ -1,26 +1,24 @@
1
1
  /**
2
2
  * knowledge/backfillNoExtract.ts — settles the files a root holds with no stored body, so a replica can tell
3
- * "nothing is extracted for this file" (binary: an explicit `[]`) from "not extracted yet".
3
+ * "nothing is extracted for this file" from "not extracted yet".
4
4
  *
5
- * A review stores `[]` for a file it finds binary (`putNoExtract`), but a root reviewed before that existed names such
5
+ * A review stores a file node for an ASSET (a binary file, assetFile.ts), but a root reviewed before that existed names such
6
6
  * files in its manifest with no body, and no later review visits them again. Two cases, neither a sweep:
7
7
  *
8
- * - binary by EXTENSION: the plan SKIPS the file (reason `binary`) yet the manifest may still name it. The extension is the
9
- * whole test, so no file is read; only a hash with no stored body is touched. (A planned file with a binary-looking
10
- * extension is a pdf/office document a host extractor handles: never `[]` by extension.)
11
- * - binary by CONTENT (a NUL): unknowable without reading. A replica that holds a file back, or is told by the server that a
12
- * body is missing, calls `store.markRecheck(hashes)`; the review reads ONLY the unchanged planned files with those hashes.
13
- * Binary → `[]`. Anything else (text, a document) → queued for extraction this run (`changed`). A hash only a SKIPPED
14
- * prior entry carries is never extracted by any review: `[]`. Hashes settled HERE are cleared here. A queued one (or one whose read
15
- * threw here) is cleared by the review only once its body is stored or a FINAL failure is recorded; a transient failure or a stop keeps the request.
8
+ * - ASSET by extension (planned with `asset`): no file is read. A manifest entry at the file's current bytes with no stored body
9
+ * queues the file, so the review writes its node; an older hash of the path with no body gets an explicit `[]`.
10
+ * - binary by CONTENT (a NUL) or any other body missing: unknowable without reading. A replica that holds a file back, or is told by
11
+ * the server that a body is missing, calls `store.markRecheck(hashes)`; the unchanged planned files with those hashes are queued
12
+ * for the review (`changed`), which stores the body or the asset node. A hash only a SKIPPED prior entry carries is never extracted
13
+ * by any review: `[]`. Hashes settled HERE are cleared here. A queued one is cleared by the review only once its body is stored or
14
+ * a FINAL failure is recorded; a transient failure or a stop keeps the request.
16
15
  *
17
16
  * A healthy root has no body missing and an empty recheck set: it reads nothing and costs only in-memory lookups.
18
17
  */
19
18
 
20
- import type { DirectorySource, KnowledgeStore } from './model.js';
19
+ import type { KnowledgeStore } from './model.js';
21
20
  import { putNoExtract } from './extractFile.js';
22
21
  import type { PlanDetail } from './plan.js';
23
- import { isBinaryText } from './sources.js';
24
22
 
25
23
  export interface BackfillResult {
26
24
  /** Hashes stored as an explicit `[]`. */
@@ -29,25 +27,30 @@ export interface BackfillResult {
29
27
  queued: string[];
30
28
  }
31
29
 
32
- /** The hashes the backfill will look up (for the review's ONE bulk preload): binary-by-extension manifest entries, and the re-check set. */
30
+ /** The hashes the backfill will look up (for the review's ONE bulk preload): the planned assets' manifest entries, and the re-check set. */
33
31
  export function backfillCandidates(detail: PlanDetail, asked: readonly string[]): string[] {
34
- const skippedBinary = detail.plan.skipped.filter((s) => s.reason === 'binary').map((s) => detail.prior.get(s.path)).filter((h): h is string => !!h);
35
- return [...new Set([...skippedBinary, ...asked])];
32
+ const assets = detail.files.filter((f) => f.asset).map((f) => detail.prior.get(f.path)).filter((h): h is string => !!h);
33
+ return [...new Set([...assets, ...asked])];
36
34
  }
37
35
 
38
- export async function backfillNoExtract(args: { store: KnowledgeStore; source: DirectorySource; detail: PlanDetail; asked: readonly string[]; only?: readonly string[] | undefined; signal?: AbortSignal | undefined }): Promise<BackfillResult> {
39
- const { store, source, detail, signal } = args;
36
+ export async function backfillNoExtract(args: { store: KnowledgeStore; detail: PlanDetail; asked: readonly string[]; only?: readonly string[] | undefined; signal?: AbortSignal | undefined }): Promise<BackfillResult> {
37
+ const { store, detail, signal } = args;
40
38
  const asked = new Set(args.asked);
41
39
  const out: BackfillResult = { recorded: 0, queued: [] };
42
40
  if (!store.getExtracted || !store.putExtracted) return out;
43
41
 
44
- const skippedBinary = detail.plan.skipped.filter((s) => s.reason === 'binary').map((s) => detail.prior.get(s.path)).filter((h): h is string => !!h);
45
-
46
- for (const hash of skippedBinary) {
42
+ for (const f of detail.files) {
43
+ if (!f.asset) continue;
47
44
  if (signal?.aborted) return out;
48
- if ((await store.getExtracted(hash)) !== undefined) continue;
49
- await putNoExtract(store, hash);
50
- out.recorded += 1;
45
+ const prior = detail.prior.get(f.path);
46
+ if (!prior || (await store.getExtracted(prior)) !== undefined) continue;
47
+ if (prior === f.hash) {
48
+ // The manifest holds the asset at its current bytes but the store holds no body for it: the review writes its node.
49
+ if (!f.changed && (!args.only || args.only.includes(f.path))) { f.changed = true; out.queued.push(f.path); }
50
+ } else {
51
+ await putNoExtract(store, prior); // an older hash of the path: nothing more will be extracted under it
52
+ out.recorded += 1;
53
+ }
51
54
  }
52
55
  if (asked.size === 0) return out;
53
56
 
@@ -69,18 +72,9 @@ export async function backfillNoExtract(args: { store: KnowledgeStore; source: D
69
72
  if (todo.length === 0) continue; // a changed file is handled by this review, which clears the request once its work is done (`settledRecheck`)
70
73
  // Pass 2 works only on `only`: a file it will not process is not queued here, and its hash stays asked for the run that will.
71
74
  if (args.only && !todo.some((t) => args.only!.includes(t.path))) continue;
72
- const f = todo[0]!;
73
- let binary = false;
74
- try {
75
- const doc = await source.read(f.path);
76
- binary = doc.content.kind === 'text' && isBinaryText(doc.content.text);
77
- } catch {
78
- // Unreadable says nothing final about the file: it goes through the review's one failure path (reported, kept asked, made owed).
79
- for (const t of todo) { t.changed = true; out.queued.push(t.path); }
80
- continue;
81
- }
82
- if (binary) { await putNoExtract(store, hash); out.recorded += 1; done.add(hash); }
83
- else for (const t of todo) { t.changed = true; out.queued.push(t.path); } // asked for until the review has stored its body (see `settledRecheck`)
75
+ // The review decides what the file is (text → its body, a NUL → its asset node, an unreadable file → its one failure path) and stores
76
+ // it; the request is asked for until then (see `settledRecheck`). No read here: a file found binary needs a node, not a bare `[]`.
77
+ for (const t of todo) { t.changed = true; out.queued.push(t.path); }
84
78
  }
85
79
  if (done.size > 0 && !signal?.aborted) await store.clearRecheck?.([...done]);
86
80
  return out;
@@ -28,7 +28,7 @@ import { applyCommunities } from './communities.js';
28
28
  import { loadPartitions, partitionOf, verdictOf } from './partitions.js';
29
29
  import { entityName } from './resolve.js';
30
30
  import {
31
- basenameOf, canonicalJson, compareStr, factRef, fileRefOf, nameResolver, pathOfRef, round6, sortBy, srcRef,
31
+ basenameOf, canonicalJson, compareStr, factRef, FALLBACK_PACK_ID, fileRefOf, nameResolver, pathOfRef, round6, sortBy, srcRef,
32
32
  } from './refs.js';
33
33
  import { buildOutline } from './outline.js';
34
34
  import { truncateGraph } from './truncate.js';
@@ -62,8 +62,13 @@ export function graphDigest(input: BuildGraphInput): string {
62
62
  /** The systems with the file nodes each holds (the graph's own count, before any cut). */
63
63
  function systemsMeta(systems: readonly GraphSystem[], nodes: readonly KNode[]): GraphSystem[] {
64
64
  const files = new Map<string, number>();
65
- for (const n of nodes) if (n.kind === 'file' && n.system !== undefined) files.set(n.system, (files.get(n.system) ?? 0) + 1);
66
- return systems.map((s) => ({ ...s, files: files.get(s.path) ?? 0 }));
65
+ const assets = new Map<string, number>();
66
+ for (const n of nodes) {
67
+ if (n.kind !== 'file' || n.system === undefined) continue;
68
+ const into = n.badges?.['asset'] !== undefined ? assets : files;
69
+ into.set(n.system, (into.get(n.system) ?? 0) + 1);
70
+ }
71
+ return systems.map((s) => ({ ...s, files: files.get(s.path) ?? 0, ...(assets.has(s.path) ? { assets: assets.get(s.path)! } : {}) }));
67
72
  }
68
73
 
69
74
  /** An absent list and an empty list mean the same input, so they hash the same. */
@@ -128,7 +133,7 @@ function factNode(f: StoredFact, rootId: string, g: GraphBuilder, sources: Reado
128
133
  const kind = f.key.startsWith('ent:') ? 'entity' : f.key.startsWith('claim:') ? 'claim' : 'fact';
129
134
  const anchors = sortBy(f.fileAnchors, (a) => a.path);
130
135
  const anchoredPack = anchors.map((a) => g.nodes.get(srcRef(rootId, a.path))?.pack).find(Boolean);
131
- const pack = kind === 'entity' ? f.key.split(':')[1] || 'memory' : anchoredPack ?? 'memory';
136
+ const pack = kind === 'entity' ? f.key.split(':')[1] || FALLBACK_PACK_ID : anchoredPack ?? FALLBACK_PACK_ID;
132
137
  const stale = f.origin === 'model' && anchors.some((a) => {
133
138
  if (!a.contentHash) return false;
134
139
  const ref = srcRef(rootId, a.path);
@@ -262,7 +267,7 @@ function closeEndpoints(g: GraphBuilder): void {
262
267
  const path = pathOfRef(end)!;
263
268
  const other = g.nodes.get(end === e.from ? e.to : e.from);
264
269
  g.node({
265
- ref: end, kind: 'missing', label: basenameOf(path) || path, pack: other?.pack ?? 'memory',
270
+ ref: end, kind: 'missing', label: basenameOf(path) || path, pack: other?.pack ?? FALLBACK_PACK_ID,
266
271
  importance: 0, origin: 'extracted', badges: { missing: 1 },
267
272
  });
268
273
  }
@@ -59,12 +59,15 @@ describe('docs extract', () => {
59
59
  expect(guide.nodes[0]!.label).toBe('The Guide');
60
60
  });
61
61
 
62
- it('resolves relative and wiki links; skips external links and images', () => {
62
+ it('resolves relative and wiki links and image references; skips external links', () => {
63
63
  expect(kinds(extract('README.md'), 'links')).toEqual([
64
64
  `${ref('README.md')}#home -> ${ref('docs/guide.md')}`,
65
65
  `${ref('README.md')}#home -> ${ref('notes.md')}`,
66
66
  ]);
67
- expect(kinds(extract('docs/guide.md'), 'links')).toEqual([`${ref('docs/guide.md')}#guide/setup -> ${ref('docs/nope.md')}`]);
67
+ expect(kinds(extract('docs/guide.md'), 'links')).toEqual([
68
+ `${ref('docs/guide.md')}#guide/setup -> ${ref('docs/nope.md')}`,
69
+ `${ref('docs/guide.md')}#guide/setup -> ${ref('docs/pic.png')}`,
70
+ ]);
68
71
  expect(kinds(extract('docs/page.html'), 'links')).toEqual([`${ref('docs/page.html')} -> ${ref('docs/guide.md')}`]);
69
72
  expect(kinds(extract('docs/plain.txt'), 'links')).toEqual([`${ref('docs/plain.txt')}#body -> ${ref('docs/guide.md')}`]);
70
73
  });
@@ -11,7 +11,7 @@ import type { Extracted, KnowledgePack, KnowledgeParser, KnowledgeStore, NodeRef
11
11
  import { BinaryContent, CHANGED_SINCE_PLAN, ExtractFailed, jobOf, runExtractor, type ExtractPool } from './extractJob.js';
12
12
  import { srcRef } from './refs.js';
13
13
  import { entityName, knownKeysOf, resolveEntities } from './resolve.js';
14
- import { asPathSource, composePacks, EXTRACTOR_VERSION, resolveRelativePath, stubSource, type ComposedPacks } from './sources.js';
14
+ import { asPathSource, composePacks, EXTRACTOR_VERSION, isAssetExtract, resolveRelativePath, stubSource, type ComposedPacks } from './sources.js';
15
15
 
16
16
  /** The normalized entity keys of `ent:` fact keys, for `mentions`. */
17
17
  export function knownKeysOfEntities(keys: Iterable<string>): ReadonlyMap<string, NodeRef> {
@@ -94,8 +94,9 @@ export async function extractFileDetailed(a: ExtractFileArgs): Promise<FileExtra
94
94
  const tLookup = Date.now();
95
95
  const cached = await a.store.getExtracted?.(a.hash);
96
96
  const lookupMs = Date.now() - tLookup;
97
- // A cached entry of another extractor version is ignored: its output may differ from today's.
98
- const found = cached?.find((e) => e.sourceRef === ref && e.extractorVersion === EXTRACTOR_VERSION);
97
+ // A cached entry of another extractor version is ignored: its output may differ from today's. So is an asset's entry
98
+ // (a document stored as an asset before a host parser claimed it): it holds no extraction.
99
+ const found = cached?.find((e) => e.sourceRef === ref && e.extractorVersion === EXTRACTOR_VERSION && !isAssetExtract(e));
99
100
  if (found) {
100
101
  const tSections = Date.now();
101
102
  if (a.pool && wants) {
@@ -13,7 +13,7 @@ import type { EdgeVerdict, Finding, KEdge, KNode, KnowledgeGraph, KnowledgePack,
13
13
  import type { SimilarPair } from '../retrieval/knowledge-index/types.js';
14
14
  import { godModuleFindings } from './godModule.js';
15
15
  import { possibleSameFindings } from './resolve.js';
16
- import { aboutTargets, compareStr, round6, srcRef } from './refs.js';
16
+ import { aboutTargets, compareStr, FALLBACK_PACK_ID, round6, srcRef } from './refs.js';
17
17
 
18
18
  /** Node badge naming the clone group (e.g. a jscpd issue id) its `duplicate` edges belong to. */
19
19
  export const CLONE_GROUP_BADGE = 'cloneGroup';
@@ -53,7 +53,7 @@ export function components(edges: readonly KEdge[]): NodeRef[][] {
53
53
 
54
54
  export function genericFindings(g: KnowledgeGraph, registries: ReadonlyMap<string, PartitionRegistry>): Finding[] {
55
55
  const byRef = new Map(g.nodes.map((n) => [n.ref, n] as const));
56
- const packOf = (ref: NodeRef) => byRef.get(ref)?.pack ?? 'memory';
56
+ const packOf = (ref: NodeRef) => byRef.get(ref)?.pack ?? FALLBACK_PACK_ID;
57
57
  const out: Finding[] = [];
58
58
 
59
59
  for (const refs of components(g.edges.filter((e) => e.cycle))) {
@@ -95,7 +95,7 @@ export function genericFindings(g: KnowledgeGraph, registries: ReadonlyMap<strin
95
95
  // A copy of another system in the same root (PRD 41 A9): its refs name the two systems' folders.
96
96
  for (const s of g.meta?.systems ?? []) {
97
97
  if (s.copyOf === undefined) continue;
98
- out.push(finding('duplicate-copy', 'memory', [srcRef(g.scope.rootId, s.path), srcRef(g.scope.rootId, s.copyOf)], 'warn', {
98
+ out.push(finding('duplicate-copy', FALLBACK_PACK_ID, [srcRef(g.scope.rootId, s.path), srcRef(g.scope.rootId, s.copyOf)], 'warn', {
99
99
  copy: s.path, original: s.copyOf, similarity: s.copySimilarity ?? 1, reason: s.copyReason ?? 'later-name',
100
100
  }, [s.path, s.copyOf]));
101
101
  }
@@ -127,7 +127,7 @@ function staleFindings(g: KnowledgeGraph, byRef: ReadonlyMap<NodeRef, KNode>): F
127
127
  bySource.set(target, list);
128
128
  }
129
129
  return [...bySource].map(([source, refs]) =>
130
- finding('stale', byRef.get(source)?.pack ?? 'memory', [source, ...refs], 'warn', { count: refs.length }));
130
+ finding('stale', byRef.get(source)?.pack ?? FALLBACK_PACK_ID, [source, ...refs], 'warn', { count: refs.length }));
131
131
  }
132
132
 
133
133
  /** Generic + possible-same + every pack's rules; deduped by id; severity, then id. */
@@ -58,6 +58,14 @@ export function byImportance(a: Pick<KNode, 'importance' | 'ref'>, b: Pick<KNode
58
58
  return b.importance - a.importance || compareStr(a.ref, b.ref);
59
59
  }
60
60
 
61
+ /**
62
+ * The order "top N" means when a cut must not be filled by assets: non-assets first (by importance), then assets
63
+ * (by importance). An asset is a binary file's node (`badges.asset`, assetFile.ts) — a folder of icons never crowds out the code and docs.
64
+ */
65
+ export function byImportanceAssetsLast(a: Pick<KNode, 'importance' | 'ref' | 'badges'>, b: Pick<KNode, 'importance' | 'ref' | 'badges'>): number {
66
+ return Number(a.badges?.['asset'] !== undefined) - Number(b.badges?.['asset'] !== undefined) || byImportance(a, b);
67
+ }
68
+
61
69
  /** Area importance: the sum of its members' importance, renormalized so the top area is 1. */
62
70
  export function areaImportance(members: ReadonlyMap<NodeRef, readonly number[]>): Map<NodeRef, number> {
63
71
  const sums = new Map<NodeRef, number>();
@@ -68,12 +68,12 @@ export {
68
68
  DEFAULT_REVIEW_MODEL_CALLS, DEFAULT_REVIEW_JUDGE_CONCURRENCY, REVIEW_FACT_SOURCE,
69
69
  } from './judge.js';
70
70
  export {
71
- composePacks, ignoreMatcher, ignoreSourcesOf, isBinaryPath, isBinaryText, isDocumentPath, mediaTypeOfPath,
71
+ composePacks, ignoreMatcher, ignoreSourcesOf, isAssetPath, isBinaryPath, isBinaryText, isDocumentPath, mediaTypeOfPath,
72
72
  resolveDocument, resolveRelativePath,
73
73
  DEFAULT_MAX_FILE_BYTES, EXTRACTOR_VERSION, filesManifestKey, extractorManifestKey, judgedManifestKey, compareManifestKey,
74
74
  } from './sources.js';
75
75
  export {
76
- srcRef, pathOfRef, fileRefOf, factRef, factKeyOf, slugOf, canonicalJson, compareStr, nameResolver, aboutTargets,
76
+ srcRef, FALLBACK_PACK_ID, pathOfRef, fileRefOf, factRef, factKeyOf, slugOf, canonicalJson, compareStr, nameResolver, aboutTargets,
77
77
  } from './refs.js';
78
78
  export { DOCS_PACK, DOCS_PACK_ID, brokenLinkRule, orphanDocumentRule, contradictionRule } from './packs/docs.js';
79
79
  export { frontMatterOf, SECTION_INDEX_BADGE } from '../ingest/docsExtract.js';
@@ -267,8 +267,10 @@ export interface GraphReadSkip { reason: string; count: number }
267
267
  export interface GraphSystem {
268
268
  path: string;
269
269
  name: string;
270
- /** File nodes the graph holds under it. */
270
+ /** File nodes the graph holds under it, not counting assets (binary files, see `assets`). */
271
271
  files: number;
272
+ /** Asset file nodes (images, fonts, archives …) under it; absent when it has none. Not part of `files`. */
273
+ assets?: number;
272
274
  apps: GraphApp[];
273
275
  /** The repo graph did not read every file of it (see `graphRead.skipped`). */
274
276
  truncated?: boolean;
@@ -6,7 +6,7 @@
6
6
 
7
7
  import type { EdgeVerdict, GraphOutline, KnowledgeGraph, NodeRef, OutlineFile } from './model.js';
8
8
  import { communityTable } from './communities.js';
9
- import { byImportance } from './importance.js';
9
+ import { byImportanceAssetsLast } from './importance.js';
10
10
  import { compareStr, fileRefOf } from './refs.js';
11
11
 
12
12
  export const OUTLINE_MAX_FILES = 20000;
@@ -19,6 +19,8 @@ export const OUTLINE_BADGE_KEYS: readonly string[] = [
19
19
  'complexity', 'maxComplexity', 'coverage', 'churn', 'owner', 'patterns', 'cloneGroup', 'unused', 'unusedExports',
20
20
  'entry', 'layerRule', 'unusedDependencies', 'externals', 'added', 'removed', 'changed', 'status',
21
21
  'communityId', 'communityConfidence',
22
+ // An asset file (assetFile.ts): a binary file the review stores as a node, never read.
23
+ 'asset', 'mediaType', 'size',
22
24
  ];
23
25
  /** Verdict codes of a link, least to worst; code 0 is "no verdict". */
24
26
  export const OUTLINE_VERDICTS: readonly ('none' | EdgeVerdict)[] = ['none', 'same', 'allowed', 'skips', 'upward'];
@@ -51,7 +53,7 @@ export function buildOutline(full: KnowledgeGraph): GraphOutline {
51
53
  let capped = false;
52
54
  let fileNodes = full.nodes.filter((n) => n.kind === 'file');
53
55
  if (fileNodes.length > OUTLINE_MAX_FILES) {
54
- fileNodes = [...fileNodes].sort(byImportance).slice(0, OUTLINE_MAX_FILES);
56
+ fileNodes = [...fileNodes].sort(byImportanceAssetsLast).slice(0, OUTLINE_MAX_FILES);
55
57
  capped = true;
56
58
  }
57
59
  fileNodes = [...fileNodes].sort((a, b) => compareStr(a.ref, b.ref));