@cortexkit/opencode-magic-context 0.25.0 → 0.27.0

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 (316) hide show
  1. package/README.md +14 -12
  2. package/dist/agents/dreamer.d.ts +19 -0
  3. package/dist/agents/dreamer.d.ts.map +1 -1
  4. package/dist/agents/hidden-agent-registrations.d.ts +67 -0
  5. package/dist/agents/hidden-agent-registrations.d.ts.map +1 -0
  6. package/dist/agents/historian.d.ts +1 -0
  7. package/dist/agents/historian.d.ts.map +1 -1
  8. package/dist/agents/permissions.d.ts +19 -42
  9. package/dist/agents/permissions.d.ts.map +1 -1
  10. package/dist/agents/smart-note-compiler.d.ts +2 -0
  11. package/dist/agents/smart-note-compiler.d.ts.map +1 -0
  12. package/dist/config/index.d.ts +1 -1
  13. package/dist/config/index.d.ts.map +1 -1
  14. package/dist/config/migrate-config-location.d.ts +89 -0
  15. package/dist/config/migrate-config-location.d.ts.map +1 -0
  16. package/dist/config/migrate-dreamer-v2.d.ts +37 -0
  17. package/dist/config/migrate-dreamer-v2.d.ts.map +1 -0
  18. package/dist/config/migrate-experimental.d.ts.map +1 -1
  19. package/dist/config/project-security.d.ts +3 -0
  20. package/dist/config/project-security.d.ts.map +1 -1
  21. package/dist/config/prune-config-leaf.d.ts.map +1 -1
  22. package/dist/config/schema/magic-context.d.ts +606 -60
  23. package/dist/config/schema/magic-context.d.ts.map +1 -1
  24. package/dist/features/magic-context/compaction-marker.d.ts +9 -3
  25. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  26. package/dist/features/magic-context/compartment-chunk-embedding.d.ts +18 -1
  27. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  28. package/dist/features/magic-context/compartment-embedding.d.ts.map +1 -1
  29. package/dist/features/magic-context/dreamer/classify-prompt.d.ts +50 -0
  30. package/dist/features/magic-context/dreamer/classify-prompt.d.ts.map +1 -0
  31. package/dist/features/magic-context/dreamer/classify.d.ts +22 -0
  32. package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -0
  33. package/dist/features/magic-context/dreamer/cron.d.ts +72 -0
  34. package/dist/features/magic-context/dreamer/cron.d.ts.map +1 -0
  35. package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts +30 -0
  36. package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -0
  37. package/dist/features/magic-context/dreamer/index.d.ts +1 -3
  38. package/dist/features/magic-context/dreamer/index.d.ts.map +1 -1
  39. package/dist/features/magic-context/dreamer/lease.d.ts +44 -6
  40. package/dist/features/magic-context/dreamer/lease.d.ts.map +1 -1
  41. package/dist/features/magic-context/dreamer/maintain-docs-protected-enforcement.d.ts +13 -0
  42. package/dist/features/magic-context/dreamer/maintain-docs-protected-enforcement.d.ts.map +1 -0
  43. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts +36 -0
  44. package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts.map +1 -0
  45. package/dist/features/magic-context/dreamer/map-memories.d.ts +22 -0
  46. package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -0
  47. package/dist/features/magic-context/dreamer/open-opencode-db.d.ts +7 -0
  48. package/dist/features/magic-context/dreamer/open-opencode-db.d.ts.map +1 -0
  49. package/dist/features/magic-context/dreamer/primer-seed.d.ts +25 -0
  50. package/dist/features/magic-context/dreamer/primer-seed.d.ts.map +1 -0
  51. package/dist/features/magic-context/dreamer/promote-primers.d.ts +21 -0
  52. package/dist/features/magic-context/dreamer/promote-primers.d.ts.map +1 -0
  53. package/dist/features/magic-context/dreamer/protected-regions.d.ts +19 -0
  54. package/dist/features/magic-context/dreamer/protected-regions.d.ts.map +1 -0
  55. package/dist/features/magic-context/dreamer/refresh-primers.d.ts +30 -0
  56. package/dist/features/magic-context/dreamer/refresh-primers.d.ts.map +1 -0
  57. package/dist/features/magic-context/dreamer/retrospective-learnings.d.ts +47 -0
  58. package/dist/features/magic-context/dreamer/retrospective-learnings.d.ts.map +1 -0
  59. package/dist/features/magic-context/dreamer/retrospective-orphan-sweep.d.ts +48 -0
  60. package/dist/features/magic-context/dreamer/retrospective-orphan-sweep.d.ts.map +1 -0
  61. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts +81 -0
  62. package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts.map +1 -0
  63. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +8 -0
  64. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
  65. package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts +82 -0
  66. package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts.map +1 -0
  67. package/dist/features/magic-context/dreamer/task-config.d.ts +28 -0
  68. package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -0
  69. package/dist/features/magic-context/dreamer/task-executor.d.ts +49 -0
  70. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -0
  71. package/dist/features/magic-context/dreamer/task-gates.d.ts +29 -0
  72. package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -0
  73. package/dist/features/magic-context/dreamer/task-prompts.d.ts +37 -6
  74. package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
  75. package/dist/features/magic-context/dreamer/task-registry.d.ts +48 -0
  76. package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -0
  77. package/dist/features/magic-context/dreamer/task-scheduler.d.ts +88 -0
  78. package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -0
  79. package/dist/features/magic-context/dreamer/verify-gate.d.ts +43 -0
  80. package/dist/features/magic-context/dreamer/verify-gate.d.ts.map +1 -0
  81. package/dist/features/magic-context/dreamer/verify-prompt.d.ts +41 -0
  82. package/dist/features/magic-context/dreamer/verify-prompt.d.ts.map +1 -0
  83. package/dist/features/magic-context/dreamer/verify.d.ts +43 -0
  84. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -0
  85. package/dist/features/magic-context/git-commits/search-git-commits.d.ts +2 -0
  86. package/dist/features/magic-context/git-commits/search-git-commits.d.ts.map +1 -1
  87. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts +4 -4
  88. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts.map +1 -1
  89. package/dist/features/magic-context/index.d.ts +1 -0
  90. package/dist/features/magic-context/index.d.ts.map +1 -1
  91. package/dist/features/magic-context/memory/embedding-cache.d.ts +2 -2
  92. package/dist/features/magic-context/memory/embedding-cache.d.ts.map +1 -1
  93. package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
  94. package/dist/features/magic-context/memory/embedding-local.d.ts +3 -3
  95. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  96. package/dist/features/magic-context/memory/embedding-openai.d.ts +20 -9
  97. package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
  98. package/dist/features/magic-context/memory/embedding-provider.d.ts +8 -4
  99. package/dist/features/magic-context/memory/embedding-provider.d.ts.map +1 -1
  100. package/dist/features/magic-context/memory/embedding.d.ts +2 -2
  101. package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
  102. package/dist/features/magic-context/memory/index.d.ts +4 -1
  103. package/dist/features/magic-context/memory/index.d.ts.map +1 -1
  104. package/dist/features/magic-context/memory/memory-migration.d.ts +1 -0
  105. package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -1
  106. package/dist/features/magic-context/memory/promotion.d.ts +16 -4
  107. package/dist/features/magic-context/memory/promotion.d.ts.map +1 -1
  108. package/dist/features/magic-context/memory/relocate-memory.d.ts +58 -0
  109. package/dist/features/magic-context/memory/relocate-memory.d.ts.map +1 -0
  110. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts +2 -2
  111. package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts.map +1 -1
  112. package/dist/features/magic-context/memory/storage-memory-verifications.d.ts +31 -0
  113. package/dist/features/magic-context/memory/storage-memory-verifications.d.ts.map +1 -0
  114. package/dist/features/magic-context/memory/storage-memory.d.ts +12 -1
  115. package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
  116. package/dist/features/magic-context/memory/types.d.ts +4 -0
  117. package/dist/features/magic-context/memory/types.d.ts.map +1 -1
  118. package/dist/features/magic-context/memory/verification-paths.d.ts +32 -0
  119. package/dist/features/magic-context/memory/verification-paths.d.ts.map +1 -0
  120. package/dist/features/magic-context/message-index.d.ts.map +1 -1
  121. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  122. package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
  123. package/dist/features/magic-context/primer-clustering.d.ts +29 -0
  124. package/dist/features/magic-context/primer-clustering.d.ts.map +1 -0
  125. package/dist/features/magic-context/project-embedding-registry.d.ts +28 -4
  126. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  127. package/dist/features/magic-context/search.d.ts +12 -2
  128. package/dist/features/magic-context/search.d.ts.map +1 -1
  129. package/dist/features/magic-context/sidekick/agent.d.ts.map +1 -1
  130. package/dist/features/magic-context/smart-notes/capabilities.d.ts +31 -0
  131. package/dist/features/magic-context/smart-notes/capabilities.d.ts.map +1 -0
  132. package/dist/features/magic-context/smart-notes/compiler-prompt.d.ts +2 -0
  133. package/dist/features/magic-context/smart-notes/compiler-prompt.d.ts.map +1 -0
  134. package/dist/features/magic-context/smart-notes/compiler.d.ts +52 -0
  135. package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -0
  136. package/dist/features/magic-context/smart-notes/index.d.ts +10 -0
  137. package/dist/features/magic-context/smart-notes/index.d.ts.map +1 -0
  138. package/dist/features/magic-context/smart-notes/runner.d.ts +18 -0
  139. package/dist/features/magic-context/smart-notes/runner.d.ts.map +1 -0
  140. package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts +22 -0
  141. package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts.map +1 -0
  142. package/dist/features/magic-context/smart-notes/schedule.d.ts +9 -0
  143. package/dist/features/magic-context/smart-notes/schedule.d.ts.map +1 -0
  144. package/dist/features/magic-context/smart-notes/ssrf-guard.d.ts +49 -0
  145. package/dist/features/magic-context/smart-notes/ssrf-guard.d.ts.map +1 -0
  146. package/dist/features/magic-context/smart-notes/storage.d.ts +27 -0
  147. package/dist/features/magic-context/smart-notes/storage.d.ts.map +1 -0
  148. package/dist/features/magic-context/smart-notes/types.d.ts +63 -0
  149. package/dist/features/magic-context/smart-notes/types.d.ts.map +1 -0
  150. package/dist/features/magic-context/storage-db.d.ts +6 -1
  151. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  152. package/dist/features/magic-context/storage-meta-persisted.d.ts +45 -4
  153. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  154. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  155. package/dist/features/magic-context/storage-meta-shared.d.ts +5 -1
  156. package/dist/features/magic-context/storage-meta-shared.d.ts.map +1 -1
  157. package/dist/features/magic-context/storage-meta.d.ts +1 -1
  158. package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
  159. package/dist/features/magic-context/storage-notes.d.ts +15 -0
  160. package/dist/features/magic-context/storage-notes.d.ts.map +1 -1
  161. package/dist/features/magic-context/storage-primers.d.ts +85 -0
  162. package/dist/features/magic-context/storage-primers.d.ts.map +1 -0
  163. package/dist/features/magic-context/storage-tags.d.ts +68 -2
  164. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  165. package/dist/features/magic-context/storage.d.ts +4 -3
  166. package/dist/features/magic-context/storage.d.ts.map +1 -1
  167. package/dist/features/magic-context/tagger.d.ts +7 -1
  168. package/dist/features/magic-context/tagger.d.ts.map +1 -1
  169. package/dist/features/magic-context/tool-owner-backfill.d.ts.map +1 -1
  170. package/dist/features/magic-context/transform-decision-log.d.ts +59 -0
  171. package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -0
  172. package/dist/features/magic-context/types.d.ts +2 -0
  173. package/dist/features/magic-context/types.d.ts.map +1 -1
  174. package/dist/features/magic-context/user-memory/review-user-memories.d.ts +5 -0
  175. package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
  176. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +18 -0
  177. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
  178. package/dist/features/magic-context/v22-deferred-backfill.d.ts.map +1 -1
  179. package/dist/hooks/auto-update-checker/semver.d.ts +9 -0
  180. package/dist/hooks/auto-update-checker/semver.d.ts.map +1 -1
  181. package/dist/hooks/magic-context/auto-search-hint.d.ts.map +1 -1
  182. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
  183. package/dist/hooks/magic-context/command-handler.d.ts +8 -15
  184. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  185. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  186. package/dist/hooks/magic-context/compartment-parser.d.ts +9 -0
  187. package/dist/hooks/magic-context/compartment-parser.d.ts.map +1 -1
  188. package/dist/hooks/magic-context/compartment-prompt.d.ts +4 -1
  189. package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
  190. package/dist/hooks/magic-context/compartment-runner-historian.d.ts +1 -0
  191. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  192. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  193. package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
  194. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  195. package/dist/hooks/magic-context/compartment-runner-types.d.ts +8 -0
  196. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  197. package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
  198. package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
  199. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  200. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts.map +1 -1
  201. package/dist/hooks/magic-context/derive-budgets.d.ts +5 -9
  202. package/dist/hooks/magic-context/derive-budgets.d.ts.map +1 -1
  203. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
  204. package/dist/hooks/magic-context/event-payloads.d.ts +1 -0
  205. package/dist/hooks/magic-context/event-payloads.d.ts.map +1 -1
  206. package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
  207. package/dist/hooks/magic-context/heuristic-cleanup.d.ts +1 -0
  208. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  209. package/dist/hooks/magic-context/historian-prompt.generated.d.ts +1 -1
  210. package/dist/hooks/magic-context/historian-prompt.generated.d.ts.map +1 -1
  211. package/dist/hooks/magic-context/historian-state-file.d.ts.map +1 -1
  212. package/dist/hooks/magic-context/hook-handlers.d.ts +2 -1
  213. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  214. package/dist/hooks/magic-context/hook.d.ts +1 -0
  215. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  216. package/dist/hooks/magic-context/inject-compartments.d.ts +0 -3
  217. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  218. package/dist/hooks/magic-context/protected-tail-boundary.d.ts +10 -0
  219. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  220. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  221. package/dist/hooks/magic-context/send-session-notification.d.ts +2 -0
  222. package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
  223. package/dist/hooks/magic-context/system-prompt-hash.d.ts +17 -0
  224. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  225. package/dist/hooks/magic-context/tag-id-fallback.d.ts.map +1 -1
  226. package/dist/hooks/magic-context/tag-messages.d.ts +10 -0
  227. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  228. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +32 -1
  229. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  230. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +14 -5
  231. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  232. package/dist/hooks/magic-context/transform.d.ts +0 -2
  233. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  234. package/dist/index.d.ts +2 -2
  235. package/dist/index.d.ts.map +1 -1
  236. package/dist/index.js +17664 -4236
  237. package/dist/plugin/dream-timer.d.ts +17 -9
  238. package/dist/plugin/dream-timer.d.ts.map +1 -1
  239. package/dist/plugin/embedding-bootstrap-helpers.d.ts +1 -1
  240. package/dist/plugin/embedding-bootstrap-helpers.d.ts.map +1 -1
  241. package/dist/plugin/embedding-bootstrap.d.ts.map +1 -1
  242. package/dist/plugin/hooks/create-session-hooks.d.ts +211 -0
  243. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  244. package/dist/plugin/instance-disposal.d.ts +2 -0
  245. package/dist/plugin/instance-disposal.d.ts.map +1 -0
  246. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  247. package/dist/shared/announcement.d.ts +1 -1
  248. package/dist/shared/announcement.d.ts.map +1 -1
  249. package/dist/shared/data-path.d.ts +26 -7
  250. package/dist/shared/data-path.d.ts.map +1 -1
  251. package/dist/shared/index.d.ts +0 -1
  252. package/dist/shared/index.d.ts.map +1 -1
  253. package/dist/shared/model-suggestion-retry.d.ts +48 -2
  254. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  255. package/dist/shared/redaction.d.ts +7 -0
  256. package/dist/shared/redaction.d.ts.map +1 -0
  257. package/dist/shared/resolve-fallbacks.d.ts +28 -16
  258. package/dist/shared/resolve-fallbacks.d.ts.map +1 -1
  259. package/dist/shared/rpc-server.d.ts.map +1 -1
  260. package/dist/shared/rpc-types.d.ts +2 -0
  261. package/dist/shared/rpc-types.d.ts.map +1 -1
  262. package/dist/shared/subagent-runner.d.ts +12 -3
  263. package/dist/shared/subagent-runner.d.ts.map +1 -1
  264. package/dist/shared/tui-config.d.ts.map +1 -1
  265. package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
  266. package/dist/tools/ctx-memory/types.d.ts.map +1 -1
  267. package/dist/tools/ctx-memory/verification-recording.d.ts +8 -0
  268. package/dist/tools/ctx-memory/verification-recording.d.ts.map +1 -0
  269. package/dist/tools/ctx-search/tools.d.ts.map +1 -1
  270. package/dist/tools/ctx-search/types.d.ts +1 -1
  271. package/dist/tools/ctx-search/types.d.ts.map +1 -1
  272. package/dist/tui/data/context-db.d.ts +2 -0
  273. package/dist/tui/data/context-db.d.ts.map +1 -1
  274. package/package.json +3 -1
  275. package/src/shared/announcement.test.ts +20 -0
  276. package/src/shared/announcement.ts +19 -7
  277. package/src/shared/data-path.test.ts +70 -6
  278. package/src/shared/data-path.ts +50 -8
  279. package/src/shared/index.ts +0 -1
  280. package/src/shared/model-suggestion-retry.test.ts +79 -2
  281. package/src/shared/model-suggestion-retry.ts +181 -3
  282. package/src/shared/redaction.test.ts +48 -0
  283. package/src/shared/redaction.ts +240 -0
  284. package/src/shared/resolve-fallbacks.test.ts +37 -71
  285. package/src/shared/resolve-fallbacks.ts +30 -26
  286. package/src/shared/rpc-server.ts +24 -0
  287. package/src/shared/rpc-types.ts +2 -0
  288. package/src/shared/subagent-runner.ts +12 -3
  289. package/src/shared/tui-config.test.ts +63 -0
  290. package/src/shared/tui-config.ts +67 -39
  291. package/src/tui/data/context-db.ts +12 -0
  292. package/src/tui/index.tsx +87 -17
  293. package/src/tui/slots/sidebar-content.tsx +15 -7
  294. package/dist/features/magic-context/dreamer/queue.d.ts +0 -55
  295. package/dist/features/magic-context/dreamer/queue.d.ts.map +0 -1
  296. package/dist/features/magic-context/dreamer/runner.d.ts +0 -92
  297. package/dist/features/magic-context/dreamer/runner.d.ts.map +0 -1
  298. package/dist/features/magic-context/dreamer/scheduler.d.ts +0 -29
  299. package/dist/features/magic-context/dreamer/scheduler.d.ts.map +0 -1
  300. package/dist/features/magic-context/key-files/aft-availability.d.ts +0 -11
  301. package/dist/features/magic-context/key-files/aft-availability.d.ts.map +0 -1
  302. package/dist/features/magic-context/key-files/identify-key-files.d.ts +0 -84
  303. package/dist/features/magic-context/key-files/identify-key-files.d.ts.map +0 -1
  304. package/dist/features/magic-context/key-files/project-key-files.d.ts +0 -42
  305. package/dist/features/magic-context/key-files/project-key-files.d.ts.map +0 -1
  306. package/dist/features/magic-context/key-files/read-history.d.ts +0 -26
  307. package/dist/features/magic-context/key-files/read-history.d.ts.map +0 -1
  308. package/dist/features/magic-context/key-files/read-stats.d.ts +0 -18
  309. package/dist/features/magic-context/key-files/read-stats.d.ts.map +0 -1
  310. package/dist/features/magic-context/key-files/storage-key-files.d.ts +0 -20
  311. package/dist/features/magic-context/key-files/storage-key-files.d.ts.map +0 -1
  312. package/dist/hooks/magic-context/key-files-block.d.ts +0 -27
  313. package/dist/hooks/magic-context/key-files-block.d.ts.map +0 -1
  314. package/dist/shared/model-requirements.d.ts +0 -26
  315. package/dist/shared/model-requirements.d.ts.map +0 -1
  316. package/src/shared/model-requirements.ts +0 -86
