@cortexkit/opencode-magic-context 0.49.93 → 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-jpxthqxg.js → context-h9x9m2p3.js} +176 -61
- package/dist/{embedding-backfill-6wzc4p2n.js → embedding-backfill-wdrqkw09.js} +5 -5
- package/dist/embedding-worker.js +2 -2
- 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-synapse.d.ts +18 -5
- package/dist/features/magic-context/memory/embedding-synapse.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/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-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 +3 -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-za1yx1m4.js → index-2gewejcz.js} +17 -8
- package/dist/{index-hee64h6k.js → index-2v9qpmb3.js} +5 -5
- package/dist/{index-g5c67kay.js → index-3tmbvn0z.js} +8 -8
- package/dist/{index-5zrzg8r1.js → index-3ywyr4zx.js} +1 -1
- package/dist/{index-kty5k23y.js → index-47hst5me.js} +1 -1
- package/dist/{index-g6y2wk32.js → index-7dzaamqg.js} +6 -6
- package/dist/{index-dr6bd4c8.js → index-7r11k4xr.js} +1 -1
- package/dist/{index-g9qtxv87.js → index-7skgrbsg.js} +100 -52
- package/dist/{index-gqfy38m9.js → index-c81tggen.js} +1 -1
- package/dist/{index-0twg41mh.js → index-ejgp0z9p.js} +1 -1
- package/dist/{index-pnawfv4e.js → index-esacb9d0.js} +1 -1
- package/dist/{index-1kem0xxx.js → index-ewta5h87.js} +4 -4
- package/dist/{index-6r99v53h.js → index-j7n64sg4.js} +162 -60
- package/dist/{index-y2vshk67.js → index-jm62g83a.js} +177 -59
- package/dist/{index-yqha238s.js → index-pc49a7zt.js} +119 -9
- package/dist/{index-ttdk2w0z.js → index-qmm8xpbc.js} +3 -3
- package/dist/{index-n9kd68vc.js → index-tedck05r.js} +3 -3
- package/dist/{index-j2w79s9r.js → index-tm799pq7.js} +1 -1
- package/dist/{index-01h7tqe3.js → index-tr4ep2ej.js} +21 -6
- package/dist/{index-rz47hf2m.js → index-wqwjawer.js} +27 -11
- package/dist/index-xe34pwb6.js +119 -0
- package/dist/{index-hes3k87g.js → index-xjaf9g90.js} +1 -1
- package/dist/{index-fpjnjxyx.js → index-yzzxb5e1.js} +2 -2
- package/dist/{index-xr1t0fxb.js → index-zk6gtf43.js} +44 -8
- package/dist/index.js +26 -26
- package/dist/{message-index-bounded-vjrnptar.js → message-index-bounded-d3x8rhpz.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/{project-embedding-registry-m8zcmrsg.js → project-embedding-registry-az68q792.js} +4 -4
- package/dist/raw-ordinal-warmup-worker.js +5 -5
- package/dist/{read-session-chunk-zkzdc0e5.js → read-session-chunk-70r1snq3.js} +2 -2
- package/dist/{recomp-orchestrator-qb2hymj5.js → recomp-orchestrator-cn4r2gz6.js} +14 -14
- package/dist/{render-34p0kek8.js → render-g45k3gts.js} +9 -9
- package/dist/{search-archive-08ppk0q5.js → search-archive-s9t3exc1.js} +8 -6
- package/dist/{search-e9bb9hpx.js → search-b0cb342r.js} +12 -12
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/{storage-tags-gk7gjkqt.js → storage-tags-xvbje7jm.js} +1 -1
- 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-neds90e3.js → transform-postprocess-phase-r1xhsjrh.js} +15 -15
- 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-ctsd80vc.js → context-2hssw26q.js} +332 -99
- package/dist/v2/{embedding-backfill-40g0anxh.js → embedding-backfill-gveter8p.js} +5 -5
- package/dist/v2/embedding-worker.js +2 -2
- 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-1vew9c37.js → message-index-bounded-tbwrff24.js} +3 -3
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/{project-embedding-registry-je5jam7y.js → project-embedding-registry-2zeycxek.js} +4 -4
- package/dist/v2/raw-ordinal-warmup-worker.js +5 -5
- package/dist/v2/{read-session-chunk-09sre4xv.js → read-session-chunk-cvgsfsgr.js} +2 -2
- package/dist/v2/{recomp-orchestrator-mgcty3we.js → recomp-orchestrator-k4cj62f2.js} +13 -13
- package/dist/v2/{render-ygcmyn9x.js → render-ys7a3zks.js} +9 -9
- package/dist/v2/{search-archive-nrsqqmk5.js → search-archive-k2yh0jj3.js} +8 -6
- package/dist/v2/{search-gmye6n25.js → search-x1cac8t6.js} +11 -11
- 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-pcarsvj2.js → server-6aj72z52.js} +3 -3
- package/dist/v2/{server-cvp9w5gs.js → server-6nh36020.js} +68 -59
- package/dist/v2/{server-btgnkr9z.js → server-88pjnecb.js} +1 -1
- package/dist/v2/{server-myp4pc6x.js → server-bfct1yvb.js} +99 -51
- package/dist/v2/{server-4ecpanyn.js → server-cd93xyyx.js} +119 -9
- package/dist/v2/{server-6x40bnb7.js → server-cvm1qrqc.js} +2 -2
- package/dist/v2/{server-z9czv2vb.js → server-gj259dqy.js} +44 -8
- package/dist/v2/{server-vc5fta6s.js → server-prrx17q3.js} +3 -3
- package/dist/v2/{server-6chcnnhq.js → server-qy58c11s.js} +1 -1
- package/dist/v2/{server-dgsjamm4.js → server-s81b3nct.js} +1 -1
- package/dist/v2/{server-g53asaqt.js → server-s8mk882p.js} +27 -11
- package/dist/v2/{server-2xm0gxke.js → server-srtq37nh.js} +1 -1
- package/dist/v2/{server-bnkc9kph.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-k1xc2bw1.js → server-zc8s06gx.js} +1 -1
- package/dist/v2/server.js +2 -2
- package/dist/v2/{storage-tags-nccqr0kr.js → storage-tags-y20j3jdp.js} +1 -1
- 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-7vmng8q7.js → v2-archive-reader-q92kwkr5.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-7r4y0bf6.js → wrapup-orchestrator-ydqkxkhj.js} +13 -13
- package/dist/{v2-archive-reader-7s90gfax.js → v2-archive-reader-x62hsr4c.js} +1 -1
- package/dist/{wrapup-orchestrator-m2p89973.js → wrapup-orchestrator-kt81d6et.js} +15 -15
- package/package.json +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");
|
|
@@ -2074,11 +2167,12 @@ function persistLkgSlot(db, sessionId, slot, publishMetadata) {
|
|
|
2074
2167
|
}
|
|
2075
2168
|
}
|
|
2076
2169
|
function saveLkgSlotToDb(db, sessionId, slot, publishMetadata, fence = {}) {
|
|
2170
|
+
const { isLoadDeadline, ...publicationFence } = fence;
|
|
2077
2171
|
return commitLkgWithRecoveryFence({
|
|
2078
2172
|
sessionId,
|
|
2079
2173
|
slot,
|
|
2080
|
-
...
|
|
2081
|
-
load: () => loadPersistedLkgSlot(db, sessionId, true),
|
|
2174
|
+
...publicationFence,
|
|
2175
|
+
load: () => loadPersistedLkgSlot(db, sessionId, true, isLoadDeadline),
|
|
2082
2176
|
commit: () => persistLkgSlot(db, sessionId, slot, publishMetadata)
|
|
2083
2177
|
});
|
|
2084
2178
|
}
|
|
@@ -2096,7 +2190,7 @@ function clearPersistedLkgSlotStrict(db, sessionId) {
|
|
|
2096
2190
|
}).immediate());
|
|
2097
2191
|
persistedFingerprints.get(db)?.delete(sessionId);
|
|
2098
2192
|
}
|
|
2099
|
-
function loadPersistedLkgSlot(db, sessionId, forPublication = false) {
|
|
2193
|
+
function loadPersistedLkgSlot(db, sessionId, forPublication = false, isLoadDeadline) {
|
|
2100
2194
|
const rustHost = getHarness2() === "opencode" || getHarness2() === "opencode2";
|
|
2101
2195
|
if (rustHost && !forPublication && isRustMarkerAdmissionFenced(db, sessionId))
|
|
2102
2196
|
return;
|
|
@@ -2111,6 +2205,10 @@ function loadPersistedLkgSlot(db, sessionId, forPublication = false) {
|
|
|
2111
2205
|
return { row: slotRow, chunkRows: slices };
|
|
2112
2206
|
}).deferred());
|
|
2113
2207
|
} catch (error) {
|
|
2208
|
+
if (isLoadDeadline?.(error)) {
|
|
2209
|
+
sessionLog2(sessionId, "LKG snapshot durable load denied by outcome clock:", error);
|
|
2210
|
+
throw error;
|
|
2211
|
+
}
|
|
2114
2212
|
sessionLog2(sessionId, "LKG snapshot durable load failed:", error);
|
|
2115
2213
|
return;
|
|
2116
2214
|
}
|
|
@@ -2544,6 +2642,7 @@ function buildLkgPrefix(input, output, completeOutput = false) {
|
|
|
2544
2642
|
prefix.push(visible);
|
|
2545
2643
|
}
|
|
2546
2644
|
}
|
|
2645
|
+
canCountFromArray &&= canCountWithoutToJSON(prefix);
|
|
2547
2646
|
let jsonPrefix;
|
|
2548
2647
|
try {
|
|
2549
2648
|
jsonPrefix = JSON.stringify(prefix);
|
|
@@ -2764,10 +2863,19 @@ function validateLkgSeam(prefix, tail, providerKey) {
|
|
|
2764
2863
|
}
|
|
2765
2864
|
return true;
|
|
2766
2865
|
}
|
|
2866
|
+
function observeReplayStage(onStage, stage) {
|
|
2867
|
+
try {
|
|
2868
|
+
onStage?.(stage);
|
|
2869
|
+
} catch {}
|
|
2870
|
+
}
|
|
2767
2871
|
function replayLkg(args) {
|
|
2872
|
+
if (args.onStage)
|
|
2873
|
+
observeReplayStage(args.onStage, "savedRequestLoad");
|
|
2768
2874
|
const slot = getSlot(args.sessionId);
|
|
2769
2875
|
if (!slot)
|
|
2770
2876
|
return { ok: false, reason: "lkg_invalidated_reshape" };
|
|
2877
|
+
if (args.onStage)
|
|
2878
|
+
observeReplayStage(args.onStage, "identityCheck");
|
|
2771
2879
|
const requestedModelKeys = canonicalLkgModelKeys(args.modelKey, args.providerKey);
|
|
2772
2880
|
const capturedModelKeys = canonicalLkgModelKeys(slot.modelKey, slot.providerKey);
|
|
2773
2881
|
if (capturedModelKeys.modelKey !== requestedModelKeys.modelKey || capturedModelKeys.providerKey !== requestedModelKeys.providerKey) {
|
|
@@ -2783,6 +2891,8 @@ function replayLkg(args) {
|
|
|
2783
2891
|
dropSlot(args.sessionId, "lkg_content_mismatch");
|
|
2784
2892
|
return { ok: false, reason: "lkg_content_mismatch" };
|
|
2785
2893
|
}
|
|
2894
|
+
if (args.onStage)
|
|
2895
|
+
observeReplayStage(args.onStage, "replayRebuild");
|
|
2786
2896
|
let prefix;
|
|
2787
2897
|
try {
|
|
2788
2898
|
const parsed = JSON.parse(slot.jsonPrefix);
|
|
@@ -5242,4 +5352,4 @@ var ERROR_CLASSES = new Set([
|
|
|
5242
5352
|
"permission_denied",
|
|
5243
5353
|
"unknown"
|
|
5244
5354
|
]);
|
|
5245
|
-
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 };
|
|
@@ -14,14 +14,14 @@ import {
|
|
|
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,7 +43,7 @@ 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
49
|
} from "./index-y915t3ey.js";
|
|
@@ -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 };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TEXT_TAG_IDENTITY_MARKER
|
|
3
|
+
} from "./index-zk6gtf43.js";
|
|
4
|
+
|
|
5
|
+
// src/features/magic-context/message-fts-session-filter.ts
|
|
6
|
+
var MESSAGE_FTS_SESSION_FILTER_SQL = `+message_history_fts.rowid IN (
|
|
7
|
+
SELECT fts_rowid FROM message_fts_rowid_map WHERE session_id = ?
|
|
8
|
+
) AND `;
|
|
9
|
+
var coverageCaches = new WeakMap;
|
|
10
|
+
var coverageScansOnThisThread = 0;
|
|
11
|
+
function getCoverageCache(db) {
|
|
12
|
+
let cache = coverageCaches.get(db);
|
|
13
|
+
if (!cache) {
|
|
14
|
+
cache = {
|
|
15
|
+
pin: db.prepare("SELECT fts_rowid FROM message_fts_rowid_map LIMIT 1"),
|
|
16
|
+
stamp: db.prepare("SELECT total_changes() AS changes, data_version AS version FROM pragma_data_version"),
|
|
17
|
+
missing: db.prepare(`SELECT DISTINCT session_id AS sessionId
|
|
18
|
+
FROM message_history_fts WHERE rowid IN (
|
|
19
|
+
SELECT id FROM message_history_fts_docsize
|
|
20
|
+
EXCEPT SELECT fts_rowid FROM message_fts_rowid_map
|
|
21
|
+
)`)
|
|
22
|
+
};
|
|
23
|
+
coverageCaches.set(db, cache);
|
|
24
|
+
}
|
|
25
|
+
return cache;
|
|
26
|
+
}
|
|
27
|
+
function withMessageFtsSessionFilter(db, sessionId, read) {
|
|
28
|
+
let cacheable = false;
|
|
29
|
+
try {
|
|
30
|
+
const transaction = db;
|
|
31
|
+
cacheable = transaction.inTransaction === false || transaction.isTransaction === false;
|
|
32
|
+
if (!cacheable)
|
|
33
|
+
coverageCaches.delete(db);
|
|
34
|
+
} catch {
|
|
35
|
+
coverageCaches.delete(db);
|
|
36
|
+
}
|
|
37
|
+
return db.transaction(() => {
|
|
38
|
+
let sessionFirst = false;
|
|
39
|
+
try {
|
|
40
|
+
const cache = getCoverageCache(db);
|
|
41
|
+
cache.pin.get();
|
|
42
|
+
const stamp = cache.stamp.get();
|
|
43
|
+
let incomplete = cache.incompleteSessions;
|
|
44
|
+
if (!cacheable || !incomplete || cache.version !== stamp.version || cache.changes !== stamp.changes) {
|
|
45
|
+
coverageScansOnThisThread += 1;
|
|
46
|
+
const rows = cache.missing.all();
|
|
47
|
+
incomplete = new Set(rows.map((row) => row.sessionId));
|
|
48
|
+
if (cacheable) {
|
|
49
|
+
cache.version = stamp.version;
|
|
50
|
+
cache.changes = stamp.changes;
|
|
51
|
+
cache.incompleteSessions = incomplete;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
sessionFirst = !incomplete.has(sessionId);
|
|
55
|
+
} catch {
|
|
56
|
+
coverageCaches.delete(db);
|
|
57
|
+
}
|
|
58
|
+
return read(sessionFirst);
|
|
59
|
+
}).deferred();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/features/magic-context/message-visibility.ts
|
|
63
|
+
function partDropSql(session, id, prefix, type, validSuffix) {
|
|
64
|
+
const next = prefix.slice(0, -1) + String.fromCharCode(prefix.charCodeAt(prefix.length - 1) + 1);
|
|
65
|
+
const suffix = `substr(t.message_id, length(${id}) + ${prefix.length + 1})`;
|
|
66
|
+
return `EXISTS (SELECT 1 FROM tags AS t INDEXED BY idx_tags_session_message_id
|
|
67
|
+
WHERE t.session_id = ${session} AND t.message_id >= ${id} || '${prefix}'
|
|
68
|
+
AND t.message_id < ${id} || '${next}' AND t.type = '${type}' AND t.status = 'dropped'
|
|
69
|
+
AND (${validSuffix(suffix)}))`;
|
|
70
|
+
}
|
|
71
|
+
var numericSuffix = (suffix) => `${suffix} <> '' AND ${suffix} NOT GLOB '*[^0-9]*'`;
|
|
72
|
+
function textDropSql(session, id) {
|
|
73
|
+
return `EXISTS (SELECT 1 FROM tags AS t INDEXED BY idx_tags_session_message_id
|
|
74
|
+
WHERE t.session_id = ${session} AND t.message_id = ${id} AND t.status = 'dropped'
|
|
75
|
+
AND t.type = 'message')
|
|
76
|
+
OR ${partDropSql(session, id, ":p", "message", numericSuffix)}
|
|
77
|
+
OR ${partDropSql(session, id, TEXT_TAG_IDENTITY_MARKER, "message", (suffix) => `${suffix} GLOB '[0-9a-f]*:[0-9a-f]*:o[0-9]*' AND ${suffix} NOT GLOB '*[^0-9a-f:o]*'
|
|
78
|
+
AND length(${suffix}) - length(replace(${suffix}, ':', '')) = 2`)}`;
|
|
79
|
+
}
|
|
80
|
+
function unresolvedCoverageSql(session, start, end) {
|
|
81
|
+
return `EXISTS (SELECT 1 FROM compartments AS unresolved
|
|
82
|
+
WHERE unresolved.session_id = ${session} AND unresolved.rebase_status = 'unresolved'
|
|
83
|
+
AND unresolved.start_message <= ${end} AND unresolved.end_message >= ${start})`;
|
|
84
|
+
}
|
|
85
|
+
function visibleSql(session, ordinal, lastSummaryEnd, dropped) {
|
|
86
|
+
return `CASE WHEN ${ordinal} <= ${lastSummaryEnd} THEN 0
|
|
87
|
+
WHEN ${unresolvedCoverageSql(session, ordinal, ordinal)} THEN 1 ELSE NOT (${dropped}) END`;
|
|
88
|
+
}
|
|
89
|
+
function liveTailRangeTouchesUnresolvedCoverage(db, sessionId, start, end, lastSummaryEnd) {
|
|
90
|
+
if (lastSummaryEnd < 0 || start <= lastSummaryEnd)
|
|
91
|
+
return false;
|
|
92
|
+
return !!db.prepare(`SELECT 1 WHERE ${unresolvedCoverageSql("?", "?", "?")}`).get(sessionId, end, start);
|
|
93
|
+
}
|
|
94
|
+
function messageTextVisibleInRequestSql(session, id, ordinal, lastSummaryEnd) {
|
|
95
|
+
return visibleSql(session, ordinal, lastSummaryEnd, textDropSql(session, id));
|
|
96
|
+
}
|
|
97
|
+
function messageVisibleInRequestSql(session, id, ordinal, lastSummaryEnd) {
|
|
98
|
+
return visibleSql(session, ordinal, lastSummaryEnd, `${textDropSql(session, id)}
|
|
99
|
+
OR ${partDropSql(session, id, ":file", "file", numericSuffix)}
|
|
100
|
+
OR EXISTS (SELECT 1 FROM tags AS t INDEXED BY idx_tags_pi_fallback_tool_owner
|
|
101
|
+
WHERE t.session_id = ${session} AND t.tool_owner_message_id = ${id}
|
|
102
|
+
AND t.type = 'tool' AND t.status = 'dropped')`);
|
|
103
|
+
}
|
|
104
|
+
function rangeHasHiddenMessages(db, sessionId, candidates, lastSummaryEnd, start, end) {
|
|
105
|
+
return !!db.prepare(`
|
|
106
|
+
WITH range(sessionId, start, end) AS (VALUES (?, ?, ?)), candidates(id, ordinal) AS (
|
|
107
|
+
SELECT json_extract(value, '$[0]'), json_extract(value, '$[1]') FROM json_each(?)
|
|
108
|
+
UNION
|
|
109
|
+
SELECT message_id, message_ordinal FROM range CROSS JOIN message_history_source
|
|
110
|
+
INDEXED BY idx_message_history_source_session_ordinal
|
|
111
|
+
WHERE session_id = range.sessionId AND message_ordinal BETWEEN range.start AND range.end
|
|
112
|
+
)
|
|
113
|
+
SELECT 1 FROM range CROSS JOIN candidates
|
|
114
|
+
WHERE NOT (${messageVisibleInRequestSql("range.sessionId", "candidates.id", "candidates.ordinal", "?")})
|
|
115
|
+
LIMIT 1
|
|
116
|
+
`).get(sessionId, start, end, JSON.stringify([...candidates]), lastSummaryEnd);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { MESSAGE_FTS_SESSION_FILTER_SQL, withMessageFtsSessionFilter, liveTailRangeTouchesUnresolvedCoverage, messageTextVisibleInRequestSql, rangeHasHiddenMessages };
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
} from "./index-s7460efs.js";
|
|
4
4
|
import {
|
|
5
5
|
getTagById2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-zk6gtf43.js";
|
|
7
7
|
import {
|
|
8
8
|
expandToolPart,
|
|
9
9
|
visitRawSessionMessages2,
|
|
10
10
|
readRawSessionMessageById2
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-7r11k4xr.js";
|
|
12
12
|
|
|
13
13
|
// src/tools/ctx-expand/render.ts
|
|
14
14
|
import { createHash } from "node:crypto";
|