@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.
- 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 +25 -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.map +1 -1
- package/dist/knowledge/extractFile.js +4 -3
- package/dist/knowledge/extractFile.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 +26 -4
- package/dist/knowledge/owedFiles.d.ts.map +1 -1
- package/dist/knowledge/owedFiles.js +58 -8
- package/dist/knowledge/owedFiles.js.map +1 -1
- package/dist/knowledge/plan.d.ts +8 -2
- package/dist/knowledge/plan.d.ts.map +1 -1
- package/dist/knowledge/plan.js +17 -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 +7 -1
- 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 +4 -0
- package/dist/knowledge/reviewPrefetch.js.map +1 -1
- package/dist/knowledge/reviewRunModel.d.ts +1 -1
- package/dist/knowledge/sources.d.ts +16 -2
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +40 -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 +206 -0
- package/src/contract/regression.recheck.test.ts +5 -5
- package/src/contract/regression.review.test.ts +129 -5
- package/src/contract/types.contract.test.ts +1 -1
- 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 +4 -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 +59 -7
- package/src/knowledge/plan.ts +25 -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 +7 -1
- package/src/knowledge/reviewPrefetch.ts +10 -2
- package/src/knowledge/reviewRunModel.ts +1 -1
- package/src/knowledge/sources.ts +44 -8
- package/src/knowledge/truncate.ts +6 -5
|
@@ -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,48 @@ 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
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 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
|
|
59
|
+
* content hashes. So the extractor entry also records ONE string, the claimed document extensions (`documents:<pdf,docx|->`); the document
|
|
60
|
+
* types whose claim changed since — in either direction — are `flipped`, and every file of those types is owed (its hash may not have moved).
|
|
61
|
+
* 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
|
|
62
|
+
* claims later as flipped, and a root from before this existed is owed everything by its version anyway.
|
|
63
|
+
*
|
|
64
|
+
* KNOWN LIMIT: two hosts with DIFFERENT pack sets sharing one manifest thrash — each switch flips every pdf/office file and re-extracts it
|
|
65
|
+
* (no model calls: judged sections re-anchor, but the work is real). Every Builderforce host is wired with the same documents pack, so the
|
|
66
|
+
* sets agree; this is deliberately not solved with per-pack-set cache entries.
|
|
67
|
+
*/
|
|
68
|
+
export function withDocuments(state: ExtractorState, now: string | undefined): ExtractorState {
|
|
69
|
+
if (now === undefined) return state;
|
|
70
|
+
const list = (s: string) => new Set(s === NO_DOCUMENTS ? [] : s.split(','));
|
|
71
|
+
const flipped = new Set<string>();
|
|
72
|
+
if (state.documents !== undefined && state.documents !== now) {
|
|
73
|
+
const was = list(state.documents), is = list(now);
|
|
74
|
+
for (const e of was) if (!is.has(e)) flipped.add(e);
|
|
75
|
+
for (const e of is) if (!was.has(e)) flipped.add(e);
|
|
76
|
+
}
|
|
77
|
+
return { ...state, documentsNow: now, flipped };
|
|
45
78
|
}
|
|
46
79
|
|
|
47
80
|
export async function loadExtractorState(manifest: IngestManifest, rootId: string): Promise<ExtractorState> {
|
|
48
81
|
let version: number | undefined;
|
|
82
|
+
let documents: string | undefined;
|
|
49
83
|
const owed = new Map<string, number>();
|
|
50
84
|
const failures = new Map<string, { hash: string; count: number }>();
|
|
51
85
|
for (const { id, hash } of (await manifest.get(extractorManifestKey(rootId))) ?? []) {
|
|
52
86
|
if (id === VERSION_ID) {
|
|
53
87
|
const v = Number(hash);
|
|
54
88
|
if (Number.isFinite(v)) version = v;
|
|
89
|
+
} else if (id === DOCUMENTS_ID) {
|
|
90
|
+
documents = hash;
|
|
55
91
|
} else if (id.startsWith(FAIL_PREFIX)) {
|
|
56
92
|
const at = hash.indexOf(':');
|
|
57
93
|
const count = Number(hash.slice(0, at));
|
|
@@ -61,16 +97,30 @@ export async function loadExtractorState(manifest: IngestManifest, rootId: strin
|
|
|
61
97
|
owed.set(id.slice(OWED_PREFIX.length), Number.isFinite(calls) && calls >= 0 ? calls : UPGRADE_CALLS);
|
|
62
98
|
}
|
|
63
99
|
}
|
|
64
|
-
return { version, owed, failures };
|
|
100
|
+
return { version, owed, failures, documents: documents ?? NO_DOCUMENTS };
|
|
65
101
|
}
|
|
66
102
|
|
|
67
|
-
/**
|
|
103
|
+
/** The file's document extension when its asset-ness flipped (a host parser arrived or left since the last run). */
|
|
104
|
+
const isFlipped = (state: ExtractorState, path: string): boolean => !!state.flipped?.size && state.flipped.has(extOf(path));
|
|
105
|
+
|
|
106
|
+
/** True when `path` is owed a re-extraction: another extractor version than today's, left unfinished before, or its asset-ness flipped. */
|
|
68
107
|
export const isOwed = (state: ExtractorState, path: string): boolean =>
|
|
69
|
-
state.version !== EXTRACTOR_VERSION || state.owed.has(path);
|
|
108
|
+
state.version !== EXTRACTOR_VERSION || state.owed.has(path) || isFlipped(state, path);
|
|
109
|
+
|
|
110
|
+
/** Whether `path` is an asset under the packs the plan was made with: binary, and not a document some parser claims. */
|
|
111
|
+
const isAssetNow = (state: ExtractorState, path: string): boolean => {
|
|
112
|
+
if (!isBinaryPath(path)) return false;
|
|
113
|
+
if (!isDocumentPath(path)) return true;
|
|
114
|
+
const claimed = state.documentsNow;
|
|
115
|
+
return claimed === undefined || claimed === NO_DOCUMENTS || !claimed.split(',').includes(extOf(path));
|
|
116
|
+
};
|
|
70
117
|
|
|
71
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Model calls an owed `path` is expected to cost: its recorded count, plus one while an upgrade is pending or its asset-ness flipped.
|
|
120
|
+
* An asset costs none (it is never read or judged); a file that flipped TO a document does.
|
|
121
|
+
*/
|
|
72
122
|
export const owedCalls = (state: ExtractorState, path: string): number =>
|
|
73
|
-
(state.version !== EXTRACTOR_VERSION ? UPGRADE_CALLS : 0) + (state.owed.get(path) ?? 0);
|
|
123
|
+
isAssetNow(state, path) ? 0 : (state.version !== EXTRACTOR_VERSION || isFlipped(state, path) ? UPGRADE_CALLS : 0) + (state.owed.get(path) ?? 0);
|
|
74
124
|
|
|
75
125
|
/**
|
|
76
126
|
* Paths in the files manifest that the plan does not list yet are owed: ignored, claimed by
|
|
@@ -112,9 +162,11 @@ export function owedAfterRun(a: {
|
|
|
112
162
|
/** Records today's version and exactly the files still owed after this run. */
|
|
113
163
|
export async function saveExtractorState(
|
|
114
164
|
manifest: IngestManifest, rootId: string, owed: ReadonlyMap<string, number>, failures: ReadonlyMap<string, { hash: string; count: number }> = new Map(),
|
|
165
|
+
documents?: string,
|
|
115
166
|
): Promise<void> {
|
|
116
167
|
await manifest.set(extractorManifestKey(rootId), [
|
|
117
168
|
{ id: VERSION_ID, hash: String(EXTRACTOR_VERSION) },
|
|
169
|
+
...(documents !== undefined && documents !== NO_DOCUMENTS ? [{ id: DOCUMENTS_ID, hash: documents }] : []),
|
|
118
170
|
...[...owed].sort((a, b) => compareStr(a[0], b[0])).map(([path, calls]) => ({ id: `${OWED_PREFIX}${path}`, hash: String(calls) })),
|
|
119
171
|
...[...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
172
|
]);
|
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,11 @@ 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. Counted in `files` (and in `ReviewPlan.assets`,
|
|
61
|
+
* not in `byPack`), diffed by hash like any file, but never read, extracted or judged; the review writes its file node (assetFile.ts).
|
|
62
|
+
*/
|
|
63
|
+
asset?: true;
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
export interface PlanDetail {
|
|
@@ -106,18 +112,27 @@ export async function planDetail(
|
|
|
106
112
|
const prior = await manifestMap(manifest, filesManifestKey(source.rootId));
|
|
107
113
|
// Another extractor version than the one that reviewed these files, or files an earlier run
|
|
108
114
|
// left unfinished: those are owed a re-extraction. `prior` stays the real manifest (removals).
|
|
109
|
-
|
|
115
|
+
// 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
|
|
116
|
+
// packs claim since the last run owes the files of those types a re-processing, whatever their hash (see withDocuments).
|
|
117
|
+
const extractor = withDocuments(await loadExtractorState(manifest, source.rootId), claimedDocumentExts(composed));
|
|
110
118
|
const packById = new Map(packs.map((p) => [p.id, p] as const));
|
|
111
119
|
|
|
112
120
|
const files: PlannedFile[] = [];
|
|
113
121
|
const skipped: ReviewPlan['skipped'] = [];
|
|
114
122
|
const byPack: Record<string, number> = {};
|
|
123
|
+
let assets = 0;
|
|
115
124
|
let estimatedSections = 0;
|
|
116
125
|
let compareSections = 0;
|
|
117
126
|
for (const e of entries) {
|
|
118
127
|
if (ignored(e.path)) { skipped.push({ path: e.path, reason: 'ignored' }); continue; }
|
|
119
128
|
const document = isDocumentPath(e.path) ? resolveDocument(composed, e.path) : undefined;
|
|
120
|
-
|
|
129
|
+
// An asset is never read, so the size cap does not apply: it is planned, hashed and diffed, and costs no model call.
|
|
130
|
+
if (isAssetPath(e.path, !!document)) {
|
|
131
|
+
const { owed, changed } = classify(extractor, prior, e.path, e.hash, opts.force === true);
|
|
132
|
+
files.push({ path: e.path, hash: e.hash, size: e.size, pack: FALLBACK_PACK_ID, changed, owed, asset: true });
|
|
133
|
+
assets += 1;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
121
136
|
if (e.size > maxBytes) { skipped.push({ path: e.path, reason: 'too-large' }); continue; }
|
|
122
137
|
const hit = document ?? composed.resolve(stubSource(e.path));
|
|
123
138
|
if (!hit) { skipped.push({ path: e.path, reason: 'no-pack' }); continue; }
|
|
@@ -152,6 +167,7 @@ export async function planDetail(
|
|
|
152
167
|
rootId: source.rootId,
|
|
153
168
|
files: files.length,
|
|
154
169
|
byPack: sortedByPack,
|
|
170
|
+
assets,
|
|
155
171
|
unchanged: files.length - changed.length,
|
|
156
172
|
changed,
|
|
157
173
|
removed,
|
|
@@ -172,7 +188,7 @@ export async function planDetail(
|
|
|
172
188
|
*/
|
|
173
189
|
export async function refreshPlan(detail: PlanDetail, manifest: IngestManifest): Promise<PlanDetail> {
|
|
174
190
|
const prior = await manifestMap(manifest, filesManifestKey(detail.plan.rootId));
|
|
175
|
-
const extractor = await loadExtractorState(manifest, detail.plan.rootId);
|
|
191
|
+
const extractor = withDocuments(await loadExtractorState(manifest, detail.plan.rootId), detail.extractor.documentsNow);
|
|
176
192
|
const files = detail.files.map((f) => {
|
|
177
193
|
const { owed, changed } = classify(extractor, prior, f.path, f.hash);
|
|
178
194
|
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;
|
package/src/knowledge/resolve.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import type { Finding, NodeRef } from './model.js';
|
|
10
10
|
import type { SimilarPair } from '../retrieval/knowledge-index/types.js';
|
|
11
11
|
import { hashText } from '../ingest/hash.js';
|
|
12
|
-
import { compareStr, normalizeKey, round6 } from './refs.js';
|
|
12
|
+
import { compareStr, FALLBACK_PACK_ID, normalizeKey, round6 } from './refs.js';
|
|
13
13
|
|
|
14
14
|
export { normalizeKey };
|
|
15
15
|
|
|
@@ -46,7 +46,7 @@ export function knownKeysOf(resolved: readonly ResolvedEntity[]): Map<string, No
|
|
|
46
46
|
* `possible-same` findings from near-duplicate pairs between two DIFFERENT entities (pairs
|
|
47
47
|
* already merged by key, or naming a non-entity, are not reported).
|
|
48
48
|
*/
|
|
49
|
-
export function possibleSameFindings(pairs: readonly SimilarPair[], pack =
|
|
49
|
+
export function possibleSameFindings(pairs: readonly SimilarPair[], pack = FALLBACK_PACK_ID): Finding[] {
|
|
50
50
|
const seen = new Set<string>();
|
|
51
51
|
const out: Finding[] = [];
|
|
52
52
|
for (const p of pairs) {
|
|
@@ -58,9 +58,10 @@ describe('binary documents', () => {
|
|
|
58
58
|
expect(isBinaryDocumentType('application/vnd.api+json')).toBe(false);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
it('a docx with no host parser is
|
|
61
|
+
it('a docx with no host parser is planned as an asset, not skipped', async () => {
|
|
62
62
|
const plan = await planReview(memSource({ 'a.docx': 'x', 'b.md': '# B\n' }), new InMemoryIngestManifest(), [DOCS_PACK]);
|
|
63
|
-
expect(plan.skipped
|
|
63
|
+
expect(plan.skipped.map((s) => s.path)).not.toContain('a.docx');
|
|
64
|
+
expect(plan.assets).toBe(1);
|
|
64
65
|
});
|
|
65
66
|
|
|
66
67
|
it('a host pdf pack placed AFTER the docs pack still claims the pdf', async () => {
|
|
@@ -95,10 +95,11 @@ describe('planReview — ignores and documents', () => {
|
|
|
95
95
|
expect(plan.changed).toContain('draft.md');
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
it('
|
|
98
|
+
it('plans pdf/office as an asset unless a host parser claims the media type', async () => {
|
|
99
99
|
const source = memSource({ 'a.pdf': 'text', 'b.md': '# B\n' });
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
const bare = await planReview(source, new InMemoryIngestManifest(), [DOCS_PACK]);
|
|
101
|
+
expect(bare.skipped.map((s) => s.path)).not.toContain('a.pdf');
|
|
102
|
+
expect(bare.assets).toBe(1);
|
|
102
103
|
const pdf: KnowledgeParser = {
|
|
103
104
|
id: 'pdf-text',
|
|
104
105
|
accepts: (s) => s.content.kind === 'text' && s.content.mediaType === 'application/pdf',
|
|
@@ -107,6 +108,7 @@ describe('planReview — ignores and documents', () => {
|
|
|
107
108
|
const withPdf: KnowledgePack = { ...DOCS_PACK, parsers: [pdf, ...DOCS_PACK.parsers] };
|
|
108
109
|
const plan = await planReview(source, new InMemoryIngestManifest(), [withPdf]);
|
|
109
110
|
expect(plan.changed).toContain('a.pdf');
|
|
111
|
+
expect(plan.assets).toBe(0);
|
|
110
112
|
});
|
|
111
113
|
});
|
|
112
114
|
|
|
@@ -35,12 +35,14 @@ describe('planReview', () => {
|
|
|
35
35
|
const plan = await planReview(source, manifest, [DOCS_PACK]);
|
|
36
36
|
expect(source.reads).toEqual(['.gitignore']);
|
|
37
37
|
expect(plan.changed).toEqual(['a.md']);
|
|
38
|
-
expect(plan.unchanged).toBe(
|
|
38
|
+
expect(plan.unchanged).toBe(2); // b.md and the img.png asset
|
|
39
39
|
expect(plan.byPack).toEqual({ docs: 2 });
|
|
40
|
+
expect(plan.assets).toBe(1);
|
|
40
41
|
expect(plan.estimatedModelCalls).toBeGreaterThan(0);
|
|
41
42
|
expect(plan.skipped).toEqual(expect.arrayContaining([
|
|
42
|
-
{ path: '.gitignore', reason: 'ignored' }, { path: '
|
|
43
|
+
{ path: '.gitignore', reason: 'ignored' }, { path: 'skip/x.md', reason: 'ignored' },
|
|
43
44
|
]));
|
|
45
|
+
expect(plan.skipped.map((s) => s.path)).not.toContain('img.png');
|
|
44
46
|
|
|
45
47
|
source.reads.length = 0;
|
|
46
48
|
await reviewDirectory(args(source, memStore(), manifest));
|
package/src/knowledge/review.ts
CHANGED
|
@@ -43,7 +43,8 @@ import {
|
|
|
43
43
|
import { createModelLimiter } from './modelLimiter.js';
|
|
44
44
|
import { JudgeBreaker } from './judgeCalls.js';
|
|
45
45
|
import { applyJudge, judgesPack, splitSections, startJudge, type JudgeJob } from './reviewJudge.js';
|
|
46
|
-
import { createPrefetch, type Prefetch } from './reviewPrefetch.js';
|
|
46
|
+
import { createPrefetch, type Prefetch, type PrefetchFile } from './reviewPrefetch.js';
|
|
47
|
+
import { putAsset } from './assetFile.js';
|
|
47
48
|
import { Lanes } from './reviewRunModel.js';
|
|
48
49
|
import { compareNew, pendingClaims, saveAwaiting } from './reviewCompare.js';
|
|
49
50
|
import { factsWithoutAnchor, StoredIndex } from './reviewStored.js';
|
|
@@ -67,7 +68,7 @@ function readAheadOf(args: ReviewArgs, concurrency: number): number {
|
|
|
67
68
|
|
|
68
69
|
/** One changed file between dispatch and the ordered writer: what its prefetch found and its judging in flight. */
|
|
69
70
|
interface Slot {
|
|
70
|
-
f:
|
|
71
|
+
f: PrefetchFile;
|
|
71
72
|
i: number;
|
|
72
73
|
job: Prefetch;
|
|
73
74
|
judge: JudgeJob | undefined;
|
|
@@ -121,13 +122,13 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
|
|
|
121
122
|
const judgedPrior = await manifestMap(manifest, judgedManifestKey(rootId));
|
|
122
123
|
const judgedNow = new Map(judgedPrior);
|
|
123
124
|
const filesNow = new Map(detail.prior);
|
|
124
|
-
//
|
|
125
|
+
// Files with no stored body: assets the manifest names (queued so their node is written, no read) and the ones a replica asked to re-check (queued; this review stores their body or asset node).
|
|
125
126
|
const asked = (await store.recheckHashes?.()) ?? [];
|
|
126
127
|
// ONE bulk fetch of the extract cache for the whole run instead of a round trip per file: the files this run extracts and the ones the backfill looks up.
|
|
127
128
|
const preChanged = detail.files.filter((f) => f.changed && (!args.only || args.only.includes(f.path)));
|
|
128
129
|
const preload = [...new Set([...preChanged.map((f) => f.hash), ...backfillCandidates(detail, asked)])];
|
|
129
130
|
if (preload.length > 0) await store.preloadExtracted?.(preload);
|
|
130
|
-
await backfillNoExtract({ store,
|
|
131
|
+
await backfillNoExtract({ store, detail, asked, only: args.only, signal });
|
|
131
132
|
// A re-check request is answered only when the work it asked for is done: the body stored, the binary recorded, or the failure recorded.
|
|
132
133
|
const askedSet = new Set(asked);
|
|
133
134
|
const settledRecheck = async (hash: string): Promise<void> => { if (askedSet.has(hash)) await store.clearRecheck?.([hash]); };
|
|
@@ -223,11 +224,13 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
|
|
|
223
224
|
return true;
|
|
224
225
|
}
|
|
225
226
|
failures.delete(f.path); // it read and extracted (or was decided): the run of failures at this hash ends
|
|
227
|
+
// An asset (planned binary, or a text-extension file found binary on read): never extracted, but it IS a file of the root, so
|
|
228
|
+
// its file node is stored (assetFile.ts) — a replica tells it from "not extracted yet", and references to its path resolve.
|
|
226
229
|
// Recorded, so a file found binary on read is not re-read by every later review.
|
|
227
|
-
if (job.kind === 'binary') {
|
|
230
|
+
if (job.kind === 'binary' || job.kind === 'asset') {
|
|
228
231
|
filesNow.set(f.path, f.hash);
|
|
229
232
|
finished.add(f.path);
|
|
230
|
-
await
|
|
233
|
+
await putAsset(store, rootId, f);
|
|
231
234
|
await settledRecheck(f.hash);
|
|
232
235
|
await store.markStale(scope, srcRef(rootId, f.path), f.hash);
|
|
233
236
|
report.staleMarked += 1;
|
|
@@ -395,7 +398,7 @@ async function reviewRun(args: ReviewArgs, flush: () => Promise<void>): Promise<
|
|
|
395
398
|
// content-changed or not, and the owed paths the plan did not list that the manifest still holds.
|
|
396
399
|
await saveExtractorState(manifest, rootId, owedAfterRun({
|
|
397
400
|
state: detail.extractor, changed, prior: detail.prior, finished, carried: detail.carried, live: filesNow, measured, unreadable,
|
|
398
|
-
}), failures);
|
|
401
|
+
}), failures, detail.extractor.documentsNow);
|
|
399
402
|
await write(report.aborted ? scopeRecord : { ...scopeRecord, lastDigest: report.digest, lastReviewedAt: new Date(now()).toISOString() });
|
|
400
403
|
report.durationMs = now() - started;
|
|
401
404
|
progress({ phase: 'done', done: work.length, total: work.length });
|
|
@@ -30,10 +30,16 @@ export interface ReviewPlan {
|
|
|
30
30
|
rootId: string;
|
|
31
31
|
files: number;
|
|
32
32
|
byPack: Record<string, number>;
|
|
33
|
+
/**
|
|
34
|
+
* Files in `files` that are assets (binary, never read): stored as a file node with `mediaType` and `size`, not counted in `byPack`.
|
|
35
|
+
* `files` includes them (the plan diffs them like any file), so a host's ETA and "files to read" figures subtract `assets`
|
|
36
|
+
* (absent on a plan from an older host or built by hand: read it as 0).
|
|
37
|
+
*/
|
|
38
|
+
assets?: number;
|
|
33
39
|
unchanged: number;
|
|
34
40
|
changed: string[];
|
|
35
41
|
removed: string[];
|
|
36
|
-
skipped: Array<{ path: string; reason: 'ignored' | '
|
|
42
|
+
skipped: Array<{ path: string; reason: 'ignored' | 'too-large' | 'no-pack' }>;
|
|
37
43
|
/** ≈ judgement calls for changed files (sections of judged kinds). */
|
|
38
44
|
estimatedModelCalls: number;
|
|
39
45
|
/** The file budget of the judge pass this run will run after the map is complete (PRD 41 A10); set by the host, so the confirm chip states it. */
|
|
@@ -23,6 +23,8 @@ import { isBinaryText, type ComposedPacks } from './sources.js';
|
|
|
23
23
|
export type Prefetch = (
|
|
24
24
|
| { kind: 'read-error'; reason: string }
|
|
25
25
|
| { kind: 'binary' }
|
|
26
|
+
/** Planned as an asset (binary by extension): decided without a read, the review writes its file node. */
|
|
27
|
+
| { kind: 'asset' }
|
|
26
28
|
| { kind: 'none' }
|
|
27
29
|
| { kind: 'extracted'; doc?: SourceDocument; extraction: FileExtraction }
|
|
28
30
|
| { kind: 'failed'; reason: string; transient?: true }
|
|
@@ -53,6 +55,7 @@ export function extractStepOf(path: string, job: Prefetch): ReviewStep {
|
|
|
53
55
|
case 'read-error': return { ...base, outcome: 'failed', reason: `read: ${job.reason}` };
|
|
54
56
|
case 'failed': return { ...base, outcome: 'failed', reason: job.reason };
|
|
55
57
|
case 'binary': return { ...base, outcome: 'skipped', reason: 'binary' };
|
|
58
|
+
case 'asset': return { ...base, outcome: 'ok', reason: 'asset' }; // its node is written: the file is stored, just not read
|
|
56
59
|
case 'none': return { ...base, outcome: 'skipped', reason: 'no-pack' };
|
|
57
60
|
case 'extracted': return { ...base, outcome: job.extraction.cached ? 'cached' : 'ok' };
|
|
58
61
|
}
|
|
@@ -64,7 +67,10 @@ export { CHANGED_SINCE_PLAN };
|
|
|
64
67
|
export const DEFAULT_READ_TIMEOUT_MS = 5_000;
|
|
65
68
|
export const DEFAULT_EXTRACT_TIMEOUT_MS = 10_000;
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
/** A changed file as the prefetch sees it: a `PlannedFile`'s path, hash, size and asset flag. */
|
|
71
|
+
export type PrefetchFile = { path: string; hash: string; size: number; asset?: true };
|
|
72
|
+
|
|
73
|
+
export function createPrefetch(c: PrefetchContext): (f: PrefetchFile) => Promise<Prefetch> {
|
|
68
74
|
// A lane is a worker: taken while the file holds an extract slot. The extract stage holds at most `extractWidth` at once, so the
|
|
69
75
|
// extract deadline counts from the moment a job holds a slot, never from its wait in line (the limiter is used as a plain semaphore).
|
|
70
76
|
const lanes = new Lanes(c.extractWidth ?? c.width);
|
|
@@ -76,9 +82,11 @@ export function createPrefetch(c: PrefetchContext): (f: { path: string; hash: st
|
|
|
76
82
|
const wantsSections = (pack: KnowledgePack) => !c.args.mechanical && judgesPack(c.args.judgement, pack);
|
|
77
83
|
const byPool = !!c.args.extractPool && !!c.args.deferRead;
|
|
78
84
|
|
|
79
|
-
const run = async (f:
|
|
85
|
+
const run = async (f: PrefetchFile, parts: NonNullable<ReviewStep['parts']>, held: { lane: number }): Promise<Outcome> => {
|
|
80
86
|
// A stopped run starts nothing: a job that has not begun settles at once. Once the read has begun the job finishes (its slot wait below is signal-free for a file already read).
|
|
81
87
|
if (c.signal.aborted) return { kind: 'failed', reason: reasonOf(c.signal.reason), transient: true };
|
|
88
|
+
// The plan decided it (isAssetPath): no read, no extract slot.
|
|
89
|
+
if (f.asset) return { kind: 'asset' };
|
|
82
90
|
let doc: SourceDocument | undefined;
|
|
83
91
|
const t0 = Date.now();
|
|
84
92
|
if (!byPool) {
|
|
@@ -10,7 +10,7 @@ export type ReviewStepOutcome = 'ok' | 'cached' | 'skipped' | 'failed';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* One file in one phase. `cached` = reused prior knowledge or an extract-cache hit; `skipped` = binary
|
|
13
|
-
* or too large; `failed` carries `reason`. `lane` is the worker/lane id (0..width-1) where known.
|
|
13
|
+
* on read or too large; an asset (a binary file never read) is `ok` with reason `asset`; `failed` carries `reason`. `lane` is the worker/lane id (0..width-1) where known.
|
|
14
14
|
*/
|
|
15
15
|
export interface ReviewStep {
|
|
16
16
|
path: string;
|
package/src/knowledge/sources.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { htmlParser, markdownParser, ParserRegistry, plainTextParser } from '../ingest/parsers.js';
|
|
8
8
|
import { isBinaryDocumentType, mediaTypeOf } from '../ingest/parserSupport.js';
|
|
9
9
|
import { CONTENT_HASH_FIELD, type ChunkFingerprint, type IngestManifest, type SourceDocument } from '../ingest/types.js';
|
|
10
|
-
import type { KnowledgePack, KnowledgeParser } from './model.js';
|
|
10
|
+
import type { Extracted, KnowledgePack, KnowledgeParser } from './model.js';
|
|
11
11
|
import { matchGlob } from './partitions.js';
|
|
12
12
|
import { compareStr, walkRelative } from './refs.js';
|
|
13
13
|
|
|
@@ -20,9 +20,13 @@ export const DEFAULT_MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
|
20
20
|
* re-extraction (judged sections with unchanged text are re-anchored, not judged again; see
|
|
21
21
|
* owedFiles.ts for how an unfinished one is carried to the next review).
|
|
22
22
|
*/
|
|
23
|
-
export const EXTRACTOR_VERSION =
|
|
24
|
-
/**
|
|
25
|
-
|
|
23
|
+
export const EXTRACTOR_VERSION = 4;
|
|
24
|
+
/**
|
|
25
|
+
* Always ignored: VCS internals, installed dependencies, builderforce config, and lockfiles (`yarn.lock`, `Cargo.lock` …): generated,
|
|
26
|
+
* huge, and plain text — extracted they would cost judgement calls for nothing; they were never stored (once skipped as binary).
|
|
27
|
+
* A `.builderforce/ignore` rule can still re-include one (`!yarn.lock`).
|
|
28
|
+
*/
|
|
29
|
+
const DEFAULT_IGNORES = ['.git/', 'node_modules/', '.builderforce/', '.gitignore', '*.lock'];
|
|
26
30
|
|
|
27
31
|
const MEDIA_TYPES: Record<string, string> = {
|
|
28
32
|
md: 'text/markdown', markdown: 'text/markdown', mdx: 'text/markdown',
|
|
@@ -38,9 +42,20 @@ const MEDIA_TYPES: Record<string, string> = {
|
|
|
38
42
|
odt: 'application/vnd.oasis.opendocument.text',
|
|
39
43
|
ods: 'application/vnd.oasis.opendocument.spreadsheet',
|
|
40
44
|
odp: 'application/vnd.oasis.opendocument.presentation',
|
|
45
|
+
// Assets (BINARY_EXT below): standard IANA types. A binary extension with none here is `application/octet-stream`.
|
|
46
|
+
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', bmp: 'image/bmp',
|
|
47
|
+
ico: 'image/vnd.microsoft.icon', icns: 'image/icns', tif: 'image/tiff', tiff: 'image/tiff', psd: 'image/vnd.adobe.photoshop',
|
|
48
|
+
avif: 'image/avif', heic: 'image/heic', svg: 'image/svg+xml',
|
|
49
|
+
mp3: 'audio/mpeg', wav: 'audio/wav', flac: 'audio/flac', ogg: 'audio/ogg', m4a: 'audio/mp4',
|
|
50
|
+
mp4: 'video/mp4', mov: 'video/quicktime', avi: 'video/x-msvideo', mkv: 'video/x-matroska', webm: 'video/webm',
|
|
51
|
+
zip: 'application/zip', gz: 'application/gzip', tgz: 'application/gzip', bz2: 'application/x-bzip2', xz: 'application/x-xz',
|
|
52
|
+
'7z': 'application/x-7z-compressed', rar: 'application/vnd.rar', tar: 'application/x-tar',
|
|
53
|
+
jar: 'application/java-archive', war: 'application/java-archive', wasm: 'application/wasm',
|
|
54
|
+
ttf: 'font/ttf', otf: 'font/otf', woff: 'font/woff', woff2: 'font/woff2', eot: 'application/vnd.ms-fontobject',
|
|
55
|
+
sqlite: 'application/vnd.sqlite3', exe: 'application/vnd.microsoft.portable-executable', dll: 'application/vnd.microsoft.portable-executable',
|
|
41
56
|
};
|
|
42
57
|
|
|
43
|
-
/** Binary documents whose text a HOST extractor may supply (§4.5); otherwise
|
|
58
|
+
/** Binary documents whose text a HOST extractor may supply (§4.5); otherwise stored as an asset (never read). */
|
|
44
59
|
const DOCUMENT_EXT = new Set(['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']);
|
|
45
60
|
|
|
46
61
|
const BINARY_EXT = new Set([
|
|
@@ -49,26 +64,39 @@ const BINARY_EXT = new Set([
|
|
|
49
64
|
'zip', 'gz', 'tgz', 'bz2', 'xz', '7z', 'rar', 'tar', 'jar', 'war',
|
|
50
65
|
'exe', 'dll', 'so', 'dylib', 'bin', 'o', 'a', 'class', 'wasm', 'node', 'pyc',
|
|
51
66
|
'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp',
|
|
52
|
-
'ttf', 'otf', 'woff', 'woff2', 'eot', 'sqlite', 'db', 'vsix',
|
|
67
|
+
'ttf', 'otf', 'woff', 'woff2', 'eot', 'sqlite', 'db', 'vsix',
|
|
53
68
|
]);
|
|
54
69
|
|
|
55
70
|
/** Shell and batch scripts are code, never documents (their `[[ … ]]` tests are not links). */
|
|
56
71
|
const SCRIPT_EXT = new Set(['sh', 'bash', 'zsh', 'ps1', 'bat', 'cmd']);
|
|
57
72
|
|
|
58
|
-
const extOf = (path: string): string => {
|
|
73
|
+
export const extOf = (path: string): string => {
|
|
59
74
|
const m = /\.([A-Za-z0-9]+)$/.exec(path);
|
|
60
75
|
return m ? m[1]!.toLowerCase() : '';
|
|
61
76
|
};
|
|
62
77
|
|
|
78
|
+
/** The ONE media-type lookup: the table, else `application/octet-stream` for a binary extension, else `text/plain`. */
|
|
63
79
|
export function mediaTypeOfPath(path: string): string {
|
|
64
|
-
|
|
80
|
+
const ext = extOf(path);
|
|
81
|
+
return MEDIA_TYPES[ext] ?? (BINARY_EXT.has(ext) ? 'application/octet-stream' : 'text/plain');
|
|
65
82
|
}
|
|
66
83
|
|
|
84
|
+
/** Whether a cached extract is an asset's (assetFile.ts): one file node marked `badges.asset`, no text was extracted — never a hit for a file a parser now extracts. */
|
|
85
|
+
export const isAssetExtract = (e: Extracted): boolean => e.nodes.some((n) => n.badges?.['asset'] !== undefined);
|
|
86
|
+
|
|
67
87
|
/** By extension — the plan never reads a file to decide. (pdf/office text needs a host extractor.) */
|
|
68
88
|
export function isBinaryPath(path: string): boolean {
|
|
69
89
|
return BINARY_EXT.has(extOf(path));
|
|
70
90
|
}
|
|
71
91
|
|
|
92
|
+
/**
|
|
93
|
+
* The ONE decision "this listed file is an asset": binary by extension and not claimed as a document by a host parser.
|
|
94
|
+
* An asset is planned, hashed and diffed like any file but never read, extracted or judged (assetFile.ts writes its node).
|
|
95
|
+
*/
|
|
96
|
+
export function isAssetPath(path: string, claimedAsDocument: boolean): boolean {
|
|
97
|
+
return isBinaryPath(path) && !claimedAsDocument;
|
|
98
|
+
}
|
|
99
|
+
|
|
72
100
|
export function isDocumentPath(path: string): boolean {
|
|
73
101
|
return DOCUMENT_EXT.has(extOf(path));
|
|
74
102
|
}
|
|
@@ -83,6 +111,14 @@ export function resolveDocument(composed: ComposedPacks, path: string): ReturnTy
|
|
|
83
111
|
return composed.resolve(stubSource(path));
|
|
84
112
|
}
|
|
85
113
|
|
|
114
|
+
/**
|
|
115
|
+
* The document extensions (pdf/office) some composed pack's parser claims, sorted and comma-joined (`-` for none). A document is an
|
|
116
|
+
* asset exactly when its extension is not in this list, so this ONE string is all a root must remember about asset-ness (owedFiles.ts).
|
|
117
|
+
*/
|
|
118
|
+
export function claimedDocumentExts(composed: ComposedPacks): string {
|
|
119
|
+
return [...DOCUMENT_EXT].filter((ext) => resolveDocument(composed, `x.${ext}`)).sort(compareStr).join(',') || '-';
|
|
120
|
+
}
|
|
121
|
+
|
|
86
122
|
/** A NUL in the first 8 KB means binary, whatever the extension said. */
|
|
87
123
|
export function isBinaryText(text: string): boolean {
|
|
88
124
|
return text.slice(0, 8192).includes('\u0000');
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { EdgeVerdict, KEdge, KNode, KnowledgeGraph, NodeRef } from './model.js';
|
|
11
|
-
import { areaImportance,
|
|
12
|
-
import { aboutTargets, compareStr, pathOfRef, srcRef } from './refs.js';
|
|
11
|
+
import { areaImportance, byImportanceAssetsLast } from './importance.js';
|
|
12
|
+
import { aboutTargets, compareStr, FALLBACK_PACK_ID, pathOfRef, srcRef } from './refs.js';
|
|
13
13
|
|
|
14
14
|
/** Hard cap on nodes, however many the keep rules ask for. */
|
|
15
15
|
export const TRUNCATION_HARD_CAP = 2000;
|
|
@@ -47,10 +47,11 @@ export function truncateGraph(g: KnowledgeGraph, opts: TruncateOptions): { nodes
|
|
|
47
47
|
for (const s of seeds) keep(s);
|
|
48
48
|
const seeded = [...kept];
|
|
49
49
|
for (const s of seeded) {
|
|
50
|
-
|
|
50
|
+
// An asset beside a seed is not worth a slot (a page that references 3k icons would keep them all): it folds into its area unless it is a seed itself.
|
|
51
|
+
const around = [...(neighbours.get(s) ?? [])].map((r) => byRef.get(r)!).filter((n) => n && n.badges?.['asset'] === undefined).sort(byImportanceAssetsLast);
|
|
51
52
|
for (const n of around) keep(n.ref);
|
|
52
53
|
}
|
|
53
|
-
for (const n of [...g.nodes].sort(
|
|
54
|
+
for (const n of [...g.nodes].sort(byImportanceAssetsLast).slice(0, opts.maxNodes)) keep(n.ref);
|
|
54
55
|
|
|
55
56
|
// Fold the rest into areas.
|
|
56
57
|
const aboutTarget = aboutTargets(g.edges);
|
|
@@ -76,7 +77,7 @@ export function truncateGraph(g: KnowledgeGraph, opts: TruncateOptions): { nodes
|
|
|
76
77
|
const ms = members.get(area)!;
|
|
77
78
|
const partition = mostCommon(ms.map((n) => n.partition));
|
|
78
79
|
return {
|
|
79
|
-
ref: area, kind: 'area', label: pathOfRef(area) ?? area, pack: mostCommon(ms.map((n) => n.pack)) ??
|
|
80
|
+
ref: area, kind: 'area', label: pathOfRef(area) ?? area, pack: mostCommon(ms.map((n) => n.pack)) ?? FALLBACK_PACK_ID,
|
|
80
81
|
...(partition !== undefined ? { partition } : {}),
|
|
81
82
|
importance: imp.get(area) ?? 0, origin: 'extracted' as const,
|
|
82
83
|
badges: { members: ms.length },
|