@cortexkit/opencode-magic-context 0.41.3 → 0.42.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 (384) hide show
  1. package/README.md +21 -3
  2. package/dist/agents/hidden-agent-registrations.d.ts +1 -3
  3. package/dist/agents/hidden-agent-registrations.d.ts.map +1 -1
  4. package/dist/agents/magic-context-prompt.d.ts +1 -1
  5. package/dist/agents/magic-context-prompt.d.ts.map +1 -1
  6. package/dist/agents/permissions.d.ts +1 -22
  7. package/dist/agents/permissions.d.ts.map +1 -1
  8. package/dist/config/agent-disable.d.ts +0 -5
  9. package/dist/config/agent-disable.d.ts.map +1 -1
  10. package/dist/config/index.d.ts +14 -0
  11. package/dist/config/index.d.ts.map +1 -1
  12. package/dist/config/migrate-config-location.d.ts.map +1 -1
  13. package/dist/config/project-security.d.ts +17 -0
  14. package/dist/config/project-security.d.ts.map +1 -1
  15. package/dist/config/removed-agent-config.d.ts +8 -0
  16. package/dist/config/removed-agent-config.d.ts.map +1 -0
  17. package/dist/config/schema/magic-context.d.ts +23 -201
  18. package/dist/config/schema/magic-context.d.ts.map +1 -1
  19. package/dist/{conflict-warning-hook-z5sd697e.js → conflict-warning-hook-6p3xqeac.js} +4 -4
  20. package/dist/{derive-budgets-901a0pk0.js → derive-budgets-s2pgnnm4.js} +4 -2
  21. package/dist/features/builtin-commands/commands.d.ts +0 -4
  22. package/dist/features/builtin-commands/commands.d.ts.map +1 -1
  23. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  24. package/dist/features/magic-context/compartment-chunk-embedding.d.ts +7 -0
  25. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  26. package/dist/features/magic-context/compartment-storage.d.ts.map +1 -1
  27. package/dist/features/magic-context/context-authority.d.ts +31 -4
  28. package/dist/features/magic-context/context-authority.d.ts.map +1 -1
  29. package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
  30. package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -1
  31. package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
  32. package/dist/features/magic-context/dreamer/open-opencode-db.d.ts.map +1 -1
  33. package/dist/features/magic-context/dreamer/refresh-primers.d.ts.map +1 -1
  34. package/dist/features/magic-context/dreamer/retrospective-orphan-sweep.d.ts +19 -9
  35. package/dist/features/magic-context/dreamer/retrospective-orphan-sweep.d.ts.map +1 -1
  36. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +13 -0
  37. package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
  38. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  39. package/dist/features/magic-context/dreamer/task-scheduler.d.ts +7 -0
  40. package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
  41. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  42. package/dist/features/magic-context/fail-closed-block.d.ts.map +1 -1
  43. package/dist/features/magic-context/git-commits/sweep-coordinator.d.ts.map +1 -1
  44. package/dist/features/magic-context/index.d.ts +0 -1
  45. package/dist/features/magic-context/index.d.ts.map +1 -1
  46. package/dist/features/magic-context/memory/embedding-local.d.ts +13 -0
  47. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  48. package/dist/features/magic-context/memory/embedding-synapse.d.ts +43 -10
  49. package/dist/features/magic-context/memory/embedding-synapse.d.ts.map +1 -1
  50. package/dist/features/magic-context/memory/embedding.d.ts +1 -1
  51. package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
  52. package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -1
  53. package/dist/features/magic-context/memory/project-identity.d.ts +1 -0
  54. package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
  55. package/dist/features/magic-context/memory/promotion.d.ts +7 -1
  56. package/dist/features/magic-context/memory/promotion.d.ts.map +1 -1
  57. package/dist/features/magic-context/merged-reasoning-decisions.d.ts +6 -0
  58. package/dist/features/magic-context/merged-reasoning-decisions.d.ts.map +1 -0
  59. package/dist/features/magic-context/message-fts-rowid-map.d.ts.map +1 -1
  60. package/dist/features/magic-context/message-index-async.d.ts +12 -0
  61. package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
  62. package/dist/features/magic-context/message-index.d.ts.map +1 -1
  63. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  64. package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
  65. package/dist/features/magic-context/mural/render-trigger.d.ts +6 -0
  66. package/dist/features/magic-context/mural/render-trigger.d.ts.map +1 -1
  67. package/dist/features/magic-context/no-content-compartment.d.ts +12 -0
  68. package/dist/features/magic-context/no-content-compartment.d.ts.map +1 -0
  69. package/dist/features/magic-context/pi-content-decisions.d.ts +9 -0
  70. package/dist/features/magic-context/pi-content-decisions.d.ts.map +1 -0
  71. package/dist/features/magic-context/project-docs-hash.d.ts +4 -0
  72. package/dist/features/magic-context/project-docs-hash.d.ts.map +1 -1
  73. package/dist/features/magic-context/project-embedding-registry.d.ts +13 -4
  74. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  75. package/dist/features/magic-context/protection-window.d.ts +79 -0
  76. package/dist/features/magic-context/protection-window.d.ts.map +1 -0
  77. package/dist/features/magic-context/search.d.ts.map +1 -1
  78. package/dist/features/magic-context/session-project-backfill.d.ts.map +1 -1
  79. package/dist/features/magic-context/shadow-backfill-state.d.ts +26 -0
  80. package/dist/features/magic-context/shadow-backfill-state.d.ts.map +1 -0
  81. package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -1
  82. package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts +4 -0
  83. package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts.map +1 -1
  84. package/dist/features/magic-context/smart-notes/storage.d.ts.map +1 -1
  85. package/dist/features/magic-context/storage-clone.d.ts.map +1 -1
  86. package/dist/features/magic-context/storage-db.d.ts +1 -1
  87. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  88. package/dist/features/magic-context/storage-embedding-measurements.d.ts +2 -2
  89. package/dist/features/magic-context/storage-embedding-measurements.d.ts.map +1 -1
  90. package/dist/features/magic-context/storage-historian-runs.d.ts +4 -0
  91. package/dist/features/magic-context/storage-historian-runs.d.ts.map +1 -1
  92. package/dist/features/magic-context/storage-memory-mutation-log.d.ts +1 -0
  93. package/dist/features/magic-context/storage-memory-mutation-log.d.ts.map +1 -1
  94. package/dist/features/magic-context/storage-meta-persisted.d.ts +81 -15
  95. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  96. package/dist/features/magic-context/storage-meta.d.ts +1 -1
  97. package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
  98. package/dist/features/magic-context/storage-native-replay.d.ts +29 -0
  99. package/dist/features/magic-context/storage-native-replay.d.ts.map +1 -0
  100. package/dist/features/magic-context/storage-notes.d.ts +6 -0
  101. package/dist/features/magic-context/storage-notes.d.ts.map +1 -1
  102. package/dist/features/magic-context/storage-replay-document.d.ts +33 -0
  103. package/dist/features/magic-context/storage-replay-document.d.ts.map +1 -0
  104. package/dist/features/magic-context/storage-subagent-invocations.d.ts +1 -1
  105. package/dist/features/magic-context/storage-subagent-invocations.d.ts.map +1 -1
  106. package/dist/features/magic-context/storage-tags.d.ts +19 -11
  107. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  108. package/dist/features/magic-context/storage.d.ts +3 -3
  109. package/dist/features/magic-context/storage.d.ts.map +1 -1
  110. package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -1
  111. package/dist/features/magic-context/tagger.d.ts +13 -0
  112. package/dist/features/magic-context/tagger.d.ts.map +1 -1
  113. package/dist/features/magic-context/tool-owner-backfill.d.ts.map +1 -1
  114. package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
  115. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
  116. package/dist/features/magic-context/workspaces.d.ts.map +1 -1
  117. package/dist/hooks/magic-context/apply-operations.d.ts +11 -5
  118. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  119. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
  120. package/dist/hooks/magic-context/cache-busting-signals.d.ts +9 -1
  121. package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
  122. package/dist/hooks/magic-context/caveman-cleanup.d.ts +1 -1
  123. package/dist/hooks/magic-context/caveman-cleanup.d.ts.map +1 -1
  124. package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
  125. package/dist/hooks/magic-context/child-session-spawn.d.ts +3 -3
  126. package/dist/hooks/magic-context/child-session-spawn.d.ts.map +1 -1
  127. package/dist/hooks/magic-context/command-handler.d.ts +5 -10
  128. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  129. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  130. package/dist/hooks/magic-context/compartment-runner-drop-queue.d.ts +10 -21
  131. package/dist/hooks/magic-context/compartment-runner-drop-queue.d.ts.map +1 -1
  132. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  133. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  134. package/dist/hooks/magic-context/compartment-runner-types.d.ts +4 -0
  135. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  136. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts +26 -2
  137. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts.map +1 -1
  138. package/dist/hooks/magic-context/decay-render.d.ts.map +1 -1
  139. package/dist/hooks/magic-context/derive-budgets.d.ts +1 -0
  140. package/dist/hooks/magic-context/derive-budgets.d.ts.map +1 -1
  141. package/dist/hooks/magic-context/dropped-input-guard.d.ts +9 -0
  142. package/dist/hooks/magic-context/dropped-input-guard.d.ts.map +1 -0
  143. package/dist/hooks/magic-context/emergency-drop.d.ts +9 -2
  144. package/dist/hooks/magic-context/emergency-drop.d.ts.map +1 -1
  145. package/dist/hooks/magic-context/event-handler.d.ts +0 -1
  146. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
  147. package/dist/hooks/magic-context/event-payloads.d.ts +7 -6
  148. package/dist/hooks/magic-context/event-payloads.d.ts.map +1 -1
  149. package/dist/hooks/magic-context/event-resolvers.d.ts +1 -1
  150. package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
  151. package/dist/hooks/magic-context/execute-status.d.ts +8 -2
  152. package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
  153. package/dist/hooks/magic-context/format-embed-status.d.ts.map +1 -1
  154. package/dist/hooks/magic-context/heuristic-cleanup.d.ts +11 -4
  155. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  156. package/dist/hooks/magic-context/hook-handlers.d.ts +5 -1
  157. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  158. package/dist/hooks/magic-context/hook.d.ts +17 -5
  159. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  160. package/dist/hooks/magic-context/inject-compartments.d.ts +14 -1
  161. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  162. package/dist/hooks/magic-context/issue-423-fixture.d.ts +37 -0
  163. package/dist/hooks/magic-context/issue-423-fixture.d.ts.map +1 -0
  164. package/dist/hooks/magic-context/issue-424-fixture.d.ts +11 -0
  165. package/dist/hooks/magic-context/issue-424-fixture.d.ts.map +1 -0
  166. package/dist/hooks/magic-context/live-session-state.d.ts +1 -1
  167. package/dist/hooks/magic-context/lkg-slot.d.ts +34 -0
  168. package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
  169. package/dist/hooks/magic-context/module-state-sync-timing.d.ts +21 -0
  170. package/dist/hooks/magic-context/module-state-sync-timing.d.ts.map +1 -0
  171. package/dist/hooks/magic-context/module-state-sync.d.ts +21 -7
  172. package/dist/hooks/magic-context/module-state-sync.d.ts.map +1 -1
  173. package/dist/hooks/magic-context/module-transport.d.ts +12 -0
  174. package/dist/hooks/magic-context/module-transport.d.ts.map +1 -1
  175. package/dist/hooks/magic-context/module-wire.d.ts +8 -0
  176. package/dist/hooks/magic-context/module-wire.d.ts.map +1 -1
  177. package/dist/hooks/magic-context/note-nudger.d.ts.map +1 -1
  178. package/dist/hooks/magic-context/persist-filtered-noise.d.ts +5 -0
  179. package/dist/hooks/magic-context/persist-filtered-noise.d.ts.map +1 -0
  180. package/dist/hooks/magic-context/producer-window-guard.d.ts +8 -0
  181. package/dist/hooks/magic-context/producer-window-guard.d.ts.map +1 -0
  182. package/dist/hooks/magic-context/protected-tail-boundary.d.ts +65 -0
  183. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  184. package/dist/hooks/magic-context/read-session-chunk.d.ts +20 -18
  185. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  186. package/dist/hooks/magic-context/read-session-db.d.ts +22 -12
  187. package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
  188. package/dist/hooks/magic-context/read-session-formatting.d.ts +8 -0
  189. package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
  190. package/dist/hooks/magic-context/read-session-raw.d.ts +10 -1
  191. package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
  192. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +4 -1
  193. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  194. package/dist/hooks/magic-context/recomp-orchestrator.d.ts +2 -0
  195. package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
  196. package/dist/hooks/magic-context/reference-retrieval.d.ts.map +1 -1
  197. package/dist/hooks/magic-context/rust-mode-transform.d.ts +79 -11
  198. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  199. package/dist/hooks/magic-context/send-session-notification.d.ts +11 -10
  200. package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
  201. package/dist/hooks/magic-context/sentinel.d.ts +3 -3
  202. package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
  203. package/dist/hooks/magic-context/strip-content.d.ts +7 -0
  204. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  205. package/dist/hooks/magic-context/supersession-reclaim.d.ts +13 -0
  206. package/dist/hooks/magic-context/supersession-reclaim.d.ts.map +1 -1
  207. package/dist/hooks/magic-context/system-prompt-hash.d.ts +2 -3
  208. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  209. package/dist/hooks/magic-context/tag-messages.d.ts +2 -0
  210. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  211. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +16 -6
  212. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
  213. package/dist/hooks/magic-context/tool-drop-target.d.ts +1 -0
  214. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  215. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +2 -0
  216. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  217. package/dist/hooks/magic-context/transform-context-state.d.ts +7 -1
  218. package/dist/hooks/magic-context/transform-context-state.d.ts.map +1 -1
  219. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +11 -4
  220. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  221. package/dist/hooks/magic-context/transform.d.ts +11 -2
  222. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  223. package/dist/hooks/magic-context/upgrade-reminder.d.ts +7 -9
  224. package/dist/hooks/magic-context/upgrade-reminder.d.ts.map +1 -1
  225. package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
  226. package/dist/index-1974jvn3.js +783 -0
  227. package/dist/{index-npx8vhmy.js → index-36wd1d6k.js} +7 -30
  228. package/dist/{index-kby1sng5.js → index-avwt563y.js} +8 -1
  229. package/dist/{index-vmmjdpc0.js → index-c9hamh36.js} +18357 -16010
  230. package/dist/{index-0bycg0np.js → index-jmtjh2d3.js} +4 -4
  231. package/dist/{index-q264erdp.js → index-nqgjwfzn.js} +70 -38
  232. package/dist/index-sd3egckz.js +1583 -0
  233. package/dist/{index-dn1rwpd8.js → index-xdtge3y2.js} +58 -16
  234. package/dist/index.d.ts.map +1 -1
  235. package/dist/index.js +6826 -6660
  236. package/dist/plugin/conflict-warning-hook.d.ts +5 -6
  237. package/dist/plugin/conflict-warning-hook.d.ts.map +1 -1
  238. package/dist/plugin/dream-timer.d.ts +1 -0
  239. package/dist/plugin/dream-timer.d.ts.map +1 -1
  240. package/dist/plugin/embedding-routing.d.ts +4 -1
  241. package/dist/plugin/embedding-routing.d.ts.map +1 -1
  242. package/dist/plugin/hooks/create-session-hooks.d.ts +19 -2
  243. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  244. package/dist/plugin/rpc-handlers.d.ts +31 -1
  245. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  246. package/dist/plugin/rust-tool-backends.d.ts +1 -0
  247. package/dist/plugin/rust-tool-backends.d.ts.map +1 -1
  248. package/dist/plugin/tool-registry.d.ts.map +1 -1
  249. package/dist/{recomp-orchestrator-f5m2wk74.js → recomp-orchestrator-3atsasjy.js} +6 -6
  250. package/dist/{send-session-notification-hdh02wy9.js → send-session-notification-1qeqkswb.js} +6 -4
  251. package/dist/shared/cache-ttl-display.d.ts +23 -0
  252. package/dist/shared/cache-ttl-display.d.ts.map +1 -0
  253. package/dist/shared/cache-ttl-seed.d.ts +10 -0
  254. package/dist/shared/cache-ttl-seed.d.ts.map +1 -0
  255. package/dist/shared/child-session-teardown.d.ts +34 -0
  256. package/dist/shared/child-session-teardown.d.ts.map +1 -0
  257. package/dist/shared/config-diagnostics.d.ts +30 -0
  258. package/dist/shared/config-diagnostics.d.ts.map +1 -0
  259. package/dist/shared/config-warning-surface.d.ts +3 -0
  260. package/dist/shared/config-warning-surface.d.ts.map +1 -0
  261. package/dist/shared/data-path.d.ts +10 -9
  262. package/dist/shared/data-path.d.ts.map +1 -1
  263. package/dist/shared/harness-provider-map.d.ts +7 -0
  264. package/dist/shared/harness-provider-map.d.ts.map +1 -1
  265. package/dist/shared/jsonc-parser.d.ts +12 -0
  266. package/dist/shared/jsonc-parser.d.ts.map +1 -1
  267. package/dist/shared/keep-subagents.d.ts +1 -1
  268. package/dist/shared/keep-subagents.d.ts.map +1 -1
  269. package/dist/shared/model-suggestion-retry.d.ts +15 -11
  270. package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
  271. package/dist/shared/opencode-db-path.d.ts +24 -0
  272. package/dist/shared/opencode-db-path.d.ts.map +1 -0
  273. package/dist/shared/pi-executable.d.ts +6 -0
  274. package/dist/shared/pi-executable.d.ts.map +1 -0
  275. package/dist/shared/prompt-surface-runtime.d.ts +10 -5
  276. package/dist/shared/prompt-surface-runtime.d.ts.map +1 -1
  277. package/dist/shared/resolve-fallbacks.d.ts +1 -1
  278. package/dist/shared/rpc-types.d.ts +117 -0
  279. package/dist/shared/rpc-types.d.ts.map +1 -1
  280. package/dist/shared/rpc-utils.d.ts.map +1 -1
  281. package/dist/shared/sqlite.d.ts +42 -0
  282. package/dist/shared/sqlite.d.ts.map +1 -1
  283. package/dist/shared/status-detail-text.d.ts.map +1 -1
  284. package/dist/shared/subagent-runner.d.ts +17 -10
  285. package/dist/shared/subagent-runner.d.ts.map +1 -1
  286. package/dist/shared/tag-transcript.d.ts.map +1 -1
  287. package/dist/shared/transcript.d.ts +6 -0
  288. package/dist/shared/transcript.d.ts.map +1 -1
  289. package/dist/shared/window-geometry.d.ts +23 -0
  290. package/dist/shared/window-geometry.d.ts.map +1 -1
  291. package/dist/shared/write-transaction-timing.d.ts +1 -1
  292. package/dist/shared/write-transaction-timing.d.ts.map +1 -1
  293. package/dist/{storage-meta-session-3rxx9ekm.js → storage-meta-session-e6g0mmec.js} +2 -2
  294. package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
  295. package/dist/tools/ctx-memory/verification-recording.d.ts.map +1 -1
  296. package/dist/tools/ctx-note/constants.d.ts +1 -1
  297. package/dist/tools/ctx-note/constants.d.ts.map +1 -1
  298. package/dist/tools/ctx-note/tools.d.ts.map +1 -1
  299. package/dist/tools/ctx-note/types.d.ts +1 -0
  300. package/dist/tools/ctx-note/types.d.ts.map +1 -1
  301. package/dist/tools/ctx-reduce/tools.d.ts +10 -1
  302. package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
  303. package/dist/tools/ctx-search/constants.d.ts +1 -1
  304. package/dist/tools/ctx-search/constants.d.ts.map +1 -1
  305. package/dist/tools/light-descriptions.d.ts +2 -2
  306. package/dist/tools/light-descriptions.d.ts.map +1 -1
  307. package/package.json +2 -3
  308. package/src/agents/hidden-agent-registrations.ts +3 -15
  309. package/src/agents/magic-context-prompt.test.ts +7 -5
  310. package/src/agents/magic-context-prompt.ts +22 -30
  311. package/src/agents/permissions.test.ts +1 -42
  312. package/src/agents/permissions.ts +1 -24
  313. package/src/config/agent-disable.ts +5 -22
  314. package/src/config/index.test.ts +169 -14
  315. package/src/config/index.ts +137 -21
  316. package/src/config/latch-permanence-guard.test.ts +4 -0
  317. package/src/config/migrate-config-location.test.ts +39 -6
  318. package/src/config/migrate-config-location.ts +18 -31
  319. package/src/config/profiles.ts +1 -1
  320. package/src/config/project-security.hostile-matrix.test.ts +0 -8
  321. package/src/config/project-security.test.ts +11 -22
  322. package/src/config/project-security.ts +103 -9
  323. package/src/config/protected-tokens.test.ts +235 -0
  324. package/src/config/removed-agent-config.ts +45 -0
  325. package/src/config/removed-agent-source-fence.test.ts +56 -0
  326. package/src/config/schema/magic-context.test.ts +21 -42
  327. package/src/config/schema/magic-context.ts +46 -37
  328. package/src/shared/cache-ttl-display.test.ts +84 -0
  329. package/src/shared/cache-ttl-display.ts +64 -0
  330. package/src/shared/cache-ttl-seed.ts +23 -0
  331. package/src/shared/child-session-teardown.test.ts +218 -0
  332. package/src/shared/child-session-teardown.ts +66 -0
  333. package/src/shared/config-diagnostics.test.ts +29 -0
  334. package/src/shared/config-diagnostics.ts +64 -0
  335. package/src/shared/config-warning-surface.ts +28 -0
  336. package/src/shared/data-path.ts +10 -9
  337. package/src/shared/harness-provider-map.test.ts +16 -0
  338. package/src/shared/harness-provider-map.ts +15 -0
  339. package/src/shared/jsonc-parser.test.ts +14 -1
  340. package/src/shared/jsonc-parser.ts +93 -0
  341. package/src/shared/keep-subagents.ts +9 -14
  342. package/src/shared/model-suggestion-retry.ts +144 -29
  343. package/src/shared/opencode-db-path.test.ts +196 -0
  344. package/src/shared/opencode-db-path.ts +215 -0
  345. package/src/shared/pi-executable.ts +20 -0
  346. package/src/shared/prompt-surface-a1-golden.md +50 -35
  347. package/src/shared/prompt-surface-runtime.test.ts +28 -0
  348. package/src/shared/prompt-surface-runtime.ts +22 -5
  349. package/src/shared/resolve-fallbacks.ts +1 -1
  350. package/src/shared/rpc-types.ts +124 -0
  351. package/src/shared/rpc-utils.ts +2 -3
  352. package/src/shared/session-messages-bounded.test.ts +1 -1
  353. package/src/shared/sqlite-import-fence.test.ts +19 -0
  354. package/src/shared/sqlite.test.ts +27 -1
  355. package/src/shared/sqlite.ts +204 -1
  356. package/src/shared/status-detail-text.test.ts +8 -4
  357. package/src/shared/status-detail-text.ts +20 -1
  358. package/src/shared/subagent-runner.ts +17 -10
  359. package/src/shared/tag-transcript.ts +53 -22
  360. package/src/shared/transcript.ts +7 -0
  361. package/src/shared/window-geometry.test.ts +44 -0
  362. package/src/shared/window-geometry.ts +89 -11
  363. package/src/shared/write-transaction-attribution.test.ts +241 -0
  364. package/src/shared/write-transaction-timing.ts +2 -1
  365. package/src/tui/index.tsx +18 -4
  366. package/src/tui/slots/sidebar-content.tsx +12 -7
  367. package/src/tui-compiled/index.tsx +237 -225
  368. package/src/tui-compiled/slots/sidebar-content.tsx +301 -305
  369. package/dist/agents/sidekick.d.ts +0 -2
  370. package/dist/agents/sidekick.d.ts.map +0 -1
  371. package/dist/features/magic-context/defaults.d.ts +0 -2
  372. package/dist/features/magic-context/defaults.d.ts.map +0 -1
  373. package/dist/features/magic-context/sidekick/agent.d.ts +0 -14
  374. package/dist/features/magic-context/sidekick/agent.d.ts.map +0 -1
  375. package/dist/features/magic-context/sidekick/core.d.ts +0 -38
  376. package/dist/features/magic-context/sidekick/core.d.ts.map +0 -1
  377. package/dist/features/magic-context/sidekick/index.d.ts +0 -3
  378. package/dist/features/magic-context/sidekick/index.d.ts.map +0 -1
  379. package/dist/hooks/magic-context/boundary-execution.d.ts +0 -27
  380. package/dist/hooks/magic-context/boundary-execution.d.ts.map +0 -1
  381. package/dist/index-jfpk81yt.js +0 -146
  382. package/dist/index-raatkvw5.js +0 -360
  383. package/src/agents/sidekick.ts +0 -1
  384. package/src/features/magic-context/defaults.ts +0 -1
