@cortexkit/opencode-magic-context 0.49.34 → 0.49.36

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 (312) hide show
  1. package/README.md +1 -1
  2. package/dist/auto-search-worker.js +163 -155
  3. package/dist/chunk-embedding-write-worker.js +70 -66
  4. package/dist/{compaction-marker-candidates-31h86ph0.js → compaction-marker-candidates-5p1qkve9.js} +5 -2
  5. package/dist/compaction-marker-candidates-worker.js +24 -23
  6. package/dist/{compartment-chunk-embedding-5q5gj67r.js → compartment-chunk-embedding-ypktm0tk.js} +10 -8
  7. package/dist/{conflict-warning-hook-xgskea1v.js → conflict-warning-hook-b75jn458.js} +11 -9
  8. package/dist/{context-p3xrarzt.js → context-969z683s.js} +1839 -746
  9. package/dist/{derive-budgets-pqybnx09.js → derive-budgets-htj16n4x.js} +3 -2
  10. package/dist/embedding-backfill-rma0v2ct.js +28 -0
  11. package/dist/embedding-worker-process.js +2 -1
  12. package/dist/embedding-worker.js +6 -5
  13. package/dist/expand-attachments-h33jbgyz.js +21 -0
  14. package/dist/features/magic-context/auto-search-diagnostics.d.ts +21 -0
  15. package/dist/features/magic-context/auto-search-diagnostics.d.ts.map +1 -0
  16. package/dist/features/magic-context/compaction-marker-candidates.d.ts.map +1 -1
  17. package/dist/features/magic-context/compaction-marker.d.ts +5 -3
  18. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  19. package/dist/features/magic-context/compartment-chunk-embedding.d.ts +1 -1
  20. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  21. package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
  22. package/dist/features/magic-context/dreamer/verify-gate.d.ts +2 -0
  23. package/dist/features/magic-context/dreamer/verify-gate.d.ts.map +1 -1
  24. package/dist/features/magic-context/dreamer/verify-state.d.ts +9 -0
  25. package/dist/features/magic-context/dreamer/verify-state.d.ts.map +1 -0
  26. package/dist/features/magic-context/dreamer/verify.d.ts +2 -1
  27. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  28. package/dist/features/magic-context/migration-worker-client.d.ts +3 -0
  29. package/dist/features/magic-context/migration-worker-client.d.ts.map +1 -1
  30. package/dist/features/magic-context/migration-worker.d.ts +15 -0
  31. package/dist/features/magic-context/migration-worker.d.ts.map +1 -1
  32. package/dist/features/magic-context/overflow-detection.d.ts +2 -2
  33. package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
  34. package/dist/features/magic-context/search-rerank.d.ts.map +1 -1
  35. package/dist/features/magic-context/search.d.ts +4 -0
  36. package/dist/features/magic-context/search.d.ts.map +1 -1
  37. package/dist/features/magic-context/storage-meta-persisted.d.ts +1 -0
  38. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  39. package/dist/features/magic-context/storage-tags.d.ts +4 -0
  40. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  41. package/dist/features/magic-context/store-generation-rebase-labels.d.ts +6 -0
  42. package/dist/features/magic-context/store-generation-rebase-labels.d.ts.map +1 -0
  43. package/dist/features/magic-context/store-generation-rebase.d.ts.map +1 -1
  44. package/dist/features/magic-context/work-metrics-carry-storage.d.ts +10 -0
  45. package/dist/features/magic-context/work-metrics-carry-storage.d.ts.map +1 -0
  46. package/dist/{history-owner-36wp3mkb.js → history-owner-0z620wgz.js} +3 -2
  47. package/dist/hooks/magic-context/apply-operations.d.ts +20 -3
  48. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  49. package/dist/hooks/magic-context/auto-search-observation.d.ts +13 -0
  50. package/dist/hooks/magic-context/auto-search-observation.d.ts.map +1 -0
  51. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
  52. package/dist/hooks/magic-context/auto-search-worker-client.d.ts +10 -2
  53. package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
  54. package/dist/hooks/magic-context/compaction-marker-publication.d.ts.map +1 -1
  55. package/dist/hooks/magic-context/compartment-commit-hashes.d.ts +4 -0
  56. package/dist/hooks/magic-context/compartment-commit-hashes.d.ts.map +1 -0
  57. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  58. package/dist/hooks/magic-context/compartment-runner-validation.d.ts +1 -0
  59. package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
  60. package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
  61. package/dist/hooks/magic-context/final-wire-completeness.d.ts +15 -0
  62. package/dist/hooks/magic-context/final-wire-completeness.d.ts.map +1 -0
  63. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
  64. package/dist/hooks/magic-context/issue-423-fixture.d.ts +1 -1
  65. package/dist/hooks/magic-context/issue-423-fixture.d.ts.map +1 -1
  66. package/dist/hooks/magic-context/issue-424-fixture.d.ts +1 -1
  67. package/dist/hooks/magic-context/issue-424-fixture.d.ts.map +1 -1
  68. package/dist/hooks/magic-context/project-structural-sentinels.d.ts +25 -0
  69. package/dist/hooks/magic-context/project-structural-sentinels.d.ts.map +1 -0
  70. package/dist/hooks/magic-context/protected-tail-boundary.d.ts +8 -1
  71. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  72. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +1 -0
  73. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
  74. package/dist/hooks/magic-context/read-session-chunk.d.ts +11 -0
  75. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  76. package/dist/hooks/magic-context/read-session-formatting.d.ts +2 -0
  77. package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
  78. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +2 -0
  79. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  80. package/dist/hooks/magic-context/release-recovery-prefix.d.ts +9 -0
  81. package/dist/hooks/magic-context/release-recovery-prefix.d.ts.map +1 -0
  82. package/dist/hooks/magic-context/strip-structural-noise.d.ts +6 -3
  83. package/dist/hooks/magic-context/strip-structural-noise.d.ts.map +1 -1
  84. package/dist/hooks/magic-context/transform-context-state.d.ts +3 -0
  85. package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
  86. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +3 -0
  87. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  88. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  89. package/dist/{index-cpjk5jd2.js → index-1d042x6w.js} +16 -14
  90. package/dist/{index-2743x98y.js → index-21fgrfrf.js} +35 -142
  91. package/dist/index-2amn2s73.js +123 -0
  92. package/dist/{index-c7phnbvk.js → index-2p37txes.js} +1 -1
  93. package/dist/index-2qbtqg1w.js +529 -0
  94. package/dist/{index-9gpw8hrm.js → index-2rs7912w.js} +4 -4
  95. package/dist/{index-m1x9ghk5.js → index-4ks89h5a.js} +37 -7
  96. package/dist/{index-b88dwwrh.js → index-4xyjr62e.js} +1 -1
  97. package/dist/index-4y35msh5.js +531 -0
  98. package/dist/index-66a50f3e.js +777 -0
  99. package/dist/index-72czy45z.js +4557 -0
  100. package/dist/index-7v05d9b7.js +58 -0
  101. package/dist/{index-qgh1qwjj.js → index-850vthn3.js} +9 -3
  102. package/dist/{index-np3rgfw4.js → index-8jjjmhab.js} +15 -4
  103. package/dist/index-96ztjvkn.js +204 -0
  104. package/dist/{index-fm36bjv4.js → index-9fgmkfaf.js} +22 -277
  105. package/dist/{index-atekmqef.js → index-9tdvbdv1.js} +508 -5547
  106. package/dist/{index-xrnsygfq.js → index-9wnbnx8f.js} +1 -1
  107. package/dist/{index-waktfbjy.js → index-ae1ar4v1.js} +4 -4
  108. package/dist/{index-v15ne3a3.js → index-b1ydbp95.js} +2 -2
  109. package/dist/{index-nxrsns5x.js → index-c5dzns43.js} +75 -75
  110. package/dist/{index-v7287tzq.js → index-dcjkw41m.js} +19 -8
  111. package/dist/{index-hbx7m8he.js → index-dfdg2cgg.js} +338 -86
  112. package/dist/{index-spwjbkc7.js → index-dnqqqc5f.js} +1 -1
  113. package/dist/{index-04z754rd.js → index-dz48h1wx.js} +33 -5
  114. package/dist/{index-rrv26qjz.js → index-fw42ms3m.js} +1 -1
  115. package/dist/{index-t5pck3ss.js → index-fxbk7gk3.js} +1 -1
  116. package/dist/{index-wfybj1dw.js → index-g4t7850m.js} +2 -2
  117. package/dist/{index-97spytxq.js → index-gnmhbyyc.js} +583 -474
  118. package/dist/{index-4pnsgvfk.js → index-hacf2tyx.js} +1 -1
  119. package/dist/index-j105mf16.js +270 -0
  120. package/dist/{index-gkee6p4g.js → index-jggt5gf2.js} +3 -3
  121. package/dist/{index-s1n8dd2n.js → index-jkanybgq.js} +2 -2
  122. package/dist/{index-h7tgn49j.js → index-jrfre9ah.js} +5 -222
  123. package/dist/{index-kfyb3k6n.js → index-jz5bk7xd.js} +2 -2
  124. package/dist/{index-7kkphb6c.js → index-nj360hcs.js} +4 -4
  125. package/dist/{index-07vskjn8.js → index-pp8vdn01.js} +15 -13
  126. package/dist/index-prw8apnc.js +194 -0
  127. package/dist/{index-rverk2vz.js → index-r2epb000.js} +34 -4
  128. package/dist/{index-7g9dr8gy.js → index-tn9drm1a.js} +125 -143
  129. package/dist/{index-kq5w68dp.js → index-txs8tce6.js} +1 -1
  130. package/dist/{index-rfxzazzy.js → index-ty4vhe4n.js} +5 -5
  131. package/dist/{index-y1qwzvxn.js → index-vd2ywmfe.js} +2 -2
  132. package/dist/{index-0677w9sd.js → index-wcwhhtdh.js} +58 -23
  133. package/dist/index-wh9fxds5.js +265 -0
  134. package/dist/{index-51rdvtkz.js → index-xd2p95m7.js} +3 -3
  135. package/dist/{index-as2amvn3.js → index-xnm0wq1r.js} +6 -531
  136. package/dist/{index-ftr84kkv.js → index-ys7j6679.js} +7 -5
  137. package/dist/index-z4p0ry94.js +222 -0
  138. package/dist/index-z9zygwse.js +89 -0
  139. package/dist/index.js +86 -74
  140. package/dist/{logger-94kew5wm.js → logger-qwnbcfj9.js} +2 -1
  141. package/dist/{message-fts-rowid-map-va36knh4.js → message-fts-rowid-map-t6qsyg9s.js} +7 -5
  142. package/dist/{message-index-bounded-qh91fdr3.js → message-index-bounded-wfk6aqxk.js} +15 -13
  143. package/dist/{message-time-backfill-4qva0b4f.js → message-time-backfill-39bm498k.js} +3 -2
  144. package/dist/migration-worker.js +55 -48
  145. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  146. package/dist/{project-embedding-registry-6yex0r9f.js → project-embedding-registry-3yyegjma.js} +16 -13
  147. package/dist/raw-ordinal-warmup-worker.js +114 -113
  148. package/dist/{read-session-chunk-kaghtr75.js → read-session-chunk-26yrrhyz.js} +18 -12
  149. package/dist/{read-session-raw-b2sd67v4.js → read-session-raw-j7c9w57v.js} +5 -3
  150. package/dist/recomp-orchestrator-wk509qkp.js +69 -0
  151. package/dist/render-h1qarr8a.js +44 -0
  152. package/dist/{safe-notification-target-mkr9yzvr.js → safe-notification-target-wztd7bgk.js} +3 -2
  153. package/dist/search-5h9fydyq.js +54 -0
  154. package/dist/search-archive-q79hyqxs.js +29 -0
  155. package/dist/{send-session-notification-vz86nt79.js → send-session-notification-14p3yje4.js} +9 -7
  156. package/dist/shared/model-suggestion-retry.d.ts +7 -0
  157. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  158. package/dist/shared/prompt-async-transport.d.ts.map +1 -1
  159. package/dist/shared/reusable-worker-entry.d.ts +4 -0
  160. package/dist/shared/reusable-worker-entry.d.ts.map +1 -0
  161. package/dist/shared/reusable-worker.d.ts +6 -0
  162. package/dist/shared/reusable-worker.d.ts.map +1 -0
  163. package/dist/shared/reusable-worker.fixture.d.ts +2 -0
  164. package/dist/shared/reusable-worker.fixture.d.ts.map +1 -0
  165. package/dist/shared/worker-shutdown.d.ts +1 -1
  166. package/dist/shared/worker-shutdown.d.ts.map +1 -1
  167. package/dist/{storage-tags-6hvkk01c.js → storage-tags-vj0yj7ed.js} +5 -4
  168. package/dist/store-reader-yh19h38c.js +14 -0
  169. package/dist/store-s3eykdjt.js +21 -0
  170. package/dist/tools/ctx-expand/render.d.ts +5 -3
  171. package/dist/tools/ctx-expand/render.d.ts.map +1 -1
  172. package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
  173. package/dist/tools/ctx-expand/tools.d.ts +2 -0
  174. package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
  175. package/dist/tools/ctx-expand/v2-archive-reader.d.ts +33 -0
  176. package/dist/tools/ctx-expand/v2-archive-reader.d.ts.map +1 -0
  177. package/dist/{transform-postprocess-phase-ph38mhrs.js → transform-postprocess-phase-4gj0mtcg.js} +39 -32
  178. package/dist/v2/auto-search-worker.js +163 -155
  179. package/dist/v2/chunk-embedding-write-worker.js +71 -67
  180. package/dist/v2/compaction-marker-candidates-worker.js +24 -23
  181. package/dist/v2/{compaction-marker-candidates-m4vmye3w.js → compaction-marker-candidates-yeb2ky46.js} +6 -3
  182. package/dist/v2/{compartment-chunk-embedding-rc31e6md.js → compartment-chunk-embedding-qfk791bd.js} +11 -9
  183. package/dist/v2/{context-s60hcatx.js → context-bxr039be.js} +2678 -1246
  184. package/dist/v2/{derive-budgets-knf763tt.js → derive-budgets-sa0v7bz0.js} +4 -3
  185. package/dist/v2/embedding-backfill-00tw59rx.js +27 -0
  186. package/dist/v2/embedding-worker-process.js +2 -1
  187. package/dist/v2/embedding-worker.js +6 -5
  188. package/dist/v2/expand-attachments-h33jbgyz.js +21 -0
  189. package/dist/v2/fold/code-mode-catalog.d.ts +3 -0
  190. package/dist/v2/fold/code-mode-catalog.d.ts.map +1 -0
  191. package/dist/v2/fold/idle.d.ts +16 -0
  192. package/dist/v2/fold/idle.d.ts.map +1 -0
  193. package/dist/v2/fold/manual-baseline.d.ts +8 -0
  194. package/dist/v2/fold/manual-baseline.d.ts.map +1 -0
  195. package/dist/v2/fold/native-replay-v3.d.ts +75 -0
  196. package/dist/v2/fold/native-replay-v3.d.ts.map +1 -0
  197. package/dist/v2/fold/native-replay.d.ts +81 -8
  198. package/dist/v2/fold/native-replay.d.ts.map +1 -1
  199. package/dist/v2/fold/policy.d.ts +2 -1
  200. package/dist/v2/fold/policy.d.ts.map +1 -1
  201. package/dist/v2/fold/restore.d.ts.map +1 -1
  202. package/dist/v2/fold/summary.d.ts +4 -0
  203. package/dist/v2/fold/summary.d.ts.map +1 -0
  204. package/dist/v2/hidden-completion.d.ts.map +1 -1
  205. package/dist/v2/{history-owner-ad0crnrn.js → history-owner-fpka43cn.js} +3 -2
  206. package/dist/v2/hooks/channel2.d.ts +6 -0
  207. package/dist/v2/hooks/channel2.d.ts.map +1 -1
  208. package/dist/v2/hooks/context.d.ts.map +1 -1
  209. package/dist/v2/hooks/expand-attachments.d.ts +8 -0
  210. package/dist/v2/hooks/expand-attachments.d.ts.map +1 -0
  211. package/dist/v2/hooks/overflow-recovery.d.ts +45 -0
  212. package/dist/v2/hooks/overflow-recovery.d.ts.map +1 -0
  213. package/dist/v2/hooks/restore-rows.d.ts +12 -2
  214. package/dist/v2/hooks/restore-rows.d.ts.map +1 -1
  215. package/dist/v2/hooks/store.d.ts +7 -2
  216. package/dist/v2/hooks/store.d.ts.map +1 -1
  217. package/dist/v2/hooks/synthetic-admission.d.ts +7 -0
  218. package/dist/v2/hooks/synthetic-admission.d.ts.map +1 -0
  219. package/dist/v2/hooks/usage-persist.d.ts.map +1 -1
  220. package/dist/v2/{logger-p34mjtja.js → logger-4cj6d03m.js} +2 -1
  221. package/dist/v2/{message-fts-rowid-map-78awh03v.js → message-fts-rowid-map-z86avy0n.js} +8 -6
  222. package/dist/v2/{message-index-bounded-4htdr1j6.js → message-index-bounded-w14496s9.js} +16 -14
  223. package/dist/v2/{message-time-backfill-zvthw6xb.js → message-time-backfill-0c4h7sg6.js} +3 -2
  224. package/dist/v2/migration-worker.js +56 -49
  225. package/dist/v2/ordinal-range.fixture.d.ts +7 -0
  226. package/dist/v2/ordinal-range.fixture.d.ts.map +1 -0
  227. package/dist/v2/{project-embedding-registry-1x5qe2fy.js → project-embedding-registry-jqq2qeqb.js} +17 -14
  228. package/dist/v2/raw-ordinal-warmup-worker.js +114 -113
  229. package/dist/v2/{read-session-chunk-1fa9qzwb.js → read-session-chunk-tqnh1ret.js} +18 -12
  230. package/dist/v2/{read-session-raw-5x088amc.js → read-session-raw-qpp6x9kg.js} +6 -4
  231. package/dist/v2/recomp-orchestrator-9cjk6aej.js +68 -0
  232. package/dist/v2/render-5dz1knf2.js +43 -0
  233. package/dist/v2/{safe-notification-target-khnzg57c.js → safe-notification-target-gphhast7.js} +3 -2
  234. package/dist/v2/search-8yfet25y.js +52 -0
  235. package/dist/v2/search-archive-z6z9jqwf.js +28 -0
  236. package/dist/v2/{send-session-notification-x5nzy34v.js → send-session-notification-kxp47tsw.js} +9 -7
  237. package/dist/v2/{server-cpjk5jd2.js → server-1d042x6w.js} +16 -14
  238. package/dist/v2/server-2amn2s73.js +123 -0
  239. package/dist/v2/{server-6g98c227.js → server-3schkz95.js} +4 -4
  240. package/dist/v2/server-468mya5v.js +209 -0
  241. package/dist/v2/{server-z2wft9zv.js → server-5by3vdzs.js} +562 -5560
  242. package/dist/v2/{server-qjvk4a9t.js → server-69m30b21.js} +1 -1
  243. package/dist/v2/server-6emy0v9a.js +531 -0
  244. package/dist/v2/{server-vr4szghm.js → server-6vzh6wej.js} +3 -3
  245. package/dist/v2/{server-ajxhrgjv.js → server-7094pk3w.js} +80 -19
  246. package/dist/v2/{server-ab8017gw.js → server-7acq7815.js} +34 -141
  247. package/dist/v2/server-7v05d9b7.js +58 -0
  248. package/dist/v2/{server-24g8r2d0.js → server-7zacmty5.js} +75 -75
  249. package/dist/v2/{server-3mz2qh5a.js → server-969cdpmg.js} +1 -1
  250. package/dist/v2/server-96ztjvkn.js +204 -0
  251. package/dist/v2/{server-grakwy1v.js → server-a9w5f0yw.js} +37 -7
  252. package/dist/v2/{server-835q39kd.js → server-avdveykk.js} +3 -3
  253. package/dist/v2/{server-qc915kw2.js → server-bez34e60.js} +4 -4
  254. package/dist/v2/{server-h1byrhwx.js → server-cp1a03vc.js} +19 -8
  255. package/dist/v2/{server-bsgd4dk1.js → server-dcws5831.js} +2 -2
  256. package/dist/v2/{server-m1pfg2d4.js → server-dfq5vb8j.js} +4 -4
  257. package/dist/v2/server-e51xmr4d.js +194 -0
  258. package/dist/v2/server-ef1mskas.js +777 -0
  259. package/dist/v2/{server-1bw1wcbp.js → server-f0j864ma.js} +1 -1
  260. package/dist/v2/{server-jw5qe9y8.js → server-g3gqq4ac.js} +18 -217
  261. package/dist/v2/{server-2aasmpsp.js → server-gkse1wyz.js} +5 -5
  262. package/dist/v2/{server-6495nmn9.js → server-jb6tjyeb.js} +5 -222
  263. package/dist/v2/{server-qvy4qavp.js → server-jd7vzwn4.js} +125 -143
  264. package/dist/v2/{server-a7x00tw8.js → server-mfn1yf9d.js} +1 -1
  265. package/dist/v2/{server-awr8qa4c.js → server-nmyganc8.js} +2 -2
  266. package/dist/v2/{server-tkdabx8q.js → server-nq3cb7be.js} +5 -530
  267. package/dist/v2/server-qjyp27vf.js +270 -0
  268. package/dist/v2/{server-gyy4k6mf.js → server-qmmkhz2z.js} +1 -1
  269. package/dist/v2/{server-29qp8nz4.js → server-qxzbmtqt.js} +1 -1
  270. package/dist/v2/{server-806rzhs6.js → server-r4430x9m.js} +10 -4
  271. package/dist/v2/{server-53eh1r8r.js → server-sd8hvzte.js} +2 -2
  272. package/dist/v2/{server-k3t06fxr.js → server-sefxj8k1.js} +1 -1
  273. package/dist/v2/server-t8y64xj7.js +4513 -0
  274. package/dist/v2/{server-6vd2n183.js → server-tnzbk64q.js} +35 -5
  275. package/dist/v2/{server-v77xa5wj.js → server-tpt7bwq8.js} +1 -1
  276. package/dist/v2/{server-51779zs2.js → server-v0p37hm2.js} +4 -1
  277. package/dist/v2/{server-nxas8v1d.js → server-xfjjbrkt.js} +15 -4
  278. package/dist/v2/{server-cqjvxyrp.js → server-xy7w7hrd.js} +2 -2
  279. package/dist/v2/server-ypf1ap0v.js +529 -0
  280. package/dist/v2/server-z4p0ry94.js +222 -0
  281. package/dist/v2/server-z9zygwse.js +89 -0
  282. package/dist/v2/{server-ab1g0wn9.js → server-zzgtgqmd.js} +2 -2
  283. package/dist/v2/server.js +7 -6
  284. package/dist/v2/{storage-tags-18nbaanf.js → storage-tags-cw07ky67.js} +5 -4
  285. package/dist/v2/store-reader-cgx47zkp.js +14 -0
  286. package/dist/v2/store-reader.d.ts +9 -2
  287. package/dist/v2/store-reader.d.ts.map +1 -1
  288. package/dist/v2/store-z3qe67cg.js +21 -0
  289. package/dist/v2/v2-archive-reader-z7wr42ry.js +11 -0
  290. package/dist/v2/{wrapup-orchestrator-wxf7n5k6.js → wrapup-orchestrator-j1v62bkj.js} +50 -42
  291. package/dist/v2-archive-reader-028z6kck.js +11 -0
  292. package/dist/wrapup-orchestrator-xg9avt2p.js +56 -0
  293. package/package.json +1 -1
  294. package/src/shared/model-suggestion-retry.ts +1 -1
  295. package/src/shared/prompt-async-transport.test.ts +64 -3
  296. package/src/shared/prompt-async-transport.ts +61 -16
  297. package/src/shared/reusable-worker-entry.ts +58 -0
  298. package/src/shared/reusable-worker-reset.test.ts +108 -0
  299. package/src/shared/reusable-worker.fixture.ts +35 -0
  300. package/src/shared/reusable-worker.test.ts +253 -0
  301. package/src/shared/reusable-worker.ts +240 -0
  302. package/src/shared/sqlite-transaction-mode-guard.test.ts +2 -0
  303. package/src/shared/worker-shutdown.ts +21 -17
  304. package/dist/embedding-backfill-0jgtqxen.js +0 -25
  305. package/dist/recomp-orchestrator-0y983w7h.js +0 -62
  306. package/dist/search-archive-1kw2rp19.js +0 -26
  307. package/dist/search-p684j8ww.js +0 -50
  308. package/dist/v2/embedding-backfill-f43hd8y6.js +0 -24
  309. package/dist/v2/recomp-orchestrator-7q9nvxte.js +0 -61
  310. package/dist/v2/search-archive-xfp51s0g.js +0 -25
  311. package/dist/v2/search-wf8rqxhm.js +0 -48
  312. package/dist/wrapup-orchestrator-ys2nrkkb.js +0 -49
