@mastra/code-sdk 0.0.0-esbuild-bundle-worker-20260807173433
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 +1349 -0
- package/LICENSE.md +30 -0
- package/README.md +70 -0
- package/dist/acp/agent.d.ts +35 -0
- package/dist/acp/agent.d.ts.map +1 -0
- package/dist/acp/agent.js +161 -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 +214 -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 +65 -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 +35 -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 +2 -0
- package/dist/agents/credential-resolver.d.ts +51 -0
- package/dist/agents/credential-resolver.d.ts.map +1 -0
- package/dist/agents/credential-resolver.js +52 -0
- package/dist/agents/credential-resolver.js.map +1 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.d.ts.map +1 -0
- package/dist/agents/custom-provider-source.js +25 -0
- package/dist/agents/custom-provider-source.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 +32 -0
- package/dist/agents/instructions.js.map +1 -0
- package/dist/agents/mastracode-gateway.d.ts +74 -0
- package/dist/agents/mastracode-gateway.d.ts.map +1 -0
- package/dist/agents/mastracode-gateway.js +400 -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 +116 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/model.d.ts +59 -0
- package/dist/agents/model.d.ts.map +1 -0
- package/dist/agents/model.js +132 -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 +44 -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 +39 -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 +37 -0
- package/dist/agents/modes/plan.js.map +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts +61 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
- package/dist/agents/prompts/agent-instructions.js +201 -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 +76 -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 +26 -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 +65 -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 +23 -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 +111 -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 +149 -0
- package/dist/agents/prompts/tool-guidance.js.map +1 -0
- package/dist/agents/sandbox-filesystem.d.ts +99 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
- package/dist/agents/sandbox-filesystem.js +328 -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 +15 -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 +107 -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 +87 -0
- package/dist/agents/tool-availability.js.map +1 -0
- package/dist/agents/tools.d.ts +19 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +105 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/workspace.d.ts +32 -0
- package/dist/agents/workspace.d.ts.map +1 -0
- package/dist/agents/workspace.js +251 -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 +163 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.d.ts.map +1 -0
- package/dist/auth/authorization-input.js +42 -0
- package/dist/auth/authorization-input.js.map +1 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.d.ts.map +1 -0
- package/dist/auth/device-code.js +129 -0
- package/dist/auth/device-code.js.map +1 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +6 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +32 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.d.ts.map +1 -0
- package/dist/auth/providers/anthropic.js +126 -0
- package/dist/auth/providers/anthropic.js.map +1 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.d.ts.map +1 -0
- package/dist/auth/providers/github-copilot.js +340 -0
- package/dist/auth/providers/github-copilot.js.map +1 -0
- package/dist/auth/providers/openai-codex.d.ts +139 -0
- package/dist/auth/providers/openai-codex.d.ts.map +1 -0
- package/dist/auth/providers/openai-codex.js +519 -0
- package/dist/auth/providers/openai-codex.js.map +1 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.d.ts.map +1 -0
- package/dist/auth/providers/xai.js +205 -0
- package/dist/auth/providers/xai.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 +197 -0
- package/dist/auth/storage.js.map +1 -0
- package/dist/auth/types.d.ts +89 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.d.ts.map +1 -0
- package/dist/clipboard/index.js +226 -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 +18 -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 +22 -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 +161 -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 +5 -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 +73 -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 +259 -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 +60 -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 +3 -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 +347 -0
- package/dist/evals/scorers/outcome.js.map +1 -0
- package/dist/goal-manager.d.ts +78 -0
- package/dist/goal-manager.d.ts.map +1 -0
- package/dist/goal-manager.js +273 -0
- package/dist/goal-manager.js.map +1 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.d.ts.map +1 -0
- package/dist/goal-signal.js +17 -0
- package/dist/goal-signal.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 +195 -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 +190 -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 +89 -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 +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.d.ts.map +1 -0
- package/dist/headless/policy.js +42 -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 +346 -0
- package/dist/headless/run-mc.js.map +1 -0
- package/dist/headless/types.d.ts +158 -0
- package/dist/headless/types.d.ts.map +1 -0
- package/dist/headless/types.js +18 -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 +73 -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 +128 -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 +5 -0
- package/dist/hooks/manager.d.ts +47 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +225 -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 +8 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +258 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +740 -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 +21 -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 +251 -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 +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.d.ts.map +1 -0
- package/dist/lsp/language.js +44 -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 +82 -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 +159 -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 +55 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/mcp/config.d.ts +54 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +240 -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 +3 -0
- package/dist/mcp/manager.d.ts +98 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +612 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/state.d.ts +33 -0
- package/dist/mcp/state.d.ts.map +1 -0
- package/dist/mcp/state.js +88 -0
- package/dist/mcp/state.js.map +1 -0
- package/dist/mcp/types.d.ts +120 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +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 +17 -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 +30 -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 +3 -0
- package/dist/onboarding/om-settings.d.ts +25 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -0
- package/dist/onboarding/om-settings.js +47 -0
- package/dist/onboarding/om-settings.js.map +1 -0
- package/dist/onboarding/packs.d.ts +46 -0
- package/dist/onboarding/packs.d.ts.map +1 -0
- package/dist/onboarding/packs.js +160 -0
- package/dist/onboarding/packs.js.map +1 -0
- package/dist/onboarding/settings.d.ts +338 -0
- package/dist/onboarding/settings.d.ts.map +1 -0
- package/dist/onboarding/settings.js +673 -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 +132 -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 +28 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.d.ts.map +1 -0
- package/dist/plugins/dependencies.js +88 -0
- package/dist/plugins/dependencies.js.map +1 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.d.ts.map +1 -0
- package/dist/plugins/install.js +190 -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 +206 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +64 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +384 -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 +50 -0
- package/dist/plugins/manifest.js.map +1 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.d.ts.map +1 -0
- package/dist/plugins/package-link.js +61 -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 +25 -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 +112 -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 +116 -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/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 +54 -0
- package/dist/processors/plan-rejection-abort.js.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.js +152 -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 +83 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/claude-max.d.ts +52 -0
- package/dist/providers/claude-max.d.ts.map +1 -0
- package/dist/providers/claude-max.js +171 -0
- package/dist/providers/claude-max.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +265 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +72 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +302 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/providers/xai.js +70 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/schema.d.ts +192 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +98 -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 +21 -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 +52 -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 +3 -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 +79 -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 +32 -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 +61 -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 +78 -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 +59 -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 +172 -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 +61 -0
- package/dist/utils/gateway-sync.js.map +1 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.d.ts.map +1 -0
- package/dist/utils/path-security.js +10 -0
- package/dist/utils/path-security.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 +62 -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 +117 -0
- package/dist/utils/plans.js.map +1 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +364 -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 +122 -0
- package/dist/utils/signals-pubsub.js.map +1 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.d.ts.map +1 -0
- package/dist/utils/slash-command-loader.js +141 -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 +105 -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 +96 -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 +121 -0
- package/dist/utils/storage-factory.js.map +1 -0
- package/dist/utils/storage-maintenance.d.ts +103 -0
- package/dist/utils/storage-maintenance.d.ts.map +1 -0
- package/dist/utils/storage-maintenance.js +274 -0
- package/dist/utils/storage-maintenance.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 +112 -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 +101 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/dist/utils/update-check.js +383 -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 +144 -0
- package/dist/voice/stt-registry.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { getLocalPlansRelativeDir, isPlanFilePath } from "../utils/plans.js";
|
|
2
|
+
import { MC_TOOLS, TOOL_NAME_OVERRIDES } from "../tool-names.js";
|
|
3
|
+
import { WORKSPACE_TOOLS } from "@mastra/core/workspace";
|
|
4
|
+
//#region src/agents/tool-availability.ts
|
|
5
|
+
const PLAN_MODE_WRITE_TOOL_NAMES = /* @__PURE__ */ new Set([WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE, WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE]);
|
|
6
|
+
function getRequestContextValue(requestContext, key) {
|
|
7
|
+
if (!requestContext) return void 0;
|
|
8
|
+
if (typeof requestContext.get === "function") return requestContext.get(key);
|
|
9
|
+
return requestContext[key];
|
|
10
|
+
}
|
|
11
|
+
function getHarnessContext(context) {
|
|
12
|
+
const requestContext = context?.requestContext;
|
|
13
|
+
const harness = getRequestContextValue(requestContext, "harness");
|
|
14
|
+
return harness && typeof harness === "object" ? harness : void 0;
|
|
15
|
+
}
|
|
16
|
+
function getHarnessState(harness) {
|
|
17
|
+
const state = harness?.session?.state?.get?.();
|
|
18
|
+
return state && typeof state === "object" ? state : void 0;
|
|
19
|
+
}
|
|
20
|
+
function getHarnessModeId(harness) {
|
|
21
|
+
const modeId = harness?.session?.modeId ?? getHarnessState(harness)?.modeId;
|
|
22
|
+
return typeof modeId === "string" ? modeId : void 0;
|
|
23
|
+
}
|
|
24
|
+
function getHarnessProjectPath(harness) {
|
|
25
|
+
const projectPath = getHarnessState(harness)?.projectPath;
|
|
26
|
+
return typeof projectPath === "string" ? projectPath : void 0;
|
|
27
|
+
}
|
|
28
|
+
function getToolInputPath(input) {
|
|
29
|
+
const toolPath = input?.path;
|
|
30
|
+
return typeof toolPath === "string" ? toolPath : void 0;
|
|
31
|
+
}
|
|
32
|
+
const PLAN_DIR_HINT = `${getLocalPlansRelativeDir()}/`;
|
|
33
|
+
function guardPlanModePlanFileWrites({ workspaceToolName, input, context }) {
|
|
34
|
+
if (!PLAN_MODE_WRITE_TOOL_NAMES.has(workspaceToolName)) return;
|
|
35
|
+
const harness = getHarnessContext(context);
|
|
36
|
+
if (getHarnessModeId(harness) !== "plan") return;
|
|
37
|
+
const projectPath = getHarnessProjectPath(harness);
|
|
38
|
+
const inputPath = getToolInputPath(input);
|
|
39
|
+
if (!projectPath || !inputPath) return {
|
|
40
|
+
proceed: false,
|
|
41
|
+
output: `Plan mode can only write plan files inside ${PLAN_DIR_HINT}.`
|
|
42
|
+
};
|
|
43
|
+
if (isPlanFilePath(projectPath, inputPath)) return;
|
|
44
|
+
return {
|
|
45
|
+
proceed: false,
|
|
46
|
+
output: `Plan mode can only write plan files inside ${PLAN_DIR_HINT}. Refusing to edit ${inputPath}.`
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const MASTRACODE_WORKSPACE_TOOLS = {
|
|
50
|
+
...TOOL_NAME_OVERRIDES,
|
|
51
|
+
hooks: { beforeToolCall: guardPlanModePlanFileWrites }
|
|
52
|
+
};
|
|
53
|
+
const PLAN_MODE_AVAILABLE_TOOLS = [
|
|
54
|
+
MC_TOOLS.VIEW,
|
|
55
|
+
MC_TOOLS.FIND_FILES,
|
|
56
|
+
MC_TOOLS.SEARCH_CONTENT,
|
|
57
|
+
MC_TOOLS.FILE_STAT,
|
|
58
|
+
MC_TOOLS.LSP_INSPECT,
|
|
59
|
+
MC_TOOLS.WRITE_FILE,
|
|
60
|
+
MC_TOOLS.STRING_REPLACE_LSP,
|
|
61
|
+
"ask_user",
|
|
62
|
+
"submit_plan",
|
|
63
|
+
"task_write",
|
|
64
|
+
"task_update",
|
|
65
|
+
"task_complete",
|
|
66
|
+
"task_check",
|
|
67
|
+
MC_TOOLS.NOTIFICATION_INBOX
|
|
68
|
+
];
|
|
69
|
+
const EXPLORE_MODE_AVAILABLE_TOOLS = [
|
|
70
|
+
MC_TOOLS.VIEW,
|
|
71
|
+
MC_TOOLS.FIND_FILES,
|
|
72
|
+
MC_TOOLS.SEARCH_CONTENT,
|
|
73
|
+
MC_TOOLS.FILE_STAT,
|
|
74
|
+
MC_TOOLS.LSP_INSPECT,
|
|
75
|
+
"ask_user"
|
|
76
|
+
];
|
|
77
|
+
const GOAL_JUDGE_READONLY_TOOLS = [
|
|
78
|
+
MC_TOOLS.VIEW,
|
|
79
|
+
MC_TOOLS.SEARCH_CONTENT,
|
|
80
|
+
MC_TOOLS.FIND_FILES,
|
|
81
|
+
MC_TOOLS.FILE_STAT,
|
|
82
|
+
MC_TOOLS.LSP_INSPECT
|
|
83
|
+
];
|
|
84
|
+
//#endregion
|
|
85
|
+
export { EXPLORE_MODE_AVAILABLE_TOOLS, GOAL_JUDGE_READONLY_TOOLS, MASTRACODE_WORKSPACE_TOOLS, PLAN_MODE_AVAILABLE_TOOLS, guardPlanModePlanFileWrites };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=tool-availability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-availability.js","names":[],"sources":["../../src/agents/tool-availability.ts"],"sourcesContent":["import { WORKSPACE_TOOLS } from '@mastra/core/workspace';\nimport type { WorkspaceToolHookContext, WorkspaceToolsConfig } from '@mastra/core/workspace';\nimport { MC_TOOLS, TOOL_NAME_OVERRIDES } from '../tool-names.js';\nimport { getLocalPlansRelativeDir, isPlanFilePath } from '../utils/plans.js';\n\nconst PLAN_MODE_WRITE_TOOL_NAMES = new Set<string>([\n WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE,\n WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE,\n]);\n\nfunction getRequestContextValue(requestContext: unknown, key: string): unknown {\n if (!requestContext) return undefined;\n if (typeof (requestContext as { get?: unknown }).get === 'function') {\n return (requestContext as { get: (key: string) => unknown }).get(key);\n }\n return (requestContext as Record<string, unknown>)[key];\n}\n\n/**\n * Subset of the real `HarnessRequestContext` shape (see\n * packages/core/src/harness/types.ts). The mode is a string property\n * (`session.modeId`) and live state is read via `session.state.get()`.\n */\ninterface PlanModeGuardHarness {\n session?: {\n modeId?: unknown;\n state?: { get?: () => unknown };\n };\n}\n\nfunction getHarnessContext(context: unknown): PlanModeGuardHarness | undefined {\n const requestContext = (context as { requestContext?: unknown } | undefined)?.requestContext;\n const harness = getRequestContextValue(requestContext, 'harness');\n return harness && typeof harness === 'object' ? (harness as PlanModeGuardHarness) : undefined;\n}\n\nfunction getHarnessState(harness: PlanModeGuardHarness | undefined): Record<string, unknown> | undefined {\n const state = harness?.session?.state?.get?.();\n return state && typeof state === 'object' ? (state as Record<string, unknown>) : undefined;\n}\n\nfunction getHarnessModeId(harness: PlanModeGuardHarness | undefined): string | undefined {\n const modeId = harness?.session?.modeId ?? getHarnessState(harness)?.modeId;\n return typeof modeId === 'string' ? modeId : undefined;\n}\n\nfunction getHarnessProjectPath(harness: PlanModeGuardHarness | undefined): string | undefined {\n const projectPath = getHarnessState(harness)?.projectPath;\n return typeof projectPath === 'string' ? projectPath : undefined;\n}\n\nfunction getToolInputPath(input: unknown): string | undefined {\n const toolPath = (input as { path?: unknown } | undefined)?.path;\n return typeof toolPath === 'string' ? toolPath : undefined;\n}\n\nconst PLAN_DIR_HINT = `${getLocalPlansRelativeDir()}/`;\n\nexport function guardPlanModePlanFileWrites({ workspaceToolName, input, context }: WorkspaceToolHookContext) {\n if (!PLAN_MODE_WRITE_TOOL_NAMES.has(workspaceToolName)) return;\n\n const harness = getHarnessContext(context);\n if (getHarnessModeId(harness) !== 'plan') return;\n\n const projectPath = getHarnessProjectPath(harness);\n const inputPath = getToolInputPath(input);\n if (!projectPath || !inputPath) {\n return {\n proceed: false as const,\n output: `Plan mode can only write plan files inside ${PLAN_DIR_HINT}.`,\n };\n }\n\n // Plan mode may write any `.md` file directly inside `.mastracode/plans/`, but\n // nothing else in the project.\n if (isPlanFilePath(projectPath, inputPath)) return;\n\n return {\n proceed: false as const,\n output: `Plan mode can only write plan files inside ${PLAN_DIR_HINT}. Refusing to edit ${inputPath}.`,\n };\n}\n\nexport const MASTRACODE_WORKSPACE_TOOLS: WorkspaceToolsConfig = {\n ...TOOL_NAME_OVERRIDES,\n hooks: {\n beforeToolCall: guardPlanModePlanFileWrites,\n },\n};\n\nexport const PLAN_MODE_AVAILABLE_TOOLS: readonly string[] = [\n // Read-only exploration tools\n MC_TOOLS.VIEW,\n MC_TOOLS.FIND_FILES,\n MC_TOOLS.SEARCH_CONTENT,\n MC_TOOLS.FILE_STAT,\n MC_TOOLS.LSP_INSPECT,\n // Plan file writing. Tool hooks enforce that these can only write `.md`\n // files inside `.mastracode/plans/` while the session is in plan mode.\n MC_TOOLS.WRITE_FILE,\n MC_TOOLS.STRING_REPLACE_LSP,\n // Plan delivery tools\n 'ask_user',\n 'submit_plan',\n // Task tools for plan-stage tracking\n 'task_write',\n 'task_update',\n 'task_complete',\n 'task_check',\n // Notification access\n MC_TOOLS.NOTIFICATION_INBOX,\n];\n\nexport const EXPLORE_MODE_AVAILABLE_TOOLS: readonly string[] = [\n MC_TOOLS.VIEW,\n MC_TOOLS.FIND_FILES,\n MC_TOOLS.SEARCH_CONTENT,\n MC_TOOLS.FILE_STAT,\n MC_TOOLS.LSP_INSPECT,\n 'ask_user',\n];\n\nexport const GOAL_JUDGE_READONLY_TOOLS: readonly string[] = [\n MC_TOOLS.VIEW,\n MC_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AE1C,MAAM,cAAc,sBAAsB,OAAO;CACjD,MAAM,YAAY,iBAAiB,KAAK;CACxC,IAAI,CAAC,eAAe,CAAC,WACnB,OAAO;EACL,SAAS;EACT,QAAQ,8CAA8C,cAAc;CACtE;CAKF,IAAI,eAAe,aAAa,SAAS,GAAG;CAE5C,OAAO;EACL,SAAS;EACT,QAAQ,8CAA8C,cAAc,qBAAqB,UAAU;CACrG;AACF;AAEA,MAAa,6BAAmD;CAC9D,GAAG;CACH,OAAO,EACL,gBAAgB,4BAClB;AACF;AAEA,MAAa,4BAA+C;CAE1D,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CAGT,SAAS;CACT,SAAS;CAET;CACA;CAEA;CACA;CACA;CACA;CAEA,SAAS;AACX;AAEA,MAAa,+BAAkD;CAC7D,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT;AACF;AAEA,MAAa,4BAA+C;CAC1D,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;AACX"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
2
|
+
import type { MastraCompositeStore } from '@mastra/core/storage';
|
|
3
|
+
import type { ToolAfterHookContext, ToolHooks } from '@mastra/core/tools';
|
|
4
|
+
import type { HookManager } from '../hooks/index.js';
|
|
5
|
+
import type { McpManager } from '../mcp/index.js';
|
|
6
|
+
/** Minimal shape for tools passed to createDynamicTools. */
|
|
7
|
+
export type ToolLike = {
|
|
8
|
+
execute?: (...args: any[]) => Promise<unknown> | unknown;
|
|
9
|
+
} & Record<string, any>;
|
|
10
|
+
export type PostToolObserver = (context: ToolAfterHookContext) => void | Promise<void>;
|
|
11
|
+
export declare function createToolHooks(hookManager?: HookManager, postToolObserver?: PostToolObserver): ToolHooks | undefined;
|
|
12
|
+
type DynamicToolProvider = Record<string, ToolLike | undefined> | ((ctx: {
|
|
13
|
+
requestContext: RequestContext;
|
|
14
|
+
}) => Record<string, ToolLike | undefined> | Promise<Record<string, ToolLike | undefined>>);
|
|
15
|
+
export declare function createDynamicTools(mcpManager?: McpManager, extraTools?: DynamicToolProvider, disabledTools?: string[], storage?: MastraCompositeStore, pluginTools?: Record<string, ToolLike>): ({ requestContext, }: {
|
|
16
|
+
requestContext: RequestContext;
|
|
17
|
+
}) => Record<string, ToolLike> | Promise<Record<string, ToolLike>>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/agents/tools.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKlD,4DAA4D;AAC5D,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC1D,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAwCxB,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvF,wBAAgB,eAAe,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,SAAS,GAAG,SAAS,CAoCrH;AAED,KAAK,mBAAmB,GACpB,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,GACpC,CAAC,CAAC,GAAG,EAAE;IACL,cAAc,EAAE,cAAc,CAAC;CAChC,KAAK,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAEhG,wBAAgB,kBAAkB,CAChC,UAAU,CAAC,EAAE,UAAU,EACvB,UAAU,CAAC,EAAE,mBAAmB,EAChC,aAAa,CAAC,EAAE,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE,oBAAoB,EAC9B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAEN,qBAE7B;IACD,cAAc,EAAE,cAAc,CAAC;CAChC,KAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAqFjE"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createWebExtractTool, createWebSearchTool, hasTavilyKey } from "../tools/web-search.js";
|
|
2
|
+
import { MC_TOOLS } from "../tool-names.js";
|
|
3
|
+
import { requestSandboxAccessTool } from "../tools/request-sandbox-access.js";
|
|
4
|
+
import "../tools/index.js";
|
|
5
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
6
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
7
|
+
import { NotificationsStorage, createNotificationInboxTool } from "@mastra/core/notifications";
|
|
8
|
+
//#region src/agents/tools.ts
|
|
9
|
+
var LazyNotificationsStorage = class extends NotificationsStorage {
|
|
10
|
+
storage;
|
|
11
|
+
constructor(storage) {
|
|
12
|
+
super();
|
|
13
|
+
this.storage = storage;
|
|
14
|
+
}
|
|
15
|
+
async getNotificationsStorage() {
|
|
16
|
+
const notifications = await this.storage.getStore("notifications");
|
|
17
|
+
if (!notifications) throw new Error("notification_inbox requires a notifications storage domain");
|
|
18
|
+
return notifications;
|
|
19
|
+
}
|
|
20
|
+
async createNotification(input) {
|
|
21
|
+
return (await this.getNotificationsStorage()).createNotification(input);
|
|
22
|
+
}
|
|
23
|
+
async listNotifications(input) {
|
|
24
|
+
return (await this.getNotificationsStorage()).listNotifications(input);
|
|
25
|
+
}
|
|
26
|
+
async listDueNotifications(input) {
|
|
27
|
+
return (await this.getNotificationsStorage()).listDueNotifications(input);
|
|
28
|
+
}
|
|
29
|
+
async getNotification(input) {
|
|
30
|
+
return (await this.getNotificationsStorage()).getNotification(input);
|
|
31
|
+
}
|
|
32
|
+
async updateNotification(input) {
|
|
33
|
+
return (await this.getNotificationsStorage()).updateNotification(input);
|
|
34
|
+
}
|
|
35
|
+
async dangerouslyClearAll() {
|
|
36
|
+
return (await this.getNotificationsStorage()).dangerouslyClearAll();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
function createToolHooks(hookManager, postToolObserver) {
|
|
40
|
+
if (!hookManager && !postToolObserver) return void 0;
|
|
41
|
+
return {
|
|
42
|
+
beforeToolCall: async ({ toolName, input }) => {
|
|
43
|
+
if (!hookManager) return;
|
|
44
|
+
const preResult = await hookManager.runPreToolUse(toolName, input);
|
|
45
|
+
if (!preResult.allowed) return {
|
|
46
|
+
proceed: false,
|
|
47
|
+
output: { error: preResult.blockReason ?? `Blocked by PreToolUse hook for tool "${toolName}"` }
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
afterToolCall: async (context) => {
|
|
51
|
+
const { toolName, input, output, error } = context;
|
|
52
|
+
if (hookManager) {
|
|
53
|
+
const failed = error !== void 0;
|
|
54
|
+
await hookManager.runPostToolUse(toolName, input, failed ? { error: error instanceof Error ? error.message : String(error) } : output, failed).catch(() => void 0);
|
|
55
|
+
}
|
|
56
|
+
await Promise.resolve().then(() => postToolObserver?.(context)).catch((error) => {
|
|
57
|
+
console.warn(`[MastraCode] Post-tool observer failed for ${toolName}.`, error);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function createDynamicTools(mcpManager, extraTools, disabledTools, storage, pluginTools) {
|
|
63
|
+
return function getDynamicTools({ requestContext }) {
|
|
64
|
+
const ctx = requestContext.get("controller");
|
|
65
|
+
const state = ctx?.getState();
|
|
66
|
+
const modelId = ctx?.session?.modelId;
|
|
67
|
+
const isAnthropicModel = modelId?.startsWith("anthropic/");
|
|
68
|
+
const isOpenAIModel = modelId?.startsWith("openai/");
|
|
69
|
+
const tools = { request_access: requestSandboxAccessTool };
|
|
70
|
+
if (storage) tools[MC_TOOLS.NOTIFICATION_INBOX] = createNotificationInboxTool({ storage: new LazyNotificationsStorage(storage) });
|
|
71
|
+
if (hasTavilyKey()) {
|
|
72
|
+
tools.web_search = createWebSearchTool();
|
|
73
|
+
tools.web_extract = createWebExtractTool();
|
|
74
|
+
} else if (isAnthropicModel) tools.web_search = createAnthropic({}).tools.webSearch_20250305();
|
|
75
|
+
else if (isOpenAIModel) tools.web_search = createOpenAI({}).tools.webSearch();
|
|
76
|
+
if (mcpManager) {
|
|
77
|
+
const mcpTools = mcpManager.getTools();
|
|
78
|
+
Object.assign(tools, mcpTools);
|
|
79
|
+
}
|
|
80
|
+
const finish = (resolvedExtra) => {
|
|
81
|
+
if (resolvedExtra) {
|
|
82
|
+
for (const [name, tool] of Object.entries(resolvedExtra)) if (tool && !(name in tools)) tools[name] = tool;
|
|
83
|
+
}
|
|
84
|
+
if (pluginTools) {
|
|
85
|
+
for (const [name, tool] of Object.entries(pluginTools)) if (!(name in tools)) tools[name] = tool;
|
|
86
|
+
}
|
|
87
|
+
if (disabledTools?.length) for (const toolName of disabledTools) delete tools[toolName];
|
|
88
|
+
const permissionRules = state?.permissionRules;
|
|
89
|
+
if (permissionRules?.tools) {
|
|
90
|
+
for (const [name, policy] of Object.entries(permissionRules.tools)) if (policy === "deny") delete tools[name];
|
|
91
|
+
}
|
|
92
|
+
return tools;
|
|
93
|
+
};
|
|
94
|
+
if (typeof extraTools === "function") {
|
|
95
|
+
const resolved = extraTools({ requestContext });
|
|
96
|
+
if (resolved && typeof resolved.then === "function") return Promise.resolve(resolved).then(finish);
|
|
97
|
+
return finish(resolved);
|
|
98
|
+
}
|
|
99
|
+
return finish(extraTools);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { createDynamicTools, createToolHooks };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","names":[],"sources":["../../src/agents/tools.ts"],"sourcesContent":["import { createAnthropic } from '@ai-sdk/anthropic';\nimport { createOpenAI } from '@ai-sdk/openai';\nimport type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport { createNotificationInboxTool, NotificationsStorage } from '@mastra/core/notifications';\nimport type {\n CreateNotificationInput,\n ListDueNotificationsInput,\n ListNotificationsInput,\n UpdateNotificationInput,\n} from '@mastra/core/notifications';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { MastraCompositeStore } from '@mastra/core/storage';\nimport type { ToolAfterHookContext, ToolHooks } from '@mastra/core/tools';\nimport type { HookManager } from '../hooks/index.js';\nimport type { McpManager } from '../mcp/index.js';\nimport type { MastraCodeComposedState } from '../schema.js';\nimport { MC_TOOLS } from '../tool-names.js';\nimport { createWebSearchTool, createWebExtractTool, hasTavilyKey, requestSandboxAccessTool } from '../tools/index.js';\n\n/** Minimal shape for tools passed to createDynamicTools. */\nexport type ToolLike = {\n execute?: (...args: any[]) => Promise<unknown> | unknown;\n} & Record<string, any>;\n\nclass LazyNotificationsStorage extends NotificationsStorage {\n constructor(private readonly storage: MastraCompositeStore) {\n super();\n }\n\n private async getNotificationsStorage(): Promise<NotificationsStorage> {\n const notifications = await this.storage.getStore('notifications');\n if (!notifications) {\n throw new Error('notification_inbox requires a notifications storage domain');\n }\n return notifications;\n }\n\n async createNotification(input: CreateNotificationInput) {\n return (await this.getNotificationsStorage()).createNotification(input);\n }\n\n async listNotifications(input: ListNotificationsInput) {\n return (await this.getNotificationsStorage()).listNotifications(input);\n }\n\n async listDueNotifications(input: ListDueNotificationsInput) {\n return (await this.getNotificationsStorage()).listDueNotifications(input);\n }\n\n async getNotification(input: { threadId: string; id: string }) {\n return (await this.getNotificationsStorage()).getNotification(input);\n }\n\n async updateNotification(input: UpdateNotificationInput) {\n return (await this.getNotificationsStorage()).updateNotification(input);\n }\n\n async dangerouslyClearAll() {\n return (await this.getNotificationsStorage()).dangerouslyClearAll();\n }\n}\n\nexport type PostToolObserver = (context: ToolAfterHookContext) => void | Promise<void>;\n\nexport function createToolHooks(hookManager?: HookManager, postToolObserver?: PostToolObserver): ToolHooks | undefined {\n if (!hookManager && !postToolObserver) return undefined;\n\n return {\n beforeToolCall: async ({ toolName, input }) => {\n if (!hookManager) return;\n const preResult = await hookManager.runPreToolUse(toolName, input);\n if (!preResult.allowed) {\n return {\n proceed: false as const,\n output: {\n error: preResult.blockReason ?? `Blocked by PreToolUse hook for tool \"${toolName}\"`,\n },\n };\n }\n },\n afterToolCall: async context => {\n const { toolName, input, output, error } = context;\n if (hookManager) {\n const failed = error !== undefined;\n await hookManager\n .runPostToolUse(\n toolName,\n input,\n failed ? { error: error instanceof Error ? error.message : String(error) } : output,\n failed,\n )\n .catch(() => undefined);\n }\n await Promise.resolve()\n .then(() => postToolObserver?.(context))\n .catch(error => {\n console.warn(`[MastraCode] Post-tool observer failed for ${toolName}.`, error);\n });\n },\n };\n}\n\ntype DynamicToolProvider =\n | Record<string, ToolLike | undefined>\n | ((ctx: {\n requestContext: RequestContext;\n }) => Record<string, ToolLike | undefined> | Promise<Record<string, ToolLike | undefined>>);\n\nexport function createDynamicTools(\n mcpManager?: McpManager,\n extraTools?: DynamicToolProvider,\n disabledTools?: string[],\n storage?: MastraCompositeStore,\n pluginTools?: Record<string, ToolLike>,\n) {\n return function getDynamicTools({\n requestContext,\n }: {\n requestContext: RequestContext;\n }): Record<string, ToolLike> | Promise<Record<string, ToolLike>> {\n const ctx = requestContext.get('controller') as AgentControllerRequestContext<MastraCodeComposedState> | undefined;\n const state = ctx?.getState();\n\n const modelId = ctx?.session?.modelId;\n const isAnthropicModel = modelId?.startsWith('anthropic/');\n const isOpenAIModel = modelId?.startsWith('openai/');\n\n // Filesystem, grep, glob, edit, write, execute_command, and process\n // management tools are now provided by the workspace (see workspace.ts).\n // Only tools without a workspace equivalent remain here.\n const tools: Record<string, ToolLike> = {\n request_access: requestSandboxAccessTool,\n };\n\n if (storage) {\n tools[MC_TOOLS.NOTIFICATION_INBOX] = createNotificationInboxTool({\n storage: new LazyNotificationsStorage(storage),\n });\n }\n\n if (hasTavilyKey()) {\n tools.web_search = createWebSearchTool();\n tools.web_extract = createWebExtractTool();\n } else if (isAnthropicModel) {\n const anthropic = createAnthropic({});\n tools.web_search = anthropic.tools.webSearch_20250305();\n } else if (isOpenAIModel) {\n const openai = createOpenAI({});\n tools.web_search = openai.tools.webSearch();\n }\n\n if (mcpManager) {\n const mcpTools = mcpManager.getTools();\n Object.assign(tools, mcpTools);\n }\n\n const finish = (resolvedExtra: Record<string, ToolLike | undefined> | undefined) => {\n if (resolvedExtra) {\n for (const [name, tool] of Object.entries(resolvedExtra)) {\n if (tool && !(name in tools)) {\n tools[name] = tool;\n }\n }\n }\n\n if (pluginTools) {\n for (const [name, tool] of Object.entries(pluginTools)) {\n if (!(name in tools)) {\n tools[name] = tool;\n }\n }\n }\n\n // Remove tools explicitly disabled via config so the model never sees them.\n if (disabledTools?.length) {\n for (const toolName of disabledTools) {\n delete tools[toolName];\n }\n }\n\n // Remove tools that have a per-tool 'deny' policy so the model never sees them.\n const permissionRules = state?.permissionRules;\n if (permissionRules?.tools) {\n for (const [name, policy] of Object.entries(permissionRules.tools)) {\n if (policy === 'deny') {\n delete tools[name];\n }\n }\n }\n\n return tools;\n };\n\n if (typeof extraTools === 'function') {\n const resolved = extraTools({ requestContext });\n // Stay synchronous for sync providers; only go async when the provider does.\n if (resolved && typeof (resolved as PromiseLike<unknown>).then === 'function') {\n return Promise.resolve(resolved).then(finish);\n }\n return finish(resolved as Record<string, ToolLike | undefined>);\n }\n\n return finish(extraTools);\n };\n}\n"],"mappings":";;;;;;;;AAwBA,IAAM,2BAAN,cAAuC,qBAAqB;CAC7B;CAA7B,YAAY,SAAgD;EAC1D,MAAM;EADqB,KAAA,UAAA;CAE7B;CAEA,MAAc,0BAAyD;EACrE,MAAM,gBAAgB,MAAM,KAAK,QAAQ,SAAS,eAAe;EACjE,IAAI,CAAC,eACH,MAAM,IAAI,MAAM,4DAA4D;EAE9E,OAAO;CACT;CAEA,MAAM,mBAAmB,OAAgC;EACvD,QAAQ,MAAM,KAAK,wBAAwB,EAAA,CAAG,mBAAmB,KAAK;CACxE;CAEA,MAAM,kBAAkB,OAA+B;EACrD,QAAQ,MAAM,KAAK,wBAAwB,EAAA,CAAG,kBAAkB,KAAK;CACvE;CAEA,MAAM,qBAAqB,OAAkC;EAC3D,QAAQ,MAAM,KAAK,wBAAwB,EAAA,CAAG,qBAAqB,KAAK;CAC1E;CAEA,MAAM,gBAAgB,OAAyC;EAC7D,QAAQ,MAAM,KAAK,wBAAwB,EAAA,CAAG,gBAAgB,KAAK;CACrE;CAEA,MAAM,mBAAmB,OAAgC;EACvD,QAAQ,MAAM,KAAK,wBAAwB,EAAA,CAAG,mBAAmB,KAAK;CACxE;CAEA,MAAM,sBAAsB;EAC1B,QAAQ,MAAM,KAAK,wBAAwB,EAAA,CAAG,oBAAoB;CACpE;AACF;AAIA,SAAgB,gBAAgB,aAA2B,kBAA4D;CACrH,IAAI,CAAC,eAAe,CAAC,kBAAkB,OAAO,KAAA;CAE9C,OAAO;EACL,gBAAgB,OAAO,EAAE,UAAU,YAAY;GAC7C,IAAI,CAAC,aAAa;GAClB,MAAM,YAAY,MAAM,YAAY,cAAc,UAAU,KAAK;GACjE,IAAI,CAAC,UAAU,SACb,OAAO;IACL,SAAS;IACT,QAAQ,EACN,OAAO,UAAU,eAAe,wCAAwC,SAAS,GACnF;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Q,aAAa,GACrD,IAAI,QAAQ,EAAE,QAAQ,QACpB,MAAM,QAAQ;GAAA;GAKpB,IAAI,aACG;SAAA,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,WAAW,GACnD,IAAI,EAAE,QAAQ,QACZ,MAAM,QAAQ;GAAA;GAMpB,IAAI,eAAe,QACjB,KAAK,MAAM,YAAY,eACrB,OAAO,MAAM;GAKjB,MAAM,kBAAkB,OAAO;GAC/B,IAAI,iBAAiB,OACd;SAAA,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,gBAAgB,KAAK,GAC/D,IAAI,WAAW,QACb,OAAO,MAAM;GAAA;GAKnB,OAAO;EACT;EAEA,IAAI,OAAO,eAAe,YAAY;GACpC,MAAM,WAAW,WAAW,EAAE,eAAe,CAAC;GAE9C,IAAI,YAAY,OAAQ,SAAkC,SAAS,YACjE,OAAO,QAAQ,QAAQ,QAAQ,CAAC,CAAC,KAAK,MAAM;GAE9C,OAAO,OAAO,QAAgD;EAChE;EAEA,OAAO,OAAO,UAAU;CAC1B;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
2
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
3
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
4
|
+
import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace';
|
|
5
|
+
import type { SkillSource } from '@mastra/core/workspace';
|
|
6
|
+
export declare function buildSkillPaths(projectPath: string, configDir: string, homeDir?: string, pluginSkillPaths?: string[]): string[];
|
|
7
|
+
export interface WorkspaceSkillExtension {
|
|
8
|
+
/** Distinguishes extended workspaces from the default resolver cache. */
|
|
9
|
+
id: string;
|
|
10
|
+
/** Additional read-only skill roots prepended to normal project/global skill roots. */
|
|
11
|
+
paths: string[];
|
|
12
|
+
/** Compose the additional roots with the workspace's normal skill source. */
|
|
13
|
+
createSource: (fallback: SkillSource, fallbackSkillRoots: string[]) => SkillSource;
|
|
14
|
+
}
|
|
15
|
+
export declare function getDynamicWorkspace({ requestContext, mastra, skillExtension, }: {
|
|
16
|
+
requestContext: RequestContext;
|
|
17
|
+
mastra?: Mastra;
|
|
18
|
+
skillExtension?: WorkspaceSkillExtension;
|
|
19
|
+
}): Promise<Workspace<import("@mastra/core/workspace").WorkspaceFilesystem | undefined, import("@mastra/core/workspace").WorkspaceSandbox | undefined, undefined> | Workspace<LocalFilesystem, LocalSandbox, undefined>>;
|
|
20
|
+
/**
|
|
21
|
+
* Resolver for the agent's `goal.tools` config. Builds the request's workspace
|
|
22
|
+
* (same per-request resolution as the agent's own tools) and returns only the
|
|
23
|
+
* read-only verification subset, remapped to mastracode's tool names (`view`,
|
|
24
|
+
* `search_content`, etc.). Returns `undefined` when no workspace can be resolved
|
|
25
|
+
* (e.g. no project path), keeping the default judge text-only rather than
|
|
26
|
+
* throwing inside the goal step.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getGoalJudgeTools({ requestContext, mastra, }: {
|
|
29
|
+
requestContext: RequestContext;
|
|
30
|
+
mastra?: Mastra;
|
|
31
|
+
}): Promise<ToolsInput | undefined>;
|
|
32
|
+
//# sourceMappingURL=workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/agents/workspace.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAwB,MAAM,wBAAwB,CAAC;AACxG,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,wBAAwB,CAAC;AA0GrE,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,SAAe,EACtB,gBAAgB,GAAE,MAAM,EAAO,GAC9B,MAAM,EAAE,CA0BV;AAED,MAAM,WAAW,uBAAuB;IACtC,yEAAyE;IACzE,EAAE,EAAE,MAAM,CAAC;IACX,uFAAuF;IACvF,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,6EAA6E;IAC7E,YAAY,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,EAAE,KAAK,WAAW,CAAC;CACpF;AAyFD,wBAAsB,mBAAmB,CAAC,EACxC,cAAc,EACd,MAAM,EACN,cAAc,GACf,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C,wNAoFA;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,cAAc,EACd,MAAM,GACP,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAclC"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import "../constants.js";
|
|
2
|
+
import { loadSettings } from "../onboarding/settings.js";
|
|
3
|
+
import { getPlansDir } from "../utils/plans.js";
|
|
4
|
+
import { isPathWithinRoot } from "../utils/path-security.js";
|
|
5
|
+
import { SandboxFilesystem } from "./sandbox-filesystem.js";
|
|
6
|
+
import { reattachProjectSandbox } from "./sandbox-reattach.js";
|
|
7
|
+
import { GOAL_JUDGE_READONLY_TOOLS, MASTRACODE_WORKSPACE_TOOLS } from "./tool-availability.js";
|
|
8
|
+
import fs, { existsSync } from "fs";
|
|
9
|
+
import os from "os";
|
|
10
|
+
import path, { dirname, join } from "path";
|
|
11
|
+
import { LocalFilesystem, LocalSandbox, Workspace, createWorkspaceTools } from "@mastra/core/workspace";
|
|
12
|
+
import { fileURLToPath } from "url";
|
|
13
|
+
//#region src/agents/workspace.ts
|
|
14
|
+
function buildSandboxEnv() {
|
|
15
|
+
return {
|
|
16
|
+
...process.env,
|
|
17
|
+
FORCE_COLOR: "1",
|
|
18
|
+
CLICOLOR_FORCE: "1",
|
|
19
|
+
TERM: process.env.TERM || "xterm-256color",
|
|
20
|
+
CI: "true",
|
|
21
|
+
NONINTERACTIVE: "1",
|
|
22
|
+
DEBIAN_FRONTEND: "noninteractive"
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function collectSkillPaths(skillsDirs, allowedRoot) {
|
|
26
|
+
const paths = [];
|
|
27
|
+
const seen = /* @__PURE__ */ new Set();
|
|
28
|
+
let realAllowedRoot;
|
|
29
|
+
if (allowedRoot) try {
|
|
30
|
+
realAllowedRoot = fs.realpathSync(allowedRoot);
|
|
31
|
+
} catch {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
for (const skillsDir of skillsDirs) {
|
|
35
|
+
const skillsDirExists = fs.existsSync(skillsDir);
|
|
36
|
+
if (skillsDirExists && realAllowedRoot) try {
|
|
37
|
+
if (!isPathWithinRoot(fs.realpathSync(skillsDir), realAllowedRoot)) continue;
|
|
38
|
+
} catch {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const resolved = path.resolve(skillsDir);
|
|
42
|
+
if (!seen.has(resolved)) {
|
|
43
|
+
seen.add(resolved);
|
|
44
|
+
paths.push(skillsDir);
|
|
45
|
+
}
|
|
46
|
+
if (!skillsDirExists) continue;
|
|
47
|
+
try {
|
|
48
|
+
const entries = fs.readdirSync(skillsDir, { withFileTypes: true });
|
|
49
|
+
for (const entry of entries) if (entry.isSymbolicLink()) try {
|
|
50
|
+
const linkPath = path.join(skillsDir, entry.name);
|
|
51
|
+
const realPath = fs.realpathSync(linkPath);
|
|
52
|
+
if (realAllowedRoot && !isPathWithinRoot(realPath, realAllowedRoot)) continue;
|
|
53
|
+
if (fs.statSync(realPath).isDirectory()) {
|
|
54
|
+
const realParent = path.dirname(realPath);
|
|
55
|
+
if (realAllowedRoot && !isPathWithinRoot(realParent, realAllowedRoot)) continue;
|
|
56
|
+
if (!seen.has(realParent)) {
|
|
57
|
+
seen.add(realParent);
|
|
58
|
+
paths.push(realParent);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
} catch {}
|
|
65
|
+
}
|
|
66
|
+
return paths;
|
|
67
|
+
}
|
|
68
|
+
function buildSkillPaths(projectPath, configDir, homeDir = os.homedir(), pluginSkillPaths = []) {
|
|
69
|
+
const mastraCodeLocalSkillsPath = path.join(projectPath, configDir, "skills");
|
|
70
|
+
const claudeLocalSkillsPath = path.join(projectPath, ".claude", "skills");
|
|
71
|
+
const agentSkillsLocalPath = path.join(projectPath, ".agents", "skills");
|
|
72
|
+
const mastraCodeGlobalSkillsPath = path.join(homeDir, configDir, "skills");
|
|
73
|
+
const claudeGlobalSkillsPath = path.join(homeDir, ".claude", "skills");
|
|
74
|
+
const agentSkillsGlobalPath = path.join(homeDir, ".agents", "skills");
|
|
75
|
+
const paths = [
|
|
76
|
+
...collectSkillPaths([
|
|
77
|
+
mastraCodeLocalSkillsPath,
|
|
78
|
+
claudeLocalSkillsPath,
|
|
79
|
+
agentSkillsLocalPath
|
|
80
|
+
], projectPath),
|
|
81
|
+
...collectSkillPaths([
|
|
82
|
+
mastraCodeGlobalSkillsPath,
|
|
83
|
+
claudeGlobalSkillsPath,
|
|
84
|
+
agentSkillsGlobalPath
|
|
85
|
+
]),
|
|
86
|
+
...pluginSkillPaths.flatMap((pluginSkillPath) => collectSkillPaths([pluginSkillPath], pluginSkillPath))
|
|
87
|
+
];
|
|
88
|
+
const seenPaths = /* @__PURE__ */ new Set();
|
|
89
|
+
return paths.filter((skillPath) => {
|
|
90
|
+
let resolved;
|
|
91
|
+
try {
|
|
92
|
+
resolved = fs.realpathSync(skillPath);
|
|
93
|
+
} catch {
|
|
94
|
+
resolved = path.resolve(skillPath);
|
|
95
|
+
}
|
|
96
|
+
if (seenPaths.has(resolved)) return false;
|
|
97
|
+
seenPaths.add(resolved);
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Paths the agent is always allowed to access (in addition to the project root
|
|
103
|
+
* and any per-thread sandboxAllowedPaths). The OS temp directory is included
|
|
104
|
+
* so the agent can use it as a scratchpad without requesting access every time.
|
|
105
|
+
*/
|
|
106
|
+
const DEFAULT_ALLOWED_PATHS = [
|
|
107
|
+
os.tmpdir(),
|
|
108
|
+
"/tmp",
|
|
109
|
+
getPlansDir()
|
|
110
|
+
].reduce((acc, p) => {
|
|
111
|
+
const resolved = path.resolve(p);
|
|
112
|
+
if (!acc.includes(resolved)) acc.push(resolved);
|
|
113
|
+
return acc;
|
|
114
|
+
}, []);
|
|
115
|
+
const WORKSPACE_ID_PREFIX = "mastra-code-workspace";
|
|
116
|
+
/**
|
|
117
|
+
* Detect the project's package runner from lock files.
|
|
118
|
+
* Used as a fallback packageRunner for LSP when no binary is found locally or on PATH.
|
|
119
|
+
*/
|
|
120
|
+
function detectPackageRunner(projectPath) {
|
|
121
|
+
if (existsSync(join(projectPath, "pnpm-lock.yaml"))) return "pnpm dlx";
|
|
122
|
+
if (existsSync(join(projectPath, "bun.lockb")) || existsSync(join(projectPath, "bun.lock"))) return "bunx";
|
|
123
|
+
if (existsSync(join(projectPath, "yarn.lock"))) return "yarn dlx";
|
|
124
|
+
if (existsSync(join(projectPath, "package-lock.json"))) return "npx --yes";
|
|
125
|
+
return "npx --yes";
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Build (or reuse) a sandbox-backed Workspace for a linked project repository. The sandbox
|
|
129
|
+
* is reattached by its persisted provider id and a `SandboxFilesystem` is layered
|
|
130
|
+
* over the in-sandbox checkout so file tools and command tools share one VM.
|
|
131
|
+
*/
|
|
132
|
+
async function getSandboxWorkspace({ projectRepositoryId, sandboxId, workdir, worktreePath, configDir, mastra, skillExtension }) {
|
|
133
|
+
const boundWorkdir = worktreePath || workdir;
|
|
134
|
+
const extensionId = skillExtension ? `-${skillExtension.id}` : "";
|
|
135
|
+
const workspaceId = `${WORKSPACE_ID_PREFIX}-repository-${projectRepositoryId}-${sandboxId}-${boundWorkdir}${extensionId}`;
|
|
136
|
+
try {
|
|
137
|
+
const existing = mastra?.getWorkspaceById(workspaceId);
|
|
138
|
+
if (existing) {
|
|
139
|
+
existing.setToolsConfig(MASTRACODE_WORKSPACE_TOOLS);
|
|
140
|
+
return existing;
|
|
141
|
+
}
|
|
142
|
+
} catch {}
|
|
143
|
+
const sandbox = await reattachProjectSandbox(sandboxId);
|
|
144
|
+
const filesystem = new SandboxFilesystem({
|
|
145
|
+
sandbox,
|
|
146
|
+
workdir: boundWorkdir
|
|
147
|
+
});
|
|
148
|
+
const projectSkillPaths = [
|
|
149
|
+
path.join(configDir, "skills"),
|
|
150
|
+
".claude/skills",
|
|
151
|
+
".agents/skills"
|
|
152
|
+
];
|
|
153
|
+
return new Workspace({
|
|
154
|
+
id: workspaceId,
|
|
155
|
+
name: "Mastra Code Sandbox Workspace",
|
|
156
|
+
filesystem,
|
|
157
|
+
sandbox,
|
|
158
|
+
tools: MASTRACODE_WORKSPACE_TOOLS,
|
|
159
|
+
skills: [...skillExtension?.paths ?? [], ...projectSkillPaths],
|
|
160
|
+
skillSource: skillExtension?.createSource(filesystem, projectSkillPaths) ?? filesystem
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
async function getDynamicWorkspace({ requestContext, mastra, skillExtension }) {
|
|
164
|
+
const state = requestContext.get("controller")?.getState();
|
|
165
|
+
if (state?.projectRepositoryId && state.sandboxId && state.sandboxWorkdir) return getSandboxWorkspace({
|
|
166
|
+
projectRepositoryId: state.projectRepositoryId,
|
|
167
|
+
sandboxId: state.sandboxId,
|
|
168
|
+
workdir: state.sandboxWorkdir,
|
|
169
|
+
worktreePath: state.worktreePath,
|
|
170
|
+
configDir: state.configDir ?? ".mastracode",
|
|
171
|
+
mastra,
|
|
172
|
+
skillExtension
|
|
173
|
+
});
|
|
174
|
+
const rawProjectPath = state?.projectPath;
|
|
175
|
+
if (!rawProjectPath) throw new Error("Project path is required");
|
|
176
|
+
const projectPath = path.resolve(rawProjectPath);
|
|
177
|
+
const projectSkillPaths = buildSkillPaths(projectPath, state?.configDir ?? ".mastracode", state?.homeDir, state?.pluginSkillPaths ?? []);
|
|
178
|
+
const skillPaths = [...skillExtension?.paths ?? [], ...projectSkillPaths];
|
|
179
|
+
const extensionId = skillExtension ? `-${skillExtension.id}` : "";
|
|
180
|
+
const workspaceId = `${WORKSPACE_ID_PREFIX}-${projectPath}${extensionId}`;
|
|
181
|
+
const sandboxPaths = state?.sandboxAllowedPaths ?? [];
|
|
182
|
+
const allowedPaths = [
|
|
183
|
+
...projectSkillPaths,
|
|
184
|
+
...DEFAULT_ALLOWED_PATHS,
|
|
185
|
+
...sandboxPaths.map((p) => path.resolve(p))
|
|
186
|
+
];
|
|
187
|
+
const workspaceTools = MASTRACODE_WORKSPACE_TOOLS;
|
|
188
|
+
let existing;
|
|
189
|
+
try {
|
|
190
|
+
existing = mastra?.getWorkspaceById(workspaceId);
|
|
191
|
+
} catch {}
|
|
192
|
+
if (existing) {
|
|
193
|
+
existing.filesystem.setAllowedPaths(allowedPaths);
|
|
194
|
+
existing.setToolsConfig(workspaceTools);
|
|
195
|
+
return existing;
|
|
196
|
+
}
|
|
197
|
+
const userLsp = loadSettings().lsp ?? {};
|
|
198
|
+
const mcModulePath = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
199
|
+
const lspConfig = {
|
|
200
|
+
...userLsp,
|
|
201
|
+
packageRunner: userLsp.packageRunner || detectPackageRunner(projectPath),
|
|
202
|
+
searchPaths: [mcModulePath, ...userLsp.searchPaths ?? []]
|
|
203
|
+
};
|
|
204
|
+
const filesystem = new LocalFilesystem({
|
|
205
|
+
basePath: projectPath,
|
|
206
|
+
allowedPaths
|
|
207
|
+
});
|
|
208
|
+
return new Workspace({
|
|
209
|
+
id: workspaceId,
|
|
210
|
+
name: "Mastra Code Workspace",
|
|
211
|
+
filesystem,
|
|
212
|
+
sandbox: new LocalSandbox({
|
|
213
|
+
workingDirectory: projectPath,
|
|
214
|
+
env: buildSandboxEnv()
|
|
215
|
+
}),
|
|
216
|
+
tools: workspaceTools,
|
|
217
|
+
skills: skillPaths,
|
|
218
|
+
...skillExtension ? { skillSource: skillExtension.createSource(filesystem, projectSkillPaths) } : {},
|
|
219
|
+
lsp: lspConfig
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Resolver for the agent's `goal.tools` config. Builds the request's workspace
|
|
224
|
+
* (same per-request resolution as the agent's own tools) and returns only the
|
|
225
|
+
* read-only verification subset, remapped to mastracode's tool names (`view`,
|
|
226
|
+
* `search_content`, etc.). Returns `undefined` when no workspace can be resolved
|
|
227
|
+
* (e.g. no project path), keeping the default judge text-only rather than
|
|
228
|
+
* throwing inside the goal step.
|
|
229
|
+
*/
|
|
230
|
+
async function getGoalJudgeTools({ requestContext, mastra }) {
|
|
231
|
+
let workspace;
|
|
232
|
+
try {
|
|
233
|
+
workspace = await getDynamicWorkspace({
|
|
234
|
+
requestContext,
|
|
235
|
+
mastra
|
|
236
|
+
});
|
|
237
|
+
} catch {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const allTools = await createWorkspaceTools(workspace, {
|
|
241
|
+
requestContext,
|
|
242
|
+
workspace
|
|
243
|
+
});
|
|
244
|
+
const readonly = {};
|
|
245
|
+
for (const name of GOAL_JUDGE_READONLY_TOOLS) if (allTools[name]) readonly[name] = allTools[name];
|
|
246
|
+
return Object.keys(readonly).length > 0 ? readonly : void 0;
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
export { buildSkillPaths, getDynamicWorkspace, getGoalJudgeTools };
|
|
250
|
+
|
|
251
|
+
//# sourceMappingURL=workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.js","names":[],"sources":["../../src/agents/workspace.ts"],"sourcesContent":["import fs, { existsSync } from 'node:fs';\nimport os from 'node:os';\nimport path, { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ToolsInput } from '@mastra/core/agent';\nimport type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { Workspace, LocalFilesystem, LocalSandbox, createWorkspaceTools } from '@mastra/core/workspace';\nimport type { LSPConfig, SkillSource } from '@mastra/core/workspace';\nimport { DEFAULT_CONFIG_DIR } from '../constants.js';\nimport { loadSettings } from '../onboarding/settings.js';\nimport type { MastraCodeState } from '../schema.js';\nimport { isPathWithinRoot } from '../utils/path-security.js';\nimport { getPlansDir } from '../utils/plans.js';\nimport { SandboxFilesystem } from './sandbox-filesystem.js';\nimport { reattachProjectSandbox } from './sandbox-reattach.js';\nimport { GOAL_JUDGE_READONLY_TOOLS, MASTRACODE_WORKSPACE_TOOLS } from './tool-availability.js';\n\n// =============================================================================\n// Sandbox Environment\n// =============================================================================\n\nfunction buildSandboxEnv(): NodeJS.ProcessEnv {\n return {\n ...process.env,\n // Explicit overrides for non-interactive subprocess execution\n FORCE_COLOR: '1',\n CLICOLOR_FORCE: '1',\n TERM: process.env.TERM || 'xterm-256color',\n CI: 'true',\n NONINTERACTIVE: '1',\n DEBIAN_FRONTEND: 'noninteractive',\n };\n}\n\n// =============================================================================\n// Create Workspace with Skills\n// =============================================================================\n\n// We support multiple skill locations for compatibility:\n// 1. Project-local: <configDir>/skills (project-specific mastracode skills)\n// 2. Project-local: .claude/skills (Claude Code compatible skills)\n// 3. Project-local: .agents/skills (Agent Skills spec compatible)\n// 4. Global: ~/<configDir>/skills (user-wide mastracode skills)\n// 5. Global: ~/.claude/skills (user-wide Claude Code skills)\n// 6. Global: ~/.agents/skills (user-wide Agent Skills spec compatible)\n\n// Mastra's LocalSkillSource.readdir uses Node's Dirent.isDirectory() which\n// returns false for symlinks. Tools like `npx skills add` install skills as\n// symlinks, so we need to resolve them. For each symlinked skill directory,\n// we add the real (resolved) parent path as an additional skill scan path.\nfunction collectSkillPaths(skillsDirs: string[], allowedRoot?: string): string[] {\n const paths: string[] = [];\n const seen = new Set<string>();\n let realAllowedRoot: string | undefined;\n\n if (allowedRoot) {\n try {\n realAllowedRoot = fs.realpathSync(allowedRoot);\n } catch {\n return [];\n }\n }\n\n for (const skillsDir of skillsDirs) {\n const skillsDirExists = fs.existsSync(skillsDir);\n if (skillsDirExists && realAllowedRoot) {\n try {\n const realSkillsDir = fs.realpathSync(skillsDir);\n if (!isPathWithinRoot(realSkillsDir, realAllowedRoot)) continue;\n } catch {\n continue;\n }\n }\n\n const resolved = path.resolve(skillsDir);\n if (!seen.has(resolved)) {\n seen.add(resolved);\n paths.push(skillsDir);\n }\n\n if (!skillsDirExists) continue;\n\n try {\n const entries = fs.readdirSync(skillsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isSymbolicLink()) {\n try {\n const linkPath = path.join(skillsDir, entry.name);\n const realPath = fs.realpathSync(linkPath);\n if (realAllowedRoot && !isPathWithinRoot(realPath, realAllowedRoot)) continue;\n const stat = fs.statSync(realPath);\n if (stat.isDirectory()) {\n const realParent = path.dirname(realPath);\n if (realAllowedRoot && !isPathWithinRoot(realParent, realAllowedRoot)) continue;\n if (!seen.has(realParent)) {\n seen.add(realParent);\n paths.push(realParent);\n }\n }\n } catch {\n continue;\n }\n }\n }\n } catch {\n // Ignore errors during symlink resolution\n }\n }\n\n return paths;\n}\n\n// Build skill paths dynamically based on configDir and projectPath\nexport function buildSkillPaths(\n projectPath: string,\n configDir: string,\n homeDir = os.homedir(),\n pluginSkillPaths: string[] = [],\n): string[] {\n const mastraCodeLocalSkillsPath = path.join(projectPath, configDir, 'skills');\n const claudeLocalSkillsPath = path.join(projectPath, '.claude', 'skills');\n const agentSkillsLocalPath = path.join(projectPath, '.agents', 'skills');\n const mastraCodeGlobalSkillsPath = path.join(homeDir, configDir, 'skills');\n const claudeGlobalSkillsPath = path.join(homeDir, '.claude', 'skills');\n const agentSkillsGlobalPath = path.join(homeDir, '.agents', 'skills');\n\n const paths = [\n ...collectSkillPaths([mastraCodeLocalSkillsPath, claudeLocalSkillsPath, agentSkillsLocalPath], projectPath),\n ...collectSkillPaths([mastraCodeGlobalSkillsPath, claudeGlobalSkillsPath, agentSkillsGlobalPath]),\n ...pluginSkillPaths.flatMap(pluginSkillPath => collectSkillPaths([pluginSkillPath], pluginSkillPath)),\n ];\n\n const seenPaths = new Set<string>();\n return paths.filter(skillPath => {\n let resolved: string;\n try {\n resolved = fs.realpathSync(skillPath);\n } catch {\n resolved = path.resolve(skillPath);\n }\n if (seenPaths.has(resolved)) return false;\n seenPaths.add(resolved);\n return true;\n });\n}\n\nexport interface WorkspaceSkillExtension {\n /** Distinguishes extended workspaces from the default resolver cache. */\n id: string;\n /** Additional read-only skill roots prepended to normal project/global skill roots. */\n paths: string[];\n /** Compose the additional roots with the workspace's normal skill source. */\n createSource: (fallback: SkillSource, fallbackSkillRoots: string[]) => SkillSource;\n}\n\n/**\n * Paths the agent is always allowed to access (in addition to the project root\n * and any per-thread sandboxAllowedPaths). The OS temp directory is included\n * so the agent can use it as a scratchpad without requesting access every time.\n */\nconst DEFAULT_ALLOWED_PATHS: string[] = [os.tmpdir(), '/tmp', getPlansDir()].reduce<string[]>((acc, p) => {\n const resolved = path.resolve(p);\n if (!acc.includes(resolved)) acc.push(resolved);\n return acc;\n}, []);\n\nconst WORKSPACE_ID_PREFIX = 'mastra-code-workspace';\n\n/**\n * Detect the project's package runner from lock files.\n * Used as a fallback packageRunner for LSP when no binary is found locally or on PATH.\n */\nfunction detectPackageRunner(projectPath: string): string | undefined {\n if (existsSync(join(projectPath, 'pnpm-lock.yaml'))) return 'pnpm dlx';\n if (existsSync(join(projectPath, 'bun.lockb')) || existsSync(join(projectPath, 'bun.lock'))) return 'bunx';\n if (existsSync(join(projectPath, 'yarn.lock'))) return 'yarn dlx';\n if (existsSync(join(projectPath, 'package-lock.json'))) return 'npx --yes';\n return 'npx --yes';\n}\n\n/**\n * Build (or reuse) a sandbox-backed Workspace for a linked project repository. The sandbox\n * is reattached by its persisted provider id and a `SandboxFilesystem` is layered\n * over the in-sandbox checkout so file tools and command tools share one VM.\n */\nasync function getSandboxWorkspace({\n projectRepositoryId,\n sandboxId,\n workdir,\n worktreePath,\n configDir,\n mastra,\n skillExtension,\n}: {\n projectRepositoryId: string;\n sandboxId: string;\n workdir: string;\n worktreePath?: string;\n configDir: string;\n mastra?: Mastra;\n skillExtension?: WorkspaceSkillExtension;\n}): Promise<Workspace> {\n // Bind the workspace to the active worktree when one is set, so file tools and\n // command tools operate inside the feature branch's working tree rather than\n // the base checkout. Falls back to the repo root when no worktree is active.\n const boundWorkdir = worktreePath || workdir;\n\n // Include the sandbox id *and* worktree path in the reuse key: a new sandbox\n // (e.g. the previous one expired) or a different worktree must each get a\n // fresh Workspace/ProcessManager instead of reusing one bound to a stale\n // sandbox or the wrong working tree.\n const extensionId = skillExtension ? `-${skillExtension.id}` : '';\n const workspaceId = `${WORKSPACE_ID_PREFIX}-repository-${projectRepositoryId}-${sandboxId}-${boundWorkdir}${extensionId}`;\n\n // Reuse the existing remote workspace if already registered (preserves the\n // reattached sandbox + ProcessManager state across re-opens).\n try {\n const existing = mastra?.getWorkspaceById(workspaceId) as Workspace | undefined;\n if (existing) {\n existing.setToolsConfig(MASTRACODE_WORKSPACE_TOOLS);\n return existing;\n }\n } catch {\n // Not registered yet.\n }\n\n const sandbox = await reattachProjectSandbox(sandboxId);\n const filesystem = new SandboxFilesystem({ sandbox, workdir: boundWorkdir });\n const projectSkillPaths = [path.join(configDir, 'skills'), '.claude/skills', '.agents/skills'];\n const skillPaths = [...(skillExtension?.paths ?? []), ...projectSkillPaths];\n\n return new Workspace({\n id: workspaceId,\n name: 'Mastra Code Sandbox Workspace',\n filesystem,\n sandbox: sandbox as unknown as ConstructorParameters<typeof Workspace>[0]['sandbox'],\n tools: MASTRACODE_WORKSPACE_TOOLS,\n skills: skillPaths,\n skillSource: skillExtension?.createSource(filesystem, projectSkillPaths) ?? filesystem,\n });\n}\n\nexport async function getDynamicWorkspace({\n requestContext,\n mastra,\n skillExtension,\n}: {\n requestContext: RequestContext;\n mastra?: Mastra;\n skillExtension?: WorkspaceSkillExtension;\n}) {\n const ctx = requestContext.get('controller') as AgentControllerRequestContext<MastraCodeState> | undefined;\n const state = ctx?.getState();\n\n // Repository-backed project: the repo lives inside a remote sandbox, not on\n // the server host. Reattach to the already-provisioned + materialized sandbox\n // and build a sandbox-backed Workspace. Optional embedders may add read-only\n // skill roots while project skills remain sandbox-backed.\n if (state?.projectRepositoryId && state.sandboxId && state.sandboxWorkdir) {\n return getSandboxWorkspace({\n projectRepositoryId: state.projectRepositoryId,\n sandboxId: state.sandboxId,\n workdir: state.sandboxWorkdir,\n worktreePath: state.worktreePath,\n configDir: state.configDir ?? DEFAULT_CONFIG_DIR,\n mastra,\n skillExtension,\n });\n }\n\n const rawProjectPath = state?.projectPath;\n\n if (!rawProjectPath) {\n throw new Error('Project path is required');\n }\n\n const projectPath = path.resolve(rawProjectPath);\n const configDir = state?.configDir ?? DEFAULT_CONFIG_DIR;\n const projectSkillPaths = buildSkillPaths(projectPath, configDir, state?.homeDir, state?.pluginSkillPaths ?? []);\n const skillPaths = [...(skillExtension?.paths ?? []), ...projectSkillPaths];\n const extensionId = skillExtension ? `-${skillExtension.id}` : '';\n const workspaceId = `${WORKSPACE_ID_PREFIX}-${projectPath}${extensionId}`;\n const sandboxPaths = state?.sandboxAllowedPaths ?? [];\n const allowedPaths = [\n ...projectSkillPaths,\n ...DEFAULT_ALLOWED_PATHS,\n ...sandboxPaths.map((p: string) => path.resolve(p)),\n ];\n\n // All modes share the same workspace tool configuration. Per-mode tool\n // visibility is enforced at LLM-call time via `availableTools` /\n // `activeTools` on the AgentController, not by mutating workspace capabilities.\n const workspaceTools = MASTRACODE_WORKSPACE_TOOLS;\n\n // Reuse existing workspace if already registered (preserves ProcessManager state)\n let existing: Workspace<LocalFilesystem, LocalSandbox> | undefined;\n try {\n existing = mastra?.getWorkspaceById(workspaceId) as Workspace<LocalFilesystem, LocalSandbox>;\n } catch {\n // Not registered yet\n }\n\n if (existing) {\n existing.filesystem.setAllowedPaths(allowedPaths);\n existing.setToolsConfig(workspaceTools);\n return existing;\n }\n\n const userLsp = loadSettings().lsp ?? {};\n const mcModulePath = join(dirname(fileURLToPath(import.meta.url)), '..');\n const lspConfig: LSPConfig = {\n ...userLsp,\n packageRunner: userLsp.packageRunner || detectPackageRunner(projectPath), // Detected runner is the fallback — user's packageRunner always wins\n searchPaths: [mcModulePath, ...(userLsp.searchPaths ?? [])],\n };\n\n // First call for this project — create the workspace\n const filesystem = new LocalFilesystem({\n basePath: projectPath,\n allowedPaths,\n });\n return new Workspace({\n id: workspaceId,\n name: 'Mastra Code Workspace',\n filesystem,\n sandbox: new LocalSandbox({\n workingDirectory: projectPath,\n env: buildSandboxEnv(),\n }),\n tools: workspaceTools,\n skills: skillPaths,\n ...(skillExtension ? { skillSource: skillExtension.createSource(filesystem, projectSkillPaths) } : {}),\n lsp: lspConfig,\n });\n}\n\n/**\n * Resolver for the agent's `goal.tools` config. Builds the request's workspace\n * (same per-request resolution as the agent's own tools) and returns only the\n * read-only verification subset, remapped to mastracode's tool names (`view`,\n * `search_content`, etc.). Returns `undefined` when no workspace can be resolved\n * (e.g. no project path), keeping the default judge text-only rather than\n * throwing inside the goal step.\n */\nexport async function getGoalJudgeTools({\n requestContext,\n mastra,\n}: {\n requestContext: RequestContext;\n mastra?: Mastra;\n}): Promise<ToolsInput | undefined> {\n let workspace: Workspace;\n try {\n workspace = await getDynamicWorkspace({ requestContext, mastra });\n } catch {\n return undefined;\n }\n\n const allTools = await createWorkspaceTools(workspace, { requestContext, workspace });\n const readonly: ToolsInput = {};\n for (const name of GOAL_JUDGE_READONLY_TOO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kB;GAClB,KAAK,gBAAgB;EACvB,CAAC;EACD,OAAO;EACP,QAAQ;EACR,GAAI,iBAAiB,EAAE,aAAa,eAAe,aAAa,YAAY,iBAAiB,EAAE,IAAI,CAAC;EACpG,KAAK;CACP,CAAC;AACH;;;;;;;;;AAUA,eAAsB,kBAAkB,EACtC,gBACA,UAIkC;CAClC,IAAI;CACJ,IAAI;EACF,YAAY,MAAM,oBAAoB;GAAE;GAAgB;EAAO,CAAC;CAClE,QAAQ;EACN;CACF;CAEA,MAAM,WAAW,MAAM,qBAAqB,WAAW;EAAE;EAAgB;CAAU,CAAC;CACpF,MAAM,WAAuB,CAAC;CAC9B,KAAK,MAAM,QAAQ,2BACjB,IAAI,SAAS,OAAO,SAAS,QAAQ,SAAS;CAEhD,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,IAAI,WAAW,KAAA;AACvD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function getMastraAnalyticsDistinctId(configPath?: string): string;
|
|
2
|
+
export type MastraCodeAnalyticsEvent = 'mastracode_session_started' | 'mastracode_prompt_submitted' | 'mastracode_thread_changed' | 'mastracode_model_changed' | 'mastracode_command_used' | 'mastracode_interactive_prompt_shown';
|
|
3
|
+
export interface MastraCodeAnalytics {
|
|
4
|
+
capture(event: MastraCodeAnalyticsEvent, properties?: Record<string, unknown>): void;
|
|
5
|
+
trackCommand(command: string, properties?: Record<string, unknown>): void;
|
|
6
|
+
trackInteractivePrompt(promptType: string, properties?: Record<string, unknown>): void;
|
|
7
|
+
shutdown(): Promise<void>;
|
|
8
|
+
isEnabled(): boolean;
|
|
9
|
+
}
|
|
10
|
+
interface MastraCodeAnalyticsOptions {
|
|
11
|
+
version: string;
|
|
12
|
+
host?: string;
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function isTelemetryDisabled(env?: NodeJS.ProcessEnv): boolean;
|
|
16
|
+
export declare function createMastraCodeAnalytics(options: MastraCodeAnalyticsOptions): MastraCodeAnalytics;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=analytics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAsCA,wBAAgB,4BAA4B,CAAC,UAAU,SAAwB,GAAG,MAAM,CAmBvF;AAeD,MAAM,MAAM,wBAAwB,GAChC,4BAA4B,GAC5B,6BAA6B,GAC7B,2BAA2B,GAC3B,0BAA0B,GAC1B,yBAAyB,GACzB,qCAAqC,CAAC;AAE1C,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,KAAK,EAAE,wBAAwB,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACrF,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1E,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACvF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC;CACtB;AAED,UAAU,0BAA0B;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA8FD,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAOjF;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B,GAAG,mBAAmB,CAOlG"}
|