@cortexkit/opencode-magic-context 0.49.97 → 0.49.98

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 (190) hide show
  1. package/dist/{announcement-8nj2jd87.js → announcement-p2xjv6cp.js} +4 -5
  2. package/dist/auto-search-worker.js +5 -5
  3. package/dist/chunk-embedding-write-worker.js +15 -16
  4. package/dist/{compaction-marker-candidates-a4b0anvv.js → compaction-marker-candidates-2apg7ewt.js} +2 -3
  5. package/dist/compaction-marker-candidates-worker.js +1 -1
  6. package/dist/{compartment-chunk-embedding-re2cw7y3.js → compartment-chunk-embedding-gnemmf79.js} +7 -8
  7. package/dist/{conflict-warning-hook-wcq55y61.js → conflict-warning-hook-x1ynwzwz.js} +7 -8
  8. package/dist/{context-br04s0b6.js → context-0ae81pg4.js} +377 -60
  9. package/dist/{derive-budgets-g1sy72e8.js → derive-budgets-vbv0fwsd.js} +4 -5
  10. package/dist/embedding-backfill-7terr34j.js +28 -0
  11. package/dist/embedding-worker-process.js +1 -2
  12. package/dist/embedding-worker.js +6 -7
  13. package/dist/{history-owner-74826t4n.js → history-owner-8dj31nyf.js} +2 -3
  14. package/dist/hooks/magic-context/transform.d.ts +2 -0
  15. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  16. package/dist/{index-0bjj9yf3.js → index-04zhtsb1.js} +2 -2
  17. package/dist/{index-tbdy1hk0.js → index-0wj3jr8n.js} +6 -6
  18. package/dist/{index-j4dcjb8t.js → index-1vv1ka4a.js} +4 -4
  19. package/dist/{index-zfx7mtqa.js → index-2m3t73wk.js} +1 -1
  20. package/dist/{index-3fhb0j32.js → index-34xvre52.js} +223 -5
  21. package/dist/{index-pkxkeezb.js → index-5wbqmvg8.js} +15 -15
  22. package/dist/{index-kj4bprep.js → index-61a853ky.js} +4 -4
  23. package/dist/{index-zmgp0tr6.js → index-74w347am.js} +3 -3
  24. package/dist/{index-hp46xe93.js → index-8hhmv0ff.js} +6 -6
  25. package/dist/{index-c205x7xd.js → index-8k9qpyjf.js} +1 -1
  26. package/dist/{index-tqtpgnhr.js → index-9awtk18w.js} +1 -1
  27. package/dist/{index-h7kta6cn.js → index-9eqt7755.js} +3 -3
  28. package/dist/{index-mmf6e740.js → index-a1295271.js} +7 -7
  29. package/dist/{index-880a24vd.js → index-ab86c21b.js} +1 -1
  30. package/dist/{index-3n4j5rqc.js → index-abhmtj00.js} +1 -1
  31. package/dist/{index-tr4ep2ej.js → index-ajmy0v5j.js} +31 -0
  32. package/dist/{index-dj64gzg5.js → index-cayqdwf9.js} +2 -2
  33. package/dist/{index-910gahfb.js → index-db1art1p.js} +6 -8
  34. package/dist/{index-8v1brm5n.js → index-em72jhc0.js} +11 -11
  35. package/dist/{index-7sdns2ww.js → index-fd3hkyk1.js} +2 -2
  36. package/dist/{index-fgw241hh.js → index-gcf2x04k.js} +2 -2
  37. package/dist/{index-89xg64wb.js → index-geph2sa6.js} +2 -2
  38. package/dist/{index-45qgkg8j.js → index-h1qh9n8b.js} +2 -2
  39. package/dist/{index-9jvxq5rt.js → index-h1xvt8fw.js} +4 -4
  40. package/dist/{index-0ve29s6f.js → index-hbqxxb2n.js} +1 -1
  41. package/dist/{index-0sqhg9nf.js → index-hmrkgd4v.js} +12 -12
  42. package/dist/{index-dnpcv1rg.js → index-hyvxmz3e.js} +4 -4
  43. package/dist/{index-hedgz8an.js → index-jsbgw33b.js} +1 -1
  44. package/dist/{index-w9hxgntq.js → index-k86ec4j2.js} +5 -5
  45. package/dist/{index-mgy7g740.js → index-kjdys7e2.js} +1 -1
  46. package/dist/{index-e6ay1gez.js → index-mfx7hzyc.js} +2 -2
  47. package/dist/{index-r1d45dsr.js → index-nyjztqyj.js} +3 -3
  48. package/dist/{index-x49x59ar.js → index-p52gf8a6.js} +23 -25
  49. package/dist/{index-azkfw78y.js → index-qxzk5s30.js} +1 -1
  50. package/dist/{index-6mryx739.js → index-t7st85f5.js} +1 -1
  51. package/dist/{index-89bkkgcn.js → index-tyjx0dwz.js} +4 -4
  52. package/dist/{index-k34hc455.js → index-vdzd98ry.js} +2 -2
  53. package/dist/{index-hj78hvhm.js → index-vegw385y.js} +2 -2
  54. package/dist/{index-qdjxrbnr.js → index-vxsxz3sp.js} +46 -43
  55. package/dist/{index-w7n7qkpf.js → index-w6kcwhhj.js} +4 -4
  56. package/dist/{index-xcej5kpt.js → index-xbna9akt.js} +5 -5
  57. package/dist/{index-cpbr0xvk.js → index-xtv4d4hv.js} +2 -2
  58. package/dist/{index-zkjx8gq3.js → index-xw608ytx.js} +11 -11
  59. package/dist/{index-jzrvdqb8.js → index-y5f5yg5a.js} +1 -1
  60. package/dist/{index-7m2tnk8q.js → index-z1mj8fv5.js} +9 -11
  61. package/dist/index.js +55 -56
  62. package/dist/{logger-nmb2508f.js → logger-dgtrf43g.js} +1 -2
  63. package/dist/{message-fts-rowid-map-vcatdan0.js → message-fts-rowid-map-cfq59g6g.js} +4 -5
  64. package/dist/{message-index-bounded-abhwe610.js → message-index-bounded-6y7p974x.js} +10 -11
  65. package/dist/{message-time-backfill-zc5rsvhv.js → message-time-backfill-av870n4c.js} +2 -3
  66. package/dist/migration-worker.js +12 -13
  67. package/dist/plugin/rpc-handlers.d.ts +1 -0
  68. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  69. package/dist/{project-embedding-registry-e566q4bg.js → project-embedding-registry-5rp9w92w.js} +13 -14
  70. package/dist/raw-ordinal-warmup-worker.js +8 -8
  71. package/dist/{read-session-chunk-sde0wym3.js → read-session-chunk-9ejnbe07.js} +8 -9
  72. package/dist/{read-session-raw-trhdgc9z.js → read-session-raw-pgc9gxtn.js} +2 -3
  73. package/dist/{recomp-orchestrator-dapm3e4v.js → recomp-orchestrator-kmkf8dm4.js} +32 -33
  74. package/dist/render-9712q3gp.js +42 -0
  75. package/dist/{safe-notification-target-54ns7dv9.js → safe-notification-target-01j8km9e.js} +2 -3
  76. package/dist/{search-archive-4bbn3ztv.js → search-archive-5jr011gc.js} +11 -12
  77. package/dist/{search-11aw8wpq.js → search-kd84wg76.js} +25 -26
  78. package/dist/{send-session-notification-gxrj4w1r.js → send-session-notification-tfhs4dbc.js} +5 -6
  79. package/dist/shared/rpc-types.d.ts +5 -0
  80. package/dist/shared/rpc-types.d.ts.map +1 -1
  81. package/dist/shared/status-view-check.d.ts.map +1 -1
  82. package/dist/shared/status-view.d.ts +8 -0
  83. package/dist/shared/status-view.d.ts.map +1 -1
  84. package/dist/{storage-tags-jq0c0zsn.js → storage-tags-vd3sgd4s.js} +5 -6
  85. package/dist/{store-29ksp6vy.js → store-235fjtsn.js} +6 -4
  86. package/dist/{store-reader-dgh3ssxx.js → store-reader-01e8t5j0.js} +4 -1
  87. package/dist/{transform-postprocess-phase-1xrjg6be.js → transform-postprocess-phase-n4q1yd72.js} +33 -34
  88. package/dist/v2/auto-search-worker.js +5 -5
  89. package/dist/v2/checkpoint-instruction-status.d.ts +13 -0
  90. package/dist/v2/checkpoint-instruction-status.d.ts.map +1 -0
  91. package/dist/v2/chunk-embedding-write-worker.js +15 -16
  92. package/dist/v2/{compaction-marker-candidates-6nypmsr3.js → compaction-marker-candidates-3rxg3f1e.js} +2 -3
  93. package/dist/v2/compaction-marker-candidates-worker.js +1 -1
  94. package/dist/v2/{compartment-chunk-embedding-jthtfhcd.js → compartment-chunk-embedding-6v74y2r3.js} +7 -8
  95. package/dist/v2/{context-43r0mzkp.js → context-fqeg60th.js} +382 -65
  96. package/dist/v2/{derive-budgets-wj0q7s7d.js → derive-budgets-9237wmq5.js} +5 -6
  97. package/dist/v2/embedding-backfill-dm33f3ce.js +28 -0
  98. package/dist/v2/embedding-worker-process.js +1 -2
  99. package/dist/v2/embedding-worker.js +6 -7
  100. package/dist/v2/fold/idle.d.ts +11 -1
  101. package/dist/v2/fold/idle.d.ts.map +1 -1
  102. package/dist/v2/fold/instruction-supersession.d.ts +22 -1
  103. package/dist/v2/fold/instruction-supersession.d.ts.map +1 -1
  104. package/dist/v2/fold/native-replay-v3.d.ts +1 -0
  105. package/dist/v2/fold/native-replay-v3.d.ts.map +1 -1
  106. package/dist/v2/fold/native-replay.d.ts +73 -0
  107. package/dist/v2/fold/native-replay.d.ts.map +1 -1
  108. package/dist/v2/{history-owner-8pd5ax3n.js → history-owner-k4gx50a0.js} +2 -3
  109. package/dist/v2/hooks/context.d.ts.map +1 -1
  110. package/dist/v2/{logger-58jfese9.js → logger-0ys28353.js} +1 -2
  111. package/dist/v2/{message-fts-rowid-map-ax4vk78j.js → message-fts-rowid-map-88x2zbyj.js} +4 -5
  112. package/dist/v2/{message-index-bounded-qh794qxx.js → message-index-bounded-wj5rs9az.js} +10 -11
  113. package/dist/v2/{message-time-backfill-yj773saf.js → message-time-backfill-5p4vwd79.js} +2 -3
  114. package/dist/v2/migration-worker.js +12 -13
  115. package/dist/v2/{project-embedding-registry-z05xvckg.js → project-embedding-registry-z9qxkdxm.js} +13 -14
  116. package/dist/v2/raw-ordinal-warmup-worker.js +8 -8
  117. package/dist/v2/{read-session-chunk-8tn2dbn1.js → read-session-chunk-89ep8br4.js} +8 -9
  118. package/dist/v2/{read-session-raw-ywebck9q.js → read-session-raw-seh1kcvp.js} +2 -3
  119. package/dist/v2/recomp-orchestrator-79362xbm.js +68 -0
  120. package/dist/v2/render-bzzypsgy.js +42 -0
  121. package/dist/v2/{safe-notification-target-zrwbh6k7.js → safe-notification-target-3e2rq2ys.js} +2 -3
  122. package/dist/v2/{search-35cz80x0.js → search-4f6kmq31.js} +24 -25
  123. package/dist/v2/{search-archive-8zqsf9e6.js → search-archive-4yr4hw2m.js} +11 -12
  124. package/dist/v2/{send-session-notification-8x146x5y.js → send-session-notification-vtnk598k.js} +5 -6
  125. package/dist/v2/{server-vj0xbbrc.js → server-0b3ms151.js} +2 -2
  126. package/dist/v2/{server-r3h4fy4k.js → server-1bks09js.js} +5 -5
  127. package/dist/v2/{server-63ree5ns.js → server-2xng77ch.js} +1 -1
  128. package/dist/v2/{server-2sare4qg.js → server-3mb205v9.js} +4 -4
  129. package/dist/v2/{server-n34vzyfm.js → server-3qeqa3b6.js} +1 -1
  130. package/dist/v2/{server-ganavh75.js → server-4ccgfzr2.js} +2 -2
  131. package/dist/v2/{server-av3p9c8k.js → server-54nc921b.js} +1 -1
  132. package/dist/v2/{server-2qvnr3t7.js → server-5zx51pm4.js} +1 -1
  133. package/dist/v2/{server-vsx9tsks.js → server-62t1852h.js} +11 -11
  134. package/dist/v2/{server-svccj9rd.js → server-6mq43ear.js} +4 -4
  135. package/dist/v2/{server-z2nv8jdv.js → server-70dhx58s.js} +12 -12
  136. package/dist/v2/{server-db91dxwc.js → server-7861dnm3.js} +6 -6
  137. package/dist/v2/{server-6qax5pds.js → server-7c5p0bh1.js} +2 -2
  138. package/dist/v2/{server-11ra1pmx.js → server-8xgs110k.js} +4 -4
  139. package/dist/v2/{server-40vdz8sf.js → server-98xd6j4r.js} +2 -2
  140. package/dist/v2/{server-nnh81jqy.js → server-b38pxt0e.js} +6 -8
  141. package/dist/v2/{server-k3ntgf6n.js → server-b5eg9ct6.js} +2 -2
  142. package/dist/v2/{server-2cq3e1c1.js → server-b65sqz7y.js} +4 -4
  143. package/dist/v2/{server-4yrvbnnm.js → server-bzebqckc.js} +2 -2
  144. package/dist/v2/{server-rt8t6s2a.js → server-cc58mckk.js} +2 -2
  145. package/dist/v2/{server-xekyjy4w.js → server-d0h1gjz2.js} +6 -6
  146. package/dist/v2/{server-73bqw5c0.js → server-d46xewmt.js} +1 -1
  147. package/dist/v2/{server-rr5c0xcg.js → server-d4h86y7v.js} +2 -2
  148. package/dist/v2/{server-7tj8yzrv.js → server-e14d7ebh.js} +2 -2
  149. package/dist/v2/{server-gh2w75fn.js → server-e8ybwfv8.js} +3 -3
  150. package/dist/v2/{server-zemnpv92.js → server-ghk96d57.js} +4 -4
  151. package/dist/v2/{server-j1gxs1gj.js → server-h95cdc30.js} +1 -1
  152. package/dist/v2/{server-5t4nzfpt.js → server-j09jx1n9.js} +1 -1
  153. package/dist/v2/{server-n33hyq9t.js → server-jrs4gny6.js} +2 -2
  154. package/dist/v2/{server-z5cv5wm5.js → server-md1cabvq.js} +9 -11
  155. package/dist/v2/{server-7h4gwphm.js → server-pqgnjf38.js} +3 -3
  156. package/dist/v2/{server-379fd3n7.js → server-rbxtp4sm.js} +1 -1
  157. package/dist/v2/{server-2wz6y46g.js → server-sfffm587.js} +1 -1
  158. package/dist/v2/{server-1fnsfm3a.js → server-tk4hpcxq.js} +24 -26
  159. package/dist/v2/{server-bx5k66qc.js → server-vgy98kcd.js} +1 -1
  160. package/dist/v2/{server-kzrrdjp5.js → server-xc7t2r4k.js} +223 -5
  161. package/dist/v2/{server-tq523gj6.js → server-yacpgq4s.js} +1 -1
  162. package/dist/v2/{server-vtkbxzw1.js → server-ysg14rv1.js} +31 -0
  163. package/dist/v2/{server-qjjky07w.js → server-zedjjdc5.js} +11 -11
  164. package/dist/v2/server.js +8 -9
  165. package/dist/v2/{storage-tags-pcenytad.js → storage-tags-8kktww54.js} +5 -6
  166. package/dist/v2/{store-gx19qc3a.js → store-0kjfynwp.js} +6 -4
  167. package/dist/v2/{store-reader-qt2msa8z.js → store-reader-w0srb18d.js} +4 -1
  168. package/dist/v2/store-reader.d.ts +1 -0
  169. package/dist/v2/store-reader.d.ts.map +1 -1
  170. package/dist/v2/tui/index.d.ts +1 -1
  171. package/dist/v2/tui/index.d.ts.map +1 -1
  172. package/dist/v2/{v2-archive-reader-hvdyz30c.js → v2-archive-reader-veyqp15a.js} +1 -1
  173. package/dist/v2/{wrapup-orchestrator-0d4ceff3.js → wrapup-orchestrator-97s5wznb.js} +33 -34
  174. package/dist/{v2-archive-reader-qs24chs6.js → v2-archive-reader-3s332fn7.js} +1 -1
  175. package/dist/wrapup-orchestrator-bm0x49e5.js +55 -0
  176. package/package.json +2 -2
  177. package/src/shared/rpc-types.ts +6 -0
  178. package/src/shared/status-view-check.ts +11 -0
  179. package/src/shared/status-view.ts +24 -1
  180. package/src/shared/test-preload-leak-scan.test.ts +56 -0
  181. package/src/v2/tui/index.ts +8 -1
  182. package/src/v2/tui/status-dialog-fallback.test.ts +21 -0
  183. package/dist/embedding-backfill-pdymqbnh.js +0 -29
  184. package/dist/index-dt7cyqfe.js +0 -223
  185. package/dist/render-6vmqzcem.js +0 -43
  186. package/dist/v2/embedding-backfill-16b16m38.js +0 -29
  187. package/dist/v2/recomp-orchestrator-vzygyqwn.js +0 -69
  188. package/dist/v2/render-9b5dxp9e.js +0 -43
  189. package/dist/v2/server-dt7cyqfe.js +0 -223
  190. package/dist/wrapup-orchestrator-v1mhjw55.js +0 -56
