@cortexkit/opencode-magic-context 0.49.48 → 0.49.50

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 (224) hide show
  1. package/dist/{announcement-g789dmt6.js → announcement-9pr71hd5.js} +3 -2
  2. package/dist/auto-search-worker.js +5 -5
  3. package/dist/chunk-embedding-write-worker.js +14 -15
  4. package/dist/{compaction-marker-candidates-dkfp1q9j.js → compaction-marker-candidates-8hazqfvj.js} +2 -3
  5. package/dist/compaction-marker-candidates-worker.js +1 -1
  6. package/dist/{compartment-chunk-embedding-snj51nmg.js → compartment-chunk-embedding-gfd093f8.js} +7 -8
  7. package/dist/config/project-security.d.ts.map +1 -1
  8. package/dist/config/schema/magic-context.d.ts +10 -0
  9. package/dist/config/schema/magic-context.d.ts.map +1 -1
  10. package/dist/{conflict-warning-hook-w1aw6w5t.js → conflict-warning-hook-56qpq7ws.js} +7 -8
  11. package/dist/{context-8r125qv3.js → context-4js5qnnm.js} +61 -49
  12. package/dist/{derive-budgets-nkw09vq7.js → derive-budgets-z53424qx.js} +2 -3
  13. package/dist/embedding-backfill-3wdjzrvs.js +27 -0
  14. package/dist/embedding-worker-process.js +2 -3
  15. package/dist/embedding-worker.js +6 -7
  16. package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
  17. package/dist/features/magic-context/dreamer/provider-output-failure.d.ts +5 -7
  18. package/dist/features/magic-context/dreamer/provider-output-failure.d.ts.map +1 -1
  19. package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
  20. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  21. package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
  22. package/dist/features/magic-context/memory/embedding-openai.d.ts +4 -0
  23. package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
  24. package/dist/features/magic-context/memory/embedding-probe.d.ts +10 -0
  25. package/dist/features/magic-context/memory/embedding-probe.d.ts.map +1 -1
  26. package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
  27. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  28. package/dist/features/magic-context/storage-db.d.ts +14 -0
  29. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  30. package/dist/features/magic-context/transform-decision-log.d.ts +2 -0
  31. package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
  32. package/dist/{history-owner-0z620wgz.js → history-owner-n50e0e8y.js} +2 -3
  33. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  34. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  35. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/protected-tail-boundary.d.ts +5 -3
  37. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  38. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  39. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  40. package/dist/{index-rvmhyk89.js → index-07rp6xcn.js} +9 -9
  41. package/dist/{index-txs8tce6.js → index-0k283v27.js} +2 -4
  42. package/dist/{index-ak11t3gm.js → index-0tz2fzpq.js} +1 -1
  43. package/dist/{index-2qbtqg1w.js → index-25tm250q.js} +1 -1
  44. package/dist/{index-h9m41624.js → index-2ny9xwdn.js} +2 -2
  45. package/dist/{index-xa9mmq6c.js → index-36wseasx.js} +1 -1
  46. package/dist/{index-cgzpbz78.js → index-5dptmnvd.js} +5 -5
  47. package/dist/{index-q41sm60t.js → index-5g6npyw5.js} +89 -63
  48. package/dist/{index-qsyx931k.js → index-5t1mr0bt.js} +13 -15
  49. package/dist/{index-jrfre9ah.js → index-82dfe8en.js} +146 -5
  50. package/dist/{index-d4qw2h43.js → index-8d7gkgjs.js} +6 -5
  51. package/dist/{index-gn6gfz4y.js → index-90z05d0p.js} +1 -1
  52. package/dist/{index-trkxkgmd.js → index-97bjd14c.js} +5 -5
  53. package/dist/{index-9wnbnx8f.js → index-a6aqpfp6.js} +1 -1
  54. package/dist/{index-s79g172v.js → index-bamnjp2t.js} +29 -13
  55. package/dist/{index-4wpfbzks.js → index-bkg4hdyh.js} +3 -3
  56. package/dist/{index-gp3kcpc4.js → index-cd3vp8xa.js} +1 -1
  57. package/dist/{index-vk6srk5r.js → index-ct3ettqt.js} +3 -3
  58. package/dist/{index-sd2s4t4p.js → index-cwj6qhmf.js} +2 -2
  59. package/dist/{index-brj6was5.js → index-em92bp7f.js} +2 -2
  60. package/dist/{index-2p37txes.js → index-ga5q492k.js} +1 -1
  61. package/dist/{index-8cfnaagj.js → index-gapnh6tk.js} +2 -4
  62. package/dist/{index-fw42ms3m.js → index-gz001bx7.js} +1 -1
  63. package/dist/{index-zetm0ayn.js → index-h8g08nxs.js} +164 -106
  64. package/dist/{index-qcz1fy7h.js → index-hexdee98.js} +4 -4
  65. package/dist/{index-fgft4qjn.js → index-hkveze74.js} +4 -4
  66. package/dist/{index-smtbdmc3.js → index-hsv31e69.js} +2 -2
  67. package/dist/{index-dj2p8653.js → index-hsyczpn7.js} +2 -2
  68. package/dist/{index-4dpvnp8k.js → index-jjy5a5w0.js} +3 -0
  69. package/dist/{index-1hwn96x1.js → index-kn1bx21r.js} +3 -3
  70. package/dist/{index-t6s0tsp7.js → index-mjh63zvw.js} +3 -3
  71. package/dist/{index-ta87fpfs.js → index-n0twfvah.js} +64 -15
  72. package/dist/{index-nj360hcs.js → index-pb8ysnq2.js} +4 -4
  73. package/dist/{index-jz5bk7xd.js → index-qperbvjn.js} +2 -2
  74. package/dist/{index-25ka1jza.js → index-r9agn061.js} +4 -4
  75. package/dist/{index-hkh8x221.js → index-rbs27k1d.js} +7 -7
  76. package/dist/{index-hacf2tyx.js → index-reyws9fy.js} +1 -1
  77. package/dist/{index-cgsmttyj.js → index-s131svmx.js} +4 -4
  78. package/dist/{index-fxbk7gk3.js → index-tad3can2.js} +1 -1
  79. package/dist/{index-8ka0ne8t.js → index-v4a1pnny.js} +6 -6
  80. package/dist/{index-xh3jyejb.js → index-wr2t8zb0.js} +17 -19
  81. package/dist/{index-q6pjqm49.js → index-z4832qfe.js} +14 -14
  82. package/dist/index.js +54 -56
  83. package/dist/{logger-qwnbcfj9.js → logger-sw7z6sjz.js} +1 -2
  84. package/dist/{message-fts-rowid-map-msffhkve.js → message-fts-rowid-map-kx1bsdyg.js} +4 -5
  85. package/dist/{message-index-bounded-0q7sy04w.js → message-index-bounded-k0ebpy3y.js} +12 -13
  86. package/dist/{message-time-backfill-39bm498k.js → message-time-backfill-hp2jgn49.js} +2 -3
  87. package/dist/migration-worker.js +12 -13
  88. package/dist/plugin/embedding-bootstrap-helpers.d.ts.map +1 -1
  89. package/dist/plugin/embedding-routing.d.ts.map +1 -1
  90. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  91. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  92. package/dist/{project-embedding-registry-r6xfsrbe.js → project-embedding-registry-5dwh5zfn.js} +12 -13
  93. package/dist/raw-ordinal-warmup-worker.js +8 -8
  94. package/dist/{read-session-chunk-7fmg9p5m.js → read-session-chunk-6712p893.js} +10 -11
  95. package/dist/{read-session-raw-x7a9b3jm.js → read-session-raw-04ger9zt.js} +2 -3
  96. package/dist/{recomp-orchestrator-jqa5z4ar.js → recomp-orchestrator-8ebydg5j.js} +31 -32
  97. package/dist/render-dtc4qkq4.js +43 -0
  98. package/dist/{safe-notification-target-wztd7bgk.js → safe-notification-target-mx5khyxf.js} +2 -3
  99. package/dist/{search-archive-df09r8qn.js → search-archive-f6hjbnsa.js} +12 -13
  100. package/dist/{search-kt764afk.js → search-edv0gy1d.js} +24 -25
  101. package/dist/{send-session-notification-j93pn2hn.js → send-session-notification-gamjee2f.js} +5 -6
  102. package/dist/shared/data-path.d.ts +7 -13
  103. package/dist/shared/data-path.d.ts.map +1 -1
  104. package/dist/shared/hidden-model-cooldown.d.ts +23 -0
  105. package/dist/shared/hidden-model-cooldown.d.ts.map +1 -0
  106. package/dist/shared/model-suggestion-retry.d.ts +0 -2
  107. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  108. package/dist/shared/provider-response-completion.d.ts +10 -0
  109. package/dist/shared/provider-response-completion.d.ts.map +1 -1
  110. package/dist/shared/rpc-types.d.ts +1 -0
  111. package/dist/shared/rpc-types.d.ts.map +1 -1
  112. package/dist/shared/status-summary.d.ts +1 -0
  113. package/dist/shared/status-summary.d.ts.map +1 -1
  114. package/dist/shared/status-view-check.d.ts.map +1 -1
  115. package/dist/shared/status-view.d.ts +1 -0
  116. package/dist/shared/status-view.d.ts.map +1 -1
  117. package/dist/shared/test-db.d.ts +13 -0
  118. package/dist/shared/test-db.d.ts.map +1 -0
  119. package/dist/{storage-tags-96vyd6ra.js → storage-tags-kdb4qsyq.js} +4 -5
  120. package/dist/test-preload.d.ts +2 -0
  121. package/dist/test-preload.d.ts.map +1 -0
  122. package/dist/{transform-postprocess-phase-a7ety10n.js → transform-postprocess-phase-1bg25094.js} +32 -33
  123. package/dist/v2/auto-search-worker.js +5 -5
  124. package/dist/v2/chunk-embedding-write-worker.js +14 -14
  125. package/dist/v2/{compaction-marker-candidates-y737qb1v.js → compaction-marker-candidates-re14353a.js} +2 -2
  126. package/dist/v2/compaction-marker-candidates-worker.js +1 -1
  127. package/dist/v2/{compartment-chunk-embedding-nj5nrnbj.js → compartment-chunk-embedding-0pxsrzrt.js} +7 -7
  128. package/dist/v2/{context-9x7mnb7x.js → context-qkr7z6d0.js} +99 -63
  129. package/dist/v2/{derive-budgets-b5cgrtp8.js → derive-budgets-w0815q82.js} +3 -3
  130. package/dist/v2/embedding-backfill-x1zpc04f.js +27 -0
  131. package/dist/v2/embedding-worker-process.js +1 -1
  132. package/dist/v2/embedding-worker.js +5 -5
  133. package/dist/v2/hidden-completion.d.ts.map +1 -1
  134. package/dist/v2/{history-owner-fpka43cn.js → history-owner-ep91wgqj.js} +2 -2
  135. package/dist/v2/hooks/context.d.ts.map +1 -1
  136. package/dist/v2/hooks/usage-persist.d.ts +1 -1
  137. package/dist/v2/hooks/usage-persist.d.ts.map +1 -1
  138. package/dist/v2/hooks/usage-reading.d.ts +3 -0
  139. package/dist/v2/hooks/usage-reading.d.ts.map +1 -1
  140. package/dist/v2/{logger-4cj6d03m.js → logger-xnscpj6w.js} +1 -1
  141. package/dist/v2/{message-fts-rowid-map-qe7cpksd.js → message-fts-rowid-map-57jh6xpb.js} +4 -4
  142. package/dist/v2/{message-index-bounded-hctgp22r.js → message-index-bounded-a36rw93p.js} +12 -12
  143. package/dist/v2/{message-time-backfill-0c4h7sg6.js → message-time-backfill-baxebka0.js} +2 -2
  144. package/dist/v2/migration-worker.js +11 -11
  145. package/dist/v2/{project-embedding-registry-ek0cy0d5.js → project-embedding-registry-v2fxrs8b.js} +12 -12
  146. package/dist/v2/raw-ordinal-warmup-worker.js +8 -8
  147. package/dist/v2/{read-session-chunk-zknadvjr.js → read-session-chunk-hzhxvhyv.js} +10 -10
  148. package/dist/v2/{read-session-raw-yss2ev98.js → read-session-raw-3e482h3c.js} +2 -2
  149. package/dist/v2/{recomp-orchestrator-m5w0eqke.js → recomp-orchestrator-yzr49pd0.js} +32 -32
  150. package/dist/v2/{render-89asy54r.js → render-rhaevxv1.js} +21 -21
  151. package/dist/v2/{safe-notification-target-gphhast7.js → safe-notification-target-9r79xnbt.js} +2 -2
  152. package/dist/v2/{search-archive-axz2gbdb.js → search-archive-9924fyk8.js} +12 -12
  153. package/dist/v2/{search-kdtja5rx.js → search-ggvexvv7.js} +23 -23
  154. package/dist/v2/{send-session-notification-na3q825m.js → send-session-notification-95p89k7q.js} +5 -5
  155. package/dist/v2/{server-yyqmvbvv.js → server-016a1whm.js} +161 -102
  156. package/dist/v2/{server-z3tyd1mx.js → server-0k586y7d.js} +3 -3
  157. package/dist/v2/{server-p9s40wfa.js → server-0ms13pc8.js} +3 -0
  158. package/dist/v2/{server-e3m10ds0.js → server-16kfxcxj.js} +4 -4
  159. package/dist/v2/{server-nn4hbymt.js → server-3bfc26r7.js} +9 -9
  160. package/dist/v2/{server-7vb38e51.js → server-3jc6qmdz.js} +1 -1
  161. package/dist/v2/{server-jra7awr5.js → server-3qf9n5ck.js} +11 -11
  162. package/dist/v2/{server-69m30b21.js → server-3yk44ddz.js} +1 -1
  163. package/dist/v2/{server-2gjqhmn9.js → server-4h4acntc.js} +27 -11
  164. package/dist/v2/{server-3schkz95.js → server-58h6rrnx.js} +4 -4
  165. package/dist/v2/{server-af1rmkyn.js → server-5kgesxck.js} +2 -2
  166. package/dist/v2/{server-mfn1yf9d.js → server-7vrtk78d.js} +1 -1
  167. package/dist/v2/{server-27kccwe7.js → server-88yvx6r9.js} +63 -12
  168. package/dist/v2/{server-f0j864ma.js → server-91gb0vh8.js} +1 -1
  169. package/dist/v2/{server-131h608x.js → server-966dq3pd.js} +2 -2
  170. package/dist/v2/{server-jb6tjyeb.js → server-bb6kf05j.js} +23 -20
  171. package/dist/v2/{server-sg2qjkrb.js → server-brsx45r6.js} +6 -4
  172. package/dist/v2/{server-gwxys0d0.js → server-c8z2grq0.js} +1 -1
  173. package/dist/v2/{server-y8n33d9j.js → server-g61hgy1y.js} +4 -4
  174. package/dist/v2/{server-zahgxer8.js → server-jxrqsn84.js} +3 -3
  175. package/dist/v2/{server-2j87594q.js → server-kgq2e2hh.js} +2 -2
  176. package/dist/v2/{server-ddw42d76.js → server-mxsy9h1d.js} +2 -2
  177. package/dist/v2/{server-qmmkhz2z.js → server-np27dgyt.js} +1 -1
  178. package/dist/v2/{server-jqn7q7tm.js → server-q93jdtz8.js} +5 -5
  179. package/dist/v2/{server-dcws5831.js → server-qp5sj6n5.js} +2 -2
  180. package/dist/v2/{server-7be0ersd.js → server-rcchadw0.js} +3 -3
  181. package/dist/v2/{server-b3r080cm.js → server-rz5jnhnv.js} +1 -1
  182. package/dist/v2/{server-zt1m5rwj.js → server-sa1fdt41.js} +1 -1
  183. package/dist/v2/{server-wa4qhryh.js → server-sb55ddgn.js} +5 -4
  184. package/dist/v2/{server-4x7n5qz7.js → server-scp3y4dh.js} +13 -11
  185. package/dist/v2/{server-pej5rnye.js → server-sgn61hht.js} +2 -2
  186. package/dist/v2/{server-ypf1ap0v.js → server-t8n27rbt.js} +1 -1
  187. package/dist/v2/{server-sefxj8k1.js → server-tmf0ayqp.js} +1 -1
  188. package/dist/v2/{server-sr8tf5dt.js → server-vjadwb3j.js} +6 -5
  189. package/dist/v2/{server-bez34e60.js → server-vqq3g1t7.js} +4 -4
  190. package/dist/v2/{server-tpt7bwq8.js → server-ww7xbxxf.js} +1 -1
  191. package/dist/v2/server.js +6 -6
  192. package/dist/v2/{storage-tags-xq8hjqkf.js → storage-tags-rzv7y0n3.js} +4 -4
  193. package/dist/v2/{v2-archive-reader-ky1wqcws.js → v2-archive-reader-5ggewg8q.js} +1 -1
  194. package/dist/v2/{wrapup-orchestrator-6wt67saz.js → wrapup-orchestrator-36c5wyvq.js} +32 -32
  195. package/dist/{v2-archive-reader-665x2x4d.js → v2-archive-reader-gx5ke1d7.js} +1 -1
  196. package/dist/wrapup-orchestrator-ya31knav.js +55 -0
  197. package/package.json +1 -1
  198. package/src/config/index.test.ts +20 -0
  199. package/src/config/project-security.test.ts +5 -1
  200. package/src/config/project-security.ts +4 -0
  201. package/src/config/schema/magic-context.test.ts +43 -0
  202. package/src/config/schema/magic-context.ts +19 -0
  203. package/src/shared/data-path.test.ts +104 -56
  204. package/src/shared/data-path.ts +30 -30
  205. package/src/shared/hidden-model-cooldown.test.ts +117 -0
  206. package/src/shared/hidden-model-cooldown.ts +123 -0
  207. package/src/shared/model-suggestion-retry.test.ts +53 -76
  208. package/src/shared/model-suggestion-retry.ts +38 -53
  209. package/src/shared/provider-response-completion.test.ts +49 -0
  210. package/src/shared/provider-response-completion.ts +64 -0
  211. package/src/shared/rpc-types.ts +1 -0
  212. package/src/shared/startup-maintenance-policy.test.ts +115 -0
  213. package/src/shared/status-detail-text.test.ts +7 -0
  214. package/src/shared/status-summary.ts +3 -0
  215. package/src/shared/status-view-check.ts +1 -0
  216. package/src/shared/status-view.test.ts +15 -0
  217. package/src/shared/status-view.ts +11 -1
  218. package/src/shared/test-db.test.ts +84 -0
  219. package/src/shared/test-db.ts +36 -0
  220. package/dist/embedding-backfill-kpy5shsa.js +0 -28
  221. package/dist/index-g2q4htwp.js +0 -146
  222. package/dist/render-mnqc74ar.js +0 -44
  223. package/dist/v2/embedding-backfill-360efh1t.js +0 -27
  224. package/dist/wrapup-orchestrator-7kmb3jf9.js +0 -56
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/opencode-magic-context",
3
- "version": "0.49.48",
3
+ "version": "0.49.50",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",
@@ -704,6 +704,26 @@ describe("loadPluginConfig — secret redaction", () => {
704
704
  expect(result.embedding.model).toBe("repo-model");
705
705
  expect(result.configWarnings?.join("\n")).toContain("embedding.endpoint/provider");
706
706
  });
