@cortexkit/opencode-magic-context 0.49.86 → 0.49.89

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 (182) hide show
  1. package/dist/{announcement-fnyxaahs.js → announcement-4ynkaf0d.js} +2 -2
  2. package/dist/auto-search-worker.js +13 -7
  3. package/dist/chunk-embedding-write-worker.js +7 -7
  4. package/dist/{compartment-chunk-embedding-ymc9mtwv.js → compartment-chunk-embedding-fey2bsyf.js} +3 -1
  5. package/dist/{conflict-warning-hook-a0wrnzch.js → conflict-warning-hook-kbq6ppjf.js} +2 -2
  6. package/dist/{context-xesm7rj3.js → context-grdg1k2k.js} +132 -52
  7. package/dist/{derive-budgets-90869322.js → derive-budgets-hzzq71rm.js} +2 -2
  8. package/dist/{embedding-backfill-v6sw58m8.js → embedding-backfill-qjkaee9s.js} +8 -8
  9. package/dist/{v2/embedding-cache-mgyr73ef.js → embedding-cache-zn4r1c31.js} +5 -1
  10. package/dist/embedding-worker.js +2 -2
  11. package/dist/features/magic-context/compartment-chunk-embedding.d.ts +1 -0
  12. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  13. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  14. package/dist/features/magic-context/dreamer/token-budget.d.ts +8 -3
  15. package/dist/features/magic-context/dreamer/token-budget.d.ts.map +1 -1
  16. package/dist/features/magic-context/memory/embedding-cache.d.ts +7 -0
  17. package/dist/features/magic-context/memory/embedding-cache.d.ts.map +1 -1
  18. package/dist/features/magic-context/search.d.ts +6 -0
  19. package/dist/features/magic-context/search.d.ts.map +1 -1
  20. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  21. package/dist/features/magic-context/tool-definition-tokens.d.ts +2 -0
  22. package/dist/features/magic-context/tool-definition-tokens.d.ts.map +1 -1
  23. package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
  24. package/dist/hooks/magic-context/auto-search-worker-probe.fixture.d.ts +2 -0
  25. package/dist/hooks/magic-context/auto-search-worker-probe.fixture.d.ts.map +1 -0
  26. package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
  27. package/dist/hooks/magic-context/compartment-runner-recomp-carry.d.ts +4 -0
  28. package/dist/hooks/magic-context/compartment-runner-recomp-carry.d.ts.map +1 -0
  29. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts +8 -2
  30. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  31. package/dist/hooks/magic-context/dropped-input-guard.d.ts.map +1 -1
  32. package/dist/hooks/magic-context/emergency-fail-closed.d.ts +2 -0
  33. package/dist/hooks/magic-context/emergency-fail-closed.d.ts.map +1 -1
  34. package/dist/hooks/magic-context/recomp-orchestrator.d.ts +3 -5
  35. package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/send-session-notification.d.ts +11 -1
  37. package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
  38. package/dist/hooks/magic-context/transform.d.ts +1 -0
  39. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  40. package/dist/{index-s8ks5nz4.js → index-2pdgy88n.js} +5 -5
  41. package/dist/{index-7j2zv9nm.js → index-2qsca7h7.js} +47 -11
  42. package/dist/{index-1bqkqde0.js → index-39rzef89.js} +9 -7
  43. package/dist/{index-snbpdpa3.js → index-3pdknr07.js} +4 -4
  44. package/dist/{index-c5tmzym6.js → index-5df2fw5b.js} +108 -13
  45. package/dist/{index-7svecf3m.js → index-5pgyqgmx.js} +1 -1
  46. package/dist/{index-xrnhxkz7.js → index-60wnwcwz.js} +1 -1
  47. package/dist/{index-k50xhjw1.js → index-60x5d68t.js} +1 -1
  48. package/dist/{index-4ntnt8ee.js → index-61knrt52.js} +1 -1
  49. package/dist/{index-g6hfh4h4.js → index-6zewd2n5.js} +14 -8
  50. package/dist/{index-70cv85b0.js → index-78t37mcq.js} +2 -2
  51. package/dist/{index-stx8zd81.js → index-83qd3n7s.js} +2 -2
  52. package/dist/{index-nny4gm06.js → index-9d3qgwq0.js} +2 -2
  53. package/dist/{index-jjvbk92s.js → index-9emdjcb5.js} +1 -1
  54. package/dist/{index-05bm2ndp.js → index-chpzb6xy.js} +1 -1
  55. package/dist/{index-2kf73btc.js → index-cr483vx6.js} +1 -1
  56. package/dist/{index-d0rtbv0f.js → index-dk3hy2a2.js} +21 -14
  57. package/dist/{index-gxdc95cp.js → index-g0mb2kb4.js} +585 -82
  58. package/dist/{index-w6v4dw5f.js → index-h9hybzr5.js} +5 -5
  59. package/dist/{index-1pf5qrx4.js → index-jzfsnbmm.js} +3 -3
  60. package/dist/{index-jrj95cce.js → index-m6dnydf8.js} +9 -2
  61. package/dist/{index-xccywqdj.js → index-mrjat4eq.js} +77 -14
  62. package/dist/{index-022w6314.js → index-n1ty0vd3.js} +116 -512
  63. package/dist/{index-ttk3trse.js → index-q7msfgwz.js} +311 -111
  64. package/dist/{index-e32b3x4n.js → index-qfcjrnpe.js} +7 -6
  65. package/dist/{v2/server-4dhv7mqz.js → index-qjwpqvnf.js} +48 -1
  66. package/dist/{index-3dtzyred.js → index-r4y0dczp.js} +1 -1
  67. package/dist/{index-4w5rx7de.js → index-tt0vs4x5.js} +2 -2
  68. package/dist/{index-k0tb2z28.js → index-w51n3576.js} +2 -2
  69. package/dist/{index-25nktq8n.js → index-wmb2mcdw.js} +7 -7
  70. package/dist/{index-zmqx48vt.js → index-xsqw8kbd.js} +1 -1
  71. package/dist/{index-fzgyvsb1.js → index-y14pawe1.js} +3 -0
  72. package/dist/{index-798s7c8s.js → index-zxhev8ze.js} +2 -2
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +68 -59
  75. package/dist/{message-index-bounded-6fr624zf.js → message-index-bounded-r1qys471.js} +4 -4
  76. package/dist/migration-worker.js +5 -5
  77. package/dist/plugin/messages-transform.d.ts +3 -4
  78. package/dist/plugin/messages-transform.d.ts.map +1 -1
  79. package/dist/plugin/refusal-notice.d.ts +3 -0
  80. package/dist/plugin/refusal-notice.d.ts.map +1 -0
  81. package/dist/{project-embedding-registry-q80scexh.js → project-embedding-registry-m3fp1pa4.js} +7 -7
  82. package/dist/raw-ordinal-warmup-worker.js +4 -4
  83. package/dist/{read-session-chunk-6wedfths.js → read-session-chunk-xv9f0wgb.js} +3 -3
  84. package/dist/{recomp-orchestrator-7ecg8ryx.js → recomp-orchestrator-dgyb394j.js} +23 -23
  85. package/dist/{render-yqp7q79f.js → render-d014e603.js} +12 -12
  86. package/dist/{rpc-notifications-t9q0ynq7.js → rpc-notifications-ta2zsxpq.js} +1 -1
  87. package/dist/{search-bw22d7zc.js → search-9gceftb9.js} +18 -18
  88. package/dist/{search-archive-r4h96j2z.js → search-archive-gybn6q7s.js} +5 -5
  89. package/dist/{send-session-notification-7x518gew.js → send-session-notification-gzxz88vq.js} +1 -1
  90. package/dist/shared/assistant-message-extractor.d.ts +2 -0
  91. package/dist/shared/assistant-message-extractor.d.ts.map +1 -1
  92. package/dist/shared/prompt-async-transport.d.ts.map +1 -1
  93. package/dist/shared/recomp-outcome.d.ts +4 -0
  94. package/dist/shared/recomp-outcome.d.ts.map +1 -0
  95. package/dist/shared/rpc-notifications.d.ts +1 -1
  96. package/dist/shared/rpc-notifications.d.ts.map +1 -1
  97. package/dist/shared/storage-permissions.d.ts +16 -2
  98. package/dist/shared/storage-permissions.d.ts.map +1 -1
  99. package/dist/shared/user-facing-codes.d.ts +4 -1
  100. package/dist/shared/user-facing-codes.d.ts.map +1 -1
  101. package/dist/{storage-memory-e6a7mb0k.js → storage-memory-hhrvfw0x.js} +2 -2
  102. package/dist/{storage-tags-y2mrb8e6.js → storage-tags-f1ftvjpw.js} +2 -2
  103. package/dist/{transform-postprocess-phase-t99yj9vt.js → transform-postprocess-phase-34k1zwsy.js} +24 -24
  104. package/dist/v2/auto-search-worker.js +13 -7
  105. package/dist/v2/chunk-embedding-write-worker.js +7 -7
  106. package/dist/v2/{compartment-chunk-embedding-x6qw6mjk.js → compartment-chunk-embedding-knt2468v.js} +3 -1
  107. package/dist/v2/{context-k8sx1nyy.js → context-8bzydxfy.js} +227 -70
  108. package/dist/v2/{derive-budgets-ecjy1aqh.js → derive-budgets-hr4qqrnv.js} +3 -3
  109. package/dist/v2/{embedding-backfill-k8kqnwfq.js → embedding-backfill-0ar1bm97.js} +8 -8
  110. package/dist/{embedding-cache-mgyr73ef.js → v2/embedding-cache-zn4r1c31.js} +5 -1
  111. package/dist/v2/embedding-worker.js +2 -2
  112. package/dist/v2/fold/native-replay.d.ts +3 -1
  113. package/dist/v2/fold/native-replay.d.ts.map +1 -1
  114. package/dist/v2/hidden-child-record.d.ts +1 -0
  115. package/dist/v2/hidden-child-record.d.ts.map +1 -1
  116. package/dist/v2/hidden-completion.d.ts.map +1 -1
  117. package/dist/v2/hooks/context.d.ts.map +1 -1
  118. package/dist/v2/{message-index-bounded-jqy7283g.js → message-index-bounded-b07r9cjv.js} +4 -4
  119. package/dist/v2/migration-worker.js +5 -5
  120. package/dist/v2/{project-embedding-registry-2jp1antr.js → project-embedding-registry-gx2waee8.js} +7 -7
  121. package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
  122. package/dist/v2/{read-session-chunk-n3nhfvd7.js → read-session-chunk-38wdy8nd.js} +3 -3
  123. package/dist/v2/{recomp-orchestrator-ssde9ft1.js → recomp-orchestrator-wq7gbkqa.js} +24 -24
  124. package/dist/v2/{render-fezgh7pa.js → render-2dan17xc.js} +12 -12
  125. package/dist/v2/{rpc-notifications-t9q0ynq7.js → rpc-notifications-ta2zsxpq.js} +1 -1
  126. package/dist/v2/{search-archive-zz1kza50.js → search-archive-89hdy0a2.js} +5 -5
  127. package/dist/v2/{search-m251amra.js → search-nyqykx7q.js} +17 -17
  128. package/dist/v2/{send-session-notification-p52rhjzy.js → send-session-notification-zazaxxpf.js} +1 -1
  129. package/dist/v2/{server-4wwwm2ya.js → server-09h2vyvs.js} +5 -5
  130. package/dist/v2/{server-r2es6zt7.js → server-0tv6kytx.js} +108 -13
  131. package/dist/v2/{server-rz4snd3x.js → server-1rrmxhd1.js} +1 -1
  132. package/dist/v2/{server-wdq85mxj.js → server-6250cxzs.js} +14 -8
  133. package/dist/v2/{server-xa8fefhw.js → server-96nm9vk4.js} +1 -1
  134. package/dist/v2/{server-jjvbk92s.js → server-9emdjcb5.js} +1 -1
  135. package/dist/v2/{server-ap81bk3c.js → server-9n2qgk29.js} +1 -1
  136. package/dist/v2/{server-ps6rz88g.js → server-a85j3kam.js} +2 -2
  137. package/dist/v2/{server-y31y6gws.js → server-add0j5n3.js} +9 -7
  138. package/dist/v2/{server-97w51d8n.js → server-b0a9h3ds.js} +3 -3
  139. package/dist/v2/{server-2k8tkbhz.js → server-c7awk5s2.js} +10 -4
  140. package/dist/v2/{server-hn8b7sfe.js → server-dgjqvpgd.js} +5 -5
  141. package/dist/v2/{server-fsw8kbng.js → server-dtcwkdqj.js} +314 -114
  142. package/dist/v2/{server-mbkwcwgw.js → server-f7tzvmzs.js} +2 -2
  143. package/dist/v2/{server-n5zr7190.js → server-fb5hvvfc.js} +77 -14
  144. package/dist/v2/{server-w7mpvkpj.js → server-fn4ky6mn.js} +1 -1
  145. package/dist/v2/{server-3p6b0qya.js → server-gqkdfdvw.js} +1 -1
  146. package/dist/v2/{server-cwtehwbb.js → server-j4jjtdc5.js} +1 -1
  147. package/dist/v2/{server-b93f0bqh.js → server-pjk9spbf.js} +1 -1
  148. package/dist/v2/{server-s15knz0w.js → server-pmws7we9.js} +1 -1
  149. package/dist/{index-4dhv7mqz.js → v2/server-qjwpqvnf.js} +48 -1
  150. package/dist/v2/{server-a2f1bhyj.js → server-stjy5dxv.js} +9 -2
  151. package/dist/v2/{server-ssg29wjg.js → server-ta4h0fch.js} +21 -14
  152. package/dist/v2/{server-e2k9mt86.js → server-tj65pgvg.js} +1 -1
  153. package/dist/v2/{server-brgandk4.js → server-vy0beygw.js} +2 -2
  154. package/dist/v2/{server-fzgyvsb1.js → server-y14pawe1.js} +3 -0
  155. package/dist/v2/{server-8pdfmc27.js → server-y17r5ryz.js} +4 -4
  156. package/dist/v2/{server-sxfbjdye.js → server-yx0nyj1q.js} +2 -2
  157. package/dist/v2/server.js +6 -6
  158. package/dist/v2/{storage-memory-e6a7mb0k.js → storage-memory-hhrvfw0x.js} +2 -2
  159. package/dist/v2/{storage-tags-xq81zgt2.js → storage-tags-pmw33chf.js} +2 -2
  160. package/dist/v2/{v2-archive-reader-e2w39c3p.js → v2-archive-reader-gh1jghf7.js} +1 -1
  161. package/dist/v2/{wrapup-orchestrator-eg5b1p89.js → wrapup-orchestrator-2h7ayss9.js} +24 -24
  162. package/dist/{v2-archive-reader-8dsngf2j.js → v2-archive-reader-8158kyfd.js} +1 -1
  163. package/dist/{wrapup-orchestrator-nmk6yf7f.js → wrapup-orchestrator-ct59br0c.js} +24 -24
  164. package/package.json +1 -1
  165. package/src/shared/assistant-message-extractor.test.ts +22 -0
  166. package/src/shared/assistant-message-extractor.ts +13 -0
  167. package/src/shared/model-suggestion-retry.test.ts +43 -12
  168. package/src/shared/prompt-async-transport.test.ts +275 -8
  169. package/src/shared/prompt-async-transport.ts +41 -2
  170. package/src/shared/recomp-outcome.ts +8 -0
  171. package/src/shared/reusable-worker.fixture.ts +15 -3
  172. package/src/shared/reusable-worker.test.ts +20 -10
  173. package/src/shared/rpc-notifications.ts +4 -1
  174. package/src/shared/sqlite-foreground-wait.test.ts +2 -2
  175. package/src/shared/startup-maintenance-policy.test.ts +4 -2
  176. package/src/shared/storage-permissions-startup.test.ts +296 -6
  177. package/src/shared/storage-permissions.ts +143 -18
  178. package/src/shared/user-facing-codes.ts +5 -2
  179. package/src/tui/dialogs/status-dialog.tsx +3 -0
  180. package/src/tui/slots/sidebar-content.tsx +6 -2
  181. package/src/tui-compiled/dialogs/status-dialog.tsx +12 -0
  182. package/src/tui-compiled/slots/sidebar-content.tsx +7 -2
