@seanhogg/builderforce-memory 2026.10.67 → 2026.10.69
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/dist/knowledge/build.d.ts.map +1 -1
- package/dist/knowledge/build.js +7 -2
- package/dist/knowledge/build.js.map +1 -1
- package/dist/knowledge/comparability.d.ts +100 -0
- package/dist/knowledge/comparability.d.ts.map +1 -0
- package/dist/knowledge/comparability.js +149 -0
- package/dist/knowledge/comparability.js.map +1 -0
- package/dist/knowledge/contentHash.d.ts +28 -0
- package/dist/knowledge/contentHash.d.ts.map +1 -0
- package/dist/knowledge/contentHash.js +54 -0
- package/dist/knowledge/contentHash.js.map +1 -0
- package/dist/knowledge/extractFile.d.ts +2 -0
- package/dist/knowledge/extractFile.d.ts.map +1 -1
- package/dist/knowledge/extractFile.js +1 -1
- package/dist/knowledge/extractFile.js.map +1 -1
- package/dist/knowledge/extractJob.d.ts +5 -2
- 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/findingBuilder.d.ts +12 -2
- package/dist/knowledge/findingBuilder.d.ts.map +1 -1
- package/dist/knowledge/findingBuilder.js +9 -2
- package/dist/knowledge/findingBuilder.js.map +1 -1
- package/dist/knowledge/findingIdentity.d.ts +52 -0
- package/dist/knowledge/findingIdentity.d.ts.map +1 -0
- package/dist/knowledge/findingIdentity.js +70 -0
- package/dist/knowledge/findingIdentity.js.map +1 -0
- package/dist/knowledge/findingModel.d.ts +30 -0
- package/dist/knowledge/findingModel.d.ts.map +1 -0
- package/dist/knowledge/findingModel.js +6 -0
- package/dist/knowledge/findingModel.js.map +1 -0
- package/dist/knowledge/findings.d.ts.map +1 -1
- package/dist/knowledge/findings.js +17 -9
- package/dist/knowledge/findings.js.map +1 -1
- package/dist/knowledge/godModule.js +2 -2
- package/dist/knowledge/godModule.js.map +1 -1
- package/dist/knowledge/index.d.ts +13 -1
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +8 -0
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/lineage.d.ts +35 -0
- package/dist/knowledge/lineage.d.ts.map +1 -0
- package/dist/knowledge/lineage.js +114 -0
- package/dist/knowledge/lineage.js.map +1 -0
- package/dist/knowledge/merkle.d.ts +65 -0
- package/dist/knowledge/merkle.d.ts.map +1 -0
- package/dist/knowledge/merkle.js +158 -0
- package/dist/knowledge/merkle.js.map +1 -0
- package/dist/knowledge/model.d.ts +20 -17
- package/dist/knowledge/model.d.ts.map +1 -1
- package/dist/knowledge/owedFiles.d.ts +5 -2
- package/dist/knowledge/owedFiles.d.ts.map +1 -1
- package/dist/knowledge/owedFiles.js +20 -5
- package/dist/knowledge/owedFiles.js.map +1 -1
- package/dist/knowledge/pack/encode.d.ts +2 -1
- package/dist/knowledge/pack/encode.d.ts.map +1 -1
- package/dist/knowledge/pack/encode.js +2 -1
- package/dist/knowledge/pack/encode.js.map +1 -1
- package/dist/knowledge/pack/extrDiff.d.ts.map +1 -1
- package/dist/knowledge/pack/extrDiff.js +4 -1
- package/dist/knowledge/pack/extrDiff.js.map +1 -1
- package/dist/knowledge/pack/sections/columns.d.ts +15 -2
- package/dist/knowledge/pack/sections/columns.d.ts.map +1 -1
- package/dist/knowledge/pack/sections/columns.js +16 -1
- package/dist/knowledge/pack/sections/columns.js.map +1 -1
- package/dist/knowledge/pack/sections/extrLists.js +2 -2
- package/dist/knowledge/pack/sections/extrLists.js.map +1 -1
- package/dist/knowledge/pack/sections/facts.d.ts.map +1 -1
- package/dist/knowledge/pack/sections/facts.js +2 -2
- package/dist/knowledge/pack/sections/facts.js.map +1 -1
- package/dist/knowledge/pack/sections/index.d.ts +1 -0
- package/dist/knowledge/pack/sections/index.d.ts.map +1 -1
- package/dist/knowledge/pack/sections/index.js +3 -1
- package/dist/knowledge/pack/sections/index.js.map +1 -1
- package/dist/knowledge/pack/sections/rows.d.ts +1 -0
- package/dist/knowledge/pack/sections/rows.d.ts.map +1 -1
- package/dist/knowledge/pack/sections/rows.js +1 -1
- package/dist/knowledge/pack/sections/rows.js.map +1 -1
- package/dist/knowledge/pack/sections/sites.d.ts +24 -0
- package/dist/knowledge/pack/sections/sites.d.ts.map +1 -0
- package/dist/knowledge/pack/sections/sites.js +96 -0
- package/dist/knowledge/pack/sections/sites.js.map +1 -0
- package/dist/knowledge/pack/types.d.ts +2 -2
- package/dist/knowledge/pack/types.d.ts.map +1 -1
- package/dist/knowledge/plan.d.ts +8 -0
- package/dist/knowledge/plan.d.ts.map +1 -1
- package/dist/knowledge/plan.js +20 -6
- package/dist/knowledge/plan.js.map +1 -1
- package/dist/knowledge/refs.d.ts +4 -0
- package/dist/knowledge/refs.d.ts.map +1 -1
- package/dist/knowledge/refs.js +8 -0
- package/dist/knowledge/refs.js.map +1 -1
- package/dist/knowledge/resolve.d.ts.map +1 -1
- package/dist/knowledge/resolve.js +2 -0
- package/dist/knowledge/resolve.js.map +1 -1
- package/dist/knowledge/reviewModel.d.ts +8 -1
- package/dist/knowledge/reviewModel.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.d.ts +2 -1
- package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.js +8 -4
- package/dist/knowledge/reviewPrefetch.js.map +1 -1
- package/dist/knowledge/sources.d.ts +11 -2
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +19 -3
- package/dist/knowledge/sources.js.map +1 -1
- package/dist/knowledge/symbolEdges.d.ts +39 -0
- package/dist/knowledge/symbolEdges.d.ts.map +1 -0
- package/dist/knowledge/symbolEdges.js +71 -0
- package/dist/knowledge/symbolEdges.js.map +1 -0
- package/dist/knowledge/truncate.d.ts.map +1 -1
- package/dist/knowledge/truncate.js +4 -0
- package/dist/knowledge/truncate.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/exports.snapshot.json +34 -0
- package/src/contract/regression.contentHash.test.ts +30 -0
- package/src/contract/regression.lineage.test.ts +27 -0
- package/src/contract/regression.listing.test.ts +85 -0
- package/src/contract/regression.symbolEdges.test.ts +323 -0
- package/src/contract/symbolEdges.golden.json +345 -0
- package/src/contract/types.contract.test.ts +68 -1
- package/src/knowledge/build.ts +7 -2
- package/src/knowledge/comparability.analysis.test.ts +73 -0
- package/src/knowledge/comparability.test.ts +44 -0
- package/src/knowledge/comparability.ts +182 -0
- package/src/knowledge/contentHash.test.ts +81 -0
- package/src/knowledge/contentHash.ts +55 -0
- package/src/knowledge/extractFile.ts +4 -2
- package/src/knowledge/extractJob.ts +5 -3
- package/src/knowledge/findingBuilder.ts +17 -2
- package/src/knowledge/findingIdentity.test.ts +102 -0
- package/src/knowledge/findingIdentity.ts +92 -0
- package/src/knowledge/findingModel.ts +32 -0
- package/src/knowledge/findings.ts +17 -9
- package/src/knowledge/godModule.ts +2 -2
- package/src/knowledge/index.ts +22 -1
- package/src/knowledge/lineage.test.ts +106 -0
- package/src/knowledge/lineage.ts +123 -0
- package/src/knowledge/merkle.test.ts +137 -0
- package/src/knowledge/merkle.ts +164 -0
- package/src/knowledge/model.ts +22 -19
- package/src/knowledge/owedFiles.contentHash.test.ts +58 -0
- package/src/knowledge/owedFiles.ts +23 -5
- package/src/knowledge/pack/encode.ts +2 -1
- package/src/knowledge/pack/extrDiff.ts +4 -1
- package/src/knowledge/pack/sections/columns.ts +16 -1
- package/src/knowledge/pack/sections/extrLists.ts +2 -2
- package/src/knowledge/pack/sections/facts.ts +2 -2
- package/src/knowledge/pack/sections/index.ts +3 -1
- package/src/knowledge/pack/sections/rows.ts +1 -1
- package/src/knowledge/pack/sections/sites.ts +87 -0
- package/src/knowledge/pack/types.ts +2 -2
- package/src/knowledge/plan.ts +28 -6
- package/src/knowledge/refs.ts +10 -0
- package/src/knowledge/resolve.ts +2 -0
- package/src/knowledge/reviewModel.ts +8 -1
- package/src/knowledge/reviewPrefetch.ts +10 -6
- package/src/knowledge/sources.ts +22 -3
- package/src/knowledge/symbolEdges.ts +72 -0
- package/src/knowledge/truncate.ts +3 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/pack/sections/sites.ts — the SITE section of BFKP v1 (PRD 43 P0b, B1a rule 10): the call sites of the
|
|
3
|
+
* `calls` edges inside EXTR. EXTR is a CLOSED section (frame.ts), so `KEdge.sites` cannot be a new edge flag there:
|
|
4
|
+
* it travels here, as a NEW tag that a reader older than this release skips — it then decodes every edge, kind and
|
|
5
|
+
* weight unchanged and only the sites are absent.
|
|
6
|
+
*
|
|
7
|
+
* count varint · per edge that has sites: row varint · entry varint · edge varint · n varint · n × (path STR · line · column · order)
|
|
8
|
+
*
|
|
9
|
+
* `row` indexes the (normalized) `extracted` list, `entry` that row's entries, `edge` the entry's edges — for a diff
|
|
10
|
+
* entry, its `edges.add` items. Positions strictly increase in (row, entry, edge) order, so a site group is attached
|
|
11
|
+
* once. Read after EXTR (ROW_SECTIONS order).
|
|
12
|
+
*
|
|
13
|
+
* ADVISORY, never fatal: sites only draw a sequence, so a bad SITE section must not cost the pack it rides in. A read
|
|
14
|
+
* decodes the whole section into scratch first and attaches nothing when any part of it is malformed (a position EXTR
|
|
15
|
+
* did not decode, a repeat, an empty list, a bad string index, trailing bytes, the row budget) — the pack decodes as an
|
|
16
|
+
* older reader would see it, without sites. A write drops an invalid site (not a non-negative integer line/column/order,
|
|
17
|
+
* no string path) instead of refusing the pack. An empty `sites` list is not written (and so is absent after a decode).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { CallSite, ExtrEntryDiff, Extracted, KEdge, Pack } from '../types.js';
|
|
21
|
+
import { boundedCount, ByteReader, ByteWriter } from '../varint.js';
|
|
22
|
+
import type { SectionCodec } from './columns.js';
|
|
23
|
+
import { TAG } from './rows.js';
|
|
24
|
+
|
|
25
|
+
/** The edges of one entry, in wire order: a full entry's list, or a diff entry's added items. */
|
|
26
|
+
function edgesOf(row: NonNullable<Pack['extracted']>[number], entry: Extracted | ExtrEntryDiff): KEdge[] {
|
|
27
|
+
return row.kind === 'full' ? (entry as Extracted).edges : (entry as ExtrEntryDiff).edges.add.map((a) => a.item);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isCount = (n: unknown): n is number => typeof n === 'number' && Number.isInteger(n) && n >= 0 && n <= Number.MAX_SAFE_INTEGER;
|
|
31
|
+
|
|
32
|
+
/** A site the wire can carry. */
|
|
33
|
+
export const isValidSite = (s: CallSite): boolean =>
|
|
34
|
+
!!s && typeof s.path === 'string' && isCount(s.line) && isCount(s.column) && isCount(s.order);
|
|
35
|
+
|
|
36
|
+
export const siteSection: SectionCodec = {
|
|
37
|
+
tag: TAG.SITE,
|
|
38
|
+
write(pack, t) {
|
|
39
|
+
const groups: Array<{ row: number; entry: number; edge: number; sites: readonly CallSite[] }> = [];
|
|
40
|
+
(pack.extracted ?? []).forEach((row, ri) => {
|
|
41
|
+
row.entries.forEach((entry, ei) => {
|
|
42
|
+
edgesOf(row, entry).forEach((e, xi) => {
|
|
43
|
+
const sites = e.sites?.filter(isValidSite);
|
|
44
|
+
if (sites?.length) groups.push({ row: ri, entry: ei, edge: xi, sites });
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
if (groups.length === 0) return undefined;
|
|
49
|
+
const w = new ByteWriter();
|
|
50
|
+
w.varint(groups.length);
|
|
51
|
+
for (const g of groups) {
|
|
52
|
+
w.varint(g.row); w.varint(g.entry); w.varint(g.edge);
|
|
53
|
+
w.varint(g.sites.length);
|
|
54
|
+
for (const s of g.sites) { w.varint(t.str(s.path)); w.varint(s.line); w.varint(s.column); w.varint(s.order); }
|
|
55
|
+
}
|
|
56
|
+
return w.finish();
|
|
57
|
+
},
|
|
58
|
+
read(bytes, t, limits, into) {
|
|
59
|
+
const scratch: Array<{ edge: KEdge; sites: CallSite[] }> = [];
|
|
60
|
+
try {
|
|
61
|
+
const r = new ByteReader(bytes);
|
|
62
|
+
const n = boundedCount(r, limits.budget, 'call-site groups');
|
|
63
|
+
const rows = into.extracted ?? [];
|
|
64
|
+
let last: [number, number, number] = [-1, -1, -1];
|
|
65
|
+
for (let i = 0; i < n; i++) {
|
|
66
|
+
const ri = r.varint(), ei = r.varint(), xi = r.varint();
|
|
67
|
+
// (row, entry, edge) strictly increasing: a group is attached once, in order.
|
|
68
|
+
const after = ri > last[0] || (ri === last[0] && (ei > last[1] || (ei === last[1] && xi > last[2])));
|
|
69
|
+
if (!after) return;
|
|
70
|
+
last = [ri, ei, xi];
|
|
71
|
+
const row = rows[ri];
|
|
72
|
+
const entry = row?.entries[ei];
|
|
73
|
+
const edge = row && entry ? edgesOf(row, entry)[xi] : undefined;
|
|
74
|
+
if (!edge) return;
|
|
75
|
+
const count = boundedCount(r, limits.budget, 'call sites');
|
|
76
|
+
if (count === 0) return;
|
|
77
|
+
const sites: CallSite[] = [];
|
|
78
|
+
for (let s = 0; s < count; s++) sites.push({ path: t.str(r.varint()), line: r.varint(), column: r.varint(), order: r.varint() });
|
|
79
|
+
scratch.push({ edge, sites });
|
|
80
|
+
}
|
|
81
|
+
if (!r.done) return;
|
|
82
|
+
} catch {
|
|
83
|
+
return; // malformed: the pack decodes without sites
|
|
84
|
+
}
|
|
85
|
+
for (const { edge, sites } of scratch) edge.sites = sites;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `Extracted`, `ScopeRecord`), so a pack carries exactly what the single writer stores.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { Extracted, KEdge, KNode, NodeRef, ScopeRecord, StoredFact, StoredOrigin, StoredRelation } from '../model.js';
|
|
7
|
+
import type { CallSite, Extracted, KEdge, KNode, NodeRef, ScopeRecord, StoredFact, StoredOrigin, StoredRelation } from '../model.js';
|
|
8
8
|
import type { Budget } from './varint.js';
|
|
9
9
|
|
|
10
10
|
/** A reviewed file: its root-relative path, the hash its extracted output is keyed under, and its size. */
|
|
@@ -95,4 +95,4 @@ export class PackTooLargeError extends Error {
|
|
|
95
95
|
constructor(readonly limit: number) { super(`pack inflates past ${limit} bytes`); this.name = 'PackTooLargeError'; }
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
export type { Extracted, KEdge, KNode, NodeRef, ScopeRecord, StoredFact, StoredOrigin, StoredRelation };
|
|
98
|
+
export type { CallSite, Extracted, KEdge, KNode, NodeRef, ScopeRecord, StoredFact, StoredOrigin, StoredRelation };
|
package/src/knowledge/plan.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import type { IngestManifest } from '../ingest/types.js';
|
|
13
13
|
import type { DirectorySource, KnowledgePack, ReviewPlan } from './model.js';
|
|
14
|
+
import { canonicalListing, merkleTree, type MerkleTree } from './merkle.js';
|
|
14
15
|
import { carriedOwed, type ExtractorState, isOwed, loadExtractorState, owedCalls, withDocuments } from './owedFiles.js';
|
|
15
16
|
import {
|
|
16
17
|
claimedDocumentExts, compareManifestKey, composePacks, DEFAULT_MAX_FILE_BYTES, filesManifestKey, ignoreMatcher, ignoreSourcesOf,
|
|
@@ -64,8 +65,16 @@ export interface PlannedFile {
|
|
|
64
65
|
asset?: true;
|
|
65
66
|
/** 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
67
|
oversized?: true;
|
|
68
|
+
/**
|
|
69
|
+
* The source's own spelling of the path, when it differs from `path` (the normalized one: POSIX, NFC — an NFD name, a `\`).
|
|
70
|
+
* Reads go through it (`DirectorySource.read`, `readTimeoutMs`, `hashOf`, a pool read); identity, refs and the manifest use `path`.
|
|
71
|
+
*/
|
|
72
|
+
listedPath?: string;
|
|
67
73
|
}
|
|
68
74
|
|
|
75
|
+
/** `{ listedPath }` when the listing spelled the path otherwise, else nothing. */
|
|
76
|
+
const listedPathOf = (e: { listedPath?: string }): { listedPath?: string } => (e.listedPath !== undefined ? { listedPath: e.listedPath } : {});
|
|
77
|
+
|
|
69
78
|
export interface PlanDetail {
|
|
70
79
|
plan: ReviewPlan;
|
|
71
80
|
/** Every included file (changed and unchanged), sorted by path. */
|
|
@@ -76,6 +85,8 @@ export interface PlanDetail {
|
|
|
76
85
|
extractor: ExtractorState;
|
|
77
86
|
/** Owed paths the manifest holds that `files` does not list (ignored, no pack, an older plan, removed). */
|
|
78
87
|
carried: string[];
|
|
88
|
+
/** The directory Merkle tree over `files` (PRD 41 §B2 step 4): `plan.merkleRoot` is its root. Optional so a hand-built detail stays valid. */
|
|
89
|
+
merkle?: MerkleTree;
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
/** The ONE classification of a listed file: did its content move, is it owed, is it re-processed. */
|
|
@@ -102,12 +113,16 @@ export async function planDetail(
|
|
|
102
113
|
): Promise<PlanDetail> {
|
|
103
114
|
const maxBytes = opts.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES;
|
|
104
115
|
const listed: Array<{ path: string; hash: string; size: number }> = [];
|
|
105
|
-
for await (const entry of source.list()) listed.push(
|
|
106
|
-
|
|
116
|
+
for await (const entry of source.list()) listed.push(entry);
|
|
117
|
+
// The ONE normalization (POSIX, NFC) — so plan paths are Merkle paths — and a listing that cannot break the plan: invalid and
|
|
118
|
+
// colliding paths are skipped with a reason (merkle.ts canonicalListing), never thrown.
|
|
119
|
+
const listing = canonicalListing(listed);
|
|
120
|
+
const entries = sortBy(listing.kept, (e) => e.path);
|
|
121
|
+
const listedOf = new Map(entries.filter((e) => e.listedPath !== undefined).map((e) => [e.path, e.listedPath!] as const));
|
|
107
122
|
|
|
108
123
|
const ignoreTexts: Array<{ text: string; base: string }> = [];
|
|
109
124
|
for (const { path, base } of ignoreSourcesOf(entries.map((e) => e.path))) {
|
|
110
|
-
const doc = await source.read(path);
|
|
125
|
+
const doc = await source.read(listedOf.get(path) ?? path);
|
|
111
126
|
if (doc.content.kind === 'text') ignoreTexts.push({ text: doc.content.text, base });
|
|
112
127
|
}
|
|
113
128
|
const ignored = ignoreMatcher(ignoreTexts);
|
|
@@ -122,7 +137,7 @@ export async function planDetail(
|
|
|
122
137
|
const packById = new Map(packs.map((p) => [p.id, p] as const));
|
|
123
138
|
|
|
124
139
|
const files: PlannedFile[] = [];
|
|
125
|
-
const skipped: ReviewPlan['skipped'] = [];
|
|
140
|
+
const skipped: ReviewPlan['skipped'] = [...listing.skipped];
|
|
126
141
|
const byPack: Record<string, number> = {};
|
|
127
142
|
let assets = 0;
|
|
128
143
|
let estimatedSections = 0;
|
|
@@ -135,7 +150,10 @@ export async function planDetail(
|
|
|
135
150
|
if (document && e.size > maxBytes) oversized.add(e.path);
|
|
136
151
|
if (isAssetPath(e.path, !!document && e.size <= maxBytes)) {
|
|
137
152
|
const { owed, changed } = classify(extractor, prior, e.path, e.hash, opts.force === true);
|
|
138
|
-
files.push({
|
|
153
|
+
files.push({
|
|
154
|
+
path: e.path, hash: e.hash, size: e.size, pack: FALLBACK_PACK_ID, changed, owed, asset: true, ...listedPathOf(e),
|
|
155
|
+
...(document && e.size > maxBytes ? { oversized: true as const } : {}),
|
|
156
|
+
});
|
|
139
157
|
assets += 1;
|
|
140
158
|
continue;
|
|
141
159
|
}
|
|
@@ -143,7 +161,7 @@ export async function planDetail(
|
|
|
143
161
|
const hit = document ?? composed.resolve(stubSource(e.path));
|
|
144
162
|
if (!hit) { skipped.push({ path: e.path, reason: 'no-pack' }); continue; }
|
|
145
163
|
const { contentChanged, owed, changed } = classify(extractor, prior, e.path, e.hash, opts.force === true);
|
|
146
|
-
files.push({ path: e.path, hash: e.hash, size: e.size, pack: hit.pack.id, changed, owed });
|
|
164
|
+
files.push({ path: e.path, hash: e.hash, size: e.size, pack: hit.pack.id, changed, owed, ...listedPathOf(e) });
|
|
147
165
|
byPack[hit.pack.id] = (byPack[hit.pack.id] ?? 0) + 1;
|
|
148
166
|
const spec = packById.get(hit.pack.id)?.judgement;
|
|
149
167
|
if (spec && (spec.claims || spec.entities)) {
|
|
@@ -168,6 +186,7 @@ export async function planDetail(
|
|
|
168
186
|
const awaiting = compares ? (await manifestMap(manifest, compareManifestKey(source.rootId))).size : 0;
|
|
169
187
|
const compareCalls = compares ? Math.ceil((compareSections + awaiting) / SECTIONS_PER_COMPARE) : 0;
|
|
170
188
|
const sortedByPack = Object.fromEntries(Object.keys(byPack).sort(compareStr).map((k) => [k, byPack[k]!]));
|
|
189
|
+
const merkle = merkleTree(files);
|
|
171
190
|
return {
|
|
172
191
|
plan: {
|
|
173
192
|
rootId: source.rootId,
|
|
@@ -179,11 +198,13 @@ export async function planDetail(
|
|
|
179
198
|
removed,
|
|
180
199
|
skipped,
|
|
181
200
|
estimatedModelCalls: estimatedSections + compareCalls,
|
|
201
|
+
merkleRoot: merkle.root,
|
|
182
202
|
},
|
|
183
203
|
files,
|
|
184
204
|
prior,
|
|
185
205
|
extractor,
|
|
186
206
|
carried: carriedOwed(extractor, prior, files.map((f) => f.path)),
|
|
207
|
+
merkle,
|
|
187
208
|
};
|
|
188
209
|
}
|
|
189
210
|
|
|
@@ -210,5 +231,6 @@ export async function refreshPlan(detail: PlanDetail, manifest: IngestManifest):
|
|
|
210
231
|
prior,
|
|
211
232
|
extractor,
|
|
212
233
|
carried: carriedOwed(extractor, prior, files.map((f) => f.path)),
|
|
234
|
+
...(detail.merkle ? { merkle: detail.merkle } : {}),
|
|
213
235
|
};
|
|
214
236
|
}
|
package/src/knowledge/refs.ts
CHANGED
|
@@ -21,6 +21,16 @@ export function compareStr(a: string, b: string): number {
|
|
|
21
21
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/** The ONE root-relative path normalization (PRD 41 §B8.1): POSIX separators, no leading `./` or `/`, NFC. The plan and merkle.ts both use it. */
|
|
25
|
+
export function normalizePath(path: string): string {
|
|
26
|
+
return path.replace(/\\/g, '/').replace(/^(\.?\/)+/, '').normalize('NFC');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Whether a normalized path names a file under the root: non-empty, with no empty, `.` or `..` segment. */
|
|
30
|
+
export function isRootFilePath(path: string): boolean {
|
|
31
|
+
return path !== '' && path.split('/').every((s) => s !== '' && s !== '.' && s !== '..');
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
export function srcRef(rootId: string, path: string): NodeRef {
|
|
25
35
|
return `src:${rootId}::${path}`;
|
|
26
36
|
}
|
package/src/knowledge/resolve.ts
CHANGED
|
@@ -60,6 +60,8 @@ export function possibleSameFindings(pairs: readonly SimilarPair[], pack = FALLB
|
|
|
60
60
|
id, kind: 'possible-same', pack, nodes: [a as NodeRef, b as NodeRef], severity: 'info',
|
|
61
61
|
params: { similarity: round6(p.similarity) },
|
|
62
62
|
requestKey: 'knowledgeGraph.fix.possibleSame',
|
|
63
|
+
// Anchor (PRD 41 §C3): the sorted-first entity of the pair.
|
|
64
|
+
anchor: a, anchorKind: 'symbol',
|
|
63
65
|
});
|
|
64
66
|
}
|
|
65
67
|
return out.sort((x, y) => compareStr(x.id, y.id));
|
|
@@ -14,6 +14,10 @@ import type { ReviewFailure, ReviewPhase, ReviewStep } from './reviewRunModel.js
|
|
|
14
14
|
export interface DirectorySource {
|
|
15
15
|
rootId: string;
|
|
16
16
|
title: string;
|
|
17
|
+
/**
|
|
18
|
+
* The root's files. `read()` (and `hashOf`, `readTimeoutMs`) receive exactly the spelling `list()` yielded, so a source must not
|
|
19
|
+
* list paths that resolve outside its root (no leading `/`, no `..`).
|
|
20
|
+
*/
|
|
17
21
|
list(): AsyncIterable<{ path: string; hash: string; size: number }>;
|
|
18
22
|
/** `signal` aborts the read when the review gives up on it (a per-job timeout, a stop); a source that cannot cancel may ignore it. */
|
|
19
23
|
read(path: string, signal?: AbortSignal): Promise<SourceDocument>;
|
|
@@ -48,11 +52,14 @@ export interface ReviewPlan {
|
|
|
48
52
|
unchanged: number;
|
|
49
53
|
changed: string[];
|
|
50
54
|
removed: string[];
|
|
51
|
-
|
|
55
|
+
/** `invalid-path` (empty, `.` or `..` segment) and `duplicate-path` (collides with another once normalized) carry the source's own spelling. */
|
|
56
|
+
skipped: Array<{ path: string; reason: 'ignored' | 'too-large' | 'no-pack' | 'invalid-path' | 'duplicate-path' }>;
|
|
52
57
|
/** ≈ judgement calls for changed files (sections of judged kinds). */
|
|
53
58
|
estimatedModelCalls: number;
|
|
54
59
|
/** 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. */
|
|
55
60
|
judgeFiles?: number;
|
|
61
|
+
/** The directory Merkle root over the planned files (PRD 41 §B2 step 4, knowledge/merkle.ts): an equal root means an equal listing. Absent on a plan from an older host. */
|
|
62
|
+
merkleRoot?: string;
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
export interface ReviewProgress {
|
|
@@ -67,8 +67,8 @@ export { CHANGED_SINCE_PLAN };
|
|
|
67
67
|
export const DEFAULT_READ_TIMEOUT_MS = 5_000;
|
|
68
68
|
export const DEFAULT_EXTRACT_TIMEOUT_MS = 10_000;
|
|
69
69
|
|
|
70
|
-
/** A changed file as the prefetch sees it: a `PlannedFile`'s path, hash, size and
|
|
71
|
-
export type PrefetchFile = { path: string; hash: string; size: number; asset?: true };
|
|
70
|
+
/** A changed file as the prefetch sees it: a `PlannedFile`'s path, hash, size, asset flag and the source's own spelling (reads use it). */
|
|
71
|
+
export type PrefetchFile = { path: string; hash: string; size: number; asset?: true; listedPath?: string };
|
|
72
72
|
|
|
73
73
|
export function createPrefetch(c: PrefetchContext): (f: PrefetchFile) => Promise<Prefetch> {
|
|
74
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
|
|
@@ -95,8 +95,10 @@ export function createPrefetch(c: PrefetchContext): (f: PrefetchFile) => Promise
|
|
|
95
95
|
if (f.asset) return { kind: 'asset' };
|
|
96
96
|
let doc: SourceDocument | undefined;
|
|
97
97
|
const t0 = Date.now();
|
|
98
|
+
// The source's own spelling opens the file; `f.path` (normalized) is its identity.
|
|
99
|
+
const readPath = f.listedPath ?? f.path;
|
|
98
100
|
if (!byPool) {
|
|
99
|
-
try { doc = await withDeadline(readMsOf(
|
|
101
|
+
try { doc = await withDeadline(readMsOf(readPath), (signal) => c.args.source.read(readPath, signal)); } catch (error) {
|
|
100
102
|
return { kind: 'read-error', reason: reasonOf(error) };
|
|
101
103
|
}
|
|
102
104
|
parts.readMs = Date.now() - t0;
|
|
@@ -105,11 +107,13 @@ export function createPrefetch(c: PrefetchContext): (f: PrefetchFile) => Promise
|
|
|
105
107
|
if (doc && doc.content.kind === 'text' && isBinaryText(doc.content.text)) return { kind: 'binary' };
|
|
106
108
|
const extraction = await extractSlots.run(async () => {
|
|
107
109
|
held.lane = lanes.take();
|
|
108
|
-
try { return await withDeadline(byPool ? extractMs + (readOverrideOf(
|
|
110
|
+
try { return await withDeadline(byPool ? extractMs + (readOverrideOf(readPath) ?? 0) : extractMs,(signal) => extractFileDetailed({
|
|
109
111
|
rootId: c.rootId, path: f.path, hash: f.hash, ...(doc ? { doc } : {}), packs: c.packs, store: c.store, composed: c.composed,
|
|
110
112
|
knownKeys: c.knownKeys, writeCache: false,
|
|
111
113
|
onTiming: (t) => { parts.lookupMs = t.lookupMs; parts.poolMs = t.poolMs; },
|
|
112
|
-
...(c.args.extractPool ? { pool: c.args.extractPool, signal, wantsSections, ...(byPool ? {
|
|
114
|
+
...(c.args.extractPool ? { pool: c.args.extractPool, signal, wantsSections, ...(byPool ? {
|
|
115
|
+
readByPool: true, ...(f.listedPath !== undefined ? { readPath } : {}), ...(readOverrideOf(readPath) ? { readMs: readOverrideOf(readPath)! } : {}),
|
|
116
|
+
} : {}) } : {}),
|
|
113
117
|
})); } finally { lanes.free(held.lane); }
|
|
114
118
|
}, byPool ? c.signal : undefined);
|
|
115
119
|
if (!extraction) return { kind: 'none' };
|
|
@@ -117,7 +121,7 @@ export function createPrefetch(c: PrefetchContext): (f: PrefetchFile) => Promise
|
|
|
117
121
|
// stored, the bytes read must be the bytes planned: hashed once, from the text already in hand. The review writes the
|
|
118
122
|
// extract cache only for an 'extracted' job, so nothing is stored under the stale hash.
|
|
119
123
|
const hashOf = c.args.source.hashOf;
|
|
120
|
-
if (hashOf && doc && doc.content.kind === 'text' && hashOf.call(c.args.source, doc.content.text,
|
|
124
|
+
if (hashOf && doc && doc.content.kind === 'text' && hashOf.call(c.args.source, doc.content.text, readPath) !== f.hash) return { kind: 'failed', reason: CHANGED_SINCE_PLAN, transient: true };
|
|
121
125
|
return { kind: 'extracted', ...(doc ? { doc } : {}), extraction };
|
|
122
126
|
} catch (error) {
|
|
123
127
|
if (error instanceof BinaryContent) return { kind: 'binary' };
|
package/src/knowledge/sources.ts
CHANGED
|
@@ -21,7 +21,8 @@ export const DEFAULT_MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
|
21
21
|
* re-extraction (judged sections with unchanged text are re-anchored, not judged again; see
|
|
22
22
|
* owedFiles.ts for how an unfinished one is carried to the next review).
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
// 5 (2026-11-10, PRD 43 P0b): the code pack's file nodes carry the file→file rollup of the symbol-level edge kinds.
|
|
25
|
+
export const EXTRACTOR_VERSION = 5;
|
|
25
26
|
/**
|
|
26
27
|
* Always ignored: VCS internals, installed dependencies, builderforce config, and lockfiles (`yarn.lock`, `Cargo.lock` …): generated,
|
|
27
28
|
* huge, and plain text — extracted they would cost judgement calls for nothing; they were never stored (once skipped as binary).
|
|
@@ -121,9 +122,27 @@ export function claimedDocumentExts(composed: ComposedPacks): string {
|
|
|
121
122
|
return [...DOCUMENT_EXT].filter((ext) => resolveDocument(composed, `x.${ext}`)).sort(compareStr).join(',') || '-';
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
/**
|
|
125
|
+
/** How far the binary sniff looks, in BYTES: a NUL (0x00) among the file's first 8192 bytes means binary. */
|
|
126
|
+
const BINARY_SNIFF_BYTES = 8192;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* THE binary rule, whatever the extension said: a 0 byte among the first {@link BINARY_SNIFF_BYTES} bytes. contentHash.ts sniffs raw
|
|
130
|
+
* bytes with it; {@link isBinaryText} applies it to decoded text.
|
|
131
|
+
*/
|
|
132
|
+
export function isBinaryBytes(bytes: Uint8Array): boolean {
|
|
133
|
+
return bytes.subarray(0, BINARY_SNIFF_BYTES).includes(0);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const utf8 = new TextEncoder();
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* {@link isBinaryBytes} over decoded text: whether the text's UTF-8 bytes hold a NUL among their first 8192. UTF-8 encodes only
|
|
140
|
+
* U+0000 as a 0 byte, and every code unit takes at least one byte, so only a NUL within the first 8192 code units can qualify;
|
|
141
|
+
* its byte offset is the UTF-8 length of the text before it.
|
|
142
|
+
*/
|
|
125
143
|
export function isBinaryText(text: string): boolean {
|
|
126
|
-
|
|
144
|
+
const at = text.slice(0, BINARY_SNIFF_BYTES).indexOf('\u0000');
|
|
145
|
+
return at >= 0 && utf8.encode(text.slice(0, at)).length < BINARY_SNIFF_BYTES;
|
|
127
146
|
}
|
|
128
147
|
|
|
129
148
|
/** A read source with its id set to the root-relative path and a media type filled in. */
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/symbolEdges.ts — the symbol-level relationship vocabulary (PRD 43 P0b, B1a rules 9–10): what a code
|
|
3
|
+
* pack's extractor says between two SYMBOLS (a class, an interface, a function, a method), beside the file-level
|
|
4
|
+
* kinds (`references`, `contains` …). Generic: memory names the kinds and their call-site shape; which language
|
|
5
|
+
* construct counts as which kind is the code pack's business.
|
|
6
|
+
*
|
|
7
|
+
* extends class/interface → the base it extends
|
|
8
|
+
* implements class → an interface it implements
|
|
9
|
+
* composes class → a class it holds as a field / property / constructor parameter property (composition, aggregation)
|
|
10
|
+
* uses symbol → a type it names in a signature or body (none of the above)
|
|
11
|
+
* calls function/method → a function/method it calls; carries its call {@link CallSite}s in source order
|
|
12
|
+
*
|
|
13
|
+
* A target outside the root (a package, a file not extracted) is still a `src:` ref, so `buildGraph` closes it as a
|
|
14
|
+
* `missing` placeholder, exactly as an unresolved import is.
|
|
15
|
+
*
|
|
16
|
+
* Bounded: {@link dedupeSymbolEdges} keeps ONE edge per (from, to, kind) — repeated calls become extra sites on it —
|
|
17
|
+
* and at most {@link MAX_SYMBOL_EDGES_PER_SYMBOL} edges and {@link MAX_CALL_SITES_PER_EDGE} sites per edge.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { CallSite, KEdge } from './model.js';
|
|
21
|
+
|
|
22
|
+
export const SYMBOL_EDGE_KINDS = ['extends', 'implements', 'composes', 'uses', 'calls'] as const;
|
|
23
|
+
export type SymbolEdgeKind = (typeof SYMBOL_EDGE_KINDS)[number];
|
|
24
|
+
|
|
25
|
+
/** Edges one symbol may start (all kinds together): a generated or god function must not flood the graph. */
|
|
26
|
+
export const MAX_SYMBOL_EDGES_PER_SYMBOL = 64;
|
|
27
|
+
/** Call sites kept on one `calls` edge (the lowest `order`s): a call in a hot loop body is a handful of sites, not hundreds. */
|
|
28
|
+
export const MAX_CALL_SITES_PER_EDGE = 16;
|
|
29
|
+
|
|
30
|
+
export const isSymbolEdgeKind = (kind: string): kind is SymbolEdgeKind => (SYMBOL_EDGE_KINDS as readonly string[]).includes(kind);
|
|
31
|
+
|
|
32
|
+
/** Sites in source order: by `order`, then position (a well-formed list already is). */
|
|
33
|
+
export const compareCallSites = (a: CallSite, b: CallSite): number =>
|
|
34
|
+
a.order - b.order || (a.path < b.path ? -1 : a.path > b.path ? 1 : 0) || a.line - b.line || a.column - b.column;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* ONE edge per (from, to, kind): weights take the max, sites merge (sorted by {@link compareCallSites}, capped at
|
|
38
|
+
* `maxSites`). Edges of a `from` past `maxPerSymbol` are dropped — the first ones kept, in input order, so an
|
|
39
|
+
* extractor that emits a body's relations in source order keeps the earliest. Non-symbol kinds pass through unchanged
|
|
40
|
+
* and uncounted. Order of the result: first appearance. Pure.
|
|
41
|
+
*/
|
|
42
|
+
export function dedupeSymbolEdges(
|
|
43
|
+
edges: readonly KEdge[], opts: { maxPerSymbol?: number; maxSites?: number } = {},
|
|
44
|
+
): KEdge[] {
|
|
45
|
+
const maxPerSymbol = opts.maxPerSymbol ?? MAX_SYMBOL_EDGES_PER_SYMBOL;
|
|
46
|
+
const maxSites = opts.maxSites ?? MAX_CALL_SITES_PER_EDGE;
|
|
47
|
+
const out: KEdge[] = [];
|
|
48
|
+
const byId = new Map<string, KEdge>();
|
|
49
|
+
const perFrom = new Map<string, number>();
|
|
50
|
+
for (const e of edges) {
|
|
51
|
+
if (!isSymbolEdgeKind(e.kind)) { out.push(e); continue; }
|
|
52
|
+
const id = `${e.from}\u0000${e.to}\u0000${e.kind}`;
|
|
53
|
+
const prior = byId.get(id);
|
|
54
|
+
if (prior) {
|
|
55
|
+
prior.weight = Math.max(prior.weight, e.weight);
|
|
56
|
+
if (e.sites?.length) prior.sites = [...(prior.sites ?? []), ...e.sites];
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const n = perFrom.get(e.from) ?? 0;
|
|
60
|
+
if (n >= maxPerSymbol) continue;
|
|
61
|
+
perFrom.set(e.from, n + 1);
|
|
62
|
+
const copy: KEdge = { ...e, ...(e.sites ? { sites: [...e.sites] } : {}) };
|
|
63
|
+
byId.set(id, copy);
|
|
64
|
+
out.push(copy);
|
|
65
|
+
}
|
|
66
|
+
for (const e of out) {
|
|
67
|
+
if (!e.sites) continue;
|
|
68
|
+
if (e.sites.length === 0) { delete e.sites; continue; }
|
|
69
|
+
e.sites = e.sites.sort(compareCallSites).slice(0, maxSites);
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import type { EdgeVerdict, KEdge, KNode, KnowledgeGraph, NodeRef } from './model.js';
|
|
11
11
|
import { areaImportance, byImportanceAssetsLast } from './importance.js';
|
|
12
12
|
import { aboutTargets, compareStr, FALLBACK_PACK_ID, pathOfRef, srcRef } from './refs.js';
|
|
13
|
+
import { isSymbolEdgeKind } from './symbolEdges.js';
|
|
13
14
|
|
|
14
15
|
/** Hard cap on nodes, however many the keep rules ask for. */
|
|
15
16
|
export const TRUNCATION_HARD_CAP = 2000;
|
|
@@ -33,7 +34,8 @@ export function truncateGraph(g: KnowledgeGraph, opts: TruncateOptions): { nodes
|
|
|
33
34
|
if (!s) neighbours.set(a, (s = new Set()));
|
|
34
35
|
s.add(b);
|
|
35
36
|
};
|
|
36
|
-
|
|
37
|
+
// A symbol-level edge restates its file's import (the code pack's rollup): it never earns a neighbour a slot.
|
|
38
|
+
for (const e of g.edges) { if (isSymbolEdgeKind(e.kind)) continue; link(e.from, e.to); link(e.to, e.from); }
|
|
37
39
|
|
|
38
40
|
const kept: NodeRef[] = [];
|
|
39
41
|
const keptSet = new Set<NodeRef>();
|