@cortexkit/opencode-magic-context 0.49.5 → 0.49.7

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 (156) hide show
  1. package/dist/auto-search-worker.js +10 -7
  2. package/dist/{compaction-marker-candidates-dd638ypn.js → compaction-marker-candidates-a0edbqrr.js} +2 -2
  3. package/dist/compaction-marker-candidates-worker.js +2 -2
  4. package/dist/{conflict-warning-hook-ae8nmv7c.js → conflict-warning-hook-myk5hbt9.js} +5 -5
  5. package/dist/{context-yg023c5r.js → context-ffr7e0g7.js} +46 -34
  6. package/dist/{embedding-backfill-aj488s8x.js → embedding-backfill-re16xncd.js} +6 -6
  7. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  8. package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts +6 -3
  9. package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts.map +1 -1
  10. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts +7 -1
  11. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts.map +1 -1
  12. package/dist/features/magic-context/dreamer/map-memories.d.ts +2 -2
  13. package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
  14. package/dist/features/magic-context/dreamer/primer-seed.d.ts +2 -0
  15. package/dist/features/magic-context/dreamer/primer-seed.d.ts.map +1 -1
  16. package/dist/features/magic-context/dreamer/refresh-primers.d.ts +2 -2
  17. package/dist/features/magic-context/storage-clone.d.ts.map +1 -1
  18. package/dist/features/magic-context/storage-meta-persisted.d.ts +10 -3
  19. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  20. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  21. package/dist/features/magic-context/storage-replay-document.d.ts +4 -0
  22. package/dist/features/magic-context/storage-replay-document.d.ts.map +1 -1
  23. package/dist/hooks/magic-context/apply-operations.d.ts +7 -0
  24. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  25. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  26. package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
  27. package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
  28. package/dist/hooks/magic-context/note-nudger.d.ts +5 -3
  29. package/dist/hooks/magic-context/note-nudger.d.ts.map +1 -1
  30. package/dist/hooks/magic-context/postprocess-read-cache.d.ts.map +1 -1
  31. package/dist/hooks/magic-context/read-session-chunk.d.ts +7 -0
  32. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  33. package/dist/hooks/magic-context/replay-committed-drops.d.ts +9 -0
  34. package/dist/hooks/magic-context/replay-committed-drops.d.ts.map +1 -0
  35. package/dist/hooks/magic-context/rust-lkg-freeze-registry.d.ts +2 -2
  36. package/dist/hooks/magic-context/rust-lkg-freeze-registry.d.ts.map +1 -1
  37. package/dist/hooks/magic-context/rust-mode-transform.d.ts +3 -0
  38. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  39. package/dist/hooks/magic-context/rust-served-raw.d.ts +29 -0
  40. package/dist/hooks/magic-context/rust-served-raw.d.ts.map +1 -0
  41. package/dist/hooks/magic-context/strip-content.d.ts +23 -24
  42. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  43. package/dist/hooks/magic-context/tag-messages.d.ts +2 -0
  44. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  45. package/dist/hooks/magic-context/tool-drop-target.d.ts +2 -0
  46. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  47. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  48. package/dist/{index-m4p77myp.js → index-0gyq3djm.js} +1 -1
  49. package/dist/{index-jpm52v9x.js → index-37q80veb.js} +1 -1
  50. package/dist/{index-znzgze2v.js → index-4btknbqh.js} +9 -8
  51. package/dist/{index-v4bqjy56.js → index-5tbvdff4.js} +59 -28
  52. package/dist/{index-7jzrrxap.js → index-9yyqq3mm.js} +1 -1
  53. package/dist/{index-qvr78ej6.js → index-a8acx4gc.js} +2 -2
  54. package/dist/{index-gcdb3rqw.js → index-ax2jhztn.js} +1 -1
  55. package/dist/{index-2mqps3c1.js → index-ebnngykq.js} +145 -94
  56. package/dist/{index-41gqa557.js → index-g8qbdb03.js} +1 -1
  57. package/dist/{index-fst3t0d9.js → index-j58gqrn2.js} +65 -65
  58. package/dist/{index-xfbfrngb.js → index-j5hce1ab.js} +2 -2
  59. package/dist/{index-kb9nn0a0.js → index-j8epsc0g.js} +35 -14
  60. package/dist/{index-7zg9dvx0.js → index-n5a170gs.js} +227 -38
  61. package/dist/{index-fjtgekd4.js → index-n7kwfw2r.js} +4 -4
  62. package/dist/{index-dd18gej8.js → index-rwmpkss5.js} +3 -3
  63. package/dist/{index-7w18gg78.js → index-rzmjkdd6.js} +1 -1
  64. package/dist/{index-c0b01zrc.js → index-sf94at64.js} +3 -3
  65. package/dist/{index-yxawqmdd.js → index-sh91t19a.js} +1 -1
  66. package/dist/{index-x3y1np1h.js → index-tagss15p.js} +857 -125
  67. package/dist/{index-yqps2zsv.js → index-tmtty2x5.js} +1 -1
  68. package/dist/{index-bhk710rw.js → index-vt4sf4ep.js} +1 -1
  69. package/dist/{index-6m7rdv7y.js → index-w4mw92w3.js} +1 -1
  70. package/dist/{index-7ndnvw7a.js → index-w6bd03dc.js} +1 -1
  71. package/dist/{index-p2hs3rps.js → index-w6vr754t.js} +4 -4
  72. package/dist/{index-3wckxwfp.js → index-wq16ahsn.js} +5 -5
  73. package/dist/index.js +36 -36
  74. package/dist/{message-index-bounded-pv6ct15d.js → message-index-bounded-04rycpx4.js} +9 -9
  75. package/dist/{message-index-jqa7qd0s.js → message-index-rqtse28y.js} +9 -9
  76. package/dist/{message-time-backfill-8x06r9kx.js → message-time-backfill-a5ytnp53.js} +1 -1
  77. package/dist/migration-worker.js +6 -6
  78. package/dist/plugin/messages-transform.d.ts.map +1 -1
  79. package/dist/{project-embedding-registry-fcmszatg.js → project-embedding-registry-k0sd9k7v.js} +5 -5
  80. package/dist/raw-ordinal-warmup-worker.js +17 -15
  81. package/dist/{read-session-chunk-cwgjwjd0.js → read-session-chunk-h1btx938.js} +7 -5
  82. package/dist/{read-session-raw-z38cn0as.js → read-session-raw-vdf4wh78.js} +2 -2
  83. package/dist/{recomp-orchestrator-xw9wt5bm.js → recomp-orchestrator-trcgmm23.js} +20 -20
  84. package/dist/{search-v1t47s2q.js → search-3rbdx6hw.js} +16 -16
  85. package/dist/{send-session-notification-yp9m5g4p.js → send-session-notification-2tp44tfa.js} +4 -4
  86. package/dist/shared/processed-image-eligibility.d.ts +22 -0
  87. package/dist/shared/processed-image-eligibility.d.ts.map +1 -0
  88. package/dist/shared/recovery-reasoning-prefix.d.ts +9 -0
  89. package/dist/shared/recovery-reasoning-prefix.d.ts.map +1 -0
  90. package/dist/shared/sqlite.d.ts +1 -1
  91. package/dist/shared/sqlite.d.ts.map +1 -1
  92. package/dist/shared/tag-transcript.d.ts +9 -0
  93. package/dist/shared/tag-transcript.d.ts.map +1 -1
  94. package/dist/{sqlite-mhjkerzq.js → sqlite-j3tvg8r0.js} +1 -1
  95. package/dist/{storage-memory-07fx57k6.js → storage-memory-8168bgef.js} +2 -2
  96. package/dist/{storage-tags-0ssbmzg9.js → storage-tags-61z5j2f9.js} +2 -2
  97. package/dist/tools/ctx-expand/search-archive.d.ts +4 -0
  98. package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -0
  99. package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
  100. package/dist/{transform-postprocess-phase-ttra554y.js → transform-postprocess-phase-7qts7h54.js} +20 -20
  101. package/dist/v2/auto-search-worker.js +10 -7
  102. package/dist/v2/{compaction-marker-candidates-1s21e2fz.js → compaction-marker-candidates-6nypjkpf.js} +2 -2
  103. package/dist/v2/compaction-marker-candidates-worker.js +2 -2
  104. package/dist/v2/{context-6en6a8ar.js → context-xq4rtywr.js} +1019 -233
  105. package/dist/v2/{embedding-backfill-9hbkfvnz.js → embedding-backfill-xd9ygzgd.js} +6 -6
  106. package/dist/v2/hooks/payload.d.ts.map +1 -1
  107. package/dist/v2/{message-index-h8ssgq3q.js → message-index-8e5z2xx8.js} +9 -9
  108. package/dist/v2/{message-index-bounded-c0810p5w.js → message-index-bounded-5vh1h2g7.js} +9 -9
  109. package/dist/v2/{message-time-backfill-cje68egj.js → message-time-backfill-2z365239.js} +1 -1
  110. package/dist/v2/migration-worker.js +6 -6
  111. package/dist/v2/{project-embedding-registry-42th7k1z.js → project-embedding-registry-b77awytr.js} +5 -5
  112. package/dist/v2/raw-ordinal-warmup-worker.js +17 -15
  113. package/dist/v2/{read-session-chunk-n86v9xfg.js → read-session-chunk-4sat83cx.js} +7 -5
  114. package/dist/v2/{read-session-raw-3b3ehga4.js → read-session-raw-a3hw9jsp.js} +2 -2
  115. package/dist/v2/{recomp-orchestrator-krvsbnds.js → recomp-orchestrator-n11zv1f1.js} +19 -19
  116. package/dist/v2/{search-048v8y02.js → search-mvgqtkkz.js} +16 -16
  117. package/dist/v2/{send-session-notification-a4h2azxa.js → send-session-notification-ppgc8qdz.js} +4 -4
  118. package/dist/v2/{server-cvgn49tr.js → server-1rfgbjfn.js} +1 -1
  119. package/dist/v2/{server-3bc6k4k4.js → server-7srtwsa4.js} +5 -5
  120. package/dist/v2/{server-7jzrrxap.js → server-9yyqq3mm.js} +1 -1
  121. package/dist/v2/{server-2htmbqbv.js → server-brhj8qtd.js} +1 -1
  122. package/dist/v2/{server-3dqjhchy.js → server-dd0nja67.js} +1 -1
  123. package/dist/v2/{server-8wcf79fe.js → server-fpqe39as.js} +1 -1
  124. package/dist/v2/{server-cjz51jm2.js → server-fw31krgq.js} +3 -3
  125. package/dist/v2/{server-4n2tknpc.js → server-gtv9wbhq.js} +227 -38
  126. package/dist/v2/{server-8pqnnmf9.js → server-hcvcxzx7.js} +2 -2
  127. package/dist/v2/{server-kb9nn0a0.js → server-j8epsc0g.js} +35 -14
  128. package/dist/v2/{server-rygvffsf.js → server-jdwd03ep.js} +4 -4
  129. package/dist/v2/{server-q6j5dasr.js → server-kdrezdy0.js} +1 -1
  130. package/dist/v2/{server-e2v4m8xe.js → server-mv1w7t6z.js} +61 -30
  131. package/dist/v2/{server-hetyb88z.js → server-nfan6zb6.js} +65 -65
  132. package/dist/v2/{server-4enr7s6x.js → server-qcw43339.js} +1 -1
  133. package/dist/v2/{server-5zrpr764.js → server-sy4b1sra.js} +1 -1
  134. package/dist/v2/{server-9a6v0wth.js → server-v4fwha43.js} +9 -8
  135. package/dist/v2/{server-pcygfdbs.js → server-w3zeywp1.js} +1 -1
  136. package/dist/v2/{server-czb2rkpk.js → server-wkdgjjch.js} +1 -1
  137. package/dist/v2/{server-9290a1mb.js → server-x08d1xf3.js} +1 -1
  138. package/dist/v2/server.js +4 -4
  139. package/dist/v2/{sqlite-mhjkerzq.js → sqlite-j3tvg8r0.js} +1 -1
  140. package/dist/v2/{storage-memory-07fx57k6.js → storage-memory-8168bgef.js} +2 -2
  141. package/dist/v2/{storage-tags-3a4cavqb.js → storage-tags-j2fzq3sw.js} +2 -2
  142. package/dist/v2/{wrapup-orchestrator-r2v7kgy3.js → wrapup-orchestrator-s92ebfzv.js} +19 -19
  143. package/dist/{wrapup-orchestrator-z7agncp8.js → wrapup-orchestrator-df61jmz9.js} +21 -21
  144. package/package.json +3 -3
  145. package/src/shared/processed-image-eligibility.test.ts +68 -0
  146. package/src/shared/processed-image-eligibility.ts +41 -0
  147. package/src/shared/processed-image-position-review.json +20 -0
  148. package/src/shared/processed-image-position-review.test.ts +19 -0
  149. package/src/shared/recovery-reasoning-prefix.test.ts +34 -0
  150. package/src/shared/recovery-reasoning-prefix.ts +35 -0
  151. package/src/shared/sqlite-acquisition-routing.test.ts +4 -3
  152. package/src/shared/sqlite-foreground-wait.test.ts +140 -0
  153. package/src/shared/sqlite-pass-scope.test.ts +4 -4
  154. package/src/shared/sqlite-writer-diagnostics.test.ts +31 -0
  155. package/src/shared/sqlite.ts +64 -23
  156. package/src/shared/tag-transcript.ts +118 -0
