@cortexkit/opencode-magic-context 0.49.11 → 0.49.13

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 (253) hide show
  1. package/README.md +1 -1
  2. package/dist/agents/smart-notes-dreamer-gate.fixture.d.ts +28 -0
  3. package/dist/agents/smart-notes-dreamer-gate.fixture.d.ts.map +1 -0
  4. package/dist/{announcement-hdbkt8v5.js → announcement-g789dmt6.js} +2 -2
  5. package/dist/auto-search-worker.js +4 -4
  6. package/dist/chunk-embedding-write-worker.js +89 -0
  7. package/dist/{compaction-marker-candidates-xxz35vwp.js → compaction-marker-candidates-v5c6997n.js} +3 -3
  8. package/dist/compaction-marker-candidates-worker.js +1 -1
  9. package/dist/config/agent-disable.d.ts +14 -0
  10. package/dist/config/agent-disable.d.ts.map +1 -1
  11. package/dist/config/dependency-notes.d.ts +34 -0
  12. package/dist/config/dependency-notes.d.ts.map +1 -0
  13. package/dist/config/schema/agent-overrides.d.ts +12 -12
  14. package/dist/config/schema/magic-context.d.ts +88 -88
  15. package/dist/config/schema/magic-context.d.ts.map +1 -1
  16. package/dist/{conflict-warning-hook-xwkfncav.js → conflict-warning-hook-mgq17yr3.js} +8 -8
  17. package/dist/{context-twz3s0cg.js → context-azqk0vfd.js} +121 -145
  18. package/dist/{derive-budgets-3nbxsyss.js → derive-budgets-zn7yzd2d.js} +3 -3
  19. package/dist/embedding-backfill-5e1t5wha.js +22 -0
  20. package/dist/embedding-worker-process.js +2 -2
  21. package/dist/embedding-worker.js +6 -6
  22. package/dist/features/magic-context/chunk-embedding-write-worker.d.ts +2 -0
  23. package/dist/features/magic-context/chunk-embedding-write-worker.d.ts.map +1 -0
  24. package/dist/features/magic-context/chunk-embedding-writer.d.ts +48 -0
  25. package/dist/features/magic-context/chunk-embedding-writer.d.ts.map +1 -0
  26. package/dist/features/magic-context/compartment-chunk-embedding.d.ts +1 -1
  27. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  28. package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts +3 -2
  29. package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts.map +1 -1
  30. package/dist/features/magic-context/dreamer/map-memories.d.ts +8 -1
  31. package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
  32. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts +2 -0
  33. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts.map +1 -1
  34. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +5 -0
  35. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
  36. package/dist/features/magic-context/dreamer/task-config.d.ts +22 -4
  37. package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -1
  38. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  39. package/dist/features/magic-context/dreamer/task-registry.d.ts +22 -0
  40. package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
  41. package/dist/features/magic-context/dreamer/task-scheduler.d.ts +4 -1
  42. package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
  43. package/dist/features/magic-context/dreamer/verify-prompt.d.ts +6 -1
  44. package/dist/features/magic-context/dreamer/verify-prompt.d.ts.map +1 -1
  45. package/dist/features/magic-context/dreamer/verify.d.ts +25 -11
  46. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  47. package/dist/features/magic-context/memory/embedding-openai.d.ts +32 -0
  48. package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
  49. package/dist/features/magic-context/memory/project-identity.d.ts +1 -0
  50. package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
  51. package/dist/features/magic-context/memory/unborn-head.d.ts +34 -0
  52. package/dist/features/magic-context/memory/unborn-head.d.ts.map +1 -0
  53. package/dist/features/magic-context/mural/compress-cues.d.ts +3 -0
  54. package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
  55. package/dist/features/magic-context/project-embedding-registry.d.ts +5 -0
  56. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  57. package/dist/features/magic-context/storage-tags.d.ts +2 -0
  58. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  59. package/dist/{history-owner-ty29fz0f.js → history-owner-xp3pngv7.js} +3 -3
  60. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  61. package/dist/hooks/magic-context/auto-embed-session.d.ts +10 -0
  62. package/dist/hooks/magic-context/auto-embed-session.d.ts.map +1 -0
  63. package/dist/hooks/magic-context/compartment-prompt.d.ts +6 -0
  64. package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
  65. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  66. package/dist/hooks/magic-context/compartment-runner-types.d.ts +3 -0
  67. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  68. package/dist/hooks/magic-context/compartment-trigger-error.d.ts +12 -0
  69. package/dist/hooks/magic-context/compartment-trigger-error.d.ts.map +1 -0
  70. package/dist/hooks/magic-context/embed-session-state.d.ts +8 -1
  71. package/dist/hooks/magic-context/embed-session-state.d.ts.map +1 -1
  72. package/dist/hooks/magic-context/historian-prompt-fit.d.ts +2 -0
  73. package/dist/hooks/magic-context/historian-prompt-fit.d.ts.map +1 -1
  74. package/dist/hooks/magic-context/hook.d.ts +3 -1
  75. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  76. package/dist/hooks/magic-context/pending-materialization.d.ts +2 -0
  77. package/dist/hooks/magic-context/pending-materialization.d.ts.map +1 -1
  78. package/dist/hooks/magic-context/protected-tail-boundary.d.ts +12 -0
  79. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  80. package/dist/hooks/magic-context/raw-exact-ordinal-read.d.ts +58 -0
  81. package/dist/hooks/magic-context/raw-exact-ordinal-read.d.ts.map +1 -0
  82. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +7 -0
  83. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
  84. package/dist/hooks/magic-context/read-session-raw.d.ts +19 -0
  85. package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
  86. package/dist/hooks/magic-context/recomp-orchestrator.d.ts +2 -0
  87. package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
  88. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +2 -0
  89. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  90. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  91. package/dist/hooks/magic-context/transform.d.ts +4 -0
  92. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  93. package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
  94. package/dist/{index-bzp9s8z2.js → index-1d289pq2.js} +2 -2
  95. package/dist/{index-w28y7d0z.js → index-1sarmj9z.js} +15 -15
  96. package/dist/{index-z7avx6rw.js → index-2jr1smmh.js} +280 -160
  97. package/dist/{index-4ccdr7yw.js → index-3kdm78zp.js} +5 -5
  98. package/dist/{index-9159kk15.js → index-3kx0kg0f.js} +64 -7
  99. package/dist/{index-0jz47061.js → index-a8bvhwqs.js} +190 -30
  100. package/dist/{index-84j7jq8a.js → index-aw1bh90w.js} +10 -10
  101. package/dist/{index-qr1mkc2y.js → index-b16gpywn.js} +9 -9
  102. package/dist/{index-g7jkrz0x.js → index-bp5083x2.js} +1 -1
  103. package/dist/{index-yhrrx7qa.js → index-bxdg2nbt.js} +3 -3
  104. package/dist/{index-0abg88h2.js → index-dgs16axy.js} +4 -4
  105. package/dist/{index-mp2kghkv.js → index-dyvbsvga.js} +1 -1
  106. package/dist/{index-bmwfzz28.js → index-e20m7284.js} +4 -4
  107. package/dist/{index-4jkhhpn1.js → index-e4dsjj1p.js} +3 -3
  108. package/dist/{index-s178h9z8.js → index-f71thw8j.js} +1 -1
  109. package/dist/{index-kvw6xew3.js → index-fkx2qnvw.js} +2 -2
  110. package/dist/{index-f8cn4xqa.js → index-fwefky9w.js} +18 -5
  111. package/dist/{index-0sahzkwr.js → index-g2q4htwp.js} +46 -2
  112. package/dist/{index-mw7c950g.js → index-gp3kcpc4.js} +1 -1
  113. package/dist/{index-g40wgxxt.js → index-hnm8raee.js} +4 -4
  114. package/dist/{index-gjvjh960.js → index-hqkczed7.js} +1 -1
  115. package/dist/{index-mvvephtj.js → index-j75v2476.js} +1 -1
  116. package/dist/{index-150zz6fh.js → index-k29z4aqh.js} +1 -1
  117. package/dist/{index-b64n4d0h.js → index-kee4kn5j.js} +1 -1
  118. package/dist/index-ksdyrrav.js +52 -0
  119. package/dist/{index-angx1s0k.js → index-mmfa86mt.js} +16 -6
  120. package/dist/{index-9jvab89d.js → index-n6m03s3n.js} +2 -2
  121. package/dist/{index-q28hsbpg.js → index-nj7yykkx.js} +1 -1
  122. package/dist/{index-ghc9f0n7.js → index-p5y3k4g7.js} +29 -1
  123. package/dist/{index-xztdf9t7.js → index-qkd9zz0p.js} +17 -17
  124. package/dist/index-saews2s3.js +229 -0
  125. package/dist/{index-kkvxnbt8.js → index-sj89f3b0.js} +62 -33
  126. package/dist/{index-jw4gbfkv.js → index-v10f1rjv.js} +5 -5
  127. package/dist/{index-0j6crjgh.js → index-v13skev1.js} +13 -13
  128. package/dist/{index-hqnggmxn.js → index-wj6ht7nm.js} +547 -179
  129. package/dist/{index-a865mj02.js → index-wk0n1cgt.js} +4 -4
  130. package/dist/{index-q3qck7j2.js → index-wz6mzzb1.js} +6 -5
  131. package/dist/{index-se1w3v2m.js → index-y1qysm3q.js} +332 -256
  132. package/dist/{index-a4b0gbyg.js → index-y9f76s3f.js} +1 -1
  133. package/dist/index.d.ts.map +1 -1
  134. package/dist/index.js +119 -129
  135. package/dist/{logger-wn328tfg.js → logger-jm3sqqzr.js} +2 -2
  136. package/dist/{message-index-bounded-0rbbg9rd.js → message-index-bounded-vm64mqpq.js} +16 -16
  137. package/dist/{message-index-ct5x2kwa.js → message-index-seaqpb7c.js} +16 -16
  138. package/dist/{message-time-backfill-nb5hhnrt.js → message-time-backfill-qjge9044.js} +3 -3
  139. package/dist/migration-worker.js +11 -11
  140. package/dist/plugin/dream-timer.d.ts.map +1 -1
  141. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  142. package/dist/plugin/tool-registry.d.ts.map +1 -1
  143. package/dist/{project-embedding-registry-ft9gh2e2.js → project-embedding-registry-x45bv3qr.js} +12 -11
  144. package/dist/raw-ordinal-warmup-worker.js +12 -7
  145. package/dist/{read-session-chunk-y3hhsbzw.js → read-session-chunk-ax05f7gr.js} +11 -11
  146. package/dist/{read-session-raw-gm6xj30v.js → read-session-raw-m56hc7v2.js} +7 -3
  147. package/dist/recomp-orchestrator-dmbeadwt.js +61 -0
  148. package/dist/{safe-notification-target-jdynm677.js → safe-notification-target-1szv1k5k.js} +3 -3
  149. package/dist/{search-jd8xh721.js → search-5yd5ytzs.js} +25 -24
  150. package/dist/{send-session-notification-vzhj8bsg.js → send-session-notification-24r4esbh.js} +6 -6
  151. package/dist/shared/data-path.d.ts +4 -0
  152. package/dist/shared/data-path.d.ts.map +1 -1
  153. package/dist/shared/model-suggestion-retry.d.ts +2 -0
  154. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  155. package/dist/shared/prompt-async-transport.d.ts.map +1 -1
  156. package/dist/{storage-tags-35m4gms2.js → storage-tags-yygfb9c8.js} +7 -5
  157. package/dist/{task-config-cgpg0nvh.js → task-config-x3qmayd2.js} +6 -2
  158. package/dist/tools/ctx-note/tools.d.ts.map +1 -1
  159. package/dist/{transform-postprocess-phase-pmqxfq4q.js → transform-postprocess-phase-72v86syx.js} +32 -31
  160. package/dist/v2/auto-search-worker.js +4 -4
  161. package/dist/v2/chunk-embedding-write-worker.js +88 -0
  162. package/dist/v2/{compaction-marker-candidates-a15w3mqh.js → compaction-marker-candidates-1vqwr3s5.js} +2 -2
  163. package/dist/v2/compaction-marker-candidates-worker.js +1 -1
  164. package/dist/v2/{context-p1zfcw41.js → context-w055w17c.js} +628 -255
  165. package/dist/v2/{derive-budgets-0rmpmxjw.js → derive-budgets-2zh4gm2c.js} +3 -3
  166. package/dist/v2/embedding-backfill-jmaf8zrr.js +21 -0
  167. package/dist/v2/embedding-worker-process.js +1 -1
  168. package/dist/v2/embedding-worker.js +5 -5
  169. package/dist/v2/{history-owner-2cr9py37.js → history-owner-42e16w0n.js} +2 -2
  170. package/dist/v2/hooks/context.d.ts.map +1 -1
  171. package/dist/v2/hooks/dream-manual.d.ts.map +1 -1
  172. package/dist/v2/hooks/dream-trigger.d.ts +1 -1
  173. package/dist/v2/hooks/dream-trigger.d.ts.map +1 -1
  174. package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
  175. package/dist/v2/hooks/transform-features.d.ts +3 -2
  176. package/dist/v2/hooks/transform-features.d.ts.map +1 -1
  177. package/dist/v2/{logger-te6e1j72.js → logger-7qt02bnb.js} +1 -1
  178. package/dist/v2/{message-index-bounded-7wcbp975.js → message-index-bounded-wepg5723.js} +15 -15
  179. package/dist/v2/{message-index-cjhv92m2.js → message-index-gcmd0ng0.js} +15 -15
  180. package/dist/v2/{message-time-backfill-rz1pnpaj.js → message-time-backfill-bsteyc4d.js} +2 -2
  181. package/dist/v2/migration-worker.js +10 -10
  182. package/dist/v2/{project-embedding-registry-g34gcf74.js → project-embedding-registry-0msp56p8.js} +11 -10
  183. package/dist/v2/raw-ordinal-warmup-worker.js +12 -7
  184. package/dist/v2/{read-session-chunk-8d3v87vr.js → read-session-chunk-hr3w5bjk.js} +10 -10
  185. package/dist/v2/{read-session-raw-h4azh85b.js → read-session-raw-b3tf6ra1.js} +6 -2
  186. package/dist/v2/recomp-orchestrator-ca7qt75a.js +60 -0
  187. package/dist/v2/retrospective-raw-provider.d.ts.map +1 -1
  188. package/dist/v2/{safe-notification-target-936374xx.js → safe-notification-target-qg7n2s77.js} +2 -2
  189. package/dist/v2/{search-a1acjwf8.js → search-c86dcv14.js} +24 -23
  190. package/dist/v2/{send-session-notification-z5mcjdea.js → send-session-notification-8ghn9tnv.js} +5 -5
  191. package/dist/v2/{server-npm52h2q.js → server-05xjtq6c.js} +1 -1
  192. package/dist/v2/{server-s6jqh8bj.js → server-0ppsweh6.js} +1 -1
  193. package/dist/v2/server-0s95v3en.js +49 -0
  194. package/dist/v2/{server-hn9fb3v0.js → server-34kwfsr4.js} +2 -2
  195. package/dist/v2/server-4gn3z5an.js +229 -0
  196. package/dist/v2/{server-kn7skz9r.js → server-6cdy4rc0.js} +3 -3
  197. package/dist/v2/{server-7dv9wt9r.js → server-6pmqg9m4.js} +1 -1
  198. package/dist/v2/{server-7fvmt15t.js → server-b81w6sw3.js} +273 -107
  199. package/dist/v2/{server-kmapq3v0.js → server-bxpwy6fy.js} +18 -5
  200. package/dist/v2/{server-d6t16r89.js → server-d8tj10db.js} +1 -1
  201. package/dist/v2/{server-cxsr0ng6.js → server-da07v4xp.js} +1 -1
  202. package/dist/v2/{server-rxcq4t50.js → server-ef89gdsx.js} +5 -5
  203. package/dist/v2/{server-9e5r8y60.js → server-f2xf5gcb.js} +46 -2
  204. package/dist/v2/{server-83d71zab.js → server-g10mdym6.js} +3 -3
  205. package/dist/v2/{server-njnx39q2.js → server-gvkm8xaj.js} +189 -29
  206. package/dist/v2/{server-ckrb5rm8.js → server-h0410h0v.js} +1 -1
  207. package/dist/v2/{server-sg68np13.js → server-hek6z3w6.js} +330 -254
  208. package/dist/v2/{server-f27he3j1.js → server-k2bzedxk.js} +4 -4
  209. package/dist/v2/{server-wkhfyzpg.js → server-m97brnat.js} +9 -9
  210. package/dist/v2/{server-erfp0xb6.js → server-n8ch9683.js} +16 -16
  211. package/dist/v2/{server-bx59ezg6.js → server-prg55b7k.js} +16 -6
  212. package/dist/v2/{server-89fcbe37.js → server-pwv4ezb0.js} +1 -1
  213. package/dist/v2/{server-r5p3b1wy.js → server-qd11g795.js} +29 -1
  214. package/dist/v2/{server-ewqshbs8.js → server-qhfvvfxj.js} +64 -7
  215. package/dist/v2/{server-988cqjme.js → server-rrqpvwqd.js} +2 -2
  216. package/dist/v2/{server-d3f4g62c.js → server-t4prcjc1.js} +13 -13
  217. package/dist/v2/{server-nveratm5.js → server-tbe1femw.js} +4 -4
  218. package/dist/v2/{server-jc8v585p.js → server-th4y11y7.js} +15 -15
  219. package/dist/v2/{server-h3wc20sv.js → server-vbe4se57.js} +4 -4
  220. package/dist/v2/{server-pbpp8r8h.js → server-xh7jar6k.js} +9 -9
  221. package/dist/v2/{server-63ha7f0f.js → server-yrvqaswb.js} +1 -1
  222. package/dist/v2/{server-5x7kmyz8.js → server-zc3e54vy.js} +10 -51
  223. package/dist/v2/{server-xqf2d2mg.js → server-zs8d0s3b.js} +2 -2
  224. package/dist/v2/server.d.ts.map +1 -1
  225. package/dist/v2/server.js +18 -10
  226. package/dist/v2/{storage-tags-c4zfcxv4.js → storage-tags-a2gq6dw7.js} +6 -4
  227. package/dist/v2/store-reader.d.ts +1 -0
  228. package/dist/v2/store-reader.d.ts.map +1 -1
  229. package/dist/v2/{task-config-x0hq3qfd.js → task-config-nvz8mapa.js} +6 -2
  230. package/dist/v2/{wrapup-orchestrator-87q9d5e2.js → wrapup-orchestrator-e1a2w6jh.js} +31 -29
  231. package/dist/wrapup-orchestrator-2051r6qm.js +48 -0
  232. package/package.json +6 -5
  233. package/src/agents/smart-notes-dreamer-gate.fixture.ts +171 -0
  234. package/src/agents/smart-notes-dreamer-gate.golden.json +245 -0
  235. package/src/agents/smart-notes-dreamer-gate.test.ts +161 -0
  236. package/src/config/agent-disable.ts +13 -0
  237. package/src/config/dependency-notes.test.ts +114 -0
  238. package/src/config/dependency-notes.ts +80 -0
  239. package/src/config/schema/magic-context.ts +23 -14
  240. package/src/features/magic-context/dreamer/task-registry.ts +40 -0
  241. package/src/shared/data-path.test.ts +35 -1
  242. package/src/shared/data-path.ts +57 -1
  243. package/src/shared/model-suggestion-retry.test.ts +34 -0
  244. package/src/shared/model-suggestion-retry.ts +23 -3
  245. package/src/shared/prompt-async-transport.test.ts +1 -1
  246. package/src/shared/prompt-async-transport.ts +16 -3
  247. package/dist/embedding-backfill-fjbfh1dt.js +0 -21
  248. package/dist/recomp-orchestrator-67k45s0b.js +0 -60
  249. package/dist/v2/embedding-backfill-xcw3t6hp.js +0 -20
  250. package/dist/v2/recomp-orchestrator-n0pq36f0.js +0 -59
  251. package/dist/wrapup-orchestrator-jqapepw0.js +0 -47
  252. /package/dist/{index-e6xnpach.js → index-b7p25tm0.js} +0 -0
  253. /package/dist/v2/{index-e6xnpach.js → index-b7p25tm0.js} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  importPluginModule,