@@ -1,37 +1,27 @@
1
- import { getAgentFallbackModels } from "./model-requirements";
2
-
3
1
  /**
4
- * Resolve the final fallback model list to attempt for an OpenCode subagent
5
- * call.
6
- *
7
- * Policy (decided 2026-05-10):
8
- * - If user configured explicit `fallback_models` in their magic-context.jsonc
9
- * for this agent: use ONLY those. Respects user intent, no surprise
10
- * providers.
11
- * - If user did NOT configure any: fall back to the plugin's builtin
12
- * provider-agnostic chain (`AGENT_MODEL_REQUIREMENTS`).
2
+ * Resolve the fallback model list to attempt for a hidden-agent (historian /
3
+ * dreamer / sidekick) call when its configured primary fails.
13
4
  *
14
- * The returned list does NOT include the primary model it's the ordered
15
- * list of *alternates* to try after the primary fails. Each entry is
16
- * "provider/modelID" form.
5
+ * Policy: ONLY the user's explicitly-configured `fallback_models` for this
6
+ * agent. There is NO builtin provider-agnostic chain a hardcoded chain
7
+ * inevitably names providers the user doesn't have (e.g. a metapi-only user got
8
+ * a chain of google/github-copilot/opencode entries, every one a
9
+ * `Model not found` retry), which produced confusing errors and wasted
10
+ * attempts. If the user configured nothing, this returns an empty list and the
11
+ * runner's session-model last resort (the model the user is actually using) is
12
+ * the only fallback.
17
13
  *
18
- * Duplicates and empty strings are filtered. Entries that don't match the
19
- * "provider/modelID" shape (must contain a "/" with non-empty parts) are
20
- * also dropped defensive guard against malformed user config.
14
+ * The returned list does NOT include the primary model — it's the ordered list
15
+ * of *alternates* to try after the primary fails. Each entry is
16
+ * "provider/modelID" form. Duplicates and empty strings are filtered; entries
17
+ * that don't match the "provider/modelID" shape (a "/" with non-empty parts) are
18
+ * dropped as a defensive guard against malformed user config.
21
19
  */