@@ -6,19 +6,19 @@ import {
6
6
  removeNestedBlocks,
7
7
  hasMeaningfulUserText2,
8
8
  extractTexts2
9
- } from "./index-b88dwwrh.js";
9
+ } from "./index-4xyjr62e.js";
10
10
  import {
11
11
  cleanUserText2
12
- } from "./index-7g9dr8gy.js";
12
+ } from "./index-tn9drm1a.js";
13
13
  import {
14
14
  recordMessageFtsRowid2,
15
15
  recordIndexedMessageTime2,
16
16
  messageFtsOrdinalRangeIsMapped2,
17
17
  deleteUnmappedMessageFtsRows2
18
- } from "./index-v15ne3a3.js";
18
+ } from "./index-b1ydbp95.js";
19
19
  import {
20
20
  logSlowWriteTransaction
21
- } from "./index-t5pck3ss.js";
21
+ } from "./index-fxbk7gk3.js";
22
22
 
23
23
  // src/features/magic-context/compression-depth-storage.ts
24
24
  var incrementDepthStatements = new WeakMap;
@@ -6,18 +6,23 @@ import {
6
6
  } from "./index-gzy5w8ya.js";
7
7
  import {
8
8
  runSessionWarmupWorker
9
- } from "./index-rverk2vz.js";
9
+ } from "./index-r2epb000.js";
10
10
  import {
11
11
  estimateTokens
12
- } from "./index-b88dwwrh.js";
12
+ } from "./index-4xyjr62e.js";
13
13
  import {
14
14
  openCodeDbExists,
15
15
  withReadOnlySessionDb
16
- } from "./index-y1qwzvxn.js";
16
+ } from "./index-vd2ywmfe.js";
17
17
  import {
18
18
  hasRawMessageProvider2,
19
+ rawMessageWorkerSource2,
20
+ rawMessageOffThreadRangeReader2,
19
21
  readRawSessionMessageIdOrdinalsForRange2
20
- } from "./index-7g9dr8gy.js";
22
+ } from "./index-tn9drm1a.js";
23
+ import {
24
+ readV2ArchiveOffThread2
25
+ } from "./index-prw8apnc.js";
21
26
 
