@cortexkit/pi-magic-context 0.49.52 → 0.49.53

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 (27) hide show
  1. package/dist/auto-search-worker.js +3 -3
  2. package/dist/chunk-embedding-write-worker.js +1 -1
  3. package/dist/{embedding-backfill-fbhpk2yy.js → embedding-backfill-ad4k8e3f.js} +2 -2
  4. package/dist/{index-mb34ngfr.js → index-1tk6065b.js} +25 -14
  5. package/dist/{index-r6dj8rm9.js → index-2yjpxzga.js} +9 -5
  6. package/dist/{index-73c292h9.js → index-4cmj48mq.js} +3 -3
  7. package/dist/{index-fec4ezww.js → index-8cgk0pyh.js} +51 -14
  8. package/dist/{index-1cvyaw9a.js → index-8d2z6503.js} +1 -1
  9. package/dist/{index-cc73przv.js → index-a70dwgff.js} +7 -7
  10. package/dist/{index-akmmkmhf.js → index-f07s5m8x.js} +504 -9
  11. package/dist/{index-ktez4jwz.js → index-nevbaezn.js} +7 -6
  12. package/dist/{index-ty2m0s0s.js → index-njd3qa8e.js} +1 -1
  13. package/dist/{index-0hewsw7v.js → index-snrkpmpf.js} +1 -1
  14. package/dist/{index-rjz01pvv.js → index-tv9pqeek.js} +1 -1
  15. package/dist/index.js +663 -144
  16. package/dist/{message-index-bounded-d50b5f2z.js → message-index-bounded-hwatm90p.js} +2 -2
  17. package/dist/migration-worker.js +1 -1
  18. package/dist/{project-embedding-registry-hpca84nz.js → project-embedding-registry-d67axw7r.js} +3 -1
  19. package/dist/raw-ordinal-warmup-worker.js +3 -3
  20. package/dist/{read-session-chunk-9yr9mava.js → read-session-chunk-mj91mv8r.js} +1 -1
  21. package/dist/{render-3s7kbr61.js → render-js5tkc4g.js} +4 -4
  22. package/dist/{search-archive-dd1z7xn0.js → search-archive-159s0qp9.js} +4 -4
  23. package/dist/{search-2vgt4717.js → search-hyc5s9t0.js} +6 -6
  24. package/dist/subagent-entry.js +11 -11
  25. package/dist/tag-snapshot-worker-pi.js +1 -1
  26. package/dist/{v2-archive-reader-6jbyaafn.js → v2-archive-reader-5sc0rsh9.js} +1 -1
  27. package/package.json +3 -1
@@ -11,6 +11,7 @@ import {
11
11
  sessionLog2
12
12
  } from "./index-yxeg8zaa.js";
