@seanhogg/builderforce-memory 2026.10.39 → 2026.10.41
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/ingest/docsExtract.d.ts +10 -0
- package/dist/ingest/docsExtract.d.ts.map +1 -1
- package/dist/ingest/docsExtract.js +48 -4
- package/dist/ingest/docsExtract.js.map +1 -1
- package/dist/ingest/fences.d.ts +15 -0
- package/dist/ingest/fences.d.ts.map +1 -0
- package/dist/ingest/fences.js +46 -0
- package/dist/ingest/fences.js.map +1 -0
- package/dist/ingest/textParsers.d.ts.map +1 -1
- package/dist/ingest/textParsers.js +8 -7
- package/dist/ingest/textParsers.js.map +1 -1
- package/dist/knowledge/build.d.ts.map +1 -1
- package/dist/knowledge/build.js +3 -0
- package/dist/knowledge/build.js.map +1 -1
- package/dist/knowledge/index.d.ts +2 -1
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +1 -0
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/model.d.ts +41 -0
- package/dist/knowledge/model.d.ts.map +1 -1
- package/dist/knowledge/outline.d.ts +23 -0
- package/dist/knowledge/outline.d.ts.map +1 -0
- package/dist/knowledge/outline.js +103 -0
- package/dist/knowledge/outline.js.map +1 -0
- package/dist/knowledge/sources.d.ts +1 -1
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +6 -2
- package/dist/knowledge/sources.js.map +1 -1
- package/package.json +3 -3
- package/src/ingest/docsExtract.ts +43 -4
- package/src/ingest/fences.ts +45 -0
- package/src/ingest/textParsers.ts +8 -6
- package/src/knowledge/build.ts +3 -0
- package/src/knowledge/index.ts +4 -1
- package/src/knowledge/model.ts +43 -0
- package/src/knowledge/outline.test.ts +163 -0
- package/src/knowledge/outline.ts +108 -0
- package/src/knowledge/scripts.test.ts +125 -0
- package/src/knowledge/sources.ts +7 -2
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/outline.ts — the whole graph's files and file-to-file references, kept when the
|
|
3
|
+
* graph is truncated so an overview (stations, layers, lines) never depends on which nodes
|
|
4
|
+
* the cut kept. Built from the FULL graph; everything is sorted, so equal input is byte-identical.
|
|
5
|
+
*/
|
|
6
|
+
import { byImportance } from './importance.js';
|
|
7
|
+
import { compareStr, fileRefOf } from './refs.js';
|
|
8
|
+
export const OUTLINE_MAX_FILES = 20000;
|
|
9
|
+
export const OUTLINE_MAX_LINKS = 60000;
|
|
10
|
+
/**
|
|
11
|
+
* The only badges an outline file carries. Mirrors agent-tools' CODE_BADGES plus the live-overlay
|
|
12
|
+
* badges (added/removed/status); memory cannot import agent-tools, so the list is kept here.
|
|
13
|
+
*/
|
|
14
|
+
export const OUTLINE_BADGE_KEYS = [
|
|
15
|
+
'complexity', 'maxComplexity', 'coverage', 'churn', 'owner', 'patterns', 'cloneGroup', 'unused', 'unusedExports',
|
|
16
|
+
'entry', 'layerRule', 'unusedDependencies', 'added', 'removed', 'changed', 'status',
|
|
17
|
+
];
|
|
18
|
+
/** Verdict codes of a link, least to worst; code 0 is "no verdict". */
|
|
19
|
+
export const OUTLINE_VERDICTS = ['none', 'same', 'allowed', 'skips', 'upward'];
|
|
20
|
+
/** Bit 1 of a link's flags. */
|
|
21
|
+
export const OUTLINE_FLAG_CYCLE = 1;
|
|
22
|
+
const HASH_CHARS = 12;
|
|
23
|
+
/** The ref of an outline file. */
|
|
24
|
+
export function outlineRef(o, f) {
|
|
25
|
+
return (o.prefix + f.path);
|
|
26
|
+
}
|
|
27
|
+
/** The ONE entry point for consumers: the attached outline of a truncated graph, else one built from the graph itself. */
|
|
28
|
+
export function outlineOf(g) {
|
|
29
|
+
return g.outline ?? buildOutline(g);
|
|
30
|
+
}
|
|
31
|
+
function commonPrefix(refs) {
|
|
32
|
+
const first = refs[0];
|
|
33
|
+
if (first === undefined)
|
|
34
|
+
return '';
|
|
35
|
+
const sep = first.indexOf('::');
|
|
36
|
+
if (sep < 0)
|
|
37
|
+
return '';
|
|
38
|
+
const prefix = first.slice(0, sep + 2);
|
|
39
|
+
return refs.every((r) => r.startsWith(prefix)) ? prefix : '';
|
|
40
|
+
}
|
|
41
|
+
export function buildOutline(full) {
|
|
42
|
+
let capped = false;
|
|
43
|
+
let fileNodes = full.nodes.filter((n) => n.kind === 'file');
|
|
44
|
+
if (fileNodes.length > OUTLINE_MAX_FILES) {
|
|
45
|
+
fileNodes = [...fileNodes].sort(byImportance).slice(0, OUTLINE_MAX_FILES);
|
|
46
|
+
capped = true;
|
|
47
|
+
}
|
|
48
|
+
fileNodes = [...fileNodes].sort((a, b) => compareStr(a.ref, b.ref));
|
|
49
|
+
const prefix = commonPrefix(fileNodes.map((n) => n.ref));
|
|
50
|
+
const areas = [...new Set(fileNodes.flatMap((n) => (n.area !== undefined ? [n.area] : [])))].sort(compareStr);
|
|
51
|
+
const partitions = [...new Set(fileNodes.flatMap((n) => (n.partition !== undefined ? [n.partition] : [])))].sort(compareStr);
|
|
52
|
+
const areaIndex = new Map(areas.map((a, i) => [a, i]));
|
|
53
|
+
const partitionIndex = new Map(partitions.map((p, i) => [p, i]));
|
|
54
|
+
const files = fileNodes.map((n) => {
|
|
55
|
+
const badges = {};
|
|
56
|
+
for (const k of OUTLINE_BADGE_KEYS) {
|
|
57
|
+
const v = n.badges?.[k];
|
|
58
|
+
if (v !== undefined)
|
|
59
|
+
badges[k] = v;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
path: n.ref.slice(prefix.length),
|
|
63
|
+
...(n.area !== undefined ? { area: areaIndex.get(n.area) } : {}),
|
|
64
|
+
...(n.partition !== undefined ? { partition: partitionIndex.get(n.partition) } : {}),
|
|
65
|
+
importance: n.importance,
|
|
66
|
+
...(n.sourceHash !== undefined ? { hash: n.sourceHash.slice(0, HASH_CHARS) } : {}),
|
|
67
|
+
...(Object.keys(badges).length > 0 ? { badges } : {}),
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
const index = new Map(fileNodes.map((n, i) => [n.ref, i]));
|
|
71
|
+
const merged = new Map();
|
|
72
|
+
for (const e of full.edges) {
|
|
73
|
+
if (e.kind !== 'references')
|
|
74
|
+
continue;
|
|
75
|
+
const from = index.get(fileRefOf(e.from));
|
|
76
|
+
const to = index.get(fileRefOf(e.to));
|
|
77
|
+
if (from === undefined || to === undefined || from === to)
|
|
78
|
+
continue;
|
|
79
|
+
const key = `${from}>${to}`;
|
|
80
|
+
const verdict = e.verdict === undefined ? 0 : OUTLINE_VERDICTS.indexOf(e.verdict);
|
|
81
|
+
const hit = merged.get(key);
|
|
82
|
+
if (hit) {
|
|
83
|
+
hit.verdict = Math.max(hit.verdict, verdict);
|
|
84
|
+
hit.cycle ||= e.cycle === true;
|
|
85
|
+
hit.weight += e.weight ?? 0;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
merged.set(key, { from, to, verdict, cycle: e.cycle === true, weight: e.weight ?? 0 });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
let list = [...merged.values()];
|
|
92
|
+
if (list.length > OUTLINE_MAX_LINKS) {
|
|
93
|
+
const imp = (m) => fileNodes[m.from].importance + fileNodes[m.to].importance;
|
|
94
|
+
list = list
|
|
95
|
+
.sort((a, b) => b.weight - a.weight || imp(b) - imp(a) || a.from - b.from || a.to - b.to)
|
|
96
|
+
.slice(0, OUTLINE_MAX_LINKS);
|
|
97
|
+
capped = true;
|
|
98
|
+
}
|
|
99
|
+
list.sort((a, b) => a.from - b.from || a.to - b.to);
|
|
100
|
+
const links = list.map((m) => [m.from, m.to, m.verdict, m.cycle ? OUTLINE_FLAG_CYCLE : 0]);
|
|
101
|
+
return { prefix, areas, partitions, files, links, capped };
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=outline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outline.js","sourceRoot":"","sources":["../../src/knowledge/outline.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO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AC,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;aACxF,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;QACjC,MAAM,GAAG,IAAI,CAAC;IAClB,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAqC,CAAC,CAAC;IAC/H,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC/D,CAAC"}
|
|
@@ -15,7 +15,7 @@ export declare const DEFAULT_MAX_FILE_BYTES: number;
|
|
|
15
15
|
* re-extraction (judged sections with unchanged text are re-anchored, not judged again; see
|
|
16
16
|
* owedFiles.ts for how an unfinished one is carried to the next review).
|
|
17
17
|
*/
|
|
18
|
-
export declare const EXTRACTOR_VERSION =
|
|
18
|
+
export declare const EXTRACTOR_VERSION = 2;
|
|
19
19
|
export declare function mediaTypeOfPath(path: string): string;
|
|
20
20
|
/** By extension — the plan never reads a file to decide. (pdf/office text needs a host extractor.) */
|
|
21
21
|
export declare function isBinaryPath(path: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../src/knowledge/sources.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAA8B,cAAc,EAAmB,MAAM,sBAAsB,CAAC;A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E,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5H;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGxF"}
|
|
@@ -17,7 +17,7 @@ export const DEFAULT_MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
|
17
17
|
* re-extraction (judged sections with unchanged text are re-anchored, not judged again; see
|
|
18
18
|
* owedFiles.ts for how an unfinished one is carried to the next review).
|
|
19
19
|
*/
|
|
20
|
-
export const EXTRACTOR_VERSION =
|
|
20
|
+
export const EXTRACTOR_VERSION = 2;
|
|
21
21
|
/** Always ignored: VCS internals, installed dependencies, builderforce config. */
|
|
22
22
|
const DEFAULT_IGNORES = ['.git/', 'node_modules/', '.builderforce/', '.gitignore'];
|
|
23
23
|
const MEDIA_TYPES = {
|
|
@@ -45,6 +45,8 @@ const BINARY_EXT = new Set([
|
|
|
45
45
|
'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp',
|
|
46
46
|
'ttf', 'otf', 'woff', 'woff2', 'eot', 'sqlite', 'db', 'vsix', 'lock',
|
|
47
47
|
]);
|
|
48
|
+
/** Shell and batch scripts are code, never documents (their `[[ … ]]` tests are not links). */
|
|
49
|
+
const SCRIPT_EXT = new Set(['sh', 'bash', 'zsh', 'ps1', 'bat', 'cmd']);
|
|
48
50
|
const extOf = (path) => {
|
|
49
51
|
const m = /\.([A-Za-z0-9]+)$/.exec(path);
|
|
50
52
|
return m ? m[1].toLowerCase() : '';
|
|
@@ -90,7 +92,9 @@ const BUILTIN_TEXT_PARSERS = new Set([markdownParser, htmlParser, plainTextParse
|
|
|
90
92
|
* types; a host-registered parser (any pack, any order) is untouched. The ingest pipeline
|
|
91
93
|
* keeps the builtins as they are.
|
|
92
94
|
*/
|
|
93
|
-
const guardBuiltin = (p) => BUILTIN_TEXT_PARSERS.has(p)
|
|
95
|
+
const guardBuiltin = (p) => BUILTIN_TEXT_PARSERS.has(p)
|
|
96
|
+
? { ...p, accepts: (s) => !SCRIPT_EXT.has(extOf(s.id)) && !isBinaryDocumentType(mediaTypeOf(s)) && p.accepts(s) }
|
|
97
|
+
: p;
|
|
94
98
|
export function composePacks(packs) {
|
|
95
99
|
const owner = new Map();
|
|
96
100
|
const guarded = new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sources.js","sourceRoot":"","sources":["../../src/knowledge/sources.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAmE,MAAM,oBAAoB,CAAC;AAEzH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAErD,yCAAyC;AACzC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACtD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,kFAAkF;AAClF,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAEnF,MAAM,WAAW,GAA2B;IACxC,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,EAAE,eAAe;IACpE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,uBAAuB,EAAE,GAAG,EAAE,iBAAiB;IAC3F,IAAI,EAAE,kBAAkB,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,2BAA2B;IAC3E,GAAG,EAAE,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,CAAC,CAAC;IACpG,MAAM,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAgB,EAAE,MAAc;IAChE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzD,OAAO,GAAG,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seanhogg/builderforce-memory",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.41",
|
|
4
4
|
"description": "BuilderForce Agent Memory — runtime layer. SSM execution, Transformer orchestration, online distillation, enterprise RAG (ingestion pipelines, vector-store adapters, tenant/ACL-scoped hybrid retrieval), multi-agent graph orchestration, LLM telemetry and cost accounting, persistent agent memory, and token-saving agent-run memory (code maps, a prompt-cache-safe working memory, chunked transcript windowing) for BuilderForce.ai agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
},
|
|
114
114
|
"homepage": "https://github.com/SeanHogg/builderforce-memory/tree/main/packages/memory#readme",
|
|
115
115
|
"peerDependencies": {
|
|
116
|
-
"@seanhogg/builderforce-memory-engine": "^2026.10.
|
|
116
|
+
"@seanhogg/builderforce-memory-engine": "^2026.10.41"
|
|
117
117
|
},
|
|
118
118
|
"devDependencies": {
|
|
119
119
|
"@jest/globals": "^29.7.0",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"ts-jest": "^29.2.0",
|
|
128
128
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
129
129
|
"typescript-7": "npm:typescript@^7.0.2",
|
|
130
|
-
"@seanhogg/builderforce-memory-engine": "2026.10.
|
|
130
|
+
"@seanhogg/builderforce-memory-engine": "2026.10.41"
|
|
131
131
|
},
|
|
132
132
|
"jest": {
|
|
133
133
|
"preset": "ts-jest/presets/default-esm",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import type { ExtractContext, Extracted, KEdge, KNode, NodeRef } from '../knowledge/model.js';
|
|
26
26
|
import { basenameOf, compareStr, normalizeKey, slugOf, srcRef, walkRelative } from '../knowledge/refs.js';
|
|
27
|
+
import { fenceMask, isListItemLine } from './fences.js';
|
|
27
28
|
import { hashText } from './hash.js';
|
|
28
29
|
import { CONTENT_HASH_FIELD, type ParsedSection, type SourceDocument } from './types.js';
|
|
29
30
|
|
|
@@ -106,7 +107,7 @@ class ExtractBuilder {
|
|
|
106
107
|
if (dest !== this.path) this.edge(from, srcRef(this.ctx.rootId, dest), 'links', byName);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
/** `[[Name]]
|
|
110
|
+
/** `[[Name]]` (in text already stripped of code by the caller): beside the linking file here; `buildGraph` re-points a bare name to the unique file of that name. */
|
|
110
111
|
wikiLinks(from: NodeRef, text: string): void {
|
|
111
112
|
for (const m of text.matchAll(/\[\[([^\]|#]+)(?:#[^\]|]*)?(?:\|[^\]]*)?\]\]/g)) {
|
|
112
113
|
const name = m[1]!.trim();
|
|
@@ -196,6 +197,43 @@ function capSectionSlug(slugPath: string, fileRef: NodeRef): string {
|
|
|
196
197
|
return `${slugPath.slice(0, Math.max(1, budget - discriminator.length - 1))}~${discriminator}`;
|
|
197
198
|
}
|
|
198
199
|
|
|
200
|
+
/** An inline code span: an exact-length backtick run to the same run, never across a blank line. */
|
|
201
|
+
const INLINE_CODE = /(?<!`)(`+)(?!`)(?:(?!\n[ \t]*\r?\n)[\s\S])*?(?<!`)\1(?!`)/g;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Markdown text with fenced blocks, indented code blocks and inline code blanked, so shell
|
|
205
|
+
* `[[ -f x ]]` tests and links inside code are never read as links. Fences come from the
|
|
206
|
+
* ONE scanner the parser also uses. An indented line is code only after a blank line, a
|
|
207
|
+
* heading or a fence, and never while continuing a list item; `indented: false` (plain text)
|
|
208
|
+
* skips that rule.
|
|
209
|
+
*/
|
|
210
|
+
export function withoutCode(text: string, opts: { indented?: boolean } = {}): string {
|
|
211
|
+
const indented = opts.indented !== false;
|
|
212
|
+
const lines = text.split('\n');
|
|
213
|
+
const fenced = fenceMask(lines);
|
|
214
|
+
const out: string[] = [];
|
|
215
|
+
let prevBlank = true;
|
|
216
|
+
let inCode = false;
|
|
217
|
+
let inList = false;
|
|
218
|
+
lines.forEach((line, i) => {
|
|
219
|
+
if (fenced[i]) { out.push(''); prevBlank = true; inCode = false; return; }
|
|
220
|
+
const blank = line.trim() === '';
|
|
221
|
+
const indent = /^(?: {4}|\t)/.test(line);
|
|
222
|
+
if (indented && indent && !blank && !inList && (prevBlank || inCode)) {
|
|
223
|
+
inCode = true;
|
|
224
|
+
out.push('');
|
|
225
|
+
prevBlank = false;
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
inCode = false;
|
|
229
|
+
if (isListItemLine(line)) inList = true;
|
|
230
|
+
else if (!blank && !/^[ \t]/.test(line)) inList = false;
|
|
231
|
+
prevBlank = blank;
|
|
232
|
+
out.push(line);
|
|
233
|
+
});
|
|
234
|
+
return out.join('\n').replace(INLINE_CODE, ' ');
|
|
235
|
+
}
|
|
236
|
+
|
|
199
237
|
const MD_LINK = /(?<!!)\[[^\]]*\]\(\s*<?([^)\s>]+)>?(?:\s+"[^"]*")?\s*\)/g;
|
|
200
238
|
/** `[id]: target` definitions (reference-style links); the use is `[text][id]` or `[id][]`. */
|
|
201
239
|
const MD_REF_DEF = /^ {0,3}\[([^\]]+)\]:\s*<?(\S+?)>?(?:\s+["'(].*)?[ \t\r]*$/gm;
|
|
@@ -256,14 +294,15 @@ export function extractMarkdown(source: SourceDocument, sections: ParsedSection[
|
|
|
256
294
|
const body = section.text.replace(FRONT_MATTER, '').trim();
|
|
257
295
|
from = body ? b.bodySection(index, body, true) : b.fileRef;
|
|
258
296
|
}
|
|
259
|
-
|
|
297
|
+
const prose = withoutCode(section.text);
|
|
298
|
+
for (const m of prose.matchAll(MD_LINK)) {
|
|
260
299
|
if (!m[1]!.startsWith('#')) b.link(from, m[1]!);
|
|
261
300
|
}
|
|
262
|
-
for (const m of
|
|
301
|
+
for (const m of prose.matchAll(MD_REF_USE)) {
|
|
263
302
|
const target = refs.get((m[2] || m[1] || '').trim().toLowerCase());
|
|
264
303
|
if (target && !target.startsWith('#')) b.link(from, target);
|
|
265
304
|
}
|
|
266
|
-
b.wikiLinks(from,
|
|
305
|
+
b.wikiLinks(from, prose);
|
|
267
306
|
b.mentions(from, section.text);
|
|
268
307
|
});
|
|
269
308
|
return b.build();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ingest/fences.ts — the ONE CommonMark-ish fenced-code scanner. The markdown parser uses
|
|
3
|
+
* it so a `#` line inside a fence is not a heading, and `withoutCode` (docsExtract.ts)
|
|
4
|
+
* uses it to blank code before links are read, so the two can never disagree.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Blockquote markers (`>`), then the fence indent; a list item's content may indent further. */
|
|
8
|
+
const BQ = String.raw`((?:[ \t]*>)*)`;
|
|
9
|
+
const OPENER = new RegExp(String.raw`^${BQ}( *)(\`{3,}|~{3,})(.*)$`);
|
|
10
|
+
const CLOSER = new RegExp(String.raw`^${BQ}( *)(\`{3,}|~{3,})[ \t]*\r?$`);
|
|
11
|
+
const LIST_ITEM = /^\s*(?:[-*+]|\d{1,9}[.)])(?:\s|$)/;
|
|
12
|
+
|
|
13
|
+
/** True when a line begins (or sits inside a list item and so may indent) — see {@link fenceMask}. */
|
|
14
|
+
export function isListItemLine(line: string): boolean {
|
|
15
|
+
return LIST_ITEM.test(line);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Per line: true when it is a fence opener, a fence closer or inside a fence. An opener
|
|
20
|
+
* indents at most 3 spaces unless it sits inside a list item (then any indent); a backtick
|
|
21
|
+
* opener's info string holds no backtick; a closer is the same marker, at least as long,
|
|
22
|
+
* followed by whitespace only. An unclosed fence runs to the end of the lines.
|
|
23
|
+
*/
|
|
24
|
+
export function fenceMask(lines: readonly string[]): boolean[] {
|
|
25
|
+
const mask: boolean[] = new Array(lines.length).fill(false);
|
|
26
|
+
let open: { char: string; len: number } | undefined;
|
|
27
|
+
let inList = false;
|
|
28
|
+
lines.forEach((line, i) => {
|
|
29
|
+
if (open) {
|
|
30
|
+
mask[i] = true;
|
|
31
|
+
const c = CLOSER.exec(line);
|
|
32
|
+
if (c && (c[2]!.length <= 3 || inList) && c[3]![0] === open.char && c[3]!.length >= open.len) open = undefined;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const m = OPENER.exec(line);
|
|
36
|
+
if (m && (m[2]!.length <= 3 || inList) && !(m[3]![0] === '`' && m[4]!.includes('`'))) {
|
|
37
|
+
mask[i] = true;
|
|
38
|
+
open = { char: m[3]![0]!, len: m[3]!.length };
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (isListItemLine(line)) inList = true;
|
|
42
|
+
else if (line.trim() !== '' && !/^[ \t]/.test(line)) inList = false;
|
|
43
|
+
});
|
|
44
|
+
return mask;
|
|
45
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { MetadataRecord } from '../vectorstore/types.js';
|
|
7
|
+
import { fenceMask } from './fences.js';
|
|
7
8
|
import { extractHtml, extractMarkdown, extractPlainText } from './docsExtract.js';
|
|
8
9
|
import { mediaTypeOf, textOf } from './parserSupport.js';
|
|
9
10
|
import type { DocumentParser, ParsedSection } from './types.js';
|
|
@@ -25,9 +26,11 @@ export const markdownParser: DocumentParser = {
|
|
|
25
26
|
let buffer: string[] = [];
|
|
26
27
|
|
|
27
28
|
const flush = () => {
|
|
28
|
-
|
|
29
|
+
// Leading blank lines go, but the first line keeps its indentation: an indented
|
|
30
|
+
// code block opening a section must still be recognisable as code.
|
|
31
|
+
const text = buffer.join('\n').replace(/^(?:[ \t]*\r?\n)+/, '').trimEnd();
|
|
29
32
|
buffer = [];
|
|
30
|
-
if (!text) return;
|
|
33
|
+
if (!text.trim()) return;
|
|
31
34
|
const metadata: MetadataRecord = {};
|
|
32
35
|
if (path.length) {
|
|
33
36
|
metadata['headingPath'] = path.join(' › ');
|
|
@@ -37,10 +40,9 @@ export const markdownParser: DocumentParser = {
|
|
|
37
40
|
sections.push({ text, metadata });
|
|
38
41
|
};
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
for (const line of lines) {
|
|
42
|
-
|
|
43
|
-
const heading = inFence ? null : /^(#{1,6})\s+(.*)$/.exec(line);
|
|
43
|
+
const fenced = fenceMask(lines);
|
|
44
|
+
for (const [i, line] of lines.entries()) {
|
|
45
|
+
const heading = fenced[i] ? null : /^(#{1,6})\s+(.*)$/.exec(line);
|
|
44
46
|
if (heading) {
|
|
45
47
|
flush();
|
|
46
48
|
const depth = (heading[1] as string).length;
|
package/src/knowledge/build.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { entityName } from './resolve.js';
|
|
|
27
27
|
import {
|
|
28
28
|
basenameOf, canonicalJson, compareStr, factRef, fileRefOf, nameResolver, pathOfRef, round6, sortBy, srcRef,
|
|
29
29
|
} from './refs.js';
|
|
30
|
+
import { buildOutline } from './outline.js';
|
|
30
31
|
import { truncateGraph } from './truncate.js';
|
|
31
32
|
|
|
32
33
|
export const DEFAULT_MAX_NODES = 400;
|
|
@@ -202,6 +203,8 @@ export function buildGraph(input: BuildGraphInput, opts: BuildGraphOptions = {})
|
|
|
202
203
|
nodes: cut.nodes,
|
|
203
204
|
edges: cut.edges,
|
|
204
205
|
stats: { ...full.stats, nodes: cut.nodes.length, edges: cut.edges.length, truncated: cut.truncated },
|
|
206
|
+
// An untruncated graph already holds everything; only a cut one needs the whole-graph outline.
|
|
207
|
+
...(cut.truncated ? { outline: buildOutline(full) } : {}),
|
|
205
208
|
};
|
|
206
209
|
}
|
|
207
210
|
|
package/src/knowledge/index.ts
CHANGED
|
@@ -11,8 +11,11 @@ export type {
|
|
|
11
11
|
PartitionRule, PartitionRegistry, JudgementSpec, JudgementRequest, JudgedClaim, JudgedEntity, JudgementResult,
|
|
12
12
|
JudgementPort, AnalyzerPort, KnowledgeParser, KnowledgePack, StoredFact, StoredRelation, Scope, ScopeRecord,
|
|
13
13
|
KnowledgeStore, DirectorySource, LiveOverlay, KnowledgeGraph, ReviewPlan, ReviewProgress, ReviewReport,
|
|
14
|
-
ReviewArgs, BuildGraphInput, BuildGraphOptions, TraceStep, Trace,
|
|
14
|
+
ReviewArgs, BuildGraphInput, BuildGraphOptions, TraceStep, Trace, GraphOutline, OutlineFile,
|
|
15
15
|
} from './model.js';
|
|
16
|
+
export {
|
|
17
|
+
buildOutline, outlineOf, outlineRef, OUTLINE_MAX_FILES, OUTLINE_MAX_LINKS, OUTLINE_BADGE_KEYS, OUTLINE_VERDICTS, OUTLINE_FLAG_CYCLE,
|
|
18
|
+
} from './outline.js';
|
|
16
19
|
|
|
17
20
|
export { buildGraph, graphDigest, oneLineLabel, DEFAULT_MAX_NODES, MAX_NODES_CAP } from './build.js';
|
|
18
21
|
export { truncateGraph, TRUNCATION_HARD_CAP, UNANCHORED_AREA } from './truncate.js';
|
package/src/knowledge/model.ts
CHANGED
|
@@ -239,6 +239,49 @@ export interface KnowledgeGraph {
|
|
|
239
239
|
edges: KEdge[];
|
|
240
240
|
findings: Finding[];
|
|
241
241
|
stats: { sources: number; nodes: number; edges: number; stale: number; truncated: boolean };
|
|
242
|
+
/**
|
|
243
|
+
* Attached only when the graph was truncated (`stats.truncated`): the whole graph's files,
|
|
244
|
+
* so an overview never depends on the cut. Consumers read it through `outlineOf`, never directly.
|
|
245
|
+
*/
|
|
246
|
+
outline?: GraphOutline;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The whole graph's files and file-to-file references, in a compact form. Read it with
|
|
251
|
+
* `outlineOf(graph)` (the one entry point: the attached outline, or one built from an untruncated
|
|
252
|
+
* graph) and resolve a file's ref with `outlineRef`.
|
|
253
|
+
*/
|
|
254
|
+
export interface GraphOutline {
|
|
255
|
+
/** Common ref prefix of every file (e.g. `src:<root>::`); a file's ref = prefix + path. '' when files share none. */
|
|
256
|
+
prefix: string;
|
|
257
|
+
/** Distinct area refs, sorted; `OutlineFile.area` indexes into it. */
|
|
258
|
+
areas: NodeRef[];
|
|
259
|
+
/** Distinct partitions, sorted; `OutlineFile.partition` indexes into it. */
|
|
260
|
+
partitions: string[];
|
|
261
|
+
/** File nodes of the full graph, sorted by ref. */
|
|
262
|
+
files: OutlineFile[];
|
|
263
|
+
/**
|
|
264
|
+
* File-to-file `references` of the full graph, as [from, to, verdict, flags]: from/to index `files`;
|
|
265
|
+
* verdict is a code into OUTLINE_VERDICTS (the worst verdict of the merged edges); flags bit 1 = cycle.
|
|
266
|
+
* Section/symbol endpoints are rolled up to their file. Sorted by [from, to].
|
|
267
|
+
*/
|
|
268
|
+
links: Array<[number, number, number, number]>;
|
|
269
|
+
/** True when files or links were capped (see OUTLINE_MAX_*). */
|
|
270
|
+
capped: boolean;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface OutlineFile {
|
|
274
|
+
/** The ref without the outline's prefix. */
|
|
275
|
+
path: string;
|
|
276
|
+
/** Index into `GraphOutline.areas`, when the file has an area. */
|
|
277
|
+
area?: number;
|
|
278
|
+
/** Index into `GraphOutline.partitions`, when the file has a partition. */
|
|
279
|
+
partition?: number;
|
|
280
|
+
importance: number;
|
|
281
|
+
/** The first 12 characters of the node's sourceHash. */
|
|
282
|
+
hash?: string;
|
|
283
|
+
/** Only the overview's badge keys (see OUTLINE_BADGE_KEYS), when present. */
|
|
284
|
+
badges?: Record<string, number | string>;
|
|
242
285
|
}
|
|
243
286
|
|
|
244
287
|
export interface BuildGraphInput {
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/outline.test.ts
|
|
3
|
+
* The truncation outline: the whole graph's files and file-to-file references, present only on a cut graph.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { buildGraph } from './build.js';
|
|
7
|
+
import type { BuildGraphInput, KEdge, KNode, KnowledgeGraph, KnowledgePack, NodeRef } from './model.js';
|
|
8
|
+
import {
|
|
9
|
+
buildOutline, outlineOf, outlineRef, OUTLINE_FLAG_CYCLE, OUTLINE_MAX_FILES, OUTLINE_MAX_LINKS, OUTLINE_VERDICTS,
|
|
10
|
+
} from './outline.js';
|
|
11
|
+
import { edge, extractedOf, fileNode, ref, ROOT } from './testkit.test-util.js';
|
|
12
|
+
|
|
13
|
+
const PACK: KnowledgePack = { id: 'docs', parsers: [] };
|
|
14
|
+
const pad = (i: number) => `p/${String(i).padStart(6, '0')}.ts`;
|
|
15
|
+
|
|
16
|
+
function chain(extra: Partial<KNode> = {}): BuildGraphInput {
|
|
17
|
+
const paths = Array.from({ length: 40 }, (_, i) => `d${i % 4}/f${String(i).padStart(2, '0')}.md`);
|
|
18
|
+
const extracted = paths.map((p, i) => extractedOf(fileNode(p, extra), i + 1 < paths.length ? [edge(p, paths[i + 1]!, 'references')] : []));
|
|
19
|
+
return { rootId: ROOT, packs: [PACK], extracted, facts: [], relations: [] };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function ref2(i: number): NodeRef { return ref(pad(i)); }
|
|
23
|
+
|
|
24
|
+
function synthetic(files: number, edges: KEdge[], nodeExtra: (i: number) => Partial<KNode> = () => ({})): KnowledgeGraph {
|
|
25
|
+
const nodes: KNode[] = Array.from({ length: files }, (_, i) => fileNode(pad(i), { importance: i / files, ...nodeExtra(i) }));
|
|
26
|
+
return {
|
|
27
|
+
scope: { rootId: ROOT, packs: [], digest: '' },
|
|
28
|
+
nodes, edges, findings: [],
|
|
29
|
+
stats: { sources: files, nodes: files, edges: edges.length, stale: 0, truncated: true },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const refEdge = (a: number, b: number, extra: Partial<KEdge> = {}): KEdge => ({ ...edge(pad(a), pad(b), 'references'), ...extra });
|
|
34
|
+
|
|
35
|
+
describe('buildGraph outline', () => {
|
|
36
|
+
it('a truncated graph carries every file, including the ones the cut dropped', () => {
|
|
37
|
+
const g = buildGraph(chain(), { maxNodes: 6 });
|
|
38
|
+
expect(g.stats.truncated).toBe(true);
|
|
39
|
+
expect(g.outline!.files).toHaveLength(40);
|
|
40
|
+
expect(g.outline!.capped).toBe(false);
|
|
41
|
+
expect(g.nodes.filter((n) => n.kind === 'file').length).toBeLessThan(40);
|
|
42
|
+
const paths = g.outline!.files.map((f) => f.path);
|
|
43
|
+
expect(paths).toEqual([...paths].sort());
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('an untruncated graph has no attached outline, but outlineOf builds one', () => {
|
|
47
|
+
const g = buildGraph(chain(), { maxNodes: 500 });
|
|
48
|
+
expect(g.stats.truncated).toBe(false);
|
|
49
|
+
expect(g.outline).toBeUndefined();
|
|
50
|
+
const o = outlineOf(g);
|
|
51
|
+
expect(o.files).toHaveLength(40);
|
|
52
|
+
expect(o.links).toHaveLength(39);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('outlineOf returns the attached outline of a truncated graph', () => {
|
|
56
|
+
const g = buildGraph(chain(), { maxNodes: 6 });
|
|
57
|
+
expect(outlineOf(g)).toBe(g.outline);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('references between cut files are links, with prefix and path round-tripping to the ref', () => {
|
|
61
|
+
const g = buildGraph(chain(), { maxNodes: 6 });
|
|
62
|
+
const o = g.outline!;
|
|
63
|
+
expect(o.prefix).toBe(`src:${ROOT}::`);
|
|
64
|
+
expect(o.links).toHaveLength(39);
|
|
65
|
+
const a = o.files.findIndex((f) => outlineRef(o, f) === ref('d0/f00.md'));
|
|
66
|
+
const b = o.files.findIndex((f) => outlineRef(o, f) === ref('d1/f01.md'));
|
|
67
|
+
expect(o.files[a]!.path).toBe('d0/f00.md');
|
|
68
|
+
expect(o.links).toContainEqual([a, b, 0, 0]);
|
|
69
|
+
const sorted = [...o.links].sort((x, y) => x[0] - y[0] || x[1] - y[1]);
|
|
70
|
+
expect(o.links).toEqual(sorted);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('is deterministic', () => {
|
|
74
|
+
const a = buildGraph(chain(), { maxNodes: 6 });
|
|
75
|
+
const b = buildGraph(chain(), { maxNodes: 6 });
|
|
76
|
+
expect(a.outline).toEqual(b.outline);
|
|
77
|
+
expect(JSON.stringify(a.outline)).toBe(JSON.stringify(b.outline));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('keeps only the whitelisted badges', () => {
|
|
81
|
+
const g = buildGraph(chain({ badges: { complexity: 7, entry: 'main', secret: 'x', added: 3, status: 'M' } }), { maxNodes: 6 });
|
|
82
|
+
for (const f of g.outline!.files) expect(f.badges).toEqual({ complexity: 7, entry: 'main', added: 3, status: 'M' });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('omits badges when none of the whitelisted keys are present', () => {
|
|
86
|
+
const g = buildGraph(chain({ badges: { other: 3 } }), { maxNodes: 6 });
|
|
87
|
+
for (const f of g.outline!.files) expect(f.badges).toBeUndefined();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('buildOutline shape', () => {
|
|
92
|
+
it('indexes areas and partitions, and shortens the hash to 12 characters', () => {
|
|
93
|
+
const areaA = ref('areaA') as NodeRef;
|
|
94
|
+
const areaB = ref('areaB') as NodeRef;
|
|
95
|
+
const g = synthetic(3, [], (i) => ({
|
|
96
|
+
area: i === 0 ? areaB : areaA, partition: i === 2 ? undefined : (i === 0 ? 'z' : 'a'), sourceHash: `0123456789abcdef${i}`,
|
|
97
|
+
}));
|
|
98
|
+
const o = buildOutline(g);
|
|
99
|
+
expect(o.areas).toEqual([areaA, areaB]);
|
|
100
|
+
expect(o.partitions).toEqual(['a', 'z']);
|
|
101
|
+
expect(o.files[0]).toMatchObject({ area: 1, partition: 1, hash: '0123456789ab' });
|
|
102
|
+
expect(o.files[1]).toMatchObject({ area: 0, partition: 0 });
|
|
103
|
+
expect(o.files[2]!.partition).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('uses an empty prefix and full refs when files share none', () => {
|
|
107
|
+
const g = synthetic(2, []);
|
|
108
|
+
g.nodes[1] = { ...g.nodes[1]!, ref: 'src:other::x.ts' };
|
|
109
|
+
const o = buildOutline(g);
|
|
110
|
+
expect(o.prefix).toBe('');
|
|
111
|
+
expect(o.files.map((f) => outlineRef(o, f))).toEqual(['src:other::x.ts', ref(pad(0))]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('rolls section endpoints up to their file and drops the resulting self-links', () => {
|
|
115
|
+
const g = synthetic(3, [
|
|
116
|
+
{ ...refEdge(0, 1), from: `${ref2(0)}#s1` as NodeRef, to: `${ref2(1)}#s2` as NodeRef },
|
|
117
|
+
{ ...refEdge(0, 0), from: `${ref2(0)}#s1` as NodeRef, to: `${ref2(0)}#s2` as NodeRef },
|
|
118
|
+
]);
|
|
119
|
+
expect(buildOutline(g).links).toEqual([[0, 1, 0, 0]]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('merges a file pair to its worst verdict and cycle flag', () => {
|
|
123
|
+
const g = synthetic(2, [
|
|
124
|
+
refEdge(0, 1, { verdict: 'allowed' }),
|
|
125
|
+
{ ...refEdge(0, 1, { verdict: 'upward', cycle: true }), from: `${ref2(0)}#s` as NodeRef },
|
|
126
|
+
]);
|
|
127
|
+
expect(buildOutline(g).links).toEqual([[0, 1, OUTLINE_VERDICTS.indexOf('upward'), OUTLINE_FLAG_CYCLE]]);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('buildOutline caps', () => {
|
|
132
|
+
it('over the file cap keeps the most important files; links re-index into the kept list', () => {
|
|
133
|
+
const n = OUTLINE_MAX_FILES + 5;
|
|
134
|
+
// Files 0..4 are the least important and are dropped; 5 -> 6 survives and 0 -> 6 does not.
|
|
135
|
+
const o = buildOutline(synthetic(n, [refEdge(5, 6, { verdict: 'same' }), refEdge(0, 6)]));
|
|
136
|
+
expect(o.files).toHaveLength(OUTLINE_MAX_FILES);
|
|
137
|
+
expect(o.capped).toBe(true);
|
|
138
|
+
expect(o.files.some((f) => outlineRef(o, f) === ref2(0))).toBe(false);
|
|
139
|
+
expect(o.files.some((f) => outlineRef(o, f) === ref2(n - 1))).toBe(true);
|
|
140
|
+
const a = o.files.findIndex((f) => outlineRef(o, f) === ref2(5));
|
|
141
|
+
const b = o.files.findIndex((f) => outlineRef(o, f) === ref2(6));
|
|
142
|
+
expect(o.links).toEqual([[a, b, OUTLINE_VERDICTS.indexOf('same'), 0]]);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('over the link cap keeps the heaviest links by weight and flags capped', () => {
|
|
146
|
+
const n = 400;
|
|
147
|
+
const edges: KEdge[] = [];
|
|
148
|
+
for (let a = 0; a < n && edges.length < OUTLINE_MAX_LINKS + 10; a++) {
|
|
149
|
+
for (let b = 0; b < n && edges.length < OUTLINE_MAX_LINKS + 10; b++) if (a !== b) edges.push(refEdge(a, b));
|
|
150
|
+
}
|
|
151
|
+
// The first pair is the lowest-ranked by every tiebreak except weight: it must survive the cut.
|
|
152
|
+
const first = edges.findIndex((e) => e.from === ref2(0) && e.to === ref2(1));
|
|
153
|
+
edges[first] = refEdge(0, 1, { weight: 50 });
|
|
154
|
+
const o = buildOutline(synthetic(n, edges));
|
|
155
|
+
expect(o.links).toHaveLength(OUTLINE_MAX_LINKS);
|
|
156
|
+
expect(o.capped).toBe(true);
|
|
157
|
+
expect(o.links).toContainEqual([0, 1, 0, 0]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('under the caps is not capped', () => {
|
|
161
|
+
expect(buildOutline(synthetic(10, [refEdge(0, 1)])).capped).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
});
|