@cortexkit/opencode-magic-context 0.49.19 → 0.49.21

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 (323) hide show
  1. package/dist/auto-search-worker.js +48 -9
  2. package/dist/chunk-embedding-write-worker.js +30 -23
  3. package/dist/{compaction-marker-candidates-n4krhat4.js → compaction-marker-candidates-31h86ph0.js} +3 -3
  4. package/dist/compaction-marker-candidates-worker.js +2 -2
  5. package/dist/compartment-chunk-embedding-he60aaa2.js +65 -0
  6. package/dist/config/project-security.d.ts.map +1 -1
  7. package/dist/config/schema/magic-context.d.ts +43 -9
  8. package/dist/config/schema/magic-context.d.ts.map +1 -1
  9. package/dist/{conflict-warning-hook-4pmz879v.js → conflict-warning-hook-2r32hyx6.js} +9 -8
  10. package/dist/{context-j31m2dv7.js → context-j7hp43a0.js} +576 -185
  11. package/dist/{derive-budgets-zn7yzd2d.js → derive-budgets-pqybnx09.js} +2 -2
  12. package/dist/embedding-backfill-dtke6tck.js +25 -0
  13. package/dist/embedding-worker-process.js +2 -2
  14. package/dist/embedding-worker.js +6 -6
  15. package/dist/features/magic-context/chunk-embedding-writer.d.ts.map +1 -1
  16. package/dist/features/magic-context/compartment-chunk-embedding.d.ts +44 -1
  17. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  18. package/dist/features/magic-context/dreamer/docs-proposals.d.ts +1 -0
  19. package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
  20. package/dist/features/magic-context/dreamer/hidden-single-shot.d.ts.map +1 -1
  21. package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -1
  22. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  23. package/dist/features/magic-context/dreamer/task-scheduler.d.ts +2 -0
  24. package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
  25. package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
  26. package/dist/features/magic-context/memory/embedding-local.d.ts +1 -0
  27. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  28. package/dist/features/magic-context/memory/embedding-synapse.d.ts.map +1 -1
  29. package/dist/features/magic-context/memory/embedding-worker-client.d.ts +7 -1
  30. package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
  31. package/dist/features/magic-context/memory/local-embedding-pooling.d.ts +22 -0
  32. package/dist/features/magic-context/memory/local-embedding-pooling.d.ts.map +1 -0
  33. package/dist/features/magic-context/message-index-async.d.ts +7 -2
  34. package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
  35. package/dist/features/magic-context/message-index.d.ts +2 -0
  36. package/dist/features/magic-context/message-index.d.ts.map +1 -1
  37. package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
  38. package/dist/features/magic-context/project-embedding-registry.d.ts +2 -0
  39. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  40. package/dist/features/magic-context/search-rerank.d.ts +9 -2
  41. package/dist/features/magic-context/search-rerank.d.ts.map +1 -1
  42. package/dist/features/magic-context/search.d.ts +29 -0
  43. package/dist/features/magic-context/search.d.ts.map +1 -1
  44. package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -1
  45. package/dist/features/magic-context/storage-db.d.ts +2 -0
  46. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  47. package/dist/features/magic-context/storage-meta-persisted.d.ts +2 -0
  48. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  49. package/dist/features/magic-context/subagent-token-capture.d.ts +20 -0
  50. package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -1
  51. package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
  52. package/dist/{history-owner-xp3pngv7.js → history-owner-36wp3mkb.js} +2 -2
  53. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  54. package/dist/hooks/magic-context/auto-embed-session.d.ts.map +1 -1
  55. package/dist/hooks/magic-context/auto-search-hint.d.ts +7 -1
  56. package/dist/hooks/magic-context/auto-search-hint.d.ts.map +1 -1
  57. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
  58. package/dist/hooks/magic-context/auto-search-worker-client.d.ts +33 -6
  59. package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
  60. package/dist/hooks/magic-context/cache-busting-signals.d.ts +6 -2
  61. package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
  62. package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
  63. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  64. package/dist/hooks/magic-context/compartment-runner-types.d.ts +5 -0
  65. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  66. package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
  67. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  68. package/dist/hooks/magic-context/diagnostic-log-state.d.ts +4 -0
  69. package/dist/hooks/magic-context/diagnostic-log-state.d.ts.map +1 -0
  70. package/dist/hooks/magic-context/execute-reclaim.d.ts +35 -0
  71. package/dist/hooks/magic-context/execute-reclaim.d.ts.map +1 -0
  72. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  73. package/dist/hooks/magic-context/hook.d.ts +1 -3
  74. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  75. package/dist/hooks/magic-context/latest-assistant-turn.d.ts +8 -0
  76. package/dist/hooks/magic-context/latest-assistant-turn.d.ts.map +1 -1
  77. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +5 -0
  78. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
  79. package/dist/hooks/magic-context/nudge-evaluation-log.d.ts +3 -0
  80. package/dist/hooks/magic-context/nudge-evaluation-log.d.ts.map +1 -0
  81. package/dist/hooks/magic-context/pending-drop-eligibility.d.ts.map +1 -1
  82. package/dist/hooks/magic-context/protected-tail-boundary.d.ts +4 -0
  83. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  84. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
  85. package/dist/hooks/magic-context/served-shape-repair.d.ts +19 -0
  86. package/dist/hooks/magic-context/served-shape-repair.d.ts.map +1 -0
  87. package/dist/hooks/magic-context/strip-content.d.ts +4 -2
  88. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  89. package/dist/hooks/magic-context/system-date-refresh.d.ts +5 -5
  90. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  91. package/dist/hooks/magic-context/system-prompt-sticky-date.d.ts +10 -0
  92. package/dist/hooks/magic-context/system-prompt-sticky-date.d.ts.map +1 -0
  93. package/dist/hooks/magic-context/tag-content-primitives.d.ts +1 -1
  94. package/dist/hooks/magic-context/tag-content-primitives.d.ts.map +1 -1
  95. package/dist/hooks/magic-context/tag-messages.d.ts +4 -1
  96. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  97. package/dist/hooks/magic-context/text-complete.d.ts +1 -1
  98. package/dist/hooks/magic-context/text-complete.d.ts.map +1 -1
  99. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  100. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +21 -6
  101. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  102. package/dist/hooks/magic-context/transform.d.ts +2 -2
  103. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  104. package/dist/{index-3esx8tkf.js → index-11gzxvf4.js} +394 -125
  105. package/dist/{index-jn12fvvh.js → index-1gtfne2c.js} +3 -3
  106. package/dist/{index-jhghdnsm.js → index-1kbznkft.js} +521 -214
  107. package/dist/{index-3h4dp9wb.js → index-3svaejkh.js} +5 -5
  108. package/dist/{index-kee4kn5j.js → index-4pnsgvfk.js} +1 -1
  109. package/dist/{index-bjcnntmz.js → index-51rdvtkz.js} +501 -20
  110. package/dist/{v2/server-8cd2j99z.js → index-5kym00ag.js} +32 -13
  111. package/dist/{index-s74zqahq.js → index-66eby7hx.js} +4 -4
  112. package/dist/{index-63k48rv9.js → index-9q1g3c5q.js} +5 -5
  113. package/dist/{index-jrr131e0.js → index-a9zvn5fe.js} +29 -15
  114. package/dist/{index-c5pytzne.js → index-b88dwwrh.js} +1 -1
  115. package/dist/{index-nj7yykkx.js → index-c7phnbvk.js} +1 -1
  116. package/dist/index-cpjk5jd2.js +82 -0
  117. package/dist/{index-c1p88z1y.js → index-ffzhwfzy.js} +4 -4
  118. package/dist/{v2/server-beht37jy.js → index-gzy5w8ya.js} +194 -5
  119. package/dist/{index-j75v2476.js → index-h7tgn49j.js} +12 -15
  120. package/dist/{index-edmpdxcw.js → index-j32jj2t8.js} +5 -5
  121. package/dist/{index-ke416mdc.js → index-j76ah6d7.js} +2 -2
  122. package/dist/{index-s734jcsr.js → index-jfem3dgz.js} +9 -3
  123. package/dist/{index-n37sebck.js → index-jjvbk92s.js} +1 -1
  124. package/dist/{index-4911rn0b.js → index-jmq8kfe7.js} +6 -6
  125. package/dist/{index-rr2bb45z.js → index-kfyb3k6n.js} +2 -2
  126. package/dist/{index-2vxtcb95.js → index-kq5w68dp.js} +2 -2
  127. package/dist/{index-kq82mtg0.js → index-ksq50rg0.js} +3 -3
  128. package/dist/{index-b5vqckbw.js → index-m32esgmj.js} +314 -127
  129. package/dist/{index-9zcsy3hh.js → index-mnhcdfxg.js} +161 -13
  130. package/dist/{index-se4m2g6w.js → index-mnnkgq0q.js} +111 -19
  131. package/dist/{index-p5y3k4g7.js → index-nda0zgna.js} +2 -1
  132. package/dist/{index-wgypt3cs.js → index-nxrsns5x.js} +2466 -1290
  133. package/dist/{index-4s3t0nd0.js → index-qgh1qwjj.js} +2 -2
  134. package/dist/{index-y9f76s3f.js → index-rrv26qjz.js} +1 -1
  135. package/dist/{index-24fezq97.js → index-rxqr723x.js} +5 -5
  136. package/dist/{index-v10f1rjv.js → index-spwjbkc7.js} +1 -1
  137. package/dist/{index-dxmq29t1.js → index-syaazvy2.js} +182 -47
  138. package/dist/{index-k29z4aqh.js → index-t5pck3ss.js} +1 -1
  139. package/dist/{index-6x57ar45.js → index-wfybj1dw.js} +4 -6
  140. package/dist/{index-cf74k5ak.js → index-whcgcfrv.js} +9 -6
  141. package/dist/{index-a6mc0v4d.js → index-x6cbrv9h.js} +3 -3
  142. package/dist/{index-bp5083x2.js → index-x9k3mqrf.js} +1 -1
  143. package/dist/{index-rpxdjkm0.js → index-y76rhsnr.js} +319 -61
  144. package/dist/{index-ze7mvk54.js → index-zy67whjr.js} +95 -59
  145. package/dist/index.js +58 -54
  146. package/dist/{logger-jm3sqqzr.js → logger-94kew5wm.js} +1 -1
  147. package/dist/{message-fts-rowid-map-17s0dfn4.js → message-fts-rowid-map-e79b7b6x.js} +6 -5
  148. package/dist/{message-index-gtpqnj8w.js → message-index-4q8ek2fc.js} +17 -16
  149. package/dist/{message-index-bounded-zyc8h32y.js → message-index-bounded-rydsg9r5.js} +17 -16
  150. package/dist/{message-time-backfill-73mmm76q.js → message-time-backfill-4qva0b4f.js} +3 -3
  151. package/dist/migration-worker.js +13 -12
  152. package/dist/{model-resolution-nx97z3x7.js → model-resolution-280gmqvd.js} +1 -1
  153. package/dist/plugin/embedding-bootstrap.d.ts +4 -1
  154. package/dist/plugin/embedding-bootstrap.d.ts.map +1 -1
  155. package/dist/plugin/hooks/create-session-hooks.d.ts +1 -0
  156. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  157. package/dist/plugin/rpc-handlers.d.ts +8 -0
  158. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  159. package/dist/plugin/subagent-tool-policy.d.ts +9 -0
  160. package/dist/plugin/subagent-tool-policy.d.ts.map +1 -1
  161. package/dist/plugin/tool-registry.d.ts.map +1 -1
  162. package/dist/{project-embedding-registry-z74mhqkf.js → project-embedding-registry-hn529988.js} +16 -13
  163. package/dist/raw-ordinal-warmup-worker.js +136 -101
  164. package/dist/{read-session-chunk-jjb48bt9.js → read-session-chunk-t039f0m5.js} +12 -11
  165. package/dist/{read-session-raw-rsc8c7qy.js → read-session-raw-aw6jgvwg.js} +4 -3
  166. package/dist/recomp-orchestrator-hbm53jj5.js +62 -0
  167. package/dist/{safe-notification-target-1szv1k5k.js → safe-notification-target-mkr9yzvr.js} +2 -2
  168. package/dist/search-archive-weh164mh.js +26 -0
  169. package/dist/search-hea079d7.js +50 -0
  170. package/dist/{send-session-notification-6ve0e8p4.js → send-session-notification-gqzkz7da.js} +7 -6
  171. package/dist/shared/logger.d.ts.map +1 -1
  172. package/dist/shared/model-resolution.d.ts +2 -0
  173. package/dist/shared/model-resolution.d.ts.map +1 -1
  174. package/dist/shared/prompt-async-transport.d.ts +3 -0
  175. package/dist/shared/prompt-async-transport.d.ts.map +1 -1
  176. package/dist/shared/rpc-types.d.ts +7 -0
  177. package/dist/shared/rpc-types.d.ts.map +1 -1
  178. package/dist/shared/sqlite.d.ts +6 -1
  179. package/dist/shared/sqlite.d.ts.map +1 -1
  180. package/dist/shared/subagent-runner.d.ts +2 -0
  181. package/dist/shared/subagent-runner.d.ts.map +1 -1
  182. package/dist/shared/tag-transcript.d.ts +2 -0
  183. package/dist/shared/tag-transcript.d.ts.map +1 -1
  184. package/dist/shared/worker-shutdown.d.ts +68 -0
  185. package/dist/shared/worker-shutdown.d.ts.map +1 -0
  186. package/dist/shared/worker-shutdown.fixture.d.ts +2 -0
  187. package/dist/shared/worker-shutdown.fixture.d.ts.map +1 -0
  188. package/dist/{sqlite-zf72c52d.js → sqlite-zdgm52sv.js} +5 -1
  189. package/dist/{storage-memory-y3qmy00r.js → storage-memory-e6a7mb0k.js} +2 -2
  190. package/dist/{storage-tags-r7k9tjcv.js → storage-tags-a77q4v77.js} +5 -5
  191. package/dist/{task-config-x3qmayd2.js → task-config-t6bpyka7.js} +2 -2
  192. package/dist/tools/ctx-search/tools.d.ts.map +1 -1
  193. package/dist/tools/ctx-search/types.d.ts +1 -0
  194. package/dist/tools/ctx-search/types.d.ts.map +1 -1
  195. package/dist/{transform-postprocess-phase-jj99r7z2.js → transform-postprocess-phase-0b04tm1p.js} +35 -32
  196. package/dist/v2/auto-search-worker.js +48 -9
  197. package/dist/v2/chunk-embedding-write-worker.js +30 -23
  198. package/dist/v2/{compaction-marker-candidates-ebx3388k.js → compaction-marker-candidates-m4vmye3w.js} +3 -3
  199. package/dist/v2/compaction-marker-candidates-worker.js +2 -2
  200. package/dist/v2/compartment-chunk-embedding-8jjmcgeg.js +64 -0
  201. package/dist/v2/{context-y5yamxak.js → context-ea3x7smm.js} +1797 -810
  202. package/dist/v2/{derive-budgets-2zh4gm2c.js → derive-budgets-knf763tt.js} +3 -3
  203. package/dist/v2/embedding-backfill-5e74ae0m.js +24 -0
  204. package/dist/v2/embedding-worker-process.js +2 -2
  205. package/dist/v2/embedding-worker.js +6 -6
  206. package/dist/v2/hidden-child-record.d.ts +2 -0
  207. package/dist/v2/hidden-child-record.d.ts.map +1 -1
  208. package/dist/v2/hidden-completion.d.ts +2 -0
  209. package/dist/v2/hidden-completion.d.ts.map +1 -1
  210. package/dist/v2/hidden-model-activity.d.ts +7 -0
  211. package/dist/v2/hidden-model-activity.d.ts.map +1 -0
  212. package/dist/v2/{history-owner-42e16w0n.js → history-owner-ad0crnrn.js} +2 -2
  213. package/dist/v2/hooks/context.d.ts.map +1 -1
  214. package/dist/v2/hooks/copied-tag-notation.d.ts +1 -1
  215. package/dist/v2/hooks/copied-tag-notation.d.ts.map +1 -1
  216. package/dist/v2/hooks/dream-timer.d.ts +2 -0
  217. package/dist/v2/hooks/dream-timer.d.ts.map +1 -1
  218. package/dist/v2/hooks/embedding-lifecycle.d.ts +7 -0
  219. package/dist/v2/hooks/embedding-lifecycle.d.ts.map +1 -0
  220. package/dist/v2/hooks/generate.d.ts +36 -1
  221. package/dist/v2/hooks/generate.d.ts.map +1 -1
  222. package/dist/v2/hooks/lkg-system.d.ts +35 -4
  223. package/dist/v2/hooks/lkg-system.d.ts.map +1 -1
  224. package/dist/v2/hooks/payload.d.ts +16 -1
  225. package/dist/v2/hooks/payload.d.ts.map +1 -1
  226. package/dist/v2/hooks/store.d.ts +2 -0
  227. package/dist/v2/hooks/store.d.ts.map +1 -1
  228. package/dist/v2/hooks/tools.d.ts +2 -1
  229. package/dist/v2/hooks/tools.d.ts.map +1 -1
  230. package/dist/v2/hooks/transform-features.d.ts +2 -2
  231. package/dist/v2/hooks/transform-features.d.ts.map +1 -1
  232. package/dist/v2/{logger-7qt02bnb.js → logger-p34mjtja.js} +1 -1
  233. package/dist/v2/{message-fts-rowid-map-wfx67gfd.js → message-fts-rowid-map-n8fdg2ja.js} +6 -5
  234. package/dist/v2/{message-index-bounded-spd8r7pj.js → message-index-bounded-8rcd7qq9.js} +17 -16
  235. package/dist/v2/{message-index-8vz2pq76.js → message-index-qz9wdp82.js} +17 -16
  236. package/dist/v2/{message-time-backfill-04t0km1z.js → message-time-backfill-zvthw6xb.js} +3 -3
  237. package/dist/v2/migration-worker.js +13 -12
  238. package/dist/v2/{model-resolution-nx97z3x7.js → model-resolution-280gmqvd.js} +1 -1
  239. package/dist/v2/{project-embedding-registry-gnkj56xp.js → project-embedding-registry-v38q4xd5.js} +16 -13
  240. package/dist/v2/raw-ordinal-warmup-worker.js +136 -101
  241. package/dist/v2/{read-session-chunk-cwkxrmns.js → read-session-chunk-wazfyxcg.js} +12 -11
  242. package/dist/v2/{read-session-raw-yaegtjzh.js → read-session-raw-b70cpwzj.js} +4 -3
  243. package/dist/v2/recomp-orchestrator-b12zaptj.js +61 -0
  244. package/dist/v2/{safe-notification-target-qg7n2s77.js → safe-notification-target-khnzg57c.js} +2 -2
  245. package/dist/v2/search-archive-x64rtz1z.js +25 -0
  246. package/dist/v2/search-hza9x72a.js +49 -0
  247. package/dist/v2/{send-session-notification-3pxn658x.js → send-session-notification-8eqe259v.js} +7 -6
  248. package/dist/v2/{server-45q69hkq.js → server-132h8twc.js} +5 -5
  249. package/dist/v2/{server-h0410h0v.js → server-1bw1wcbp.js} +1 -1
  250. package/dist/v2/{server-271qxsf5.js → server-24g8r2d0.js} +2466 -1290
  251. package/dist/v2/{server-tbe1femw.js → server-29qp8nz4.js} +1 -1
  252. package/dist/v2/{server-gsxjv2q2.js → server-33nqbqkw.js} +182 -47
  253. package/dist/v2/{server-tgnbmwah.js → server-3mz2qh5a.js} +1 -1
  254. package/dist/v2/{server-n1prf1g6.js → server-3vhxy2k5.js} +2 -2
  255. package/dist/v2/{server-xj136kt8.js → server-4kjmrjn4.js} +9 -3
  256. package/dist/v2/{server-34kwfsr4.js → server-53eh1r8r.js} +2 -2
  257. package/dist/{index-8cd2j99z.js → v2/server-5kym00ag.js} +32 -13
  258. package/dist/v2/{server-46neh5fa.js → server-62g58aaz.js} +314 -127
  259. package/dist/v2/{server-f2xf5gcb.js → server-6495nmn9.js} +12 -15
  260. package/dist/v2/{server-a9xqj88f.js → server-6v3cdzsx.js} +4 -4
  261. package/dist/v2/{server-d04vrx0j.js → server-806rzhs6.js} +2 -2
  262. package/dist/v2/{server-qd11g795.js → server-92g7d776.js} +2 -1
  263. package/dist/v2/{server-nj659894.js → server-94wk1ey3.js} +14 -3
  264. package/dist/v2/{server-6tmj0s7j.js → server-ab1g0wn9.js} +4 -6
  265. package/dist/v2/{server-8by8qfec.js → server-ad18djzs.js} +95 -59
  266. package/dist/v2/{server-hy3d3vsx.js → server-bsgd4dk1.js} +2 -2
  267. package/dist/v2/server-cpjk5jd2.js +82 -0
  268. package/dist/v2/{server-g3qma5c0.js → server-d1dzgvwd.js} +2 -2
  269. package/dist/v2/{server-hm38q7r0.js → server-d48x3m4x.js} +5 -5
  270. package/dist/v2/{server-1wy7b9de.js → server-dtp8hcjh.js} +3 -3
  271. package/dist/v2/{server-27gq4mfz.js → server-fa7vtp40.js} +9 -6
  272. package/dist/v2/{server-6pmqg9m4.js → server-gyy4k6mf.js} +1 -1
  273. package/dist/{index-beht37jy.js → v2/server-gzy5w8ya.js} +194 -5
  274. package/dist/v2/{server-bmymkx73.js → server-j8h7bsca.js} +29 -15
  275. package/dist/v2/{server-n37sebck.js → server-jjvbk92s.js} +1 -1
  276. package/dist/v2/{server-da07v4xp.js → server-k3t06fxr.js} +1 -1
  277. package/dist/v2/{server-9hx7g5jp.js → server-m4bfaevz.js} +1197 -1049
  278. package/dist/v2/{server-2ar62dyx.js → server-ppcd1qxh.js} +191 -99
  279. package/dist/v2/{server-rmygf5pn.js → server-qjvk4a9t.js} +2 -2
  280. package/dist/v2/{server-zzkj2fch.js → server-qteg2kt9.js} +5 -5
  281. package/dist/v2/{server-pwv4ezb0.js → server-rqebawx1.js} +2 -2
  282. package/dist/v2/{server-h1v0pyxb.js → server-vr4szghm.js} +501 -20
  283. package/dist/v2/{server-xq7dfjke.js → server-wwaw5npa.js} +5 -5
  284. package/dist/v2/{server-6vdzn1td.js → server-zg5y109h.js} +323 -76
  285. package/dist/v2/server.js +8 -8
  286. package/dist/v2/{sqlite-zf72c52d.js → sqlite-zdgm52sv.js} +5 -1
  287. package/dist/v2/{storage-memory-y3qmy00r.js → storage-memory-e6a7mb0k.js} +2 -2
  288. package/dist/v2/{storage-tags-3wdb8zph.js → storage-tags-q71rnr9f.js} +5 -5
  289. package/dist/v2/store-reader.d.ts +10 -0
  290. package/dist/v2/store-reader.d.ts.map +1 -1
  291. package/dist/v2/{task-config-nvz8mapa.js → task-config-7md27rx8.js} +2 -2
  292. package/dist/v2/{wrapup-orchestrator-embdz8gj.js → wrapup-orchestrator-3ssd5yy1.js} +33 -32
  293. package/dist/wrapup-orchestrator-5vpcd1zx.js +49 -0
  294. package/package.json +2 -2
  295. package/src/config/index.test.ts +72 -6
  296. package/src/config/project-security.ts +15 -0
  297. package/src/config/rerank.test.ts +60 -0
  298. package/src/config/schema/magic-context.ts +57 -0
  299. package/src/shared/logger.test.ts +42 -1
  300. package/src/shared/logger.ts +11 -13
  301. package/src/shared/model-resolution.test.ts +67 -12
  302. package/src/shared/model-resolution.ts +43 -16
  303. package/src/shared/model-suggestion-retry.ts +2 -2
  304. package/src/shared/prompt-async-transport.ts +47 -3
  305. package/src/shared/rpc-types.ts +7 -0
  306. package/src/shared/sqlite-busy-budget-review.test.ts +6 -1
  307. package/src/shared/sqlite-turn-deadline.test.ts +270 -0
  308. package/src/shared/sqlite.ts +239 -9
  309. package/src/shared/subagent-runner.ts +2 -0
  310. package/src/shared/tag-transcript.ts +9 -1
  311. package/src/shared/worker-shutdown-fence.test.ts +87 -0
  312. package/src/shared/worker-shutdown.fixture.ts +25 -0
  313. package/src/shared/worker-shutdown.test.ts +127 -0
  314. package/src/shared/worker-shutdown.ts +160 -0
  315. package/dist/embedding-backfill-fmz50tsy.js +0 -24
  316. package/dist/recomp-orchestrator-999jj4bc.js +0 -61
  317. package/dist/search-archive-6vm0e2f5.js +0 -25
  318. package/dist/search-xsqk1bj4.js +0 -49
  319. package/dist/v2/embedding-backfill-7c7yr69y.js +0 -23
  320. package/dist/v2/recomp-orchestrator-f6m9jr7p.js +0 -60
  321. package/dist/v2/search-archive-wve3tq1k.js +0 -24
  322. package/dist/v2/search-hwg7jfbj.js +0 -48
  323. package/dist/wrapup-orchestrator-whhbjmaz.js +0 -48
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  DEFAULT_LOCAL_EMBEDDING_MODEL
3
- } from "./index-wgypt3cs.js";
3
+ } from "./index-nxrsns5x.js";
4
4
  import {
5
5
  getSynapseLaneIdentity
6
- } from "./index-6x57ar45.js";
6
+ } from "./index-wfybj1dw.js";
7
7
  import {
8
8
  getHarness2
9
9
  } from "./index-pavzsdc6.js";