13
13
  import {
14
+ isPrefixBoundThinkingModel,
14
15
  MERGED_REASONING_PARTS_PREFIX,
15
16
  decodeMergedReasoningParts,
16
17
  SESSION_META_SELECT_COLUMNS,
@@ -39,7 +40,7 @@ import {
39
40
  expandToolPart,
40
41
  visitRawSessionMessages2,
41
42
  readRawSessionMessageById2
42
- } from "./index-fec4ezww.js";
43
+ } from "./index-8cgk0pyh.js";
43
44
  import {
44
45
  isRecord,
45
46
  providerVisibleMessage,
@@ -64,7 +65,7 @@ import {
64
65
  import {
65
66
  isPidAlive,
66
67
  readProcessStartTime
67
- } from "./index-rjz01pvv.js";
68
+ } from "./index-tv9pqeek.js";
68
69
  import {
69
70
  gaDatabasePath2,
70
71
  V2StoreReader2
@@ -1297,7 +1298,7 @@ function getUncoveredCompartmentEndsThrough(db, sessionId, endOrdinal = Number.M
1297
1298
  const rows = db.prepare(`SELECT k.end_message_id, k.end_message,
1298
1299
  n.start_message_id AS successor_id, n.start_message AS successor_start FROM compartments k
1299
1300
  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
1301
+ WHERE k.session_id = ? AND k.end_message <= ? AND k.end_message > ? AND k.end_block_index IS NOT NULL
1301
1302
  AND NOT COALESCE(n.sequence IS NOT NULL AND (
1302
1303
  (n.start_message_id = k.end_message_id AND n.start_block_index > k.end_block_index)
1303
1304
  OR n.start_message = k.end_message + 1), 0)
@@ -1438,7 +1439,7 @@ function readProjectDocsCanonical(projectDirectory) {
1438
1439
  return { renderedBlock, canonicalHash };
1439
1440
  }
1440
1441
  // ../plugin/src/hooks/magic-context/lkg-slot.ts
1441
- import { createHash as createHash5 } from "node:crypto";
1442
+ import { createHash as createHash6 } from "node:crypto";
1442
1443
 
1443
1444
  // ../plugin/src/shared/provider-response-completion.ts
1444
1445
  function providerResponseFailed(input) {
@@ -2238,8 +2239,10 @@ function replayLkg(args) {
2238
2239
 
2239
2240
  // ../plugin/src/hooks/magic-context/lkg-recovery-prefix.ts
2240
2241
  var sessions = new BoundedSessionMap(1000);
2242
+ var restartHeadChecked = new BoundedSessionMap(1000);
2241
2243
  function clearLkgRecoverySession(sessionId) {
2242
2244
  sessions.delete(sessionId);
2245
+ restartHeadChecked.delete(sessionId);
2243
2246
  clearLkgFenceProcessState(sessionId);
2244
2247
  }
2245
2248
  function noteLkgCapturedPrefix(sessionId) {
@@ -2247,6 +2250,498 @@ function noteLkgCapturedPrefix(sessionId) {
2247
2250
  sessions.set(sessionId, {});
2248
2251
  }
2249
2252
 
2253
+ // ../plugin/src/hooks/magic-context/served-check.ts
2254
+ import { createHash as createHash5 } from "node:crypto";
2255
+ var RECORD_SESSIONS = 256;
2256
+ var records = new BoundedSessionMap(RECORD_SESSIONS);
2257
+ var pending4 = new BoundedSessionMap(1000);
2258
+ var counters = new BoundedSessionMap(1000);
2259
+ var SERVED_FULL_CHECK_INTERVAL = 100;
2260
+ var COUNT_LOG_INTERVAL = 100;
2261
+ var HEAD_MIN = 2;
2262
+ var HEAD_MAX = 4;
2263
+ var lastWork = { fingerprinted: 0, digested: 0, full: false, ms: 0, shapeMs: 0 };
2264
+ function emptyCounters() {
2265
+ return {
2266
+ commits: 0,
2267
+ compared: 0,
2268
+ unknown: 0,
2269
+ refused: 0,
2270
+ appendOnly: 0,
2271
+ changed: 0,
2272
+ shorter: 0,
2273
+ modelChanged: 0,
2274
+ unpermittedChange: 0,
2275
+ mixedReplay: 0,
2276
+ thinkingPrefixChange: 0,
2277
+ sameShapeChange: 0,
2278
+ fullChecks: 0
2279
+ };
2280
+ }
2281
+ function countersFor(sessionId) {
2282
+ let value = counters.get(sessionId);
2283
+ if (!value) {
2284
+ value = emptyCounters();
2285
+ counters.set(sessionId, value);
2286
+ }
2287
+ return value;
2288
+ }
2289
+ function pendingFor(sessionId) {
2290
+ let value = pending4.get(sessionId);
2291
+ if (!value) {
2292
+ value = {};
2293
+ pending4.set(sessionId, value);
2294
+ }
2295
+ return value;
2296
+ }
2297
+ function beginServedRequest(sessionId) {
2298
+ pending4.delete(sessionId);
2299
+ }
2300
+ function noteServedPassPermission(sessionId, permission) {
2301
+ pendingFor(sessionId).permission = permission;
2302
+ }
2303
+ function noteServedReplay(sessionId) {
2304
+ pendingFor(sessionId).replay = true;
2305
+ }
2306
+ function countServedRefusal(sessionId) {
2307
+ try {
2308
+ pending4.delete(sessionId);
2309
+ countersFor(sessionId).refused += 1;
2310
+ } catch {}
2311
+ }
2312
+ function dropServedRecord(sessionId, reason) {
2313
+ try {
2314
+ const value = counters.peek(sessionId);
2315
+ if (value && value.commits + value.refused > 0)
2316
+ logCounts(sessionId, value, reason);
2317
+ if (records.has(sessionId))
2318
+ sessionLog2(sessionId, `served check: record dropped reason=${reason}; the next request is not compared`);
2319
+ } catch {}
2320
+ records.delete(sessionId);
2321
+ pending4.delete(sessionId);
2322
+ counters.delete(sessionId);
2323
+ }
2324
+ function logCounts(sessionId, value, reason) {
2325
+ 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}`);
2326
+ }
2327
+ function mix(hash, value) {
2328
+ return Math.imul(hash ^ (value | 0), 16777619);
2329
+ }
2330
+ function mixName(hash, value) {
2331
+ if (typeof value !== "string")
2332
+ return mix(hash, value === undefined ? -1 : -2);
2333
+ const length = value.length;
2334
+ const h = mix(hash, length);
2335
+ return length === 0 ? h : mix(h, value.charCodeAt(length - 1) << 16 | value.charCodeAt(length >> 1));
2336
+ }
2337
+ function mixId(hash, value) {
2338
+ if (typeof value !== "string")
2339
+ return mix(hash, value === undefined ? -1 : -2);
2340
+ const length = value.length;
2341
+ let h = mix(hash, length);
2342
+ const stop = length > 8 ? length - 8 : 0;
2343
+ let index = length - 1;
2344
+ for (;index > stop; index -= 2)
2345
+ h = mix(h, value.charCodeAt(index) << 16 | value.charCodeAt(index - 1));
2346
+ if (index === stop && length > 0)
2347
+ h = mix(h, value.charCodeAt(index));
2348
+ return h;
2349
+ }
2350
+ function mixNumber(hash, value) {
2351
+ const whole = Math.trunc(value);
2352
+ return mix(mix(mix(hash, whole), whole / 4294967296), Math.round((value - whole) * 1e6));
2353
+ }
2354
+ function mixLength(hash, value) {
2355
+ return typeof value === "string" ? mix(hash, value.length) : mix(hash, value === undefined ? -1 : -2);
2356
+ }
2357
+ function mixShallow(hash, value) {
2358
+ switch (typeof value) {
2359
+ case "string":
2360
+ return mix(mix(hash, 1), value.length);
2361
+ case "number":
2362
+ return mixNumber(mix(hash, 2), value);
2363
+ case "boolean":
2364
+ return mix(hash, value ? 5 : 4);
2365
+ case "undefined":
2366
+ return mix(hash, -1);
2367
+ case "object":
2368
+ if (value === null)
2369
+ return mix(hash, 3);
2370
+ if (Array.isArray(value))
2371
+ return mix(mix(hash, 9), value.length);
2372
+ {
2373
+ const size = value.byteLength;
2374
+ return typeof size === "number" ? mix(mix(hash, 7), size) : mix(hash, 10);
2375
+ }
2376
+ default:
2377
+ return mix(hash, 6);
2378
+ }
2379
+ }
2380
+ function mixToolState(hash, state) {
2381
+ let h = mixName(hash, state.status);
2382
+ h = mixShallow(h, state.input);
2383
+ h = mixShallow(h, state.output);
2384
+ if (state.error !== undefined)
2385
+ h = mixShallow(h, state.error);
2386
+ if (state.attachments !== undefined)
2387
+ h = mixShallow(h, state.attachments);
2388
+ if (state.content !== undefined)
2389
+ h = mixShallow(h, state.content);
2390
+ const time = state.time;
2391
+ h = mix(h, time && typeof time === "object" && time.compacted !== undefined ? 1 : 0);
2392
+ if (state.status === "error") {
2393
+ const metadata = state.metadata;
2394
+ if (metadata && typeof metadata === "object" && metadata.interrupted === true)
2395
+ h = mixShallow(h, metadata.output);
2396
+ }
2397
+ return h;
2398
+ }
2399
+ function isThinkingType(type) {
2400
+ return type === "reasoning" || type === "thinking" || type === "redacted_thinking";
2401
+ }
2402
+ function isKeptThinkingPart(part) {
2403
+ if (!isThinkingType(part.type) || part.ignored === true)
2404
+ return false;
2405
+ if (part.type === "redacted_thinking" || part.redacted === true)
2406
+ return true;
2407
+ if (typeof part.text === "string" && part.text !== "")
2408
+ return true;
2409
+ if (typeof part.thinking === "string" && part.thinking !== "")
2410
+ return true;
2411
+ const metadata = part.metadata;
2412
+ if (metadata && typeof metadata === "object") {
2413
+ for (const record of Object.values(metadata))
2414
+ if (record && typeof record === "object" && "redactedData" in record)
2415
+ return true;
2416
+ }
2417
+ return false;
2418
+ }
2419
+ var PART_FIELDS = [
2420
+ "text",
2421
+ "thinking",
2422
+ "thinkingSignature",
2423
+ "signature",
2424
+ "redacted",
2425
+ "data",
2426
+ "url",
2427
+ "mime",
2428
+ "mimeType",
2429
+ "mediaType",
2430
+ "filename",
2431
+ "name",
2432
+ "tool",
2433
+ "callID",
2434
+ "toolCallId",
2435
+ "input",
2436
+ "arguments",
2437
+ "output",
2438
+ "error",
2439
+ "isError",
2440
+ "providerExecuted",
2441
+ "synthetic",
2442
+ "ignored"
2443
+ ];
2444
+ var walkOut = { partThinking: false, messageThinking: false, messageHead: false };
2445
+ function mixPart(hash, rawPart) {
2446
+ walkOut.partThinking = false;
2447
+ if (!rawPart || typeof rawPart !== "object")
2448
+ return mix(hash, 11);
2449
+ const part = rawPart;
2450
+ const type = part.type;
2451
+ let h = mixId(mixName(hash, type), part.id);
2452
+ if (type === "text") {
2453
+ h = mixLength(h, part.text);
2454
+ return mix(h, (part.synthetic === true ? 1 : 0) | (part.ignored === true ? 2 : 0));
2455
+ }
2456
+ if (type === "tool" && part.state && typeof part.state === "object")
2457
+ return mixToolState(mixId(mixName(h, part.tool), part.callID), part.state);
2458
+ for (let index = 0;index < PART_FIELDS.length; index += 1) {
2459
+ const value = part[PART_FIELDS[index]];
2460
+ if (value !== undefined)
2461
+ h = mixShallow(mix(h, index), value);
2462
+ }
2463
+ const result = part.result;
2464
+ if (result && typeof result === "object") {
2465
+ h = mixName(h, result.type);
2466
+ h = mixShallow(h, result.value);
2467
+ }
2468
+ if (isThinkingType(type)) {
2469
+ walkOut.partThinking = isKeptThinkingPart(part);
2470
+ const metadata = part.metadata;
2471
+ const anthropic = metadata && typeof metadata === "object" ? metadata.anthropic : undefined;
2472
+ if (anthropic && typeof anthropic === "object") {
2473
+ h = mixShallow(h, anthropic.signature);
2474
+ h = mixShallow(h, anthropic.redactedData);
2475
+ } else
2476
+ h = mix(h, metadata && typeof metadata === "object" ? 17 : 18);
2477
+ }
2478
+ return h;
2479
+ }
2480
+ function messageShape(message) {
2481
+ const record = message && typeof message === "object" ? message : {};
2482
+ const info = record.info && typeof record.info === "object" ? record.info : record;
2483
+ const parts = Array.isArray(record.parts) ? record.parts : record.content;
2484
+ const role = info.role;
2485
+ let hash = mixId(2166136261, info.id);
2486
+ hash = mixName(hash, role);
2487
+ if (typeof record.timestamp === "number")
2488
+ hash = mixNumber(hash, record.timestamp);
2489
+ if (typeof record.toolCallId === "string")
2490
+ hash = mixId(hash, record.toolCallId);
2491
+ if (record.isError === true)
2492
+ hash = mix(hash, 12);
2493
+ if (info.summary === true)
2494
+ hash = mix(hash, 13);
2495
+ let thinking = false;
2496
+ let synthetic = info.synthetic === true || info.summary === true;
2497
+ if (typeof parts === "string") {
2498
+ hash = mix(mix(hash, 14), parts.length);
2499
+ } else if (Array.isArray(parts)) {
2500
+ hash = mix(mix(hash, 15), parts.length);
2501
+ let allSynthetic = parts.length > 0;
2502
+ for (const part of parts) {
2503
+ hash = mixPart(hash, part);
2504
+ if (walkOut.partThinking)
2505
+ thinking = true;
2506
+ if (allSynthetic && part?.synthetic !== true)
2507
+ allSynthetic = false;
2508
+ }
2509
+ if (allSynthetic)
2510
+ synthetic = true;
2511
+ } else {
2512
+ hash = mix(hash, 16);
2513
+ }
2514
+ walkOut.messageThinking = thinking && role === "assistant";
2515
+ walkOut.messageHead = synthetic || role === "system" || role === "compactionSummary" || role === "branchSummary";
2516
+ return hash >>> 0;
2517
+ }
2518
+ function digestInto(message, out, index) {
2519
+ let json;
2520
+ try {
2521
+ json = JSON.stringify(contentSnapshotValue(message));
2522
+ } catch {
2523
+ json = undefined;
2524
+ }
2525
+ if (json === undefined) {
2526
+ out[2 * index] = 0;
2527
+ out[2 * index + 1] = 0;
2528
+ return;
2529
+ }
2530
+ const digest = createHash5("sha256").update(json).digest();
2531
+ out[2 * index] = digest.readUInt32LE(0);
2532
+ out[2 * index + 1] = digest.readUInt32LE(4);
2533
+ }
2534
+ function digestsDiffer(a, ai, b, bi) {
2535
+ const a0 = a[2 * ai];
2536
+ const a1 = a[2 * ai + 1];
2537
+ const b0 = b[2 * bi];
2538
+ const b1 = b[2 * bi + 1];
2539
+ if (a0 === 0 && a1 === 0 || b0 === 0 && b1 === 0)
2540
+ return false;
2541
+ return a0 !== b0 || a1 !== b1;
2542
+ }
2543
+ function permittedLabel(permitted) {
2544
+ return permitted === null ? "unknown" : String(permitted);
2545
+ }
2546
+ function commitServedRequest(args) {
2547
+ try {
2548
+ return commit(args);
2549
+ } catch (error) {
2550
+ try {
2551
+ records.delete(args.sessionId);
2552
+ sessionLog2(args.sessionId, "served check failed; the record is unknown again:", error);
2553
+ } catch {}
2554
+ return null;
2555
+ }
2556
+ }
2557
+ function commit(args) {
2558
+ const { sessionId, messages, host } = args;
2559
+ const startedAt = performance.now();
2560
+ const note = pending4.peek(sessionId) ?? {};
2561
+ pending4.delete(sessionId);
2562
+ const count = countersFor(sessionId);
2563
+ const kind = note.replay ? "replay" : note.input ? "input" : "pass";
2564
+ const permission = note.permission;
2565
+ const permitted = permission?.permitted ?? (args.compactionOff ? false : kind === "input" ? false : null);
2566
+ const prior = records.get(sessionId);
2567
+ if (note.refused) {
2568
+ count.refused += 1;
2569
+ return {
2570
+ class: "refused",
2571
+ kind,
2572
+ firstIndex: null,
2573
+ recorded: prior?.count ?? 0,
2574
+ served: messages.length,
2575
+ seenBy: null,
2576
+ keptThinkingIndex: -1,
2577
+ recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
2578
+ permitted,
2579
+ events: []
2580
+ };
2581
+ }
2582
+ count.commits += 1;
2583
+ const m = messages.length;
2584
+ const providerID = note.model?.providerID ?? args.providerID;
2585
+ const modelID = note.model?.modelID ?? args.modelID;
2586
+ const prefixBound = isPrefixBoundThinkingModel(providerID, modelID);
2587
+ const modelKey = modelID ? `${providerID ?? ""}/${modelID}` : null;
2588
+ const shapes = new Uint32Array(m);
2589
+ let keptThinkingIndex = -1;
2590
+ let headCount = Math.min(HEAD_MIN, m);
2591
+ let leading = true;
2592
+ for (let index = 0;index < m; index += 1) {
2593
+ shapes[index] = messageShape(messages[index]);
2594
+ if (prefixBound && keptThinkingIndex < 0 && walkOut.messageThinking)
2595
+ keptThinkingIndex = index;
2596
+ if (leading && index >= HEAD_MIN) {
2597
+ if (walkOut.messageHead && index < HEAD_MAX)
2598
+ headCount = index + 1;
2599
+ else
2600
+ leading = false;
2601
+ }
2602
+ }
2603
+ const shapeMs = performance.now() - startedAt;
2604
+ const digests = new Uint32Array(2 * m);
2605
+ const computed = new Uint8Array(m);
2606
+ let digested = 0;
2607
+ const digest = (index) => {
2608
+ if (index < 0 || index >= m || computed[index])
2609
+ return;
2610
+ computed[index] = 1;
2611
+ digested += 1;
2612
+ digestInto(messages[index], digests, index);
2613
+ };
2614
+ const finish = (comparison, full, passesSinceFull) => {
2615
+ records.set(sessionId, {
2616
+ count: m,
2617
+ shapes,
2618
+ digests,
2619
+ modelKey: modelKey ?? prior?.modelKey ?? null,
2620
+ kind,
2621
+ keptThinkingIndex,
2622
+ passesSinceFull
2623
+ });
2624
+ lastWork = { fingerprinted: m, digested, full, ms: 0, shapeMs };
2625
+ if (count.commits % COUNT_LOG_INTERVAL === 0)
2626
+ logCounts(sessionId, count, "periodic");
2627
+ lastWork.ms = performance.now() - startedAt;
2628
+ return { ...comparison, kind, permitted, served: m };
2629
+ };
2630
+ const modelChanged = prior !== undefined && prior.modelKey !== null && modelKey !== null && prior.modelKey !== modelKey;
2631
+ if (!prior || modelChanged) {
2632
+ for (let index = 0;index < m; index += 1)
2633
+ digest(index);
2634
+ if (prior)
2635
+ count.modelChanged += 1;
2636
+ else
2637
+ count.unknown += 1;
2638
+ return finish({
2639
+ class: prior ? "model_change" : "unknown",
2640
+ firstIndex: null,
2641
+ recorded: prior?.count ?? 0,
2642
+ seenBy: null,
2643
+ keptThinkingIndex,
2644
+ recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
2645
+ events: []
2646
+ }, true, 0);
2647
+ }
2648
+ count.compared += 1;
2649
+ const n = prior.count;
2650
+ const overlap = Math.min(n, m);
2651
+ let shapeDiff = -1;
2652
+ for (let index = 0;index < overlap; index += 1)
2653
+ if (shapes[index] !== prior.shapes[index]) {
2654
+ shapeDiff = index;
2655
+ break;
2656
+ }
2657
+ for (let index = 0;index < headCount; index += 1)
2658
+ digest(index);
2659
+ digest(n - 1);
2660
+ digest(prior.keptThinkingIndex);
2661
+ digest(keptThinkingIndex);
2662
+ for (let index = n;index < m; index += 1)
2663
+ digest(index);
2664
+ let handfulDiff = -1;
2665
+ for (let index = 0;index < overlap; index += 1)
2666
+ if (computed[index] && digestsDiffer(digests, index, prior.digests, index)) {
2667
+ handfulDiff = index;
2668
+ break;
2669
+ }
2670
+ const full = kind === "replay" || prior.kind === "replay" || shapeDiff >= 0 || handfulDiff >= 0 || m < n || prior.passesSinceFull + 1 >= SERVED_FULL_CHECK_INTERVAL;
2671
+ let contentDiff = handfulDiff;
2672
+ if (full) {
2673
+ count.fullChecks += 1;
2674
+ for (let index = 0;index < m; index += 1)
2675
+ digest(index);
2676
+ contentDiff = -1;
2677
+ for (let index = 0;index < overlap; index += 1)
2678
+ if (digestsDiffer(digests, index, prior.digests, index)) {
2679
+ contentDiff = index;
2680
+ break;
2681
+ }
2682
+ } else {
2683
+ for (let index = 0;index < overlap; index += 1)
2684
+ if (!computed[index]) {
2685
+ digests[2 * index] = prior.digests[2 * index];
2686
+ digests[2 * index + 1] = prior.digests[2 * index + 1];
2687
+ }
2688
+ }
2689
+ const candidates = [shapeDiff, contentDiff].filter((value) => value >= 0);
2690
+ const firstIndex = candidates.length > 0 ? Math.min(...candidates) : -1;
2691
+ let comparisonClass;
2692
+ let seenBy = null;
2693
+ if (firstIndex >= 0) {
2694
+ comparisonClass = "changed";
2695
+ count.changed += 1;
2696
+ seenBy = shapeDiff >= 0 && shapeDiff === firstIndex ? "shape" : handfulDiff === firstIndex ? "digest" : "full";
2697
+ } else if (m < n) {
2698
+ comparisonClass = "shorter";
2699
+ count.shorter += 1;
2700
+ seenBy = "length";
2701
+ } else {
2702
+ comparisonClass = "append_only";
2703
+ count.appendOnly += 1;
2704
+ }
2705
+ const reportedIndex = firstIndex >= 0 ? firstIndex : comparisonClass === "shorter" ? m : null;
2706
+ const events = [];
2707
+ 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";
2708
+ if (reportedIndex !== null) {
2709
+ const after = n - reportedIndex;
2710
+ if (kind === "replay") {
2711
+ events.push("mixed_replay");
2712
+ count.mixedReplay += 1;
2713
+ 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}`);
2714
+ } else if (permitted !== true) {
2715
+ events.push("unpermitted_change");
2716
+ count.unpermittedChange += 1;
2717
+ 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}`);
2718
+ }
2719
+ }
2720
+ if (firstIndex >= 0 && shapeDiff !== firstIndex) {
2721
+ events.push("same_shape_change");
2722
+ count.sameShapeChange += 1;
2723
+ sessionLog2(sessionId, `served check: content changed with the same shape first_index=${firstIndex} seen_by=${seenBy} kind=${kind} permitted=${permittedLabel(permitted)} host=${host}`);
2724
+ }
2725
+ if (prefixBound && firstIndex >= 0) {
2726
+ const unstripped = keptThinkingIndex >= 0 && firstIndex <= keptThinkingIndex;
2727
+ const stripped = !unstripped && prior.keptThinkingIndex >= 0 && firstIndex <= prior.keptThinkingIndex;
2728
+ if (unstripped || stripped && permitted !== true) {
2729
+ events.push("thinking_prefix_change");
2730
+ count.thinkingPrefixChange += 1;
2731
+ 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}`);
2732
+ }
2733
+ }
2734
+ return finish({
2735
+ class: comparisonClass,
2736
+ firstIndex: reportedIndex,
2737
+ recorded: n,
2738
+ seenBy,
2739
+ keptThinkingIndex,
2740
+ recordedThinkingIndex: prior.keptThinkingIndex,
2741
+ events
2742
+ }, full, full ? 0 : prior.passesSinceFull + 1);
2743
+ }
2744
+
2250
2745
  // ../plugin/src/hooks/magic-context/lkg-slot.ts
2251
2746
  var POSITIONAL_SYSTEM_KEY = "\x00mc-system:";
2252
2747
  function lkgInputIdentity(id, role, index) {
@@ -2390,7 +2885,7 @@ var DIGEST_CHUNK_BYTES = 64 * 1024;
2390
2885
  var digestChunk;
2391
2886
  function lkgContentDigestFromFields(fields) {
2392
2887
  lkgDigestsComputed += 1;
2393
- const hash = createHash5("sha256");
2888
+ const hash = createHash6("sha256");
2394
2889
  digestChunk ??= Buffer.allocUnsafe(DIGEST_CHUNK_BYTES);
2395
2890
  const chunk = digestChunk;
2396
2891
  let offset = 0;
@@ -2453,7 +2948,7 @@ function legacyLkgDigestFromFields(fields) {
2453
2948
  const value = typeof field === "symbol" ? field.description ?? "" : String(field);
2454
2949
  key += `${typeof field}:${value.length}:${value}\x00`;
2455
2950
  }
2456
- return createHash5("sha256").update(key).digest("base64url");
2951
+ return createHash6("sha256").update(key).digest("base64url");
2457
2952
  }
2458
2953
  function legacyLkgContentDigest(message) {
2459
2954
  const fields = flattenContentFields(withoutEmptyUserDiffSummary(message));
@@ -3912,7 +4407,7 @@ var ERROR_CLASSES = new Set([
3912
4407
  "unknown"
3913
4408
  ]);
3914
4409
  // ../plugin/src/tools/ctx-expand/render.ts
3915
- import { createHash as createHash6 } from "node:crypto";
4410
+ import { createHash as createHash7 } from "node:crypto";
3916
4411
  function recoveryParts(sessionId, message, attachments) {
3917
4412
  return attachments ? [...message.parts, ...attachments(sessionId, message.id)] : message.parts;
3918
4413
  }
@@ -4163,9 +4658,9 @@ function renderItemByTag2(db, sessionId, number, textIndexDomain = "part", attac
4163
4658
  const parts = [...message.parts, ...attached];
4164
4659
  const piText = parts.filter((part) => isRecord2(part) && part.type === "text");
4165
4660
  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]) : [];
4661
+ const matching = derived ? piText.filter((part) => isRecord2(part) && typeof part.text === "string" && createHash7("sha256").update(part.text).digest("hex") === derived[3]) : [];
4167
4662
  const selected = derived ? matching[Number(derived[4])] : textIndexDomain === "text" && tag.type !== "file" ? piText[index] : part;
4168
4663
  return selected ? renderPartFull(selected) ?? "" : `Tag ${number}'s original text part is no longer in stored history.`;
4169
4664
  }
4170
4665
 
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 };
4666
+ 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 };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  withMessageFtsSessionFilter
3
- } from "./index-1cvyaw9a.js";
3
+ } from "./index-8d2z6503.js";
4
4
  import {
5
5
  estimateTokens
6
6
  } from "./index-7y60kyea.js";