@@ -62,13 +62,14 @@ import {
62
62
  getTagsByNumbers2,
63
63
  getNewestToolTagNumbers2,
64
64
  getDroppedTagsByNumbers2,
65
+ getMaxDroppedTagNumber2,
65
66
  getTagById2,
66
67
  getToolTagNumberByOwner2,
67
68
  getNullOwnerToolTag2,
68
69
  adoptNullOwnerToolTag2,
69
70
  getCandidateToolOwners2,
70
71
  pickNearestPriorOwner2
71
- } from "./index-yqps2zsv.js";
72
+ } from "./index-tmtty2x5.js";
72
73
  import {
73
74
  textMentionsRecentCommit,
74
75
  hasMeaningfulUserText2,
@@ -83,7 +84,7 @@ import {
83
84
  getSqliteDatabasePath2,
84
85
  assertTransformWrite2,
85
86
  isTransientSqliteError2
86
- } from "./index-kb9nn0a0.js";
87
+ } from "./index-j8epsc0g.js";
87
88
  import {
88
89
  isValidLanguageCode
89
90
  } from "./index-k6xvbj2e.js";
@@ -91,7 +92,7 @@ import {
91
92
  getProjectEmbeddingSnapshot2,
92
93
  embedTextForProject2,
93
94
  embedBatchForProject2
94
- } from "./index-c0b01zrc.js";
95
+ } from "./index-sf94at64.js";
95
96
  import {
96
97
  isEmbeddingHostBusy2
97
98
  } from "./index-qt1qqasc.js";