4
4
  writeForwardedLogLine2,
5
5
  log2
6
- } from "./index-mvvephtj.js";
6
+ } from "./index-j75v2476.js";
7
7
  import {
8
8
  inRootAsyncContext2,
9
9
  registerSlowWriteReporter2,
@@ -18,7 +18,7 @@ import {
18
18
  import {
19
19
  bootQuietRemainingMs,
20
20
  scheduleAfterBootQuiet
21
- } from "./index-0jz47061.js";
21
+ } from "./index-a8bvhwqs.js";
22
22
  import {
23
23
  getHarness2,
24
24
  harnessOwnsOpenCodeStore2
@@ -26,7 +26,7 @@ import {
26
26
  import {
27
27
  getMagicContextStorageDir,
28
28
  getLegacyOpenCodeMagicContextStorageDir
29
- } from "./index-0sahzkwr.js";
29
+ } from "./index-g2q4htwp.js";
30
30
  import {
31
31
  isOwnRpcServerRecord,
32
32
  isPidAlive,
@@ -37,13 +37,13 @@ import {
37
37
  parseRpcPortFile,
38
38
  inspectProcessesAsync,
39
39
  inspectWindowsProcessesSync
40
- } from "./index-q28hsbpg.js";
40
+ } from "./index-nj7yykkx.js";
41
41
  import {
42
42
  configureContextDatabasePragmas2
43
43
  } from "./index-fb3zxn06.js";
44
44
  import {
45
45
  startMessageFtsRowidMapBackfill
46
- } from "./index-mp2kghkv.js";
46
+ } from "./index-dyvbsvga.js";
47
47
  import {
48
48
  LKG_SLOT_CHUNKS_DDL,
49
49
  SESSION_REPLAY_DECISIONS_DDL,
@@ -53,12 +53,12 @@ import {
53
53
  hasPendingMigrations,
54
54
  getMainThreadMigrationBodyCount,
55
55
  runMigrations
56
- } from "./index-a865mj02.js";
56
+ } from "./index-wk0n1cgt.js";
57
57
  import {
58
58
  installTagIdentityRevisionTrigger,
59
59
  ensureColumn,
60
60
  installV95PerfSchema
61
- } from "./index-g7jkrz0x.js";
61
+ } from "./index-bp5083x2.js";
62
62
  import {
63
63
  resolveOpenCodeDbPath,
64
64
  hasV1MessageTables
@@ -66,10 +66,16 @@ import {
66
66
  import {
67
67
  setDatabase,
68
68
  loadToolDefinitionMeasurements
69
- } from "./index-9jvab89d.js";
69
+ } from "./index-n6m03s3n.js";
70
70
  import {
71
71
  getErrorMessage
72
72
  } from "./index-y8v6yerm.js";
73
+ import {
74
+ closeQuietly
75
+ } from "./index-8ajstryz.js";
76
+ import {
77
+ logSlowWriteTransaction
78
+ } from "./index-k29z4aqh.js";
73
79
  import {
74
80
  shouldEnforcePrivateStoragePermissions,
75
81
  ensureStorageDirectorySync,
@@ -78,12 +84,6 @@ import {
78
84
  copyStorageTreeSync,
79
85
  tightenStorageTreeSync
80
86
  } from "./index-fvnzcnww.js";
81
- import {
82
- closeQuietly
83
- } from "./index-8ajstryz.js";
84
- import {
85
- logSlowWriteTransaction
86
- } from "./index-150zz6fh.js";
87
87
 
88
88
  // src/features/magic-context/fail-closed-block.ts
89
89
  var FAIL_CLOSED_DOCTOR_COMMAND = "npx @cortexkit/magic-context@latest doctor";
@@ -1270,8 +1270,8 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1270
1270
  startMessageFtsRowidMapBackfill(db).then(async () => {
1271
1271
  if (!readsOpenCodeStore)
1272
1272
  return;
1273
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-y3hhsbzw.js"));
1274
- const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-nb5hhnrt.js"));
1273
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-ax05f7gr.js"));
1274
+ const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-qjge9044.js"));
1275
1275
  await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
1276
1276
  readPage: readRawSessionMessagePage
1277
1277
  }));
@@ -2762,4 +2762,4 @@ function getDatabasePersistenceError(db) {
2762
2762
  return persistenceErrorByDatabase.get(db) ?? null;
2763
2763
  }
2764
2764
 
2765
- export { FAIL_CLOSED_DOCTOR_COMMAND, formatFailClosedBlockingMessage, formatFailClosedBlockingSummary, createFailClosedBlockingError, isFailClosedBlockingError, shouldBypassFailClosedBlock, resolveAgentNameFromMessages, createFailClosedController, recordHookInitFailure, clearHookInitFailure, getLastHookInitFailure, startBootDeadline, getUnconfirmedMigrationHolders, getSchemaFenceRejection, getMigrationOnOpenRefusal, LATEST_SUPPORTED_VERSION, BOOT_SQLITE_BUSY_TIMEOUT_MS, getDatabasePath, getPersistedSchemaVersion, setSqlitePragmaConfig, runSqliteOptimize, initializeDatabase, openDatabase, openCurrentDatabase, openDatabaseAsync, isDatabasePersisted, getDatabasePersistenceError };
2765
+ export { FAIL_CLOSED_DOCTOR_COMMAND, formatFailClosedBlockingMessage, formatFailClosedBlockingSummary, createFailClosedBlockingError, isFailClosedBlockingError, shouldBypassFailClosedBlock, resolveAgentNameFromMessages, createFailClosedController, recordHookInitFailure, clearHookInitFailure, getLastHookInitFailure, startBootDeadline, getUnconfirmedMigrationHolders, getSchemaFenceRejection, getMigrationOnOpenRefusal, LATEST_SUPPORTED_VERSION, BOOT_SQLITE_BUSY_TIMEOUT_MS, getDatabasePath, getPersistedSchemaVersion, enforceSchemaFence, setSqlitePragmaConfig, runSqliteOptimize, initializeDatabase, openDatabase, openCurrentDatabase, openDatabaseAsync, isDatabasePersisted, getDatabasePersistenceError };
@@ -0,0 +1,229 @@
1
+ import {
2
+ getHarness2
3
+ } from "./index-pavzsdc6.js";
4
+ import {
5
+ isUserHomeDirectory
6
+ } from "./index-a8bvhwqs.js";
7
+ import {
8
+ logSlowWriteTransaction
9
+ } from "./index-k29z4aqh.js";
10
+
11
+ // src/features/magic-context/session-project-storage.ts
12
+ var SESSION_CHUNK_REPAIR_BATCH_SIZE = 100;
13
+ var upsertSessionProjectStatements = new WeakMap;
14
+ var repairSessionChunkProjectStatements = new WeakMap;
15
+ var misScopedProjectChunkStatements = new WeakMap;
16
+ var MIS_SCOPED_PROJECT_CHUNK_IDS_SQL = `
17
+ SELECT e.id FROM compartment_chunk_embeddings e
18
+ JOIN session_projects sp ON sp.session_id = e.session_id AND sp.harness = e.harness
19
+ WHERE e.project_path = ? AND sp.project_path <> e.project_path
20
+ UNION ALL
21
+ SELECT e.id FROM session_projects sp
22
+ JOIN compartment_chunk_embeddings e ON e.session_id = sp.session_id
23
+ WHERE sp.project_path = ? AND e.harness = sp.harness AND e.project_path <> sp.project_path`;
24
+ function getUpsertSessionProjectStatement(db) {
25
+ let stmt = upsertSessionProjectStatements.get(db);
26
+ if (!stmt) {
27
+ stmt = db.prepare(`INSERT INTO session_projects (session_id, harness, project_path, updated_at)
28
+ VALUES (?, ?, ?, ?)
29
+ ON CONFLICT(session_id, harness) DO UPDATE SET
30
+ project_path = excluded.project_path,
31
+ updated_at = excluded.updated_at
32
+ WHERE session_projects.project_path <> excluded.project_path`);
33
+ upsertSessionProjectStatements.set(db, stmt);
34
+ }
35
+ return stmt;
36
+ }
37
+ function getRepairSessionChunkProjectStatement(db) {
38
+ let stmt = repairSessionChunkProjectStatements.get(db);
39
+ if (!stmt) {
40
+ stmt = db.prepare(`UPDATE compartment_chunk_embeddings
41
+ SET project_path = ?
42
+ WHERE id IN (
43
+ SELECT id
44
+ FROM compartment_chunk_embeddings
45
+ WHERE session_id = ?
46
+ AND harness = ?
47
+ AND project_path <> ?
48
+ LIMIT ?
49
+ )`);
50
+ repairSessionChunkProjectStatements.set(db, stmt);
51
+ }
52
+ return stmt;
53
+ }
54
+ function findMisScopedCompartmentChunkEmbeddingIdsForProject(db, projectPath) {
55
+ return db.prepare(`SELECT id FROM (${MIS_SCOPED_PROJECT_CHUNK_IDS_SQL}) LIMIT 25`).all(projectPath, projectPath).map(({ id }) => id);
56
+ }
57
+ function recordSessionProjectIdentity(db, sessionId, projectPath) {
58
+ if (!sessionId || !projectPath)
59
+ return;
60
+ if (!projectPath.startsWith("git:") && !projectPath.startsWith("dir:") && isUserHomeDirectory(projectPath))
61
+ return;
62
+ const harness = getHarness2();
63
+ const now = Date.now();
64
+ let previousProjectPath;
65
+ db.transaction(() => {
66
+ const existing = db.prepare("SELECT project_path FROM session_projects WHERE session_id = ? AND harness = ?").get(sessionId, harness);
67
+ previousProjectPath = existing?.project_path;
68
+ getUpsertSessionProjectStatement(db).run(sessionId, harness, projectPath, now);
69
+ getRepairSessionChunkProjectStatement(db).run(projectPath, sessionId, harness, projectPath, SESSION_CHUNK_REPAIR_BATCH_SIZE);
70
+ }).immediate();
71
+ return previousProjectPath === projectPath ? undefined : { previousProjectPath, projectPath };
72
+ }
73
+ function hasRecordedSessionProjectIdentity(db, sessionId) {
74
+ const row = db.prepare("SELECT 1 AS found FROM session_projects WHERE session_id = ? AND harness = ?").get(sessionId, getHarness2());
75
+ return row?.found === 1;
76
+ }
77
+ function repairMisScopedCompartmentChunkEmbeddingsForProject(db, projectPath, ids = findMisScopedCompartmentChunkEmbeddingIdsForProject(db, projectPath)) {
78
+ if (!projectPath || ids.length === 0)
79
+ return 0;
80
+ return db.prepare(`UPDATE compartment_chunk_embeddings
81
+ SET project_path = (SELECT sp.project_path FROM session_projects sp
82
+ WHERE sp.session_id = compartment_chunk_embeddings.session_id
83
+ AND sp.harness = compartment_chunk_embeddings.harness)
84
+ WHERE id IN (${ids.map(() => "?").join(",")}) AND EXISTS (
85
+ SELECT 1 FROM session_projects sp
86
+ WHERE sp.session_id = compartment_chunk_embeddings.session_id
87
+ AND sp.harness = compartment_chunk_embeddings.harness
88
+ AND sp.project_path <> compartment_chunk_embeddings.project_path
89
+ AND (sp.project_path = ? OR compartment_chunk_embeddings.project_path = ?)
90
+ )`).run(...ids, projectPath, projectPath).changes;
91
+ }
92
+
93
+ // src/features/magic-context/git-commits/sweep-coordinator.ts
94
+ var GIT_SWEEP_COOLDOWN_MS = 10 * 60 * 1000;
95
+ var GIT_SWEEP_LEASE_TTL_MS = 5 * 60 * 1000;
96
+ var GIT_SWEEP_NON_INDEXABLE_REPROBE_MS = 24 * 60 * 60 * 1000;
97
+ var GIT_SWEEP_LEASE_RENEWAL_MS = 60 * 1000;
98
+ function runImmediate(db, body) {
99
+ db.exec("BEGIN IMMEDIATE");
100
+ const transactionStartedAt = performance.now();
101
+ let committed = false;
102
+ try {
103
+ const result = body();
104
+ db.exec("COMMIT");
105
+ committed = true;
106
+ logSlowWriteTransaction("git_sweep_lease", transactionStartedAt);
107
+ return result;
108
+ } finally {
109
+ if (!committed) {
110
+ try {
111
+ db.exec("ROLLBACK");
112
+ } catch {}
113
+ }
114
+ }
115
+ }
116
+ function rowToState(row) {
117
+ return {
118
+ projectPath: row.project_path,
119
+ leaseHolder: row.lease_holder,
120
+ leaseExpiresAt: row.lease_expires_at,
121
+ lastSweptAt: row.last_swept_at
122
+ };
123
+ }
124
+ function getGitSweepCoordinatorState(db, projectPath) {
125
+ const row = db.prepare(`SELECT project_path, lease_holder, lease_expires_at, last_swept_at
126
+ FROM git_sweep_coordinator
127
+ WHERE project_path = ?`).get(projectPath);
128
+ return row ? rowToState(row) : null;
129
+ }
130
+ function acquireGitSweepLease(db, projectPath, holderId, options = {}) {
131
+ const cooldownMs = options.cooldownMs ?? GIT_SWEEP_COOLDOWN_MS;
132
+ const leaseTtlMs = options.leaseTtlMs ?? GIT_SWEEP_LEASE_TTL_MS;
133
+ return runImmediate(db, () => {
134
+ const now = Date.now();
135
+ const row = getGitSweepCoordinatorState(db, projectPath);
136
+ if (row?.leaseHolder && row.leaseExpiresAt !== null && row.leaseExpiresAt > now) {
137
+ return {
138
+ acquired: false,
139
+ projectPath,
140
+ reason: "lease_active",
141
+ leaseHolder: row.leaseHolder,
142
+ leaseExpiresAt: row.leaseExpiresAt,
143
+ lastSweptAt: row.lastSweptAt,
144
+ nextAllowedAt: null
145
+ };
146
+ }
147
+ if (!options.ignoreCooldown && row?.lastSweptAt !== null && row?.lastSweptAt !== undefined) {
148
+ const nextAllowedAt = row.lastSweptAt + cooldownMs;
149
+ if (nextAllowedAt > now) {
150
+ return {
151
+ acquired: false,
152
+ projectPath,
153
+ reason: "cooldown_active",
154
+ leaseHolder: row.leaseHolder,
155
+ leaseExpiresAt: row.leaseExpiresAt,
156
+ lastSweptAt: row.lastSweptAt,
157
+ nextAllowedAt
158
+ };
159
+ }
160
+ }
161
+ const leaseExpiresAt = now + leaseTtlMs;
162
+ db.prepare(`INSERT INTO git_sweep_coordinator (
163
+ project_path,
164
+ lease_holder,
165
+ lease_expires_at,
166
+ last_swept_at
167
+ ) VALUES (?, ?, ?, NULL)
168
+ ON CONFLICT(project_path) DO UPDATE SET
169
+ lease_holder = excluded.lease_holder,
170
+ lease_expires_at = excluded.lease_expires_at`).run(projectPath, holderId, leaseExpiresAt);
171
+ return {
172
+ acquired: true,
173
+ projectPath,
174
+ holderId,
175
+ acquiredAt: now,
176
+ leaseExpiresAt
177
+ };
178
+ });
179
+ }
180
+ function renewGitSweepLease(db, projectPath, holderId, leaseTtlMs = GIT_SWEEP_LEASE_TTL_MS) {
181
+ return runImmediate(db, () => {
182
+ const now = Date.now();
183
+ const leaseExpiresAt = now + leaseTtlMs;
184
+ const result = db.prepare(`UPDATE git_sweep_coordinator
185
+ SET lease_expires_at = ?
186
+ WHERE project_path = ?
187
+ AND lease_holder = ?
188
+ AND lease_expires_at > ?`).run(leaseExpiresAt, projectPath, holderId, now);
189
+ return result.changes === 1;
190
+ });
191
+ }
192
+ function markGitSweepSuccessAndRelease(db, projectPath, holderId) {
193
+ return runImmediate(db, () => {
194
+ const now = Date.now();
195
+ const result = db.prepare(`UPDATE git_sweep_coordinator
196
+ SET lease_holder = NULL,
197
+ lease_expires_at = NULL,
198
+ last_swept_at = ?
199
+ WHERE project_path = ?
200
+ AND lease_holder = ?
201
+ AND lease_expires_at > ?`).run(now, projectPath, holderId, now);
202
+ return result.changes === 1;
203
+ });
204
+ }
205
+ function parkGitSweepNonIndexable(db, projectPath, holderId, reprobeMs = GIT_SWEEP_NON_INDEXABLE_REPROBE_MS) {
206
+ return runImmediate(db, () => {
207
+ const now = Date.now();
208
+ const sweptAt = now + reprobeMs - GIT_SWEEP_COOLDOWN_MS;
209
+ const result = db.prepare(`UPDATE git_sweep_coordinator
210
+ SET lease_holder = NULL,
211
+ lease_expires_at = NULL,
212
+ last_swept_at = ?
213
+ WHERE project_path = ?
214
+ AND lease_holder = ?
215
+ AND lease_expires_at > ?`).run(sweptAt, projectPath, holderId, now);
216
+ return result.changes === 1;
217
+ });
218
+ }
219
+ function releaseGitSweepLease(db, projectPath, holderId) {
220
+ runImmediate(db, () => {
221
+ db.prepare(`UPDATE git_sweep_coordinator
222
+ SET lease_holder = NULL,
223
+ lease_expires_at = NULL
224
+ WHERE project_path = ?
225
+ AND lease_holder = ?`).run(projectPath, holderId);
226
+ });
227
+ }
228
+
229
+ export { findMisScopedCompartmentChunkEmbeddingIdsForProject, recordSessionProjectIdentity, hasRecordedSessionProjectIdentity, repairMisScopedCompartmentChunkEmbeddingsForProject, GIT_SWEEP_LEASE_RENEWAL_MS, acquireGitSweepLease, renewGitSweepLease, markGitSweepSuccessAndRelease, parkGitSweepNonIndexable, releaseGitSweepLease };
@@ -6,7 +6,7 @@ import {
6
6
  getTemporalDecisions,
7
7
  freezeTemporalDecisions,
8
8
  stableStringify
9
- } from "./index-g7jkrz0x.js";
9
+ } from "./index-bp5083x2.js";
10
10
  import {
11
11
  protectedToolTagNumbers,
12
12
  byteSize,
@@ -47,6 +47,7 @@ import {
47
47
  backfillTagTokenCounts2,
48
48
  insertTag2,
49
49
  updateTagStatus2,
50
+ markTagDropped2,
50
51
  markWhitespaceAssistantTagInert2,
51
52
  getInertWhitespaceAssistantTags2,
52
53
  updateTagDropMode2,
@@ -69,16 +70,16 @@ import {
69
70
  adoptNullOwnerToolTag2,
70
71
  getCandidateToolOwners2,
71
72
  pickNearestPriorOwner2
72
- } from "./index-f8cn4xqa.js";
73
+ } from "./index-fwefky9w.js";
73
74
  import {
74
75
  textMentionsRecentCommit,
75
76
  hasMeaningfulUserText2,
76
77
  estimateTokens
77
- } from "./index-gjvjh960.js";
78
+ } from "./index-hqkczed7.js";
78
79
  import {
79
80
  log2,
80
81
  sessionLog2
81
- } from "./index-mvvephtj.js";
82
+ } from "./index-j75v2476.js";
82
83
  import {
83
84
  inRootAsyncContext2,
84
85
  getTagIdentityWriteGeneration2,
@@ -88,12 +89,12 @@ import {
88
89
  } from "./index-wafzvyhg.js";
89
90
  import {
90
91
  isValidLanguageCode
91
- } from "./index-w28y7d0z.js";
92
+ } from "./index-1sarmj9z.js";
92
93
  import {
93
94
  getProjectEmbeddingSnapshot2,
94
95
  embedTextForProject2,
95
96
  embedBatchForProject2
96
- } from "./index-se1w3v2m.js";
97
+ } from "./index-y1qysm3q.js";
97
98
  import {
98
99
  isEmbeddingHostBusy2
99
100
  } from "./index-qt1qqasc.js";
