@mastra/code-sdk 0.0.0-aggregate-trace-20261015182851
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/LICENSE.md +32 -0
- package/README.md +284 -0
- package/dist/acp/agent.d.ts +48 -0
- package/dist/acp/agent.d.ts.map +1 -0
- package/dist/acp/agent.js +416 -0
- package/dist/acp/agent.js.map +1 -0
- package/dist/acp/errors.d.ts +3 -0
- package/dist/acp/errors.d.ts.map +1 -0
- package/dist/acp/errors.js +14 -0
- package/dist/acp/errors.js.map +1 -0
- package/dist/acp/event-mapper.d.ts +28 -0
- package/dist/acp/event-mapper.d.ts.map +1 -0
- package/dist/acp/event-mapper.js +279 -0
- package/dist/acp/event-mapper.js.map +1 -0
- package/dist/acp/index.d.ts +9 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +24 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/runtime.d.ts +5 -0
- package/dist/acp/runtime.d.ts.map +1 -0
- package/dist/acp/runtime.js +91 -0
- package/dist/acp/runtime.js.map +1 -0
- package/dist/acp/server.d.ts +4 -0
- package/dist/acp/server.d.ts.map +1 -0
- package/dist/acp/server.js +38 -0
- package/dist/acp/server.js.map +1 -0
- package/dist/acp/skills.d.ts +6 -0
- package/dist/acp/skills.d.ts.map +1 -0
- package/dist/acp/skills.js +33 -0
- package/dist/acp/skills.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/agent-connections/messaging-processor.d.ts +17 -0
- package/dist/agent-connections/messaging-processor.d.ts.map +1 -0
- package/dist/agent-connections/messaging-processor.js +134 -0
- package/dist/agent-connections/messaging-processor.js.map +1 -0
- package/dist/agent-connections/ownership.d.ts +24 -0
- package/dist/agent-connections/ownership.d.ts.map +1 -0
- package/dist/agent-connections/ownership.js +99 -0
- package/dist/agent-connections/ownership.js.map +1 -0
- package/dist/agent-connections/registry.d.ts +20 -0
- package/dist/agent-connections/registry.d.ts.map +1 -0
- package/dist/agent-connections/registry.js +170 -0
- package/dist/agent-connections/registry.js.map +1 -0
- package/dist/agent-connections/session-advertisement.d.ts +27 -0
- package/dist/agent-connections/session-advertisement.d.ts.map +1 -0
- package/dist/agent-connections/session-advertisement.js +89 -0
- package/dist/agent-connections/session-advertisement.js.map +1 -0
- package/dist/agent-connections/signal-provider.d.ts +141 -0
- package/dist/agent-connections/signal-provider.d.ts.map +1 -0
- package/dist/agent-connections/signal-provider.js +38 -0
- package/dist/agent-connections/signal-provider.js.map +1 -0
- package/dist/agent-connections/state-processor.d.ts +23 -0
- package/dist/agent-connections/state-processor.d.ts.map +1 -0
- package/dist/agent-connections/state-processor.js +273 -0
- package/dist/agent-connections/state-processor.js.map +1 -0
- package/dist/agent-connections/thread-state.d.ts +41 -0
- package/dist/agent-connections/thread-state.d.ts.map +1 -0
- package/dist/agent-connections/thread-state.js +160 -0
- package/dist/agent-connections/thread-state.js.map +1 -0
- package/dist/agent-connections/tools.d.ts +133 -0
- package/dist/agent-connections/tools.d.ts.map +1 -0
- package/dist/agent-connections/tools.js +552 -0
- package/dist/agent-connections/tools.js.map +1 -0
- package/dist/agent-connections/types.d.ts +99 -0
- package/dist/agent-connections/types.d.ts.map +1 -0
- package/dist/agent-connections/types.js +7 -0
- package/dist/agent-connections/types.js.map +1 -0
- package/dist/agent-connections/untrusted-text.d.ts +5 -0
- package/dist/agent-connections/untrusted-text.d.ts.map +1 -0
- package/dist/agent-connections/untrusted-text.js +22 -0
- package/dist/agent-connections/untrusted-text.js.map +1 -0
- package/dist/agents/background-completion-events.d.ts +16 -0
- package/dist/agents/background-completion-events.d.ts.map +1 -0
- package/dist/agents/background-completion-events.js +19 -0
- package/dist/agents/background-completion-events.js.map +1 -0
- package/dist/agents/background-completion.d.ts +9 -0
- package/dist/agents/background-completion.d.ts.map +1 -0
- package/dist/agents/background-completion.js +59 -0
- package/dist/agents/background-completion.js.map +1 -0
- package/dist/agents/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.d.ts.map +1 -0
- package/dist/agents/context-audit.js +118 -0
- package/dist/agents/context-audit.js.map +1 -0
- package/dist/agents/credential-resolver.d.ts +67 -0
- package/dist/agents/credential-resolver.d.ts.map +1 -0
- package/dist/agents/credential-resolver.js +136 -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 +40 -0
- package/dist/agents/instructions.d.ts.map +1 -0
- package/dist/agents/instructions.js +63 -0
- package/dist/agents/instructions.js.map +1 -0
- package/dist/agents/mastracode-gateway.d.ts +76 -0
- package/dist/agents/mastracode-gateway.d.ts.map +1 -0
- package/dist/agents/mastracode-gateway.js +434 -0
- package/dist/agents/mastracode-gateway.js.map +1 -0
- package/dist/agents/memory.d.ts +39 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +266 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/model.d.ts +123 -0
- package/dist/agents/model.d.ts.map +1 -0
- package/dist/agents/model.js +295 -0
- package/dist/agents/model.js.map +1 -0
- package/dist/agents/modes/build.d.ts +12 -0
- package/dist/agents/modes/build.d.ts.map +1 -0
- package/dist/agents/modes/build.js +36 -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 +28 -0
- package/dist/agents/modes/explore.js.map +1 -0
- package/dist/agents/modes/plan.d.ts +8 -0
- package/dist/agents/modes/plan.d.ts.map +1 -0
- package/dist/agents/modes/plan.js +46 -0
- package/dist/agents/modes/plan.js.map +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts +99 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
- package/dist/agents/prompts/agent-instructions.js +275 -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 +54 -0
- package/dist/agents/prompts/index.d.ts.map +1 -0
- package/dist/agents/prompts/index.js +127 -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 +8 -0
- package/dist/agents/prompts/plan.d.ts.map +1 -0
- package/dist/agents/prompts/plan.js +129 -0
- package/dist/agents/prompts/plan.js.map +1 -0
- package/dist/agents/prompts/tool-guidance.d.ts +18 -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 +151 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
- package/dist/agents/sandbox-filesystem.js +581 -0
- package/dist/agents/sandbox-filesystem.js.map +1 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.d.ts.map +1 -0
- package/dist/agents/subagents/execute.js +27 -0
- package/dist/agents/subagents/execute.js.map +1 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.d.ts.map +1 -0
- package/dist/agents/subagents/explore.js +18 -0
- package/dist/agents/subagents/explore.js.map +1 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.d.ts.map +1 -0
- package/dist/agents/subagents/plan.js +18 -0
- package/dist/agents/subagents/plan.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 +12 -0
- package/dist/agents/tool-availability.d.ts.map +1 -0
- package/dist/agents/tool-availability.js +129 -0
- package/dist/agents/tool-availability.js.map +1 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +131 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.d.ts.map +1 -0
- package/dist/agents/workflow-builder-agent.js +82 -0
- package/dist/agents/workflow-builder-agent.js.map +1 -0
- package/dist/agents/workspace.d.ts +33 -0
- package/dist/agents/workspace.d.ts.map +1 -0
- package/dist/agents/workspace.js +208 -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 +162 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth/account-rotation-processor.d.ts +182 -0
- package/dist/auth/account-rotation-processor.d.ts.map +1 -0
- package/dist/auth/account-rotation-processor.js +609 -0
- package/dist/auth/account-rotation-processor.js.map +1 -0
- package/dist/auth/account-routing-context.d.ts +13 -0
- package/dist/auth/account-routing-context.d.ts.map +1 -0
- package/dist/auth/account-routing-context.js +41 -0
- package/dist/auth/account-routing-context.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 +13 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +9 -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/provider-auth-error.d.ts +12 -0
- package/dist/auth/provider-auth-error.d.ts.map +1 -0
- package/dist/auth/provider-auth-error.js +16 -0
- package/dist/auth/provider-auth-error.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 +120 -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 +362 -0
- package/dist/auth/providers/github-copilot.js.map +1 -0
- package/dist/auth/providers/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.d.ts.map +1 -0
- package/dist/auth/providers/kimi-coding.js +228 -0
- package/dist/auth/providers/kimi-coding.js.map +1 -0
- package/dist/auth/providers/openai-codex.d.ts +141 -0
- package/dist/auth/providers/openai-codex.d.ts.map +1 -0
- package/dist/auth/providers/openai-codex.js +533 -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 +226 -0
- package/dist/auth/providers/xai.js.map +1 -0
- package/dist/auth/storage.d.ts +214 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +774 -0
- package/dist/auth/storage.js.map +1 -0
- package/dist/auth/types.d.ts +164 -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 +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +20 -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/experimental-agent.d.ts +11 -0
- package/dist/experimental-agent.d.ts.map +1 -0
- package/dist/experimental-agent.js +36 -0
- package/dist/experimental-agent.js.map +1 -0
- package/dist/goal-manager.d.ts +114 -0
- package/dist/goal-manager.d.ts.map +1 -0
- package/dist/goal-manager.js +354 -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 +48 -0
- package/dist/headless/cli.d.ts.map +1 -0
- package/dist/headless/cli.js +239 -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 +203 -0
- package/dist/headless/flags.js.map +1 -0
- package/dist/headless/format.d.ts +39 -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 +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 +408 -0
- package/dist/headless/run-mc.js.map +1 -0
- package/dist/headless/types.d.ts +174 -0
- package/dist/headless/types.d.ts.map +1 -0
- package/dist/headless/types.js +19 -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 +80 -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 +129 -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 +54 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +241 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +172 -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 +463 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1305 -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/knowledge-inspector.d.ts +123 -0
- package/dist/knowledge-inspector.d.ts.map +1 -0
- package/dist/knowledge-inspector.js +516 -0
- package/dist/knowledge-inspector.js.map +1 -0
- package/dist/knowledge-scope.d.ts +35 -0
- package/dist/knowledge-scope.d.ts.map +1 -0
- package/dist/knowledge-scope.js +47 -0
- package/dist/knowledge-scope.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 +77 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +316 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +102 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +650 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.d.ts.map +1 -0
- package/dist/mcp/state.js +97 -0
- package/dist/mcp/state.js.map +1 -0
- package/dist/mcp/types.d.ts +139 -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 +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 +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 +47 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -0
- package/dist/onboarding/om-settings.js +83 -0
- package/dist/onboarding/om-settings.js.map +1 -0
- package/dist/onboarding/pack-activation.d.ts +52 -0
- package/dist/onboarding/pack-activation.d.ts.map +1 -0
- package/dist/onboarding/pack-activation.js +108 -0
- package/dist/onboarding/pack-activation.js.map +1 -0
- package/dist/onboarding/packs.d.ts +102 -0
- package/dist/onboarding/packs.d.ts.map +1 -0
- package/dist/onboarding/packs.js +278 -0
- package/dist/onboarding/packs.js.map +1 -0
- package/dist/onboarding/settings.d.ts +538 -0
- package/dist/onboarding/settings.d.ts.map +1 -0
- package/dist/onboarding/settings.js +1060 -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 +142 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugin.d.ts +156 -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/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.d.ts.map +1 -0
- package/dist/plugins/dependencies.js +87 -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 +19 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +260 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +98 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +456 -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/signal-lane.d.ts +58 -0
- package/dist/plugins/signal-lane.d.ts.map +1 -0
- package/dist/plugins/signal-lane.js +166 -0
- package/dist/plugins/signal-lane.js.map +1 -0
- package/dist/plugins/types.d.ts +81 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +135 -0
- package/dist/process-memory-diagnostics.d.ts.map +1 -0
- package/dist/process-memory-diagnostics.js +499 -0
- package/dist/process-memory-diagnostics.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 +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 +144 -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 +102 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
- package/dist/providers/anthropic-prompt-cache.d.ts.map +1 -0
- package/dist/providers/anthropic-prompt-cache.js +11 -0
- package/dist/providers/anthropic-prompt-cache.js.map +1 -0
- package/dist/providers/anthropic-thinking.d.ts +5 -0
- package/dist/providers/anthropic-thinking.d.ts.map +1 -0
- package/dist/providers/anthropic-thinking.js +25 -0
- package/dist/providers/anthropic-thinking.js.map +1 -0
- package/dist/providers/claude-max.d.ts +67 -0
- package/dist/providers/claude-max.d.ts.map +1 -0
- package/dist/providers/claude-max.js +226 -0
- package/dist/providers/claude-max.js.map +1 -0
- package/dist/providers/github-copilot-gateway.d.ts +35 -0
- package/dist/providers/github-copilot-gateway.d.ts.map +1 -0
- package/dist/providers/github-copilot-gateway.js +61 -0
- package/dist/providers/github-copilot-gateway.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 +318 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/google-thinking.d.ts +31 -0
- package/dist/providers/google-thinking.d.ts.map +1 -0
- package/dist/providers/google-thinking.js +67 -0
- package/dist/providers/google-thinking.js.map +1 -0
- package/dist/providers/kimi-coding.d.ts +14 -0
- package/dist/providers/kimi-coding.d.ts.map +1 -0
- package/dist/providers/kimi-coding.js +78 -0
- package/dist/providers/kimi-coding.js.map +1 -0
- package/dist/providers/model-ids.d.ts +30 -0
- package/dist/providers/model-ids.d.ts.map +1 -0
- package/dist/providers/model-ids.js +79 -0
- package/dist/providers/model-ids.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +84 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +347 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/provider-thinking.d.ts +23 -0
- package/dist/providers/provider-thinking.d.ts.map +1 -0
- package/dist/providers/provider-thinking.js +64 -0
- package/dist/providers/provider-thinking.js.map +1 -0
- package/dist/providers/thinking-request.d.ts +14 -0
- package/dist/providers/thinking-request.d.ts.map +1 -0
- package/dist/providers/thinking-request.js +90 -0
- package/dist/providers/thinking-request.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 +71 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/schedules/index.d.ts +10 -0
- package/dist/schedules/index.d.ts.map +1 -0
- package/dist/schedules/index.js +6 -0
- package/dist/schedules/interval.d.ts +49 -0
- package/dist/schedules/interval.d.ts.map +1 -0
- package/dist/schedules/interval.js +215 -0
- package/dist/schedules/interval.js.map +1 -0
- package/dist/schedules/prompt.d.ts +36 -0
- package/dist/schedules/prompt.d.ts.map +1 -0
- package/dist/schedules/prompt.js +39 -0
- package/dist/schedules/prompt.js.map +1 -0
- package/dist/schedules/run-script.d.ts +8 -0
- package/dist/schedules/run-script.d.ts.map +1 -0
- package/dist/schedules/run-script.js +83 -0
- package/dist/schedules/run-script.js.map +1 -0
- package/dist/schedules/scheduler.d.ts +101 -0
- package/dist/schedules/scheduler.d.ts.map +1 -0
- package/dist/schedules/scheduler.js +169 -0
- package/dist/schedules/scheduler.js.map +1 -0
- package/dist/schedules/tools.d.ts +57 -0
- package/dist/schedules/tools.d.ts.map +1 -0
- package/dist/schedules/tools.js +220 -0
- package/dist/schedules/tools.js.map +1 -0
- package/dist/schema.d.ts +499 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +134 -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/thinking-catalog.d.ts +4 -0
- package/dist/thinking-catalog.d.ts.map +1 -0
- package/dist/thinking-catalog.js +13 -0
- package/dist/thinking-catalog.js.map +1 -0
- package/dist/thinking.d.ts +37 -0
- package/dist/thinking.d.ts.map +1 -0
- package/dist/thinking.js +137 -0
- package/dist/thinking.js.map +1 -0
- package/dist/tool-names.d.ts +77 -0
- package/dist/tool-names.d.ts.map +1 -0
- package/dist/tool-names.js +56 -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 +80 -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 +114 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +155 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/create-workflow.js +81 -0
- package/dist/tools/workflows/create-workflow.js.map +1 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/delete-workflow.js +21 -0
- package/dist/tools/workflows/delete-workflow.js.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.js +44 -0
- package/dist/tools/workflows/ephemeral-memory.js.map +1 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.d.ts.map +1 -0
- package/dist/tools/workflows/extract-json-schema.js +22 -0
- package/dist/tools/workflows/extract-json-schema.js.map +1 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/get-workflow.js +34 -0
- package/dist/tools/workflows/get-workflow.js.map +1 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-agents.js +32 -0
- package/dist/tools/workflows/list-available-agents.js.map +1 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-classifiers.js +56 -0
- package/dist/tools/workflows/list-available-classifiers.js.map +1 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-tools.js +40 -0
- package/dist/tools/workflows/list-available-tools.js.map +1 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-workflows.js +32 -0
- package/dist/tools/workflows/list-available-workflows.js.map +1 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-workflows.js +33 -0
- package/dist/tools/workflows/list-workflows.js.map +1 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/run-workflow.js +52 -0
- package/dist/tools/workflows/run-workflow.js.map +1 -0
- package/dist/tools/workflows/save-workflow.d.ts +1125 -0
- package/dist/tools/workflows/save-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/save-workflow.js +28 -0
- package/dist/tools/workflows/save-workflow.js.map +1 -0
- package/dist/tools/workflows/tool-ids.d.ts +16 -0
- package/dist/tools/workflows/tool-ids.d.ts.map +1 -0
- package/dist/tools/workflows/tool-ids.js +20 -0
- package/dist/tools/workflows/tool-ids.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/discarding-scores-storage.d.ts +33 -0
- package/dist/utils/discarding-scores-storage.d.ts.map +1 -0
- package/dist/utils/discarding-scores-storage.js +54 -0
- package/dist/utils/discarding-scores-storage.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 +196 -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/maintenance-lock.d.ts +42 -0
- package/dist/utils/maintenance-lock.d.ts.map +1 -0
- package/dist/utils/maintenance-lock.js +199 -0
- package/dist/utils/maintenance-lock.js.map +1 -0
- package/dist/utils/notification-dispatch.d.ts +59 -0
- package/dist/utils/notification-dispatch.d.ts.map +1 -0
- package/dist/utils/notification-dispatch.js +109 -0
- package/dist/utils/notification-dispatch.js.map +1 -0
- package/dist/utils/open-url.d.ts +10 -0
- package/dist/utils/open-url.d.ts.map +1 -0
- package/dist/utils/open-url.js +30 -0
- package/dist/utils/open-url.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 +59 -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/prune-cli.d.ts +24 -0
- package/dist/utils/prune-cli.d.ts.map +1 -0
- package/dist/utils/prune-cli.js +125 -0
- package/dist/utils/prune-cli.js.map +1 -0
- package/dist/utils/signals-pubsub.d.ts +101 -0
- package/dist/utils/signals-pubsub.d.ts.map +1 -0
- package/dist/utils/signals-pubsub.js +410 -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 +142 -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 +109 -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 +121 -0
- package/dist/utils/storage-maintenance.d.ts.map +1 -0
- package/dist/utils/storage-maintenance.js +355 -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 +151 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/dist/utils/update-check.js +432 -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/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.d.ts.map +1 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/register-primitives.js.map +1 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.d.ts.map +1 -0
- package/dist/workflows/service.js +53 -0
- package/dist/workflows/service.js.map +1 -0
- package/package.json +107 -0
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
import { posix } from "path";
|
|
2
|
+
import { DirectoryNotFoundError, FileExistsError, FileNotFoundError, IsDirectoryError, NotDirectoryError, UnsupportedGrepPatternError } from "@mastra/core/workspace";
|
|
3
|
+
//#region src/agents/sandbox-filesystem.ts
|
|
4
|
+
/**
|
|
5
|
+
* SandboxFilesystem
|
|
6
|
+
*
|
|
7
|
+
* A `WorkspaceFilesystem` that stores files inside a remote `MastraSandbox`
|
|
8
|
+
* (e.g. a Railway VM) rather than on the server host. File operations are
|
|
9
|
+
* implemented by shelling out through the sandbox's `executeCommand`, so the
|
|
10
|
+
* agent's file tools and command tools share one VM and one view of the repo.
|
|
11
|
+
*
|
|
12
|
+
* Paths are workspace-relative (`/src/foo.ts`) and resolve under the sandbox
|
|
13
|
+
* working directory (`basePath`). A traversal guard rejects any path that
|
|
14
|
+
* escapes the workdir, mirroring `LocalFilesystem`'s contained mode.
|
|
15
|
+
*
|
|
16
|
+
* Reads/writes use base64 over the wire so binary content survives the shell.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Sentinel exit codes used by guard clauses that run before the real command,
|
|
20
|
+
* so shell failures can be mapped to typed filesystem errors.
|
|
21
|
+
*/
|
|
22
|
+
const EXIT_NOT_FOUND = 20;
|
|
23
|
+
const EXIT_IS_DIRECTORY = 21;
|
|
24
|
+
const EXIT_EXISTS = 22;
|
|
25
|
+
const EXIT_NOT_DIRECTORY = 23;
|
|
26
|
+
/** Default per-command deadline so a hung sandbox can't block file tools forever. */
|
|
27
|
+
const COMMAND_TIMEOUT_MS = 3e4;
|
|
28
|
+
/** Single-quote a string for safe POSIX shell interpolation. */
|
|
29
|
+
function shellQuote(value) {
|
|
30
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
31
|
+
}
|
|
32
|
+
function isFileContentString(content) {
|
|
33
|
+
return typeof content === "string";
|
|
34
|
+
}
|
|
35
|
+
function toBuffer(content) {
|
|
36
|
+
if (isFileContentString(content)) return Buffer.from(content, "utf8");
|
|
37
|
+
return Buffer.from(content);
|
|
38
|
+
}
|
|
39
|
+
var SandboxFilesystem = class SandboxFilesystem {
|
|
40
|
+
id;
|
|
41
|
+
name = "SandboxFilesystem";
|
|
42
|
+
provider = "sandbox";
|
|
43
|
+
status = "ready";
|
|
44
|
+
sandbox;
|
|
45
|
+
workdirSource;
|
|
46
|
+
resolvedBase;
|
|
47
|
+
resolvingBase;
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.sandbox = options.sandbox;
|
|
50
|
+
this.workdirSource = options.workdir;
|
|
51
|
+
if (typeof options.workdir === "string") this.resolvedBase = options.workdir;
|
|
52
|
+
this.id = options.id ?? (typeof options.workdir === "string" ? `sandbox-fs:${options.sandbox.id}:${options.workdir}` : `sandbox-fs:${options.sandbox.id}`);
|
|
53
|
+
}
|
|
54
|
+
/** The resolved workspace root; empty until a lazy workdir first resolves. */
|
|
55
|
+
get basePath() {
|
|
56
|
+
return this.resolvedBase ?? "";
|
|
57
|
+
}
|
|
58
|
+
/** Await (and memoize) the workspace root, resolving a lazy workdir once. */
|
|
59
|
+
async base() {
|
|
60
|
+
if (this.resolvedBase) return this.resolvedBase;
|
|
61
|
+
const source = this.workdirSource;
|
|
62
|
+
if (typeof source === "string") return this.resolvedBase = source;
|
|
63
|
+
this.resolvingBase ??= Promise.resolve().then(source).then((resolved) => {
|
|
64
|
+
if (!resolved) throw new Error("Sandbox workspace root resolution returned an empty path");
|
|
65
|
+
return this.resolvedBase = resolved;
|
|
66
|
+
}).finally(() => {
|
|
67
|
+
this.resolvingBase = void 0;
|
|
68
|
+
});
|
|
69
|
+
return this.resolvingBase;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolve a workspace path to an absolute path inside the sandbox, enforcing
|
|
73
|
+
* that it stays within the workdir. Awaits the workspace root first, which
|
|
74
|
+
* for a lazy workdir may start the VM.
|
|
75
|
+
*/
|
|
76
|
+
async resolveAsync(inputPath) {
|
|
77
|
+
return this.resolveAgainst(await this.base(), inputPath);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolve a workspace path against a known base, enforcing that it stays
|
|
81
|
+
* within the workdir.
|
|
82
|
+
*
|
|
83
|
+
* Accepts both workspace-relative paths (`src/foo.ts`, `/src/foo.ts`) and
|
|
84
|
+
* absolute sandbox paths that already live under the workdir — the agent's
|
|
85
|
+
* prompt advertises the workdir as its working directory, so tools are
|
|
86
|
+
* routinely called with fully-qualified paths like `<workdir>/src/foo.ts`.
|
|
87
|
+
*/
|
|
88
|
+
resolveAgainst(basePath, inputPath) {
|
|
89
|
+
const base = posix.normalize(basePath);
|
|
90
|
+
const normalizedInput = posix.normalize(inputPath);
|
|
91
|
+
const rel = normalizedInput === base ? "" : normalizedInput.startsWith(`${base}/`) ? normalizedInput.slice(base.length + 1) : inputPath.startsWith("/") ? inputPath.slice(1) : inputPath;
|
|
92
|
+
const resolved = posix.normalize(posix.join(base, rel));
|
|
93
|
+
if (resolved !== base && !resolved.startsWith(`${base}/`)) throw new Error(`Path escapes workspace root: ${inputPath}`);
|
|
94
|
+
return resolved;
|
|
95
|
+
}
|
|
96
|
+
resolveAbsolutePath(inputPath) {
|
|
97
|
+
if (!this.resolvedBase) return void 0;
|
|
98
|
+
return this.resolveAgainst(this.resolvedBase, inputPath);
|
|
99
|
+
}
|
|
100
|
+
async exec(script) {
|
|
101
|
+
return this.sandbox.executeCommand("sh", ["-c", script], {
|
|
102
|
+
timeout: COMMAND_TIMEOUT_MS,
|
|
103
|
+
maxRetainedBytes: Infinity
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Lexical guard catches `..` traversal, but a symlink inside the workdir can
|
|
108
|
+
* still point outside it. After resolving a path that refers to an existing
|
|
109
|
+
* entry, verify its realpath is still contained in the workdir.
|
|
110
|
+
*
|
|
111
|
+
* Canonicalization tries `realpath`, then `readlink -f` (GNU/busybox), then
|
|
112
|
+
* `cd && pwd -P` for directories — covering GNU hosts, macOS/BSD, and
|
|
113
|
+
* busybox. If the path exists but cannot be canonicalized we fail CLOSED:
|
|
114
|
+
* returning without a check would let a symlink bypass containment.
|
|
115
|
+
*/
|
|
116
|
+
async assertContainedRealpath(abs, inputPath) {
|
|
117
|
+
const result = await this.exec([
|
|
118
|
+
`p=${shellQuote(abs)}`,
|
|
119
|
+
`if [ ! -e "$p" ] && [ ! -L "$p" ]; then exit ${EXIT_NOT_FOUND}; fi`,
|
|
120
|
+
`root=$(cd ${shellQuote(this.basePath)} 2>/dev/null && pwd -P)`,
|
|
121
|
+
`[ -n "$root" ] || exit 1`,
|
|
122
|
+
`rp=$(realpath "$p" 2>/dev/null) || rp=$(readlink -f "$p" 2>/dev/null) || { [ -d "$p" ] && rp=$(cd "$p" 2>/dev/null && pwd -P); }`,
|
|
123
|
+
`[ -n "$rp" ] || exit 1`,
|
|
124
|
+
`printf '%s\\n%s' "$root" "$rp"`
|
|
125
|
+
].join("\n"));
|
|
126
|
+
if (result.exitCode === EXIT_NOT_FOUND) return;
|
|
127
|
+
const [root, real] = result.stdout.split("\n").map((s) => s.trim());
|
|
128
|
+
if (result.exitCode !== 0 || !root || !real) throw new Error(`Unable to verify path stays within workspace root: ${inputPath}`);
|
|
129
|
+
if (real !== root && !real.startsWith(`${root}/`)) throw new Error(`Path escapes workspace root (symlink): ${inputPath}`);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Guard for write destinations. The lexical guard catches `..`, but a symlink
|
|
133
|
+
* inside the workdir can redirect a write outside it. For an existing target
|
|
134
|
+
* we check its realpath; for a not-yet-existing target we check the realpath
|
|
135
|
+
* of its nearest existing ancestor directory, since a symlinked parent is the
|
|
136
|
+
* escape vector (e.g. `link -> /etc` then writing `link/passwd`).
|
|
137
|
+
*/
|
|
138
|
+
async assertContainedDest(abs, inputPath) {
|
|
139
|
+
await this.assertContainedRealpath(abs, inputPath);
|
|
140
|
+
const parent = posix.dirname(abs);
|
|
141
|
+
if (parent && parent !== abs) await this.assertContainedRealpath(parent, inputPath);
|
|
142
|
+
}
|
|
143
|
+
async execOk(script, context) {
|
|
144
|
+
const result = await this.exec(script);
|
|
145
|
+
if (result.exitCode !== 0) throw new Error(`${context} failed (exit ${result.exitCode}): ${result.stderr.trim() || result.stdout.trim()}`);
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
async readFile(path, options) {
|
|
149
|
+
const abs = await this.resolveAsync(path);
|
|
150
|
+
await this.assertContainedRealpath(abs, path);
|
|
151
|
+
const result = await this.exec(`if [ -d ${shellQuote(abs)} ]; then exit ${EXIT_IS_DIRECTORY}; elif [ ! -e ${shellQuote(abs)} ]; then exit ${EXIT_NOT_FOUND}; fi; base64 < ${shellQuote(abs)}`);
|
|
152
|
+
if (result.exitCode === EXIT_IS_DIRECTORY) throw new IsDirectoryError(path);
|
|
153
|
+
if (result.exitCode === EXIT_NOT_FOUND) throw new FileNotFoundError(path);
|
|
154
|
+
if (result.exitCode !== 0) throw new Error(`readFile ${path} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
155
|
+
const buffer = Buffer.from(result.stdout.replace(/\s/g, ""), "base64");
|
|
156
|
+
if (options?.encoding) return buffer.toString(options.encoding);
|
|
157
|
+
return buffer;
|
|
158
|
+
}
|
|
159
|
+
async writeFile(path, content, options) {
|
|
160
|
+
const abs = await this.resolveAsync(path);
|
|
161
|
+
await this.assertContainedDest(abs, path);
|
|
162
|
+
const b64 = toBuffer(content).toString("base64");
|
|
163
|
+
const dir = posix.dirname(abs);
|
|
164
|
+
const mkdir = options?.recursive === false ? "" : `mkdir -p ${shellQuote(dir)} && `;
|
|
165
|
+
if (options?.overwrite === false) {
|
|
166
|
+
const result = await this.exec(`${mkdir}{ (set -C; printf %s ${shellQuote(b64)} | base64 -d > ${shellQuote(abs)}) 2>/dev/null || { [ -e ${shellQuote(abs)} ] && exit ${EXIT_EXISTS} || exit 1; }; }`);
|
|
167
|
+
if (result.exitCode === EXIT_EXISTS) throw new FileExistsError(path);
|
|
168
|
+
if (result.exitCode !== 0) throw new Error(`writeFile ${path} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
await this.execOk(`${mkdir}printf %s ${shellQuote(b64)} | base64 -d > ${shellQuote(abs)}`, `writeFile ${path}`);
|
|
172
|
+
}
|
|
173
|
+
async appendFile(path, content) {
|
|
174
|
+
const abs = await this.resolveAsync(path);
|
|
175
|
+
await this.assertContainedDest(abs, path);
|
|
176
|
+
const b64 = toBuffer(content).toString("base64");
|
|
177
|
+
await this.execOk(`mkdir -p ${shellQuote(posix.dirname(abs))} && printf %s ${shellQuote(b64)} | base64 -d >> ${shellQuote(abs)}`, `appendFile ${path}`);
|
|
178
|
+
}
|
|
179
|
+
async deleteFile(path, options) {
|
|
180
|
+
const abs = await this.resolveAsync(path);
|
|
181
|
+
await this.assertContainedRealpath(posix.dirname(abs), path);
|
|
182
|
+
if (options?.force) {
|
|
183
|
+
await this.execOk(`rm -f ${shellQuote(abs)}`, `deleteFile ${path}`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const result = await this.exec(`if [ ! -e ${shellQuote(abs)} ]; then exit ${EXIT_NOT_FOUND}; fi; rm ${shellQuote(abs)}`);
|
|
187
|
+
if (result.exitCode === EXIT_NOT_FOUND) throw new FileNotFoundError(path);
|
|
188
|
+
if (result.exitCode !== 0) throw new Error(`deleteFile ${path} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
189
|
+
}
|
|
190
|
+
async copyFile(src, dest, options) {
|
|
191
|
+
const srcAbs = await this.resolveAsync(src);
|
|
192
|
+
const destAbs = await this.resolveAsync(dest);
|
|
193
|
+
await this.assertContainedRealpath(srcAbs, src);
|
|
194
|
+
await this.assertContainedDest(destAbs, dest);
|
|
195
|
+
const recursive = options?.recursive ? "-r " : "";
|
|
196
|
+
if (options?.overwrite === false) {
|
|
197
|
+
const result = await this.exec([
|
|
198
|
+
`src=${shellQuote(srcAbs)}`,
|
|
199
|
+
`dest=${shellQuote(destAbs)}`,
|
|
200
|
+
`if [ ! -e "$src" ] && [ ! -L "$src" ]; then exit ${EXIT_NOT_FOUND}; fi`,
|
|
201
|
+
`mkdir -p ${shellQuote(posix.dirname(destAbs))} || exit 1`,
|
|
202
|
+
`if [ -d "$src" ]; then`,
|
|
203
|
+
` mkdir "$dest" 2>/dev/null || exit ${EXIT_EXISTS}`,
|
|
204
|
+
` cp -R "$src"/. "$dest"/`,
|
|
205
|
+
`else`,
|
|
206
|
+
` tmp="$dest.__cptmp$$"`,
|
|
207
|
+
` cp "$src" "$tmp" || exit 1`,
|
|
208
|
+
` ln "$tmp" "$dest" 2>/dev/null || { rm -f "$tmp"; [ -e "$dest" ] && exit ${EXIT_EXISTS} || exit 1; }`,
|
|
209
|
+
` rm -f "$tmp"`,
|
|
210
|
+
`fi`
|
|
211
|
+
].join("\n"));
|
|
212
|
+
if (result.exitCode === EXIT_NOT_FOUND) throw new FileNotFoundError(src);
|
|
213
|
+
if (result.exitCode === EXIT_EXISTS) throw new FileExistsError(dest);
|
|
214
|
+
if (result.exitCode !== 0) throw new Error(`copyFile ${src} -> ${dest} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const result = await this.exec(`if [ ! -e ${shellQuote(srcAbs)} ]; then exit ${EXIT_NOT_FOUND}; fi; mkdir -p ${shellQuote(posix.dirname(destAbs))} && cp ${recursive}${shellQuote(srcAbs)} ${shellQuote(destAbs)}`);
|
|
218
|
+
if (result.exitCode === EXIT_NOT_FOUND) throw new FileNotFoundError(src);
|
|
219
|
+
if (result.exitCode !== 0) throw new Error(`copyFile ${src} -> ${dest} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
220
|
+
}
|
|
221
|
+
async moveFile(src, dest, options) {
|
|
222
|
+
const srcAbs = await this.resolveAsync(src);
|
|
223
|
+
const destAbs = await this.resolveAsync(dest);
|
|
224
|
+
await this.assertContainedRealpath(srcAbs, src);
|
|
225
|
+
await this.assertContainedDest(destAbs, dest);
|
|
226
|
+
if (options?.overwrite === false) {
|
|
227
|
+
const result = await this.exec([
|
|
228
|
+
`src=${shellQuote(srcAbs)}`,
|
|
229
|
+
`dest=${shellQuote(destAbs)}`,
|
|
230
|
+
`if [ ! -e "$src" ] && [ ! -L "$src" ]; then exit ${EXIT_NOT_FOUND}; fi`,
|
|
231
|
+
`mkdir -p ${shellQuote(posix.dirname(destAbs))} || exit 1`,
|
|
232
|
+
`mv -n "$src" "$dest" 2>/dev/null || exit 1`,
|
|
233
|
+
`if [ -e "$src" ] || [ -L "$src" ]; then exit ${EXIT_EXISTS}; fi`
|
|
234
|
+
].join("\n"));
|
|
235
|
+
if (result.exitCode === EXIT_NOT_FOUND) throw new FileNotFoundError(src);
|
|
236
|
+
if (result.exitCode === EXIT_EXISTS) throw new FileExistsError(dest);
|
|
237
|
+
if (result.exitCode !== 0) throw new Error(`moveFile ${src} -> ${dest} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const result = await this.exec(`if [ ! -e ${shellQuote(srcAbs)} ]; then exit ${EXIT_NOT_FOUND}; fi; mkdir -p ${shellQuote(posix.dirname(destAbs))} && mv ${shellQuote(srcAbs)} ${shellQuote(destAbs)}`);
|
|
241
|
+
if (result.exitCode === EXIT_NOT_FOUND) throw new FileNotFoundError(src);
|
|
242
|
+
if (result.exitCode !== 0) throw new Error(`moveFile ${src} -> ${dest} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
243
|
+
}
|
|
244
|
+
async mkdir(path, options) {
|
|
245
|
+
const abs = await this.resolveAsync(path);
|
|
246
|
+
await this.assertContainedDest(abs, path);
|
|
247
|
+
const flag = options?.recursive === false ? "" : "-p ";
|
|
248
|
+
await this.execOk(`mkdir ${flag}${shellQuote(abs)}`, `mkdir ${path}`);
|
|
249
|
+
}
|
|
250
|
+
async rmdir(path, options) {
|
|
251
|
+
const abs = await this.resolveAsync(path);
|
|
252
|
+
await this.assertContainedRealpath(posix.dirname(abs), path);
|
|
253
|
+
if (options?.recursive) {
|
|
254
|
+
const force = options?.force ? "-f " : "";
|
|
255
|
+
await this.execOk(`rm -r ${force}${shellQuote(abs)}`, `rmdir ${path}`);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if ((await this.exec(`rmdir ${shellQuote(abs)}`)).exitCode !== 0 && !options?.force) throw new Error(`Directory not empty or not found: ${path}`);
|
|
259
|
+
}
|
|
260
|
+
async readdir(path, options) {
|
|
261
|
+
const abs = await this.resolveAsync(path);
|
|
262
|
+
await this.assertContainedRealpath(abs, path);
|
|
263
|
+
if (options?.recursive) {
|
|
264
|
+
const result = await this.exec(`test -d ${shellQuote(abs)} && find ${shellQuote(abs)} -mindepth 1 ${options.maxDepth ? `-maxdepth ${Number(options.maxDepth)} ` : ""}2>/dev/null | while IFS= read -r f; do if [ -d "$f" ]; then printf 'd\\t%s\\n' "$f"; else printf 'f\\t%s\\n' "$f"; fi; done`);
|
|
265
|
+
if (result.exitCode !== 0) throw new Error(`Directory not found: ${path}`);
|
|
266
|
+
return this.parseFindOutput(result.stdout, abs, options);
|
|
267
|
+
}
|
|
268
|
+
const result = await this.exec(`cd ${shellQuote(abs)} 2>/dev/null && for f in * .[!.]*; do [ -e "$f" ] || continue; if [ -d "$f" ]; then printf 'd\\t%s\\n' "$f"; else printf 'f\\t%s\\n' "$f"; fi; done`);
|
|
269
|
+
if (result.exitCode !== 0) throw new Error(`Directory not found: ${path}`);
|
|
270
|
+
return this.parseListOutput(result.stdout, options);
|
|
271
|
+
}
|
|
272
|
+
parseListOutput(stdout, options) {
|
|
273
|
+
const entries = [];
|
|
274
|
+
for (const line of stdout.split("\n")) {
|
|
275
|
+
if (!line) continue;
|
|
276
|
+
const tab = line.indexOf(" ");
|
|
277
|
+
if (tab < 0) continue;
|
|
278
|
+
const type = line.slice(0, tab) === "d" ? "directory" : "file";
|
|
279
|
+
const name = line.slice(tab + 1);
|
|
280
|
+
if (!name || name === "." || name === "..") continue;
|
|
281
|
+
if (type === "file" && !this.matchesExtension(name, options?.extension)) continue;
|
|
282
|
+
entries.push({
|
|
283
|
+
name,
|
|
284
|
+
type
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
return entries;
|
|
288
|
+
}
|
|
289
|
+
parseFindOutput(stdout, base, options) {
|
|
290
|
+
const entries = [];
|
|
291
|
+
for (const line of stdout.split("\n")) {
|
|
292
|
+
if (!line) continue;
|
|
293
|
+
const tab = line.indexOf(" ");
|
|
294
|
+
if (tab < 0) continue;
|
|
295
|
+
const type = line.slice(0, tab) === "d" ? "directory" : "file";
|
|
296
|
+
const fullPath = line.slice(tab + 1);
|
|
297
|
+
const name = posix.relative(base, fullPath);
|
|
298
|
+
if (!name) continue;
|
|
299
|
+
if (type === "file" && !this.matchesExtension(name, options?.extension)) continue;
|
|
300
|
+
entries.push({
|
|
301
|
+
name,
|
|
302
|
+
type
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
return entries;
|
|
306
|
+
}
|
|
307
|
+
matchesExtension(name, extension) {
|
|
308
|
+
if (!extension) return true;
|
|
309
|
+
return (Array.isArray(extension) ? extension : [extension]).some((ext) => name.endsWith(ext));
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Walk the tree in a single sandbox command instead of one readdir round
|
|
313
|
+
* trip per directory. Uses `find` with a portable classification loop
|
|
314
|
+
* (`find -printf` is GNU-only and fails on macOS/BSD hosts). `find` does
|
|
315
|
+
* not follow symlinked directories by default, matching the host-side
|
|
316
|
+
* walker's no-recursion-into-symlinks behavior.
|
|
317
|
+
*/
|
|
318
|
+
async walk(path, options) {
|
|
319
|
+
const abs = await this.resolveAsync(path);
|
|
320
|
+
await this.assertContainedRealpath(abs, path);
|
|
321
|
+
const maxDepth = options?.maxDepth !== void 0 && Number.isFinite(options.maxDepth) ? `-maxdepth ${Math.max(0, Math.floor(options.maxDepth))} ` : "";
|
|
322
|
+
const hiddenPrune = options?.includeHidden ? "" : `-name '.*' -prune -o `;
|
|
323
|
+
const script = `root=${shellQuote(abs)}\n[ -e "$root" ] || [ -L "$root" ] || exit ${EXIT_NOT_FOUND}\n[ -d "$root" ] || exit ${EXIT_NOT_DIRECTORY}\nfind "$root" -mindepth 1 ${maxDepth}${hiddenPrune}-print 2>/dev/null | while IFS= read -r f; do if [ -L "$f" ]; then if [ -d "$f" ]; then t=D; else t=F; fi; printf '%s\\t%s\\t%s\\n' "$t" "$f" "$(readlink "$f")"; elif [ -d "$f" ]; then printf 'd\\t%s\\n' "$f"; else printf 'f\\t%s\\n' "$f"; fi; done`;
|
|
324
|
+
const result = await this.exec(script);
|
|
325
|
+
if (result.exitCode === EXIT_NOT_FOUND) throw new DirectoryNotFoundError(path);
|
|
326
|
+
if (result.exitCode === EXIT_NOT_DIRECTORY) throw new NotDirectoryError(path);
|
|
327
|
+
if (result.exitCode !== 0) throw new Error(`walk ${path} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
|
|
328
|
+
const entries = [];
|
|
329
|
+
for (const line of result.stdout.split("\n")) {
|
|
330
|
+
if (!line) continue;
|
|
331
|
+
const tab = line.indexOf(" ");
|
|
332
|
+
if (tab < 0) continue;
|
|
333
|
+
const flag = line.slice(0, tab);
|
|
334
|
+
const isSymlink = flag === "D" || flag === "F";
|
|
335
|
+
let fullPath = line.slice(tab + 1);
|
|
336
|
+
let symlinkTarget;
|
|
337
|
+
if (isSymlink) {
|
|
338
|
+
const tab2 = fullPath.lastIndexOf(" ");
|
|
339
|
+
if (tab2 >= 0) {
|
|
340
|
+
symlinkTarget = fullPath.slice(tab2 + 1) || void 0;
|
|
341
|
+
fullPath = fullPath.slice(0, tab2);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const rel = posix.relative(abs, fullPath);
|
|
345
|
+
if (!rel || rel.startsWith("..")) continue;
|
|
346
|
+
entries.push({
|
|
347
|
+
name: posix.basename(rel),
|
|
348
|
+
type: flag === "d" || flag === "D" ? "directory" : "file",
|
|
349
|
+
...isSymlink ? {
|
|
350
|
+
isSymlink: true,
|
|
351
|
+
...symlinkTarget ? { symlinkTarget } : {}
|
|
352
|
+
} : {},
|
|
353
|
+
path: rel
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
return entries;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Content search executed inside the sandbox in one command. Prefers
|
|
360
|
+
* ripgrep (`rg --json`) when installed; otherwise falls back to
|
|
361
|
+
* `grep -rnE`. Patterns the ERE fallback can't express (PCRE-style classes,
|
|
362
|
+
* word boundaries, lookarounds, non-greedy quantifiers) throw
|
|
363
|
+
* {@link UnsupportedGrepPatternError} so callers use their host-side walk.
|
|
364
|
+
*
|
|
365
|
+
* Callers are expected to apply their own gitignore/hidden/glob filtering
|
|
366
|
+
* to the returned paths; both engines run with ignore rules disabled so
|
|
367
|
+
* results are a superset of what any host-side filter would keep.
|
|
368
|
+
*/
|
|
369
|
+
async grep(options) {
|
|
370
|
+
const abs = await this.resolveAsync(options.path);
|
|
371
|
+
await this.assertContainedRealpath(abs, options.path);
|
|
372
|
+
if (await this.hasRipgrep()) return this.grepWithRipgrep(abs, options);
|
|
373
|
+
return this.grepWithPosixGrep(abs, options);
|
|
374
|
+
}
|
|
375
|
+
rgCheck;
|
|
376
|
+
hasRipgrep() {
|
|
377
|
+
this.rgCheck ??= this.exec("command -v rg >/dev/null 2>&1").then((r) => r.exitCode === 0, () => false);
|
|
378
|
+
return this.rgCheck;
|
|
379
|
+
}
|
|
380
|
+
async grepWithRipgrep(abs, options) {
|
|
381
|
+
const args = [
|
|
382
|
+
"rg --json --no-ignore --hidden",
|
|
383
|
+
`-g ${shellQuote("!.git/**")}`,
|
|
384
|
+
options.caseSensitive ? "" : "-i",
|
|
385
|
+
options.maxCountPerFile !== void 0 ? `-m ${Math.max(1, Math.floor(options.maxCountPerFile))}` : "",
|
|
386
|
+
options.contextLines ? `-C ${Math.max(0, Math.floor(options.contextLines))}` : "",
|
|
387
|
+
`-e ${shellQuote(options.pattern)}`,
|
|
388
|
+
shellQuote(abs)
|
|
389
|
+
].filter(Boolean).join(" ");
|
|
390
|
+
const result = await this.exec(args);
|
|
391
|
+
if (result.exitCode === 1) return [];
|
|
392
|
+
const results = this.parseRipgrepJson(result.stdout, abs, options);
|
|
393
|
+
if (result.exitCode !== 0 && results.length === 0) throw new UnsupportedGrepPatternError(options.pattern);
|
|
394
|
+
return results;
|
|
395
|
+
}
|
|
396
|
+
parseRipgrepJson(stdout, abs, options) {
|
|
397
|
+
const files = /* @__PURE__ */ new Map();
|
|
398
|
+
for (const line of stdout.split("\n")) {
|
|
399
|
+
if (!line) continue;
|
|
400
|
+
let event;
|
|
401
|
+
try {
|
|
402
|
+
event = JSON.parse(line);
|
|
403
|
+
} catch {
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (event.type !== "match" && event.type !== "context") continue;
|
|
407
|
+
const filePath = event.data?.path?.text;
|
|
408
|
+
const lineNumber = event.data?.line_number;
|
|
409
|
+
if (!filePath || !lineNumber) continue;
|
|
410
|
+
let state = files.get(filePath);
|
|
411
|
+
if (!state) {
|
|
412
|
+
state = {
|
|
413
|
+
matches: [],
|
|
414
|
+
linesByNumber: /* @__PURE__ */ new Map()
|
|
415
|
+
};
|
|
416
|
+
files.set(filePath, state);
|
|
417
|
+
}
|
|
418
|
+
const text = (event.data?.lines?.text ?? "").replace(/\r?\n$/, "");
|
|
419
|
+
state.linesByNumber.set(lineNumber, text);
|
|
420
|
+
if (event.type === "match") {
|
|
421
|
+
const byteStart = event.data?.submatches?.[0]?.start ?? 0;
|
|
422
|
+
const column = Buffer.from(text, "utf8").subarray(0, byteStart).toString("utf8").length;
|
|
423
|
+
state.matches.push({
|
|
424
|
+
line: lineNumber,
|
|
425
|
+
column,
|
|
426
|
+
text,
|
|
427
|
+
lineNumber
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const contextLines = options.contextLines ?? 0;
|
|
432
|
+
const results = [];
|
|
433
|
+
for (const [filePath, state] of files) {
|
|
434
|
+
if (state.matches.length === 0) continue;
|
|
435
|
+
const rel = posix.relative(abs, filePath) || posix.basename(filePath);
|
|
436
|
+
const matches = state.matches.map(({ lineNumber, ...match }) => {
|
|
437
|
+
if (contextLines <= 0) return match;
|
|
438
|
+
const before = [];
|
|
439
|
+
for (let n = lineNumber - 1; n >= Math.max(1, lineNumber - contextLines); n--) {
|
|
440
|
+
const t = state.linesByNumber.get(n);
|
|
441
|
+
if (t === void 0) break;
|
|
442
|
+
before.unshift(t);
|
|
443
|
+
}
|
|
444
|
+
const after = [];
|
|
445
|
+
for (let n = lineNumber + 1; n <= lineNumber + contextLines; n++) {
|
|
446
|
+
const t = state.linesByNumber.get(n);
|
|
447
|
+
if (t === void 0) break;
|
|
448
|
+
after.push(t);
|
|
449
|
+
}
|
|
450
|
+
return {
|
|
451
|
+
...match,
|
|
452
|
+
before,
|
|
453
|
+
after
|
|
454
|
+
};
|
|
455
|
+
});
|
|
456
|
+
results.push({
|
|
457
|
+
path: rel,
|
|
458
|
+
matches
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
return this.applyTotalCap(results, options.maxTotalMatches);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Patterns whose meaning differs between POSIX ERE and JS RegExp. The grep
|
|
465
|
+
* runs with ERE but match columns are recomputed with JS, so anything that
|
|
466
|
+
* only one side understands (PCRE classes, lookarounds, lazy quantifiers,
|
|
467
|
+
* POSIX bracket classes, GNU word anchors) must fall back to the host walk.
|
|
468
|
+
*/
|
|
469
|
+
static ERE_UNSUPPORTED = /\\[dDwWsSbB<>]|\(\?|[*+?}]\?|\[:[a-z]+:\]/;
|
|
470
|
+
async grepWithPosixGrep(abs, options) {
|
|
471
|
+
if (SandboxFilesystem.ERE_UNSUPPORTED.test(options.pattern)) throw new UnsupportedGrepPatternError(options.pattern);
|
|
472
|
+
let jsRegex;
|
|
473
|
+
try {
|
|
474
|
+
jsRegex = new RegExp(options.pattern, options.caseSensitive ? "" : "i");
|
|
475
|
+
} catch {
|
|
476
|
+
throw new UnsupportedGrepPatternError(options.pattern);
|
|
477
|
+
}
|
|
478
|
+
if (options.contextLines) throw new UnsupportedGrepPatternError(options.pattern);
|
|
479
|
+
const args = [
|
|
480
|
+
"grep -rnIE",
|
|
481
|
+
options.caseSensitive ? "" : "-i",
|
|
482
|
+
options.maxCountPerFile !== void 0 ? `-m ${Math.max(1, Math.floor(options.maxCountPerFile))}` : "",
|
|
483
|
+
"--",
|
|
484
|
+
shellQuote(options.pattern),
|
|
485
|
+
shellQuote(abs)
|
|
486
|
+
].filter(Boolean).join(" ");
|
|
487
|
+
const result = await this.exec(args);
|
|
488
|
+
if (result.exitCode === 1) return [];
|
|
489
|
+
if (result.exitCode !== 0) throw new UnsupportedGrepPatternError(options.pattern);
|
|
490
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
491
|
+
for (const line of result.stdout.split("\n")) {
|
|
492
|
+
if (!line) continue;
|
|
493
|
+
const parsed = /^(.*?):(\d+):(.*)$/.exec(line);
|
|
494
|
+
if (!parsed) continue;
|
|
495
|
+
const rel = posix.relative(abs, parsed[1]) || posix.basename(parsed[1]);
|
|
496
|
+
const text = parsed[3];
|
|
497
|
+
const column = jsRegex.exec(text)?.index;
|
|
498
|
+
if (column === void 0) throw new UnsupportedGrepPatternError(options.pattern);
|
|
499
|
+
let matches = byFile.get(rel);
|
|
500
|
+
if (!matches) {
|
|
501
|
+
matches = [];
|
|
502
|
+
byFile.set(rel, matches);
|
|
503
|
+
}
|
|
504
|
+
matches.push({
|
|
505
|
+
line: Number(parsed[2]),
|
|
506
|
+
column,
|
|
507
|
+
text
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
const results = [...byFile.entries()].map(([path, matches]) => ({
|
|
511
|
+
path,
|
|
512
|
+
matches
|
|
513
|
+
}));
|
|
514
|
+
return this.applyTotalCap(results, options.maxTotalMatches);
|
|
515
|
+
}
|
|
516
|
+
applyTotalCap(results, maxTotal) {
|
|
517
|
+
if (maxTotal === void 0) return results;
|
|
518
|
+
const capped = [];
|
|
519
|
+
let total = 0;
|
|
520
|
+
for (const file of results) {
|
|
521
|
+
if (total >= maxTotal) break;
|
|
522
|
+
const remaining = maxTotal - total;
|
|
523
|
+
const matches = file.matches.slice(0, remaining);
|
|
524
|
+
total += matches.length;
|
|
525
|
+
capped.push({
|
|
526
|
+
path: file.path,
|
|
527
|
+
matches
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
return capped;
|
|
531
|
+
}
|
|
532
|
+
async exists(path) {
|
|
533
|
+
const abs = await this.resolveAsync(path);
|
|
534
|
+
return (await this.exec(`test -e ${shellQuote(abs)}`)).exitCode === 0;
|
|
535
|
+
}
|
|
536
|
+
async stat(path) {
|
|
537
|
+
const abs = await this.resolveAsync(path);
|
|
538
|
+
await this.assertContainedRealpath(abs, path);
|
|
539
|
+
const result = await this.exec(`stat -c '%F|%s|%Y|%W' ${shellQuote(abs)} 2>/dev/null || stat -f '%HT|%z|%m|%B' ${shellQuote(abs)}`);
|
|
540
|
+
if (result.exitCode !== 0) throw new FileNotFoundError(path);
|
|
541
|
+
const [kind, sizeStr, mtimeStr, ctimeStr] = result.stdout.trim().split("|");
|
|
542
|
+
const type = kind && kind.toLowerCase().includes("directory") ? "directory" : "file";
|
|
543
|
+
const size = Number(sizeStr) || 0;
|
|
544
|
+
const mtime = Number(mtimeStr) || 0;
|
|
545
|
+
const ctime = Number(ctimeStr);
|
|
546
|
+
return {
|
|
547
|
+
name: posix.basename(abs),
|
|
548
|
+
path: `/${posix.relative(this.basePath, abs)}`,
|
|
549
|
+
type,
|
|
550
|
+
size: type === "directory" ? 0 : size,
|
|
551
|
+
modifiedAt: /* @__PURE__ */ new Date(mtime * 1e3),
|
|
552
|
+
createdAt: /* @__PURE__ */ new Date((ctime > 0 ? ctime : mtime) * 1e3)
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
async init() {
|
|
556
|
+
await this.execOk(`mkdir -p ${shellQuote(await this.base())}`, "init workdir");
|
|
557
|
+
}
|
|
558
|
+
async destroy() {}
|
|
559
|
+
async isReady() {
|
|
560
|
+
return (await this.exec(`test -d ${shellQuote(await this.base())}`)).exitCode === 0;
|
|
561
|
+
}
|
|
562
|
+
getInfo() {
|
|
563
|
+
return {
|
|
564
|
+
id: this.id,
|
|
565
|
+
name: this.name,
|
|
566
|
+
provider: this.provider,
|
|
567
|
+
status: this.status,
|
|
568
|
+
metadata: {
|
|
569
|
+
basePath: this.basePath,
|
|
570
|
+
sandboxId: this.sandbox.id
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
getInstructions() {
|
|
575
|
+
return `Files are stored in a remote sandbox at ${this.basePath}. Use absolute workspace paths like /src/index.ts. All reads, writes and commands run inside the same sandbox.`;
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
//#endregion
|
|
579
|
+
export { SandboxFilesystem };
|
|
580
|
+
|
|
581
|
+
//# sourceMappingURL=sandbox-filesystem.js.map
|