@seanhogg/builderforce-memory 2026.10.63 → 2026.10.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/knowledge/pack/frame.d.ts +12 -3
- package/dist/knowledge/pack/frame.d.ts.map +1 -1
- package/dist/knowledge/pack/frame.js +18 -4
- package/dist/knowledge/pack/frame.js.map +1 -1
- package/dist/knowledge/pack/manifest.d.ts +11 -3
- package/dist/knowledge/pack/manifest.d.ts.map +1 -1
- package/dist/knowledge/pack/manifest.js +26 -12
- package/dist/knowledge/pack/manifest.js.map +1 -1
- package/dist/knowledge/pack/sections/extr.d.ts.map +1 -1
- package/dist/knowledge/pack/sections/extr.js +16 -4
- package/dist/knowledge/pack/sections/extr.js.map +1 -1
- package/dist/knowledge/pack/sections/extrLists.d.ts +0 -1
- package/dist/knowledge/pack/sections/extrLists.d.ts.map +1 -1
- package/dist/knowledge/pack/sections/extrLists.js +5 -6
- package/dist/knowledge/pack/sections/extrLists.js.map +1 -1
- package/dist/knowledge/pack/sections/facts.d.ts.map +1 -1
- package/dist/knowledge/pack/sections/facts.js +3 -2
- package/dist/knowledge/pack/sections/facts.js.map +1 -1
- package/dist/knowledge/pack/sections/rows.d.ts.map +1 -1
- package/dist/knowledge/pack/sections/rows.js +11 -2
- package/dist/knowledge/pack/sections/rows.js.map +1 -1
- package/dist/knowledge/pack/strings.d.ts.map +1 -1
- package/dist/knowledge/pack/strings.js +6 -1
- package/dist/knowledge/pack/strings.js.map +1 -1
- package/dist/knowledge/pack/varint.d.ts +14 -0
- package/dist/knowledge/pack/varint.d.ts.map +1 -1
- package/dist/knowledge/pack/varint.js +32 -1
- package/dist/knowledge/pack/varint.js.map +1 -1
- package/dist/knowledge/review.d.ts +6 -6
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +56 -329
- package/dist/knowledge/review.js.map +1 -1
- package/dist/knowledge/reviewAnalyse.d.ts +17 -0
- package/dist/knowledge/reviewAnalyse.d.ts.map +1 -0
- package/dist/knowledge/reviewAnalyse.js +61 -0
- package/dist/knowledge/reviewAnalyse.js.map +1 -0
- package/dist/knowledge/reviewApply.d.ts +33 -0
- package/dist/knowledge/reviewApply.d.ts.map +1 -0
- package/dist/knowledge/reviewApply.js +121 -0
- package/dist/knowledge/reviewApply.js.map +1 -0
- package/dist/knowledge/reviewContext.d.ts +77 -0
- package/dist/knowledge/reviewContext.d.ts.map +1 -0
- package/dist/knowledge/reviewContext.js +111 -0
- package/dist/knowledge/reviewContext.js.map +1 -0
- package/dist/knowledge/reviewFinish.d.ts +9 -0
- package/dist/knowledge/reviewFinish.d.ts.map +1 -0
- package/dist/knowledge/reviewFinish.js +62 -0
- package/dist/knowledge/reviewFinish.js.map +1 -0
- package/dist/knowledge/reviewRunModel.d.ts +3 -0
- package/dist/knowledge/reviewRunModel.d.ts.map +1 -1
- package/dist/knowledge/reviewRunModel.js.map +1 -1
- package/dist/knowledge/stores/extractLogWriter.d.ts +16 -3
- package/dist/knowledge/stores/extractLogWriter.d.ts.map +1 -1
- package/dist/knowledge/stores/extractLogWriter.js +38 -13
- package/dist/knowledge/stores/extractLogWriter.js.map +1 -1
- package/dist/knowledge/stores/extractRefs.d.ts +68 -0
- package/dist/knowledge/stores/extractRefs.d.ts.map +1 -0
- package/dist/knowledge/stores/extractRefs.js +168 -0
- package/dist/knowledge/stores/extractRefs.js.map +1 -0
- package/dist/knowledge/stores/localSnapshotStore.d.ts +5 -0
- package/dist/knowledge/stores/localSnapshotStore.d.ts.map +1 -1
- package/dist/knowledge/stores/localSnapshotStore.js +25 -5
- package/dist/knowledge/stores/localSnapshotStore.js.map +1 -1
- package/dist/knowledge/stores/rowDelta.d.ts +6 -0
- package/dist/knowledge/stores/rowDelta.d.ts.map +1 -1
- package/dist/knowledge/stores/rowDelta.js.map +1 -1
- package/dist/knowledge/stores/rowMemory.d.ts +30 -0
- package/dist/knowledge/stores/rowMemory.d.ts.map +1 -1
- package/dist/knowledge/stores/rowMemory.js +46 -1
- package/dist/knowledge/stores/rowMemory.js.map +1 -1
- package/dist/knowledge/stores/rowSync.d.ts.map +1 -1
- package/dist/knowledge/stores/rowSync.js +2 -1
- package/dist/knowledge/stores/rowSync.js.map +1 -1
- package/dist/knowledge/stores/snapshotFormat.d.ts +13 -2
- package/dist/knowledge/stores/snapshotFormat.d.ts.map +1 -1
- package/dist/knowledge/stores/snapshotFormat.js +22 -9
- package/dist/knowledge/stores/snapshotFormat.js.map +1 -1
- package/dist/working/fold.d.ts +14 -0
- package/dist/working/fold.d.ts.map +1 -1
- package/dist/working/fold.js +14 -4
- package/dist/working/fold.js.map +1 -1
- package/dist/working/index.d.ts +3 -1
- package/dist/working/index.d.ts.map +1 -1
- package/dist/working/index.js +2 -1
- package/dist/working/index.js.map +1 -1
- package/dist/working/textSummary.d.ts +46 -0
- package/dist/working/textSummary.d.ts.map +1 -0
- package/dist/working/textSummary.js +142 -0
- package/dist/working/textSummary.js.map +1 -0
- package/package.json +1 -1
- package/src/contract/exports.snapshot.json +7 -1
- package/src/contract/regression.extractEviction.test.ts +162 -0
- package/src/contract/regression.fixCommits.test.ts +112 -0
- package/src/contract/regression.packWire.test.ts +174 -0
- package/src/contract/types.contract.test.ts +2 -1
- package/src/knowledge/pack/frame.ts +21 -5
- package/src/knowledge/pack/manifest.ts +26 -11
- package/src/knowledge/pack/sections/extr.ts +14 -4
- package/src/knowledge/pack/sections/extrLists.ts +4 -6
- package/src/knowledge/pack/sections/facts.ts +3 -2
- package/src/knowledge/pack/sections/rows.ts +11 -2
- package/src/knowledge/pack/strings.ts +5 -1
- package/src/knowledge/pack/varint.ts +33 -1
- package/src/knowledge/review.ts +58 -311
- package/src/knowledge/reviewAnalyse.ts +59 -0
- package/src/knowledge/reviewApply.ts +128 -0
- package/src/knowledge/reviewContext.ts +158 -0
- package/src/knowledge/reviewFinish.ts +63 -0
- package/src/knowledge/reviewRunModel.ts +3 -0
- package/src/knowledge/stores/extractLogWriter.ts +36 -12
- package/src/knowledge/stores/extractRefs.ts +161 -0
- package/src/knowledge/stores/localSnapshotStore.ts +22 -5
- package/src/knowledge/stores/rowDelta.ts +6 -0
- package/src/knowledge/stores/rowMemory.ts +50 -1
- package/src/knowledge/stores/rowSync.ts +2 -1
- package/src/knowledge/stores/snapshotFormat.ts +27 -10
- package/src/working/fold.ts +15 -4
- package/src/working/index.ts +13 -1
- package/src/working/textSummary.test.ts +113 -0
- package/src/working/textSummary.ts +156 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/reviewApply.ts — the ordered writer of a review (PRD 41 A8): applies ONE settled file, in plan order — its failure,
|
|
3
|
+
* its asset node, its "nothing to extract", or its extract cache entry, judgement, write and markStale. Moved out of review.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { writeBatch } from './reviewContext.js';
|
|
6
|
+
import { owedCalls } from './owedFiles.js';
|
|
7
|
+
import { putExtract, putNoExtract } from './extractFile.js';
|
|
8
|
+
import { recordFailure } from './reviewFailure.js';
|
|
9
|
+
import { applyJudge, judgesPack, splitSections } from './reviewJudge.js';
|
|
10
|
+
import { putAsset } from './assetFile.js';
|
|
11
|
+
import { srcRef } from './refs.js';
|
|
12
|
+
/**
|
|
13
|
+
* Applies one file, in plan order. False when its work was cut short by an abort (extracted, judging
|
|
14
|
+
* unfinished): nothing of it is applied and it stays as it was, owed. A file whose work is complete is
|
|
15
|
+
* applied even after an abort — the work is done, so it is kept.
|
|
16
|
+
*/
|
|
17
|
+
export async function applyFile(a, slot) {
|
|
18
|
+
a.gate.inWriter = true;
|
|
19
|
+
try {
|
|
20
|
+
return await applyInner(a, slot);
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
a.gate.inWriter = false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function applyInner(a, { f, i, job, judge }) {
|
|
27
|
+
const { c } = a;
|
|
28
|
+
const { store } = c.args;
|
|
29
|
+
c.progress({ phase: 'extract', done: i, total: c.work.length, path: f.path });
|
|
30
|
+
// A read that throws (permissions, a lock, a race with a delete) or an extraction that throws says nothing
|
|
31
|
+
// about the file: skipped with its knowledge and manifest hash intact, tried again next review.
|
|
32
|
+
if (job.kind === 'read-error' || job.kind === 'failed') {
|
|
33
|
+
if (job.kind === 'read-error')
|
|
34
|
+
c.report.readErrors += 1;
|
|
35
|
+
else
|
|
36
|
+
c.report.extractErrors += 1;
|
|
37
|
+
c.report.failures.push({ path: f.path, phase: 'extract', reason: job.kind === 'read-error' ? `read: ${job.reason}` : job.reason });
|
|
38
|
+
c.measured.set(f.path, owedCalls(c.detail.extractor, f.path)); // learns nothing: keep what it was owed
|
|
39
|
+
// The ONE failure path (reviewFailure.ts): a transient failure keeps the re-check request and makes the file owed; only a proven-final
|
|
40
|
+
// one (or the third in a row at the same bytes) is answered with a terminal `[]`.
|
|
41
|
+
const ctx = { store, detail: c.detail, stopped: () => a.runSignal.aborted, unreadable: c.unreadable, failures: c.failures, settledRecheck: c.settledRecheck };
|
|
42
|
+
if (await recordFailure(ctx, f, job))
|
|
43
|
+
c.finished.add(f.path); // final: settled, not re-read while its bytes stand
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
c.failures.delete(f.path); // it read and extracted (or was decided): the run of failures at this hash ends
|
|
47
|
+
// An asset (planned binary, or a text-extension file found binary on read): never extracted, but it IS a file of the root, so
|
|
48
|
+
// its file node is stored (assetFile.ts) — a replica tells it from "not extracted yet", and references to its path resolve.
|
|
49
|
+
// Recorded, so a file found binary on read is not re-read by every later review.
|
|
50
|
+
if (job.kind === 'binary' || job.kind === 'asset') {
|
|
51
|
+
c.filesNow.set(f.path, f.hash);
|
|
52
|
+
c.finished.add(f.path);
|
|
53
|
+
await putAsset(store, c.rootId, f);
|
|
54
|
+
await c.settledRecheck(f.hash);
|
|
55
|
+
await store.markStale(c.scope, srcRef(c.rootId, f.path), f.hash);
|
|
56
|
+
c.report.staleMarked += 1;
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (job.kind === 'none') {
|
|
60
|
+
// No pack accepts the file: nothing will ever be extracted for it, so say so (and answer any re-check of it).
|
|
61
|
+
c.finished.add(f.path);
|
|
62
|
+
await putNoExtract(store, f.hash);
|
|
63
|
+
await c.settledRecheck(f.hash);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
c.report.extracted += 1;
|
|
67
|
+
// The extract cache is written HERE, in plan order, so the cache, the counts and the order match a sequential run.
|
|
68
|
+
if (!job.extraction.cached)
|
|
69
|
+
await putExtract(store, f.hash, job.extraction.extracted);
|
|
70
|
+
await c.settledRecheck(f.hash);
|
|
71
|
+
let complete = true;
|
|
72
|
+
let deferred = false;
|
|
73
|
+
if (c.args.mechanical && judgesPack(c.args.judgement, job.extraction.pack)) {
|
|
74
|
+
// Pass 1: the map has this file; its judgement is pass 2's. With sections at hand (in-thread parse) a file whose sections are all
|
|
75
|
+
// still judged costs no model call: its facts are refreshed and it is complete. A pool returns none in a mechanical run, so those files are
|
|
76
|
+
// owed and pass 2 finds nothing to judge (a cache hit, no call).
|
|
77
|
+
const { reuse, toJudge } = splitSections(c.judgedPrior, job.extraction);
|
|
78
|
+
if (job.extraction.sections.length > 0 && toJudge.length === 0) {
|
|
79
|
+
for (const ref of reuse)
|
|
80
|
+
c.stored.refresh(ref, f.path, f.hash, c.batch, c.entities);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
complete = false;
|
|
84
|
+
deferred = true;
|
|
85
|
+
c.owedJudge.push(f.path);
|
|
86
|
+
c.measured.set(f.path, Math.max(1, toJudge.length));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (judge) {
|
|
90
|
+
c.progress({ phase: 'judge', done: i, total: c.work.length, path: f.path });
|
|
91
|
+
a.gate.inWriter = false; // waiting for the model calls is not the writer working
|
|
92
|
+
const outcome = await applyJudge(a.judgeCtx, f, judge);
|
|
93
|
+
a.gate.inWriter = true;
|
|
94
|
+
if (outcome === 'aborted')
|
|
95
|
+
return false;
|
|
96
|
+
if (outcome === 'failed') {
|
|
97
|
+
c.owedJudge.push(f.path);
|
|
98
|
+
// Judging failed as a whole: leave the file exactly as it was (facts, manifest hash, owed) so the next review retries it.
|
|
99
|
+
c.measured.set(f.path, owedCalls(c.detail.extractor, f.path));
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
complete = outcome.complete;
|
|
103
|
+
if (!complete)
|
|
104
|
+
c.owedJudge.push(f.path);
|
|
105
|
+
}
|
|
106
|
+
c.progress({ phase: 'write', done: i, total: c.work.length, path: f.path });
|
|
107
|
+
const t0 = c.now();
|
|
108
|
+
await writeBatch(c);
|
|
109
|
+
// An owed file keeps its old judgement current until pass 2 replaces it: nothing of it is marked stale yet.
|
|
110
|
+
if (!deferred) {
|
|
111
|
+
await store.markStale(c.scope, srcRef(c.rootId, f.path), f.hash);
|
|
112
|
+
c.report.staleMarked += 1;
|
|
113
|
+
}
|
|
114
|
+
c.args.onStep?.({ path: f.path, phase: 'write', ms: c.now() - t0, outcome: 'ok' });
|
|
115
|
+
if (complete) {
|
|
116
|
+
c.filesNow.set(f.path, f.hash);
|
|
117
|
+
c.finished.add(f.path);
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=reviewApply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reviewApply.js","sourceRoot":"","sources":["../../src/knowledge/reviewApply.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAiB,MAAM,kBAAkB,CAAC;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AAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAAC,CAAC;IACzE,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/reviewContext.ts — the state ONE review run shares between its stages (review.ts): the plan and what the store
|
|
3
|
+
* holds (opened by {@link openReview}), the run's books (files finished, owed, failed), and the two store writes every stage
|
|
4
|
+
* uses: {@link writeBatch} (the judged batch, with the scope) and {@link retire} (sources that are gone).
|
|
5
|
+
*
|
|
6
|
+
* Moved out of review.ts's one long closure so each stage is a function of this context. No behaviour of its own beyond that.
|
|
7
|
+
*/
|
|
8
|
+
import type { ReviewArgs, ReviewReport, ScopeRecord, StoredFact, StoredRelation } from './model.js';
|
|
9
|
+
import { type PlanDetail, type PlannedFile } from './plan.js';
|
|
10
|
+
import { JudgedBatch, type JudgeBudget } from './judge.js';
|
|
11
|
+
import { JudgeBreaker } from './judgeCalls.js';
|
|
12
|
+
import { type PendingClaims } from './reviewCompare.js';
|
|
13
|
+
import { StoredIndex } from './reviewStored.js';
|
|
14
|
+
import type { ComposedPacks } from './sources.js';
|
|
15
|
+
import type { NodeRef } from './model.js';
|
|
16
|
+
export type ReviewProgressEvent = Parameters<NonNullable<ReviewArgs['onProgress']>>[0];
|
|
17
|
+
export interface ReviewContext {
|
|
18
|
+
args: ReviewArgs;
|
|
19
|
+
rootId: string;
|
|
20
|
+
scope: {
|
|
21
|
+
rootId: string;
|
|
22
|
+
};
|
|
23
|
+
scopeRecord: ScopeRecord;
|
|
24
|
+
packIds: string[];
|
|
25
|
+
report: ReviewReport;
|
|
26
|
+
detail: PlanDetail;
|
|
27
|
+
composed: ComposedPacks;
|
|
28
|
+
stored: StoredIndex;
|
|
29
|
+
entities: Map<string, StoredFact>;
|
|
30
|
+
knownKeys: ReadonlyMap<string, NodeRef>;
|
|
31
|
+
budget: JudgeBudget;
|
|
32
|
+
batch: JudgedBatch;
|
|
33
|
+
breaker: JudgeBreaker;
|
|
34
|
+
judgedPrior: Map<string, string>;
|
|
35
|
+
judgedNow: Map<string, string>;
|
|
36
|
+
/** The files manifest as this run leaves it. */
|
|
37
|
+
filesNow: Map<string, string>;
|
|
38
|
+
newClaims: PendingClaims;
|
|
39
|
+
/** Changed files of the plan, and the ones this run works on (`only` narrows them, in its order). */
|
|
40
|
+
changed: PlannedFile[];
|
|
41
|
+
work: PlannedFile[];
|
|
42
|
+
/** Files whose judging is still owed. */
|
|
43
|
+
owedJudge: string[];
|
|
44
|
+
/** Changed files this run finished (or had nothing to do for). */
|
|
45
|
+
finished: Set<string>;
|
|
46
|
+
/** Files that failed for a reason that says nothing final about them, at the manifest's own bytes. */
|
|
47
|
+
unreadable: Set<string>;
|
|
48
|
+
/** Consecutive transient failures by path at one hash. */
|
|
49
|
+
failures: Map<string, {
|
|
50
|
+
hash: string;
|
|
51
|
+
count: number;
|
|
52
|
+
}>;
|
|
53
|
+
/** Model calls each unfinished file is still owed. */
|
|
54
|
+
measured: Map<string, number>;
|
|
55
|
+
/** Facts a retire rewrote: a later retire never restores an anchor an earlier one dropped. */
|
|
56
|
+
rewritten: Map<string, StoredFact>;
|
|
57
|
+
started: number;
|
|
58
|
+
now(): number;
|
|
59
|
+
progress(p: ReviewProgressEvent): void;
|
|
60
|
+
/** Answers a replica's re-check request for `hash`, once its work is done. */
|
|
61
|
+
settledRecheck(hash: string): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
/** Plans the run, reads what the store holds of the root, preloads the extract cache and runs the no-extract backfill. */
|
|
64
|
+
export declare function openReview(args: ReviewArgs): Promise<ReviewContext>;
|
|
65
|
+
/** Throws if a batch carries `extracted` items — perception is never memory. */
|
|
66
|
+
export declare function assertStoredBatch(batch: {
|
|
67
|
+
facts: readonly StoredFact[];
|
|
68
|
+
relations: readonly StoredRelation[];
|
|
69
|
+
}): void;
|
|
70
|
+
/** Stores what the judged batch holds (with `withScope`); a no-op when there is nothing and the scope is the run's own. */
|
|
71
|
+
export declare function writeBatch(c: ReviewContext, withScope?: ScopeRecord): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Sources that are gone: their knowledge goes stale at no hash, their judged sections are forgotten, and facts other
|
|
74
|
+
* sources still back drop their anchor (recorded in `rewritten`, so a later retire never restores it).
|
|
75
|
+
*/
|
|
76
|
+
export declare function retire(c: ReviewContext, paths: readonly string[]): Promise<void>;
|
|
77
|
+
//# sourceMappingURL=reviewContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reviewContext.d.ts","sourceRoot":"","sources":["../../src/knowledge/reviewContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EAA2B,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAIvF,OAAO,EAA8B,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAsB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvF,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE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AAE,UAAU,CAAC,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,IAAI,MAAM,CAAC;IACd,QAAQ,CAAC,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACvC,8EAA8E;IAC9E,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAOD,0HAA0H;AAC1H,wBAAsB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAgDzE;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAAC,SAAS,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,GAAG,IAAI,CAGrH;AAED,2HAA2H;AAC3H,wBAAsB,UAAU,CAAC,CAAC,EAAE,aAAa,EAAE,SAAS,GAAE,WAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxG;AAED;;;GAGG;AACH,wBAAsB,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBtF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/reviewContext.ts — the state ONE review run shares between its stages (review.ts): the plan and what the store
|
|
3
|
+
* holds (opened by {@link openReview}), the run's books (files finished, owed, failed), and the two store writes every stage
|
|
4
|
+
* uses: {@link writeBatch} (the judged batch, with the scope) and {@link retire} (sources that are gone).
|
|
5
|
+
*
|
|
6
|
+
* Moved out of review.ts's one long closure so each stage is a function of this context. No behaviour of its own beyond that.
|
|
7
|
+
*/
|
|
8
|
+
import { planDetail, refreshPlan } from './plan.js';
|
|
9
|
+
import { composePacks, judgedManifestKey, manifestMap } from './sources.js';
|
|
10
|
+
import { knownKeysOfEntities } from './extractFile.js';
|
|
11
|
+
import { backfillCandidates, backfillNoExtract } from './backfillNoExtract.js';
|
|
12
|
+
import { DEFAULT_REVIEW_MODEL_CALLS, JudgedBatch } from './judge.js';
|
|
13
|
+
import { JudgeBreaker } from './judgeCalls.js';
|
|
14
|
+
import { pendingClaims } from './reviewCompare.js';
|
|
15
|
+
import { factsWithoutAnchor, StoredIndex } from './reviewStored.js';
|
|
16
|
+
import { compareStr, srcRef } from './refs.js';
|
|
17
|
+
const emptyReport = (rootId) => ({
|
|
18
|
+
rootId, digest: '', extracted: 0, judged: 0, unjudged: 0, invalidJudgements: 0,
|
|
19
|
+
factsWritten: 0, relationsWritten: 0, staleMarked: 0, readErrors: 0, extractErrors: 0, failures: [], awaitingJudge: [], aborted: false, durationMs: 0,
|
|
20
|
+
});
|
|
21
|
+
/** Plans the run, reads what the store holds of the root, preloads the extract cache and runs the no-extract backfill. */
|
|
22
|
+
export async function openReview(args) {
|
|
23
|
+
const now = () => Date.now();
|
|
24
|
+
const started = now();
|
|
25
|
+
const { source, store, packs, manifest, signal } = args;
|
|
26
|
+
const rootId = source.rootId;
|
|
27
|
+
const scope = { rootId };
|
|
28
|
+
const progress = (p) => args.onProgress?.(p);
|
|
29
|
+
const detail = args.plan
|
|
30
|
+
? await refreshPlan(args.plan, manifest)
|
|
31
|
+
: await planDetail(source, manifest, packs, { ...(args.force ? { force: true } : {}), compare: !!args.similar && !!args.judgement });
|
|
32
|
+
progress({ phase: 'plan', done: detail.files.length, total: detail.files.length });
|
|
33
|
+
const packIds = packs.map((p) => p.id).sort(compareStr);
|
|
34
|
+
const [storedFacts, storedRelations] = await Promise.all([store.facts(scope), store.relations(scope)]);
|
|
35
|
+
const stored = new StoredIndex(storedFacts, storedRelations);
|
|
36
|
+
const entities = new Map(storedFacts.filter((f) => f.key.startsWith('ent:')).map((f) => [f.key, f]));
|
|
37
|
+
const judgedPrior = await manifestMap(manifest, judgedManifestKey(rootId));
|
|
38
|
+
// Files with no stored body: assets the manifest names (queued so their node is written, no read) and the ones a replica asked to re-check (queued; this review stores their body or asset node).
|
|
39
|
+
const asked = (await store.recheckHashes?.()) ?? [];
|
|
40
|
+
// ONE bulk fetch of the extract cache for the whole run instead of a round trip per file: the files this run extracts and the ones the backfill looks up.
|
|
41
|
+
const preChanged = detail.files.filter((f) => f.changed && (!args.only || args.only.includes(f.path)));
|
|
42
|
+
const preload = [...new Set([...preChanged.map((f) => f.hash), ...backfillCandidates(detail, asked)])];
|
|
43
|
+
if (preload.length > 0)
|
|
44
|
+
await store.preloadExtracted?.(preload);
|
|
45
|
+
await backfillNoExtract({ store, detail, asked, only: args.only, signal });
|
|
46
|
+
// A re-check request is answered only when the work it asked for is done: the body stored, the binary recorded, or the failure recorded.
|
|
47
|
+
const askedSet = new Set(asked);
|
|
48
|
+
// Claims awaiting comparison: those a previous run could not compare, then this run's.
|
|
49
|
+
const newClaims = await pendingClaims(manifest, rootId, stored.facts);
|
|
50
|
+
const changed = detail.files.filter((f) => f.changed);
|
|
51
|
+
// `only` (pass 2) narrows what this run works on; the other changed files are untouched and stay owed (owedAfterRun sees them all).
|
|
52
|
+
// Pass 2 works in the order it was given (priority), so a model-call ceiling is spent on the most important files first.
|
|
53
|
+
const byPath = new Map(changed.map((f) => [f.path, f]));
|
|
54
|
+
return {
|
|
55
|
+
args, rootId, scope, scopeRecord: { rootId, title: source.title, packs: packIds }, packIds, report: emptyReport(rootId),
|
|
56
|
+
detail, composed: composePacks(packs), stored, entities, knownKeys: knownKeysOfEntities(entities.keys()),
|
|
57
|
+
budget: {
|
|
58
|
+
modelCalls: args.budget?.modelCalls ?? DEFAULT_REVIEW_MODEL_CALLS,
|
|
59
|
+
deadline: started + (Number.isFinite(args.budget?.ms) ? args.budget.ms : Number.POSITIVE_INFINITY),
|
|
60
|
+
used: 0, now,
|
|
61
|
+
},
|
|
62
|
+
batch: new JudgedBatch(), breaker: new JudgeBreaker(),
|
|
63
|
+
judgedPrior, judgedNow: new Map(judgedPrior), filesNow: new Map(detail.prior), newClaims,
|
|
64
|
+
changed, work: args.only ? args.only.flatMap((p) => byPath.get(p) ?? []) : changed,
|
|
65
|
+
owedJudge: [], finished: new Set(), unreadable: new Set(), failures: new Map(detail.extractor.failures ?? []), measured: new Map(),
|
|
66
|
+
rewritten: new Map(), started, now, progress,
|
|
67
|
+
settledRecheck: async (hash) => { if (askedSet.has(hash))
|
|
68
|
+
await store.clearRecheck?.([hash]); },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Throws if a batch carries `extracted` items — perception is never memory. */
|
|
72
|
+
export function assertStoredBatch(batch) {
|
|
73
|
+
const bad = [...batch.facts, ...batch.relations].find((x) => x.origin === 'extracted');
|
|
74
|
+
if (bad)
|
|
75
|
+
throw new Error('knowledge: extracted output is never written to a KnowledgeStore');
|
|
76
|
+
}
|
|
77
|
+
/** Stores what the judged batch holds (with `withScope`); a no-op when there is nothing and the scope is the run's own. */
|
|
78
|
+
export async function writeBatch(c, withScope = c.scopeRecord) {
|
|
79
|
+
const out = c.batch.take();
|
|
80
|
+
assertStoredBatch(out);
|
|
81
|
+
if (out.facts.length === 0 && out.relations.length === 0 && withScope === c.scopeRecord)
|
|
82
|
+
return;
|
|
83
|
+
await c.args.store.write({ scope: withScope, ...out });
|
|
84
|
+
c.report.factsWritten += out.facts.length;
|
|
85
|
+
c.report.relationsWritten += out.relations.length;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Sources that are gone: their knowledge goes stale at no hash, their judged sections are forgotten, and facts other
|
|
89
|
+
* sources still back drop their anchor (recorded in `rewritten`, so a later retire never restores it).
|
|
90
|
+
*/
|
|
91
|
+
export async function retire(c, paths) {
|
|
92
|
+
const live = new Map([...c.stored.facts, ...c.entities, ...c.rewritten]);
|
|
93
|
+
for (const path of paths) {
|
|
94
|
+
await c.args.store.markStale(c.scope, srcRef(c.rootId, path), '');
|
|
95
|
+
c.report.staleMarked += 1;
|
|
96
|
+
c.filesNow.delete(path);
|
|
97
|
+
const sectionPrefix = `${srcRef(c.rootId, path)}#`;
|
|
98
|
+
for (const section of [...c.judgedNow.keys()])
|
|
99
|
+
if (section.startsWith(sectionPrefix))
|
|
100
|
+
c.judgedNow.delete(section);
|
|
101
|
+
for (const fact of factsWithoutAnchor(live.values(), path)) {
|
|
102
|
+
c.batch.fact(fact);
|
|
103
|
+
live.set(fact.key, fact);
|
|
104
|
+
c.rewritten.set(fact.key, fact);
|
|
105
|
+
if (c.entities.has(fact.key))
|
|
106
|
+
c.entities.set(fact.key, fact);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
await writeBatch(c);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=reviewContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reviewContext.js","sourceRoot":"","sources":["../../src/knowledge/reviewContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAqC,MAAM,WAAW,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,WAAW,EAAoB,MAAM,YAAY,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAsB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAgD/C,MAAM,WAAW,GAAG,CAAC,MAAc,EAAgB,EAAE,CAAC,CAAC;IACnD,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CA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run produced is stored and
|
|
3
|
+
* durable BEFORE the manifests say its files are done, then the report's totals, the manifests and the scope's digest stamp.
|
|
4
|
+
* Moved out of review.ts.
|
|
5
|
+
*/
|
|
6
|
+
import type { ReviewReport } from './model.js';
|
|
7
|
+
import { type ReviewContext } from './reviewContext.js';
|
|
8
|
+
export declare function finishReview(c: ReviewContext, flush: () => Promise<void>): Promise<ReviewReport>;
|
|
9
|
+
//# sourceMappingURL=reviewFinish.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reviewFinish.d.ts","sourceRoot":"","sources":["../../src/knowledge/reviewFinish.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGpE,wBAAsB,YAAY,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CA+CtG"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/reviewFinish.ts — the end of a review: the near-duplicate compare, then everything the run produced is stored and
|
|
3
|
+
* durable BEFORE the manifests say its files are done, then the report's totals, the manifests and the scope's digest stamp.
|
|
4
|
+
* Moved out of review.ts.
|
|
5
|
+
*/
|
|
6
|
+
import { sha256Hex } from '../retrieval/knowledge-index/sha256.js';
|
|
7
|
+
import { owedAfterRun, saveExtractorState } from './owedFiles.js';
|
|
8
|
+
import { filesManifestKey, judgedManifestKey, saveManifestMap } from './sources.js';
|
|
9
|
+
import { compareNew, saveAwaiting } from './reviewCompare.js';
|
|
10
|
+
import { writeBatch } from './reviewContext.js';
|
|
11
|
+
import { canonicalJson, compareStr } from './refs.js';
|
|
12
|
+
export async function finishReview(c, flush) {
|
|
13
|
+
const { args, report } = c;
|
|
14
|
+
const { manifest } = args;
|
|
15
|
+
// The compare phase needs a pack asking for it AND both ports.
|
|
16
|
+
const wantsCompare = args.packs.some((p) => p.judgement?.contradictions);
|
|
17
|
+
const canCompare = wantsCompare && !!args.judgement && !!args.similar;
|
|
18
|
+
let outcome;
|
|
19
|
+
if (!report.aborted && canCompare && !args.mechanical) {
|
|
20
|
+
outcome = await compareNew({
|
|
21
|
+
args, pending: c.newClaims, known: c.stored.facts, budget: c.budget, batch: c.batch,
|
|
22
|
+
onPairs: (total) => c.progress({ phase: 'compare', done: 0, total }),
|
|
23
|
+
});
|
|
24
|
+
// Aborted only if the abort landed before the last pair was compared.
|
|
25
|
+
if (outcome?.aborted)
|
|
26
|
+
report.aborted = true;
|
|
27
|
+
}
|
|
28
|
+
// DURABILITY ORDER: everything the run produced is stored and durable BEFORE a manifest says its files are
|
|
29
|
+
// done. A manifest ahead of the store loses knowledge for good (the next review sees those files unchanged
|
|
30
|
+
// and skips them); a store ahead of the manifest only re-reviews files. `write()` first stores what the compare
|
|
31
|
+
// phase left in the batch, then one flush covers the awaiting set (it names stored claims) and the files
|
|
32
|
+
// manifest: nothing mutates the store between them. The trailing write only stamps lastDigest; the end of
|
|
33
|
+
// the batch persists it.
|
|
34
|
+
await writeBatch(c);
|
|
35
|
+
await flush();
|
|
36
|
+
// No pack asks for contradictions: nothing waits, and an earlier run's awaiting set is left as it was.
|
|
37
|
+
if (wantsCompare && !args.mechanical)
|
|
38
|
+
await saveAwaiting(manifest, c.rootId, c.newClaims, outcome);
|
|
39
|
+
// Pass 2: what is still owed is every file of its slice it did not finish (an abort leaves the unreached ones owed too).
|
|
40
|
+
report.awaitingJudge = args.only ? c.work.filter((f) => !c.finished.has(f.path)).map((f) => f.path) : c.owedJudge;
|
|
41
|
+
report.awaitingJudgeCount = report.awaitingJudge.length;
|
|
42
|
+
report.judgedFiles = args.only ? c.work.length - report.awaitingJudge.length : 0;
|
|
43
|
+
if (c.breaker.stopped)
|
|
44
|
+
report.judgeStopped = c.breaker.stopped;
|
|
45
|
+
report.judged = c.batch.judged;
|
|
46
|
+
report.unjudged = c.batch.unjudged;
|
|
47
|
+
report.invalidJudgements = c.batch.invalid;
|
|
48
|
+
report.digest = sha256Hex(canonicalJson({ rootId: c.rootId, packs: c.packIds, files: [...c.filesNow].sort((a, b) => compareStr(a[0], b[0])) }));
|
|
49
|
+
await saveManifestMap(manifest, filesManifestKey(c.rootId), c.filesNow);
|
|
50
|
+
await saveManifestMap(manifest, judgedManifestKey(c.rootId), c.judgedNow);
|
|
51
|
+
// After every run: today's version and every file still owed a re-extraction — the unfinished ones,
|
|
52
|
+
// content-changed or not, and the owed paths the plan did not list that the manifest still holds.
|
|
53
|
+
await saveExtractorState(manifest, c.rootId, owedAfterRun({
|
|
54
|
+
state: c.detail.extractor, changed: c.changed, prior: c.detail.prior, finished: c.finished, carried: c.detail.carried,
|
|
55
|
+
live: c.filesNow, measured: c.measured, unreadable: c.unreadable,
|
|
56
|
+
}), c.failures, c.detail.extractor.documentsNow);
|
|
57
|
+
await writeBatch(c, report.aborted ? c.scopeRecord : { ...c.scopeRecord, lastDigest: report.digest, lastReviewedAt: new Date(c.now()).toISOString() });
|
|
58
|
+
report.durationMs = c.now() - c.started;
|
|
59
|
+
c.progress({ phase: 'done', done: c.work.length, total: c.work.length });
|
|
60
|
+
return report;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=reviewFinish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reviewFinish.js","sourceRoot":"","sources":["../../src/knowledge/reviewFinish.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAGnE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CA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EAAE,EAAE,CAAC,CAAC;IACvJ,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC;IACxC,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACzE,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -25,9 +25,12 @@ export interface ReviewStep {
|
|
|
25
25
|
}
|
|
26
26
|
/** A file a review could not finish: its prior knowledge and manifest hash are kept, so the next review retries it. */
|
|
27
27
|
export interface ReviewFailure {
|
|
28
|
+
/** The file's path; for an `analyzer` failure, `analyzer:<pack id>` (never a path: read `kind` first). */
|
|
28
29
|
path: string;
|
|
29
30
|
phase: ReviewPhase;
|
|
30
31
|
reason: string;
|
|
32
|
+
/** What failed: absent or `file` for a file of the root, `analyzer` for a pack's analyzer (`path` then names the pack, not a file). */
|
|
33
|
+
kind?: 'file' | 'analyzer';
|
|
31
34
|
}
|
|
32
35
|
/** Lane ids 0..width-1 for in-flight work: `take` the lowest free one, `free` it when the work settles. */
|
|
33
36
|
export declare class Lanes {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewRunModel.d.ts","sourceRoot":"","sources":["../../src/knowledge/reviewRunModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oHAAoH;AACpH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEnI,MAAM,MAAM,iBAAiB,GAAG,IAAI,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEvE;;;GAGG;AACH,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAA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AuH;AACvH,MAAM,WAAW,aAAa;IAC1B,0GAA0G;IAC1G,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,uIAAuI;IACvI,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CAC9B;AAED,2GAA2G;AAC3G,qBAAa,KAAK;IACd,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B,YAAY,KAAK,EAAE,MAAM,EAAyB;IAElD,IAAI,IAAI,MAAM,CAOb;IAED,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAA0B;CACnD;AAED,qDAAqD;AACrD,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,MAGzC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewRunModel.js","sourceRoot":"","sources":["../../src/knowledge/reviewRunModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"reviewRunModel.js","sourceRoot":"","sources":["../../src/knowledge/reviewRunModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgCH,2GAA2G;AAC3G,MAAM,OAAO,KAAK;IACG,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IACzB,KAAK,CAAS;IAE/B,YAAY,KAAa,IAAI,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;IAElD,IAAI;QACA,uGAAuG;QACvG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,CAAC,KAAK,iBAAiB,CAAC,CAAC;QAClH,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,EAAE,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClB,OAAO,EAAE,CAAC;IACd,CAAC;IAED,IAAI,CAAC,EAAU,IAAU,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACnD;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAU,EAAE;IAC/C,MAAM,IAAI,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACpE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,eAAe,CAAC;AACpE,CAAC,CAAC"}
|
|
@@ -5,18 +5,31 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { Extracted } from '../model.js';
|
|
7
7
|
import type { ExtractedLogPersistence } from './localSnapshotStore.js';
|
|
8
|
+
import type { RowMemory } from './rowMemory.js';
|
|
8
9
|
export declare class ExtractLogWriter {
|
|
9
10
|
private readonly port;
|
|
11
|
+
private readonly isLive;
|
|
10
12
|
/** Entries not yet appended. */
|
|
11
13
|
private pending;
|
|
12
14
|
/** The log's last line is torn (no newline), so the next append starts on a fresh line. */
|
|
13
15
|
private torn;
|
|
14
|
-
|
|
16
|
+
/** `isLive(hash)`: the body is still in the cache (not evicted), so a failed append may put it back in line. */
|
|
17
|
+
constructor(port: ExtractedLogPersistence, isLive?: (hash: string) => boolean);
|
|
15
18
|
read(): Promise<string | undefined>;
|
|
16
19
|
/** Queues an entry for the next {@link flush}. */
|
|
17
20
|
queue(hash: string, entries: Extracted[]): void;
|
|
18
|
-
/**
|
|
19
|
-
|
|
21
|
+
/** An evicted body that was never appended is not appended at all. */
|
|
22
|
+
unqueue(hash: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Fills `mem` by REPLAYING the log's lines in order, exactly as the puts happened (last line per hash wins; a put claims only the
|
|
25
|
+
* entries it added or changed, and evicts what is then neither current nor previous for any source, extractRefs.ts), then compacts
|
|
26
|
+
* the log when dead bytes (superseded lines, evicted bodies, torn lines) exceed live bytes. A compacted line carries the body's
|
|
27
|
+
* reference state (`c`/`p`, snapshotFormat.ts), so the replay of a compacted log RESTORES the state instead of re-deriving it
|
|
28
|
+
* from a put order compaction no longer has.
|
|
29
|
+
*/
|
|
30
|
+
load(text: string | undefined, mem: RowMemory): Promise<void>;
|
|
31
|
+
/** Told about a compaction that failed (the load itself succeeds). */
|
|
32
|
+
onError: ((err: unknown) => void) | undefined;
|
|
20
33
|
/**
|
|
21
34
|
* Appends the not-yet-logged entries as ONE `append` of complete lines. A failed append keeps them pending and marks the
|
|
22
35
|
* log torn (it may hold a partial line), so the next append starts on a fresh line.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractLogWriter.d.ts","sourceRoot":"","sources":["../../../src/knowledge/stores/extractLogWriter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"extractLogWriter.d.ts","sourceRoot":"","sources":["../../../src/knowledge/stores/extractLogWriter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,qBAAa,gBAAgB;IAOb,OAAO,CAAC,QAAQ,CAAC,IAAI;IAA2B,OAAO,CAAC,QAAQ,CAAC,MAAM;IANnF,gCAAgC;IAChC,OAAO,CAAC,OAAO,CAAkC;IACjD,2FAA2F;IAC3F,OAAO,CAAC,IAAI,CAAS;IAErB,gHAAgH;IAChH,YAA6B,IAAI,EAAE,uBAAuB,EAAmB,MAAM,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAoB,EAAI;IAE/H,IAAI,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAA6B;IAEhE,kDAAkD;IAClD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,CAAqC;IAEpF,sEAAsE;IACtE,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAA+B;IAE1D;;;;;;OAMG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBlE;IAED,sEAAsE;IACtE,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAE9C;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAe3B;CACJ"}
|
|
@@ -3,35 +3,59 @@
|
|
|
3
3
|
* out of {@link LocalSnapshotStore}. It owns what is not yet appended and whether the log's last line is torn; the store
|
|
4
4
|
* owns WHEN to flush (inside `persistIfDirty`). No behaviour of its own beyond the log port.
|
|
5
5
|
*/
|
|
6
|
-
import { parseLog } from './snapshotFormat.js';
|
|
6
|
+
import { compactedLogLine, parseLog } from './snapshotFormat.js';
|
|
7
7
|
export class ExtractLogWriter {
|
|
8
8
|
port;
|
|
9
|
+
isLive;
|
|
9
10
|
/** Entries not yet appended. */
|
|
10
11
|
pending = new Map();
|
|
11
12
|
/** The log's last line is torn (no newline), so the next append starts on a fresh line. */
|
|
12
13
|
torn = false;
|
|
13
|
-
|
|
14
|
+
/** `isLive(hash)`: the body is still in the cache (not evicted), so a failed append may put it back in line. */
|
|
15
|
+
constructor(port, isLive = () => true) {
|
|
14
16
|
this.port = port;
|
|
17
|
+
this.isLive = isLive;
|
|
15
18
|
}
|
|
16
19
|
read() { return this.port.read(); }
|
|
17
20
|
/** Queues an entry for the next {@link flush}. */
|
|
18
21
|
queue(hash, entries) { this.pending.set(hash, entries); }
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/** An evicted body that was never appended is not appended at all. */
|
|
23
|
+
unqueue(hash) { this.pending.delete(hash); }
|
|
24
|
+
/**
|
|
25
|
+
* Fills `mem` by REPLAYING the log's lines in order, exactly as the puts happened (last line per hash wins; a put claims only the
|
|
26
|
+
* entries it added or changed, and evicts what is then neither current nor previous for any source, extractRefs.ts), then compacts
|
|
27
|
+
* the log when dead bytes (superseded lines, evicted bodies, torn lines) exceed live bytes. A compacted line carries the body's
|
|
28
|
+
* reference state (`c`/`p`, snapshotFormat.ts), so the replay of a compacted log RESTORES the state instead of re-deriving it
|
|
29
|
+
* from a put order compaction no longer has.
|
|
30
|
+
*/
|
|
31
|
+
async load(text, mem) {
|
|
32
|
+
const parsed = parseLog(text, (h, e, state) => { if (state)
|
|
33
|
+
mem.restoreBody(h, e, state);
|
|
34
|
+
else
|
|
35
|
+
mem.putBody(h, e); });
|
|
36
|
+
const kept = [...parsed.liveLines].filter(([h]) => mem.extracted.has(h));
|
|
37
|
+
const liveBytes = kept.reduce((n, [, l]) => n + l.length, 0);
|
|
38
|
+
// A body that names no source (no reference state) keeps its line byte for byte; any other carries its state.
|
|
39
|
+
const live = kept.map(([h, line]) => {
|
|
40
|
+
const state = mem.bodyState(h);
|
|
41
|
+
return state.current.length + state.previous.length === 0 ? line : compactedLogLine(h, mem.extracted.get(h), state);
|
|
42
|
+
});
|
|
43
|
+
const deadBytes = Math.max(0, (text?.length ?? 0) - liveBytes);
|
|
24
44
|
this.torn = !!text && !text.endsWith('\n');
|
|
25
|
-
// Needs the port's `replace`; a failure
|
|
26
|
-
// this read and the replace loses those lines from the cache — a cache miss, re-extracted next review.
|
|
27
|
-
if (!this.port.replace ||
|
|
45
|
+
// Needs the port's `replace`; a failure keeps the uncompacted log (still correct, only larger) and is reported to `onError`.
|
|
46
|
+
// Another window appending between this read and the replace loses those lines from the cache — a cache miss, re-extracted next review.
|
|
47
|
+
if (!this.port.replace || deadBytes <= liveBytes)
|
|
28
48
|
return;
|
|
29
49
|
try {
|
|
30
|
-
await this.port.replace(
|
|
50
|
+
await this.port.replace(live.join(''));
|
|
31
51
|
this.torn = false;
|
|
32
52
|
}
|
|
33
|
-
catch {
|
|
53
|
+
catch (err) {
|
|
54
|
+
this.onError?.(err);
|
|
55
|
+
}
|
|
34
56
|
}
|
|
57
|
+
/** Told about a compaction that failed (the load itself succeeds). */
|
|
58
|
+
onError;
|
|
35
59
|
/**
|
|
36
60
|
* Appends the not-yet-logged entries as ONE `append` of complete lines. A failed append keeps them pending and marks the
|
|
37
61
|
* log torn (it may hold a partial line), so the next append starts on a fresh line.
|
|
@@ -50,8 +74,9 @@ export class ExtractLogWriter {
|
|
|
50
74
|
}
|
|
51
75
|
catch (err) {
|
|
52
76
|
this.torn = true;
|
|
77
|
+
// An entry evicted while the append was in flight is not put back: appended later, it would supersede its successor.
|
|
53
78
|
for (const [h, e] of batch)
|
|
54
|
-
if (!this.pending.has(h))
|
|
79
|
+
if (!this.pending.has(h) && this.isLive(h))
|
|
55
80
|
this.pending.set(h, e);
|
|
56
81
|
throw err;
|
|
57
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractLogWriter.js","sourceRoot":"","sources":["../../../src/knowledge/stores/extractLogWriter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"extractLogWriter.js","sourceRoot":"","sources":["../../../src/knowledge/stores/extractLogWriter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEjE,MAAM,OAAO,gBAAgB;IAOI,IA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