@@ -189,7 +190,7 @@ import {
189
190
  extractToolCallObservation,
190
191
  ToolMutationBatch,
191
192
  createToolDropTarget
192
- } from "./index-qr1mkc2y.js";
193
+ } from "./index-b16gpywn.js";
193
194
  import {
194
195
  getMaxM0MutationId,
195
196
  rememberUnpublishedAutoSearchNoHint,
@@ -201,6 +202,7 @@ import {
201
202
  advanceToolReclaimWatermark,
202
203
  requestPendingMaterialization,
203
204
  pendingMaterializationOrigin,
205
+ hasPendingMaterializationOrigin,
204
206
  clearPendingMaterialization,
205
207
  saveSourceContent,
206
208
  replaceSourceContent,
@@ -223,31 +225,31 @@ import {
223
225
  peekNoteNudgeText,
224
226
  markNoteNudgeDelivered,
225
227
  getActiveCompartmentRun
226
- } from "./index-z7avx6rw.js";
228
+ } from "./index-2jr1smmh.js";
227
229
  import {
228
230
  runSessionWarmupWorker
229
- } from "./index-angx1s0k.js";
231
+ } from "./index-mmfa86mt.js";
230
232
  import {
231
233
  openCodeDbExists,
232
234
  withReadOnlySessionDb,
233
235
  getMessageTimesFromOpenCodeDb
234
- } from "./index-bzp9s8z2.js";
236
+ } from "./index-1d289pq2.js";
235
237
  import {
236
238
  BoundedSessionMap
237
- } from "./index-0j6crjgh.js";
239
+ } from "./index-v13skev1.js";
238
240
  import {
239
241
  renderUserFacingFailure
240
- } from "./index-yhrrx7qa.js";
241
- import {
242
- getErrorMessage
243
- } from "./index-y8v6yerm.js";
242
+ } from "./index-bxdg2nbt.js";
244
243
  import {
245
244
  normalizeProtectedToolName,
246
245
  mergeProtectedTools
247
246
  } from "./index-d9vfe7xq.js";
