@seanhogg/builderforce-memory 2026.10.68 → 2026.10.70
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 +3 -1
- package/dist/knowledge/comparability.d.ts.map +1 -1
- package/dist/knowledge/comparability.js +2 -1
- package/dist/knowledge/comparability.js.map +1 -1
- package/dist/knowledge/index.d.ts +3 -2
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +2 -1
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/model.d.ts +17 -1
- package/dist/knowledge/model.d.ts.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/sources.d.ts +1 -1
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +2 -1
- 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 +7 -0
- package/src/contract/regression.analysisTruncated.test.ts +32 -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 +15 -2
- package/src/knowledge/build.ts +7 -2
- package/src/knowledge/comparability.analysis.test.ts +16 -1
- package/src/knowledge/comparability.ts +4 -1
- package/src/knowledge/index.ts +6 -2
- package/src/knowledge/model.ts +18 -1
- 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/sources.ts +2 -1
- 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/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).
|
|
@@ -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>();
|