@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,54 @@
1
+ // src/utils/local-observability.ts
2
+ /**
3
+ * Age limits for the local trace store: 14 days for spans, metrics and logs,
4
+ * 30 days for scores and feedback. Spans, logs and scores use the same windows
5
+ * as libsql's `DEFAULT_RETENTION`, which has no metrics or feedback entries.
6
+ */
7
+ const LOCAL_OBSERVABILITY_RETENTION = { observability: {
8
+ spans: { maxAge: "14d" },
9
+ metrics: { maxAge: "14d" },
10
+ logs: { maxAge: "14d" },
11
+ scores: { maxAge: "30d" },
12
+ feedback: { maxAge: "30d" }
13
+ } };
14
+ /** Upper bound on rows deleted per table per session, so startup pruning never runs long. */
15
+ const MAX_ROWS_PER_OPEN = 5e4;
16
+ const OBSERVABILITY_TABLES = [
17
+ "span_events",
18
+ "metric_events",
19
+ "log_events",
20
+ "score_events",
21
+ "feedback_events"
22
+ ];
23
+ /**
24
+ * Prune only when every observability table already exists. A brand-new file
25
+ * has no tables until the session composite runs init(), and pruning it would
26
+ * log a missing-table error from the storage layer for a file with nothing to delete.
27
+ */
28
+ async function pruneExistingTables(store) {
29
+ if ((await store.db.query(`SELECT table_name FROM information_schema.tables WHERE table_name IN (${OBSERVABILITY_TABLES.map(() => "?").join(", ")})`, OBSERVABILITY_TABLES)).length < OBSERVABILITY_TABLES.length) return [];
30
+ return store.prune({
31
+ maxRows: MAX_ROWS_PER_OPEN,
32
+ pauseMs: 10
33
+ });
34
+ }
35
+ /**
36
+ * Open the local observability DuckDB file used when `/observability local on`.
37
+ * Connects eagerly so a lock error surfaces now, not mid-session, then prunes
38
+ * aged events in the background so the file cannot grow without bound.
39
+ * `pruned` never rejects; anything left over is pruned on the next open.
40
+ */
41
+ async function openLocalObservabilityStore(path) {
42
+ const { DuckDBStore } = await import("@mastra/duckdb");
43
+ const store = new DuckDBStore({
44
+ id: "mastra-code-observability",
45
+ path,
46
+ retention: LOCAL_OBSERVABILITY_RETENTION
47
+ });
48
+ await store.db.query("SELECT 1");
49
+ return {
50
+ store,
51
+ pruned: pruneExistingTables(store).catch(() => [])
52
+ };
53
+ }
54
+ export { LOCAL_OBSERVABILITY_RETENTION, openLocalObservabilityStore };
@@ -0,0 +1,42 @@
1
+ export declare class MaintenanceLockError extends Error {
2
+ readonly ownerPids: number[];
3
+ constructor(message: string, ownerPids: number[]);
4
+ }
5
+ export declare function getMaintenanceLockPath(): string;
6
+ /** Owner of a lock whose pid file is still being written (PID not known yet). */
7
+ export declare const UNKNOWN_OWNER = -1;
8
+ /**
9
+ * Creating a pid file (open, then write) is not atomic, so an empty or
10
+ * unparseable file may belong to a process that is mid-write. Only treat it as
11
+ * stale once it is older than this.
12
+ */
13
+ export declare const MALFORMED_PID_FILE_GRACE_MS = 5000;
14
+ /**
15
+ * PID holding the maintenance lock, `UNKNOWN_OWNER` while its pid file is still
16
+ * being written, or null. Stale locks are removed.
17
+ */
18
+ export declare function getMaintenanceLockOwner(): number | null;
19
+ /** PIDs of other live registered sessions. Stale registrations are removed. */
20
+ export declare function getLiveSessionPids(): number[];
21
+ /** Test-only: drop every registration held by this process and forget lock ownership. */
22
+ export declare function resetSessionRegistrationsForTesting(): void;
23
+ /** Register one running session in this process. Pair with exactly one unregisterSession(). */
24
+ export declare function registerSession(): void;
25
+ /** Release one registration made by registerSession(). */
26
+ export declare function unregisterSession(): void;
27
+ /**
28
+ * Register this session, then wait for any running maintenance to finish.
29
+ * Waits indefinitely by default: a vacuum on a multi-GB database can take
30
+ * minutes. With `timeoutMs`, throws after that long naming the holder.
31
+ */
32
+ export declare function registerSessionAndWaitForMaintenance({ timeoutMs, pollMs, onWait, }?: {
33
+ timeoutMs?: number;
34
+ pollMs?: number;
35
+ onWait?: (ownerPid: number) => void;
36
+ }): Promise<void>;
37
+ /**
38
+ * Acquire the maintenance lock, then refuse if any mastracode session is live.
39
+ * Returns a release function.
40
+ */
41
+ export declare function acquireMaintenanceLock(): () => void;
42
+ //# sourceMappingURL=maintenance-lock.d.ts.map
@@ -0,0 +1,196 @@
1
+ import { getAppDataDir } from "./project.js";
2
+ import path from "path";
3
+ import fs from "fs";
4
+ // src/utils/maintenance-lock.ts
5
+ /**
6
+ * Mutual exclusion between storage maintenance (`mastracode prune`) and running
7
+ * mastracode sessions, using the same pid-file / stale-PID pattern as
8
+ * thread-lock.ts.
9
+ *
10
+ * - Every process that opens storage registers a session pid file.
11
+ * - `prune` holds `maintenance.lock` for its whole run.
12
+ *
13
+ * The checks are ordered so the race is closed both ways: `prune` acquires the
14
+ * lock and THEN looks for live sessions; a starter registers and THEN looks for
15
+ * the lock. Whichever acts second always sees the other.
16
+ */
17
+ var MaintenanceLockError = class extends Error {
18
+ ownerPids;
19
+ constructor(message, ownerPids) {
20
+ super(message);
21
+ this.ownerPids = ownerPids;
22
+ this.name = "MaintenanceLockError";
23
+ }
24
+ };
25
+ function getLocksDir() {
26
+ const dir = path.join(getAppDataDir(), "locks");
27
+ fs.mkdirSync(dir, { recursive: true });
28
+ return dir;
29
+ }
30
+ function getSessionsDir() {
31
+ const dir = path.join(getLocksDir(), "sessions");
32
+ fs.mkdirSync(dir, { recursive: true });
33
+ return dir;
34
+ }
35
+ function getMaintenanceLockPath() {
36
+ return path.join(getLocksDir(), "maintenance.lock");
37
+ }
38
+ /** Owner of a lock whose pid file is still being written (PID not known yet). */
39
+ const UNKNOWN_OWNER = -1;
40
+ /**
41
+ * Creating a pid file (open, then write) is not atomic, so an empty or
42
+ * unparseable file may belong to a process that is mid-write. Only treat it as
43
+ * stale once it is older than this.
44
+ */
45
+ const MALFORMED_PID_FILE_GRACE_MS = 5e3;
46
+ function isProcessAlive(pid) {
47
+ try {
48
+ process.kill(pid, 0);
49
+ return true;
50
+ } catch (error) {
51
+ return error.code !== "ESRCH";
52
+ }
53
+ }
54
+ /** Whether a pid file with no readable PID is old enough to reap. Missing files count as reapable. */
55
+ function isMalformedPidFileStale(file) {
56
+ try {
57
+ return Date.now() - fs.statSync(file).mtimeMs > MALFORMED_PID_FILE_GRACE_MS;
58
+ } catch {
59
+ return true;
60
+ }
61
+ }
62
+ function describeOwners(pids) {
63
+ const known = pids.filter((pid) => pid !== -1);
64
+ return known.length > 0 ? ` (PID ${known.join(", ")})` : "";
65
+ }
66
+ function readPid(file) {
67
+ try {
68
+ const pid = parseInt(fs.readFileSync(file, "utf-8").trim(), 10);
69
+ return isNaN(pid) ? null : pid;
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+ let lockHeld = false;
75
+ /**
76
+ * PID holding the maintenance lock, `UNKNOWN_OWNER` while its pid file is still
77
+ * being written, or null. Stale locks are removed.
78
+ */
79
+ function getMaintenanceLockOwner() {
80
+ const lockPath = getMaintenanceLockPath();
81
+ if (!fs.existsSync(lockPath)) return null;
82
+ const pid = readPid(lockPath);
83
+ if (pid === process.pid) {
84
+ if (lockHeld) return pid;
85
+ } else if (pid !== null && isProcessAlive(pid)) return pid;
86
+ if (pid === null && !isMalformedPidFileStale(lockPath)) return -1;
87
+ try {
88
+ fs.unlinkSync(lockPath);
89
+ } catch {}
90
+ return null;
91
+ }
92
+ /** PIDs of other live registered sessions. Stale registrations are removed. */
93
+ function getLiveSessionPids() {
94
+ const dir = getSessionsDir();
95
+ const live = [];
96
+ for (const file of fs.readdirSync(dir)) {
97
+ if (!file.endsWith(".pid")) continue;
98
+ const filePath = path.join(dir, file);
99
+ const pid = readPid(filePath);
100
+ if (pid === process.pid) continue;
101
+ if (pid !== null && isProcessAlive(pid)) live.push(pid);
102
+ else if (pid === null && !isMalformedPidFileStale(filePath)) live.push(-1);
103
+ else try {
104
+ fs.unlinkSync(filePath);
105
+ } catch {}
106
+ }
107
+ return live;
108
+ }
109
+ let sessionRefs = 0;
110
+ let exitHookInstalled = false;
111
+ /** Test-only: drop every registration held by this process and forget lock ownership. */
112
+ function resetSessionRegistrationsForTesting() {
113
+ while (sessionRefs > 0) unregisterSession();
114
+ lockHeld = false;
115
+ }
116
+ function getSessionPidPath() {
117
+ return path.join(getSessionsDir(), `${process.pid}.pid`);
118
+ }
119
+ function removeSessionPidFile() {
120
+ try {
121
+ fs.unlinkSync(getSessionPidPath());
122
+ } catch {}
123
+ }
124
+ /** Register one running session in this process. Pair with exactly one unregisterSession(). */
125
+ function registerSession() {
126
+ if (sessionRefs === 0) fs.writeFileSync(getSessionPidPath(), String(process.pid), { mode: 420 });
127
+ sessionRefs++;
128
+ if (!exitHookInstalled) {
129
+ exitHookInstalled = true;
130
+ process.once("exit", removeSessionPidFile);
131
+ }
132
+ }
133
+ /** Release one registration made by registerSession(). */
134
+ function unregisterSession() {
135
+ if (sessionRefs === 0) return;
136
+ sessionRefs--;
137
+ if (sessionRefs === 0) removeSessionPidFile();
138
+ }
139
+ /**
140
+ * Register this session, then wait for any running maintenance to finish.
141
+ * Waits indefinitely by default: a vacuum on a multi-GB database can take
142
+ * minutes. With `timeoutMs`, throws after that long naming the holder.
143
+ */
144
+ async function registerSessionAndWaitForMaintenance({ timeoutMs = Infinity, pollMs = 250, onWait } = {}) {
145
+ registerSession();
146
+ const deadline = Date.now() + timeoutMs;
147
+ let notified = false;
148
+ for (;;) {
149
+ const owner = getMaintenanceLockOwner();
150
+ if (owner === null) return;
151
+ if (!notified) {
152
+ notified = true;
153
+ onWait?.(owner);
154
+ }
155
+ if (Date.now() >= deadline) {
156
+ unregisterSession();
157
+ throw new MaintenanceLockError(`Storage maintenance (mastracode prune${describeOwners([owner])}) is still running after ${Math.round(timeoutMs / 1e3)}s. Wait for it to finish, or stop it, then start mastracode again.`, [owner]);
158
+ }
159
+ await new Promise((resolve) => setTimeout(resolve, pollMs));
160
+ }
161
+ }
162
+ /**
163
+ * Acquire the maintenance lock, then refuse if any mastracode session is live.
164
+ * Returns a release function.
165
+ */
166
+ function acquireMaintenanceLock() {
167
+ const lockPath = getMaintenanceLockPath();
168
+ for (let attempt = 0;; attempt++) try {
169
+ fs.writeFileSync(lockPath, String(process.pid), {
170
+ flag: "wx",
171
+ mode: 420
172
+ });
173
+ lockHeld = true;
174
+ break;
175
+ } catch (error) {
176
+ if (error.code !== "EEXIST") throw error;
177
+ const owner = getMaintenanceLockOwner();
178
+ if (owner !== null || attempt > 0) throw new MaintenanceLockError(`Another mastracode prune is already running${owner === null ? "" : describeOwners([owner])}.`, owner === null ? [] : [owner]);
179
+ }
180
+ let released = false;
181
+ const release = () => {
182
+ if (released) return;
183
+ released = true;
184
+ lockHeld = false;
185
+ if (readPid(lockPath) === process.pid) try {
186
+ fs.unlinkSync(lockPath);
187
+ } catch {}
188
+ };
189
+ const sessions = getLiveSessionPids();
190
+ if (sessions.length > 0) {
191
+ release();
192
+ throw new MaintenanceLockError(`mastracode is running${describeOwners(sessions)}. Exit every mastracode session before running prune.`, sessions);
193
+ }
194
+ return release;
195
+ }
196
+ export { MALFORMED_PID_FILE_GRACE_MS, MaintenanceLockError, UNKNOWN_OWNER, acquireMaintenanceLock, getLiveSessionPids, getMaintenanceLockOwner, getMaintenanceLockPath, registerSession, registerSessionAndWaitForMaintenance, resetSessionRegistrationsForTesting, unregisterSession };
@@ -0,0 +1,74 @@
1
+ import type { LeaseProvider } from '@mastra/core/events';
2
+ import type { Mastra } from '@mastra/core/mastra';
3
+ /**
4
+ * Whether this call runs inside this process's own dispatch pass for
5
+ * `resourceId`, holding the lease for threads of `scope` (or with no `scope`,
6
+ * for threads that carry none), as opposed to the dispatch schedule every
7
+ * process sharing the database takes turns running.
8
+ */
9
+ export declare function isDispatchingNotificationsFor(resourceId: string, scope?: string): boolean;
10
+ /**
11
+ * Whether a delivery-time policy should leave a due notification pending
12
+ * (`hold`). Deliveries happen from this process's own dispatch pass for the
13
+ * record's resource, under the lease that covers the record's thread. Anything
14
+ * else holds: a thread no session here owns belongs to another process sharing
15
+ * the database, and once this process's dispatcher runs, its own resources are
16
+ * delivered by whichever process holds their dispatch lease, never by the
17
+ * shared dispatch schedule.
18
+ */
19
+ export declare function shouldHoldNotificationDelivery({ resourceId, scope, ownedHere, dispatcher, }: {
20
+ resourceId: string;
21
+ /** The thread's scope (`WakeSession.scope`), unset for a thread that carries none. */
22
+ scope?: string;
23
+ /** Whether a session in this process owns the resource. */
24
+ ownedHere: boolean;
25
+ dispatcher: {
26
+ readonly running: boolean;
27
+ };
28
+ }): boolean;
29
+ type SessionScope = {
30
+ resourceId: string;
31
+ scope?: string;
32
+ };
33
+ export type ResourceNotificationDispatcherOptions = {
34
+ getMastra: () => Mastra | undefined;
35
+ /**
36
+ * The resources this process runs sessions for, each with the thread scope
37
+ * (`threadScopeKey`) of a session serving it, unset when it has none.
38
+ */
39
+ getSessionScopes: () => Iterable<SessionScope> | Promise<Iterable<SessionScope>>;
40
+ /**
41
+ * Cross-process leases. When set, a resource's notifications are dispatched
42
+ * only by the processes holding its dispatch leases, so two processes
43
+ * serving the same resource never both deliver one: the threads of each
44
+ * scope (each project, for processes in different directories) go to the
45
+ * process holding that scope's lease, and threads with no scope to the one
46
+ * holding the resource's own.
47
+ */
48
+ leases?: LeaseProvider;
49
+ /** Unique to this process. */
50
+ owner: string;
51
+ intervalMs?: number;
52
+ leaseTtlMs?: number;
53
+ onError?: (error: unknown) => void;
54
+ };
55
+ /**
56
+ * Delivers the due notifications of the resources this process serves, on a
57
+ * timer of its own.
58
+ *
59
+ * Every Mastra Code process shares one database, so one notification store and
60
+ * one dispatch schedule, and the scheduler gives each fire to whichever process
61
+ * claims it first, usually the same one for as long as it runs. That process
62
+ * cannot run another project's thread, so its delivery policy holds those
63
+ * records. Each process therefore dispatches its own resources here.
64
+ */
65
+ export declare function createResourceNotificationDispatcher(options: ResourceNotificationDispatcherOptions): {
66
+ readonly running: boolean;
67
+ start(): void;
68
+ stop(): Promise<void>;
69
+ /** Runs one dispatch pass now. Only dispatches while started. */
70
+ tick: () => Promise<void>;
71
+ };
72
+ export type ResourceNotificationDispatcher = ReturnType<typeof createResourceNotificationDispatcher>;
73
+ export {};
74
+ //# sourceMappingURL=notification-dispatch.d.ts.map
@@ -0,0 +1,128 @@
1
+ import { notificationDispatchLeaseKey } from "./signals-pubsub.js";
2
+ import { dispatchDueNotifications } from "@mastra/core/notifications";
3
+ import { AsyncLocalStorage } from "async_hooks";
4
+ // src/utils/notification-dispatch.ts
5
+ const DEFAULT_INTERVAL_MS = 1e4;
6
+ const DEFAULT_LEASE_TTL_MS = 6e4;
7
+ /**
8
+ * The resource the current async context is dispatching notifications for,
9
+ * and which of its dispatch leases this pass holds.
10
+ */
11
+ const dispatching = new AsyncLocalStorage();
12
+ /**
13
+ * Whether this call runs inside this process's own dispatch pass for
14
+ * `resourceId`, holding the lease for threads of `scope` (or with no `scope`,
15
+ * for threads that carry none), as opposed to the dispatch schedule every
16
+ * process sharing the database takes turns running.
17
+ */
18
+ function isDispatchingNotificationsFor(resourceId, scope) {
19
+ const pass = dispatching.getStore();
20
+ if (pass?.resourceId !== resourceId) return false;
21
+ return scope === void 0 ? pass.unscoped : pass.scopes.has(scope);
22
+ }
23
+ /**
24
+ * Whether a delivery-time policy should leave a due notification pending
25
+ * (`hold`). Deliveries happen from this process's own dispatch pass for the
26
+ * record's resource, under the lease that covers the record's thread. Anything
27
+ * else holds: a thread no session here owns belongs to another process sharing
28
+ * the database, and once this process's dispatcher runs, its own resources are
29
+ * delivered by whichever process holds their dispatch lease, never by the
30
+ * shared dispatch schedule.
31
+ */
32
+ function shouldHoldNotificationDelivery({ resourceId, scope, ownedHere, dispatcher }) {
33
+ if (isDispatchingNotificationsFor(resourceId, scope)) return false;
34
+ return !ownedHere || dispatcher.running;
35
+ }
36
+ /**
37
+ * Delivers the due notifications of the resources this process serves, on a
38
+ * timer of its own.
39
+ *
40
+ * Every Mastra Code process shares one database, so one notification store and
41
+ * one dispatch schedule, and the scheduler gives each fire to whichever process
42
+ * claims it first, usually the same one for as long as it runs. That process
43
+ * cannot run another project's thread, so its delivery policy holds those
44
+ * records. Each process therefore dispatches its own resources here.
45
+ */
46
+ function createResourceNotificationDispatcher(options) {
47
+ const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
48
+ const leaseTtlMs = options.leaseTtlMs ?? DEFAULT_LEASE_TTL_MS;
49
+ /** The dispatch lease keys this process holds. */
50
+ const held = /* @__PURE__ */ new Set();
51
+ let timer;
52
+ let ticking;
53
+ const release = async (key) => {
54
+ held.delete(key);
55
+ await options.leases?.releaseLease(key, options.owner).catch(options.onError);
56
+ };
57
+ const claim = async (key) => {
58
+ if (!options.leases) return true;
59
+ try {
60
+ const { acquired } = await options.leases.acquireLease(key, options.owner, leaseTtlMs);
61
+ if (acquired) held.add(key);
62
+ else held.delete(key);
63
+ return acquired;
64
+ } catch (error) {
65
+ options.onError?.(error);
66
+ return false;
67
+ }
68
+ };
69
+ const runTick = async () => {
70
+ const mastra = options.getMastra();
71
+ const storage = await mastra?.getStorage()?.getStore("notifications");
72
+ if (!mastra || !storage) return;
73
+ const scopesByResource = /* @__PURE__ */ new Map();
74
+ for (const { resourceId, scope } of await options.getSessionScopes()) {
75
+ const scopes = scopesByResource.get(resourceId) ?? /* @__PURE__ */ new Set();
76
+ if (scope !== void 0) scopes.add(scope);
77
+ scopesByResource.set(resourceId, scopes);
78
+ }
79
+ const wanted = new Set([...scopesByResource].flatMap(([resourceId, scopes]) => [notificationDispatchLeaseKey(resourceId), ...[...scopes].map((scope) => notificationDispatchLeaseKey(resourceId, scope))]));
80
+ for (const key of [...held]) if (!wanted.has(key)) await release(key);
81
+ for (const [resourceId, scopes] of scopesByResource) {
82
+ if (!timer) continue;
83
+ const unscoped = await claim(notificationDispatchLeaseKey(resourceId));
84
+ const heldScopes = /* @__PURE__ */ new Set();
85
+ for (const scope of scopes) if (await claim(notificationDispatchLeaseKey(resourceId, scope))) heldScopes.add(scope);
86
+ if (!unscoped && heldScopes.size === 0) continue;
87
+ try {
88
+ await dispatching.run({
89
+ resourceId,
90
+ unscoped,
91
+ scopes: heldScopes
92
+ }, () => dispatchDueNotifications({
93
+ mastra,
94
+ storage,
95
+ resourceId
96
+ }));
97
+ } catch (error) {
98
+ options.onError?.(error);
99
+ }
100
+ }
101
+ };
102
+ const tick = () => {
103
+ ticking ??= runTick().catch((error) => options.onError?.(error)).finally(() => {
104
+ ticking = void 0;
105
+ });
106
+ return ticking;
107
+ };
108
+ return {
109
+ get running() {
110
+ return timer !== void 0;
111
+ },
112
+ start() {
113
+ if (timer) return;
114
+ timer = setInterval(() => void tick(), intervalMs);
115
+ timer.unref?.();
116
+ tick();
117
+ },
118
+ async stop() {
119
+ if (timer) clearInterval(timer);
120
+ timer = void 0;
121
+ await ticking;
122
+ await Promise.all([...held].map(release));
123
+ },
124
+ /** Runs one dispatch pass now. Only dispatches while started. */
125
+ tick
126
+ };
127
+ }
128
+ export { createResourceNotificationDispatcher, isDispatchingNotificationsFor, shouldHoldNotificationDelivery };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Best-effort browser opening for OAuth and other login flows.
3
+ */
4
+ /**
5
+ * Open a URL in the default browser without going through a shell.
6
+ * Only well-formed http(s) URLs are opened; anything else is ignored
7
+ * (the URL is still displayed for the user to open manually).
8
+ */
9
+ export declare function openUrlInBrowser(url: string): void;
10
+ //# sourceMappingURL=open-url.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { spawn } from "child_process";
2
+ // src/utils/open-url.ts
3
+ /**
4
+ * Best-effort browser opening for OAuth and other login flows.
5
+ */
6
+ /**
7
+ * Open a URL in the default browser without going through a shell.
8
+ * Only well-formed http(s) URLs are opened; anything else is ignored
9
+ * (the URL is still displayed for the user to open manually).
10
+ */
11
+ function openUrlInBrowser(url) {
12
+ let parsed;
13
+ try {
14
+ parsed = new URL(url);
15
+ } catch {
16
+ return;
17
+ }
18
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return;
19
+ const [cmd, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", url]] : ["xdg-open", [url]];
20
+ const child = spawn(cmd, args, {
21
+ stdio: "ignore",
22
+ detached: true
23
+ });
24
+ child.on("error", () => {});
25
+ child.unref();
26
+ }
27
+ export { openUrlInBrowser };
@@ -0,0 +1,2 @@
1
+ export declare function isPathWithinRoot(candidatePath: string, rootPath: string): boolean;
2
+ //# sourceMappingURL=path-security.d.ts.map
@@ -0,0 +1,7 @@
1
+ import path from "path";
2
+ // src/utils/path-security.ts
3
+ function isPathWithinRoot(candidatePath, rootPath) {
4
+ const relativePath = path.relative(rootPath, candidatePath);
5
+ return relativePath === "" || !relativePath.startsWith(`..${path.sep}`) && relativePath !== ".." && !path.isAbsolute(relativePath);
6
+ }
7
+ export { isPathWithinRoot };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Line-level diffing for plan revisions.
3
+ *
4
+ * Uses a real LCS (longest common subsequence) diff so that inserting or deleting a few
5
+ * lines doesn't mark everything after it as changed. Both the rendered approval diff and
6
+ * the "is a diff worth showing" heuristic share this so the heuristic measures the actual
7
+ * diff rather than predicting one.
8
+ */
9
+ export interface DiffEntry {
10
+ type: 'added' | 'removed' | 'context';
11
+ text: string;
12
+ }
13
+ /** Produce structured diff entries between two plan texts using an LCS diff. */
14
+ export declare function generatePlanDiff(oldText: string, newText: string): DiffEntry[];
15
+ /**
16
+ * Decide whether a diff is worth rendering instead of just showing the full new plan.
17
+ *
18
+ * We generate the real diff and compare its size (added + removed lines) against the size
19
+ * of the whole diff (added + removed + unchanged context). When most of the diff is changes
20
+ * rather than shared context, the diff is no clearer than the full text, so callers fall
21
+ * back to rendering the whole plan. A genuinely new plan (no previous text, or no shared
22
+ * lines) is therefore shown in full.
23
+ */
24
+ export declare function shouldShowDiff(previousPlan: string, plan: string, maxChangedRatio?: number): boolean;
25
+ //# sourceMappingURL=plan-diff.d.ts.map
@@ -0,0 +1,59 @@
1
+ // src/utils/plan-diff.ts
2
+ /** Produce structured diff entries between two plan texts using an LCS diff. */
3
+ function generatePlanDiff(oldText, newText) {
4
+ const oldLines = oldText.split(/\r?\n/);
5
+ const newLines = newText.split(/\r?\n/);
6
+ const n = oldLines.length;
7
+ const m = newLines.length;
8
+ const lcs = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
9
+ for (let i = n - 1; i >= 0; i--) for (let j = m - 1; j >= 0; j--) lcs[i][j] = oldLines[i] === newLines[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
10
+ const entries = [];
11
+ let i = 0;
12
+ let j = 0;
13
+ while (i < n && j < m) if (oldLines[i] === newLines[j]) {
14
+ entries.push({
15
+ type: "context",
16
+ text: oldLines[i]
17
+ });
18
+ i++;
19
+ j++;
20
+ } else if (lcs[i + 1][j] >= lcs[i][j + 1]) {
21
+ entries.push({
22
+ type: "removed",
23
+ text: oldLines[i]
24
+ });
25
+ i++;
26
+ } else {
27
+ entries.push({
28
+ type: "added",
29
+ text: newLines[j]
30
+ });
31
+ j++;
32
+ }
33
+ while (i < n) entries.push({
34
+ type: "removed",
35
+ text: oldLines[i++]
36
+ });
37
+ while (j < m) entries.push({
38
+ type: "added",
39
+ text: newLines[j++]
40
+ });
41
+ return entries;
42
+ }
43
+ /**
44
+ * Decide whether a diff is worth rendering instead of just showing the full new plan.
45
+ *
46
+ * We generate the real diff and compare its size (added + removed lines) against the size
47
+ * of the whole diff (added + removed + unchanged context). When most of the diff is changes
48
+ * rather than shared context, the diff is no clearer than the full text, so callers fall
49
+ * back to rendering the whole plan. A genuinely new plan (no previous text, or no shared
50
+ * lines) is therefore shown in full.
51
+ */
52
+ function shouldShowDiff(previousPlan, plan, maxChangedRatio = .5) {
53
+ if (!previousPlan || previousPlan === plan) return false;
54
+ const entries = generatePlanDiff(previousPlan, plan);
55
+ const changed = entries.filter((e) => e.type !== "context").length;
56
+ if (changed === 0) return false;
57
+ return changed / Math.max(entries.length, 1) <= maxChangedRatio;
58
+ }
59
+ export { generatePlanDiff, shouldShowDiff };