@@ -140,6 +141,7 @@ import {
140
141
  addTrailingBlankDecisions,
141
142
  demoteTrailingBlankKeepDecisions,
142
143
  addStaleReduceStrippedIds,
144
+ getProcessedImageMarkers,
143
145
  addProcessedImageStrippedIds,
144
146
  getPendingCompactionMarkerState,
145
147
  loadPostprocessReplaySnapshot,
@@ -185,7 +187,7 @@ import {
185
187
  extractToolCallObservation,
186
188
  ToolMutationBatch,
187
189
  createToolDropTarget
188
- } from "./index-7zg9dvx0.js";
190
+ } from "./index-n5a170gs.js";
189
191
  import {
190
192
  getMaxM0MutationId,
191
193
  rememberUnpublishedAutoSearchNoHint,
@@ -219,21 +221,21 @@ import {
219
221
  peekNoteNudgeText,
220
222
  markNoteNudgeDelivered,
221
223
  getActiveCompartmentRun
222
- } from "./index-v4bqjy56.js";
224
+ } from "./index-5tbvdff4.js";
223
225
  import {
224
226
  runSessionWarmupWorker
225
- } from "./index-jpm52v9x.js";
227
+ } from "./index-37q80veb.js";
226
228
  import {
227
229
  openCodeDbExists,
228
230
  withReadOnlySessionDb,
229
231
  getMessageTimesFromOpenCodeDb
230
- } from "./index-qvr78ej6.js";
232
+ } from "./index-a8acx4gc.js";
231
233
  import {
232
234
  BoundedSessionMap
233
- } from "./index-3wckxwfp.js";
235
+ } from "./index-wq16ahsn.js";
234
236
  import {
235
237
  renderUserFacingFailure
236
- } from "./index-fjtgekd4.js";
238
+ } from "./index-n7kwfw2r.js";
237
239
  import {
238
240
  getErrorMessage
239
241
  } from "./index-y8v6yerm.js";
@@ -2765,21 +2767,40 @@ function buildReplacementContent(tagId) {
2765
2767
  return `[dropped §${tagId}§]`;
2766
2768
  }
