@cortexkit/pi-magic-context 0.49.52 → 0.49.54

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.
Files changed (40) hide show
  1. package/dist/auto-search-worker.js +3 -3
  2. package/dist/chunk-embedding-write-worker.js +3 -4
  3. package/dist/{embedding-backfill-fbhpk2yy.js → embedding-backfill-qde2zywg.js} +4 -4
  4. package/dist/embedding-worker.js +2 -2
  5. package/dist/{index-0hewsw7v.js → index-2pptpxq8.js} +1 -1
  6. package/dist/index-5n3e2gq5.js +6469 -0
  7. package/dist/{index-rjz01pvv.js → index-625kbnqd.js} +5 -7
  8. package/dist/{index-73c292h9.js → index-6ahmfva8.js} +3 -3
  9. package/dist/{index-1cvyaw9a.js → index-8d2z6503.js} +1 -1
  10. package/dist/{index-ktez4jwz.js → index-9kaj9ty1.js} +7 -6
  11. package/dist/{index-46wk0td0.js → index-awpx91y5.js} +1 -1
  12. package/dist/{index-mb34ngfr.js → index-c3mms4dp.js} +27 -16
  13. package/dist/{index-zc6fdyx7.js → index-d40ecdbn.js} +1 -1
  14. package/dist/{index-r6dj8rm9.js → index-erkb5dee.js} +11 -7
  15. package/dist/{index-38pf5bqw.js → index-hec3bwev.js} +1 -1
  16. package/dist/{index-ty2m0s0s.js → index-jnh7a6a3.js} +3 -3
  17. package/dist/{index-akmmkmhf.js → index-k2z7r444.js} +523 -30
  18. package/dist/{index-pkg07s54.js → index-nhpvvdhw.js} +2 -2
  19. package/dist/index-rekymyxd.js +2287 -0
  20. package/dist/{index-cc73przv.js → index-tn38he5d.js} +44 -31
  21. package/dist/{index-jxm4bvm4.js → index-v858d5d1.js} +168 -1
  22. package/dist/{index-aec63gtj.js → index-vcegxfwg.js} +16 -6
  23. package/dist/index.js +970 -352
  24. package/dist/{message-index-bounded-d50b5f2z.js → message-index-bounded-ac4qg6aw.js} +5 -6
  25. package/dist/migration-worker.js +3 -4
  26. package/dist/{project-embedding-registry-hpca84nz.js → project-embedding-registry-qx2zjbgs.js} +5 -3
  27. package/dist/raw-ordinal-warmup-worker.js +4 -4
  28. package/dist/{read-session-chunk-9yr9mava.js → read-session-chunk-jyfcykg4.js} +4 -5
  29. package/dist/{render-3s7kbr61.js → render-bqqx15n8.js} +9 -10
  30. package/dist/{search-archive-dd1z7xn0.js → search-archive-31054zxj.js} +7 -8
  31. package/dist/{search-2vgt4717.js → search-w12nc025.js} +12 -13
  32. package/dist/{storage-tags-ahhwtfdq.js → storage-tags-g0328gwp.js} +4 -2
  33. package/dist/subagent-entry.js +39 -18
  34. package/dist/tag-snapshot-worker-pi.js +6 -6
  35. package/dist/{v2-archive-reader-6jbyaafn.js → v2-archive-reader-hg4c36em.js} +1 -1
  36. package/package.json +3 -1
  37. package/dist/index-674f6qs2.js +0 -16
  38. package/dist/index-c6wbq66z.js +0 -168
  39. package/dist/index-fec4ezww.js +0 -5271
  40. package/dist/index-qcsjj9m0.js +0 -3412
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  piModelRefToCanonical
3
- } from "./index-aec63gtj.js";
3
+ } from "./index-vcegxfwg.js";
4
4
  import {
5
5
  getHarness2
6
6
  } from "./index-0h2mkab2.js";
@@ -11,8 +11,11 @@ import {
11
11
  sessionLog2
12
12
  } from "./index-yxeg8zaa.js";