22
20
  export function resolveFallbackChain(
23
- agentName: string,
24
21
  userFallbacks: readonly string[] | string | undefined,
25
22
  ): string[] {
26
23
  const userList = normalizeUserFallbacks(userFallbacks);
27
-
28
- if (userList.length > 0) {
29
- return dedupe(userList.filter(isValidModelSpec));
30
- }
31
-
32
- const builtin = getAgentFallbackModels(agentName);
33
- if (!builtin || builtin.length === 0) return [];
34
- return dedupe(builtin.filter(isValidModelSpec));
24
+ return dedupe(userList.filter(isValidModelSpec));
35
25
  }
36
26
 
37
27
  function normalizeUserFallbacks(userFallbacks: readonly string[] | string | undefined): string[] {
@@ -74,3 +64,17 @@ export function parseProviderModel(spec: string): { providerID: string; modelID:
74
64
  modelID: spec.slice(slash + 1).trim(),
75
65
  };
76
66
  }
67
+
68
+ /**
69
+ * Build the `{ model: { providerID, modelID } }` fragment for an OpenCode prompt
70
+ * body from a `provider/model` spec string, or `{}` when the spec is absent or
71
+ * unparseable (the session falls back to its default model). Spread into a
72
+ * `client.session.prompt` body.
73
+ */
74
+ export function modelBodyField(spec: string | undefined): {
75
+ model?: { providerID: string; modelID: string };
76
+ } {
77
+ if (!spec) return {};
78
+ const parsed = parseProviderModel(spec);
79
+ return parsed ? { model: parsed } : {};
80
+ }
@@ -1,9 +1,11 @@
1
1
  import { randomBytes, timingSafeEqual } from "node:crypto";
