@seanhogg/builderforce-memory 2026.10.31 → 2026.10.33
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/agent/SSMAgent.d.ts.map +1 -1
- package/dist/agent/SSMAgent.js.map +1 -1
- package/dist/bridges/AnthropicBridge.d.ts.map +1 -1
- package/dist/bridges/AnthropicBridge.js.map +1 -1
- package/dist/bridges/CachingBridge.d.ts.map +1 -1
- package/dist/bridges/CachingBridge.js.map +1 -1
- package/dist/bridges/FetchBridge.d.ts.map +1 -1
- package/dist/bridges/OpenAIBridge.d.ts.map +1 -1
- package/dist/bridges/OpenAIBridge.js.map +1 -1
- package/dist/bridges/ResponseCache.d.ts.map +1 -1
- package/dist/bridges/ResponseCache.js.map +1 -1
- package/dist/bridges/SemanticCachingBridge.d.ts.map +1 -1
- package/dist/bridges/SemanticCachingBridge.js.map +1 -1
- package/dist/bridges/VertexAIBridge.d.ts.map +1 -1
- package/dist/bridges/VertexAIBridge.js.map +1 -1
- package/dist/cache/FetchSemanticCacheBackend.d.ts.map +1 -1
- package/dist/cache/SemanticCache.d.ts.map +1 -1
- package/dist/cognition/EvermindCognition.d.ts.map +1 -1
- package/dist/cognition/EvermindCognition.js.map +1 -1
- package/dist/diagnostics/stack-diagnostic.js.map +1 -1
- package/dist/distillation/DistillationEngine.d.ts.map +1 -1
- package/dist/distillation/DistillationEngine.js.map +1 -1
- package/dist/errors/SSMError.d.ts +2 -2
- package/dist/errors/SSMError.d.ts.map +1 -1
- package/dist/errors/SSMError.js.map +1 -1
- package/dist/eval/EvalHarness.d.ts.map +1 -1
- package/dist/eval/EvalHarness.js.map +1 -1
- package/dist/evermind/runtime.js.map +1 -1
- package/dist/evermind/textCoherence.js.map +1 -1
- package/dist/evermind/toolCall.js.map +1 -1
- package/dist/handoff/pack.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/ingest/IngestionPipeline.d.ts.map +1 -1
- package/dist/ingest/docsExtract.d.ts +9 -3
- package/dist/ingest/docsExtract.d.ts.map +1 -1
- package/dist/ingest/docsExtract.js +73 -20
- package/dist/ingest/docsExtract.js.map +1 -1
- package/dist/ingest/index.d.ts +1 -1
- package/dist/ingest/index.d.ts.map +1 -1
- package/dist/ingest/index.js +1 -1
- package/dist/ingest/index.js.map +1 -1
- package/dist/ingest/parserSupport.d.ts +16 -0
- package/dist/ingest/parserSupport.d.ts.map +1 -0
- package/dist/ingest/parserSupport.js +18 -0
- package/dist/ingest/parserSupport.js.map +1 -0
- package/dist/ingest/parsers.d.ts +3 -3
- package/dist/ingest/parsers.d.ts.map +1 -1
- package/dist/ingest/parsers.js +3 -92
- package/dist/ingest/parsers.js.map +1 -1
- package/dist/ingest/textParsers.d.ts +9 -0
- package/dist/ingest/textParsers.d.ts.map +1 -0
- package/dist/ingest/textParsers.js +99 -0
- package/dist/ingest/textParsers.js.map +1 -0
- package/dist/knowledge/build.d.ts +2 -0
- package/dist/knowledge/build.d.ts.map +1 -1
- package/dist/knowledge/build.js +46 -12
- package/dist/knowledge/build.js.map +1 -1
- package/dist/knowledge/cards.js.map +1 -1
- package/dist/knowledge/extractFile.d.ts +51 -0
- package/dist/knowledge/extractFile.d.ts.map +1 -0
- package/dist/knowledge/extractFile.js +59 -0
- package/dist/knowledge/extractFile.js.map +1 -0
- package/dist/knowledge/findings.d.ts +6 -0
- package/dist/knowledge/findings.d.ts.map +1 -1
- package/dist/knowledge/findings.js +9 -7
- package/dist/knowledge/findings.js.map +1 -1
- package/dist/knowledge/importance.js.map +1 -1
- package/dist/knowledge/index.d.ts +10 -7
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +8 -7
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/judge.d.ts +34 -2
- package/dist/knowledge/judge.d.ts.map +1 -1
- package/dist/knowledge/judge.js +86 -16
- package/dist/knowledge/judge.js.map +1 -1
- package/dist/knowledge/model.d.ts +13 -62
- package/dist/knowledge/model.d.ts.map +1 -1
- package/dist/knowledge/owedFiles.d.ts +68 -0
- package/dist/knowledge/owedFiles.d.ts.map +1 -0
- package/dist/knowledge/owedFiles.js +86 -0
- package/dist/knowledge/owedFiles.js.map +1 -0
- package/dist/knowledge/packs/docs.d.ts +5 -2
- package/dist/knowledge/packs/docs.d.ts.map +1 -1
- package/dist/knowledge/packs/docs.js +33 -5
- package/dist/knowledge/packs/docs.js.map +1 -1
- package/dist/knowledge/plan.d.ts +37 -3
- package/dist/knowledge/plan.d.ts.map +1 -1
- package/dist/knowledge/plan.js +66 -19
- package/dist/knowledge/plan.js.map +1 -1
- package/dist/knowledge/refs.d.ts +22 -1
- package/dist/knowledge/refs.d.ts.map +1 -1
- package/dist/knowledge/refs.js +52 -0
- package/dist/knowledge/refs.js.map +1 -1
- package/dist/knowledge/review.d.ts +10 -4
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +125 -109
- package/dist/knowledge/review.js.map +1 -1
- package/dist/knowledge/reviewCompare.d.ts +39 -0
- package/dist/knowledge/reviewCompare.d.ts.map +1 -0
- package/dist/knowledge/reviewCompare.js +70 -0
- package/dist/knowledge/reviewCompare.js.map +1 -0
- package/dist/knowledge/reviewModel.d.ts +86 -0
- package/dist/knowledge/reviewModel.d.ts.map +1 -0
- package/dist/knowledge/reviewModel.js +6 -0
- package/dist/knowledge/reviewModel.js.map +1 -0
- package/dist/knowledge/reviewStored.d.ts +23 -0
- package/dist/knowledge/reviewStored.d.ts.map +1 -0
- package/dist/knowledge/reviewStored.js +62 -0
- package/dist/knowledge/reviewStored.js.map +1 -0
- package/dist/knowledge/sources.d.ts +34 -4
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +92 -26
- package/dist/knowledge/sources.js.map +1 -1
- package/dist/knowledge/stores/localSnapshotStore.d.ts.map +1 -1
- package/dist/knowledge/stores/localSnapshotStore.js.map +1 -1
- package/dist/knowledge/trace.js.map +1 -1
- package/dist/knowledge/truncate.d.ts +4 -4
- package/dist/knowledge/truncate.d.ts.map +1 -1
- package/dist/knowledge/truncate.js +9 -13
- package/dist/knowledge/truncate.js.map +1 -1
- package/dist/limbic/LimbicSession.d.ts.map +1 -1
- package/dist/limbic/LimbicSession.js.map +1 -1
- package/dist/memory/MemoryStore.d.ts.map +1 -1
- package/dist/memory/MemoryStore.js.map +1 -1
- package/dist/memory/SemanticRecall.d.ts.map +1 -1
- package/dist/memory/SemanticRecall.js.map +1 -1
- package/dist/memory/ttlSweeper.d.ts.map +1 -1
- package/dist/orchestration/AgentGraph.d.ts.map +1 -1
- package/dist/orchestration/AgentGraph.js.map +1 -1
- package/dist/orchestration/checkpoint.d.ts.map +1 -1
- package/dist/orchestration/checkpoint.js.map +1 -1
- package/dist/publish/huggingface.js.map +1 -1
- package/dist/rag/EnterpriseRetriever.d.ts.map +1 -1
- package/dist/rag/EnterpriseRetriever.js.map +1 -1
- package/dist/retrieval/HybridRetriever.js.map +1 -1
- package/dist/retrieval/bm25.js.map +1 -1
- package/dist/retrieval/chunk.js.map +1 -1
- package/dist/retrieval/fusion.js.map +1 -1
- package/dist/retrieval/hnsw.d.ts.map +1 -1
- package/dist/retrieval/hnsw.js.map +1 -1
- package/dist/retrieval/knowledge-index/bytes.d.ts.map +1 -1
- package/dist/retrieval/knowledge-index/bytes.js.map +1 -1
- package/dist/retrieval/knowledge-index/cascade.js.map +1 -1
- package/dist/retrieval/knowledge-index/embeddings.d.ts.map +1 -1
- package/dist/retrieval/knowledge-index/embeddings.js.map +1 -1
- package/dist/retrieval/knowledge-index/expand.js.map +1 -1
- package/dist/retrieval/knowledge-index/index.js.map +1 -1
- package/dist/retrieval/knowledge-index/lexical.d.ts.map +1 -1
- package/dist/retrieval/knowledge-index/sha256.d.ts.map +1 -1
- package/dist/retrieval/order.js.map +1 -1
- package/dist/router/InferenceRouter.d.ts.map +1 -1
- package/dist/router/InferenceRouter.js.map +1 -1
- package/dist/runtime/SSMRuntime.d.ts.map +1 -1
- package/dist/runtime/SSMRuntime.js.map +1 -1
- package/dist/session/errors.d.ts +2 -2
- package/dist/session/errors.d.ts.map +1 -1
- package/dist/session/errors.js.map +1 -1
- package/dist/session/session.d.ts.map +1 -1
- package/dist/session/session.js.map +1 -1
- package/dist/session/streaming.js.map +1 -1
- package/dist/storage/ScopedFactRepository.d.ts.map +1 -1
- package/dist/storage/ScopedFactRepository.js.map +1 -1
- package/dist/storage/fileLock.d.ts.map +1 -1
- package/dist/storage/fileLock.js.map +1 -1
- package/dist/storage/fileTransaction.d.ts.map +1 -1
- package/dist/storage/fileTransaction.js.map +1 -1
- package/dist/storage/idbAdapter.d.ts +1 -1
- package/dist/storage/idbAdapter.d.ts.map +1 -1
- package/dist/storage/idbAdapter.js.map +1 -1
- package/dist/storage/nodeFileAdapter.d.ts +1 -1
- package/dist/storage/nodeFileAdapter.d.ts.map +1 -1
- package/dist/storage/nodeFileAdapter.js.map +1 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/telemetry/InstrumentedBridge.d.ts.map +1 -1
- package/dist/telemetry/InstrumentedBridge.js.map +1 -1
- package/dist/telemetry/MetricsRegistry.d.ts.map +1 -1
- package/dist/telemetry/MetricsRegistry.js.map +1 -1
- package/dist/telemetry/Tracer.d.ts.map +1 -1
- package/dist/telemetry/Tracer.js.map +1 -1
- package/dist/telemetry/exporters.d.ts.map +1 -1
- package/dist/telemetry/exporters.js.map +1 -1
- package/dist/telemetry/pricing.js.map +1 -1
- package/dist/vectorstore/MemoryVectorStore.d.ts.map +1 -1
- package/dist/vectorstore/MemoryVectorStore.js.map +1 -1
- package/dist/vectorstore/RestVectorStore.d.ts.map +1 -1
- package/dist/vectorstore/dialects.js.map +1 -1
- package/dist/vectorstore/filter.js.map +1 -1
- package/dist/wire/chatClient.d.ts +5 -0
- package/dist/wire/chatClient.d.ts.map +1 -1
- package/dist/wire/chatClient.js +6 -0
- package/dist/wire/chatClient.js.map +1 -1
- package/dist/wire/usage.d.ts.map +1 -1
- package/dist/workflow/registry.d.ts.map +1 -1
- package/dist/workflow/run.js.map +1 -1
- package/dist/workflow/templates.js.map +1 -1
- package/dist/working/codemapAreas.js.map +1 -1
- package/dist/working/consolidate.js.map +1 -1
- package/dist/working/workingMemory.d.ts.map +1 -1
- package/dist/working/workingMemory.js.map +1 -1
- package/package.json +8 -9
- package/src/ingest/docsExtract.ts +68 -18
- package/src/ingest/index.ts +1 -0
- package/src/ingest/parserSupport.ts +24 -0
- package/src/ingest/parsers.ts +4 -102
- package/src/ingest/textParsers.ts +107 -0
- package/src/knowledge/build.ts +43 -11
- package/src/knowledge/extractFile.ts +86 -0
- package/src/knowledge/findings.ts +12 -5
- package/src/knowledge/index.ts +15 -8
- package/src/knowledge/judge.clamp.test.ts +61 -0
- package/src/knowledge/judge.ts +88 -19
- package/src/knowledge/model.ts +15 -57
- package/src/knowledge/owedFiles.ts +108 -0
- package/src/knowledge/packs/docs.ts +34 -5
- package/src/knowledge/plan.ts +93 -19
- package/src/knowledge/refs.ts +49 -1
- package/src/knowledge/review.details.test.ts +93 -0
- package/src/knowledge/review.estimate.test.ts +112 -0
- package/src/knowledge/review.fixes.test.ts +235 -0
- package/src/knowledge/review.gaps.test.ts +167 -0
- package/src/knowledge/review.owed.test.ts +379 -0
- package/src/knowledge/review.test.ts +2 -15
- package/src/knowledge/review.ts +114 -117
- package/src/knowledge/review.upgrade.test.ts +257 -0
- package/src/knowledge/reviewCompare.ts +80 -0
- package/src/knowledge/reviewModel.ts +81 -0
- package/src/knowledge/reviewStored.ts +62 -0
- package/src/knowledge/sources.ts +97 -20
- package/src/knowledge/testkit.test-util.ts +39 -1
- package/src/knowledge/truncate.ts +8 -11
- package/src/wire/chatClient.ts +13 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/review.fixes.test.ts
|
|
3
|
+
* Review follow-ups: binary documents are claimed only by a host extractor (any pack order);
|
|
4
|
+
* `[[Name]]` is resolved at build time, never in the cached extract; a fact outlives one of
|
|
5
|
+
* its deleted sources; ignore precedence; out-of-root and root links; compare pairs survive
|
|
6
|
+
* a skipped run; extractor versions; a stale plan.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
10
|
+
import { hashText } from '../ingest/hash.js';
|
|
11
|
+
import { htmlParser, isBinaryDocumentType, markdownParser, plainTextParser } from '../ingest/parsers.js';
|
|
12
|
+
import type { SourceDocument } from '../ingest/types.js';
|
|
13
|
+
import { buildGraph } from './build.js';
|
|
14
|
+
import type { ExtractContext, Extracted, KnowledgePack, KnowledgeParser, ReviewArgs } from './model.js';
|
|
15
|
+
import { DOCS_PACK } from './packs/docs.js';
|
|
16
|
+
import { planDetail, planReview } from './plan.js';
|
|
17
|
+
import { reviewDirectory } from './review.js';
|
|
18
|
+
import {
|
|
19
|
+
asPathSource, compareManifestKey, composePacks, EXTRACTOR_VERSION, filesManifestKey, manifestMap, resolveRelativePath,
|
|
20
|
+
} from './sources.js';
|
|
21
|
+
import {
|
|
22
|
+
extractedOf, fakeJudge, fileNode, graphOf, memSource, memStore, ref, ROOT, type SpySource,
|
|
23
|
+
} from './testkit.test-util.js';
|
|
24
|
+
|
|
25
|
+
const BUDGET = { modelCalls: 200, ms: 60_000 };
|
|
26
|
+
const args = (source: SpySource, store = memStore(), manifest = new InMemoryIngestManifest(), extra: Partial<ReviewArgs> = {}): ReviewArgs =>
|
|
27
|
+
({ source, store, manifest, packs: [DOCS_PACK], budget: BUDGET, ...extra });
|
|
28
|
+
|
|
29
|
+
const ctx: ExtractContext = { rootId: ROOT, knownKeys: new Map(), resolvePath: resolveRelativePath };
|
|
30
|
+
const doc = (path: string, text: string): SourceDocument =>
|
|
31
|
+
asPathSource({ id: path, tenantId: 't', content: { kind: 'text', text } }, path, `h:${path}`);
|
|
32
|
+
const extractMd = (path: string, text: string): Extracted => {
|
|
33
|
+
const src = doc(path, text);
|
|
34
|
+
return markdownParser.extract!(src, markdownParser.parse(src), ctx);
|
|
35
|
+
};
|
|
36
|
+
const links = (ex: Extracted) => ex.edges.filter((e) => e.kind === 'links');
|
|
37
|
+
|
|
38
|
+
const pdfParser: KnowledgeParser = {
|
|
39
|
+
id: 'pdf-text',
|
|
40
|
+
accepts: (s) => s.content.kind === 'text' && s.content.mediaType === 'application/pdf',
|
|
41
|
+
parse: (s) => [{ text: s.content.kind === 'text' ? s.content.text : '' }],
|
|
42
|
+
};
|
|
43
|
+
const pdfPack: KnowledgePack = { id: 'pdf', parsers: [pdfParser] };
|
|
44
|
+
|
|
45
|
+
describe('binary documents', () => {
|
|
46
|
+
it('knowledge composition refuses an office or pdf media type to the builtin text parsers; ingest is unchanged', () => {
|
|
47
|
+
const docx = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
48
|
+
for (const type of [docx, 'application/pdf', 'application/msword', 'application/vnd.ms-excel']) {
|
|
49
|
+
expect(isBinaryDocumentType(type)).toBe(true);
|
|
50
|
+
const source: SourceDocument = { id: 'x', tenantId: 't', content: { kind: 'text', text: 't', mediaType: type } };
|
|
51
|
+
expect(composePacks([DOCS_PACK]).resolve(source)).toBeUndefined();
|
|
52
|
+
expect(composePacks([DOCS_PACK, pdfPack]).resolve(source)?.pack.id).toBe(type === 'application/pdf' ? 'pdf' : undefined);
|
|
53
|
+
// The ingest pipeline's builtins accept exactly what they always did.
|
|
54
|
+
expect(plainTextParser.accepts(source)).toBe(true);
|
|
55
|
+
}
|
|
56
|
+
const xml: SourceDocument = { id: 'x', tenantId: 't', content: { kind: 'text', text: 't', mediaType: docx } };
|
|
57
|
+
expect(htmlParser.accepts(xml)).toBe(true);
|
|
58
|
+
expect(isBinaryDocumentType('application/vnd.api+json')).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('a docx with no host parser is skipped as binary', async () => {
|
|
62
|
+
const plan = await planReview(memSource({ 'a.docx': 'x', 'b.md': '# B\n' }), new InMemoryIngestManifest(), [DOCS_PACK]);
|
|
63
|
+
expect(plan.skipped).toContainEqual({ path: 'a.docx', reason: 'binary' });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('a host pdf pack placed AFTER the docs pack still claims the pdf', async () => {
|
|
67
|
+
const source = memSource({ 'a.pdf': 'text' });
|
|
68
|
+
const plan = await planReview(source, new InMemoryIngestManifest(), [DOCS_PACK, pdfPack]);
|
|
69
|
+
expect(plan.byPack).toEqual({ pdf: 1 });
|
|
70
|
+
const report = await reviewDirectory(args(source, memStore(), new InMemoryIngestManifest(), { packs: [DOCS_PACK, pdfPack] }));
|
|
71
|
+
expect(report.extracted).toBe(1);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('[[Name]] links resolve at build time', () => {
|
|
76
|
+
const one = extractMd('a/one.md', '# One\nSee [[Two]].\n');
|
|
77
|
+
const build = (...paths: string[]) => buildGraph({
|
|
78
|
+
rootId: ROOT, packs: [DOCS_PACK], extracted: [one, ...paths.map((p) => extractedOf(fileNode(p)))], facts: [], relations: [],
|
|
79
|
+
});
|
|
80
|
+
const targets = (g: ReturnType<typeof build>) => g.edges.filter((e) => e.kind === 'links').map((e) => e.to);
|
|
81
|
+
|
|
82
|
+
it('the cached extract carries the fallback and the name, not the resolution', () => {
|
|
83
|
+
expect(links(one)).toEqual([expect.objectContaining({ to: ref('a/Two.md'), byName: 'Two' })]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('points at the unique file of that name, even when it appeared after the extract', () => {
|
|
87
|
+
const g = build('b/Two.md');
|
|
88
|
+
expect(targets(g)).toEqual([ref('b/Two.md')]);
|
|
89
|
+
expect(g.edges.every((e) => !('byName' in e))).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('keeps the fallback when the name is ambiguous or absent', () => {
|
|
93
|
+
expect(targets(build('b/Two.md', 'c/Two.md'))).toEqual([ref('a/Two.md')]);
|
|
94
|
+
expect(targets(build())).toEqual([ref('a/Two.md')]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('a fact outlives one of its deleted sources', () => {
|
|
99
|
+
it('drops the removed anchor from a fact other sources back; a fact anchored only there stays stale', async () => {
|
|
100
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' });
|
|
101
|
+
const store = memStore();
|
|
102
|
+
const manifest = new InMemoryIngestManifest();
|
|
103
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
104
|
+
const lease = (await store.facts({ rootId: ROOT })).find((f) => f.key === 'ent:docs:lease')!;
|
|
105
|
+
expect(lease.fileAnchors.map((a) => a.path)).toEqual(['a.md', 'b.md']);
|
|
106
|
+
|
|
107
|
+
delete source.files['b.md'];
|
|
108
|
+
await reviewDirectory(args(source, store, manifest));
|
|
109
|
+
const facts = await store.facts({ rootId: ROOT });
|
|
110
|
+
expect(facts.find((f) => f.key === 'ent:docs:lease')!.fileAnchors.map((a) => a.path)).toEqual(['a.md']);
|
|
111
|
+
const g = await graphOf(source, store);
|
|
112
|
+
expect(g.nodes.find((n) => n.ref === 'ent:docs:lease')?.stale).toBeUndefined();
|
|
113
|
+
const onlyB = facts.find((f) => f.key.startsWith('claim:') && f.fileAnchors.every((a) => a.path === 'b.md'))!;
|
|
114
|
+
expect(g.nodes.find((n) => n.ref === `fact:${onlyB.key}`)?.stale).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('ignore precedence', () => {
|
|
119
|
+
it('.builderforce/ignore overrides .gitignore', async () => {
|
|
120
|
+
const source = memSource({
|
|
121
|
+
'.gitignore': 'docs/generated/\n', '.builderforce/ignore': '!docs/generated/\n', 'docs/generated/x.md': '# X\n',
|
|
122
|
+
});
|
|
123
|
+
const plan = await planReview(source, new InMemoryIngestManifest(), [DOCS_PACK]);
|
|
124
|
+
expect(plan.changed).toEqual(['docs/generated/x.md']);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('links out of and to the root', () => {
|
|
129
|
+
it('a link to the root itself is no link', () => {
|
|
130
|
+
expect(links(extractMd('a/b.md', '# T\n[x](/) [y](./) [z](.) [w](..) [v](../) [d](docs/)\n'))).toEqual([]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('an escape stays a broken link under a normalized path that never collapses different files', () => {
|
|
134
|
+
const refs = [
|
|
135
|
+
links(extractMd('a/x.md', '# T\n[u](../../y.md)\n')),
|
|
136
|
+
links(extractMd('a/b/x.md', '# T\n[u](../../../y.md)\n')),
|
|
137
|
+
links(extractMd('x.md', '# T\n[u](../../y.md)\n')),
|
|
138
|
+
].map((l) => l.map((e) => e.to));
|
|
139
|
+
expect(refs).toEqual([[ref('../y.md')], [ref('../y.md')], [ref('../../y.md')]]);
|
|
140
|
+
|
|
141
|
+
const g = buildGraph({ rootId: ROOT, packs: [DOCS_PACK], extracted: [extractMd('a/x.md', '# T\n[u](../../y.md)\n')], facts: [], relations: [] });
|
|
142
|
+
const missing = g.nodes.find((n) => n.ref === ref('../y.md'));
|
|
143
|
+
expect(missing).toMatchObject({ kind: 'missing' });
|
|
144
|
+
expect(missing?.partition).toBeUndefined();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('a reference definition may end in whitespace', () => {
|
|
148
|
+
for (const eol of [' \n', '\t\r\n']) {
|
|
149
|
+
const ex = extractMd('one.md', `# One\nSee [the guide][g].\n\n[g]: docs/guide.md${eol}`);
|
|
150
|
+
expect(links(ex).map((e) => e.to)).toEqual([ref('docs/guide.md')]);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('compare pairs skipped can continue', () => {
|
|
156
|
+
const similar = async (ids: string[]) => (ids.length >= 2 ? [{ a: ids[0]!, b: ids[1]!, similarity: 0.95 }] : []);
|
|
157
|
+
|
|
158
|
+
it('a pair skipped for budget is compared by the next run, once', async () => {
|
|
159
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' });
|
|
160
|
+
const store = memStore();
|
|
161
|
+
const manifest = new InMemoryIngestManifest();
|
|
162
|
+
const first = await reviewDirectory(args(source, store, manifest, {
|
|
163
|
+
judgement: fakeJudge(), similar, budget: { modelCalls: 2, ms: 60_000 },
|
|
164
|
+
}));
|
|
165
|
+
expect(first.unjudged).toBe(1);
|
|
166
|
+
expect((await manifestMap(manifest, compareManifestKey(ROOT))).size).toBe(2);
|
|
167
|
+
|
|
168
|
+
const judge = fakeJudge();
|
|
169
|
+
const second = await reviewDirectory(args(source, store, manifest, { judgement: judge, similar }));
|
|
170
|
+
expect(judge.requests.map((r) => r.kind)).toEqual(['compare']);
|
|
171
|
+
expect(second.unjudged).toBe(0);
|
|
172
|
+
expect(await store.relations({ rootId: ROOT })).toContainEqual(expect.objectContaining({ kind: 'contradicts' }));
|
|
173
|
+
expect((await manifestMap(manifest, compareManifestKey(ROOT))).size).toBe(0);
|
|
174
|
+
|
|
175
|
+
const third = fakeJudge();
|
|
176
|
+
await reviewDirectory(args(source, store, manifest, { judgement: third, similar }));
|
|
177
|
+
expect(third.requests).toHaveLength(0);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('aborted is set only when the abort landed before compare finished', async () => {
|
|
181
|
+
const run = async (files: Record<string, string>, pairs: number) => {
|
|
182
|
+
const controller = new AbortController();
|
|
183
|
+
const judge = fakeJudge();
|
|
184
|
+
const inner = judge.judge.bind(judge);
|
|
185
|
+
judge.judge = async (req) => {
|
|
186
|
+
const out = await inner(req);
|
|
187
|
+
if (req.kind === 'compare') controller.abort();
|
|
188
|
+
return out;
|
|
189
|
+
};
|
|
190
|
+
const manifest = new InMemoryIngestManifest();
|
|
191
|
+
const report = await reviewDirectory(args(memSource(files), memStore(), manifest, {
|
|
192
|
+
judgement: judge, signal: controller.signal,
|
|
193
|
+
similar: async (ids) => ids.slice(1).slice(0, pairs).map((b, i) => ({ a: ids[i]!, b, similarity: 0.9 })),
|
|
194
|
+
}));
|
|
195
|
+
return { report, awaiting: (await manifestMap(manifest, compareManifestKey(ROOT))).size };
|
|
196
|
+
};
|
|
197
|
+
const last = await run({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' }, 1);
|
|
198
|
+
expect(last.report.aborted).toBe(false);
|
|
199
|
+
expect(last.awaiting).toBe(0);
|
|
200
|
+
const mid = await run({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n', 'c.md': '# C\ngamma\n' }, 2);
|
|
201
|
+
expect(mid.report.aborted).toBe(true);
|
|
202
|
+
expect(mid.awaiting).toBeGreaterThan(0);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('extractor version and stale plans', () => {
|
|
207
|
+
it('a cached Extracted of an older version is re-extracted', async () => {
|
|
208
|
+
const text = '# A\nalpha\n';
|
|
209
|
+
const store = memStore();
|
|
210
|
+
const hash = hashText(text);
|
|
211
|
+
await store.putExtracted(hash, [{ sourceRef: ref('a.md'), sourceHash: hash, extractorVersion: EXTRACTOR_VERSION - 1, nodes: [], edges: [], keys: [] }]);
|
|
212
|
+
await reviewDirectory(args(memSource({ 'a.md': text }), store));
|
|
213
|
+
const cached = (await store.getExtracted(hash))!;
|
|
214
|
+
expect(cached).toHaveLength(1);
|
|
215
|
+
expect(cached[0]).toMatchObject({ extractorVersion: EXTRACTOR_VERSION });
|
|
216
|
+
expect(cached[0]!.nodes.length).toBeGreaterThan(0);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('Continue with a plan that lists a file that can no longer be read skips it, without retiring it', async () => {
|
|
220
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' });
|
|
221
|
+
const manifest = new InMemoryIngestManifest();
|
|
222
|
+
const detail = await planDetail(source, manifest, [DOCS_PACK]);
|
|
223
|
+
delete source.files['b.md'];
|
|
224
|
+
const read = source.read.bind(source);
|
|
225
|
+
source.read = async (p) => {
|
|
226
|
+
if (!(p in source.files)) throw new Error('ENOENT');
|
|
227
|
+
return read(p);
|
|
228
|
+
};
|
|
229
|
+
const report = await reviewDirectory(args(source, memStore(), manifest, { plan: detail }));
|
|
230
|
+
expect(report.aborted).toBe(false);
|
|
231
|
+
expect(report.extracted).toBe(1);
|
|
232
|
+
expect(report.readErrors).toBe(1);
|
|
233
|
+
expect([...(await manifestMap(manifest, filesManifestKey(ROOT))).keys()]).toEqual(['a.md']);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/review.gaps.test.ts
|
|
3
|
+
* PRD 38 audit follow-ups: abort DURING judgement re-judges next time; stale relations and
|
|
4
|
+
* facts on deleted sources show stale; the contradiction finding; nested `.gitignore`;
|
|
5
|
+
* pdf/office only with a host extractor; files binary on read are not re-read; *Continue*
|
|
6
|
+
* reuses the confirmed plan; wiki links by name, reference-style links, out-of-root links
|
|
7
|
+
* and the pre-heading section.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
11
|
+
import { markdownParser } from '../ingest/parsers.js';
|
|
12
|
+
import type { SourceDocument } from '../ingest/types.js';
|
|
13
|
+
import { buildGraph } from './build.js';
|
|
14
|
+
import type { ExtractContext, KnowledgePack, KnowledgeParser, NodeRef, ReviewArgs, StoredFact } from './model.js';
|
|
15
|
+
import { DOCS_PACK } from './packs/docs.js';
|
|
16
|
+
import { planDetail, planReview } from './plan.js';
|
|
17
|
+
import { reviewDirectory } from './review.js';
|
|
18
|
+
import { asPathSource, resolveRelativePath } from './sources.js';
|
|
19
|
+
import { extractedOf, fakeJudge, fileNode, memSource, memStore, ref, ROOT, type SpySource } from './testkit.test-util.js';
|
|
20
|
+
|
|
21
|
+
const BUDGET = { modelCalls: 200, ms: 60_000 };
|
|
22
|
+
const args = (source: SpySource, store = memStore(), manifest = new InMemoryIngestManifest(), extra: Partial<ReviewArgs> = {}): ReviewArgs =>
|
|
23
|
+
({ source, store, manifest, packs: [DOCS_PACK], budget: BUDGET, ...extra });
|
|
24
|
+
|
|
25
|
+
describe('reviewDirectory — audit follow-ups', () => {
|
|
26
|
+
it('an abort during judgement leaves that file to be judged again', async () => {
|
|
27
|
+
const source = memSource({ 'a.md': '# A\nalpha\n## B\nbeta\n' });
|
|
28
|
+
const store = memStore();
|
|
29
|
+
const manifest = new InMemoryIngestManifest();
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
let calls = 0;
|
|
32
|
+
const judge = fakeJudge();
|
|
33
|
+
const inner = judge.judge.bind(judge);
|
|
34
|
+
judge.judge = async (req) => {
|
|
35
|
+
calls += 1;
|
|
36
|
+
const out = await inner(req);
|
|
37
|
+
if (calls === 1) controller.abort();
|
|
38
|
+
return out;
|
|
39
|
+
};
|
|
40
|
+
const first = await reviewDirectory(args(source, store, manifest, { judgement: judge, signal: controller.signal }));
|
|
41
|
+
expect(first.aborted).toBe(true);
|
|
42
|
+
expect((await store.facts({ rootId: ROOT })).filter((f) => f.key.startsWith('claim:'))).toHaveLength(0);
|
|
43
|
+
|
|
44
|
+
const again = fakeJudge();
|
|
45
|
+
await reviewDirectory(args(source, store, manifest, { judgement: again }));
|
|
46
|
+
expect(again.requests.filter((r) => r.kind === 'extract')).toHaveLength(2);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('records a file found binary on read, so it is not re-read', async () => {
|
|
50
|
+
const source = memSource({ 'a.txt': 'bin\u0000ary' });
|
|
51
|
+
const manifest = new InMemoryIngestManifest();
|
|
52
|
+
await reviewDirectory(args(source, memStore(), manifest));
|
|
53
|
+
source.reads.length = 0;
|
|
54
|
+
await reviewDirectory(args(source, memStore(), manifest));
|
|
55
|
+
expect(source.reads).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('Continue reuses the confirmed plan without re-walking', async () => {
|
|
59
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' });
|
|
60
|
+
const manifest = new InMemoryIngestManifest();
|
|
61
|
+
const detail = await planDetail(source, manifest, [DOCS_PACK]);
|
|
62
|
+
let walks = 0;
|
|
63
|
+
const list = source.list.bind(source);
|
|
64
|
+
source.list = () => { walks += 1; return list(); };
|
|
65
|
+
const store = memStore();
|
|
66
|
+
const report = await reviewDirectory(args(source, store, manifest, { plan: detail }));
|
|
67
|
+
expect(walks).toBe(0);
|
|
68
|
+
expect(report.extracted).toBe(2);
|
|
69
|
+
|
|
70
|
+
// Run again with the same plan: what the first run finished is not reviewed (or read) again.
|
|
71
|
+
source.reads.length = 0;
|
|
72
|
+
const again = await reviewDirectory(args(source, store, manifest, { plan: detail }));
|
|
73
|
+
expect(again.extracted).toBe(0);
|
|
74
|
+
expect(source.reads).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('counts compare pairs skipped for budget as unjudged', async () => {
|
|
78
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' });
|
|
79
|
+
const report = await reviewDirectory(args(source, memStore(), new InMemoryIngestManifest(), {
|
|
80
|
+
judgement: fakeJudge(),
|
|
81
|
+
budget: { modelCalls: 2, ms: 60_000 },
|
|
82
|
+
similar: async (ids) => (ids.length >= 2 ? [{ a: ids[0]!, b: ids[1]!, similarity: 0.95 }] : []),
|
|
83
|
+
}));
|
|
84
|
+
expect(report.judged).toBe(2);
|
|
85
|
+
expect(report.unjudged).toBe(1);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('planReview — ignores and documents', () => {
|
|
90
|
+
it('scopes a nested .gitignore to its folder', async () => {
|
|
91
|
+
const source = memSource({ 'docs/.gitignore': 'draft.md\n', 'docs/draft.md': '# D\n', 'draft.md': '# Root\n' });
|
|
92
|
+
const plan = await planReview(source, new InMemoryIngestManifest(), [DOCS_PACK]);
|
|
93
|
+
expect(plan.skipped).toContainEqual({ path: 'docs/draft.md', reason: 'ignored' });
|
|
94
|
+
expect(plan.changed).toContain('draft.md');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('skips pdf/office as binary unless a host parser claims the media type', async () => {
|
|
98
|
+
const source = memSource({ 'a.pdf': 'text', 'b.md': '# B\n' });
|
|
99
|
+
expect((await planReview(source, new InMemoryIngestManifest(), [DOCS_PACK])).skipped)
|
|
100
|
+
.toContainEqual({ path: 'a.pdf', reason: 'binary' });
|
|
101
|
+
const pdf: KnowledgeParser = {
|
|
102
|
+
id: 'pdf-text',
|
|
103
|
+
accepts: (s) => s.content.kind === 'text' && s.content.mediaType === 'application/pdf',
|
|
104
|
+
parse: (s) => [{ text: s.content.kind === 'text' ? s.content.text : '' }],
|
|
105
|
+
};
|
|
106
|
+
const withPdf: KnowledgePack = { ...DOCS_PACK, parsers: [pdf, ...DOCS_PACK.parsers] };
|
|
107
|
+
const plan = await planReview(source, new InMemoryIngestManifest(), [withPdf]);
|
|
108
|
+
expect(plan.changed).toContain('a.pdf');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('buildGraph — stale knowledge', () => {
|
|
113
|
+
const claim: StoredFact = {
|
|
114
|
+
key: 'claim:x', content: 'The lease ends', source: 'review', importance: 0.5, origin: 'model',
|
|
115
|
+
fileAnchors: [{ path: 'gone.md', contentHash: 'h:old' }],
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
it('marks a model fact anchored to a deleted source stale', () => {
|
|
119
|
+
const g = buildGraph({ rootId: ROOT, packs: [DOCS_PACK], extracted: [extractedOf(fileNode('a.md'))], facts: [claim], relations: [] });
|
|
120
|
+
expect(g.nodes.find((n) => n.ref === 'fact:claim:x')?.stale).toBe(true);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('carries a stale relation as a stale edge', () => {
|
|
124
|
+
const g = buildGraph({
|
|
125
|
+
rootId: ROOT, packs: [DOCS_PACK], extracted: [extractedOf(fileNode('a.md')), extractedOf(fileNode('b.md'))], facts: [],
|
|
126
|
+
relations: [{ from: ref('a.md'), to: ref('b.md'), kind: 'agrees', weight: 1, origin: 'model', staleAt: '2026-10-28' }],
|
|
127
|
+
});
|
|
128
|
+
expect(g.edges.find((e) => e.kind === 'agrees')?.stale).toBe(true);
|
|
129
|
+
expect(g.stats.stale).toBe(0); // stale NODES only; the edge carries its own flag
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('reports a contradiction naming both sections', () => {
|
|
133
|
+
const fact = (key: string, path: string): StoredFact => ({
|
|
134
|
+
key, content: key, source: 'review', importance: 0.5, origin: 'model', fileAnchors: [{ path, contentHash: `h:${path}` }],
|
|
135
|
+
});
|
|
136
|
+
const g = buildGraph({
|
|
137
|
+
rootId: ROOT, packs: [DOCS_PACK],
|
|
138
|
+
extracted: [extractedOf(fileNode('a.md')), extractedOf(fileNode('b.md'))],
|
|
139
|
+
facts: [fact('claim:a', 'a.md'), fact('claim:b', 'b.md')],
|
|
140
|
+
relations: [{ from: 'fact:claim:a', to: 'fact:claim:b', kind: 'contradicts', weight: 1, origin: 'model', confidence: 0.8 }],
|
|
141
|
+
});
|
|
142
|
+
const f = g.findings.find((x) => x.kind === 'contradiction');
|
|
143
|
+
expect(f?.params).toMatchObject({ fileA: 'a.md', fileB: 'b.md', confidence: 80 });
|
|
144
|
+
expect(f?.requestKey).toBe('knowledgeGraph.fix.contradiction');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('docs extract — links and sections', () => {
|
|
149
|
+
const ctx: ExtractContext = { rootId: ROOT, knownKeys: new Map(), resolvePath: resolveRelativePath };
|
|
150
|
+
const extract = (path: string, text: string) => {
|
|
151
|
+
const src: SourceDocument = asPathSource({ id: path, tenantId: 't', content: { kind: 'text', text } }, path, `h:${path}`);
|
|
152
|
+
return markdownParser.extract!(src, markdownParser.parse(src), ctx);
|
|
153
|
+
};
|
|
154
|
+
const links = (ex: ReturnType<typeof extract>) => ex.edges.filter((e) => e.kind === 'links').map((e) => e.to as NodeRef);
|
|
155
|
+
|
|
156
|
+
it('extracts reference-style links and keeps out-of-root targets as broken', () => {
|
|
157
|
+
const ex = extract('one.md', '# One\nSee [the guide][g] and [up](../outside.md).\n\n[g]: docs/guide.md\n');
|
|
158
|
+
expect(links(ex).sort()).toEqual([ref('../outside.md'), ref('docs/guide.md')].sort());
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('makes text before the first heading a section, but not front matter alone', () => {
|
|
162
|
+
const pre = extract('p.md', 'Intro before any heading.\n# H\nbody\n');
|
|
163
|
+
expect(pre.nodes.some((n) => n.ref === `${ref('p.md')}#~preamble`)).toBe(true);
|
|
164
|
+
const fm = extract('f.md', '---\ntitle: T\n---\n# H\nbody\n');
|
|
165
|
+
expect(fm.nodes.some((n) => n.ref.endsWith('#body'))).toBe(false);
|
|
166
|
+
});
|
|
167
|
+
});
|