@cortexkit/opencode-magic-context 0.49.2 → 0.49.3
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/README.md +2 -38
- package/dist/auto-search-worker.js +3 -3
- package/dist/compaction-marker-candidates-dd638ypn.js +19 -0
- package/dist/compaction-marker-candidates-worker.js +24 -0
- package/dist/{conflict-warning-hook-asnt6hfc.js → conflict-warning-hook-ae8nmv7c.js} +5 -4
- package/dist/{context-tfyhtdcs.js → context-9tbxh883.js} +63 -29
- package/dist/{embedding-backfill-wyc3ykyf.js → embedding-backfill-aj488s8x.js} +5 -5
- package/dist/features/magic-context/compaction-marker-candidates-worker.d.ts +2 -0
- package/dist/features/magic-context/compaction-marker-candidates-worker.d.ts.map +1 -0
- package/dist/features/magic-context/compaction-marker-candidates.d.ts +47 -0
- package/dist/features/magic-context/compaction-marker-candidates.d.ts.map +1 -0
- package/dist/features/magic-context/compaction-marker.d.ts +12 -0
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/memory/project-identity.d.ts +5 -1
- package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
- package/dist/features/magic-context/message-index-async.d.ts +3 -0
- package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/storage-clone.d.ts +2 -0
- package/dist/features/magic-context/storage-clone.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +1 -1
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts +3 -0
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/history-boundary-repair.d.ts +11 -2
- package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +4 -3
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +10 -0
- package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/{index-sfhndpcb.js → index-3wckxwfp.js} +39 -39
- package/dist/{index-gzky5rva.js → index-41gqa557.js} +4 -2
- package/dist/{index-r2zcs71c.js → index-7ndnvw7a.js} +1 -1
- package/dist/{index-sv0bb7vg.js → index-7zg9dvx0.js} +35 -4
- package/dist/{index-xgrwmj82.js → index-bhk710rw.js} +1 -1
- package/dist/{index-fg00p1cg.js → index-c0b01zrc.js} +2 -2
- package/dist/{index-rafsaxac.js → index-fjtgekd4.js} +2 -2
- package/dist/{index-fdtkt5r1.js → index-fst3t0d9.js} +9 -9
- package/dist/{index-6tfxmc4n.js → index-je2na55n.js} +4 -4
- package/dist/{index-h5zfkjyk.js → index-jpm52v9x.js} +6 -24
- package/dist/{index-s7fc0fkn.js → index-m4p77myp.js} +1 -1
- package/dist/{index-xnanvj3w.js → index-mgy5dwcw.js} +607 -579
- package/dist/{index-0pjvpfkf.js → index-qvr78ej6.js} +1 -1
- package/dist/{index-zfzdpeq2.js → index-s4ztdn8v.js} +1311 -1271
- package/dist/index-v0p37hm2.js +22 -0
- package/dist/{index-eypn4ba6.js → index-w9pe0nx1.js} +3 -3
- package/dist/{index-p0n5ryq8.js → index-ws3gcy5m.js} +19 -9
- package/dist/{index-att4bfan.js → index-xfbfrngb.js} +1 -1
- package/dist/{index-nydv6g8r.js → index-yqps2zsv.js} +44 -6
- package/dist/index-yxawqmdd.js +212 -0
- package/dist/{index-zg8yq4ya.js → index-znzgze2v.js} +3 -3
- package/dist/index.js +38 -35
- package/dist/{message-index-bounded-hqktkhdy.js → message-index-bounded-pv6ct15d.js} +18 -17
- package/dist/message-index-jqa7qd0s.js +60 -0
- package/dist/migration-worker.js +3 -3
- package/dist/{project-embedding-registry-0gv3h6y8.js → project-embedding-registry-fcmszatg.js} +4 -4
- package/dist/raw-ordinal-warmup-worker.js +22 -5
- package/dist/{read-session-chunk-5mh0bh8y.js → read-session-chunk-cwgjwjd0.js} +7 -6
- package/dist/{read-session-raw-8sjbc9h0.js → read-session-raw-z38cn0as.js} +2 -1
- package/dist/{recomp-orchestrator-kpkhkjhq.js → recomp-orchestrator-txcc802e.js} +19 -17
- package/dist/{search-p9w39qv4.js → search-v1t47s2q.js} +14 -13
- package/dist/{send-session-notification-xffh3bbe.js → send-session-notification-yp9m5g4p.js} +4 -3
- package/dist/shared/tag-owner-id.d.ts +1 -0
- package/dist/shared/tag-owner-id.d.ts.map +1 -1
- package/dist/{storage-tags-k0pda32s.js → storage-tags-0ssbmzg9.js} +2 -2
- package/dist/{transform-postprocess-phase-481j5a7z.js → transform-postprocess-phase-113rwew1.js} +19 -17
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/compaction-marker-candidates-1s21e2fz.js +18 -0
- package/dist/v2/compaction-marker-candidates-worker.js +24 -0
- package/dist/v2/{context-gsdtha5v.js → context-p1xf3w5q.js} +115 -44
- package/dist/v2/{embedding-backfill-dbvjbcmm.js → embedding-backfill-9hbkfvnz.js} +5 -5
- package/dist/v2/{message-index-bounded-p6v0n8qh.js → message-index-bounded-c0810p5w.js} +17 -16
- package/dist/v2/message-index-h8ssgq3q.js +59 -0
- package/dist/v2/migration-worker.js +3 -3
- package/dist/v2/{project-embedding-registry-nyq7z8y6.js → project-embedding-registry-42th7k1z.js} +4 -4
- package/dist/v2/raw-ordinal-warmup-worker.js +22 -5
- package/dist/v2/{read-session-chunk-fhyfe4qa.js → read-session-chunk-n86v9xfg.js} +6 -5
- package/dist/v2/{read-session-raw-j8dvp7f4.js → read-session-raw-3b3ehga4.js} +2 -1
- package/dist/v2/{recomp-orchestrator-5xy7w136.js → recomp-orchestrator-v168jwgg.js} +16 -14
- package/dist/v2/{search-j7bakcwa.js → search-048v8y02.js} +13 -12
- package/dist/v2/{send-session-notification-f6v698r5.js → send-session-notification-a4h2azxa.js} +2 -1
- package/dist/v2/{server-bgzy0phk.js → server-3bc6k4k4.js} +62 -33
- package/dist/v2/{server-7h861yms.js → server-3dqjhchy.js} +5 -18
- package/dist/v2/{server-c7n2ftng.js → server-4n2tknpc.js} +34 -3
- package/dist/v2/server-51779zs2.js +19 -0
- package/dist/v2/{server-kh958yj8.js → server-5zrpr764.js} +1 -1
- package/dist/v2/{server-6tcrjfw8.js → server-8pqnnmf9.js} +1 -1
- package/dist/v2/server-9290a1mb.js +212 -0
- package/dist/v2/{server-7vkj6zhb.js → server-9a6v0wth.js} +3 -3
- package/dist/v2/{server-1fszbabv.js → server-cjz51jm2.js} +2 -2
- package/dist/v2/{server-7spkq1y6.js → server-cxxjb33r.js} +2286 -2246
- package/dist/v2/{server-mqvtz7wz.js → server-hetyb88z.js} +9 -9
- package/dist/v2/{server-4c7jt8gq.js → server-pcygfdbs.js} +44 -6
- package/dist/v2/{server-8xmq9h3f.js → server-q6j5dasr.js} +4 -2
- package/dist/v2/{server-zbxjj2mz.js → server-rygvffsf.js} +2 -2
- package/dist/v2/server.js +4 -4
- package/dist/v2/{storage-tags-5yxrvkaf.js → storage-tags-3a4cavqb.js} +2 -2
- package/dist/v2/{wrapup-orchestrator-yem5422s.js → wrapup-orchestrator-zcyf8ymw.js} +14 -12
- package/dist/{wrapup-orchestrator-xvrr27ws.js → wrapup-orchestrator-5aa2q4v3.js} +20 -18
- package/package.json +3 -3
- package/src/config/latch-permanence-guard.test.ts +6 -1
- package/src/shared/sqlite-writer-diagnostics.test.ts +21 -10
- package/src/shared/tag-owner-id.ts +13 -0
- package/src/shared/tag-transcript.test.ts +6 -1
- package/src/shared/tag-transcript.ts +2 -1
- package/src/shared/windows-hidden-spawns.test.ts +60 -4
- /package/dist/{index-69vas84q.js → index-e6xnpach.js} +0 -0
- /package/dist/{index-p1hnwfd8.js → index-gcdb3rqw.js} +0 -0
- /package/dist/v2/{index-69vas84q.js → index-e6xnpach.js} +0 -0
- /package/dist/v2/{server-s2st631p.js → server-8wcf79fe.js} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/shared/exit-abort-registry.ts
|
|
2
|
+
var controllers = new Set;
|
|
3
|
+
var listenerRegistered = false;
|
|
4
|
+
function abortAll() {
|
|
5
|
+
for (const controller of controllers) {
|
|
6
|
+
try {
|
|
7
|
+
controller.abort();
|
|
8
|
+
} catch {}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function registerExitAbort(controller) {
|
|
12
|
+
controllers.add(controller);
|
|
13
|
+
if (listenerRegistered)
|
|
14
|
+
return;
|
|
15
|
+
listenerRegistered = true;
|
|
16
|
+
process.once("exit", abortAll);
|
|
17
|
+
}
|
|
18
|
+
function unregisterExitAbort(controller) {
|
|
19
|
+
controllers.delete(controller);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { registerExitAbort, unregisterExitAbort };
|
|
@@ -3,16 +3,16 @@ import {
|
|
|
3
3
|
} from "./index-nsjyysj0.js";
|
|
4
4
|
import {
|
|
5
5
|
clearEmergencyRecovery
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-7zg9dvx0.js";
|
|
7
7
|
import {
|
|
8
8
|
requestPendingMaterialization,
|
|
9
9
|
dropSlot,
|
|
10
10
|
executeContextRecomp
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-s4ztdn8v.js";
|
|
12
12
|
import {
|
|
13
13
|
renderUserFacingFailure,
|
|
14
14
|
userFacingFailureCode
|
|
15
|
-
} from "./index-
|
|
15
|
+
} from "./index-fjtgekd4.js";
|
|
16
16
|
|
|
17
17
|
// src/hooks/magic-context/recomp-orchestrator.ts
|
|
18
18
|
function resolveLiveModelKey(liveSessionState, sessionId) {
|
|
@@ -68,7 +68,7 @@ import {
|
|
|
68
68
|
adoptNullOwnerToolTag2,
|
|
69
69
|
getCandidateToolOwners2,
|
|
70
70
|
pickNearestPriorOwner2
|
|
71
|
-
} from "./index-
|
|
71
|
+
} from "./index-yqps2zsv.js";
|
|
72
72
|
import {
|
|
73
73
|
textMentionsRecentCommit,
|
|
74
74
|
hasMeaningfulUserText2,
|
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
getProjectEmbeddingSnapshot2,
|
|
92
92
|
embedTextForProject2,
|
|
93
93
|
embedBatchForProject2
|
|
94
|
-
} from "./index-
|
|
94
|
+
} from "./index-c0b01zrc.js";
|
|
95
95
|
import {
|
|
96
96
|
isEmbeddingHostBusy2
|
|
97
97
|
} from "./index-qt1qqasc.js";
|
|
@@ -185,7 +185,7 @@ import {
|
|
|
185
185
|
extractToolCallObservation,
|
|
186
186
|
ToolMutationBatch,
|
|
187
187
|
createToolDropTarget
|
|
188
|
-
} from "./index-
|
|
188
|
+
} from "./index-7zg9dvx0.js";
|
|
189
189
|
import {
|
|
190
190
|
getMaxM0MutationId,
|
|
191
191
|
rememberUnpublishedAutoSearchNoHint,
|
|
@@ -202,6 +202,7 @@ import {
|
|
|
202
202
|
replaceSourceContent,
|
|
203
203
|
getSourceContents,
|
|
204
204
|
compareOpenCodeMessagesByCanonicalOrder,
|
|
205
|
+
prepareCompactionMarkerCandidates,
|
|
205
206
|
MARKER_SUMMARY_TEXT,
|
|
206
207
|
applyDeferredCompactionMarker,
|
|
207
208
|
injectTemporalMarkers,
|
|
@@ -218,21 +219,21 @@ import {
|
|
|
218
219
|
peekNoteNudgeText,
|
|
219
220
|
markNoteNudgeDelivered,
|
|
220
221
|
getActiveCompartmentRun
|
|
221
|
-
} from "./index-
|
|
222
|
+
} from "./index-s4ztdn8v.js";
|
|
222
223
|
import {
|
|
223
224
|
runSessionWarmupWorker
|
|
224
|
-
} from "./index-
|
|
225
|
+
} from "./index-jpm52v9x.js";
|
|
225
226
|
import {
|
|
226
227
|
openCodeDbExists,
|
|
227
228
|
withReadOnlySessionDb,
|
|
228
229
|
getMessageTimesFromOpenCodeDb
|
|
229
|
-
} from "./index-
|
|
230
|
+
} from "./index-qvr78ej6.js";
|
|
230
231
|
import {
|
|
231
232
|
BoundedSessionMap
|
|
232
|
-
} from "./index-
|
|
233
|
+
} from "./index-3wckxwfp.js";
|
|
233
234
|
import {
|
|
234
235
|
renderUserFacingFailure
|
|
235
|
-
} from "./index-
|
|
236
|
+
} from "./index-fjtgekd4.js";
|
|
236
237
|
import {
|
|
237
238
|
getErrorMessage
|
|
238
239
|
} from "./index-y8v6yerm.js";
|
|
@@ -4766,6 +4767,9 @@ function applyRustModeDeferredCompactionMarker2(args) {
|
|
|
4766
4767
|
const outcome = (args.applyDeferred ?? applyDeferredCompactionMarker)(args.db, args.sessionId, pending, args.sessionDirectory, trustedBoundary);
|
|
4767
4768
|
args.afterApply?.(outcome);
|
|
4768
4769
|
switch (outcome.kind) {
|
|
4770
|
+
case "deferred":
|
|
4771
|
+
sessionLog2(args.sessionId, "rust compaction-marker drain: candidate preparation deferred; pending target retained");
|
|
4772
|
+
break;
|
|
4769
4773
|
case "applied":
|
|
4770
4774
|
case "already-current":
|
|
4771
4775
|
case "stale-skip":
|
|
@@ -5976,9 +5980,15 @@ async function runPostTransformPhase2(args) {
|
|
|
5976
5980
|
sessionLog2(args.sessionId, `compaction-marker drain: refusing ordinal ${pending.ordinal} because prefix trim through ${args.pendingCompartmentInjection?.compartmentEndMessageId ?? "<none>"} was not proven; preserving deferred history refresh signal`);
|
|
5977
5981
|
} else {
|
|
5978
5982
|
const tMarkerDrain = performance.now();
|
|
5979
|
-
const
|
|
5983
|
+
const strategy = args.compactionMarkerStrategy ?? defaultCompactionMarkerStrategy2;
|
|
5984
|
+
const candidatesReady = strategy.applyDeferred !== applyDeferredCompactionMarker || await prepareCompactionMarkerCandidates(args.sessionId);
|
|
5985
|
+
const outcome = candidatesReady ? strategy.applyDeferred(args.db, args.sessionId, pending, args.sessionDirectory) : { kind: "deferred", reason: "candidate-preparation" };
|
|
5980
5986
|
logTransformTiming(args.sessionId, "pp.markerDrain", tMarkerDrain, `outcome=${outcome.kind}`);
|
|
5981
5987
|
switch (outcome.kind) {
|
|
5988
|
+
case "deferred":
|
|
5989
|
+
suppressV12HistoryDrain = true;
|
|
5990
|
+
sessionLog2(args.sessionId, "compaction-marker drain: candidate preparation deferred; preserving deferred history refresh signal");
|
|
5991
|
+
break;
|
|
5982
5992
|
case "applied":
|
|
5983
5993
|
case "already-current":
|
|
5984
5994
|
case "stale-skip":
|
|
@@ -129,6 +129,7 @@ function isThinkingPart(part) {
|
|
|
129
129
|
|
|
130
130
|
// src/shared/tag-owner-id.ts
|
|
131
131
|
var TEXT_TAG_IDENTITY_MARKER = ":mc-text-v1:";
|
|
132
|
+
var PI_FALLBACK_PREFIXES_JSON = JSON.stringify([..."pi-msg-"].reduce((prefixes, char) => prefixes.flatMap((prefix) => /[a-z]/.test(char) ? [prefix + char, prefix + char.toUpperCase()] : [prefix + char]), [""]));
|
|
132
133
|
var POSITIONAL_CONTENT_SUFFIX = /:(?:p|file)\d+$/;
|
|
133
134
|
var CONTENT_DERIVED_TEXT_SUFFIX = /:mc-text-v1:[0-9a-f]+:[0-9a-f]+:o\d+$/;
|
|
134
135
|
function contentTagOwnerMessageId(contentId) {
|
|
@@ -2257,8 +2258,41 @@ function getPersistedToolTagAccounting2(db, sessionId, tagNumber) {
|
|
|
2257
2258
|
}
|
|
2258
2259
|
return row;
|
|
2259
2260
|
}
|
|
2260
|
-
function getAllStatusTagTokenTotalsFlat2(db, sessionId, floor = 0, calibration = { proseRatio: 1, toolsRatio: 1 }) {
|
|
2261
|
-
const
|
|
2261
|
+
function getAllStatusTagTokenTotalsFlat2(db, sessionId, floor = 0, calibration = { proseRatio: 1, toolsRatio: 1 }, ownerMessageIds) {
|
|
2262
|
+
const columns = "type, message_id, tool_owner_message_id, token_count, input_token_count, reasoning_token_count";
|
|
2263
|
+
const owners = ownerMessageIds ? new Set(ownerMessageIds) : undefined;
|
|
2264
|
+
let scanOrder = "id";
|
|
2265
|
+
if (owners) {
|
|
2266
|
+
const planStatement = db.prepare(`EXPLAIN QUERY PLAN SELECT ${columns} FROM tags WHERE session_id = ?${floor > 0 ? " AND tag_number >= ?" : ""}`);
|
|
2267
|
+
let plan;
|
|
2268
|
+
try {
|
|
2269
|
+
plan = planStatement.all(sessionId, ...floor > 0 ? [floor] : []);
|
|
2270
|
+
} finally {
|
|
2271
|
+
planStatement.finalize?.();
|
|
2272
|
+
}
|
|
2273
|
+
const index = plan.map((row) => /USING (?:COVERING )?INDEX (\S+)/.exec(row.detail)?.[1]).find(Boolean);
|
|
2274
|
+
if (index) {
|
|
2275
|
+
const keyStatement = db.prepare("SELECT name, coll, desc FROM pragma_index_xinfo(?) WHERE key = 1 ORDER BY seqno");
|
|
2276
|
+
let keys;
|
|
2277
|
+
try {
|
|
2278
|
+
keys = keyStatement.all(index);
|
|
2279
|
+
} finally {
|
|
2280
|
+
keyStatement.finalize?.();
|
|
2281
|
+
}
|
|
2282
|
+
scanOrder = [
|
|
2283
|
+
...keys.map((key) => `"${(key.name ?? "id").replaceAll('"', '""')}" COLLATE "${key.coll.replaceAll('"', '""')}"${key.desc ? " DESC" : ""}`),
|
|
2284
|
+
"id"
|
|
2285
|
+
].join(", ");
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
const rows = owners ? db.prepare(`SELECT ${columns} FROM tags WHERE id IN (
|
|
2289
|
+
SELECT t.id FROM json_each(?) o CROSS JOIN tags t INDEXED BY idx_tags_session_message_id
|
|
2290
|
+
ON t.session_id = ? AND t.message_id >= o.value AND t.message_id < o.value || ';'
|
|
2291
|
+
UNION
|
|
2292
|
+
SELECT t.id FROM json_each(?) o CROSS JOIN tags t INDEXED BY idx_tags_pi_fallback_tool_owner
|
|
2293
|
+
ON t.session_id = ? AND t.tool_owner_message_id = o.value
|
|
2294
|
+
WHERE t.type = 'tool'
|
|
2295
|
+
) AND tag_number >= ? ORDER BY ${scanOrder}`).all(JSON.stringify([...owners]), sessionId, JSON.stringify([...owners]), sessionId, floor) : floor > 0 ? db.prepare(`SELECT type, message_id, tool_owner_message_id, token_count, input_token_count, reasoning_token_count
|
|
2262
2296
|
FROM tags
|
|
2263
2297
|
WHERE session_id = ? AND tag_number >= ?`).all(sessionId, floor) : db.prepare(`SELECT type, message_id, tool_owner_message_id, token_count, input_token_count, reasoning_token_count
|
|
2264
2298
|
FROM tags
|
|
@@ -2269,6 +2303,8 @@ function getAllStatusTagTokenTotalsFlat2(db, sessionId, floor = 0, calibration =
|
|
|
2269
2303
|
if (row.type === "tool" && row.tool_owner_message_id === null)
|
|
2270
2304
|
continue;
|
|
2271
2305
|
const owner = ownerMessageIdForTagRow(row);
|
|
2306
|
+
if (owners && !owners.has(owner))
|
|
2307
|
+
continue;
|
|
2272
2308
|
if (row.token_count === null) {
|
|
2273
2309
|
nullMessageIds.add(owner);
|
|
2274
2310
|
totals.delete(owner);
|
|
@@ -3032,11 +3068,13 @@ function findPiFallbackToolOwnerTags2(db, sessionId) {
|
|
|
3032
3068
|
message_id AS callId,
|
|
3033
3069
|
tool_owner_message_id AS toolOwnerMessageId,
|
|
3034
3070
|
status
|
|
3035
|
-
FROM tags
|
|
3071
|
+
FROM json_each(?) prefix CROSS JOIN tags
|
|
3036
3072
|
WHERE session_id = ?
|
|
3037
|
-
AND type = 'tool'
|
|
3038
|
-
|
|
3039
|
-
|
|
3073
|
+
AND tags.type = 'tool'
|
|
3074
|
+
AND tool_owner_message_id >= prefix.value
|
|
3075
|
+
AND tool_owner_message_id < substr(prefix.value, 1, 6) || '.'
|
|
3076
|
+
AND tool_owner_message_id LIKE 'pi-msg-%'
|
|
3077
|
+
ORDER BY tag_number ASC`).all(PI_FALLBACK_PREFIXES_JSON, sessionId).filter(isPiFallbackToolOwnerTag);
|
|
3040
3078
|
}
|
|
3041
3079
|
|
|
3042
3080
|
class PiTagIdentityConflictError extends Error {
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerExitAbort
|
|
3
|
+
} from "./index-v0p37hm2.js";
|
|
4
|
+
import {
|
|
5
|
+
log2
|
|
6
|
+
} from "./index-nsjyysj0.js";
|
|
7
|
+
import {
|
|
8
|
+
getSqliteDatabasePath2
|
|
9
|
+
} from "./index-kb9nn0a0.js";
|
|
10
|
+
|
|
11
|
+
// src/features/magic-context/compaction-marker-candidates.ts
|
|
12
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { Worker } from "node:worker_threads";
|
|
15
|
+
var candidates = new WeakMap;
|
|
16
|
+
var pending = new WeakMap;
|
|
17
|
+
var workers = new Set;
|
|
18
|
+
var missingWorkerWarnings = new Set;
|
|
19
|
+
var ownWriteRevisions = new Map;
|
|
20
|
+
var exitRegistered = false;
|
|
21
|
+
function reportWorkerUnavailable(entry, detail) {
|
|
22
|
+
if (missingWorkerWarnings.has(entry.href))
|
|
23
|
+
return;
|
|
24
|
+
missingWorkerWarnings.add(entry.href);
|
|
25
|
+
const path = entry.protocol === "file:" ? fileURLToPath(entry) : entry.href;
|
|
26
|
+
log2(`[magic-context] [ERROR] compaction-marker: candidate worker unavailable ${path}: ${detail}; marker unchanged, advancement deferred`);
|
|
27
|
+
}
|
|
28
|
+
var MARKER_CERTIFICATION_SQL = `SELECT
|
|
29
|
+
(SELECT rowid FROM message WHERE id = ?) AS previousRowid,
|
|
30
|
+
(SELECT rowid FROM message ORDER BY rowid DESC LIMIT 1) AS newestRowid,
|
|
31
|
+
(SELECT id FROM message ORDER BY rowid DESC LIMIT 1) AS newestId,
|
|
32
|
+
EXISTS(SELECT 1 FROM message
|
|
33
|
+
WHERE rowid > ? AND +session_id = ? AND json_valid(data)
|
|
34
|
+
AND COALESCE(json_extract(data, '$.summary'), 0) = 1) AS newSummary`;
|
|
35
|
+
function isMarkerCandidateBasisCurrent2(db, basis) {
|
|
36
|
+
if (basis.connection !== db || ownWriteRevisions.get(basis.revisionKey) !== basis.ownWriteRevision)
|
|
37
|
+
return false;
|
|
38
|
+
try {
|
|
39
|
+
const current = db.prepare(MARKER_CERTIFICATION_SQL).get(basis.frontier?.id ?? null, basis.frontier?.rowid ?? 0, basis.sessionId);
|
|
40
|
+
if (current.newSummary || basis.frontier && (current.previousRowid !== basis.frontier.rowid || current.newestRowid === null || current.newestRowid < basis.frontier.rowid))
|
|
41
|
+
return false;
|
|
42
|
+
if (current.newestRowid !== null && (!Number.isSafeInteger(current.newestRowid) || current.newestId === null))
|
|
43
|
+
return false;
|
|
44
|
+
basis.frontier = current.newestRowid === null || current.newestId === null ? null : { rowid: current.newestRowid, id: current.newestId };
|
|
45
|
+
return true;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function invalidateMarkerCandidateBasis2(db, sessionId) {
|
|
51
|
+
candidates.get(db)?.delete(sessionId);
|
|
52
|
+
const path = getSqliteDatabasePath2(db);
|
|
53
|
+
if (!path)
|
|
54
|
+
return;
|
|
55
|
+
const key = `${realpathSync(path)}\x00${sessionId}`;
|
|
56
|
+
const revision = ownWriteRevisions.get(key);
|
|
57
|
+
if (revision !== undefined)
|
|
58
|
+
ownWriteRevisions.set(key, revision + 1);
|
|
59
|
+
}
|
|
60
|
+
function readMarkerCandidateBasis2(db, sessionId) {
|
|
61
|
+
const basis = candidates.get(db)?.get(sessionId);
|
|
62
|
+
if (basis && isMarkerCandidateBasisCurrent2(db, basis))
|
|
63
|
+
return basis;
|
|
64
|
+
candidates.get(db)?.delete(sessionId);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
function prepareMarkerCandidateBasis2(db, sessionId, options = {}) {
|
|
68
|
+
if (readMarkerCandidateBasis2(db, sessionId))
|
|
69
|
+
return Promise.resolve(true);
|
|
70
|
+
const path = getSqliteDatabasePath2(db);
|
|
71
|
+
if (!path || db.inTransaction)
|
|
72
|
+
return Promise.resolve(false);
|
|
73
|
+
const active = pending.get(db) ?? new Map;
|
|
74
|
+
const existing = active.get(sessionId);
|
|
75
|
+
if (existing)
|
|
76
|
+
return existing;
|
|
77
|
+
const revisionKey = `${realpathSync(path)}\x00${sessionId}`;
|
|
78
|
+
const ownWriteRevision = ownWriteRevisions.get(revisionKey) ?? 0;
|
|
79
|
+
ownWriteRevisions.set(revisionKey, ownWriteRevision);
|
|
80
|
+
const entry = options.entry ?? markerWorkerEntry();
|
|
81
|
+
if (entry.protocol === "file:" && !existsSync(fileURLToPath(entry))) {
|
|
82
|
+
reportWorkerUnavailable(entry, "file missing");
|
|
83
|
+
return Promise.resolve(false);
|
|
84
|
+
}
|
|
85
|
+
const preparation = runCandidateWorker(path, sessionId, options).then((snapshot) => {
|
|
86
|
+
if (!snapshot)
|
|
87
|
+
return false;
|
|
88
|
+
const basis = {
|
|
89
|
+
...snapshot,
|
|
90
|
+
connection: db,
|
|
91
|
+
sessionId,
|
|
92
|
+
revisionKey,
|
|
93
|
+
ownWriteRevision
|
|
94
|
+
};
|
|
95
|
+
if (!isMarkerCandidateBasisCurrent2(db, basis)) {
|
|
96
|
+
candidates.get(db)?.delete(sessionId);
|
|
97
|
+
log2(`[magic-context] compaction-marker: deferred candidate preparation for ${sessionId}: summary set or frontier changed during discovery; marker unchanged`);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const sessions = candidates.get(db) ?? new Map;
|
|
101
|
+
sessions.set(sessionId, basis);
|
|
102
|
+
candidates.set(db, sessions);
|
|
103
|
+
return true;
|
|
104
|
+
}).finally(() => {
|
|
105
|
+
if (active.get(sessionId) === preparation)
|
|
106
|
+
active.delete(sessionId);
|
|
107
|
+
});
|
|
108
|
+
active.set(sessionId, preparation);
|
|
109
|
+
pending.set(db, active);
|
|
110
|
+
return preparation;
|
|
111
|
+
}
|
|
112
|
+
function markerWorkerEntry() {
|
|
113
|
+
return new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./compaction-marker-candidates-worker.ts" : "./compaction-marker-candidates-worker.js", import.meta.url);
|
|
114
|
+
}
|
|
115
|
+
function runCandidateWorker(path, sessionId, options) {
|
|
116
|
+
if (!exitRegistered) {
|
|
117
|
+
exitRegistered = true;
|
|
118
|
+
const controller = new AbortController;
|
|
119
|
+
controller.signal.addEventListener("abort", () => {
|
|
120
|
+
for (const worker of workers) {
|
|
121
|
+
worker.terminate();
|
|
122
|
+
worker.unref();
|
|
123
|
+
}
|
|
124
|
+
}, { once: true });
|
|
125
|
+
registerExitAbort(controller);
|
|
126
|
+
}
|
|
127
|
+
return new Promise((resolve) => {
|
|
128
|
+
const entry = options.entry ?? markerWorkerEntry();
|
|
129
|
+
let worker;
|
|
130
|
+
let timer;
|
|
131
|
+
let done = false;
|
|
132
|
+
const finish = (snapshot) => {
|
|
133
|
+
if (done)
|
|
134
|
+
return;
|
|
135
|
+
done = true;
|
|
136
|
+
clearTimeout(timer);
|
|
137
|
+
if (!worker) {
|
|
138
|
+
resolve(snapshot);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
workers.delete(worker);
|
|
142
|
+
const stopped = worker.terminate();
|
|
143
|
+
worker.unref();
|
|
144
|
+
stopped.then(() => resolve(snapshot), () => resolve(snapshot));
|
|
145
|
+
};
|
|
146
|
+
const deadline = (ms) => {
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
timer = setTimeout(() => {
|
|
149
|
+
reportWorkerUnavailable(entry, "worker deadline exceeded");
|
|
150
|
+
finish();
|
|
151
|
+
}, ms);
|
|
152
|
+
timer.unref?.();
|
|
153
|
+
};
|
|
154
|
+
try {
|
|
155
|
+
worker = new Worker(entry, { workerData: { path, sessionId } });
|
|
156
|
+
workers.add(worker);
|
|
157
|
+
worker.unref();
|
|
158
|
+
deadline(options.acceptMs ?? 2000);
|
|
159
|
+
worker.on("message", (reply) => {
|
|
160
|
+
if (reply.kind === "accepted")
|
|
161
|
+
deadline(options.resultMs ?? 600000);
|
|
162
|
+
else if (reply.kind === "candidates")
|
|
163
|
+
finish(reply.snapshot);
|
|
164
|
+
else {
|
|
165
|
+
reportWorkerUnavailable(entry, reply.error);
|
|
166
|
+
finish();
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
worker.on("error", (error) => {
|
|
170
|
+
reportWorkerUnavailable(entry, error.message);
|
|
171
|
+
finish();
|
|
172
|
+
});
|
|
173
|
+
worker.on("exit", (code) => {
|
|
174
|
+
if (!done)
|
|
175
|
+
reportWorkerUnavailable(entry, `worker exited before replying (${code})`);
|
|
176
|
+
finish();
|
|
177
|
+
});
|
|
178
|
+
} catch (error) {
|
|
179
|
+
reportWorkerUnavailable(entry, error instanceof Error ? error.message : String(error));
|
|
180
|
+
finish();
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function scanMarkerSummaryCandidates(db, sessionId) {
|
|
185
|
+
const ownsSnapshot = !db.inTransaction;
|
|
186
|
+
if (ownsSnapshot)
|
|
187
|
+
db.exec("BEGIN");
|
|
188
|
+
try {
|
|
189
|
+
return db.prepare(`SELECT id FROM message WHERE session_id=? AND
|
|
190
|
+
CASE WHEN json_valid(data) THEN COALESCE(json_extract(data,'$.summary'),0) ELSE 0 END=1`).all(sessionId).map((row) => row.id);
|
|
191
|
+
} finally {
|
|
192
|
+
if (ownsSnapshot)
|
|
193
|
+
db.exec("ROLLBACK");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function scanMarkerCandidateSnapshot2(db, sessionId) {
|
|
197
|
+
const ownsSnapshot = !db.inTransaction;
|
|
198
|
+
if (ownsSnapshot)
|
|
199
|
+
db.exec("BEGIN");
|
|
200
|
+
try {
|
|
201
|
+
const ids = scanMarkerSummaryCandidates(db, sessionId);
|
|
202
|
+
const frontier = db.prepare("SELECT rowid,id FROM message ORDER BY rowid DESC LIMIT 1").get() ?? null;
|
|
203
|
+
if (frontier && !Number.isSafeInteger(frontier.rowid))
|
|
204
|
+
throw new Error("marker frontier rowid is not a safe integer");
|
|
205
|
+
return { ids, frontier };
|
|
206
|
+
} finally {
|
|
207
|
+
if (ownsSnapshot)
|
|
208
|
+
db.exec("ROLLBACK");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export { isMarkerCandidateBasisCurrent2, invalidateMarkerCandidateBasis2, readMarkerCandidateBasis2, prepareMarkerCandidateBasis2, scanMarkerCandidateSnapshot2 };
|
|
@@ -47,7 +47,7 @@ import {
|
|
|
47
47
|
hasPendingMigrations,
|
|
48
48
|
getMainThreadMigrationBodyCount,
|
|
49
49
|
runMigrations
|
|
50
|
-
} from "./index-
|
|
50
|
+
} from "./index-xfbfrngb.js";
|
|
51
51
|
import {
|
|
52
52
|
installTagIdentityRevisionTrigger,
|
|
53
53
|
ensureColumn,
|
|
@@ -60,7 +60,7 @@ import {
|
|
|
60
60
|
import {
|
|
61
61
|
bootQuietRemainingMs,
|
|
62
62
|
scheduleAfterBootQuiet
|
|
63
|
-
} from "./index-
|
|
63
|
+
} from "./index-41gqa557.js";
|
|
64
64
|
import {
|
|
65
65
|
setDatabase,
|
|
66
66
|
loadToolDefinitionMeasurements
|
|
@@ -1259,7 +1259,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
1259
1259
|
startMessageFtsRowidMapBackfill(db).then(async () => {
|
|
1260
1260
|
if (!readsOpenCodeStore)
|
|
1261
1261
|
return;
|
|
1262
|
-
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-
|
|
1262
|
+
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-cwgjwjd0.js"));
|
|
1263
1263
|
const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-8x06r9kx.js"));
|
|
1264
1264
|
await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
|
|
1265
1265
|
readPage: readRawSessionMessagePage
|