13
13
  import {
14
+ isPrefixBoundThinkingModel,
14
15
  MERGED_REASONING_PARTS_PREFIX,
15
16
  decodeMergedReasoningParts,
17
+ isRecord,
18
+ providerVisibleMessage,
16
19
  SESSION_META_SELECT_COLUMNS,
17
20
  META_COLUMNS,
18
21
  BOOLEAN_META_KEYS,
@@ -26,6 +29,7 @@ import {
26
29
  readReplayDocument,
27
30
  updateReplayDocument,
28
31
  writeReplayDocument,
32
+ getTagById2,
29
33
  parseStrippedPlaceholderState,
30
34
  serializeStrippedPlaceholderState,
31
35
  THINKING_BINDING_RECOVERY_FROZEN_PREFIX,
@@ -34,37 +38,35 @@ import {
34
38
  parseProcessedImageMarkers,
35
39
  serializeProcessedImageMarkers,
36
40
  getPendingPiCompactionMarkerState,
37
- logPiCompactionMarkerClear,
38
- withReadOnlySessionDb,
39
- expandToolPart,
40
- visitRawSessionMessages2,
41
- readRawSessionMessageById2
42
- } from "./index-fec4ezww.js";
43
- import {
44
- isRecord,
45
- providerVisibleMessage,
46
- getTagById2
47
- } from "./index-qcsjj9m0.js";
41
+ logPiCompactionMarkerClear
42
+ } from "./index-5n3e2gq5.js";
48
43
  import {
49
44
  estimateTokens
50
45
  } from "./index-7y60kyea.js";
51
46
  import {
52
- prepareCachedStatement2,
53
- withSqliteBackgroundWriter2,
54
- withoutSqliteTransformPass2
55
- } from "./index-2qtx0q6h.js";
56
- import {
47
+ BoundedSessionMap,
57
48
  getTableColumnNames,
58
49
  tagTombstoneOwnerRange,
59
50
  tagTombstoneOwnerKey,
60
51
  tagRevisionKey,
61
52
  tagIdentityRevisionKey,
62
53
  deleteTagIdentityRevisions
63
- } from "./index-jxm4bvm4.js";
54
+ } from "./index-v858d5d1.js";
55
+ import {
56
+ prepareCachedStatement2,
57
+ withSqliteBackgroundWriter2,
58
+ withoutSqliteTransformPass2
59
+ } from "./index-2qtx0q6h.js";
64
60
  import {
65
61
  isPidAlive,
66
62
  readProcessStartTime
67
- } from "./index-rjz01pvv.js";
63
+ } from "./index-625kbnqd.js";
64
+ import {
65
+ withReadOnlySessionDb,
66
+ expandToolPart,
67
+ visitRawSessionMessages2,
68
+ readRawSessionMessageById2
69
+ } from "./index-rekymyxd.js";
68
70
  import {
69
71
  gaDatabasePath2,
70
72
  V2StoreReader2
@@ -79,13 +81,10 @@ import {
79
81
  invalidateAutoEmbedSession,
80
82
  drainBackgroundBatches
81
83
  } from "./index-hgd00nas.js";
82
- import {
83
- BoundedSessionMap
84
- } from "./index-c6wbq66z.js";
85
84
  import {
86
85
  layoutLkgPrefix,
87
86
  assembleLkgPrefix
88
- } from "./index-zc6fdyx7.js";
87
+ } from "./index-d40ecdbn.js";
89
88
  import {
90
89
  logSlowWriteTransaction
91
90
  } from "./index-j0eagxkz.js";
