@cortexkit/opencode-magic-context 0.49.93 → 0.49.96

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 (256) hide show
  1. package/dist/{announcement-4ynkaf0d.js → announcement-8nj2jd87.js} +5 -5
  2. package/dist/auto-search-worker.js +5 -5
  3. package/dist/chunk-embedding-write-worker.js +16 -16
  4. package/dist/{compaction-marker-candidates-1ndjqh9k.js → compaction-marker-candidates-a4b0anvv.js} +3 -3
  5. package/dist/compaction-marker-candidates-worker.js +1 -1
  6. package/dist/{compartment-chunk-embedding-rp4asvk0.js → compartment-chunk-embedding-re2cw7y3.js} +8 -8
  7. package/dist/config/removed-agent-config.d.ts +1 -1
  8. package/dist/config/removed-agent-config.d.ts.map +1 -1
  9. package/dist/config/schema/magic-context.d.ts +0 -75
  10. package/dist/config/schema/magic-context.d.ts.map +1 -1
  11. package/dist/{conflict-warning-hook-exf96bpt.js → conflict-warning-hook-wcq55y61.js} +8 -8
  12. package/dist/{context-jpxthqxg.js → context-gtjdrp8f.js} +237 -140
  13. package/dist/{derive-budgets-hzzq71rm.js → derive-budgets-g1sy72e8.js} +5 -5
  14. package/dist/embedding-backfill-pdymqbnh.js +29 -0
  15. package/dist/embedding-worker-process.js +2 -2
  16. package/dist/embedding-worker.js +8 -8
  17. package/dist/features/magic-context/compartment-storage.d.ts.map +1 -1
  18. package/dist/features/magic-context/dreamer/docs-proposals.d.ts +5 -2
  19. package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
  20. package/dist/features/magic-context/dreamer/token-budget.d.ts +2 -2
  21. package/dist/features/magic-context/dreamer/token-budget.d.ts.map +1 -1
  22. package/dist/features/magic-context/history-gap-recovery.d.ts +42 -0
  23. package/dist/features/magic-context/history-gap-recovery.d.ts.map +1 -0
  24. package/dist/features/magic-context/memory/embedding-synapse.d.ts +18 -5
  25. package/dist/features/magic-context/memory/embedding-synapse.d.ts.map +1 -1
  26. package/dist/features/magic-context/message-visibility.d.ts +10 -0
  27. package/dist/features/magic-context/message-visibility.d.ts.map +1 -0
  28. package/dist/features/magic-context/search-rerank.d.ts +2 -2
  29. package/dist/features/magic-context/search-rerank.d.ts.map +1 -1
  30. package/dist/features/magic-context/search.d.ts +4 -0
  31. package/dist/features/magic-context/search.d.ts.map +1 -1
  32. package/dist/features/magic-context/session-decision-calibration.d.ts.map +1 -1
  33. package/dist/features/magic-context/session-project-backfill.d.ts.map +1 -1
  34. package/dist/features/magic-context/store-generation-rebase.d.ts.map +1 -1
  35. package/dist/{history-owner-xqfsvf9k.js → history-owner-74826t4n.js} +3 -3
  36. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  37. package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
  38. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  39. package/dist/hooks/magic-context/history-boundary-repair.d.ts +2 -2
  40. package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
  41. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  42. package/dist/hooks/magic-context/inject-compartments.d.ts +6 -1
  43. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  44. package/dist/hooks/magic-context/lkg-persist.d.ts +3 -1
  45. package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
  46. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +1 -0
  47. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
  48. package/dist/hooks/magic-context/lkg-replay.d.ts +3 -0
  49. package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
  50. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +1 -0
  51. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
  52. package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts +4 -0
  53. package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts.map +1 -1
  54. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +2 -0
  55. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
  56. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +2 -1
  57. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  58. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +1 -0
  59. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  60. package/dist/hooks/magic-context/transform-stage-logger.d.ts +6 -0
  61. package/dist/hooks/magic-context/transform-stage-logger.d.ts.map +1 -1
  62. package/dist/hooks/magic-context/transform.d.ts +2 -0
  63. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  64. package/dist/{index-5zrzg8r1.js → index-0bjj9yf3.js} +2 -2
  65. package/dist/{index-g9qtxv87.js → index-0sqhg9nf.js} +132 -64
  66. package/dist/{index-nxxzeq4y.js → index-0ve29s6f.js} +1 -1
  67. package/dist/{index-g6y2wk32.js → index-2afrmgy3.js} +6 -6
  68. package/dist/{index-ywrz4wy2.js → index-3fhb0j32.js} +1 -1
  69. package/dist/{index-gqf8r04r.js → index-3n4j5rqc.js} +1 -1
  70. package/dist/{index-xsqw8kbd.js → index-45qgkg8j.js} +2 -2
  71. package/dist/{index-5df2fw5b.js → index-6mryx739.js} +1 -1
  72. package/dist/{index-n9kd68vc.js → index-7m2tnk8q.js} +10 -10
  73. package/dist/{index-r4y0dczp.js → index-7sdns2ww.js} +2 -2
  74. package/dist/{index-mjy2k9jr.js → index-880a24vd.js} +1 -1
  75. package/dist/{index-pnawfv4e.js → index-89bkkgcn.js} +4 -4
  76. package/dist/{index-s32f8y67.js → index-89xg64wb.js} +2 -2
  77. package/dist/{index-hee64h6k.js → index-8sgv96kq.js} +7 -7
  78. package/dist/{index-ttdk2w0z.js → index-910gahfb.js} +6 -6
  79. package/dist/{index-kty5k23y.js → index-9jvxq5rt.js} +4 -4
  80. package/dist/{index-832w615x.js → index-azkfw78y.js} +1 -1
  81. package/dist/{index-wh9fxds5.js → index-c205x7xd.js} +1 -1
  82. package/dist/{index-mg9s2rc3.js → index-cpbr0xvk.js} +2 -2
  83. package/dist/{index-g5c67kay.js → index-cq8znmyw.js} +17 -17
  84. package/dist/{index-cr483vx6.js → index-dj64gzg5.js} +2 -2
  85. package/dist/{index-jba6ny4m.js → index-dnpcv1rg.js} +4 -4
  86. package/dist/{index-z4p0ry94.js → index-dt7cyqfe.js} +2 -1
  87. package/dist/{index-j2w79s9r.js → index-e6ay1gez.js} +2 -2
  88. package/dist/{index-y2vshk67.js → index-f154w8m4.js} +229 -84
  89. package/dist/{index-6r99v53h.js → index-fgw241hh.js} +164 -62
  90. package/dist/{index-rz47hf2m.js → index-fvfnq8n6.js} +30 -14
  91. package/dist/{index-yqha238s.js → index-gnrwgvn7.js} +127 -17
  92. package/dist/{index-fpjnjxyx.js → index-h7kta6cn.js} +3 -3
  93. package/dist/{index-q7q6qp1f.js → index-hedgz8an.js} +1 -1
  94. package/dist/{index-5pgyqgmx.js → index-hj78hvhm.js} +2 -2
  95. package/dist/{index-dr6bd4c8.js → index-hp46xe93.js} +7 -7
  96. package/dist/{index-0twg41mh.js → index-j4dcjb8t.js} +4 -4
  97. package/dist/{index-e6ncz7a6.js → index-jzrvdqb8.js} +1 -1
  98. package/dist/{index-sp5pvs95.js → index-k34hc455.js} +2 -2
  99. package/dist/{index-9ffntwyr.js → index-kj4bprep.js} +4 -4
  100. package/dist/index-mgy7g740.js +119 -0
  101. package/dist/{index-za1yx1m4.js → index-nqdwpdje.js} +154 -32
  102. package/dist/{index-hes3k87g.js → index-r1d45dsr.js} +4 -4
  103. package/dist/{index-y915t3ey.js → index-r3f85n7y.js} +5 -1
  104. package/dist/{index-1kem0xxx.js → index-t2e10rag.js} +5 -5
  105. package/dist/{index-m0pwswv9.js → index-tqtpgnhr.js} +1 -1
  106. package/dist/{index-01h7tqe3.js → index-tr4ep2ej.js} +21 -6
  107. package/dist/{index-xr1t0fxb.js → index-w7n7qkpf.js} +49 -13
  108. package/dist/{index-s7460efs.js → index-zfx7mtqa.js} +1 -1
  109. package/dist/{index-gqfy38m9.js → index-zkjx8gq3.js} +11 -11
  110. package/dist/{index-et39x9k3.js → index-zmgp0tr6.js} +3 -3
  111. package/dist/index.js +59 -56
  112. package/dist/{logger-d7c8akh9.js → logger-nmb2508f.js} +2 -2
  113. package/dist/{message-fts-rowid-map-0xx8ge09.js → message-fts-rowid-map-vcatdan0.js} +5 -5
  114. package/dist/{message-index-bounded-vjrnptar.js → message-index-bounded-abhwe610.js} +12 -12
  115. package/dist/{message-time-backfill-pz5981mf.js → message-time-backfill-zc5rsvhv.js} +3 -3
  116. package/dist/migration-worker.js +13 -13
  117. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  118. package/dist/{project-embedding-registry-m8zcmrsg.js → project-embedding-registry-e566q4bg.js} +15 -15
  119. package/dist/raw-ordinal-warmup-worker.js +9 -9
  120. package/dist/{read-session-chunk-zkzdc0e5.js → read-session-chunk-sde0wym3.js} +10 -10
  121. package/dist/{read-session-raw-3sc9231y.js → read-session-raw-trhdgc9z.js} +3 -3
  122. package/dist/recomp-orchestrator-d3rbpa59.js +69 -0
  123. package/dist/render-6cf1dgc4.js +43 -0
  124. package/dist/{safe-notification-target-d21swr3n.js → safe-notification-target-54ns7dv9.js} +3 -3
  125. package/dist/{search-e9bb9hpx.js → search-11aw8wpq.js} +27 -27
  126. package/dist/search-archive-s9m5szf0.js +29 -0
  127. package/dist/{send-session-notification-0779tyd9.js → send-session-notification-gxrj4w1r.js} +6 -6
  128. package/dist/shared/host-sqlite-runtime.d.ts +3 -0
  129. package/dist/shared/host-sqlite-runtime.d.ts.map +1 -0
  130. package/dist/shared/redaction.d.ts.map +1 -1
  131. package/dist/shared/storage-file-mutex.d.ts.map +1 -1
  132. package/dist/{storage-tags-gk7gjkqt.js → storage-tags-jq0c0zsn.js} +7 -7
  133. package/dist/{store-yr443ye8.js → store-29ksp6vy.js} +4 -4
  134. package/dist/{store-reader-qbq6q4v0.js → store-reader-dgh3ssxx.js} +1 -1
  135. package/dist/tools/ctx-expand/search-archive.d.ts +3 -2
  136. package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
  137. package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
  138. package/dist/tools/ctx-expand/v2-archive-reader.d.ts +2 -0
  139. package/dist/tools/ctx-expand/v2-archive-reader.d.ts.map +1 -1
  140. package/dist/tools/ctx-search/tools.d.ts.map +1 -1
  141. package/dist/{transform-postprocess-phase-neds90e3.js → transform-postprocess-phase-376xn40x.js} +35 -35
  142. package/dist/v2/auto-search-worker.js +5 -5
  143. package/dist/v2/chunk-embedding-write-worker.js +16 -16
  144. package/dist/v2/{compaction-marker-candidates-bp1bn579.js → compaction-marker-candidates-6nypmsr3.js} +3 -3
  145. package/dist/v2/compaction-marker-candidates-worker.js +1 -1
  146. package/dist/v2/{compartment-chunk-embedding-w7ht0t9v.js → compartment-chunk-embedding-jthtfhcd.js} +8 -8
  147. package/dist/v2/{context-ctsd80vc.js → context-vm09agrs.js} +426 -185
  148. package/dist/v2/{derive-budgets-hr4qqrnv.js → derive-budgets-wj0q7s7d.js} +6 -6
  149. package/dist/v2/embedding-backfill-16b16m38.js +29 -0
  150. package/dist/v2/embedding-worker-process.js +2 -2
  151. package/dist/v2/embedding-worker.js +8 -8
  152. package/dist/v2/fold/memory-cache.d.ts +2 -0
  153. package/dist/v2/fold/memory-cache.d.ts.map +1 -1
  154. package/dist/v2/fold/native-replay.d.ts +23 -5
  155. package/dist/v2/fold/native-replay.d.ts.map +1 -1
  156. package/dist/v2/hidden-child-native.d.ts.map +1 -1
  157. package/dist/v2/hidden-child-record.d.ts +8 -0
  158. package/dist/v2/hidden-child-record.d.ts.map +1 -1
  159. package/dist/v2/hidden-completion.d.ts.map +1 -1
  160. package/dist/v2/hidden-run-holder.d.ts +8 -2
  161. package/dist/v2/hidden-run-holder.d.ts.map +1 -1
  162. package/dist/v2/{history-owner-260djmv5.js → history-owner-8pd5ax3n.js} +3 -3
  163. package/dist/v2/hooks/context.d.ts.map +1 -1
  164. package/dist/v2/hooks/hidden-child.d.ts +3 -0
  165. package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
  166. package/dist/v2/hooks/revert-message-state.d.ts.map +1 -1
  167. package/dist/v2/hooks/session-project-backfill.d.ts +2 -1
  168. package/dist/v2/hooks/session-project-backfill.d.ts.map +1 -1
  169. package/dist/v2/{logger-zyf43np1.js → logger-58jfese9.js} +2 -2
  170. package/dist/v2/{message-fts-rowid-map-n8mcvcpz.js → message-fts-rowid-map-ax4vk78j.js} +5 -5
  171. package/dist/v2/{message-index-bounded-1vew9c37.js → message-index-bounded-qh794qxx.js} +12 -12
  172. package/dist/v2/{message-time-backfill-ynb3vg6r.js → message-time-backfill-yj773saf.js} +3 -3
  173. package/dist/v2/migration-worker.js +13 -13
  174. package/dist/v2/{project-embedding-registry-je5jam7y.js → project-embedding-registry-z05xvckg.js} +15 -15
  175. package/dist/v2/raw-ordinal-warmup-worker.js +9 -9
  176. package/dist/v2/{read-session-chunk-09sre4xv.js → read-session-chunk-8tn2dbn1.js} +10 -10
  177. package/dist/v2/{read-session-raw-wg5zc29f.js → read-session-raw-ywebck9q.js} +3 -3
  178. package/dist/v2/recomp-orchestrator-pfjpzdrb.js +69 -0
  179. package/dist/v2/render-7t5d7hkv.js +43 -0
  180. package/dist/v2/{safe-notification-target-y55z2zat.js → safe-notification-target-zrwbh6k7.js} +3 -3
  181. package/dist/v2/{search-gmye6n25.js → search-35cz80x0.js} +26 -26
  182. package/dist/v2/search-archive-5dpxv0ck.js +29 -0
  183. package/dist/v2/{send-session-notification-v69y04f5.js → send-session-notification-8x146x5y.js} +6 -6
  184. package/dist/v2/{server-z9czv2vb.js → server-11ra1pmx.js} +49 -13
  185. package/dist/v2/{server-gs2251jr.js → server-2cq3e1c1.js} +4 -4
  186. package/dist/v2/{server-39bcszk4.js → server-2qvnr3t7.js} +1 -1
  187. package/dist/v2/{server-jkj1dq6j.js → server-2sare4qg.js} +4 -4
  188. package/dist/v2/{server-jdfe07mp.js → server-2wz6y46g.js} +1 -1
  189. package/dist/v2/{server-at0v0z4t.js → server-379fd3n7.js} +1 -1
  190. package/dist/v2/{server-ds8vpfkr.js → server-40vdz8sf.js} +2 -2
  191. package/dist/v2/{server-qntmqaca.js → server-4yrvbnnm.js} +2 -2
  192. package/dist/v2/{server-x69fqsvz.js → server-5t4nzfpt.js} +1 -1
  193. package/dist/v2/{server-npdey91q.js → server-63ree5ns.js} +1 -1
  194. package/dist/v2/{server-gqkdfdvw.js → server-6qax5pds.js} +2 -2
  195. package/dist/v2/{server-qb3s0mnc.js → server-73bqw5c0.js} +1 -1
  196. package/dist/v2/{server-6chcnnhq.js → server-7h4gwphm.js} +4 -4
  197. package/dist/v2/{server-rkj44mez.js → server-7tj8yzrv.js} +2 -2
  198. package/dist/v2/{server-e6xneh68.js → server-arfzfxe8.js} +5 -1
  199. package/dist/v2/{server-6ash6z8z.js → server-av3p9c8k.js} +1 -1
  200. package/dist/v2/{server-5hwf5c7r.js → server-bx5k66qc.js} +1 -1
  201. package/dist/v2/{server-dgsjamm4.js → server-db91dxwc.js} +7 -7
  202. package/dist/v2/{server-z4p0ry94.js → server-dt7cyqfe.js} +2 -1
  203. package/dist/v2/{server-k1xc2bw1.js → server-ganavh75.js} +2 -2
  204. package/dist/v2/{server-6x40bnb7.js → server-gh2w75fn.js} +3 -3
  205. package/dist/v2/server-j1gxs1gj.js +119 -0
  206. package/dist/v2/{server-ps6zrzwj.js → server-k3ntgf6n.js} +164 -62
  207. package/dist/v2/{server-j8376q08.js → server-kzrrdjp5.js} +1 -1
  208. package/dist/v2/{server-1rrmxhd1.js → server-n33hyq9t.js} +2 -2
  209. package/dist/v2/{server-0tv6kytx.js → server-n34vzyfm.js} +1 -1
  210. package/dist/v2/{server-vc5fta6s.js → server-nnh81jqy.js} +6 -6
  211. package/dist/v2/{server-g53asaqt.js → server-pcq2d1wh.js} +30 -14
  212. package/dist/v2/{server-bnkc9kph.js → server-ppy2dj7g.js} +6 -6
  213. package/dist/v2/{server-96nm9vk4.js → server-rr5c0xcg.js} +2 -2
  214. package/dist/v2/{server-j4jjtdc5.js → server-rt8t6s2a.js} +2 -2
  215. package/dist/v2/{server-2xm0gxke.js → server-svccj9rd.js} +4 -4
  216. package/dist/v2/{server-5sbsnpkn.js → server-tq523gj6.js} +1 -1
  217. package/dist/v2/{server-00adcfjd.js → server-vj0xbbrc.js} +17 -3
  218. package/dist/v2/{server-4ecpanyn.js → server-vntc961c.js} +127 -17
  219. package/dist/v2/{server-btgnkr9z.js → server-vsx9tsks.js} +11 -11
  220. package/dist/v2/{server-vtgeyhq6.js → server-vtkbxzw1.js} +21 -6
  221. package/dist/v2/{server-cvp9w5gs.js → server-w35ep6wn.js} +192 -84
  222. package/dist/v2/{server-myp4pc6x.js → server-z2nv8jdv.js} +132 -64
  223. package/dist/v2/{server-pcarsvj2.js → server-z5cv5wm5.js} +10 -10
  224. package/dist/v2/{server-barj0mjz.js → server-zemnpv92.js} +4 -4
  225. package/dist/v2/server.js +9 -9
  226. package/dist/v2/{storage-tags-nccqr0kr.js → storage-tags-pcenytad.js} +7 -7
  227. package/dist/v2/{store-enef5jcn.js → store-gx19qc3a.js} +4 -4
  228. package/dist/v2/{store-reader-jbaqv1yp.js → store-reader-qt2msa8z.js} +1 -1
  229. package/dist/v2/store-reader.d.ts +1 -1
  230. package/dist/v2/store-reader.d.ts.map +1 -1
  231. package/dist/v2/{v2-archive-reader-7vmng8q7.js → v2-archive-reader-jqrwz7b8.js} +1 -1
  232. package/dist/v2/{wrapup-orchestrator-7r4y0bf6.js → wrapup-orchestrator-kcq3cv7y.js} +35 -35
  233. package/dist/{v2-archive-reader-7s90gfax.js → v2-archive-reader-64h2gtam.js} +1 -1
  234. package/dist/wrapup-orchestrator-knyac7jp.js +56 -0
  235. package/package.json +1 -1
  236. package/src/config/index.test.ts +23 -5
  237. package/src/config/live-run-config.test.ts +7 -7
  238. package/src/config/removed-agent-config.ts +14 -1
  239. package/src/config/schema/magic-context.ts +5 -1
  240. package/src/shared/host-sqlite-runtime.test.ts +21 -0
  241. package/src/shared/host-sqlite-runtime.ts +32 -0
  242. package/src/shared/redaction.test.ts +11 -8
  243. package/src/shared/redaction.ts +5 -1
  244. package/src/shared/storage-file-mutex-review.test.ts +110 -0
  245. package/src/shared/storage-file-mutex.ts +12 -0
  246. package/dist/embedding-backfill-6wzc4p2n.js +0 -29
  247. package/dist/index-52x68mj4.js +0 -58
  248. package/dist/recomp-orchestrator-qb2hymj5.js +0 -69
  249. package/dist/render-34p0kek8.js +0 -43
  250. package/dist/search-archive-08ppk0q5.js +0 -27
  251. package/dist/v2/embedding-backfill-40g0anxh.js +0 -29
  252. package/dist/v2/recomp-orchestrator-mgcty3we.js +0 -69
  253. package/dist/v2/render-ygcmyn9x.js +0 -43
  254. package/dist/v2/search-archive-nrsqqmk5.js +0 -27
  255. package/dist/v2/server-52x68mj4.js +0 -58
  256. package/dist/wrapup-orchestrator-m2p89973.js +0 -56