@@ -51,7 +51,7 @@ import {
51
51
  clearNoteNudgeTriggerOnly,
52
52
  nonNarrativeStoredGapRanges,
53
53
  getActiveCompartmentRun
54
- } from "./index-x49x59ar.js";
54
+ } from "./index-p52gf8a6.js";
55
55
  import"./index-sd3egckz.js";
56
56
  import {
57
57
  getHarness2
@@ -61,10 +61,9 @@ import {
61
61
  getMagicContextStorageDir,
62
62
  log2,
63
63
  sessionLog2
64
- } from "./index-3fhb0j32.js";
65
- import"./index-dt7cyqfe.js";
66
- import"./index-3n4j5rqc.js";
67
- import"./index-6mryx739.js";
64
+ } from "./index-34xvre52.js";
65
+ import"./index-abhmtj00.js";
66
+ import"./index-t7st85f5.js";
68
67
  import {
69
68
  isSaneLimit,
70
69
  setOutputReserveConfig,
@@ -75,7 +74,7 @@ import {
75
74
  deriveHistorianChunkTokens2,
76
75
  resolveKnownHistorianContextLimit2,
77
76
  resolveHistorianContextLimit2
78
- } from "./index-45qgkg8j.js";
77
+ } from "./index-h1qh9n8b.js";
79
78
  import {
80
79
  isDreamerRunnable,
81
80
  isSmartNoteSurfaceAvailable,
@@ -147,7 +146,7 @@ import {
147
146
  applyJsonSchemaParameterDescriptions,
148
147
  MagicContextRpcServer,
149
148
  subagentTemperature
150
- } from "./index-qdjxrbnr.js";
149
+ } from "./index-vxsxz3sp.js";
151
150
  import {
152
151
  invalidateAutoEmbedSession,
153
152
  clearEmbedSessionState
@@ -156,8 +155,8 @@ import {
156
155
  hasMeaningfulUserText2,
157
156
  preloadTokenizer,
158
157
  estimateTokens
159
- } from "./index-zfx7mtqa.js";
160
- import"./index-fgw241hh.js";
158
+ } from "./index-2m3t73wk.js";
159
+ import"./index-gcf2x04k.js";
161
160
  import {
162
161
  inRootAsyncContext2,
163
162
  withSqliteTransformPass2,
@@ -168,11 +167,11 @@ import {
168
167
  import"./index-v0p37hm2.js";
169
168
  import"./index-96ztjvkn.js";
170
169
  import"./index-1d042x6w.js";
171
- import"./index-hedgz8an.js";
172
- import"./index-89xg64wb.js";
170
+ import"./index-jsbgw33b.js";
171
+ import"./index-geph2sa6.js";
173
172
  import {
174
173
  deleteChunkEmbedBackoffForSession2
175
- } from "./index-j4dcjb8t.js";
174
+ } from "./index-1vv1ka4a.js";
176
175
  import {
177
176
  advanceSessionActivity,
178
177
  backfillSessionActivity,
@@ -203,6 +202,7 @@ import {
203
202
  currentLkgRequestIdentity,
204
203
  noteLkgProviderResponse,
205
204
  clearLkgMeasuredRequest,
205
+ loadPersistedLkgSlot,
206
206
  beginServedRequest,
207
207
  noteServedRefusal,
208
208
  countServedRefusal,
@@ -212,8 +212,8 @@ import {
212
212
  getSlot,
213
213
  dropSlot,
214
214
  copySessionStateForClone
215
- } from "./index-8v1brm5n.js";
216
- import"./index-89bkkgcn.js";
215
+ } from "./index-em72jhc0.js";
216
+ import"./index-tyjx0dwz.js";
217
217
  import {
218
218
  stripPersistedAssistantText,
219
219
  currentReclaimableToolOutputCount,
@@ -226,6 +226,8 @@ import {
226
226
  clearCachedM0M1,
227
227
  clearCachedM0,
228
228
  readReplayEnvelope,
229
+ updateReplayDocument,
230
+ loadPersistedUsage,
229
231
  getPersistedReasoningWatermark,
230
232
  setPersistedReasoningWatermark,
231
233
  getChannel2NudgeState,
@@ -256,13 +258,13 @@ import {
256
258
  estimateFinalWireInputTokens,
257
259
  getMaxTagNumberBySession2,
258
260
  getTagsBySession2
259
- } from "./index-w7n7qkpf.js";
261
+ } from "./index-w6kcwhhj.js";
260
262
  import {
261
263
  BoundedSessionMap,
262
264
  getTableColumnNames,
263
265
  recordToolDefinitionSet,
264
266
  getCurrentToolSetHash
265
- } from "./index-cpbr0xvk.js";
267
+ } from "./index-xtv4d4hv.js";
266
268
  import {
267
269
  resolveHistorianModel2
268
270
  } from "./index-5kym00ag.js";
@@ -278,15 +280,15 @@ import {
278
280
  isFailClosedBlockingError,
279
281
  shouldBypassFailClosedBlock,
280
282
  createFailClosedController
281
- } from "./index-c205x7xd.js";
283
+ } from "./index-8k9qpyjf.js";
282
284
  import {
283
285
  setHomeProjectPermission,
284
286
  resolveProjectIdentityForSession,
285
287
  scheduleAfterBootQuiet
286
- } from "./index-hj78hvhm.js";
288
+ } from "./index-vegw385y.js";
287
289
  import"./index-1zx87sdm.js";