@@ -12,7 +12,7 @@ import {
12
12
  getCompartments,
13
13
  getLastCompartmentEndMessage,
14
14
  requestPendingMaterialization
15
- } from "./server-4wwwm2ya.js";
15
+ } from "./server-09h2vyvs.js";
16
16
  import"./server-2amn2s73.js";
17
17
  import"./server-y8xjr8rx.js";
18
18
  import"./server-x6fn9x8q.js";
@@ -24,8 +24,8 @@ import"./server-96ztjvkn.js";
24
24
  import"./server-1d042x6w.js";
25
25
  import"./server-6ash6z8z.js";
26
26
  import"./server-ds8vpfkr.js";
27
- import"./server-8pdfmc27.js";
28
- import"./server-ap81bk3c.js";
27
+ import"./server-y17r5ryz.js";
28
+ import"./server-9n2qgk29.js";
29
29
  import {
30
30
  getWrapupInProgressState,
31
31
  acquireWrapupInProgress,
@@ -33,27 +33,27 @@ import {
33
33
  releaseWrapupInProgress,
34
34
  getHistorianFailureState,
35
35
  clearEmergencyRecovery
36
- } from "./server-s15knz0w.js";
37
- import"./server-a2f1bhyj.js";
38
- import"./server-n5zr7190.js";
36
+ } from "./server-pmws7we9.js";
37
+ import"./server-stjy5dxv.js";
38
+ import"./server-fb5hvvfc.js";
39
39
  import"./server-1zx87sdm.js";