@@ -7,18 +7,21 @@ import {
7
7
  pluginConfigReader,
8
8
  withLiveDreamerOutputCap,
9
9
  HiddenCompletionRefusal,
10
+ keptUnderRetention,
11
+ roleTitle,
12
+ childCreateInput,
13
+ assistantOutcome,
14
+ withReader,
15
+ errorText,
16
+ supportsHolderArchive,
10
17
  supportsQuietHiddenChildren,
11
18
  matchesHiddenRunLocation,
12
19
  hiddenRunPlacement,
13
- HIDDEN_HISTORIAN_AGENT,
14
- HIDDEN_DREAMER_AGENT,
15
20
  HIDDEN_CURATE_AGENT,
16
- hiddenAgentFor,
17
21
  hiddenToolLoop,
18
22
  HIDDEN_RUN_DISPOSED_REASON,
19
23
  noteChildOfDisposedInstance,
20
24
  noteTimedOutHiddenChild,
21
- hiddenChildPermissions,
22
25
  registerHiddenChildAgents,
23
26
  hiddenToolCallRefusal,
24
27
  HiddenAgentStepLimit,
@@ -48,7 +51,7 @@ import {
48
51
  clearNoteNudgeTriggerOnly,
49
52
  nonNarrativeStoredGapRanges,
50
53
  getActiveCompartmentRun
51
- } from "./index-za1yx1m4.js";
54
+ } from "./index-nqdwpdje.js";
52
55
  import"./index-sd3egckz.js";