2
2
  import {
3
+ chmodSync,
3
4
  mkdirSync,
4
5
  readdirSync,
5
6
  readFileSync,
6
7
  renameSync,
8
+ rmSync,
7
9
  unlinkSync,
8
10
  writeFileSync,
9
11
  } from "node:fs";
@@ -85,7 +87,22 @@ export class MagicContextRpcServer {
85
87
  // file 0o600. renameSync preserves the tmp file's mode, so
86
88
  // the 0o600 on the write covers the final file.
87
89
  mkdirSync(dir, { recursive: true, mode: 0o700 });
90
+ // mkdirSync's mode only applies on CREATION — a dir left by an
91
+ // older build (or default 0o755 umask) keeps its loose perms, so
92
+ // chmod it defensively so the bearer token isn't world-readable.
93
+ try {
94
+ chmodSync(dir, 0o700);
95
+ } catch {
96
+ // best-effort
97
+ }
88
98
  const tmpPath = `${this.portFilePath}.tmp`;
99
+ // A stale tmp from a crashed write could exist with loose perms;
100
+ // writeFileSync's mode only applies on create, so remove it first.
101
+ try {
102
+ rmSync(tmpPath, { force: true });
103
+ } catch {
104
+ // best-effort
105
+ }
89
106
  writeFileSync(
90
107
  tmpPath,
91
108
  JSON.stringify({
@@ -97,6 +114,13 @@ export class MagicContextRpcServer {
97
114
  { encoding: "utf-8", mode: 0o600 },
98
115
  );
99
116
  renameSync(tmpPath, this.portFilePath);
117
+ // renameSync preserves the tmp's mode, but chmod the final path
118
+ // defensively in case the token file pre-existed with loose perms.
119
+ try {
120
+ chmodSync(this.portFilePath, 0o600);
121
+ } catch {
122
+ // best-effort
123
+ }
100
124
  log(`[rpc] server listening on 127.0.0.1:${this.port}`);
101
125
  } catch (err) {
102
126
  log(`[rpc] failed to write port file: ${err}`);
@@ -121,6 +121,8 @@ export interface StatusDetail extends SidebarSnapshot {
121
121
  historyBlockTokens: number;
122
122
  compressionBudget: number | null;
123
123
  compressionUsage: string | null;
124
+ /** Effective configured toast duration in ms after config resolution. */
125
+ toastDurationMs: number;
124
126
  }
125
127
 
126
128
  /** Embedding coverage for `/ctx-embed` status (mirrors getEmbeddingCoverageStatus). */
@@ -155,9 +155,9 @@ export type SubagentProgressEvent =
155
155
  * Fields:
156
156
  * - `ok`: true iff the child produced a final assistant message.
157
157
  * - `assistantText`: concatenated text content from the final assistant
158
- * message, with leading/trailing whitespace trimmed. Empty string if the
159
- * child finished but produced no text (rare usually means the model
160
- * only emitted tool calls and we didn't follow up).
158
+ * message, with leading/trailing whitespace trimmed. Empty assistant text is
159
+ * reported as `ok: false, reason: "no_assistant"` so callers can try fallback
160
+ * models instead of accepting an unusable success.
161
161
  * - `reason`: failure category, one of:
162
162
  * - `"timeout"`: hit `timeoutMs` before the child finished
163
163
  * - `"abort"`: caller's `signal` was triggered
@@ -180,6 +180,15 @@ export type SubagentRunResult =
180
180
  ok: true;
181
181
  assistantText: string;
182
182
  durationMs: number;
183
+ /**
184
+ * Number of tool invocations the agent made during the run. Pi reports
185
+ * this so callers that gate on "did the agent actually investigate vs
186
+ * just paraphrase" (refresh-primers' grounding gate) work on Pi, whose
187
+ * facade otherwise surfaces only the final assistant text. OpenCode
188
+ * leaves it undefined — its callers read tool-call parts straight off
189
+ * the real session messages.
190
+ */
191
+ toolCallCount?: number;
183
192
  meta?: Record<string, unknown>;
184
193
  }
185
194
  | {
@@ -0,0 +1,63 @@
1
+ import { afterEach, describe, expect, it } from "bun:test";
2
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ const roots: string[] = [];
7
+ const prevConfigDir = process.env.OPENCODE_CONFIG_DIR;
8
+
9
+ afterEach(() => {
10
+ if (prevConfigDir === undefined) delete process.env.OPENCODE_CONFIG_DIR;
11
+ else process.env.OPENCODE_CONFIG_DIR = prevConfigDir;
12
+ for (const root of roots.splice(0)) {
13
+ rmSync(root, { recursive: true, force: true });
14
+ }
15
+ });
16
+
17
+ describe("ensureTuiPluginEntry", () => {
18
+ it("preserves tuple dev-path plugin entry and does not add @latest", async () => {
19
+ const root = mkdtempSync(join(tmpdir(), "mc-tui-"));
20
+ roots.push(root);
21
+ process.env.OPENCODE_CONFIG_DIR = root;
22
+ const devPath = "/Work/magic-context/packages/plugin";
23
+ const tuiPath = join(root, "tui.json");
24
+ writeFileSync(
25
+ tuiPath,
26
+ `${JSON.stringify({ plugin: [[devPath, { sidebar: true }], "other-plugin"] }, null, 2)}\n`,
27
+ );
28
+
29
+ const { ensureTuiPluginEntry } = await import("./tui-config");
30
+ const changed = ensureTuiPluginEntry();
31
+ expect(changed).toBe(false);
32
+ const parsed = JSON.parse(readFileSync(tuiPath, "utf-8")) as { plugin: unknown[] };
33
+ expect(parsed.plugin).toHaveLength(2);
34
+ expect(Array.isArray(parsed.plugin[0])).toBe(true);
35
+ expect((parsed.plugin[0] as unknown[])[0]).toBe(devPath);
36
+ expect(parsed.plugin[1]).toBe("other-plugin");
37
+ expect(existsSync(`${tuiPath}.tmp`)).toBe(false);
38
+ });
39
+
40
+ it("upgrades bare npm name to @latest while preserving tuple options", async () => {
41
+ const root = mkdtempSync(join(tmpdir(), "mc-tui-npm-"));
42
+ roots.push(root);
43
+ process.env.OPENCODE_CONFIG_DIR = root;
44
+ const tuiPath = join(root, "tui.json");
45
+ writeFileSync(
46
+ tuiPath,
47
+ `${JSON.stringify(
48
+ {
49
+ plugin: [["@cortexkit/opencode-magic-context", { enabled: true }]],
50
+ },
51
+ null,
52
+ 2,
53
+ )}\n`,
54
+ );
55
+
56
+ const { ensureTuiPluginEntry } = await import("./tui-config");
57
+ expect(ensureTuiPluginEntry()).toBe(true);
58
+ const parsed = JSON.parse(readFileSync(tuiPath, "utf-8")) as { plugin: unknown[] };
59
+ const entry = parsed.plugin[0] as unknown[];
60
+ expect(entry[0]).toBe("@cortexkit/opencode-magic-context@latest");
61
+ expect(entry[1]).toEqual({ enabled: true });
62
+ });
63
+ });
@@ -3,7 +3,15 @@
3
3
  * Called from the server plugin at startup so the TUI sidebar loads on next restart.
4
4
  */
5
5
 
6
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
6
+ import {
7
+ chmodSync,
8
+ existsSync,
9
+ mkdirSync,
10
+ readFileSync,
11
+ renameSync,
12
+ statSync,
13
+ writeFileSync,
14
+ } from "node:fs";
7
15
  import { dirname, join } from "node:path";
8
16
  import { parse, stringify } from "comment-json";
9
17
  import { log } from "./logger";
@@ -12,27 +20,41 @@ import { getOpenCodeConfigPaths } from "./opencode-config-dir";
12
20
  const PLUGIN_NAME = "@cortexkit/opencode-magic-context";
13
21
  const PLUGIN_ENTRY = `${PLUGIN_NAME}@latest`;
14
22
 
15
- /**
16
- * Detect whether a tui.json plugin entry already references magic-context, in
17
- * any form. Covers:
18
- * - Bare npm name: "@cortexkit/opencode-magic-context"
19
- * - Versioned npm: "@cortexkit/opencode-magic-context@latest" / "@0.15.7" / etc.
20
- * - Local dev directory path (absolute or relative): ".../magic-context"
21
- * or ".../magic-context/packages/plugin"
22
- * - file:// URLs pointing at the same paths
23
- * - Tarball paths ending in opencode-magic-context-*.tgz
24
- *
25
- * Without the path/URL detection, doctor/setup auto-injection adds the npm
26
- * @latest entry on top of an existing dev path, double-loading the plugin.
27
- */
28
- function isMagicContextEntry(entry: string): boolean {
29
- if (!entry) return false;
30
- if (entry === PLUGIN_NAME) return true;
31
- if (entry.startsWith(`${PLUGIN_NAME}@`)) return true;
32
- // Local directory paths: match anywhere in the string so the setup pattern
33
- // (dir-only, dir + /packages/plugin, file:// + either) all qualify.
34
- if (entry.includes("opencode-magic-context")) return true;
35
- return false;
23
+ function pluginEntryId(entry: unknown): string {
24
+ if (typeof entry === "string") return entry;
25
+ if (Array.isArray(entry) && typeof entry[0] === "string") return entry[0];
26
+ return "";
27
+ }
28
+
29
+ function isLocalMagicContextDevEntry(entry: unknown): boolean {
30
+ const id = pluginEntryId(entry);
31
+ if (!id) return false;
32
+ if (id === PLUGIN_NAME || id.startsWith(`${PLUGIN_NAME}@`)) return false;
33
+ const isPath =
34
+ id.startsWith("file://") || id.startsWith("/") || id.startsWith("./") || id.includes("\\");
35
+ if (!isPath) return false;
36
+ return id.includes("opencode-magic-context") || id.includes("magic-context");
37
+ }
38
+
39
+ function isMagicContextPluginEntry(entry: unknown): boolean {
40
+ const id = pluginEntryId(entry);
41
+ if (!id) return false;
42
+ if (id === PLUGIN_NAME || id.startsWith(`${PLUGIN_NAME}@`)) return true;
43
+ return isLocalMagicContextDevEntry(entry);
44
+ }
45
+
46
+ function writeTuiConfigAtomic(configPath: string, config: Record<string, unknown>): void {
47
+ const body = `${stringify(config, null, 2)}\n`;
48
+ const tmpPath = `${configPath}.tmp`;
49
+ writeFileSync(tmpPath, body);
50
+ try {
51
+ if (statSync(configPath, { throwIfNoEntry: false })?.isFile()) {
52
+ chmodSync(tmpPath, statSync(configPath).mode & 0o777);
53
+ }
54
+ } catch {
55
+ /* new file */
56
+ }
57
+ renameSync(tmpPath, configPath);
36
58
  }
37
59
 
38
60
  function resolveTuiConfigPath(): string {
@@ -59,35 +81,41 @@ export function ensureTuiPluginEntry(): boolean {
59
81
  config = (parse(raw) as Record<string, unknown>) ?? {};
60
82
  }
61
83
 
62
- const plugins = Array.isArray(config.plugin)
63
- ? config.plugin.filter((p): p is string => typeof p === "string")
64
- : [];
84
+ const plugins: unknown[] = Array.isArray(config.plugin) ? [...config.plugin] : [];
65
85
 
66
- const existingIdx = plugins.findIndex(isMagicContextEntry);
86
+ const existingIdx = plugins.findIndex(isMagicContextPluginEntry);
67
87
  if (existingIdx >= 0) {
68
88
  const existing = plugins[existingIdx];
69
- if (existing === PLUGIN_ENTRY) {
70
- return false; // Already @latest
89
+ if (isLocalMagicContextDevEntry(existing)) {
90
+ return false;
91
+ }
92
+ const id = pluginEntryId(existing);
93
+ if (id === PLUGIN_ENTRY) {
94
+ return false;
71
95
  }
72
- // Only upgrade the bare versionless npm name to @latest.
73
- // Pinned versions (e.g. @0.8.10), local dev paths
74
- // (~/Work/OSS/magic-context/packages/plugin), and
75
- // file:// URLs are all left as-is — the user chose them
76
- // intentionally and overwriting their dev-loop entry would
77
- // either double-load the plugin (npm + dev) or replace
78
- // their working directory pointer.
79
- if (existing === PLUGIN_NAME) {
80
- plugins[existingIdx] = PLUGIN_ENTRY;
96
+ if (id === PLUGIN_NAME) {
97
+ if (Array.isArray(existing) && existing.length >= 1) {
98
+ const replacement = [...existing];
99
+ replacement[0] = PLUGIN_ENTRY;
100
+ plugins[existingIdx] = replacement;
101
+ } else {
102
+ plugins[existingIdx] = PLUGIN_ENTRY;
103
+ }
81
104
  } else {
82
105
  return false;
83
106
  }
84
107
  } else {
85
- plugins.push(PLUGIN_ENTRY);
108
+ const hasDev = plugins.some(isLocalMagicContextDevEntry);
109
+ if (!hasDev) {
110
+ plugins.push(PLUGIN_ENTRY);
111
+ } else {
112
+ return false;
113
+ }
86
114
  }
87
115
  config.plugin = plugins;
88
116
 
89
117
  mkdirSync(dirname(configPath), { recursive: true });
90
- writeFileSync(configPath, `${stringify(config, null, 2)}\n`);
118
+ writeTuiConfigAtomic(configPath, config);
91
119
  log(`[magic-context] updated TUI plugin entry in ${configPath}`);
92
120
  return true;
93
121
  } catch (error) {
@@ -205,6 +205,7 @@ export async function loadStatusDetail(
205
205
  historyBlockTokens: 0,
206
206
  compressionBudget: null,
207
207
  compressionUsage: null,
208
+ toastDurationMs: 5000,
208
209
  };
209
210
 
210
211
  if (!rpcClient) return emptyDetail;
@@ -299,6 +300,17 @@ export async function dismissUpgradeReminder(sessionId: string): Promise<boolean
299
300
  }
300
301
  }
301
302
 
303
+ /** Resolve global toast duration from server config via RPC. */
304
+ export async function loadToastDurationMs(): Promise<number> {
305
+ if (!rpcClient) return 5000;
306
+ try {
307
+ const result = await rpcClient.call<{ toastDurationMs?: number }>("toast-duration", {});
308
+ return typeof result.toastDurationMs === "number" ? result.toastDurationMs : 5000;
309
+ } catch {
310
+ return 5000;
311
+ }
312
+ }
313
+
302
314
  export interface TuiMessage {
303
315
  id: number;
304
316
  type: string;
package/src/tui/index.tsx CHANGED
@@ -6,7 +6,7 @@ import { createMemo } from "solid-js"
6
6
  import type { TuiPlugin, TuiPluginApi, TuiThemeCurrent } from "@opencode-ai/plugin/tui"
7
7
  import { createSidebarContentSlot, kickRecompProgressRefresh } from "./slots/sidebar-content"
8
8
  import packageJson from "../../package.json"
9
- import { closeRpc, consumeTuiMessages, dismissUpgradeReminder, getAnnouncement, getCompartmentCount, getRpcGeneration, initRpcClient, loadEmbedDetail, loadStatusDetail, markAnnounced, markTuiMessagesHandled, requestRecomp, requestUpgrade, type EmbedDetail, type TuiMessage, type StatusDetail } from "./data/context-db"
9
+ import { closeRpc, consumeTuiMessages, dismissUpgradeReminder, getAnnouncement, getCompartmentCount, getRpcGeneration, initRpcClient, loadEmbedDetail, loadStatusDetail, loadToastDurationMs, markAnnounced, markTuiMessagesHandled, requestRecomp, requestUpgrade, type EmbedDetail, type TuiMessage, type StatusDetail } from "./data/context-db"
10
10
  import { formatThresholdPercent } from "../shared/format-threshold"
11
11
  import { detectConflicts } from "../shared/conflict-detector"
12
12
  import { fixConflicts } from "../shared/conflict-fixer"
@@ -14,6 +14,48 @@ import { readJsoncFile } from "../shared/jsonc-parser"
14
14
  import { getOpenCodeConfigPaths } from "../shared/opencode-config-dir"
15
15
 
16
16
  const PLUGIN_NAME = "@cortexkit/opencode-magic-context"
17
+ const DEFAULT_TOAST_DURATION_MS = 5000
18
+ let unifiedToastDurationMs = DEFAULT_TOAST_DURATION_MS
19
+
20
+ async function refreshToastDurationMs(): Promise<void> {
21
+ try {
22
+ const resolved = await loadToastDurationMs()
23
+ if (typeof resolved === "number" && Number.isFinite(resolved)) {
24
+ unifiedToastDurationMs = resolved
25
+ }
26
+ } catch {
27
+ // Keep the current value; the next poll/startup can retry.
28
+ }
29
+ }
30
+
31
+ function getToastDurationMs(): number {
32
+ return unifiedToastDurationMs
33
+ }
34
+
35
+ function showToast(
36
+ api: TuiPluginApi,
37
+ input: {
38
+ message: string
39
+ variant: "info" | "warning" | "error" | "success"
40
+ durationOverrideMs?: number
41
+ },
42
+ ): void {
43
+ const duration =
44
+ typeof input.durationOverrideMs === "number" && Number.isFinite(input.durationOverrideMs)
45
+ ? input.durationOverrideMs
46
+ : getToastDurationMs()
47
+ // toast_duration_ms = 0 disables Magic Context toasts entirely. An explicit
48
+ // positive per-call override (e.g. restart-required) still shows; only a
49
+ // non-positive effective duration suppresses the toast.
50
+ if (!(duration > 0)) {
51
+ return
52
+ }
53
+ api.ui.toast({
54
+ message: input.message,
55
+ variant: input.variant,
56
+ duration,
57
+ })
58
+ }
17
59
 
18
60
  function ensureParentDir(filePath: string) {
19
61
  mkdirSync(dirname(filePath), { recursive: true })
@@ -97,14 +139,18 @@ function showConflictDialog(api: TuiPluginApi, directory: string, reasons: strin
97
139
  title="✅ Configuration Fixed"
98
140
  message={`${actionSummary}\n\nPlease restart OpenCode for changes to take effect.`}
99
141
  onConfirm={() => {
100
- api.ui.toast({ message: "Restart OpenCode to enable Magic Context", variant: "warning", duration: 10000 })
142
+ showToast(api, {
143
+ message: "Restart OpenCode to enable Magic Context",
144
+ variant: "warning",
145
+ durationOverrideMs: 10_000,
146
+ })
101
147
  }}
102
148
  />
103
149
  ))
104
150
  }, 50)
105
151
  }}
106
152
  onCancel={() => {
107
- api.ui.toast({ message: "Magic Context remains disabled. Run: npx @cortexkit/opencode-magic-context@latest doctor", variant: "warning", duration: 5000 })
153
+ showToast(api, { message: "Magic Context remains disabled. Run: npx @cortexkit/opencode-magic-context@latest doctor", variant: "warning" })
108
154
  }}
109
155
  />
110
156
  ))
@@ -132,7 +178,7 @@ function showTuiSetupDialog(api: TuiPluginApi) {
132
178
  title="❌ Setup Failed"
133
179
  message={'Could not update tui.json automatically. Add the plugin manually:\n\n { "plugin": ["@cortexkit/opencode-magic-context"] }'}
134
180
  onConfirm={() => {
135
- api.ui.toast({ message: "Add plugin to tui.json manually", variant: "warning", duration: 5000 })
181
+ showToast(api, { message: "Add plugin to tui.json manually", variant: "warning" })
136
182
  }}
137
183
  />
138
184
  ))
@@ -146,14 +192,18 @@ function showTuiSetupDialog(api: TuiPluginApi) {
146
192
  title="✅ Sidebar Enabled"
147
193
  message="tui.json updated with Magic Context plugin.\n\nPlease restart OpenCode to see the sidebar."
148
194
  onConfirm={() => {
149
- api.ui.toast({ message: "Restart OpenCode to see the sidebar", variant: "warning", duration: 10000 })
195
+ showToast(api, {
196
+ message: "Restart OpenCode to see the sidebar",
197
+ variant: "warning",
198
+ durationOverrideMs: 10_000,
199
+ })
150
200
  }}
151
201
  />
152
202
  ))