7
7
  import {
8
8
  readRawSessionMessageIdOrdinalsForRange2
9
- } from "./index-fec4ezww.js";
9
+ } from "./index-8cgk0pyh.js";
10
10
 
11
11
  // ../plugin/src/tools/ctx-expand/search-archive.ts
12
12
  var archiveReadsOnThisThread = 0;
@@ -17,17 +17,18 @@ function renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnl
17
17
  const rows = db.prepare(sessionFirst ? `SELECT f.message_ordinal AS ordinal, f.message_id AS id, f.role, f.content
18
18
  FROM message_fts_rowid_map AS m
19
19
  JOIN message_history_fts AS f ON f.rowid = m.fts_rowid
20
- WHERE m.session_id = ?1 AND m.message_ordinal BETWEEN ?2 AND ?3
21
- AND f.session_id = ?1 AND f.message_ordinal BETWEEN ?2 AND ?3
20
+ WHERE m.session_id = ? AND m.message_ordinal BETWEEN ? AND ?
21
+ AND f.session_id = ? AND f.message_ordinal BETWEEN ? AND ?
22
22
  ORDER BY m.message_ordinal` : `SELECT message_ordinal AS ordinal, message_id AS id, role, content
23
23
  FROM message_history_fts
24
- WHERE session_id = ?1 AND message_ordinal BETWEEN ?2 AND ?3
24
+ WHERE session_id = ? AND message_ordinal BETWEEN ? AND ?
25
25
  ORDER BY CAST(message_ordinal AS INTEGER)`);