707
+
708
+ it("ignores a project embedding.dimensions override while the user width still applies", () => {
709
+ const userConfig = JSON.stringify({
710
+ embedding: {
711
+ provider: "openai-compatible",
712
+ endpoint: "https://trusted.example/v1",
713
+ model: "qwen/qwen3-embedding-8b",
714
+ dimensions: 768,
715
+ },
716
+ });
717
+ const projectConfig = JSON.stringify({ embedding: { dimensions: 4096 } });
718
+
719
+ const result = loadWithUserAndProjectConfig(userConfig, projectConfig);
720
+
721
+ expect(result.embedding.provider).toBe("openai-compatible");
722
+ if (result.embedding.provider === "openai-compatible") {
723
+ expect(result.embedding.dimensions).toBe(768);
724
+ }
725
+ expect(result.configWarnings?.join("\n")).toContain("dimensions");
726
+ });
707
727
  });
708
728
 
709
729
  describe("loadPluginConfig — experimental graduation migration", () => {
@@ -173,6 +173,7 @@ describe("stripUnsafeProjectConfigFields", () => {
173
173
  query_input_type: "query",
174
174
  query_instruction: "repo-controlled instruction",
175
175
  document_prefix: "repo-controlled document prefix",
176
+ dimensions: 1,
176
177
  },
177
178
  };
178
179
 
@@ -185,9 +186,12 @@ describe("stripUnsafeProjectConfigFields", () => {
185
186
  expect(embedding.query_input_type).toBe("query");
186
187
  expect(embedding.query_instruction).toBeUndefined();
187
188
  expect(embedding.document_prefix).toBeUndefined();
189
+ expect(embedding.dimensions).toBeUndefined();
188
190
  expect(
189
191
  warnings.some((w) =>
190
- w.includes("embedding.endpoint/provider/query_instruction/document_prefix"),
192
+ w.includes(
193
+ "embedding.endpoint/provider/query_instruction/document_prefix/dimensions",
194
+ ),
191
195
  ),
192
196
  ).toBe(true);
193
197
  });
@@ -64,6 +64,10 @@ const EMBEDDING_USER_ONLY_FIELDS = [
64
64
  "fallback_provider",
65
65
  "query_instruction",
66
66
  "document_prefix",
67
+ // Per-request output width. A repository choosing it changes the stored-vector
68
+ // identity (one re-embed of the project's history) and, if the pinned endpoint
69
+ // ignores or rejects that width, breaks embedding and semantic search outright.
70
+ "dimensions",
67
71
  ] as const;
68
72
  const PERCENTAGE_THRESHOLD_REASON =
69
73
  "security: a repository may only raise compaction thresholds above the user's effective value; it cannot force earlier historian work or cloned-repo cost escalation.";
@@ -770,6 +770,49 @@ describe("MagicContextConfigSchema", () => {
770
770
  ).toMatchObject({ query_instruction: false });
771
771
  });
772
772
 
773
+ it("preserves embedding.dimensions through the schema transform", () => {
774
+ const parsed = MagicContextConfigSchema.parse({
775
+ embedding: {
776
+ provider: "openai-compatible",
777
+ endpoint: "http://localhost:1234/v1",
778
+ model: "qwen/qwen3-embedding-8b",
779
+ dimensions: 768,
780
+ },
781
+ }).embedding;
782
+
783
+ expect(parsed).toMatchObject({ dimensions: 768 });
784
+ // The transform rebuilds the object field by field; a field it forgets
785
+ // is silently dropped and the wire request loses the parameter.
786
+ expect("dimensions" in parsed).toBe(true);
787
+ });
788
+
789
+ it("omits embedding.dimensions from the resolved config when unset", () => {
790
+ const parsed = MagicContextConfigSchema.parse({
791
+ embedding: {
792
+ provider: "openai-compatible",
793
+ endpoint: "http://localhost:1234/v1",
794
+ model: "text-embedding-3-small",
795
+ },
796
+ }).embedding;
797
+
798
+ expect("dimensions" in parsed).toBe(false);
799
+ });
800
+
801
+ it("rejects a non-positive or non-integer embedding.dimensions", () => {
802
+ for (const dimensions of [0, -768, 1.5]) {
803
+ expect(
804
+ MagicContextConfigSchema.safeParse({
805
+ embedding: {
806
+ provider: "openai-compatible",
807
+ endpoint: "http://localhost:1234/v1",
808
+ model: "text-embedding-3-small",
809
+ dimensions,
810
+ },
811
+ }).success,
812
+ ).toBe(false);
813
+ }
814
+ });
815
+
773
816
  it("defaults local embedding runtime to auto and accepts explicit overrides", () => {
774
817
  expect(
775
818
  MagicContextConfigSchema.parse({ embedding: { provider: "local" } }).embedding,
@@ -795,6 +795,15 @@ const BaseEmbeddingConfigSchema = z
795
795
  .describe(
796
796
  "Optional truncate mode sent in the embedding request body (e.g. NVIDIA NIM accepts 'NONE' | 'START' | 'END'). Omitted from the request when unset.",
797
797
  ),
798
+ dimensions: z
799
+ .number()
800
+ .int()
801
+ .min(1)
802
+ .max(8192)
803
+ .optional()
804
+ .describe(
805
+ "Optional output width for Matryoshka embedding models (e.g. Qwen3-Embedding-8B accepts 768 | 1024 | 2048 | 4096; OpenAI text-embedding-3-* accept smaller widths than native). Sent as the OpenAI-compatible `dimensions` request field. Omitted from the request when unset, so the endpoint default applies. Changing it changes the produced vectors and folds into the embedding model identity, so switching widths re-embeds rather than mixing vector spaces. Not supported for the local provider, and ignored from project config like the other embedding fields (a repository cannot choose how private text is embedded).",
806
+ ),
798
807
  max_input_tokens: z
799
808
  .number()
800
809
  .int()
@@ -864,6 +873,12 @@ export const EmbeddingConfigSchema = BaseEmbeddingConfigSchema.transform((data)
864
873
  ...(model ? { model } : {}),
865
874
  ...(endpoint ? { endpoint } : {}),
866
875
  ...(apiKey ? { api_key: apiKey } : {}),
876
+ // dimensions is carried on the synapse block ONLY so it survives to
877
+ // the openai-compatible fallback lane (fallbackConfig rebuilds that
878
+ // provider from this object). Synapse's own lane ignores it — its
879
+ // width is pinned from the first embed response, and a static width
880
+ // here would fight that.
881
+ ...(data.dimensions ? { dimensions: data.dimensions } : {}),
867
882
  ...(inputType ? { input_type: inputType } : {}),
868
883
  ...(queryInputType ? { query_input_type: queryInputType } : {}),
869
884
  ...(data.query_instruction !== undefined
@@ -902,6 +917,10 @@ export const EmbeddingConfigSchema = BaseEmbeddingConfigSchema.transform((data)
902
917
  provider: "openai-compatible" as const,
903
918
  model: data.model?.trim() ?? "",
904
919
  endpoint: data.endpoint?.trim() ?? "",
920
+ // dimensions is spread CONDITIONALLY (mirrors truncate/local_dtype):
921
+ // omitting it when unset keeps the identity byte-identical for every
922
+ // existing config, so adding this field forces no global re-embed.
923
+ ...(data.dimensions ? { dimensions: data.dimensions } : {}),
905
924
  ...(apiKey ? { api_key: apiKey } : {}),
906
925
  ...(inputType ? { input_type: inputType } : {}),
907
926
  ...(queryInputType ? { query_input_type: queryInputType } : {}),
@@ -1,5 +1,13 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
- import { mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
1
+ import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
2
+ import {
3
+ existsSync,
4
+ mkdirSync,
5
+ readFileSync,
6
+ rmSync,
7
+ statSync,
8
+ symlinkSync,
9
+ writeFileSync,
10
+ } from "node:fs";
3
11
  import * as os from "node:os";
4
12
  import * as path from "node:path";
5
13
  import {
@@ -16,6 +24,7 @@ import {
16
24
  getProjectMagicContextHistorianDir,
17
25
  isMagicContextStorageOutsideEngram,
18
26
  } from "./data-path";
27
+ import * as logger from "./logger";
19
28
  import { createTestTempDirFromPath } from "./test-temp-dir";
20
29
 
21
30
  const savedEnv = {
@@ -320,63 +329,102 @@ describe("data-path", () => {
320
329
  });
321
330
 
322
331
  describe("ensureCortexKitArtifactGitignore", () => {
323
- test("creates .cortexkit/.gitignore with a fenced magic-context block", () => {
324
- const dir = createTestTempDirFromPath(path.join(os.tmpdir(), "mc-gi-"));
325
- try {
326
- ensureCortexKitArtifactGitignore(dir);
327
- const gi = readFileSync(path.join(dir, ".cortexkit", ".gitignore"), "utf8");
328
- expect(gi).toContain("# >>> cortexkit:magic-context");
329
- expect(gi).toContain("magic-context/");
330
- expect(gi).toContain("# <<< cortexkit:magic-context");
331
- } finally {
332
- rmSync(dir, { recursive: true, force: true });
333
- }
334
- });
335
-
336
- test("is idempotent — a second call does not duplicate the block", () => {
337
- const dir = createTestTempDirFromPath(path.join(os.tmpdir(), "mc-gi-"));
338
- try {
339
- ensureCortexKitArtifactGitignore(dir);
340
- ensureCortexKitArtifactGitignore(dir);
341
- const gi = readFileSync(path.join(dir, ".cortexkit", ".gitignore"), "utf8");
342
- const occurrences = gi.split("# >>> cortexkit:magic-context").length - 1;
343
- expect(occurrences).toBe(1);
344
- } finally {
345
- rmSync(dir, { recursive: true, force: true });
346
- }
347
- });
348
-
349
- test("preserves a sibling module's existing entries (appends, never clobbers)", () => {
350
- const dir = createTestTempDirFromPath(path.join(os.tmpdir(), "mc-gi-"));
351
- try {
352
- const ckDir = path.join(dir, ".cortexkit");
353
- mkdirSync(ckDir, { recursive: true });
354
- // Simulate a sibling (e.g. AFT) already owning a fenced block.
355
- writeFileSync(
356
- path.join(ckDir, ".gitignore"),
357
- "# >>> cortexkit:aft\naft/scratch/\n# <<< cortexkit:aft\n",
358
- );
359
- ensureCortexKitArtifactGitignore(dir);
360
- const gi = readFileSync(path.join(ckDir, ".gitignore"), "utf8");
361
- expect(gi).toContain("# >>> cortexkit:aft");
362
- expect(gi).toContain("aft/scratch/");
363
- expect(gi).toContain("# >>> cortexkit:magic-context");
364
- expect(gi).toContain("magic-context/");
365
- } finally {
366
- rmSync(dir, { recursive: true, force: true });
367
- }
368
- });
369
-
370
- test("does not ignore the project config — only the artifact dir", () => {
332
+ const dirs: string[] = [];
333
+ const legacy = "# >>> cortexkit:magic-context\nmagic-context/\n# <<< cortexkit:magic-context\n";
334
+ function fixture() {
371
335
  const dir = createTestTempDirFromPath(path.join(os.tmpdir(), "mc-gi-"));
336
+ dirs.push(dir);
337
+ mkdirSync(path.join(dir, ".cortexkit"), { recursive: true });
338
+ return {
339
+ dir,
340
+ shared: path.join(dir, ".cortexkit/.gitignore"),
341
+ nested: path.join(dir, ".cortexkit/magic-context/.gitignore"),
342
+ };
343
+ }
344
+ afterEach(() => {
345
+ for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
346
+ });
347
+
348
+ test("creates only the self-ignoring nested file and does not rewrite matching bytes", () => {
349
+ const { dir, nested, shared } = fixture();
350
+ ensureCortexKitArtifactGitignore(dir);
351
+ expect(readFileSync(nested, "utf8")).toBe("*\n");
352
+ const before = statSync(nested).mtimeMs;
353
+ ensureCortexKitArtifactGitignore(dir);
354
+ expect(statSync(nested).mtimeMs).toBe(before);
355
+ expect(existsSync(shared)).toBe(false);
356
+ });
357
+
358
+ test.each([
359
+ "",
360
+ "*",
361
+ "*\r\n",
362
+ "artifacts/\n",
363
+ ])("repairs differing nested bytes %j", (existing) => {
364
+ const { dir, nested } = fixture();
365
+ mkdirSync(path.dirname(nested), { recursive: true });
366
+ writeFileSync(nested, existing);
367
+ ensureCortexKitArtifactGitignore(dir);
368
+ expect(readFileSync(nested, "utf8")).toBe("*\n");
369
+ });
370
+
371
+ test.each([
372
+ legacy,
373
+ ` \r\n\t\n${legacy}\n `,
374
+ legacy.replaceAll("\n", "\r\n"),
375
+ legacy.trimEnd(),
376
+ ])("deletes the old shared file when only our block and whitespace remain %j", (existing) => {
377
+ const { dir, nested, shared } = fixture();
378
+ writeFileSync(shared, existing);
379
+ ensureCortexKitArtifactGitignore(dir);
380
+ expect(readFileSync(nested, "utf8")).toBe("*\n");
381
+ expect(existsSync(shared)).toBe(false);
382
+ });
383
+
384
+ test("removes our complete blocks while preserving every other byte", () => {
385
+ const { dir, shared } = fixture();
386
+ const prefix = "# café\r\n# >>> cortexkit:aft\r\naft/scratch/\r\n# <<< cortexkit:aft\r\n\n";
387
+ const suffix = "# >>> cortexkit:other\nother/\n# <<< cortexkit:other\nlast-without-newline";
388
+ writeFileSync(shared, prefix + legacy.replaceAll("\n", "\r\n") + legacy + suffix);
389
+ ensureCortexKitArtifactGitignore(dir);
390
+ ensureCortexKitArtifactGitignore(dir);
391
+ expect(readFileSync(shared)).toEqual(Buffer.from(prefix + suffix));
392
+ });
393
+
394
+ test("shared cleanup preserves non-UTF8 bytes outside our block", () => {
395
+ const { dir, shared } = fixture();
396
+ const prefix = Buffer.from([0xff, 0x80, 0x0a]);
397
+ const suffix = Buffer.from("# >>> cortexkit:aft\naft/\n# <<< cortexkit:aft\n");
398
+ writeFileSync(shared, Buffer.concat([prefix, Buffer.from(legacy), suffix]));
399
+ ensureCortexKitArtifactGitignore(dir);
400
+ expect(readFileSync(shared)).toEqual(Buffer.concat([prefix, suffix]));
401
+ });
402
+
403
+ test.each([
404
+ "# >>> cortexkit:aft\naft/scratch/\n# <<< cortexkit:aft\n",
405
+ "# >>> cortexkit:magic-context\nmagic-context/\n# >>> cortexkit:aft\naft/\n# <<< cortexkit:aft\n# <<< cortexkit:magic-context\n",
406
+ "prefix # >>> cortexkit:magic-context\nmagic-context/\n# <<< cortexkit:magic-context\n",
407
+ ])("leaves unowned or incomplete shared blocks unchanged %j", (existing) => {
408
+ const { dir, shared } = fixture();
409
+ writeFileSync(shared, existing);
410
+ ensureCortexKitArtifactGitignore(dir);
411
+ expect(readFileSync(shared)).toEqual(Buffer.from(existing));
412
+ });
413
+
414
+ test("logs a nested write failure without throwing or retiring the shared rule", () => {
415
+ const { dir, nested, shared } = fixture();
416
+ mkdirSync(nested, { recursive: true });
417
+ writeFileSync(shared, legacy);
418
+ const logged = spyOn(logger, "log").mockImplementation(() => {});
372
419
  try {
373
- ensureCortexKitArtifactGitignore(dir);
374
- const gi = readFileSync(path.join(dir, ".cortexkit", ".gitignore"), "utf8");
375
- // The config file stays tracked: it must NOT appear as an ignore.
376
- expect(gi).not.toContain("magic-context.jsonc");
377
- expect(gi).not.toContain("*.jsonc");
420
+ expect(() => ensureCortexKitArtifactGitignore(dir)).not.toThrow();
421
+ expect(readFileSync(shared, "utf8")).toBe(legacy);
422
+ expect(logged).toHaveBeenCalledWith("Failed to ensure project artifact gitignore", {
423
+ directory: dir,
424
+ error: expect.any(String),
425
+ });
378
426
  } finally {
379
- rmSync(dir, { recursive: true, force: true });
427
+ logged.mockRestore();
380
428
  }
381
429
  });
382
430
  });
@@ -5,11 +5,13 @@ import {
5
5
  readFileSync,
6
6
  readlinkSync,
7
7
  realpathSync,
8
+ unlinkSync,
8
9
  writeFileSync,
9
10
  } from "node:fs";
10
11
  import * as os from "node:os";
11
12
  import * as path from "node:path";
12
13
  import { getHarness, type HarnessId } from "./harness";
14
+ import { log } from "./logger";
13
15
  import { createTestTempDir } from "./test-temp-dir";
14
16
 
15
17
  export function getDataDir(): string {
@@ -90,8 +92,8 @@ export function getMagicContextHistorianDir(harness: HarnessId = getHarness()):
90
92
  *
91
93
  * `.cortexkit/` is the shared CortexKit per-project dir (also holds the
92
94
  * project config `magic-context.jsonc`). Because these artifacts are transient
93
- * debug dumps that shouldn't dirty the user's repo, the first write also drops
94
- * a fenced-block `.gitignore` entry ignoring this subdir (see
95
+ * debug dumps that shouldn't dirty the user's repo, each writer ensures a
96
+ * self-ignoring `.gitignore` inside this subdir (see
95
97
  * ensureCortexKitArtifactGitignore) while leaving `*.jsonc` config tracked.
96
98
  *
97
99
  * Migration note: artifacts used to live under `.opencode/magic-context/`. We
@@ -106,47 +108,45 @@ export function getProjectMagicContextDir(directory: string): string {
106
108
  return path.join(directory, ".cortexkit", "magic-context");
107
109
  }
108
110
 
109
- const GITIGNORE_GUARD_OPEN = "# >>> cortexkit:magic-context";
110
- const GITIGNORE_GUARD_CLOSE = "# <<< cortexkit:magic-context";
111
-
112
111
  /**
113
- * Ensure `<project>/.cortexkit/.gitignore` ignores Magic Context's transient
114
- * artifact subdir (`magic-context/`) without touching anything else in the
115
- * shared `.cortexkit/` dir — the project config `magic-context.jsonc` stays
116
- * tracked, and any sibling module's (e.g. AFT's) entries are preserved.
117
- *
118
- * Uses the shared CortexKit fenced-block convention: each module owns exactly
119
- * its `# >>> cortexkit:<module>` … `# <<< cortexkit:<module>` block and appends
120
- * it idempotently (no-op when its own guard line is already present). This lets
121
- * multiple cortexkit modules coexist in one `.gitignore` without clobbering.
112
+ * Hide artifacts and their ignore file without hiding the sibling project
113
+ * config. Retire our old shared-file block only after the nested rule is ready,
114
+ * preserving all bytes outside our complete fences.
122
115
  *
123
116
  * Best-effort: a write failure never blocks an artifact write (the caller
124
117
  * already degrades gracefully on its own write failures).
125
118
  */
126
119
  export function ensureCortexKitArtifactGitignore(directory: string): void {
127
120
  try {
128
- const cortexKitDir = path.join(directory, ".cortexkit");
129
- const gitignorePath = path.join(cortexKitDir, ".gitignore");
130
- let existing = "";
131
- if (existsSync(gitignorePath)) {
132
- existing = readFileSync(gitignorePath, "utf8");
133
- // Already fenced by us — nothing to do.
134
- if (existing.includes(GITIGNORE_GUARD_OPEN)) return;
121
+ const artifactDir = getProjectMagicContextDir(directory);
122
+ const gitignorePath = path.join(artifactDir, ".gitignore");
123
+ mkdirSync(artifactDir, { recursive: true });
124
+ if (!existsSync(gitignorePath) || readFileSync(gitignorePath, "utf8") !== "*\n") {
125
+ writeFileSync(gitignorePath, "*\n", "utf8");
135
126
  }
136
- const block = `${GITIGNORE_GUARD_OPEN}\nmagic-context/\n${GITIGNORE_GUARD_CLOSE}\n`;
137
- const needsLeadingNewline = existing.length > 0 && !existing.endsWith("\n");
138
- const next = existing + (needsLeadingNewline ? "\n" : "") + block;
139
- mkdirSync(cortexKitDir, { recursive: true });
140
- writeFileSync(gitignorePath, next, "utf8");
141
- } catch {
142
- // best-effort — never block an artifact write on the gitignore.
127
+
128
+ const sharedPath = path.join(directory, ".cortexkit", ".gitignore");
129
+ if (!existsSync(sharedPath)) return;
130
+ // A byte-preserving encoding keeps even non-UTF8 sibling entries intact.
131
+ const existing = readFileSync(sharedPath).toString("latin1");
132
+ // Do not cross another module's fence if an old block is incomplete.
133
+ const next = existing.replace(
134
+ /^# >>> cortexkit:magic-context\r?\n(?:(?!^# (?:>>>|<<<) cortexkit:)[\s\S])*?^# <<< cortexkit:magic-context(?:\r?\n|$)/gm,
135
+ "",
136
+ );
137
+ if (next === existing) return;
138
+ const remaining = Buffer.from(next, "latin1");
139
+ if (remaining.toString("utf8").trim() === "") unlinkSync(sharedPath);
140
+ else writeFileSync(sharedPath, remaining);
141
+ } catch (error) {
142
+ log("Failed to ensure project artifact gitignore", { directory, error: String(error) });
143
143
  }
144
144
  }
145
145
 
146
146
  /**
147
147
  * Project-local historian artifact directory.
148
148
  *
149
- * Layout: `<project-directory>/.opencode/magic-context/historian/`
149
+ * Layout: `<project-directory>/.cortexkit/magic-context/historian/`
150
150
  *
151
151
  * Used for:
152
152
  * - existing-state offload XMLs that long historian/recomp passes write
@@ -154,7 +154,7 @@ export function ensureCortexKitArtifactGitignore(directory: string): void {
154
154
  * - validation-failure dump XMLs preserved for debugging
155
155
  *
156
156
  * Callers must `mkdirSync(dir, { recursive: true })` before writing — the
157
- * `.opencode/` parent may not exist on a fresh project, and write failures
157
+ * `.cortexkit/` parent may not exist on a fresh project, and write failures
158
158
  * here must degrade gracefully (e.g. historian falls back to inline state).
159
159
  */
160
160
  export function getProjectMagicContextHistorianDir(directory: string): string {
@@ -0,0 +1,117 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { HiddenModelCooldowns } from "./hidden-model-cooldown";
3
+
4
+ const epoch = Date.parse("2026-10-08T00:00:00Z");
5
+ const refusal = (seconds: string, statusCode = 412) => ({
6
+ name: "APIError",
7
+ data: { statusCode, responseHeaders: { "retry-after": seconds }, isRetryable: false },
8
+ });
9
+
10
+ describe("hidden model quota cooldown", () => {
11
+ test("structured quota refusal skips across runs, expires, and is removed", () => {
12
+ let now = epoch;
13
+ const table = new HiddenModelCooldowns(() => now);
14
+ const messages: string[] = [];
15
+ table.record("google/primary", refusal("190000"));
16
+ expect(
17
+ table.startIndex(["google/primary", "other/fallback"], (line) => messages.push(line)),
18
+ ).toBe(1);
19
+ expect(messages).toEqual([
20
+ "skipping google/primary until 2026-10-10T04:46:40.000Z: provider said to retry later",
21
+ ]);
22
+ now += 190_000_000;
23
+ expect(table.startIndex(["google/primary", "other/fallback"], () => {})).toBe(0);
24
+ expect(table.live()).toEqual([]);
25
+ });
26
+
27
+ test("success clears a model and providers have independent keys", () => {
28
+ const table = new HiddenModelCooldowns(() => epoch);
29
+ table.record("one/model", refusal("120"));
30
+ table.record("two/model", refusal("180"));
31
+ table.succeeded("one/model");
32
+ expect(table.live().map((entry) => entry.model)).toEqual(["two/model"]);
33
+ expect(table.startIndex(["one/model", "two/model"], () => {})).toBe(0);
34
+ });
35
+
36
+ test("all unavailable models still try the soonest, preserving subsequent fallback order", () => {
37
+ const table = new HiddenModelCooldowns(() => epoch);
38
+ for (const [model, delay] of [
39
+ ["p/first", "300"],
40
+ ["p/second", "120"],
41
+ ["p/third", "200"],
42
+ ])
43
+ table.record(model, refusal(delay));
44
+ expect(table.startIndex(["p/first", "p/second", "p/third"], () => {})).toBe(1);
45
+ expect(table.startIndex(["p/first"], () => {})).toBe(0);
46
+ });
47
+
48
+ test("clamps long windows to seven days and leaves ordinary retries at sixty seconds alone", () => {
49
+ const table = new HiddenModelCooldowns(() => epoch);
50
+ table.record("p/long", refusal("99999999"));
51
+ table.record("p/short", refusal("60"));
52
+ table.record("p/above-floor", refusal("61"));
53
+ expect(table.live()).toEqual([
54
+ {
55
+ model: "p/long",
56
+ until: epoch + 604_800_000,
57
+ reason: "provider said to retry later",
58
+ },
59
+ {
60
+ model: "p/above-floor",
61
+ until: epoch + 61_000,
62
+ reason: "provider said to retry later",
63
+ },
64
+ ]);
65
+ });
66
+
67
+ test("accepts HTTP dates and OpenCode 2.2 millisecond delays with not-now statuses", () => {
68
+ const table = new HiddenModelCooldowns(() => epoch);
69
+ table.record("p/date", refusal("Thu, 08 Oct 2026 00:02:00 GMT", 429));
70
+ table.record("p/oc2", {
71
+ type: "provider.overloaded",
72
+ status: 503,
73
+ retryAfterMs: 190_000_000,
74
+ });
75
+ table.record("p/sdk", {
76
+ statusCode: 412,
77
+ data: { error: "quota" },
78
+ responseHeaders: { "Retry-After": "120" },
79
+ });
80
+ table.record("p/rfc850", refusal("Thursday, 08-Oct-26 00:02:00 GMT"));
81
+ table.record("p/asctime", refusal("Thu Oct 8 00:02:00 2026"));
82
+ expect(table.live().map((entry) => entry.until)).toEqual([
83
+ epoch + 120_000,
84
+ epoch + 190_000_000,
85
+ epoch + 120_000,
86
+ epoch + 120_000,
87
+ epoch + 120_000,
88
+ ]);
89
+ });
90
+
91
+ test("ignores missing, invalid, nonfinite, past and prose reset times and unrelated failures", () => {
92
+ const table = new HiddenModelCooldowns(() => epoch);
93
+ const failures: unknown[] = [
94
+ { data: { statusCode: 412, message: "Quota resets in 52h 38m" } },
95
+ { type: "provider.rate-limit", status: 429, message: "Quota exhausted" },
96
+ new Error("timeout"),
97
+ refusal("190000", 500),
98
+ refusal("190000", 401),
99
+ refusal("190000", 404),
100
+ ...[
101
+ "0",
102
+ "-1",
103
+ "1.5",
104
+ "NaN",
105
+ "Infinity",
106
+ "1e10",
107
+ "52h 38m",
108
+ "120 seconds",
109
+ "Wed, 07 Oct 2026 00:00:00 GMT",
110
+ ].map((delay) => refusal(delay)),
111
+ { status: 429, retryAfterMs: Number.POSITIVE_INFINITY },
112
+ { status: 429, retryAfterMs: Number.NaN },
113
+ ];
114
+ for (const error of failures) table.record("p/model", error);
115
+ expect(table.live()).toEqual([]);
116
+ });
117
+ });