@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.
- package/README.md +3 -3
- package/dist/ingest/docsExtract.d.ts.map +1 -1
- package/dist/ingest/docsExtract.js +8 -4
- package/dist/ingest/docsExtract.js.map +1 -1
- package/dist/ingest/parserSupport.d.ts +2 -2
- package/dist/ingest/parserSupport.js +3 -3
- package/dist/ingest/parserSupport.js.map +1 -1
- package/dist/knowledge/assetFile.d.ts +27 -0
- package/dist/knowledge/assetFile.d.ts.map +1 -0
- package/dist/knowledge/assetFile.js +31 -0
- package/dist/knowledge/assetFile.js.map +1 -0
- package/dist/knowledge/backfillNoExtract.d.ts +11 -13
- package/dist/knowledge/backfillNoExtract.d.ts.map +1 -1
- package/dist/knowledge/backfillNoExtract.js +34 -43
- package/dist/knowledge/backfillNoExtract.js.map +1 -1
- package/dist/knowledge/build.d.ts.map +1 -1
- package/dist/knowledge/build.js +11 -7
- package/dist/knowledge/build.js.map +1 -1
- package/dist/knowledge/extractFile.d.ts +2 -0
- package/dist/knowledge/extractFile.d.ts.map +1 -1
- package/dist/knowledge/extractFile.js +6 -5
- package/dist/knowledge/extractFile.js.map +1 -1
- package/dist/knowledge/extractJob.d.ts +3 -1
- package/dist/knowledge/extractJob.d.ts.map +1 -1
- package/dist/knowledge/extractJob.js +1 -1
- package/dist/knowledge/extractJob.js.map +1 -1
- package/dist/knowledge/findings.js +4 -4
- package/dist/knowledge/findings.js.map +1 -1
- package/dist/knowledge/importance.d.ts +5 -0
- package/dist/knowledge/importance.d.ts.map +1 -1
- package/dist/knowledge/importance.js +7 -0
- package/dist/knowledge/importance.js.map +1 -1
- package/dist/knowledge/index.d.ts +2 -2
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +2 -2
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/model.d.ts +3 -1
- package/dist/knowledge/model.d.ts.map +1 -1
- package/dist/knowledge/outline.d.ts.map +1 -1
- package/dist/knowledge/outline.js +4 -2
- package/dist/knowledge/outline.js.map +1 -1
- package/dist/knowledge/owedFiles.d.ts +28 -4
- package/dist/knowledge/owedFiles.d.ts.map +1 -1
- package/dist/knowledge/owedFiles.js +60 -8
- package/dist/knowledge/owedFiles.js.map +1 -1
- package/dist/knowledge/plan.d.ts +11 -2
- package/dist/knowledge/plan.d.ts.map +1 -1
- package/dist/knowledge/plan.js +24 -9
- package/dist/knowledge/plan.js.map +1 -1
- package/dist/knowledge/refs.d.ts +2 -0
- package/dist/knowledge/refs.d.ts.map +1 -1
- package/dist/knowledge/refs.js +2 -0
- package/dist/knowledge/refs.js.map +1 -1
- package/dist/knowledge/resolve.d.ts.map +1 -1
- package/dist/knowledge/resolve.js +2 -2
- package/dist/knowledge/resolve.js.map +1 -1
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +8 -5
- package/dist/knowledge/review.js.map +1 -1
- package/dist/knowledge/reviewModel.d.ts +17 -2
- package/dist/knowledge/reviewModel.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.d.ts +10 -2
- package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.js +15 -5
- package/dist/knowledge/reviewPrefetch.js.map +1 -1
- package/dist/knowledge/reviewRunModel.d.ts +1 -1
- package/dist/knowledge/sources.d.ts +17 -2
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +42 -7
- package/dist/knowledge/sources.js.map +1 -1
- package/dist/knowledge/truncate.d.ts.map +1 -1
- package/dist/knowledge/truncate.js +6 -5
- package/dist/knowledge/truncate.js.map +1 -1
- package/package.json +3 -3
- package/src/contract/exports.snapshot.json +2 -0
- package/src/contract/regression.assets.test.ts +246 -0
- package/src/contract/regression.recheck.test.ts +5 -5
- package/src/contract/regression.review.test.ts +185 -5
- package/src/contract/types.contract.test.ts +16 -3
- package/src/ingest/docsExtract.ts +9 -4
- package/src/ingest/parserSupport.ts +3 -3
- package/src/knowledge/assetFile.ts +34 -0
- package/src/knowledge/backfillNoExtract.ts +29 -35
- package/src/knowledge/build.ts +10 -5
- package/src/knowledge/docs.test.ts +5 -2
- package/src/knowledge/extractFile.ts +8 -5
- package/src/knowledge/extractJob.ts +3 -3
- package/src/knowledge/findings.ts +4 -4
- package/src/knowledge/importance.ts +8 -0
- package/src/knowledge/index.ts +2 -2
- package/src/knowledge/model.ts +3 -1
- package/src/knowledge/outline.ts +4 -2
- package/src/knowledge/owedFiles.ts +62 -7
- package/src/knowledge/plan.ts +34 -9
- package/src/knowledge/refs.ts +3 -0
- package/src/knowledge/resolve.ts +2 -2
- package/src/knowledge/review.fixes.test.ts +3 -2
- package/src/knowledge/review.gaps.test.ts +5 -3
- package/src/knowledge/review.test.ts +4 -2
- package/src/knowledge/review.ts +10 -7
- package/src/knowledge/reviewModel.ts +17 -2
- package/src/knowledge/reviewPrefetch.ts +21 -7
- package/src/knowledge/reviewRunModel.ts +1 -1
- package/src/knowledge/sources.ts +46 -8
- package/src/knowledge/truncate.ts +6 -5
|
@@ -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), plus `oversized: 1` for a host-claimed document left an asset by the size cap. 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; oversized?: true }): 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, ...(file.oversized ? { oversized: 1 } : {}) },
|
|
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; oversized?: true }): 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"
|
|
3
|
+
* "nothing is extracted for this file" from "not extracted yet".
|
|
4
4
|
*
|
|
5
|
-
* A review stores
|
|
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
|
-
* -
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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 {
|
|
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):
|
|
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
|
|
35
|
-
return [...new Set([...
|
|
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;
|
|
39
|
-
const { store,
|
|
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
|
-
|
|
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
|
-
|
|
49
|
-
await
|
|
50
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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;
|
package/src/knowledge/build.ts
CHANGED
|
@@ -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
|
-
|
|
66
|
-
|
|
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] ||
|
|
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 ??
|
|
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
|
|
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([
|
|
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> {
|
|
@@ -42,6 +42,8 @@ export interface ExtractFileArgs {
|
|
|
42
42
|
wantsSections?: (pack: KnowledgePack) => boolean;
|
|
43
43
|
/** The pool reads the file itself: no `doc` (see `ExtractJob.readByPool`). */
|
|
44
44
|
readByPool?: boolean;
|
|
45
|
+
/** With `readByPool`: the read deadline for this path (`DirectorySource.readTimeoutMs`), handed to the worker. */
|
|
46
|
+
readMs?: number;
|
|
45
47
|
/** Told where the time went: the cache lookup and the pool job (PRD 41 A10, so a stall names itself). */
|
|
46
48
|
onTiming?: (t: { lookupMs: number; poolMs: number }) => void;
|
|
47
49
|
/** Leave the extract cache write to the caller (the review writes it in plan order); default: write it. */
|
|
@@ -94,12 +96,13 @@ export async function extractFileDetailed(a: ExtractFileArgs): Promise<FileExtra
|
|
|
94
96
|
const tLookup = Date.now();
|
|
95
97
|
const cached = await a.store.getExtracted?.(a.hash);
|
|
96
98
|
const lookupMs = Date.now() - tLookup;
|
|
97
|
-
// A cached entry of another extractor version is ignored: its output may differ from today's.
|
|
98
|
-
|
|
99
|
+
// A cached entry of another extractor version is ignored: its output may differ from today's. So is an asset's entry
|
|
100
|
+
// (a document stored as an asset before a host parser claimed it): it holds no extraction.
|
|
101
|
+
const found = cached?.find((e) => e.sourceRef === ref && e.extractorVersion === EXTRACTOR_VERSION && !isAssetExtract(e));
|
|
99
102
|
if (found) {
|
|
100
103
|
const tSections = Date.now();
|
|
101
104
|
if (a.pool && wants) {
|
|
102
|
-
const out = await a.pool(jobOf({ rootId: a.rootId, path: a.path, hash: a.hash, knownKeys: new Map(), sectionsOnly: true, ...jobSource(a) }), a.signal);
|
|
105
|
+
const out = await a.pool(jobOf({ rootId: a.rootId, path: a.path, hash: a.hash, knownKeys: new Map(), sectionsOnly: true, ...(a.readMs ? { readMs: a.readMs } : {}), ...jobSource(a) }), a.signal);
|
|
103
106
|
if (out.binary) throw new BinaryContent();
|
|
104
107
|
if (!out.sections) throw new Error(`extract pool returned no sections for ${a.path}`);
|
|
105
108
|
sections = out.sections;
|
|
@@ -112,7 +115,7 @@ export async function extractFileDetailed(a: ExtractFileArgs): Promise<FileExtra
|
|
|
112
115
|
let extracted: Extracted;
|
|
113
116
|
if (a.pool) {
|
|
114
117
|
const tPool = Date.now();
|
|
115
|
-
const out = await a.pool(jobOf({ rootId: a.rootId, path: a.path, hash: a.hash, knownKeys, needSections: wants, ...jobSource(a) }), a.signal);
|
|
118
|
+
const out = await a.pool(jobOf({ rootId: a.rootId, path: a.path, hash: a.hash, knownKeys, needSections: wants, ...(a.readMs ? { readMs: a.readMs } : {}), ...jobSource(a) }), a.signal);
|
|
116
119
|
a.onTiming?.({ lookupMs, poolMs: Date.now() - tPool });
|
|
117
120
|
if (out.binary) throw new BinaryContent();
|
|
118
121
|
// Exact match only: a result for another file, or none although the packs accept this one, is a failure.
|
|
@@ -36,7 +36,7 @@ export interface ExtractJobBase {
|
|
|
36
36
|
*/
|
|
37
37
|
export type ExtractJobSource =
|
|
38
38
|
| { doc: SourceDocument; readByPool?: never }
|
|
39
|
-
| { doc?: never; readByPool: { path: string; hash: string } };
|
|
39
|
+
| { doc?: never; readByPool: { path: string; hash: string; /** The read deadline for this path (`DirectorySource.readTimeoutMs`), when the source sets one; a worker may use it in place of its constant. */ readMs?: number } };
|
|
40
40
|
|
|
41
41
|
export type ExtractJob = ExtractJobBase & ExtractJobSource;
|
|
42
42
|
|
|
@@ -92,13 +92,13 @@ export function runExtractor(
|
|
|
92
92
|
export function jobOf(
|
|
93
93
|
f: {
|
|
94
94
|
rootId: string; path: string; hash: string; knownKeys: ReadonlyMap<string, NodeRef>;
|
|
95
|
-
needSections?: boolean; sectionsOnly?: boolean;
|
|
95
|
+
needSections?: boolean; sectionsOnly?: boolean; readMs?: number;
|
|
96
96
|
} & ({ doc: SourceDocument; readByPool?: false } | { doc?: undefined; readByPool: true }),
|
|
97
97
|
): ExtractJob {
|
|
98
98
|
return {
|
|
99
99
|
rootId: f.rootId, path: f.path, hash: f.hash, knownKeys: [...f.knownKeys],
|
|
100
100
|
...(f.needSections ? { needSections: true } : {}), ...(f.sectionsOnly ? { sectionsOnly: true } : {}),
|
|
101
|
-
...(f.readByPool ? { readByPool: { path: f.path, hash: f.hash } } : { doc: f.doc! }),
|
|
101
|
+
...(f.readByPool ? { readByPool: { path: f.path, hash: f.hash, ...(f.readMs ? { readMs: f.readMs } : {}) } } : { doc: f.doc! }),
|
|
102
102
|
} as ExtractJob;
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -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 ??
|
|
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',
|
|
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 ??
|
|
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>();
|
package/src/knowledge/index.ts
CHANGED
|
@@ -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';
|
package/src/knowledge/model.ts
CHANGED
|
@@ -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;
|
package/src/knowledge/outline.ts
CHANGED
|
@@ -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 {
|
|
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', 'oversized',
|
|
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(
|
|
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));
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* retired it drops out.
|
|
13
13
|
*
|
|
14
14
|
* Stored under {@link extractorManifestKey} as fingerprints: `{ id: 'version', hash: '<version>' }`
|
|
15
|
-
* plus
|
|
15
|
+
* plus `{ id: 'documents', hash: '<pdf,docx|->' }` (the document types the packs claimed, see {@link withDocuments})
|
|
16
|
+
* and one `{ id: 'owed:<path>', hash: '<calls>' }` per owed file, where `<calls>` is the
|
|
16
17
|
* decimal number of model calls the file is still expected to cost (the plan's estimate):
|
|
17
18
|
* • a file the run reached but did not finish: the sections the budget or a failed call left
|
|
18
19
|
* unjudged; for a content-changed file, every section it had to judge plus what it was
|
|
@@ -27,9 +28,12 @@
|
|
|
27
28
|
|
|
28
29
|
import type { IngestManifest } from '../ingest/types.js';
|
|
29
30
|
import { compareStr } from './refs.js';
|
|
30
|
-
import { EXTRACTOR_VERSION, extractorManifestKey } from './sources.js';
|
|
31
|
+
import { EXTRACTOR_VERSION, extOf, extractorManifestKey, isBinaryPath, isDocumentPath } from './sources.js';
|
|
31
32
|
|
|
32
33
|
const VERSION_ID = 'version';
|
|
34
|
+
const DOCUMENTS_ID = 'documents';
|
|
35
|
+
/** No document type claimed — also what an entry with no `documents` record means, so a root that never had a host parser stores nothing extra. */
|
|
36
|
+
const NO_DOCUMENTS = '-';
|
|
33
37
|
const OWED_PREFIX = 'owed:';
|
|
34
38
|
const FAIL_PREFIX = 'fail:';
|
|
35
39
|
/** What a version upgrade costs per file: the one new section a re-extraction may add (an upper bound). */
|
|
@@ -42,16 +46,50 @@ export interface ExtractorState {
|
|
|
42
46
|
owed: ReadonlyMap<string, number>;
|
|
43
47
|
/** Consecutive transient failures of a path at one content hash (stored beside its owed entry); a success or a new hash resets it. Optional: a caller that builds a state by hand need not know it. */
|
|
44
48
|
failures?: ReadonlyMap<string, { hash: string; count: number }>;
|
|
49
|
+
/** The document extensions the packs claimed when the files were last reviewed (see {@link claimedDocumentExts}); undefined when never recorded. */
|
|
50
|
+
documents?: string;
|
|
51
|
+
/** The ones the packs claim now: set by the plan (and carried to *Continue*), saved by the run. */
|
|
52
|
+
documentsNow?: string;
|
|
53
|
+
/** Document extensions whose asset-ness changed between `documents` and `documentsNow`: their files are owed a re-processing. */
|
|
54
|
+
flipped?: ReadonlySet<string>;
|
|
55
|
+
/** Claimed documents over the plan's size cap: planned as assets (never read), so they owe no calls. Set by the plan, carried to *Continue*. */
|
|
56
|
+
oversized?: ReadonlySet<string>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether a file is an asset depends on the packs (a pdf is an asset until a host parser claims it), but the files manifest records only
|
|
61
|
+
* content hashes. So the extractor entry also records ONE string, the claimed document extensions (`documents:<pdf,docx|->`); the document
|
|
62
|
+
* types whose claim changed since — in either direction — are `flipped`, and every file of those types is owed (its hash may not have moved).
|
|
63
|
+
* No record reads as "none claimed" (and is not written), so a root reviewed before any host parser existed sees the document types a parser
|
|
64
|
+
* claims later as flipped, and a root from before this existed is owed everything by its version anyway.
|
|
65
|
+
*
|
|
66
|
+
* KNOWN LIMIT: two hosts with DIFFERENT pack sets sharing one manifest thrash — each switch flips every pdf/office file and re-extracts it
|
|
67
|
+
* (no model calls: judged sections re-anchor, but the work is real). Every Builderforce host is wired with the same documents pack, so the
|
|
68
|
+
* sets agree; this is deliberately not solved with per-pack-set cache entries.
|
|
69
|
+
*/
|
|
70
|
+
export function withDocuments(state: ExtractorState, now: string | undefined): ExtractorState {
|
|
71
|
+
if (now === undefined) return state;
|
|
72
|
+
const list = (s: string) => new Set(s === NO_DOCUMENTS ? [] : s.split(','));
|
|
73
|
+
const flipped = new Set<string>();
|
|
74
|
+
if (state.documents !== undefined && state.documents !== now) {
|
|
75
|
+
const was = list(state.documents), is = list(now);
|
|
76
|
+
for (const e of was) if (!is.has(e)) flipped.add(e);
|
|
77
|
+
for (const e of is) if (!was.has(e)) flipped.add(e);
|
|
78
|
+
}
|
|
79
|
+
return { ...state, documentsNow: now, flipped };
|
|
45
80
|
}
|
|
46
81
|
|
|
47
82
|
export async function loadExtractorState(manifest: IngestManifest, rootId: string): Promise<ExtractorState> {
|
|
48
83
|
let version: number | undefined;
|
|
84
|
+
let documents: string | undefined;
|
|
49
85
|
const owed = new Map<string, number>();
|
|
50
86
|
const failures = new Map<string, { hash: string; count: number }>();
|
|
51
87
|
for (const { id, hash } of (await manifest.get(extractorManifestKey(rootId))) ?? []) {
|
|
52
88
|
if (id === VERSION_ID) {
|
|
53
89
|
const v = Number(hash);
|
|
54
90
|
if (Number.isFinite(v)) version = v;
|
|
91
|
+
} else if (id === DOCUMENTS_ID) {
|
|
92
|
+
documents = hash;
|
|
55
93
|
} else if (id.startsWith(FAIL_PREFIX)) {
|
|
56
94
|
const at = hash.indexOf(':');
|
|
57
95
|
const count = Number(hash.slice(0, at));
|
|
@@ -61,16 +99,31 @@ export async function loadExtractorState(manifest: IngestManifest, rootId: strin
|
|
|
61
99
|
owed.set(id.slice(OWED_PREFIX.length), Number.isFinite(calls) && calls >= 0 ? calls : UPGRADE_CALLS);
|
|
62
100
|
}
|
|
63
101
|
}
|
|
64
|
-
return { version, owed, failures };
|
|
102
|
+
return { version, owed, failures, documents: documents ?? NO_DOCUMENTS };
|
|
65
103
|
}
|
|
66
104
|
|
|
67
|
-
/**
|
|
105
|
+
/** The file's document extension when its asset-ness flipped (a host parser arrived or left since the last run). */
|
|
106
|
+
const isFlipped = (state: ExtractorState, path: string): boolean => !!state.flipped?.size && state.flipped.has(extOf(path));
|
|
107
|
+
|
|
108
|
+
/** True when `path` is owed a re-extraction: another extractor version than today's, left unfinished before, or its asset-ness flipped. */
|
|
68
109
|
export const isOwed = (state: ExtractorState, path: string): boolean =>
|
|
69
|
-
state.version !== EXTRACTOR_VERSION || state.owed.has(path);
|
|
110
|
+
state.version !== EXTRACTOR_VERSION || state.owed.has(path) || isFlipped(state, path);
|
|
111
|
+
|
|
112
|
+
/** Whether `path` is an asset under the packs the plan was made with: binary, and not a document some parser claims. */
|
|
113
|
+
const isAssetNow = (state: ExtractorState, path: string): boolean => {
|
|
114
|
+
if (!isBinaryPath(path)) return false;
|
|
115
|
+
if (!isDocumentPath(path)) return true;
|
|
116
|
+
if (state.oversized?.has(path)) return true; // claimed, but over the size cap: an asset like an unclaimed one
|
|
117
|
+
const claimed = state.documentsNow;
|
|
118
|
+
return claimed === undefined || claimed === NO_DOCUMENTS || !claimed.split(',').includes(extOf(path));
|
|
119
|
+
};
|
|
70
120
|
|
|
71
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Model calls an owed `path` is expected to cost: its recorded count, plus one while an upgrade is pending or its asset-ness flipped.
|
|
123
|
+
* An asset costs none (it is never read or judged); a file that flipped TO a document does.
|
|
124
|
+
*/
|
|
72
125
|
export const owedCalls = (state: ExtractorState, path: string): number =>
|
|
73
|
-
(state.version !== EXTRACTOR_VERSION ? UPGRADE_CALLS : 0) + (state.owed.get(path) ?? 0);
|
|
126
|
+
isAssetNow(state, path) ? 0 : (state.version !== EXTRACTOR_VERSION || isFlipped(state, path) ? UPGRADE_CALLS : 0) + (state.owed.get(path) ?? 0);
|
|
74
127
|
|
|
75
128
|
/**
|
|
76
129
|
* Paths in the files manifest that the plan does not list yet are owed: ignored, claimed by
|
|
@@ -112,9 +165,11 @@ export function owedAfterRun(a: {
|
|
|
112
165
|
/** Records today's version and exactly the files still owed after this run. */
|
|
113
166
|
export async function saveExtractorState(
|
|
114
167
|
manifest: IngestManifest, rootId: string, owed: ReadonlyMap<string, number>, failures: ReadonlyMap<string, { hash: string; count: number }> = new Map(),
|
|
168
|
+
documents?: string,
|
|
115
169
|
): Promise<void> {
|
|
116
170
|
await manifest.set(extractorManifestKey(rootId), [
|
|
117
171
|
{ id: VERSION_ID, hash: String(EXTRACTOR_VERSION) },
|
|
172
|
+
...(documents !== undefined && documents !== NO_DOCUMENTS ? [{ id: DOCUMENTS_ID, hash: documents }] : []),
|
|
118
173
|
...[...owed].sort((a, b) => compareStr(a[0], b[0])).map(([path, calls]) => ({ id: `${OWED_PREFIX}${path}`, hash: String(calls) })),
|
|
119
174
|
...[...failures].filter(([path]) => owed.has(path)).sort((a, b) => compareStr(a[0], b[0])).map(([path, f]) => ({ id: `${FAIL_PREFIX}${path}`, hash: `${f.count}:${f.hash}` })),
|
|
120
175
|
]);
|
package/src/knowledge/plan.ts
CHANGED
|
@@ -4,18 +4,19 @@
|
|
|
4
4
|
* A walk plus a manifest diff by hash, nothing more: a file whose hash is unchanged is
|
|
5
5
|
* never read. The only reads are the ignore files (`.builderforce/ignore` and every
|
|
6
6
|
* `.gitignore`, a nested one scoped to its folder) when the listing has them. Binary files
|
|
7
|
-
* (by extension — pdf/office only when a host parser claims their media type)
|
|
8
|
-
*
|
|
7
|
+
* (by extension — pdf/office only when a host parser claims their media type) are planned as
|
|
8
|
+
* ASSETS (never read; the review writes their file node); oversized files and files no pack
|
|
9
|
+
* accepts are skipped with a reason.
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
import type { IngestManifest } from '../ingest/types.js';
|
|
12
13
|
import type { DirectorySource, KnowledgePack, ReviewPlan } from './model.js';
|
|
13
|
-
import { carriedOwed, type ExtractorState, isOwed, loadExtractorState, owedCalls } from './owedFiles.js';
|
|
14
|
+
import { carriedOwed, type ExtractorState, isOwed, loadExtractorState, owedCalls, withDocuments } from './owedFiles.js';
|
|
14
15
|
import {
|
|
15
|
-
compareManifestKey, composePacks, DEFAULT_MAX_FILE_BYTES, filesManifestKey, ignoreMatcher, ignoreSourcesOf,
|
|
16
|
-
isDocumentPath, manifestMap, resolveDocument, stubSource,
|
|
16
|
+
claimedDocumentExts, compareManifestKey, composePacks, DEFAULT_MAX_FILE_BYTES, filesManifestKey, ignoreMatcher, ignoreSourcesOf,
|
|
17
|
+
isAssetPath, isDocumentPath, manifestMap, resolveDocument, stubSource,
|
|
17
18
|
} from './sources.js';
|
|
18
|
-
import { compareStr, sortBy } from './refs.js';
|
|
19
|
+
import { compareStr, FALLBACK_PACK_ID, sortBy } from './refs.js';
|
|
19
20
|
|
|
20
21
|
/** ≈ bytes per judged section, for the estimate (the plan does not read changed files). */
|
|
21
22
|
export const AVG_SECTION_BYTES = 1500;
|
|
@@ -55,6 +56,14 @@ export interface PlannedFile {
|
|
|
55
56
|
* whether or not its content moved. See owedFiles.ts.
|
|
56
57
|
*/
|
|
57
58
|
owed: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* An asset: binary by extension and not claimed as a document by a host parser, OR a claimed document over the size cap
|
|
61
|
+
* (`maxFileBytes`, see `oversized`). Counted in `files` (and in `ReviewPlan.assets`,
|
|
62
|
+
* not in `byPack`), diffed by hash like any file, but never read, extracted or judged; the review writes its file node (assetFile.ts).
|
|
63
|
+
*/
|
|
64
|
+
asset?: true;
|
|
65
|
+
/** An asset only because a claimed document exceeds the size cap: its node carries `badges.oversized` so a UI can say why it has no text. */
|
|
66
|
+
oversized?: true;
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
export interface PlanDetail {
|
|
@@ -106,18 +115,30 @@ export async function planDetail(
|
|
|
106
115
|
const prior = await manifestMap(manifest, filesManifestKey(source.rootId));
|
|
107
116
|
// Another extractor version than the one that reviewed these files, or files an earlier run
|
|
108
117
|
// left unfinished: those are owed a re-extraction. `prior` stays the real manifest (removals).
|
|
109
|
-
|
|
118
|
+
// A file's asset-ness depends on the packs (a pdf is an asset until a host parser claims it): a change in the document types the
|
|
119
|
+
// packs claim since the last run owes the files of those types a re-processing, whatever their hash (see withDocuments).
|
|
120
|
+
const oversized = new Set<string>();
|
|
121
|
+
const extractor: ExtractorState = { ...withDocuments(await loadExtractorState(manifest, source.rootId), claimedDocumentExts(composed)), oversized };
|
|
110
122
|
const packById = new Map(packs.map((p) => [p.id, p] as const));
|
|
111
123
|
|
|
112
124
|
const files: PlannedFile[] = [];
|
|
113
125
|
const skipped: ReviewPlan['skipped'] = [];
|
|
114
126
|
const byPack: Record<string, number> = {};
|
|
127
|
+
let assets = 0;
|
|
115
128
|
let estimatedSections = 0;
|
|
116
129
|
let compareSections = 0;
|
|
117
130
|
for (const e of entries) {
|
|
118
131
|
if (ignored(e.path)) { skipped.push({ path: e.path, reason: 'ignored' }); continue; }
|
|
119
132
|
const document = isDocumentPath(e.path) ? resolveDocument(composed, e.path) : undefined;
|
|
120
|
-
|
|
133
|
+
// An asset is never read, so the size cap does not apply: it is planned, hashed and diffed, and costs no model call.
|
|
134
|
+
// A claimed document over the cap stays an asset (as before host parsers existed): never read, no calls (owedFiles isAssetNow agrees via `oversized`).
|
|
135
|
+
if (document && e.size > maxBytes) oversized.add(e.path);
|
|
136
|
+
if (isAssetPath(e.path, !!document && e.size <= maxBytes)) {
|
|
137
|
+
const { owed, changed } = classify(extractor, prior, e.path, e.hash, opts.force === true);
|
|
138
|
+
files.push({ path: e.path, hash: e.hash, size: e.size, pack: FALLBACK_PACK_ID, changed, owed, asset: true, ...(document && e.size > maxBytes ? { oversized: true as const } : {}) });
|
|
139
|
+
assets += 1;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
121
142
|
if (e.size > maxBytes) { skipped.push({ path: e.path, reason: 'too-large' }); continue; }
|
|
122
143
|
const hit = document ?? composed.resolve(stubSource(e.path));
|
|
123
144
|
if (!hit) { skipped.push({ path: e.path, reason: 'no-pack' }); continue; }
|
|
@@ -152,6 +173,7 @@ export async function planDetail(
|
|
|
152
173
|
rootId: source.rootId,
|
|
153
174
|
files: files.length,
|
|
154
175
|
byPack: sortedByPack,
|
|
176
|
+
assets,
|
|
155
177
|
unchanged: files.length - changed.length,
|
|
156
178
|
changed,
|
|
157
179
|
removed,
|
|
@@ -172,7 +194,10 @@ export async function planDetail(
|
|
|
172
194
|
*/
|
|
173
195
|
export async function refreshPlan(detail: PlanDetail, manifest: IngestManifest): Promise<PlanDetail> {
|
|
174
196
|
const prior = await manifestMap(manifest, filesManifestKey(detail.plan.rootId));
|
|
175
|
-
const extractor =
|
|
197
|
+
const extractor: ExtractorState = {
|
|
198
|
+
...withDocuments(await loadExtractorState(manifest, detail.plan.rootId), detail.extractor.documentsNow),
|
|
199
|
+
...(detail.extractor.oversized ? { oversized: detail.extractor.oversized } : {}),
|
|
200
|
+
};
|
|
176
201
|
const files = detail.files.map((f) => {
|
|
177
202
|
const { owed, changed } = classify(extractor, prior, f.path, f.hash);
|
|
178
203
|
return { ...f, changed, owed };
|
package/src/knowledge/refs.ts
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
import type { KEdge, NodeRef } from './model.js';
|
|
15
15
|
|
|
16
|
+
/** The generic pack id: what a node or finding belongs to when no real pack owns it (memory facts, `missing` placeholders, asset files). */
|
|
17
|
+
export const FALLBACK_PACK_ID = 'memory';
|
|
18
|
+
|
|
16
19
|
/** Code-unit ordering — never `localeCompare`, whose result depends on the host's ICU. */
|
|
17
20
|
export function compareStr(a: string, b: string): number {
|
|
18
21
|
return a < b ? -1 : a > b ? 1 : 0;
|