22
27
  // src/tools/ctx-expand/search-archive.ts
23
28
  var archiveReadsOnThisThread = 0;
@@ -72,9 +77,34 @@ function renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnl
72
77
  }
73
78
  async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBudget, archiveOnly = false) {
74
79
  const path = getSqliteDatabasePath2(db);
75
- if (!path)
76
- return renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnly);
77
80
  const provider = hasRawMessageProvider2(sessionId);
81
+ const source = rawMessageWorkerSource2(sessionId);
82
+ const offThreadReader = rawMessageOffThreadRangeReader2(sessionId);
83
+ let rawIds;
84
+ if (!archiveOnly && !source && offThreadReader) {
85
+ try {
86
+ rawIds = await offThreadReader(start, end);
87
+ } catch (error) {
88
+ throw new Error(`Search archive worker unavailable: ${String(error)}`);
89
+ }
90
+ }
91
+ if (!path) {
92
+ return renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnly, rawIds ? () => rawIds : provider ? () => {
93
+ throw new Error("Search archive worker unavailable: private archive has no off-thread source");
94
+ } : undefined);
95
+ }
96
+ if (!archiveOnly && source) {
97
+ return readV2ArchiveOffThread2(path, source.path, sessionId, {
98
+ kind: "archive",
99
+ start,
100
+ end,
101
+ tokenBudget,
102
+ archiveOnly
103
+ });
104
+ }
105
+ if (!archiveOnly && provider && !rawIds) {
106
+ throw new Error("Search archive worker unavailable: raw-message provider has no off-thread source");
107
+ }
78
108
  const rawPath = !archiveOnly && !provider && openCodeDbExists() ? withReadOnlySessionDb(getSqliteDatabasePath2) : null;