26
26
  const blocks = [];
27
27
  let tokens = 0;
28
28
  let lastOrdinal = start - 1;
29
29
  let truncated = false;
30
- for (const row of rows.iterate(sessionId, start, end)) {
30
+ const bindings = sessionFirst ? [sessionId, start, end, sessionId, start, end] : [sessionId, start, end];
31
+ for (const row of rows.iterate(...bindings)) {
31
32
  if (!row.content)
32
33
  continue;
33
34
  if (!archiveOnly) {
@@ -15,7 +15,7 @@ import {
15
15
  OpenAICompatibleEmbeddingProvider,
16
16
  getProjectEmbeddingSnapshot2,
17
17
  embedBatchForProject2
18
- } from "./index-r6dj8rm9.js";
18
+ } from "./index-2yjpxzga.js";
19
19
  import {
20
20
  isEmbeddingHostBusy2
21
21
  } from "./index-9p40dgkm.js";
@@ -9,7 +9,7 @@ import {
9
9
  } from "./index-7y60kyea.js";
10
10
  import {
11
11
  cleanUserText2
12
- } from "./index-fec4ezww.js";
12
+ } from "./index-8cgk0pyh.js";
13
13
  import {
14
14
  recordMessageFtsRowid2,
15
15
  recordIndexedMessageTime2,
@@ -1789,7 +1789,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1789
1789
  state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
1790
1790
  if (signal.aborted || !readsOpenCodeStore)
1791
1791
  return;
1792
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-9yr9mava.js"));
1792
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-mj91mv8r.js"));
1793
1793
  const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-krre2qnb.js"));
1794
1794
  if (signal.aborted)
1795
1795
  return;