40
40
  import"./server-rz6g5xne.js";
41
41
  import"./server-2ra6pwf3.js";
42
42
  import"./server-3ap5dmhc.js";
43
43
  import {
44
44
  prepareRawSessionOrdinals2
45
- } from "./server-2k8tkbhz.js";
45
+ } from "./server-c7awk5s2.js";
46
46
  import"./server-fr0wbhdn.js";
47
- import"./server-ps6rz88g.js";
48
- import"./server-r2es6zt7.js";
49
- import"./server-rz4snd3x.js";
47
+ import"./server-a85j3kam.js";
48
+ import"./server-0tv6kytx.js";
49
+ import"./server-1rrmxhd1.js";
50
50
  import"./server-qyazxy92.js";
51
51
  import"./server-fb3zxn06.js";
52
52
  import"./server-39bcszk4.js";
53
- import"./server-w7mpvkpj.js";
53
+ import"./server-fn4ky6mn.js";
54
54
  import {
55
55
  pushNotification2
56
- } from "./server-fzgyvsb1.js";
56
+ } from "./server-y14pawe1.js";
57
57
  import"./server-at0v0z4t.js";
58
58
  import {
59
59
  describeBoundaryDiagnostics,
@@ -65,22 +65,22 @@ import {
65
65
  registerActiveCompartmentRun,
66
66
  setRecompStarting2,
67
67
  setRecompTerminal2
68
- } from "./server-fsw8kbng.js";
68
+ } from "./server-dtcwkdqj.js";
69
69
  import"./server-qt1qqasc.js";
