@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,141 @@
|
|
|
1
|
+
import { DEFAULT_CONFIG_DIR } from "../constants.js";
|
|
2
|
+
import { isPathWithinRoot } from "./path-security.js";
|
|
3
|
+
import { promises } from "fs";
|
|
4
|
+
import * as path$1 from "path";
|
|
5
|
+
import { parse } from "yaml";
|
|
6
|
+
//#region src/utils/slash-command-loader.ts
|
|
7
|
+
/**
|
|
8
|
+
* Parse a command file and extract metadata and template
|
|
9
|
+
* Supports both frontmatter-based and plain markdown files
|
|
10
|
+
*/
|
|
11
|
+
async function parseCommandFile(filePath, baseDir) {
|
|
12
|
+
try {
|
|
13
|
+
const content = await promises.readFile(filePath, "utf-8");
|
|
14
|
+
if (!content.trim().startsWith("---")) return {
|
|
15
|
+
name: baseDir ? extractCommandName(filePath, baseDir) : path$1.basename(filePath, ".md"),
|
|
16
|
+
description: "",
|
|
17
|
+
template: content,
|
|
18
|
+
sourcePath: filePath
|
|
19
|
+
};
|
|
20
|
+
const parts = content.split("---");
|
|
21
|
+
if (parts.length < 3) return null;
|
|
22
|
+
const frontmatter = parts[1].trim();
|
|
23
|
+
const template = parts.slice(2).join("---").trim();
|
|
24
|
+
const metadata = parse(frontmatter);
|
|
25
|
+
let name;
|
|
26
|
+
if (typeof metadata?.name === "string" && metadata.name) name = metadata.name;
|
|
27
|
+
else if (baseDir) name = extractCommandName(filePath, baseDir);
|
|
28
|
+
else name = path$1.basename(filePath, ".md");
|
|
29
|
+
return {
|
|
30
|
+
name,
|
|
31
|
+
description: typeof metadata?.description === "string" ? metadata.description : "",
|
|
32
|
+
template,
|
|
33
|
+
sourcePath: filePath,
|
|
34
|
+
namespace: typeof metadata?.namespace === "string" ? metadata.namespace : void 0,
|
|
35
|
+
goal: metadata?.goal === true
|
|
36
|
+
};
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(`Error parsing command file ${filePath}:`, error);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extract command name from file path
|
|
44
|
+
* Converts path like "git/commit.md" to "git:commit"
|
|
45
|
+
*/
|
|
46
|
+
function extractCommandName(filePath, baseDir) {
|
|
47
|
+
const relativePath = path$1.relative(baseDir, filePath);
|
|
48
|
+
const dirName = path$1.dirname(relativePath);
|
|
49
|
+
const baseName = path$1.basename(relativePath, ".md");
|
|
50
|
+
if (dirName === "." || dirName === "") return baseName;
|
|
51
|
+
return `${dirName.replace(/[\\/]/g, ":")}:${baseName}`;
|
|
52
|
+
}
|
|
53
|
+
async function scanCommandDirectory(dirPath, rootDir, options = {}) {
|
|
54
|
+
const baseDir = rootDir ?? dirPath;
|
|
55
|
+
const commands = [];
|
|
56
|
+
const visitedDirectories = options.visitedDirectories ?? /* @__PURE__ */ new Set();
|
|
57
|
+
try {
|
|
58
|
+
const realDirectory = await promises.realpath(dirPath);
|
|
59
|
+
const realAllowedRoot = options.allowedRoot ? await promises.realpath(options.allowedRoot) : void 0;
|
|
60
|
+
if (realAllowedRoot && !isPathWithinRoot(realDirectory, realAllowedRoot)) return commands;
|
|
61
|
+
if (visitedDirectories.has(realDirectory)) return commands;
|
|
62
|
+
visitedDirectories.add(realDirectory);
|
|
63
|
+
const entries = await promises.readdir(dirPath, { withFileTypes: true });
|
|
64
|
+
for (const entry of entries) {
|
|
65
|
+
const fullPath = path$1.join(dirPath, entry.name);
|
|
66
|
+
const stats = entry.isSymbolicLink() ? await promises.stat(fullPath).catch(() => null) : entry;
|
|
67
|
+
if (!stats) continue;
|
|
68
|
+
if (stats.isDirectory()) {
|
|
69
|
+
const subCommands = await scanCommandDirectory(fullPath, baseDir, {
|
|
70
|
+
...options,
|
|
71
|
+
visitedDirectories
|
|
72
|
+
});
|
|
73
|
+
commands.push(...subCommands);
|
|
74
|
+
} else if (entry.name.endsWith(".md") && stats.isFile()) {
|
|
75
|
+
if (realAllowedRoot) {
|
|
76
|
+
const realFile = await promises.realpath(fullPath).catch(() => null);
|
|
77
|
+
if (!realFile || !isPathWithinRoot(realFile, realAllowedRoot)) continue;
|
|
78
|
+
}
|
|
79
|
+
const command = await parseCommandFile(fullPath, baseDir);
|
|
80
|
+
if (command) commands.push(command);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch {}
|
|
84
|
+
return commands;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Load custom slash commands from all configured directories
|
|
88
|
+
* Priority: mastra project > claude project > opencode project > mastra user > claude user > opencode user
|
|
89
|
+
*/
|
|
90
|
+
async function loadCustomCommands(projectDir, configDirName = DEFAULT_CONFIG_DIR, extraCommandDirs = []) {
|
|
91
|
+
const commandMap = /* @__PURE__ */ new Map();
|
|
92
|
+
const addCommands = (newCommands) => {
|
|
93
|
+
for (const cmd of newCommands) commandMap.set(cmd.name, cmd);
|
|
94
|
+
};
|
|
95
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
96
|
+
if (homeDir) addCommands(await scanCommandDirectory(path$1.join(homeDir, ".opencode", "command")));
|
|
97
|
+
if (homeDir) addCommands(await scanCommandDirectory(path$1.join(homeDir, ".claude", "commands")));
|
|
98
|
+
if (homeDir) addCommands(await scanCommandDirectory(path$1.join(homeDir, configDirName, "commands")));
|
|
99
|
+
if (projectDir) addCommands(await scanCommandDirectory(path$1.join(projectDir, ".opencode", "command"), void 0, { allowedRoot: projectDir }));
|
|
100
|
+
if (projectDir) addCommands(await scanCommandDirectory(path$1.join(projectDir, ".claude", "commands"), void 0, { allowedRoot: projectDir }));
|
|
101
|
+
if (projectDir) addCommands(await scanCommandDirectory(path$1.join(projectDir, configDirName, "commands"), void 0, { allowedRoot: projectDir }));
|
|
102
|
+
for (const commandsDir of extraCommandDirs) addCommands(await scanCommandDirectory(commandsDir, void 0, { allowedRoot: commandsDir }));
|
|
103
|
+
return Array.from(commandMap.values());
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the commands directory path for a project
|
|
107
|
+
*/
|
|
108
|
+
function getProjectCommandsDir(projectDir, configDirName = DEFAULT_CONFIG_DIR) {
|
|
109
|
+
return path$1.join(projectDir, configDirName, "commands");
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Initialize a commands directory with an example command
|
|
113
|
+
*/
|
|
114
|
+
async function initCommandsDirectory(projectDir, configDirName = DEFAULT_CONFIG_DIR) {
|
|
115
|
+
const commandsDir = getProjectCommandsDir(projectDir, configDirName);
|
|
116
|
+
try {
|
|
117
|
+
await promises.mkdir(commandsDir, { recursive: true });
|
|
118
|
+
const examplePath = path$1.join(commandsDir, "example.md");
|
|
119
|
+
const exampleContent = `---
|
|
120
|
+
name: example
|
|
121
|
+
description: An example slash command
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
This is an example slash command template.
|
|
125
|
+
You can use variables like \$ARGUMENTS or \$1, \$2 for positional args.
|
|
126
|
+
You can also include file content with @filename.
|
|
127
|
+
Shell commands with !command will be executed and output included.
|
|
128
|
+
`;
|
|
129
|
+
try {
|
|
130
|
+
await promises.access(examplePath);
|
|
131
|
+
} catch {
|
|
132
|
+
await promises.writeFile(examplePath, exampleContent, "utf-8");
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error("Error initializing commands directory:", error);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
export { extractCommandName, getProjectCommandsDir, initCommandsDirectory, loadCustomCommands, parseCommandFile, scanCommandDirectory };
|
|
140
|
+
|
|
141
|
+
//# sourceMappingURL=slash-command-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slash-command-loader.js","names":["fs","path","parseYaml"],"sources":["../../src/utils/slash-command-loader.ts"],"sourcesContent":["import { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport { parse as parseYaml } from 'yaml';\nimport { DEFAULT_CONFIG_DIR } from '../constants.js';\nimport { isPathWithinRoot } from './path-security.js';\n\n/**\n * Metadata for a slash command\n */\nexport interface SlashCommandMetadata {\n /** Command name (e.g., \"git:commit\") */\n name: string;\n /** Human-readable description */\n description: string;\n /** The command template with variables */\n template: string;\n /** Source file path */\n sourcePath: string;\n /** Namespace derived from directory structure */\n namespace?: string;\n /** Whether this command should also be exposed as /goal/<name> */\n goal?: boolean;\n}\n\n/**\n * Parse a command file and extract metadata and template\n * Supports both frontmatter-based and plain markdown files\n */\nexport async function parseCommandFile(filePath: string, baseDir?: string): Promise<SlashCommandMetadata | null> {\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n const trimmedContent = content.trim();\n\n // Check if file has frontmatter (starts with ---)\n if (!trimmedContent.startsWith('---')) {\n // No frontmatter - treat entire file as template\n // Derive name from file path\n const name = baseDir ? extractCommandName(filePath, baseDir) : path.basename(filePath, '.md');\n\n return {\n name,\n description: '',\n template: content,\n sourcePath: filePath,\n };\n }\n\n // Split frontmatter and template\n const parts = content.split('---');\n if (parts.length < 3) {\n return null;\n }\n\n const frontmatter = parts[1]!.trim();\n const template = parts.slice(2).join('---').trim();\n\n // Parse YAML frontmatter\n const metadata = parseYaml(frontmatter) as Record<string, unknown>;\n\n // Derive name from file path if not specified in frontmatter\n let name: string;\n if (typeof metadata?.name === 'string' && metadata.name) {\n name = metadata.name;\n } else if (baseDir) {\n name = extractCommandName(filePath, baseDir);\n } else {\n name = path.basename(filePath, '.md');\n }\n\n return {\n name,\n description: typeof metadata?.description === 'string' ? metadata.description : '',\n template,\n sourcePath: filePath,\n namespace: typeof metadata?.namespace === 'string' ? metadata.namespace : undefined,\n goal: metadata?.goal === true,\n };\n } catch (error) {\n console.error(`Error parsing command file ${filePath}:`, error);\n return null;\n }\n}\n\n/**\n * Extract command name from file path\n * Converts path like \"git/commit.md\" to \"git:commit\"\n */\nexport function extractCommandName(filePath: string, baseDir: string): string {\n const relativePath = path.relative(baseDir, filePath);\n const dirName = path.dirname(relativePath);\n const baseName = path.basename(relativePath, '.md');\n\n if (dirName === '.' || dirName === '') {\n return baseName;\n }\n\n // Replace path separators with colons for namespacing\n const namespace = dirName.replace(/[\\\\/]/g, ':');\n return `${namespace}:${baseName}`;\n}\n\n/**\n * Recursively scan a directory for command files.\n * @param dirPath - Current directory to scan\n * @param rootDir - Original root commands directory (used for namespace derivation).\n * When omitted the first call sets it to dirPath.\n */\nexport interface ScanCommandDirectoryOptions {\n allowedRoot?: string;\n visitedDirectories?: Set<string>;\n}\n\nexport async function scanCommandDirectory(\n dirPath: string,\n rootDir?: string,\n options: ScanCommandDirectoryOptions = {},\n): Promise<SlashCommandMetadata[]> {\n const baseDir = rootDir ?? dirPath;\n const commands: SlashCommandMetadata[] = [];\n const visitedDirectories = options.visitedDirectories ?? new Set<string>();\n\n try {\n const realDirectory = await fs.realpath(dirPath);\n const realAllowedRoot = options.allowedRoot ? await fs.realpath(options.allowedRoot) : undefined;\n if (realAllowedRoot && !isPathWithinRoot(realDirectory, realAllowedRoot)) return commands;\n if (visitedDirectories.has(realDirectory)) return commands;\n visitedDirectories.add(realDirectory);\n\n const entries = await fs.readdir(dirPath, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dirPath, entry.name);\n const stats = entry.isSymbolicLink() ? await fs.stat(fullPath).catch(() => null) : entry;\n if (!stats) continue;\n\n if (stats.isDirectory()) {\n // Recursively scan subdirectories, preserving the root directory for namespace derivation\n const subCommands = await scanCommandDirectory(fullPath, baseDir, {\n ...options,\n visitedDirectories,\n });\n commands.push(...subCommands);\n } else if (entry.name.endsWith('.md') && stats.isFile()) {\n if (realAllowedRoot) {\n const realFile = await fs.realpath(fullPath).catch(() => null);\n if (!realFile || !isPathWithinRoot(realFile, realAllowedRoot)) continue;\n }\n\n // Parse markdown command files, passing the root commands dir as baseDir for name derivation\n const command = await parseCommandFile(fullPath, baseDir);\n if (command) {\n commands.push(command);\n }\n }\n }\n } catch {\n // Directory doesn't exist or can't be read - silently skip\n }\n\n return commands;\n}\n/**\n * Load custom slash commands from all configured directories\n * Priority: mastra project > claude project > opencode project > mastra user > claude user > opencode user\n */\nexport async function loadCustomCommands(\n projectDir?: string,\n configDirName = DEFAULT_CONFIG_DIR,\n extraCommandDirs: string[] = [],\n): Promise<SlashCommandMetadata[]> {\n // Use a Map so later (higher priority) sources override earlier ones with the same name\n const commandMap = new Map<string, SlashCommandMetadata>();\n\n const addCommands = (newCommands: SlashCommandMetadata[]) => {\n for (const cmd of newCommands) {\n commandMap.set(cmd.name, cmd);\n }\n };\n\n const homeDir = process.env.HOME || process.env.USERPROFILE;\n\n // 1. Load from opencode user directory ~/.opencode/command (lowest priority)\n if (homeDir) {\n const opencodeUserDir = path.join(homeDir, '.opencode', 'command');\n const opencodeUserCommands = await scanCommandDirectory(opencodeUserDir);\n addCommands(opencodeUserCommands);\n }\n\n // 2. Load from claude user directory ~/.claude/commands (Claude Code compat)\n if (homeDir) {\n const claudeUserDir = path.join(homeDir, '.claude', 'commands');\n const claudeUserCommands = await scanCommandDirectory(claudeUserDir);\n addCommands(claudeUserCommands);\n }\n\n // 3. Load from mastra user directory ~/<configDirName>/commands\n if (homeDir) {\n const mastraUserDir = path.join(homeDir, configDirName, 'commands');\n const mastraUserCommands = await scanCommandDirectory(mastraUserDir);\n addCommands(mastraUserCommands);\n }\n\n // 4. Load from opencode project directory .opencode/command\n if (projectDir) {\n const opencodeProjectDir = path.join(projectDir, '.opencode', 'command');\n const opencodeProjectCommands = await scanCommandDirectory(opencodeProjectDir, undefined, {\n allowedRoot: projectDir,\n });\n addCommands(opencodeProjectCommands);\n }\n\n // 5. Load from claude project directory .claude/commands (Claude Code compat)\n if (projectDir) {\n const claudeProjectDir = path.join(projectDir, '.claude', 'commands');\n const claudeProjectCommands = await scanCommandDirectory(claudeProjectDir, undefined, {\n allowedRoot: projectDir,\n });\n addCommands(claudeProjectCommands);\n }\n\n // 6. Load from mastra project directory <configDirName>/commands\n if (projectDir) {\n const mastraProjectDir = path.join(projectDir, configDirName, 'commands');\n const mastraProjectCommands = await scanCommandDirectory(mastraProjectDir, undefined, {\n allowedRoot: projectDir,\n });\n addCommands(mastraProjectCommands);\n }\n\n // 7. Load from active plugin command directories (highest priority)\n for (const commandsDir of extraCommandDirs) {\n addCommands(await scanCommandDirectory(commandsDir, undefined, { allowedRoot: commandsDir }));\n }\n\n return Array.from(commandMap.values());\n}\n\n/**\n * Get the commands directory path for a project\n */\nexport function getProjectCommandsDir(projectDir: string, configDirName = DEFAULT_CONFIG_DIR): string {\n return path.join(projectDir, configDirName, 'commands');\n}\n\n/**\n * Initialize a commands directory with an example command\n */\nexport async function initCommandsDirectory(projectDir: string, configDirName = DEFAULT_CONFIG_DIR): Promise<void> {\n const commandsDir = getProjectCommandsDir(projectDir, configDirName);\n\n try {\n await fs.mkdir(commandsDir, { recursive: true });\n\n // Create an example command\n const examplePath = path.join(commandsDir, 'example.md');\n const exampleContent = `---\nname: example\ndescription: An example slash command\n---\n\nThis is an example slash command template.\nYou can use variables like \\$ARGUMENTS or \\$1, \\$2 for positional args.\nYou can also include file content with @filename.\nShell commands with !command will be executed and output included.\n`;\n\n try {\n await fs.access(examplePath);\n // File already exists, don't overwrite\n } catch {\n await fs.writeFile(examplePath, exampleContent, 'utf-8');\n }\n } catch (error) {\n console.error('Error initializing commands directory:', error);\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SlashCommandMetadata } from './slash-command-loader.js';
|
|
2
|
+
/**
|
|
3
|
+
* Process a slash command by replacing variables and executing shell commands
|
|
4
|
+
*/
|
|
5
|
+
export declare function processSlashCommand(command: SlashCommandMetadata, args: string[], workingDir: string): Promise<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Format a command for display in help/autocomplete
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatCommandForDisplay(command: SlashCommandMetadata): string;
|
|
10
|
+
/**
|
|
11
|
+
* Group commands by namespace for display
|
|
12
|
+
*/
|
|
13
|
+
export declare function groupCommandsByNamespace(commands: SlashCommandMetadata[]): Map<string, SlashCommandMetadata[]>;
|
|
14
|
+
//# sourceMappingURL=slash-command-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slash-command-processor.d.ts","sourceRoot":"","sources":["../../src/utils/slash-command-processor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,oBAAoB,EAC7B,IAAI,EAAE,MAAM,EAAE,EACd,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAgBjB;AA0FD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAQ7E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAc9G"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { promises } from "fs";
|
|
2
|
+
import * as path$1 from "path";
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
//#region src/utils/slash-command-processor.ts
|
|
5
|
+
/**
|
|
6
|
+
* Process a slash command by replacing variables and executing shell commands
|
|
7
|
+
*/
|
|
8
|
+
async function processSlashCommand(command, args, workingDir) {
|
|
9
|
+
const { result: withArgs, shouldAppendRawArgs } = replaceArguments(command.template, args);
|
|
10
|
+
let result = withArgs;
|
|
11
|
+
result = await replaceShellOutput(result, workingDir);
|
|
12
|
+
result = await replaceFileReferences(result, workingDir);
|
|
13
|
+
if (shouldAppendRawArgs) result = result.trimEnd() + `\n\nARGUMENTS: ${args.join(" ")}`;
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Replace argument variables in template
|
|
18
|
+
* $ARGUMENTS - all arguments joined
|
|
19
|
+
* $1, $2, etc. - positional arguments
|
|
20
|
+
*/
|
|
21
|
+
function replaceArguments(template, args) {
|
|
22
|
+
let result = template;
|
|
23
|
+
const hasArgumentsVar = /\$ARGUMENTS/.test(template);
|
|
24
|
+
const hasPositionalVar = /\$[1-9]\d*/.test(template);
|
|
25
|
+
result = result.replace(/\$ARGUMENTS/g, args.join(" "));
|
|
26
|
+
args.forEach((_, index) => {
|
|
27
|
+
const argNumber = index + 1;
|
|
28
|
+
const pattern = new RegExp(`\\\$${argNumber}\\+`, "g");
|
|
29
|
+
result = result.replace(pattern, args.slice(index).join(" "));
|
|
30
|
+
});
|
|
31
|
+
args.forEach((arg, index) => {
|
|
32
|
+
const pattern = new RegExp(`\\\$${index + 1}`, "g");
|
|
33
|
+
result = result.replace(pattern, arg);
|
|
34
|
+
});
|
|
35
|
+
result = result.replace(/\$[1-9]\d*\+?/g, "");
|
|
36
|
+
return {
|
|
37
|
+
result,
|
|
38
|
+
shouldAppendRawArgs: !hasArgumentsVar && !hasPositionalVar && args.length > 0
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Replace shell command references with their output
|
|
43
|
+
* Format: !`command`
|
|
44
|
+
*/
|
|
45
|
+
async function replaceShellOutput(template, workingDir) {
|
|
46
|
+
const matches = [...template.matchAll(/!`([^`]+)`/g)];
|
|
47
|
+
let result = template;
|
|
48
|
+
for (const match of matches) {
|
|
49
|
+
const [fullMatch, command] = match;
|
|
50
|
+
try {
|
|
51
|
+
const output = execSync(command, {
|
|
52
|
+
cwd: workingDir,
|
|
53
|
+
encoding: "utf-8",
|
|
54
|
+
timeout: 3e4,
|
|
55
|
+
maxBuffer: 1024 * 1024
|
|
56
|
+
});
|
|
57
|
+
result = result.replace(fullMatch, output.trim());
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error(`Error executing shell command "${command}":`, error);
|
|
60
|
+
result = result.replace(fullMatch, `[Error: Failed to execute "${command}"]`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Replace file references with file content
|
|
67
|
+
* Format: @filename or @path/to/file
|
|
68
|
+
*/
|
|
69
|
+
async function replaceFileReferences(template, workingDir) {
|
|
70
|
+
const matches = [...template.matchAll(/@([\w./-]+)/g)];
|
|
71
|
+
let result = template;
|
|
72
|
+
for (const match of matches) {
|
|
73
|
+
const [fullMatch, filePath] = match;
|
|
74
|
+
try {
|
|
75
|
+
const fullPath = path$1.resolve(workingDir, filePath);
|
|
76
|
+
const content = await promises.readFile(fullPath, "utf-8");
|
|
77
|
+
result = result.replace(fullMatch, content);
|
|
78
|
+
} catch {}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Format a command for display in help/autocomplete
|
|
84
|
+
*/
|
|
85
|
+
function formatCommandForDisplay(command) {
|
|
86
|
+
const parts = [command.name];
|
|
87
|
+
if (command.description) parts.push(`- ${command.description}`);
|
|
88
|
+
return parts.join(" ");
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Group commands by namespace for display
|
|
92
|
+
*/
|
|
93
|
+
function groupCommandsByNamespace(commands) {
|
|
94
|
+
const groups = /* @__PURE__ */ new Map();
|
|
95
|
+
for (const command of commands) {
|
|
96
|
+
const namespace = command.namespace || command.name.split(":")[0] || "general";
|
|
97
|
+
if (!groups.has(namespace)) groups.set(namespace, []);
|
|
98
|
+
groups.get(namespace).push(command);
|
|
99
|
+
}
|
|
100
|
+
return groups;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { formatCommandForDisplay, groupCommandsByNamespace, processSlashCommand };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=slash-command-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slash-command-processor.js","names":["path","fs"],"sources":["../../src/utils/slash-command-processor.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport type { SlashCommandMetadata } from './slash-command-loader.js';\n\n/**\n * Process a slash command by replacing variables and executing shell commands\n */\nexport async function processSlashCommand(\n command: SlashCommandMetadata,\n args: string[],\n workingDir: string,\n): Promise<string> {\n const { result: withArgs, shouldAppendRawArgs } = replaceArguments(command.template, args);\n let result = withArgs;\n\n // Replace shell commands\n result = await replaceShellOutput(result, workingDir);\n\n // Replace file references\n result = await replaceFileReferences(result, workingDir);\n\n // Append raw args after shell/file processing to avoid executing user input\n if (shouldAppendRawArgs) {\n result = result.trimEnd() + `\\n\\nARGUMENTS: ${args.join(' ')}`;\n }\n\n return result;\n}\n\n/**\n * Replace argument variables in template\n * $ARGUMENTS - all arguments joined\n * $1, $2, etc. - positional arguments\n */\nfunction replaceArguments(template: string, args: string[]): { result: string; shouldAppendRawArgs: boolean } {\n let result = template;\n\n // Check if template references any argument variables\n const hasArgumentsVar = /\\$ARGUMENTS/.test(template);\n const hasPositionalVar = /\\$[1-9]\\d*/.test(template);\n\n // Replace $ARGUMENTS with all args joined\n result = result.replace(/\\$ARGUMENTS/g, args.join(' '));\n\n // Replace range arguments $1+, $2+, etc. before single positional arguments.\n args.forEach((_, index) => {\n const argNumber = index + 1;\n const pattern = new RegExp(`\\\\\\$${argNumber}\\\\+`, 'g');\n result = result.replace(pattern, args.slice(index).join(' '));\n });\n\n // Replace positional arguments $1, $2, etc.\n args.forEach((arg, index) => {\n const pattern = new RegExp(`\\\\\\$${index + 1}`, 'g');\n result = result.replace(pattern, arg);\n });\n\n // Clear unused positional and range arguments\n result = result.replace(/\\$[1-9]\\d*\\+?/g, '');\n\n return {\n result,\n shouldAppendRawArgs: !hasArgumentsVar && !hasPositionalVar && args.length > 0,\n };\n}\n\n/**\n * Replace shell command references with their output\n * Format: !`command`\n */\nasync function replaceShellOutput(template: string, workingDir: string): Promise<string> {\n const shellPattern = /!`([^`]+)`/g;\n const matches = [...template.matchAll(shellPattern)];\n\n let result = template;\n for (const match of matches) {\n const [fullMatch, command] = match;\n try {\n const output = execSync(command!, {\n cwd: workingDir,\n encoding: 'utf-8',\n timeout: 30000,\n maxBuffer: 1024 * 1024, // 1MB buffer\n });\n result = result.replace(fullMatch, output.trim());\n } catch (error) {\n console.error(`Error executing shell command \"${command}\":`, error);\n result = result.replace(fullMatch, `[Error: Failed to execute \"${command}\"]`);\n }\n }\n\n return result;\n}\n\n/**\n * Replace file references with file content\n * Format: @filename or @path/to/file\n */\nasync function replaceFileReferences(template: string, workingDir: string): Promise<string> {\n const filePattern = /@([\\w./-]+)/g;\n const matches = [...template.matchAll(filePattern)];\n\n let result = template;\n for (const match of matches) {\n const [fullMatch, filePath] = match;\n try {\n const fullPath = path.resolve(workingDir, filePath!);\n const content = await fs.readFile(fullPath, 'utf-8');\n result = result.replace(fullMatch, content);\n } catch {\n // Leave literal @mentions/search qualifiers such as @me intact when they do not resolve to files.\n }\n }\n\n return result;\n}\n\n/**\n * Format a command for display in help/autocomplete\n */\nexport function formatCommandForDisplay(command: SlashCommandMetadata): string {\n const parts = [command.name];\n\n if (command.description) {\n parts.push(`- ${command.description}`);\n }\n\n return parts.join(' ');\n}\n\n/**\n * Group commands by namespace for display\n */\nexport function groupCommandsByNamespace(commands: SlashCommandMetadata[]): Map<string, SlashCommandMetadata[]> {\n const groups = new Map<string, SlashCommandMetadata[]>();\n\n for (const command of commands) {\n const namespace = command.namespace || command.name.split(':')[0] || 'general';\n\n if (!groups.has(namespace)) {\n groups.set(namespace, []);\n }\n\n groups.get(namespace)!.push(command);\n }\n\n return groups;\n}\n"],"mappings":";;;;;;;AAQA,eAAsB,oBACpB,SACA,MACA,YACiB;CACjB,MAAM,EAAE,QAAQ,UAAU,wBAAwB,iBAAiB,QAAQ,UAAU,IAAI;CACzF,IAAI,SAAS;CAGb,SAAS,MAAM,mBAAmB,QAAQ,UAAU;CAGpD,SAAS,MAAM,sBAAsB,QAAQ,UAAU;CAGvD,IAAI,qBACF,SAAS,OAAO,QAAQ,IAAI,kBAAkB,KAAK,KAAK,GAAG;CAG7D,OAAO;AACT;;;;;;AAOA,SAAS,iBAAiB,UAAkB,MAAkE;CAC5G,IAAI,SAAS;CAGb,MAAM,kBAAkB,cAAc,KAAK,QAAQ;CACnD,MAAM,mBAAmB,aAAa,KAAK,QAAQ;CAGnD,SAAS,OAAO,QAAQ,gBAAgB,KAAK,KAAK,GAAG,CAAC;CAGtD,KAAK,SAAS,GAAG,UAAU;EACzB,MAAM,YAAY,QAAQ;EAC1B,MAAM,UAAU,IAAI,OAAO,OAAO,UAAU,MAAM,GAAG;EACrD,SAAS,OAAO,QAAQ,SAAS,KAAK,MAAM,KAAK,CAAC,CAAC,KAAK,GAAG,CAAC;CAC9D,CAAC;CAGD,KAAK,SAAS,KAAK,UAAU;EAC3B,MAAM,UAAU,IAAI,OAAO,OAAO,QAAQ,KAAK,GAAG;EAClD,SAAS,OAAO,QAAQ,SAAS,GAAG;CACtC,CAAC;CAGD,SAAS,OAAO,QAAQ,kBAAkB,EAAE;CAE5C,OAAO;EACL;EACA,qBAAqB,CAAC,mBAAmB,CAAC,oBAAoB,KAAK,SAAS;CAC9E;AACF;;;;;AAMA,eAAe,mBAAmB,UAAkB,YAAqC;CAEvF,MAAM,UAAU,CAAC,GAAG,SAAS,SAAS,aAAY,CAAC;CAEnD,IAAI,SAAS;CACb,KAAK,MAAM,SAAS,SAAS;EAC3B,MAAM,CAAC,WAAW,WAAW;EAC7B,IAAI;GACF,MAAM,SAAS,SAAS,SAAU;IAChC,KAAK;IACL,UAAU;IACV,SAAS;IACT,WAAW,OAAO;GACpB,CAAC;GACD,SAAS,OAAO,QAAQ,WAAW,OAAO,KAAK,CAAC;EAClD,SAAS,OAAO;GACd,QAAQ,MAAM,kCAAkC,QAAQ,KAAK,KAAK;GAClE,SAAS,OAAO,QAAQ,WAAW,8BAA8B,QAAQ,GAAG;EAC9E;CACF;CAEA,OAAO;AACT;;;;;AAMA,eAAe,sBAAsB,UAAkB,YAAqC;CAE1F,MAAM,UAAU,CAAC,GAAG,SAAS,SAAS,cAAW,CAAC;CAElD,IAAI,SAAS;CACb,KAAK,MAAM,SAAS,SAAS;EAC3B,MAAM,CAAC,WAAW,YAAY;EAC9B,IAAI;GACF,MAAM,WAAWA,OAAK,QAAQ,YAAY,QAAS;GACnD,MAAM,UAAU,MAAMC,SAAG,SAAS,UAAU,OAAO;GACnD,SAAS,OAAO,QAAQ,WAAW,OAAO;EAC5C,QAAQ,CAER;CACF;CAEA,OAAO;AACT;;;;AAKA,SAAgB,wBAAwB,SAAuC;CAC7E,MAAM,QAAQ,CAAC,QAAQ,IAAI;CAE3B,IAAI,QAAQ,aACV,MAAM,KAAK,KAAK,QAAQ,aAAa;CAGvC,OAAO,MAAM,KAAK,GAAG;AACvB;;;;AAKA,SAAgB,yBAAyB,UAAuE;CAC9G,MAAM,yBAAS,IAAI,IAAoC;CAEvD,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,YAAY,QAAQ,aAAa,QAAQ,KAAK,MAAM,GAAG,CAAC,CAAC,MAAM;EAErE,IAAI,CAAC,OAAO,IAAI,SAAS,GACvB,OAAO,IAAI,WAAW,CAAC,CAAC;EAG1B,OAAO,IAAI,SAAS,CAAC,CAAE,KAAK,OAAO;CACrC;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clean up raw piped output so the agent sees readable text, not terminal
|
|
3
|
+
* control noise.
|
|
4
|
+
*
|
|
5
|
+
* 1. Strip all ANSI escape sequences (colors, cursor movement, line clears).
|
|
6
|
+
* 2. Simulate carriage-return overwrites: for each line, split on `\r` and
|
|
7
|
+
* keep only the last segment — this is what the terminal would display
|
|
8
|
+
* after a spinner/progress bar finishes.
|
|
9
|
+
* 3. Collapse runs of blank lines.
|
|
10
|
+
*/
|
|
11
|
+
export declare function sanitizePipedOutput(raw: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* If stdin is a pipe (not a TTY), read **all** data until EOF and return it as
|
|
14
|
+
* a string. The returned promise only resolves once the write end of the pipe
|
|
15
|
+
* is closed — i.e. the sending process has fully exited — so callers are
|
|
16
|
+
* guaranteed to receive the complete output, not a partial snapshot from a
|
|
17
|
+
* program that writes progressively.
|
|
18
|
+
*
|
|
19
|
+
* Returns `null` when:
|
|
20
|
+
* - stdin is a TTY (interactive terminal)
|
|
21
|
+
* - the pipe was empty or contained only whitespace
|
|
22
|
+
*/
|
|
23
|
+
export declare function drainPipedStdin(): Promise<string | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Reopen `/dev/tty` (or `CON` on Windows) as `process.stdin` so that the
|
|
26
|
+
* interactive TUI can read keyboard input after the original piped stdin has
|
|
27
|
+
* been consumed.
|
|
28
|
+
*
|
|
29
|
+
* @returns `true` if the swap succeeded, `false` if a TTY could not be opened
|
|
30
|
+
* (e.g. running in a headless CI container with no controlling terminal).
|
|
31
|
+
*/
|
|
32
|
+
export declare function reopenStdinFromTTY(): boolean;
|
|
33
|
+
//# sourceMappingURL=stdin-pipe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdin-pipe.d.ts","sourceRoot":"","sources":["../../src/utils/stdin-pipe.ts"],"names":[],"mappings":"AAYA;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA0BvD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA2C9D;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAmB5C"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as fs$1 from "fs";
|
|
2
|
+
import * as tty from "tty";
|
|
3
|
+
//#region src/utils/stdin-pipe.ts
|
|
4
|
+
/** Maximum piped input size (1 MB). Content beyond this is truncated. */
|
|
5
|
+
const MAX_PIPE_BYTES = 1024 * 1024;
|
|
6
|
+
/**
|
|
7
|
+
* Matches all ANSI escape sequences — SGR (colors), cursor movement, line
|
|
8
|
+
* clears, scrolling, window titles, etc.
|
|
9
|
+
*/
|
|
10
|
+
const ANSI_RE = /\x1b(?:\[[0-9;?]*[A-Za-z]|\][^\x07\x1b]*(?:\x07|\x1b\\)?|\([A-Z])/g;
|
|
11
|
+
/**
|
|
12
|
+
* Clean up raw piped output so the agent sees readable text, not terminal
|
|
13
|
+
* control noise.
|
|
14
|
+
*
|
|
15
|
+
* 1. Strip all ANSI escape sequences (colors, cursor movement, line clears).
|
|
16
|
+
* 2. Simulate carriage-return overwrites: for each line, split on `\r` and
|
|
17
|
+
* keep only the last segment — this is what the terminal would display
|
|
18
|
+
* after a spinner/progress bar finishes.
|
|
19
|
+
* 3. Collapse runs of blank lines.
|
|
20
|
+
*/
|
|
21
|
+
function sanitizePipedOutput(raw) {
|
|
22
|
+
let text = raw.replace(ANSI_RE, "");
|
|
23
|
+
text = text.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
|
|
24
|
+
text = text.split("\n").map((line) => {
|
|
25
|
+
if (!line.includes("\r")) return line;
|
|
26
|
+
const segments = line.split("\r");
|
|
27
|
+
for (let i = segments.length - 1; i >= 0; i--) if (segments[i].length > 0) return segments[i];
|
|
28
|
+
return "";
|
|
29
|
+
}).join("\n");
|
|
30
|
+
text = text.replace(/\n{3,}/g, "\n\n");
|
|
31
|
+
return text.trim();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* If stdin is a pipe (not a TTY), read **all** data until EOF and return it as
|
|
35
|
+
* a string. The returned promise only resolves once the write end of the pipe
|
|
36
|
+
* is closed — i.e. the sending process has fully exited — so callers are
|
|
37
|
+
* guaranteed to receive the complete output, not a partial snapshot from a
|
|
38
|
+
* program that writes progressively.
|
|
39
|
+
*
|
|
40
|
+
* Returns `null` when:
|
|
41
|
+
* - stdin is a TTY (interactive terminal)
|
|
42
|
+
* - the pipe was empty or contained only whitespace
|
|
43
|
+
*/
|
|
44
|
+
async function drainPipedStdin() {
|
|
45
|
+
if (process.stdin.isTTY) return null;
|
|
46
|
+
const chunks = [];
|
|
47
|
+
let totalBytes = 0;
|
|
48
|
+
let truncated = false;
|
|
49
|
+
for await (const chunk of process.stdin) {
|
|
50
|
+
const buf = chunk;
|
|
51
|
+
if (totalBytes + buf.length > MAX_PIPE_BYTES) {
|
|
52
|
+
const remaining = MAX_PIPE_BYTES - totalBytes;
|
|
53
|
+
if (remaining > 0) chunks.push(Buffer.from(buf.subarray(0, remaining)));
|
|
54
|
+
buf.fill(0);
|
|
55
|
+
totalBytes = MAX_PIPE_BYTES;
|
|
56
|
+
truncated = true;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
chunks.push(buf);
|
|
60
|
+
totalBytes += buf.length;
|
|
61
|
+
}
|
|
62
|
+
if (truncated) process.stderr.write(`Warning: Piped input exceeded ${MAX_PIPE_BYTES / 1024 / 1024}MB and was truncated.\n`);
|
|
63
|
+
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
64
|
+
for (const buf of chunks) buf.fill(0);
|
|
65
|
+
chunks.length = 0;
|
|
66
|
+
const content = sanitizePipedOutput(raw);
|
|
67
|
+
return content.length > 0 ? content : null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reopen `/dev/tty` (or `CON` on Windows) as `process.stdin` so that the
|
|
71
|
+
* interactive TUI can read keyboard input after the original piped stdin has
|
|
72
|
+
* been consumed.
|
|
73
|
+
*
|
|
74
|
+
* @returns `true` if the swap succeeded, `false` if a TTY could not be opened
|
|
75
|
+
* (e.g. running in a headless CI container with no controlling terminal).
|
|
76
|
+
*/
|
|
77
|
+
function reopenStdinFromTTY() {
|
|
78
|
+
const ttyPath = process.platform === "win32" ? "CON" : "/dev/tty";
|
|
79
|
+
let fd;
|
|
80
|
+
try {
|
|
81
|
+
fd = fs$1.openSync(ttyPath, "r");
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const ttyStream = new tty.ReadStream(fd);
|
|
86
|
+
Object.defineProperty(process, "stdin", {
|
|
87
|
+
value: ttyStream,
|
|
88
|
+
writable: true,
|
|
89
|
+
configurable: true
|
|
90
|
+
});
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { drainPipedStdin, reopenStdinFromTTY, sanitizePipedOutput };
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=stdin-pipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdin-pipe.js","names":["fs"],"sources":["../../src/utils/stdin-pipe.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport * as tty from 'node:tty';\n\n/** Maximum piped input size (1 MB). Content beyond this is truncated. */\nconst MAX_PIPE_BYTES = 1024 * 1024;\n\n/**\n * Matches all ANSI escape sequences — SGR (colors), cursor movement, line\n * clears, scrolling, window titles, etc.\n */\nconst ANSI_RE = /\\x1b(?:\\[[0-9;?]*[A-Za-z]|\\][^\\x07\\x1b]*(?:\\x07|\\x1b\\\\)?|\\([A-Z])/g;\n\n/**\n * Clean up raw piped output so the agent sees readable text, not terminal\n * control noise.\n *\n * 1. Strip all ANSI escape sequences (colors, cursor movement, line clears).\n * 2. Simulate carriage-return overwrites: for each line, split on `\\r` and\n * keep only the last segment — this is what the terminal would display\n * after a spinner/progress bar finishes.\n * 3. Collapse runs of blank lines.\n */\nexport function sanitizePipedOutput(raw: string): string {\n // Strip ANSI escapes first\n let text = raw.replace(ANSI_RE, '');\n\n // Strip binary control characters (everything below 0x20 except \\t, \\n, \\r)\n text = text.replace(/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]/g, '');\n\n // Simulate \\r overwrites: for each line, the last \\r-segment wins\n text = text\n .split('\\n')\n .map(line => {\n if (!line.includes('\\r')) return line;\n const segments = line.split('\\r');\n // Walk backwards to find the last non-empty segment — a trailing \\r\n // produces an empty final segment that would otherwise discard visible text.\n for (let i = segments.length - 1; i >= 0; i--) {\n if (segments[i]!.length > 0) return segments[i]!;\n }\n return '';\n })\n .join('\\n');\n\n // Collapse 3+ consecutive blank lines into 2\n text = text.replace(/\\n{3,}/g, '\\n\\n');\n\n return text.trim();\n}\n\n/**\n * If stdin is a pipe (not a TTY), read **all** data until EOF and return it as\n * a string. The returned promise only resolves once the write end of the pipe\n * is closed — i.e. the sending process has fully exited — so callers are\n * guaranteed to receive the complete output, not a partial snapshot from a\n * program that writes progressively.\n *\n * Returns `null` when:\n * - stdin is a TTY (interactive terminal)\n * - the pipe was empty or contained only whitespace\n */\nexport async function drainPipedStdin(): Promise<string | null> {\n if (process.stdin.isTTY) return null;\n\n const chunks: Buffer[] = [];\n let totalBytes = 0;\n let truncated = false;\n\n for await (const chunk of process.stdin) {\n const buf = chunk as Buffer;\n\n if (totalBytes + buf.length > MAX_PIPE_BYTES) {\n // Take only what fits under the cap — copy so we don't retain the\n // original backing buffer, then zero the source.\n const remaining = MAX_PIPE_BYTES - totalBytes;\n if (remaining > 0) {\n chunks.push(Buffer.from(buf.subarray(0, remaining)));\n }\n buf.fill(0);\n totalBytes = MAX_PIPE_BYTES;\n truncated = true;\n // Keep draining so we don't leave unread data in the pipe, but don't\n // store it — we still need to wait for EOF.\n continue;\n }\n\n chunks.push(buf);\n totalBytes += buf.length;\n }\n\n if (truncated) {\n process.stderr.write(`Warning: Piped input exceeded ${MAX_PIPE_BYTES / 1024 / 1024}MB and was truncated.\\n`);\n }\n\n const raw = Buffer.concat(chunks).toString('utf-8');\n\n // Zero out raw buffers so piped secrets don't linger in memory\n for (const buf of chunks) {\n buf.fill(0);\n }\n chunks.length = 0;\n\n const content = sanitizePipedOutput(raw);\n return content.length > 0 ? content : null;\n}\n\n/**\n * Reopen `/dev/tty` (or `CON` on Windows) as `process.stdin` so that the\n * interactive TUI can read keyboard input after the original piped stdin has\n * been consumed.\n *\n * @returns `true` if the swap succeeded, `false` if a TTY could not be opened\n * (e.g. running in a headless CI container with no controlling terminal).\n */\nexport function reopenStdinFromTTY(): boolean {\n const ttyPath = process.platform === 'win32' ? 'CON' : '/dev/tty';\n\n let fd: number;\n try {\n fd = fs.openSync(ttyPath, 'r');\n } catch {\n return false;\n }\n\n const ttyStream = new tty.ReadStream(fd);\n\n Object.defineProperty(process, 'stdin', {\n value: ttyStream,\n writable: true,\n configurable: true,\n });\n\n return true;\n}\n"],"mappings":";;;;AAIA,MAAM,iBAAiB,OAAO;;;;;AAM9B,MAAM,UAAU;;;;;;;;;;;AAYhB,SAAgB,oBAAoB,KAAqB;CAEvD,IAAI,OAAO,IAAI,QAAQ,SAAS,EAAE;CAGlC,OAAO,KAAK,QAAQ,qCAAqC,EAAE;CAG3D,OAAO,KACJ,MAAM,IAAI,CAAC,CACX,KAAI,SAAQ;EACX,IAAI,CAAC,KAAK,SAAS,IAAI,GAAG,OAAO;EACjC,MAAM,WAAW,KAAK,MAAM,IAAI;EAGhC,KAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KACxC,IAAI,SAAS,EAAE,CAAE,SAAS,GAAG,OAAO,SAAS;EAE/C,OAAO;CACT,CAAC,CAAC,CACD,KAAK,IAAI;CAGZ,OAAO,KAAK,QAAQ,WAAW,MAAM;CAErC,OAAO,KAAK,KAAK;AACnB;;;;;;;;;;;;AAaA,eAAsB,kBAA0C;CAC9D,IAAI,QAAQ,MAAM,OAAO,OAAO;CAEhC,MAAM,SAAmB,CAAC;CAC1B,IAAI,aAAa;CACjB,IAAI,YAAY;CAEhB,WAAW,MAAM,SAAS,QAAQ,OAAO;EACvC,MAAM,MAAM;EAEZ,IAAI,aAAa,IAAI,SAAS,gBAAgB;GAG5C,MAAM,YAAY,iBAAiB;GACnC,IAAI,YAAY,GACd,OAAO,KAAK,OAAO,KAAK,IAAI,SAAS,GAAG,SAAS,CAAC,CAAC;GAErD,IAAI,KAAK,CAAC;GACV,aAAa;GACb,YAAY;GAGZ;EACF;EAEA,OAAO,KAAK,GAAG;EACf,cAAc,IAAI;CACpB;CAEA,IAAI,WACF,QAAQ,OAAO,MAAM,iCAAiC,iBAAiB,OAAO,KAAK,wBAAwB;CAG7G,MAAM,MAAM,OAAO,OAAO,MAAM,CAAC,CAAC,SAAS,OAAO;CAGlD,KAAK,MAAM,OAAO,QAChB,IAAI,KAAK,CAAC;CAEZ,OAAO,SAAS;CAEhB,MAAM,UAAU,oBAAoB,GAAG;CACvC,OAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;;;;;;;;;AAUA,SAAgB,qBAA8B;CAC5C,MAAM,UAAU,QAAQ,aAAa,UAAU,QAAQ;CAEvD,IAAI;CACJ,IAAI;EACF,KAAKA,KAAG,SAAS,SAAS,GAAG;CAC/B,QAAQ;EACN,OAAO;CACT;CAEA,MAAM,YAAY,IAAI,IAAI,WAAW,EAAE;CAEvC,OAAO,eAAe,SAAS,SAAS;EACtC,OAAO;EACP,UAAU;EACV,cAAc;CAChB,CAAC;CAED,OAAO;AACT"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage factory — creates the appropriate storage backend based on resolved config.
|
|
3
|
+
*
|
|
4
|
+
* If PG is selected but fails to connect, falls back to LibSQL so the TUI
|
|
5
|
+
* can start and the user can fix the connection via /settings.
|
|
6
|
+
*/
|
|
7
|
+
import type { MastraCompositeStore, RetentionConfig } from '@mastra/core/storage';
|
|
8
|
+
import type { MastraVector } from '@mastra/core/vector';
|
|
9
|
+
import type { StorageConfig } from './project.js';
|
|
10
|
+
export declare const MASTRA_CODE_LOCAL_PRAGMAS: {
|
|
11
|
+
cacheSize: number;
|
|
12
|
+
mmapSize: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Construct a LibSQL store for an arbitrary url/authToken, applying the same
|
|
16
|
+
* local pragmas the default factory uses.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildLibSQLStore(opts: {
|
|
19
|
+
id?: string;
|
|
20
|
+
url: string;
|
|
21
|
+
authToken?: string;
|
|
22
|
+
retention?: RetentionConfig;
|
|
23
|
+
}): MastraCompositeStore;
|
|
24
|
+
/** Construct a LibSQL vector store for an arbitrary url/authToken. */
|
|
25
|
+
export declare function buildLibSQLVector(opts: {
|
|
26
|
+
id?: string;
|
|
27
|
+
url: string;
|
|
28
|
+
authToken?: string;
|
|
29
|
+
}): MastraVector;
|
|
30
|
+
export interface StorageResult {
|
|
31
|
+
storage: MastraCompositeStore;
|
|
32
|
+
/** The effective backend after any fallback logic has run. */
|
|
33
|
+
backend: 'libsql' | 'pg';
|
|
34
|
+
/** Non-null when PG was requested but failed — contains a user-facing warning. */
|
|
35
|
+
warning?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a storage instance from the resolved config.
|
|
39
|
+
*
|
|
40
|
+
* - `libsql` backend → LibSQLStore (always available)
|
|
41
|
+
* - `pg` backend → PostgresStore, falls back to LibSQL on connection failure
|
|
42
|
+
*/
|
|
43
|
+
export declare function createStorage(config: StorageConfig): Promise<StorageResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Create a vector store for recall search.
|
|
46
|
+
* Uses a separate LibSQL file to avoid bloating the main storage DB with embedding data.
|
|
47
|
+
* For PG backends, reuses the same connection (PG handles the extra tables fine).
|
|
48
|
+
*/
|
|
49
|
+
export declare function createVectorStore(config: StorageConfig, effectiveBackend?: 'libsql' | 'pg'): Promise<MastraVector | undefined>;
|
|
50
|
+
//# sourceMappingURL=storage-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-factory.d.ts","sourceRoot":"","sources":["../../src/utils/storage-factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAInE,eAAO,MAAM,yBAAyB;;;CAGrC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B,GAAG,oBAAoB,CAQvB;AAED,sEAAsE;AACtE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,YAAY,CAMtG;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,8DAA8D;IAC9D,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IACzB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAMD;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAUjF;AAyDD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,aAAa,EACrB,gBAAgB,GAAE,QAAQ,GAAG,IAAqB,GACjD,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAuBnC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { getDatabasePath, getVectorDatabasePath } from "./project.js";
|
|
2
|
+
import { DEFAULT_RETENTION } from "./storage-maintenance.js";
|
|
3
|
+
import { LibSQLStore, LibSQLVector } from "@mastra/libsql";
|
|
4
|
+
import { PostgresStore } from "@mastra/pg";
|
|
5
|
+
//#region src/utils/storage-factory.ts
|
|
6
|
+
const MASTRA_CODE_LOCAL_PRAGMAS = {
|
|
7
|
+
cacheSize: -128e3,
|
|
8
|
+
mmapSize: 536870912
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Construct a LibSQL store for an arbitrary url/authToken, applying the same
|
|
12
|
+
* local pragmas the default factory uses.
|
|
13
|
+
*/
|
|
14
|
+
function buildLibSQLStore(opts) {
|
|
15
|
+
return new LibSQLStore({
|
|
16
|
+
id: opts.id ?? "mastra-code-storage",
|
|
17
|
+
url: opts.url,
|
|
18
|
+
...opts.authToken ? { authToken: opts.authToken } : {},
|
|
19
|
+
...opts.retention ? { retention: opts.retention } : {},
|
|
20
|
+
localPragmas: MASTRA_CODE_LOCAL_PRAGMAS
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Construct a LibSQL vector store for an arbitrary url/authToken. */
|
|
24
|
+
function buildLibSQLVector(opts) {
|
|
25
|
+
return new LibSQLVector({
|
|
26
|
+
id: opts.id ?? "mastra-code-vectors",
|
|
27
|
+
url: opts.url,
|
|
28
|
+
...opts.authToken ? { authToken: opts.authToken } : {}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function createFallbackLibSQL() {
|
|
32
|
+
return buildLibSQLStore({
|
|
33
|
+
url: `file:${getDatabasePath()}`,
|
|
34
|
+
retention: DEFAULT_RETENTION
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a storage instance from the resolved config.
|
|
39
|
+
*
|
|
40
|
+
* - `libsql` backend → LibSQLStore (always available)
|
|
41
|
+
* - `pg` backend → PostgresStore, falls back to LibSQL on connection failure
|
|
42
|
+
*/
|
|
43
|
+
async function createStorage(config) {
|
|
44
|
+
if (config.backend === "pg") return createPgStorage(config);
|
|
45
|
+
return {
|
|
46
|
+
storage: buildLibSQLStore({
|
|
47
|
+
url: config.url,
|
|
48
|
+
authToken: config.authToken,
|
|
49
|
+
retention: DEFAULT_RETENTION
|
|
50
|
+
}),
|
|
51
|
+
backend: "libsql"
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async function createPgStorage(config) {
|
|
55
|
+
if (!config.connectionString && !config.host) return {
|
|
56
|
+
storage: createFallbackLibSQL(),
|
|
57
|
+
backend: "libsql",
|
|
58
|
+
warning: "PostgreSQL backend selected but no connection info configured. Using LibSQL fallback. Set a connection string via /settings."
|
|
59
|
+
};
|
|
60
|
+
const base = {
|
|
61
|
+
id: "mastra-code-storage",
|
|
62
|
+
retention: DEFAULT_RETENTION,
|
|
63
|
+
...config.schemaName ? { schemaName: config.schemaName } : {},
|
|
64
|
+
...config.disableInit ? { disableInit: config.disableInit } : {},
|
|
65
|
+
...config.skipDefaultIndexes ? { skipDefaultIndexes: config.skipDefaultIndexes } : {}
|
|
66
|
+
};
|
|
67
|
+
const store = config.connectionString ? new PostgresStore({
|
|
68
|
+
...base,
|
|
69
|
+
connectionString: config.connectionString
|
|
70
|
+
}) : new PostgresStore({
|
|
71
|
+
...base,
|
|
72
|
+
host: config.host,
|
|
73
|
+
port: config.port,
|
|
74
|
+
database: config.database,
|
|
75
|
+
user: config.user,
|
|
76
|
+
password: config.password
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
await store.init();
|
|
80
|
+
} catch (err) {
|
|
81
|
+
const msg = err?.message ?? String(err);
|
|
82
|
+
const target = config.connectionString ?? `${config.host}:${config.port ?? 5432}`;
|
|
83
|
+
try {
|
|
84
|
+
await store.close();
|
|
85
|
+
} catch {}
|
|
86
|
+
return {
|
|
87
|
+
storage: createFallbackLibSQL(),
|
|
88
|
+
backend: "libsql",
|
|
89
|
+
warning: `Failed to connect to PostgreSQL at ${target}: ${msg}\nUsing LibSQL fallback. Fix the connection via /settings.`
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
storage: store,
|
|
94
|
+
backend: "pg"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a vector store for recall search.
|
|
99
|
+
* Uses a separate LibSQL file to avoid bloating the main storage DB with embedding data.
|
|
100
|
+
* For PG backends, reuses the same connection (PG handles the extra tables fine).
|
|
101
|
+
*/
|
|
102
|
+
async function createVectorStore(config, effectiveBackend = config.backend) {
|
|
103
|
+
if (effectiveBackend === "pg") {
|
|
104
|
+
const pgConfig = config;
|
|
105
|
+
if (!pgConfig.connectionString && !pgConfig.host) return void 0;
|
|
106
|
+
const { PgVector } = await import("@mastra/pg");
|
|
107
|
+
return new PgVector({
|
|
108
|
+
id: "mastra-code-vectors",
|
|
109
|
+
connectionString: pgConfig.connectionString ?? `postgresql://${pgConfig.user}:${pgConfig.password}@${pgConfig.host}:${pgConfig.port ?? 5432}/${pgConfig.database}`
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const libsqlConfig = config;
|
|
113
|
+
return buildLibSQLVector({
|
|
114
|
+
url: libsqlConfig.vectorUrl ?? `file:${getVectorDatabasePath()}`,
|
|
115
|
+
authToken: libsqlConfig.vectorAuthToken
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { MASTRA_CODE_LOCAL_PRAGMAS, buildLibSQLStore, buildLibSQLVector, createStorage, createVectorStore };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=storage-factory.js.map
|