@@ -0,0 +1,56 @@
1
+ /// <reference types="bun-types" />
2
+
3
+ import { describe, expect, it } from "bun:test";
4
+ import { readdirSync, readFileSync, statSync } from "node:fs";
5
+ import { join, relative } from "node:path";
6
+
7
+ const RETIRED_AGENT_NAME = ["side", "kick"].join("");
8
+ const RETIRED_AGENT_PATTERN = new RegExp(RETIRED_AGENT_NAME, "gi");
9
+ const REPO_ROOT = join(__dirname, "..", "..", "..", "..");
10
+ const WARNING_SOURCE = join(
11
+ REPO_ROOT,
12
+ "packages",
13
+ "plugin",
14
+ "src",
15
+ "config",
16
+ "removed-agent-config.ts",
17
+ );
18
+ const SOURCE_ROOTS = [
19
+ join(REPO_ROOT, "packages", "plugin", "src"),
20
+ join(REPO_ROOT, "packages", "pi-plugin", "src"),
21
+ join(REPO_ROOT, "packages", "cli", "src"),
22
+ join(REPO_ROOT, "packages", "dashboard", "src"),
23
+ join(REPO_ROOT, "packages", "dashboard", "src-tauri", "src"),
24
+ ];
25
+ const SOURCE_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".rs", ".json"]);
26
+
27
+ function sourceFiles(directory: string, files: string[] = []): string[] {
28
+ for (const entry of readdirSync(directory)) {
29
+ if (entry === "node_modules" || entry === "dist") continue;
30
+ const path = join(directory, entry);
31
+ const stat = statSync(path);
32
+ if (stat.isDirectory()) {
33
+ sourceFiles(path, files);
34
+ continue;
35
+ }
36
+ const extension = entry.slice(entry.lastIndexOf("."));
37
+ if (stat.isFile() && SOURCE_EXTENSIONS.has(extension)) files.push(path);
38
+ }
39
+ return files;
40
+ }
41
+
42
+ describe("retired agent source fence", () => {
43
+ it("keeps only the removed-config warning key literal", () => {
44
+ const offenses: string[] = [];
45
+ for (const file of SOURCE_ROOTS.flatMap((root) => sourceFiles(root))) {
46
+ const matches = readFileSync(file, "utf8").match(RETIRED_AGENT_PATTERN) ?? [];
47
+ const allowed = file === WARNING_SOURCE && matches.length === 1;
48
+ if (!allowed && matches.length > 0) {
49
+ offenses.push(`${relative(REPO_ROOT, file)} (${matches.length})`);
50
+ }
51
+ }
52
+
53
+ expect(offenses).toEqual([]);
54
+ expect(readFileSync(WARNING_SOURCE, "utf8").match(RETIRED_AGENT_PATTERN)).toHaveLength(1);
55
+ });
56
+ });
@@ -23,7 +23,6 @@ describe("MagicContextConfigSchema", () => {
23
23
  cache_ttl: "5m",
24
24
  prompt_surface: { default: "full" },
25
25
  execute_threshold_percentage: 65,
26
- protected_tags: 20,
27
26
  clear_reasoning_age: 50,
28
27
  history_budget_percentage: DEFAULT_HISTORY_BUDGET_PERCENTAGE,
29
28
  historian_timeout_ms: DEFAULT_HISTORIAN_TIMEOUT_MS,
@@ -46,7 +45,6 @@ describe("MagicContextConfigSchema", () => {
46
45
  expect(result.historian_timeout_ms).toBeGreaterThanOrEqual(10 * 60_000);
47
46
  expect(result.historian).toBeUndefined();
48
47
  expect(result.dreamer).toBeUndefined();
49
- expect(result.sidekick).toBeUndefined();
50
48
  expect(result.pi).toBeUndefined();
51
49
  expect(result.mural).toEqual({ enabled: false });
52
50
  });
@@ -107,6 +105,7 @@ describe("MagicContextConfigSchema", () => {
107
105
  },
108
106
  temporal_awareness: false,
109
107
  keep_subagents: false,
108
+ debug_rpc: false,
110
109
  todowrite: {
111
110
  enabled: false,
112
111
  overlay: false,
@@ -145,15 +144,6 @@ describe("MagicContextConfigSchema", () => {
145
144
  pi: {
146
145
  subagent_extensions: ["@example/provider", "./extensions/local.ts"],
147
146
  },
148
- sidekick: {
149
- disable: false,
150
- model: "qwen-test",
151
- fallback_models: ["qwen-fallback"],
152
- temperature: 0.1,
153
- variant: "fast",
154
- timeout_ms: 12_000,
155
- system_prompt: "Custom prompt",
156
- },
157
147
  compaction: {
158
148
  enabled: true,
159
149
  },
@@ -177,19 +167,6 @@ describe("MagicContextConfigSchema", () => {
177
167
  ).toBe(false);
178
168
  });
179
169
 
180
- it("applies sidekick defaults when the object is present", () => {
181
- const result = MagicContextConfigSchema.parse({
182
- sidekick: {
183
- model: "github-copilot/gpt-5.4",
184
- },
185
- });
186
-
187
- expect(result.sidekick).toEqual({
188
- model: "github-copilot/gpt-5.4",
189
- timeout_ms: 30000,
190
- });
191
- });
192
-
193
170
  it("accepts disable on hidden agents and strips deprecated top-level enabled", () => {
194
171
  const result = MagicContextConfigSchema.parse({
195
172
  historian: { disable: true },
@@ -203,14 +180,11 @@ describe("MagicContextConfigSchema", () => {
203
180
  "maintain-docs": { schedule: "0 * * * *" },
204
181
  },
205
182
  },
206
- sidekick: { disable: true, enabled: true },
207
183
  });
208
184
 
209
185
  expect(result.historian?.disable).toBe(true);
210
186
  expect(result.dreamer?.disable).toBe(true);
211
- expect(result.sidekick?.disable).toBe(true);
212
187
  expect("enabled" in (result.dreamer as Record<string, unknown>)).toBe(false);
213
- expect("enabled" in (result.sidekick as Record<string, unknown>)).toBe(false);
214
188
  expect(result.dreamer?.tasks["review-user-memories"].schedule).toBe("");
215
189
  expect(result.dreamer?.tasks["maintain-docs"].schedule).toBe("0 * * * *");
216
190
  expect(result.dreamer?.tasks["classify-memories"].schedule).toBe("0 6 * * *");
@@ -353,10 +327,6 @@ describe("MagicContextConfigSchema", () => {
353
327
  thinking_level: "inherit",
354
328
  },
355
329
  },
356
- sidekick: {
357
- model: "anthropic/work-sidekick",
358
- fallback_models: ["openai/work-sidekick-fallback"],
359
- },
360
330
  },
361
331
  },
362
332
  });
@@ -376,7 +346,6 @@ describe("MagicContextConfigSchema", () => {
376
346
  { model: "opencode/work-historian-fallback", thinking_level: "inherit" },
377
347
  ]);
378
348
  expect(result.profiles?.work?.dreamer?.omp?.thinking_level).toBe("inherit");
379
- expect(result.profiles?.work?.sidekick?.model).toBe("anthropic/work-sidekick");
380
349
  });
381
350
 
382
351
  it("rejects timeout_minutes in a dreamer profile", () => {
@@ -432,7 +401,7 @@ describe("MagicContextConfigSchema", () => {
432
401
  },
433
402
  },
434
403
  { work: { dreamer: { tasks: { verify: { schedule: "0 3 * * *" } } } } },
435
- { work: { sidekick: { timeout_ms: 60_000 } } },
404
+ { work: { dreamer: { timeout_ms: 60_000 } } },
436
405
  ];
437
406
 
438
407
  for (const profiles of profilesWithExcludedFields) {
@@ -667,17 +636,27 @@ describe("MagicContextConfigSchema", () => {
667
636
  ).toThrow();
668
637
  });
669
638
 
670
- it("rejects protected_tags greater than 100", () => {
671
- expect(() => MagicContextConfigSchema.parse({ protected_tags: 101 })).toThrow();
672
- });
673
-
674
- it("rejects protected_tags less than 1", () => {
675
- expect(() => MagicContextConfigSchema.parse({ protected_tags: 0 })).toThrow();
639
+ it("accepts protected_tags at any value including 0 and 101 as deprecated inert key", () => {
640
+ expect(MagicContextConfigSchema.parse({ protected_tags: 101 }).protected_tags).toBe(
641
+ 101,
642
+ );
643
+ expect(MagicContextConfigSchema.parse({ protected_tags: 0 }).protected_tags).toBe(0);
644
+ expect(MagicContextConfigSchema.parse({ protected_tags: 20 }).protected_tags).toBe(20);
676
645
  });
677
646
 
678
- it("accepts protected_tags boundary values", () => {
679
- expect(MagicContextConfigSchema.parse({ protected_tags: 1 }).protected_tags).toBe(1);
680
- expect(MagicContextConfigSchema.parse({ protected_tags: 20 }).protected_tags).toBe(20);
647
+ it("enforces protected_tokens override range at both ends", () => {
648
+ expect(() => MagicContextConfigSchema.parse({ protected_tokens: 3999 })).toThrow();
649
+ expect(() => MagicContextConfigSchema.parse({ protected_tokens: 1_000_001 })).toThrow();
650
+ expect(() => MagicContextConfigSchema.parse({ protected_tokens: 30000.5 })).toThrow();
651
+ expect(
652
+ MagicContextConfigSchema.parse({ protected_tokens: 4000 }).protected_tokens,
653
+ ).toBe(4000);
654
+ expect(
655
+ MagicContextConfigSchema.parse({ protected_tokens: 1_000_000 }).protected_tokens,
656
+ ).toBe(1_000_000);
657
+ expect(
658
+ MagicContextConfigSchema.parse({ protected_tokens: 30000 }).protected_tokens,
659
+ ).toBe(30000);
681
660
  });
682
661
 
683
662
  it("rejects clear_reasoning_age below minimum", () => {
@@ -1,7 +1,6 @@
1
1
  import { homedir } from "node:os";
2
2
  import { z } from "zod";
3
3
  import { isValidLanguageCode } from "../../agents/language-directive";
4
- import { DEFAULT_PROTECTED_TAGS } from "../../features/magic-context/defaults";
5
4
  import { isValidCron } from "../../features/magic-context/dreamer/cron";
6
5
  import type {
7
6
  AGENTIC_DREAM_TASKS,
@@ -446,27 +445,15 @@ const ProfileDreamerSchema = z
446
445
  omp: ProfileOmpModelBlockSchema.optional(),
447
446
  })
448
447
  .strict();
449
- const ProfileSidekickSchema = AgentOverrideConfigSchema.pick({
450
- model: true,
451
- fallback_models: true,
452
- variant: true,
453
- })
454
- .extend({
455
- thinking_level: PiThinkingLevelSchema.describe(
456
- "Pi thinking level for the sidekick model selection.",
457
- ),
458
- })
459
- .strict();
460
448
 
461
449
  export const ConfigProfileSchema = z
462
450
  .object({
463
451
  historian: ProfileHistorianSchema.optional(),
464
452
  dreamer: ProfileDreamerSchema.optional(),
465
- sidekick: ProfileSidekickSchema.optional(),
466
453
  })
467
454
  .strict()
468
455
  .describe(
469
- "User-owned model-selection overlay. Only historian/dreamer harness model blocks and sidekick model-selection fields are allowed.",
456
+ "User-owned model-selection overlay. Only historian/dreamer harness model blocks are allowed.",
470
457
  );
471
458
  export type ConfigProfile = z.infer<typeof ConfigProfileSchema>;
472
459
 
@@ -626,15 +613,6 @@ export const DreamerConfigSchema = AgentMetadataSchema.extend({
626
613
  });
627
614
  export type DreamerConfig = z.infer<typeof DreamerConfigSchema>;
628
615
 
629
- export const SidekickConfigSchema = AgentOverrideConfigSchema.extend({
630
- timeout_ms: z.number().default(30000).describe("Timeout for sidekick calls in milliseconds"),
631
- system_prompt: z.string().optional().describe("Custom system prompt for sidekick"),
632
- thinking_level: PiThinkingLevelSchema.describe(
633
- "Pi only: explicit thinking level for sidekick subagent invocations. See historian.pi.thinking_level.",
634
- ),
635
- }).optional();
636
- export type SidekickConfig = NonNullable<z.infer<typeof SidekickConfigSchema>>;
637
-
638
616
  /**
639
617
  * Historian metadata remains harness-independent. Only model resolution moves to
640
618
  * the strict opencode, pi, and omp blocks; two_pass and disallowed_tools stay here.
@@ -871,7 +849,8 @@ export interface MagicContextConfig {
871
849
  * this overrides `execute_threshold_percentage` for that model. Useful for hard caps
872
850
  * matching provider input limits. Values above 90% × context_limit are clamped with a warning. */
873
851
  execute_threshold_tokens?: { default?: number; [modelKey: string]: number | undefined };
874
- protected_tags: number;
852
+ protected_tokens?: number;
853
+ protected_tags?: number;
875
854
  clear_reasoning_age: number;
876
855
  history_budget_percentage: number;
877
856
  historian_timeout_ms: number;
@@ -917,10 +896,12 @@ export interface MagicContextConfig {
917
896
  * Graduated from `experimental.temporal_awareness`; default: true. */
918
897
  temporal_awareness: boolean;
919
898
  /** Debug: when true, keep the child sessions Magic Context spawns for its
920
- * own subagents (historian, dreamer, sidekick, memory-migration) instead
899
+ * own subagents (historian, dreamer, memory-migration) instead
921
900
  * of deleting them on success. For short-term inspection/data collection;
922
901
  * kept sessions accumulate until manually cleared. Default false. */
923
902
  keep_subagents: boolean;
903
+ /** Enable loopback-only diagnostic RPCs that expose memory usage and heap snapshots. */
904
+ debug_rpc?: boolean;
924
905
  /**
925
906
  * When true (default), deterministic inoperability (schema fence, storage
926
907
  * open/migration failure) blocks the primary-session transform with a loud
@@ -1011,7 +992,6 @@ export interface MagicContextConfig {
1011
992
  max_commits: number;
1012
993
  };
1013
994
  };
1014
- sidekick?: SidekickConfig;
1015
995
  }
1016
996
 
1017
997
  export const MagicContextConfigSchema = z
@@ -1063,7 +1043,7 @@ export const MagicContextConfigSchema = z
1063
1043
  .describe(
1064
1044
  "Output language for Magic Context's generated content and guidance, as a " +
1065
1045
  '2-letter ISO 639-1 code (e.g. "tr", "es", "de", "ja", "pt"). When set, the ' +
1066
- "historian, dreamer, sidekick, and the agent-guidance block instruct the model to " +
1046
+ "historian, dreamer, and the agent-guidance block instruct the model to " +
1067
1047
  "write its PROSE in this language while keeping all structural tokens (XML tags, " +
1068
1048
  "the five memory category names, code identifiers, file paths) in English. " +
1069
1049
  "USER-LEVEL ONLY (ignored in project config for security). Unset = today's " +
@@ -1080,7 +1060,7 @@ export const MagicContextConfigSchema = z
1080
1060
  "Select a named user-owned model profile. A valid project name overrides this user default; an empty string, null, or other non-string project value is ignored with a warning so the user selection still applies. Unknown names warn and use the base configuration.",
1081
1061
  ),
1082
1062
  profiles: ConfigProfilesSchema.optional().describe(
1083
- "User-level named model profiles. A profile may contain only historian/dreamer model, fallback_models, OpenCode variant, and Pi/OMP thinking_level fields plus sidekick model-selection fields; task execution policy (including timeout_minutes) is excluded. Project configs may select a name but cannot define profiles.",
1063
+ "User-level named model profiles. A profile may contain only historian/dreamer model, fallback_models, OpenCode variant, and Pi/OMP thinking_level fields; task execution policy (including timeout_minutes) is excluded. Project configs may select a name but cannot define profiles.",
1084
1064
  ),
1085
1065
  historian: HistorianConfigSchema.describe(
1086
1066
  "Historian metadata plus independent strict OpenCode, Pi, and OMP execution blocks. Retained metadata stays at historian; model, fallback_models, variant, and thinking_level belong only in historian.opencode, historian.pi, or historian.omp.",
@@ -1153,14 +1133,22 @@ export const MagicContextConfigSchema = z
1153
1133
  .describe(
1154
1134
  "Absolute token thresholds per model. When matched, overrides execute_threshold_percentage for that model. Accepts `default` for all models or per-model keys. Values above 90% × context_limit are clamped with a warning log. Min 5_000, max 2_000_000.",
1155
1135
  ),
1156
- protected_tags: z
1136
+ protected_tokens: z
1157
1137
  .number()
1158
- .min(1)
1159
- .max(100)
1138
+ .int()
1139
+ .min(4000)
1140
+ .max(1_000_000)
1160
1141
  .optional()
1161
1142
  .describe(
1162
- "Number of recent tags to protect from dropping (min: 1, max: 100, default: 20)",
1143
+ "Positive integer token floor to protect from automatic reclaim (min: 4_000, max: 1_000_000). When omitted, the derived default is clamp(round(0.05 × usableSoft), min(16_000, round(0.08 × usableSoft)), 64_000).",
1163
1144
  ),
1145
+ protected_tags: z
1146
+ .unknown()
1147
+ .optional()
1148
+ .describe(
1149
+ "Deprecated: number of recent tags to protect. Ignored for behaviour; use protected_tokens instead.",
1150
+ )
1151
+ .meta({ deprecated: true }),
1164
1152
  clear_reasoning_age: z
1165
1153
  .number()
1166
1154
  .min(10)
@@ -1294,7 +1282,13 @@ export const MagicContextConfigSchema = z
1294
1282
  .boolean()
1295
1283
  .default(false)
1296
1284
  .describe(
1297
- "Debug: keep the child sessions Magic Context spawns for its own subagents (historian, dreamer, sidekick, memory-migration) instead of deleting them on success. Useful for short-term inspection/data collection — their full transcript (prompt, tool calls, token usage, output) stays in the host session store. Kept sessions accumulate until manually cleared; leave false for normal use. Requires a restart to take effect.",
1285
+ "Debug: keep the child sessions Magic Context spawns for its own subagents (historian, dreamer, memory-migration) instead of deleting them on success. Useful for short-term inspection/data collection — their full transcript (prompt, tool calls, token usage, output) stays in the host session store. Kept sessions accumulate until manually cleared; leave false for normal use. Requires a restart to take effect.",
1286
+ ),
1287
+ debug_rpc: z
1288
+ .boolean()
1289
+ .default(false)
1290
+ .describe(
1291
+ "Developer-only: enable authenticated loopback RPCs for memory counters and heap snapshots. Disabled by default. USER-LEVEL ONLY and requires a restart.",
1298
1292
  ),
1299
1293
  fail_closed_blocking: z
1300
1294
  .boolean()
@@ -1459,13 +1453,28 @@ export const MagicContextConfigSchema = z
1459
1453
  git_commit_indexing: { enabled: false, since_days: 365, max_commits: 2000 },
1460
1454
  })
1461
1455
  .describe("Cross-session memory configuration"),
1462
- sidekick: SidekickConfigSchema.describe(
1463
- "Optional sidekick agent configuration for session-start memory retrieval",
1464
- ),
1465
1456
  })
1466
1457
  .transform((data): MagicContextConfig => {
1467
1458
  return {
1468
1459
  ...data,
1469
- protected_tags: data.protected_tags ?? DEFAULT_PROTECTED_TAGS,
1460
+ protected_tags: data.protected_tags as number | undefined,
1470
1461
  };
1471
1462
  });
1463
+
1464
+ /**
1465
+ * Derived default protected_tokens formula:
1466
+ * clamp(round(0.05 × usableSoft), min(16000, round(0.08 × usableSoft)), 64000)
1467
+ *
1468
+ * Sizing table:
1469
+ * 100k -> 8,000
1470
+ * 200k -> 16,000
1471
+ * 372k -> 18,600
1472
+ * 872k -> 43,600
1473
+ * 1M -> 50,000
1474
+ */
1475
+ export function deriveDefaultProtectedTokens(usableSoft: number): number {
1476
+ const clampedUsable = Math.max(0, usableSoft);
1477
+ const lowerBound = Math.min(16_000, Math.round(0.08 * clampedUsable));
1478
+ const target = Math.round(0.05 * clampedUsable);
1479
+ return Math.min(64_000, Math.max(lowerBound, target));
1480
+ }
@@ -0,0 +1,84 @@
1
+ import { describe, expect, it } from "bun:test";
2
+
3
+ import { initializeDatabase } from "../features/magic-context/storage-db";
4
+ import { getOrCreateSessionMeta, updateSessionMeta } from "../features/magic-context/storage-meta";
5
+ import { resolveCacheTtlDisplay } from "./cache-ttl-display";
6
+ import { seedSessionCacheTtlIfUnsynced } from "./cache-ttl-seed";
7
+ import { Database } from "./sqlite";
8
+
9
+ const modelKey = "anthropic/claude-opus-5";
10
+
11
+ describe("resolveCacheTtlDisplay", () => {
12
+ it("shows config before the first message_end sync", () => {
13
+ expect(
14
+ resolveCacheTtlDisplay({
15
+ configured: { default: "5m", [modelKey]: "1h" },
16
+ configuredExplicitly: true,
17
+ modelKey,
18
+ sessionValue: "5m",
19
+ sessionModelKey: null,
20
+ }),
21
+ ).toEqual({ value: "1h", source: "config", modelKey });
22
+ });
23
+
24
+ it("discriminates config, session, and guessed default provenance", () => {
25
+ const configured = resolveCacheTtlDisplay({
26
+ configured: "1h",
27
+ configuredExplicitly: true,
28
+ modelKey,
29
+ sessionValue: "5m",
30
+ sessionModelKey: null,
31
+ });
32
+ const session = resolveCacheTtlDisplay({
33
+ configured: "1h",
34
+ configuredExplicitly: true,
35
+ modelKey,
36
+ sessionValue: "45m",
37
+ sessionModelKey: modelKey,
38
+ });
39
+ const fallback = resolveCacheTtlDisplay({
40
+ configured: "5m",
41
+ configuredExplicitly: false,
42
+ modelKey,
43
+ sessionValue: "5m",
44
+ sessionModelKey: null,
45
+ });
46
+
47
+ expect(configured.source).toBe("config");
48
+ expect(session).toEqual({ value: "45m", source: "session", modelKey });
49
+ expect(fallback).toEqual({ value: "5m", source: "default", modelKey });
50
+ });
51
+
52
+ it("seeds only an unsynced row and leaves a scheduler-owned row unchanged", () => {
53
+ const db = new Database(":memory:");
54
+ initializeDatabase(db);
55
+ try {
56
+ expect(
57
+ seedSessionCacheTtlIfUnsynced({
58
+ db,
59
+ sessionId: "ses-seed",
60
+ configured: { default: "5m", [modelKey]: "1h" },
61
+ modelKey,
62
+ }),
63
+ ).toBe(true);
64
+ expect(getOrCreateSessionMeta(db, "ses-seed").cacheTtl).toBe("1h");
65
+
66
+ updateSessionMeta(db, "ses-seed", {
67
+ cacheTtl: "45m",
68
+ lastObservedModelKey: modelKey,
69
+ lastResponseTime: 1,
70
+ });
71
+ expect(
72
+ seedSessionCacheTtlIfUnsynced({
73
+ db,
74
+ sessionId: "ses-seed",
75
+ configured: "2h",
76
+ modelKey,
77
+ }),
78
+ ).toBe(false);
79
+ expect(getOrCreateSessionMeta(db, "ses-seed").cacheTtl).toBe("45m");
80
+ } finally {
81
+ db.close();
82
+ }
83
+ });
84
+ });
@@ -0,0 +1,64 @@
1
+ import type { MagicContextConfig } from "../config/schema/magic-context";
2
+ import { resolveModelConfigValue } from "./prompt-surface";
3
+
4
+ export type CacheTtlDisplaySource = "config" | "session" | "default";
5
+
6
+ export interface CacheTtlDisplay {
7
+ value: string;
8
+ source: CacheTtlDisplaySource;
9
+ modelKey: string | undefined;
10
+ }
11
+
12
+ export interface ResolveCacheTtlDisplayArgs {
13
+ configured: MagicContextConfig["cache_ttl"];
14
+ configuredExplicitly: boolean;
15
+ modelKey: string | undefined;
16
+ sessionValue: string;
17
+ /** Model key persisted with the last completed assistant response. */
18
+ sessionModelKey: string | null;
19
+ }
20
+
21
+ /**
22
+ * Resolve status-only TTL text without changing the scheduler's persisted truth.
23
+ * Use the session value only when its persisted model key matches the model being
24
+ * displayed; otherwise use live config because the session value may be for another model.
25
+ */
26
+ export function resolveCacheTtlDisplay(args: ResolveCacheTtlDisplayArgs): CacheTtlDisplay {
27
+ if (
28
+ (args.sessionModelKey && (!args.modelKey || args.sessionModelKey === args.modelKey)) ||
29
+ (!args.modelKey && !args.sessionModelKey && args.sessionValue !== "5m")
30
+ ) {
31
+ return {
32
+ value: args.sessionValue || "5m",
33
+ source: "session",
34
+ modelKey: args.modelKey ?? args.sessionModelKey ?? undefined,
35
+ };
36
+ }
37
+
38
+ if (typeof args.configured === "string") {
39
+ return {
40
+ value: args.configured,
41
+ source: args.configuredExplicitly ? "config" : "default",
42
+ modelKey: args.modelKey,
43
+ };
44
+ }
45
+
46
+ const matched = resolveModelConfigValue(args.configured, args.modelKey);
47
+ if (matched) {
48
+ return { value: matched.value, source: "config", modelKey: args.modelKey };
49
+ }
50
+
51
+ return {
52
+ value: args.configured.default ?? "5m",
53
+ source: "default",
54
+ modelKey: args.modelKey,
55
+ };
56
+ }
57
+
58
+ export function formatCacheTtlDisplay(display: CacheTtlDisplay): string {
59
+ if (display.source === "session") return `Cache TTL: ${display.value} (session)`;
60
+ if (display.source === "config") {
61
+ return `Cache TTL: ${display.value} (config for ${display.modelKey ?? "current model"})`;
62
+ }
63
+ return `Cache TTL: ${display.value} (default — no cache_ttl for ${display.modelKey ?? "unknown model"})`;
64
+ }
@@ -0,0 +1,23 @@
1
+ import type { MagicContextConfig } from "../config/schema/magic-context";
2
+ import { getOrCreateSessionMeta, updateSessionMeta } from "../features/magic-context/storage-meta";
3
+ import { resolveModelConfigValue } from "./prompt-surface";
4
+ import type { Database } from "./sqlite";
5
+
6
+ /** Seed only before a completed assistant response has made the session row authoritative. */
7
+ export function seedSessionCacheTtlIfUnsynced(args: {
8
+ db: Database;
9
+ sessionId: string;
10
+ configured: MagicContextConfig["cache_ttl"];
11
+ modelKey: string;
12
+ }): boolean {
13
+ const meta = getOrCreateSessionMeta(args.db, args.sessionId);
14
+ if (meta.lastResponseTime !== 0 || meta.lastObservedModelKey !== null) return false;
15
+ const cacheTtl =
16
+ typeof args.configured === "string"
17
+ ? args.configured
18
+ : (resolveModelConfigValue(args.configured, args.modelKey)?.value ??
19
+ args.configured.default ??
20
+ "5m");
21
+ updateSessionMeta(args.db, args.sessionId, { cacheTtl });
22
+ return true;
23
+ }