@cortexkit/opencode-magic-context 0.49.92 → 0.49.95
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/auto-search-worker.js +4 -4
- package/dist/chunk-embedding-write-worker.js +3 -3
- package/dist/{compartment-chunk-embedding-rp4asvk0.js → compartment-chunk-embedding-4nn3hsw2.js} +2 -2
- package/dist/{context-e8qd2v00.js → context-h9x9m2p3.js} +192 -68
- package/dist/{embedding-backfill-w0yq71q2.js → embedding-backfill-wdrqkw09.js} +6 -6
- package/dist/embedding-worker.js +3 -3
- package/dist/features/magic-context/compartment-storage.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/docs-proposals.d.ts +5 -2
- package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
- package/dist/features/magic-context/history-gap-recovery.d.ts +42 -0
- package/dist/features/magic-context/history-gap-recovery.d.ts.map +1 -0
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-synapse.d.ts +18 -5
- package/dist/features/magic-context/memory/embedding-synapse.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts +3 -0
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/message-visibility.d.ts +10 -0
- package/dist/features/magic-context/message-visibility.d.ts.map +1 -0
- package/dist/features/magic-context/search.d.ts +4 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/session-decision-calibration.d.ts.map +1 -1
- package/dist/features/magic-context/session-project-backfill.d.ts.map +1 -1
- package/dist/features/magic-context/store-generation-rebase.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/history-boundary-repair.d.ts +2 -2
- package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-measured-request.d.ts +1 -0
- package/dist/hooks/magic-context/lkg-measured-request.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts +3 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +1 -0
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts +4 -0
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +1 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts +4 -0
- package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts.map +1 -1
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +2 -0
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-stage-logger.d.ts +6 -0
- package/dist/hooks/magic-context/transform-stage-logger.d.ts.map +1 -1
- package/dist/{index-3f3d548g.js → index-2gewejcz.js} +18 -9
- package/dist/{index-n71006wq.js → index-2v9qpmb3.js} +5 -5
- package/dist/{index-zzhcshdk.js → index-3tmbvn0z.js} +9 -9
- package/dist/{index-f25ha337.js → index-3ywyr4zx.js} +1 -1
- package/dist/{index-hbn5g7rt.js → index-47hst5me.js} +1 -1
- package/dist/{index-xg1zjht5.js → index-7dzaamqg.js} +6 -6
- package/dist/{index-5y9w2ax7.js → index-7r11k4xr.js} +2 -2
- package/dist/{index-5pmf4jpj.js → index-7skgrbsg.js} +100 -52
- package/dist/{index-6rk44cer.js → index-c81tggen.js} +1 -1
- package/dist/{index-0twg41mh.js → index-ejgp0z9p.js} +1 -1
- package/dist/{index-hre29c1a.js → index-esacb9d0.js} +1 -1
- package/dist/{index-5a9kwapd.js → index-ewta5h87.js} +4 -4
- package/dist/{index-6r99v53h.js → index-j7n64sg4.js} +162 -60
- package/dist/{index-r3tdqqtq.js → index-jm62g83a.js} +180 -64
- package/dist/{index-anwy2mfb.js → index-pc49a7zt.js} +162 -31
- package/dist/{index-ydhymf0b.js → index-qmm8xpbc.js} +4 -4
- package/dist/{index-3n376ann.js → index-tedck05r.js} +4 -4
- package/dist/{index-j2w79s9r.js → index-tm799pq7.js} +1 -1
- package/dist/{index-01h7tqe3.js → index-tr4ep2ej.js} +21 -6
- package/dist/{index-wvbg9m0h.js → index-wqwjawer.js} +27 -11
- package/dist/index-xe34pwb6.js +119 -0
- package/dist/{index-xn9efn18.js → index-xjaf9g90.js} +13 -6
- package/dist/{index-6nqz8hsz.js → index-y915t3ey.js} +1 -1
- package/dist/{index-41bma6qs.js → index-yzzxb5e1.js} +2 -2
- package/dist/{index-901exj0f.js → index-zk6gtf43.js} +45 -9
- package/dist/index.js +27 -27
- package/dist/{message-index-bounded-f6fc00ze.js → message-index-bounded-d3x8rhpz.js} +4 -4
- package/dist/migration-worker.js +1 -1
- package/dist/{project-embedding-registry-8je0xg18.js → project-embedding-registry-az68q792.js} +5 -5
- package/dist/raw-ordinal-warmup-worker.js +5 -5
- package/dist/{read-session-chunk-y2ew3630.js → read-session-chunk-70r1snq3.js} +3 -3
- package/dist/{recomp-orchestrator-ggtcvb9g.js → recomp-orchestrator-cn4r2gz6.js} +15 -15
- package/dist/{render-q8c6wrq9.js → render-g45k3gts.js} +10 -10
- package/dist/{search-archive-pz1jf655.js → search-archive-s9t3exc1.js} +9 -7
- package/dist/{search-gjyrwapc.js → search-b0cb342r.js} +13 -13
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/{storage-tags-7raphcw6.js → storage-tags-xvbje7jm.js} +2 -2
- package/dist/{store-yr443ye8.js → store-91kawq9a.js} +2 -2
- package/dist/{store-reader-qbq6q4v0.js → store-reader-dgh3ssxx.js} +1 -1
- package/dist/tools/ctx-expand/search-archive.d.ts +3 -2
- package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-expand/v2-archive-reader.d.ts +2 -0
- package/dist/tools/ctx-expand/v2-archive-reader.d.ts.map +1 -1
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-pmzdd3s2.js → transform-postprocess-phase-r1xhsjrh.js} +16 -16
- package/dist/v2/auto-search-worker.js +4 -4
- package/dist/v2/chunk-embedding-write-worker.js +3 -3
- package/dist/v2/{compartment-chunk-embedding-w7ht0t9v.js → compartment-chunk-embedding-a7ddvz7v.js} +2 -2
- package/dist/v2/{context-qqbpzk1q.js → context-2hssw26q.js} +351 -111
- package/dist/v2/{embedding-backfill-95m72gxa.js → embedding-backfill-gveter8p.js} +6 -6
- package/dist/v2/embedding-worker.js +3 -3
- package/dist/v2/fold/memory-cache.d.ts +2 -0
- package/dist/v2/fold/memory-cache.d.ts.map +1 -1
- package/dist/v2/fold/native-replay.d.ts +22 -5
- 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.map +1 -1
- package/dist/v2/hooks/session-project-backfill.d.ts +2 -1
- package/dist/v2/hooks/session-project-backfill.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-70g28hyg.js → message-index-bounded-tbwrff24.js} +4 -4
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/{project-embedding-registry-fcxf4qht.js → project-embedding-registry-2zeycxek.js} +5 -5
- package/dist/v2/raw-ordinal-warmup-worker.js +5 -5
- package/dist/v2/{read-session-chunk-9rf0n9e6.js → read-session-chunk-cvgsfsgr.js} +3 -3
- package/dist/v2/{recomp-orchestrator-cwghhjc9.js → recomp-orchestrator-k4cj62f2.js} +15 -15
- package/dist/v2/{render-e852zmxz.js → render-ys7a3zks.js} +10 -10
- package/dist/v2/{search-archive-tmn6b5w8.js → search-archive-k2yh0jj3.js} +9 -7
- package/dist/v2/{search-jd3vczhn.js → search-x1cac8t6.js} +12 -12
- package/dist/v2/{server-vsqmkvxc.js → server-00adcfjd.js} +1 -1
- package/dist/v2/{server-rkj44mez.js → server-476anw1w.js} +1 -1
- package/dist/v2/{server-barj0mjz.js → server-5016ccyn.js} +1 -1
- package/dist/v2/{server-72k2r3kt.js → server-6aj72z52.js} +4 -4
- package/dist/v2/{server-7x5a46hf.js → server-6nh36020.js} +70 -61
- package/dist/v2/{server-fj3pekz2.js → server-88pjnecb.js} +1 -1
- package/dist/v2/{server-js2v309w.js → server-bfct1yvb.js} +99 -51
- package/dist/v2/{server-6t3asmx8.js → server-cd93xyyx.js} +162 -31
- package/dist/v2/{server-ysjjcatk.js → server-cvm1qrqc.js} +2 -2
- package/dist/v2/{server-rz6g5xne.js → server-e6xneh68.js} +1 -1
- package/dist/v2/{server-d4trxrj3.js → server-gj259dqy.js} +45 -9
- package/dist/v2/{server-8ps3717t.js → server-prrx17q3.js} +4 -4
- package/dist/v2/{server-7e89a2kf.js → server-qy58c11s.js} +13 -6
- package/dist/v2/{server-9011eteb.js → server-s81b3nct.js} +2 -2
- package/dist/v2/{server-p4g021y5.js → server-s8mk882p.js} +27 -11
- package/dist/v2/{server-mgxqfprb.js → server-srtq37nh.js} +1 -1
- package/dist/v2/{server-bvr9xs8h.js → server-vbr1rdkg.js} +6 -6
- package/dist/v2/{server-vtgeyhq6.js → server-vtkbxzw1.js} +21 -6
- package/dist/v2/{server-ps6zrzwj.js → server-xepfjgv5.js} +162 -60
- package/dist/v2/server-y0pd600x.js +119 -0
- package/dist/v2/{server-b4efn08m.js → server-zc8s06gx.js} +1 -1
- package/dist/v2/server.js +4 -4
- package/dist/v2/{storage-tags-wgsemtw1.js → storage-tags-y20j3jdp.js} +2 -2
- package/dist/v2/{store-enef5jcn.js → store-b95snz31.js} +2 -2
- package/dist/v2/{store-reader-jbaqv1yp.js → store-reader-qt2msa8z.js} +1 -1
- package/dist/v2/store-reader.d.ts +1 -1
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{v2-archive-reader-dm1aeqk2.js → v2-archive-reader-q92kwkr5.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-cke368np.js → wrapup-orchestrator-ydqkxkhj.js} +15 -15
- package/dist/{v2-archive-reader-39ye0d3b.js → v2-archive-reader-x62hsr4c.js} +1 -1
- package/dist/{wrapup-orchestrator-ggnk0r4r.js → wrapup-orchestrator-kt81d6et.js} +16 -16
- package/package.json +1 -1
- package/src/config/schema/magic-context.ts +1 -1
- package/src/shared/storage-file-mutex-review.test.ts +110 -0
- package/src/shared/storage-file-mutex.ts +12 -0
- package/dist/index-52x68mj4.js +0 -58
- package/dist/v2/server-52x68mj4.js +0 -58
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
} from "./index-s32f8y67.js";
|
|
32
32
|
import {
|
|
33
33
|
deleteChunkEmbedBackoffForSession2
|
|
34
|
-
} from "./index-
|
|
34
|
+
} from "./index-ejgp0z9p.js";
|
|
35
35
|
import {
|
|
36
36
|
isPidAlive,
|
|
37
37
|
readProcessStartTime
|
|
@@ -68,7 +68,7 @@ import {
|
|
|
68
68
|
getPendingPiCompactionMarkerState,
|
|
69
69
|
logPiCompactionMarkerClear,
|
|
70
70
|
isPrefixBoundThinkingModel
|
|
71
|
-
} from "./index-
|
|
71
|
+
} from "./index-zk6gtf43.js";
|
|
72
72
|
import {
|
|
73
73
|
withReadOnlySessionDb
|
|
74
74
|
} from "./index-sp5pvs95.js";
|
|
@@ -86,7 +86,7 @@ import {
|
|
|
86
86
|
import {
|
|
87
87
|
gaDatabasePath2,
|
|
88
88
|
V2StoreReader2
|
|
89
|
-
} from "./index-
|
|
89
|
+
} from "./index-tr4ep2ej.js";
|
|
90
90
|
import {
|
|
91
91
|
markHostInstructionRow,
|
|
92
92
|
hostInstructionRowID,
|
|
@@ -240,6 +240,86 @@ function isCompartmentLeaseHeld(db, sessionId, holderId) {
|
|
|
240
240
|
return row != null;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
// src/features/magic-context/history-gap-recovery.ts
|
|
244
|
+
var STATE = `CASE WHEN json_valid(deferred_execute_state)
|
|
245
|
+
AND json_type(deferred_execute_state) = 'object' THEN deferred_execute_state ELSE '{}' END`;
|
|
246
|
+
var PATH = "$.historyGapRecovery";
|
|
247
|
+
var MARK = `json_extract(${STATE}, '${PATH}')`;
|
|
248
|
+
var MARK_ID = `json_extract(${STATE}, '${PATH}.id')`;
|
|
249
|
+
var CHECKED_AT = `json_extract(${STATE}, '${PATH}.checkedAt')`;
|
|
250
|
+
function readSummaryCoverage(db, sessionId) {
|
|
251
|
+
return db.prepare(`SELECT id, sequence, end_message AS endOrdinal, end_message_id AS messageId
|
|
252
|
+
FROM compartments WHERE session_id = ? AND rebase_status != 'unresolved'
|
|
253
|
+
ORDER BY end_message DESC, sequence DESC LIMIT 1`).get(sessionId) ?? null;
|
|
254
|
+
}
|
|
255
|
+
function markHistoryGapAfterCoverageChange(db, sessionId, before, projectionChanged = false) {
|
|
256
|
+
if (!before)
|
|
257
|
+
return false;
|
|
258
|
+
const after = readSummaryCoverage(db, sessionId);
|
|
259
|
+
if (projectionChanged && after && before.messageId && before.messageId === after.messageId) {
|
|
260
|
+
if (before.endOrdinal !== after.endOrdinal) {
|
|
261
|
+
const pending = readHistoryGapMark(db, sessionId);
|
|
262
|
+
if (pending && pending.endOrdinal < before.endOrdinal) {
|
|
263
|
+
clearHistoryGapMark(db, sessionId, pending.id);
|
|
264
|
+
} else if (pending && pending.endOrdinal === before.endOrdinal) {
|
|
265
|
+
db.prepare(`UPDATE session_meta SET deferred_execute_state = json_set(${STATE}, '${PATH}.endOrdinal', ?)
|
|
266
|
+
WHERE session_id = ? AND ${MARK_ID} = ?`).run(after.endOrdinal, sessionId, pending.id);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
if (db.prepare("SELECT 1 FROM compartments WHERE id = ?").get(before.id))
|
|
272
|
+
return false;
|
|
273
|
+
if (after) {
|
|
274
|
+
if (before.messageId && before.messageId === after.messageId)
|
|
275
|
+
return false;
|
|
276
|
+
if (projectionChanged) {
|
|
277
|
+
if (after.sequence > before.sequence)
|
|
278
|
+
return false;
|
|
279
|
+
} else if (after.endOrdinal >= before.endOrdinal)
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
ensureSessionMetaRow(db, sessionId);
|
|
283
|
+
const mark = { id: crypto.randomUUID(), endOrdinal: after?.endOrdinal ?? -1 };
|
|
284
|
+
db.prepare(`UPDATE session_meta SET deferred_execute_state = json_set(${STATE}, '${PATH}', json(?))
|
|
285
|
+
WHERE session_id = ?`).run(JSON.stringify(mark), sessionId);
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
function settleHistoryGapAfterReplacement(db, sessionId, before, published) {
|
|
289
|
+
if (!markHistoryGapAfterCoverageChange(db, sessionId, before) && published) {
|
|
290
|
+
clearPublishedHistoryGapMark(db, sessionId);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function readHistoryGapMark(db, sessionId) {
|
|
294
|
+
const row = db.prepare(`SELECT ${MARK} AS mark FROM session_meta WHERE session_id = ?`).get(sessionId);
|
|
295
|
+
if (typeof row?.mark !== "string" || !row.mark.startsWith("{"))
|
|
296
|
+
return null;
|
|
297
|
+
const mark = JSON.parse(row.mark);
|
|
298
|
+
return typeof mark.id === "string" && Number.isInteger(mark.endOrdinal) ? mark : null;
|
|
299
|
+
}
|
|
300
|
+
function clearHistoryGapMark(db, sessionId, expected) {
|
|
301
|
+
db.prepare(`UPDATE session_meta SET deferred_execute_state = json_remove(${STATE}, '${PATH}')
|
|
302
|
+
WHERE session_id = ? AND ${MARK_ID} = ?`).run(sessionId, expected);
|
|
303
|
+
}
|
|
304
|
+
function clearPublishedHistoryGapMark(db, sessionId) {
|
|
305
|
+
const mark = readHistoryGapMark(db, sessionId);
|
|
306
|
+
if (!mark)
|
|
307
|
+
return;
|
|
308
|
+
const coverage = readSummaryCoverage(db, sessionId);
|
|
309
|
+
if (coverage && coverage.endOrdinal > mark.endOrdinal)
|
|
310
|
+
clearHistoryGapMark(db, sessionId, mark.id);
|
|
311
|
+
}
|
|
312
|
+
function claimHistoryGapCheck(db, sessionId, mark, now, inspectedCount) {
|
|
313
|
+
return db.prepare(`UPDATE session_meta SET deferred_execute_state = json_set(${STATE},
|
|
314
|
+
'${PATH}.checkedAt', ?, '${PATH}.inspectedCount', ?)
|
|
315
|
+
WHERE session_id = ? AND ${MARK_ID} = ? AND ${CHECKED_AT} IS ?`).run(now, inspectedCount, sessionId, mark.id, mark.checkedAt ?? null).changes > 0;
|
|
316
|
+
}
|
|
317
|
+
function recordHistoryGapAdmission(db, sessionId, admission) {
|
|
318
|
+
return db.prepare(`UPDATE session_meta SET deferred_execute_state = json_set(${STATE},
|
|
319
|
+
'${PATH}.admittedRuns', ?, '${PATH}.failureCountAtAdmission', ?)
|
|
320
|
+
WHERE session_id = ? AND ${MARK_ID} = ? AND ${CHECKED_AT} = ?`).run(admission.admittedRuns, admission.failureCount, sessionId, admission.id, admission.checkedAt).changes > 0;
|
|
321
|
+
}
|
|
322
|
+
|
|
243
323
|
// src/features/magic-context/no-content-compartment.ts
|
|
244
324
|
function isNoContentCompartment(row) {
|
|
245
325
|
return [row.title, row.content, row.p1, row.p2, row.p3, row.p4].every((value) => !value);
|
|
@@ -400,6 +480,8 @@ function appendCompartments(db, sessionId, compartments) {
|
|
|
400
480
|
const now = Date.now();
|
|
401
481
|
db.transaction(() => {
|
|
402
482
|
insertCompartmentRows(db, sessionId, compartments, now);
|
|
483
|
+
if (compartments.some((row) => !isNoContentCompartment(row)))
|
|
484
|
+
clearPublishedHistoryGapMark(db, sessionId);
|
|
403
485
|
}).immediate();
|
|
404
486
|
}
|
|
405
487
|
function buildCompartmentBlock(compartments, facts, memoryBlock, dateRanges) {
|
|
@@ -793,6 +875,11 @@ function withStorageFileMutex(directory, work, timeoutMs = 1000) {
|
|
|
793
875
|
writeStorageFileSync(ownPath, encodedTicket(), { flag: "wx", forcePrivate: true });
|
|
794
876
|
break;
|
|
795
877
|
} catch (error) {
|
|
878
|
+
try {
|
|
879
|
+
rmSync(ownPath, { force: true });
|
|
880
|
+
} catch (cleanupError) {
|
|
881
|
+
log2(`[magic-context] storage mutex could not remove its unwritten ticket ${ownPath}: ${String(cleanupError)}`);
|
|
882
|
+
}
|
|
796
883
|
const code = error.code;
|
|
797
884
|
if (code !== "ENOENT" && code !== "EEXIST" && code !== "EINVAL" || performance.now() >= deadline)
|
|
798
885
|
throw error;
|
|
@@ -1093,14 +1180,19 @@ function markLkgRecoveryDirty(args) {
|
|
|
1093
1180
|
});
|
|
1094
1181
|
}
|
|
1095
1182
|
function commitLkgWithRecoveryFence(args) {
|
|
1096
|
-
if (!durableFencesSupported())
|
|
1097
|
-
|
|
1183
|
+
if (!durableFencesSupported()) {
|
|
1184
|
+
const committed = args.commit();
|
|
1185
|
+
if (committed)
|
|
1186
|
+
args.onCommitted?.();
|
|
1187
|
+
return committed;
|
|
1188
|
+
}
|
|
1098
1189
|
const state = known(args.sessionId);
|
|
1099
1190
|
if (state.state === "clean" && !args.requiredRevision && !args.retainDirtyRevision) {
|
|
1100
1191
|
const committed = args.commit();
|
|
1101
1192
|
if (committed) {
|
|
1102
1193
|
observer?.("committed");
|
|
1103
1194
|
remember(args.sessionId, { state: "clean", record: null });
|
|
1195
|
+
args.onCommitted?.();
|
|
1104
1196
|
}
|
|
1105
1197
|
return committed;
|
|
1106
1198
|
}
|
|
@@ -1118,6 +1210,7 @@ function commitLkgWithRecoveryFence(args) {
|
|
|
1118
1210
|
if (!args.commit())
|
|
1119
1211
|
return false;
|
|
1120
1212
|
observer?.("committed");
|
|
1213
|
+
args.onCommitted?.();
|
|
1121
1214
|
const saved = args.load();
|
|
1122
1215
|
if (!saved || representationKey(saved) !== representationKey(args.slot))
|
|
1123
1216
|
throw new LkgRecoveryFenceError("Last-good commit did not match its certificate");
|
|
@@ -1836,7 +1929,7 @@ function noteCapturedLkgRequest(args) {
|
|
|
1836
1929
|
captures.set(args.sessionId, {
|
|
1837
1930
|
request,
|
|
1838
1931
|
slot: identity(args.slot),
|
|
1839
|
-
prefixCount: JSON.parse(args.slot.jsonPrefix).length,
|
|
1932
|
+
prefixCount: args.prefixCount ?? JSON.parse(args.slot.jsonPrefix).length,
|
|
1840
1933
|
envelope: envelope(request.modelKey, args.systemPromptTokens, args.agentName, args.sessionId)
|
|
1841
1934
|
});
|
|
1842
1935
|
}
|
|
@@ -1998,22 +2091,32 @@ function rememberFingerprint(db, sessionId, fingerprint) {
|
|
|
1998
2091
|
}
|
|
1999
2092
|
saved.set(sessionId, fingerprint);
|
|
2000
2093
|
}
|
|
2001
|
-
function
|
|
2002
|
-
return
|
|
2003
|
-
slot.
|
|
2004
|
-
slot.
|
|
2005
|
-
slot.
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2094
|
+
function serializeSlotMetadata(slot) {
|
|
2095
|
+
return {
|
|
2096
|
+
inputIdSeq: JSON.stringify(slot.piOutputEntryIds ? { version: 1, inputIds: slot.inputIdSeq, piOutputEntryIds: slot.piOutputEntryIds } : slot.inputIdSeq),
|
|
2097
|
+
inputContentDigests: JSON.stringify(slot.inputContentDigests),
|
|
2098
|
+
inputContentSignatures: slot.inputContentSignatures ? JSON.stringify(slot.inputContentSignatures) : null
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
2101
|
+
function slotFingerprint(slot, metadata = serializeSlotMetadata(slot)) {
|
|
2102
|
+
return createHash5("sha256").update([
|
|
2103
|
+
JSON.stringify([
|
|
2104
|
+
slot.jsonPrefix,
|
|
2105
|
+
slot.lastInputMessageId,
|
|
2106
|
+
slot.modelKey,
|
|
2107
|
+
slot.providerKey,
|
|
2108
|
+
slot.rowVersion,
|
|
2109
|
+
slot.captureSequence
|
|
2110
|
+
]),
|
|
2111
|
+
metadata.inputIdSeq,
|
|
2112
|
+
metadata.inputContentDigests,
|
|
2113
|
+
metadata.inputContentSignatures ?? "null"
|
|
2114
|
+
].join(`
|
|
2115
|
+
`)).digest("hex");
|
|
2014
2116
|
}
|
|
2015
2117
|
function persistLkgSlot(db, sessionId, slot, publishMetadata) {
|
|
2016
|
-
const
|
|
2118
|
+
const metadata = serializeSlotMetadata(slot);
|
|
2119
|
+
const fingerprint = slotFingerprint(slot, metadata);
|
|
2017
2120
|
if (!publishMetadata && persistedFingerprints.get(db)?.get(sessionId) === fingerprint) {
|
|
2018
2121
|
const durable = loadPersistedLkgSlot(db, sessionId);
|
|
2019
2122
|
if (durable && slotFingerprint(durable) === fingerprint)
|
|
@@ -2021,9 +2124,6 @@ function persistLkgSlot(db, sessionId, slot, publishMetadata) {
|
|
|
2021
2124
|
}
|
|
2022
2125
|
const layout = layoutLkgPrefix(slot.jsonPrefix);
|
|
2023
2126
|
try {
|
|
2024
|
-
const inputIdSeq = JSON.stringify(slot.piOutputEntryIds ? { version: 1, inputIds: slot.inputIdSeq, piOutputEntryIds: slot.piOutputEntryIds } : slot.inputIdSeq);
|
|
2025
|
-
const inputContentDigests = JSON.stringify(slot.inputContentDigests);
|
|
2026
|
-
const inputContentSignatures = slot.inputContentSignatures ? JSON.stringify(slot.inputContentSignatures) : null;
|
|
2027
2127
|
db.transaction(() => {
|
|
2028
2128
|
const storedHashes = new Map;
|
|
2029
2129
|
for (const row of db.prepare("SELECT chunk, hash FROM lkg_slot_chunks WHERE session_id = ?").all(sessionId)) {
|
|
@@ -2055,7 +2155,7 @@ function persistLkgSlot(db, sessionId, slot, publishMetadata) {
|
|
|
2055
2155
|
provider_key = excluded.provider_key,
|
|
2056
2156
|
captured_at = excluded.captured_at,
|
|
2057
2157
|
row_version = excluded.row_version,
|
|
2058
|
-
capture_sequence = excluded.capture_sequence`).run(sessionId, layout.chars, layout.chunks.length, layout.hash, inputIdSeq, inputContentDigests, inputContentSignatures, slot.lastInputMessageId, slot.modelKey, slot.providerKey, slot.capturedAt, slot.rowVersion ?? null, slot.captureSequence ?? null);
|
|
2158
|
+
capture_sequence = excluded.capture_sequence`).run(sessionId, layout.chars, layout.chunks.length, layout.hash, metadata.inputIdSeq, metadata.inputContentDigests, metadata.inputContentSignatures, slot.lastInputMessageId, slot.modelKey, slot.providerKey, slot.capturedAt, slot.rowVersion ?? null, slot.captureSequence ?? null);
|
|
2059
2159
|
publishMetadata?.();
|
|
2060
2160
|
}).immediate();
|
|
2061
2161
|
rememberFingerprint(db, sessionId, fingerprint);
|
|
@@ -2067,11 +2167,12 @@ function persistLkgSlot(db, sessionId, slot, publishMetadata) {
|
|
|
2067
2167
|
}
|
|
2068
2168
|
}
|
|
2069
2169
|
function saveLkgSlotToDb(db, sessionId, slot, publishMetadata, fence = {}) {
|
|
2170
|
+
const { isLoadDeadline, ...publicationFence } = fence;
|
|
2070
2171
|
return commitLkgWithRecoveryFence({
|
|
2071
2172
|
sessionId,
|
|
2072
2173
|
slot,
|
|
2073
|
-
...
|
|
2074
|
-
load: () => loadPersistedLkgSlot(db, sessionId, true),
|
|
2174
|
+
...publicationFence,
|
|
2175
|
+
load: () => loadPersistedLkgSlot(db, sessionId, true, isLoadDeadline),
|
|
2075
2176
|
commit: () => persistLkgSlot(db, sessionId, slot, publishMetadata)
|
|
2076
2177
|
});
|
|
2077
2178
|
}
|
|
@@ -2089,7 +2190,7 @@ function clearPersistedLkgSlotStrict(db, sessionId) {
|
|
|
2089
2190
|
}).immediate());
|
|
2090
2191
|
persistedFingerprints.get(db)?.delete(sessionId);
|
|
2091
2192
|
}
|
|
2092
|
-
function loadPersistedLkgSlot(db, sessionId, forPublication = false) {
|
|
2193
|
+
function loadPersistedLkgSlot(db, sessionId, forPublication = false, isLoadDeadline) {
|
|
2093
2194
|
const rustHost = getHarness2() === "opencode" || getHarness2() === "opencode2";
|
|
2094
2195
|
if (rustHost && !forPublication && isRustMarkerAdmissionFenced(db, sessionId))
|
|
2095
2196
|
return;
|
|
@@ -2104,6 +2205,10 @@ function loadPersistedLkgSlot(db, sessionId, forPublication = false) {
|
|
|
2104
2205
|
return { row: slotRow, chunkRows: slices };
|
|
2105
2206
|
}).deferred());
|
|
2106
2207
|
} catch (error) {
|
|
2208
|
+
if (isLoadDeadline?.(error)) {
|
|
2209
|
+
sessionLog2(sessionId, "LKG snapshot durable load denied by outcome clock:", error);
|
|
2210
|
+
throw error;
|
|
2211
|
+
}
|
|
2107
2212
|
sessionLog2(sessionId, "LKG snapshot durable load failed:", error);
|
|
2108
2213
|
return;
|
|
2109
2214
|
}
|
|
@@ -2468,6 +2573,13 @@ function outputMessageIsPostAnchor(message, inputIndexById, anchorIndex, systemI
|
|
|
2468
2573
|
const linkedIndex = inputIndexById.get(linked);
|
|
2469
2574
|
return linkedIndex === undefined ? null : linkedIndex > anchorIndex;
|
|
2470
2575
|
}
|
|
2576
|
+
function canCountWithoutToJSON(value) {
|
|
2577
|
+
try {
|
|
2578
|
+
return !("toJSON" in value);
|
|
2579
|
+
} catch {
|
|
2580
|
+
return false;
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2471
2583
|
function buildLkgPrefix(input, output, completeOutput = false) {
|
|
2472
2584
|
const projected = asEntryProjection(input);
|
|
2473
2585
|
let anchorIndex = completeOutput && projected.length > 0 ? projected.length - 1 : findLkgAnchor(projected);
|
|
@@ -2517,15 +2629,20 @@ function buildLkgPrefix(input, output, completeOutput = false) {
|
|
|
2517
2629
|
if (inputContentDigests.some((digest) => digest === null))
|
|
2518
2630
|
return null;
|
|
2519
2631
|
const prefix = [];
|
|
2632
|
+
let canCountFromArray = canCountWithoutToJSON(prefix);
|
|
2520
2633
|
for (const message of output) {
|
|
2521
2634
|
const postAnchor = completeOutput ? false : outputMessageIsPostAnchor(message, inputIndexById, anchorIndex, systemIndices);
|
|
2522
2635
|
if (postAnchor === null)
|
|
2523
2636
|
return null;
|
|
2524
2637
|
if (isRetiredInstructionRow(message.info) && messageRole(message) === "system" && messageParts(message).length === 0)
|
|
2525
2638
|
continue;
|
|
2526
|
-
if (!postAnchor)
|
|
2527
|
-
|
|
2639
|
+
if (!postAnchor) {
|
|
2640
|
+
const visible = providerVisibleMessage(message);
|
|
2641
|
+
canCountFromArray &&= canCountWithoutToJSON(visible);
|
|
2642
|
+
prefix.push(visible);
|
|
2643
|
+
}
|
|
2528
2644
|
}
|
|
2645
|
+
canCountFromArray &&= canCountWithoutToJSON(prefix);
|
|
2529
2646
|
let jsonPrefix;
|
|
2530
2647
|
try {
|
|
2531
2648
|
jsonPrefix = JSON.stringify(prefix);
|
|
@@ -2534,12 +2651,14 @@ function buildLkgPrefix(input, output, completeOutput = false) {
|
|
|
2534
2651
|
} catch {
|
|
2535
2652
|
return null;
|
|
2536
2653
|
}
|
|
2654
|
+
canCountFromArray &&= canCountWithoutToJSON(prefix);
|
|
2537
2655
|
return {
|
|
2538
2656
|
anchorIndex,
|
|
2539
2657
|
anchorMessageId,
|
|
2540
2658
|
inputIdSeq: validIds.slice(0, anchorIndex + 1),
|
|
2541
2659
|
inputContentDigests,
|
|
2542
|
-
jsonPrefix
|
|
2660
|
+
jsonPrefix,
|
|
2661
|
+
prefixCount: canCountFromArray ? prefix.length : undefined
|
|
2543
2662
|
};
|
|
2544
2663
|
}
|
|
2545
2664
|
function captureLkgSlot(args) {
|
|
@@ -2561,6 +2680,7 @@ function captureLkgSlot(args) {
|
|
|
2561
2680
|
noteCapturedLkgRequest({
|
|
2562
2681
|
sessionId: args.sessionId,
|
|
2563
2682
|
slot,
|
|
2683
|
+
prefixCount: built.prefixCount,
|
|
2564
2684
|
request: built.anchorIndex === args.input.length - 1 ? claimLkgRequestIdentity(args.sessionId) : undefined,
|
|
2565
2685
|
systemPromptTokens: args.systemPromptTokens ?? 0,
|
|
2566
2686
|
agentName: args.agentName
|
|
@@ -2743,10 +2863,19 @@ function validateLkgSeam(prefix, tail, providerKey) {
|
|
|
2743
2863
|
}
|
|
2744
2864
|
return true;
|
|
2745
2865
|
}
|
|
2866
|
+
function observeReplayStage(onStage, stage) {
|
|
2867
|
+
try {
|
|
2868
|
+
onStage?.(stage);
|
|
2869
|
+
} catch {}
|
|
2870
|
+
}
|
|
2746
2871
|
function replayLkg(args) {
|
|
2872
|
+
if (args.onStage)
|
|
2873
|
+
observeReplayStage(args.onStage, "savedRequestLoad");
|
|
2747
2874
|
const slot = getSlot(args.sessionId);
|
|
2748
2875
|
if (!slot)
|
|
2749
2876
|
return { ok: false, reason: "lkg_invalidated_reshape" };
|
|
2877
|
+
if (args.onStage)
|
|
2878
|
+
observeReplayStage(args.onStage, "identityCheck");
|
|
2750
2879
|
const requestedModelKeys = canonicalLkgModelKeys(args.modelKey, args.providerKey);
|
|
2751
2880
|
const capturedModelKeys = canonicalLkgModelKeys(slot.modelKey, slot.providerKey);
|
|
2752
2881
|
if (capturedModelKeys.modelKey !== requestedModelKeys.modelKey || capturedModelKeys.providerKey !== requestedModelKeys.providerKey) {
|
|
@@ -2762,6 +2891,8 @@ function replayLkg(args) {
|
|
|
2762
2891
|
dropSlot(args.sessionId, "lkg_content_mismatch");
|
|
2763
2892
|
return { ok: false, reason: "lkg_content_mismatch" };
|
|
2764
2893
|
}
|
|
2894
|
+
if (args.onStage)
|
|
2895
|
+
observeReplayStage(args.onStage, "replayRebuild");
|
|
2765
2896
|
let prefix;
|
|
2766
2897
|
try {
|
|
2767
2898
|
const parsed = JSON.parse(slot.jsonPrefix);
|
|
@@ -5221,4 +5352,4 @@ var ERROR_CLASSES = new Set([
|
|
|
5221
5352
|
"permission_denied",
|
|
5222
5353
|
"unknown"
|
|
5223
5354
|
]);
|
|
5224
|
-
export { advanceSessionActivity, observeSessionActivity, backfillSessionActivity, COMPARTMENT_LEASE_RENEWAL_MS, getCompartmentLeaseBlocker, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, isNoContentCompartment, queueM0Mutation, getMaxM0MutationId, getCompartments, getNewestCompartmentIds, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, cachedHistoryCoversLatestCompartment, getCompartmentsByEndMessageId, appendCompartments, buildCompartmentBlock, saveRecompStagingPass, getRecompStaging, clearRecompStaging, getRecompPartialRange, setRecompPartialRange, escapeXmlAttr, escapeXmlContent, getUncoveredCompartmentEndsThrough, isPartialCompartmentEnd, readProjectDocsCanonical, readServerFallbackUsage, providerResponseFailed, isSuccessfulProviderCompletion, LkgRecoveryFenceError, lkgServedArrayDigest, hasCleanLkgRecoveryFence, dirtyLkgRecoveryRevision, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, prepareLkgCaptureFence, certifyCommittedLkgCapture, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, cancelAutoSearchWork, readSessionMeta, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, markSessionCleanupPending, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, clearSession, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, hasExplicitRefreshRequest, clearPendingMaterialization, clearReclaimedMaterialization, clearPendingMaterializationOrigin, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, isHeldHeadForRequest, deferDeliveredSystemRefresh, retirePendingSystemPromptDelivery, lkgProviderInputTotal, beginV2LkgRequest, claimLkgRequestIdentity, currentLkgRequestIdentity, noteCapturedLkgRequest, noteLkgProviderResponse, measuredLkgPrefix, clearLkgMeasuredRequest, saveLkgSlotToDb, clearPersistedLkgSlotStrict, loadPersistedLkgSlot, drainStaleLkgSlots, createDbLkgPersistence, resolveLkgModelKeys, createLkgEntryProjector, captureLkgSlot, validateAnthropicReasoningRuns, validateLkgSeam, replayLkg, coldStartRawServedIndex, coldStartUncapturedReplay, noteUncertifiedNormalLkg, hasProcessLocalLkgProof, lkgDirtyRevision, rememberLkgDirtyRevision, readPersistedLkgUntaggedInputIds, persistLkgUntaggedInputIds, noteLkgRecoveryPrefix, readLkgRecoveryPrefix, noteLkgHealthyPrefix, lkgRecoveryReplayUnproven, lkgRecoveryEntryUnproven, beginServedRequest, noteServedPassPermission, noteServedModel, noteServedReplay, noteServedHostInput, noteServedRefusal, countServedRefusal, dropServedRecord, forgetServedRecord, commitServedRequest, lkgInputIdentity, registerLkgPersistence, beginLkgPass, visitMessageContentFields, contentSnapshotValue, messageContentFields, signatureForFields, exactReusablePrefix, incrementalLkgContentDigests, lkgContentDigest, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, forgetInMemorySlot, dropSlot, noteEntry, getLkgSlotHeapStats, TOOL_SWEEP_SCOPED_MARKER, useScopedToolSweep, createPreAdoptionToolSweepResolver, copySessionStateForClone, externalHistorianFailureReason, getRecentFailedHistorianRunTimes, recordHistorianRun, summarizeImportance, tallyFactsByCategory, MEMORY_VISIBILITY_MUTATION_CATEGORY, queueMemoryMutation, getMemoryMutationsForRender, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationId, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, recordSubagentInvocation, getLatestHistorianInvocationId };
|
|
5355
|
+
export { advanceSessionActivity, observeSessionActivity, backfillSessionActivity, COMPARTMENT_LEASE_RENEWAL_MS, getCompartmentLeaseBlocker, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, readSummaryCoverage, markHistoryGapAfterCoverageChange, settleHistoryGapAfterReplacement, readHistoryGapMark, clearHistoryGapMark, claimHistoryGapCheck, recordHistoryGapAdmission, isNoContentCompartment, queueM0Mutation, getMaxM0MutationId, getCompartments, getNewestCompartmentIds, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, cachedHistoryCoversLatestCompartment, getCompartmentsByEndMessageId, appendCompartments, buildCompartmentBlock, saveRecompStagingPass, getRecompStaging, clearRecompStaging, getRecompPartialRange, setRecompPartialRange, escapeXmlAttr, escapeXmlContent, getUncoveredCompartmentEndsThrough, isPartialCompartmentEnd, readProjectDocsCanonical, readServerFallbackUsage, providerResponseFailed, isSuccessfulProviderCompletion, LkgRecoveryFenceError, lkgServedArrayDigest, hasCleanLkgRecoveryFence, dirtyLkgRecoveryRevision, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, prepareLkgCaptureFence, certifyCommittedLkgCapture, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, cancelAutoSearchWork, readSessionMeta, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, markSessionCleanupPending, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, clearSession, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, hasExplicitRefreshRequest, clearPendingMaterialization, clearReclaimedMaterialization, clearPendingMaterializationOrigin, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, isHeldHeadForRequest, deferDeliveredSystemRefresh, retirePendingSystemPromptDelivery, lkgProviderInputTotal, beginV2LkgRequest, claimLkgRequestIdentity, currentLkgRequestIdentity, noteCapturedLkgRequest, noteLkgProviderResponse, measuredLkgPrefix, clearLkgMeasuredRequest, saveLkgSlotToDb, clearPersistedLkgSlotStrict, loadPersistedLkgSlot, drainStaleLkgSlots, createDbLkgPersistence, resolveLkgModelKeys, createLkgEntryProjector, captureLkgSlot, validateAnthropicReasoningRuns, validateLkgSeam, replayLkg, coldStartRawServedIndex, coldStartUncapturedReplay, noteUncertifiedNormalLkg, hasProcessLocalLkgProof, lkgDirtyRevision, rememberLkgDirtyRevision, readPersistedLkgUntaggedInputIds, persistLkgUntaggedInputIds, noteLkgRecoveryPrefix, readLkgRecoveryPrefix, noteLkgHealthyPrefix, lkgRecoveryReplayUnproven, lkgRecoveryEntryUnproven, beginServedRequest, noteServedPassPermission, noteServedModel, noteServedReplay, noteServedHostInput, noteServedRefusal, countServedRefusal, dropServedRecord, forgetServedRecord, commitServedRequest, lkgInputIdentity, registerLkgPersistence, beginLkgPass, visitMessageContentFields, contentSnapshotValue, messageContentFields, signatureForFields, exactReusablePrefix, incrementalLkgContentDigests, lkgContentDigest, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, forgetInMemorySlot, dropSlot, noteEntry, getLkgSlotHeapStats, TOOL_SWEEP_SCOPED_MARKER, useScopedToolSweep, createPreAdoptionToolSweepResolver, copySessionStateForClone, externalHistorianFailureReason, getRecentFailedHistorianRunTimes, recordHistorianRun, summarizeImportance, tallyFactsByCategory, MEMORY_VISIBILITY_MUTATION_CATEGORY, queueMemoryMutation, getMemoryMutationsForRender, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationId, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, recordSubagentInvocation, getLatestHistorianInvocationId };
|
|
@@ -7,21 +7,21 @@ import {
|
|
|
7
7
|
} from "./index-fr0wbhdn.js";
|
|
8
8
|
import {
|
|
9
9
|
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-y915t3ey.js";
|
|
11
11
|
import {
|
|
12
12
|
sessionLog2
|
|
13
13
|
} from "./index-ywrz4wy2.js";
|
|
14
14
|
import {
|
|
15
15
|
isSynapseEmbeddingTruncated,
|
|
16
16
|
SynapseEmbeddingProvider
|
|
17
|
-
} from "./index-
|
|
17
|
+
} from "./index-j7n64sg4.js";
|
|
18
18
|
import {
|
|
19
19
|
LocalEmbeddingProvider
|
|
20
|
-
} from "./index-
|
|
20
|
+
} from "./index-xjaf9g90.js";
|
|
21
21
|
import {
|
|
22
22
|
OpenAICompatibleEmbeddingProvider,
|
|
23
23
|
embedTextForProject2
|
|
24
|
-
} from "./index-
|
|
24
|
+
} from "./index-tedck05r.js";
|
|
25
25
|
import {
|
|
26
26
|
saveEmbeddingIfHashMatches
|
|
27
27
|
} from "./index-qjwpqvnf.js";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
isSynapseEmbeddingTruncated,
|
|
16
16
|
getSynapseBatchRequestKey,
|
|
17
17
|
SynapseEmbeddingProvider
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-j7n64sg4.js";
|
|
19
19
|
import {
|
|
20
20
|
inRootAsyncContext2,
|
|
21
21
|
getSqliteDatabasePath2
|
|
@@ -43,10 +43,10 @@ import {
|
|
|
43
43
|
countSessionCompartmentEmbedCoverage2,
|
|
44
44
|
countSessionCompartmentEmbedCoveragePolite2,
|
|
45
45
|
countUnembeddedSessionCompartmentsPolite2
|
|
46
|
-
} from "./index-
|
|
46
|
+
} from "./index-ejgp0z9p.js";
|
|
47
47
|
import {
|
|
48
48
|
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
49
|
-
} from "./index-
|
|
49
|
+
} from "./index-y915t3ey.js";
|
|
50
50
|
import {
|
|
51
51
|
embeddingModelsMatch,
|
|
52
52
|
resolveEmbeddingTextPrefixes,
|
|
@@ -56,7 +56,7 @@ import {
|
|
|
56
56
|
getEmbeddingProviderIdentity,
|
|
57
57
|
dominantEmbeddingFailure,
|
|
58
58
|
LocalEmbeddingProvider
|
|
59
|
-
} from "./index-
|
|
59
|
+
} from "./index-xjaf9g90.js";
|
|
60
60
|
import {
|
|
61
61
|
embedPauseBySession,
|
|
62
62
|
activeEmbeddingSessions,
|
|
@@ -122,16 +122,32 @@ function decode(row) {
|
|
|
122
122
|
}
|
|
123
123
|
return { ...row, data };
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function fileIdentity(path) {
|
|
126
126
|
const stat = statSync(path);
|
|
127
|
-
|
|
127
|
+
return `${stat.dev}:${stat.ino}:${stat.birthtimeMs}`;
|
|
128
|
+
}
|
|
129
|
+
function openConfirmed(path, identity) {
|
|
128
130
|
const db = new Database2(path, { readonly: true, fileMustExist: true });
|
|
129
131
|
try {
|
|
130
|
-
|
|
132
|
+
if (fileIdentity(path) === identity) {
|
|
133
|
+
assertOpenCodeStoreGeneration(db, "v2", path);
|
|
134
|
+
return db;
|
|
135
|
+
}
|
|
131
136
|
} catch (error) {
|
|
132
137
|
db.close();
|
|
133
138
|
throw error;
|
|
134
139
|
}
|
|
140
|
+
db.close();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
function connect(path, identity = fileIdentity(path)) {
|
|
144
|
+
let db = openConfirmed(path, identity);
|
|
145
|
+
if (!db) {
|
|
146
|
+
identity = fileIdentity(path);
|
|
147
|
+
db = openConfirmed(path, identity);
|
|
148
|
+
if (!db)
|
|
149
|
+
throw new Error("OpenCode database file changed during reader open");
|
|
150
|
+
}
|
|
135
151
|
const counters = debugCounters();
|
|
136
152
|
counters.openReaders += 1;
|
|
137
153
|
counters.readersOpened += 1;
|
|
@@ -139,7 +155,7 @@ function connect(path, identity = "") {
|
|
|
139
155
|
return {
|
|
140
156
|
db,
|
|
141
157
|
statements: new Map,
|
|
142
|
-
identity
|
|
158
|
+
identity,
|
|
143
159
|
leases: 0,
|
|
144
160
|
retired: false,
|
|
145
161
|
ordinalSequences: new Map
|
|
@@ -175,8 +191,7 @@ class V2StoreReaderPool2 {
|
|
|
175
191
|
if (this.closed)
|
|
176
192
|
throw new Error("Store reader pool is closed");
|
|
177
193
|
const key = resolve(path);
|
|
178
|
-
const
|
|
179
|
-
const identity = `${stat.dev}:${stat.ino}:${stat.birthtimeMs}`;
|
|
194
|
+
const identity = fileIdentity(key);
|
|
180
195
|
let connection = this.connections.get(key);
|
|
181
196
|
if (connection && connection.identity !== identity) {
|
|
182
197
|
this.connections.delete(key);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
withMessageFtsSessionFilter
|
|
3
|
-
|
|
2
|
+
withMessageFtsSessionFilter,
|
|
3
|
+
liveTailRangeTouchesUnresolvedCoverage,
|
|
4
|
+
rangeHasHiddenMessages
|
|
5
|
+
} from "./index-xe34pwb6.js";
|
|
4
6
|
import {
|
|
5
7
|
getSqliteDatabasePath2
|
|
6
8
|
} from "./index-gzy5w8ya.js";
|
|
@@ -19,17 +21,29 @@ import {
|
|
|
19
21
|
rawMessageWorkerSource2,
|
|
20
22
|
rawMessageOffThreadRangeReader2,
|
|
21
23
|
readRawSessionMessageIdOrdinalsForRange2
|
|
22
|
-
} from "./index-
|
|
24
|
+
} from "./index-7r11k4xr.js";
|
|
23
25
|
import {
|
|
24
26
|
readV2ArchiveOffThread2
|
|
25
|
-
} from "./index-
|
|
27
|
+
} from "./index-7dzaamqg.js";
|
|
26
28
|
|
|
27
29
|
// src/tools/ctx-expand/search-archive.ts
|
|
28
30
|
var archiveReadsOnThisThread = 0;
|
|
29
|
-
function
|
|
31
|
+
function liveTailRefusal(start, end, lastCompartmentEnd) {
|
|
32
|
+
return `Range ${start}-${end} is entirely within the live tail (after the last compacted message ${lastCompartmentEnd}); those messages are already visible in context.`;
|
|
33
|
+
}
|
|
34
|
+
function unresolvedLiveTailRefusal2(db, sessionId, start, end, lastCompartmentEnd) {
|
|
35
|
+
return liveTailRangeTouchesUnresolvedCoverage(db, sessionId, start, end, lastCompartmentEnd) ? liveTailRefusal(start, end, lastCompartmentEnd) : null;
|
|
36
|
+
}
|
|
37
|
+
function renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnly = false, readRawIds = () => readRawSessionMessageIdOrdinalsForRange2(sessionId, start, end), liveTailAfter) {
|
|
30
38
|
archiveReadsOnThisThread += 1;
|
|
39
|
+
let rawIds;
|
|
40
|
+
if (liveTailAfter !== undefined) {
|
|
41
|
+
rawIds = readRawIds();
|
|
42
|
+
if (!rangeHasHiddenMessages(db, sessionId, rawIds, liveTailAfter, start, end)) {
|
|
43
|
+
return liveTailRefusal(start, end, liveTailAfter);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
31
46
|
return withMessageFtsSessionFilter(db, sessionId, (sessionFirst) => {
|
|
32
|
-
let rawIds;
|
|
33
47
|
const rows = db.prepare(sessionFirst ? `SELECT f.message_ordinal AS ordinal, f.message_id AS id, f.role, f.content
|
|
34
48
|
FROM message_fts_rowid_map AS m
|
|
35
49
|
JOIN message_history_fts AS f ON f.rowid = m.fts_rowid
|
|
@@ -76,7 +90,7 @@ function renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnl
|
|
|
76
90
|
`);
|
|
77
91
|
});
|
|
78
92
|
}
|
|
79
|
-
async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBudget, archiveOnly = false) {
|
|
93
|
+
async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBudget, archiveOnly = false, liveTailAfter) {
|
|
80
94
|
const path = getSqliteDatabasePath2(db);
|
|
81
95
|
const provider = hasRawMessageProvider2(sessionId);
|
|
82
96
|
const source = rawMessageWorkerSource2(sessionId);
|
|
@@ -92,7 +106,7 @@ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBud
|
|
|
92
106
|
if (!path) {
|
|
93
107
|
return renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnly, rawIds ? () => rawIds : provider ? () => {
|
|
94
108
|
throw new Error("Search archive worker unavailable: private archive has no off-thread source");
|
|
95
|
-
} : undefined);
|
|
109
|
+
} : undefined, liveTailAfter);
|
|
96
110
|
}
|
|
97
111
|
if (!archiveOnly && source) {
|
|
98
112
|
return readV2ArchiveOffThread2(path, source.path, sessionId, {
|
|
@@ -100,7 +114,8 @@ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBud
|
|
|
100
114
|
start,
|
|
101
115
|
end,
|
|
102
116
|
tokenBudget,
|
|
103
|
-
archiveOnly
|
|
117
|
+
archiveOnly,
|
|
118
|
+
liveTailAfter
|
|
104
119
|
});
|
|
105
120
|
}
|
|
106
121
|
if (!archiveOnly && provider && !rawIds) {
|
|
@@ -116,7 +131,8 @@ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBud
|
|
|
116
131
|
tokenBudget,
|
|
117
132
|
archiveOnly,
|
|
118
133
|
rawPath,
|
|
119
|
-
rawIds: rawIds ? [...rawIds] : undefined
|
|
134
|
+
rawIds: rawIds ? [...rawIds] : undefined,
|
|
135
|
+
liveTailAfter
|
|
120
136
|
}
|
|
121
137
|
}, {});
|
|
122
138
|
if ("searchArchive" in result)
|
|
@@ -124,4 +140,4 @@ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBud
|
|
|
124
140
|
throw new Error(`Search archive worker unavailable: ${"failure" in result ? `${result.failure}: ${result.detail}` : "unexpected reply"}`);
|
|
125
141
|
}
|
|
126
142
|
|
|
127
|
-
export { renderSearchArchive2, renderSearchArchiveOffThread2 };
|
|
143
|
+
export { unresolvedLiveTailRefusal2, renderSearchArchive2, renderSearchArchiveOffThread2 };
|