70
- import"./server-hn8b7sfe.js";
71
- import"./server-3p6b0qya.js";
72
- import"./server-4dhv7mqz.js";
73
- import"./server-b93f0bqh.js";
74
- import"./server-y31y6gws.js";
75
- import"./server-mbkwcwgw.js";
76
- import"./server-jjvbk92s.js";
77
- import"./server-e2k9mt86.js";
78
- import"./server-xa8fefhw.js";
79
- import"./server-cwtehwbb.js";
70
+ import"./server-dgjqvpgd.js";
71
+ import"./server-gqkdfdvw.js";
72
+ import"./server-qjwpqvnf.js";
73
+ import"./server-pjk9spbf.js";
74
+ import"./server-add0j5n3.js";
75
+ import"./server-f7tzvmzs.js";
76
+ import"./server-9emdjcb5.js";
77
+ import"./server-tj65pgvg.js";
78
+ import"./server-96nm9vk4.js";
79
+ import"./server-j4jjtdc5.js";
80
80
  import"./server-npdey91q.js";
81
81
  import {
82
82
  sendStatusNotification2
83
- } from "./server-wdq85mxj.js";
83
+ } from "./server-6250cxzs.js";
84
84
  import"./server-5sbsnpkn.js";
85
85
 
86
86
  // src/hooks/magic-context/wrapup-orchestrator.ts
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readV2ArchiveOffThread2,
3
3
  serveV2ArchiveReads2
4
- } from "./index-1pf5qrx4.js";
4
+ } from "./index-jzfsnbmm.js";
5
5
  import"./index-v0p37hm2.js";
6
6
  import"./index-gzy5w8ya.js";
7
7
  import"./index-1d042x6w.js";
@@ -1,48 +1,48 @@
1
1
  import {
2
2
  runManagedWrapup2
3
- } from "./index-25nktq8n.js";
4
- import"./index-e32b3x4n.js";
5
- import"./index-ttk3trse.js";
3
+ } from "./index-wmb2mcdw.js";
4
+ import"./index-qfcjrnpe.js";
5
+ import"./index-q7msfgwz.js";
6
6
  import"./index-832w615x.js";
7
7
  import"./index-sd3egckz.js";
8
- import"./index-1bqkqde0.js";
9
- import"./index-k0tb2z28.js";
10
- import"./index-jjvbk92s.js";
11
- import"./index-s8ks5nz4.js";
12
- import"./index-4dhv7mqz.js";
13
- import"./index-w6v4dw5f.js";
14
- import"./index-4ntnt8ee.js";
15
- import"./index-05bm2ndp.js";
8
+ import"./index-39rzef89.js";
9
+ import"./index-w51n3576.js";
10
+ import"./index-9emdjcb5.js";
11
+ import"./index-2pdgy88n.js";
12
+ import"./index-qjwpqvnf.js";
13
+ import"./index-h9hybzr5.js";
14
+ import"./index-61knrt52.js";
15
+ import"./index-chpzb6xy.js";
16
16
  import"./index-2amn2s73.js";
17
17
  import"./index-1y4y98r1.js";
18
- import"./index-zmqx48vt.js";
19
- import"./index-g6hfh4h4.js";
18
+ import"./index-xsqw8kbd.js";
19
+ import"./index-6zewd2n5.js";
20
20
  import"./index-qt1qqasc.js";
21
- import"./index-7j2zv9nm.js";
22
- import"./index-xrnhxkz7.js";
21
+ import"./index-2qsca7h7.js";
22
+ import"./index-60wnwcwz.js";
23
23
  import"./index-1zx87sdm.js";
24
24
  import"./index-x40zr813.js";
25
- import"./index-fzgyvsb1.js";
25
+ import"./index-y14pawe1.js";
26
26
  import"./index-e6ncz7a6.js";
27
- import"./index-k50xhjw1.js";
27
+ import"./index-60x5d68t.js";
28
28
  import"./index-6nqz8hsz.js";
29
- import"./index-3dtzyred.js";
30
- import"./index-snbpdpa3.js";
29
+ import"./index-r4y0dczp.js";
30
+ import"./index-3pdknr07.js";
31
31
  import"./index-pxnzyvjc.js";