@@ -13,10 +13,10 @@ import {
13
13
  import {
14
14
  importPluginModule,
15
15
  log2
16
- } from "./index-j75v2476.js";
16
+ } from "./index-h7tgn49j.js";
17
17
  import {
18
18
  inRootAsyncContext2
19
- } from "./index-beht37jy.js";
19
+ } from "./index-gzy5w8ya.js";
20
20
  import {
21
21
  computeNormalizedHash
22
22
  } from "./index-2bvekkfy.js";
@@ -100,6 +100,432 @@ function resolveEmbeddingTextPrefixes(model, queryInstruction, documentPrefix) {
100
100
  };
101
101
  }
102
102
 
103
+ // src/features/magic-context/memory/local-embedding-pooling.ts
104
+ import { createHash } from "node:crypto";
105
+ import { existsSync, readFileSync, statSync } from "node:fs";
106
+ import { join } from "node:path";
107
+ var decisionLogged = new Set;
108
+ var unavailableLogged = new Set;
109
+ var metadataByCache = new Map;
110
+ var testMetadataByModel = new Map;
111
+ var testMetadataFallback;
112
+ var UNRESOLVED_LOCAL_EMBEDDING_POOLING = {
113
+ status: "unresolved",
114
+ pooling: "mean",
115
+ normalize: true,
116
+ declared: false,
117
+ reason: "pooling metadata is unavailable; preserving legacy mean pooling and normalization"
118
+ };
119
+ var LEGACY_MEAN_POOLING = {
120
+ status: "ready",
121
+ pooling: "mean",
122
+ normalize: true,
123
+ declared: false,
124
+ reason: "no sentence-transformers Pooling module is declared; preserving legacy mean pooling and normalization"
125
+ };
126
+ function defaultModelCacheDir() {
127
+ return join(getMagicContextStorageDir(), "models");
128
+ }
129
+ function metadataDirectory(model, modelCacheDir) {
130
+ const digest = createHash("sha256").update(model).digest("hex");
131
+ return join(modelCacheDir, ".pooling-metadata", digest);
132
+ }
133
+ function parseJson(text, label) {
134
+ try {
135
+ return JSON.parse(text);
136
+ } catch (error) {
137
+ throw new Error(`${label} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
138
+ }
139
+ }
140
+ function isRecord(value) {
141
+ return typeof value === "object" && value !== null && !Array.isArray(value);
142
+ }
143
+ function isModelDirectory(model) {
144
+ try {
145
+ return statSync(model).isDirectory();
146
+ } catch {
147
+ return false;
148
+ }
149
+ }
150
+ function isPoolingModule(value) {
151
+ if (!isRecord(value))
152
+ return false;
153
+ return typeof value.type === "string" && /(?:^|\.)Pooling$/.test(value.type) || typeof value.name === "string" && value.name.toLowerCase() === "pooling";
154
+ }
155
+ function isNormalizeModule(value) {
156
+ if (!isRecord(value))
157
+ return false;
158
+ return typeof value.type === "string" && /(?:^|\.)Normalize$/.test(value.type) || typeof value.name === "string" && value.name.toLowerCase() === "normalize";
159
+ }
160
+ function safeModulePath(value) {
161
+ if (typeof value !== "string" || !value.trim())
162
+ return null;
163
+ const pieces = value.replaceAll("\\", "/").split("/");
164
+ if (pieces.some((piece) => piece === ".." || piece === "."))
165
+ return null;
166
+ return pieces.filter(Boolean).join("/");
167
+ }
168
+ function poolingFromFiles(modulesText, configText, label) {
169
+ if (modulesText === null)
170
+ return LEGACY_MEAN_POOLING;
171
+ const modulesValue = parseJson(modulesText, `${label}/modules.json`);
172
+ if (!Array.isArray(modulesValue)) {
173
+ return {
174
+ status: "unsupported",
175
+ normalize: false,
176
+ declared: true,
177
+ reason: "modules.json is not a module list"
178
+ };
179
+ }
180
+ const poolingModule = modulesValue.find(isPoolingModule);
181
+ if (!poolingModule)
182
+ return LEGACY_MEAN_POOLING;
183
+ const modulePath = safeModulePath(poolingModule.path);
184
+ if (modulePath === null || configText === null) {
185
+ return {
186
+ status: "unsupported",
187
+ normalize: modulesValue.some(isNormalizeModule),
188
+ declared: true,
189
+ reason: `Pooling module at ${String(poolingModule.path ?? "<missing path>")} has no readable config.json`
190
+ };
191
+ }
192
+ const config = parseJson(configText, `${label}/${modulePath}/config.json`);
193
+ if (!isRecord(config)) {
194
+ return {
195
+ status: "unsupported",
196
+ normalize: modulesValue.some(isNormalizeModule),
197
+ declared: true,
198
+ reason: `Pooling config at ${modulePath}/config.json is not an object`
199
+ };
200
+ }
201
+ const enabledModes = [
202
+ ["pooling_mode_cls_token", "cls"],
203
+ ["pooling_mode_mean_tokens", "mean"],
204
+ ["pooling_mode_lasttoken", "last_token"],
205
+ ["pooling_mode_max_tokens", undefined],
206
+ ["pooling_mode_mean_sqrt_len_tokens", undefined],
207
+ ["pooling_mode_weightedmean_tokens", undefined],
208
+ ["pooling_mode_mean_last_token", undefined]
209
+ ].filter(([key]) => config[key] === true);
210
+ const normalize = modulesValue.some(isNormalizeModule);
211
+ if (enabledModes.length !== 1) {
212
+ return {
213
+ status: "unsupported",
214
+ normalize,
215
+ declared: true,
216
+ reason: enabledModes.length === 0 ? `Pooling config at ${modulePath}/config.json enables no pooling mode` : `Pooling config enables multiple modes: ${enabledModes.map(([key]) => key).join(", ")}`
217
+ };
218
+ }
219
+ const [flag, method] = enabledModes[0];
220
+ if (!method) {
221
+ return {
222
+ status: "unsupported",
223
+ normalize,
224
+ declared: true,
225
+ reason: `unsupported declared pooling mode ${flag}`
226
+ };
227
+ }
228
+ return {
229
+ status: "ready",
230
+ pooling: method,
231
+ normalize,
232
+ declared: true,
233
+ reason: `modules.json declares ${flag}; ${normalize ? "a Normalize module is present" : "no Normalize module is declared"}`
234
+ };
235
+ }
236
+ function poolingMetadataCacheKey(model, modelCacheDir) {
237
+ return JSON.stringify([model, modelCacheDir]);
238
+ }
239
+ function cachedMetadataPath(model, modelCacheDir) {
240
+ return join(metadataDirectory(model, modelCacheDir), "resolution.json");
241
+ }
242
+ function parseCachedMetadata(text) {
243
+ try {
244
+ const value = JSON.parse(text);
245
+ if (!isRecord(value) || value.status !== "ready" && value.status !== "unsupported")
246
+ return null;
247
+ if (typeof value.normalize !== "boolean" || typeof value.declared !== "boolean" || typeof value.reason !== "string")
248
+ return null;
249
+ if (value.status === "ready" && value.pooling !== "mean" && value.pooling !== "cls" && value.pooling !== "last_token")
250
+ return null;
251
+ return value;
252
+ } catch {
253
+ return null;
254
+ }
255
+ }
256
+ function readDirectoryMetadata(model) {
257
+ const modulesPath = join(model, "modules.json");
258
+ if (!existsSync(modulesPath))
259
+ return LEGACY_MEAN_POOLING;
260
+ const modulesText = readFileSync(modulesPath, "utf8");
261
+ const moduleList = parseJson(modulesText, `${model}/modules.json`);
262
+ if (!Array.isArray(moduleList)) {
263
+ return {
264
+ status: "unsupported",
265
+ normalize: false,
266
+ declared: true,
267
+ reason: "modules.json is not a module list"
268
+ };
269
+ }
270
+ const poolingModule = moduleList.find(isPoolingModule);
271
+ const modulePath = poolingModule ? safeModulePath(poolingModule.path) : null;
272
+ const configText = modulePath ? readFileSync(join(model, modulePath, "config.json"), "utf8") : null;
273
+ return poolingFromFiles(modulesText, configText, model);
274
+ }
275
+ function getCachedLocalEmbeddingPooling(model, modelCacheDir = defaultModelCacheDir()) {
276
+ if (testMetadataByModel.has(model))
277
+ return testMetadataByModel.get(model) ?? null;
278
+ const cacheKey = poolingMetadataCacheKey(model, modelCacheDir);
279
+ const cachedInMemory = metadataByCache.get(cacheKey);
280
+ if (cachedInMemory)
281
+ return cachedInMemory;
282
+ if (isModelDirectory(model)) {
283
+ try {
284
+ const metadata = readDirectoryMetadata(model);
285
+ metadataByCache.set(cacheKey, metadata);
286
+ return metadata;
287
+ } catch (error) {
288
+ const metadata = {
289
+ status: "unsupported",
290
+ normalize: false,
291
+ declared: true,
292
+ reason: error instanceof Error ? error.message : String(error)
293
+ };
294
+ metadataByCache.set(cacheKey, metadata);
295
+ return metadata;
296
+ }
297
+ }
298
+ try {
299
+ const cached = parseCachedMetadata(readFileSync(cachedMetadataPath(model, modelCacheDir), "utf8"));
300
+ if (cached) {
301
+ metadataByCache.set(cacheKey, cached);
302
+ return cached;
303
+ }
304
+ } catch {}
305
+ if (testMetadataFallback) {
306
+ metadataByCache.set(cacheKey, testMetadataFallback);
307
+ return testMetadataFallback;
308
+ }
309
+ metadataByCache.set(cacheKey, UNRESOLVED_LOCAL_EMBEDDING_POOLING);
310
+ return UNRESOLVED_LOCAL_EMBEDDING_POOLING;
311
+ }
312
+ function logLocalEmbeddingPoolingDecisionOnce(model, metadata, logger = log2) {
313
+ const decisionKey = `${model}:${metadata.status}:${metadata.pooling ?? "none"}:${metadata.normalize}`;
314
+ if (decisionLogged.has(decisionKey))
315
+ return;
316
+ decisionLogged.add(decisionKey);
317
+ if (metadata.status === "unsupported") {
318
+ logger(`[magic-context] local embedding pooling for ${model} is unsupported: ${metadata.reason}`);
319
+ } else {
320
+ logger(`[magic-context] local embedding pooling for ${model}: ${metadata.pooling} pooling, normalization ${metadata.normalize ? "enabled" : "disabled"} (${metadata.reason})`);
321
+ }
322
+ }
323
+ function logUnavailableOnce(model, reason, logger) {
324
+ if (unavailableLogged.has(model))
325
+ return;
326
+ unavailableLogged.add(model);
327
+ logger(`[magic-context] local embedding pooling metadata for ${model} is not available: ${reason}; using legacy mean pooling and retrying during a later background bootstrap`);
328
+ }
329
+ function remoteHost() {
330
+ const configured = process.env.HF_ENDPOINT?.trim().replace(/\/+$/, "");
331
+ return configured || "https://huggingface.co";
332
+ }
333
+ function safeRepoId(repo) {
334
+ return repo.length > 0 && repo.split("/").every((part) => part && part !== "." && part !== "..");
335
+ }
336
+ function modelFileUrl(host, repo, file) {
337
+ const path = repo.split("/").map(encodeURIComponent).join("/");
338
+ const filePath = file.split("/").map(encodeURIComponent).join("/");
339
+ return `${host}/${path}/resolve/main/${filePath}`;
340
+ }
341
+ async function fetchModelFile(host, repo, file, fetcher) {
342
+ const response = await fetcher(modelFileUrl(host, repo, file));
343
+ if (response.status === 404)
344
+ return { kind: "missing" };
345
+ if (!response.ok)
346
+ throw new Error(`HTTP ${response.status} fetching ${repo}/${file}`);
347
+ return { kind: "found", text: await response.text() };
348
+ }
349
+ async function filesForRepo(host, repo, fetcher) {
350
+ const modules = await fetchModelFile(host, repo, "modules.json", fetcher);
351
+ if (modules.kind === "missing") {
352
+ const rootConfigResult = await fetchModelFile(host, repo, "config.json", fetcher);
353
+ if (rootConfigResult.kind === "missing") {
354
+ return {
355
+ modulesText: null,
356
+ configText: null,
357
+ configPath: null,
358
+ rootConfig: null,
359
+ rootModules: null
360
+ };
361
+ }
362
+ const rootConfigValue = parseJson(rootConfigResult.text, `${repo}/config.json`);
363
+ const origin = isRecord(rootConfigValue) && typeof rootConfigValue._name_or_path === "string" ? rootConfigValue._name_or_path.trim() : "";
364
+ if (!origin || origin === repo || !safeRepoId(origin)) {
365
+ return {
366
+ modulesText: null,
367
+ configText: null,
368
+ configPath: null,
369
+ rootConfig: rootConfigResult.text,
370
+ rootModules: null
371
+ };
372
+ }
373
+ const originModules = await fetchModelFile(host, origin, "modules.json", fetcher);
374
+ if (originModules.kind === "missing") {
375
+ return {
376
+ modulesText: null,
377
+ configText: null,
378
+ configPath: null,
379
+ rootConfig: rootConfigResult.text,
380
+ rootModules: null
381
+ };
382
+ }
383
+ const originModuleList = parseJson(originModules.text, `${origin}/modules.json`);
384
+ if (!Array.isArray(originModuleList)) {
385
+ return {
386
+ modulesText: originModules.text,
387
+ configText: null,
388
+ configPath: null,
389
+ rootConfig: rootConfigResult.text,
390
+ rootModules: originModules.text
391
+ };
392
+ }
393
+ const poolingModule = originModuleList.find(isPoolingModule);
394
+ const modulePath = poolingModule ? safeModulePath(poolingModule.path) : null;
395
+ if (!modulePath) {
396
+ return {
397
+ modulesText: originModules.text,
398
+ configText: null,
399
+ configPath: null,
400
+ rootConfig: rootConfigResult.text,
401
+ rootModules: originModules.text
402
+ };
403
+ }
404
+ const poolingConfig = await fetchModelFile(host, origin, `${modulePath}/config.json`, fetcher);
405
+ if (poolingConfig.kind === "missing") {
406
+ return {
407
+ modulesText: originModules.text,
408
+ configText: null,
409
+ configPath: `${origin}/${modulePath}/config.json`,
410
+ rootConfig: rootConfigResult.text,
411
+ rootModules: originModules.text
412
+ };
413
+ }
414
+ return {
415
+ modulesText: originModules.text,
416
+ configText: poolingConfig.text,
417
+ configPath: `${origin}/${modulePath}/config.json`,
418
+ rootConfig: rootConfigResult.text,
419
+ rootModules: originModules.text
420
+ };
421
+ }
422
+ const modulesValue = parseJson(modules.text, `${repo}/modules.json`);
423
+ if (!Array.isArray(modulesValue)) {
424
+ return {
425
+ modulesText: modules.text,
426
+ configText: null,
427
+ configPath: null,
428
+ rootConfig: null,
429
+ rootModules: modules.text
430
+ };
431
+ }
432
+ const poolingModule = modulesValue.find(isPoolingModule);
433
+ const modulePath = poolingModule ? safeModulePath(poolingModule.path) : null;
434
+ if (!modulePath) {
435
+ return {
436
+ modulesText: modules.text,
437
+ configText: null,
438
+ configPath: null,
439
+ rootConfig: null,
440
+ rootModules: modules.text
441
+ };
442
+ }
443
+ const poolingConfig = await fetchModelFile(host, repo, `${modulePath}/config.json`, fetcher);
444
+ return {
445
+ modulesText: modules.text,
446
+ configText: poolingConfig.kind === "found" ? poolingConfig.text : null,
447
+ configPath: `${repo}/${modulePath}/config.json`,
448
+ rootConfig: null,
449
+ rootModules: modules.text
450
+ };
451
+ }
452
+ async function cacheRemoteFiles(model, modelCacheDir, files) {
453
+ const root = metadataDirectory(model, modelCacheDir);
454
+ const writes = [];
455
+ if (files.rootConfig !== null)
456
+ writes.push(writeStorageFileAsync(join(root, "config.json"), files.rootConfig, true));
457
+ if (files.rootModules !== null)
458
+ writes.push(writeStorageFileAsync(join(root, "modules.json"), files.rootModules, true));
459
+ if (files.configText !== null && files.configPath !== null) {
460
+ const slash = files.configPath.indexOf("/");
461
+ const repo = files.configPath.slice(0, slash);
462
+ const relative = files.configPath.slice(slash + 1);
463
+ writes.push(writeStorageFileAsync(join(root, "source", repo, relative), files.configText, true));
464
+ }
465
+ await Promise.all(writes);
466
+ }
467
+ async function preflightLocalEmbeddingPooling(model, options = {}) {
468
+ const cacheDir = options.modelCacheDir ?? defaultModelCacheDir();
469
+ const logger = options.logger ?? log2;
470
+ const cacheKey = poolingMetadataCacheKey(model, cacheDir);
471
+ const cached = getCachedLocalEmbeddingPooling(model, cacheDir);
472
+ if (cached && cached.status !== "unresolved") {
473
+ logLocalEmbeddingPoolingDecisionOnce(model, cached, logger);
474
+ return cached;
475
+ }
476
+ if (isModelDirectory(model)) {
477
+ try {
478
+ const metadata = readDirectoryMetadata(model);
479
+ metadataByCache.set(cacheKey, metadata);
480
+ testMetadataByModel.delete(model);
481
+ logLocalEmbeddingPoolingDecisionOnce(model, metadata, logger);
482
+ return metadata;
483
+ } catch (error) {
484
+ const reason = error instanceof Error ? error.message : String(error);
485
+ const metadata = {
486
+ status: "unsupported",
487
+ normalize: false,
488
+ declared: true,
489
+ reason
490
+ };
491
+ metadataByCache.set(cacheKey, metadata);
492
+ testMetadataByModel.delete(model);
493
+ logLocalEmbeddingPoolingDecisionOnce(model, metadata, logger);
494
+ return metadata;
495
+ }
496
+ }
497
+ try {
498
+ const fetcher = options.fetcher ?? ((url) => fetch(url, { signal: AbortSignal.timeout(20000) }));
499
+ const files = await filesForRepo(remoteHost(), model, fetcher);
500
+ let metadata;
501
+ try {
502
+ metadata = poolingFromFiles(files.modulesText, files.configText, model);
503
+ } catch (error) {
504
+ metadata = {
505
+ status: "unsupported",
506
+ normalize: false,
507
+ declared: true,
508
+ reason: error instanceof Error ? error.message : String(error)
509
+ };
510
+ }
511
+ await cacheRemoteFiles(model, cacheDir, files);
512
+ await writeStorageFileAsync(cachedMetadataPath(model, cacheDir), JSON.stringify(metadata), true);
513
+ metadataByCache.set(cacheKey, metadata);
514
+ testMetadataByModel.delete(model);
515
+ logLocalEmbeddingPoolingDecisionOnce(model, metadata, logger);
516
+ return metadata;
517
+ } catch (error) {
518
+ const reason = error instanceof Error ? error.message : String(error);
519
+ metadataByCache.set(cacheKey, UNRESOLVED_LOCAL_EMBEDDING_POOLING);
520
+ testMetadataByModel.delete(model);
521
+ logUnavailableOnce(model, reason, logger);
522
+ return UNRESOLVED_LOCAL_EMBEDDING_POOLING;
523
+ }
524
+ }
525
+ function logLocalEmbeddingPoolingUnavailableOnce(model, reason, logger = log2) {
526
+ logUnavailableOnce(model, reason, logger);
527
+ }
528
+
103
529
  // src/features/magic-context/memory/embedding-identity.ts
104
530
  function normalizeEndpoint(endpoint) {
105
531
  return endpoint?.trim().replace(/\/+$/, "") ?? "";
@@ -121,6 +547,8 @@ function getEmbeddingProviderIdentity(config) {
121
547
  const truncate = config.provider === "openai-compatible" ? config.truncate?.trim() : undefined;
122
548
  const documentPrefix = config.provider === "openai-compatible" ? resolveEmbeddingTextPrefixes(config.model, config.query_instruction, config.document_prefix).documentPrefix : "";
123
549
  const localDtype = config.provider === "local" && config.local_dtype && config.local_dtype !== "fp32" ? config.local_dtype : undefined;
550
+ const localPooling = config.provider === "local" ? getCachedLocalEmbeddingPooling(config.model?.trim() || DEFAULT_LOCAL_EMBEDDING_MODEL) : null;
551
+ const localPoolingFingerprint = localPooling?.status === "ready" && (localPooling.pooling !== "mean" || !localPooling.normalize) ? `${localPooling.pooling};normalize=${localPooling.normalize}` : undefined;
124
552
  const identityInput = config.provider === "openai-compatible" ? {
125
553
  provider: "openai-compatible",
126
554
  model: config.model.trim(),
@@ -135,15 +563,16 @@ function getEmbeddingProviderIdentity(config) {
135
563
  endpoint: "",
136
564
  apiKeyPresent: false,
137
565
  runtimeFingerprint: LOCAL_EMBEDDING_RUNTIME_FINGERPRINT,
138
- ...localDtype ? { localDtype } : {}
566
+ ...localDtype ? { localDtype } : {},
567
+ ...localPoolingFingerprint ? { localPooling: localPoolingFingerprint } : {}
139
568
  };
140
569
  return `embedding-provider:${computeNormalizedHash(JSON.stringify(identityInput))}`;
141
570
  }
142
571
 
143
572
  // src/features/magic-context/memory/embedding-local.ts
144
- import { readdirSync, statSync } from "node:fs";
573
+ import { readdirSync, statSync as statSync2 } from "node:fs";
145
574
  import { stat, unlink } from "node:fs/promises";
146
- import { dirname, join } from "node:path";
575
+ import { dirname, join as join2 } from "node:path";
147
576
  import { pathToFileURL } from "node:url";
148
577
  import { workerData } from "node:worker_threads";
149
578
 
@@ -298,16 +727,20 @@ class EmbeddingWorkerClient {
298
727
  entry;
299
728
  timeoutMs;
300
729
  prepareTelemetry;
730
+ idleMs;
301
731
  worker = null;
302
732
  startPromise = null;
303
733
  nextId = 1;
304
734
  pending = new Map;
305
735
  disposed = false;
306
- constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000, prepareTelemetry = prepareNativeOnnxTelemetry) {
736
+ activeRequests = 0;
737
+ idleTimer = null;
738
+ constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000, prepareTelemetry = prepareNativeOnnxTelemetry, idleMs = 10 * 60000) {
307
739
  this.data = data;
308
740
  this.entry = entry;
309
741
  this.timeoutMs = timeoutMs;
310
742
  this.prepareTelemetry = prepareTelemetry;
743
+ this.idleMs = idleMs;
311
744
  }
312
745
  start() {
313
746
  if (this.startPromise)
@@ -373,6 +806,7 @@ class EmbeddingWorkerClient {
373
806
  const fail = (error) => {
374
807
  if (this.worker !== worker)
375
808
  return;
809
+ this.clearIdleTimer();
376
810
  this.worker = null;
377
811
  for (const request of this.pending.values()) {
378
812
  clearTimeout(request.timer);
@@ -397,6 +831,31 @@ class EmbeddingWorkerClient {
397
831
  async request(texts, signal) {
398
832
  if (signal?.aborted)
399
833
  return Promise.reject(new Error("embedding request aborted"));
834
+ this.activeRequests++;
835
+ this.clearIdleTimer();
836
+ try {
837
+ return await this.requestOnWorker(texts, signal);
838
+ } finally {
839
+ this.activeRequests--;
840
+ this.armIdleTimer();
841
+ }
842
+ }
843
+ clearIdleTimer() {
844
+ if (this.idleTimer)
845
+ clearTimeout(this.idleTimer);
846
+ this.idleTimer = null;
847
+ }
848
+ armIdleTimer() {
849
+ if (this.disposed || this.activeRequests !== 0 || !this.worker)
850
+ return;
851
+ this.clearIdleTimer();
852
+ this.idleTimer = inRootAsyncContext2(() => setTimeout(() => {
853
+ this.idleTimer = null;
854
+ this.stop(new Error("embedding worker idle"));
855
+ }, this.idleMs));
856
+ this.idleTimer.unref();
857
+ }
858
+ async requestOnWorker(texts, signal) {
400
859
  const worker = await this.start();
401
860
  if (this.disposed)
402
861
  throw new Error("embedding worker disposed");
@@ -448,6 +907,7 @@ class EmbeddingWorkerClient {
448
907
  });
449
908
  }
450
909
  async stop(error) {
910
+ this.clearIdleTimer();
451
911
  const worker = this.worker;
452
912
  this.worker = null;
453
913
  for (const request of this.pending.values()) {
@@ -605,7 +1065,7 @@ var importTransformersNodeWasmFallbackForRuntime = async () => {
605
1065
  const nodeWasmEntry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "../../../../dist/transformers-node-wasm.js" : "./transformers-node-wasm.js", import.meta.url).href;
606
1066
  return await importPluginModule(() => import(nodeWasmEntry));
607
1067
  };
608
- var modelCacheDirForRuntime = () => workerData?.magicContextEmbeddingWorker && typeof workerData.modelCacheDir === "string" ? workerData.modelCacheDir : join(getMagicContextStorageDir(), "models");
1068
+ var modelCacheDirForRuntime = () => workerData?.magicContextEmbeddingWorker && typeof workerData.modelCacheDir === "string" ? workerData.modelCacheDir : join2(getMagicContextStorageDir(), "models");
609
1069
  var logForRuntime = log2;
610
1070
  var injectWasmOrtForRuntime = injectWasmOrt;
611
1071
  var loadedLocalEmbeddingRuntimes = new Map;
@@ -614,14 +1074,14 @@ function directoryBytes(path) {
614
1074
  let total = 0;
615
1075
  try {
616
1076
  for (const entry of readdirSync(path, { withFileTypes: true })) {
617
- const entryPath = join(path, entry.name);
1077
+ const entryPath = join2(path, entry.name);
618
1078
  if (entry.isDirectory()) {
619
1079
  const childBytes = directoryBytes(entryPath);
620
1080
  if (childBytes === null)
621
1081
  return null;
622
1082
  total += childBytes;
623
1083
  } else if (entry.isFile()) {
624
- total += statSync(entryPath).size;
1084
+ total += statSync2(entryPath).size;
625
1085
  }
626
1086
  }
627
1087
  return total;
@@ -847,6 +1307,7 @@ class LocalEmbeddingProvider {
847
1307
  dtype;
848
1308
  runtimePreference;
849
1309
  pipeline = null;
1310
+ poolingMetadata = null;
850
1311
  workerClient;
851
1312
  workerLoaded = false;
852
1313
  initPromise = null;
@@ -924,6 +1385,18 @@ class LocalEmbeddingProvider {
924
1385
  throw new LocalEmbeddingFsUnavailableError;
925
1386
  }
926
1387
  const modelCacheDir = modelCacheDirForRuntime();
1388
+ const cachedPoolingMetadata = getCachedLocalEmbeddingPooling(this.model, modelCacheDir);
1389
+ const poolingMetadata = cachedPoolingMetadata?.status === "unresolved" || !cachedPoolingMetadata ? UNRESOLVED_LOCAL_EMBEDDING_POOLING : cachedPoolingMetadata;
1390
+ if (poolingMetadata.status === "unsupported" || !poolingMetadata.pooling) {
1391
+ throw new Error(`unsupported pooling for local model '${this.model}': ${poolingMetadata.reason}`);
1392
+ }
1393
+ if (poolingMetadata.status === "unresolved") {
1394
+ logLocalEmbeddingPoolingUnavailableOnce(this.model, poolingMetadata.reason, logForRuntime);
1395
+ }
1396
+ this.poolingMetadata = poolingMetadata;
1397
+ if (!workerData?.magicContextEmbeddingWorker) {
1398
+ logLocalEmbeddingPoolingDecisionOnce(this.model, poolingMetadata, logForRuntime);
1399
+ }
927
1400
  try {
928
1401
  ensureStorageDirectorySync(modelCacheDir);
929
1402
  env.cacheDir = modelCacheDir;
@@ -931,7 +1404,7 @@ class LocalEmbeddingProvider {
931
1404
  log2("[magic-context] could not create model cache dir, using library default");
932
1405
  }
933
1406
  const createPipeline = transformersModule.pipeline;
934
- const lockPath = join(modelCacheDir, ".load.lock");
1407
+ const lockPath = join2(modelCacheDir, ".load.lock");
935
1408
  const releaseLock = await acquireModelLoadLock(lockPath);
936
1409
  const stopHeartbeat = startLockHeartbeat(lockPath);
937
1410
  try {
@@ -1038,8 +1511,8 @@ class LocalEmbeddingProvider {
1038
1511
  return null;
1039
1512
  }
1040
1513
  const result = await withQuietConsole(() => pipeline(text, {
1041
- pooling: "mean",
1042
- normalize: true
1514
+ pooling: this.poolingMetadata?.pooling ?? "mean",
1515
+ normalize: this.poolingMetadata?.normalize ?? true
1043
1516
  }));
1044
1517
  const embedding = extractBatchEmbeddings(result, 1)[0] ?? null;
1045
1518
  if (!embedding) {
@@ -1090,11 +1563,19 @@ class LocalEmbeddingProvider {
1090
1563
  if (!pipeline) {
1091
1564
  return Array.from({ length: texts.length }, () => null);
1092
1565
  }
1093
- const result = await withQuietConsole(() => pipeline(texts, {
1094
- pooling: "mean",
1095
- normalize: true
1096
- }));
1097
- const embeddings = extractBatchEmbeddings(result, texts.length);
1566
+ const pooling = this.poolingMetadata?.pooling ?? "mean";
1567
+ const normalize = this.poolingMetadata?.normalize ?? true;
1568
+ let embeddings;
1569
+ if (pooling === "last_token" && texts.length > 1) {
1570
+ embeddings = [];
1571
+ for (const text of texts) {
1572
+ const result = await withQuietConsole(() => pipeline(text, { pooling, normalize }));
1573
+ embeddings.push(extractBatchEmbeddings(result, 1)[0] ?? null);
1574
+ }
1575
+ } else {
1576
+ const result = await withQuietConsole(() => pipeline(texts, { pooling, normalize }));
1577
+ embeddings = extractBatchEmbeddings(result, texts.length);
1578
+ }
1098
1579
  if (embeddings.every((embedding) => embedding === null)) {
1099
1580
  this.lastFailureReason = classifyLocalEmbeddingFailure(new Error("local embedding pipeline returned no vectors"), { usesWasm: this.usesWasm });
1100
1581
  } else {
@@ -1170,4 +1651,4 @@ class LocalEmbeddingProvider {
1170
1651
  }
1171
1652
  }
1172
1653
 
1173
- export { embeddingModelsMatch, resolveEmbeddingTextPrefixes, getEmbeddingProviderIdentity, dominantEmbeddingFailure, resolveLocalEmbeddingWorkerRuntime, getLocalEmbeddingNativeMemoryStats, LocalEmbeddingProvider };
1654
+ export { embeddingModelsMatch, resolveEmbeddingTextPrefixes, getCachedLocalEmbeddingPooling, logLocalEmbeddingPoolingDecisionOnce, preflightLocalEmbeddingPooling, logLocalEmbeddingPoolingUnavailableOnce, getEmbeddingProviderIdentity, dominantEmbeddingFailure, resolveLocalEmbeddingWorkerRuntime, getLocalEmbeddingNativeMemoryStats, LocalEmbeddingProvider };