2767
2769
  function applyNewToolDrop(target, options) {
2768
- if (!target)
2770
+ if (options.persist && (target?.prepareDrop?.() ?? target?.canDrop?.()) === false) {
2771
+ return { result: "incomplete", mode: "full" };
2772
+ }
2773
+ if (!target) {
2774
+ options.persist?.("full");
2769
2775
  return { result: "absent", mode: "full" };
2770
- if (options.inWindow && hasSmallToolInput(target) || options.keepSkeleton === true || target.cannotRemove?.() === true) {
2776
+ }
2777
+ if (options.inWindow && hasSmallToolInput(target) || options.keepSkeleton === true || target.cannotRemove?.() === true || target.wouldStrandConversationEnd?.() === true) {
2771
2778
  const strip = target.hasAttachments?.() === true;
2779
+ options.persist?.(strip ? "skeleton_stripped" : "skeleton_real");
2772
2780
  return {
2773
2781
  result: (strip ? target.skeletonStripped?.() : target.skeletonReal?.()) ?? "absent",
2774
2782
  mode: strip ? "skeleton_stripped" : "skeleton_real"
2775
2783
  };
2776
2784
  }
2785
+ options.persist?.("full");
2777
2786
  const result = target.drop?.() ?? "absent";
2778
2787
  if (result === "truncated" && target.hasAttachments?.() === true) {
2779
2788
  return { result: target.skeletonStripped?.() ?? "absent", mode: "skeleton_stripped" };
2780
2789
  }
2781
2790
  return { result, mode: result === "truncated" ? "skeleton_real" : "full" };
2782
2791
  }
2792
+ function applyPersistedToolDrop(db, sessionId, tagNumber, target, options, afterWrite) {
2793
+ return applyNewToolDrop(target, {
2794
+ ...options,
2795
+ persist: (mode) => {
2796
+ db.transaction(() => {
2797
+ updateTagDropMode2(db, sessionId, tagNumber, mode);
2798
+ updateTagStatus2(db, sessionId, tagNumber, "dropped");
2799
+ afterWrite?.();
2800
+ }).immediate();
2801
+ }
2802
+ });
2803
+ }
2783
2804
  function hasSmallToolInput(target) {
2784
2805
  const bytes = target?.inputStringBytes?.() ?? null;
2785
2806
  return bytes !== null && bytes <= SKELETON_REAL_INPUT_MAX_BYTES;
@@ -2859,11 +2880,11 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
2859
2880
  diagnostics.reasons[reason] = (diagnostics.reasons[reason] ?? 0) + 1;
2860
2881
  };
2861
2882
  let admitted = false;
2862
- let startedAt = 0;
2863
2883
  try {
2864
2884
  db.transaction(() => {
2865
2885
  admitted = true;
2866
- startedAt = performance.now();
2886
+ }).immediate();
2887
+ {
2867
2888
  const pendingOps = preloadedPendingOps ?? getPendingOps(db, sessionId);
2868
2889
  const tags = preloadedTags ?? getTagsByNumbers2(db, sessionId, [
2869
2890
  ...new Set([
@@ -2915,10 +2936,31 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
2915
2936
  continue;
2916
2937
  }
2917
2938
  }
2939
+ const persistDrop = (mode) => {
2940
+ let startedAt = 0;
2941
+ try {
2942
+ db.transaction(() => {
2943
+ startedAt = performance.now();
2944
+ if (mode)
2945
+ updateTagDropMode2(db, sessionId, pendingOp.tagId, mode);
2946
+ updateTagStatus2(db, sessionId, pendingOp.tagId, "dropped");
2947
+ if (!synthetic)
2948
+ removePendingOp(db, sessionId, pendingOp.tagId);
2949
+ }).immediate();
2950
+ } finally {
2951
+ if (startedAt)
2952
+ logSlowWriteTransaction("apply_pending_operation", startedAt);
2953
+ }
2954
+ };
2918
2955
  let shouldPersistDrop = false;
2919
2956
  if (isToolTag) {
2920
2957
  if (editMarkerTagIds.has(pendingOp.tagId)) {
2921
2958
  const strip = target?.hasAttachments?.() === true;
2959
+ if (target?.canDrop?.() === false || target?.prepareDrop?.() === false || !target) {
2960
+ reject("edit_marker_incomplete");
2961
+ continue;
2962
+ }
2963
+ persistDrop(strip ? "edit_marker_stripped" : "edit_marker");
2922
2964
  const markResult = (strip ? target?.editMarkerStripped?.() : target?.editMarker?.()) ?? "absent";
2923
2965
  if (markResult === "incomplete" || markResult === "absent") {
2924
2966
  reject(`edit_marker_${markResult}`);
@@ -2927,11 +2969,11 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
2927
2969
  didMutateMessage = true;
2928
2970
  operationMutated = true;
2929
2971
  onTagReduced?.({ tagNumber: pendingOp.tagId, mode: "edit_marker" });
2930
- updateTagDropMode2(db, sessionId, pendingOp.tagId, strip ? "edit_marker_stripped" : "edit_marker");
2931
2972
  shouldPersistDrop = true;
2932
2973
  } else {
2933
2974
  const { result: dropResult, mode: appliedMode } = applyNewToolDrop(target, {
2934
- inWindow: skeletonWindow.has(pendingOp.tagId)
2975
+ inWindow: skeletonWindow.has(pendingOp.tagId),
2976
+ persist: persistDrop
2935
2977
  });
2936
2978
  if (dropResult === "incomplete" || synthetic && dropResult !== "removed" && dropResult !== "truncated") {
2937
2979
  reject(`drop_${dropResult}`);
@@ -2947,12 +2989,12 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
2947
2989
  } else {
2948
2990
  reject(`drop_${dropResult}`);
2949
2991
  }
2950
- updateTagDropMode2(db, sessionId, pendingOp.tagId, appliedMode);
2951
2992
  shouldPersistDrop = true;
2952
2993
  }
2953
2994
  } else if (target) {
2954
2995
  const replacement = buildReplacementContent(pendingOp.tagId);
2955
2996
  const priorContent = target.getContent?.();
2997
+ persistDrop();
2956
2998
  const changed = target.setContent(replacement);
2957
2999
  if (changed) {
2958
3000
  didMutateMessage = true;
@@ -2969,30 +3011,25 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
2969
3011
  shouldPersistDrop = true;
2970
3012
  } else if (!synthetic) {
2971
3013
  reject("target_absent");
3014
+ persistDrop();
2972
3015
  shouldPersistDrop = true;
2973
3016
  }
2974
3017
  if (!shouldPersistDrop) {
2975
3018
  reject("not_persisted");
2976
3019
  continue;
2977
3020
  }
2978
- updateTagStatus2(db, sessionId, pendingOp.tagId, "dropped");
2979
- if (!synthetic)
2980
- removePendingOp(db, sessionId, pendingOp.tagId);
2981
3021
  if (operationMutated)
2982
3022
  diagnostics.mutated += 1;
2983
3023
  else
2984
3024
  diagnostics.persistedWithoutMutation += 1;
2985
3025
  }
2986
- }).immediate();
3026
+ }
2987
3027
  } catch (error) {
2988
3028
  if (!admitted && /database (?:table )?is locked|sqlite_(busy|locked)/i.test(String(error))) {
2989
3029
  sessionLog2(sessionId, "pending operations write admission busy; retaining prior bytes for retry");
2990
3030
  return false;
2991
3031
  }
2992
3032
  throw error;
2993
- } finally {
2994
- if (admitted)
2995
- logSlowWriteTransaction("apply_pending_operations", startedAt);
2996
3033
  }
2997
3034
  if (diagnostics) {
2998
3035
  onBatchComplete?.(diagnostics);
@@ -3281,31 +3318,27 @@ function applyHeuristicCleanup(sessionId, db, targets, messageTagNumbers, config
3281
3318
  if (plan.shouldDrop) {
3282
3319
  const toDrop = new Set(plan.tagNumbers);
3283
3320
  const newestEmergencyTags = recentTags;
3284
- db.transaction(() => {
3285
- for (const tag of tags) {
3286
- if (!toDrop.has(tag.tagNumber))
3287
- continue;
3288
- if (tag.status !== "active" || tag.type !== "tool")
3289
- continue;
3290
- const target = targets.get(tag.tagNumber);
3291
- const recent = (emergency.usagePercentage ?? 0) < 95 && newestEmergencyTags.has(tag.tagNumber);
3292
- const { result, mode } = applyNewToolDrop(target, {
3293
- inWindow: recent,
3294
- keepSkeleton: target?.requiresToolArcSkeleton === true
3321
+ for (const tag of tags) {
3322
+ if (!toDrop.has(tag.tagNumber))
3323
+ continue;
3324
+ if (tag.status !== "active" || tag.type !== "tool")
3325
+ continue;
3326
+ const target = targets.get(tag.tagNumber);
3327
+ const recent = (emergency.usagePercentage ?? 0) < 95 && newestEmergencyTags.has(tag.tagNumber);
3328
+ const { result } = applyPersistedToolDrop(db, sessionId, tag.tagNumber, target, {
3329
+ inWindow: recent,
3330
+ keepSkeleton: target?.requiresToolArcSkeleton === true
3331
+ });
3332
+ if (result === "removed" || result === "truncated") {
3333
+ droppedTools++;
3334
+ emergencyDroppedTools++;
3335
+ droppedTokenReductions.push({
3336
+ tagNumber: tag.tagNumber,
3337
+ mode: result === "removed" ? "full" : "truncated"
3295
3338
  });
3296
- if (result === "removed" || result === "truncated") {
3297
- updateTagStatus2(db, sessionId, tag.tagNumber, "dropped");
3298
- updateTagDropMode2(db, sessionId, tag.tagNumber, mode);
3299
- droppedTools++;
3300
- emergencyDroppedTools++;
3301
- droppedTokenReductions.push({
3302
- tagNumber: tag.tagNumber,
3303
- mode: result === "removed" ? "full" : "truncated"
3304
- });
3305
- emergencyReclaimedTokens += estimateEmergencyDropReclaimTokens(measuredByTag.get(tag.tagNumber) ?? tag);
3306
- }
3339
+ emergencyReclaimedTokens += estimateEmergencyDropReclaimTokens(measuredByTag.get(tag.tagNumber) ?? tag);
3307
3340
  }
3308
- }).immediate();
3341
+ }
3309
3342
  sessionLog2(sessionId, `emergency tiered drop: ${plan.reason}`);
3310
3343
  } else {
3311
3344
  sessionLog2(sessionId, `emergency tiered drop skipped: ${plan.reason}`);
@@ -3386,35 +3419,33 @@ function applyHeuristicCleanup(sessionId, db, targets, messageTagNumbers, config
3386
3419
  group.push(tag);
3387
3420
  fingerprintGroups.set(fingerprint, group);
3388
3421
  }
3389
- db.transaction(() => {
3390
- for (const [, group] of fingerprintGroups) {
3391
- if (group.length <= 1)
3422
+ for (const [, group] of fingerprintGroups) {
3423
+ if (group.length <= 1)
3424
+ continue;
3425
+ group.sort((a, b) => a.tagNumber - b.tagNumber);
3426
+ for (let i = 0;i < group.length - 1; i++) {
3427
+ const tag = group[i];
3428
+ if (config.protectedTagNumbers.has(tag.tagNumber))
3392
3429
  continue;
3393
- group.sort((a, b) => a.tagNumber - b.tagNumber);
3394
- for (let i = 0;i < group.length - 1; i++) {
3395
- const tag = group[i];
3396
- if (config.protectedTagNumbers.has(tag.tagNumber))
3397
- continue;
3398
- const target = targets.get(tag.tagNumber);
3399
- if (protectedTools.has(tag.tagNumber))
3400
- continue;
3401
- if (target?.canDrop?.() === false)
3402
- continue;
3403
- const { result, mode } = applyNewToolDrop(target, { inWindow: false });
3404
- if (result === "incomplete")
3405
- continue;
3406
- updateTagDropMode2(db, sessionId, tag.tagNumber, mode);
3407
- updateTagStatus2(db, sessionId, tag.tagNumber, "dropped");
3408
- if (result === "removed" || result === "truncated") {
3409
- deduplicatedTools++;
3410
- droppedTokenReductions.push({
3411
- tagNumber: tag.tagNumber,
3412
- mode: result === "removed" ? "full" : "truncated"
3413
- });
3414
- }
3430
+ const target = targets.get(tag.tagNumber);
3431
+ if (protectedTools.has(tag.tagNumber))
3432
+ continue;
3433
+ if (target?.canDrop?.() === false)
3434
+ continue;
3435
+ const { result } = applyPersistedToolDrop(db, sessionId, tag.tagNumber, target, {
3436
+ inWindow: false
3437
+ });
3438
+ if (result === "incomplete")
3439
+ continue;
3440
+ if (result === "removed" || result === "truncated") {
3441
+ deduplicatedTools++;
3442
+ droppedTokenReductions.push({
3443
+ tagNumber: tag.tagNumber,
3444
+ mode: result === "removed" ? "full" : "truncated"
3445
+ });
3415
3446
  }
3416
3447
  }
3417
- }).immediate();
3448
+ }
3418
3449
  }
3419
3450
  if (droppedTools > 0 || deduplicatedTools > 0 || droppedInjections > 0) {
3420
3451
  sessionLog2(sessionId, `heuristic cleanup: dropped ${droppedTools} tool tags, deduplicated ${deduplicatedTools} tool calls, dropped ${droppedInjections} system injections`);
@@ -3588,6 +3619,7 @@ function postprocessReplaySnapshot(db, sessionId) {
3588
3619
  ...replay,
3589
3620
  staleReduceStrippedIds: new Set(replay.staleReduceStrippedIds),
3590
3621
  processedImageStrippedIds: new Set(replay.processedImageStrippedIds),
3622
+ processedImageMarkers: new Map(replay.processedImageMarkers),
3591
3623
  strippedPlaceholderIds: new Set(replay.strippedPlaceholderIds),
3592
3624
  hiddenSeamPlaceholderIds: new Set(replay.hiddenSeamPlaceholderIds),
3593
3625
  mergedReasoningStrippedIds: new Set(replay.mergedReasoningStrippedIds),
@@ -4897,11 +4929,6 @@ function runRustModePostprocess2(args) {
4897
4929
  for (const anchor of getNoteNudgeAnchors(args.db, args.sessionId)) {
4898
4930
  appendReminderToUserMessageById(args.messages, anchor.messageId, anchor.text);
4899
4931
  }
4900
- for (const decision of getAutoSearchHintDecisions(args.db, args.sessionId)) {
4901
- if (decision.decision === "hint" && getUnpublishedAutoSearchNoHint(args.sessionId, decision.messageId) === undefined) {
4902
- appendReminderToUserMessageById(args.messages, decision.messageId, decision.text);
4903
- }
4904
- }
4905
4932
  const trailingBlankDecisions = new Map;
4906
4933
  const visibleAssistantIds = args.messages.filter((message) => message.info.role === "assistant").map((message) => message.info.id).filter((id) => typeof id === "string");
4907
4934
  if (modelAcceptsEmptyContent(args.resolvedProviderID)) {
@@ -4939,7 +4966,7 @@ function runRustModePostprocess2(args) {
4939
4966
  userMessageIds: args.messages.filter((m) => m.info.role === "user" && typeof m.info.id === "string").map((m) => m.info.id),
4940
4967
  anchorMessageId: currentUserMessageId,
4941
4968
  isLiveTail: args.messages.at(-1)?.info.id === currentUserMessageId,
4942
- isCacheBustingPass: args.cacheBustingPass === true
4969
+ prefixRewriteCoversAnchor: false
4943
4970
  });
4944
4971
  const noteReadStillVisible = hasVisibleNoteReadCall(args.messages);
4945
4972
  const deferredNoteText = peekNoteNudgeText(args.db, args.sessionId, currentUserMessageId, args.projectPath, noteReadStillVisible, eligibility);
@@ -4956,6 +4983,11 @@ function runRustModePostprocess2(args) {
4956
4983
  sessionLog2(args.sessionId, `rust note-nudge delivery skipped wire append: ${outcome.kind}`);
4957
4984
  }
4958
4985
  }
4986
+ for (const decision of getAutoSearchHintDecisions(args.db, args.sessionId)) {
4987
+ if (decision.decision === "hint" && getUnpublishedAutoSearchNoHint(args.sessionId, decision.messageId) === undefined) {
4988
+ appendReminderToUserMessageById(args.messages, decision.messageId, decision.text);
4989
+ }
4990
+ }
4959
4991
  const { thinkingBindingRecovery, proactiveThinkingStrip } = applyRustModeThinkingStrips(args, noteNudgeAppended || servedMarkerRecord() !== servedMarkerBefore);
4960
4992
  const marker = getPersistedCompactionMarkerState(args.db, args.sessionId);
4961
4993
  return {
@@ -5814,15 +5846,32 @@ async function runPostTransformPhase2(args) {
5814
5846
  sessionLog2(args.sessionId, "transform failed dropping stale ctx_reduce calls:", error);
5815
5847
  }
5816
5848
  }
5817
- if (canUseEmptySentinels && !compactionOff && replaySnapshot) {
5849
+ if (!compactionOff && replaySnapshot) {
5818
5850
  try {
5819
5851
  const tImg = performance.now();
5852
+ const imageWatermark = canEditWholePrefix ? Math.max(args.watermark, getMaxDroppedTagNumber2(args.db, args.sessionId)) : args.watermark;
5820
5853
  const frozenImageIds = replaySnapshot.processedImageStrippedIds;
5854
+ const frozenMarkers = replaySnapshot.processedImageMarkers;
5855
+ const replacementText = canUseEmptySentinels ? "" : "[image stripped]";
5821
5856
  stripProcessedImages(args.messages, frozenImageIds, {
5822
- detect: canEditWholePrefix && args.watermark > 0,
5823
- watermark: args.watermark,
5857
+ detect: canEditWholePrefix && imageWatermark > 0,
5858
+ watermark: imageWatermark,
5824
5859
  messageTagNumbers: args.messageTagNumbers,
5825
- persistNewIds: (ids) => addProcessedImageStrippedIds(args.db, args.sessionId, ids),
5860
+ protectedCutoff: args.protectedCutoff,
5861
+ contextPercentage: args.contextUsage.percentage,
5862
+ replacementText,
5863
+ frozenMarkers,
5864
+ protectedMessageIds: new Set([
5865
+ ...args.tags.filter((tag) => protectedToolTags.has(tag.tagNumber)).map((tag) => tag.toolOwnerMessageId ?? tag.messageId)
5866
+ ]),
5867
+ persistNewIds: (ids, markers) => {
5868
+ if (!addProcessedImageStrippedIds(args.db, args.sessionId, ids, markers))
5869
+ return false;
5870
+ const committed = getProcessedImageMarkers(args.db, args.sessionId);
5871
+ for (const id of ids)
5872
+ frozenMarkers.set(id, committed.get(id) ?? replacementText);
5873
+ return true;
5874
+ },
5826
5875
  onFirstApplication: recordFirstApplicationAt
5827
5876
  });
5828
5877
  logTransformTiming(args.sessionId, "stripProcessedImages", tImg);
@@ -5950,16 +5999,6 @@ async function runPostTransformPhase2(args) {
5950
5999
  logTransformTiming(args.sessionId, "pp.placeholderNeutralize", tPlaceholder);
5951
6000
  }
5952
6001
  const tNudgeBlock = performance.now();
5953
- if (args.fullFeatureMode && !compactionOff && replaySnapshot) {
5954
- for (const anchor of replaySnapshot.noteNudgeAnchors) {
5955
- appendReminderToUserMessageById(args.messages, anchor.messageId, anchor.text);
5956
- }
5957
- for (const decision of replaySnapshot.autoSearchHintDecisions) {
5958
- if (decision.decision === "hint") {
5959
- appendReminderToUserMessageById(args.messages, decision.messageId, decision.text);
5960
- }
5961
- }
5962
- }
5963
6002
  logTransformTiming(args.sessionId, "pp.nudgeAndSticky", tNudgeBlock);
5964
6003
  const tMarker = performance.now();
5965
6004
  const explicitRebuildHappened = args.historyRefreshExplicitBeforePrepare && args.rebuiltHistoryFromInitialPrepare;
@@ -6035,13 +6074,15 @@ async function runPostTransformPhase2(args) {
6035
6074
  const noteReadStillVisible = args.fullFeatureMode ? hasVisibleNoteReadCall(args.messages) : false;
6036
6075
  let noteNudgeAppendedThisPass = false;
6037
6076
  const noteNudgeUserMessageId = findNoteNudgeUserMessageId(args.messages);
6077
+ const lastServedForNote = canEditWholePrefix && (m0RematerializedThisPass || historyWasConsumedThisPass) ? args.readLastServedMessages?.() : null;
6078
+ const rewrittenHeadCoversNote = !!lastServedForNote && args.messages.slice(0, prependedMessageCount).some((message, index) => isSyntheticHeadMessage2(message) && index < lastServedForNote.length && servedMessageKey(message, args.resolvedProviderID) !== servedMessageKey(lastServedForNote[index], args.resolvedProviderID));
6038
6079
  const noteNudgeEligibility = args.fullFeatureMode ? observeNoteNudgeServe({
6039
6080
  db: args.db,
6040
6081
  sessionId: args.sessionId,
6041
6082
  userMessageIds: args.messages.filter((m) => m.info.role === "user" && typeof m.info.id === "string").map((m) => m.info.id),
6042
6083
  anchorMessageId: noteNudgeUserMessageId,
6043
6084
  isLiveTail: args.messages.at(-1)?.info.id === noteNudgeUserMessageId,
6044
- isCacheBustingPass
6085
+ prefixRewriteCoversAnchor: canEditWholePrefix && rewrittenHeadCoversNote
6045
6086
  }) : undefined;
6046
6087
  const deferredNoteText = args.fullFeatureMode ? peekNoteNudgeText(args.db, args.sessionId, noteNudgeUserMessageId, args.projectPath, noteReadStillVisible, noteNudgeEligibility) : null;
6047
6088
  if (deferredNoteText) {
@@ -6058,6 +6099,16 @@ async function runPostTransformPhase2(args) {
6058
6099
  sessionLog2(args.sessionId, `note-nudge delivery skipped wire append: ${outcome.kind}`);
6059
6100
  }
6060
6101
  }
6102
+ if (args.fullFeatureMode && !compactionOff && replaySnapshot) {
6103
+ for (const anchor of replaySnapshot.noteNudgeAnchors) {
6104
+ appendReminderToUserMessageById(args.messages, anchor.messageId, anchor.text);
6105
+ }
6106
+ for (const decision of replaySnapshot.autoSearchHintDecisions) {
6107
+ if (decision.decision === "hint") {
6108
+ appendReminderToUserMessageById(args.messages, decision.messageId, decision.text);
6109
+ }
6110
+ }
6111
+ }
6061
6112
  let todoAnchorMovedThisPass = false;
6062
6113
  if (args.fullFeatureMode && !compactionOff) {
6063
6114
  const todoAnchorBefore = replaySnapshot ? replaySnapshot.todoSyntheticAnchor : getPersistedTodoSyntheticAnchor(args.db, args.sessionId);
@@ -6541,4 +6592,4 @@ function checkM0MutationDriftAndSignal2(args) {
6541
6592
  return false;
6542
6593
  }
6543
6594
 
6544
- export { createTagger, cavemanWordRulesForLanguage, searchMessageHistoryOffThread, findSessionId, findLastUserMessageId, clearAutoSearchForSession, setCtxReduceRegisteredGlobally, resolveCtxReduceAvailabilityFromMessages, resolveCtxReduceAvailability, primeCtxReduceSpawnPermission, ctxReduceSpawnPermissionReadNeeded, spawnAgentFromMessages, spawnAgentFromOpenCodeDb, todowritePermissionDenied, cachedToolPermissionDenied, clearToolPermissionDenied, resolveTodowriteAvailabilityFromMessages, resolveTodowriteAvailability, canConsumeDeferredOnThisPass, hasReclaimRide, reclaimRideLabel, captureOpencodeReasoningBudgetStatus, reasoningBudgetStatusLine, ENGINE_RECONNECTING_USER_MESSAGE, ENGINE_BUSY_USER_MESSAGE, SIGNED_THINKING_RESET_FENCE_FAILED, contextRefusalError, protectedToolRefusal, outgoingContextRefusal, signedTurnContextRefusal, EmergencyFailClosedError, latestAssistantTurnStart, latestAssistantTurnMessages, hasActiveAnthropicThinkingTurn, replayCavemanCompression, DegradedPassRefusalError, degradedPassError, applyFlushedStatuses, prewarmTagOwners, waitForTagOwners, stripStructuralNoise, logTransformTiming, hasRecentAssistantCommit, tagMessages, resetDegradedCacheCount2, isSyntheticHeadMessage2, applyTodoSynthesis2, freezeReasoningOnBustingPass2, firstServedDivergenceIndex2, rustModeServedKeyAfterPersistedStrips2, replayRustModeBindingMismatchStrips2, RUST_MARKER_LOCK_SKIP_LOG2, applyRustModeDeferredCompactionMarker2, clearRustModeBoundaryRecord2, runRustModePostprocess2, reconcileMarkerRepresentation2, clearPendingCompactionMarkerAfterSuccessfulDrain2, defaultCompactionMarkerStrategy2, abortSessionFailClosed2, evaluateEmergencyFailClosed2, finalizeMessageRepresentation2, runPostTransformPhase2, checkM0MutationDriftAndSignal2 };
6595
+ export { makeToolCompositeKey, createTagger, cavemanWordRulesForLanguage, searchMessageHistoryOffThread, findSessionId, findLastUserMessageId, clearAutoSearchForSession, setCtxReduceRegisteredGlobally, resolveCtxReduceAvailabilityFromMessages, resolveCtxReduceAvailability, primeCtxReduceSpawnPermission, ctxReduceSpawnPermissionReadNeeded, spawnAgentFromMessages, spawnAgentFromOpenCodeDb, todowritePermissionDenied, cachedToolPermissionDenied, clearToolPermissionDenied, resolveTodowriteAvailabilityFromMessages, resolveTodowriteAvailability, canConsumeDeferredOnThisPass, hasReclaimRide, reclaimRideLabel, captureOpencodeReasoningBudgetStatus, reasoningBudgetStatusLine, ENGINE_RECONNECTING_USER_MESSAGE, ENGINE_BUSY_USER_MESSAGE, SIGNED_THINKING_RESET_FENCE_FAILED, contextRefusalError, protectedToolRefusal, outgoingContextRefusal, signedTurnContextRefusal, EmergencyFailClosedError, latestAssistantTurnStart, latestAssistantTurnMessages, hasActiveAnthropicThinkingTurn, replayCavemanCompression, DegradedPassRefusalError, degradedPassError, applyFlushedStatuses, prewarmTagOwners, waitForTagOwners, stripStructuralNoise, logTransformTiming, hasRecentAssistantCommit, tagMessages, resetDegradedCacheCount2, isSyntheticHeadMessage2, applyTodoSynthesis2, freezeReasoningOnBustingPass2, firstServedDivergenceIndex2, rustModeServedKeyAfterPersistedStrips2, replayRustModeBindingMismatchStrips2, RUST_MARKER_LOCK_SKIP_LOG2, applyRustModeDeferredCompactionMarker2, clearRustModeBoundaryRecord2, runRustModePostprocess2, reconcileMarkerRepresentation2, clearPendingCompactionMarkerAfterSuccessfulDrain2, defaultCompactionMarkerStrategy2, abortSessionFailClosed2, evaluateEmergencyFailClosed2, finalizeMessageRepresentation2, runPostTransformPhase2, checkM0MutationDriftAndSignal2 };
@@ -6,7 +6,7 @@ import {
6
6
  } from "./index-nsjyysj0.js";
7
7
  import {
8
8
  projectDirectoryKey
9
- } from "./index-7w18gg78.js";
9
+ } from "./index-rzmjkdd6.js";
10
10
  import {
11
11
  writeStorageFileAtomicSync
12
12
  } from "./index-fvnzcnww.js";