@mastra/code-sdk 0.0.0-agent-tags-alpha-20261125185303

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 (407) hide show
  1. package/LICENSE.md +32 -0
  2. package/README.md +284 -0
  3. package/dist/acp/agent.d.ts +48 -0
  4. package/dist/acp/agent.js +414 -0
  5. package/dist/acp/errors.d.ts +3 -0
  6. package/dist/acp/errors.js +11 -0
  7. package/dist/acp/event-mapper.d.ts +28 -0
  8. package/dist/acp/event-mapper.js +274 -0
  9. package/dist/acp/index.d.ts +9 -0
  10. package/dist/acp/index.js +21 -0
  11. package/dist/acp/runtime.d.ts +5 -0
  12. package/dist/acp/runtime.js +91 -0
  13. package/dist/acp/server.d.ts +4 -0
  14. package/dist/acp/server.js +35 -0
  15. package/dist/acp/skills.d.ts +6 -0
  16. package/dist/acp/skills.js +30 -0
  17. package/dist/acp.d.ts +2 -0
  18. package/dist/acp.js +1 -0
  19. package/dist/agent-connections/messaging-processor.d.ts +17 -0
  20. package/dist/agent-connections/messaging-processor.js +131 -0
  21. package/dist/agent-connections/ownership.d.ts +24 -0
  22. package/dist/agent-connections/ownership.js +96 -0
  23. package/dist/agent-connections/registry.d.ts +20 -0
  24. package/dist/agent-connections/registry.js +167 -0
  25. package/dist/agent-connections/session-advertisement.d.ts +27 -0
  26. package/dist/agent-connections/session-advertisement.js +86 -0
  27. package/dist/agent-connections/signal-provider.d.ts +141 -0
  28. package/dist/agent-connections/signal-provider.js +35 -0
  29. package/dist/agent-connections/state-processor.d.ts +23 -0
  30. package/dist/agent-connections/state-processor.js +270 -0
  31. package/dist/agent-connections/thread-state.d.ts +41 -0
  32. package/dist/agent-connections/thread-state.js +157 -0
  33. package/dist/agent-connections/tools.d.ts +133 -0
  34. package/dist/agent-connections/tools.js +616 -0
  35. package/dist/agent-connections/types.d.ts +99 -0
  36. package/dist/agent-connections/types.js +4 -0
  37. package/dist/agent-connections/untrusted-text.d.ts +5 -0
  38. package/dist/agent-connections/untrusted-text.js +19 -0
  39. package/dist/agents/background-completion-events.d.ts +16 -0
  40. package/dist/agents/background-completion-events.js +16 -0
  41. package/dist/agents/background-completion.d.ts +22 -0
  42. package/dist/agents/background-completion.js +73 -0
  43. package/dist/agents/context-audit.d.ts +84 -0
  44. package/dist/agents/context-audit.js +115 -0
  45. package/dist/agents/credential-resolver.d.ts +74 -0
  46. package/dist/agents/credential-resolver.js +142 -0
  47. package/dist/agents/custom-provider-source.d.ts +35 -0
  48. package/dist/agents/custom-provider-source.js +22 -0
  49. package/dist/agents/fastembed-subprocess.d.ts +52 -0
  50. package/dist/agents/fastembed-subprocess.js +282 -0
  51. package/dist/agents/instructions.d.ts +42 -0
  52. package/dist/agents/instructions.js +69 -0
  53. package/dist/agents/mastracode-gateway.d.ts +85 -0
  54. package/dist/agents/mastracode-gateway.js +500 -0
  55. package/dist/agents/memory.d.ts +36 -0
  56. package/dist/agents/memory.js +248 -0
  57. package/dist/agents/model.d.ts +158 -0
  58. package/dist/agents/model.js +382 -0
  59. package/dist/agents/modes/build.d.ts +12 -0
  60. package/dist/agents/modes/build.js +33 -0
  61. package/dist/agents/modes/explore.d.ts +10 -0
  62. package/dist/agents/modes/explore.js +25 -0
  63. package/dist/agents/modes/plan.d.ts +8 -0
  64. package/dist/agents/modes/plan.js +43 -0
  65. package/dist/agents/prompts/agent-instructions.d.ts +122 -0
  66. package/dist/agents/prompts/agent-instructions.js +617 -0
  67. package/dist/agents/prompts/build.d.ts +12 -0
  68. package/dist/agents/prompts/build.js +73 -0
  69. package/dist/agents/prompts/fast.d.ts +5 -0
  70. package/dist/agents/prompts/fast.js +23 -0
  71. package/dist/agents/prompts/index.d.ts +61 -0
  72. package/dist/agents/prompts/index.js +141 -0
  73. package/dist/agents/prompts/model.d.ts +5 -0
  74. package/dist/agents/prompts/model.js +20 -0
  75. package/dist/agents/prompts/plan.d.ts +11 -0
  76. package/dist/agents/prompts/plan.js +132 -0
  77. package/dist/agents/prompts/tool-guidance.d.ts +18 -0
  78. package/dist/agents/prompts/tool-guidance.js +158 -0
  79. package/dist/agents/sandbox-filesystem.d.ts +232 -0
  80. package/dist/agents/sandbox-filesystem.js +851 -0
  81. package/dist/agents/subagents/execute.d.ts +3 -0
  82. package/dist/agents/subagents/execute.js +24 -0
  83. package/dist/agents/subagents/explore.d.ts +3 -0
  84. package/dist/agents/subagents/explore.js +15 -0
  85. package/dist/agents/subagents/index.d.ts +6 -0
  86. package/dist/agents/subagents/index.js +15 -0
  87. package/dist/agents/subagents/plan.d.ts +3 -0
  88. package/dist/agents/subagents/plan.js +15 -0
  89. package/dist/agents/thread-caveman-state.d.ts +17 -0
  90. package/dist/agents/thread-caveman-state.js +104 -0
  91. package/dist/agents/tool-availability.d.ts +17 -0
  92. package/dist/agents/tool-availability.js +134 -0
  93. package/dist/agents/tools.d.ts +37 -0
  94. package/dist/agents/tools.js +154 -0
  95. package/dist/agents/workflow-builder-agent.d.ts +2 -0
  96. package/dist/agents/workflow-builder-agent.js +79 -0
  97. package/dist/agents/workspace.d.ts +35 -0
  98. package/dist/agents/workspace.js +207 -0
  99. package/dist/analytics.d.ts +18 -0
  100. package/dist/analytics.js +159 -0
  101. package/dist/auth/account-rotation-processor.d.ts +210 -0
  102. package/dist/auth/account-rotation-processor.js +662 -0
  103. package/dist/auth/account-routing-context.d.ts +17 -0
  104. package/dist/auth/account-routing-context.js +38 -0
  105. package/dist/auth/authorization-input.d.ts +16 -0
  106. package/dist/auth/authorization-input.js +39 -0
  107. package/dist/auth/device-code.d.ts +93 -0
  108. package/dist/auth/device-code.js +126 -0
  109. package/dist/auth/index.d.ts +13 -0
  110. package/dist/auth/index.js +9 -0
  111. package/dist/auth/pkce.d.ts +13 -0
  112. package/dist/auth/pkce.js +29 -0
  113. package/dist/auth/provider-auth-error.d.ts +24 -0
  114. package/dist/auth/provider-auth-error.js +44 -0
  115. package/dist/auth/providers/anthropic.d.ts +40 -0
  116. package/dist/auth/providers/anthropic.js +117 -0
  117. package/dist/auth/providers/github-copilot.d.ts +154 -0
  118. package/dist/auth/providers/github-copilot.js +359 -0
  119. package/dist/auth/providers/kimi-coding.d.ts +38 -0
  120. package/dist/auth/providers/kimi-coding.js +225 -0
  121. package/dist/auth/providers/openai-codex.d.ts +141 -0
  122. package/dist/auth/providers/openai-codex.js +531 -0
  123. package/dist/auth/providers/xai.d.ts +64 -0
  124. package/dist/auth/providers/xai.js +223 -0
  125. package/dist/auth/storage.d.ts +222 -0
  126. package/dist/auth/storage.js +805 -0
  127. package/dist/auth/types.d.ts +164 -0
  128. package/dist/auth/types.js +1 -0
  129. package/dist/clipboard/index.d.ts +26 -0
  130. package/dist/clipboard/index.js +224 -0
  131. package/dist/constants.d.ts +29 -0
  132. package/dist/constants.js +34 -0
  133. package/dist/error-classification.d.ts +10 -0
  134. package/dist/error-classification.js +19 -0
  135. package/dist/evals/context-builder.d.ts +41 -0
  136. package/dist/evals/context-builder.js +156 -0
  137. package/dist/evals/index.d.ts +4 -0
  138. package/dist/evals/index.js +5 -0
  139. package/dist/evals/scorers/classify-command.d.ts +30 -0
  140. package/dist/evals/scorers/classify-command.js +61 -0
  141. package/dist/evals/scorers/efficiency.d.ts +44 -0
  142. package/dist/evals/scorers/efficiency.js +256 -0
  143. package/dist/evals/scorers/extract-tools.d.ts +25 -0
  144. package/dist/evals/scorers/extract-tools.js +57 -0
  145. package/dist/evals/scorers/index.d.ts +3 -0
  146. package/dist/evals/scorers/index.js +3 -0
  147. package/dist/evals/scorers/outcome.d.ts +49 -0
  148. package/dist/evals/scorers/outcome.js +360 -0
  149. package/dist/experimental-agent.d.ts +19 -0
  150. package/dist/experimental-agent.js +45 -0
  151. package/dist/factory/client.d.ts +44 -0
  152. package/dist/factory/client.js +110 -0
  153. package/dist/factory/remote-controller.d.ts +34 -0
  154. package/dist/factory/remote-controller.js +40 -0
  155. package/dist/factory/remote-session.d.ts +210 -0
  156. package/dist/factory/remote-session.js +415 -0
  157. package/dist/goal-manager.d.ts +114 -0
  158. package/dist/goal-manager.js +351 -0
  159. package/dist/goal-signal.d.ts +14 -0
  160. package/dist/goal-signal.js +14 -0
  161. package/dist/headless/cli.d.ts +55 -0
  162. package/dist/headless/cli.js +261 -0
  163. package/dist/headless/flags.d.ts +33 -0
  164. package/dist/headless/flags.js +207 -0
  165. package/dist/headless/format.d.ts +41 -0
  166. package/dist/headless/format.js +94 -0
  167. package/dist/headless/index.d.ts +25 -0
  168. package/dist/headless/index.js +6 -0
  169. package/dist/headless/policy.d.ts +17 -0
  170. package/dist/headless/policy.js +39 -0
  171. package/dist/headless/run-mc.d.ts +7 -0
  172. package/dist/headless/run-mc.js +438 -0
  173. package/dist/headless/types.d.ts +175 -0
  174. package/dist/headless/types.js +16 -0
  175. package/dist/hooks/config.d.ts +11 -0
  176. package/dist/hooks/config.js +77 -0
  177. package/dist/hooks/executor.d.ts +13 -0
  178. package/dist/hooks/executor.js +128 -0
  179. package/dist/hooks/index.d.ts +6 -0
  180. package/dist/hooks/index.js +5 -0
  181. package/dist/hooks/manager.d.ts +75 -0
  182. package/dist/hooks/manager.js +289 -0
  183. package/dist/hooks/types.d.ts +180 -0
  184. package/dist/hooks/types.js +5 -0
  185. package/dist/index.d.ts +537 -0
  186. package/dist/index.js +1399 -0
  187. package/dist/ipc/ipc-reporter.d.ts +14 -0
  188. package/dist/ipc/ipc-reporter.js +18 -0
  189. package/dist/knowledge-inspector.d.ts +139 -0
  190. package/dist/knowledge-inspector.js +533 -0
  191. package/dist/knowledge-scope-id.d.ts +7 -0
  192. package/dist/knowledge-scope-id.js +10 -0
  193. package/dist/knowledge-scope.d.ts +41 -0
  194. package/dist/knowledge-scope.js +85 -0
  195. package/dist/lsp/client.d.ts +56 -0
  196. package/dist/lsp/client.js +248 -0
  197. package/dist/lsp/index.d.ts +4 -0
  198. package/dist/lsp/index.js +4 -0
  199. package/dist/lsp/language.d.ts +9 -0
  200. package/dist/lsp/language.js +41 -0
  201. package/dist/lsp/manager.d.ts +34 -0
  202. package/dist/lsp/manager.js +79 -0
  203. package/dist/lsp/server.d.ts +27 -0
  204. package/dist/lsp/server.js +158 -0
  205. package/dist/lsp/workspace.d.ts +9 -0
  206. package/dist/lsp/workspace.js +52 -0
  207. package/dist/mcp/config.d.ts +77 -0
  208. package/dist/mcp/config.js +313 -0
  209. package/dist/mcp/index.d.ts +6 -0
  210. package/dist/mcp/index.js +3 -0
  211. package/dist/mcp/manager.d.ts +104 -0
  212. package/dist/mcp/manager.js +693 -0
  213. package/dist/mcp/state.d.ts +35 -0
  214. package/dist/mcp/state.js +94 -0
  215. package/dist/mcp/types.d.ts +139 -0
  216. package/dist/mcp/types.js +1 -0
  217. package/dist/onboarding/custom-packs.d.ts +7 -0
  218. package/dist/onboarding/custom-packs.js +17 -0
  219. package/dist/onboarding/custom-providers.d.ts +4 -0
  220. package/dist/onboarding/custom-providers.js +27 -0
  221. package/dist/onboarding/index.d.ts +5 -0
  222. package/dist/onboarding/index.js +3 -0
  223. package/dist/onboarding/om-settings.d.ts +47 -0
  224. package/dist/onboarding/om-settings.js +80 -0
  225. package/dist/onboarding/pack-activation.d.ts +43 -0
  226. package/dist/onboarding/pack-activation.js +105 -0
  227. package/dist/onboarding/packs.d.ts +106 -0
  228. package/dist/onboarding/packs.js +283 -0
  229. package/dist/onboarding/settings.d.ts +563 -0
  230. package/dist/onboarding/settings.js +1110 -0
  231. package/dist/permissions.d.ts +55 -0
  232. package/dist/permissions.js +139 -0
  233. package/dist/platform/index.d.ts +74 -0
  234. package/dist/platform/index.js +199 -0
  235. package/dist/plugin.d.ts +156 -0
  236. package/dist/plugin.js +27 -0
  237. package/dist/plugins/dependencies.d.ts +9 -0
  238. package/dist/plugins/dependencies.js +84 -0
  239. package/dist/plugins/install.d.ts +21 -0
  240. package/dist/plugins/install.js +187 -0
  241. package/dist/plugins/loader.d.ts +25 -0
  242. package/dist/plugins/loader.js +264 -0
  243. package/dist/plugins/manager.d.ts +115 -0
  244. package/dist/plugins/manager.js +507 -0
  245. package/dist/plugins/manifest.d.ts +14 -0
  246. package/dist/plugins/manifest.js +47 -0
  247. package/dist/plugins/package-link.d.ts +3 -0
  248. package/dist/plugins/package-link.js +58 -0
  249. package/dist/plugins/paths.d.ts +10 -0
  250. package/dist/plugins/paths.js +22 -0
  251. package/dist/plugins/registry.d.ts +8 -0
  252. package/dist/plugins/registry.js +109 -0
  253. package/dist/plugins/scaffold.d.ts +10 -0
  254. package/dist/plugins/scaffold.js +115 -0
  255. package/dist/plugins/signal-lane.d.ts +59 -0
  256. package/dist/plugins/signal-lane.js +163 -0
  257. package/dist/plugins/types.d.ts +95 -0
  258. package/dist/plugins/types.js +1 -0
  259. package/dist/process-memory-diagnostics.d.ts +136 -0
  260. package/dist/process-memory-diagnostics.js +497 -0
  261. package/dist/processors/plan-rejection-abort.d.ts +16 -0
  262. package/dist/processors/plan-rejection-abort.js +62 -0
  263. package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
  264. package/dist/providers/amazon-bedrock-gateway.js +142 -0
  265. package/dist/providers/amazon-bedrock.d.ts +28 -0
  266. package/dist/providers/amazon-bedrock.js +99 -0
  267. package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
  268. package/dist/providers/anthropic-prompt-cache.js +8 -0
  269. package/dist/providers/anthropic-thinking.d.ts +5 -0
  270. package/dist/providers/anthropic-thinking.js +22 -0
  271. package/dist/providers/claude-max.d.ts +67 -0
  272. package/dist/providers/claude-max.js +232 -0
  273. package/dist/providers/github-copilot-gateway.d.ts +35 -0
  274. package/dist/providers/github-copilot-gateway.js +58 -0
  275. package/dist/providers/github-copilot.d.ts +60 -0
  276. package/dist/providers/github-copilot.js +320 -0
  277. package/dist/providers/google-thinking.d.ts +31 -0
  278. package/dist/providers/google-thinking.js +64 -0
  279. package/dist/providers/google-vertex-gateway.d.ts +23 -0
  280. package/dist/providers/google-vertex-gateway.js +49 -0
  281. package/dist/providers/google-vertex.d.ts +6 -0
  282. package/dist/providers/google-vertex.js +51 -0
  283. package/dist/providers/kimi-coding.d.ts +14 -0
  284. package/dist/providers/kimi-coding.js +80 -0
  285. package/dist/providers/model-ids.d.ts +53 -0
  286. package/dist/providers/model-ids.js +132 -0
  287. package/dist/providers/openai-codex.d.ts +114 -0
  288. package/dist/providers/openai-codex.js +427 -0
  289. package/dist/providers/provider-thinking.d.ts +23 -0
  290. package/dist/providers/provider-thinking.js +61 -0
  291. package/dist/providers/thinking-request.d.ts +14 -0
  292. package/dist/providers/thinking-request.js +87 -0
  293. package/dist/providers/xai.d.ts +33 -0
  294. package/dist/providers/xai.js +72 -0
  295. package/dist/schedules/index.d.ts +10 -0
  296. package/dist/schedules/index.js +6 -0
  297. package/dist/schedules/interval.d.ts +49 -0
  298. package/dist/schedules/interval.js +212 -0
  299. package/dist/schedules/prompt.d.ts +36 -0
  300. package/dist/schedules/prompt.js +36 -0
  301. package/dist/schedules/run-script.d.ts +8 -0
  302. package/dist/schedules/run-script.js +80 -0
  303. package/dist/schedules/scheduler.d.ts +101 -0
  304. package/dist/schedules/scheduler.js +167 -0
  305. package/dist/schedules/tools.d.ts +57 -0
  306. package/dist/schedules/tools.js +217 -0
  307. package/dist/schema.d.ts +499 -0
  308. package/dist/schema.js +131 -0
  309. package/dist/theme-palette.d.ts +17 -0
  310. package/dist/theme-palette.js +18 -0
  311. package/dist/thinking-catalog.d.ts +4 -0
  312. package/dist/thinking-catalog.js +13 -0
  313. package/dist/thinking.d.ts +37 -0
  314. package/dist/thinking.js +134 -0
  315. package/dist/tool-names.d.ts +77 -0
  316. package/dist/tool-names.js +53 -0
  317. package/dist/tools/index.d.ts +6 -0
  318. package/dist/tools/index.js +3 -0
  319. package/dist/tools/request-sandbox-access.d.ts +6 -0
  320. package/dist/tools/request-sandbox-access.js +80 -0
  321. package/dist/tools/utils.d.ts +20 -0
  322. package/dist/tools/utils.js +31 -0
  323. package/dist/tools/web-search.d.ts +116 -0
  324. package/dist/tools/web-search.js +158 -0
  325. package/dist/tools/workflows/create-workflow.d.ts +7 -0
  326. package/dist/tools/workflows/create-workflow.js +82 -0
  327. package/dist/tools/workflows/delete-workflow.d.ts +7 -0
  328. package/dist/tools/workflows/delete-workflow.js +18 -0
  329. package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
  330. package/dist/tools/workflows/ephemeral-memory.js +41 -0
  331. package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
  332. package/dist/tools/workflows/extract-json-schema.js +19 -0
  333. package/dist/tools/workflows/get-workflow.d.ts +11 -0
  334. package/dist/tools/workflows/get-workflow.js +31 -0
  335. package/dist/tools/workflows/list-available-agents.d.ts +8 -0
  336. package/dist/tools/workflows/list-available-agents.js +29 -0
  337. package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
  338. package/dist/tools/workflows/list-available-classifiers.js +53 -0
  339. package/dist/tools/workflows/list-available-tools.d.ts +9 -0
  340. package/dist/tools/workflows/list-available-tools.js +37 -0
  341. package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
  342. package/dist/tools/workflows/list-available-workflows.js +29 -0
  343. package/dist/tools/workflows/list-workflows.d.ts +9 -0
  344. package/dist/tools/workflows/list-workflows.js +30 -0
  345. package/dist/tools/workflows/run-workflow.d.ts +9 -0
  346. package/dist/tools/workflows/run-workflow.js +49 -0
  347. package/dist/tools/workflows/save-workflow.d.ts +1125 -0
  348. package/dist/tools/workflows/save-workflow.js +25 -0
  349. package/dist/tools/workflows/tool-ids.d.ts +16 -0
  350. package/dist/tools/workflows/tool-ids.js +17 -0
  351. package/dist/utils/binaries.d.ts +7 -0
  352. package/dist/utils/binaries.js +97 -0
  353. package/dist/utils/debug-log.d.ts +12 -0
  354. package/dist/utils/debug-log.js +56 -0
  355. package/dist/utils/discarding-scores-storage.d.ts +33 -0
  356. package/dist/utils/discarding-scores-storage.js +51 -0
  357. package/dist/utils/errors.d.ts +36 -0
  358. package/dist/utils/errors.js +215 -0
  359. package/dist/utils/gateway-sync.d.ts +26 -0
  360. package/dist/utils/gateway-sync.js +58 -0
  361. package/dist/utils/local-observability.d.ts +19 -0
  362. package/dist/utils/local-observability.js +54 -0
  363. package/dist/utils/maintenance-lock.d.ts +42 -0
  364. package/dist/utils/maintenance-lock.js +196 -0
  365. package/dist/utils/notification-dispatch.d.ts +74 -0
  366. package/dist/utils/notification-dispatch.js +128 -0
  367. package/dist/utils/open-url.d.ts +10 -0
  368. package/dist/utils/open-url.js +27 -0
  369. package/dist/utils/path-security.d.ts +2 -0
  370. package/dist/utils/path-security.js +7 -0
  371. package/dist/utils/plan-diff.d.ts +25 -0
  372. package/dist/utils/plan-diff.js +59 -0
  373. package/dist/utils/plans.d.ts +61 -0
  374. package/dist/utils/plans.js +120 -0
  375. package/dist/utils/project.d.ts +160 -0
  376. package/dist/utils/project.js +361 -0
  377. package/dist/utils/prune-cli.d.ts +24 -0
  378. package/dist/utils/prune-cli.js +124 -0
  379. package/dist/utils/signals-pubsub.d.ts +103 -0
  380. package/dist/utils/signals-pubsub.js +409 -0
  381. package/dist/utils/slash-command-loader.d.ts +52 -0
  382. package/dist/utils/slash-command-loader.js +139 -0
  383. package/dist/utils/slash-command-processor.d.ts +14 -0
  384. package/dist/utils/slash-command-processor.js +106 -0
  385. package/dist/utils/stdin-pipe.d.ts +33 -0
  386. package/dist/utils/stdin-pipe.js +93 -0
  387. package/dist/utils/storage-factory.d.ts +50 -0
  388. package/dist/utils/storage-factory.js +118 -0
  389. package/dist/utils/storage-maintenance.d.ts +121 -0
  390. package/dist/utils/storage-maintenance.js +352 -0
  391. package/dist/utils/thread-lock.d.ts +26 -0
  392. package/dist/utils/thread-lock.js +109 -0
  393. package/dist/utils/token-estimator.d.ts +3 -0
  394. package/dist/utils/token-estimator.js +19 -0
  395. package/dist/utils/update-check.d.ts +151 -0
  396. package/dist/utils/update-check.js +430 -0
  397. package/dist/utils/wake-session.d.ts +44 -0
  398. package/dist/utils/wake-session.js +83 -0
  399. package/dist/voice/stt-registry.d.ts +67 -0
  400. package/dist/voice/stt-registry.js +144 -0
  401. package/dist/voice/transcribe.d.ts +10 -0
  402. package/dist/voice/transcribe.js +75 -0
  403. package/dist/workflows/register-primitives.d.ts +52 -0
  404. package/dist/workflows/register-primitives.js +40 -0
  405. package/dist/workflows/service.d.ts +64 -0
  406. package/dist/workflows/service.js +50 -0
  407. package/package.json +117 -0
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Persisted MCP disable state — mastracode-owned so user config files
3
+ * (mcp.json, .mcp.json, .claude/settings.local.json) are never mutated.
4
+ *
5
+ * Stored as a single JSON file in the app data dir, with a global section
6
+ * (applies to every project) and per-project entries:
7
+ *
8
+ * {
9
+ * "global": { "allDisabled": true, "disabledServers": ["name"] },
10
+ * "projects": {
11
+ * "/path/to/project": { "serverOverrides": { "name": "enabled" } }
12
+ * }
13
+ * }
14
+ *
15
+ * Project overrides are kept even if the server disappears from config, so a
16
+ * server that is removed and later re-added keeps its explicit project state.
17
+ */
18
+ export type McpProjectServerOverride = 'enabled' | 'disabled';
19
+ /** Global (all-projects) MCP disable state. */
20
+ export interface McpGlobalDisableState {
21
+ /** When true, every MCP server is disabled regardless of per-server state. */
22
+ allDisabled: boolean;
23
+ /** Server names disabled across all projects. */
24
+ disabledServers: string[];
25
+ }
26
+ export declare function getMcpStatePath(): string;
27
+ /** Load project-specific server overrides, migrating legacy disabled names in memory. */
28
+ export declare function loadProjectServerOverrides(projectDir: string): Record<string, McpProjectServerOverride>;
29
+ /** Persist project-specific server overrides. */
30
+ export declare function saveProjectServerOverrides(projectDir: string, serverOverrides: Record<string, McpProjectServerOverride>): void;
31
+ /** Load the persisted global disable state (applies to all projects). */
32
+ export declare function loadGlobalDisableState(): McpGlobalDisableState;
33
+ /** Persist the global disable state. Prunes the section when empty. */
34
+ export declare function saveGlobalDisableState(globalState: McpGlobalDisableState): void;
35
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1,94 @@
1
+ import { getAppDataDir } from "../utils/project.js";
2
+ import { dirname, join } from "path";
3
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
4
+ // src/mcp/state.ts
5
+ /**
6
+ * Persisted MCP disable state — mastracode-owned so user config files
7
+ * (mcp.json, .mcp.json, .claude/settings.local.json) are never mutated.
8
+ *
9
+ * Stored as a single JSON file in the app data dir, with a global section
10
+ * (applies to every project) and per-project entries:
11
+ *
12
+ * {
13
+ * "global": { "allDisabled": true, "disabledServers": ["name"] },
14
+ * "projects": {
15
+ * "/path/to/project": { "serverOverrides": { "name": "enabled" } }
16
+ * }
17
+ * }
18
+ *
19
+ * Project overrides are kept even if the server disappears from config, so a
20
+ * server that is removed and later re-added keeps its explicit project state.
21
+ */
22
+ function getMcpStatePath() {
23
+ return join(getAppDataDir(), "mcp-state.json");
24
+ }
25
+ function readStateFile() {
26
+ const filePath = getMcpStatePath();
27
+ if (!existsSync(filePath)) return {};
28
+ try {
29
+ const parsed = JSON.parse(readFileSync(filePath, "utf-8"));
30
+ return parsed && typeof parsed === "object" ? parsed : {};
31
+ } catch {
32
+ return {};
33
+ }
34
+ }
35
+ function writeStateFile(state) {
36
+ const filePath = getMcpStatePath();
37
+ const dir = dirname(filePath);
38
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
39
+ const tmpPath = `${filePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
40
+ writeFileSync(tmpPath, JSON.stringify(state, null, 2), "utf-8");
41
+ renameSync(tmpPath, filePath);
42
+ }
43
+ function cleanNames(names) {
44
+ if (!Array.isArray(names)) return [];
45
+ return names.filter((name) => typeof name === "string");
46
+ }
47
+ function cleanProjectOverrides(overrides) {
48
+ if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) return {};
49
+ return Object.fromEntries(Object.entries(overrides).filter((entry) => entry[1] === "enabled" || entry[1] === "disabled"));
50
+ }
51
+ /** Load project-specific server overrides, migrating legacy disabled names in memory. */
52
+ function loadProjectServerOverrides(projectDir) {
53
+ const project = readStateFile().projects?.[projectDir];
54
+ const overrides = cleanProjectOverrides(project?.serverOverrides);
55
+ for (const name of cleanNames(project?.disabledServers)) overrides[name] ??= "disabled";
56
+ return overrides;
57
+ }
58
+ /** Persist project-specific server overrides. */
59
+ function saveProjectServerOverrides(projectDir, serverOverrides) {
60
+ const state = readStateFile();
61
+ const projects = state.projects ?? {};
62
+ const sortedOverrides = Object.fromEntries(Object.entries(serverOverrides).sort(([a], [b]) => a.localeCompare(b)));
63
+ if (Object.keys(sortedOverrides).length > 0) projects[projectDir] = { serverOverrides: sortedOverrides };
64
+ else delete projects[projectDir];
65
+ writeStateFile({
66
+ ...state,
67
+ projects
68
+ });
69
+ }
70
+ /** Load the persisted global disable state (applies to all projects). */
71
+ function loadGlobalDisableState() {
72
+ const global = readStateFile().global;
73
+ return {
74
+ allDisabled: global?.allDisabled === true,
75
+ disabledServers: cleanNames(global?.disabledServers)
76
+ };
77
+ }
78
+ /** Persist the global disable state. Prunes the section when empty. */
79
+ function saveGlobalDisableState(globalState) {
80
+ const state = readStateFile();
81
+ if (!globalState.allDisabled && globalState.disabledServers.length === 0) {
82
+ delete state.global;
83
+ writeStateFile(state);
84
+ return;
85
+ }
86
+ writeStateFile({
87
+ ...state,
88
+ global: {
89
+ ...globalState.allDisabled ? { allDisabled: true } : {},
90
+ ...globalState.disabledServers.length > 0 ? { disabledServers: [...globalState.disabledServers].sort() } : {}
91
+ }
92
+ });
93
+ }
94
+ export { getMcpStatePath, loadGlobalDisableState, loadProjectServerOverrides, saveGlobalDisableState, saveProjectServerOverrides };
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Type definitions for the MCP server system.
3
+ * Servers provide external tools via Model Context Protocol.
4
+ */
5
+ /**
6
+ * A stdio-based MCP server configuration entry.
7
+ * Launches a local process that communicates via stdin/stdout.
8
+ */
9
+ export interface McpStdioServerConfig {
10
+ /** The command to launch the MCP server process */
11
+ command: string;
12
+ /** Arguments for the command */
13
+ args?: string[];
14
+ /** Working directory for the server process. Defaults to the parent process directory. */
15
+ cwd?: string;
16
+ /** Environment variables to set for the server process */
17
+ env?: Record<string, string>;
18
+ }
19
+ /**
20
+ * An HTTP-based MCP server configuration entry.
21
+ * Connects to a remote server via Streamable HTTP or SSE.
22
+ */
23
+ export interface McpHttpServerConfig {
24
+ /** The URL of the remote MCP server endpoint */
25
+ url: string;
26
+ /** Optional HTTP headers (e.g. for authentication) */
27
+ headers?: Record<string, string>;
28
+ /** Optional OAuth configuration for protected HTTP MCP servers */
29
+ oauth?: McpHttpOAuthConfig;
30
+ }
31
+ /**
32
+ * OAuth client configuration for an HTTP MCP server.
33
+ */
34
+ export interface McpHttpOAuthConfig {
35
+ /**
36
+ * Redirect URL for OAuth callbacks. Defaults to DEFAULT_OAUTH_REDIRECT_URL
37
+ * when omitted. Without a `clientId`, Mastra Code's hosted Client ID
38
+ * Metadata Document only lists the default URL and its port fallbacks, so
39
+ * a custom value works only with authorization servers that ignore the
40
+ * loopback port (RFC 8252 §7.3); otherwise set `clientId` too.
41
+ */
42
+ redirectUrl?: string;
43
+ /**
44
+ * Shorthand for a loopback redirect URL: synthesizes
45
+ * `http://localhost:<callbackPort>/callback`, matching the convention
46
+ * Claude Code and Codex use. Config files reject entries that set both
47
+ * `callbackPort` and `redirectUrl`; for programmatically registered
48
+ * servers, `callbackPort` takes precedence over `redirectUrl`. The same
49
+ * `clientId` caveat as `redirectUrl` applies.
50
+ */
51
+ callbackPort?: number;
52
+ /** Human-readable OAuth client name */
53
+ clientName?: string;
54
+ /** Optional scopes requested during OAuth */
55
+ scopes?: string[];
56
+ /**
57
+ * Optional pre-registered OAuth client ID. When omitted, Mastra Code
58
+ * identifies itself with its Client ID Metadata Document URL, which
59
+ * authorization servers supporting URL-based client IDs accept without
60
+ * any registration step.
61
+ */
62
+ clientId?: string;
63
+ /** Optional pre-registered OAuth client secret */
64
+ clientSecret?: string;
65
+ }
66
+ /**
67
+ * A single MCP server configuration entry.
68
+ * Detected by the presence of `command` (stdio) or `url` (http).
69
+ */
70
+ export type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;
71
+ /**
72
+ * An MCP server entry that was skipped during config loading.
73
+ */
74
+ export interface McpSkippedServer {
75
+ /** Server name (from config key) */
76
+ name: string;
77
+ /** Human-readable reason the server was skipped */
78
+ reason: string;
79
+ }
80
+ /**
81
+ * The top-level config object from mcp.json or settings.local.json.
82
+ * Maps server names to their config.
83
+ */
84
+ export interface McpConfig {
85
+ mcpServers?: Record<string, McpServerConfig>;
86
+ skippedServers?: McpSkippedServer[];
87
+ }
88
+ /**
89
+ * Runtime status of a connected MCP server.
90
+ */
91
+ export interface McpServerStatus {
92
+ /** Server name (from config key) */
93
+ name: string;
94
+ /** Whether the server is currently connected */
95
+ connected: boolean;
96
+ /** Whether the server is currently connecting */
97
+ connecting?: boolean;
98
+ /** Number of tools provided by this server */
99
+ toolCount: number;
100
+ /** List of tool names provided */
101
+ toolNames: string[];
102
+ /** Transport type used by the server */
103
+ transport: 'stdio' | 'http';
104
+ /** Error message if connection failed */
105
+ error?: string;
106
+ /** Whether the server rejected the connection pending OAuth authorization */
107
+ needsAuth?: boolean;
108
+ /**
109
+ * Whether an OAuth authorization flow is currently in flight for this server.
110
+ * Owned by the manager so the state survives a selector being closed/reopened;
111
+ * the UI uses it to keep offering "Cancel authentication" while auth is pending.
112
+ */
113
+ authenticating?: boolean;
114
+ /**
115
+ * Whether this failed status is the result of the caller deliberately
116
+ * cancelling an in-flight authentication (rather than a genuine failure).
117
+ * The UI uses it to suppress a misleading "Failed to authenticate" message.
118
+ */
119
+ cancelled?: boolean;
120
+ /**
121
+ * Whether the user disabled this server. Disabled servers stay visible in
122
+ * status listings (so they can be re-enabled) but are never connected and
123
+ * contribute no tools.
124
+ */
125
+ disabled?: boolean;
126
+ /**
127
+ * Where the effective disable state comes from when `disabled` is true.
128
+ * `global` means the global all-MCP kill switch or inherited global default
129
+ * applies; `project` means this project explicitly disabled the server.
130
+ */
131
+ disabledScope?: 'project' | 'global';
132
+ /** This project's explicit server override, or undefined when inheriting the global default. */
133
+ projectOverride?: 'enabled' | 'disabled';
134
+ /** The per-server global default before applying a project override or the global kill switch. */
135
+ globalDefault?: 'enabled' | 'disabled';
136
+ /** Whether the global all-MCP kill switch currently overrides every server and project setting. */
137
+ globalKillSwitch?: boolean;
138
+ }
139
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Pure `GlobalSettings` mutation helpers for custom model packs. Shared by the
3
+ * TUI `/models` command and the web settings routes — no UI dependencies.
4
+ */
5
+ import type { GlobalSettings } from './settings.js';
6
+ export declare function removeCustomPackFromSettings(settings: GlobalSettings, packId: string): void;
7
+ //# sourceMappingURL=custom-packs.d.ts.map
@@ -0,0 +1,17 @@
1
+ // src/onboarding/custom-packs.ts
2
+ function removeCustomPackFromSettings(settings, packId) {
3
+ if (!packId.startsWith("custom:")) return;
4
+ const packName = packId.slice(7);
5
+ const removedPack = settings.customModelPacks.find((p) => p.name === packName);
6
+ settings.customModelPacks = settings.customModelPacks.filter((p) => p.name !== packName);
7
+ const modeDefaultsMatchRemovedPack = !!removedPack && settings.models.modeDefaults.plan === removedPack.models.plan && settings.models.modeDefaults.build === removedPack.models.build && settings.models.modeDefaults.fast === removedPack.models.fast;
8
+ if (settings.models.activeModelPackId === packId) {
9
+ settings.models.activeModelPackId = null;
10
+ settings.models.modeDefaults = {};
11
+ } else if (modeDefaultsMatchRemovedPack) settings.models.modeDefaults = {};
12
+ if (settings.onboarding.modePackId === packId) settings.onboarding.modePackId = null;
13
+ const fallbacks = settings.models.packFallbacks ?? {};
14
+ settings.models.packFallbacks = Object.fromEntries(Object.entries(fallbacks).filter(([sourcePackId, targetPackId]) => sourcePackId !== packId && targetPackId !== packId));
15
+ delete settings.models.packAccountPreferences?.[packId];
16
+ }
17
+ export { removeCustomPackFromSettings };
@@ -0,0 +1,4 @@
1
+ import type { CustomProviderSetting, GlobalSettings } from './settings.js';
2
+ export declare function upsertCustomProviderInSettings(settings: GlobalSettings, provider: CustomProviderSetting, previousProviderId?: string): void;
3
+ export declare function removeCustomProviderFromSettings(settings: GlobalSettings, providerId: string): void;
4
+ //# sourceMappingURL=custom-providers.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { getCustomProviderId } from "./settings.js";
2
+ // src/onboarding/custom-providers.ts
3
+ /**
4
+ * Pure `GlobalSettings` mutation helpers for custom OpenAI-compatible
5
+ * providers. Shared by the TUI `/custom-providers` command and the web
6
+ * settings routes — no UI dependencies.
7
+ */
8
+ function normalizeProvider(input) {
9
+ return {
10
+ name: input.name.trim(),
11
+ url: input.url.trim(),
12
+ apiKey: input.apiKey?.trim() || void 0,
13
+ models: [...new Set(input.models.map((model) => model.trim()).filter(Boolean))]
14
+ };
15
+ }
16
+ function upsertCustomProviderInSettings(settings, provider, previousProviderId) {
17
+ const next = normalizeProvider(provider);
18
+ const nextProviderId = getCustomProviderId(next.name);
19
+ settings.customProviders = [...settings.customProviders.filter((existing) => {
20
+ const id = getCustomProviderId(existing.name);
21
+ return id !== nextProviderId && (!previousProviderId || id !== previousProviderId);
22
+ }), next];
23
+ }
24
+ function removeCustomProviderFromSettings(settings, providerId) {
25
+ settings.customProviders = settings.customProviders.filter((provider) => getCustomProviderId(provider.name) !== providerId);
26
+ }
27
+ export { removeCustomProviderFromSettings, upsertCustomProviderInSettings };
@@ -0,0 +1,5 @@
1
+ export { getAvailableModePacks, getAvailableOmPacks, selectPreferredOMPack, ONBOARDING_VERSION } from './packs.js';
2
+ export type { ModePack, OMPack, ProviderAccess, ProviderAccessLevel } from './packs.js';
3
+ export { loadSettings, saveSettings, getSettingsPath, resolveModelDefaults, resolveOmModel, resolveOmRoleModel, } from './settings.js';
4
+ export type { GlobalSettings, CustomPack } from './settings.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { ONBOARDING_VERSION, getAvailableModePacks, getAvailableOmPacks, selectPreferredOMPack } from "./packs.js";
2
+ import { getSettingsPath, loadSettings, resolveModelDefaults, resolveOmModel, resolveOmRoleModel, saveSettings } from "./settings.js";
3
+ export { ONBOARDING_VERSION, getAvailableModePacks, getAvailableOmPacks, getSettingsPath, loadSettings, resolveModelDefaults, resolveOmModel, resolveOmRoleModel, saveSettings, selectPreferredOMPack };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Pure `GlobalSettings` mutation helpers for observational-memory (OM)
3
+ * configuration. Shared by the TUI `/om` command and the web settings
4
+ * routes — no UI dependencies.
5
+ */
6
+ import type { OMPack } from './packs.js';
7
+ import type { GlobalSettings } from './settings.js';
8
+ /**
9
+ * Whether the user has already chosen any persisted OM model or pack.
10
+ *
11
+ * No longer called inside this repo — auto selection replaced the "seed a pack
12
+ * at login" flow — but part of the documented `@mastra/code-sdk/onboarding/om-settings`
13
+ * surface since 1.1.0, so it stays for external callers.
14
+ *
15
+ * @deprecated Observer and Reflector default to Auto; there is no default left to seed.
16
+ */
17
+ export declare function hasExplicitOMConfiguration(settings: GlobalSettings): boolean;
18
+ /**
19
+ * Seed a built-in OM pack unless the user already chose one; true when settings changed.
20
+ *
21
+ * The TUI stopped calling this when auto became the default; kept exported for
22
+ * external callers alongside {@link hasExplicitOMConfiguration}.
23
+ *
24
+ * @deprecated Seeding pins both roles to a fixed model. Leave them on Auto instead.
25
+ */
26
+ export declare function applyOMDefaultIfUnconfigured(settings: GlobalSettings, pack: OMPack): boolean;
27
+ /**
28
+ * Seed the provider's built-in OM pack into saved settings unless the user already chose one.
29
+ *
30
+ * @deprecated Signing in no longer seeds memory models; seeding pins both roles instead of
31
+ * leaving them on Auto.
32
+ */
33
+ export declare function seedProviderOMDefault(providerId: string): OMPack | undefined;
34
+ /**
35
+ * Apply a role-specific OM model override to an in-memory `GlobalSettings`.
36
+ *
37
+ * Role intent outranks the pack in `resolveOmRoleModel`, so `activeOmPackId` is
38
+ * deliberately left alone: the other role keeps resolving from its built-in
39
+ * pack instead of being dragged along by this role's choice.
40
+ *
41
+ * Exported for unit testing; `persistOmRoleOverride` is the disk-backed wrapper.
42
+ */
43
+ export declare function applyOmRoleOverride(settings: GlobalSettings, role: 'observer' | 'reflector', modelId: string): void;
44
+ /** Reset one persisted OM role to dynamic auto selection without touching the other role. */
45
+ export declare function applyOmRoleAuto(settings: GlobalSettings, role: 'observer' | 'reflector'): void;
46
+ export declare function persistOmObserveAttachments(value: 'auto' | boolean): void;
47
+ //# sourceMappingURL=om-settings.d.ts.map
@@ -0,0 +1,80 @@
1
+ import { resolveProviderOMDefault } from "./packs.js";
2
+ import { loadSettings, saveSettings } from "./settings.js";
3
+ // src/onboarding/om-settings.ts
4
+ /**
5
+ * Whether the user has already chosen any persisted OM model or pack.
6
+ *
7
+ * No longer called inside this repo — auto selection replaced the "seed a pack
8
+ * at login" flow — but part of the documented `@mastra/code-sdk/onboarding/om-settings`
9
+ * surface since 1.1.0, so it stays for external callers.
10
+ *
11
+ * @deprecated Observer and Reflector default to Auto; there is no default left to seed.
12
+ */
13
+ function hasExplicitOMConfiguration(settings) {
14
+ const { activeOmPackId, omModelOverride, observerModelOverride, observerModelSelection, reflectorModelOverride, reflectorModelSelection } = settings.models;
15
+ if (omModelOverride || observerModelOverride || observerModelSelection && observerModelSelection !== "auto" || reflectorModelOverride || reflectorModelSelection && reflectorModelSelection !== "auto") return true;
16
+ return [settings.onboarding.omPackId, activeOmPackId].some((packId) => packId && packId !== "custom");
17
+ }
18
+ /**
19
+ * Seed a built-in OM pack unless the user already chose one; true when settings changed.
20
+ *
21
+ * The TUI stopped calling this when auto became the default; kept exported for
22
+ * external callers alongside {@link hasExplicitOMConfiguration}.
23
+ *
24
+ * @deprecated Seeding pins both roles to a fixed model. Leave them on Auto instead.
25
+ */
26
+ function applyOMDefaultIfUnconfigured(settings, pack) {
27
+ if (hasExplicitOMConfiguration(settings)) return false;
28
+ settings.onboarding.omPackId = pack.id;
29
+ settings.models.activeOmPackId = pack.id;
30
+ settings.models.omModelOverride = null;
31
+ return true;
32
+ }
33
+ /**
34
+ * Seed the provider's built-in OM pack into saved settings unless the user already chose one.
35
+ *
36
+ * @deprecated Signing in no longer seeds memory models; seeding pins both roles instead of
37
+ * leaving them on Auto.
38
+ */
39
+ function seedProviderOMDefault(providerId) {
40
+ const pack = resolveProviderOMDefault(providerId);
41
+ if (pack.id === "custom") return void 0;
42
+ const settings = loadSettings();
43
+ if (!applyOMDefaultIfUnconfigured(settings, pack)) return void 0;
44
+ saveSettings(settings);
45
+ return pack;
46
+ }
47
+ /**
48
+ * Apply a role-specific OM model override to an in-memory `GlobalSettings`.
49
+ *
50
+ * Role intent outranks the pack in `resolveOmRoleModel`, so `activeOmPackId` is
51
+ * deliberately left alone: the other role keeps resolving from its built-in
52
+ * pack instead of being dragged along by this role's choice.
53
+ *
54
+ * Exported for unit testing; `persistOmRoleOverride` is the disk-backed wrapper.
55
+ */
56
+ function applyOmRoleOverride(settings, role, modelId) {
57
+ if (role === "observer") {
58
+ settings.models.observerModelOverride = modelId;
59
+ settings.models.observerModelSelection = modelId;
60
+ } else {
61
+ settings.models.reflectorModelOverride = modelId;
62
+ settings.models.reflectorModelSelection = modelId;
63
+ }
64
+ }
65
+ /** Reset one persisted OM role to dynamic auto selection without touching the other role. */
66
+ function applyOmRoleAuto(settings, role) {
67
+ if (role === "observer") {
68
+ settings.models.observerModelOverride = null;
69
+ settings.models.observerModelSelection = "auto";
70
+ } else {
71
+ settings.models.reflectorModelOverride = null;
72
+ settings.models.reflectorModelSelection = "auto";
73
+ }
74
+ }
75
+ function persistOmObserveAttachments(value) {
76
+ const settings = loadSettings();
77
+ settings.models.omObserveAttachments = value;
78
+ saveSettings(settings);
79
+ }
80
+ export { applyOMDefaultIfUnconfigured, applyOmRoleAuto, applyOmRoleOverride, hasExplicitOMConfiguration, persistOmObserveAttachments, seedProviderOMDefault };
@@ -0,0 +1,43 @@
1
+ import type { ModePack } from './packs.js';
2
+ import type { GlobalSettings } from './settings.js';
3
+ /** Every pack id that can be activated: built-ins plus saved custom packs (`custom:<name>`). */
4
+ export declare function listResolvableModePacks(settings: GlobalSettings): ModePack[];
5
+ /** The valid `--pack` values, in display order. */
6
+ export declare function listValidModePackIds(settings: GlobalSettings): string[];
7
+ /**
8
+ * Resolve a `--pack` argument to a canonical pack id.
9
+ *
10
+ * Accepts a built-in pack id (`anthropic`), a fully qualified custom pack id
11
+ * (`custom:Kimi`), or a bare custom pack name (`Kimi`) — the `custom:` prefix
12
+ * is a storage detail users never see in the picker. On a collision between a
13
+ * built-in id and a custom pack name, the built-in wins; `custom:<name>`
14
+ * always reaches the custom pack.
15
+ */
16
+ export declare function resolveModePackArg(settings: GlobalSettings, raw: string): {
17
+ packId: string;
18
+ } | {
19
+ error: string;
20
+ };
21
+ export interface PackSelection {
22
+ modelId: string;
23
+ subagentModels: Record<string, string>;
24
+ modelRoute: {
25
+ entries: Array<{
26
+ id: string;
27
+ label: string;
28
+ modelId: string;
29
+ accountId?: string;
30
+ memoryModelId?: string;
31
+ }>;
32
+ };
33
+ }
34
+ /** Resolve what activating `packId` in `modeId` applies to the session. */
35
+ export declare function resolvePackSelection(settings: GlobalSettings, packId: string, modeId: string): PackSelection | undefined;
36
+ /**
37
+ * Mutate global settings the way /models → Activate does: point the global
38
+ * default pack at `packId` and clear the per-agent subagent model overrides
39
+ * so the pack's subagent models apply. The caller persists with
40
+ * `saveSettings`.
41
+ */
42
+ export declare function activateModePackInSettings(settings: GlobalSettings, packId: string): void;
43
+ //# sourceMappingURL=pack-activation.d.ts.map
@@ -0,0 +1,105 @@
1
+ import { listBuiltinModePacks, resolveModePackFallbackChain } from "./packs.js";
2
+ import { resolveModePackModels } from "./settings.js";
3
+ // src/onboarding/pack-activation.ts
4
+ /**
5
+ * Shared model-pack resolution and activation helpers.
6
+ *
7
+ * Used by both the interactive TUI (`--pack`, /models → Activate) and the
8
+ * headless CLI (`--pack`) so a pack id from the command line behaves exactly
9
+ * like activating the pack in the picker: the global default pack changes and
10
+ * the session it starts gets the pack's models for every mode, its subagent
11
+ * models, its fallback route, and the thread's `activeModelPackId`.
12
+ */
13
+ /** Every pack id that can be activated: built-ins plus saved custom packs (`custom:<name>`). */
14
+ function listResolvableModePacks(settings) {
15
+ return [...listBuiltinModePacks(), ...settings.customModelPacks.map((pack) => ({
16
+ id: `custom:${pack.name}`,
17
+ name: pack.name,
18
+ description: "Saved custom pack",
19
+ models: {
20
+ build: pack.models.build ?? "",
21
+ plan: pack.models.plan ?? "",
22
+ fast: pack.models.fast ?? "",
23
+ ...pack.models.memory ? { memory: pack.models.memory } : {}
24
+ }
25
+ }))];
26
+ }
27
+ /** The valid `--pack` values, in display order. */
28
+ function listValidModePackIds(settings) {
29
+ return listResolvableModePacks(settings).map((pack) => pack.id);
30
+ }
31
+ /**
32
+ * Resolve a `--pack` argument to a canonical pack id.
33
+ *
34
+ * Accepts a built-in pack id (`anthropic`), a fully qualified custom pack id
35
+ * (`custom:Kimi`), or a bare custom pack name (`Kimi`) — the `custom:` prefix
36
+ * is a storage detail users never see in the picker. On a collision between a
37
+ * built-in id and a custom pack name, the built-in wins; `custom:<name>`
38
+ * always reaches the custom pack.
39
+ */
40
+ function resolveModePackArg(settings, raw) {
41
+ const input = raw.trim();
42
+ const valid = listValidModePackIds(settings);
43
+ if (input && valid.includes(input)) return { packId: input };
44
+ if (input && !input.startsWith("custom:")) {
45
+ const asCustom = `custom:${input}`;
46
+ if (valid.includes(asCustom)) return { packId: asCustom };
47
+ }
48
+ return { error: `Unknown model pack: "${raw}". Valid packs: ${valid.join(", ")} (a custom pack also accepts its bare name, e.g. "Kimi" for "custom:Kimi")` };
49
+ }
50
+ /** Resolve what activating `packId` in `modeId` applies to the session. */
51
+ function resolvePackSelection(settings, packId, modeId) {
52
+ const packs = listResolvableModePacks(settings);
53
+ const packsById = new Map(packs.map((pack) => [pack.id, pack]));
54
+ const pack = packsById.get(packId);
55
+ if (!pack) return void 0;
56
+ const packModels = resolveModePackModels(settings, pack);
57
+ const modelId = packModels[modeId];
58
+ if (!modelId) return void 0;
59
+ return {
60
+ modelId,
61
+ subagentModels: Object.fromEntries(Object.entries({
62
+ explore: "fast",
63
+ plan: "plan",
64
+ execute: "build"
65
+ }).flatMap(([agentType, subagentModeId]) => {
66
+ const subagentModelId = packModels[subagentModeId];
67
+ return subagentModelId ? [[agentType, subagentModelId]] : [];
68
+ })),
69
+ modelRoute: { entries: resolveModePackFallbackChain(settings.models.packFallbacks, packId, settings.customModelPacks).flatMap((routeId) => {
70
+ const routePack = packsById.get(routeId);
71
+ if (!routePack) return [];
72
+ const routeModels = resolveModePackModels(settings, routePack);
73
+ const routeModelId = routeModels[modeId];
74
+ if (!routeModelId) return [];
75
+ const accountId = settings.models.packAccountPreferences?.[routeId]?.[routeModelId];
76
+ return [{
77
+ id: routeId,
78
+ label: routePack.name,
79
+ modelId: routeModelId,
80
+ ...accountId ? { accountId } : {},
81
+ ...routeModels.memory ? { memoryModelId: routeModels.memory } : {}
82
+ }];
83
+ }) }
84
+ };
85
+ }
86
+ /**
87
+ * Mutate global settings the way /models → Activate does: point the global
88
+ * default pack at `packId` and clear the per-agent subagent model overrides
89
+ * so the pack's subagent models apply. The caller persists with
90
+ * `saveSettings`.
91
+ */
92
+ function activateModePackInSettings(settings, packId) {
93
+ settings.models.activeModelPackId = packId;
94
+ if (packId.startsWith("custom:")) {
95
+ const pack = listResolvableModePacks(settings).find((candidate) => candidate.id === packId);
96
+ if (pack) settings.models.modeDefaults = {
97
+ build: pack.models.build,
98
+ plan: pack.models.plan,
99
+ fast: pack.models.fast,
100
+ ...pack.models.memory ? { memory: pack.models.memory } : {}
101
+ };
102
+ } else settings.models.modeDefaults = {};
103
+ settings.models.subagentModels = {};
104
+ }
105
+ export { activateModePackInSettings, listResolvableModePacks, listValidModePackIds, resolveModePackArg, resolvePackSelection };