53
56
  import {
54
57
  getHarness2
@@ -58,10 +61,10 @@ import {
58
61
  getMagicContextStorageDir,
59
62
  log2,
60
63
  sessionLog2
61
- } from "./index-ywrz4wy2.js";
62
- import"./index-z4p0ry94.js";
63
- import"./index-gqf8r04r.js";
64
- import"./index-5df2fw5b.js";
64
+ } from "./index-3fhb0j32.js";
65
+ import"./index-dt7cyqfe.js";
66
+ import"./index-3n4j5rqc.js";
67
+ import"./index-6mryx739.js";
65
68
  import {
66
69
  isSaneLimit,
67
70
  setOutputReserveConfig,
@@ -72,7 +75,7 @@ import {
72
75
  deriveHistorianChunkTokens2,
73
76
  resolveKnownHistorianContextLimit2,
74
77
  resolveHistorianContextLimit2
75
- } from "./index-xsqw8kbd.js";
78
+ } from "./index-45qgkg8j.js";
76
79
  import {
77
80
  isDreamerRunnable,
78
81
  isSmartNoteSurfaceAvailable,
@@ -82,7 +85,7 @@ import {
82
85
  formatUnsupportedDreamTasks,
83
86
  isCanonicalDreamTask
84
87
  } from "./index-fqth7850.js";
85
- import"./index-y915t3ey.js";
88
+ import"./index-r3f85n7y.js";
86
89
  import {
87
90
  logConfigDependencyNotesOnce,
88
91
  runSessionProjectBackfill,
@@ -102,6 +105,7 @@ import {
102
105
  createToolExecuteAfterHook,
103
106
  recordHiddenVariantWarning,
104
107
  registerRpcHandlers,
108
+ recordHostSqliteRuntime,
105
109
  maybeAutoEmbedSessionBackfill,
106
110
  stageOpenCodeV2TransformDecision,
107
111
  bindOpenCodeV2TransformDecision,
@@ -143,7 +147,7 @@ import {
143
147
  applyJsonSchemaParameterDescriptions,
144
148
  MagicContextRpcServer,
145
149
  subagentTemperature
146
- } from "./index-y2vshk67.js";
150
+ } from "./index-f154w8m4.js";
147
151
  import {
148
152
  invalidateAutoEmbedSession,
149
153
  clearEmbedSessionState
@@ -152,8 +156,8 @@ import {
152
156
  hasMeaningfulUserText2,
153
157
  preloadTokenizer,
154
158
  estimateTokens
155
- } from "./index-s7460efs.js";
156
- import"./index-6r99v53h.js";
159
+ } from "./index-zfx7mtqa.js";
160
+ import"./index-fgw241hh.js";
157
161
  import {
158
162
  inRootAsyncContext2,
159
163
  withSqliteTransformPass2,
@@ -164,17 +168,19 @@ import {
164
168
  import"./index-v0p37hm2.js";
165
169
  import"./index-96ztjvkn.js";
166
170
  import"./index-1d042x6w.js";
167
- import"./index-q7q6qp1f.js";
168
- import"./index-s32f8y67.js";
171
+ import"./index-hedgz8an.js";
172
+ import"./index-89xg64wb.js";
169
173
  import {
170
174
  deleteChunkEmbedBackoffForSession2
171
- } from "./index-0twg41mh.js";
175
+ } from "./index-j4dcjb8t.js";
172
176
  import {
173
177
  advanceSessionActivity,
174
178
  backfillSessionActivity,
175
179
  acquireCompartmentLease,
176
180
  releaseCompartmentLeaseBestEffort,
177
181
  isCompartmentLeaseHeld,
182
+ readSummaryCoverage,
183
+ markHistoryGapAfterCoverageChange,
178
184
  queueM0Mutation,
179
185
  getLastCompartmentEndMessageId,
180
186
  clearRecompStaging,
@@ -206,8 +212,8 @@ import {
206
212
  getSlot,
207
213
  dropSlot,
208
214
  copySessionStateForClone
209
- } from "./index-yqha238s.js";
210
- import"./index-pnawfv4e.js";
215
+ } from "./index-gnrwgvn7.js";
216
+ import"./index-89bkkgcn.js";
211
217
  import {
212
218
  stripPersistedAssistantText,
213
219
  currentReclaimableToolOutputCount,
@@ -250,13 +256,13 @@ import {
250
256
  estimateFinalWireInputTokens,
251
257
  getMaxTagNumberBySession2,
252
258
  getTagsBySession2
253
- } from "./index-xr1t0fxb.js";
259
+ } from "./index-w7n7qkpf.js";
254
260
  import {
255
261
  BoundedSessionMap,
256
262
  getTableColumnNames,
257
263
  recordToolDefinitionSet,
258
264
  getCurrentToolSetHash
259
- } from "./index-mg9s2rc3.js";
265
+ } from "./index-cpbr0xvk.js";
260
266
  import {
261
267
  resolveHistorianModel2
262
268
  } from "./index-5kym00ag.js";
@@ -272,15 +278,15 @@ import {
272
278
  isFailClosedBlockingError,
273
279
  shouldBypassFailClosedBlock,
274
280
  createFailClosedController
275
- } from "./index-wh9fxds5.js";
281
+ } from "./index-c205x7xd.js";
276
282
  import {
277
283
  setHomeProjectPermission,
278
284
  resolveProjectIdentityForSession,
279
285
  scheduleAfterBootQuiet
280
- } from "./index-5pgyqgmx.js";
286
+ } from "./index-hj78hvhm.js";
281
287
  import"./index-1zx87sdm.js";
282
288
  import"./index-58e3y90n.js";