32
- import"./index-xccywqdj.js";
32
+ import"./index-mrjat4eq.js";
33
33
  import"./index-fb3zxn06.js";
34
- import"./index-4w5rx7de.js";
34
+ import"./index-tt0vs4x5.js";
35
35
  import"./index-fr0wbhdn.js";
36
- import"./index-7svecf3m.js";
36
+ import"./index-5pgyqgmx.js";
37
37
  import"./index-s32f8y67.js";
38
38
  import"./index-wh9fxds5.js";
39
- import"./index-jrj95cce.js";
39
+ import"./index-m6dnydf8.js";
40
40
  import"./index-q7q6qp1f.js";
41
41
  import"./index-96ztjvkn.js";
42
42
  import"./index-v0p37hm2.js";
43
43
  import"./index-58e3y90n.js";
44
44
  import"./index-m0pwswv9.js";
45
- import"./index-c5tmzym6.js";
45
+ import"./index-5df2fw5b.js";
46
46
  import"./index-gqf8r04r.js";
47
47
  import"./index-5vsk2cpp.js";
48
48
  import"./index-gzy5w8ya.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/opencode-magic-context",
3
- "version": "0.49.86",
3
+ "version": "0.49.89",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",
@@ -3,6 +3,7 @@ import {
3
3
  describeAssistantSettlement,
4
4
  extractLatestAssistantText,
5
5
  hasLengthCappedOutput,
6
+ isLatestAssistantLengthCapped,
6
7
  } from "./assistant-message-extractor";
7
8
 
8
9
  test("reasoning-only and tool-only turns stay out of manifest text and retain finish diagnostics", () => {
@@ -45,3 +46,24 @@ describe("hasLengthCappedOutput", () => {
45
46
  expect(hasLengthCappedOutput({ role: "assistant", stopReason: "length" })).toBe(true);
46
47
  });
47
48
  });
49
+
50
+ test("only the latest assistant's settlement counts on a reused child", () => {
51
+ const capped = {
52
+ info: { role: "assistant", time: { created: 1 }, finish: "length" },
53
+ parts: [],
54
+ };
55
+ const stopped = {
56
+ info: { role: "assistant", time: { created: 2 }, finish: "stop" },
57
+ parts: [{ type: "tool", state: { input: { finish: "length" } } }],
58
+ };
59
+ expect(isLatestAssistantLengthCapped([capped, stopped])).toBe(false);
60
+ expect(isLatestAssistantLengthCapped([capped])).toBe(true);
61
+ expect(
62
+ isLatestAssistantLengthCapped([
63
+ {
64
+ ...stopped,
65
+ parts: [{ type: "step-finish", reason: "max_tokens" }],
66
+ },
67
+ ]),
68
+ ).toBe(true);
69
+ });
@@ -128,6 +128,19 @@ export function hasLengthCappedOutput(value: unknown): boolean {
128
128
  return Object.values(value).some((item) => hasLengthCappedOutput(item));
129
129
  }
130
130
 
131
+ /** A reused child may still have a capped answer from an earlier turn or model. */
132
+ export function isLatestAssistantLengthCapped(messages: unknown): boolean {
133
+ const latest = getLatestAssistantMessage(messages);
134
+ return (
135
+ hasLengthCappedOutput(latest?.info?.finish ? { finish: latest.info.finish } : null) ||
136
+ (Array.isArray(latest?.parts) &&
137
+ latest.parts.some(
138
+ (part) =>
139
+ isRecord(part) && part.type === "step-finish" && hasLengthCappedOutput(part),
140
+ ))
141
+ );
142
+ }
143
+
131
144
  /** Settlement metadata for diagnostics, never private reasoning as task output. */
