@seanhogg/builderforce-memory 2026.10.58 → 2026.10.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +3 -3
- 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 +11 -3
- 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 +2 -1
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +44 -10
- 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/reviewRun.js +1 -1
- package/dist/knowledge/reviewRun.js.map +1 -1
- package/dist/knowledge/reviewRunModel.d.ts +2 -2
- package/dist/knowledge/reviewRunModel.d.ts.map +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 +184 -5
- package/src/contract/types.contract.test.ts +2 -2
- 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 +3 -3
- package/src/knowledge/model.ts +8 -3
- 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 +38 -13
- package/src/knowledge/reviewModel.ts +7 -1
- package/src/knowledge/reviewPrefetch.ts +10 -2
- package/src/knowledge/reviewRun.ts +1 -1
- package/src/knowledge/reviewRunModel.ts +2 -2
- package/src/knowledge/sources.ts +44 -8
- package/src/knowledge/truncate.ts +6 -5
|
@@ -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> {
|
|
@@ -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
|
-
|
|
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 ??
|
|
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
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
export type {
|
|
10
10
|
NodeRef, Origin, StoredOrigin, KNode, EdgeVerdict, KEdge, Extracted, ExtractContext, Finding, FindingRule,
|
|
11
11
|
PartitionRule, PartitionRegistry, JudgementSpec, JudgementRequest, JudgedClaim, JudgedEntity, JudgementResult,
|
|
12
|
-
JudgementPort, AnalyzerPort, KnowledgeParser, KnowledgePack, StoredFact, StoredRelation, Scope, ScopeRecord,
|
|
12
|
+
JudgementPort, AnalyzerPort, AnalyzerProgress, KnowledgeParser, KnowledgePack, StoredFact, StoredRelation, Scope, ScopeRecord,
|
|
13
13
|
KnowledgeStore, DirectorySource, LiveOverlay, KnowledgeGraph, ReviewPlan, ReviewProgress, ReviewReport,
|
|
14
14
|
ReviewArgs, BuildGraphInput, BuildGraphOptions, TraceStep, Trace, GraphOutline, OutlineFile, OutlineCommunity,
|
|
15
15
|
GraphSystem, GraphApp, GraphReadSkip,
|
|
@@ -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
|
@@ -149,9 +149,12 @@ export interface JudgementPort {
|
|
|
149
149
|
judge(req: JudgementRequest): Promise<JudgementResult>;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
/**
|
|
152
|
+
/** Progress an analyzer reports while it runs (files listed/read, tools finished). */
|
|
153
|
+
export interface AnalyzerProgress { done: number; total: number; path?: string }
|
|
154
|
+
|
|
155
|
+
/** Host-run tools for a pack (code: dependency-cruiser/jscpd/knip). Returns extra extracted edges/badges. `onProgress` is optional to call and to honour. */
|
|
153
156
|
export interface AnalyzerPort {
|
|
154
|
-
analyse(rootId: string, signal?: AbortSignal): Promise<Extracted[]>;
|
|
157
|
+
analyse(rootId: string, signal?: AbortSignal, onProgress?: (p: AnalyzerProgress) => void): Promise<Extracted[]>;
|
|
155
158
|
}
|
|
156
159
|
|
|
157
160
|
/** A host-supplied parser that also extracts graph structure. `extract` is the optional ingest extension. */
|
|
@@ -264,8 +267,10 @@ export interface GraphReadSkip { reason: string; count: number }
|
|
|
264
267
|
export interface GraphSystem {
|
|
265
268
|
path: string;
|
|
266
269
|
name: string;
|
|
267
|
-
/** File nodes the graph holds under it. */
|
|
270
|
+
/** File nodes the graph holds under it, not counting assets (binary files, see `assets`). */
|
|
268
271
|
files: number;
|
|
272
|
+
/** Asset file nodes (images, fonts, archives …) under it; absent when it has none. Not part of `files`. */
|
|
273
|
+
assets?: number;
|
|
269
274
|
apps: GraphApp[];
|
|
270
275
|
/** The repo graph did not read every file of it (see `graphRead.skipped`). */
|
|
271
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',
|
|
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,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));
|