247
+ import {
248
+ getErrorMessage
249
+ } from "./index-y8v6yerm.js";
248
250
  import {
249
251
  logSlowWriteTransaction
250
- } from "./index-150zz6fh.js";
252
+ } from "./index-k29z4aqh.js";
251
253
 
252
254
  // src/features/magic-context/tagger.ts
253
255
  var TOOL_COMPOSITE_KEY_SEP = "\x00";
@@ -2829,13 +2831,20 @@ function foldBustsServedPrefix(reason, before, after) {
2829
2831
  return CACHE_LOSING_FOLD_REASONS.has(reason ?? "") || foldChangesServedPrefix(before, after);
2830
2832
  }
2831
2833
  function prepareLegacyToolSkeletonConversions(db, sessionId, targets, options = {}) {
2832
- const readRows = (connection) => connection.prepare(`SELECT tag_number AS tagNumber, drop_mode AS dropMode, message_id AS callId
2833
- FROM tags
2834
- WHERE session_id = ? AND type = 'tool' AND status = 'dropped'
2835
- AND drop_mode IN ('truncated', 'full')
2836
- ORDER BY tag_number`).all(sessionId);
2834
+ const candidates = [...targets.keys()].sort((a, b) => a - b);
2835
+ const readRows = (connection) => {
2836
+ if (candidates.length === 0)
2837
+ return [];
2838
+ const statement = connection.prepare(`SELECT tag_number AS tagNumber, drop_mode AS dropMode, message_id AS callId
2839
+ FROM tags WHERE session_id = ? AND tag_number = ?
2840
+ AND type = 'tool' AND status = 'dropped'
2841
+ AND drop_mode IN ('truncated', 'full')`);
2842
+ return candidates.flatMap((tagNumber) => {
2843
+ const row = statement.get(sessionId, tagNumber);
2844
+ return row ? [row] : [];
2845
+ });
2846
+ };
2837
2847
  const rows = readRows(db);
2838
- const identity = JSON.stringify(rows);
2839
2848
  const converted = new Map;
2840
2849
  for (const row of rows) {
2841
2850
  const target = targets.get(row.tagNumber);
@@ -2856,7 +2865,10 @@ function prepareLegacyToolSkeletonConversions(db, sessionId, targets, options =
2856
2865
  }
2857
2866
  return {
2858
2867
  converted,
2859
- isCurrent: (connection) => JSON.stringify(readRows(connection)) === identity,
2868
+ isCurrent: (connection) => {
2869
+ const current = readRows(connection);
2870
+ return current.length === rows.length && current.every((row, index) => row.tagNumber === rows[index].tagNumber && row.dropMode === rows[index].dropMode && row.callId === rows[index].callId);
2871
+ },
2860
2872
  persist: (connection) => {
2861
2873
  for (const [tagNumber, mode] of converted)
2862
2874
  updateTagDropMode2(connection, sessionId, tagNumber, mode);
@@ -2943,9 +2955,7 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
2943
2955
  try {
2944
2956
  db.transaction(() => {
2945
2957
  startedAt = performance.now();
2946
- if (mode)
2947
- updateTagDropMode2(db, sessionId, pendingOp.tagId, mode);
2948
- updateTagStatus2(db, sessionId, pendingOp.tagId, "dropped");
2958
+ markTagDropped2(db, sessionId, pendingOp.tagId, mode);
2949
2959
  if (!synthetic)
2950
2960
  removePendingOp(db, sessionId, pendingOp.tagId);
2951
2961
  }).immediate();
@@ -5279,6 +5289,25 @@ function finalizeMessageRepresentation2(messages, resolvedProviderID, options) {
5279
5289
  }
5280
5290
  return { clearedParts, mergedReasoningParts };
5281
5291
  }
5292
+ function legacyPublishedHeadChanged(args) {
5293
+ if (!args.pendingCompartmentInjection || !args.readLastServedMessages)
5294
+ return false;
5295
+ const served = args.readLastServedMessages();
5296
+ if (served === null)
5297
+ return true;
5298
+ const previous = served[0];
5299
+ if (!Array.isArray(previous?.parts) || !args.pendingCompartmentInjection)
5300
+ return false;
5301
+ const text = previous.parts.find((part) => typeof part === "object" && part !== null && ("type" in part) && part.type === "text" && ("text" in part))?.text;
5302
+ if (typeof text !== "string")
5303
+ return false;
5304
+ const block = `<session-history>
5305
+ ${args.pendingCompartmentInjection.block}
5306
+ </session-history>`;
5307
+ return text !== block && !text.startsWith(`${block}
5308
+
5309
+ `);
5310
+ }
5282
5311
  async function runPostTransformPhase2(args) {
5283
5312
  const tPostprocessSetup = performance.now();
5284
5313
  const compactionOff = args.compactionOff === true;
@@ -5489,11 +5518,6 @@ async function runPostTransformPhase2(args) {
5489
5518
  }
5490
5519
  sessionLog2(args.sessionId, `m[0] HARD fold decision: reason=${m0MaterializeReason ?? foldDueDecision.reason ?? (foldExecutedThisPass ? "drift" : "soft_refresh")} executed=${foldExecutedThisPass} bustsServedPrefix=${foldBustsServedPrefixThisPass}`);
5491
5520
  }
5492
- if (args.normalizeRecoveryTail && (foldBustsServedPrefixThisPass || firstRenderBust)) {
5493
- args.normalizeRecoveryTail();
5494
- args.tags = getTagsBySession2(args.db, args.sessionId);
5495
- newTargets = protectNewTagMutations(args.messages, args.targets, retainedThinking, args.thinkingBindingRecoveryEnabledForModel === true);
5496
- }
5497
5521
  logTransformTiming(args.sessionId, "pp.prefixPreflight", tPostprocessSetup, `foldExecuted=${foldExecutedThisPass} m1Refreshed=${publishedM1RefreshedThisPass}`);
5498
5522
  const tPassDecisions = performance.now();
5499
5523
  const frontToolCandidates = args.tags.filter((tag) => tag.type === "tool" && tag.status === "active" && args.targets.get(tag.tagNumber)?.canDrop?.());
@@ -5520,13 +5544,18 @@ async function runPostTransformPhase2(args) {
5520
5544
  subagentExecute: !args.fullFeatureMode && args.schedulerDecision === "execute",
5521
5545
  hardFold: foldBustsServedPrefixThisPass || firstRenderBust || idleExpiryRebuild,
5522
5546
  force: emergencyDropEligible && (args.contextUsage.percentage >= 95 || getEmergencyInputSample(args.db, args.sessionId) === 0),
5523
- explicitFlush: isExplicitFlush || deferredMaterialize && !prefixPreflightFailed,
5524
- publishedHistory: publishedM1RefreshedThisPass || !m0M1EnabledForFold && (args.pendingCompartmentInjection?.compartmentCount ?? 0) > 0 && (args.historyRebuiltThisPass || args.rebuiltHistoryFromInitialPrepare || args.canConsumeDeferredLate && args.deferredHistoryWasPendingAtPassStart)
5547
+ explicitFlush: isExplicitFlush && hasPendingMaterializationOrigin(args.pendingMaterializationSessions, args.sessionId, "user_flush"),
5548
+ publishedHistory: !prefixPreflightFailed && (publishedM1RefreshedThisPass || !m0M1EnabledForFold && (args.pendingCompartmentInjection?.compartmentCount ?? 0) > 0 && legacyPublishedHeadChanged(args))
5525
5549
  };
5526
5550
  const publishedWorkDrainAllowed = !compactionOff && (!activeThinkingPrefixHold || firstRenderBust || idleExpiryRebuild || emergencyDropEligible) && hasReclaimRide(rideSignals);
5527
5551
  const shouldApplyPendingOps = publishedWorkDrainAllowed;
5528
5552
  const shouldRunHeuristics = publishedWorkDrainAllowed && (rideSignals.publishedHistory || materializationRequested || forceMaterialization || foldBustsServedPrefixThisPass || firstRenderBust || heldIdleExpiryRebuild || emergencyDropEligible || args.schedulerDecision === "execute" && (!alreadyRanThisTurn || !args.fullFeatureMode));
5529
5553
  const isCacheBustingPass = publishedWorkDrainAllowed;
5554
+ if (args.normalizeRecoveryTail && isCacheBustingPass) {
5555
+ args.normalizeRecoveryTail();
5556
+ args.tags = getTagsBySession2(args.db, args.sessionId);
5557
+ newTargets = protectNewTagMutations(args.messages, args.targets, retainedThinking, args.thinkingBindingRecoveryEnabledForModel === true);
5558
+ }
5530
5559
  const reclaimDistance = isCacheBustingPass ? toolReclaimDistanceEntries(args.messages, args.targets) : [];
5531
5560
  const canEditWholePrefix = isCacheBustingPass && !activeThinkingPrefixHold;
5532
5561
  const previousTemporalDecisions = args.temporalCandidates && !compactionOff ? new Map([
@@ -3,21 +3,21 @@ import {
3
3
  } from "./index-pavzsdc6.js";
4
4
  import {
5
5
  getMagicContextStorageDir
6
- } from "./index-0sahzkwr.js";
6
+ } from "./index-g2q4htwp.js";
7
7
  import {
8
8
  log2,
9
9
  sessionLog2
10
- } from "./index-mvvephtj.js";
10
+ } from "./index-j75v2476.js";
11
11
  import {
12
12
  localBudget,
13
13
  calibrationForModelKey
14
14
  } from "./index-1zx87sdm.js";
15
- import {
16
- writeStorageFileAtomicSync
17
- } from "./index-fvnzcnww.js";
18
15
  import {
19
16
  modelRefLookupOrder
20
17
  } from "./index-avwt563y.js";
18
+ import {
19
+ writeStorageFileAtomicSync
20
+ } from "./index-fvnzcnww.js";
21
21
 
22
22
  // src/shared/models-dev-cache.ts
23
23
  import { readFileSync } from "node:fs";
@@ -5,7 +5,7 @@ import {
5
5
  tagRevisionKey,
6
6
  tagIdentityRevisionKey,
7
7
  deleteTagIdentityRevisions
8
- } from "./index-g7jkrz0x.js";
8
+ } from "./index-bp5083x2.js";
9
9
  import {
10
10
  getHarness2
11
11
  } from "./index-pavzsdc6.js";
@@ -13,30 +13,36 @@ import {
13
13
  removeSystemReminders,
14
14
  hasMeaningfulUserText2,
15
15
  extractTexts2
16
- } from "./index-gjvjh960.js";
16
+ } from "./index-hqkczed7.js";
17
17
  import {
18
18
  getMagicContextStorageDir
19
- } from "./index-0sahzkwr.js";
19
+ } from "./index-g2q4htwp.js";
20
20
  import {
21
21
  withSqliteBackgroundWriter2,
22
22
  withoutSqliteTransformPass2
23
23
  } from "./index-wafzvyhg.js";
24
24
  import {
25
25
  cleanUserText2
26
- } from "./index-qr1mkc2y.js";
26
+ } from "./index-b16gpywn.js";
27
27
  import {
28
28
  recordMessageFtsRowid,
29
29
  recordIndexedMessageTime,
30
30
  messageFtsOrdinalRangeIsMapped,
31
31
  deleteUnmappedMessageFtsRows
32
- } from "./index-mp2kghkv.js";
32
+ } from "./index-dyvbsvga.js";
33
33
  import {
34
34
  isPidAlive,
35
35
  readProcessStartTime
36
- } from "./index-q28hsbpg.js";
36
+ } from "./index-nj7yykkx.js";
37
37
  import {
38
38
  deleteChunkEmbedBackoffForSession
39
- } from "./index-9159kk15.js";
39
+ } from "./index-3kx0kg0f.js";
40
+ import {
41
+ closeQuietly
42
+ } from "./index-8ajstryz.js";
43
+ import {
44
+ logSlowWriteTransaction
45
+ } from "./index-k29z4aqh.js";
40
46
  import {
41
47
  ensurePrivateStorageDirectorySync,
42
48
  writeStorageFileSync,
@@ -44,12 +50,6 @@ import {
44
50
  syncStorageDirectorySync,
45
51
  writeStorageFileDurableAtomicSync
46
52
  } from "./index-fvnzcnww.js";
47
- import {
48
- closeQuietly
49
- } from "./index-8ajstryz.js";
50
- import {
51
- logSlowWriteTransaction
52
- } from "./index-150zz6fh.js";
53
53
 
54
54
  // src/shared/bounded-session-map.ts
55
55
  class BoundedSessionMap {