@cortexkit/opencode-magic-context 0.49.89 → 0.49.90
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/{context-grdg1k2k.js → context-cdds0gjj.js} +198 -20
- package/dist/hooks/magic-context/history-boundary-repair.d.ts +2 -0
- package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/v2/{context-8bzydxfy.js → context-satgm752.js} +197 -20
- package/dist/v2/fold/native-replay.d.ts +11 -2
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/revert-message-state.d.ts +19 -1
- package/dist/v2/hooks/revert-message-state.d.ts.map +1 -1
- package/dist/v2/server.js +2 -2
- package/package.json +1 -1
|
@@ -169,6 +169,7 @@ import {
|
|
|
169
169
|
releaseCompartmentLeaseBestEffort,
|
|
170
170
|
isCompartmentLeaseHeld,
|
|
171
171
|
queueM0Mutation,
|
|
172
|
+
getLastCompartmentEndMessageId,
|
|
172
173
|
clearRecompStaging,
|
|
173
174
|
getUncoveredCompartmentEndsThrough,
|
|
174
175
|
readServerFallbackUsage,
|
|
@@ -494,6 +495,49 @@ function dropCompartmentsAfter(db, sessionId, anchor, holderId, activeBranch = f
|
|
|
494
495
|
}
|
|
495
496
|
function repairMissingHistoryBoundary(args) {
|
|
496
497
|
const { db, sessionId, isInHostStore, scope = "store" } = args;
|
|
498
|
+
const removed = args.removedByCommittedRevert;
|
|
499
|
+
if (removed) {
|
|
500
|
+
const firstRemoved = removed.values().next().value;
|
|
501
|
+
if (firstRemoved === undefined)
|
|
502
|
+
return { kind: "intact" };
|
|
503
|
+
const busy = {
|
|
504
|
+
kind: "unresolved",
|
|
505
|
+
reason: "busy",
|
|
506
|
+
missingEndMessageId: firstRemoved
|
|
507
|
+
};
|
|
508
|
+
const holderId = crypto.randomUUID();
|
|
509
|
+
if (getActiveCompartmentRun(sessionId) || !acquireCompartmentLease(db, sessionId, holderId))
|
|
510
|
+
return busy;
|
|
511
|
+
try {
|
|
512
|
+
const boundaries = readStoreBoundaries(db, sessionId);
|
|
513
|
+
const first = boundaries.findIndex(({ endMessageId }) => removed.has(endMessageId));
|
|
514
|
+
const affected = boundaries[first];
|
|
515
|
+
if (!affected)
|
|
516
|
+
return { kind: "intact" };
|
|
517
|
+
const previous = boundaries[first - 1];
|
|
518
|
+
let anchor = null;
|
|
519
|
+
if (previous) {
|
|
520
|
+
const row = db.prepare("SELECT end_message AS endMessage FROM compartments WHERE session_id = ? AND sequence = ?").get(sessionId, previous.sequence);
|
|
521
|
+
if (!row)
|
|
522
|
+
return busy;
|
|
523
|
+
anchor = { ...previous, endMessage: row.endMessage };
|
|
524
|
+
}
|
|
525
|
+
const dropped = dropCompartmentsAfter(db, sessionId, anchor, holderId, false, () => args.onRetire?.(boundaries.slice(first), anchor));
|
|
526
|
+
if (dropped === null)
|
|
527
|
+
return busy;
|
|
528
|
+
invalidateAutoEmbedSession(sessionId);
|
|
529
|
+
forgetCachedPrefix(sessionId);
|
|
530
|
+
sessionLog2(sessionId, `committed revert history repair: removed compartments ${dropped.join(",")} and cleared the cached history; removed boundary ${affected.endMessageId}`);
|
|
531
|
+
return {
|
|
532
|
+
kind: "repaired",
|
|
533
|
+
missingEndMessageId: affected.endMessageId,
|
|
534
|
+
anchorEndMessageId: anchor?.endMessageId ?? "",
|
|
535
|
+
droppedSequences: dropped
|
|
536
|
+
};
|
|
537
|
+
} finally {
|
|
538
|
+
releaseCompartmentLeaseBestEffort(db, sessionId, holderId);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
497
541
|
const compartments = scope === "active-branch" ? db.prepare("SELECT sequence, COALESCE(end_message_id, '') AS endMessageId FROM compartments WHERE session_id = ? ORDER BY sequence").all(sessionId) : readStoreBoundaries(db, sessionId);
|
|
498
542
|
let latestIndex = compartments.length - 1;
|
|
499
543
|
while (latestIndex >= 0 && !compartments[latestIndex]?.endMessageId)
|
|
@@ -2401,15 +2445,33 @@ class NativeFoldReplay {
|
|
|
2401
2445
|
this.options.log?.(sessionID, `v3 host fold: ${reason}`);
|
|
2402
2446
|
} catch {}
|
|
2403
2447
|
}
|
|
2448
|
+
historyCoverage(sessionID, reader) {
|
|
2449
|
+
if (!this.options.rendersHistory?.(sessionID))
|
|
2450
|
+
return;
|
|
2451
|
+
const db = this.storage.db;
|
|
2452
|
+
const cached = db.prepare("SELECT cached_m0_last_baseline_end_message_id AS id, cached_m0_bytes IS NOT NULL AS hasBytes FROM session_meta WHERE session_id=?").get(sessionID);
|
|
2453
|
+
const id = cached?.hasBytes ? cached.id : getLastCompartmentEndMessageId(db, sessionID);
|
|
2454
|
+
const after = id ? reader.sequenceForId(sessionID, id) : (reader.earliestSequence(sessionID) ?? 0) - 1;
|
|
2455
|
+
return after === undefined ? undefined : { id, after };
|
|
2456
|
+
}
|
|
2457
|
+
floorCovered(sessionID, floor, coverage, record) {
|
|
2458
|
+
if (!coverage || floor.kind === "start" || floor.kind === "host-checkpoint" && !record?.withoutRecentContext && this.options.servesHostCheckpoint?.(sessionID, floor.id) || floor.after <= coverage.after)
|
|
2459
|
+
return true;
|
|
2460
|
+
this.options.onUncoveredFloor?.(sessionID, floor, coverage);
|
|
2461
|
+
return false;
|
|
2462
|
+
}
|
|
2404
2463
|
async floorState(sessionID, reader, boundary, served, preferCapture = false) {
|
|
2464
|
+
const coverage = this.historyCoverage(sessionID, reader);
|
|
2405
2465
|
const retained = this.tail(sessionID)?.replay;
|
|
2406
2466
|
const controlsKnown = (replay) => replay.controls.every((control) => !control.after || reader.sequenceForId(sessionID, control.after) !== undefined);
|
|
2407
|
-
const memory = retained && validReplayState(retained) && controlsKnown(retained) && validFloor(reader, sessionID, retained.floor) ? retained : undefined;
|
|
2467
|
+
const memory = retained && validReplayState(retained) && controlsKnown(retained) && validFloor(reader, sessionID, retained.floor) && this.floorCovered(sessionID, retained.floor, coverage, retained) ? retained : undefined;
|
|
2408
2468
|
const cut = reader.latestCompaction(sessionID);
|
|
2409
2469
|
const saved = await this.readV3(sessionID);
|
|
2410
|
-
const durable = saved && saved.proof.sourceDigest === foldDigest(reader.hostIdentity()) && (!cut || saved.proof.admissionID === cut.id) && controlsKnown(saved.replay) && validFloor(reader, sessionID, saved.replay.floor) ? saved.replay : undefined;
|
|
2411
|
-
const
|
|
2412
|
-
const
|
|
2470
|
+
const durable = saved && saved.proof.sourceDigest === foldDigest(reader.hostIdentity()) && (!cut || saved.proof.admissionID === cut.id) && controlsKnown(saved.replay) && validFloor(reader, sessionID, saved.replay.floor) && this.floorCovered(sessionID, saved.replay.floor, coverage, saved.replay) ? saved.replay : undefined;
|
|
2471
|
+
const marker = importedFloor(reader, sessionID, cut?.seq);
|
|
2472
|
+
const imported = marker && this.floorCovered(sessionID, marker, coverage) ? marker : undefined;
|
|
2473
|
+
const capturedRecord = await this.readCapturedReplay(sessionID, reader);
|
|
2474
|
+
const captured = capturedRecord && this.floorCovered(sessionID, capturedRecord.floor, coverage, capturedRecord) ? capturedRecord : undefined;
|
|
2413
2475
|
const existing = preferCapture ? captured ?? memory ?? durable : memory ?? durable ?? captured;
|
|
2414
2476
|
if (preferCapture && !existing && !served)
|
|
2415
2477
|
return;
|
|
@@ -2716,6 +2778,8 @@ ${cached}
|
|
|
2716
2778
|
await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
2717
2779
|
return false;
|
|
2718
2780
|
}
|
|
2781
|
+
if (!this.floorCovered(sessionID, replay.floor, this.historyCoverage(sessionID, reader), replay))
|
|
2782
|
+
return false;
|
|
2719
2783
|
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
2720
2784
|
if (proof.historyDigest !== historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after)) {
|
|
2721
2785
|
this.staleHeads.add(sessionID);
|
|
@@ -2810,7 +2874,7 @@ ${cached}
|
|
|
2810
2874
|
return "legacy";
|
|
2811
2875
|
if (saved.proof.admissionID !== cut.id)
|
|
2812
2876
|
return "legacy";
|
|
2813
|
-
return saved.proof.sourceDigest === foldDigest(reader.hostIdentity()) && saved.proof.summaryDigest === foldDigest(cut.data.summary ?? "") && validFloor(reader, sessionID, saved.replay.floor) && saved.proof.historyDigest === historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after) ? "native" : undefined;
|
|
2877
|
+
return saved.proof.sourceDigest === foldDigest(reader.hostIdentity()) && saved.proof.summaryDigest === foldDigest(cut.data.summary ?? "") && validFloor(reader, sessionID, saved.replay.floor) && this.floorCovered(sessionID, saved.replay.floor, this.historyCoverage(sessionID, reader), saved.replay) && saved.proof.historyDigest === historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after) ? "native" : undefined;
|
|
2814
2878
|
}
|
|
2815
2879
|
if (!isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
2816
2880
|
return;
|
|
@@ -2977,7 +3041,7 @@ ${cached}
|
|
|
2977
3041
|
}
|
|
2978
3042
|
return [...grouped].map(([row, messages]) => this.record(row, messages));
|
|
2979
3043
|
}
|
|
2980
|
-
async capture(draft, native, boundary) {
|
|
3044
|
+
async capture(draft, native, boundary, restoredFirstRow) {
|
|
2981
3045
|
const release = this.storage.hold(draft.sessionID);
|
|
2982
3046
|
let replay;
|
|
2983
3047
|
let sourceSeq = -1;
|
|
@@ -2987,6 +3051,11 @@ ${cached}
|
|
|
2987
3051
|
try {
|
|
2988
3052
|
if (this.options.protocol === 3) {
|
|
2989
3053
|
replay = await this.floorState(draft.sessionID, reader, boundary, draft);
|
|
3054
|
+
if (!replay && restoredFirstRow) {
|
|
3055
|
+
const first = reader.page(draft.sessionID, { limit: 1 }).rows[0];
|
|
3056
|
+
if (first?.id === restoredFirstRow)
|
|
3057
|
+
replay = { floor: floorFor(first, "start"), controls: [] };
|
|
3058
|
+
}
|
|
2990
3059
|
if (!replay)
|
|
2991
3060
|
throw new NativeReplayUnavailable("No usable host replay boundary");
|
|
2992
3061
|
replay = { ...replay, blocked: false };
|
|
@@ -3054,7 +3123,7 @@ ${cached}
|
|
|
3054
3123
|
await this.saveCapturedReplay(draft.sessionID, replay, reader);
|
|
3055
3124
|
const saved = await this.readV3(draft.sessionID);
|
|
3056
3125
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
3057
|
-
if (saved && !this.editedAdmissions.has(draft.sessionID) && cut?.id === saved.proof.admissionID && replay.floor.after > saved.replay.floor.after && boundary && this.servedBaseline(draft) === boundary.summary) {
|
|
3126
|
+
if (saved && !this.editedAdmissions.has(draft.sessionID) && cut?.id === saved.proof.admissionID && (replay.floor.after > saved.replay.floor.after || !this.floorCovered(draft.sessionID, saved.replay.floor, this.historyCoverage(draft.sessionID, reader), saved.replay)) && (boundary && this.servedBaseline(draft) === boundary.summary || replay.floor.kind === "start" && restoredFirstRow === replay.floor.id)) {
|
|
3058
3127
|
const value = {
|
|
3059
3128
|
...saved,
|
|
3060
3129
|
replay: {
|
|
@@ -3305,11 +3374,12 @@ ${cached}
|
|
|
3305
3374
|
}
|
|
3306
3375
|
const through = cut.seq - 1;
|
|
3307
3376
|
let metadata = this.metadata.get(sessionID);
|
|
3308
|
-
if (!metadata || (this.metadataThrough.get(sessionID) ?? -1) < through) {
|
|
3377
|
+
if (!metadata || (this.metadataThrough.get(sessionID) ?? -1) < through || this.options.protocol === 3 && this.options.rendersHistory?.(sessionID) && (this.metadataAfter.get(sessionID) ?? -1) > after) {
|
|
3309
3378
|
reader ??= this.openReader(sessionID);
|
|
3310
3379
|
metadata = reader.rowStampsThrough(sessionID, through, this.options.protocol === 3 ? after : undefined).filter(conversational);
|
|
3311
3380
|
this.metadata.set(sessionID, metadata);
|
|
3312
3381
|
this.metadataThrough.set(sessionID, through);
|
|
3382
|
+
this.metadataAfter.set(sessionID, this.options.protocol === 3 ? after : undefined);
|
|
3313
3383
|
}
|
|
3314
3384
|
const required = metadata.filter((row) => row.seq > after && row.seq <= through);
|
|
3315
3385
|
if (this.dirty.has(sessionID) || !tail || (this.loaded.get(sessionID) ?? -1) < through && !this.storage.admission(sessionID, cut.id) || !this.storage.containsRows(sessionID, required.map((row) => row.id))) {
|
|
@@ -6238,6 +6308,7 @@ var MAX_STAGED_SUFFIX_ROWS = 1e4;
|
|
|
6238
6308
|
class V2RevertMessageCleanup {
|
|
6239
6309
|
openStoreReader;
|
|
6240
6310
|
staged = new BoundedSessionMap(MAX_STAGED_REVERTS);
|
|
6311
|
+
pendingHistory = [];
|
|
6241
6312
|
constructor(openStoreReader) {
|
|
6242
6313
|
this.openStoreReader = openStoreReader;
|
|
6243
6314
|
}
|
|
@@ -6266,7 +6337,11 @@ class V2RevertMessageCleanup {
|
|
|
6266
6337
|
discardAllStageProofs() {
|
|
6267
6338
|
this.staged.clear();
|
|
6268
6339
|
}
|
|
6269
|
-
|
|
6340
|
+
forgetSession(sessionID) {
|
|
6341
|
+
this.discardStageProof(sessionID);
|
|
6342
|
+
this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID);
|
|
6343
|
+
}
|
|
6344
|
+
pruneOnCommit(db, sessionID, to, retireHistory) {
|
|
6270
6345
|
const staged = this.staged.peek(sessionID);
|
|
6271
6346
|
this.discardStageProof(sessionID);
|
|
6272
6347
|
const noteSkippedCleanup = (reason) => {
|
|
@@ -6296,9 +6371,45 @@ class V2RevertMessageCleanup {
|
|
|
6296
6371
|
return noteSkippedCleanup("retained predecessor is not visible at commit");
|
|
6297
6372
|
if (!removed.size)
|
|
6298
6373
|
return noteSkippedCleanup("all staged rows still exist");
|
|
6374
|
+
if (retireHistory) {
|
|
6375
|
+
if (this.pendingHistory.length === MAX_STAGED_REVERTS)
|
|
6376
|
+
this.pendingHistory.shift();
|
|
6377
|
+
this.pendingHistory.push({ sessionID, host: staged.host, removed });
|
|
6378
|
+
}
|
|
6299
6379
|
pruneMessages(db, sessionID, removed);
|
|
6300
6380
|
return true;
|
|
6301
6381
|
}
|
|
6382
|
+
retireProvenHistory(db, sessionID, reader) {
|
|
6383
|
+
const ownProofs = this.pendingHistory.filter((proof) => proof.sessionID === sessionID);
|
|
6384
|
+
if (ownProofs.length === 0)
|
|
6385
|
+
return;
|
|
6386
|
+
const source = reader ?? this.openStoreReader();
|
|
6387
|
+
try {
|
|
6388
|
+
const host = source.hostIdentity();
|
|
6389
|
+
const current = ownProofs.filter((proof) => proof.host === host);
|
|
6390
|
+
this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID || proof.host === host);
|
|
6391
|
+
if (current.length === 0)
|
|
6392
|
+
return;
|
|
6393
|
+
const removed = new Set;
|
|
6394
|
+
for (const proof of current)
|
|
6395
|
+
for (const id of proof.removed)
|
|
6396
|
+
removed.add(id);
|
|
6397
|
+
const result = repairMissingHistoryBoundary({
|
|
6398
|
+
db,
|
|
6399
|
+
sessionId: sessionID,
|
|
6400
|
+
isInHostStore: (id) => source.sequenceForId(sessionID, id) !== undefined,
|
|
6401
|
+
removedByCommittedRevert: removed,
|
|
6402
|
+
onRetire: () => clearRecompStaging(db, sessionID)
|
|
6403
|
+
});
|
|
6404
|
+
if (result.kind !== "unresolved") {
|
|
6405
|
+
this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID);
|
|
6406
|
+
}
|
|
6407
|
+
return result.kind === "intact" ? undefined : result;
|
|
6408
|
+
} finally {
|
|
6409
|
+
if (!reader)
|
|
6410
|
+
source.close();
|
|
6411
|
+
}
|
|
6412
|
+
}
|
|
6302
6413
|
}
|
|
6303
6414
|
function pruneMessages(db, sessionID, removed) {
|
|
6304
6415
|
db.transaction(() => {
|
|
@@ -6965,12 +7076,16 @@ function checkHistoryBoundary(db, reader, sessionID) {
|
|
|
6965
7076
|
}
|
|
6966
7077
|
}
|
|
6967
7078
|
function newBaselineStartAfter(db, reader, sessionID, cached, compactionOff) {
|
|
6968
|
-
if (cached?.id != null
|
|
7079
|
+
if (cached?.id != null)
|
|
6969
7080
|
return;
|
|
6970
7081
|
const isSubagent = storedSubagentMode(db, sessionID);
|
|
6971
7082
|
if (isSubagent === undefined || !rendersCompartmentHistory(isSubagent, compactionOff))
|
|
6972
7083
|
return;
|
|
7084
|
+
if (cached?.hasBytes)
|
|
7085
|
+
return reader.earliestSequence(sessionID) === undefined ? undefined : null;
|
|
6973
7086
|
const newest = db.prepare("SELECT end_message_id AS id, rebase_status AS status FROM compartments WHERE session_id = ? ORDER BY sequence DESC LIMIT 1").get(sessionID);
|
|
7087
|
+
if (!newest && reader.earliestSequence(sessionID) !== undefined)
|
|
7088
|
+
return null;
|
|
6974
7089
|
if (newest?.id && newest.status !== "unresolved" && reader.sequenceForId(sessionID, newest.id) !== undefined)
|
|
6975
7090
|
return newest.id;
|
|
6976
7091
|
return;
|
|
@@ -6988,6 +7103,12 @@ async function cacheV2SessionDirectory(session, sessionID, directories) {
|
|
|
6988
7103
|
}
|
|
6989
7104
|
}
|
|
6990
7105
|
var contextPass = new AsyncLocalStorage;
|
|
7106
|
+
function noteCheckpointWithoutTail(sessionID, cut, incoming, messageCount) {
|
|
7107
|
+
const pass = contextPass.getStore();
|
|
7108
|
+
if (pass?.sessionID !== sessionID)
|
|
7109
|
+
return;
|
|
7110
|
+
pass.checkpointWithoutTail = cut && incoming && messageCount === 1 && !isCheckpointNote(cut.data.summary) ? cut.id : undefined;
|
|
7111
|
+
}
|
|
6991
7112
|
function withV2ContextPass(sessionID, run) {
|
|
6992
7113
|
const pass = { sessionID, refused: false };
|
|
6993
7114
|
return withSqliteTransformPass2(() => contextPass.run(pass, () => run(pass)));
|
|
@@ -7204,9 +7325,34 @@ async function registerContext(context) {
|
|
|
7204
7325
|
const embeddings = createV2EmbeddingScope(resolveProjectIdentityForSession(directory, config.allow_home_project));
|
|
7205
7326
|
const folds = new FoldOwner(context.storage);
|
|
7206
7327
|
const nativeFoldMemory = compactionOff ? undefined : nativeFoldCache(() => storage.require());
|
|
7328
|
+
const loggedUncoveredCheckpoints = new BoundedSessionMap(1000);
|
|
7207
7329
|
const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader(), context.storage, {
|
|
7208
7330
|
protocol: 3,
|
|
7209
|
-
log: sessionLog2
|
|
7331
|
+
log: sessionLog2,
|
|
7332
|
+
rendersHistory: (sessionID) => {
|
|
7333
|
+
if (rustModeModuleClient)
|
|
7334
|
+
return false;
|
|
7335
|
+
const mode = storedSubagentMode(storage.require(), sessionID);
|
|
7336
|
+
return mode !== undefined && rendersCompartmentHistory(mode, compactionOff);
|
|
7337
|
+
},
|
|
7338
|
+
servesHostCheckpoint: (sessionID, checkpointID) => {
|
|
7339
|
+
const pass = contextPass.getStore();
|
|
7340
|
+
return pass?.sessionID === sessionID && pass.checkpointWithoutTail === checkpointID;
|
|
7341
|
+
},
|
|
7342
|
+
onUncoveredFloor: (sessionID, floor, coverage) => {
|
|
7343
|
+
const pass = contextPass.getStore();
|
|
7344
|
+
if (pass?.sessionID === sessionID && pass.loggedUncoveredFloor)
|
|
7345
|
+
return;
|
|
7346
|
+
if (floor.kind === "checkpoint") {
|
|
7347
|
+
const key = JSON.stringify([sessionID, floor.id]);
|
|
7348
|
+
if (loggedUncoveredCheckpoints.get(key))
|
|
7349
|
+
return;
|
|
7350
|
+
loggedUncoveredCheckpoints.set(key, true);
|
|
7351
|
+
}
|
|
7352
|
+
if (pass?.sessionID === sessionID)
|
|
7353
|
+
pass.loggedUncoveredFloor = true;
|
|
7354
|
+
sessionLog2(sessionID, `v2 restore: ignored ${floor.kind} floor ${floor.id} at seq=${floor.after}; rendered coverage ${coverage.id ?? "none"} ends at seq=${coverage.after}`);
|
|
7355
|
+
}
|
|
7210
7356
|
}) : undefined;
|
|
7211
7357
|
setOutputReserveConfig(config.output_reserve);
|
|
7212
7358
|
const queriedModels = new Set;
|
|
@@ -7811,9 +7957,11 @@ async function registerContext(context) {
|
|
|
7811
7957
|
if (event.type === "session.revert.staged" && db) {
|
|
7812
7958
|
revertMessageCleanup.captureStageProof(sessionID, event.data.revert?.messageID);
|
|
7813
7959
|
}
|
|
7814
|
-
if (event.type === "session.revert.cleared"
|
|
7960
|
+
if (event.type === "session.revert.cleared") {
|
|
7815
7961
|
revertMessageCleanup.discardStageProof(sessionID);
|
|
7816
7962
|
}
|
|
7963
|
+
if (event.type === "session.deleted")
|
|
7964
|
+
revertMessageCleanup.forgetSession(sessionID);
|
|
7817
7965
|
if (event.type === "session.revert.committed") {
|
|
7818
7966
|
dropServedRecord(sessionID, "host_edit");
|
|
7819
7967
|
if (db) {
|
|
@@ -7821,9 +7969,10 @@ async function registerContext(context) {
|
|
|
7821
7969
|
withoutSqliteTransformPass2(() => {
|
|
7822
7970
|
scheduleClearAndReindex(indexDb, sessionID, pagedRead);
|
|
7823
7971
|
try {
|
|
7824
|
-
if (revertMessageCleanup.pruneOnCommit(indexDb, sessionID, event.data?.to)) {
|
|
7972
|
+
if (revertMessageCleanup.pruneOnCommit(indexDb, sessionID, event.data?.to, !compactionOff && !rustModeModuleClient)) {
|
|
7825
7973
|
tagger.cleanup(sessionID);
|
|
7826
7974
|
transform?.invalidateRustWireState(sessionID);
|
|
7975
|
+
revertMessageCleanup.retireProvenHistory(indexDb, sessionID);
|
|
7827
7976
|
}
|
|
7828
7977
|
} catch (error) {
|
|
7829
7978
|
sessionLog2(sessionID, "committed revert message cleanup failed:", error);
|
|
@@ -8121,7 +8270,7 @@ async function registerContext(context) {
|
|
|
8121
8270
|
const nativeFloor = await nativeFoldReplay?.restorationFloor(draft.sessionID, cut, reader, {
|
|
8122
8271
|
allowMissingFloor: newStart !== undefined
|
|
8123
8272
|
});
|
|
8124
|
-
if (newStart && nativeFloor === undefined) {
|
|
8273
|
+
if (newStart !== undefined && nativeFloor === undefined) {
|
|
8125
8274
|
const pass = contextPass.getStore();
|
|
8126
8275
|
if (pass)
|
|
8127
8276
|
pass.recoveredCheckpointID = cut.id;
|
|
@@ -8130,6 +8279,12 @@ async function registerContext(context) {
|
|
|
8130
8279
|
const servedBoundary = boundaryID ? servedBoundaryRow2(reader, draft.sessionID, boundaryID) : null;
|
|
8131
8280
|
const retiredInstructions = await nativeFoldReplay?.instructionRetirement(draft.sessionID, reader) ?? (() => false);
|
|
8132
8281
|
const floor = Math.max(nativeFloor ?? -Infinity, (nativeFoldReplay?.sourceChanged(draft.sessionID) && !rustModeModuleClient ? (reader.earliestSequence(draft.sessionID) ?? 0) - 1 : undefined) ?? (moduleBoundarySeq !== undefined ? moduleBoundarySeq - 1 : undefined) ?? servedBoundary?.seq ?? reader.sequenceForId(draft.sessionID, boundaryID) ?? (reader.earliestSequence(draft.sessionID) ?? 0) - 1);
|
|
8282
|
+
if (nativeFloor === undefined && newStart === null) {
|
|
8283
|
+
const first = reader.page(draft.sessionID, { limit: 1 }).rows[0];
|
|
8284
|
+
if (first?.seq === floor + 1)
|
|
8285
|
+
args.onStartAtFirstRow?.(first.id);
|
|
8286
|
+
sessionLog2(draft.sessionID, `v2 restore: no rendered history boundary; starting at stored row seq=${floor + 1}`);
|
|
8287
|
+
}
|
|
8133
8288
|
const floorRow = !rustModeModuleClient && Number.isFinite(floor) ? reader.range(draft.sessionID, floor - 1, floor).find((row) => row.seq === floor) : undefined;
|
|
8134
8289
|
const boundary = floorRow && hasUnsummarizedBlocks(db, reader, draft.sessionID, floorRow.id) ? floor - 1 : floor;
|
|
8135
8290
|
if (moduleBoundarySeq !== undefined)
|
|
@@ -8358,6 +8513,7 @@ async function registerContext(context) {
|
|
|
8358
8513
|
const incoming = localCut && messages.find((message) => message.id === localCut.id);
|
|
8359
8514
|
if (localCut && !incoming)
|
|
8360
8515
|
return;
|
|
8516
|
+
noteCheckpointWithoutTail(draft.sessionID, localCut, incoming, messages.length);
|
|
8361
8517
|
checkpointAtEntry = incoming || null;
|
|
8362
8518
|
const modeDb = db ?? storage.current();
|
|
8363
8519
|
const subagent = modeDb ? storedSubagentMode(modeDb, draft.sessionID) : undefined;
|
|
@@ -8554,18 +8710,20 @@ async function registerContext(context) {
|
|
|
8554
8710
|
let submitted;
|
|
8555
8711
|
let recordedHead;
|
|
8556
8712
|
let upgradeCheckpointSequence;
|
|
8713
|
+
let restoredFirstRow;
|
|
8557
8714
|
try {
|
|
8558
8715
|
syntheticIDs = await readSyntheticProvenance(reader, draft.messages);
|
|
8559
8716
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
8560
8717
|
if (nativeFoldReplay)
|
|
8561
8718
|
await nativeFoldReplay.observeSource(draft.sessionID, reader);
|
|
8562
|
-
const boundaryRepair = !rustModeModuleClient && db && !compactionOff ? checkHistoryBoundary(db, reader, draft.sessionID) : undefined;
|
|
8719
|
+
const boundaryRepair = !rustModeModuleClient && db && !compactionOff ? revertMessageCleanup.retireProvenHistory(db, draft.sessionID, reader) ?? checkHistoryBoundary(db, reader, draft.sessionID) : undefined;
|
|
8563
8720
|
if (boundaryRepair?.kind === "repaired" || boundaryRepair?.kind === "baseline-reset") {
|
|
8564
8721
|
historyRefreshSessions.add(draft.sessionID);
|
|
8565
8722
|
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "boundary_repair");
|
|
8566
8723
|
}
|
|
8567
8724
|
const localCut = cut && isLocalCheckpoint(cut) ? cut : undefined;
|
|
8568
8725
|
const incoming = localCut && draft.messages.find((message) => message.id === localCut.id);
|
|
8726
|
+
noteCheckpointWithoutTail(draft.sessionID, localCut, incoming, draft.messages.length);
|
|
8569
8727
|
if (!compactionOff && localCut && !incoming)
|
|
8570
8728
|
throw new Error("The host checkpoint disappeared from the context draft");
|
|
8571
8729
|
checkpointAtEntry = incoming || null;
|
|
@@ -8647,7 +8805,10 @@ async function registerContext(context) {
|
|
|
8647
8805
|
messages: draft.messages,
|
|
8648
8806
|
cut: localCut,
|
|
8649
8807
|
incoming,
|
|
8650
|
-
canRebuild: true
|
|
8808
|
+
canRebuild: true,
|
|
8809
|
+
onStartAtFirstRow: (id) => {
|
|
8810
|
+
restoredFirstRow = id;
|
|
8811
|
+
}
|
|
8651
8812
|
}));
|
|
8652
8813
|
}
|
|
8653
8814
|
instructionRows = new Map(bindKeptInstructionCoordinates(draft.messages, incoming || undefined, reader, draft.sessionID).map((row) => [row.id, row]));
|
|
@@ -8701,14 +8862,30 @@ async function registerContext(context) {
|
|
|
8701
8862
|
})({}, mapped);
|
|
8702
8863
|
mapped.commit();
|
|
8703
8864
|
if (replayHead === undefined && (pass.recoveredCheckpointID || previousRecovery && pass.nativeReplayCheckpointID === previousRecovery.checkpointID)) {
|
|
8865
|
+
let coveredAfterRestore;
|
|
8866
|
+
if (pass.recoveredCheckpointID && restoredFirstRow) {
|
|
8867
|
+
try {
|
|
8868
|
+
const end = db.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id=?").get(draft.sessionID);
|
|
8869
|
+
if (end?.id) {
|
|
8870
|
+
const source = openStoreReader();
|
|
8871
|
+
try {
|
|
8872
|
+
const seq = source.sequenceForId(draft.sessionID, end.id);
|
|
8873
|
+
if (seq !== undefined)
|
|
8874
|
+
coveredAfterRestore = new Set(source.instructionRowsThrough(draft.sessionID, seq).map(({ id }) => id));
|
|
8875
|
+
} finally {
|
|
8876
|
+
source.close();
|
|
8877
|
+
}
|
|
8878
|
+
}
|
|
8879
|
+
} catch {}
|
|
8880
|
+
}
|
|
8704
8881
|
pass.servedInstructionIDs = new Set(mapped.messages.flatMap(({ info, parts }) => {
|
|
8705
|
-
|
|
8882
|
+
const id = hostInstructionRowID(info);
|
|
8883
|
+
if (!id || info.role !== "system" || pass.recoveredCheckpointID && !isCoveredInstructionRow(info) && !coveredAfterRestore?.has(id) || !parts.some((value) => {
|
|
8706
8884
|
const part = value;
|
|
8707
8885
|
return part?.type === "text" && typeof part.text === "string" && part.text.length > 0;
|
|
8708
8886
|
}))
|
|
8709
8887
|
return [];
|
|
8710
|
-
|
|
8711
|
-
return id ? [id] : [];
|
|
8888
|
+
return [id];
|
|
8712
8889
|
}));
|
|
8713
8890
|
}
|
|
8714
8891
|
const checkpointPermission = checkpointPassPermissions.get(draft.sessionID);
|
|
@@ -8756,7 +8933,7 @@ async function registerContext(context) {
|
|
|
8756
8933
|
try {
|
|
8757
8934
|
const state = db && getOrCreateSessionMeta(db, draft.sessionID);
|
|
8758
8935
|
const boundary = db?.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id=?").get(draft.sessionID);
|
|
8759
|
-
await nativeFoldReplay?.capture(draft, nativeMessages, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined);
|
|
8936
|
+
await nativeFoldReplay?.capture(draft, nativeMessages, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined, restoredFirstRow);
|
|
8760
8937
|
} catch (error) {
|
|
8761
8938
|
nativeFoldReplay?.invalidate(draft.sessionID, true);
|
|
8762
8939
|
sessionLog2(draft.sessionID, "v2 host fold: optional capture unavailable", error);
|
|
@@ -9073,6 +9250,7 @@ async function registerContext(context) {
|
|
|
9073
9250
|
await hiddenChildSweep.dispose();
|
|
9074
9251
|
messageTimesCache.clear();
|
|
9075
9252
|
recoveredInstructions.clear();
|
|
9253
|
+
loggedUncoveredCheckpoints.clear();
|
|
9076
9254
|
hostFoldIdle?.dispose();
|
|
9077
9255
|
usageController.abort();
|
|
9078
9256
|
await hiddenCompletionExecutor?.dispose();
|
|
@@ -48,6 +48,8 @@ export declare function repairMissingHistoryBoundary(args: {
|
|
|
48
48
|
scope?: "store" | "active-branch";
|
|
49
49
|
/** Queue historian recovery in the same transaction that deletes stale summaries. */
|
|
50
50
|
onRetire?: (retired: readonly HistoryBoundary[], anchor: HistoryBoundary | null) => void;
|
|
51
|
+
/** Exact host row IDs that a committed revert proved it removed. */
|
|
52
|
+
removedByCommittedRevert?: ReadonlySet<string>;
|
|
51
53
|
}): HistoryBoundaryRepair;
|
|
52
54
|
export {};
|
|
53
55
|
//# sourceMappingURL=history-boundary-repair.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history-boundary-repair.d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KAAK,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;IAClC,qFAAqF;IACrF,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,KAAK,IAAI,CAAC;IACzF,oEAAoE;IACpE,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAClD,GAAG,qBAAqB,CAkLxB"}
|
package/dist/index.js
CHANGED
|
@@ -8206,7 +8206,7 @@ var require_src2 = __commonJS(function(exports, module) {
|
|
|
8206
8206
|
// package.json
|
|
8207
8207
|
var package_default = {
|
|
8208
8208
|
name: "@cortexkit/opencode-magic-context",
|
|
8209
|
-
version: "0.49.
|
|
8209
|
+
version: "0.49.90",
|
|
8210
8210
|
type: "module",
|
|
8211
8211
|
description: "OpenCode plugin for Magic Context — cross-session memory and context management",
|
|
8212
8212
|
main: "dist/index.js",
|
|
@@ -12101,7 +12101,7 @@ async function setup(context) {
|
|
|
12101
12101
|
if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
|
|
12102
12102
|
log2(`[magic-context] Magic Context storage is at ${storageDir}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
|
|
12103
12103
|
}
|
|
12104
|
-
const { registerContext } = await import("./context-
|
|
12104
|
+
const { registerContext } = await import("./context-cdds0gjj.js");
|
|
12105
12105
|
setHarness2("opencode2");
|
|
12106
12106
|
bindStaleBuildNotice({}, import.meta.url, "opencode2");
|
|
12107
12107
|
const duties = await registerContext(context);
|
|
@@ -3384,6 +3384,49 @@ function dropCompartmentsAfter(db, sessionId, anchor, holderId, activeBranch = f
|
|
|
3384
3384
|
}
|
|
3385
3385
|
function repairMissingHistoryBoundary(args) {
|
|
3386
3386
|
const { db, sessionId, isInHostStore, scope = "store" } = args;
|
|
3387
|
+
const removed = args.removedByCommittedRevert;
|
|
3388
|
+
if (removed) {
|
|
3389
|
+
const firstRemoved = removed.values().next().value;
|
|
3390
|
+
if (firstRemoved === undefined)
|
|
3391
|
+
return { kind: "intact" };
|
|
3392
|
+
const busy = {
|
|
3393
|
+
kind: "unresolved",
|
|
3394
|
+
reason: "busy",
|
|
3395
|
+
missingEndMessageId: firstRemoved
|
|
3396
|
+
};
|
|
3397
|
+
const holderId = crypto.randomUUID();
|
|
3398
|
+
if (getActiveCompartmentRun(sessionId) || !acquireCompartmentLease(db, sessionId, holderId))
|
|
3399
|
+
return busy;
|
|
3400
|
+
try {
|
|
3401
|
+
const boundaries = readStoreBoundaries(db, sessionId);
|
|
3402
|
+
const first = boundaries.findIndex(({ endMessageId }) => removed.has(endMessageId));
|
|
3403
|
+
const affected = boundaries[first];
|
|
3404
|
+
if (!affected)
|
|
3405
|
+
return { kind: "intact" };
|
|
3406
|
+
const previous = boundaries[first - 1];
|
|
3407
|
+
let anchor = null;
|
|
3408
|
+
if (previous) {
|
|
3409
|
+
const row = db.prepare("SELECT end_message AS endMessage FROM compartments WHERE session_id = ? AND sequence = ?").get(sessionId, previous.sequence);
|
|
3410
|
+
if (!row)
|
|
3411
|
+
return busy;
|
|
3412
|
+
anchor = { ...previous, endMessage: row.endMessage };
|
|
3413
|
+
}
|
|
3414
|
+
const dropped = dropCompartmentsAfter(db, sessionId, anchor, holderId, false, () => args.onRetire?.(boundaries.slice(first), anchor));
|
|
3415
|
+
if (dropped === null)
|
|
3416
|
+
return busy;
|
|
3417
|
+
invalidateAutoEmbedSession(sessionId);
|
|
3418
|
+
forgetCachedPrefix(sessionId);
|
|
3419
|
+
sessionLog2(sessionId, `committed revert history repair: removed compartments ${dropped.join(",")} and cleared the cached history; removed boundary ${affected.endMessageId}`);
|
|
3420
|
+
return {
|
|
3421
|
+
kind: "repaired",
|
|
3422
|
+
missingEndMessageId: affected.endMessageId,
|
|
3423
|
+
anchorEndMessageId: anchor?.endMessageId ?? "",
|
|
3424
|
+
droppedSequences: dropped
|
|
3425
|
+
};
|
|
3426
|
+
} finally {
|
|
3427
|
+
releaseCompartmentLeaseBestEffort(db, sessionId, holderId);
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3387
3430
|
const compartments = scope === "active-branch" ? db.prepare("SELECT sequence, COALESCE(end_message_id, '') AS endMessageId FROM compartments WHERE session_id = ? ORDER BY sequence").all(sessionId) : readStoreBoundaries(db, sessionId);
|
|
3388
3431
|
let latestIndex = compartments.length - 1;
|
|
3389
3432
|
while (latestIndex >= 0 && !compartments[latestIndex]?.endMessageId)
|
|
@@ -29202,15 +29245,33 @@ class NativeFoldReplay {
|
|
|
29202
29245
|
this.options.log?.(sessionID, `v3 host fold: ${reason}`);
|
|
29203
29246
|
} catch {}
|
|
29204
29247
|
}
|
|
29248
|
+
historyCoverage(sessionID, reader) {
|
|
29249
|
+
if (!this.options.rendersHistory?.(sessionID))
|
|
29250
|
+
return;
|
|
29251
|
+
const db = this.storage.db;
|
|
29252
|
+
const cached = db.prepare("SELECT cached_m0_last_baseline_end_message_id AS id, cached_m0_bytes IS NOT NULL AS hasBytes FROM session_meta WHERE session_id=?").get(sessionID);
|
|
29253
|
+
const id = cached?.hasBytes ? cached.id : getLastCompartmentEndMessageId(db, sessionID);
|
|
29254
|
+
const after = id ? reader.sequenceForId(sessionID, id) : (reader.earliestSequence(sessionID) ?? 0) - 1;
|
|
29255
|
+
return after === undefined ? undefined : { id, after };
|
|
29256
|
+
}
|
|
29257
|
+
floorCovered(sessionID, floor, coverage, record) {
|
|
29258
|
+
if (!coverage || floor.kind === "start" || floor.kind === "host-checkpoint" && !record?.withoutRecentContext && this.options.servesHostCheckpoint?.(sessionID, floor.id) || floor.after <= coverage.after)
|
|
29259
|
+
return true;
|
|
29260
|
+
this.options.onUncoveredFloor?.(sessionID, floor, coverage);
|
|
29261
|
+
return false;
|
|
29262
|
+
}
|
|
29205
29263
|
async floorState(sessionID, reader, boundary, served, preferCapture = false) {
|
|
29264
|
+
const coverage = this.historyCoverage(sessionID, reader);
|
|
29206
29265
|
const retained = this.tail(sessionID)?.replay;
|
|
29207
29266
|
const controlsKnown = (replay) => replay.controls.every((control) => !control.after || reader.sequenceForId(sessionID, control.after) !== undefined);
|
|
29208
|
-
const memory = retained && validReplayState(retained) && controlsKnown(retained) && validFloor(reader, sessionID, retained.floor) ? retained : undefined;
|
|
29267
|
+
const memory = retained && validReplayState(retained) && controlsKnown(retained) && validFloor(reader, sessionID, retained.floor) && this.floorCovered(sessionID, retained.floor, coverage, retained) ? retained : undefined;
|
|
29209
29268
|
const cut = reader.latestCompaction(sessionID);
|
|
29210
29269
|
const saved = await this.readV3(sessionID);
|
|
29211
|
-
const durable = saved && saved.proof.sourceDigest === foldDigest(reader.hostIdentity()) && (!cut || saved.proof.admissionID === cut.id) && controlsKnown(saved.replay) && validFloor(reader, sessionID, saved.replay.floor) ? saved.replay : undefined;
|
|
29212
|
-
const
|
|
29213
|
-
const
|
|
29270
|
+
const durable = saved && saved.proof.sourceDigest === foldDigest(reader.hostIdentity()) && (!cut || saved.proof.admissionID === cut.id) && controlsKnown(saved.replay) && validFloor(reader, sessionID, saved.replay.floor) && this.floorCovered(sessionID, saved.replay.floor, coverage, saved.replay) ? saved.replay : undefined;
|
|
29271
|
+
const marker = importedFloor(reader, sessionID, cut?.seq);
|
|
29272
|
+
const imported = marker && this.floorCovered(sessionID, marker, coverage) ? marker : undefined;
|
|
29273
|
+
const capturedRecord = await this.readCapturedReplay(sessionID, reader);
|
|
29274
|
+
const captured = capturedRecord && this.floorCovered(sessionID, capturedRecord.floor, coverage, capturedRecord) ? capturedRecord : undefined;
|
|
29214
29275
|
const existing = preferCapture ? captured ?? memory ?? durable : memory ?? durable ?? captured;
|
|
29215
29276
|
if (preferCapture && !existing && !served)
|
|
29216
29277
|
return;
|
|
@@ -29517,6 +29578,8 @@ ${cached}
|
|
|
29517
29578
|
await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
29518
29579
|
return false;
|
|
29519
29580
|
}
|
|
29581
|
+
if (!this.floorCovered(sessionID, replay.floor, this.historyCoverage(sessionID, reader), replay))
|
|
29582
|
+
return false;
|
|
29520
29583
|
await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
|
|
29521
29584
|
if (proof.historyDigest !== historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after)) {
|
|
29522
29585
|
this.staleHeads.add(sessionID);
|
|
@@ -29611,7 +29674,7 @@ ${cached}
|
|
|
29611
29674
|
return "legacy";
|
|
29612
29675
|
if (saved.proof.admissionID !== cut.id)
|
|
29613
29676
|
return "legacy";
|
|
29614
|
-
return saved.proof.sourceDigest === foldDigest(reader.hostIdentity()) && saved.proof.summaryDigest === foldDigest(cut.data.summary ?? "") && validFloor(reader, sessionID, saved.replay.floor) && saved.proof.historyDigest === historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after) ? "native" : undefined;
|
|
29677
|
+
return saved.proof.sourceDigest === foldDigest(reader.hostIdentity()) && saved.proof.summaryDigest === foldDigest(cut.data.summary ?? "") && validFloor(reader, sessionID, saved.replay.floor) && this.floorCovered(sessionID, saved.replay.floor, this.historyCoverage(sessionID, reader), saved.replay) && saved.proof.historyDigest === historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after) ? "native" : undefined;
|
|
29615
29678
|
}
|
|
29616
29679
|
if (!isLocalCheckpoint(cut) || cut.session_id !== sessionID)
|
|
29617
29680
|
return;
|
|
@@ -29778,7 +29841,7 @@ ${cached}
|
|
|
29778
29841
|
}
|
|
29779
29842
|
return [...grouped].map(([row, messages]) => this.record(row, messages));
|
|
29780
29843
|
}
|
|
29781
|
-
async capture(draft, native, boundary) {
|
|
29844
|
+
async capture(draft, native, boundary, restoredFirstRow) {
|
|
29782
29845
|
const release = this.storage.hold(draft.sessionID);
|
|
29783
29846
|
let replay;
|
|
29784
29847
|
let sourceSeq = -1;
|
|
@@ -29788,6 +29851,11 @@ ${cached}
|
|
|
29788
29851
|
try {
|
|
29789
29852
|
if (this.options.protocol === 3) {
|
|
29790
29853
|
replay = await this.floorState(draft.sessionID, reader, boundary, draft);
|
|
29854
|
+
if (!replay && restoredFirstRow) {
|
|
29855
|
+
const first = reader.page(draft.sessionID, { limit: 1 }).rows[0];
|
|
29856
|
+
if (first?.id === restoredFirstRow)
|
|
29857
|
+
replay = { floor: floorFor(first, "start"), controls: [] };
|
|
29858
|
+
}
|
|
29791
29859
|
if (!replay)
|
|
29792
29860
|
throw new NativeReplayUnavailable("No usable host replay boundary");
|
|
29793
29861
|
replay = { ...replay, blocked: false };
|
|
@@ -29855,7 +29923,7 @@ ${cached}
|
|
|
29855
29923
|
await this.saveCapturedReplay(draft.sessionID, replay, reader);
|
|
29856
29924
|
const saved = await this.readV3(draft.sessionID);
|
|
29857
29925
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
29858
|
-
if (saved && !this.editedAdmissions.has(draft.sessionID) && cut?.id === saved.proof.admissionID && replay.floor.after > saved.replay.floor.after && boundary && this.servedBaseline(draft) === boundary.summary) {
|
|
29926
|
+
if (saved && !this.editedAdmissions.has(draft.sessionID) && cut?.id === saved.proof.admissionID && (replay.floor.after > saved.replay.floor.after || !this.floorCovered(draft.sessionID, saved.replay.floor, this.historyCoverage(draft.sessionID, reader), saved.replay)) && (boundary && this.servedBaseline(draft) === boundary.summary || replay.floor.kind === "start" && restoredFirstRow === replay.floor.id)) {
|
|
29859
29927
|
const value = {
|
|
29860
29928
|
...saved,
|
|
29861
29929
|
replay: {
|
|
@@ -30106,11 +30174,12 @@ ${cached}
|
|
|
30106
30174
|
}
|
|
30107
30175
|
const through = cut.seq - 1;
|
|
30108
30176
|
let metadata = this.metadata.get(sessionID);
|
|
30109
|
-
if (!metadata || (this.metadataThrough.get(sessionID) ?? -1) < through) {
|
|
30177
|
+
if (!metadata || (this.metadataThrough.get(sessionID) ?? -1) < through || this.options.protocol === 3 && this.options.rendersHistory?.(sessionID) && (this.metadataAfter.get(sessionID) ?? -1) > after) {
|
|
30110
30178
|
reader ??= this.openReader(sessionID);
|
|
30111
30179
|
metadata = reader.rowStampsThrough(sessionID, through, this.options.protocol === 3 ? after : undefined).filter(conversational);
|
|
30112
30180
|
this.metadata.set(sessionID, metadata);
|
|
30113
30181
|
this.metadataThrough.set(sessionID, through);
|
|
30182
|
+
this.metadataAfter.set(sessionID, this.options.protocol === 3 ? after : undefined);
|
|
30114
30183
|
}
|
|
30115
30184
|
const required = metadata.filter((row) => row.seq > after && row.seq <= through);
|
|
30116
30185
|
if (this.dirty.has(sessionID) || !tail || (this.loaded.get(sessionID) ?? -1) < through && !this.storage.admission(sessionID, cut.id) || !this.storage.containsRows(sessionID, required.map((row) => row.id))) {
|
|
@@ -42496,6 +42565,7 @@ var MAX_STAGED_SUFFIX_ROWS = 1e4;
|
|
|
42496
42565
|
class V2RevertMessageCleanup {
|
|
42497
42566
|
openStoreReader;
|
|
42498
42567
|
staged = new BoundedSessionMap(MAX_STAGED_REVERTS);
|
|
42568
|
+
pendingHistory = [];
|
|
42499
42569
|
constructor(openStoreReader) {
|
|
42500
42570
|
this.openStoreReader = openStoreReader;
|
|
42501
42571
|
}
|
|
@@ -42524,7 +42594,11 @@ class V2RevertMessageCleanup {
|
|
|
42524
42594
|
discardAllStageProofs() {
|
|
42525
42595
|
this.staged.clear();
|
|
42526
42596
|
}
|
|
42527
|
-
|
|
42597
|
+
forgetSession(sessionID) {
|
|
42598
|
+
this.discardStageProof(sessionID);
|
|
42599
|
+
this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID);
|
|
42600
|
+
}
|
|
42601
|
+
pruneOnCommit(db, sessionID, to, retireHistory) {
|
|
42528
42602
|
const staged = this.staged.peek(sessionID);
|
|
42529
42603
|
this.discardStageProof(sessionID);
|
|
42530
42604
|
const noteSkippedCleanup = (reason) => {
|
|
@@ -42554,9 +42628,45 @@ class V2RevertMessageCleanup {
|
|
|
42554
42628
|
return noteSkippedCleanup("retained predecessor is not visible at commit");
|
|
42555
42629
|
if (!removed.size)
|
|
42556
42630
|
return noteSkippedCleanup("all staged rows still exist");
|
|
42631
|
+
if (retireHistory) {
|
|
42632
|
+
if (this.pendingHistory.length === MAX_STAGED_REVERTS)
|
|
42633
|
+
this.pendingHistory.shift();
|
|
42634
|
+
this.pendingHistory.push({ sessionID, host: staged.host, removed });
|
|
42635
|
+
}
|
|
42557
42636
|
pruneMessages(db, sessionID, removed);
|
|
42558
42637
|
return true;
|
|
42559
42638
|
}
|
|
42639
|
+
retireProvenHistory(db, sessionID, reader) {
|
|
42640
|
+
const ownProofs = this.pendingHistory.filter((proof) => proof.sessionID === sessionID);
|
|
42641
|
+
if (ownProofs.length === 0)
|
|
42642
|
+
return;
|
|
42643
|
+
const source = reader ?? this.openStoreReader();
|
|
42644
|
+
try {
|
|
42645
|
+
const host = source.hostIdentity();
|
|
42646
|
+
const current = ownProofs.filter((proof) => proof.host === host);
|
|
42647
|
+
this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID || proof.host === host);
|
|
42648
|
+
if (current.length === 0)
|
|
42649
|
+
return;
|
|
42650
|
+
const removed = new Set;
|
|
42651
|
+
for (const proof of current)
|
|
42652
|
+
for (const id of proof.removed)
|
|
42653
|
+
removed.add(id);
|
|
42654
|
+
const result = repairMissingHistoryBoundary({
|
|
42655
|
+
db,
|
|
42656
|
+
sessionId: sessionID,
|
|
42657
|
+
isInHostStore: (id) => source.sequenceForId(sessionID, id) !== undefined,
|
|
42658
|
+
removedByCommittedRevert: removed,
|
|
42659
|
+
onRetire: () => clearRecompStaging(db, sessionID)
|
|
42660
|
+
});
|
|
42661
|
+
if (result.kind !== "unresolved") {
|
|
42662
|
+
this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID);
|
|
42663
|
+
}
|
|
42664
|
+
return result.kind === "intact" ? undefined : result;
|
|
42665
|
+
} finally {
|
|
42666
|
+
if (!reader)
|
|
42667
|
+
source.close();
|
|
42668
|
+
}
|
|
42669
|
+
}
|
|
42560
42670
|
}
|
|
42561
42671
|
function pruneMessages(db, sessionID, removed) {
|
|
42562
42672
|
db.transaction(() => {
|
|
@@ -57517,12 +57627,16 @@ function checkHistoryBoundary(db, reader, sessionID) {
|
|
|
57517
57627
|
}
|
|
57518
57628
|
}
|
|
57519
57629
|
function newBaselineStartAfter(db, reader, sessionID, cached, compactionOff) {
|
|
57520
|
-
if (cached?.id != null
|
|
57630
|
+
if (cached?.id != null)
|
|
57521
57631
|
return;
|
|
57522
57632
|
const isSubagent = storedSubagentMode(db, sessionID);
|
|
57523
57633
|
if (isSubagent === undefined || !rendersCompartmentHistory(isSubagent, compactionOff))
|
|
57524
57634
|
return;
|
|
57635
|
+
if (cached?.hasBytes)
|
|
57636
|
+
return reader.earliestSequence(sessionID) === undefined ? undefined : null;
|
|
57525
57637
|
const newest = db.prepare("SELECT end_message_id AS id, rebase_status AS status FROM compartments WHERE session_id = ? ORDER BY sequence DESC LIMIT 1").get(sessionID);
|
|
57638
|
+
if (!newest && reader.earliestSequence(sessionID) !== undefined)
|
|
57639
|
+
return null;
|
|
57526
57640
|
if (newest?.id && newest.status !== "unresolved" && reader.sequenceForId(sessionID, newest.id) !== undefined)
|
|
57527
57641
|
return newest.id;
|
|
57528
57642
|
return;
|
|
@@ -57540,6 +57654,12 @@ async function cacheV2SessionDirectory(session, sessionID, directories) {
|
|
|
57540
57654
|
}
|
|
57541
57655
|
}
|
|
57542
57656
|
var contextPass = new AsyncLocalStorage2;
|
|
57657
|
+
function noteCheckpointWithoutTail(sessionID, cut, incoming, messageCount) {
|
|
57658
|
+
const pass = contextPass.getStore();
|
|
57659
|
+
if (pass?.sessionID !== sessionID)
|
|
57660
|
+
return;
|
|
57661
|
+
pass.checkpointWithoutTail = cut && incoming && messageCount === 1 && !isCheckpointNote(cut.data.summary) ? cut.id : undefined;
|
|
57662
|
+
}
|
|
57543
57663
|
function withV2ContextPass(sessionID, run) {
|
|
57544
57664
|
const pass = { sessionID, refused: false };
|
|
57545
57665
|
return withSqliteTransformPass2(() => contextPass.run(pass, () => run(pass)));
|
|
@@ -57756,9 +57876,34 @@ async function registerContext(context) {
|
|
|
57756
57876
|
const embeddings = createV2EmbeddingScope(resolveProjectIdentityForSession(directory, config.allow_home_project));
|
|
57757
57877
|
const folds = new FoldOwner(context.storage);
|
|
57758
57878
|
const nativeFoldMemory = compactionOff ? undefined : nativeFoldCache(() => storage.require());
|
|
57879
|
+
const loggedUncoveredCheckpoints = new BoundedSessionMap(1000);
|
|
57759
57880
|
const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader(), context.storage, {
|
|
57760
57881
|
protocol: 3,
|
|
57761
|
-
log: sessionLog2
|
|
57882
|
+
log: sessionLog2,
|
|
57883
|
+
rendersHistory: (sessionID) => {
|
|
57884
|
+
if (rustModeModuleClient)
|
|
57885
|
+
return false;
|
|
57886
|
+
const mode = storedSubagentMode(storage.require(), sessionID);
|
|
57887
|
+
return mode !== undefined && rendersCompartmentHistory(mode, compactionOff);
|
|
57888
|
+
},
|
|
57889
|
+
servesHostCheckpoint: (sessionID, checkpointID) => {
|
|
57890
|
+
const pass = contextPass.getStore();
|
|
57891
|
+
return pass?.sessionID === sessionID && pass.checkpointWithoutTail === checkpointID;
|
|
57892
|
+
},
|
|
57893
|
+
onUncoveredFloor: (sessionID, floor, coverage) => {
|
|
57894
|
+
const pass = contextPass.getStore();
|
|
57895
|
+
if (pass?.sessionID === sessionID && pass.loggedUncoveredFloor)
|
|
57896
|
+
return;
|
|
57897
|
+
if (floor.kind === "checkpoint") {
|
|
57898
|
+
const key = JSON.stringify([sessionID, floor.id]);
|
|
57899
|
+
if (loggedUncoveredCheckpoints.get(key))
|
|
57900
|
+
return;
|
|
57901
|
+
loggedUncoveredCheckpoints.set(key, true);
|
|
57902
|
+
}
|
|
57903
|
+
if (pass?.sessionID === sessionID)
|
|
57904
|
+
pass.loggedUncoveredFloor = true;
|
|
57905
|
+
sessionLog2(sessionID, `v2 restore: ignored ${floor.kind} floor ${floor.id} at seq=${floor.after}; rendered coverage ${coverage.id ?? "none"} ends at seq=${coverage.after}`);
|
|
57906
|
+
}
|
|
57762
57907
|
}) : undefined;
|
|
57763
57908
|
setOutputReserveConfig(config.output_reserve);
|
|
57764
57909
|
const queriedModels = new Set;
|
|
@@ -58363,9 +58508,11 @@ async function registerContext(context) {
|
|
|
58363
58508
|
if (event.type === "session.revert.staged" && db) {
|
|
58364
58509
|
revertMessageCleanup.captureStageProof(sessionID, event.data.revert?.messageID);
|
|
58365
58510
|
}
|
|
58366
|
-
if (event.type === "session.revert.cleared"
|
|
58511
|
+
if (event.type === "session.revert.cleared") {
|
|
58367
58512
|
revertMessageCleanup.discardStageProof(sessionID);
|
|
58368
58513
|
}
|
|
58514
|
+
if (event.type === "session.deleted")
|
|
58515
|
+
revertMessageCleanup.forgetSession(sessionID);
|
|
58369
58516
|
if (event.type === "session.revert.committed") {
|
|
58370
58517
|
dropServedRecord(sessionID, "host_edit");
|
|
58371
58518
|
if (db) {
|
|
@@ -58373,9 +58520,10 @@ async function registerContext(context) {
|
|
|
58373
58520
|
withoutSqliteTransformPass2(() => {
|
|
58374
58521
|
scheduleClearAndReindex(indexDb, sessionID, pagedRead);
|
|
58375
58522
|
try {
|
|
58376
|
-
if (revertMessageCleanup.pruneOnCommit(indexDb, sessionID, event.data?.to)) {
|
|
58523
|
+
if (revertMessageCleanup.pruneOnCommit(indexDb, sessionID, event.data?.to, !compactionOff && !rustModeModuleClient)) {
|
|
58377
58524
|
tagger.cleanup(sessionID);
|
|
58378
58525
|
transform?.invalidateRustWireState(sessionID);
|
|
58526
|
+
revertMessageCleanup.retireProvenHistory(indexDb, sessionID);
|
|
58379
58527
|
}
|
|
58380
58528
|
} catch (error) {
|
|
58381
58529
|
sessionLog2(sessionID, "committed revert message cleanup failed:", error);
|
|
@@ -58673,7 +58821,7 @@ async function registerContext(context) {
|
|
|
58673
58821
|
const nativeFloor = await nativeFoldReplay?.restorationFloor(draft.sessionID, cut, reader, {
|
|
58674
58822
|
allowMissingFloor: newStart !== undefined
|
|
58675
58823
|
});
|
|
58676
|
-
if (newStart && nativeFloor === undefined) {
|
|
58824
|
+
if (newStart !== undefined && nativeFloor === undefined) {
|
|
58677
58825
|
const pass = contextPass.getStore();
|
|
58678
58826
|
if (pass)
|
|
58679
58827
|
pass.recoveredCheckpointID = cut.id;
|
|
@@ -58682,6 +58830,12 @@ async function registerContext(context) {
|
|
|
58682
58830
|
const servedBoundary = boundaryID ? servedBoundaryRow2(reader, draft.sessionID, boundaryID) : null;
|
|
58683
58831
|
const retiredInstructions = await nativeFoldReplay?.instructionRetirement(draft.sessionID, reader) ?? (() => false);
|
|
58684
58832
|
const floor = Math.max(nativeFloor ?? -Infinity, (nativeFoldReplay?.sourceChanged(draft.sessionID) && !rustModeModuleClient ? (reader.earliestSequence(draft.sessionID) ?? 0) - 1 : undefined) ?? (moduleBoundarySeq !== undefined ? moduleBoundarySeq - 1 : undefined) ?? servedBoundary?.seq ?? reader.sequenceForId(draft.sessionID, boundaryID) ?? (reader.earliestSequence(draft.sessionID) ?? 0) - 1);
|
|
58833
|
+
if (nativeFloor === undefined && newStart === null) {
|
|
58834
|
+
const first = reader.page(draft.sessionID, { limit: 1 }).rows[0];
|
|
58835
|
+
if (first?.seq === floor + 1)
|
|
58836
|
+
args.onStartAtFirstRow?.(first.id);
|
|
58837
|
+
sessionLog2(draft.sessionID, `v2 restore: no rendered history boundary; starting at stored row seq=${floor + 1}`);
|
|
58838
|
+
}
|
|
58685
58839
|
const floorRow = !rustModeModuleClient && Number.isFinite(floor) ? reader.range(draft.sessionID, floor - 1, floor).find((row) => row.seq === floor) : undefined;
|
|
58686
58840
|
const boundary = floorRow && hasUnsummarizedBlocks(db, reader, draft.sessionID, floorRow.id) ? floor - 1 : floor;
|
|
58687
58841
|
if (moduleBoundarySeq !== undefined)
|
|
@@ -58910,6 +59064,7 @@ async function registerContext(context) {
|
|
|
58910
59064
|
const incoming = localCut && messages.find((message) => message.id === localCut.id);
|
|
58911
59065
|
if (localCut && !incoming)
|
|
58912
59066
|
return;
|
|
59067
|
+
noteCheckpointWithoutTail(draft.sessionID, localCut, incoming, messages.length);
|
|
58913
59068
|
checkpointAtEntry = incoming || null;
|
|
58914
59069
|
const modeDb = db ?? storage.current();
|
|
58915
59070
|
const subagent = modeDb ? storedSubagentMode(modeDb, draft.sessionID) : undefined;
|
|
@@ -59106,18 +59261,20 @@ async function registerContext(context) {
|
|
|
59106
59261
|
let submitted;
|
|
59107
59262
|
let recordedHead;
|
|
59108
59263
|
let upgradeCheckpointSequence;
|
|
59264
|
+
let restoredFirstRow;
|
|
59109
59265
|
try {
|
|
59110
59266
|
syntheticIDs = await readSyntheticProvenance(reader, draft.messages);
|
|
59111
59267
|
const cut = reader.latestCompaction(draft.sessionID);
|
|
59112
59268
|
if (nativeFoldReplay)
|
|
59113
59269
|
await nativeFoldReplay.observeSource(draft.sessionID, reader);
|
|
59114
|
-
const boundaryRepair = !rustModeModuleClient && db && !compactionOff ? checkHistoryBoundary(db, reader, draft.sessionID) : undefined;
|
|
59270
|
+
const boundaryRepair = !rustModeModuleClient && db && !compactionOff ? revertMessageCleanup.retireProvenHistory(db, draft.sessionID, reader) ?? checkHistoryBoundary(db, reader, draft.sessionID) : undefined;
|
|
59115
59271
|
if (boundaryRepair?.kind === "repaired" || boundaryRepair?.kind === "baseline-reset") {
|
|
59116
59272
|
historyRefreshSessions.add(draft.sessionID);
|
|
59117
59273
|
requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "boundary_repair");
|
|
59118
59274
|
}
|
|
59119
59275
|
const localCut = cut && isLocalCheckpoint(cut) ? cut : undefined;
|
|
59120
59276
|
const incoming = localCut && draft.messages.find((message) => message.id === localCut.id);
|
|
59277
|
+
noteCheckpointWithoutTail(draft.sessionID, localCut, incoming, draft.messages.length);
|
|
59121
59278
|
if (!compactionOff && localCut && !incoming)
|
|
59122
59279
|
throw new Error("The host checkpoint disappeared from the context draft");
|
|
59123
59280
|
checkpointAtEntry = incoming || null;
|
|
@@ -59199,7 +59356,10 @@ async function registerContext(context) {
|
|
|
59199
59356
|
messages: draft.messages,
|
|
59200
59357
|
cut: localCut,
|
|
59201
59358
|
incoming,
|
|
59202
|
-
canRebuild: true
|
|
59359
|
+
canRebuild: true,
|
|
59360
|
+
onStartAtFirstRow: (id) => {
|
|
59361
|
+
restoredFirstRow = id;
|
|
59362
|
+
}
|
|
59203
59363
|
}));
|
|
59204
59364
|
}
|
|
59205
59365
|
instructionRows = new Map(bindKeptInstructionCoordinates(draft.messages, incoming || undefined, reader, draft.sessionID).map((row) => [row.id, row]));
|
|
@@ -59253,14 +59413,30 @@ async function registerContext(context) {
|
|
|
59253
59413
|
})({}, mapped);
|
|
59254
59414
|
mapped.commit();
|
|
59255
59415
|
if (replayHead === undefined && (pass.recoveredCheckpointID || previousRecovery && pass.nativeReplayCheckpointID === previousRecovery.checkpointID)) {
|
|
59416
|
+
let coveredAfterRestore;
|
|
59417
|
+
if (pass.recoveredCheckpointID && restoredFirstRow) {
|
|
59418
|
+
try {
|
|
59419
|
+
const end = db.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id=?").get(draft.sessionID);
|
|
59420
|
+
if (end?.id) {
|
|
59421
|
+
const source = openStoreReader();
|
|
59422
|
+
try {
|
|
59423
|
+
const seq = source.sequenceForId(draft.sessionID, end.id);
|
|
59424
|
+
if (seq !== undefined)
|
|
59425
|
+
coveredAfterRestore = new Set(source.instructionRowsThrough(draft.sessionID, seq).map(({ id }) => id));
|
|
59426
|
+
} finally {
|
|
59427
|
+
source.close();
|
|
59428
|
+
}
|
|
59429
|
+
}
|
|
59430
|
+
} catch {}
|
|
59431
|
+
}
|
|
59256
59432
|
pass.servedInstructionIDs = new Set(mapped.messages.flatMap(({ info, parts }) => {
|
|
59257
|
-
|
|
59433
|
+
const id = hostInstructionRowID(info);
|
|
59434
|
+
if (!id || info.role !== "system" || pass.recoveredCheckpointID && !isCoveredInstructionRow(info) && !coveredAfterRestore?.has(id) || !parts.some((value) => {
|
|
59258
59435
|
const part = value;
|
|
59259
59436
|
return part?.type === "text" && typeof part.text === "string" && part.text.length > 0;
|
|
59260
59437
|
}))
|
|
59261
59438
|
return [];
|
|
59262
|
-
|
|
59263
|
-
return id ? [id] : [];
|
|
59439
|
+
return [id];
|
|
59264
59440
|
}));
|
|
59265
59441
|
}
|
|
59266
59442
|
const checkpointPermission = checkpointPassPermissions.get(draft.sessionID);
|
|
@@ -59308,7 +59484,7 @@ async function registerContext(context) {
|
|
|
59308
59484
|
try {
|
|
59309
59485
|
const state = db && getOrCreateSessionMeta(db, draft.sessionID);
|
|
59310
59486
|
const boundary = db?.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id=?").get(draft.sessionID);
|
|
59311
|
-
await nativeFoldReplay?.capture(draft, nativeMessages, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined);
|
|
59487
|
+
await nativeFoldReplay?.capture(draft, nativeMessages, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined, restoredFirstRow);
|
|
59312
59488
|
} catch (error) {
|
|
59313
59489
|
nativeFoldReplay?.invalidate(draft.sessionID, true);
|
|
59314
59490
|
sessionLog2(draft.sessionID, "v2 host fold: optional capture unavailable", error);
|
|
@@ -59625,6 +59801,7 @@ async function registerContext(context) {
|
|
|
59625
59801
|
await hiddenChildSweep.dispose();
|
|
59626
59802
|
messageTimesCache.clear();
|
|
59627
59803
|
recoveredInstructions.clear();
|
|
59804
|
+
loggedUncoveredCheckpoints.clear();
|
|
59628
59805
|
hostFoldIdle?.dispose();
|
|
59629
59806
|
usageController.abort();
|
|
59630
59807
|
await hiddenCompletionExecutor?.dispose();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SessionContext, V2Context, V2Message } from "../hooks/types";
|
|
2
2
|
import { type StoreRow, type V2StoreReader } from "../store-reader";
|
|
3
3
|
import type { NativeFoldCache } from "./memory-cache";
|
|
4
|
-
import { type ReplayStateV3 } from "./native-replay-v3";
|
|
4
|
+
import { type ReplayFloor, type ReplayStateV3 } from "./native-replay-v3";
|
|
5
5
|
interface SupplyArgs {
|
|
6
6
|
draft: SessionContext;
|
|
7
7
|
reader: V2StoreReader;
|
|
@@ -24,6 +24,10 @@ export declare function copyNativeInput(messages: readonly V2Message[]): V2Messa
|
|
|
24
24
|
export declare function isLocalCheckpoint(row: StoreRow): row is StoreRow<"compaction">;
|
|
25
25
|
export declare function isAdmittedLocalCheckpoint(storage: NativeFoldCache, sessionID: string, cut: StoreRow<"compaction">): boolean;
|
|
26
26
|
export declare function forgetNativeFoldProvenance(storage: V2Context["storage"], sessionID: string, legacyOnly?: boolean): Promise<void>;
|
|
27
|
+
interface FloorCoverage {
|
|
28
|
+
id: string | null;
|
|
29
|
+
after: number;
|
|
30
|
+
}
|
|
27
31
|
/** A disposable per-session row cache. The host owns the session history and
|
|
28
32
|
* every edit and revert to it; this cache only holds copies. Host events
|
|
29
33
|
* invalidate the copies of hidden rows, and visible rows are replaced from each
|
|
@@ -51,6 +55,9 @@ export declare class NativeFoldReplay {
|
|
|
51
55
|
constructor(storage: NativeFoldCache, openReader: (sessionID: string) => V2StoreReader, admissions?: V2Context["storage"] | undefined, options?: {
|
|
52
56
|
protocol?: 2 | 3;
|
|
53
57
|
log?: (sessionID: string, line: string) => void;
|
|
58
|
+
rendersHistory?: (sessionID: string) => boolean;
|
|
59
|
+
servesHostCheckpoint?: (sessionID: string, checkpointID: string) => boolean;
|
|
60
|
+
onUncoveredFloor?: (sessionID: string, floor: ReplayFloor, coverage: FloorCoverage) => void;
|
|
54
61
|
});
|
|
55
62
|
private account;
|
|
56
63
|
observeSource(sessionID: string, reader: V2StoreReader): Promise<void>;
|
|
@@ -74,6 +81,8 @@ export declare class NativeFoldReplay {
|
|
|
74
81
|
prepareManualFold(sessionID: string, reader: V2StoreReader, boundaryID: string | null, summary: string): Promise<ReplayStateV3>;
|
|
75
82
|
private admissionKey;
|
|
76
83
|
private report;
|
|
84
|
+
private historyCoverage;
|
|
85
|
+
private floorCovered;
|
|
77
86
|
private floorState;
|
|
78
87
|
private readV3;
|
|
79
88
|
private readCapturedReplay;
|
|
@@ -126,7 +135,7 @@ export declare class NativeFoldReplay {
|
|
|
126
135
|
capture(draft: SessionContext, native: readonly V2Message[], boundary?: {
|
|
127
136
|
id: string;
|
|
128
137
|
summary: string;
|
|
129
|
-
}): Promise<void>;
|
|
138
|
+
}, restoredFirstRow?: string): Promise<void>;
|
|
130
139
|
canReplay(sessionID: string, _reader: V2StoreReader): Promise<boolean>;
|
|
131
140
|
supply(args: SupplyArgs): Promise<boolean>;
|
|
132
141
|
private supplyHeld;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-replay.d.ts","sourceRoot":"","sources":["../../../src/v2/fold/native-replay.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native-replay.d.ts","sourceRoot":"","sources":["../../../src/v2/fold/native-replay.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAEH,KAAK,QAAQ,EAEb,KAAK,aAAa,EACrB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EAaH,KAAK,WAAW,EAChB,KAAK,aAAa,EAKrB,MAAM,oBAAoB,CAAC;AAyB5B,UAAU,UAAU;IAChB,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,aAAa,CAAC;IACtB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB;;yCAEqC;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE;QAAE,MAAM,E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EAAE,cAAc,CAAC,OAAO,CAAC,GACrC,KAAK,CAAC;IACL,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/D,CAAC,CAyCD;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAElE;AAED,4EAA4E;AAC5E,wBAAgB,yBAAyB,CACrC,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,mBAAmB,GAAG,SAAS,EACvC,iBAAiB,UAAO,GACzB,IAAI,CAsBN;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAqBnE;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,cAAc,GAAG,uBAAuB,CAE7F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,mBAAmB,CACrC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,6BAA6B,CAAC,EAAE,SAAS,CAAC,EAC/E,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC,GACrF,OAAO,CAAC,IAAI,CAAC,CAwCf;AAyBD,wBAAsB,eAAe,CAAC,OAAO,EAAE,SAAS;;eA+sGvD"}
|
|
@@ -3,10 +3,28 @@ import type { V2StoreReader } from "../store-reader";
|
|
|
3
3
|
export declare class V2RevertMessageCleanup {
|
|
4
4
|
private readonly openStoreReader;
|
|
5
5
|
private readonly staged;
|
|
6
|
+
private pendingHistory;
|
|
6
7
|
constructor(openStoreReader: () => V2StoreReader);
|
|
7
8
|
captureStageProof(sessionID: string, cutoff: unknown): void;
|
|
8
9
|
discardStageProof(sessionID: string): void;
|
|
9
10
|
discardAllStageProofs(): void;
|
|
10
|
-
|
|
11
|
+
forgetSession(sessionID: string): void;
|
|
12
|
+
pruneOnCommit(db: Database, sessionID: string, to: unknown, retireHistory: boolean): boolean;
|
|
13
|
+
retireProvenHistory(db: Database, sessionID: string, reader?: V2StoreReader): {
|
|
14
|
+
kind: "unknown";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "repaired";
|
|
17
|
+
missingEndMessageId: string;
|
|
18
|
+
anchorEndMessageId: string;
|
|
19
|
+
droppedSequences: number[];
|
|
20
|
+
} | {
|
|
21
|
+
kind: "baseline-reset";
|
|
22
|
+
anchorEndMessageId: string;
|
|
23
|
+
staleBaselineId: string | null;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "unresolved";
|
|
26
|
+
reason: "no-anchor" | "busy";
|
|
27
|
+
missingEndMessageId: string;
|
|
28
|
+
} | undefined;
|
|
11
29
|
}
|
|
12
30
|
//# sourceMappingURL=revert-message-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revert-message-state.d.ts","sourceRoot":"","sources":["../../../src/v2/hooks/revert-message-state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"revert-message-state.d.ts","sourceRoot":"","sources":["../../../src/v2/hooks/revert-message-state.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAerE,qBAAa,sBAAsB;IAInB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAH5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2D;IAClF,OAAO,CAAC,cAAc,CAAyB;gBAElB,eAAe,EAAE,MAAM,aAAa;IAEjE,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAyB3D,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAI1C,qBAAqB,IAAI,IAAI;IAI7B,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAKtC,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,GAAG,OAAO;IAqC5F,mBAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa;;;;;;;;;;;;;;;;CA8B9E"}
|
package/dist/v2/server.js
CHANGED
|
@@ -7877,7 +7877,7 @@ var require_src2 = __commonJS(function(exports, module) {
|
|
|
7877
7877
|
// package.json
|
|
7878
7878
|
var package_default = {
|
|
7879
7879
|
name: "@cortexkit/opencode-magic-context",
|
|
7880
|
-
version: "0.49.
|
|
7880
|
+
version: "0.49.90",
|
|
7881
7881
|
type: "module",
|
|
7882
7882
|
description: "OpenCode plugin for Magic Context — cross-session memory and context management",
|
|
7883
7883
|
main: "dist/index.js",
|
|
@@ -8198,7 +8198,7 @@ async function setup(context) {
|
|
|
8198
8198
|
if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
|
|
8199
8199
|
log2(`[magic-context] Magic Context storage is at ${storageDir}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
|
|
8200
8200
|
}
|
|
8201
|
-
const { registerContext } = await import("./context-
|
|
8201
|
+
const { registerContext } = await import("./context-satgm752.js");
|
|
8202
8202
|
setHarness2("opencode2");
|
|
8203
8203
|
bindStaleBuildNotice({}, import.meta.url, "opencode2");
|
|
8204
8204
|
const duties = await registerContext(context);
|
package/package.json
CHANGED