79
109
  const result = await runSessionWarmupWorker({
80
110
  path,
@@ -85,7 +115,7 @@ async function renderSearchArchiveOffThread2(db, sessionId, start, end, tokenBud
85
115
  tokenBudget,
86
116
  archiveOnly,
87
117
  rawPath,
88
- rawIds: !archiveOnly && provider ? [...readRawSessionMessageIdOrdinalsForRange2(sessionId, start, end)] : undefined
118
+ rawIds: rawIds ? [...rawIds] : undefined
89
119
  }
90
120
  }, {});
91
121
  if ("searchArchive" in result)
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  log2
3
- } from "./index-h7tgn49j.js";
3
+ } from "./index-jrfre9ah.js";
4
4
 
5
5
  // src/hooks/magic-context/read-session-formatting.ts
6
6
  import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
@@ -0,0 +1,531 @@
1
+ import {
2
+ formatFailClosedBlockingSummary
3
+ } from "./index-wh9fxds5.js";
4
+ import {
5
+ RAW_MESSAGE_TYPES2
6
+ } from "./index-66a50f3e.js";
7
+ import {
8
+ markHostUnservedRow
9
+ } from "./index-z9zygwse.js";
10
+
11
+ // src/v2/fold/restore.ts
12
+ import { fileURLToPath } from "node:url";
13
+
14
+ // src/v2/hooks/storage-notice.ts
15
+ var STORAGE_NOTICE_PREFIX = "[Magic Context storage notice] ";
16
+ function formatStorageRefusalNotice(reason) {
17
+ return `${STORAGE_NOTICE_PREFIX}This turn was not sent to the model. ${formatFailClosedBlockingSummary(reason)}`;
18
+ }
19
+ function formatStorageRecoveryNotice(hiddenWorkRecovered) {
20
+ return hiddenWorkRecovered ? `${STORAGE_NOTICE_PREFIX}Magic Context storage is available again and turns are sent to the model. The historian and dreamer are running again. Restart OpenCode to enable Magic Context's tools.` : `${STORAGE_NOTICE_PREFIX}Magic Context storage is available again and turns are sent to the model. Restart OpenCode to enable Magic Context's tools, historian and dreamer.`;
21
+ }
22
+ function isStorageNoticeText(text) {
23
+ return typeof text === "string" && text.startsWith(STORAGE_NOTICE_PREFIX);
24
+ }
25
+ function hasStorageNoticeShape(message) {
26
+ if (message.role !== "user" || typeof message.id !== "string")
27
+ return false;
28
+ if (message.content.length !== 1)
29
+ return false;
30
+ const part = message.content[0];
31
+ return part?.type === "text" && isStorageNoticeText(part.text);
32
+ }
33
+ async function dropStorageNotices(messages, isAdmittedSynthetic) {
34
+ const drop = new Set;
35
+ for (const message of messages) {
36
+ if (!hasStorageNoticeShape(message))
37
+ continue;
38
+ if (await isAdmittedSynthetic(message.id))
39
+ drop.add(message);
40
+ }
41
+ if (drop.size === 0)
42
+ return 0;
43
+ const kept = messages.filter((message) => !drop.has(message));
44
+ messages.splice(0, messages.length, ...kept);
45
+ return drop.size;
46
+ }
47
+
48
+ // src/v2/fold/restore.ts
49
+ function unavailableAttachmentNote(name, mediaType) {
50
+ return `[Attachment ${name ? `"${name}" ` : ""}(${mediaType}) is not available in this restored history]`;
51
+ }
52
+ var imageMimes = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
53
+ function attachmentParts(files, rowID, media) {
54
+ const seen = new Map;
55
+ return files.flatMap((file) => {
56
+ if (imageMimes.has(file.mime) && file.source.type === "inline" && file.mention?.text) {
57
+ const key = JSON.stringify([
58
+ file.mime,
59
+ file.name ?? null,
60
+ file.description ?? null,
61
+ file.mention.text
62
+ ]);
63
+ const payloads = seen.get(key) ?? new Set;
64
+ if (payloads.has(file.data))
65
+ return [];
66
+ payloads.add(file.data);
67
+ seen.set(key, payloads);
68
+ }
69
+ const uri = file.source.type === "uri" ? file.source.uri : undefined;
70
+ const location = uri?.startsWith("file:") ? fileURLToPath(uri) : undefined;
71
+ if (file.mime === "text/plain" || file.mime === "application/x-directory") {
72
+ const directory = file.mime === "application/x-directory";
73
+ return [
74
+ {
75
+ type: "text",
76
+ text: `
77
+
78
+ ${[
79
+ directory ? `Attached directory: ${location ?? file.name ?? uri ?? "directory"}` : `Attached file: ${file.name ?? uri ?? "inline attachment"}`,
80
+ file.description === undefined ? undefined : `Description: ${file.description}`,
81
+ directory && !file.data.length ? undefined : "",
82
+ directory && !file.data.length ? undefined : Buffer.from(file.data, "base64").toString("utf8")
83
+ ].filter((line) => line !== undefined).join(`
84
+ `)}`,
85
+ metadata: {
86
+ attachment: {
87
+ source: file.source,
88
+ name: file.name,
89
+ description: file.description
90
+ }
91
+ }
92
+ }
93
+ ];
94
+ }
95
+ if (!imageMimes.has(file.mime) && file.mime !== "application/pdf")
96
+ return [];
97
+ const metadata = file.description === undefined ? undefined : { description: file.description };
98
+ const located = location ? [{ type: "text", text: `Attached file: ${location}` }] : [];
99
+ if (!media)
100
+ return [
101
+ ...located,
102
+ {
103
+ type: "media",
104
+ mediaType: file.mime,
105
+ data: file.data,
106
+ filename: file.name,
107
+ metadata
108
+ }
109
+ ];
110
+ const asset = media.asset(file.data, file.mime);
111
+ if (typeof asset === "string") {
112
+ media.unavailable({ rowID, name: file.name, mediaType: file.mime, reason: asset });
113
+ return [
114
+ ...located,
115
+ { type: "text", text: unavailableAttachmentNote(file.name, file.mime) }
116
+ ];
117
+ }
118
+ return [...located, { type: "media", media: asset, filename: file.name, metadata }];
119
+ });
120
+ }
121
+ function restoreRow(row, model, media) {
122
+ const data = row.data;
123
+ const make = (role, content, metadata = data.metadata) => ({
124
+ id: row.id,
125
+ role,
126
+ content,
127
+ ...metadata === undefined ? {} : { metadata }
128
+ });
129
+ if (row.type === "user") {
130
+ const skills = data.skills ?? [];
131
+ const content = [
132
+ ...skills.flatMap((skill) => skill.text === undefined ? [] : [{ type: "text", text: skill.text }]),
133
+ ...data.text ? [{ type: "text", text: data.text }] : [],
134
+ ...attachmentParts(data.files ?? [], row.id, media)
135
+ ];
136
+ return content.length ? [
137
+ make("user", content, {
138
+ ...data.metadata ?? {},
139
+ ...data.agents?.length ? { agents: data.agents } : {}
140
+ })
141
+ ] : [];
142
+ }
143
+ if (row.type === "system")
144
+ return [{ role: "system", content: [{ type: "text", text: data.text ?? "" }] }];
145
+ if (row.type === "synthetic" && isStorageNoticeText(data.text))
146
+ return [];
147
+ if (["synthetic", "skill"].includes(row.type))
148
+ return [make("user", [{ type: "text", text: data.text ?? "" }])];
149
+ if (row.type === "location-switched")
150
+ return [
151
+ make("user", [
152
+ {
153
+ type: "text",
154
+ text: `The working directory has been changed to ${data.location.directory}.`
155
+ }
156
+ ])
157
+ ];
158
+ if (row.type === "shell")
159
+ return data.metadata?.background === true ? [] : [
160
+ make("user", [
161
+ {
162
+ type: "text",
163
+ text: `The following shell command was executed by the user:
164
+
165
+ Command:
166
+ ${data.command}
167
+
168
+ Output:
169
+ ${data.output?.output ?? ""}`
170
+ }
171
+ ])
172
+ ];
173
+ if (row.type !== "assistant")
174
+ return [];
175
+ const previousModel = data.model;
176
+ const sameProvider = previousModel?.providerID === model.providerID;
177
+ const sameModel = sameProvider && previousModel?.id === model.id;
178
+ const reuse = sameModel && data.error === undefined;
179
+ const metadata = (state) => state === undefined ? undefined : { [model.providerID]: state };
180
+ const reasoningInterrupted = data.content?.some((part) => part.type === "reasoning" && part.time !== undefined && part.time.completed === undefined);
181
+ const content = [];
182
+ const results = [];
183
+ for (const part of data.content ?? []) {
184
+ let native = "native" in part ? part.native : part.type === "tool" ? part.providerState : part.state;
185
+ if (part.type === "tool" && part.providerResultState !== null && typeof part.providerResultState === "object" && !Array.isArray(part.providerResultState))
186
+ native = {
187
+ ...native !== null && typeof native === "object" && !Array.isArray(native) ? native : {},
188
+ ...part.providerResultState
189
+ };
190
+ if (part.type === "text") {
191
+ if (part.text !== "")
192
+ content.push({
193
+ type: "text",
194
+ text: part.text,
195
+ providerMetadata: reuse ? metadata(native) : undefined
196
+ });
197
+ continue;
198
+ }
199
+ if (part.type === "reasoning") {
200
+ if (part.text !== "" || reuse && !reasoningInterrupted && native !== undefined)
201
+ content.push({
202
+ type: data.error === undefined && !reasoningInterrupted ? "reasoning" : "text",
203
+ text: part.text,
204
+ providerMetadata: reuse && !reasoningInterrupted ? metadata(native) : undefined
205
+ });
206
+ continue;
207
+ }
208
+ const state = part.state;
209
+ const completed = state.status === "completed" || state.status === "error";
210
+ const toolReuse = reuse || sameModel && part.executed === true && completed;
211
+ let input = state.input;
212
+ if (state.status === "streaming" && typeof input === "string") {
213
+ try {
214
+ input = JSON.parse(input);
215
+ } catch {}
216
+ }
217
+ content.push({
218
+ type: "tool-call",
219
+ id: part.id,
220
+ name: part.name,
221
+ input,
222
+ providerExecuted: part.executed,
223
+ providerMetadata: toolReuse ? metadata(native) : undefined
224
+ });
225
+ if (!completed)
226
+ continue;
227
+ const toolContent = state.content ?? [];
228
+ const single = toolContent.length === 1 ? toolContent[0] : undefined;
229
+ const result = {
230
+ type: "tool-result",
231
+ id: part.id,
232
+ name: part.name,
233
+ providerExecuted: part.executed,
234
+ providerMetadata: (part.executed === true ? sameProvider : reuse) ? metadata(native) : undefined,
235
+ result: state.status === "error" ? { type: "error", value: { error: state.error, content: toolContent } } : single?.type === "text" ? { type: "text", value: single.text } : { type: "content", value: toolContent }
236
+ };
237
+ if (part.executed === true)
238
+ content.push(result);
239
+ else
240
+ results.push({ role: "tool", content: [result] });
241
+ }
242
+ return [...content.length ? [make("assistant", content)] : [], ...results];
243
+ }
244
+
245
+ // src/v2/tool-result.ts
246
+ function isToolError(part) {
247
+ const result = part.result;
248
+ return part.resultType === "error" || result?.type === "error" || result !== null && typeof result === "object" && "error" in result;
249
+ }
250
+ function toolErrorText(result) {
251
+ const value = result.value === undefined ? result : result.value;
252
+ return typeof value === "string" ? value : JSON.stringify(value);
253
+ }
254
+ function toolStateContent(state) {
255
+ if (typeof state.output === "string")
256
+ return state.output;
257
+ if (state.status === "error")
258
+ return toolErrorText({ error: state.error, content: state.content ?? [] });
259
+ if (typeof state.content === "string")
260
+ return state.content;
261
+ if (!Array.isArray(state.content))
262
+ return "";
263
+ return state.content.map((part) => {
264
+ if (typeof part === "string")
265
+ return part;
266
+ if (!part || typeof part !== "object")
267
+ return "";
268
+ const value = part;
269
+ if (typeof value.text === "string")
270
+ return value.text;
271
+ if (typeof value.value === "string")
272
+ return value.value;
273
+ return "";
274
+ }).filter(Boolean).join(`
275
+ `);
276
+ }
277
+
278
+ // src/v2/hooks/store.ts
279
+ var rawMessageTypes = new Set(RAW_MESSAGE_TYPES2);
280
+ var isRawRow = (row) => rawMessageTypes.has(row.type);
281
+ var NO_MODEL = { providerID: "", id: "" };
282
+ function hostServesRowById(row) {
283
+ return isRawRow(row) && restoreRow(row, NO_MODEL).some((message) => message.id === row.id);
284
+ }
285
+ function projectRawMessages(rows, ordinalFor) {
286
+ return rows.filter(isRawRow).map((row, index) => {
287
+ const message = {
288
+ id: row.id,
289
+ ordinal: ordinalFor(row, index),
290
+ role: row.type === "assistant" ? "assistant" : row.type === "system" ? "system" : "user",
291
+ createdAt: row.time_created ?? row.data.time?.created,
292
+ parts: row.type === "assistant" ? (row.data.content ?? []).map((part) => {
293
+ if (part.type !== "tool")
294
+ return { ...part };
295
+ const state = part.state;
296
+ const content = state.content;
297
+ return {
298
+ type: "tool",
299
+ tool: part.name,
300
+ callID: part.id,
301
+ state: {
302
+ ...state,
303
+ output: state.status === "error" ? toolStateContent(state) : content?.filter((p) => p.type === "text").map((p) => p.text).join(`
304
+ `) ?? ""
305
+ }
306
+ };
307
+ }) : [{ type: "text", text: row.data.text ?? "" }]
308
+ };
309
+ Object.defineProperty(message, "storeType", { value: row.type, enumerable: false });
310
+ if (!hostServesRowById(row))
311
+ markHostUnservedRow(message);
312
+ return message;
313
+ });
314
+ }
315
+ function rawMessages(rows, history = rows) {
316
+ const ordinals = new Map(history.filter(isRawRow).map((row, index) => [row.id, index + 1]));
317
+ return projectRawMessages(rows, (row) => {
318
+ return ordinals.get(row.id) ?? 0;
319
+ });
320
+ }
321
+ function rawMessagePage(rows, afterOrdinal) {
322
+ return projectRawMessages(rows, (_row, index) => afterOrdinal + index + 1);
323
+ }
324
+ var SERVED_BOUNDARY_PAGE = 50;
325
+ function servedBoundaryRow2(reader, sessionID, messageID) {
326
+ const boundary = reader.messageById(sessionID, messageID);
327
+ if (!boundary)
328
+ return null;
329
+ if (hostServesRowById(boundary))
330
+ return boundary;
331
+ let through = boundary.seq - 1;
332
+ for (;; ) {
333
+ const rows = reader.rawRowsThrough(sessionID, through, SERVED_BOUNDARY_PAGE);
334
+ const served = rows.find(hostServesRowById);
335
+ if (served)
336
+ return served;
337
+ const oldest = rows.at(-1);
338
+ if (rows.length < SERVED_BOUNDARY_PAGE || !oldest)
339
+ return null;
340
+ through = oldest.seq - 1;
341
+ }
342
+ }
343
+ function resolveV2BoundaryUserMessage2(reader, sessionID, endMessageID) {
344
+ const end = reader.messageById(sessionID, endMessageID);
345
+ if (!end || !isRawRow(end))
346
+ return null;
347
+ let through = end.seq;
348
+ for (;; ) {
349
+ const rows = reader.rawRowsThrough(sessionID, through, SERVED_BOUNDARY_PAGE);
350
+ const user = rows.find((row) => row.type !== "assistant");
351
+ if (user)
352
+ return rawMessagePage([user], 0)[0] ?? null;
353
+ const oldest = rows.at(-1);
354
+ if (rows.length < SERVED_BOUNDARY_PAGE || !oldest)
355
+ return null;
356
+ through = oldest.seq - 1;
357
+ }
358
+ }
359
+ function readAllV2RawMessagesForConversion2(openReader, sessionID) {
360
+ const reader = openReader();
361
+ try {
362
+ return rawMessages(reader.history(sessionID));
363
+ } finally {
364
+ reader.close();
365
+ }
366
+ }
367
+ var CONVERSION_PAGE_ROWS = 1000;
368
+ function* readV2RawMessagePagesForConversion2(openReader, sessionID, pageRows = CONVERSION_PAGE_ROWS) {
369
+ const reader = openReader();
370
+ try {
371
+ let after = -1;
372
+ let ordinal = 0;
373
+ for (;; ) {
374
+ const page = reader.page(sessionID, { after, limit: pageRows });
375
+ const messages = rawMessagePage(page.rows, ordinal);
376
+ ordinal += messages.length;
377
+ if (messages.length > 0)
378
+ yield messages;
379
+ if (page.rows.length < pageRows || page.cursor === undefined)
380
+ return;
381
+ after = page.cursor;
382
+ }
383
+ } finally {
384
+ reader.close();
385
+ }
386
+ }
387
+ function createV2RawMessageReader2(openReader, storePath, releaseReader = (reader) => reader.close()) {
388
+ const servedBoundaryCache = new Map;
389
+ return {
390
+ storePath,
391
+ getRevision: (sessionID) => {
392
+ const reader = openReader();
393
+ try {
394
+ return reader.latestSequence(sessionID);
395
+ } finally {
396
+ releaseReader(reader);
397
+ }
398
+ },
399
+ getCountAfterRevision: (sessionID, after, through) => {
400
+ const reader = openReader();
401
+ try {
402
+ return reader.messageCountAfterSequence(sessionID, after, through);
403
+ } finally {
404
+ releaseReader(reader);
405
+ }
406
+ },
407
+ readPage: (sessionID, afterOrdinal, limit, finalWatermark, after) => {
408
+ const reader = openReader();
409
+ try {
410
+ return rawMessagePage(reader.messagePage(sessionID, afterOrdinal, limit, finalWatermark, after), afterOrdinal);
411
+ } finally {
412
+ releaseReader(reader);
413
+ }
414
+ },
415
+ findById: (sessionID, messageID) => {
416
+ const reader = openReader();
417
+ try {
418
+ const ordinal = reader.messageOrdinalById(sessionID, messageID);
419
+ const row = reader.messageById(sessionID, messageID);
420
+ if (ordinal === null || row === null)
421
+ return null;
422
+ return rawMessagePage([row], ordinal - 1)[0] ?? null;
423
+ } finally {
424
+ releaseReader(reader);
425
+ }
426
+ },
427
+ findPartsById: (sessionID, messageID) => {
428
+ const reader = openReader();
429
+ try {
430
+ const row = reader.messageById(sessionID, messageID);
431
+ return row ? rawMessagePage([row], 0)[0] ?? null : null;
432
+ } finally {
433
+ releaseReader(reader);
434
+ }
435
+ },
436
+ hasById: (sessionID, messageID) => {
437
+ const reader = openReader();
438
+ try {
439
+ return reader.messageExistsById(sessionID, messageID);
440
+ } finally {
441
+ releaseReader(reader);
442
+ }
443
+ },
444
+ ordinalOf: (sessionID, messageID) => {
445
+ const reader = openReader();
446
+ try {
447
+ return reader.messageOrdinalById(sessionID, messageID);
448
+ } finally {
449
+ releaseReader(reader);
450
+ }
451
+ },
452
+ orderOf: (sessionID, messageID) => {
453
+ const reader = openReader();
454
+ try {
455
+ return reader.sequenceForId(sessionID, messageID) ?? null;
456
+ } finally {
457
+ releaseReader(reader);
458
+ }
459
+ },
460
+ ordinalMapForRange: (sessionID, fromOrdinal, toOrdinal) => {
461
+ const reader = openReader();
462
+ try {
463
+ return reader.messageIdOrdinals(sessionID, fromOrdinal, toOrdinal);
464
+ } finally {
465
+ releaseReader(reader);
466
+ }
467
+ },
468
+ readOrdinalPage: (sessionID, after, limit) => {
469
+ const reader = openReader();
470
+ try {
471
+ return reader.messageOrdinalPage(sessionID, after, limit);
472
+ } finally {
473
+ releaseReader(reader);
474
+ }
475
+ },
476
+ getCount: (sessionID) => {
477
+ const reader = openReader();
478
+ try {
479
+ return reader.messageCount(sessionID);
480
+ } finally {
481
+ releaseReader(reader);
482
+ }
483
+ },
484
+ getStoredCount: (sessionID) => {
485
+ const reader = openReader();
486
+ try {
487
+ return reader.storedMessageCount(sessionID);
488
+ } finally {
489
+ releaseReader(reader);
490
+ }
491
+ },
492
+ servedBoundaryIdOf: (sessionID, messageID) => {
493
+ const key = `${sessionID}\x00${messageID}`;
494
+ if (servedBoundaryCache.has(key))
495
+ return servedBoundaryCache.get(key) ?? null;
496
+ const reader = openReader();
497
+ try {
498
+ const served = servedBoundaryRow2(reader, sessionID, messageID)?.id ?? null;
499
+ if (servedBoundaryCache.size >= 1000)
500
+ servedBoundaryCache.clear();
501
+ if (served !== null)
502
+ servedBoundaryCache.set(key, served);
503
+ return served;
504
+ } finally {
505
+ releaseReader(reader);
506
+ }
507
+ }
508
+ };
509
+ }
510
+ function createV2RawMessageProvider2(reader, sessionID) {
511
+ return {
512
+ ...reader.storePath ? { workerSource: { kind: "opencode2", path: reader.storePath } } : {},
513
+ readMessagePage: (afterOrdinal, limit, finalWatermark, after) => reader.readPage(sessionID, afterOrdinal, limit, finalWatermark, after),
514
+ readMessageById: (messageID) => reader.findById(sessionID, messageID),
515
+ readMessagePartsById: (messageID) => reader.findPartsById(sessionID, messageID),
516
+ hasMessageById: (messageID) => reader.hasById(sessionID, messageID),
517
+ readMessageOrdinalById: (messageID) => reader.ordinalOf(sessionID, messageID),
518
+ ...reader.orderOf ? {
519
+ readMessageOrderById: (messageID) => reader.orderOf?.(sessionID, messageID) ?? null
520
+ } : {},
521
+ readMessageIdOrdinalsForRange: (fromOrdinal, toOrdinal) => reader.ordinalMapForRange(sessionID, fromOrdinal, toOrdinal),
522
+ readMessageOrdinalPage: (after, limit) => reader.readOrdinalPage(sessionID, after, limit),
523
+ getMessageCount: () => reader.getCount(sessionID),
524
+ getStoredMessageCount: () => reader.getStoredCount(sessionID),
525
+ ...reader.servedBoundaryIdOf ? {
526
+ readServedBoundaryId: (messageID) => reader.servedBoundaryIdOf?.(sessionID, messageID) ?? null
527
+ } : {}
528
+ };
529
+ }
530
+
531
+ export { STORAGE_NOTICE_PREFIX, formatStorageRefusalNotice, formatStorageRecoveryNotice, hasStorageNoticeShape, dropStorageNotices, restoreRow, isToolError, toolErrorText, toolStateContent, servedBoundaryRow2, resolveV2BoundaryUserMessage2, readAllV2RawMessagesForConversion2, readV2RawMessagePagesForConversion2, createV2RawMessageReader2, createV2RawMessageProvider2 };