@mastra/code-sdk 0.0.0-mastracode-cloud-20260706153555
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.
- package/CHANGELOG.md +22 -0
- package/LICENSE.md +30 -0
- package/README.md +50 -0
- package/dist/acp/agent.d.ts +35 -0
- package/dist/acp/agent.d.ts.map +1 -0
- package/dist/acp/agent.js +173 -0
- package/dist/acp/agent.js.map +1 -0
- package/dist/acp/event-mapper.d.ts +22 -0
- package/dist/acp/event-mapper.d.ts.map +1 -0
- package/dist/acp/event-mapper.js +166 -0
- package/dist/acp/event-mapper.js.map +1 -0
- package/dist/acp/index.d.ts +8 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +54 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/server.d.ts +7 -0
- package/dist/acp/server.d.ts.map +1 -0
- package/dist/acp/server.js +34 -0
- package/dist/acp/server.js.map +1 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.d.ts.map +1 -0
- package/dist/acp.js +5 -0
- package/dist/acp.js.map +1 -0
- package/dist/agents/instructions.d.ts +6 -0
- package/dist/agents/instructions.d.ts.map +1 -0
- package/dist/agents/instructions.js +41 -0
- package/dist/agents/instructions.js.map +1 -0
- package/dist/agents/mastracode-gateway.d.ts +65 -0
- package/dist/agents/mastracode-gateway.d.ts.map +1 -0
- package/dist/agents/mastracode-gateway.js +442 -0
- package/dist/agents/mastracode-gateway.js.map +1 -0
- package/dist/agents/memory.d.ts +13 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +107 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/model.d.ts +55 -0
- package/dist/agents/model.d.ts.map +1 -0
- package/dist/agents/model.js +115 -0
- package/dist/agents/model.js.map +1 -0
- package/dist/agents/modes/build.d.ts +10 -0
- package/dist/agents/modes/build.d.ts.map +1 -0
- package/dist/agents/modes/build.js +45 -0
- package/dist/agents/modes/build.js.map +1 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.d.ts.map +1 -0
- package/dist/agents/modes/explore.js +38 -0
- package/dist/agents/modes/explore.js.map +1 -0
- package/dist/agents/modes/plan.d.ts +6 -0
- package/dist/agents/modes/plan.d.ts.map +1 -0
- package/dist/agents/modes/plan.js +38 -0
- package/dist/agents/modes/plan.js.map +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts +20 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
- package/dist/agents/prompts/agent-instructions.js +82 -0
- package/dist/agents/prompts/agent-instructions.js.map +1 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.d.ts.map +1 -0
- package/dist/agents/prompts/build.js +73 -0
- package/dist/agents/prompts/build.js.map +1 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.d.ts.map +1 -0
- package/dist/agents/prompts/fast.js +22 -0
- package/dist/agents/prompts/fast.js.map +1 -0
- package/dist/agents/prompts/index.d.ts +19 -0
- package/dist/agents/prompts/index.d.ts.map +1 -0
- package/dist/agents/prompts/index.js +57 -0
- package/dist/agents/prompts/index.js.map +1 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.d.ts.map +1 -0
- package/dist/agents/prompts/model.js +22 -0
- package/dist/agents/prompts/model.js.map +1 -0
- package/dist/agents/prompts/plan.d.ts +6 -0
- package/dist/agents/prompts/plan.d.ts.map +1 -0
- package/dist/agents/prompts/plan.js +107 -0
- package/dist/agents/prompts/plan.js.map +1 -0
- package/dist/agents/prompts/tool-guidance.d.ts +13 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -0
- package/dist/agents/prompts/tool-guidance.js +181 -0
- package/dist/agents/prompts/tool-guidance.js.map +1 -0
- package/dist/agents/sandbox-filesystem.d.ts +89 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
- package/dist/agents/sandbox-filesystem.js +268 -0
- package/dist/agents/sandbox-filesystem.js.map +1 -0
- package/dist/agents/sandbox-reattach.d.ts +19 -0
- package/dist/agents/sandbox-reattach.d.ts.map +1 -0
- package/dist/agents/sandbox-reattach.js +17 -0
- package/dist/agents/sandbox-reattach.js.map +1 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.d.ts.map +1 -0
- package/dist/agents/thread-caveman-state.js +96 -0
- package/dist/agents/thread-caveman-state.js.map +1 -0
- package/dist/agents/tool-availability.d.ts +10 -0
- package/dist/agents/tool-availability.d.ts.map +1 -0
- package/dist/agents/tool-availability.js +105 -0
- package/dist/agents/tool-availability.js.map +1 -0
- package/dist/agents/tools.d.ts +18 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +126 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/workspace.d.ts +22 -0
- package/dist/agents/workspace.d.ts.map +1 -0
- package/dist/agents/workspace.js +194 -0
- package/dist/agents/workspace.js.map +1 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +152 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth/index.d.ts +9 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +11 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +21 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/providers/anthropic.d.ts +17 -0
- package/dist/auth/providers/anthropic.d.ts.map +1 -0
- package/dist/auth/providers/anthropic.js +94 -0
- package/dist/auth/providers/anthropic.js.map +1 -0
- package/dist/auth/providers/github-copilot.d.ts +100 -0
- package/dist/auth/providers/github-copilot.d.ts.map +1 -0
- package/dist/auth/providers/github-copilot.js +302 -0
- package/dist/auth/providers/github-copilot.js.map +1 -0
- package/dist/auth/providers/openai-codex.d.ts +95 -0
- package/dist/auth/providers/openai-codex.d.ts.map +1 -0
- package/dist/auth/providers/openai-codex.js +527 -0
- package/dist/auth/providers/openai-codex.js.map +1 -0
- package/dist/auth/storage.d.ts +91 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +187 -0
- package/dist/auth/storage.js.map +1 -0
- package/dist/auth/types.d.ts +68 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.d.ts.map +1 -0
- package/dist/clipboard/index.js +192 -0
- package/dist/clipboard/index.js.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +23 -0
- package/dist/constants.js.map +1 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.d.ts.map +1 -0
- package/dist/error-classification.js +14 -0
- package/dist/error-classification.js.map +1 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.d.ts.map +1 -0
- package/dist/evals/context-builder.js +120 -0
- package/dist/evals/context-builder.js.map +1 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +8 -0
- package/dist/evals/index.js.map +1 -0
- package/dist/evals/scorers/classify-command.d.ts +31 -0
- package/dist/evals/scorers/classify-command.d.ts.map +1 -0
- package/dist/evals/scorers/classify-command.js +52 -0
- package/dist/evals/scorers/classify-command.js.map +1 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.d.ts.map +1 -0
- package/dist/evals/scorers/efficiency.js +201 -0
- package/dist/evals/scorers/efficiency.js.map +1 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.d.ts.map +1 -0
- package/dist/evals/scorers/extract-tools.js +56 -0
- package/dist/evals/scorers/extract-tools.js.map +1 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.d.ts.map +1 -0
- package/dist/evals/scorers/index.js +7 -0
- package/dist/evals/scorers/index.js.map +1 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.d.ts.map +1 -0
- package/dist/evals/scorers/outcome.js +238 -0
- package/dist/evals/scorers/outcome.js.map +1 -0
- package/dist/headless/cli.d.ts +42 -0
- package/dist/headless/cli.d.ts.map +1 -0
- package/dist/headless/cli.js +196 -0
- package/dist/headless/cli.js.map +1 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.d.ts.map +1 -0
- package/dist/headless/flags.js +188 -0
- package/dist/headless/flags.js.map +1 -0
- package/dist/headless/format.d.ts +38 -0
- package/dist/headless/format.d.ts.map +1 -0
- package/dist/headless/format.js +85 -0
- package/dist/headless/format.js.map +1 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.d.ts.map +1 -0
- package/dist/headless/index.js +32 -0
- package/dist/headless/index.js.map +1 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.d.ts.map +1 -0
- package/dist/headless/policy.js +38 -0
- package/dist/headless/policy.js.map +1 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.d.ts.map +1 -0
- package/dist/headless/run-mc.js +296 -0
- package/dist/headless/run-mc.js.map +1 -0
- package/dist/headless/types.d.ts +134 -0
- package/dist/headless/types.d.ts.map +1 -0
- package/dist/headless/types.js +9 -0
- package/dist/headless/types.js.map +1 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.d.ts.map +1 -0
- package/dist/hooks/config.js +78 -0
- package/dist/hooks/config.js.map +1 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +125 -0
- package/dist/hooks/executor.js.map +1 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +16 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/manager.d.ts +47 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +284 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +152 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +7 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +241 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +712 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.d.ts.map +1 -0
- package/dist/ipc/ipc-reporter.js +24 -0
- package/dist/ipc/ipc-reporter.js.map +1 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.d.ts.map +1 -0
- package/dist/lsp/client.js +309 -0
- package/dist/lsp/client.js.map +1 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +9 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.d.ts.map +1 -0
- package/dist/lsp/language.js +48 -0
- package/dist/lsp/language.js.map +1 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.d.ts.map +1 -0
- package/dist/lsp/manager.js +97 -0
- package/dist/lsp/manager.js.map +1 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +128 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.d.ts.map +1 -0
- package/dist/lsp/workspace.js +52 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/mcp/config.d.ts +34 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +205 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +5 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +10 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +49 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +374 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/types.d.ts +85 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +1 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.d.ts.map +1 -0
- package/dist/onboarding/custom-packs.js +20 -0
- package/dist/onboarding/custom-packs.js.map +1 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.d.ts.map +1 -0
- package/dist/onboarding/custom-providers.js +28 -0
- package/dist/onboarding/custom-providers.js.map +1 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.d.ts.map +1 -0
- package/dist/onboarding/index.js +21 -0
- package/dist/onboarding/index.js.map +1 -0
- package/dist/onboarding/om-settings.d.ts +20 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -0
- package/dist/onboarding/om-settings.js +26 -0
- package/dist/onboarding/om-settings.js.map +1 -0
- package/dist/onboarding/packs.d.ts +48 -0
- package/dist/onboarding/packs.d.ts.map +1 -0
- package/dist/onboarding/packs.js +111 -0
- package/dist/onboarding/packs.js.map +1 -0
- package/dist/onboarding/settings.d.ts +323 -0
- package/dist/onboarding/settings.d.ts.map +1 -0
- package/dist/onboarding/settings.js +594 -0
- package/dist/onboarding/settings.js.map +1 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +119 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugin.d.ts +81 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +30 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/install.d.ts +20 -0
- package/dist/plugins/install.d.ts.map +1 -0
- package/dist/plugins/install.js +179 -0
- package/dist/plugins/install.js.map +1 -0
- package/dist/plugins/loader.d.ts +15 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +221 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +60 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +369 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +75 -0
- package/dist/plugins/manifest.js.map +1 -0
- package/dist/plugins/package-link.d.ts +2 -0
- package/dist/plugins/package-link.d.ts.map +1 -0
- package/dist/plugins/package-link.js +20 -0
- package/dist/plugins/package-link.js.map +1 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.d.ts.map +1 -0
- package/dist/plugins/paths.js +26 -0
- package/dist/plugins/paths.js.map +1 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +96 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.d.ts.map +1 -0
- package/dist/plugins/scaffold.js +152 -0
- package/dist/plugins/scaffold.js.map +1 -0
- package/dist/plugins/types.d.ts +45 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +1 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/processors/plan-rejection-abort.d.ts +12 -0
- package/dist/processors/plan-rejection-abort.d.ts.map +1 -0
- package/dist/processors/plan-rejection-abort.js +53 -0
- package/dist/processors/plan-rejection-abort.js.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +40 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.js +79 -0
- package/dist/providers/amazon-bedrock-gateway.js.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.js +62 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/claude-max.d.ts +50 -0
- package/dist/providers/claude-max.d.ts.map +1 -0
- package/dist/providers/claude-max.js +151 -0
- package/dist/providers/claude-max.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +58 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +263 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +70 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +291 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/schema.d.ts +167 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +92 -0
- package/dist/schema.js.map +1 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.d.ts.map +1 -0
- package/dist/theme-palette.js +17 -0
- package/dist/theme-palette.js.map +1 -0
- package/dist/tool-names.d.ts +73 -0
- package/dist/tool-names.d.ts.map +1 -0
- package/dist/tool-names.js +43 -0
- package/dist/tool-names.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +9 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.d.ts.map +1 -0
- package/dist/tools/request-sandbox-access.js +88 -0
- package/dist/tools/request-sandbox-access.js.map +1 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +22 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools/web-search.d.ts +35 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +65 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.d.ts.map +1 -0
- package/dist/utils/binaries.js +74 -0
- package/dist/utils/binaries.js.map +1 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.d.ts.map +1 -0
- package/dist/utils/debug-log.js +55 -0
- package/dist/utils/debug-log.js.map +1 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +207 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.d.ts.map +1 -0
- package/dist/utils/gateway-sync.js +49 -0
- package/dist/utils/gateway-sync.js.map +1 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.d.ts.map +1 -0
- package/dist/utils/plan-diff.js +43 -0
- package/dist/utils/plan-diff.js.map +1 -0
- package/dist/utils/plans.d.ts +56 -0
- package/dist/utils/plans.d.ts.map +1 -0
- package/dist/utils/plans.js +99 -0
- package/dist/utils/plans.js.map +1 -0
- package/dist/utils/project.d.ts +161 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +302 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/signals-pubsub.d.ts +41 -0
- package/dist/utils/signals-pubsub.d.ts.map +1 -0
- package/dist/utils/signals-pubsub.js +104 -0
- package/dist/utils/signals-pubsub.js.map +1 -0
- package/dist/utils/slash-command-loader.d.ts +48 -0
- package/dist/utils/slash-command-loader.d.ts.map +1 -0
- package/dist/utils/slash-command-loader.js +155 -0
- package/dist/utils/slash-command-loader.js.map +1 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.d.ts.map +1 -0
- package/dist/utils/slash-command-processor.js +96 -0
- package/dist/utils/slash-command-processor.js.map +1 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.d.ts.map +1 -0
- package/dist/utils/stdin-pipe.js +72 -0
- package/dist/utils/stdin-pipe.js.map +1 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.d.ts.map +1 -0
- package/dist/utils/storage-factory.js +98 -0
- package/dist/utils/storage-factory.js.map +1 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.d.ts.map +1 -0
- package/dist/utils/thread-lock.js +108 -0
- package/dist/utils/thread-lock.js.map +1 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.d.ts.map +1 -0
- package/dist/utils/token-estimator.js +21 -0
- package/dist/utils/token-estimator.js.map +1 -0
- package/dist/utils/update-check.d.ts +52 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/dist/utils/update-check.js +177 -0
- package/dist/utils/update-check.js.map +1 -0
- package/dist/voice/stt-registry.d.ts +64 -0
- package/dist/voice/stt-registry.d.ts.map +1 -0
- package/dist/voice/stt-registry.js +126 -0
- package/dist/voice/stt-registry.js.map +1 -0
- package/package.json +92 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,712 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { hostname } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { AgentController } from "@mastra/core/agent-controller";
|
|
5
|
+
import { createCodingAgent } from "@mastra/core/coding-agent";
|
|
6
|
+
import { PROVIDER_REGISTRY } from "@mastra/core/llm";
|
|
7
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
8
|
+
import {
|
|
9
|
+
AgentsMDInjector,
|
|
10
|
+
isBadRequestError,
|
|
11
|
+
PrefillErrorHandler,
|
|
12
|
+
ProviderHistoryCompat,
|
|
13
|
+
StreamErrorRetryProcessor
|
|
14
|
+
} from "@mastra/core/processors";
|
|
15
|
+
import { RequestContext } from "@mastra/core/request-context";
|
|
16
|
+
import { TaskSignalProvider } from "@mastra/core/signals";
|
|
17
|
+
import { InMemoryHarness, MastraCompositeStore } from "@mastra/core/storage";
|
|
18
|
+
import { DEFAULT_GOAL_JUDGE_PROMPT } from "@mastra/core/tools";
|
|
19
|
+
import { DuckDBStore } from "@mastra/duckdb";
|
|
20
|
+
import { GithubSignals } from "@mastra/github-signals";
|
|
21
|
+
import {
|
|
22
|
+
Observability,
|
|
23
|
+
MastraStorageExporter,
|
|
24
|
+
MastraPlatformExporter,
|
|
25
|
+
SensitiveDataFilter
|
|
26
|
+
} from "@mastra/observability";
|
|
27
|
+
import { getDynamicInstructions } from "./agents/instructions.js";
|
|
28
|
+
import { getDynamicMemory } from "./agents/memory.js";
|
|
29
|
+
import { createMastraCodeGateway, getDynamicModel, getGoalJudgeModel, resolveModel } from "./agents/model.js";
|
|
30
|
+
import { buildMode } from "./agents/modes/build.js";
|
|
31
|
+
import { fastMode } from "./agents/modes/explore.js";
|
|
32
|
+
import { planMode } from "./agents/modes/plan.js";
|
|
33
|
+
import { getStaticallyLoadedInstructionPaths } from "./agents/prompts/agent-instructions.js";
|
|
34
|
+
import { attachOMThreadStatePersistence, restoreOMThreadStateForCurrentThread } from "./agents/thread-caveman-state.js";
|
|
35
|
+
import { createDynamicTools, createToolHooks } from "./agents/tools.js";
|
|
36
|
+
import { getDynamicWorkspace, getGoalJudgeTools } from "./agents/workspace.js";
|
|
37
|
+
import { AuthStorage } from "./auth/storage.js";
|
|
38
|
+
import { DEFAULT_CONFIG_DIR, validateConfigDirName } from "./constants.js";
|
|
39
|
+
import { createOutcomeScorer, createEfficiencyScorer } from "./evals/scorers/index.js";
|
|
40
|
+
import { HookManager } from "./hooks/index.js";
|
|
41
|
+
import { createMcpManager } from "./mcp/index.js";
|
|
42
|
+
import { getAvailableModePacks, getAvailableOmPacks } from "./onboarding/packs.js";
|
|
43
|
+
import {
|
|
44
|
+
loadSettings,
|
|
45
|
+
MEMORY_GATEWAY_PROVIDER,
|
|
46
|
+
OBSERVABILITY_AUTH_PREFIX,
|
|
47
|
+
resolveModelDefaults,
|
|
48
|
+
resolveOmRoleModel,
|
|
49
|
+
saveSettings
|
|
50
|
+
} from "./onboarding/settings.js";
|
|
51
|
+
import { getToolCategory } from "./permissions.js";
|
|
52
|
+
import { PluginManager } from "./plugins/manager.js";
|
|
53
|
+
import { PlanRejectionAbortProcessor } from "./processors/plan-rejection-abort.js";
|
|
54
|
+
import { createAmazonBedrockGateway } from "./providers/amazon-bedrock-gateway.js";
|
|
55
|
+
import { setAuthStorage } from "./providers/claude-max.js";
|
|
56
|
+
import { setAuthStorage as setGitHubCopilotAuthStorage } from "./providers/github-copilot.js";
|
|
57
|
+
import { setAuthStorage as setOpenAIAuthStorage } from "./providers/openai-codex.js";
|
|
58
|
+
import { stateSchema } from "./schema.js";
|
|
59
|
+
import { mastraBrand } from "./theme-palette.js";
|
|
60
|
+
import { syncGateways } from "./utils/gateway-sync.js";
|
|
61
|
+
import {
|
|
62
|
+
detectProject,
|
|
63
|
+
getObservabilityDatabasePath,
|
|
64
|
+
getStorageConfig,
|
|
65
|
+
getResourceIdOverride
|
|
66
|
+
} from "./utils/project.js";
|
|
67
|
+
import { createSignalsPubSub } from "./utils/signals-pubsub.js";
|
|
68
|
+
import { createStorage, createVectorStore } from "./utils/storage-factory.js";
|
|
69
|
+
import { acquireThreadLock, releaseThreadLock } from "./utils/thread-lock.js";
|
|
70
|
+
const CODE_AGENT_ID = "code-agent";
|
|
71
|
+
const MASTRACODE_ECONNRESET_MAX_RETRIES = 2;
|
|
72
|
+
const MASTRACODE_ECONNRESET_RETRY_INITIAL_DELAY_MS = 1e3;
|
|
73
|
+
const MASTRACODE_ECONNRESET_RETRY_MAX_DELAY_MS = 3e4;
|
|
74
|
+
const ECONNRESET_MESSAGE_PATTERN = /econnreset|socket hang up/i;
|
|
75
|
+
function isECONNRESETError(error) {
|
|
76
|
+
if (!error) return false;
|
|
77
|
+
const code = typeof error === "object" && "code" in error ? error.code : void 0;
|
|
78
|
+
if (typeof code === "string" && code.toUpperCase() === "ECONNRESET") return true;
|
|
79
|
+
const message = error instanceof Error ? error.message : void 0;
|
|
80
|
+
if (typeof message === "string" && ECONNRESET_MESSAGE_PATTERN.test(message)) return true;
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
function shortHash(input) {
|
|
84
|
+
return createHash("sha256").update(input).digest("hex").slice(0, 12);
|
|
85
|
+
}
|
|
86
|
+
function applyEffectiveDefaultsToModes(modes, effectiveDefaults) {
|
|
87
|
+
return modes.map((mode) => {
|
|
88
|
+
const savedModel = effectiveDefaults[mode.id];
|
|
89
|
+
if (!savedModel) {
|
|
90
|
+
return mode;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...mode,
|
|
94
|
+
defaultModelId: savedModel
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function addPluginToolsToModeAllowlists(modes, pluginToolNames) {
|
|
99
|
+
if (pluginToolNames.length === 0) return modes;
|
|
100
|
+
return modes.map((mode) => {
|
|
101
|
+
if (!mode.availableTools) return mode;
|
|
102
|
+
return {
|
|
103
|
+
...mode,
|
|
104
|
+
availableTools: Array.from(/* @__PURE__ */ new Set([...mode.availableTools, ...pluginToolNames]))
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function createAuthStorage() {
|
|
109
|
+
const authStorage = new AuthStorage();
|
|
110
|
+
setAuthStorage(authStorage);
|
|
111
|
+
setOpenAIAuthStorage(authStorage);
|
|
112
|
+
setGitHubCopilotAuthStorage(authStorage);
|
|
113
|
+
return authStorage;
|
|
114
|
+
}
|
|
115
|
+
function resolveCloudObservabilityConfig(settings, authStorage, resourceId) {
|
|
116
|
+
const resourceConfig = settings.observability.resources[resourceId];
|
|
117
|
+
if (resourceConfig) {
|
|
118
|
+
const token = authStorage.getStoredApiKey(`${OBSERVABILITY_AUTH_PREFIX}${resourceId}`);
|
|
119
|
+
if (token) {
|
|
120
|
+
return { accessToken: token, projectId: resourceConfig.projectId };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
accessToken: process.env.MASTRA_CLOUD_ACCESS_TOKEN,
|
|
125
|
+
projectId: process.env.MASTRA_PROJECT_ID
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async function createMastraCodeAgentController(config) {
|
|
129
|
+
const cwd = config?.cwd ?? process.cwd();
|
|
130
|
+
const homeDir = config?.homeDir ?? config?.initialState?.homeDir;
|
|
131
|
+
const configDir = config?.configDir ?? DEFAULT_CONFIG_DIR;
|
|
132
|
+
let activeSession;
|
|
133
|
+
if (configDir !== DEFAULT_CONFIG_DIR) {
|
|
134
|
+
validateConfigDirName(configDir);
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
process.loadEnvFile(path.join(cwd, ".env"));
|
|
138
|
+
} catch {
|
|
139
|
+
}
|
|
140
|
+
const authStorage = createAuthStorage();
|
|
141
|
+
const globalSettings = loadSettings(config?.settingsPath);
|
|
142
|
+
const storedGatewayKey = authStorage.getStoredApiKey(MEMORY_GATEWAY_PROVIDER);
|
|
143
|
+
const storedGatewayUrl = globalSettings.memoryGateway?.baseUrl;
|
|
144
|
+
if (storedGatewayKey) {
|
|
145
|
+
process.env["MASTRA_GATEWAY_API_KEY"] ??= storedGatewayKey;
|
|
146
|
+
}
|
|
147
|
+
if (storedGatewayUrl) {
|
|
148
|
+
process.env["MASTRA_GATEWAY_URL"] ??= storedGatewayUrl;
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const registry = PROVIDER_REGISTRY;
|
|
152
|
+
const providerEnvVars = {};
|
|
153
|
+
for (const [provider, cfg] of Object.entries(registry)) {
|
|
154
|
+
const envVars = cfg?.apiKeyEnvVar;
|
|
155
|
+
providerEnvVars[provider] = Array.isArray(envVars) ? envVars[0] : envVars;
|
|
156
|
+
}
|
|
157
|
+
providerEnvVars[MEMORY_GATEWAY_PROVIDER] ??= "MASTRA_GATEWAY_API_KEY";
|
|
158
|
+
authStorage.loadStoredApiKeysIntoEnv(providerEnvVars);
|
|
159
|
+
} catch {
|
|
160
|
+
authStorage.loadStoredApiKeysIntoEnv({
|
|
161
|
+
[MEMORY_GATEWAY_PROVIDER]: "MASTRA_GATEWAY_API_KEY",
|
|
162
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
163
|
+
openai: "OPENAI_API_KEY",
|
|
164
|
+
google: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
165
|
+
cerebras: "CEREBRAS_API_KEY",
|
|
166
|
+
deepseek: "DEEPSEEK_API_KEY"
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const mgApiKey = process.env["MASTRA_GATEWAY_API_KEY"] ?? storedGatewayKey;
|
|
170
|
+
const mastraGatewayBaseUrl = (process.env["MASTRA_GATEWAY_URL"] ?? storedGatewayUrl ?? "https://gateway-api.mastra.ai").replace(/\/+$/, "").replace(/\/v1$/, "");
|
|
171
|
+
const mastraCodeGateway = createMastraCodeGateway({
|
|
172
|
+
mastraGatewayBaseUrl,
|
|
173
|
+
mastraGatewayApiKey: mgApiKey,
|
|
174
|
+
routeThroughMastraGateway: false,
|
|
175
|
+
settingsPath: config?.settingsPath
|
|
176
|
+
});
|
|
177
|
+
const amazonBedrockGateway = createAmazonBedrockGateway();
|
|
178
|
+
const project = detectProject(cwd);
|
|
179
|
+
const resourceIdOverride = getResourceIdOverride(project.rootPath, configDir);
|
|
180
|
+
if (resourceIdOverride) {
|
|
181
|
+
project.resourceId = resourceIdOverride;
|
|
182
|
+
project.resourceIdOverride = true;
|
|
183
|
+
}
|
|
184
|
+
const sessionId = `mastracode-session-${shortHash(project.resourceId)}`;
|
|
185
|
+
const ownerId = `mastracode-${shortHash(`${hostname()}\0${project.rootPath}`)}`;
|
|
186
|
+
const configuredPubSub = config?.pubsub;
|
|
187
|
+
const useUnixSocketPubSub = (config?.unixSocketPubSub ?? globalSettings.signals?.unixSocketPubSub ?? false) && process.platform !== "win32";
|
|
188
|
+
const signalsPubSub = configuredPubSub ?? (useUnixSocketPubSub ? createSignalsPubSub(project.resourceId) : void 0);
|
|
189
|
+
const crossProcessPubSub = config?.crossProcessPubSub ?? (!configuredPubSub && useUnixSocketPubSub);
|
|
190
|
+
if (crossProcessPubSub && !signalsPubSub) {
|
|
191
|
+
throw new Error("crossProcessPubSub requires a pubsub instance");
|
|
192
|
+
}
|
|
193
|
+
const storageConfig = config?.storage ?? getStorageConfig(project.rootPath, globalSettings.storage, configDir);
|
|
194
|
+
const storageResult = await createStorage(storageConfig);
|
|
195
|
+
const storageWarning = storageResult.warning;
|
|
196
|
+
let observabilityDomain;
|
|
197
|
+
let observabilityWarning;
|
|
198
|
+
if (globalSettings.observability.localTracing) {
|
|
199
|
+
try {
|
|
200
|
+
const observabilityDuckDB = new DuckDBStore({
|
|
201
|
+
id: "mastra-code-observability",
|
|
202
|
+
path: getObservabilityDatabasePath()
|
|
203
|
+
});
|
|
204
|
+
await observabilityDuckDB.db.getConnection();
|
|
205
|
+
observabilityDomain = observabilityDuckDB.observability;
|
|
206
|
+
} catch (err) {
|
|
207
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
208
|
+
const isLockError = /lock|locked|busy/i.test(message);
|
|
209
|
+
if (isLockError) {
|
|
210
|
+
observabilityWarning = "Observability unavailable \u2014 another MastraCode instance holds the database lock. Traces, scores, and feedback will not be recorded in this session.";
|
|
211
|
+
} else {
|
|
212
|
+
observabilityWarning = `Observability unavailable \u2014 DuckDB initialization failed: ${message}`;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const harnessStorage = new InMemoryHarness();
|
|
217
|
+
const storage = new MastraCompositeStore({
|
|
218
|
+
id: "mastra-code-storage",
|
|
219
|
+
default: storageResult.storage,
|
|
220
|
+
domains: {
|
|
221
|
+
...observabilityDomain ? { observability: observabilityDomain } : {},
|
|
222
|
+
harness: harnessStorage
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
const observability = new Observability({
|
|
226
|
+
configs: {
|
|
227
|
+
default: {
|
|
228
|
+
serviceName: "mastracode",
|
|
229
|
+
// Only these requestContext keys are stored on spans — prevents leaking
|
|
230
|
+
// large objects (controller state, workspace, env vars) into trace data.
|
|
231
|
+
// Use dot-notation because these are nested inside the 'controller' key.
|
|
232
|
+
//
|
|
233
|
+
// Session identifiers:
|
|
234
|
+
// threadId, resourceId, session.modeId, agentControllerId
|
|
235
|
+
// Environment & project:
|
|
236
|
+
// state.projectName, state.gitBranch
|
|
237
|
+
// Model configuration:
|
|
238
|
+
// session.modelId, state.subagentModelId
|
|
239
|
+
// Agent settings:
|
|
240
|
+
// state.yolo, state.thinkingLevel, state.smartEditing
|
|
241
|
+
// Observational memory settings:
|
|
242
|
+
// state.omScope, state.observerModelId, state.reflectorModelId,
|
|
243
|
+
// state.observationThreshold, state.reflectionThreshold
|
|
244
|
+
requestContextKeys: [
|
|
245
|
+
// Session identifiers
|
|
246
|
+
"controller.threadId",
|
|
247
|
+
"controller.resourceId",
|
|
248
|
+
"controller.session.modeId",
|
|
249
|
+
"controller.controllerId",
|
|
250
|
+
// Environment & project
|
|
251
|
+
"controller.state.projectName",
|
|
252
|
+
"controller.state.gitBranch",
|
|
253
|
+
// Model configuration
|
|
254
|
+
"controller.session.modelId",
|
|
255
|
+
"controller.state.subagentModelId",
|
|
256
|
+
// Agent settings
|
|
257
|
+
"controller.state.yolo",
|
|
258
|
+
"controller.state.thinkingLevel",
|
|
259
|
+
"controller.state.smartEditing",
|
|
260
|
+
// Observational memory settings
|
|
261
|
+
"controller.state.omScope",
|
|
262
|
+
"controller.state.observerModelId",
|
|
263
|
+
"controller.state.reflectorModelId",
|
|
264
|
+
"controller.state.observationThreshold",
|
|
265
|
+
"controller.state.reflectionThreshold"
|
|
266
|
+
],
|
|
267
|
+
exporters: [
|
|
268
|
+
// Only persist traces locally when DuckDB observability is available
|
|
269
|
+
// (via `/observability local on`). Without this guard the storage
|
|
270
|
+
// exporter falls through to the default libsql backend and silently
|
|
271
|
+
// fills the main database with gigabytes of span data.
|
|
272
|
+
...observabilityDomain ? [new MastraStorageExporter({ strategy: "event-sourced" })] : [],
|
|
273
|
+
new MastraPlatformExporter(resolveCloudObservabilityConfig(globalSettings, authStorage, project.resourceId))
|
|
274
|
+
],
|
|
275
|
+
spanOutputProcessors: [new SensitiveDataFilter()]
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
const vectorStore = await createVectorStore(storageConfig, storageResult.backend);
|
|
280
|
+
const memory = config?.memory === false ? void 0 : config?.memory ?? getDynamicMemory(storage, vectorStore);
|
|
281
|
+
const mcpManager = config?.disableMcp ? void 0 : createMcpManager(project.rootPath, configDir, config?.mcpServers);
|
|
282
|
+
const hookManager = config?.disableHooks ? void 0 : new HookManager(project.rootPath, "session-init", configDir, homeDir);
|
|
283
|
+
const pluginManager = config?.disablePlugins ? void 0 : config?.pluginManager ?? new PluginManager({ projectRoot: project.rootPath, configDir, homeDir });
|
|
284
|
+
const loadedPlugins = pluginManager ? await pluginManager.reload() : [];
|
|
285
|
+
const pluginTools = pluginManager?.getPluginTools() ?? {};
|
|
286
|
+
const outcomeScorer = createOutcomeScorer();
|
|
287
|
+
const efficiencyScorer = createEfficiencyScorer();
|
|
288
|
+
const githubSignals = globalSettings.signals?.experimentalGithubSignals ? new GithubSignals({
|
|
289
|
+
cwd: project.rootPath,
|
|
290
|
+
gitcrawlCommand: process.env.MASTRACODE_GITCRAWL_BIN ?? process.env.GITCRAWL_BIN ?? process.env.MASTRACODE_GITCRAWL_COMMAND ?? process.env.GITCRAWL_COMMAND,
|
|
291
|
+
getNotificationStreamOptions: async ({ resourceId, threadId }) => {
|
|
292
|
+
const session = await controller.getSessionByResource(resourceId) ?? activeSession;
|
|
293
|
+
const modeId = session.mode.get();
|
|
294
|
+
const defaultModeModelId = controller.listModes().find((mode) => mode.id === modeId)?.defaultModelId;
|
|
295
|
+
const modelId = session.model.get() || activeSession?.model.get() || defaultModeModelId || "";
|
|
296
|
+
const requestContext = new RequestContext();
|
|
297
|
+
const agentControllerContext = {
|
|
298
|
+
controllerId: controller.id,
|
|
299
|
+
state: session.state.get(),
|
|
300
|
+
getState: () => session.state.get(),
|
|
301
|
+
setState: (updates) => session.state.set(updates),
|
|
302
|
+
threadId,
|
|
303
|
+
resourceId,
|
|
304
|
+
session: {
|
|
305
|
+
id: session.identity.getId(),
|
|
306
|
+
ownerId: session.identity.getOwnerId(),
|
|
307
|
+
modeId,
|
|
308
|
+
modelId,
|
|
309
|
+
state: {
|
|
310
|
+
get: () => session.state.get(),
|
|
311
|
+
set: (updates) => session.state.set(updates),
|
|
312
|
+
update: (updater) => session.state.update(updater)
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
workspace: controller.getWorkspace(),
|
|
316
|
+
getSubagentModelId: (params) => session.subagents.model.get(params ?? {})
|
|
317
|
+
};
|
|
318
|
+
requestContext.set("controller", agentControllerContext);
|
|
319
|
+
return {
|
|
320
|
+
memory: { thread: threadId, resource: resourceId },
|
|
321
|
+
requestContext,
|
|
322
|
+
maxSteps: 1e3,
|
|
323
|
+
savePerStep: false,
|
|
324
|
+
requireToolApproval: session.state.get().yolo !== true,
|
|
325
|
+
modelSettings: { temperature: 1 }
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}) : void 0;
|
|
329
|
+
const codeAgent = createCodingAgent({
|
|
330
|
+
id: CODE_AGENT_ID,
|
|
331
|
+
name: "Code Agent",
|
|
332
|
+
// Workspace is wired per-request at the AgentController level (see
|
|
333
|
+
// `config.workspace` below), so opt out of the factory's default local
|
|
334
|
+
// workspace. An explicit `undefined` is required: the factory only builds a
|
|
335
|
+
// default when the `workspace` key is absent.
|
|
336
|
+
workspace: void 0,
|
|
337
|
+
instructions: getDynamicInstructions,
|
|
338
|
+
model: getDynamicModel,
|
|
339
|
+
tools: createDynamicTools(mcpManager, config?.extraTools, config?.disabledTools, storage, pluginTools),
|
|
340
|
+
hooks: createToolHooks(hookManager),
|
|
341
|
+
scorers: {
|
|
342
|
+
outcome: {
|
|
343
|
+
scorer: outcomeScorer,
|
|
344
|
+
sampling: { type: "none" }
|
|
345
|
+
},
|
|
346
|
+
efficiency: {
|
|
347
|
+
scorer: efficiencyScorer,
|
|
348
|
+
sampling: { type: "ratio", rate: 0.3 }
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
// TaskSignalProvider bundles the task tools + TaskStateProcessor: it merges
|
|
352
|
+
// the tools into the toolset and registers the task state-signal processor,
|
|
353
|
+
// so the task list persists across turns and survives OM truncation.
|
|
354
|
+
signals: [new TaskSignalProvider(), ...githubSignals ? [githubSignals] : []],
|
|
355
|
+
// Native goal mechanism: the in-loop goal step judges the thread's active
|
|
356
|
+
// objective each qualifying iteration. The judge model is required for any
|
|
357
|
+
// gating to occur; when unset the goal step is a complete no-op. A6 auto-wires
|
|
358
|
+
// the GoalStateProcessor so the `<current-objective>` signal persists across
|
|
359
|
+
// turns. Per-thread overrides live in the ThreadState `goal` record and win
|
|
360
|
+
// over these defaults.
|
|
361
|
+
goal: {
|
|
362
|
+
// Resolve the judge model through mastracode's gateway (a model-resolver
|
|
363
|
+
// function) so provider credentials are injected; returns undefined when no
|
|
364
|
+
// judge model is configured, keeping the goal step a no-op. Bind the same
|
|
365
|
+
// `settingsPath` used above so the judge model and `maxRuns` come from one
|
|
366
|
+
// config (a custom settings file would otherwise diverge).
|
|
367
|
+
judge: (ctx) => getGoalJudgeModel(ctx, config?.settingsPath),
|
|
368
|
+
maxRuns: globalSettings.models.goalMaxTurns ?? 50,
|
|
369
|
+
maxSteps: 1e3,
|
|
370
|
+
prompt: DEFAULT_GOAL_JUDGE_PROMPT,
|
|
371
|
+
// Read-only workspace tools the default goal judge may call to verify the
|
|
372
|
+
// agent's work against the actual filesystem (view, search_content,
|
|
373
|
+
// find_files, file_stat, lsp_inspect) rather than grading prose alone —
|
|
374
|
+
// restoring the original MastraCode judge's verification ability. Resolved
|
|
375
|
+
// per-request from the active workspace (mirrors `judge`).
|
|
376
|
+
tools: getGoalJudgeTools
|
|
377
|
+
},
|
|
378
|
+
inputProcessors: [
|
|
379
|
+
new PlanRejectionAbortProcessor(),
|
|
380
|
+
new AgentsMDInjector({
|
|
381
|
+
getIgnoredInstructionPaths: ({ requestContext }) => {
|
|
382
|
+
const agentControllerContext = requestContext?.get("controller");
|
|
383
|
+
const state = agentControllerContext?.getState();
|
|
384
|
+
return getStaticallyLoadedInstructionPaths(state?.projectPath ?? project.rootPath);
|
|
385
|
+
}
|
|
386
|
+
}),
|
|
387
|
+
new ProviderHistoryCompat()
|
|
388
|
+
],
|
|
389
|
+
errorProcessors: [
|
|
390
|
+
new StreamErrorRetryProcessor({
|
|
391
|
+
matchers: [
|
|
392
|
+
{ match: isBadRequestError, maxRetries: 1, delayMs: 2e3 },
|
|
393
|
+
{
|
|
394
|
+
match: isECONNRESETError,
|
|
395
|
+
maxRetries: MASTRACODE_ECONNRESET_MAX_RETRIES,
|
|
396
|
+
delayMs: ({ retryCount }) => Math.min(
|
|
397
|
+
MASTRACODE_ECONNRESET_RETRY_INITIAL_DELAY_MS * Math.pow(2, retryCount),
|
|
398
|
+
MASTRACODE_ECONNRESET_RETRY_MAX_DELAY_MS
|
|
399
|
+
)
|
|
400
|
+
}
|
|
401
|
+
]
|
|
402
|
+
}),
|
|
403
|
+
new PrefillErrorHandler(),
|
|
404
|
+
new ProviderHistoryCompat()
|
|
405
|
+
]
|
|
406
|
+
});
|
|
407
|
+
const defaultModes = [
|
|
408
|
+
{
|
|
409
|
+
...buildMode,
|
|
410
|
+
metadata: {
|
|
411
|
+
...buildMode.metadata,
|
|
412
|
+
color: mastraBrand.green
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
...planMode,
|
|
417
|
+
metadata: {
|
|
418
|
+
...planMode.metadata,
|
|
419
|
+
color: mastraBrand.purple
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
...fastMode,
|
|
424
|
+
metadata: {
|
|
425
|
+
...fastMode.metadata,
|
|
426
|
+
color: mastraBrand.orange
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
];
|
|
430
|
+
const defaultIntervalHandlers = [
|
|
431
|
+
{
|
|
432
|
+
id: "gateway-sync",
|
|
433
|
+
intervalMs: 5 * 60 * 1e3,
|
|
434
|
+
immediate: false,
|
|
435
|
+
handler: () => syncGateways()
|
|
436
|
+
}
|
|
437
|
+
];
|
|
438
|
+
const intervalHandlers = config?.intervalHandlers ?? defaultIntervalHandlers;
|
|
439
|
+
const anthropicCred = authStorage.get("anthropic");
|
|
440
|
+
const openaiCred = authStorage.get("openai-codex");
|
|
441
|
+
const githubCopilotCred = authStorage.get("github-copilot");
|
|
442
|
+
const startupAccess = {
|
|
443
|
+
anthropic: anthropicCred?.type === "oauth" ? "oauth" : anthropicCred?.type === "api_key" && anthropicCred.key.trim().length > 0 ? "apikey" : false,
|
|
444
|
+
openai: openaiCred?.type === "oauth" ? "oauth" : openaiCred?.type === "api_key" && openaiCred.key.trim().length > 0 ? "apikey" : false,
|
|
445
|
+
cerebras: process.env.CEREBRAS_API_KEY ? "apikey" : false,
|
|
446
|
+
google: process.env.GOOGLE_GENERATIVE_AI_API_KEY ? "apikey" : false,
|
|
447
|
+
deepseek: process.env.DEEPSEEK_API_KEY ? "apikey" : false,
|
|
448
|
+
"github-copilot": githubCopilotCred?.type === "oauth" ? "oauth" : false
|
|
449
|
+
};
|
|
450
|
+
if (mgApiKey) {
|
|
451
|
+
if (!startupAccess.anthropic) startupAccess.anthropic = "apikey";
|
|
452
|
+
if (!startupAccess.openai) startupAccess.openai = "apikey";
|
|
453
|
+
}
|
|
454
|
+
try {
|
|
455
|
+
const registry = PROVIDER_REGISTRY;
|
|
456
|
+
for (const [provider, config2] of Object.entries(registry)) {
|
|
457
|
+
if (startupAccess[provider] === "oauth" || startupAccess[provider] === "apikey") continue;
|
|
458
|
+
if (provider === "anthropic" || provider === "openai") continue;
|
|
459
|
+
const envVars = config2?.apiKeyEnvVar;
|
|
460
|
+
const envVarList = Array.isArray(envVars) ? envVars : envVars ? [envVars] : [];
|
|
461
|
+
if (envVarList.some((envVar) => process.env[envVar])) {
|
|
462
|
+
startupAccess[provider] = "apikey";
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
} catch {
|
|
466
|
+
}
|
|
467
|
+
const builtinPacks = getAvailableModePacks(startupAccess);
|
|
468
|
+
const builtinOmPacks = getAvailableOmPacks(startupAccess);
|
|
469
|
+
const effectiveDefaults = resolveModelDefaults(globalSettings, builtinPacks);
|
|
470
|
+
const effectiveObserverModel = resolveOmRoleModel(globalSettings, "observer", builtinOmPacks);
|
|
471
|
+
const effectiveReflectorModel = resolveOmRoleModel(globalSettings, "reflector", builtinOmPacks);
|
|
472
|
+
const effectiveObservationThreshold = globalSettings.models.omObservationThreshold ?? void 0;
|
|
473
|
+
const effectiveReflectionThreshold = globalSettings.models.omReflectionThreshold ?? void 0;
|
|
474
|
+
const effectiveCavemanObservations = globalSettings.models.omCavemanObservations ?? void 0;
|
|
475
|
+
const effectiveObserveAttachments = globalSettings.models.omObserveAttachments ?? "auto";
|
|
476
|
+
const modes = addPluginToolsToModeAllowlists(
|
|
477
|
+
applyEffectiveDefaultsToModes(config?.modes ? config.modes : defaultModes, effectiveDefaults),
|
|
478
|
+
Object.keys(pluginTools)
|
|
479
|
+
);
|
|
480
|
+
const defaultModeId = modes.find((mode) => mode.metadata?.default === true)?.id ?? modes.find((mode) => mode.id === "build")?.id ?? modes[0]?.id;
|
|
481
|
+
if (!defaultModeId) {
|
|
482
|
+
throw new Error("MastraCode requires at least one mode");
|
|
483
|
+
}
|
|
484
|
+
const globalInitialState = {};
|
|
485
|
+
if (effectiveObserverModel) {
|
|
486
|
+
globalInitialState.observerModelId = effectiveObserverModel;
|
|
487
|
+
}
|
|
488
|
+
if (effectiveReflectorModel) {
|
|
489
|
+
globalInitialState.reflectorModelId = effectiveReflectorModel;
|
|
490
|
+
}
|
|
491
|
+
if (effectiveObservationThreshold !== void 0) {
|
|
492
|
+
globalInitialState.observationThreshold = effectiveObservationThreshold;
|
|
493
|
+
}
|
|
494
|
+
if (effectiveReflectionThreshold !== void 0) {
|
|
495
|
+
globalInitialState.reflectionThreshold = effectiveReflectionThreshold;
|
|
496
|
+
}
|
|
497
|
+
if (effectiveCavemanObservations !== void 0) {
|
|
498
|
+
globalInitialState.cavemanObservations = effectiveCavemanObservations;
|
|
499
|
+
}
|
|
500
|
+
if (effectiveObserveAttachments !== void 0) {
|
|
501
|
+
globalInitialState.observeAttachments = effectiveObserveAttachments;
|
|
502
|
+
}
|
|
503
|
+
if (globalSettings.preferences.yolo !== null) {
|
|
504
|
+
globalInitialState.yolo = globalSettings.preferences.yolo;
|
|
505
|
+
}
|
|
506
|
+
globalInitialState.thinkingLevel = globalSettings.preferences.thinkingLevel;
|
|
507
|
+
if (config?.omScope) {
|
|
508
|
+
globalInitialState.omScope = config.omScope;
|
|
509
|
+
}
|
|
510
|
+
for (const [key, modelId] of Object.entries(globalSettings.models.subagentModels)) {
|
|
511
|
+
if (key === "default" || key === "_default") {
|
|
512
|
+
globalInitialState.subagentModelId = modelId;
|
|
513
|
+
} else {
|
|
514
|
+
globalInitialState[`subagentModelId_${key}`] = modelId;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
const typedStateSchema = stateSchema;
|
|
518
|
+
const controller = new AgentController({
|
|
519
|
+
id: "mastra-code",
|
|
520
|
+
resourceId: project.resourceId,
|
|
521
|
+
storage,
|
|
522
|
+
observability,
|
|
523
|
+
memory,
|
|
524
|
+
pubsub: signalsPubSub,
|
|
525
|
+
stateSchema: typedStateSchema,
|
|
526
|
+
agent: codeAgent,
|
|
527
|
+
subagents: config?.subagents ?? [],
|
|
528
|
+
gateways: [amazonBedrockGateway, mastraCodeGateway],
|
|
529
|
+
workspace: config?.workspace ?? ((args) => getDynamicWorkspace(args)),
|
|
530
|
+
browser: config?.browser,
|
|
531
|
+
idGenerator: config?.idGenerator,
|
|
532
|
+
toolCategoryResolver: getToolCategory,
|
|
533
|
+
initialState: {
|
|
534
|
+
projectPath: project.rootPath,
|
|
535
|
+
projectName: project.name,
|
|
536
|
+
gitBranch: project.gitBranch,
|
|
537
|
+
pluginSkillPaths: loadedPlugins.flatMap((plugin) => plugin.status === "active" ? plugin.skillPaths ?? [] : []),
|
|
538
|
+
pluginCommandPaths: loadedPlugins.flatMap(
|
|
539
|
+
(plugin) => plugin.status === "active" ? plugin.commandPaths ?? [] : []
|
|
540
|
+
),
|
|
541
|
+
pluginInstructions: loadedPlugins.flatMap(
|
|
542
|
+
(plugin) => plugin.status === "active" && plugin.instructions ? [plugin.instructions] : []
|
|
543
|
+
),
|
|
544
|
+
yolo: true,
|
|
545
|
+
...globalInitialState,
|
|
546
|
+
...config?.initialState,
|
|
547
|
+
// configDir must always win over initialState spreads to stay in sync
|
|
548
|
+
// with MCP/hooks/storage which were already initialized with this value.
|
|
549
|
+
configDir
|
|
550
|
+
},
|
|
551
|
+
modes,
|
|
552
|
+
intervalHandlers,
|
|
553
|
+
modelUseCountProvider: () => loadSettings().modelUseCounts,
|
|
554
|
+
modelUseCountTracker: (modelId) => {
|
|
555
|
+
try {
|
|
556
|
+
const settings = loadSettings();
|
|
557
|
+
settings.modelUseCounts[modelId] = (settings.modelUseCounts[modelId] ?? 0) + 1;
|
|
558
|
+
saveSettings(settings);
|
|
559
|
+
} catch (error) {
|
|
560
|
+
console.error("Failed to persist model usage count", error);
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
threadLock: crossProcessPubSub ? void 0 : {
|
|
564
|
+
acquire: acquireThreadLock,
|
|
565
|
+
release: releaseThreadLock
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
return {
|
|
569
|
+
controller,
|
|
570
|
+
storage,
|
|
571
|
+
observability,
|
|
572
|
+
memory,
|
|
573
|
+
mcpManager,
|
|
574
|
+
hookManager,
|
|
575
|
+
pluginManager,
|
|
576
|
+
loadedPlugins,
|
|
577
|
+
pluginTools,
|
|
578
|
+
signalsPubSub,
|
|
579
|
+
authStorage,
|
|
580
|
+
resolveModel,
|
|
581
|
+
storageWarning,
|
|
582
|
+
observabilityWarning,
|
|
583
|
+
builtinPacks,
|
|
584
|
+
builtinOmPacks,
|
|
585
|
+
effectiveDefaults,
|
|
586
|
+
githubSignals,
|
|
587
|
+
// Identity for the single local session (Case 3). Servers ignore these and
|
|
588
|
+
// mint per-request sessions with client-supplied resourceIds instead.
|
|
589
|
+
sessionId,
|
|
590
|
+
ownerId,
|
|
591
|
+
// Lets the composition layer publish the created session back into the
|
|
592
|
+
// config closures (e.g. notification stream options read it lazily).
|
|
593
|
+
setActiveSession: (session) => {
|
|
594
|
+
activeSession = session;
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
async function wireSessionConcerns(base, session) {
|
|
599
|
+
const { hookManager, githubSignals } = base;
|
|
600
|
+
base.setActiveSession(session);
|
|
601
|
+
if (hookManager) {
|
|
602
|
+
session.subscribe((event) => {
|
|
603
|
+
if (event.type === "thread_changed") {
|
|
604
|
+
hookManager.setSessionId(event.threadId);
|
|
605
|
+
} else if (event.type === "thread_created") {
|
|
606
|
+
hookManager.setSessionId(event.thread.id);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
if (githubSignals) {
|
|
611
|
+
const startGithubPollingForCurrentThread = async (threadId) => {
|
|
612
|
+
if (!threadId) return;
|
|
613
|
+
githubSignals.stopAllPolling();
|
|
614
|
+
try {
|
|
615
|
+
const threads = await session.thread.list({ allResources: true });
|
|
616
|
+
const thread = threads.find((item) => item.id === threadId);
|
|
617
|
+
await githubSignals.startPollingForThread(
|
|
618
|
+
{
|
|
619
|
+
threadId,
|
|
620
|
+
resourceId: thread?.resourceId ?? session.identity.getResourceId()
|
|
621
|
+
},
|
|
622
|
+
{ pollImmediately: true }
|
|
623
|
+
);
|
|
624
|
+
} catch (error) {
|
|
625
|
+
console.warn("Failed to start GitHub PR polling:", error);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
session.subscribe((event) => {
|
|
629
|
+
if (event.type === "thread_changed") void startGithubPollingForCurrentThread(event.threadId);
|
|
630
|
+
else if (event.type === "thread_created") void startGithubPollingForCurrentThread(event.thread.id);
|
|
631
|
+
});
|
|
632
|
+
void startGithubPollingForCurrentThread(session.thread.getId());
|
|
633
|
+
}
|
|
634
|
+
const omThreadStateSession = session;
|
|
635
|
+
attachOMThreadStatePersistence(omThreadStateSession);
|
|
636
|
+
await restoreOMThreadStateForCurrentThread(omThreadStateSession).catch(() => {
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
async function bootLocalAgentController(config) {
|
|
640
|
+
const base = await createMastraCodeAgentController(config);
|
|
641
|
+
const { controller, sessionId, ownerId } = base;
|
|
642
|
+
await controller.init();
|
|
643
|
+
await controller.getMastra()?.startWorkers();
|
|
644
|
+
const session = await controller.createSession({ id: sessionId, ownerId });
|
|
645
|
+
await wireSessionConcerns(base, session);
|
|
646
|
+
return { ...base, session };
|
|
647
|
+
}
|
|
648
|
+
async function mountAgentControllerOnMastra(config) {
|
|
649
|
+
const prepared = await prepareAgentControllerMount(config);
|
|
650
|
+
if (config?.mastra) {
|
|
651
|
+
prepared.base.controller.__registerMastra(config.mastra);
|
|
652
|
+
await prepared.finalize();
|
|
653
|
+
return { ...prepared.base, mastra: config.mastra };
|
|
654
|
+
}
|
|
655
|
+
const mastra = new Mastra(prepared.mastraArgs);
|
|
656
|
+
await prepared.finalize();
|
|
657
|
+
return { ...prepared.base, mastra };
|
|
658
|
+
}
|
|
659
|
+
async function prepareAgentControllerMount(config) {
|
|
660
|
+
const base = await createMastraCodeAgentController(config);
|
|
661
|
+
const { controller, storage, authStorage } = base;
|
|
662
|
+
const controllerId = config?.controllerId ?? controller.id;
|
|
663
|
+
const apiRoutes = config?.buildApiRoutes?.({ controller, authStorage });
|
|
664
|
+
const extraServerConfig = config?.buildServerConfig?.({ controller, authStorage });
|
|
665
|
+
const serverConfig = {
|
|
666
|
+
...extraServerConfig,
|
|
667
|
+
...apiRoutes?.length ? { apiRoutes } : {}
|
|
668
|
+
};
|
|
669
|
+
const mastraArgs = {
|
|
670
|
+
agentControllers: { [controllerId]: controller },
|
|
671
|
+
storage,
|
|
672
|
+
...Object.keys(serverConfig).length ? { server: serverConfig } : {}
|
|
673
|
+
};
|
|
674
|
+
const finalize = async () => {
|
|
675
|
+
await controller.init();
|
|
676
|
+
await controller.getMastra()?.startWorkers();
|
|
677
|
+
};
|
|
678
|
+
return { base, mastraArgs, finalize };
|
|
679
|
+
}
|
|
680
|
+
const createMastraCode = bootLocalAgentController;
|
|
681
|
+
import {
|
|
682
|
+
runMC,
|
|
683
|
+
runMCCli,
|
|
684
|
+
hasHeadlessFlag,
|
|
685
|
+
autoApprovePolicy,
|
|
686
|
+
denyPolicy,
|
|
687
|
+
permissionModeToPolicy,
|
|
688
|
+
formatHuman,
|
|
689
|
+
formatJsonl,
|
|
690
|
+
renderTextResult,
|
|
691
|
+
renderJsonResult
|
|
692
|
+
} from "./headless/index.js";
|
|
693
|
+
export {
|
|
694
|
+
autoApprovePolicy,
|
|
695
|
+
bootLocalAgentController,
|
|
696
|
+
createAuthStorage,
|
|
697
|
+
createMastraCode,
|
|
698
|
+
createMastraCodeAgentController,
|
|
699
|
+
denyPolicy,
|
|
700
|
+
formatHuman,
|
|
701
|
+
formatJsonl,
|
|
702
|
+
hasHeadlessFlag,
|
|
703
|
+
mountAgentControllerOnMastra,
|
|
704
|
+
permissionModeToPolicy,
|
|
705
|
+
prepareAgentControllerMount,
|
|
706
|
+
renderJsonResult,
|
|
707
|
+
renderTextResult,
|
|
708
|
+
runMC,
|
|
709
|
+
runMCCli,
|
|
710
|
+
wireSessionConcerns
|
|
711
|
+
};
|
|
712
|
+
//# sourceMappingURL=index.js.map
|