288
290
  import"./index-58e3y90n.js";
289
- import"./index-k34hc455.js";
291
+ import"./index-vdzd98ry.js";
290
292
  import {
291
293
  needsBlockedRead,
292
294
  DreamTokenBudgetExceeded,
@@ -299,10 +301,10 @@ import {
299
301
  cleanUserText2,
300
302
  readRawSessionMessageIdOrdinalsForRange2,
301
303
  readRawSessionMessageOrdinalById2
302
- } from "./index-hp46xe93.js";
304
+ } from "./index-8hhmv0ff.js";
303
305
  import {
304
306
  scheduleClearAndReindex
305
- } from "./index-9jvxq5rt.js";
307
+ } from "./index-h1xvt8fw.js";
306
308
  import {
307
309
  startBootDeadline,
308
310
  getSchemaFenceRejection,
@@ -312,20 +314,21 @@ import {
312
314
  openDatabaseAsync,
313
315
  isDatabasePersisted,
314
316
  getDatabasePersistenceError
315
- } from "./index-zkjx8gq3.js";
317
+ } from "./index-xw608ytx.js";
316
318
  import"./index-fr0wbhdn.js";
317
- import"./index-dnpcv1rg.js";
319
+ import"./index-hyvxmz3e.js";
318
320
  import {
319
321
  gaDatabasePath2,
320
322
  RAW_MESSAGE_TYPES2,
321
323
  V2StoreReaderPool2,
322
324
  V2StoreReader2
323
- } from "./index-tr4ep2ej.js";
325
+ } from "./index-ajmy0v5j.js";
324
326
  import"./index-fb3zxn06.js";
325
- import"./index-880a24vd.js";
327
+ import"./index-ab86c21b.js";
326
328
  import {
327
329
  resolveContextLimit,
328
330
  resolveOpenCodeOverflowLimit,
331
+ resolveExecuteThresholdDetail,
329
332
  resolveModelKey,
330
333
  parseCacheTtl,
331
334
  createScheduler,
@@ -341,34 +344,34 @@ import {
341
344
  servedHeadChanged,
342
345
  noteHostCheckpointCommit,
343
346
  isSyntheticHeadMessage2
344
- } from "./index-pkxkeezb.js";
345
- import"./index-azkfw78y.js";
347
+ } from "./index-5wbqmvg8.js";
348
+ import"./index-qxzk5s30.js";
346
349
  import"./index-qt1qqasc.js";
347
350
  import {
348
351
  retainProjectEmbedding2
349
- } from "./index-7m2tnk8q.js";
350
- import"./index-7sdns2ww.js";
352
+ } from "./index-z1mj8fv5.js";
353
+ import"./index-fd3hkyk1.js";
351
354
  import"./index-qjwpqvnf.js";
352
- import"./index-r1d45dsr.js";
355
+ import"./index-nyjztqyj.js";
353
356
  import {
354
357
  renderUserFacingFailure,
355
358
  userFacingFailureCode
356
- } from "./index-910gahfb.js";
357
- import"./index-0bjj9yf3.js";
359
+ } from "./index-db1art1p.js";
360
+ import"./index-04zhtsb1.js";
358
361
  import"./index-9emdjcb5.js";