283
- import"./index-sp5pvs95.js";
289
+ import"./index-k34hc455.js";
284
290
  import {
285
291
  needsBlockedRead,
286
292
  DreamTokenBudgetExceeded,
@@ -293,10 +299,10 @@ import {
293
299
  cleanUserText2,
294
300
  readRawSessionMessageIdOrdinalsForRange2,
295
301
  readRawSessionMessageOrdinalById2
296
- } from "./index-dr6bd4c8.js";
302
+ } from "./index-hp46xe93.js";
297
303
  import {
298
304
  scheduleClearAndReindex
299
- } from "./index-kty5k23y.js";
305
+ } from "./index-9jvxq5rt.js";
300
306
  import {
301
307
  startBootDeadline,
302
308
  getSchemaFenceRejection,
@@ -306,17 +312,17 @@ import {
306
312
  openDatabaseAsync,
307
313
  isDatabasePersisted,
308
314
  getDatabasePersistenceError
309
- } from "./index-gqfy38m9.js";
315
+ } from "./index-zkjx8gq3.js";
310
316
  import"./index-fr0wbhdn.js";
311
- import"./index-jba6ny4m.js";
317
+ import"./index-dnpcv1rg.js";
312
318
  import {
313
319
  gaDatabasePath2,
314
320
  RAW_MESSAGE_TYPES2,
315
321
  V2StoreReaderPool2,
316
322
  V2StoreReader2
317
- } from "./index-01h7tqe3.js";
323
+ } from "./index-tr4ep2ej.js";
318
324
  import"./index-fb3zxn06.js";
319
- import"./index-mjy2k9jr.js";
325
+ import"./index-880a24vd.js";
320
326
  import {
321
327
  resolveContextLimit,
322
328
  resolveOpenCodeOverflowLimit,
@@ -335,34 +341,34 @@ import {
335
341
  servedHeadChanged,
336
342
  noteHostCheckpointCommit,
337
343
  isSyntheticHeadMessage2
338
- } from "./index-g5c67kay.js";
339
- import"./index-832w615x.js";
344
+ } from "./index-cq8znmyw.js";
345
+ import"./index-azkfw78y.js";
340
346
  import"./index-qt1qqasc.js";
341
347
  import {
342
348
  retainProjectEmbedding2
343
- } from "./index-n9kd68vc.js";
344
- import"./index-r4y0dczp.js";
349
+ } from "./index-7m2tnk8q.js";
350
+ import"./index-7sdns2ww.js";
345
351
  import"./index-qjwpqvnf.js";
346
- import"./index-hes3k87g.js";
352
+ import"./index-r1d45dsr.js";
347
353
  import {
348
354
  renderUserFacingFailure,
349
355
  userFacingFailureCode
350
- } from "./index-ttdk2w0z.js";
351
- import"./index-5zrzg8r1.js";
356
+ } from "./index-910gahfb.js";
357
+ import"./index-0bjj9yf3.js";
352
358
  import"./index-9emdjcb5.js";
353
359
  import {
354
360
  pushLiveNotification2,
355
361
  pushNotification2,
356
362
  isTuiConnected2
357
363
  } from "./index-y14pawe1.js";
358
- import"./index-e6ncz7a6.js";
359
- import"./index-9ffntwyr.js";
360
- import"./index-g9qtxv87.js";
361
- import"./index-1kem0xxx.js";
362
- import"./index-cr483vx6.js";
364
+ import"./index-jzrvdqb8.js";
365
+ import"./index-kj4bprep.js";
366
+ import"./index-0sqhg9nf.js";
367
+ import"./index-t2e10rag.js";
368
+ import"./index-dj64gzg5.js";
363
369
  import {
364
370
  detectConflicts
365
- } from "./index-nxxzeq4y.js";
371
+ } from "./index-0ve29s6f.js";
366
372
  import {
367
373
  STORAGE_NOTICE_PREFIX,
368
374
  formatStorageRefusalNotice,
@@ -388,12 +394,12 @@ import {
388
394
  readV2RawMessagePagesForConversion2,
389
395
  createV2RawMessageReader2,
390
396
  createV2RawMessageProvider2
391
- } from "./index-j2w79s9r.js";
397
+ } from "./index-e6ay1gez.js";
392
398
  import"./index-fmsr7v69.js";