153
203
  }, 50)
154
204
  }}
155
205
  onCancel={() => {
156
- api.ui.toast({ message: "You can add the sidebar later via: npx @cortexkit/opencode-magic-context@latest doctor", variant: "info", duration: 5000 })
206
+ showToast(api, { message: "You can add the sidebar later via: npx @cortexkit/opencode-magic-context@latest doctor", variant: "info" })
157
207
  }}
158
208
  />
159
209
  ))
@@ -203,8 +253,16 @@ const StatusDialog = (props: { api: TuiPluginApi; s: StatusDetail }) => {
203
253
  const t = () => theme()
204
254
  const s = () => props.s
205
255
 
256
+ // Prefer the RPC-provided model context limit (what the sidebar shows) so the
257
+ // two surfaces never disagree. Fall back to deriving from usage% only when the
258
+ // RPC limit is absent (0) — and that derivation is itself undefined at 0%, so
259
+ // it stays "?" rather than showing a number inconsistent with the sidebar.
206
260
  const contextLimit = () =>
207
- s().usagePercentage > 0 ? Math.round(s().inputTokens / (s().usagePercentage / 100)) : 0
261
+ s().contextLimit > 0
262
+ ? s().contextLimit
263
+ : s().usagePercentage > 0
264
+ ? Math.round(s().inputTokens / (s().usagePercentage / 100))
265
+ : 0
208
266
 
209
267
  const elapsed = () => (s().lastResponseTime > 0 ? Date.now() - s().lastResponseTime : 0)
210
268
 
@@ -450,7 +508,7 @@ function getModelKeyFromMessages(api: TuiPluginApi, sessionId: string): string |
450
508
  async function showRecompDialog(api: TuiPluginApi, targetSessionId = getSessionId(api)): Promise<boolean> {
451
509
  const sessionId = targetSessionId
452
510
  if (!sessionId) {
453
- api.ui.toast({ message: "No active session", variant: "warning" })
511
+ showToast(api, { message: "No active session", variant: "warning" })
454
512
  return false
455
513
  }
456
514
 
@@ -475,10 +533,10 @@ async function showRecompDialog(api: TuiPluginApi, targetSessionId = getSessionI
475
533
  onConfirm={() => {
476
534
  void requestRecomp(sessionId)
477
535
  kickRecompProgressRefresh()
478
- api.ui.toast({ message: "Recomp requested — historian will start shortly", variant: "info", duration: 5000 })
536
+ showToast(api, { message: "Recomp requested — historian will start shortly", variant: "info" })
479
537
  }}
480
538
  onCancel={() => {
481
- api.ui.toast({ message: "Recomp cancelled", variant: "info", duration: 3000 })
539
+ showToast(api, { message: "Recomp cancelled", variant: "info", durationOverrideMs: 3000 })
482
540
  }}
483
541
  />
484
542
  ))
@@ -535,12 +593,11 @@ function showUpgradeDialog(
535
593
  // call fires no message event, so without this the progress
536
594
  // bar wouldn't appear until the upgrade finished.
537
595
  kickRecompProgressRefresh()
538
- api.ui.toast({
596
+ showToast(api, {
539
597
  message: resume
540
598
  ? "Resuming session upgrade — running in the background"
541
599
  : "Session upgrade started — running in the background",
542
600
  variant: "info",
543
- duration: 5000,
544
601
  })
545
602
  // Dismiss the durable reminder ONLY after the upgrade request
546
603
  // actually started. If requestUpgrade() returns false (RPC /
@@ -558,10 +615,10 @@ function showUpgradeDialog(
558
615
  // never-upgraded session (dogfood 2026-05-30) relies on THIS
559
616
  // being the only place the TUI path stamps.
560
617
  void dismissUpgradeReminder(sessionId)
561
- api.ui.toast({
618
+ showToast(api, {
562
619
  message: "Upgrade skipped — run /ctx-session-upgrade anytime",
563
620
  variant: "info",
564
- duration: 4000,
621
+ durationOverrideMs: 4000,
565
622
  })
566
623
  }}
567
624
  />
@@ -573,7 +630,7 @@ function showUpgradeDialog(
573
630
  async function showStatusDialog(api: TuiPluginApi, targetSessionId = getSessionId(api)): Promise<boolean> {
574
631
  const sessionId = targetSessionId
575
632
  if (!sessionId) {
576
- api.ui.toast({ message: "No active session", variant: "warning" })
633
+ showToast(api, { message: "No active session", variant: "warning" })
577
634
  return false
578
635
  }
579
636
 
@@ -793,6 +850,7 @@ const tui: TuiPlugin = async (api, _options, meta) => {
793
850
  // Initialize RPC client for server communication
794
851
  const directory = api.state.path.directory ?? ""
795
852
  initRpcClient(directory)
853
+ await refreshToastDurationMs()
796
854
 
797
855
  // Register sidebar slot
798
856
  api.slots.register(createSidebarContentSlot(api))
@@ -830,6 +888,9 @@ const tui: TuiPlugin = async (api, _options, meta) => {
830
888
  pollInFlight = true
831
889
  const pollGeneration = getRpcGeneration()
832
890
  void consumeTuiMessages(requestedSessionId).then(async (messages) => {
891
+ if (unifiedToastDurationMs === DEFAULT_TOAST_DURATION_MS) {
892
+ void refreshToastDurationMs()
893
+ }
833
894
  // The dialog handlers read the current session when they run. If the
834
895
  // user switched routes while the RPC was in flight, drop this whole
835
896
  // batch without advancing the cursor; the next poll for the new
@@ -843,6 +904,12 @@ const tui: TuiPlugin = async (api, _options, meta) => {
843
904
  const orderedMessages = [...messages].sort((a, b) => a.id - b.id)
844
905
  const handledMessageIds = new Set<number>()
845
906
  for (const msg of orderedMessages) {
907
+ // A dialog helper earlier in this batch may have awaited; re-check
908
+ // the route before EACH message so a later action/toast in the same
909
+ // batch can't paint into a session the user switched to mid-batch
910
+ // (the pre-batch + pre-ack guards alone don't cover mid-batch awaits).
911
+ if (getRpcGeneration() !== pollGeneration) return
912
+ if (getSessionId(api) !== requestedSessionId) return
846
913
  // Drop any action/dialog whose sessionId doesn't match this TUI's
847
914
  // active session (session-less/global notifications still apply).
848
915
  if (
@@ -854,10 +921,13 @@ const tui: TuiPlugin = async (api, _options, meta) => {
854
921
  }
855
922
  if (msg.type === "toast") {
856
923
  const p = msg.payload
857
- api.ui.toast({
924
+ showToast(api, {
858
925
  message: String(p.message ?? ""),
859
926
  variant: (p.variant as "info" | "warning" | "error" | "success") ?? "info",
860
- duration: typeof p.duration === "number" ? p.duration : 5000,
927
+ durationOverrideMs:
928
+ typeof p.duration === "number" && Number.isFinite(p.duration)
929
+ ? p.duration
930
+ : undefined,
861
931
  })
862
932
  handledMessageIds.add(msg.id)
863
933
  } else if (msg.type === "action") {