359
362
  import {
360
363
  pushLiveNotification2,
361
364
  pushNotification2,
362
365
  isTuiConnected2
363
366
  } from "./index-y14pawe1.js";
364
- import"./index-jzrvdqb8.js";
365
- import"./index-kj4bprep.js";
366
- import"./index-0sqhg9nf.js";
367
- import"./index-w9hxgntq.js";
368
- import"./index-dj64gzg5.js";
367
+ import"./index-y5f5yg5a.js";
368
+ import"./index-61a853ky.js";
369
+ import"./index-hmrkgd4v.js";
370
+ import"./index-k86ec4j2.js";
371
+ import"./index-cayqdwf9.js";
369
372
  import {
370
373
  detectConflicts
371
- } from "./index-0ve29s6f.js";
374
+ } from "./index-hbqxxb2n.js";
372
375
  import {
373
376
  STORAGE_NOTICE_PREFIX,
374
377
  formatStorageRefusalNotice,
@@ -394,12 +397,12 @@ import {
394
397
  readV2RawMessagePagesForConversion2,
395
398
  createV2RawMessageReader2,
396
399
  createV2RawMessageProvider2
397
- } from "./index-e6ay1gez.js";
400
+ } from "./index-mfx7hzyc.js";
398
401
  import"./index-fmsr7v69.js";