393
- import"./index-fpjnjxyx.js";
394
- import"./index-52x68mj4.js";
395
- import"./index-g6y2wk32.js";
396
- import"./index-rz47hf2m.js";
399
+ import"./index-h7kta6cn.js";
400
+ import"./index-mgy7g740.js";
401
+ import"./index-2afrmgy3.js";
402
+ import"./index-fvfnq8n6.js";
397
403
  import {
398
404
  markHostInstructionRow,
399
405
  hostInstructionRow,
@@ -408,7 +414,7 @@ import {
408
414
  import {
409
415
  getErrorMessage
410
416
  } from "./index-y8v6yerm.js";
411
- import"./index-m0pwswv9.js";
417
+ import"./index-tqtpgnhr.js";
412
418
  import {
413
419
  sameProjectDirectory
414
420
  } from "./index-knvkbfvh.js";
@@ -474,11 +480,14 @@ function dropCompartmentsAfter(db, sessionId, anchor, holderId, activeBranch = f
474
480
  return null;
475
481
  }
476
482
  const dropped = db.prepare("SELECT id, sequence FROM compartments WHERE session_id = ? AND sequence > ? ORDER BY sequence").all(sessionId, anchor?.sequence ?? -1);
477
- onRetire?.();
483
+ const previousCoverage = readSummaryCoverage(db, sessionId);
484
+ const hostQueuedRecovery = onRetire?.() === true;
478
485
  const deleteEmbeddings = db.prepare("DELETE FROM compartment_chunk_embeddings WHERE compartment_id = ?");
479
486
  for (const row of dropped)
480
487
  deleteEmbeddings.run(row.id);
481
488
  db.prepare("DELETE FROM compartments WHERE session_id = ? AND sequence > ?").run(sessionId, anchor?.sequence ?? -1);
489
+ if (!hostQueuedRecovery)
490
+ markHistoryGapAfterCoverageChange(db, sessionId, previousCoverage);
482
491
  db.prepare("DELETE FROM compression_depth WHERE session_id = ? AND message_ordinal > ?").run(sessionId, anchor?.endMessage ?? 0);
483
492
  if (activeBranch) {
484
493
  db.prepare("UPDATE session_meta SET prior_boundary_ordinal = ? WHERE session_id = ?").run((anchor?.endMessage ?? 0) + 1, sessionId);
@@ -1463,6 +1472,9 @@ class NativeFoldCache {
1463
1472
  const kept = this.nativeRows.get(sessionID);
1464
1473
  return ids.every((id) => kept?.has(id));
1465
1474
  }
1475
+ holdsState(sessionID) {
1476
+ return this.tails.has(sessionID) || (this.nativeRows.get(sessionID)?.size ?? 0) > 0;
1477
+ }
1466
1478
  rows(sessionID, after, through) {
1467
1479
  if (this.retention.has(sessionID))
1468
1480
  this.touch(sessionID);
@@ -2363,8 +2375,11 @@ class NativeFoldReplay {
2363
2375
  stampMRU;
2364
2376
  loaded = new Map;
2365
2377
  sources = new Map;
2378
+ memorySources = new Map;
2366
2379
  staleHeads = new Set;
2367
2380
  unprovenControls = new Set;
2381
+ reportedCaptureReplacements = new Set;
2382
+ reportedForeignRefreshes = new Set;
2368
2383
  editedAdmissions = new Map;
2369
2384
  legacyUpgrades = new Map;
2370
2385
  constructor(storage, openReader, admissions, options = {}) {
@@ -2388,6 +2403,7 @@ class NativeFoldReplay {
2388
2403
  await this.forget(sessionID);
2389
2404
  this.sources.set(sessionID, source);
2390
2405
  this.account(sessionID);
2406
+ return source;
2391
2407
  }
2392
2408
  onEvent(event) {
2393
2409
  const sessionID = event.data?.sessionID;
@@ -2460,6 +2476,18 @@ class NativeFoldReplay {
2460
2476
  this.options.log?.(sessionID, `v3 host fold: ${reason}`);
2461
2477
  } catch {}
2462
2478
  }
2479
+ reportOnce(sessionID, reported, message) {
2480
+ if (reported.has(sessionID))
2481
+ return;
2482
+ reported.add(sessionID);
2483
+ const sessionLog = this.options.log;
2484
+ try {
2485
+ sessionLog?.(sessionID, message);
2486
+ } catch {}
2487
+ }
2488
+ reportCaptureReplacement(sessionID) {
2489
+ this.reportOnce(sessionID, this.reportedCaptureReplacements, "v3 host fold: capture skipped: host database file changed between readers");
2490
+ }
2463
2491
  historyCoverage(sessionID, reader) {
2464
2492
  if (!this.options.rendersHistory?.(sessionID))
2465
2493
  return;
@@ -2476,13 +2504,15 @@ class NativeFoldReplay {
2476
2504
  return false;
2477
2505
  }
2478
2506
  async floorState(sessionID, reader, boundary, served, preferCapture = false) {
2507
+ const source = reader.hostIdentity();
2508
+ await this.fenceMemory(sessionID, source);
2479
2509
  const coverage = this.historyCoverage(sessionID, reader);
2480
2510
  const retained = this.tail(sessionID)?.replay;
2481
2511
  const controlsKnown = (replay) => replay.controls.every((control) => !control.after || reader.sequenceForId(sessionID, control.after) !== undefined);
2482
2512
  const memory = retained && validReplayState(retained) && controlsKnown(retained) && validFloor(reader, sessionID, retained.floor) && this.floorCovered(sessionID, retained.floor, coverage, retained) ? retained : undefined;
2483
2513
  const cut = reader.latestCompaction(sessionID);
2484
2514
  const saved = await this.readV3(sessionID);
2485
- const durable = saved && saved.proof.sourceDigest === foldDigest(reader.hostIdentity()) && (!cut || saved.proof.admissionID === cut.id) && controlsKnown(saved.replay) && validFloor(reader, sessionID, saved.replay.floor) && this.floorCovered(sessionID, saved.replay.floor, coverage, saved.replay) ? saved.replay : undefined;
2515
+ const durable = saved && saved.proof.sourceDigest === foldDigest(source) && (!cut || saved.proof.admissionID === cut.id) && controlsKnown(saved.replay) && validFloor(reader, sessionID, saved.replay.floor) && this.floorCovered(sessionID, saved.replay.floor, coverage, saved.replay) ? saved.replay : undefined;
2486
2516
  const marker = importedFloor(reader, sessionID, cut?.seq);
2487
2517
  const imported = marker && this.floorCovered(sessionID, marker, coverage) ? marker : undefined;
2488
2518
  const capturedRecord = await this.readCapturedReplay(sessionID, reader);
@@ -2542,11 +2572,11 @@ class NativeFoldReplay {
2542
2572
  return;
2543
2573
  }
2544
2574
  }
2545
- async saveCapturedReplay(sessionID, replay, reader) {
2575
+ async saveCapturedReplay(sessionID, replay, reader, sourceDigest) {
2546
2576
  const value = {
2547
2577
  version: 3,
2548
2578
  sessionID,
2549
- sourceDigest: foldDigest(reader.hostIdentity()),
2579
+ sourceDigest,
2550
2580
  through: reader.latestSequence(sessionID),
2551
2581
  replay
2552
2582
  };
@@ -2576,11 +2606,33 @@ class NativeFoldReplay {
2576
2606
  ${cached}
2577
2607
  </summary>`)))) ? cached : undefined;
2578
2608
  }
2579
- async retainReplay(sessionID, replay, model, sourceSeq) {
2609
+ async retainReplay(sessionID, replay, model, sourceSeq, source) {
2610
+ await this.fenceMemory(sessionID, source);
2580
2611
  const tail = this.tail(sessionID) ?? { model, sourceSeq };
2581
2612
  await this.storage.saveTail(sessionID, JSON.stringify({ ...tail, replay }), []);
2582
2613
  if (!this.storage.tail(sessionID))
2583
2614
  await this.storage.saveTail(sessionID, JSON.stringify({ model, sourceSeq, replay }), []);
2615
+ this.memorySources.set(sessionID, source);
2616
+ }
2617
+ async fenceMemory(sessionID, source) {
2618
+ const recorded = this.memorySources.get(sessionID);
2619
+ if (recorded === source)
2620
+ return;
2621
+ if (recorded === undefined && !this.storage.holdsState(sessionID) && !this.metadata.has(sessionID))
2622
+ return;
2623
+ await this.discardCapture(sessionID);
2624
+ this.reportCaptureReplacement(sessionID);
2625
+ }
2626
+ async discardCapture(sessionID) {
2627
+ if (this.stampMRU?.sessionID === sessionID)
2628
+ this.stampMRU = undefined;
2629
+ const source = this.sources.get(sessionID);
2630
+ const forgotten = this.storage.forget(sessionID);
2631
+ if (source !== undefined) {
2632
+ this.sources.set(sessionID, source);
2633
+ this.account(sessionID);
2634
+ }
2635
+ await forgotten;
2584
2636
  }
2585
2637
  async canFold(sessionID, reader) {
2586
2638
  if (this.options.protocol !== 3) {
@@ -2681,7 +2733,7 @@ ${cached}
2681
2733
  }
2682
2734
  };
2683
2735
  this.legacyUpgrades.set(draft.sessionID, { value, rows, started });
2684
- await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, cut.seq - 1);
2736
+ await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, cut.seq - 1, reader.hostIdentity());
2685
2737
  return true;
2686
2738
  }
2687
2739
  legacyUpgradeInput(sessionID, model) {
@@ -2689,8 +2741,16 @@ ${cached}
2689
2741
  if (!pending)
2690
2742
  return;
2691
2743
  let reader;
2744
+ const open = () => {
2745
+ const opened = this.openReader(sessionID);
2746
+ if (foldDigest(opened.hostIdentity()) !== pending.value.proof.sourceDigest) {
2747
+ opened.close();
2748
+ throw new NativeReplayUnavailable("Host database file changed during upgrade");
2749
+ }
2750
+ return opened;
2751
+ };
2692
2752
  const blobs = {
2693
- mediaBlob: (hash) => (reader ??= this.openReader(sessionID)).mediaBlob(hash)
2753
+ mediaBlob: (hash) => (reader ??= open()).mediaBlob(hash)
2694
2754
  };
2695
2755
  try {
2696
2756
  return pending.rows.filter((row) => row.seq > pending.value.replay.floor.after).flatMap((row) => {
@@ -2710,6 +2770,11 @@ ${cached}
2710
2770
  const admissions = this.admissions;
2711
2771
  if (!pending || !admissions)
2712
2772
  return false;
2773
+ const recorded = this.memorySources.get(sessionID);
2774
+ if (recorded === undefined ? this.storage.holdsState(sessionID) || this.metadata.has(sessionID) : foldDigest(recorded) !== pending.value.proof.sourceDigest) {
2775
+ await this.discardCapture(sessionID);
2776
+ this.reportCaptureReplacement(sessionID);
2777
+ }
2713
2778
  const replay = this.tail(sessionID)?.replay ?? pending.value.replay;
2714
2779
  if (replay.blocked)
2715
2780
  return false;
@@ -2747,13 +2812,16 @@ ${cached}
2747
2812
  stripCheckpointRecentContext(rendered, row.data.summary ?? "");
2748
2813
  return { row, rendered, submitted: row.data.summary ?? "" };
2749
2814
  }
2750
- async checkpointCovered(sessionID, checkpointID) {
2815
+ async checkpointCovered(sessionID, checkpointID, sourceIdentity) {
2751
2816
  const admissions = this.admissions;
2752
2817
  if (!admissions)
2753
2818
  return;
2819
+ await this.fenceMemory(sessionID, sourceIdentity);
2754
2820
  const pending = this.legacyUpgrades.get(sessionID);
2755
- const value = await this.readV3(sessionID) ?? pending?.value;
2756
- if (value?.replay.floor.kind !== "host-checkpoint" || value.replay.floor.id !== checkpointID || value.replay.withoutRecentContext)
2821
+ const sourceDigest = foldDigest(sourceIdentity);
2822
+ const saved = await this.readV3(sessionID);
2823
+ const value = saved?.proof.sourceDigest === sourceDigest ? saved : pending?.value;
2824
+ if (value?.proof.sourceDigest !== sourceDigest || value.replay.floor.kind !== "host-checkpoint" || value.replay.floor.id !== checkpointID || value.replay.withoutRecentContext)
2757
2825
  return;
2758
2826
  value.replay.withoutRecentContext = true;
2759
2827
  const payload = encodeAdmissionV3(value);
@@ -2764,7 +2832,7 @@ ${cached}
2764
2832
  });
2765
2833
  const tail = this.tail(sessionID);
2766
2834
  if (tail)
2767
- await this.retainReplay(sessionID, value.replay, tail.model, tail.sourceSeq);
2835
+ await this.retainReplay(sessionID, value.replay, tail.model, tail.sourceSeq, sourceIdentity);
2768
2836
  }
2769
2837
  async removeAdmission(key) {
2770
2838
  if (this.admissions?.remove)
@@ -2782,7 +2850,8 @@ ${cached}
2782
2850
  if (!saved || !isLocalCheckpoint(cut) || cut.session_id !== sessionID)
2783
2851
  return false;
2784
2852
  const proof = saved.proof;
2785
- if (proof.sourceDigest !== foldDigest(reader.hostIdentity()) || proof.admissionID !== cut.id || proof.summaryDigest !== foldDigest(cut.data.summary ?? "")) {
2853
+ const source = reader.hostIdentity();
2854
+ if (proof.sourceDigest !== foldDigest(source) || proof.admissionID !== cut.id || proof.summaryDigest !== foldDigest(cut.data.summary ?? "")) {
2786
2855
  this.report(sessionID, "replay refused: invalid checkpoint floor or provenance");
2787
2856
  return false;
2788
2857
  }
@@ -2798,17 +2867,17 @@ ${cached}
2798
2867
  this.editedAdmissions.set(sessionID, { original: saved, replay });
2799
2868
  this.staleHeads.add(sessionID);
2800
2869
  this.invalidate(sessionID);
2801
- await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
2870
+ await this.retainReplay(sessionID, replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
2802
2871
  return false;
2803
2872
  }
2804
2873
  if (!this.floorCovered(sessionID, replay.floor, this.historyCoverage(sessionID, reader), replay))
2805
2874
  return false;
2806
- await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
2875
+ await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
2807
2876
  if (proof.historyDigest !== historyDigest(reader, sessionID, cut.seq - 1, saved.replay.floor.after)) {
2808
2877
  this.staleHeads.add(sessionID);
2809
2878
  this.invalidate(sessionID);
2810
2879
  this.editedAdmissions.set(sessionID, { original: saved, replay });
2811
- await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1);
2880
+ await this.retainReplay(sessionID, saved.replay, this.tail(sessionID)?.model ?? "", cut.seq - 1, source);
2812
2881
  return false;
2813
2882
  }
2814
2883
  await this.storage.supply(sessionID, cut.id, JSON.stringify({
@@ -2860,6 +2929,7 @@ ${cached}
2860
2929
  return false;
2861
2930
  const reader = this.openReader(sessionID);
2862
2931
  try {
2932
+ await this.fenceMemory(sessionID, reader.hostIdentity());
2863
2933
  const cut = reader.latestCompaction(sessionID);
2864
2934
  const proof = pending.original.proof;
2865
2935
  const replay = this.tail(sessionID)?.replay ?? pending.replay;
@@ -3064,14 +3134,23 @@ ${cached}
3064
3134
  }
3065
3135
  return [...grouped].map(([row, messages]) => this.record(row, messages));
3066
3136
  }
3067
- async capture(draft, native, boundary, restoredFirstRow) {
3137
+ async capture(draft, native, draftSourceIdentity, boundary, restoredFirstRow) {
3068
3138
  const release = this.storage.hold(draft.sessionID);
3069
3139
  let replay;
3140
+ let capturedIdentity;
3070
3141
  let sourceSeq = -1;
3071
3142
  try {
3072
3143
  rememberHostMedia(native);
3073
3144
  const reader = this.openReader(draft.sessionID);
3074
3145
  try {
3146
+ capturedIdentity = reader.hostIdentity();
3147
+ if (capturedIdentity !== draftSourceIdentity) {
3148
+ await this.discardCapture(draft.sessionID);
3149
+ this.reportCaptureReplacement(draft.sessionID);
3150
+ return;
3151
+ }
3152
+ await this.fenceMemory(draft.sessionID, capturedIdentity);
3153
+ this.memorySources.set(draft.sessionID, capturedIdentity);
3075
3154
  if (this.options.protocol === 3) {
3076
3155
  replay = await this.floorState(draft.sessionID, reader, boundary, draft);
3077
3156
  if (!replay && restoredFirstRow) {
@@ -3121,6 +3200,7 @@ ${cached}
3121
3200
  };
3122
3201
  await this.storage.saveTail(draft.sessionID, JSON.stringify(tail), rows);
3123
3202
  this.storage.truncate(draft.sessionID, through);
3203
+ this.memorySources.set(draft.sessionID, capturedIdentity);
3124
3204
  this.loaded.set(draft.sessionID, through);
3125
3205
  this.unavailable.delete(draft.sessionID);
3126
3206
  this.changed.delete(draft.sessionID);
@@ -3143,13 +3223,24 @@ ${cached}
3143
3223
  }
3144
3224
  }
3145
3225
  if (replay) {
3146
- await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, sourceSeq);
3226
+ await this.retainReplay(draft.sessionID, replay, `${draft.model.providerID}/${draft.model.id}`, sourceSeq, draftSourceIdentity);
3147
3227
  const reader = this.openReader(draft.sessionID);
3148
3228
  try {
3149
- await this.saveCapturedReplay(draft.sessionID, replay, reader);
3229
+ const identity = reader.hostIdentity();
3230
+ if (identity !== capturedIdentity) {
3231
+ await this.discardCapture(draft.sessionID);
3232
+ this.reportCaptureReplacement(draft.sessionID);
3233
+ return;
3234
+ }
3235
+ const sourceDigest = foldDigest(identity);
3236
+ await this.saveCapturedReplay(draft.sessionID, replay, reader, sourceDigest);
3150
3237
  const saved = await this.readV3(draft.sessionID);
3151
3238
  const cut = reader.latestCompaction(draft.sessionID);
3152
3239
  if (saved && !this.editedAdmissions.has(draft.sessionID) && cut?.id === saved.proof.admissionID && (replay.floor.after > saved.replay.floor.after || !this.floorCovered(draft.sessionID, saved.replay.floor, this.historyCoverage(draft.sessionID, reader), saved.replay)) && (boundary && this.servedBaseline(draft) === boundary.summary || replay.floor.kind === "start" && restoredFirstRow === replay.floor.id)) {
3240
+ if (saved.proof.sourceDigest !== sourceDigest) {
3241
+ this.reportOnce(draft.sessionID, this.reportedForeignRefreshes, "v3 host fold: admission refresh skipped: admission belongs to a different host database file");
3242
+ return;
3243
+ }
3153
3244
  const value = {
3154
3245
  ...saved,
3155
3246
  replay: {
@@ -3192,6 +3283,8 @@ ${cached}
3192
3283
  async supplyHeld(args) {
3193
3284
  const { draft, reader, summary } = args;
3194
3285
  const stored = args.checkpointText ?? summary;
3286
+ const source = reader.hostIdentity();
3287
+ await this.fenceMemory(draft.sessionID, source);
3195
3288
  if (this.options.protocol === 3) {
3196
3289
  if (this.unprovenControls.has(draft.sessionID))
3197
3290
  return false;
@@ -3216,7 +3309,7 @@ ${cached}
3216
3309
  if (!args.manual && this.tail(draft.sessionID)?.model !== model)
3217
3310
  this.storage.replaceRows(draft.sessionID, reader.latestSequence(draft.sessionID), []);
3218
3311
  if (!args.manual)
3219
- await this.retainReplay(draft.sessionID, replay, model, reader.latestSequence(draft.sessionID));
3312
+ await this.retainReplay(draft.sessionID, replay, model, reader.latestSequence(draft.sessionID), source);
3220
3313
  if (!args.manual)
3221
3314
  await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
3222
3315
  source: this.storage.sourceID,
@@ -3278,7 +3371,7 @@ ${cached}
3278
3371
  this.invalidate(draft.sessionID);
3279
3372
  this.cancelLegacyUpgrade(draft.sessionID);
3280
3373
  this.cancelEditedAdmission(draft.sessionID);
3281
- await this.retainReplay(draft.sessionID, replay, model, running.seq - 1);
3374
+ await this.retainReplay(draft.sessionID, replay, model, running.seq - 1, source);
3282
3375
  await this.storage.supply(draft.sessionID, running.id, JSON.stringify({
3283
3376
  source: this.storage.sourceID,
3284
3377
  sessionID: draft.sessionID,
@@ -3311,6 +3404,7 @@ ${cached}
3311
3404
  baseline: tail?.baseline ?? summary,
3312
3405
  sourceSeq: Math.max(tail?.sourceSeq ?? through, ...fresh.map((row) => row.seq))
3313
3406
  }), records);
3407
+ this.memorySources.set(draft.sessionID, source);
3314
3408
  this.dirty.delete(draft.sessionID);
3315
3409
  this.metadata.delete(draft.sessionID);
3316
3410
  this.metadataThrough.delete(draft.sessionID);
@@ -3339,13 +3433,16 @@ ${cached}
3339
3433
  }
3340
3434
  return true;
3341
3435
  }
3342
- async restore(sessionID, cut, model, options = {}) {
3436
+ async restore(sessionID, cut, model, passSource, options = {}) {
3343
3437
  let replay;
3344
3438
  let controls = [];
3345
3439
  let after;
3440
+ await this.fenceMemory(sessionID, passSource);
3346
3441
  if (this.options.protocol === 3) {
3347
3442
  const reader = this.openReader(sessionID);
3348
3443
  try {
3444
+ if (reader.hostIdentity() !== passSource)
3445
+ throw new NativeReplayUnavailable("Host database file changed during restore");
3349
3446
  replay = await this.floorState(sessionID, reader);
3350
3447
  if (replay) {
3351
3448
  controls = controlsThrough(replay.controls, reader, sessionID, cut.seq - 1);
@@ -3369,7 +3466,7 @@ ${cached}
3369
3466
  const release = this.storage.hold(sessionID);
3370
3467
  let result;
3371
3468
  try {
3372
- result = await this.restoreHeld(sessionID, cut, model, options);
3469
+ result = await this.restoreHeld(sessionID, cut, model, options, passSource);
3373
3470
  } finally {
3374
3471
  try {
3375
3472
  this.account(sessionID);
@@ -3378,14 +3475,25 @@ ${cached}
3378
3475
  }
3379
3476
  }
3380
3477
  if (replay) {
3381
- await this.retainReplay(sessionID, replay, model, cut.seq - 1);
3478
+ await this.retainReplay(sessionID, replay, model, cut.seq - 1, passSource);
3479
+ if (result && replay.floor.kind === "summary" && after === replay.floor.seq && after < cut.seq)
3480
+ options.onRestoredAfterSummary?.(replay.floor.id);
3382
3481
  return result && insertControls(result, controls, nativeRowID);
3383
3482
  }
3384
3483
  return result;
3385
3484
  }
3386
- async restoreHeld(sessionID, cut, model, options) {
3485
+ async restoreHeld(sessionID, cut, model, options, expected) {
3387
3486
  if (!isLocalCheckpoint(cut))
3388
3487
  return;
3488
+ const open = () => {
3489
+ const opened = this.openReader(sessionID);
3490
+ if (opened.hostIdentity() !== expected) {
3491
+ opened.close();
3492
+ throw new NativeReplayUnavailable("Host database file changed during restore");
3493
+ }
3494
+ this.memorySources.set(sessionID, expected);
3495
+ return opened;
3496
+ };
3389
3497
  const resolvedModel = {
3390
3498
  providerID: model.slice(0, model.indexOf("/")),
3391
3499
  id: model.slice(model.indexOf("/") + 1)
@@ -3401,13 +3509,13 @@ ${cached}
3401
3509
  const max = this.storage.db.prepare("SELECT COALESCE(MAX(id),0) AS id FROM m0_mutation_log WHERE session_id=?").get(sessionID);
3402
3510
  const boundary = this.storage.db.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id=?").get(sessionID)?.id;
3403
3511
  if (max.id <= (state.cachedM0MaxMutationId ?? 0) && boundary) {
3404
- after = this.storage.sequenceForID(sessionID, boundary) ?? (reader = this.openReader(sessionID)).sequenceForId(sessionID, boundary) ?? -1;
3512
+ after = this.storage.sequenceForID(sessionID, boundary) ?? (reader = open()).sequenceForId(sessionID, boundary) ?? -1;
3405
3513
  }
3406
3514
  }
3407
3515
  const through = cut.seq - 1;
3408
3516
  let metadata = this.metadata.get(sessionID);
3409
3517
  if (!metadata || (this.metadataThrough.get(sessionID) ?? -1) < through || this.options.protocol === 3 && this.options.rendersHistory?.(sessionID) && (this.metadataAfter.get(sessionID) ?? -1) > after) {
3410
- reader ??= this.openReader(sessionID);
3518
+ reader ??= open();
3411
3519
  metadata = reader.rowStampsThrough(sessionID, through, this.options.protocol === 3 ? after : undefined).filter(conversational);
3412
3520
  this.metadata.set(sessionID, metadata);
3413
3521
  this.metadataThrough.set(sessionID, through);
@@ -3415,7 +3523,7 @@ ${cached}
3415
3523
  }
3416
3524
  const required = metadata.filter((row) => row.seq > after && row.seq <= through);
3417
3525
  if (this.dirty.has(sessionID) || !tail || (this.loaded.get(sessionID) ?? -1) < through && !this.storage.admission(sessionID, cut.id) || !this.storage.containsRows(sessionID, required.map((row) => row.id))) {
3418
- const source = reader ??= this.openReader(sessionID);
3526
+ const source = reader ??= open();
3419
3527
  const fresh = source.range(sessionID, after, through).filter(conversational);
3420
3528
  const records = fresh.map((row) => this.record(row, this.rendered(row, resolvedModel, source)));
3421
3529
  const restored = new Set(records.map((row) => row.id));
@@ -3445,9 +3553,11 @@ ${cached}
3445
3553
  }
3446
3554
  return messages;
3447
3555
  }
3448
- async restoreRead(sessionID, cut, model) {
3556
+ async restoreRead(sessionID, cut, model, passSource, onRestoredAfterSummary) {
3449
3557
  const reader = this.openReader(sessionID);
3450
3558
  try {
3559
+ if (reader.hostIdentity() !== passSource)
3560
+ throw new NativeReplayUnavailable("Host checkpoint replay boundary is unavailable");
3451
3561
  const replay = this.options.protocol === 3 ? await this.floorState(sessionID, reader) : undefined;
3452
3562
  if (this.options.protocol === 3 && !replay) {
3453
3563
  this.report(sessionID, "replay refused: missing usable checkpoint boundary");
@@ -3461,6 +3571,8 @@ ${cached}
3461
3571
  bindNativeRowID(message, row.id, row.seq);
3462
3572
  return messages;
3463
3573
  });
3574
+ if (replay?.floor.kind === "summary" && after === replay.floor.seq && after < cut.seq)
3575
+ onRestoredAfterSummary?.(replay.floor.id);
3464
3576
  return replay ? insertControls(messages, controlsThrough(replay.controls, reader, sessionID, cut.seq - 1), nativeRowID) : messages;
3465
3577
  } finally {
3466
3578
  reader.close();
@@ -3474,6 +3586,7 @@ ${cached}
3474
3586
  }
3475
3587
  clear(sessionID) {
3476
3588
  this.sources.delete(sessionID);
3589
+ this.memorySources.delete(sessionID);
3477
3590
  this.metadata.delete(sessionID);
3478
3591
  this.metadataThrough.delete(sessionID);
3479
3592
  this.metadataAfter.delete(sessionID);
@@ -3488,6 +3601,8 @@ ${cached}
3488
3601
  if (this.stampMRU?.sessionID === sessionID)
3489
3602
  this.stampMRU = undefined;
3490
3603
  this.unprovenControls.delete(sessionID);
3604
+ this.reportedCaptureReplacements.delete(sessionID);
3605
+ this.reportedForeignRefreshes.delete(sessionID);
3491
3606
  this.cancelLegacyUpgrade(sessionID);
3492
3607
  this.cancelEditedAdmission(sessionID);
3493
3608
  if (this.admissions)
@@ -3852,57 +3967,6 @@ function seedV2ForkFromParent(args) {
3852
3967
  return { kind: "seeded", parentSessionID, pairedRows: idMap.parentToFork.size, result };
3853
3968
  }
3854
3969
 
3855
- // src/v2/hidden-child-record.ts
3856
- function keptUnderRetention(keepSubagents, child) {
3857
- return keepSubagents && (child.ever_settled === true || child.role === "historian");
3858
- }
3859
- function roleTitle(role) {
3860
- return role === "historian" ? "Magic Context historian" : "Magic Context dreamer";
3861
- }
3862
- function roleAgent(role) {
3863
- if (role === "historian")
3864
- return HIDDEN_HISTORIAN_AGENT;
3865
- return role === "dreamer-curate" ? HIDDEN_CURATE_AGENT : HIDDEN_DREAMER_AGENT;
3866
- }
3867
- function childCreateInput(identity, role, model) {
3868
- const agent = hiddenToolLoop(identity) ? hiddenAgentFor(identity) : roleAgent(role);
3869
- return {
3870
- title: roleTitle(role),
3871
- agent,
3872
- model: {
3873
- providerID: model.providerID,
3874
- id: model.modelID,
3875
- ...model.variant ? { variant: model.variant } : {}
3876
- },
3877
- location: { directory: identity.directory },
3878
- metadata: { magic_context: "hidden-run", role },
3879
- permissions: hiddenChildPermissions(agent, model.providerID)
3880
- };
3881
- }
3882
- function assistantOutcome(row) {
3883
- const outcome = row?.data.outcome;
3884
- return outcome === "succeeded" || outcome === "failed" || outcome === "interrupted" ? outcome : undefined;
3885
- }
3886
- function withReader(openReader, read) {
3887
- const reader = openReader();
3888
- try {
3889
- return read(reader);
3890
- } finally {
3891
- reader.close?.();
3892
- }
3893
- }
3894
- function errorText(value) {
3895
- if (value instanceof Error)
3896
- return value.message;
3897
- if (typeof value === "string")
3898
- return value;
3899
- try {
3900
- return JSON.stringify(value);
3901
- } catch {
3902
- return String(value);
3903
- }
3904
- }
3905
-
3906
3970
  // src/v2/hidden-child-sweep.ts
3907
3971
  var PREFIX = "hidden_child:";
3908
3972
  var HIDDEN_CHILD_MAX_AGE_MS = 60 * 60 * 1000;
@@ -4023,6 +4087,7 @@ function isSessionNotFound(error) {
4023
4087
  }
4024
4088
  function createNativeHiddenChildren(host, removeSession, options) {
4025
4089
  const quiet = supportsQuietHiddenChildren(options.hostVersion);
4090
+ const archiveHolder = host.archiveHolder && supportsHolderArchive(options.hostVersion) ? { update: host.archiveHolder, log: options.log } : undefined;
4026
4091
  const removing = new Map;
4027
4092
  const removeBounded = async (id, timeoutMs = options.removalTimeoutMs ?? 5000) => {
4028
4093
  let timer;
@@ -4091,7 +4156,7 @@ function createNativeHiddenChildren(host, removeSession, options) {
4091
4156
  const input = childCreateInput(identity, role, model);
4092
4157
  const directory = identity.directory;
4093
4158
  if (quiet && host.createHolder) {
4094
- const placement = await hiddenRunPlacement(host.createHolder, directory, budget);
4159
+ const placement = await hiddenRunPlacement(host.createHolder, directory, budget, archiveHolder);
4095
4160
  input.id = placement.id;
4096
4161
  input.parentID = placement.parentID;
4097
4162
  delete input.location;
@@ -4979,6 +5044,7 @@ async function createV2HiddenCompletionExecutor(host, options) {
4979
5044
  throw new DreamTokenBudgetExceeded(run.child.id, budget.snapshot().spent);
4980
5045
  }
4981
5046
  let usageSeq = baseline;
5047
+ let finishedSteps = 0;
4982
5048
  let budgetPoll;
4983
5049
  let budgetReject;
4984
5050
  const budgetStopped = new Promise((_resolve, reject) => {
@@ -4994,7 +5060,15 @@ async function createV2HiddenCompletionExecutor(host, options) {
4994
5060
  break;
4995
5061
  usageSeq = row.seq;
4996
5062
  const tokens = row.data.tokens;
4997
- const decision = budget.charge(Math.max(0, tokens?.input ?? 0), Math.max(0, tokens?.cache?.read ?? 0), Math.max(0, tokens?.cache?.write ?? 0), row.data.finish === "stop" && !(row.data.content ?? []).some((part) => part.type === "tool-call"), false);
5063
+ const hasUsage = [
5064
+ tokens?.input,
5065
+ tokens?.output,
5066
+ tokens?.cache?.read,
5067
+ tokens?.cache?.write,
5068
+ tokens?.reasoning
5069
+ ].some((value) => typeof value === "number" && Number.isFinite(value));
5070
+ const estimatedInput = attempt.requestTokenEstimates?.[finishedSteps++] ?? 0;
5071
+ const decision = budget.charge(hasUsage ? Math.max(0, tokens?.input ?? 0) : estimatedInput, hasUsage ? Math.max(0, tokens?.cache?.read ?? 0) : 0, hasUsage ? Math.max(0, tokens?.cache?.write ?? 0) : 0, row.data.finish === "stop" && !(row.data.content ?? []).some((part) => part.type === "tool-call"), false);
4998
5072
  const onBudgetUpdate = run.identity.metadata?.onBudgetUpdate;
4999
5073
  if (typeof onBudgetUpdate === "function")
5000
5074
  onBudgetUpdate({ ...budget.snapshot(), sessionId: run.child.id });
@@ -6662,7 +6736,10 @@ class V2RevertMessageCleanup {
6662
6736
  sessionId: sessionID,
6663
6737
  isInHostStore: (id) => source.sequenceForId(sessionID, id) !== undefined,
6664
6738
  removedByCommittedRevert: removed,
6665
- onRetire: () => clearRecompStaging(db, sessionID)
6739
+ onRetire: () => {
6740
+ clearRecompStaging(db, sessionID);
6741
+ return;
6742
+ }
6666
6743
  });
6667
6744
  if (result.kind !== "unresolved") {
6668
6745
  this.pendingHistory = this.pendingHistory.filter((proof) => proof.sessionID !== sessionID);
@@ -7345,7 +7422,10 @@ function checkHistoryBoundary(db, reader, sessionID) {
7345
7422
  db,
7346
7423
  sessionId: sessionID,
7347
7424
  isInHostStore: (messageId) => storeHasSession ? reader.sequenceForId(sessionID, messageId) !== undefined : null,
7348
- onRetire: () => clearRecompStaging(db, sessionID)
7425
+ onRetire: () => {
7426
+ clearRecompStaging(db, sessionID);
7427
+ return;
7428
+ }
7349
7429
  });
7350
7430
  } catch (error) {
7351
7431
  sessionLog2(sessionID, "history boundary check failed; continuing without repair", error);
@@ -7707,6 +7787,8 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
7707
7787
  };
7708
7788
  const wrapperStorageGuard = { failClosed, failClosedBlockingEnabled };
7709
7789
  let db = await probeV2StorageAtBoot(storage);
7790
+ if (db)
7791
+ recordHostSqliteRuntime(db, "opencode2");
7710
7792
  const storageOpenedAtBoot = db !== undefined;
7711
7793
  let legacyCleanupStarted = false;
7712
7794
  const hiddenChildSweep = createHiddenChildSweeper(nativeRemove, log2, {
@@ -7855,6 +7937,7 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
7855
7937
  return createV2HiddenCompletionExecutor({
7856
7938
  ...context.session,
7857
7939
  createHolder: (input) => context.session.create(input),
7940
+ archiveHolder: (input) => context.session.update.call(context.session, input),
7858
7941
  watchModelActivity: (sessionID, onOutput) => hiddenModelActivity.watch(sessionID, onOutput),
7859
7942
  get: async (input) => {
7860
7943
  const session = await context.session.get(input);
@@ -8662,6 +8745,9 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
8662
8745
  sessionLog2(draft.sessionID, `v2 restore: from the module boundary ${moduleBoundaryID} to the host checkpoint`);
8663
8746
  const present = new Set(args.messages.map((message) => message.id));
8664
8747
  const restored = restoredRows.rows(reader, draft.sessionID, boundary, cut.seq).filter((row) => !retiredInstructions(row)).filter((row) => !present.has(row.id)).flatMap((row) => restoreRow(row, draft.model, readerRestoreMedia(reader, (detail) => sessionLog2(draft.sessionID, `v2 restore: attachment replaced by a note row=${detail.rowID} name=${JSON.stringify(detail.name ?? null)} mediaType=${detail.mediaType} reason=${JSON.stringify(detail.reason)}`))));
8748
+ const pass = contextPass.getStore();
8749
+ if (args.canRebuild && pass?.sessionID === draft.sessionID && floorRow && floorRow.id === boundaryID && boundary === floorRow.seq && boundary < cut.seq)
8750
+ pass.restoredAfterSummaryId = floorRow.id;
8665
8751
  return [
8666
8752
  ...rustModeModuleClient ? [] : coveredInstructionRows(reader, draft.sessionID, Math.min(boundary, cut.seq), draft.model, retiredInstructions),
8667
8753
  ...restored,
@@ -8684,6 +8770,10 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
8684
8770
  pushLiveNotification2("toast", { message, variant: "warning" }, sessionID);
8685
8771
  },
8686
8772
  hostInputEstimate: (sessionID) => checkpointInputEstimates.get(sessionID),
8773
+ restoredAfterSummaryBoundary: (sessionID) => {
8774
+ const pass = contextPass.getStore();
8775
+ return pass?.sessionID === sessionID ? pass.restoredAfterSummaryId : undefined;
8776
+ },
8687
8777
  onPassPermission: (sessionID, permission) => {
8688
8778
  checkpointPassPermissions.set(sessionID, permission);
8689
8779
  },
@@ -9079,11 +9169,12 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9079
9169
  let recordedHead;
9080
9170
  let upgradeCheckpointSequence;
9081
9171
  let restoredFirstRow;
9172
+ let draftSourceIdentity;
9082
9173
  try {
9083
9174
  syntheticIDs = await readSyntheticProvenance(reader, draft.messages);
9084
9175
  const cut = reader.latestCompaction(draft.sessionID);
9085
9176
  if (nativeFoldReplay)
9086
- await nativeFoldReplay.observeSource(draft.sessionID, reader);
9177
+ draftSourceIdentity = await nativeFoldReplay.observeSource(draft.sessionID, reader);
9087
9178
  const boundaryRepair = !rustModeModuleClient && db && !compactionOff ? revertMessageCleanup.retireProvenHistory(db, draft.sessionID, reader) ?? checkHistoryBoundary(db, reader, draft.sessionID) : undefined;
9088
9179
  if (boundaryRepair?.kind === "repaired" || boundaryRepair?.kind === "baseline-reset") {
9089
9180
  historyRefreshSessions.add(draft.sessionID);
@@ -9123,13 +9214,18 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9123
9214
  }
9124
9215
  }
9125
9216
  let nativeRestored = localCut ? nativeFoldReplay?.legacyUpgradeInput(draft.sessionID, draft.model) : undefined;
9126
- if (nativeRestored === undefined && cut && nativeFoldReplay && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
9217
+ let nativeRestoredAfterSummaryId;
9218
+ if (nativeRestored === undefined && cut && nativeFoldReplay && draftSourceIdentity !== undefined && await nativeFoldReplay.admits(draft.sessionID, cut, reader)) {
9219
+ const passSource = draftSourceIdentity;
9220
+ const onRestoredAfterSummary = (id) => {
9221
+ nativeRestoredAfterSummaryId = id;
9222
+ };
9127
9223
  try {
9128
- nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, { bounded: !rustModeModuleClient });
9224
+ nativeRestored = await nativeFoldReplay.restore(draft.sessionID, cut, `${draft.model.providerID}/${draft.model.id}`, passSource, { bounded: !rustModeModuleClient, onRestoredAfterSummary });
9129
9225
  } catch (error) {
9130
9226
  nativeFoldReplay.invalidate(draft.sessionID, true);
9131
9227
  sessionLog2(draft.sessionID, "v2 host fold: cache unavailable; restoring host rows", error);
9132
- nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model);
9228
+ nativeRestored = await nativeFoldReplay.restoreRead(draft.sessionID, cut, draft.model, passSource, onRestoredAfterSummary);
9133
9229
  }
9134
9230
  if (nativeRestored)
9135
9231
  pass.nativeReplayCheckpointID = cut.id;
@@ -9143,6 +9239,7 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9143
9239
  requestPendingMaterialization(pendingMaterializationSessions, draft.sessionID, "host_history_change");
9144
9240
  }
9145
9241
  if (cut && incoming && nativeRestored) {
9242
+ pass.restoredAfterSummaryId = nativeRestoredAfterSummaryId;
9146
9243
  draft.messages.splice(0, draft.messages.length, ...restoreNativeCheckpointInput(draft.messages, incoming, nativeRestored, reader, draft.sessionID));
9147
9244
  } else if (!compactionOff && localCut && cut && incoming) {
9148
9245
  const legacy = await folds.read(draft.sessionID);
@@ -9278,8 +9375,8 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9278
9375
  const stripped = await folds.stripRecentContext(draft.sessionID, checkpointID);
9279
9376
  if (stripped?.rendered) {
9280
9377
  checkpoint = structuredClone(stripped.rendered);
9281
- if (upgradeCheckpointSequence !== undefined)
9282
- await nativeFoldReplay?.checkpointCovered(draft.sessionID, checkpointID);
9378
+ if (upgradeCheckpointSequence !== undefined && draftSourceIdentity !== undefined)
9379
+ await nativeFoldReplay?.checkpointCovered(draft.sessionID, checkpointID, draftSourceIdentity);
9283
9380
  }
9284
9381
  }
9285
9382
  }
@@ -9297,11 +9394,11 @@ async function setupContext(context, config, nativeRemove, compactionOff, cleanu
9297
9394
  } : null;
9298
9395
  const servedHead = head && structuredClone(head);
9299
9396
  const headApplied = head ? applyCheckpointHead(draft, head) : false;
9300
- if (nativeMessages && (!checkpoint || upgradeCheckpointSequence !== undefined)) {
9397
+ if (nativeMessages && draftSourceIdentity !== undefined && (!checkpoint || upgradeCheckpointSequence !== undefined)) {
9301
9398
  try {
9302
9399
  const state = db && getOrCreateSessionMeta(db, draft.sessionID);
9303
9400
  const boundary = db?.prepare("SELECT cached_m0_last_baseline_end_message_id AS id FROM session_meta WHERE session_id=?").get(draft.sessionID);
9304
- await nativeFoldReplay?.capture(draft, nativeMessages, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined, restoredFirstRow);
9401
+ await nativeFoldReplay?.capture(draft, nativeMessages, draftSourceIdentity, boundary?.id && state?.cachedM0Bytes ? { id: boundary.id, summary: state.cachedM0Bytes.toString("utf8") } : undefined, restoredFirstRow);
9305
9402
  } catch (error) {
9306
9403
  nativeFoldReplay?.invalidate(draft.sessionID, true);
9307
9404
  sessionLog2(draft.sessionID, "v2 host fold: optional capture unavailable", error);