@@ -1297,7 +1296,7 @@ function getUncoveredCompartmentEndsThrough(db, sessionId, endOrdinal = Number.M
1297
1296
  const rows = db.prepare(`SELECT k.end_message_id, k.end_message,
1298
1297
  n.start_message_id AS successor_id, n.start_message AS successor_start FROM compartments k
1299
1298
  LEFT JOIN compartments n ON n.session_id = k.session_id AND n.sequence = k.sequence + 1
1300
- WHERE k.session_id = ?1 AND k.end_message <= ?2 AND k.end_message > ?3 AND k.end_block_index IS NOT NULL
1299
+ WHERE k.session_id = ? AND k.end_message <= ? AND k.end_message > ? AND k.end_block_index IS NOT NULL
1301
1300
  AND NOT COALESCE(n.sequence IS NOT NULL AND (
1302
1301
  (n.start_message_id = k.end_message_id AND n.start_block_index > k.end_block_index)
1303
1302
  OR n.start_message = k.end_message + 1), 0)
@@ -1438,7 +1437,7 @@ function readProjectDocsCanonical(projectDirectory) {
1438
1437
  return { renderedBlock, canonicalHash };
1439
1438
  }
1440
1439
  // ../plugin/src/hooks/magic-context/lkg-slot.ts
1441
- import { createHash as createHash5 } from "node:crypto";
1440
+ import { createHash as createHash6 } from "node:crypto";
1442
1441
 
1443
1442
  // ../plugin/src/shared/provider-response-completion.ts
1444
1443
  function providerResponseFailed(input) {
@@ -2238,8 +2237,10 @@ function replayLkg(args) {
2238
2237
 
2239
2238
  // ../plugin/src/hooks/magic-context/lkg-recovery-prefix.ts
2240
2239
  var sessions = new BoundedSessionMap(1000);
2240
+ var restartHeadChecked = new BoundedSessionMap(1000);
2241
2241
  function clearLkgRecoverySession(sessionId) {
2242
2242
  sessions.delete(sessionId);
2243
+ restartHeadChecked.delete(sessionId);
2243
2244
  clearLkgFenceProcessState(sessionId);
2244
2245
  }
2245
2246
  function noteLkgCapturedPrefix(sessionId) {
@@ -2247,6 +2248,498 @@ function noteLkgCapturedPrefix(sessionId) {
2247
2248
  sessions.set(sessionId, {});
2248
2249
  }
2249
2250
 
2251
+ // ../plugin/src/hooks/magic-context/served-check.ts
2252
+ import { createHash as createHash5 } from "node:crypto";
2253
+ var RECORD_SESSIONS = 256;
2254
+ var records = new BoundedSessionMap(RECORD_SESSIONS);
2255
+ var pending4 = new BoundedSessionMap(1000);
2256
+ var counters = new BoundedSessionMap(1000);
2257
+ var SERVED_FULL_CHECK_INTERVAL = 100;
2258
+ var COUNT_LOG_INTERVAL = 100;
2259
+ var HEAD_MIN = 2;
2260
+ var HEAD_MAX = 4;
2261
+ var lastWork = { fingerprinted: 0, digested: 0, full: false, ms: 0, shapeMs: 0 };
2262
+ function emptyCounters() {
2263
+ return {
2264
+ commits: 0,
2265
+ compared: 0,
2266
+ unknown: 0,
2267
+ refused: 0,
2268
+ appendOnly: 0,
2269
+ changed: 0,
2270
+ shorter: 0,
2271
+ modelChanged: 0,
2272
+ unpermittedChange: 0,
2273
+ mixedReplay: 0,
2274
+ thinkingPrefixChange: 0,
2275
+ sameShapeChange: 0,
2276
+ fullChecks: 0
2277
+ };
2278
+ }
2279
+ function countersFor(sessionId) {
2280
+ let value = counters.get(sessionId);
2281
+ if (!value) {
2282
+ value = emptyCounters();
2283
+ counters.set(sessionId, value);
2284
+ }
2285
+ return value;
2286
+ }
2287
+ function pendingFor(sessionId) {
2288
+ let value = pending4.get(sessionId);
2289
+ if (!value) {
2290
+ value = {};
2291
+ pending4.set(sessionId, value);
2292
+ }
2293
+ return value;
2294
+ }
2295
+ function beginServedRequest(sessionId) {
2296
+ pending4.delete(sessionId);
2297
+ }
2298
+ function noteServedPassPermission(sessionId, permission) {
2299
+ pendingFor(sessionId).permission = permission;
2300
+ }
2301
+ function noteServedReplay(sessionId) {
2302
+ pendingFor(sessionId).replay = true;
2303
+ }
2304
+ function countServedRefusal(sessionId) {
2305
+ try {
2306
+ pending4.delete(sessionId);
2307
+ countersFor(sessionId).refused += 1;
2308
+ } catch {}
2309
+ }
2310
+ function dropServedRecord(sessionId, reason) {
2311
+ try {
2312
+ const value = counters.peek(sessionId);
2313
+ if (value && value.commits + value.refused > 0)
2314
+ logCounts(sessionId, value, reason);
2315
+ if (records.has(sessionId))
2316
+ sessionLog2(sessionId, `served check: record dropped reason=${reason}; the next request is not compared`);
2317
+ } catch {}
2318
+ records.delete(sessionId);
2319
+ pending4.delete(sessionId);
2320
+ counters.delete(sessionId);
2321
+ }
2322
+ function logCounts(sessionId, value, reason) {
2323
+ sessionLog2(sessionId, `served check counts: compared=${value.compared} unknown=${value.unknown} refused=${value.refused} append_only=${value.appendOnly} changed=${value.changed} shorter=${value.shorter} model_changed=${value.modelChanged} unpermitted_change=${value.unpermittedChange} mixed_replay=${value.mixedReplay} thinking_prefix_change=${value.thinkingPrefixChange} same_shape_change=${value.sameShapeChange} full_checks=${value.fullChecks} reason=${reason}`);
2324
+ }
2325
+ function mix(hash, value) {
2326
+ return Math.imul(hash ^ (value | 0), 16777619);
2327
+ }
2328
+ function mixName(hash, value) {
2329
+ if (typeof value !== "string")
2330
+ return mix(hash, value === undefined ? -1 : -2);
2331
+ const length = value.length;
2332
+ const h = mix(hash, length);
2333
+ return length === 0 ? h : mix(h, value.charCodeAt(length - 1) << 16 | value.charCodeAt(length >> 1));
2334
+ }
2335
+ function mixId(hash, value) {
2336
+ if (typeof value !== "string")
2337
+ return mix(hash, value === undefined ? -1 : -2);
2338
+ const length = value.length;
2339
+ let h = mix(hash, length);
2340
+ const stop = length > 8 ? length - 8 : 0;
2341
+ let index = length - 1;
2342
+ for (;index > stop; index -= 2)
2343
+ h = mix(h, value.charCodeAt(index) << 16 | value.charCodeAt(index - 1));
2344
+ if (index === stop && length > 0)
2345
+ h = mix(h, value.charCodeAt(index));
2346
+ return h;
2347
+ }
2348
+ function mixNumber(hash, value) {
2349
+ const whole = Math.trunc(value);
2350
+ return mix(mix(mix(hash, whole), whole / 4294967296), Math.round((value - whole) * 1e6));
2351
+ }
2352
+ function mixLength(hash, value) {
2353
+ return typeof value === "string" ? mix(hash, value.length) : mix(hash, value === undefined ? -1 : -2);
2354
+ }
2355
+ function mixShallow(hash, value) {
2356
+ switch (typeof value) {
2357
+ case "string":
2358
+ return mix(mix(hash, 1), value.length);
2359
+ case "number":
2360
+ return mixNumber(mix(hash, 2), value);
2361
+ case "boolean":
2362
+ return mix(hash, value ? 5 : 4);
2363
+ case "undefined":
2364
+ return mix(hash, -1);
2365
+ case "object":
2366
+ if (value === null)
2367
+ return mix(hash, 3);
2368
+ if (Array.isArray(value))
2369
+ return mix(mix(hash, 9), value.length);
2370
+ {
2371
+ const size = value.byteLength;
2372
+ return typeof size === "number" ? mix(mix(hash, 7), size) : mix(hash, 10);
2373
+ }
2374
+ default:
2375
+ return mix(hash, 6);
2376
+ }
2377
+ }
2378
+ function mixToolState(hash, state) {
2379
+ let h = mixName(hash, state.status);
2380
+ h = mixShallow(h, state.input);
2381
+ h = mixShallow(h, state.output);
2382
+ if (state.error !== undefined)
2383
+ h = mixShallow(h, state.error);
2384
+ if (state.attachments !== undefined)
2385
+ h = mixShallow(h, state.attachments);
2386
+ if (state.content !== undefined)
2387
+ h = mixShallow(h, state.content);
2388
+ const time = state.time;
2389
+ h = mix(h, time && typeof time === "object" && time.compacted !== undefined ? 1 : 0);
2390
+ if (state.status === "error") {
2391
+ const metadata = state.metadata;
2392
+ if (metadata && typeof metadata === "object" && metadata.interrupted === true)
2393
+ h = mixShallow(h, metadata.output);
2394
+ }
2395
+ return h;
2396
+ }
2397
+ function isThinkingType(type) {
2398
+ return type === "reasoning" || type === "thinking" || type === "redacted_thinking";
2399
+ }
2400
+ function isKeptThinkingPart(part) {
2401
+ if (!isThinkingType(part.type) || part.ignored === true)
2402
+ return false;
2403
+ if (part.type === "redacted_thinking" || part.redacted === true)
2404
+ return true;
2405
+ if (typeof part.text === "string" && part.text !== "")
2406
+ return true;
2407
+ if (typeof part.thinking === "string" && part.thinking !== "")
2408
+ return true;
2409
+ const metadata = part.metadata;
2410
+ if (metadata && typeof metadata === "object") {
2411
+ for (const record of Object.values(metadata))
2412
+ if (record && typeof record === "object" && "redactedData" in record)
2413
+ return true;
2414
+ }
2415
+ return false;
2416
+ }
2417
+ var PART_FIELDS = [
2418
+ "text",
2419
+ "thinking",
2420
+ "thinkingSignature",
2421
+ "signature",
2422
+ "redacted",
2423
+ "data",
2424
+ "url",
2425
+ "mime",
2426
+ "mimeType",
2427
+ "mediaType",
2428
+ "filename",
2429
+ "name",
2430
+ "tool",
2431
+ "callID",
2432
+ "toolCallId",
2433
+ "input",
2434
+ "arguments",
2435
+ "output",
2436
+ "error",
2437
+ "isError",
2438
+ "providerExecuted",
2439
+ "synthetic",
2440
+ "ignored"
2441
+ ];
2442
+ var walkOut = { partThinking: false, messageThinking: false, messageHead: false };
2443
+ function mixPart(hash, rawPart) {
2444
+ walkOut.partThinking = false;
2445
+ if (!rawPart || typeof rawPart !== "object")
2446
+ return mix(hash, 11);
2447
+ const part = rawPart;
2448
+ const type = part.type;
2449
+ let h = mixId(mixName(hash, type), part.id);
2450
+ if (type === "text") {
2451
+ h = mixLength(h, part.text);
2452
+ return mix(h, (part.synthetic === true ? 1 : 0) | (part.ignored === true ? 2 : 0));
2453
+ }
2454
+ if (type === "tool" && part.state && typeof part.state === "object")
2455
+ return mixToolState(mixId(mixName(h, part.tool), part.callID), part.state);
2456
+ for (let index = 0;index < PART_FIELDS.length; index += 1) {
2457
+ const value = part[PART_FIELDS[index]];
2458
+ if (value !== undefined)
2459
+ h = mixShallow(mix(h, index), value);
2460
+ }
2461
+ const result = part.result;
2462
+ if (result && typeof result === "object") {
2463
+ h = mixName(h, result.type);
2464
+ h = mixShallow(h, result.value);
2465
+ }
2466
+ if (isThinkingType(type)) {
2467
+ walkOut.partThinking = isKeptThinkingPart(part);
2468
+ const metadata = part.metadata;
2469
+ const anthropic = metadata && typeof metadata === "object" ? metadata.anthropic : undefined;
2470
+ if (anthropic && typeof anthropic === "object") {
2471
+ h = mixShallow(h, anthropic.signature);
2472
+ h = mixShallow(h, anthropic.redactedData);
2473
+ } else
2474
+ h = mix(h, metadata && typeof metadata === "object" ? 17 : 18);
2475
+ }
2476
+ return h;
2477
+ }
2478
+ function messageShape(message) {
2479
+ const record = message && typeof message === "object" ? message : {};
2480
+ const info = record.info && typeof record.info === "object" ? record.info : record;
2481
+ const parts = Array.isArray(record.parts) ? record.parts : record.content;
2482
+ const role = info.role;
2483
+ let hash = mixId(2166136261, info.id);
2484
+ hash = mixName(hash, role);
2485
+ if (typeof record.timestamp === "number")
2486
+ hash = mixNumber(hash, record.timestamp);
2487
+ if (typeof record.toolCallId === "string")
2488
+ hash = mixId(hash, record.toolCallId);
2489
+ if (record.isError === true)
2490
+ hash = mix(hash, 12);
2491
+ if (info.summary === true)
2492
+ hash = mix(hash, 13);
2493
+ let thinking = false;
2494
+ let synthetic = info.synthetic === true || info.summary === true;
2495
+ if (typeof parts === "string") {
2496
+ hash = mix(mix(hash, 14), parts.length);
2497
+ } else if (Array.isArray(parts)) {
2498
+ hash = mix(mix(hash, 15), parts.length);
2499
+ let allSynthetic = parts.length > 0;
2500
+ for (const part of parts) {
2501
+ hash = mixPart(hash, part);
2502
+ if (walkOut.partThinking)
2503
+ thinking = true;
2504
+ if (allSynthetic && part?.synthetic !== true)
2505
+ allSynthetic = false;
2506
+ }
2507
+ if (allSynthetic)
2508
+ synthetic = true;
2509
+ } else {
2510
+ hash = mix(hash, 16);
2511
+ }
2512
+ walkOut.messageThinking = thinking && role === "assistant";
2513
+ walkOut.messageHead = synthetic || role === "system" || role === "compactionSummary" || role === "branchSummary";
2514
+ return hash >>> 0;
2515
+ }
2516
+ function digestInto(message, out, index) {
2517
+ let json;
2518
+ try {
2519
+ json = JSON.stringify(contentSnapshotValue(message));
2520
+ } catch {
2521
+ json = undefined;
2522
+ }
2523
+ if (json === undefined) {
2524
+ out[2 * index] = 0;
2525
+ out[2 * index + 1] = 0;
2526
+ return;
2527
+ }
2528
+ const digest = createHash5("sha256").update(json).digest();
2529
+ out[2 * index] = digest.readUInt32LE(0);
2530
+ out[2 * index + 1] = digest.readUInt32LE(4);
2531
+ }
2532
+ function digestsDiffer(a, ai, b, bi) {
2533
+ const a0 = a[2 * ai];
2534
+ const a1 = a[2 * ai + 1];
2535
+ const b0 = b[2 * bi];
2536
+ const b1 = b[2 * bi + 1];
2537
+ if (a0 === 0 && a1 === 0 || b0 === 0 && b1 === 0)
2538
+ return false;
2539
+ return a0 !== b0 || a1 !== b1;
2540
+ }
2541
+ function permittedLabel(permitted) {
2542
+ return permitted === null ? "unknown" : String(permitted);
2543
+ }
2544
+ function commitServedRequest(args) {
2545
+ try {
2546
+ return commit(args);
2547
+ } catch (error) {
2548
+ try {
2549
+ records.delete(args.sessionId);
2550
+ sessionLog2(args.sessionId, "served check failed; the record is unknown again:", error);
2551
+ } catch {}
2552
+ return null;
2553
+ }
2554
+ }
2555
+ function commit(args) {
2556
+ const { sessionId, messages, host } = args;
2557
+ const startedAt = performance.now();
2558
+ const note = pending4.peek(sessionId) ?? {};
2559
+ pending4.delete(sessionId);
2560
+ const count = countersFor(sessionId);
2561
+ const kind = note.replay ? "replay" : note.input ? "input" : "pass";
2562
+ const permission = note.permission;
2563
+ const permitted = permission?.permitted ?? (args.compactionOff ? false : kind === "input" ? false : null);
2564
+ const prior = records.get(sessionId);
2565
+ if (note.refused) {
2566
+ count.refused += 1;
2567
+ return {
2568
+ class: "refused",
2569
+ kind,
2570
+ firstIndex: null,
2571
+ recorded: prior?.count ?? 0,
2572
+ served: messages.length,
2573
+ seenBy: null,
2574
+ keptThinkingIndex: -1,
2575
+ recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
2576
+ permitted,
2577
+ events: []
2578
+ };
2579
+ }
2580
+ count.commits += 1;
2581
+ const m = messages.length;
2582
+ const providerID = note.model?.providerID ?? args.providerID;
2583
+ const modelID = note.model?.modelID ?? args.modelID;
2584
+ const prefixBound = isPrefixBoundThinkingModel(providerID, modelID);
2585
+ const modelKey = modelID ? `${providerID ?? ""}/${modelID}` : null;
2586
+ const shapes = new Uint32Array(m);
2587
+ let keptThinkingIndex = -1;
2588
+ let headCount = Math.min(HEAD_MIN, m);
2589
+ let leading = true;
2590
+ for (let index = 0;index < m; index += 1) {
2591
+ shapes[index] = messageShape(messages[index]);
2592
+ if (prefixBound && keptThinkingIndex < 0 && walkOut.messageThinking)
2593
+ keptThinkingIndex = index;
2594
+ if (leading && index >= HEAD_MIN) {
2595
+ if (walkOut.messageHead && index < HEAD_MAX)
2596
+ headCount = index + 1;
2597
+ else
2598
+ leading = false;
2599
+ }
2600
+ }
2601
+ const shapeMs = performance.now() - startedAt;
2602
+ const digests = new Uint32Array(2 * m);
2603
+ const computed = new Uint8Array(m);
2604
+ let digested = 0;
2605
+ const digest = (index) => {
2606
+ if (index < 0 || index >= m || computed[index])
2607
+ return;
2608
+ computed[index] = 1;
2609
+ digested += 1;
2610
+ digestInto(messages[index], digests, index);
2611
+ };
2612
+ const finish = (comparison, full, passesSinceFull) => {
2613
+ records.set(sessionId, {
2614
+ count: m,
2615
+ shapes,
2616
+ digests,
2617
+ modelKey: modelKey ?? prior?.modelKey ?? null,
2618
+ kind,
2619
+ keptThinkingIndex,
2620
+ passesSinceFull
2621
+ });
2622
+ lastWork = { fingerprinted: m, digested, full, ms: 0, shapeMs };
2623
+ if (count.commits % COUNT_LOG_INTERVAL === 0)
2624
+ logCounts(sessionId, count, "periodic");
2625
+ lastWork.ms = performance.now() - startedAt;
2626
+ return { ...comparison, kind, permitted, served: m };
2627
+ };
2628
+ const modelChanged = prior !== undefined && prior.modelKey !== null && modelKey !== null && prior.modelKey !== modelKey;
2629
+ if (!prior || modelChanged) {
2630
+ for (let index = 0;index < m; index += 1)
2631
+ digest(index);
2632
+ if (prior)
2633
+ count.modelChanged += 1;
2634
+ else
2635
+ count.unknown += 1;
2636
+ return finish({
2637
+ class: prior ? "model_change" : "unknown",
2638
+ firstIndex: null,
2639
+ recorded: prior?.count ?? 0,
2640
+ seenBy: null,
2641
+ keptThinkingIndex,
2642
+ recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
2643
+ events: []
2644
+ }, true, 0);
2645
+ }
2646
+ count.compared += 1;
2647
+ const n = prior.count;
2648
+ const overlap = Math.min(n, m);
2649
+ let shapeDiff = -1;
2650
+ for (let index = 0;index < overlap; index += 1)
2651
+ if (shapes[index] !== prior.shapes[index]) {
2652
+ shapeDiff = index;
2653
+ break;
2654
+ }
2655
+ for (let index = 0;index < headCount; index += 1)
2656
+ digest(index);
2657
+ digest(n - 1);
2658
+ digest(prior.keptThinkingIndex);
2659
+ digest(keptThinkingIndex);
2660
+ for (let index = n;index < m; index += 1)
2661
+ digest(index);
2662
+ let handfulDiff = -1;
2663
+ for (let index = 0;index < overlap; index += 1)
2664
+ if (computed[index] && digestsDiffer(digests, index, prior.digests, index)) {
2665
+ handfulDiff = index;
2666
+ break;
2667
+ }
2668
+ const full = kind === "replay" || prior.kind === "replay" || shapeDiff >= 0 || handfulDiff >= 0 || m < n || prior.passesSinceFull + 1 >= SERVED_FULL_CHECK_INTERVAL;
2669
+ let contentDiff = handfulDiff;
2670
+ if (full) {
2671
+ count.fullChecks += 1;
2672
+ for (let index = 0;index < m; index += 1)
2673
+ digest(index);
2674
+ contentDiff = -1;
2675
+ for (let index = 0;index < overlap; index += 1)
2676
+ if (digestsDiffer(digests, index, prior.digests, index)) {
2677
+ contentDiff = index;
2678
+ break;
2679
+ }
2680
+ } else {
2681
+ for (let index = 0;index < overlap; index += 1)
2682
+ if (!computed[index]) {
2683
+ digests[2 * index] = prior.digests[2 * index];
2684
+ digests[2 * index + 1] = prior.digests[2 * index + 1];
2685
+ }
2686
+ }
2687
+ const candidates = [shapeDiff, contentDiff].filter((value) => value >= 0);
2688
+ const firstIndex = candidates.length > 0 ? Math.min(...candidates) : -1;
2689
+ let comparisonClass;
2690
+ let seenBy = null;
2691
+ if (firstIndex >= 0) {
2692
+ comparisonClass = "changed";
2693
+ count.changed += 1;
2694
+ seenBy = shapeDiff >= 0 && shapeDiff === firstIndex ? "shape" : handfulDiff === firstIndex ? "digest" : "full";
2695
+ } else if (m < n) {
2696
+ comparisonClass = "shorter";
2697
+ count.shorter += 1;
2698
+ seenBy = "length";
2699
+ } else {
2700
+ comparisonClass = "append_only";
2701
+ count.appendOnly += 1;
2702
+ }
2703
+ const reportedIndex = firstIndex >= 0 ? firstIndex : comparisonClass === "shorter" ? m : null;
2704
+ const events = [];
2705
+ const permissionInputs = permission ? `decision=${permission.schedulerDecision} ${permission.rides} thinking_hold=${permission.signedThinkingHold} first_render=${permission.firstRender} host_checkpoint_head=${permission.hostCheckpointHead} emergency=${permission.emergency}` : "decision=unknown ride=unknown";
2706
+ if (reportedIndex !== null) {
2707
+ const after = n - reportedIndex;
2708
+ if (kind === "replay") {
2709
+ events.push("mixed_replay");
2710
+ count.mixedReplay += 1;
2711
+ sessionLog2(sessionId, `served check: a replay differed from the request served before it first_index=${reportedIndex} recorded=${n} after_first=${after} served=${m} class=${comparisonClass} seen_by=${seenBy} refused_pass_permitted=${permittedLabel(permitted)} host=${host}`);
2712
+ } else if (permitted !== true) {
2713
+ events.push("unpermitted_change");
2714
+ count.unpermittedChange += 1;
2715
+ sessionLog2(sessionId, `served check: a pass without rebuild permission changed served messages first_index=${reportedIndex} recorded=${n} after_first=${after} served=${m} class=${comparisonClass} seen_by=${seenBy} kind=${kind} permitted=${permittedLabel(permitted)} ${permissionInputs} previous_kind=${prior.kind} host=${host}`);
2716
+ }
2717
+ }
2718
+ if (firstIndex >= 0 && shapeDiff !== firstIndex) {
2719
+ events.push("same_shape_change");
2720
+ count.sameShapeChange += 1;
2721
+ sessionLog2(sessionId, `served check: content changed with the same shape first_index=${firstIndex} seen_by=${seenBy} kind=${kind} permitted=${permittedLabel(permitted)} host=${host}`);
2722
+ }
2723
+ if (prefixBound && firstIndex >= 0) {
2724
+ const unstripped = keptThinkingIndex >= 0 && firstIndex <= keptThinkingIndex;
2725
+ const stripped = !unstripped && prior.keptThinkingIndex >= 0 && firstIndex <= prior.keptThinkingIndex;
2726
+ if (unstripped || stripped && permitted !== true) {
2727
+ events.push("thinking_prefix_change");
2728
+ count.thinkingPrefixChange += 1;
2729
+ sessionLog2(sessionId, `served check: a change in front of kept signed thinking on a prefix-bound model first_index=${firstIndex} kept_thinking_index=${keptThinkingIndex} recorded_thinking_index=${prior.keptThinkingIndex} thinking_stripped=${stripped} kind=${kind} permitted=${permittedLabel(permitted)} seen_by=${seenBy} host=${host}`);
2730
+ }
2731
+ }
2732
+ return finish({
2733
+ class: comparisonClass,
2734
+ firstIndex: reportedIndex,
2735
+ recorded: n,
2736
+ seenBy,
2737
+ keptThinkingIndex,
2738
+ recordedThinkingIndex: prior.keptThinkingIndex,
2739
+ events
2740
+ }, full, full ? 0 : prior.passesSinceFull + 1);
2741
+ }
2742
+
2250
2743
  // ../plugin/src/hooks/magic-context/lkg-slot.ts
2251
2744
  var POSITIONAL_SYSTEM_KEY = "\x00mc-system:";
2252
2745
  function lkgInputIdentity(id, role, index) {
@@ -2390,7 +2883,7 @@ var DIGEST_CHUNK_BYTES = 64 * 1024;
2390
2883
  var digestChunk;
2391
2884
  function lkgContentDigestFromFields(fields) {
2392
2885
  lkgDigestsComputed += 1;
2393
- const hash = createHash5("sha256");
2886
+ const hash = createHash6("sha256");
2394
2887
  digestChunk ??= Buffer.allocUnsafe(DIGEST_CHUNK_BYTES);
2395
2888
  const chunk = digestChunk;
2396
2889
  let offset = 0;
@@ -2453,7 +2946,7 @@ function legacyLkgDigestFromFields(fields) {
2453
2946
  const value = typeof field === "symbol" ? field.description ?? "" : String(field);
2454
2947
  key += `${typeof field}:${value.length}:${value}\x00`;
2455
2948
  }
2456
- return createHash5("sha256").update(key).digest("base64url");
2949
+ return createHash6("sha256").update(key).digest("base64url");
2457
2950
  }
2458
2951
  function legacyLkgContentDigest(message) {
2459
2952
  const fields = flattenContentFields(withoutEmptyUserDiffSummary(message));
@@ -3912,7 +4405,7 @@ var ERROR_CLASSES = new Set([
3912
4405
  "unknown"
3913
4406
  ]);
3914
4407
  // ../plugin/src/tools/ctx-expand/render.ts
3915
- import { createHash as createHash6 } from "node:crypto";
4408
+ import { createHash as createHash7 } from "node:crypto";
3916
4409
  function recoveryParts(sessionId, message, attachments) {
3917
4410
  return attachments ? [...message.parts, ...attachments(sessionId, message.id)] : message.parts;
3918
4411
  }
@@ -4163,9 +4656,9 @@ function renderItemByTag2(db, sessionId, number, textIndexDomain = "part", attac
4163
4656
  const parts = [...message.parts, ...attached];
4164
4657
  const piText = parts.filter((part) => isRecord2(part) && part.type === "text");
4165
4658
  const part = tag.type === "file" ? attached.find((part) => isRecord2(part) && part.partIndex === index) ?? message.parts[index] : parts[index];
4166
- const matching = derived ? piText.filter((part) => isRecord2(part) && typeof part.text === "string" && createHash6("sha256").update(part.text).digest("hex") === derived[3]) : [];
4659
+ const matching = derived ? piText.filter((part) => isRecord2(part) && typeof part.text === "string" && createHash7("sha256").update(part.text).digest("hex") === derived[3]) : [];
4167
4660
  const selected = derived ? matching[Number(derived[4])] : textIndexDomain === "text" && tag.type !== "file" ? piText[index] : part;
4168
4661
  return selected ? renderPartFull(selected) ?? "" : `Tag ${number}'s original text part is no longer in stored history.`;
4169
4662
  }
4170
4663
 
4171
- export { LkgRecoveryFenceError, clearLkgFenceProcessState, lkgFenceRequiresRebuild, lkgRecoveryFenceUnclean, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, cancelAutoSearchWork, readSessionActivity, observeSessionActivity, backfillSessionActivity, readSessionMeta, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, isNoContentCompartment, HAS_COMPARTMENT_CONTENT_SQL, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, getCompartmentsByEndMessageId, appendCompartments, saveRecompStagingPass, getRecompStaging, clearRecompStaging, getRecompPartialRange, setRecompPartialRange, escapeXmlAttr, escapeXmlContent, getUncoveredCompartmentEndThrough, getUncoveredCompartmentEndsThrough, isPartialCompartmentEnd, readProjectDocsCanonical, providerResponseFailed, isSuccessfulProviderCompletion, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, clearPendingMaterialization, recordSystemRefreshOwnership, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, acknowledgeSystemPromptDelivery, deferDeliveredSystemRefresh, clearSystemPromptDelivery, saveLkgSlotToDb, loadPersistedLkgSlot, drainStaleLkgSlots, createDbLkgPersistence, replayLkg, registerLkgPersistence, LKG_SNAPSHOT_ARRAY, LKG_SNAPSHOT_OBJECT, LKG_SNAPSHOT_KEY, LKG_SNAPSHOT_STRING, LKG_SNAPSHOT_NUMBER, LKG_SNAPSHOT_BOOLEAN, LKG_SNAPSHOT_NULL, LKG_SNAPSHOT_UNDEFINED, contentSnapshotValue, signatureForFields, lkgContentFields, lkgContentDigestFromFields, isLegacyLkgDigest, legacyLkgDigestFromFields, lkgFieldsMatchDigest, exactReusablePrefix, incrementalLkgContentDigests, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, dropSlot, TOOL_SWEEP_SCOPED_MARKER, encodePiContentDecision, decodePiContentDecision, getPiContentDecisions, freezePiContentDecision, withNativeReplayWriteBarrier, getNativeReplayState, saveNativeToolInputs, addNativeReasoningIds, copySessionStateForClone, externalHistorianFailureReason, subprocessExitHistorianFailureReason, countHistorianRuns, recordHistorianRun, summarizeImportance, tallyFactsByCategory, queueMemoryMutation, getMemoryMutationsForRender, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationId, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, getSourceContents, recordSubagentInvocation, getLatestHistorianInvocationId, renderMessageByOrdinal2, renderVerboseRange2, renderVerboseRangeForTool2, renderItemByTag2 };
4664
+ export { LkgRecoveryFenceError, clearLkgFenceProcessState, lkgFenceRequiresRebuild, lkgRecoveryFenceUnclean, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, cancelAutoSearchWork, readSessionActivity, observeSessionActivity, backfillSessionActivity, readSessionMeta, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, isNoContentCompartment, HAS_COMPARTMENT_CONTENT_SQL, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, getCompartmentsByEndMessageId, appendCompartments, saveRecompStagingPass, getRecompStaging, clearRecompStaging, getRecompPartialRange, setRecompPartialRange, escapeXmlAttr, escapeXmlContent, getUncoveredCompartmentEndThrough, getUncoveredCompartmentEndsThrough, isPartialCompartmentEnd, readProjectDocsCanonical, providerResponseFailed, isSuccessfulProviderCompletion, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, clearPendingMaterialization, recordSystemRefreshOwnership, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, acknowledgeSystemPromptDelivery, deferDeliveredSystemRefresh, clearSystemPromptDelivery, saveLkgSlotToDb, loadPersistedLkgSlot, drainStaleLkgSlots, createDbLkgPersistence, replayLkg, beginServedRequest, noteServedPassPermission, noteServedReplay, countServedRefusal, dropServedRecord, commitServedRequest, registerLkgPersistence, LKG_SNAPSHOT_ARRAY, LKG_SNAPSHOT_OBJECT, LKG_SNAPSHOT_KEY, LKG_SNAPSHOT_STRING, LKG_SNAPSHOT_NUMBER, LKG_SNAPSHOT_BOOLEAN, LKG_SNAPSHOT_NULL, LKG_SNAPSHOT_UNDEFINED, contentSnapshotValue, signatureForFields, lkgContentFields, lkgContentDigestFromFields, isLegacyLkgDigest, legacyLkgDigestFromFields, lkgFieldsMatchDigest, exactReusablePrefix, incrementalLkgContentDigests, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, dropSlot, TOOL_SWEEP_SCOPED_MARKER, encodePiContentDecision, decodePiContentDecision, getPiContentDecisions, freezePiContentDecision, withNativeReplayWriteBarrier, getNativeReplayState, saveNativeToolInputs, addNativeReasoningIds, copySessionStateForClone, externalHistorianFailureReason, subprocessExitHistorianFailureReason, countHistorianRuns, recordHistorianRun, summarizeImportance, tallyFactsByCategory, queueMemoryMutation, getMemoryMutationsForRender, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationId, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, getSourceContents, recordSubagentInvocation, getLatestHistorianInvocationId, renderMessageByOrdinal2, renderVerboseRange2, renderVerboseRangeForTool2, renderItemByTag2 };
@@ -3,11 +3,11 @@ import {
3
3
  tagRevisionCountSql,
4
4
  tagRevisionKey,
5
5
  TAG_INSERT_CONFLICT_ROWS
6
- } from "./index-jxm4bvm4.js";
6
+ } from "./index-v858d5d1.js";
7
7
  import {
8
8
  getTagsBySession2,
9
9
  getTagsByNumbers2
10
- } from "./index-qcsjj9m0.js";
10
+ } from "./index-5n3e2gq5.js";
11
11
  import {
12
12
  inRootAsyncContext2,
13
13
  getSqliteDatabasePath2,