@mastra/code-sdk 0.0.0-agent-tags-alpha-20261125185303
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +32 -0
- package/README.md +284 -0
- package/dist/acp/agent.d.ts +48 -0
- package/dist/acp/agent.js +414 -0
- package/dist/acp/errors.d.ts +3 -0
- package/dist/acp/errors.js +11 -0
- package/dist/acp/event-mapper.d.ts +28 -0
- package/dist/acp/event-mapper.js +274 -0
- package/dist/acp/index.d.ts +9 -0
- package/dist/acp/index.js +21 -0
- package/dist/acp/runtime.d.ts +5 -0
- package/dist/acp/runtime.js +91 -0
- package/dist/acp/server.d.ts +4 -0
- package/dist/acp/server.js +35 -0
- package/dist/acp/skills.d.ts +6 -0
- package/dist/acp/skills.js +30 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.js +1 -0
- package/dist/agent-connections/messaging-processor.d.ts +17 -0
- package/dist/agent-connections/messaging-processor.js +131 -0
- package/dist/agent-connections/ownership.d.ts +24 -0
- package/dist/agent-connections/ownership.js +96 -0
- package/dist/agent-connections/registry.d.ts +20 -0
- package/dist/agent-connections/registry.js +167 -0
- package/dist/agent-connections/session-advertisement.d.ts +27 -0
- package/dist/agent-connections/session-advertisement.js +86 -0
- package/dist/agent-connections/signal-provider.d.ts +141 -0
- package/dist/agent-connections/signal-provider.js +35 -0
- package/dist/agent-connections/state-processor.d.ts +23 -0
- package/dist/agent-connections/state-processor.js +270 -0
- package/dist/agent-connections/thread-state.d.ts +41 -0
- package/dist/agent-connections/thread-state.js +157 -0
- package/dist/agent-connections/tools.d.ts +133 -0
- package/dist/agent-connections/tools.js +616 -0
- package/dist/agent-connections/types.d.ts +99 -0
- package/dist/agent-connections/types.js +4 -0
- package/dist/agent-connections/untrusted-text.d.ts +5 -0
- package/dist/agent-connections/untrusted-text.js +19 -0
- package/dist/agents/background-completion-events.d.ts +16 -0
- package/dist/agents/background-completion-events.js +16 -0
- package/dist/agents/background-completion.d.ts +22 -0
- package/dist/agents/background-completion.js +73 -0
- package/dist/agents/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.js +115 -0
- package/dist/agents/credential-resolver.d.ts +74 -0
- package/dist/agents/credential-resolver.js +142 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.js +22 -0
- package/dist/agents/fastembed-subprocess.d.ts +52 -0
- package/dist/agents/fastembed-subprocess.js +282 -0
- package/dist/agents/instructions.d.ts +42 -0
- package/dist/agents/instructions.js +69 -0
- package/dist/agents/mastracode-gateway.d.ts +85 -0
- package/dist/agents/mastracode-gateway.js +500 -0
- package/dist/agents/memory.d.ts +36 -0
- package/dist/agents/memory.js +248 -0
- package/dist/agents/model.d.ts +158 -0
- package/dist/agents/model.js +382 -0
- package/dist/agents/modes/build.d.ts +12 -0
- package/dist/agents/modes/build.js +33 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.js +25 -0
- package/dist/agents/modes/plan.d.ts +8 -0
- package/dist/agents/modes/plan.js +43 -0
- package/dist/agents/prompts/agent-instructions.d.ts +122 -0
- package/dist/agents/prompts/agent-instructions.js +617 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.js +73 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.js +23 -0
- package/dist/agents/prompts/index.d.ts +61 -0
- package/dist/agents/prompts/index.js +141 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.js +20 -0
- package/dist/agents/prompts/plan.d.ts +11 -0
- package/dist/agents/prompts/plan.js +132 -0
- package/dist/agents/prompts/tool-guidance.d.ts +18 -0
- package/dist/agents/prompts/tool-guidance.js +158 -0
- package/dist/agents/sandbox-filesystem.d.ts +232 -0
- package/dist/agents/sandbox-filesystem.js +851 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.js +24 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.js +15 -0
- package/dist/agents/subagents/index.d.ts +6 -0
- package/dist/agents/subagents/index.js +15 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.js +15 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.js +104 -0
- package/dist/agents/tool-availability.d.ts +17 -0
- package/dist/agents/tool-availability.js +134 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.js +154 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.js +79 -0
- package/dist/agents/workspace.d.ts +35 -0
- package/dist/agents/workspace.js +207 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.js +159 -0
- package/dist/auth/account-rotation-processor.d.ts +210 -0
- package/dist/auth/account-rotation-processor.js +662 -0
- package/dist/auth/account-routing-context.d.ts +17 -0
- package/dist/auth/account-routing-context.js +38 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.js +39 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.js +126 -0
- package/dist/auth/index.d.ts +13 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.js +29 -0
- package/dist/auth/provider-auth-error.d.ts +24 -0
- package/dist/auth/provider-auth-error.js +44 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.js +117 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.js +359 -0
- package/dist/auth/providers/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.js +225 -0
- package/dist/auth/providers/openai-codex.d.ts +141 -0
- package/dist/auth/providers/openai-codex.js +531 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.js +223 -0
- package/dist/auth/storage.d.ts +222 -0
- package/dist/auth/storage.js +805 -0
- package/dist/auth/types.d.ts +164 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.js +224 -0
- package/dist/constants.d.ts +29 -0
- package/dist/constants.js +34 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.js +19 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.js +156 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.js +5 -0
- package/dist/evals/scorers/classify-command.d.ts +30 -0
- package/dist/evals/scorers/classify-command.js +61 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.js +256 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.js +57 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.js +3 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.js +360 -0
- package/dist/experimental-agent.d.ts +19 -0
- package/dist/experimental-agent.js +45 -0
- package/dist/factory/client.d.ts +44 -0
- package/dist/factory/client.js +110 -0
- package/dist/factory/remote-controller.d.ts +34 -0
- package/dist/factory/remote-controller.js +40 -0
- package/dist/factory/remote-session.d.ts +210 -0
- package/dist/factory/remote-session.js +415 -0
- package/dist/goal-manager.d.ts +114 -0
- package/dist/goal-manager.js +351 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.js +14 -0
- package/dist/headless/cli.d.ts +55 -0
- package/dist/headless/cli.js +261 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.js +207 -0
- package/dist/headless/format.d.ts +41 -0
- package/dist/headless/format.js +94 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.js +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.js +39 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.js +438 -0
- package/dist/headless/types.d.ts +175 -0
- package/dist/headless/types.js +16 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.js +77 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.js +128 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +75 -0
- package/dist/hooks/manager.js +289 -0
- package/dist/hooks/types.d.ts +180 -0
- package/dist/hooks/types.js +5 -0
- package/dist/index.d.ts +537 -0
- package/dist/index.js +1399 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.js +18 -0
- package/dist/knowledge-inspector.d.ts +139 -0
- package/dist/knowledge-inspector.js +533 -0
- package/dist/knowledge-scope-id.d.ts +7 -0
- package/dist/knowledge-scope-id.js +10 -0
- package/dist/knowledge-scope.d.ts +41 -0
- package/dist/knowledge-scope.js +85 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.js +248 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.js +41 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.js +79 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.js +158 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.js +52 -0
- package/dist/mcp/config.d.ts +77 -0
- package/dist/mcp/config.js +313 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +104 -0
- package/dist/mcp/manager.js +693 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.js +94 -0
- package/dist/mcp/types.d.ts +139 -0
- package/dist/mcp/types.js +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.js +17 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.js +27 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.js +3 -0
- package/dist/onboarding/om-settings.d.ts +47 -0
- package/dist/onboarding/om-settings.js +80 -0
- package/dist/onboarding/pack-activation.d.ts +43 -0
- package/dist/onboarding/pack-activation.js +105 -0
- package/dist/onboarding/packs.d.ts +106 -0
- package/dist/onboarding/packs.js +283 -0
- package/dist/onboarding/settings.d.ts +563 -0
- package/dist/onboarding/settings.js +1110 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.js +139 -0
- package/dist/platform/index.d.ts +74 -0
- package/dist/platform/index.js +199 -0
- package/dist/plugin.d.ts +156 -0
- package/dist/plugin.js +27 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.js +84 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.js +187 -0
- package/dist/plugins/loader.d.ts +25 -0
- package/dist/plugins/loader.js +264 -0
- package/dist/plugins/manager.d.ts +115 -0
- package/dist/plugins/manager.js +507 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.js +47 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.js +58 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.js +22 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.js +109 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.js +115 -0
- package/dist/plugins/signal-lane.d.ts +59 -0
- package/dist/plugins/signal-lane.js +163 -0
- package/dist/plugins/types.d.ts +95 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +136 -0
- package/dist/process-memory-diagnostics.js +497 -0
- package/dist/processors/plan-rejection-abort.d.ts +16 -0
- package/dist/processors/plan-rejection-abort.js +62 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.js +142 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.js +99 -0
- package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
- package/dist/providers/anthropic-prompt-cache.js +8 -0
- package/dist/providers/anthropic-thinking.d.ts +5 -0
- package/dist/providers/anthropic-thinking.js +22 -0
- package/dist/providers/claude-max.d.ts +67 -0
- package/dist/providers/claude-max.js +232 -0
- package/dist/providers/github-copilot-gateway.d.ts +35 -0
- package/dist/providers/github-copilot-gateway.js +58 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.js +320 -0
- package/dist/providers/google-thinking.d.ts +31 -0
- package/dist/providers/google-thinking.js +64 -0
- package/dist/providers/google-vertex-gateway.d.ts +23 -0
- package/dist/providers/google-vertex-gateway.js +49 -0
- package/dist/providers/google-vertex.d.ts +6 -0
- package/dist/providers/google-vertex.js +51 -0
- package/dist/providers/kimi-coding.d.ts +14 -0
- package/dist/providers/kimi-coding.js +80 -0
- package/dist/providers/model-ids.d.ts +53 -0
- package/dist/providers/model-ids.js +132 -0
- package/dist/providers/openai-codex.d.ts +114 -0
- package/dist/providers/openai-codex.js +427 -0
- package/dist/providers/provider-thinking.d.ts +23 -0
- package/dist/providers/provider-thinking.js +61 -0
- package/dist/providers/thinking-request.d.ts +14 -0
- package/dist/providers/thinking-request.js +87 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.js +72 -0
- package/dist/schedules/index.d.ts +10 -0
- package/dist/schedules/index.js +6 -0
- package/dist/schedules/interval.d.ts +49 -0
- package/dist/schedules/interval.js +212 -0
- package/dist/schedules/prompt.d.ts +36 -0
- package/dist/schedules/prompt.js +36 -0
- package/dist/schedules/run-script.d.ts +8 -0
- package/dist/schedules/run-script.js +80 -0
- package/dist/schedules/scheduler.d.ts +101 -0
- package/dist/schedules/scheduler.js +167 -0
- package/dist/schedules/tools.d.ts +57 -0
- package/dist/schedules/tools.js +217 -0
- package/dist/schema.d.ts +499 -0
- package/dist/schema.js +131 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.js +18 -0
- package/dist/thinking-catalog.d.ts +4 -0
- package/dist/thinking-catalog.js +13 -0
- package/dist/thinking.d.ts +37 -0
- package/dist/thinking.js +134 -0
- package/dist/tool-names.d.ts +77 -0
- package/dist/tool-names.js +53 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.js +80 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.js +31 -0
- package/dist/tools/web-search.d.ts +116 -0
- package/dist/tools/web-search.js +158 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.js +82 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.js +18 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
- package/dist/tools/workflows/ephemeral-memory.js +41 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.js +19 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.js +31 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.js +29 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
- package/dist/tools/workflows/list-available-classifiers.js +53 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.js +37 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.js +29 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.js +30 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.js +49 -0
- package/dist/tools/workflows/save-workflow.d.ts +1125 -0
- package/dist/tools/workflows/save-workflow.js +25 -0
- package/dist/tools/workflows/tool-ids.d.ts +16 -0
- package/dist/tools/workflows/tool-ids.js +17 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.js +97 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.js +56 -0
- package/dist/utils/discarding-scores-storage.d.ts +33 -0
- package/dist/utils/discarding-scores-storage.js +51 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.js +215 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.js +58 -0
- package/dist/utils/local-observability.d.ts +19 -0
- package/dist/utils/local-observability.js +54 -0
- package/dist/utils/maintenance-lock.d.ts +42 -0
- package/dist/utils/maintenance-lock.js +196 -0
- package/dist/utils/notification-dispatch.d.ts +74 -0
- package/dist/utils/notification-dispatch.js +128 -0
- package/dist/utils/open-url.d.ts +10 -0
- package/dist/utils/open-url.js +27 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.js +7 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.js +59 -0
- package/dist/utils/plans.d.ts +61 -0
- package/dist/utils/plans.js +120 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.js +361 -0
- package/dist/utils/prune-cli.d.ts +24 -0
- package/dist/utils/prune-cli.js +124 -0
- package/dist/utils/signals-pubsub.d.ts +103 -0
- package/dist/utils/signals-pubsub.js +409 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.js +139 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.js +106 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.js +93 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.js +118 -0
- package/dist/utils/storage-maintenance.d.ts +121 -0
- package/dist/utils/storage-maintenance.js +352 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.js +109 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.js +19 -0
- package/dist/utils/update-check.d.ts +151 -0
- package/dist/utils/update-check.js +430 -0
- package/dist/utils/wake-session.d.ts +44 -0
- package/dist/utils/wake-session.js +83 -0
- package/dist/voice/stt-registry.d.ts +67 -0
- package/dist/voice/stt-registry.js +144 -0
- package/dist/voice/transcribe.d.ts +10 -0
- package/dist/voice/transcribe.js +75 -0
- package/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.js +50 -0
- package/package.json +117 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Global plans directory for approved-plan archives. */
|
|
2
|
+
export declare function getPlansDir(): string;
|
|
3
|
+
export interface LocalPlansOptions {
|
|
4
|
+
factoryProjectId?: string | null;
|
|
5
|
+
/** Host-configured workspace-relative plans directory; wins over the default. */
|
|
6
|
+
plansDir?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Workspace-relative directory the agent writes plan files into. */
|
|
9
|
+
export declare function getLocalPlansRelativeDir(options?: LocalPlansOptions): string;
|
|
10
|
+
/** Local (project-scoped) plans directory where the agent writes named plan files. */
|
|
11
|
+
export declare function getLocalPlansDir(projectPath: string, options?: LocalPlansOptions): string;
|
|
12
|
+
/** Derive a plan filename from a title (e.g. `add-dark-mode.md`). */
|
|
13
|
+
export declare function getPlanFilename(title: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Suggested workspace-relative path for a new plan file, shown in plan-mode prompts.
|
|
16
|
+
* Without a title we fall back to a generic name the agent can rename later.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getSuggestedPlanRelativePath(title?: string, options?: LocalPlansOptions): string;
|
|
19
|
+
/**
|
|
20
|
+
* Resolve a plan path submitted by the agent (absolute or project-relative) to an
|
|
21
|
+
* absolute path. Returns `undefined` when no usable path was provided.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolvePlanPath(projectPath: string, submittedPath: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Whether `targetPath` (absolute or project-relative) is a valid plan file: a `.md`
|
|
26
|
+
* file located directly inside the project's configured plan directory. Used by the
|
|
27
|
+
* plan-mode write guard so the agent can write any named plan file there, but nothing
|
|
28
|
+
* outside that directory.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isPlanFilePath(projectPath: string, targetPath: string, options?: LocalPlansOptions): boolean;
|
|
31
|
+
export declare function savePlanToDisk(opts: {
|
|
32
|
+
title: string;
|
|
33
|
+
plan: string;
|
|
34
|
+
resourceId: string;
|
|
35
|
+
plansDir?: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Read a plan markdown file by absolute path.
|
|
39
|
+
*
|
|
40
|
+
* The leading `# <title>` heading (if present) is parsed as the title and the remaining
|
|
41
|
+
* content is returned as the plan body. Returns `undefined` when the file does not exist.
|
|
42
|
+
*/
|
|
43
|
+
export declare function readPlanFile(absPath: string): Promise<{
|
|
44
|
+
title: string;
|
|
45
|
+
plan: string;
|
|
46
|
+
} | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* Approve the plan file at `planPath`: write a timestamped copy to the global plans
|
|
49
|
+
* archive so approved plans are findable later. The local named plan file is left in
|
|
50
|
+
* place so the user can review every plan made over time.
|
|
51
|
+
*
|
|
52
|
+
* Returns the local plan filename (e.g. `add-dark-mode.md`), or `undefined` when there
|
|
53
|
+
* was no plan file to approve.
|
|
54
|
+
*/
|
|
55
|
+
export declare function approvePlanFile(opts: {
|
|
56
|
+
planPath: string;
|
|
57
|
+
title: string;
|
|
58
|
+
resourceId: string;
|
|
59
|
+
plansDir?: string;
|
|
60
|
+
}): Promise<string | undefined>;
|
|
61
|
+
//# sourceMappingURL=plans.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { DEFAULT_CONFIG_DIR } from "../constants.js";
|
|
2
|
+
import { getAppDataDir } from "./project.js";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import fs from "fs/promises";
|
|
5
|
+
// src/utils/plans.ts
|
|
6
|
+
/** Global plans directory for approved-plan archives. */
|
|
7
|
+
function getPlansDir() {
|
|
8
|
+
return process.env.MASTRA_PLANS_DIR ?? path.join(getAppDataDir(), "plans");
|
|
9
|
+
}
|
|
10
|
+
/** Workspace-relative directory the agent writes plan files into. */
|
|
11
|
+
function getLocalPlansRelativeDir(options = {}) {
|
|
12
|
+
if (options.plansDir) {
|
|
13
|
+
const dir = path.normalize(options.plansDir);
|
|
14
|
+
let end = dir.length;
|
|
15
|
+
while (end > 0 && (dir[end - 1] === "/" || dir[end - 1] === "\\")) end--;
|
|
16
|
+
return dir.slice(0, end);
|
|
17
|
+
}
|
|
18
|
+
return options.factoryProjectId ? path.join(".artifacts", "plans") : path.join(DEFAULT_CONFIG_DIR, "plans");
|
|
19
|
+
}
|
|
20
|
+
/** Local (project-scoped) plans directory where the agent writes named plan files. */
|
|
21
|
+
function getLocalPlansDir(projectPath, options = {}) {
|
|
22
|
+
return path.join(projectPath, getLocalPlansRelativeDir(options));
|
|
23
|
+
}
|
|
24
|
+
function slugify(str) {
|
|
25
|
+
return str.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "untitled";
|
|
26
|
+
}
|
|
27
|
+
/** Derive a plan filename from a title (e.g. `add-dark-mode.md`). */
|
|
28
|
+
function getPlanFilename(title) {
|
|
29
|
+
return `${slugify(title)}.md`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Suggested workspace-relative path for a new plan file, shown in plan-mode prompts.
|
|
33
|
+
* Without a title we fall back to a generic name the agent can rename later.
|
|
34
|
+
*/
|
|
35
|
+
function getSuggestedPlanRelativePath(title, options = {}) {
|
|
36
|
+
const filename = title ? getPlanFilename(title) : "plan.md";
|
|
37
|
+
return path.join(getLocalPlansRelativeDir(options), filename);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Resolve a plan path submitted by the agent (absolute or project-relative) to an
|
|
41
|
+
* absolute path. Returns `undefined` when no usable path was provided.
|
|
42
|
+
*/
|
|
43
|
+
function resolvePlanPath(projectPath, submittedPath) {
|
|
44
|
+
if (!submittedPath) return void 0;
|
|
45
|
+
return path.isAbsolute(submittedPath) ? submittedPath : path.resolve(projectPath, submittedPath);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Whether `targetPath` (absolute or project-relative) is a valid plan file: a `.md`
|
|
49
|
+
* file located directly inside the project's configured plan directory. Used by the
|
|
50
|
+
* plan-mode write guard so the agent can write any named plan file there, but nothing
|
|
51
|
+
* outside that directory.
|
|
52
|
+
*/
|
|
53
|
+
function isPlanFilePath(projectPath, targetPath, options = {}) {
|
|
54
|
+
const abs = resolvePlanPath(projectPath, targetPath);
|
|
55
|
+
if (!abs) return false;
|
|
56
|
+
if (path.extname(abs).toLowerCase() !== ".md") return false;
|
|
57
|
+
const plansDir = path.resolve(getLocalPlansDir(projectPath, options));
|
|
58
|
+
const rel = path.relative(plansDir, abs);
|
|
59
|
+
if (rel === "" || rel.startsWith("..") || path.isAbsolute(rel)) return false;
|
|
60
|
+
return !rel.includes(path.sep);
|
|
61
|
+
}
|
|
62
|
+
async function savePlanToDisk(opts) {
|
|
63
|
+
const { title, plan, resourceId } = opts;
|
|
64
|
+
const plansDir = opts.plansDir ?? getPlansDir();
|
|
65
|
+
const baseDir = path.resolve(plansDir);
|
|
66
|
+
const dir = path.resolve(baseDir, resourceId);
|
|
67
|
+
const rel = path.relative(baseDir, dir);
|
|
68
|
+
if (rel.startsWith("..") || path.isAbsolute(rel)) throw new Error(`Invalid resourceId: ${resourceId}`);
|
|
69
|
+
await fs.mkdir(dir, { recursive: true });
|
|
70
|
+
const now = /* @__PURE__ */ new Date();
|
|
71
|
+
const filename = `${now.toISOString().replace(/:/g, "-")}-${slugify(title)}.md`;
|
|
72
|
+
const content = `# ${title}\n\nApproved: ${now.toISOString()}\n\n${plan}\n`;
|
|
73
|
+
await fs.writeFile(path.join(dir, filename), content, "utf-8");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Read a plan markdown file by absolute path.
|
|
77
|
+
*
|
|
78
|
+
* The leading `# <title>` heading (if present) is parsed as the title and the remaining
|
|
79
|
+
* content is returned as the plan body. Returns `undefined` when the file does not exist.
|
|
80
|
+
*/
|
|
81
|
+
async function readPlanFile(absPath) {
|
|
82
|
+
let raw;
|
|
83
|
+
try {
|
|
84
|
+
raw = await fs.readFile(absPath, "utf-8");
|
|
85
|
+
} catch {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const lines = raw.split(/\r?\n/);
|
|
89
|
+
const headingIndex = lines.findIndex((line) => line.trim().length > 0);
|
|
90
|
+
const heading = headingIndex >= 0 ? lines[headingIndex] : void 0;
|
|
91
|
+
if (heading?.startsWith("# ")) return {
|
|
92
|
+
title: heading.slice(2).trim(),
|
|
93
|
+
plan: lines.slice(headingIndex + 1).join("\n").replace(/^\n+/, "").trimEnd()
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
title: "",
|
|
97
|
+
plan: raw.trimEnd()
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Approve the plan file at `planPath`: write a timestamped copy to the global plans
|
|
102
|
+
* archive so approved plans are findable later. The local named plan file is left in
|
|
103
|
+
* place so the user can review every plan made over time.
|
|
104
|
+
*
|
|
105
|
+
* Returns the local plan filename (e.g. `add-dark-mode.md`), or `undefined` when there
|
|
106
|
+
* was no plan file to approve.
|
|
107
|
+
*/
|
|
108
|
+
async function approvePlanFile(opts) {
|
|
109
|
+
const { planPath, title, resourceId, plansDir } = opts;
|
|
110
|
+
const current = await readPlanFile(planPath);
|
|
111
|
+
if (!current) return;
|
|
112
|
+
await savePlanToDisk({
|
|
113
|
+
title: title || current.title || "Implementation Plan",
|
|
114
|
+
plan: current.plan,
|
|
115
|
+
resourceId,
|
|
116
|
+
plansDir
|
|
117
|
+
});
|
|
118
|
+
return path.basename(planPath);
|
|
119
|
+
}
|
|
120
|
+
export { approvePlanFile, getLocalPlansDir, getLocalPlansRelativeDir, getPlanFilename, getPlansDir, getSuggestedPlanRelativePath, isPlanFilePath, readPlanFile, resolvePlanPath, savePlanToDisk };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project detection utilities
|
|
3
|
+
*
|
|
4
|
+
* Detects project identity from git repo or filesystem path.
|
|
5
|
+
* Handles git worktrees by finding the main repository.
|
|
6
|
+
*/
|
|
7
|
+
export interface ProjectInfo {
|
|
8
|
+
/** Unique resource ID for this project (used for thread grouping) */
|
|
9
|
+
resourceId: string;
|
|
10
|
+
/** Human-readable project name */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Absolute path to the project root */
|
|
13
|
+
rootPath: string;
|
|
14
|
+
/** Git remote URL if available */
|
|
15
|
+
gitUrl?: string;
|
|
16
|
+
/** Current git branch */
|
|
17
|
+
gitBranch?: string;
|
|
18
|
+
/** Whether this is a git worktree */
|
|
19
|
+
isWorktree: boolean;
|
|
20
|
+
/** Path to main git repo (different from rootPath if worktree) */
|
|
21
|
+
mainRepoPath?: string;
|
|
22
|
+
/** Whether the resourceId was explicitly overridden (env var or config) */
|
|
23
|
+
resourceIdOverride?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Detect project info from a directory path
|
|
27
|
+
*/
|
|
28
|
+
export declare function detectProject(projectPath: string): ProjectInfo;
|
|
29
|
+
/**
|
|
30
|
+
* Get the current git branch for a given directory.
|
|
31
|
+
* Lightweight alternative to detectProject() for refreshing just the branch.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getCurrentGitBranch(cwd: string): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Async version of getCurrentGitBranch — avoids blocking the event loop
|
|
36
|
+
* with execSync. Falls back to undefined on any failure.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getCurrentGitBranchAsync(cwd: string): Promise<string | undefined>;
|
|
39
|
+
/**
|
|
40
|
+
* Get the application data directory for mastracode
|
|
41
|
+
* - macOS: ~/Library/Application Support/mastracode
|
|
42
|
+
* - Linux: ~/.local/share/mastracode
|
|
43
|
+
* - Windows: %APPDATA%/mastracode
|
|
44
|
+
*/
|
|
45
|
+
export declare function getAppDataDir(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Get the database path for mastracode
|
|
48
|
+
* Can be overridden with the MASTRA_DB_PATH environment variable for debugging.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getDatabasePath(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Get the vector database path for mastracode.
|
|
53
|
+
* Separate from the main DB to avoid bloating it with embedding data.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getVectorDatabasePath(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Get the observability DuckDB database path for mastracode.
|
|
58
|
+
* Separate from the main DB — DuckDB is used for OLAP-style trace/score/feedback queries.
|
|
59
|
+
* Can be overridden with the MASTRA_OBSERVABILITY_DB_PATH environment variable.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getObservabilityDatabasePath(): string;
|
|
62
|
+
import type { StorageSettings } from '../onboarding/settings.js';
|
|
63
|
+
/**
|
|
64
|
+
* LibSQL storage configuration.
|
|
65
|
+
*/
|
|
66
|
+
export interface LibSQLStorageConfig {
|
|
67
|
+
backend: 'libsql';
|
|
68
|
+
url: string;
|
|
69
|
+
authToken?: string;
|
|
70
|
+
isRemote: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Optional explicit url for the recall vector DB. When omitted, the factory
|
|
73
|
+
* uses the shared default vector file.
|
|
74
|
+
*/
|
|
75
|
+
vectorUrl?: string;
|
|
76
|
+
/** Auth token for the vector DB when `vectorUrl` points at a remote libSQL. */
|
|
77
|
+
vectorAuthToken?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* PostgreSQL storage configuration.
|
|
81
|
+
*/
|
|
82
|
+
export interface PgStorageConfig {
|
|
83
|
+
backend: 'pg';
|
|
84
|
+
connectionString?: string;
|
|
85
|
+
host?: string;
|
|
86
|
+
port?: number;
|
|
87
|
+
database?: string;
|
|
88
|
+
user?: string;
|
|
89
|
+
password?: string;
|
|
90
|
+
schemaName?: string;
|
|
91
|
+
disableInit?: boolean;
|
|
92
|
+
skipDefaultIndexes?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Resolved storage configuration for either backend.
|
|
96
|
+
*/
|
|
97
|
+
export type StorageConfig = LibSQLStorageConfig | PgStorageConfig;
|
|
98
|
+
/**
|
|
99
|
+
* Get the resolved storage configuration.
|
|
100
|
+
*
|
|
101
|
+
* Priority (highest to lowest):
|
|
102
|
+
* 1. Environment variables: MASTRA_STORAGE_BACKEND + backend-specific vars
|
|
103
|
+
* 2. Global settings (from /settings): settings.storage
|
|
104
|
+
* 3. Legacy config files: .mastracode/database.json (LibSQL only)
|
|
105
|
+
* 4. Local file database (LibSQL default)
|
|
106
|
+
*
|
|
107
|
+
* For PG, the env vars are:
|
|
108
|
+
* MASTRA_STORAGE_BACKEND=pg
|
|
109
|
+
* MASTRA_PG_CONNECTION_STRING or MASTRA_PG_HOST/PORT/DATABASE/USER/PASSWORD
|
|
110
|
+
* MASTRA_PG_SCHEMA_NAME (optional)
|
|
111
|
+
*
|
|
112
|
+
* For LibSQL, the legacy env vars still work:
|
|
113
|
+
* MASTRA_DB_URL + MASTRA_DB_AUTH_TOKEN
|
|
114
|
+
*/
|
|
115
|
+
export declare function getStorageConfig(projectDir?: string, storageSettings?: StorageSettings, configDirName?: string): StorageConfig;
|
|
116
|
+
/**
|
|
117
|
+
* Get the current user identity.
|
|
118
|
+
*
|
|
119
|
+
* Priority:
|
|
120
|
+
* 1. MASTRA_USER_ID environment variable
|
|
121
|
+
* 2. git config user.email (from project dir or global)
|
|
122
|
+
* 3. OS username as fallback
|
|
123
|
+
*/
|
|
124
|
+
export declare function getUserId(projectDir?: string): string;
|
|
125
|
+
/**
|
|
126
|
+
* Get the current user's display name.
|
|
127
|
+
*
|
|
128
|
+
* Priority:
|
|
129
|
+
* 1. git config user.name
|
|
130
|
+
* 2. OS username as fallback
|
|
131
|
+
*/
|
|
132
|
+
export declare function getUserName(projectDir?: string): string;
|
|
133
|
+
/**
|
|
134
|
+
* Observational memory scope: "thread" (per-conversation) or "resource" (shared across threads).
|
|
135
|
+
*/
|
|
136
|
+
export type OmScope = 'thread' | 'resource';
|
|
137
|
+
/**
|
|
138
|
+
* Get the configured observational memory scope.
|
|
139
|
+
*
|
|
140
|
+
* Priority:
|
|
141
|
+
* 1. MASTRA_OM_SCOPE environment variable ("thread" or "resource")
|
|
142
|
+
* 2. Project config: .mastracode/database.json → omScope
|
|
143
|
+
* 3. Global config: ~/.mastracode/database.json → omScope
|
|
144
|
+
* 4. Default: "thread"
|
|
145
|
+
*/
|
|
146
|
+
export declare function getOmScope(projectDir?: string, configDirName?: string): OmScope;
|
|
147
|
+
/**
|
|
148
|
+
* Get an explicit resource ID override, if configured.
|
|
149
|
+
*
|
|
150
|
+
* Resource IDs act as shared tags — two users who set the same resourceId
|
|
151
|
+
* will share threads and observations for that resource.
|
|
152
|
+
*
|
|
153
|
+
* Priority:
|
|
154
|
+
* 1. MASTRA_RESOURCE_ID environment variable
|
|
155
|
+
* 2. Project config: .mastracode/database.json → resourceId
|
|
156
|
+
* 3. Global config: ~/.mastracode/database.json → resourceId
|
|
157
|
+
* 4. null (use auto-detected value)
|
|
158
|
+
*/
|
|
159
|
+
export declare function getResourceIdOverride(projectDir?: string, configDirName?: string): string | null;
|
|
160
|
+
//# sourceMappingURL=project.d.ts.map
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { DEFAULT_CONFIG_DIR } from "../constants.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { createHash } from "crypto";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import { execFile, execSync } from "child_process";
|
|
6
|
+
import os from "os";
|
|
7
|
+
// src/utils/project.ts
|
|
8
|
+
/**
|
|
9
|
+
* Project detection utilities
|
|
10
|
+
*
|
|
11
|
+
* Detects project identity from git repo or filesystem path.
|
|
12
|
+
* Handles git worktrees by finding the main repository.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Run a git command and return stdout, or undefined if it fails
|
|
16
|
+
*/
|
|
17
|
+
function git(args, cwd) {
|
|
18
|
+
try {
|
|
19
|
+
return execSync(`git ${args}`, {
|
|
20
|
+
cwd,
|
|
21
|
+
encoding: "utf-8",
|
|
22
|
+
stdio: [
|
|
23
|
+
"pipe",
|
|
24
|
+
"pipe",
|
|
25
|
+
"pipe"
|
|
26
|
+
]
|
|
27
|
+
}).trim();
|
|
28
|
+
} catch {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Slugify a string for use in IDs
|
|
34
|
+
*/
|
|
35
|
+
function slugify(str) {
|
|
36
|
+
return str.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a short hash of a string
|
|
40
|
+
*/
|
|
41
|
+
function shortHash(str) {
|
|
42
|
+
return createHash("sha256").update(str).digest("hex").slice(0, 12);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Normalize a git URL to a canonical form for comparison
|
|
46
|
+
* - Removes .git suffix
|
|
47
|
+
* - Converts SSH to HTTPS format for consistency
|
|
48
|
+
* - Lowercases
|
|
49
|
+
*/
|
|
50
|
+
function normalizeGitUrl(url) {
|
|
51
|
+
return url.replace(/\.git$/, "").replace(/^git@([^:]+):/, "https://$1/").replace(/^ssh:\/\/git@/, "https://").toLowerCase();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Detect project info from a directory path
|
|
55
|
+
*/
|
|
56
|
+
function detectProject(projectPath) {
|
|
57
|
+
const absolutePath = path.resolve(projectPath);
|
|
58
|
+
const gitDir = git("rev-parse --git-dir", absolutePath);
|
|
59
|
+
const isGitRepo = gitDir !== void 0;
|
|
60
|
+
let rootPath = absolutePath;
|
|
61
|
+
let gitUrl;
|
|
62
|
+
let gitBranch;
|
|
63
|
+
let isWorktree = false;
|
|
64
|
+
let mainRepoPath;
|
|
65
|
+
if (isGitRepo) {
|
|
66
|
+
rootPath = git("rev-parse --show-toplevel", absolutePath) || absolutePath;
|
|
67
|
+
const commonDir = git("rev-parse --git-common-dir", absolutePath);
|
|
68
|
+
if (commonDir && commonDir !== ".git" && commonDir !== gitDir) {
|
|
69
|
+
isWorktree = true;
|
|
70
|
+
mainRepoPath = path.dirname(path.resolve(rootPath, commonDir));
|
|
71
|
+
}
|
|
72
|
+
gitUrl = git("remote get-url origin", absolutePath);
|
|
73
|
+
if (!gitUrl) {
|
|
74
|
+
const remotes = git("remote", absolutePath);
|
|
75
|
+
if (remotes) {
|
|
76
|
+
const firstRemote = remotes.split("\n")[0];
|
|
77
|
+
if (firstRemote) gitUrl = git(`remote get-url ${firstRemote}`, absolutePath);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
gitBranch = git("rev-parse --abbrev-ref HEAD", absolutePath);
|
|
81
|
+
}
|
|
82
|
+
let resourceIdSource;
|
|
83
|
+
if (gitUrl) resourceIdSource = normalizeGitUrl(gitUrl);
|
|
84
|
+
else if (mainRepoPath) resourceIdSource = mainRepoPath;
|
|
85
|
+
else resourceIdSource = rootPath;
|
|
86
|
+
const baseName = gitUrl ? gitUrl.split("/").pop()?.replace(/\.git$/, "") || "project" : path.basename(rootPath);
|
|
87
|
+
return {
|
|
88
|
+
resourceId: `${slugify(baseName)}-${shortHash(resourceIdSource)}`,
|
|
89
|
+
name: baseName,
|
|
90
|
+
rootPath,
|
|
91
|
+
gitUrl,
|
|
92
|
+
gitBranch,
|
|
93
|
+
isWorktree,
|
|
94
|
+
mainRepoPath
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the current git branch for a given directory.
|
|
99
|
+
* Lightweight alternative to detectProject() for refreshing just the branch.
|
|
100
|
+
*/
|
|
101
|
+
function getCurrentGitBranch(cwd) {
|
|
102
|
+
return git("rev-parse --abbrev-ref HEAD", cwd);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Async version of getCurrentGitBranch — avoids blocking the event loop
|
|
106
|
+
* with execSync. Falls back to undefined on any failure.
|
|
107
|
+
*/
|
|
108
|
+
function getCurrentGitBranchAsync(cwd) {
|
|
109
|
+
return new Promise((resolve) => {
|
|
110
|
+
execFile("git", [
|
|
111
|
+
"rev-parse",
|
|
112
|
+
"--abbrev-ref",
|
|
113
|
+
"HEAD"
|
|
114
|
+
], {
|
|
115
|
+
cwd,
|
|
116
|
+
encoding: "utf-8"
|
|
117
|
+
}, (err, stdout) => {
|
|
118
|
+
if (err) {
|
|
119
|
+
resolve(void 0);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
resolve(stdout.trim() || void 0);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get the application data directory for mastracode
|
|
128
|
+
* - macOS: ~/Library/Application Support/mastracode
|
|
129
|
+
* - Linux: ~/.local/share/mastracode
|
|
130
|
+
* - Windows: %APPDATA%/mastracode
|
|
131
|
+
*/
|
|
132
|
+
function getAppDataDir() {
|
|
133
|
+
if (process.env.MASTRA_APP_DATA_DIR) {
|
|
134
|
+
fs.mkdirSync(process.env.MASTRA_APP_DATA_DIR, { recursive: true });
|
|
135
|
+
return process.env.MASTRA_APP_DATA_DIR;
|
|
136
|
+
}
|
|
137
|
+
const platform = os.platform();
|
|
138
|
+
let baseDir;
|
|
139
|
+
if (platform === "darwin") baseDir = path.join(os.homedir(), "Library", "Application Support");
|
|
140
|
+
else if (platform === "win32") baseDir = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
|
141
|
+
else baseDir = process.env.XDG_DATA_HOME || path.join(os.homedir(), ".local", "share");
|
|
142
|
+
const appDir = path.join(baseDir, "mastracode");
|
|
143
|
+
if (!fs.existsSync(appDir)) fs.mkdirSync(appDir, { recursive: true });
|
|
144
|
+
return appDir;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get the database path for mastracode
|
|
148
|
+
* Can be overridden with the MASTRA_DB_PATH environment variable for debugging.
|
|
149
|
+
*/
|
|
150
|
+
function getDatabasePath() {
|
|
151
|
+
if (process.env.MASTRA_DB_PATH) return process.env.MASTRA_DB_PATH;
|
|
152
|
+
return path.join(getAppDataDir(), "mastra.db");
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get the vector database path for mastracode.
|
|
156
|
+
* Separate from the main DB to avoid bloating it with embedding data.
|
|
157
|
+
*/
|
|
158
|
+
function getVectorDatabasePath() {
|
|
159
|
+
return path.join(getAppDataDir(), "mastra-vectors.db");
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get the observability DuckDB database path for mastracode.
|
|
163
|
+
* Separate from the main DB — DuckDB is used for OLAP-style trace/score/feedback queries.
|
|
164
|
+
* Can be overridden with the MASTRA_OBSERVABILITY_DB_PATH environment variable.
|
|
165
|
+
*/
|
|
166
|
+
function getObservabilityDatabasePath() {
|
|
167
|
+
if (process.env.MASTRA_OBSERVABILITY_DB_PATH) return process.env.MASTRA_OBSERVABILITY_DB_PATH;
|
|
168
|
+
return path.join(getAppDataDir(), "observability.duckdb");
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get the resolved storage configuration.
|
|
172
|
+
*
|
|
173
|
+
* Priority (highest to lowest):
|
|
174
|
+
* 1. Environment variables: MASTRA_STORAGE_BACKEND + backend-specific vars
|
|
175
|
+
* 2. Global settings (from /settings): settings.storage
|
|
176
|
+
* 3. Legacy config files: .mastracode/database.json (LibSQL only)
|
|
177
|
+
* 4. Local file database (LibSQL default)
|
|
178
|
+
*
|
|
179
|
+
* For PG, the env vars are:
|
|
180
|
+
* MASTRA_STORAGE_BACKEND=pg
|
|
181
|
+
* MASTRA_PG_CONNECTION_STRING or MASTRA_PG_HOST/PORT/DATABASE/USER/PASSWORD
|
|
182
|
+
* MASTRA_PG_SCHEMA_NAME (optional)
|
|
183
|
+
*
|
|
184
|
+
* For LibSQL, the legacy env vars still work:
|
|
185
|
+
* MASTRA_DB_URL + MASTRA_DB_AUTH_TOKEN
|
|
186
|
+
*/
|
|
187
|
+
function getStorageConfig(projectDir, storageSettings, configDirName = DEFAULT_CONFIG_DIR) {
|
|
188
|
+
const envBackend = process.env.MASTRA_STORAGE_BACKEND;
|
|
189
|
+
if (envBackend === "pg") return resolvePgFromEnv();
|
|
190
|
+
if (envBackend === "libsql" || process.env.MASTRA_DB_URL) return resolveLibSQLFromEnv();
|
|
191
|
+
if (storageSettings && storageSettings.backend === "pg") return resolvePgFromSettings(storageSettings);
|
|
192
|
+
if (storageSettings && storageSettings.backend === "libsql" && storageSettings.libsql.url) return {
|
|
193
|
+
backend: "libsql",
|
|
194
|
+
url: storageSettings.libsql.url,
|
|
195
|
+
authToken: storageSettings.libsql.authToken,
|
|
196
|
+
isRemote: !storageSettings.libsql.url.startsWith("file:")
|
|
197
|
+
};
|
|
198
|
+
if (projectDir) {
|
|
199
|
+
const projectConfig = loadDatabaseConfig(path.join(projectDir, configDirName, "database.json"));
|
|
200
|
+
if (projectConfig) return projectConfig;
|
|
201
|
+
}
|
|
202
|
+
const globalConfig = loadDatabaseConfig(path.join(os.homedir(), configDirName, "database.json"));
|
|
203
|
+
if (globalConfig) return globalConfig;
|
|
204
|
+
return {
|
|
205
|
+
backend: "libsql",
|
|
206
|
+
url: `file:${getDatabasePath()}`,
|
|
207
|
+
isRemote: false
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function resolveLibSQLFromEnv() {
|
|
211
|
+
const url = process.env.MASTRA_DB_URL;
|
|
212
|
+
return {
|
|
213
|
+
backend: "libsql",
|
|
214
|
+
url,
|
|
215
|
+
authToken: process.env.MASTRA_DB_AUTH_TOKEN,
|
|
216
|
+
isRemote: !url.startsWith("file:")
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function resolvePgFromEnv() {
|
|
220
|
+
const connectionString = process.env.MASTRA_PG_CONNECTION_STRING;
|
|
221
|
+
if (connectionString) return {
|
|
222
|
+
backend: "pg",
|
|
223
|
+
connectionString,
|
|
224
|
+
schemaName: process.env.MASTRA_PG_SCHEMA_NAME
|
|
225
|
+
};
|
|
226
|
+
return {
|
|
227
|
+
backend: "pg",
|
|
228
|
+
host: process.env.MASTRA_PG_HOST,
|
|
229
|
+
port: process.env.MASTRA_PG_PORT ? parseInt(process.env.MASTRA_PG_PORT, 10) : void 0,
|
|
230
|
+
database: process.env.MASTRA_PG_DATABASE,
|
|
231
|
+
user: process.env.MASTRA_PG_USER,
|
|
232
|
+
password: process.env.MASTRA_PG_PASSWORD,
|
|
233
|
+
schemaName: process.env.MASTRA_PG_SCHEMA_NAME
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function resolvePgFromSettings(settings) {
|
|
237
|
+
const pg = settings.pg;
|
|
238
|
+
return {
|
|
239
|
+
backend: "pg",
|
|
240
|
+
connectionString: pg.connectionString,
|
|
241
|
+
host: pg.host,
|
|
242
|
+
port: pg.port,
|
|
243
|
+
database: pg.database,
|
|
244
|
+
user: pg.user,
|
|
245
|
+
password: pg.password,
|
|
246
|
+
schemaName: pg.schemaName,
|
|
247
|
+
disableInit: pg.disableInit,
|
|
248
|
+
skipDefaultIndexes: pg.skipDefaultIndexes
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Load database config from a legacy JSON file.
|
|
253
|
+
* Expected format: { "url": "libsql://...", "authToken": "..." }
|
|
254
|
+
*/
|
|
255
|
+
function loadDatabaseConfig(filePath) {
|
|
256
|
+
try {
|
|
257
|
+
if (!fs.existsSync(filePath)) return null;
|
|
258
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
259
|
+
const parsed = JSON.parse(raw);
|
|
260
|
+
if (typeof parsed?.url === "string" && parsed.url) return {
|
|
261
|
+
backend: "libsql",
|
|
262
|
+
url: parsed.url,
|
|
263
|
+
authToken: typeof parsed.authToken === "string" ? parsed.authToken : void 0,
|
|
264
|
+
isRemote: !parsed.url.startsWith("file:")
|
|
265
|
+
};
|
|
266
|
+
return null;
|
|
267
|
+
} catch {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Get the current user identity.
|
|
273
|
+
*
|
|
274
|
+
* Priority:
|
|
275
|
+
* 1. MASTRA_USER_ID environment variable
|
|
276
|
+
* 2. git config user.email (from project dir or global)
|
|
277
|
+
* 3. OS username as fallback
|
|
278
|
+
*/
|
|
279
|
+
function getUserId(projectDir) {
|
|
280
|
+
if (process.env.MASTRA_USER_ID) return process.env.MASTRA_USER_ID;
|
|
281
|
+
const email = git("config user.email", projectDir || process.cwd());
|
|
282
|
+
if (email) return email;
|
|
283
|
+
return os.userInfo().username || "unknown";
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get the current user's display name.
|
|
287
|
+
*
|
|
288
|
+
* Priority:
|
|
289
|
+
* 1. git config user.name
|
|
290
|
+
* 2. OS username as fallback
|
|
291
|
+
*/
|
|
292
|
+
function getUserName(projectDir) {
|
|
293
|
+
const name = git("config user.name", projectDir || process.cwd());
|
|
294
|
+
if (name) return name;
|
|
295
|
+
return os.userInfo().username || "unknown";
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Get the configured observational memory scope.
|
|
299
|
+
*
|
|
300
|
+
* Priority:
|
|
301
|
+
* 1. MASTRA_OM_SCOPE environment variable ("thread" or "resource")
|
|
302
|
+
* 2. Project config: .mastracode/database.json → omScope
|
|
303
|
+
* 3. Global config: ~/.mastracode/database.json → omScope
|
|
304
|
+
* 4. Default: "thread"
|
|
305
|
+
*/
|
|
306
|
+
function getOmScope(projectDir, configDirName = DEFAULT_CONFIG_DIR) {
|
|
307
|
+
const envScope = process.env.MASTRA_OM_SCOPE;
|
|
308
|
+
if (envScope === "thread" || envScope === "resource") return envScope;
|
|
309
|
+
if (projectDir) {
|
|
310
|
+
const scope = loadOmScopeFromConfig(path.join(projectDir, configDirName, "database.json"));
|
|
311
|
+
if (scope) return scope;
|
|
312
|
+
}
|
|
313
|
+
const scope = loadOmScopeFromConfig(path.join(os.homedir(), configDirName, "database.json"));
|
|
314
|
+
if (scope) return scope;
|
|
315
|
+
return "thread";
|
|
316
|
+
}
|
|
317
|
+
function loadOmScopeFromConfig(filePath) {
|
|
318
|
+
try {
|
|
319
|
+
if (!fs.existsSync(filePath)) return null;
|
|
320
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
321
|
+
const parsed = JSON.parse(raw);
|
|
322
|
+
if (parsed?.omScope === "thread" || parsed?.omScope === "resource") return parsed.omScope;
|
|
323
|
+
return null;
|
|
324
|
+
} catch {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Get an explicit resource ID override, if configured.
|
|
330
|
+
*
|
|
331
|
+
* Resource IDs act as shared tags — two users who set the same resourceId
|
|
332
|
+
* will share threads and observations for that resource.
|
|
333
|
+
*
|
|
334
|
+
* Priority:
|
|
335
|
+
* 1. MASTRA_RESOURCE_ID environment variable
|
|
336
|
+
* 2. Project config: .mastracode/database.json → resourceId
|
|
337
|
+
* 3. Global config: ~/.mastracode/database.json → resourceId
|
|
338
|
+
* 4. null (use auto-detected value)
|
|
339
|
+
*/
|
|
340
|
+
function getResourceIdOverride(projectDir, configDirName = DEFAULT_CONFIG_DIR) {
|
|
341
|
+
if (process.env.MASTRA_RESOURCE_ID) return process.env.MASTRA_RESOURCE_ID;
|
|
342
|
+
if (projectDir) {
|
|
343
|
+
const rid = loadStringField(path.join(projectDir, configDirName, "database.json"), "resourceId");
|
|
344
|
+
if (rid) return rid;
|
|
345
|
+
}
|
|
346
|
+
const rid = loadStringField(path.join(os.homedir(), configDirName, "database.json"), "resourceId");
|
|
347
|
+
if (rid) return rid;
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
function loadStringField(filePath, field) {
|
|
351
|
+
try {
|
|
352
|
+
if (!fs.existsSync(filePath)) return null;
|
|
353
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
354
|
+
const value = JSON.parse(raw)?.[field];
|
|
355
|
+
if (typeof value === "string" && value) return value;
|
|
356
|
+
return null;
|
|
357
|
+
} catch {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
export { detectProject, getAppDataDir, getCurrentGitBranch, getCurrentGitBranchAsync, getDatabasePath, getObservabilityDatabasePath, getOmScope, getResourceIdOverride, getStorageConfig, getUserId, getUserName, getVectorDatabasePath };
|