132
145
  export function describeAssistantSettlement(output: unknown): string {
133
146
  if (isRecord(output) && isRecord(output.tokenLog)) {
@@ -1,4 +1,4 @@
1
- import { describe, expect, mock, spyOn, test } from "bun:test";
1
+ import { afterEach, describe, expect, jest, mock, spyOn, test } from "bun:test";
2
2
  import { recordedGeminiQuotaMessages } from "../features/magic-context/dreamer/provider-output-failure.test-support";
3
3
  import { HiddenAgentStepLimit } from "../v2/hooks/hidden-child";
4
4
  import { hiddenModelCooldowns } from "./hidden-model-cooldown";
@@ -817,6 +817,19 @@ describe("first-output deadline", () => {
817
817
  const primary = { providerID: "opencode", modelID: "free-model" };
818
818
  type Behaviour = "silent" | "partial" | "answer" | "unmonitored";
819
819
 
820
+ afterEach(() => jest.useRealTimers());
821
+
822
+ function freezeTime() {
823
+ jest.useFakeTimers({ doNotFake: ["setImmediate"] });
824
+ jest.setSystemTime(new Date("2026-08-11T12:00:00Z"));
825
+ }
826
+
827
+ async function advance(ms: number) {
828
+ jest.advanceTimersByTime(ms);
829
+ // Let the attempt's rejection and the next attempt's startup settle.
830
+ await new Promise<void>((resolve) => setImmediate(resolve));
831
+ }
832
+
820
833
  /**
821
834
  * A transport double that behaves per model. "silent" watches the child but the
822
835
  * model never answers; "partial" streams something and then hangs; "unmonitored"
@@ -874,18 +887,27 @@ describe("first-output deadline", () => {
874
887
  }
875
888
 
876
889
  test("a primary that streams nothing by the deadline moves on to the fallback", async () => {
877
- const outcome = await run(
890
+ freezeTime();
891
+ let settled = false;
892
+ const pending = run(
878
893
  { "opencode/free-model": "silent" },
879
894
  { timeoutMs: 2_000, firstOutputTimeoutMs: 40 },
880
- );
895
+ ).then((outcome) => {
896
+ settled = true;
897
+ return outcome;
898
+ });
899
+ await advance(39);
900
+ expect(settled).toBe(false);
901
+ await advance(1);
902
+ expect(settled).toBe(true);
903
+ const outcome = await pending;
881
904
  expect(outcome.caught).toBeUndefined();
882
905
  expect(outcome.result?.attempt.label).toBe("anthropic/claude-sonnet-5-5");
883
906
  expect(outcome.calls.map((call) => call.model)).toEqual([
884
907
  "opencode/free-model",
885
908
  "anthropic/claude-sonnet-5-5",
886
909
  ]);
887
- // The silent primary was cut at its first-output deadline, not its timeout.
888
- expect(outcome.elapsedMs).toBeLessThan(1_000);
910
+ expect(outcome.elapsedMs).toBe(40);
889
911
  });
890
912
 
891
913
  test("the unvalidated chain also moves on from a silent primary", async () => {
@@ -919,16 +941,25 @@ describe("first-output deadline", () => {
919
941
  test("a silent primary's time comes out of the fallback's timeout", async () => {
920
942
  // The fallback is the last model, so it gets no first-output cut of its own;
921
943
  // its timeout is what the silent primary left of the overall 300 ms.
922
- const outcome = await run(
944
+ freezeTime();
945
+ let settled = false;
946
+ const pending = run(
923
947
  { "opencode/free-model": "silent", "anthropic/claude-sonnet-5-5": "silent" },
924
948
  { timeoutMs: 300, firstOutputTimeoutMs: 100 },
925
- );
926
- const message = (outcome.caught as Error).message;
927
- const fallbackTimeoutMs = Number(/prompt timed out after (\d+)ms$/.exec(message)?.[1]);
949
+ ).then((outcome) => {
950
+ settled = true;
951
+ return outcome;
952
+ });
953
+ await advance(100);
954
+ await advance(199);
955
+ expect(settled).toBe(false);
956
+ await advance(1);
957
+ expect(settled).toBe(true);
958
+ const outcome = await pending;
928
959
  expect(outcome.calls).toHaveLength(2);
929
- expect(fallbackTimeoutMs).toBeLessThanOrEqual(200);
930
- expect(fallbackTimeoutMs).toBeGreaterThan(100);
931
- expect(outcome.elapsedMs).toBeLessThan(300 + 150);
960
+ expect(outcome.calls[1]!.startedAt - outcome.calls[0]!.startedAt).toBe(100);
961
+ expect((outcome.caught as Error).message).toBe("prompt timed out after 200ms");
962
+ expect(outcome.elapsedMs).toBe(300);
932
963
  });
933
964
 
934
965
  test("the last model in the chain is never cut for silence", async () => {
@@ -1,5 +1,8 @@
1
- import { describe, expect, mock, test } from "bun:test";
2
- import { refuseBudgetedToolCall } from "../features/magic-context/dreamer/token-budget";
1
+ import { afterEach, beforeEach, describe, expect, jest, mock, test } from "bun:test";
2
+ import {
3
+ createDreamTokenBudget,
4
+ refuseBudgetedToolCall,
5
+ } from "../features/magic-context/dreamer/token-budget";
3
6
  import { createDroppedInputToolExecuteBeforeHook } from "../hooks/magic-context/dropped-input-guard";
4
7
  import { promptSyncWithValidatedOutputRetry } from "./model-suggestion-retry";
5
8
  import {
@@ -609,6 +612,234 @@ describe("dreamer budget on an async child", () => {
609
612
  });
610
613
  });
611
614
 
615
+ describe("tool refusals at finalize submission", () => {
616
+ const toolPart = (callID: string, status = "running", interrupted = false) => ({
617
+ type: "tool",
618
+ callID,
619
+ state: {
620
+ status,
621
+ ...(interrupted
622
+ ? { error: "Tool execution aborted", metadata: { interrupted: true } }
623
+ : {}),
624
+ },
625
+ });
626
+ const interruptedPart = (id: string) => toolPart(id, "error", true);
627
+
628
+ interface RefusalScript {
629
+ beforeAbort?: ReturnType<typeof toolPart>[];
630
+ afterAbort?: ReturnType<typeof toolPart>[] | null;
631
+ duringAbort?: string[];
632
+ afterSubmission?: (string | undefined)[];
633
+ counts: number[];
634
+ answer?: boolean;
635
+ }
636
+
637
+ async function runScript(script: RefusalScript) {
638
+ const before = createDroppedInputToolExecuteBeforeHook();
639
+ const budget = createDreamTokenBudget(100);
640
+ const counts: number[] = [];
641
+ const answer = { type: "text", text: "<mappings/>" };
642
+ const replies = (parts: ReturnType<typeof toolPart>[]) => [
643
+ {
644
+ info: {
645
+ id: "meter",
646
+ role: "assistant",
647
+ tokens: { input: 81 },
648
+ finish: "tool-calls",
649
+ },
650
+ },
651
+ { info: { id: "pending", role: "assistant" }, parts },
652
+ ];
653
+ let submissions = 0;
654
+ let latest: unknown;
655
+ const refuse = async (id: string | undefined) => {
656
+ let reason: unknown;
657
+ try {
658
+ await before({ tool: "read", sessionID: "ses-child", callID: id }, { args: {} });
659
+ } catch (error) {
660
+ reason = error;
661
+ }
662
+ counts.push(budget.snapshot().refusedCalls);
663
+ expect(reason).toBeInstanceOf(Error);
664
+ expect((reason as Error).message).toContain("Out of token budget");
665
+ };
666
+ const abort = mock(async () => {
667
+ if (submissions === 1) {
668
+ for (const id of script.duringAbort ?? []) await refuse(id);
669
+ }
670
+ });
671
+ const client = {
672
+ session: {
673
+ promptAsync: async () => {
674
+ submissions++;
675
+ if (submissions === 1) {
676
+ await before(
677
+ { tool: "read", sessionID: "ses-child", callID: "a" },
678
+ { args: {} },
679
+ );
680
+ expect(refuseBudgetedToolCall("ses-child")).toBeNull();
681
+ }
682
+ if (submissions === 2) {
683
+ await before(
684
+ { tool: "read", sessionID: "other-child", callID: "a" },
685
+ { args: {} },
686
+ );
687
+ for (const id of script.afterSubmission ?? []) await refuse(id);
688
+ if (script.answer) {
689
+ latest = {
690
+ info: {
691
+ id: "final",
692
+ role: "assistant",
693
+ finish: "stop",
694
+ time: { completed: 1 },
695
+ },
696
+ parts: [answer],
697
+ };
698
+ }
699
+ }
700
+ return { data: undefined };
701
+ },
702
+ abort,
703
+ status: async () => ({
704
+ data:
705
+ submissions === 1 && abort.mock.calls.length === 0
706
+ ? { "ses-child": { type: "busy" } }
707
+ : {},
708
+ }),
709
+ messages: async () => {
710
+ if (!submissions) return { data: [] };
711
+ if (abort.mock.calls.length === 0)
712
+ return { data: replies(script.beforeAbort ?? []) };
713
+ if (submissions === 1 && script.afterAbort === null)
714
+ return { error: "unavailable" };
715
+ const rows: unknown[] = replies(script.afterAbort ?? script.beforeAbort ?? []);
716
+ if (submissions === 2) rows.push({ info: { id: "finalize", role: "user" } });
717
+ if (latest) rows.push(latest);
718
+ return { data: rows };
719
+ },
720
+ },
721
+ } as never;
722
+ const result = await promptAsyncAndWaitForIdle(client, request(), {
723
+ pollIntervalMs: 1,
724
+ startGraceMs: 30,
725
+ budgetGuard: budget,
726
+ }).catch((error: unknown) => error);
727
+ expect(counts).toEqual(script.counts);
728
+ expect(submissions).toBe(2);
729
+ if (script.answer) {
730
+ expect(result).toBeUndefined();
731
+ expect(latest).toMatchObject({ parts: [answer] });
732
+ expect(abort).toHaveBeenCalledTimes(1);
733
+ } else {
734
+ expect(result).toBeInstanceOf(Error);
735
+ expect((result as Error).message).toContain("token_budget");
736
+ expect(abort).toHaveBeenCalledTimes(2);
737
+ }
738
+ expect(refuseBudgetedToolCall("ses-child")).toBeNull();
739
+ }
740
+
741
+ test("keeps the answer after two old calls are refused before submission", () =>
742
+ runScript({ duringAbort: ["a", "b"], counts: [0, 0], answer: true }));
743
+
744
+ test("keeps the answer when two cancelled tools reach the guard after submission", () =>
745
+ runScript({
746
+ beforeAbort: [toolPart("a")],
747
+ afterAbort: [interruptedPart("a"), interruptedPart("b")],
748
+ afterSubmission: ["b", "a"],
749
+ counts: [0, 0],
750
+ answer: true,
751
+ }));
752
+
753
+ test("spares a call that is still running in the cancellation snapshot", () =>
754
+ runScript({
755
+ afterAbort: [toolPart("a", "running")],
756
+ afterSubmission: ["a"],
757
+ counts: [0],
758
+ answer: true,
759
+ }));
760
+
761
+ test("counts a call whose part closed with an ordinary tool error", () =>
762
+ runScript({
763
+ afterAbort: [{ ...toolPart("a"), state: { status: "error", error: "File not found" } }],
764
+ afterSubmission: ["a", "b"],
765
+ counts: [1, 2],
766
+ }));
767
+
768
+ test("spares an early refusal but counts a reuse and a second new call", () =>
769
+ runScript({
770
+ beforeAbort: [toolPart("a")],
771
+ duringAbort: ["a"],
772
+ afterSubmission: ["a", "b"],
773
+ counts: [0, 1, 2],
774
+ }));
775
+
776
+ test("stops on exactly two new calls issued after submission", () =>
777
+ runScript({ afterSubmission: ["a", "b"], counts: [1, 2] }));
778
+
779
+ test("spares each in-flight id only once when ids are reused after submission", () =>
780
+ runScript({
781
+ afterAbort: [interruptedPart("a"), toolPart("b", "pending")],
782
+ afterSubmission: ["a", "b", "a", "b"],
783
+ counts: [0, 0, 1, 2],
784
+ }));
785
+
786
+ test("counts both refusals when the cancellation snapshot is unreadable", () =>
787
+ runScript({
788
+ beforeAbort: [toolPart("a"), toolPart("b")],
789
+ afterAbort: null,
790
+ afterSubmission: ["a", "b"],
791
+ counts: [1, 2],
792
+ }));
793
+
794
+ test("releases the guard without submitting finalize when the cancellation read throws", async () => {
795
+ const readError = new Error("socket hang up");
796
+ const meter = { info: { id: "meter", role: "assistant", tokens: { input: 81 } } };
797
+ const cancelled = {
798
+ info: {
799
+ id: "cancelled",
800
+ role: "assistant",
801
+ finish: "tool-calls",
802
+ time: { completed: 1 },
803
+ },
804
+ parts: [toolPart("a", "completed")],
805
+ };
806
+ const promptAsync = mock(async () => ({ data: undefined }));
807
+ const abort = mock(async () => ({ data: true }));
808
+ const messages = mock(async () => {
809
+ if (!promptAsync.mock.calls.length) return { data: [] };
810
+ if (!abort.mock.calls.length) return { data: [meter] };
811
+ if (promptAsync.mock.calls.length === 1) throw readError;
812
+ // A settled tool reply missing from the poll that triggered cancellation
813
+ // must not be mistaken for the finalize response.
814
+ return { data: [meter, cancelled] };
815
+ });
816
+ const client = {
817
+ session: { promptAsync, abort, messages, status: async () => ({ data: {} }) },
818
+ } as never;
819
+ const run = promptAsyncAndWaitForIdle(client, request(), {
820
+ pollIntervalMs: 1,
821
+ tokenBudget: 100,
822
+ });
823
+ await expect(run).rejects.toBe(readError);
824
+ expect(promptAsync).toHaveBeenCalledTimes(1);
825
+ expect(abort).toHaveBeenCalledTimes(1);
826
+ expect(refuseBudgetedToolCall("ses-child")).toBeNull();
827
+ });
828
+
829
+ test("counts missing ids and ids of completed tools after submission", () =>
830
+ runScript({
831
+ beforeAbort: [toolPart("a"), toolPart("b")],
832
+ afterAbort: [toolPart("a", "completed"), toolPart("b", "running")],
833
+ afterSubmission: ["a", undefined],
834
+ counts: [1, 2],
835
+ }));
836
+
837
+ test("does not carry an unspent exemption into a fresh run on the same child", async () => {
838
+ await runScript({ afterAbort: [interruptedPart("a")], counts: [], answer: true });
839
+ await runScript({ afterSubmission: ["a", "b"], counts: [1, 2] });
840
+ });
841
+ });
842
+
612
843
  describe("prompt_async transport under the retry chain", () => {
613
844
  test("our slice stays the only timer and aborts the busy child when it expires", async () => {
614
845
  const host = asyncHost({ plan: ["busy"] });
@@ -683,6 +914,18 @@ test("session errors belonging to another child do not fail the run", async () =
683
914
  });
684
915
 
685
916
  describe("prompt_async transport and the first-output deadline", () => {
917
+ beforeEach(() => {
918
+ jest.useFakeTimers({ doNotFake: ["setImmediate"] });
919
+ jest.setSystemTime(new Date("2026-08-11T12:00:00Z"));
920
+ });
921
+ afterEach(() => jest.useRealTimers());
922
+
923
+ async function poll(ms: number) {
924
+ jest.advanceTimersByTime(ms);
925
+ // Drain the host replies and let the waiter arm its next poll.
926
+ await new Promise<void>((resolve) => setImmediate(resolve));
927
+ }
928
+
686
929
  /**
687
930
  * A child session where each model answers its own way. "dead" leaves the
688
931
  * empty assistant row the host writes before the provider responds and stays
@@ -784,19 +1027,38 @@ describe("prompt_async transport and the first-output deadline", () => {
784
1027
  const host = modelHost({ "opencode/free-model": "dead" });
785
1028
  const startedAt = Date.now();
786
1029
 
787
- const run = await runChain(host, 5_000, 60);
1030
+ const pending = runChain(host, 5_000, 60);
1031
+ await new Promise<void>((resolve) => setImmediate(resolve));
1032
+ await poll(59);
1033
+ expect(host.sent).toEqual(["opencode/free-model"]);
1034
+ expect(host.abort).not.toHaveBeenCalled();
1035
+ await poll(1);
1036
+ expect(host.sent).toEqual(["opencode/free-model", "anthropic/claude-sonnet-5-5"]);
1037
+ await poll(5);
1038
+ const run = await pending;
788
1039
 
789
1040
  expect(run.attempt.label).toBe("anthropic/claude-sonnet-5-5");
790
- expect(host.sent).toEqual(["opencode/free-model", "anthropic/claude-sonnet-5-5"]);
791
1041
  // The dead model's run is stopped on the host before the fallback is sent.
792
1042
  expect(host.abort).toHaveBeenCalledWith({ path: { id: "ses-child" } });
793
- expect(Date.now() - startedAt).toBeLessThan(2_000);
1043
+ expect(Date.now() - startedAt).toBe(65);
794
1044
  });
795
1045
 
796
1046
  test("a model that streamed part of an answer keeps its timeout and does not fall back", async () => {
797
1047
  const host = modelHost({ "opencode/free-model": "partial" });
798
1048
 
799
- await expect(runChain(host, 200, 40)).rejects.toThrow("prompt timed out after 200ms");
1049
+ let outcome: unknown;
1050
+ const pending = runChain(host, 200, 40).then(
1051
+ (result) => (outcome = result),
1052
+ (error: unknown) => (outcome = error),
1053
+ );
1054
+ await new Promise<void>((resolve) => setImmediate(resolve));
1055
+ await poll(5); // Let the first poll see the streamed answer before advancing to the cut.
1056
+ await poll(194);
1057
+ expect(host.abort).not.toHaveBeenCalled();
1058
+ await poll(1);
1059
+ expect(outcome).toBeInstanceOf(Error);
1060
+ expect((outcome as Error).message).toBe("prompt timed out after 200ms");
1061
+ await pending;
800
1062
  expect(host.sent).toEqual(["opencode/free-model"]);
801
1063
  });
802
1064
 
@@ -804,12 +1066,17 @@ describe("prompt_async transport and the first-output deadline", () => {
804
1066
  test(`a recorded provider ${failure} stops the host retry loop and immediately tries the fallback`, async () => {
805
1067
  const host = modelHost({ "opencode/free-model": failure });
806
1068
  const startedAt = Date.now();
807
- const result = await runChain(host, 5_000, 5_000);
1069
+ const pending = runChain(host, 5_000, 5_000);
1070
+ await new Promise<void>((resolve) => setImmediate(resolve));
1071
+ await poll(5);
1072
+ expect(host.sent).toEqual(["opencode/free-model", "anthropic/claude-sonnet-5-5"]);
1073
+ await poll(5);
1074
+ const result = await pending;
808
1075
  expect(result.attempt.label).toBe("anthropic/claude-sonnet-5-5");
809
1076
  expect(host.sent).toEqual(["opencode/free-model", "anthropic/claude-sonnet-5-5"]);
810
1077
  expect(host.abort).toHaveBeenCalledTimes(1);
811
1078
  expect(host.abort).toHaveBeenCalledWith({ path: { id: "ses-child" } });
812
- expect(Date.now() - startedAt).toBeLessThan(2_000);
1079
+ expect(Date.now() - startedAt).toBe(10);
813
1080
  });
814
1081
  }
815
1082
  });