@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
package/src/knowledge/review.ts
CHANGED
|
@@ -5,33 +5,34 @@
|
|
|
5
5
|
* plan (walk + manifest diff) → per changed file: read · parse (the ONE ParserRegistry,
|
|
6
6
|
* composed from the packs) · extract (cached by content hash) · judge (changed sections
|
|
7
7
|
* of judged kinds, within budget) · write · markStale → analyzers → compare near-duplicate
|
|
8
|
-
* claims → manifest + scope digest.
|
|
8
|
+
* claims → manifest + scope digest. Claims whose compare pairs were skipped wait in the
|
|
9
|
+
* compare manifest for *Continue*.
|
|
9
10
|
*
|
|
10
11
|
* Store judgement, compute perception: only `model` facts and relations are written —
|
|
11
12
|
* `extracted` output goes to the extracted cache, never to memory ({@link assertStoredBatch}).
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* and
|
|
13
|
+
* A file whose read throws is skipped, never retired: its knowledge and manifest hash stay
|
|
14
|
+
* as they were (`readErrors`); only a file the fresh plan no longer lists is removed.
|
|
15
|
+
* Abort is honoured between files and inside judgement; a file is written whole or not at
|
|
16
|
+
* all. A file whose sections were cut by the budget stays "changed" in the manifest, so
|
|
17
|
+
* *Continue* (the confirmed plan passed back as `args.plan`, no re-walk) judges only the
|
|
18
|
+
* sections not judged yet. A file owed under an extractor upgrade that this run left
|
|
19
|
+
* unfinished (a failed read, an abort, the budget) stays owed — see owedFiles.ts — so the
|
|
20
|
+
* next review or *Continue* picks up exactly those files, whatever their content does.
|
|
15
21
|
*/
|
|
16
22
|
|
|
17
23
|
import { hashText } from '../ingest/hash.js';
|
|
24
|
+
import type { SourceDocument } from '../ingest/types.js';
|
|
18
25
|
import { sha256Hex } from '../retrieval/knowledge-index/sha256.js';
|
|
19
|
-
import type {
|
|
20
|
-
ExtractContext, Extracted, KnowledgeParser, KnowledgeStore, NodeRef, ReviewArgs, ReviewReport, ScopeRecord,
|
|
21
|
-
StoredFact, StoredRelation,
|
|
22
|
-
} from './model.js';
|
|
23
|
-
import type { SourceDocument, ParsedSection } from '../ingest/types.js';
|
|
26
|
+
import type { NodeRef, ReviewArgs, ReviewReport, ScopeRecord, StoredFact, StoredRelation } from './model.js';
|
|
24
27
|
import { SECTION_INDEX_BADGE } from '../ingest/docsExtract.js';
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} from './
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
} from './
|
|
33
|
-
import { entityName, knownKeysOf, resolveEntities } from './resolve.js';
|
|
34
|
-
import { basenameOf, canonicalJson, compareStr, factKeyOf, srcRef } from './refs.js';
|
|
28
|
+
import { owedAfterRun, owedCalls, saveExtractorState } from './owedFiles.js';
|
|
29
|
+
import { planDetail, refreshPlan } from './plan.js';
|
|
30
|
+
import { composePacks, filesManifestKey, isBinaryText, judgedManifestKey, manifestMap, saveManifestMap } from './sources.js';
|
|
31
|
+
import { extractFileDetailed, knownKeysOfEntities } from './extractFile.js';
|
|
32
|
+
import { DEFAULT_REVIEW_MODEL_CALLS, JudgedBatch, judgeSections, type CompareOutcome, type JudgeBudget } from './judge.js';
|
|
33
|
+
import { compareNew, pendingClaims, saveAwaiting } from './reviewCompare.js';
|
|
34
|
+
import { factsWithoutAnchor, StoredIndex } from './reviewStored.js';
|
|
35
|
+
import { canonicalJson, compareStr, srcRef } from './refs.js';
|
|
35
36
|
|
|
36
37
|
/** Throws if a batch carries `extracted` items — perception is never memory. */
|
|
37
38
|
export function assertStoredBatch(batch: { facts: readonly StoredFact[]; relations: readonly StoredRelation[] }): void {
|
|
@@ -39,66 +40,6 @@ export function assertStoredBatch(batch: { facts: readonly StoredFact[]; relatio
|
|
|
39
40
|
if (bad) throw new Error('knowledge: extracted output is never written to a KnowledgeStore');
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
async function extractedFor(
|
|
43
|
-
store: KnowledgeStore, parser: KnowledgeParser, pack: string, src: SourceDocument, sections: ParsedSection[],
|
|
44
|
-
ctx: ExtractContext, hash: string,
|
|
45
|
-
): Promise<Extracted> {
|
|
46
|
-
const ref = srcRef(ctx.rootId, src.id);
|
|
47
|
-
const cached = await store.getExtracted?.(hash);
|
|
48
|
-
const hit = cached?.find((e) => e.sourceRef === ref);
|
|
49
|
-
if (hit) return hit;
|
|
50
|
-
const ex: Extracted = parser.extract
|
|
51
|
-
? { ...parser.extract(src, sections, ctx), sourceHash: hash }
|
|
52
|
-
: {
|
|
53
|
-
sourceRef: ref, sourceHash: hash, edges: [], keys: [{ ref, key: src.id }],
|
|
54
|
-
nodes: [{ ref, kind: 'file', label: basenameOf(src.id), pack, importance: 0, origin: 'extracted', sourceHash: hash }],
|
|
55
|
-
};
|
|
56
|
-
await store.putExtracted?.(hash, [...(cached ?? []).filter((e) => e.sourceRef !== ref), ex]);
|
|
57
|
-
return ex;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Stored knowledge, indexed for re-anchoring unchanged sections without a model call. */
|
|
61
|
-
class StoredIndex {
|
|
62
|
-
readonly facts: Map<string, StoredFact>;
|
|
63
|
-
private readonly from = new Map<string, StoredRelation[]>();
|
|
64
|
-
private readonly to = new Map<string, StoredRelation[]>();
|
|
65
|
-
|
|
66
|
-
constructor(facts: StoredFact[], relations: StoredRelation[]) {
|
|
67
|
-
this.facts = new Map(facts.map((f) => [f.key, f] as const));
|
|
68
|
-
for (const r of relations) {
|
|
69
|
-
if (r.origin !== 'model') continue;
|
|
70
|
-
(this.from.get(r.from) ?? this.from.set(r.from, []).get(r.from)!).push(r);
|
|
71
|
-
(this.to.get(r.to) ?? this.to.set(r.to, []).get(r.to)!).push(r);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** An unchanged section keeps its claims and mentions; they are re-anchored to the file's new hash. */
|
|
76
|
-
refresh(section: NodeRef, path: string, hash: string, batch: JudgedBatch, entities: Map<string, StoredFact>): void {
|
|
77
|
-
const reanchor = (f: StoredFact): StoredFact => ({
|
|
78
|
-
...f, fileAnchors: f.fileAnchors.map((a) => (a.path === path ? { ...a, contentHash: hash } : a)),
|
|
79
|
-
});
|
|
80
|
-
const relation = (r: StoredRelation) => batch.relation({ ...r, sourceHash: hash, staleAt: null });
|
|
81
|
-
for (const r of this.to.get(section) ?? []) {
|
|
82
|
-
if (r.kind !== 'about') continue;
|
|
83
|
-
relation(r);
|
|
84
|
-
const key = factKeyOf(r.from);
|
|
85
|
-
const fact = key && (batch.facts.get(key) ?? this.facts.get(key));
|
|
86
|
-
if (fact && fact.origin === 'model') batch.fact(reanchor(fact));
|
|
87
|
-
for (const m of this.from.get(r.from) ?? []) if (m.kind === 'mentions') relation(m);
|
|
88
|
-
}
|
|
89
|
-
for (const r of this.from.get(section) ?? []) {
|
|
90
|
-
if (r.kind !== 'mentions') continue;
|
|
91
|
-
relation(r);
|
|
92
|
-
const ent = entities.get(r.to);
|
|
93
|
-
if (ent && ent.origin === 'model') {
|
|
94
|
-
const next = reanchor(ent);
|
|
95
|
-
entities.set(r.to, next);
|
|
96
|
-
batch.fact(next);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
43
|
export async function reviewDirectory(args: ReviewArgs): Promise<ReviewReport> {
|
|
103
44
|
const now = () => Date.now();
|
|
104
45
|
const started = now();
|
|
@@ -108,10 +49,12 @@ export async function reviewDirectory(args: ReviewArgs): Promise<ReviewReport> {
|
|
|
108
49
|
const progress = (p: Parameters<NonNullable<ReviewArgs['onProgress']>>[0]) => args.onProgress?.(p);
|
|
109
50
|
const report: ReviewReport = {
|
|
110
51
|
rootId, digest: '', extracted: 0, judged: 0, unjudged: 0, invalidJudgements: 0,
|
|
111
|
-
factsWritten: 0, relationsWritten: 0, staleMarked: 0, aborted: false, durationMs: 0,
|
|
52
|
+
factsWritten: 0, relationsWritten: 0, staleMarked: 0, readErrors: 0, aborted: false, durationMs: 0,
|
|
112
53
|
};
|
|
113
54
|
|
|
114
|
-
const detail =
|
|
55
|
+
const detail = args.plan
|
|
56
|
+
? await refreshPlan(args.plan, manifest)
|
|
57
|
+
: await planDetail(source, manifest, packs, { ...(args.force ? { force: true } : {}), compare: !!args.similar && !!args.judgement });
|
|
115
58
|
progress({ phase: 'plan', done: detail.files.length, total: detail.files.length });
|
|
116
59
|
const composed = composePacks(packs);
|
|
117
60
|
const packIds = packs.map((p) => p.id).sort(compareStr);
|
|
@@ -119,11 +62,7 @@ export async function reviewDirectory(args: ReviewArgs): Promise<ReviewReport> {
|
|
|
119
62
|
const [storedFacts, storedRelations] = await Promise.all([store.facts(scope), store.relations(scope)]);
|
|
120
63
|
const stored = new StoredIndex(storedFacts, storedRelations);
|
|
121
64
|
const entities = new Map(storedFacts.filter((f) => f.key.startsWith('ent:')).map((f) => [f.key, f] as const));
|
|
122
|
-
const
|
|
123
|
-
rootId,
|
|
124
|
-
knownKeys: knownKeysOf(resolveEntities([...entities.keys()].map((k) => ({ ref: k as NodeRef, key: entityName(k) })))),
|
|
125
|
-
resolvePath: resolveRelativePath,
|
|
126
|
-
};
|
|
65
|
+
const knownKeys = knownKeysOfEntities(entities.keys());
|
|
127
66
|
const budget: JudgeBudget = {
|
|
128
67
|
modelCalls: args.budget?.modelCalls ?? DEFAULT_REVIEW_MODEL_CALLS,
|
|
129
68
|
deadline: started + (Number.isFinite(args.budget?.ms) ? args.budget.ms : Number.POSITIVE_INFINITY),
|
|
@@ -133,7 +72,8 @@ export async function reviewDirectory(args: ReviewArgs): Promise<ReviewReport> {
|
|
|
133
72
|
const judgedPrior = await manifestMap(manifest, judgedManifestKey(rootId));
|
|
134
73
|
const judgedNow = new Map(judgedPrior);
|
|
135
74
|
const filesNow = new Map(detail.prior);
|
|
136
|
-
|
|
75
|
+
// Claims awaiting comparison: those a previous run could not compare, then this run's.
|
|
76
|
+
const newClaims = await pendingClaims(manifest, rootId, stored.facts);
|
|
137
77
|
|
|
138
78
|
const write = async (withScope: ScopeRecord = scopeRecord) => {
|
|
139
79
|
const out = batch.take();
|
|
@@ -144,20 +84,60 @@ export async function reviewDirectory(args: ReviewArgs): Promise<ReviewReport> {
|
|
|
144
84
|
report.relationsWritten += out.relations.length;
|
|
145
85
|
};
|
|
146
86
|
|
|
87
|
+
// A source that is gone: its knowledge goes stale at no hash, its judged sections are forgotten, and
|
|
88
|
+
// facts other sources still back drop its anchor. `rewritten` is the run's one record of such facts,
|
|
89
|
+
// so a later retire() never restores an anchor an earlier one dropped.
|
|
90
|
+
const rewritten = new Map<string, StoredFact>();
|
|
91
|
+
const retire = async (paths: readonly string[]) => {
|
|
92
|
+
const live = new Map([...stored.facts, ...entities, ...rewritten]);
|
|
93
|
+
for (const path of paths) {
|
|
94
|
+
await store.markStale(scope, srcRef(rootId, path), '');
|
|
95
|
+
report.staleMarked += 1;
|
|
96
|
+
filesNow.delete(path);
|
|
97
|
+
const sectionPrefix = `${srcRef(rootId, path)}#`;
|
|
98
|
+
for (const section of [...judgedNow.keys()]) if (section.startsWith(sectionPrefix)) judgedNow.delete(section);
|
|
99
|
+
for (const fact of factsWithoutAnchor(live.values(), path)) {
|
|
100
|
+
batch.fact(fact);
|
|
101
|
+
live.set(fact.key, fact);
|
|
102
|
+
rewritten.set(fact.key, fact);
|
|
103
|
+
if (entities.has(fact.key)) entities.set(fact.key, fact);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
await write();
|
|
107
|
+
};
|
|
108
|
+
|
|
147
109
|
const changed = detail.files.filter((f) => f.changed);
|
|
110
|
+
// Changed files this run finished (or had nothing to do for); an owed file not in it stays owed,
|
|
111
|
+
// at the model calls it still costs where this run could measure that (see owedFiles.ts).
|
|
112
|
+
const finished = new Set<string>();
|
|
113
|
+
const measured = new Map<string, number>();
|
|
148
114
|
for (const [i, f] of changed.entries()) {
|
|
149
115
|
if (signal?.aborted) { report.aborted = true; break; }
|
|
150
116
|
progress({ phase: 'extract', done: i, total: changed.length, path: f.path });
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
117
|
+
// A read that throws (permissions, a lock, a race with a delete) says nothing about the file:
|
|
118
|
+
// skipped with its knowledge and manifest hash intact, tried again next review.
|
|
119
|
+
let doc: SourceDocument;
|
|
120
|
+
try { doc = await source.read(f.path); } catch {
|
|
121
|
+
report.readErrors += 1;
|
|
122
|
+
measured.set(f.path, owedCalls(detail.extractor, f.path)); // a read error learns nothing: keep what it was owed
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
// Recorded, so a file found binary on read is not re-read by every later review.
|
|
126
|
+
if (doc.content.kind === 'text' && isBinaryText(doc.content.text)) {
|
|
127
|
+
filesNow.set(f.path, f.hash);
|
|
128
|
+
finished.add(f.path);
|
|
129
|
+
await store.markStale(scope, srcRef(rootId, f.path), f.hash);
|
|
130
|
+
report.staleMarked += 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const extraction = await extractFileDetailed({
|
|
134
|
+
rootId, path: f.path, hash: f.hash, doc, packs, store, composed, knownKeys,
|
|
135
|
+
});
|
|
136
|
+
if (!extraction) { finished.add(f.path); continue; }
|
|
137
|
+
const { extracted: ex, sections, pack } = extraction;
|
|
158
138
|
report.extracted += 1;
|
|
159
139
|
|
|
160
|
-
const spec =
|
|
140
|
+
const spec = pack.judgement;
|
|
161
141
|
let complete = true;
|
|
162
142
|
if (spec && args.judgement && (spec.claims || spec.entities)) {
|
|
163
143
|
const kinds = new Set(spec.nodeKinds);
|
|
@@ -170,35 +150,45 @@ export async function reviewDirectory(args: ReviewArgs): Promise<ReviewReport> {
|
|
|
170
150
|
else toJudge.push({ ref: node.ref, text });
|
|
171
151
|
}
|
|
172
152
|
const unjudgedBefore = batch.unjudged;
|
|
153
|
+
// Staged per file: a section counts as judged only once its facts are written,
|
|
154
|
+
// so an abort mid-file leaves it to be judged again (written whole or not at all).
|
|
155
|
+
const judgedHere = new Map<NodeRef, string>();
|
|
173
156
|
progress({ phase: 'judge', done: i, total: changed.length, path: f.path });
|
|
174
157
|
try {
|
|
175
158
|
const claims = await judgeSections({
|
|
176
|
-
port: args.judgement, pack:
|
|
159
|
+
port: args.judgement, pack: pack.id, path: f.path, fileHash: f.hash, sections: toJudge,
|
|
177
160
|
budget, batch, entities, ...(signal ? { signal } : {}),
|
|
178
|
-
onJudged: (ref) =>
|
|
161
|
+
onJudged: (ref) => judgedHere.set(ref, hashText(toJudge.find((s) => s.ref === ref)!.text)),
|
|
179
162
|
});
|
|
180
|
-
for
|
|
163
|
+
// Only a pack that asks for contradictions has claims to compare (the estimate counts the same).
|
|
164
|
+
// Deleted first so a re-judged claim moves to the newest position (the awaiting cap drops the oldest).
|
|
165
|
+
if (spec.contradictions) {
|
|
166
|
+
for (const c of claims) { newClaims.delete(c.ref); newClaims.set(c.ref, { text: c.text, hash: f.hash }); }
|
|
167
|
+
}
|
|
181
168
|
} catch (err) {
|
|
182
169
|
if (!signal?.aborted) throw err;
|
|
183
170
|
batch.take();
|
|
184
171
|
report.aborted = true;
|
|
185
172
|
break;
|
|
186
173
|
}
|
|
174
|
+
for (const [ref, h] of judgedHere) judgedNow.set(ref, h);
|
|
187
175
|
complete = batch.unjudged === unjudgedBefore;
|
|
176
|
+
// A content-changed file may revert to the manifest bytes: then all it had to judge — and what it was
|
|
177
|
+
// already owed from earlier cuts — is still owed.
|
|
178
|
+
if (!complete) {
|
|
179
|
+
const contentChanged = detail.prior.get(f.path) !== f.hash;
|
|
180
|
+
measured.set(f.path, contentChanged ? toJudge.length + (detail.extractor.owed.get(f.path) ?? 0) : batch.unjudged - unjudgedBefore);
|
|
181
|
+
}
|
|
188
182
|
}
|
|
189
183
|
progress({ phase: 'write', done: i, total: changed.length, path: f.path });
|
|
190
184
|
await write();
|
|
191
185
|
await store.markStale(scope, srcRef(rootId, f.path), f.hash);
|
|
192
186
|
report.staleMarked += 1;
|
|
193
|
-
if (complete) filesNow.set(f.path, f.hash);
|
|
187
|
+
if (complete) { filesNow.set(f.path, f.hash); finished.add(f.path); }
|
|
194
188
|
}
|
|
195
189
|
|
|
196
190
|
if (!report.aborted) {
|
|
197
|
-
|
|
198
|
-
await store.markStale(scope, srcRef(rootId, path), '');
|
|
199
|
-
report.staleMarked += 1;
|
|
200
|
-
filesNow.delete(path);
|
|
201
|
-
}
|
|
191
|
+
await retire(detail.plan.removed);
|
|
202
192
|
for (const pack of packs) {
|
|
203
193
|
if (!pack.analyzers) continue;
|
|
204
194
|
for (const ex of await pack.analyzers.analyse(rootId, signal)) {
|
|
@@ -207,27 +197,34 @@ export async function reviewDirectory(args: ReviewArgs): Promise<ReviewReport> {
|
|
|
207
197
|
}
|
|
208
198
|
}
|
|
209
199
|
progress({ phase: 'resolve', done: 0, total: newClaims.size });
|
|
210
|
-
const wantsCompare = packs.some((p) => p.judgement?.contradictions);
|
|
211
|
-
if (wantsCompare && args.judgement && args.similar && newClaims.size > 0 && budgetLeft(budget)) {
|
|
212
|
-
const pairs = await args.similar([...newClaims.keys()].sort(compareStr));
|
|
213
|
-
const claims = new Map(newClaims);
|
|
214
|
-
for (const p of pairs) {
|
|
215
|
-
for (const id of [p.a, p.b]) {
|
|
216
|
-
const fact = !claims.has(id) ? stored.facts.get(factKeyOf(id as NodeRef) ?? '') : undefined;
|
|
217
|
-
if (fact?.key.startsWith('claim:')) claims.set(id, { text: fact.content, hash: fact.fileAnchors[0]?.contentHash ?? '' });
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
progress({ phase: 'judge', done: 0, total: pairs.length });
|
|
221
|
-
await compareClaims({ port: args.judgement, pairs, claims, budget, batch, ...(signal ? { signal } : {}) });
|
|
222
|
-
}
|
|
223
200
|
}
|
|
224
201
|
|
|
202
|
+
// The compare phase needs a pack asking for it AND both ports.
|
|
203
|
+
const wantsCompare = packs.some((p) => p.judgement?.contradictions);
|
|
204
|
+
const canCompare = wantsCompare && !!args.judgement && !!args.similar;
|
|
205
|
+
let outcome: CompareOutcome | undefined;
|
|
206
|
+
if (!report.aborted && canCompare) {
|
|
207
|
+
outcome = await compareNew({
|
|
208
|
+
args, pending: newClaims, known: stored.facts, budget, batch,
|
|
209
|
+
onPairs: (total) => progress({ phase: 'judge', done: 0, total }),
|
|
210
|
+
});
|
|
211
|
+
// Aborted only if the abort landed before the last pair was compared.
|
|
212
|
+
if (outcome?.aborted) report.aborted = true;
|
|
213
|
+
}
|
|
214
|
+
// No pack asks for contradictions: nothing waits, and an earlier run's awaiting set is left as it was.
|
|
215
|
+
if (wantsCompare) await saveAwaiting(manifest, rootId, newClaims, outcome);
|
|
216
|
+
|
|
225
217
|
report.judged = batch.judged;
|
|
226
218
|
report.unjudged = batch.unjudged;
|
|
227
219
|
report.invalidJudgements = batch.invalid;
|
|
228
220
|
report.digest = sha256Hex(canonicalJson({ rootId, packs: packIds, files: [...filesNow].sort((a, b) => compareStr(a[0], b[0])) }));
|
|
229
221
|
await saveManifestMap(manifest, filesManifestKey(rootId), filesNow);
|
|
230
222
|
await saveManifestMap(manifest, judgedManifestKey(rootId), judgedNow);
|
|
223
|
+
// After every run: today's version and every file still owed a re-extraction — the unfinished ones,
|
|
224
|
+
// content-changed or not, and the owed paths the plan did not list that the manifest still holds.
|
|
225
|
+
await saveExtractorState(manifest, rootId, owedAfterRun({
|
|
226
|
+
state: detail.extractor, changed, prior: detail.prior, finished, carried: detail.carried, live: filesNow, measured,
|
|
227
|
+
}));
|
|
231
228
|
await write(report.aborted ? scopeRecord : { ...scopeRecord, lastDigest: report.digest, lastReviewedAt: new Date(now()).toISOString() });
|
|
232
229
|
report.durationMs = now() - started;
|
|
233
230
|
progress({ phase: 'done', done: changed.length, total: changed.length });
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/review.upgrade.test.ts
|
|
3
|
+
* Upgrade and robustness follow-ups: the extractor version lives in its own manifest entry
|
|
4
|
+
* (the files manifest keeps its key), *Re-review all*, a failed read retires nothing, the
|
|
5
|
+
* compare phase without its ports, the reserved preamble ref, claim text and byName determinism.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
9
|
+
import { hashText } from '../ingest/hash.js';
|
|
10
|
+
import { markdownParser } from '../ingest/parsers.js';
|
|
11
|
+
import { buildGraph, graphDigest } from './build.js';
|
|
12
|
+
import type { ExtractContext, KnowledgePack } from './model.js';
|
|
13
|
+
import { DOCS_PACK } from './packs/docs.js';
|
|
14
|
+
import { planReview } from './plan.js';
|
|
15
|
+
import { reviewDirectory } from './review.js';
|
|
16
|
+
import { MAX_AWAITING_CLAIMS, saveAwaiting, type PendingClaims } from './reviewCompare.js';
|
|
17
|
+
import {
|
|
18
|
+
asPathSource, compareManifestKey, EXTRACTOR_VERSION, extractorManifestKey, filesManifestKey, judgedManifestKey, manifestMap,
|
|
19
|
+
resolveRelativePath,
|
|
20
|
+
} from './sources.js';
|
|
21
|
+
import {
|
|
22
|
+
args, edge, extractedOf, fakeJudge, FILES, fileNode, memSource, memStore, quietPack, ref, ROOT, similar, stateOf,
|
|
23
|
+
} from './testkit.test-util.js';
|
|
24
|
+
import { canonicalJson, factRef, srcRef } from './refs.js';
|
|
25
|
+
|
|
26
|
+
describe('the extractor version has its own manifest entry', () => {
|
|
27
|
+
it('the files manifest keeps the key consumers read', () => {
|
|
28
|
+
expect(filesManifestKey(ROOT)).toBe(`knowledge:${ROOT}`);
|
|
29
|
+
expect(extractorManifestKey(ROOT)).toBe(`knowledge:${ROOT}:extractor`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('an old manifest (files, no version entry) re-extracts once, still detects removals, and re-anchors unchanged sections', async () => {
|
|
33
|
+
const source = memSource({ ...FILES });
|
|
34
|
+
const store = memStore();
|
|
35
|
+
const manifest = new InMemoryIngestManifest();
|
|
36
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
37
|
+
expect(await stateOf(manifest)).toEqual({ version: EXTRACTOR_VERSION, owed: [] });
|
|
38
|
+
expect((await manifest.get(filesManifestKey(ROOT)))!.map((f) => f.id)).toEqual(['a.md', 'b.md', 'c.md']);
|
|
39
|
+
|
|
40
|
+
delete source.files['b.md'];
|
|
41
|
+
source.files['c.md'] = '# C\ngamma changed\n';
|
|
42
|
+
const withVersion = await planReview(source, manifest, [DOCS_PACK]);
|
|
43
|
+
expect(withVersion.changed).toEqual(['c.md']);
|
|
44
|
+
|
|
45
|
+
await manifest.set(extractorManifestKey(ROOT), []); // what a v2026.10.31 manifest looks like
|
|
46
|
+
const old = await planReview(source, manifest, [DOCS_PACK]);
|
|
47
|
+
expect(old.removed).toEqual(['b.md']);
|
|
48
|
+
expect(old.changed).toEqual(['a.md', 'c.md']);
|
|
49
|
+
|
|
50
|
+
const judge = fakeJudge();
|
|
51
|
+
const report = await reviewDirectory(args(source, store, manifest, { judgement: judge }));
|
|
52
|
+
expect(report.extracted).toBe(2);
|
|
53
|
+
expect(judge.requests.filter((r) => r.kind === 'extract')).toHaveLength(1); // c.md only; a.md is re-anchored
|
|
54
|
+
expect([...(await manifestMap(manifest, filesManifestKey(ROOT))).keys()]).toEqual(['a.md', 'c.md']);
|
|
55
|
+
expect(await stateOf(manifest)).toEqual({ version: EXTRACTOR_VERSION, owed: [] });
|
|
56
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual([]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('an aborted upgrade run records the version and owes the files it never reached', async () => {
|
|
60
|
+
const source = memSource({ ...FILES });
|
|
61
|
+
const store = memStore();
|
|
62
|
+
const manifest = new InMemoryIngestManifest();
|
|
63
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
64
|
+
await manifest.delete(extractorManifestKey(ROOT));
|
|
65
|
+
|
|
66
|
+
const controller = new AbortController();
|
|
67
|
+
controller.abort();
|
|
68
|
+
const report = await reviewDirectory(args(source, store, manifest, { signal: controller.signal }));
|
|
69
|
+
expect(report.aborted).toBe(true);
|
|
70
|
+
expect(await stateOf(manifest)).toEqual({ version: EXTRACTOR_VERSION, owed: ['a.md', 'b.md', 'c.md'] });
|
|
71
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual(['a.md', 'b.md', 'c.md']);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('re-review all', () => {
|
|
76
|
+
it('marks every file changed, still finds removals and does not inflate the estimate', async () => {
|
|
77
|
+
const source = memSource({ ...FILES });
|
|
78
|
+
const manifest = new InMemoryIngestManifest();
|
|
79
|
+
const store = memStore();
|
|
80
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
81
|
+
delete source.files['b.md'];
|
|
82
|
+
|
|
83
|
+
const plain = await planReview(source, manifest, [DOCS_PACK]);
|
|
84
|
+
const forced = await planReview(source, manifest, [DOCS_PACK], { force: true });
|
|
85
|
+
expect(plain.changed).toEqual([]);
|
|
86
|
+
expect(forced.changed).toEqual(['a.md', 'c.md']);
|
|
87
|
+
expect(forced.removed).toEqual(['b.md']);
|
|
88
|
+
expect(forced.estimatedModelCalls).toBe(plain.estimatedModelCalls);
|
|
89
|
+
|
|
90
|
+
const judge = fakeJudge();
|
|
91
|
+
const report = await reviewDirectory(args(source, store, manifest, { judgement: judge, force: true }));
|
|
92
|
+
expect(report.extracted).toBe(2);
|
|
93
|
+
expect(judge.requests).toHaveLength(0);
|
|
94
|
+
expect([...(await manifestMap(manifest, filesManifestKey(ROOT))).keys()]).toEqual(['a.md', 'c.md']);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('a file that cannot be read', () => {
|
|
99
|
+
it('keeps its facts, anchors and manifest hash, and is counted', async () => {
|
|
100
|
+
const source = memSource({ 'a.md': '# A\nalpha\n' });
|
|
101
|
+
const store = memStore();
|
|
102
|
+
const manifest = new InMemoryIngestManifest();
|
|
103
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
104
|
+
const before = { facts: await store.facts({ rootId: ROOT }), relations: await store.relations({ rootId: ROOT }) };
|
|
105
|
+
const hash = hashText('# A\nalpha\n');
|
|
106
|
+
|
|
107
|
+
source.files['a.md'] = '# A\nalpha edited\n';
|
|
108
|
+
source.read = async () => { throw Object.assign(new Error('permission denied'), { code: 'EACCES' }); };
|
|
109
|
+
const report = await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
110
|
+
expect(report).toMatchObject({ readErrors: 1, extracted: 0, aborted: false });
|
|
111
|
+
expect(await store.facts({ rootId: ROOT })).toEqual(before.facts);
|
|
112
|
+
expect((await store.relations({ rootId: ROOT })).every((r) => !r.staleAt)).toBe(true);
|
|
113
|
+
expect((await manifestMap(manifest, filesManifestKey(ROOT))).get('a.md')).toBe(hash);
|
|
114
|
+
// Still changed for the next review.
|
|
115
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual(['a.md']);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('bookkeeping of removed and binary files', () => {
|
|
120
|
+
it('counts them stale, prunes their judged sections and drops their anchor from shared entities', async () => {
|
|
121
|
+
const source = memSource({ ...FILES });
|
|
122
|
+
const store = memStore();
|
|
123
|
+
const manifest = new InMemoryIngestManifest();
|
|
124
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
125
|
+
expect([...(await manifestMap(manifest, judgedManifestKey(ROOT))).keys()].some((k) => k.startsWith(`${srcRef(ROOT, 'b.md')}#`))).toBe(true);
|
|
126
|
+
|
|
127
|
+
delete source.files['b.md'];
|
|
128
|
+
delete source.files['c.md'];
|
|
129
|
+
const removed = await reviewDirectory(args(source, store, manifest));
|
|
130
|
+
expect(removed.staleMarked).toBe(2);
|
|
131
|
+
const judged = [...(await manifestMap(manifest, judgedManifestKey(ROOT))).keys()];
|
|
132
|
+
expect(judged.every((k) => k.startsWith(`${srcRef(ROOT, 'a.md')}#`))).toBe(true);
|
|
133
|
+
const lease = (await store.facts({ rootId: ROOT })).find((f) => f.key === 'ent:docs:lease')!;
|
|
134
|
+
expect(lease.fileAnchors.map((a) => a.path)).toEqual(['a.md']);
|
|
135
|
+
|
|
136
|
+
source.files['a.md'] = 'bin\u0000ary';
|
|
137
|
+
expect((await reviewDirectory(args(source, store, manifest))).staleMarked).toBe(1);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('the compare phase', () => {
|
|
142
|
+
it('keeps the claims awaiting when the host has no similar port, so a later run with one can compare them', async () => {
|
|
143
|
+
const manifest = new InMemoryIngestManifest();
|
|
144
|
+
await reviewDirectory(args(memSource({ ...FILES }), memStore(), manifest, { judgement: fakeJudge() }));
|
|
145
|
+
expect((await manifestMap(manifest, compareManifestKey(ROOT))).size).toBeGreaterThan(0);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('an extracted-only run (no judgement port) leaves the awaiting set intact', async () => {
|
|
149
|
+
const source = memSource({ ...FILES });
|
|
150
|
+
const store = memStore();
|
|
151
|
+
const manifest = new InMemoryIngestManifest();
|
|
152
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
153
|
+
const before = await manifest.get(compareManifestKey(ROOT));
|
|
154
|
+
expect(before!.length).toBeGreaterThan(0);
|
|
155
|
+
|
|
156
|
+
await reviewDirectory(args(source, store, manifest));
|
|
157
|
+
expect(await manifest.get(compareManifestKey(ROOT))).toEqual(before);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('a pack that does not ask for contradictions never touches the awaiting set', async () => {
|
|
161
|
+
const source = memSource({ ...FILES });
|
|
162
|
+
const store = memStore();
|
|
163
|
+
const manifest = new InMemoryIngestManifest();
|
|
164
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
165
|
+
const before = JSON.stringify(await manifest.get(compareManifestKey(ROOT)));
|
|
166
|
+
expect(before).not.toBe('[]');
|
|
167
|
+
|
|
168
|
+
// A new claim exists after this run, yet nothing is saved for it: no pack waits on a compare.
|
|
169
|
+
source.files['a.md'] = '# A\nalphabet\n';
|
|
170
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge(), packs: [quietPack] }));
|
|
171
|
+
expect((await store.facts({ rootId: ROOT })).some((f) => f.content.startsWith('Lease ends alphabet'))).toBe(true);
|
|
172
|
+
expect(JSON.stringify(await manifest.get(compareManifestKey(ROOT)))).toBe(before);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('bounds the awaiting set to the most recent claims', async () => {
|
|
176
|
+
const manifest = new InMemoryIngestManifest();
|
|
177
|
+
const pending: PendingClaims = new Map();
|
|
178
|
+
for (let i = 0; i < MAX_AWAITING_CLAIMS + 50; i++) pending.set(`fact:claim:${String(i).padStart(5, '0')}`, { text: 't', hash: 'h' });
|
|
179
|
+
await saveAwaiting(manifest, ROOT, pending, undefined);
|
|
180
|
+
const kept = [...(await manifestMap(manifest, compareManifestKey(ROOT))).keys()];
|
|
181
|
+
expect(kept).toHaveLength(MAX_AWAITING_CLAIMS);
|
|
182
|
+
expect(kept).toContain(`fact:claim:${String(MAX_AWAITING_CLAIMS + 49).padStart(5, '0')}`);
|
|
183
|
+
expect(kept).not.toContain('fact:claim:00000');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('only a pack that asks for contradictions puts its claims up for comparison', async () => {
|
|
187
|
+
const notes: KnowledgePack = {
|
|
188
|
+
id: 'notes',
|
|
189
|
+
parsers: [{ ...markdownParser, id: 'notes-md', accepts: (s) => s.id.endsWith('.txt') }],
|
|
190
|
+
judgement: { nodeKinds: ['section'], claims: true, entities: true, contradictions: false },
|
|
191
|
+
};
|
|
192
|
+
const store = memStore();
|
|
193
|
+
const manifest = new InMemoryIngestManifest();
|
|
194
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'n.txt': '# N\nnotes\n' });
|
|
195
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge(), packs: [notes, DOCS_PACK] }));
|
|
196
|
+
|
|
197
|
+
const claimRef = async (text: string) => {
|
|
198
|
+
const fact = (await store.facts({ rootId: ROOT })).find((f) => f.content.startsWith(text));
|
|
199
|
+
expect(fact).toBeDefined(); // judged either way
|
|
200
|
+
return factRef(fact!.key);
|
|
201
|
+
};
|
|
202
|
+
const awaiting = [...(await manifestMap(manifest, compareManifestKey(ROOT))).keys()];
|
|
203
|
+
expect(awaiting).toEqual([await claimRef('Lease ends alpha')]);
|
|
204
|
+
expect(awaiting).not.toContain(await claimRef('Lease ends notes'));
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('hands the similar port the texts of the pending claims, as the compare reads them', async () => {
|
|
208
|
+
const calls: Array<{ ids: string[]; texts: ReadonlyMap<string, string> | undefined }> = [];
|
|
209
|
+
const spy = async (ids: string[], texts?: ReadonlyMap<string, string>) => {
|
|
210
|
+
calls.push({ ids, texts });
|
|
211
|
+
return similar(ids);
|
|
212
|
+
};
|
|
213
|
+
const judge = fakeJudge();
|
|
214
|
+
await reviewDirectory(args(memSource({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' }), memStore(), new InMemoryIngestManifest(), {
|
|
215
|
+
judgement: judge, similar: spy,
|
|
216
|
+
}));
|
|
217
|
+
expect(calls).toHaveLength(1);
|
|
218
|
+
expect(calls[0]!.ids).toHaveLength(2);
|
|
219
|
+
expect([...calls[0]!.texts!.keys()].sort()).toEqual(calls[0]!.ids);
|
|
220
|
+
expect([...calls[0]!.texts!.values()].sort()).toEqual(['Lease ends alpha', 'Lease ends beta']);
|
|
221
|
+
// The same texts the compare call carries.
|
|
222
|
+
expect(judge.requests.find((r) => r.kind === 'compare')!.items.map((i) => i.text).sort()).toEqual(['Lease ends alpha', 'Lease ends beta']);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('compares a claim left awaiting by its claim text, the form a first run uses', async () => {
|
|
226
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'b.md': '# B\nbeta\n' });
|
|
227
|
+
const store = memStore();
|
|
228
|
+
const manifest = new InMemoryIngestManifest();
|
|
229
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge(), similar, budget: { modelCalls: 2, ms: 60_000 } }));
|
|
230
|
+
const judge = fakeJudge();
|
|
231
|
+
await reviewDirectory(args(source, store, manifest, { judgement: judge, similar }));
|
|
232
|
+
const compare = judge.requests.find((r) => r.kind === 'compare')!;
|
|
233
|
+
expect(compare.items.map((i) => i.text).sort()).toEqual(['Lease ends alpha', 'Lease ends beta']);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe('docs extract determinism and refs', () => {
|
|
238
|
+
const ctx: ExtractContext = { rootId: ROOT, knownKeys: new Map(), resolvePath: resolveRelativePath };
|
|
239
|
+
|
|
240
|
+
it('a preamble and a top-level "# Body" heading keep distinct refs', () => {
|
|
241
|
+
const text = 'Intro text.\n# Body\nunder the heading\n';
|
|
242
|
+
const src = asPathSource({ id: 'p.md', tenantId: 't', content: { kind: 'text', text } }, 'p.md', 'h:p');
|
|
243
|
+
const ex = markdownParser.extract!(src, markdownParser.parse(src), ctx);
|
|
244
|
+
const sections = ex.nodes.filter((n) => n.kind === 'section');
|
|
245
|
+
expect(sections.map((n) => n.ref).sort()).toEqual([`${ref('p.md')}#body`, `${ref('p.md')}#~preamble`].sort());
|
|
246
|
+
expect(sections.find((n) => n.ref.endsWith('#body'))!.label).toBe('Body');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('edges that differ only by byName digest and build the same in any input order', () => {
|
|
250
|
+
const edges = [edge('a.md', 'x.md', 'links', { byName: 'X' }), edge('a.md', 'x.md', 'links', { byName: 'Y' })];
|
|
251
|
+
const input = (es: typeof edges) => ({
|
|
252
|
+
rootId: ROOT, packs: [DOCS_PACK], facts: [], relations: [], extracted: [extractedOf(fileNode('a.md'), es)],
|
|
253
|
+
});
|
|
254
|
+
expect(graphDigest(input(edges))).toBe(graphDigest(input([...edges].reverse())));
|
|
255
|
+
expect(canonicalJson(buildGraph(input(edges)))).toBe(canonicalJson(buildGraph(input([...edges].reverse()))));
|
|
256
|
+
});
|
|
257
|
+
});
|