@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,617 @@
1
+ import { DEFAULT_CONFIG_DIR } from "../../constants.js";
2
+ import { dirname, isAbsolute, join, normalize, relative, resolve, sep } from "path";
3
+ import { createHash } from "crypto";
4
+ import { existsSync, readFileSync, realpathSync, statSync } from "fs";
5
+ import { execFileSync, spawn } from "child_process";
6
+ import { homedir } from "os";
7
+ import { readFile, realpath, stat } from "fs/promises";
8
+ // src/agents/prompts/agent-instructions.ts
9
+ /**
10
+ * Load project and global agent instruction files (AGENTS.md, CLAUDE.md).
11
+ * Prefers AGENTS.md over CLAUDE.md when multiple exist at the same location.
12
+ */
13
+ const INSTRUCTION_FILES = ["AGENTS.md", "CLAUDE.md"];
14
+ const PROJECT_LOCATIONS = [
15
+ "",
16
+ ".claude",
17
+ ".mastracode"
18
+ ];
19
+ const GLOBAL_LOCATIONS = [
20
+ ".claude",
21
+ ".mastracode",
22
+ ".config/claude",
23
+ ".config/mastracode"
24
+ ];
25
+ const fsInstructionReader = {
26
+ exists: (path) => existsSync(path),
27
+ read: (path) => readFileSync(path, "utf-8")
28
+ };
29
+ function realpathOrResolved(path) {
30
+ try {
31
+ return realpathSync(path);
32
+ } catch {
33
+ return resolve(path);
34
+ }
35
+ }
36
+ function createProjectPathResolver(projectPath) {
37
+ const canonicalRoot = realpathOrResolved(projectPath);
38
+ return (path) => {
39
+ const rel = relative(projectPath, path);
40
+ if (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)) return rel.split(sep).join("/");
41
+ let ancestor = resolve(path);
42
+ let projectRelativePath = null;
43
+ while (true) {
44
+ if (realpathOrResolved(ancestor) === canonicalRoot) projectRelativePath = relative(ancestor, path).split(sep).join("/");
45
+ const parent = dirname(ancestor);
46
+ if (parent === ancestor) return projectRelativePath;
47
+ ancestor = parent;
48
+ }
49
+ };
50
+ }
51
+ const GIT_OBJECT_CACHE_MAX_CHARS = 16777216;
52
+ const gitObjectOutputs = /* @__PURE__ */ new Map();
53
+ let gitObjectCacheChars = 0;
54
+ function gitObjectRead(projectPath, args, matchesId = () => true) {
55
+ const key = args.join("\0");
56
+ const cached = gitObjectOutputs.get(key);
57
+ if (cached !== void 0) return cached;
58
+ try {
59
+ const raw = execFileSync("git", [
60
+ "--no-replace-objects",
61
+ "-C",
62
+ projectPath,
63
+ "--literal-pathspecs",
64
+ ...args
65
+ ], {
66
+ stdio: [
67
+ "ignore",
68
+ "pipe",
69
+ "ignore"
70
+ ],
71
+ maxBuffer: 1048576
72
+ });
73
+ if (!matchesId(raw)) return null;
74
+ const output = raw.toString("utf-8");
75
+ gitObjectOutputs.set(key, output);
76
+ gitObjectCacheChars += key.length + output.length;
77
+ for (const [oldest, evicted] of gitObjectOutputs) {
78
+ if (gitObjectCacheChars <= GIT_OBJECT_CACHE_MAX_CHARS) break;
79
+ gitObjectOutputs.delete(oldest);
80
+ gitObjectCacheChars -= oldest.length + evicted.length;
81
+ }
82
+ return output;
83
+ } catch {
84
+ return null;
85
+ }
86
+ }
87
+ function blobMatchesId(id, content) {
88
+ return createHash(id.length === 40 ? "sha1" : "sha256").update(`blob ${content.length}\0`).update(content).digest("hex") === id;
89
+ }
90
+ function createGitRefLookup(projectPath, ref) {
91
+ let trees;
92
+ const resolveTrees = () => {
93
+ if ([...ref].some((char) => char <= " " || char === "")) return [];
94
+ try {
95
+ const output = execFileSync("git", [
96
+ "-C",
97
+ projectPath,
98
+ "cat-file",
99
+ "--batch-check=%(objectname)"
100
+ ], {
101
+ encoding: "utf-8",
102
+ input: `origin/${ref}^{tree}\n${ref}^{tree}\n`,
103
+ stdio: [
104
+ "pipe",
105
+ "pipe",
106
+ "ignore"
107
+ ]
108
+ });
109
+ return [...new Set(output.split("\n").filter((line) => /^[0-9a-f]+$/.test(line)))];
110
+ } catch {
111
+ return [];
112
+ }
113
+ };
114
+ const entryAt = (tree, rel) => {
115
+ let entry = [
116
+ "",
117
+ "tree",
118
+ tree
119
+ ];
120
+ for (const name of rel.split("/")) {
121
+ if (entry[1] !== "tree") return [];
122
+ entry = gitObjectRead(projectPath, [
123
+ "ls-tree",
124
+ "--full-tree",
125
+ entry[2],
126
+ "--",
127
+ name
128
+ ])?.split(/\s/) ?? [];
129
+ }
130
+ return entry;
131
+ };
132
+ return {
133
+ type: (rel) => {
134
+ for (const tree of trees ??= resolveTrees()) {
135
+ const [, type] = entryAt(tree, rel);
136
+ if (type) return type;
137
+ }
138
+ return null;
139
+ },
140
+ show: (rel) => {
141
+ for (const tree of trees ??= resolveTrees()) {
142
+ const [, type, blob] = entryAt(tree, rel);
143
+ if (type !== "blob" || !blob) continue;
144
+ const content = gitObjectRead(projectPath, [
145
+ "cat-file",
146
+ "blob",
147
+ blob
148
+ ], (raw) => blobMatchesId(blob, raw));
149
+ if (content !== null) return content;
150
+ }
151
+ return null;
152
+ }
153
+ };
154
+ }
155
+ /**
156
+ * Create a reader that serves instruction files from a git ref instead of the
157
+ * working tree. Paths are still addressed as working-tree paths under
158
+ * `projectPath`; content comes from the blob at `<ref>:<relpath>` so an untrusted
159
+ * checkout (e.g. a PR branch under review) cannot influence what is loaded.
160
+ * Tries `origin/<ref>` first (remote truth), then the local ref. Any git
161
+ * failure (missing ref, missing file, no repo) reports the file as absent.
162
+ */
163
+ function createGitRefInstructionReader(projectPath, ref) {
164
+ const toRelative = createProjectPathResolver(projectPath);
165
+ const lookup = createGitRefLookup(projectPath, ref);
166
+ const show = (path) => {
167
+ const rel = toRelative(path);
168
+ return rel ? lookup.show(rel) : null;
169
+ };
170
+ return {
171
+ ref,
172
+ exists: (path) => show(path) !== null,
173
+ read: (path) => {
174
+ const content = show(path);
175
+ if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);
176
+ return content;
177
+ }
178
+ };
179
+ }
180
+ /**
181
+ * Reader for the reactive reminder channel (AgentsMDInjector) that serves
182
+ * paths under `projectPath` from a trusted git ref. Paths outside the project
183
+ * fall back to the operator machine's filesystem (those are trusted); paths
184
+ * inside the project are only ever resolved against the ref, never the
185
+ * working tree, so an untrusted checkout cannot feed content in.
186
+ */
187
+ function createGitRefReminderReader(projectPath, ref) {
188
+ const toRelative = createProjectPathResolver(projectPath);
189
+ const canonicalRoot = realpathOrResolved(projectPath);
190
+ const lookup = createGitRefLookup(projectPath, ref);
191
+ const objectType = (rel) => {
192
+ if (rel === "") return "tree";
193
+ return lookup.type(rel);
194
+ };
195
+ return {
196
+ pathExists: (path) => {
197
+ const rel = toRelative(path);
198
+ if (rel === null) return existsSync(path);
199
+ return objectType(rel) !== null;
200
+ },
201
+ isDirectory: (path) => {
202
+ const rel = toRelative(path);
203
+ if (rel === null) try {
204
+ return statSync(path).isDirectory();
205
+ } catch {
206
+ return false;
207
+ }
208
+ return objectType(rel) === "tree";
209
+ },
210
+ readFile: (path) => {
211
+ const rel = toRelative(path);
212
+ if (rel === null) return readFileSync(path, "utf-8");
213
+ const content = rel ? lookup.show(rel) : null;
214
+ if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);
215
+ return content;
216
+ },
217
+ getPathIdentity: (path) => {
218
+ const rel = toRelative(path);
219
+ return rel === null ? realpathOrResolved(path) : join(canonicalRoot, rel);
220
+ }
221
+ };
222
+ }
223
+ const pendingGitObjects = /* @__PURE__ */ new Map();
224
+ function gitAsync(args, input) {
225
+ return new Promise((resolveOutput) => {
226
+ let child;
227
+ try {
228
+ child = spawn("git", args, { stdio: [
229
+ input === void 0 ? "ignore" : "pipe",
230
+ "pipe",
231
+ "ignore"
232
+ ] });
233
+ } catch {
234
+ resolveOutput(null);
235
+ return;
236
+ }
237
+ const chunks = [];
238
+ let size = 0;
239
+ let failed = false;
240
+ child.stdout?.on("data", (chunk) => {
241
+ size += chunk.length;
242
+ if (size > 1048576) {
243
+ failed = true;
244
+ child.kill();
245
+ } else chunks.push(chunk);
246
+ });
247
+ child.on("error", () => {
248
+ failed = true;
249
+ });
250
+ child.on("close", (code) => resolveOutput(!failed && code === 0 ? Buffer.concat(chunks) : null));
251
+ if (input !== void 0) {
252
+ child.stdin?.on("error", () => {
253
+ failed = true;
254
+ });
255
+ child.stdin?.end(input);
256
+ }
257
+ });
258
+ }
259
+ async function gitObjectReadAsync(projectPath, args, matchesId = () => true) {
260
+ const key = args.join("\0");
261
+ const cached = gitObjectOutputs.get(key);
262
+ if (cached !== void 0) return cached;
263
+ const pendingKey = `${projectPath}\0${key}`;
264
+ let pending = pendingGitObjects.get(pendingKey);
265
+ if (!pending) {
266
+ pending = (async () => {
267
+ const raw = await gitAsync([
268
+ "--no-replace-objects",
269
+ "-C",
270
+ projectPath,
271
+ "--literal-pathspecs",
272
+ ...args
273
+ ]);
274
+ if (!raw || !matchesId(raw)) return null;
275
+ const output = raw.toString("utf-8");
276
+ gitObjectOutputs.set(key, output);
277
+ gitObjectCacheChars += key.length + output.length;
278
+ for (const [oldest, evicted] of gitObjectOutputs) {
279
+ if (gitObjectCacheChars <= GIT_OBJECT_CACHE_MAX_CHARS) break;
280
+ gitObjectOutputs.delete(oldest);
281
+ gitObjectCacheChars -= oldest.length + evicted.length;
282
+ }
283
+ return output;
284
+ })();
285
+ pendingGitObjects.set(pendingKey, pending);
286
+ pending.then(() => pendingGitObjects.delete(pendingKey), () => pendingGitObjects.delete(pendingKey));
287
+ }
288
+ return pending;
289
+ }
290
+ async function realpathOrResolvedAsync(path) {
291
+ try {
292
+ return await realpath(path);
293
+ } catch {
294
+ return resolve(path);
295
+ }
296
+ }
297
+ async function createProjectPathResolverAsync(projectPath) {
298
+ const canonicalRoot = await realpathOrResolvedAsync(projectPath);
299
+ return async (path) => {
300
+ const rel = relative(projectPath, path);
301
+ if (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)) return rel.split(sep).join("/");
302
+ let ancestor = resolve(path);
303
+ let projectRelativePath = null;
304
+ while (true) {
305
+ if (await realpathOrResolvedAsync(ancestor) === canonicalRoot) projectRelativePath = relative(ancestor, path).split(sep).join("/");
306
+ const parent = dirname(ancestor);
307
+ if (parent === ancestor) return projectRelativePath;
308
+ ancestor = parent;
309
+ }
310
+ };
311
+ }
312
+ function createGitRefLookupAsync(projectPath, ref) {
313
+ let trees;
314
+ const resolveTrees = async () => {
315
+ if ([...ref].some((char) => char <= " " || char === "")) return [];
316
+ const raw = await gitAsync([
317
+ "-C",
318
+ projectPath,
319
+ "cat-file",
320
+ "--batch-check=%(objectname)"
321
+ ], `origin/${ref}^{tree}\n${ref}^{tree}\n`);
322
+ return raw ? [...new Set(raw.toString("utf-8").split("\n").filter((line) => /^[0-9a-f]+$/.test(line)))] : [];
323
+ };
324
+ const entryAt = async (tree, rel) => {
325
+ let entry = [
326
+ "",
327
+ "tree",
328
+ tree
329
+ ];
330
+ for (const name of rel.split("/")) {
331
+ if (entry[1] !== "tree") return [];
332
+ entry = (await gitObjectReadAsync(projectPath, [
333
+ "ls-tree",
334
+ "--full-tree",
335
+ entry[2],
336
+ "--",
337
+ name
338
+ ]))?.split(/\s/) ?? [];
339
+ }
340
+ return entry;
341
+ };
342
+ return {
343
+ type: async (rel) => {
344
+ for (const tree of await (trees ??= resolveTrees())) {
345
+ const [, type] = await entryAt(tree, rel);
346
+ if (type) return type;
347
+ }
348
+ return null;
349
+ },
350
+ show: async (rel) => {
351
+ for (const tree of await (trees ??= resolveTrees())) {
352
+ const [, type, blob] = await entryAt(tree, rel);
353
+ if (type !== "blob" || !blob) continue;
354
+ const content = await gitObjectReadAsync(projectPath, [
355
+ "cat-file",
356
+ "blob",
357
+ blob
358
+ ], (raw) => blobMatchesId(blob, raw));
359
+ if (content !== null) return content;
360
+ }
361
+ return null;
362
+ }
363
+ };
364
+ }
365
+ async function createGitRefInstructionReaderAsync(projectPath, ref) {
366
+ const toRelative = await createProjectPathResolverAsync(projectPath);
367
+ const lookup = createGitRefLookupAsync(projectPath, ref);
368
+ const show = async (path) => {
369
+ const rel = await toRelative(path);
370
+ return rel ? lookup.show(rel) : null;
371
+ };
372
+ return {
373
+ ref,
374
+ exists: async (path) => await show(path) !== null,
375
+ read: async (path) => {
376
+ const content = await show(path);
377
+ if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);
378
+ return content;
379
+ }
380
+ };
381
+ }
382
+ function createGitRefReminderReaderAsync(projectPath, ref) {
383
+ const toRelative = createProjectPathResolverAsync(projectPath);
384
+ const canonicalRoot = realpathOrResolvedAsync(projectPath);
385
+ const lookup = createGitRefLookupAsync(projectPath, ref);
386
+ const objectType = (rel) => rel === "" ? Promise.resolve("tree") : lookup.type(rel);
387
+ return {
388
+ pathExists: async (path) => {
389
+ const rel = await (await toRelative)(path);
390
+ if (rel === null) try {
391
+ await stat(path);
392
+ return true;
393
+ } catch {
394
+ return false;
395
+ }
396
+ return await objectType(rel) !== null;
397
+ },
398
+ isDirectory: async (path) => {
399
+ const rel = await (await toRelative)(path);
400
+ if (rel === null) try {
401
+ return (await stat(path)).isDirectory();
402
+ } catch {
403
+ return false;
404
+ }
405
+ return await objectType(rel) === "tree";
406
+ },
407
+ readFile: async (path) => {
408
+ const rel = await (await toRelative)(path);
409
+ if (rel === null) return readFile(path, "utf-8");
410
+ const content = rel ? await lookup.show(rel) : null;
411
+ if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);
412
+ return content;
413
+ },
414
+ getPathIdentity: async (path) => {
415
+ const rel = await (await toRelative)(path);
416
+ return rel === null ? realpathOrResolvedAsync(path) : join(await canonicalRoot, rel);
417
+ }
418
+ };
419
+ }
420
+ const fsInstructionReaderAsync = {
421
+ exists: async (path) => {
422
+ try {
423
+ await stat(path);
424
+ return true;
425
+ } catch {
426
+ return false;
427
+ }
428
+ },
429
+ read: (path) => readFile(path, "utf-8")
430
+ };
431
+ async function loadAgentInstructionsAsync(projectPath, configDirName = DEFAULT_CONFIG_DIR, projectReader = fsInstructionReaderAsync, { skipGlobal = false } = {}) {
432
+ const sources = [];
433
+ const projectLocations = PROJECT_LOCATIONS.map((loc) => loc === ".mastracode" ? configDirName : loc);
434
+ const globalLocations = skipGlobal ? [] : GLOBAL_LOCATIONS.map((loc) => {
435
+ if (loc === ".mastracode") return configDirName;
436
+ if (loc === ".config/mastracode") return ".config/" + configDirName.replace(/^\./, "");
437
+ return loc;
438
+ });
439
+ for (const location of globalLocations) {
440
+ const base = join(homedir(), location);
441
+ for (const filename of INSTRUCTION_FILES) {
442
+ const path = join(base, filename);
443
+ if (!await fsInstructionReaderAsync.exists(path)) continue;
444
+ try {
445
+ const content = (await fsInstructionReaderAsync.read(path)).trim();
446
+ if (content) {
447
+ sources.push({
448
+ path,
449
+ content,
450
+ scope: "global"
451
+ });
452
+ break;
453
+ }
454
+ } catch {}
455
+ break;
456
+ }
457
+ if (sources.length) break;
458
+ }
459
+ for (const location of projectLocations) {
460
+ const base = location ? join(projectPath, location) : projectPath;
461
+ for (const filename of INSTRUCTION_FILES) {
462
+ const path = join(base, filename);
463
+ if (!await projectReader.exists(path)) continue;
464
+ try {
465
+ const content = (await projectReader.read(path)).trim();
466
+ if (content) {
467
+ sources.push({
468
+ path,
469
+ content,
470
+ scope: "project",
471
+ ...projectReader.ref ? { ref: projectReader.ref } : {}
472
+ });
473
+ break;
474
+ }
475
+ } catch {}
476
+ break;
477
+ }
478
+ if (sources.some((source) => source.scope === "project")) break;
479
+ }
480
+ return sources;
481
+ }
482
+ async function loadSessionInstructionsAsync({ workingDir, instructionRoots, configDir, untrustedCheckout = false, baseRef, skipGlobal = false }) {
483
+ const [primary, ...others] = sessionInstructionRoots(workingDir, instructionRoots);
484
+ const sources = await loadAgentInstructionsAsync(primary, configDir, untrustedCheckout ? baseRef ? await createGitRefInstructionReaderAsync(primary, baseRef) : {
485
+ exists: async () => false,
486
+ read: async () => ""
487
+ } : void 0, { skipGlobal });
488
+ if (!untrustedCheckout) for (const root of others) sources.push(...await loadAgentInstructionsAsync(root, configDir, void 0, { skipGlobal: true }));
489
+ return sources;
490
+ }
491
+ /**
492
+ * Find the first existing instruction file at a given base path.
493
+ * Prefers AGENTS.md over CLAUDE.md.
494
+ */
495
+ function findInstructionFile(basePath, reader = fsInstructionReader) {
496
+ for (const filename of INSTRUCTION_FILES) {
497
+ const fullPath = join(basePath, filename);
498
+ if (reader.exists(fullPath)) return fullPath;
499
+ }
500
+ return null;
501
+ }
502
+ /**
503
+ * Load all agent instruction files from global and project locations.
504
+ * Returns an array of instruction sources, with global ones first.
505
+ *
506
+ * `projectReader` controls where project-scope content comes from (defaults to
507
+ * the working tree). Global instructions read the operator machine's
508
+ * filesystem, unless `skipGlobal` keeps them out entirely.
509
+ */
510
+ function loadAgentInstructions(projectPath, configDirName = DEFAULT_CONFIG_DIR, projectReader = fsInstructionReader, { skipGlobal = false } = {}) {
511
+ const sources = [];
512
+ const home = homedir();
513
+ const projectLocations = PROJECT_LOCATIONS.map((loc) => loc === ".mastracode" ? configDirName : loc);
514
+ const globalLocations = skipGlobal ? [] : GLOBAL_LOCATIONS.map((loc) => {
515
+ if (loc === ".mastracode") return configDirName;
516
+ if (loc === ".config/mastracode") return ".config/" + configDirName.replace(/^\./, "");
517
+ return loc;
518
+ });
519
+ for (const location of globalLocations) {
520
+ const filePath = findInstructionFile(join(home, location));
521
+ if (filePath) try {
522
+ const content = readFileSync(filePath, "utf-8").trim();
523
+ if (content) {
524
+ sources.push({
525
+ path: filePath,
526
+ content,
527
+ scope: "global"
528
+ });
529
+ break;
530
+ }
531
+ } catch {}
532
+ }
533
+ for (const location of projectLocations) {
534
+ const filePath = findInstructionFile(location ? join(projectPath, location) : projectPath, projectReader);
535
+ if (filePath) try {
536
+ const content = projectReader.read(filePath).trim();
537
+ if (content) {
538
+ sources.push({
539
+ path: filePath,
540
+ content,
541
+ scope: "project",
542
+ ...projectReader.ref ? { ref: projectReader.ref } : {}
543
+ });
544
+ break;
545
+ }
546
+ } catch {}
547
+ }
548
+ return sources;
549
+ }
550
+ function getStaticallyLoadedInstructionPaths(projectPath, configDirName = DEFAULT_CONFIG_DIR, projectReader) {
551
+ return instructionSourcePaths(loadAgentInstructions(projectPath, configDirName, projectReader), [projectPath]);
552
+ }
553
+ /**
554
+ * Directories a session's project instructions load from: the host's
555
+ * `instructionRoots` (resolved against the working directory, the session's
556
+ * own checkout first) when it sets any, else the working directory itself.
557
+ */
558
+ function sessionInstructionRoots(workingDir, instructionRoots) {
559
+ if (!instructionRoots?.length) return [workingDir];
560
+ return [...new Set(instructionRoots.map((root) => resolve(workingDir, root)))];
561
+ }
562
+ /**
563
+ * The instruction files a session's system prompt carries. Global files load
564
+ * once (unless `skipGlobal`), then each instruction root's project files, in
565
+ * root order. An untrusted checkout never reads project files off the working
566
+ * tree: with a `baseRef` the first root (the session's own checkout) is served
567
+ * from that ref and the other roots are skipped; without one no project files
568
+ * load.
569
+ */
570
+ function loadSessionInstructions({ workingDir, instructionRoots, configDir, untrustedCheckout = false, baseRef, skipGlobal = false }) {
571
+ const [primary, ...others] = sessionInstructionRoots(workingDir, instructionRoots);
572
+ const sources = loadAgentInstructions(primary, configDir, untrustedCheckout ? baseRef ? createGitRefInstructionReader(primary, baseRef) : {
573
+ exists: () => false,
574
+ read: () => ""
575
+ } : void 0, { skipGlobal });
576
+ if (untrustedCheckout) return sources;
577
+ for (const root of others) sources.push(...loadAgentInstructions(root, configDir, void 0, { skipGlobal: true }));
578
+ return sources;
579
+ }
580
+ /**
581
+ * Paths of loaded instruction sources, each project source also under its
582
+ * root's canonical path, so reactive reminders never repeat a file the
583
+ * system prompt already carries.
584
+ */
585
+ function instructionSourcePaths(sources, roots) {
586
+ return sources.flatMap((source) => {
587
+ const path = normalize(source.path);
588
+ if (source.scope !== "project") return [path];
589
+ const root = roots.find((candidate) => {
590
+ const rel = relative(candidate, path);
591
+ return rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
592
+ });
593
+ if (!root) return [path];
594
+ const canonicalPath = join(realpathOrResolved(root), relative(root, path));
595
+ return path === canonicalPath ? [path] : [path, canonicalPath];
596
+ });
597
+ }
598
+ /** Heading the agent-instructions block is introduced by in the system prompt. */
599
+ const AGENT_INSTRUCTIONS_HEADING = "# Agent Instructions";
600
+ /**
601
+ * Format a single instruction source as it appears in the system prompt.
602
+ *
603
+ * Exported so callers that attribute prompt cost per source (the `/context`
604
+ * audit) measure the exact block that is sent rather than reconstructing it.
605
+ */
606
+ function formatInstructionSource(source) {
607
+ return `<!-- ${source.scope === "global" ? "Global" : "Project"} instructions from ${source.ref ? `${source.path} (at ref ${source.ref})` : source.path} -->\n${source.content}`;
608
+ }
609
+ /**
610
+ * Format loaded instructions into a string for the system prompt.
611
+ */
612
+ function formatAgentInstructions(sources) {
613
+ if (sources.length === 0) return "";
614
+ const sections = sources.map(formatInstructionSource);
615
+ return `\n${AGENT_INSTRUCTIONS_HEADING}\n\n${sections.join("\n\n")}\n`;
616
+ }
617
+ export { AGENT_INSTRUCTIONS_HEADING, createGitRefInstructionReader, createGitRefInstructionReaderAsync, createGitRefReminderReader, createGitRefReminderReaderAsync, formatAgentInstructions, formatInstructionSource, getStaticallyLoadedInstructionPaths, instructionSourcePaths, loadAgentInstructions, loadAgentInstructionsAsync, loadSessionInstructions, loadSessionInstructionsAsync, sessionInstructionRoots };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Build mode prompt — full tool access, make changes and verify.
3
+ */
4
+ import type { PromptContext } from './index.js';
5
+ /**
6
+ * Dynamic build mode prompt function.
7
+ * When an approved plan exists in state, prepends it so the agent
8
+ * knows exactly what to implement.
9
+ */
10
+ export declare function buildModePromptFn(ctx: PromptContext): string;
11
+ export declare const buildModePrompt = "\n# Build Mode\n\nYou are in BUILD mode. You have full access to all tools and can read, write, edit, and execute commands.\n\n## Working Style\n\n**For simple tasks** (typo fixes, small edits, single-file changes):\n- Just do it. No need to explain your plan first.\n\n**For non-trivial tasks** (3+ files, architectural decisions, unclear requirements):\n- Use the available task-management tools to create and update your task list\n- Work on ONE step at a time \u2014 complete it and verify it works before moving on\n- If multiple approaches are plausible and the choice would materially affect scope, behavior, or risk, stop and ask the user\n\n## The Implementation Loop\n\nFor each change you make:\n\n1. **Understand** \u2014 Read the relevant code. Check how similar things are done elsewhere.\n2. **Implement** \u2014 Make the change. Follow existing patterns and conventions.\n3. **Verify** \u2014 Test that it works. Don't assume \u2014 actually run it.\n4. **Prove** \u2014 Proactively prove that the change is good, makes sense in context, is a positive contribution, and works fully. The burden of proof is on YOU.\n5. **Clean up** \u2014 Ensure no broken code, no debug statements, no half-done features.\n\nOnly move to the next change after the current one is verified and proved to be working.\n\n## Verification is Required\n\nBefore considering any task complete:\n- Run relevant tests (check package.json for test scripts)\n- For TypeScript, run `tsc --noEmit` to catch type errors\n- If there are no automated tests, manually verify the behavior works as expected\n- Confirm the result makes sense in the codebase and improves the requested behavior\n- Use available task-checking tools to ensure all tracked tasks are done\n\n**Don't mark something as done until you've verified and proved it actually works.**\n\n## Error Recovery\n\nWhen something breaks:\n1. Read the full error output carefully \u2014 don't guess\n2. Find the root cause, not just the symptom\n3. Fix it properly \u2014 no casts or suppressions to hide errors\n4. Re-run to confirm the fix\n5. If progress is blocked after reasonable attempts, briefly explain the blocker, what you've tried, and the next best option\n\n## Git in Build Mode\n\n- Before committing, verify the code compiles and passes lint\n- Use descriptive branch names: `feat/...`, `fix/...`, `refactor/...`\n";
12
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1,73 @@
1
+ // src/agents/prompts/build.ts
2
+ /**
3
+ * Dynamic build mode prompt function.
4
+ * When an approved plan exists in state, prepends it so the agent
5
+ * knows exactly what to implement.
6
+ */
7
+ function buildModePromptFn(ctx) {
8
+ if (ctx.activePlan) return `# Approved Plan
9
+
10
+ **${ctx.activePlan.title}**
11
+
12
+ ${ctx.activePlan.plan}
13
+
14
+ ---
15
+
16
+ Implement the approved plan above. Follow the steps in order and verify each step works before moving on.
17
+
18
+ ` + buildModePrompt;
19
+ return buildModePrompt;
20
+ }
21
+ const buildModePrompt = `
22
+ # Build Mode
23
+
24
+ You are in BUILD mode. You have full access to all tools and can read, write, edit, and execute commands.
25
+
26
+ ## Working Style
27
+
28
+ **For simple tasks** (typo fixes, small edits, single-file changes):
29
+ - Just do it. No need to explain your plan first.
30
+
31
+ **For non-trivial tasks** (3+ files, architectural decisions, unclear requirements):
32
+ - Use the available task-management tools to create and update your task list
33
+ - Work on ONE step at a time — complete it and verify it works before moving on
34
+ - If multiple approaches are plausible and the choice would materially affect scope, behavior, or risk, stop and ask the user
35
+
36
+ ## The Implementation Loop
37
+
38
+ For each change you make:
39
+
40
+ 1. **Understand** — Read the relevant code. Check how similar things are done elsewhere.
41
+ 2. **Implement** — Make the change. Follow existing patterns and conventions.
42
+ 3. **Verify** — Test that it works. Don't assume — actually run it.
43
+ 4. **Prove** — Proactively prove that the change is good, makes sense in context, is a positive contribution, and works fully. The burden of proof is on YOU.
44
+ 5. **Clean up** — Ensure no broken code, no debug statements, no half-done features.
45
+
46
+ Only move to the next change after the current one is verified and proved to be working.
47
+
48
+ ## Verification is Required
49
+
50
+ Before considering any task complete:
51
+ - Run relevant tests (check package.json for test scripts)
52
+ - For TypeScript, run \`tsc --noEmit\` to catch type errors
53
+ - If there are no automated tests, manually verify the behavior works as expected
54
+ - Confirm the result makes sense in the codebase and improves the requested behavior
55
+ - Use available task-checking tools to ensure all tracked tasks are done
56
+
57
+ **Don't mark something as done until you've verified and proved it actually works.**
58
+
59
+ ## Error Recovery
60
+
61
+ When something breaks:
62
+ 1. Read the full error output carefully — don't guess
63
+ 2. Find the root cause, not just the symptom
64
+ 3. Fix it properly — no casts or suppressions to hide errors
65
+ 4. Re-run to confirm the fix
66
+ 5. If progress is blocked after reasonable attempts, briefly explain the blocker, what you've tried, and the next best option
67
+
68
+ ## Git in Build Mode
69
+
70
+ - Before committing, verify the code compiles and passes lint
71
+ - Use descriptive branch names: \`feat/...\`, \`fix/...\`, \`refactor/...\`
72
+ `;
73
+ export { buildModePrompt, buildModePromptFn };