399
- import"./index-h7kta6cn.js";
400
- import"./index-mgy7g740.js";
401
- import"./index-xcej5kpt.js";
402
- import"./index-tbdy1hk0.js";
402
+ import"./index-9eqt7755.js";
403
+ import"./index-kjdys7e2.js";
404
+ import"./index-xbna9akt.js";
405
+ import"./index-0wj3jr8n.js";
403
406
  import {
404
407
  markHostInstructionRow,
405
408
  hostInstructionRow,
@@ -414,7 +417,7 @@ import {
414
417
  import {
415
418
  getErrorMessage
416
419
  } from "./index-y8v6yerm.js";
417
- import"./index-tqtpgnhr.js";
420
+ import"./index-9awtk18w.js";
418
421
  import {
419
422
  sameProjectDirectory
420
423
  } from "./index-knvkbfvh.js";
@@ -790,12 +793,24 @@ function trimToRecordedBoundary(db, sessionId, messages) {
790
793
  }
791
794
 
792
795
  // src/v2/fold/idle.ts
796
+ function publishedHistoryCanRide({
797
+ directoryResolved,
798
+ percentage,
799
+ executeThreshold,
800
+ publishedEnd,
801
+ servedEnd
802
+ }) {
803
+ return directoryResolved && percentage >= executeThreshold && publishedEnd !== null && publishedEnd !== servedEnd;
804
+ }
805
+
793
806
  class HostFoldIdle {
794
807
  fold;
795
808
  now;
796
809
  timers;
797
810
  windows = new Map;
798
811
  attempted = new Map;
812
+ publicationWindows = new BoundedSessionMap(1000);
813
+ publicationAttempts = new BoundedSessionMap(1000);
799
814
  constructor(fold, now = Date.now, timers = { setTimeout, clearTimeout }) {
800
815
  this.fold = fold;
801
816
  this.now = now;
@@ -806,8 +821,10 @@ class HostFoldIdle {
806
821
  if (window?.timer)
807
822
  this.timers.clearTimeout(window.timer);
808
823
  this.windows.delete(sessionID);
824
+ this.publicationWindows.delete(sessionID);
809
825
  }
810
826
  idle(sessionID, cacheTtl, lastResponseTime) {
827
+ const previousPublication = this.publicationWindows.peek(sessionID);
811
828
  this.active(sessionID);
812
829
  let ttl;
813
830
  try {
@@ -815,8 +832,12 @@ class HostFoldIdle {
815
832
  } catch {
816
833
  ttl = 5 * 60 * 1000;
817
834
  }
818
- if (!Number.isFinite(ttl) || lastResponseTime <= 0)
835
+ if (lastResponseTime <= 0)
819
836
  return;
837
+ if (!Number.isFinite(ttl)) {
838
+ this.publicationWindows.set(sessionID, previousPublication?.responseTime === lastResponseTime ? previousPublication : { responseTime: lastResponseTime });
839
+ return;
840
+ }
820
841
  const attempted = this.attempted.get(sessionID);
821
842
  if (attempted?.cacheTtl === cacheTtl && attempted.lastResponseTime === lastResponseTime)
822
843
  return;
@@ -842,10 +863,24 @@ class HostFoldIdle {
842
863
  };
843
864
  wake();
844
865
  }
866
+ published(sessionID, ready) {
867
+ const window = this.publicationWindows.get(sessionID);
868
+ if (!window || this.publicationAttempts.get(sessionID) === window.responseTime)
869
+ return;
870
+ const eligible = () => this.publicationWindows.peek(sessionID) === window && ready();
871
+ if (!eligible())
872
+ return;
873
+ this.publicationAttempts.set(sessionID, window.responseTime);
874
+ this.fold(sessionID, eligible).catch(() => {
875
+ return;
876
+ });
877
+ }
845
878
  dispose() {
846
879
  for (const sessionID of this.windows.keys())
847
880
  this.active(sessionID);
848
881
  this.attempted.clear();
882
+ this.publicationWindows.clear();
883
+ this.publicationAttempts.clear();
849
884
  }
850
885
  }
851
886
 
@@ -1064,8 +1099,58 @@ function retiredLiveInstructionIDs(db, sessionID) {
1064
1099
  function coveredInstructionSupersessionOn(db, sessionID) {
1065
1100
  return coveredOn(readReplayEnvelope(db, sessionID)[coveredNamespace]);
1066
1101
  }
1102
+ var leftOutNamespace = "legacyCheckpointInstructionsLeftOut";
1103
+ function decodeLeftOut(value) {
1104
+ if (typeof value !== "object" || value === null)
1105
+ return;
1106
+ const { through, ids } = value;
1107
+ if (typeof through !== "number" || !Number.isSafeInteger(through) || through < -1 || !Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0))
1108
+ return;
1109
+ return { through, ids: [...ids] };
1110
+ }
1111
+ function instructionsLeftOut(db, sessionID) {
1112
+ let doc;
1113
+ try {
1114
+ doc = readReplayEnvelope(db, sessionID, "read");
1115
+ } catch {
1116
+ return;
1117
+ }
1118
+ return decodeLeftOut(doc[leftOutNamespace]);
1119
+ }
1120
+ function mergeInstructionsLeftOut(a, b) {
1121
+ return {
1122
+ through: Math.max(a?.through ?? -1, b.through),
1123
+ ids: [...new Set([...a?.ids ?? [], ...b.ids])]
1124
+ };
1125
+ }
1126
+ function raisesInstructionsLeftOut(current, next) {
1127
+ if (!current)
1128
+ return true;
1129
+ const ids = new Set(current.ids);
1130
+ return next.through > current.through || next.ids.some((id) => !ids.has(id));
1131
+ }
1132
+ function recordInstructionsLeftOut(db, sessionID, value) {
1133
+ return updateReplayDocument(db, sessionID, (doc) => {
1134
+ const current = decodeLeftOut(doc[leftOutNamespace]);
1135
+ if (current && !raisesInstructionsLeftOut(current, value))
1136
+ return false;
1137
+ doc.version = 2;
1138
+ doc[leftOutNamespace] = mergeInstructionsLeftOut(current, value);
1139
+ return true;
1140
+ });
1141
+ }
1142
+ function isLeftOutInstruction(leftOut, row) {
1143
+ return !!leftOut && row.type === "system" && (row.seq <= leftOut.through || leftOut.ids.includes(row.id));
1144
+ }
1067
1145
  var coveredSupersessionEnabled = true;
1068
- function reclaimInstructionRows(db, sessionID, messages, permitted, folded = new Set, covered = []) {
1146
+ function isMarkedInstructionUpdate(row) {
1147
+ const metadata = row.data.metadata;
1148
+ if (typeof metadata !== "object" || metadata === null || !("instructionSources" in metadata))
1149
+ return false;
1150
+ const sources = metadata.instructionSources;
1151
+ return row.type === "system" && "notice" in metadata && metadata.notice === "instructions" && Array.isArray(sources) && sources.length > 0 && sources.every((source) => typeof source === "string" && source.length > 0);
1152
+ }
1153
+ function reclaimInstructionRows(db, sessionID, messages, permitted, folded = new Set, covered = [], checkpointSequence, checkpointCoveredThrough) {
1069
1154
  const instructionRows = (list) => list.flatMap((message) => {
1070
1155
  const row = hostInstructionRow(message.info);
1071
1156
  return row ? [{ message, row }] : [];
@@ -1077,6 +1162,12 @@ function reclaimInstructionRows(db, sessionID, messages, permitted, folded = new
1077
1162
  const coveredFollowed = rows.length > 0 && (coveredRows.length > 0 || permitted) && coveredInstructionSupersessionOn(db, sessionID);
1078
1163
  const switchCovered = permitted && rows.length > 0 && !coveredFollowed && coveredSupersessionEnabled;
1079
1164
  const selected = permitted ? supersededInstructionIDs(rows.map(({ row }) => row)) : new Set;
1165
+ if (permitted && checkpointSequence !== undefined) {
1166
+ for (const { row } of rows) {
1167
+ if (row.seq < checkpointSequence && (isMarkedInstructionUpdate(row) || checkpointCoveredThrough !== undefined && row.seq <= checkpointCoveredThrough))
1168
+ selected.add(row.id);
1169
+ }
1170
+ }
1080
1171
  const newlyRetired = new Set([...selected].filter((id) => !retired.has(id)));
1081
1172
  const omitted = new Set([...retired, ...newlyRetired]);
1082
1173
  const omits = (message, id) => omitted.has(id) && (!coveredMessages.has(message) || coveredFollowed || switchCovered);
@@ -2101,12 +2192,13 @@ function validReplayState(value) {
2101
2192
  "upgrade",
2102
2193
  "withoutRecentContext",
2103
2194
  "retiredInstructionThrough",
2104
- "retiredInstructionIDs"
2195
+ "retiredInstructionIDs",
2196
+ "reclaimCoveredInstructionsThrough"
2105
2197
  ]))
2106
2198
  return false;
2107
2199
  const floor = value.floor;
2108
2200
  const upgrade = value.upgrade;
2109
- return object(floor) && keys(floor, ["kind", "id", "seq", "after", "digest"]) && ["start", "summary", "checkpoint", "host-checkpoint"].includes(floor.kind) && identity(floor.id) && typeof floor.seq === "number" && typeof floor.after === "number" && Number.isSafeInteger(floor.seq) && Number.isSafeInteger(floor.after) && floor.after === (floor.kind === "start" || floor.kind === "host-checkpoint" ? floor.seq - 1 : floor.seq) && digest(floor.digest) && validControls(value.controls) && (value.blocked === undefined || typeof value.blocked === "boolean") && (value.withoutRecentContext === undefined || typeof value.withoutRecentContext === "boolean") && (value.retiredInstructionThrough === undefined || Number.isSafeInteger(value.retiredInstructionThrough) && value.retiredInstructionThrough >= 0) && (value.retiredInstructionIDs === undefined || Array.isArray(value.retiredInstructionIDs) && value.retiredInstructionIDs.every(identity)) && (upgrade === undefined || object(upgrade) && keys(upgrade, ["admissionID", "mode"]) && identity(upgrade.admissionID) && ["bounded", "host-checkpoint", "source-repair"].includes(upgrade.mode));
2201
+ return object(floor) && keys(floor, ["kind", "id", "seq", "after", "digest"]) && ["start", "summary", "checkpoint", "host-checkpoint"].includes(floor.kind) && identity(floor.id) && typeof floor.seq === "number" && typeof floor.after === "number" && Number.isSafeInteger(floor.seq) && Number.isSafeInteger(floor.after) && floor.after === (floor.kind === "start" || floor.kind === "host-checkpoint" ? floor.seq - 1 : floor.seq) && digest(floor.digest) && validControls(value.controls) && (value.blocked === undefined || typeof value.blocked === "boolean") && (value.withoutRecentContext === undefined || typeof value.withoutRecentContext === "boolean") && (value.retiredInstructionThrough === undefined || Number.isSafeInteger(value.retiredInstructionThrough) && value.retiredInstructionThrough >= 0) && (value.retiredInstructionIDs === undefined || Array.isArray(value.retiredInstructionIDs) && value.retiredInstructionIDs.every(identity)) && (value.reclaimCoveredInstructionsThrough === undefined || Number.isSafeInteger(value.reclaimCoveredInstructionsThrough) && value.reclaimCoveredInstructionsThrough >= 0) && (upgrade === undefined || object(upgrade) && keys(upgrade, ["admissionID", "mode"]) && identity(upgrade.admissionID) && ["bounded", "host-checkpoint", "source-repair"].includes(upgrade.mode));
2110
2202
  }
2111
2203
  function instructionRetirement(replay) {
2112
2204
  const ids = new Set(replay?.retiredInstructionIDs);
@@ -2360,6 +2452,17 @@ async function forgetNativeFoldProvenance(storage, sessionID, legacyOnly = false
2360
2452
  after = page.next;
2361
2453
  } while (after);
2362
2454
  }
2455
+ function legacyLeftOut(record) {
2456
+ const replay = record.replay;
2457
+ if (replay.reclaimCoveredInstructionsThrough !== undefined || replay.floor.after < 0)
2458
+ return;
2459
+ const through = replay.retiredInstructionThrough ?? -1;
2460
+ const ids = [...replay.retiredInstructionIDs ?? []];
2461
+ return {
2462
+ native: { through: Math.max(replay.floor.after, through), ids },
2463
+ fallback: { through, ids }
2464
+ };
2465
+ }
2363
2466
 
2364
2467
  class NativeFoldReplay {
2365
2468
  storage;
@@ -2382,6 +2485,8 @@ class NativeFoldReplay {
2382
2485
  reportedForeignRefreshes = new Set;
2383
2486
  editedAdmissions = new Map;
2384
2487
  legacyUpgrades = new Map;
2488
+ passRecords = new Map;
2489
+ passLeftOut = new Map;
2385
2490
  constructor(storage, openReader, admissions, options = {}) {
2386
2491
  this.storage = storage;
2387
2492
  this.openReader = openReader;
@@ -2438,6 +2543,103 @@ class NativeFoldReplay {
2438
2543
  return instructionRetirement();
2439
2544
  return instructionRetirement(await this.floorState(sessionID, reader));
2440
2545
  }
2546
+ async coveredInstructionReclaimBoundary(sessionID, cut, reader) {
2547
+ if (!this.options.deferCoveredInstructionRetirement?.())
2548
+ return;
2549
+ const admission = await this.passRecord(sessionID, reader);
2550
+ if (admission?.proof.admissionID !== cut.id || admission.proof.sourceDigest !== foldDigest(reader.hostIdentity()) || admission.proof.summaryDigest !== foldDigest(cut.data.summary ?? "") || admission.replay.reclaimCoveredInstructionsThrough === undefined)
2551
+ return;
2552
+ const coverage = this.historyCoverage(sessionID, reader);
2553
+ return coverage && this.floorCovered(sessionID, admission.replay.floor, coverage, admission.replay) ? admission.replay.reclaimCoveredInstructionsThrough : undefined;
2554
+ }
2555
+ async admittedInstructionRetirement(sessionID, reader) {
2556
+ return instructionRetirement((await this.passRecord(sessionID, reader))?.replay);
2557
+ }
2558
+ async leftOutForPass(sessionID, cut, reader, served) {
2559
+ const stored = instructionsLeftOut(this.storage.db, sessionID);
2560
+ const record = await this.passRecord(sessionID, reader);
2561
+ if (!record || record.proof.sourceDigest !== foldDigest(reader.hostIdentity()) || stored && served === "fallback")
2562
+ return { leftOut: stored };
2563
+ const legacy = legacyLeftOut(record);
2564
+ if (!legacy || !raisesInstructionsLeftOut(stored, legacy.native))
2565
+ return { leftOut: stored };
2566
+ const path = this.legacyPath(sessionID, record, cut, reader, served);
2567
+ const value = mergeInstructionsLeftOut(stored, legacy[path]);
2568
+ if (raisesInstructionsLeftOut(stored, legacy[path]))
2569
+ this.passLeftOut.set(sessionID, value);
2570
+ if (served !== "native" || path !== "fallback")
2571
+ return { leftOut: value };
2572
+ return {
2573
+ leftOut: value,
2574
+ restoreCoveredThrough: record.replay.floor.after,
2575
+ stageRetirement: () => this.passLeftOut.set(sessionID, mergeInstructionsLeftOut(value, legacy.native))
2576
+ };
2577
+ }
2578
+ legacyPath(sessionID, record, cut, reader, served) {
2579
+ const carried = this.savedRequestCarriedCovered(sessionID, record, reader);
2580
+ if (carried !== undefined)
2581
+ return carried ? "fallback" : "native";
2582
+ if (served === "native" || served === undefined && cut && this.oldReleaseAdmits(sessionID, record, cut, reader))
2583
+ return "native";
2584
+ return "fallback";
2585
+ }
2586
+ oldReleaseAdmits(sessionID, record, cut, reader) {
2587
+ return isLocalCheckpoint(cut) && record.proof.admissionID === cut.id && record.proof.sourceDigest === foldDigest(reader.hostIdentity()) && record.proof.summaryDigest === foldDigest(cut.data.summary ?? "") && validFloor(reader, sessionID, record.replay.floor) && this.floorCovered(sessionID, record.replay.floor, this.historyCoverage(sessionID, reader), record.replay) && record.proof.historyDigest === historyDigest(reader, sessionID, cut.seq - 1, record.replay.floor.after);
2588
+ }
2589
+ savedRequestCarriedCovered(sessionID, record, reader) {
2590
+ let slot;
2591
+ try {
2592
+ slot = getSlot(sessionID) ?? loadPersistedLkgSlot(this.storage.db, sessionID);
2593
+ } catch {
2594
+ return;
2595
+ }
2596
+ if (!slot)
2597
+ return;
2598
+ const first = slot.inputIdSeq.findIndex((id) => !id.startsWith("\x00"));
2599
+ if (first < 0 || !slot.inputIdSeq.slice(0, first).every((id) => id.startsWith("\x00mc-system:")))
2600
+ return;
2601
+ const firstID = slot.inputIdSeq[first];
2602
+ const seq = firstID === undefined ? undefined : reader.sequenceForId(sessionID, firstID);
2603
+ const floor = record.replay.floor.after;
2604
+ if (seq === undefined || seq <= floor)
2605
+ return;
2606
+ const retired = instructionRetirement(record.replay);
2607
+ const between = reader.instructionRowsThrough(sessionID, seq - 1).filter((row) => row.seq > floor && !retired(row)).length;
2608
+ if (first === between)
2609
+ return false;
2610
+ return first > between ? true : undefined;
2611
+ }
2612
+ commitPassLeftOut(sessionID) {
2613
+ const value = this.passLeftOut.get(sessionID);
2614
+ this.passLeftOut.delete(sessionID);
2615
+ return !value || recordInstructionsLeftOut(this.storage.db, sessionID, value);
2616
+ }
2617
+ cancelPassLeftOut(sessionID) {
2618
+ this.passLeftOut.delete(sessionID);
2619
+ this.passRecords.delete(sessionID);
2620
+ }
2621
+ async passRecord(sessionID, reader) {
2622
+ const seen = this.passRecords.get(sessionID);
2623
+ if (seen?.reader === reader)
2624
+ return seen.record;
2625
+ const record = await this.readV3(sessionID);
2626
+ this.passRecords.set(sessionID, { reader, record });
2627
+ return record;
2628
+ }
2629
+ rememberLegacyLeftOut(sessionID, previous, reader) {
2630
+ if (!previous || previous.proof.sourceDigest !== foldDigest(reader.hostIdentity()))
2631
+ return true;
2632
+ if (instructionsLeftOut(this.storage.db, sessionID))
2633
+ return true;
2634
+ const leftOut = this.passLeftOut.get(sessionID) ?? legacyLeftOut(previous)?.[this.legacyPath(sessionID, previous, reader.latestCompaction(sessionID), reader)];
2635
+ if (!leftOut)
2636
+ return true;
2637
+ try {
2638
+ return recordInstructionsLeftOut(this.storage.db, sessionID, leftOut);
2639
+ } catch {
2640
+ return false;
2641
+ }
2642
+ }
2441
2643
  async prepareManualFold(sessionID, reader, boundaryID, summary) {
2442
2644
  const running = reader.latestRunningCompaction(sessionID);
2443
2645
  if (!running || this.options.protocol !== 3)
@@ -2461,10 +2663,11 @@ class NativeFoldReplay {
2461
2663
  if (instruction.seq > floor.after && (liveRetired.has(instruction.id) || superseded.has(instruction.id) || text.length > 0 && summary.includes(text)))
2462
2664
  retiredInstructionIDs.push(instruction.id);
2463
2665
  }
2666
+ const retiredThrough = this.options.deferCoveredInstructionRetirement?.() ? previous?.retiredInstructionThrough : floor.after;
2464
2667
  return {
2465
2668
  floor,
2466
2669
  controls: previous?.controls ?? [],
2467
- ...floor.after >= 0 ? { retiredInstructionThrough: floor.after } : {},
2670
+ ...retiredThrough !== undefined && retiredThrough >= 0 ? { retiredInstructionThrough: retiredThrough } : {},
2468
2671
  retiredInstructionIDs
2469
2672
  };
2470
2673
  }
@@ -2787,6 +2990,7 @@ ${cached}
2787
2990
  }
2788
2991
  };
2789
2992
  const payload = encodeAdmissionV3(value);
2993
+ this.passRecords.delete(sessionID);
2790
2994
  await admissions.set(this.admissionKey(sessionID), {
2791
2995
  payload,
2792
2996
  digest: foldDigest(payload)
@@ -2825,6 +3029,7 @@ ${cached}
2825
3029
  return;
2826
3030
  value.replay.withoutRecentContext = true;
2827
3031
  const payload = encodeAdmissionV3(value);
3032
+ this.passRecords.delete(sessionID);
2828
3033
  if (!pending)
2829
3034
  await admissions.set(this.admissionKey(sessionID), {
2830
3035
  payload,
@@ -2846,7 +3051,7 @@ ${cached}
2846
3051
  }
2847
3052
  async admits(sessionID, cut, reader) {
2848
3053
  if (this.options.protocol === 3) {
2849
- const saved = await this.readV3(sessionID);
3054
+ const saved = await this.passRecord(sessionID, reader);
2850
3055
  if (!saved || !isLocalCheckpoint(cut) || cut.session_id !== sessionID)
2851
3056
  return false;
2852
3057
  const proof = saved.proof;
@@ -2905,6 +3110,7 @@ ${cached}
2905
3110
  if (snapshot.historyDigest !== historyDigest(reader, sessionID, cut.seq - 1)) {
2906
3111
  this.staleHeads.add(sessionID);
2907
3112
  this.invalidate(sessionID);
3113
+ this.passRecords.delete(sessionID);
2908
3114
  await this.removeAdmission(this.admissionKey(sessionID));
2909
3115
  return false;
2910
3116
  }
@@ -2947,6 +3153,7 @@ ${cached}
2947
3153
  }
2948
3154
  };
2949
3155
  const payload = encodeAdmissionV3(value);
3156
+ this.passRecords.delete(sessionID);
2950
3157
  await admissions.set(this.admissionKey(sessionID), {
2951
3158
  payload,
2952
3159
  digest: foldDigest(payload)
@@ -2962,7 +3169,7 @@ ${cached}
2962
3169
  }
2963
3170
  async replayAdmission(sessionID, cut, reader) {
2964
3171
  if (this.options.protocol === 3) {
2965
- const saved = await this.readV3(sessionID);
3172
+ const saved = await this.passRecord(sessionID, reader);
2966
3173
  if (!saved)
2967
3174
  return "legacy";
2968
3175
  if (saved.proof.admissionID !== cut.id)
@@ -3241,10 +3448,12 @@ ${cached}
3241
3448
  this.reportOnce(draft.sessionID, this.reportedForeignRefreshes, "v3 host fold: admission refresh skipped: admission belongs to a different host database file");
3242
3449
  return;
3243
3450
  }
3451
+ const coveredThrough = Math.min(replay.floor.after, cut.seq - 1);
3244
3452
  const value = {
3245
3453
  ...saved,
3246
3454
  replay: {
3247
3455
  ...replay,
3456
+ ...this.options.deferCoveredInstructionRetirement?.() && coveredThrough >= 0 ? { reclaimCoveredInstructionsThrough: coveredThrough } : {},
3248
3457
  controls: controlsThrough(replay.controls, reader, draft.sessionID, cut.seq - 1)
3249
3458
  },
3250
3459
  proof: {
@@ -3253,6 +3462,11 @@ ${cached}
3253
3462
  }
3254
3463
  };
3255
3464
  const payload = encodeAdmissionV3(value);
3465
+ if (!this.rememberLegacyLeftOut(draft.sessionID, saved, reader)) {
3466
+ this.report(draft.sessionID, "admission refresh skipped: the instruction rows an older checkpoint record left out could not be recorded");
3467
+ return;
3468
+ }
3469
+ this.passRecords.delete(draft.sessionID);
3256
3470
  await this.admissions?.set(this.admissionKey(draft.sessionID), {
3257
3471
  payload,
3258
3472
  digest: foldDigest(payload)
@@ -3296,6 +3510,12 @@ ${cached}
3296
3510
  this.report(draft.sessionID, "fold refused: no usable host checkpoint boundary");
3297
3511
  return false;
3298
3512
  }
3513
+ if (this.options.deferCoveredInstructionRetirement?.() && replay.floor.after >= 0) {
3514
+ replay = {
3515
+ ...replay,
3516
+ reclaimCoveredInstructionsThrough: Math.min(replay.floor.after, running.seq - 1)
3517
+ };
3518
+ }
3299
3519
  const liveRetired = retiredLiveInstructionIDs(this.storage.db, draft.sessionID);
3300
3520
  const absentRetired = liveRetired.size === 0 ? [] : reader.instructionRowsThrough(draft.sessionID, reader.latestSequence(draft.sessionID)).filter((row) => liveRetired.has(row.id) && !draft.messages.some((message) => nativeRowID(message) === row.id || message.role === "system" && !nativeRowID(message) && message.content.map((part) => part.text ?? "").join("") === row.data.text)).map((row) => row.id);
3301
3521
  if (absentRetired.length > 0)
@@ -3305,6 +3525,10 @@ ${cached}
3305
3525
  ...new Set([...replay.retiredInstructionIDs ?? [], ...absentRetired])
3306
3526
  ]
3307
3527
  };
3528
+ if (!this.rememberLegacyLeftOut(draft.sessionID, await this.readV3(draft.sessionID), reader)) {
3529
+ this.report(draft.sessionID, "fold refused: the instruction rows an older checkpoint record left out could not be recorded");
3530
+ return false;
3531
+ }
3308
3532
  const model = `${draft.model.providerID}/${draft.model.id}`;
3309
3533
  if (!args.manual && this.tail(draft.sessionID)?.model !== model)
3310
3534
  this.storage.replaceRows(draft.sessionID, reader.latestSequence(draft.sessionID), []);
@@ -3344,6 +3568,7 @@ ${cached}
3344
3568
  };
3345
3569
  const capturedPayload = JSON.stringify(capture);
3346
3570
  let written = 0;
3571
+ this.passRecords.delete(draft.sessionID);
3347
3572
  try {
3348
3573
  for (const [index, key] of keys.entries()) {
3349
3574
  const data = index === 0 ? capturedPayload : payload;
@@ -3380,6 +3605,7 @@ ${cached}
3380
3605
  }));
3381
3606
  return true;
3382
3607
  }
3608
+ this.passRecords.delete(draft.sessionID);
3383
3609
  await this.admissions?.set(this.admissionKey(draft.sessionID), {
3384
3610
  payload,
3385
3611
  digest: foldDigest(payload)
@@ -3425,6 +3651,7 @@ ${cached}
3425
3651
  historyDigest: historyDigest(reader, draft.sessionID, (running?.seq ?? through) - 1)
3426
3652
  };
3427
3653
  const payload = JSON.stringify(provenance);
3654
+ this.passRecords.delete(draft.sessionID);
3428
3655
  await this.admissions.set(this.admissionKey(draft.sessionID), {
3429
3656
  payload,
3430
3657
  digest: foldDigest(payload)
@@ -3596,6 +3823,7 @@ ${cached}
3596
3823
  this.dirty.delete(sessionID);
3597
3824
  this.changed.delete(sessionID);
3598
3825
  this.staleHeads.delete(sessionID);
3826
+ this.passRecords.delete(sessionID);
3599
3827
  }
3600
3828
  async forget(sessionID) {
3601
3829
  if (this.stampMRU?.sessionID === sessionID)
@@ -3605,6 +3833,7 @@ ${cached}
3605
3833
  this.reportedForeignRefreshes.delete(sessionID);
3606
3834
  this.cancelLegacyUpgrade(sessionID);
3607
3835
  this.cancelEditedAdmission(sessionID);
3836
+ this.cancelPassLeftOut(sessionID);
3608
3837
  if (this.admissions)
3609
3838
  await forgetNativeFoldProvenance(this.admissions, sessionID);
3610
3839
  await this.storage.forget(sessionID);
@@ -7732,6 +7961,7 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
7732
7961
  const nativeFoldReplay = nativeFoldMemory ? new NativeFoldReplay(nativeFoldMemory, () => openStoreReader(), context.storage, {
7733
7962
  protocol: 3,
7734
7963
  log: sessionLog2,
7964
+ deferCoveredInstructionRetirement: () => !rustModeModuleClient,
7735
7965
  rendersHistory: (sessionID) => {
7736
7966
  if (rustModeModuleClient)
7737
7967
  return false;
@@ -8332,6 +8562,33 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
8332
8562
  log: sessionLog2
8333
8563
  }) : undefined;
8334
8564
  const hostFoldIdle = hostFolds ? new HostFoldIdle((sessionID, eligible) => hostFolds.idle(sessionID, eligible)) : undefined;
8565
+ const considerPublishedHostFold = (sessionID) => {
8566
+ if (rustModeModuleClient)
8567
+ return;
8568
+ hostFoldIdle?.published(sessionID, () => {
8569
+ if (!db)
8570
+ return false;
8571
+ try {
8572
+ const reading = loadPersistedUsage(db, sessionID);
8573
+ if (!reading)
8574
+ return false;
8575
+ const threshold = resolveExecuteThresholdDetail(config.execute_threshold_percentage, reading.lastObservedModelKey ?? undefined, 65, {
8576
+ tokensConfig: config.execute_threshold_tokens,
8577
+ contextLimit: reading.lastUsageContextLimit,
8578
+ sessionId: sessionID
8579
+ });
8580
+ return publishedHistoryCanRide({
8581
+ directoryResolved: sessionDirectories.has(sessionID),
8582
+ percentage: reading.usage.percentage,
8583
+ executeThreshold: threshold.percentage,
8584
+ publishedEnd: getLastCompartmentEndMessageId(db, sessionID),
8585
+ servedEnd: readSessionMeta(db, sessionID).cachedM0TrimBoundaryId ?? null
8586
+ });
8587
+ } catch {
8588
+ return false;
8589
+ }
8590
+ });
8591
+ };
8335
8592
  cleanup.idle = () => {
8336
8593
  messageTimesCache.clear();
8337
8594
  recoveredInstructions.clear();
@@ -8524,6 +8781,7 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
8524
8781
  if (db) {
8525
8782
  const meta = getOrCreateSessionMeta(db, sessionID);
8526
8783
  hostFoldIdle?.idle(sessionID, meta.cacheTtl, meta.lastResponseTime);
8784
+ considerPublishedHostFold(sessionID);
8527
8785
  }
8528
8786
  }
8529
8787
  }
@@ -8681,17 +8939,18 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
8681
8939
  const temporalTimes = config.temporal_awareness === true;
8682
8940
  const anchorTimesOnly = !temporalTimes && !rustModeModuleClient;
8683
8941
  const foldedInstructionIDs = new Map;
8684
- const retireInstructionMessages = async (sessionID, reader, messages) => {
8685
- const retired = await nativeFoldReplay?.instructionRetirement(sessionID, reader);
8686
- if (!retired)
8942
+ const retireInstructionMessages = async (sessionID, reader, messages, leftOut) => {
8943
+ const recorded = await nativeFoldReplay?.instructionRetirement(sessionID, reader);
8944
+ if (!recorded)
8687
8945
  return messages;
8688
8946
  if (db) {
8689
- foldedInstructionIDs.set(sessionID, new Set([...retiredLiveInstructionIDs(db, sessionID)].filter((id) => retired({
8947
+ foldedInstructionIDs.set(sessionID, new Set([...retiredLiveInstructionIDs(db, sessionID)].filter((id) => recorded({
8690
8948
  type: "system",
8691
8949
  id,
8692
8950
  seq: reader.sequenceForId(sessionID, id) ?? Infinity
8693
8951
  }))));
8694
8952
  }
8953
+ const retired = (row) => recorded(row) || isLeftOutInstruction(leftOut, row);
8695
8954
  return messages.filter((message) => {
8696
8955
  const id = nativeRowID(message);
8697
8956
  return message.role !== "system" || !id || !retired({
@@ -8754,6 +9013,17 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
8754
9013
  ...args.messages.filter((message) => message !== args.incoming)
8755
9014
  ];
8756
9015
  };
9016
+ const restoreAdmittedCheckpoint = async (draft, messages, incoming, restored, reader, coveredThrough) => {
9017
+ const merged = restoreNativeCheckpointInput(messages, incoming, restored, reader, draft.sessionID);
9018
+ if (coveredThrough === undefined)
9019
+ return merged;
9020
+ const present = new Set(merged.map(nativeRowID));
9021
+ const retired = await nativeFoldReplay?.admittedInstructionRetirement(draft.sessionID, reader);
9022
+ return [
9023
+ ...coveredInstructionRows(reader, draft.sessionID, coveredThrough, draft.model, (row) => present.has(row.id) || retired?.(row) === true),
9024
+ ...merged
9025
+ ];
9026
+ };
8757
9027
  const checkpointPassPermissions = new Map;
8758
9028
  const checkpointInputEstimates = new Map;
8759
9029
  const admissionRebuildPasses = new Set;
@@ -8777,7 +9047,13 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
8777
9047
  onPassPermission: (sessionID, permission) => {
8778
9048
  checkpointPassPermissions.set(sessionID, permission);
8779
9049
  },
8780
- reclaimHostRows: (sessionID, messages, permitted, covered) => reclaimInstructionRows(database, sessionID, messages, permitted, foldedInstructionIDs.get(sessionID), covered),
9050
+ onHistoryPublished: considerPublishedHostFold,
9051
+ reclaimHostRows: (sessionID, messages, permitted, covered) => {
9052
+ const pass = contextPass.getStore();
9053
+ if (pass)
9054
+ pass.legacyCoveredReclaimPermitted = permitted;
9055
+ return reclaimInstructionRows(database, sessionID, messages, permitted, foldedInstructionIDs.get(sessionID), covered, pass?.checkpointSequence, pass?.checkpointCoveredThrough);
9056
+ },
8781
9057
  compactionOff,
8782
9058
  storeGeneration: "v2",
8783
9059
  normalizeRestoredAssistantText: (text, providerID) => stripCopiedTagNotation(text, providerID === "anthropic"),
@@ -8982,6 +9258,7 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
8982
9258
  if (!rustModeModuleClient) {
8983
9259
  syntheticIDs = await readSyntheticProvenance(reader, messages);
8984
9260
  const replayDb = db ?? storage.current();
9261
+ let leftOut;
8985
9262
  if (!compactionOff && localCut && incoming && replayDb) {
8986
9263
  const admission = nativeFoldReplay ? await nativeFoldReplay.replayAdmission(draft.sessionID, localCut, reader) : "legacy";
8987
9264
  if (admission === undefined)
@@ -8996,7 +9273,9 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
8996
9273
  });
8997
9274
  if (!restored)
8998
9275
  return;
8999
- messages = restoreNativeCheckpointInput(messages, incoming, restored, reader, draft.sessionID);
9276
+ const legacy = await nativeFoldReplay.leftOutForPass(draft.sessionID, localCut, reader, "native");
9277
+ leftOut = legacy?.leftOut;
9278
+ messages = await restoreAdmittedCheckpoint(draft, messages, incoming, restored, reader, legacy?.restoreCoveredThrough ?? await nativeFoldReplay.coveredInstructionReclaimBoundary(draft.sessionID, localCut, reader));
9000
9279
  } else {
9001
9280
  messages = await restoreAfterCheckpoint({
9002
9281
  db: replayDb,
@@ -9006,10 +9285,11 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9006
9285
  cut: localCut,
9007
9286
  incoming
9008
9287
  });
9288
+ leftOut = (await nativeFoldReplay?.leftOutForPass(draft.sessionID, localCut, reader, "fallback"))?.leftOut;
9009
9289
  }
9010
9290
  } else if (localCut)
9011
9291
  return;
9012
- messages = await retireInstructionMessages(draft.sessionID, reader, messages);
9292
+ messages = await retireInstructionMessages(draft.sessionID, reader, messages, leftOut);
9013
9293
  times = readTimes(reader, messages);
9014
9294
  }
9015
9295
  } finally {
@@ -9163,6 +9443,7 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9163
9443
  let syntheticIDs;
9164
9444
  let messageTimes;
9165
9445
  let instructionRows = new Map;
9446
+ let legacyInstructions;
9166
9447
  const reader = openStoreReader();
9167
9448
  let checkpoint;
9168
9449
  let submitted;
@@ -9173,6 +9454,8 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9173
9454
  try {
9174
9455
  syntheticIDs = await readSyntheticProvenance(reader, draft.messages);
9175
9456
  const cut = reader.latestCompaction(draft.sessionID);
9457
+ if (!rustModeModuleClient)
9458
+ pass.checkpointSequence = cut?.seq;
9176
9459
  if (nativeFoldReplay)
9177
9460
  draftSourceIdentity = await nativeFoldReplay.observeSource(draft.sessionID, reader);
9178
9461
  const boundaryRepair = !rustModeModuleClient && db && !compactionOff ? revertMessageCleanup.retireProvenHistory(db, draft.sessionID, reader) ?? checkHistoryBoundary(db, reader, draft.sessionID) : undefined;
@@ -9238,9 +9521,15 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9238
9521
  historyRefreshSessions.add(draft.sessionID);
9239
9522
  requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "host_history_change");
9240
9523
  }
9524
+ if (!rustModeModuleClient && cut)
9525
+ pass.checkpointCoveredThrough = await nativeFoldReplay?.coveredInstructionReclaimBoundary(draft.sessionID, cut, reader);
9241
9526
  if (cut && incoming && nativeRestored) {
9242
9527
  pass.restoredAfterSummaryId = nativeRestoredAfterSummaryId;
9243
- draft.messages.splice(0, draft.messages.length, ...restoreNativeCheckpointInput(draft.messages, incoming, nativeRestored, reader, draft.sessionID));
9528
+ if (!rustModeModuleClient) {
9529
+ legacyInstructions = await nativeFoldReplay?.leftOutForPass(draft.sessionID, cut, reader, "native");
9530
+ pass.checkpointCoveredThrough ??= legacyInstructions?.restoreCoveredThrough;
9531
+ }
9532
+ draft.messages.splice(0, draft.messages.length, ...await restoreAdmittedCheckpoint(draft, draft.messages, incoming, nativeRestored, reader, pass.checkpointCoveredThrough));
9244
9533
  } else if (!compactionOff && localCut && cut && incoming) {
9245
9534
  const legacy = await folds.read(draft.sessionID);
9246
9535
  if (legacy?.cutSeq === cut.seq && legacy.submittedSha === foldDigest(cut.data.summary ?? "")) {
@@ -9275,9 +9564,11 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9275
9564
  restoredFirstRow = id;
9276
9565
  }
9277
9566
  }));
9567
+ if (!rustModeModuleClient)
9568
+ legacyInstructions = await nativeFoldReplay?.leftOutForPass(draft.sessionID, cut, reader, "fallback");
9278
9569
  }
9279
9570
  instructionRows = new Map(bindKeptInstructionCoordinates(draft.messages, incoming || undefined, reader, draft.sessionID).map((row) => [row.id, row]));
9280
- draft.messages = await retireInstructionMessages(draft.sessionID, reader, draft.messages);
9571
+ draft.messages = await retireInstructionMessages(draft.sessionID, reader, draft.messages, legacyInstructions?.leftOut);
9281
9572
  messageTimes = readTimes(reader, draft.messages);
9282
9573
  } finally {
9283
9574
  reader.close();
@@ -9326,6 +9617,8 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9326
9617
  rustReplayParticipant: () => transform?.getRustReplayParticipant() ?? null
9327
9618
  })({}, mapped);
9328
9619
  mapped.commit();
9620
+ if (pass.legacyCoveredReclaimPermitted && replayHead === undefined)
9621
+ pass.stageLegacyRetirement = legacyInstructions?.stageRetirement;
9329
9622
  if (replayHead === undefined && (pass.recoveredCheckpointID || previousRecovery && pass.nativeReplayCheckpointID === previousRecovery.checkpointID)) {
9330
9623
  let coveredAfterRestore;
9331
9624
  if (pass.recoveredCheckpointID && restoredFirstRow) {
@@ -9545,11 +9838,23 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9545
9838
  hostFoldIdle.idle(draft.sessionID, meta.cacheTtl, meta.lastResponseTime);
9546
9839
  }
9547
9840
  }
9841
+ if (!deletedSessions.has(draft.sessionID)) {
9842
+ let recorded = false;
9843
+ try {
9844
+ pass.stageLegacyRetirement?.();
9845
+ recorded = nativeFoldReplay?.commitPassLeftOut(draft.sessionID) ?? true;
9846
+ } catch {
9847
+ recorded = false;
9848
+ }
9849
+ if (!recorded)
9850
+ sessionLog2(draft.sessionID, "v2 host fold: instruction rows an older checkpoint record left out were not recorded; the next pass leaves them out again");
9851
+ }
9548
9852
  returned = true;
9549
9853
  } finally {
9550
9854
  admissionRebuildPasses.delete(draft.sessionID);
9551
9855
  nativeFoldReplay?.cancelLegacyUpgrade(draft.sessionID);
9552
9856
  nativeFoldReplay?.cancelEditedAdmission(draft.sessionID);
9857
+ nativeFoldReplay?.cancelPassLeftOut(draft.sessionID);
9553
9858
  checkpointInputEstimates.delete(draft.sessionID);
9554
9859
  checkpointPassPermissions.delete(draft.sessionID);
9555
9860
  foldedInstructionIDs.delete(draft.sessionID);
@@ -9623,6 +9928,18 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9623
9928
  compactionMarkerStrategy: v2CompactionMarkerStrategy,
9624
9929
  prepareHistorySession,
9625
9930
  readForkHistoryGap: (database, sessionID) => readForkHistoryGap(database, openStoreReader, sessionID),
9931
+ readCheckpointInstructions: (sessionID) => {
9932
+ try {
9933
+ const reader = openStoreReader();
9934
+ try {
9935
+ return reader.checkpointInstructionEstimate(sessionID);
9936
+ } finally {
9937
+ reader.close();
9938
+ }
9939
+ } catch {
9940
+ return;
9941
+ }
9942
+ },
9626
9943
  readSessionDirectory: async (sessionID) => {
9627
9944
  try {
9628
9945
  return (await context.session.get({ sessionID })).location?.directory ?? null;