@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,115 @@
1
+ import type { SignalProvider } from '@mastra/core/signals';
2
+ import type { MastraCodePluginConfigValue, MastraCodePluginRuntime } from '../plugin.js';
3
+ import { discoverLocalPlugins } from './install.js';
4
+ import type { InstallPluginOptions } from './install.js';
5
+ import type { PluginPathOptions } from './paths.js';
6
+ import type { LoadedPlugin, PluginContribution, PluginErrorEvent, PluginProcessorEntries, PluginScope } from './types.js';
7
+ type PluginManagerOptions = PluginPathOptions & {
8
+ githubCliPath?: string;
9
+ /**
10
+ * Lazy accessors for Mastra Code's runtime, handed to plugin field resolvers on
11
+ * every load and reload.
12
+ */
13
+ runtime?: MastraCodePluginRuntime;
14
+ };
15
+ export declare class PluginManager {
16
+ private readonly options;
17
+ private loadedPlugins;
18
+ private readonly pluginTools;
19
+ private readonly rawPluginTools;
20
+ private readonly toolRenderConfigs;
21
+ private readonly watchedLocalEntries;
22
+ private readonly localEntryVersions;
23
+ /** Last known git HEAD per GitHub checkout, kept current by the poller. */
24
+ private readonly githubCheckoutHeads;
25
+ private githubPollTimer;
26
+ private githubPollInFlight;
27
+ private reloadInFlight;
28
+ private readonly reloadListeners;
29
+ private readonly githubUpdateListeners;
30
+ private readonly pluginErrorListeners;
31
+ private readonly unheardPluginErrors;
32
+ private runtime;
33
+ constructor(options: PluginManagerOptions);
34
+ /**
35
+ * Publish (or replace) the runtime accessors handed to plugin field resolvers.
36
+ * Takes effect on the next load or reload. `createMastraCode` calls this for
37
+ * every manager it uses — including an injected one — so a manager constructed
38
+ * without a runtime still exposes `getController`/`getActiveSession` to plugins.
39
+ * A manager shared across controllers sees the most recent controller's accessors.
40
+ */
41
+ setRuntime(runtime: MastraCodePluginRuntime): void;
42
+ onReload(listener: (plugins: LoadedPlugin[]) => void | Promise<void>): () => void;
43
+ /** Notified with the display names of GitHub plugins that were updated by the background poll. */
44
+ onGithubPluginsUpdated(listener: (pluginNames: string[]) => void | Promise<void>): () => void;
45
+ reload(): Promise<LoadedPlugin[]>;
46
+ /**
47
+ * Notified of plugin problems the user should see. With no listener, they go to
48
+ * `console.warn` so a headless embedder still has a trace, and the most recent
49
+ * ones are handed to the first listener that subscribes: plugin signal providers
50
+ * start while Mastra Code boots, before a UI exists to subscribe.
51
+ */
52
+ onPluginError(listener: (event: PluginErrorEvent) => void): () => void;
53
+ reportPluginError(event: PluginErrorEvent): void;
54
+ private notifyPluginErrorListener;
55
+ /**
56
+ * Reports each reload that kept a plugin's previous load, once per distinct
57
+ * error: a plugin that stays broken across later reloads (another plugin's
58
+ * update, a config edit) must not repeat its notice on every one.
59
+ */
60
+ private reportReloadFailures;
61
+ listPlugins(): Promise<LoadedPlugin[]>;
62
+ getLoadedPlugins(): LoadedPlugin[];
63
+ getPluginTools(): import("../plugin.js").MastraCodePluginTools;
64
+ getToolRenderConfig(toolName: string): import("../plugin.js").MastraCodeToolRenderConfig | undefined;
65
+ getPluginSkillPaths(): string[];
66
+ getPluginCommandPaths(): string[];
67
+ getPluginInstructions(): string[];
68
+ /**
69
+ * Processors contributed by active plugins, tagged with the plugin that owns
70
+ * each one. Reads already-resolved state — no filesystem access — because the
71
+ * agent's processor lanes call this before every request.
72
+ */
73
+ getPluginProcessors(): PluginProcessorEntries;
74
+ /** Signal providers contributed by active plugins, tagged with their owning plugin. */
75
+ getPluginSignalProviders(): PluginContribution<SignalProvider<string>>[];
76
+ private collectActive;
77
+ private notifyReloadListeners;
78
+ /**
79
+ * Stamps each plugin with a value that changes when its contributions should
80
+ * be rebuilt. Runs on every reload, so it stays off the network: GitHub heads
81
+ * come from the cache the poller keeps current and cost one `git rev-parse`
82
+ * per checkout the first time it is seen.
83
+ */
84
+ private stampLoadedPlugins;
85
+ private readSourceStamp;
86
+ private updatePluginRenderConfigs;
87
+ private updatePluginTools;
88
+ private createLiveToolProxy;
89
+ private syncLiveToolProxy;
90
+ private reloadChangedLocalPlugins;
91
+ private updateLocalEntryWatchers;
92
+ private updateGithubPoller;
93
+ pollGithubSourcesForUpdates(): Promise<boolean>;
94
+ private pollGithubSourcesForUpdatesOnce;
95
+ private notifyGithubUpdateListeners;
96
+ private refreshGithubCheckout;
97
+ private backupGitCheckout;
98
+ private resolveGitUpstream;
99
+ private readGitAheadBehind;
100
+ private hasGitWorkingTreeChanges;
101
+ private hasGitStagedChanges;
102
+ private restoreGitCheckout;
103
+ private readGitCurrentBranch;
104
+ private createGitBackupBranchName;
105
+ private resolvePluginSourcePath;
106
+ private readGitHead;
107
+ discoverLocal(searchRoot?: string): ReturnType<typeof discoverLocalPlugins>;
108
+ installLocal(localPath: string, scope: PluginScope, options?: Pick<InstallPluginOptions, 'entry'>): Promise<string>;
109
+ installGithub(url: string, scope: PluginScope, options?: Pick<InstallPluginOptions, 'entry' | 'ref' | 'onOutput' | 'signal'>): Promise<string>;
110
+ setEnabled(pluginId: string, scope: PluginScope, enabled: boolean): Promise<void>;
111
+ setConfigValue(pluginId: string, scope: PluginScope, key: string, value: MastraCodePluginConfigValue): Promise<void>;
112
+ uninstall(pluginId: string, scope: PluginScope): Promise<void>;
113
+ }
114
+ export {};
115
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1,507 @@
1
+ import { getEntryPackageRoot, installPluginDependenciesForEntry } from "./dependencies.js";
2
+ import { NON_INTERACTIVE_GIT_ENV, discoverLocalPlugins, installGithubPlugin, installLocalPlugin } from "./install.js";
3
+ import { collectActivePluginTools, isInsideDirectory, loadPlugins, resolvePluginEntryPath } from "./loader.js";
4
+ import { ensureMastraCodePackageLink } from "./package-link.js";
5
+ import { getPluginScopePaths } from "./paths.js";
6
+ import { loadPluginRegistry, removePluginRecord, savePluginRegistry, setPluginRecord } from "./registry.js";
7
+ import path from "path";
8
+ import fs from "fs";
9
+ import { execa } from "execa";
10
+ // src/plugins/manager.ts
11
+ const GITHUB_PLUGIN_POLL_INTERVAL_MS = 6e4;
12
+ const MAX_UNHEARD_PLUGIN_ERRORS = 20;
13
+ function gitExecOptions(cwd) {
14
+ return {
15
+ cwd,
16
+ env: NON_INTERACTIVE_GIT_ENV
17
+ };
18
+ }
19
+ function getEntryVersion(entryPath) {
20
+ const stat = fs.statSync(entryPath, { bigint: true });
21
+ return `${stat.mtimeNs}:${stat.size}`;
22
+ }
23
+ var PluginManager = class {
24
+ options;
25
+ loadedPlugins = [];
26
+ pluginTools = {};
27
+ rawPluginTools = {};
28
+ toolRenderConfigs = /* @__PURE__ */ new Map();
29
+ watchedLocalEntries = /* @__PURE__ */ new Set();
30
+ localEntryVersions = /* @__PURE__ */ new Map();
31
+ /** Last known git HEAD per GitHub checkout, kept current by the poller. */
32
+ githubCheckoutHeads = /* @__PURE__ */ new Map();
33
+ githubPollTimer;
34
+ githubPollInFlight;
35
+ reloadInFlight;
36
+ reloadListeners = /* @__PURE__ */ new Set();
37
+ githubUpdateListeners = /* @__PURE__ */ new Set();
38
+ pluginErrorListeners = /* @__PURE__ */ new Set();
39
+ unheardPluginErrors = [];
40
+ runtime;
41
+ constructor(options) {
42
+ this.options = options;
43
+ this.runtime = options.runtime;
44
+ }
45
+ /**
46
+ * Publish (or replace) the runtime accessors handed to plugin field resolvers.
47
+ * Takes effect on the next load or reload. `createMastraCode` calls this for
48
+ * every manager it uses — including an injected one — so a manager constructed
49
+ * without a runtime still exposes `getController`/`getActiveSession` to plugins.
50
+ * A manager shared across controllers sees the most recent controller's accessors.
51
+ */
52
+ setRuntime(runtime) {
53
+ this.runtime = runtime;
54
+ }
55
+ onReload(listener) {
56
+ this.reloadListeners.add(listener);
57
+ return () => this.reloadListeners.delete(listener);
58
+ }
59
+ /** Notified with the display names of GitHub plugins that were updated by the background poll. */
60
+ onGithubPluginsUpdated(listener) {
61
+ this.githubUpdateListeners.add(listener);
62
+ return () => this.githubUpdateListeners.delete(listener);
63
+ }
64
+ async reload() {
65
+ if (this.reloadInFlight) return this.reloadInFlight;
66
+ this.reloadInFlight = (async () => {
67
+ const previous = this.loadedPlugins;
68
+ this.loadedPlugins = await loadPlugins({
69
+ ...this.options,
70
+ runtime: this.runtime,
71
+ previous
72
+ });
73
+ await this.stampLoadedPlugins(this.loadedPlugins);
74
+ this.updateLocalEntryWatchers(this.loadedPlugins);
75
+ this.updateGithubPoller(this.loadedPlugins);
76
+ this.updatePluginRenderConfigs(this.loadedPlugins);
77
+ this.updatePluginTools(collectActivePluginTools(this.loadedPlugins));
78
+ this.reportReloadFailures(previous, this.loadedPlugins);
79
+ await this.notifyReloadListeners(this.loadedPlugins);
80
+ return this.loadedPlugins;
81
+ })().finally(() => {
82
+ this.reloadInFlight = void 0;
83
+ });
84
+ return this.reloadInFlight;
85
+ }
86
+ /**
87
+ * Notified of plugin problems the user should see. With no listener, they go to
88
+ * `console.warn` so a headless embedder still has a trace, and the most recent
89
+ * ones are handed to the first listener that subscribes: plugin signal providers
90
+ * start while Mastra Code boots, before a UI exists to subscribe.
91
+ */
92
+ onPluginError(listener) {
93
+ this.pluginErrorListeners.add(listener);
94
+ const unheard = this.unheardPluginErrors.splice(0);
95
+ for (const event of unheard) this.notifyPluginErrorListener(listener, event);
96
+ return () => this.pluginErrorListeners.delete(listener);
97
+ }
98
+ reportPluginError(event) {
99
+ if (this.pluginErrorListeners.size === 0) {
100
+ console.warn(event.message);
101
+ this.unheardPluginErrors.push(event);
102
+ if (this.unheardPluginErrors.length > MAX_UNHEARD_PLUGIN_ERRORS) this.unheardPluginErrors.shift();
103
+ return;
104
+ }
105
+ for (const listener of this.pluginErrorListeners) this.notifyPluginErrorListener(listener, event);
106
+ }
107
+ notifyPluginErrorListener(listener, event) {
108
+ try {
109
+ listener(event);
110
+ } catch (error) {
111
+ console.warn(`Plugin error listener failed: ${error instanceof Error ? error.message : String(error)}`);
112
+ }
113
+ }
114
+ /**
115
+ * Reports each reload that kept a plugin's previous load, once per distinct
116
+ * error: a plugin that stays broken across later reloads (another plugin's
117
+ * update, a config edit) must not repeat its notice on every one.
118
+ */
119
+ reportReloadFailures(previous, plugins) {
120
+ for (const plugin of plugins) {
121
+ if (plugin.reloadError === void 0) continue;
122
+ if (previous.find((entry) => entry.id === plugin.id && entry.scope === plugin.scope)?.reloadError === plugin.reloadError) continue;
123
+ const outcome = plugin.status === "active" ? " Still running the previous version." : "";
124
+ this.reportPluginError({
125
+ pluginId: plugin.id,
126
+ message: `Plugin "${plugin.name ?? plugin.id}" failed to reload: ${plugin.reloadError}.${outcome}`
127
+ });
128
+ }
129
+ }
130
+ async listPlugins() {
131
+ if (this.loadedPlugins.length === 0) await this.reload();
132
+ return this.loadedPlugins;
133
+ }
134
+ getLoadedPlugins() {
135
+ return this.loadedPlugins;
136
+ }
137
+ getPluginTools() {
138
+ return this.pluginTools;
139
+ }
140
+ getToolRenderConfig(toolName) {
141
+ return this.toolRenderConfigs.get(toolName);
142
+ }
143
+ getPluginSkillPaths() {
144
+ return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" ? plugin.skillPaths ?? [] : []);
145
+ }
146
+ getPluginCommandPaths() {
147
+ return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" ? plugin.commandPaths ?? [] : []);
148
+ }
149
+ getPluginInstructions() {
150
+ return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" && plugin.instructions ? [plugin.instructions] : []);
151
+ }
152
+ /**
153
+ * Processors contributed by active plugins, tagged with the plugin that owns
154
+ * each one. Reads already-resolved state — no filesystem access — because the
155
+ * agent's processor lanes call this before every request.
156
+ */
157
+ getPluginProcessors() {
158
+ return {
159
+ input: this.collectActive((plugin) => plugin.processors?.input ?? []),
160
+ output: this.collectActive((plugin) => plugin.processors?.output ?? [])
161
+ };
162
+ }
163
+ /** Signal providers contributed by active plugins, tagged with their owning plugin. */
164
+ getPluginSignalProviders() {
165
+ return this.collectActive((plugin) => plugin.signalProviders ?? []);
166
+ }
167
+ collectActive(select) {
168
+ return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" ? select(plugin).map((value) => ({
169
+ pluginId: plugin.id,
170
+ versionStamp: plugin.versionStamp ?? "",
171
+ value
172
+ })) : []);
173
+ }
174
+ async notifyReloadListeners(plugins) {
175
+ await Promise.all([...this.reloadListeners].map((listener) => Promise.resolve(listener(plugins))));
176
+ }
177
+ /**
178
+ * Stamps each plugin with a value that changes when its contributions should
179
+ * be rebuilt. Runs on every reload, so it stays off the network: GitHub heads
180
+ * come from the cache the poller keeps current and cost one `git rev-parse`
181
+ * per checkout the first time it is seen.
182
+ */
183
+ async stampLoadedPlugins(plugins) {
184
+ for (const plugin of plugins) {
185
+ if (plugin.reloadError !== void 0) continue;
186
+ plugin.versionStamp = [
187
+ plugin.status,
188
+ await this.readSourceStamp(plugin),
189
+ JSON.stringify(plugin.configValues ?? {})
190
+ ].join("|");
191
+ }
192
+ }
193
+ async readSourceStamp(plugin) {
194
+ try {
195
+ if (plugin.source === "github") {
196
+ const checkoutPath = this.resolvePluginSourcePath(plugin);
197
+ let head = this.githubCheckoutHeads.get(checkoutPath);
198
+ if (head === void 0) {
199
+ head = await this.readGitHead(checkoutPath);
200
+ this.githubCheckoutHeads.set(checkoutPath, head);
201
+ }
202
+ return head;
203
+ }
204
+ return getEntryVersion(resolvePluginEntryPath(plugin, this.options));
205
+ } catch {
206
+ return "";
207
+ }
208
+ }
209
+ updatePluginRenderConfigs(plugins) {
210
+ this.toolRenderConfigs.clear();
211
+ for (const plugin of plugins) {
212
+ if (plugin.status !== "active") continue;
213
+ for (const [toolName, renderConfig] of Object.entries(plugin.renderConfigs ?? {})) if (!this.toolRenderConfigs.has(toolName)) this.toolRenderConfigs.set(toolName, renderConfig);
214
+ }
215
+ }
216
+ updatePluginTools(nextTools) {
217
+ for (const name of Object.keys(this.rawPluginTools)) if (!(name in nextTools)) {
218
+ delete this.rawPluginTools[name];
219
+ delete this.pluginTools[name];
220
+ }
221
+ for (const [name, tool] of Object.entries(nextTools)) {
222
+ this.rawPluginTools[name] = tool;
223
+ if (!this.pluginTools[name]) this.pluginTools[name] = this.createLiveToolProxy(name);
224
+ this.syncLiveToolProxy(name, tool);
225
+ }
226
+ }
227
+ createLiveToolProxy(toolName) {
228
+ return { execute: async (...args) => {
229
+ await this.reloadChangedLocalPlugins();
230
+ const latestTool = this.rawPluginTools[toolName];
231
+ if (!latestTool?.execute) throw new Error(`Plugin tool "${toolName}" is no longer available`);
232
+ return latestTool.execute(...args);
233
+ } };
234
+ }
235
+ syncLiveToolProxy(toolName, tool) {
236
+ const proxy = this.pluginTools[toolName];
237
+ if (!proxy) return;
238
+ const mutableProxy = proxy;
239
+ for (const key of Object.keys(mutableProxy)) delete mutableProxy[key];
240
+ Object.assign(proxy, tool);
241
+ proxy.execute = this.createLiveToolProxy(toolName).execute;
242
+ }
243
+ async reloadChangedLocalPlugins() {
244
+ for (const plugin of this.loadedPlugins) {
245
+ if (plugin.source !== "local" || plugin.status !== "active") continue;
246
+ const entryPath = resolvePluginEntryPath(plugin, this.options);
247
+ const currentVersion = getEntryVersion(entryPath);
248
+ if (this.localEntryVersions.get(entryPath) !== currentVersion) {
249
+ await this.reload();
250
+ return;
251
+ }
252
+ }
253
+ }
254
+ updateLocalEntryWatchers(plugins) {
255
+ const nextEntries = /* @__PURE__ */ new Set();
256
+ for (const plugin of plugins) {
257
+ if (plugin.source !== "local" || plugin.status !== "active") continue;
258
+ let entryPath;
259
+ let entryVersion;
260
+ try {
261
+ entryPath = resolvePluginEntryPath(plugin, this.options);
262
+ entryVersion = getEntryVersion(entryPath);
263
+ } catch {
264
+ continue;
265
+ }
266
+ nextEntries.add(entryPath);
267
+ this.localEntryVersions.set(entryPath, entryVersion);
268
+ if (this.watchedLocalEntries.has(entryPath)) continue;
269
+ fs.watchFile(entryPath, { interval: 500 }, (current, previous) => {
270
+ if (current.mtimeMs === previous.mtimeMs) return;
271
+ this.reload().catch(() => void 0);
272
+ }).unref?.();
273
+ this.watchedLocalEntries.add(entryPath);
274
+ }
275
+ for (const entryPath of this.watchedLocalEntries) {
276
+ if (nextEntries.has(entryPath)) continue;
277
+ fs.unwatchFile(entryPath);
278
+ this.watchedLocalEntries.delete(entryPath);
279
+ this.localEntryVersions.delete(entryPath);
280
+ }
281
+ }
282
+ updateGithubPoller(plugins) {
283
+ const hasGithubPlugin = plugins.some((plugin) => plugin.source === "github" && plugin.status !== "inactive" && plugin.status !== "blocked");
284
+ if (hasGithubPlugin && !this.githubPollTimer) {
285
+ this.githubPollTimer = setInterval(() => {
286
+ this.pollGithubSourcesForUpdates().catch(() => void 0);
287
+ }, GITHUB_PLUGIN_POLL_INTERVAL_MS);
288
+ this.githubPollTimer.unref?.();
289
+ }
290
+ if (!hasGithubPlugin && this.githubPollTimer) {
291
+ clearInterval(this.githubPollTimer);
292
+ this.githubPollTimer = void 0;
293
+ }
294
+ }
295
+ async pollGithubSourcesForUpdates() {
296
+ if (this.githubPollInFlight) return this.githubPollInFlight;
297
+ this.githubPollInFlight = this.pollGithubSourcesForUpdatesOnce().finally(() => {
298
+ this.githubPollInFlight = void 0;
299
+ });
300
+ return this.githubPollInFlight;
301
+ }
302
+ async pollGithubSourcesForUpdatesOnce() {
303
+ const changedCheckouts = /* @__PURE__ */ new Set();
304
+ const seen = /* @__PURE__ */ new Set();
305
+ for (const plugin of this.loadedPlugins) {
306
+ if (plugin.source !== "github" || plugin.status === "inactive" || plugin.status === "blocked") continue;
307
+ const checkoutPath = this.resolvePluginSourcePath(plugin);
308
+ if (seen.has(checkoutPath) || !fs.existsSync(path.join(checkoutPath, ".git"))) continue;
309
+ seen.add(checkoutPath);
310
+ const before = await this.readGitHead(checkoutPath);
311
+ const checkoutChanged = await this.refreshGithubCheckout(plugin, checkoutPath, before);
312
+ const after = await this.readGitHead(checkoutPath);
313
+ this.githubCheckoutHeads.set(checkoutPath, after);
314
+ if (checkoutChanged || before !== after) changedCheckouts.add(checkoutPath);
315
+ }
316
+ if (changedCheckouts.size === 0) return false;
317
+ await this.reload();
318
+ const updatedPluginNames = this.loadedPlugins.filter((plugin) => plugin.source === "github" && plugin.status !== "inactive" && plugin.status !== "blocked" && plugin.reloadError === void 0 && changedCheckouts.has(this.resolvePluginSourcePath(plugin))).map((plugin) => plugin.name ?? plugin.id);
319
+ await this.notifyGithubUpdateListeners(updatedPluginNames);
320
+ return true;
321
+ }
322
+ async notifyGithubUpdateListeners(pluginNames) {
323
+ await Promise.all([...this.githubUpdateListeners].map((listener) => Promise.resolve(listener(pluginNames))));
324
+ }
325
+ async refreshGithubCheckout(plugin, checkoutPath, currentHead) {
326
+ await execa("git", ["fetch", "origin"], gitExecOptions(checkoutPath));
327
+ const upstream = await this.resolveGitUpstream(checkoutPath, plugin.ref);
328
+ if (!upstream) return false;
329
+ const [localOnly, remoteOnly] = await this.readGitAheadBehind(checkoutPath, upstream);
330
+ const hasLocalChanges = await this.hasGitWorkingTreeChanges(checkoutPath);
331
+ if (localOnly > 0 || hasLocalChanges) await this.backupGitCheckout(checkoutPath, currentHead, hasLocalChanges);
332
+ if (remoteOnly > 0 || localOnly > 0 || hasLocalChanges) {
333
+ await execa("git", [
334
+ "reset",
335
+ "--hard",
336
+ upstream
337
+ ], gitExecOptions(checkoutPath));
338
+ try {
339
+ await installPluginDependenciesForEntry(checkoutPath, plugin.entry);
340
+ ensureMastraCodePackageLink(getEntryPackageRoot(checkoutPath, plugin.entry));
341
+ } catch (error) {
342
+ await execa("git", [
343
+ "reset",
344
+ "--hard",
345
+ currentHead
346
+ ], gitExecOptions(checkoutPath));
347
+ throw error;
348
+ }
349
+ return true;
350
+ }
351
+ return false;
352
+ }
353
+ async backupGitCheckout(checkoutPath, currentHead, includeWorkingTree) {
354
+ const backupBranch = this.createGitBackupBranchName(currentHead);
355
+ if (includeWorkingTree) {
356
+ const currentBranch = await this.readGitCurrentBranch(checkoutPath);
357
+ await execa("git", [
358
+ "switch",
359
+ "-c",
360
+ backupBranch
361
+ ], gitExecOptions(checkoutPath));
362
+ await execa("git", ["add", "-A"], gitExecOptions(checkoutPath));
363
+ if (await this.hasGitStagedChanges(checkoutPath)) await execa("git", [
364
+ "-c",
365
+ "user.name=Mastra Code",
366
+ "-c",
367
+ "user.email=noreply@mastra.ai",
368
+ "commit",
369
+ "-m",
370
+ "chore: backup local plugin checkout changes"
371
+ ], gitExecOptions(checkoutPath));
372
+ await this.restoreGitCheckout(checkoutPath, currentBranch, currentHead);
373
+ return;
374
+ }
375
+ await execa("git", [
376
+ "branch",
377
+ backupBranch,
378
+ "HEAD"
379
+ ], gitExecOptions(checkoutPath));
380
+ }
381
+ async resolveGitUpstream(cwd, installedRef) {
382
+ try {
383
+ const { stdout } = await execa("git", [
384
+ "rev-parse",
385
+ "--abbrev-ref",
386
+ "--symbolic-full-name",
387
+ "@{u}"
388
+ ], gitExecOptions(cwd));
389
+ return stdout.trim();
390
+ } catch {
391
+ return installedRef ? void 0 : "origin/main";
392
+ }
393
+ }
394
+ async readGitAheadBehind(cwd, upstream) {
395
+ const { stdout } = await execa("git", [
396
+ "rev-list",
397
+ "--left-right",
398
+ "--count",
399
+ `HEAD...${upstream}`
400
+ ], gitExecOptions(cwd));
401
+ const [ahead = "0", behind = "0"] = stdout.trim().split(/\s+/);
402
+ return [Number(ahead) || 0, Number(behind) || 0];
403
+ }
404
+ async hasGitWorkingTreeChanges(cwd) {
405
+ const { stdout } = await execa("git", ["status", "--porcelain"], gitExecOptions(cwd));
406
+ return stdout.trim().length > 0;
407
+ }
408
+ async hasGitStagedChanges(cwd) {
409
+ try {
410
+ await execa("git", [
411
+ "diff",
412
+ "--cached",
413
+ "--quiet"
414
+ ], gitExecOptions(cwd));
415
+ return false;
416
+ } catch {
417
+ return true;
418
+ }
419
+ }
420
+ async restoreGitCheckout(cwd, branch, fallbackHead) {
421
+ if (branch) {
422
+ await execa("git", ["switch", branch], gitExecOptions(cwd));
423
+ return;
424
+ }
425
+ await execa("git", ["checkout", fallbackHead], gitExecOptions(cwd));
426
+ }
427
+ async readGitCurrentBranch(cwd) {
428
+ const { stdout } = await execa("git", ["branch", "--show-current"], gitExecOptions(cwd));
429
+ const branch = stdout.trim();
430
+ return branch.length > 0 ? branch : void 0;
431
+ }
432
+ createGitBackupBranchName(currentHead) {
433
+ return `mastracode/plugin-backup/${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}-${currentHead.slice(0, 8)}`;
434
+ }
435
+ resolvePluginSourcePath(plugin) {
436
+ const paths = getPluginScopePaths(plugin.scope, this.options);
437
+ return path.resolve(path.isAbsolute(plugin.path) ? plugin.path : path.join(paths.root, plugin.path));
438
+ }
439
+ async readGitHead(cwd) {
440
+ const { stdout } = await execa("git", ["rev-parse", "HEAD"], gitExecOptions(cwd));
441
+ return stdout.trim();
442
+ }
443
+ discoverLocal(searchRoot = ".") {
444
+ return discoverLocalPlugins(searchRoot, this.options);
445
+ }
446
+ async installLocal(localPath, scope, options = {}) {
447
+ const id = await installLocalPlugin(localPath, scope, {
448
+ ...this.options,
449
+ ...options
450
+ });
451
+ await this.reload();
452
+ return id;
453
+ }
454
+ async installGithub(url, scope, options = {}) {
455
+ const id = await installGithubPlugin(url, scope, {
456
+ ...this.options,
457
+ ...options
458
+ });
459
+ this.githubCheckoutHeads.clear();
460
+ await this.reload();
461
+ return id;
462
+ }
463
+ async setEnabled(pluginId, scope, enabled) {
464
+ const paths = getPluginScopePaths(scope, this.options);
465
+ const registry = loadPluginRegistry(paths.registryPath);
466
+ const record = registry.plugins[pluginId];
467
+ if (!record) throw new Error(`Plugin "${pluginId}" is not installed in ${scope} scope`);
468
+ savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, {
469
+ ...record,
470
+ enabled
471
+ }));
472
+ await this.reload();
473
+ }
474
+ async setConfigValue(pluginId, scope, key, value) {
475
+ const paths = getPluginScopePaths(scope, this.options);
476
+ const registry = loadPluginRegistry(paths.registryPath);
477
+ const record = registry.plugins[pluginId];
478
+ if (!record) throw new Error(`Plugin "${pluginId}" is not installed in ${scope} scope`);
479
+ const config = { ...record.config ?? {} };
480
+ if (value === void 0 || value === "") delete config[key];
481
+ else config[key] = value;
482
+ const nextRecord = {
483
+ ...record,
484
+ config: Object.keys(config).length > 0 ? config : void 0
485
+ };
486
+ savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, nextRecord));
487
+ await this.reload();
488
+ }
489
+ async uninstall(pluginId, scope) {
490
+ const paths = getPluginScopePaths(scope, this.options);
491
+ const registry = loadPluginRegistry(paths.registryPath);
492
+ const record = registry.plugins[pluginId];
493
+ if (!record) throw new Error(`Plugin "${pluginId}" is not installed in ${scope} scope`);
494
+ savePluginRegistry(paths.registryPath, removePluginRecord(registry, pluginId));
495
+ if (record.source === "github") {
496
+ const checkoutPath = path.resolve(path.isAbsolute(record.path) ? record.path : path.join(paths.root, record.path));
497
+ const githubSourcesPath = path.resolve(paths.sourcesPath, "github");
498
+ if (isInsideDirectory(checkoutPath, githubSourcesPath)) fs.rmSync(checkoutPath, {
499
+ recursive: true,
500
+ force: true
501
+ });
502
+ this.githubCheckoutHeads.delete(checkoutPath);
503
+ }
504
+ await this.reload();
505
+ }
506
+ };
507
+ export { PluginManager };
@@ -0,0 +1,14 @@
1
+ export declare const PLUGIN_MANIFEST_FILE = ".mastracode-plugin.json";
2
+ export type PluginManifestEntry = {
3
+ id: string;
4
+ name?: string;
5
+ entry: string;
6
+ };
7
+ export type PluginManifest = {
8
+ plugins: PluginManifestEntry[];
9
+ };
10
+ export declare function loadPluginManifest(rootDir: string): PluginManifest | undefined;
11
+ export declare function savePluginManifest(rootDir: string, manifest: PluginManifest): void;
12
+ export declare function upsertPluginManifestEntry(rootDir: string, entry: PluginManifestEntry): void;
13
+ export declare function getSingleManifestPlugin(rootDir: string): PluginManifestEntry | undefined;
14
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1,47 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ // src/plugins/manifest.ts
4
+ const PLUGIN_MANIFEST_FILE = ".mastracode-plugin.json";
5
+ function loadPluginManifest(rootDir) {
6
+ const manifestPath = path.join(rootDir, PLUGIN_MANIFEST_FILE);
7
+ if (!fs.existsSync(manifestPath)) return void 0;
8
+ let parsed;
9
+ try {
10
+ parsed = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
11
+ } catch (error) {
12
+ throw new Error(`Could not parse ${PLUGIN_MANIFEST_FILE}: ${error instanceof Error ? error.message : String(error)}`);
13
+ }
14
+ if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins)) throw new Error(`${PLUGIN_MANIFEST_FILE} must contain a plugins array`);
15
+ return { plugins: parsed.plugins.map((entry, index) => validateManifestEntry(entry, index)) };
16
+ }
17
+ function savePluginManifest(rootDir, manifest) {
18
+ fs.writeFileSync(path.join(rootDir, PLUGIN_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
19
+ }
20
+ function upsertPluginManifestEntry(rootDir, entry) {
21
+ const manifest = loadPluginManifest(rootDir) ?? { plugins: [] };
22
+ const validatedEntry = validateManifestEntry(entry, manifest.plugins.length);
23
+ const existingIndex = manifest.plugins.findIndex((plugin) => plugin.id === validatedEntry.id);
24
+ if (existingIndex >= 0) manifest.plugins[existingIndex] = validateManifestEntry(validatedEntry, existingIndex);
25
+ else manifest.plugins.push(validatedEntry);
26
+ savePluginManifest(rootDir, manifest);
27
+ }
28
+ function getSingleManifestPlugin(rootDir) {
29
+ const manifest = loadPluginManifest(rootDir);
30
+ if (!manifest) return void 0;
31
+ if (manifest.plugins.length === 0) return void 0;
32
+ if (manifest.plugins.length > 1) throw new Error(`${PLUGIN_MANIFEST_FILE} contains multiple plugins. Provide an entry path for one of: ${manifest.plugins.map((plugin) => `${plugin.id} (${plugin.entry})`).join(", ")}`);
33
+ return manifest.plugins[0];
34
+ }
35
+ function validateManifestEntry(entry, index) {
36
+ if (!entry || typeof entry !== "object") throw new Error(`${PLUGIN_MANIFEST_FILE} plugin at index ${index} must be an object`);
37
+ const candidate = entry;
38
+ if (typeof candidate.id !== "string" || candidate.id.length === 0) throw new Error(`${PLUGIN_MANIFEST_FILE} plugin at index ${index} must include an id`);
39
+ if (typeof candidate.entry !== "string" || candidate.entry.length === 0) throw new Error(`${PLUGIN_MANIFEST_FILE} plugin ${candidate.id} must include an entry`);
40
+ if (candidate.name !== void 0 && typeof candidate.name !== "string") throw new Error(`${PLUGIN_MANIFEST_FILE} plugin ${candidate.id} name must be a string`);
41
+ return {
42
+ id: candidate.id,
43
+ entry: candidate.entry,
44
+ ...candidate.name ? { name: candidate.name } : {}
45
+ };
46
+ }
47
+ export { PLUGIN_MANIFEST_FILE, getSingleManifestPlugin, loadPluginManifest, savePluginManifest, upsertPluginManifestEntry };
@@ -0,0 +1,3 @@
1
+ export declare function findMastraCodePackageRoot(startDir: string): string;
2
+ export declare function ensureMastraCodePackageLink(pluginDir: string): void;
3
+ //# sourceMappingURL=package-link.d.ts.map