@mastra/code-sdk 0.1.0-alpha.1 → 0.1.0-alpha.11
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 +125 -0
- package/dist/agents/mastracode-gateway.d.ts +4 -2
- package/dist/agents/mastracode-gateway.d.ts.map +1 -1
- package/dist/agents/mastracode-gateway.js +11 -7
- package/dist/agents/mastracode-gateway.js.map +1 -1
- package/dist/agents/model.js +1 -1
- package/dist/agents/model.js.map +1 -1
- package/dist/agents/tools.d.ts +3 -3
- package/dist/agents/tools.d.ts.map +1 -1
- package/dist/agents/tools.js +33 -22
- package/dist/agents/tools.js.map +1 -1
- package/dist/agents/workspace.d.ts.map +1 -1
- package/dist/agents/workspace.js +51 -19
- package/dist/agents/workspace.js.map +1 -1
- package/dist/index.d.ts +7 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -5
- package/dist/index.js.map +1 -1
- package/dist/onboarding/settings.d.ts +6 -2
- package/dist/onboarding/settings.d.ts.map +1 -1
- package/dist/onboarding/settings.js +6 -2
- package/dist/onboarding/settings.js.map +1 -1
- package/dist/plugins/dependencies.d.ts.map +1 -1
- package/dist/plugins/dependencies.js +28 -58
- package/dist/plugins/dependencies.js.map +1 -1
- 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 +9 -0
- package/dist/utils/path-security.js.map +1 -0
- package/dist/utils/project.d.ts +1 -2
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/slash-command-loader.d.ts +5 -1
- package/dist/utils/slash-command-loader.d.ts.map +1 -1
- package/dist/utils/slash-command-loader.js +30 -8
- package/dist/utils/slash-command-loader.js.map +1 -1
- package/dist/utils/storage-factory.d.ts +3 -3
- package/dist/utils/storage-factory.d.ts.map +1 -1
- package/dist/utils/storage-factory.js +5 -2
- package/dist/utils/storage-factory.js.map +1 -1
- 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 +236 -0
- package/dist/utils/storage-maintenance.js.map +1 -0
- package/package.json +17 -15
package/dist/agents/workspace.js
CHANGED
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { Workspace, LocalFilesystem, LocalSandbox, createWorkspaceTools } from "@mastra/core/workspace";
|
|
6
6
|
import { DEFAULT_CONFIG_DIR } from "../constants.js";
|
|
7
7
|
import { loadSettings } from "../onboarding/settings.js";
|
|
8
|
+
import { isPathWithinRoot } from "../utils/path-security.js";
|
|
8
9
|
import { getPlansDir } from "../utils/plans.js";
|
|
9
10
|
import { SandboxFilesystem } from "./sandbox-filesystem.js";
|
|
10
11
|
import { reattachProjectSandbox } from "./sandbox-reattach.js";
|
|
@@ -21,29 +22,52 @@ function buildSandboxEnv() {
|
|
|
21
22
|
DEBIAN_FRONTEND: "noninteractive"
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
function collectSkillPaths(skillsDirs) {
|
|
25
|
+
function collectSkillPaths(skillsDirs, allowedRoot) {
|
|
25
26
|
const paths = [];
|
|
26
27
|
const seen = /* @__PURE__ */ new Set();
|
|
28
|
+
let realAllowedRoot;
|
|
29
|
+
if (allowedRoot) {
|
|
30
|
+
try {
|
|
31
|
+
realAllowedRoot = fs.realpathSync(allowedRoot);
|
|
32
|
+
} catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
27
36
|
for (const skillsDir of skillsDirs) {
|
|
37
|
+
const skillsDirExists = fs.existsSync(skillsDir);
|
|
38
|
+
if (skillsDirExists && realAllowedRoot) {
|
|
39
|
+
try {
|
|
40
|
+
const realSkillsDir = fs.realpathSync(skillsDir);
|
|
41
|
+
if (!isPathWithinRoot(realSkillsDir, realAllowedRoot)) continue;
|
|
42
|
+
} catch {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
28
46
|
const resolved = path.resolve(skillsDir);
|
|
29
47
|
if (!seen.has(resolved)) {
|
|
30
48
|
seen.add(resolved);
|
|
31
49
|
paths.push(skillsDir);
|
|
32
50
|
}
|
|
33
|
-
if (!
|
|
51
|
+
if (!skillsDirExists) continue;
|
|
34
52
|
try {
|
|
35
53
|
const entries = fs.readdirSync(skillsDir, { withFileTypes: true });
|
|
36
54
|
for (const entry of entries) {
|
|
37
55
|
if (entry.isSymbolicLink()) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
try {
|
|
57
|
+
const linkPath = path.join(skillsDir, entry.name);
|
|
58
|
+
const realPath = fs.realpathSync(linkPath);
|
|
59
|
+
if (realAllowedRoot && !isPathWithinRoot(realPath, realAllowedRoot)) continue;
|
|
60
|
+
const stat = fs.statSync(realPath);
|
|
61
|
+
if (stat.isDirectory()) {
|
|
62
|
+
const realParent = path.dirname(realPath);
|
|
63
|
+
if (realAllowedRoot && !isPathWithinRoot(realParent, realAllowedRoot)) continue;
|
|
64
|
+
if (!seen.has(realParent)) {
|
|
65
|
+
seen.add(realParent);
|
|
66
|
+
paths.push(realParent);
|
|
67
|
+
}
|
|
46
68
|
}
|
|
69
|
+
} catch {
|
|
70
|
+
continue;
|
|
47
71
|
}
|
|
48
72
|
}
|
|
49
73
|
}
|
|
@@ -59,15 +83,23 @@ function buildSkillPaths(projectPath, configDir, homeDir = os.homedir(), pluginS
|
|
|
59
83
|
const mastraCodeGlobalSkillsPath = path.join(homeDir, configDir, "skills");
|
|
60
84
|
const claudeGlobalSkillsPath = path.join(homeDir, ".claude", "skills");
|
|
61
85
|
const agentSkillsGlobalPath = path.join(homeDir, ".agents", "skills");
|
|
62
|
-
|
|
63
|
-
mastraCodeLocalSkillsPath,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
86
|
+
const paths = [
|
|
87
|
+
...collectSkillPaths([mastraCodeLocalSkillsPath, claudeLocalSkillsPath, agentSkillsLocalPath], projectPath),
|
|
88
|
+
...collectSkillPaths([mastraCodeGlobalSkillsPath, claudeGlobalSkillsPath, agentSkillsGlobalPath]),
|
|
89
|
+
...pluginSkillPaths.flatMap((pluginSkillPath) => collectSkillPaths([pluginSkillPath], pluginSkillPath))
|
|
90
|
+
];
|
|
91
|
+
const seenPaths = /* @__PURE__ */ new Set();
|
|
92
|
+
return paths.filter((skillPath) => {
|
|
93
|
+
let resolved;
|
|
94
|
+
try {
|
|
95
|
+
resolved = fs.realpathSync(skillPath);
|
|
96
|
+
} catch {
|
|
97
|
+
resolved = path.resolve(skillPath);
|
|
98
|
+
}
|
|
99
|
+
if (seenPaths.has(resolved)) return false;
|
|
100
|
+
seenPaths.add(resolved);
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
71
103
|
}
|
|
72
104
|
const DEFAULT_ALLOWED_PATHS = [os.tmpdir(), "/tmp", getPlansDir()].reduce((acc, p) => {
|
|
73
105
|
const resolved = path.resolve(p);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/agents/workspace.ts"],"sourcesContent":["import fs, { existsSync } from 'node:fs';\nimport os from 'node:os';\nimport path, { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ToolsInput } from '@mastra/core/agent';\nimport type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { Workspace, LocalFilesystem, LocalSandbox, createWorkspaceTools } from '@mastra/core/workspace';\nimport type { LSPConfig } from '@mastra/core/workspace';\nimport { DEFAULT_CONFIG_DIR } from '../constants.js';\nimport { loadSettings } from '../onboarding/settings.js';\nimport type { MastraCodeState } from '../schema.js';\nimport { getPlansDir } from '../utils/plans.js';\nimport { SandboxFilesystem } from './sandbox-filesystem.js';\nimport { reattachProjectSandbox } from './sandbox-reattach.js';\nimport { GOAL_JUDGE_READONLY_TOOLS, MASTRACODE_WORKSPACE_TOOLS } from './tool-availability.js';\n\n// =============================================================================\n// Sandbox Environment\n// =============================================================================\n\nfunction buildSandboxEnv(): NodeJS.ProcessEnv {\n return {\n ...process.env,\n // Explicit overrides for non-interactive subprocess execution\n FORCE_COLOR: '1',\n CLICOLOR_FORCE: '1',\n TERM: process.env.TERM || 'xterm-256color',\n CI: 'true',\n NONINTERACTIVE: '1',\n DEBIAN_FRONTEND: 'noninteractive',\n };\n}\n\n// =============================================================================\n// Create Workspace with Skills\n// =============================================================================\n\n// We support multiple skill locations for compatibility:\n// 1. Project-local: <configDir>/skills (project-specific mastracode skills)\n// 2. Project-local: .claude/skills (Claude Code compatible skills)\n// 3. Project-local: .agents/skills (Agent Skills spec compatible)\n// 4. Global: ~/<configDir>/skills (user-wide mastracode skills)\n// 5. Global: ~/.claude/skills (user-wide Claude Code skills)\n// 6. Global: ~/.agents/skills (user-wide Agent Skills spec compatible)\n\n// Mastra's LocalSkillSource.readdir uses Node's Dirent.isDirectory() which\n// returns false for symlinks. Tools like `npx skills add` install skills as\n// symlinks, so we need to resolve them. For each symlinked skill directory,\n// we add the real (resolved) parent path as an additional skill scan path.\nfunction collectSkillPaths(skillsDirs: string[]): string[] {\n const paths: string[] = [];\n const seen = new Set<string>();\n\n for (const skillsDir of skillsDirs) {\n const resolved = path.resolve(skillsDir);\n if (!seen.has(resolved)) {\n seen.add(resolved);\n paths.push(skillsDir);\n }\n\n if (!fs.existsSync(skillsDir)) continue;\n\n try {\n const entries = fs.readdirSync(skillsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isSymbolicLink()) {\n const linkPath = path.join(skillsDir, entry.name);\n const realPath = fs.realpathSync(linkPath);\n const stat = fs.statSync(realPath);\n if (stat.isDirectory()) {\n const realParent = path.dirname(realPath);\n if (!seen.has(realParent)) {\n seen.add(realParent);\n paths.push(realParent);\n }\n }\n }\n }\n } catch {\n // Ignore errors during symlink resolution\n }\n }\n\n return paths;\n}\n\n// Build skill paths dynamically based on configDir and projectPath\nexport function buildSkillPaths(\n projectPath: string,\n configDir: string,\n homeDir = os.homedir(),\n pluginSkillPaths: string[] = [],\n): string[] {\n const mastraCodeLocalSkillsPath = path.join(projectPath, configDir, 'skills');\n const claudeLocalSkillsPath = path.join(projectPath, '.claude', 'skills');\n const agentSkillsLocalPath = path.join(projectPath, '.agents', 'skills');\n const mastraCodeGlobalSkillsPath = path.join(homeDir, configDir, 'skills');\n const claudeGlobalSkillsPath = path.join(homeDir, '.claude', 'skills');\n const agentSkillsGlobalPath = path.join(homeDir, '.agents', 'skills');\n\n return collectSkillPaths([\n mastraCodeLocalSkillsPath,\n claudeLocalSkillsPath,\n agentSkillsLocalPath,\n mastraCodeGlobalSkillsPath,\n claudeGlobalSkillsPath,\n agentSkillsGlobalPath,\n ...pluginSkillPaths,\n ]);\n}\n\n/**\n * Paths the agent is always allowed to access (in addition to the project root\n * and any per-thread sandboxAllowedPaths). The OS temp directory is included\n * so the agent can use it as a scratchpad without requesting access every time.\n */\nconst DEFAULT_ALLOWED_PATHS: string[] = [os.tmpdir(), '/tmp', getPlansDir()].reduce<string[]>((acc, p) => {\n const resolved = path.resolve(p);\n if (!acc.includes(resolved)) acc.push(resolved);\n return acc;\n}, []);\n\nconst WORKSPACE_ID_PREFIX = 'mastra-code-workspace';\n\n/**\n * Detect the project's package runner from lock files.\n * Used as a fallback packageRunner for LSP when no binary is found locally or on PATH.\n */\nfunction detectPackageRunner(projectPath: string): string | undefined {\n if (existsSync(join(projectPath, 'pnpm-lock.yaml'))) return 'pnpm dlx';\n if (existsSync(join(projectPath, 'bun.lockb')) || existsSync(join(projectPath, 'bun.lock'))) return 'bunx';\n if (existsSync(join(projectPath, 'yarn.lock'))) return 'yarn dlx';\n if (existsSync(join(projectPath, 'package-lock.json'))) return 'npx --yes';\n return 'npx --yes';\n}\n\n/**\n * Build (or reuse) a sandbox-backed Workspace for a GitHub project. The sandbox\n * is reattached by its persisted provider id and a `SandboxFilesystem` is layered\n * over the in-sandbox checkout so file tools and command tools share one VM.\n */\nasync function getSandboxWorkspace({\n githubProjectId,\n sandboxId,\n workdir,\n worktreePath,\n mastra,\n}: {\n githubProjectId: string;\n sandboxId: string;\n workdir: string;\n worktreePath?: string;\n mastra?: Mastra;\n}): Promise<Workspace> {\n // Bind the workspace to the active worktree when one is set, so file tools and\n // command tools operate inside the feature branch's working tree rather than\n // the base checkout. Falls back to the repo root when no worktree is active.\n const boundWorkdir = worktreePath || workdir;\n\n // Include the sandbox id *and* worktree path in the reuse key: a new sandbox\n // (e.g. the previous one expired) or a different worktree must each get a\n // fresh Workspace/ProcessManager instead of reusing one bound to a stale\n // sandbox or the wrong working tree.\n const workspaceId = `${WORKSPACE_ID_PREFIX}-gh-${githubProjectId}-${sandboxId}-${boundWorkdir}`;\n\n // Reuse the existing remote workspace if already registered (preserves the\n // reattached sandbox + ProcessManager state across re-opens).\n try {\n const existing = mastra?.getWorkspaceById(workspaceId) as Workspace | undefined;\n if (existing) {\n existing.setToolsConfig(MASTRACODE_WORKSPACE_TOOLS);\n return existing;\n }\n } catch {\n // Not registered yet.\n }\n\n const sandbox = await reattachProjectSandbox(sandboxId);\n const filesystem = new SandboxFilesystem({ sandbox, workdir: boundWorkdir });\n\n return new Workspace({\n id: workspaceId,\n name: 'Mastra Code Sandbox Workspace',\n filesystem,\n sandbox: sandbox as unknown as ConstructorParameters<typeof Workspace>[0]['sandbox'],\n tools: MASTRACODE_WORKSPACE_TOOLS,\n });\n}\n\nexport async function getDynamicWorkspace({\n requestContext,\n mastra,\n}: {\n requestContext: RequestContext;\n mastra?: Mastra;\n}) {\n const ctx = requestContext.get('controller') as AgentControllerRequestContext<MastraCodeState> | undefined;\n const state = ctx?.getState();\n\n // GitHub/cloud-sandbox-backed project: the repo lives inside a remote sandbox,\n // not on the server host. Reattach to the already-provisioned + materialized\n // sandbox (the SPA called `.../ensure` first, persisting sandboxId/workdir on\n // controller state) and build a sandbox-backed Workspace. LSP/host skill paths\n // are skipped for these workspaces (follow-up).\n if (state?.githubProjectId && state.sandboxId && state.sandboxWorkdir) {\n return getSandboxWorkspace({\n githubProjectId: state.githubProjectId,\n sandboxId: state.sandboxId,\n workdir: state.sandboxWorkdir,\n worktreePath: state.worktreePath,\n mastra,\n });\n }\n\n const rawProjectPath = state?.projectPath;\n\n if (!rawProjectPath) {\n throw new Error('Project path is required');\n }\n\n const projectPath = path.resolve(rawProjectPath);\n const configDir = state?.configDir ?? DEFAULT_CONFIG_DIR;\n const skillPaths = buildSkillPaths(projectPath, configDir, state?.homeDir, state?.pluginSkillPaths ?? []);\n const workspaceId = `${WORKSPACE_ID_PREFIX}-${projectPath}`;\n const sandboxPaths = state?.sandboxAllowedPaths ?? [];\n const allowedPaths = [...skillPaths, ...DEFAULT_ALLOWED_PATHS, ...sandboxPaths.map((p: string) => path.resolve(p))];\n\n // All modes share the same workspace tool configuration. Per-mode tool\n // visibility is enforced at LLM-call time via `availableTools` /\n // `activeTools` on the AgentController, not by mutating workspace capabilities.\n const workspaceTools = MASTRACODE_WORKSPACE_TOOLS;\n\n // Reuse existing workspace if already registered (preserves ProcessManager state)\n let existing: Workspace<LocalFilesystem, LocalSandbox> | undefined;\n try {\n existing = mastra?.getWorkspaceById(workspaceId) as Workspace<LocalFilesystem, LocalSandbox>;\n } catch {\n // Not registered yet\n }\n\n if (existing) {\n existing.filesystem.setAllowedPaths(allowedPaths);\n existing.setToolsConfig(workspaceTools);\n return existing;\n }\n\n const userLsp = loadSettings().lsp ?? {};\n const mcModulePath = join(dirname(fileURLToPath(import.meta.url)), '..');\n const lspConfig: LSPConfig = {\n ...userLsp,\n packageRunner: userLsp.packageRunner || detectPackageRunner(projectPath), // Detected runner is the fallback — user's packageRunner always wins\n searchPaths: [mcModulePath, ...(userLsp.searchPaths ?? [])],\n };\n\n // First call for this project — create the workspace\n return new Workspace({\n id: workspaceId,\n name: 'Mastra Code Workspace',\n filesystem: new LocalFilesystem({\n basePath: projectPath,\n allowedPaths,\n }),\n sandbox: new LocalSandbox({\n workingDirectory: projectPath,\n env: buildSandboxEnv(),\n }),\n tools: workspaceTools,\n ...(skillPaths.length > 0 ? { skills: skillPaths } : {}),\n lsp: lspConfig,\n });\n}\n\n/**\n * Resolver for the agent's `goal.tools` config. Builds the request's workspace\n * (same per-request resolution as the agent's own tools) and returns only the\n * read-only verification subset, remapped to mastracode's tool names (`view`,\n * `search_content`, etc.). Returns `undefined` when no workspace can be resolved\n * (e.g. no project path), keeping the default judge text-only rather than\n * throwing inside the goal step.\n */\nexport async function getGoalJudgeTools({\n requestContext,\n mastra,\n}: {\n requestContext: RequestContext;\n mastra?: Mastra;\n}): Promise<ToolsInput | undefined> {\n let workspace: Workspace;\n try {\n workspace = await getDynamicWorkspace({ requestContext, mastra });\n } catch {\n return undefined;\n }\n\n const allTools = await createWorkspaceTools(workspace, { requestContext, workspace });\n const readonly: ToolsInput = {};\n for (const name of GOAL_JUDGE_READONLY_TOOLS) {\n if (allTools[name]) readonly[name] = allTools[name];\n }\n return Object.keys(readonly).length > 0 ? readonly : undefined;\n}\n"],"mappings":"AAAA,OAAO,MAAM,kBAAkB;AAC/B,OAAO,QAAQ;AACf,OAAO,QAAQ,SAAS,YAAY;AACpC,SAAS,qBAAqB;AAK9B,SAAS,WAAW,iBAAiB,cAAc,4BAA4B;AAE/E,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAE7B,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B,kCAAkC;AAMtE,SAAS,kBAAqC;AAC5C,SAAO;AAAA,IACL,GAAG,QAAQ;AAAA;AAAA,IAEX,aAAa;AAAA,IACb,gBAAgB;AAAA,IAChB,MAAM,QAAQ,IAAI,QAAQ;AAAA,IAC1B,IAAI;AAAA,IACJ,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,EACnB;AACF;AAk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GA,SAAO,IAAI,UAAU;AAAA,IACnB,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,YAAY,IAAI,gBAAgB;AAAA,MAC9B,UAAU;AAAA,MACV;AAAA,IACF,CAAC;AAAA,IACD,SAAS,IAAI,aAAa;AAAA,MACxB,kBAAkB;AAAA,MAClB,KAAK,gBAAgB;AAAA,IACvB,CAAC;AAAA,IACD,OAAO;AAAA,IACP,GAAI,WAAW,SAAS,IAAI,EAAE,QAAQ,WAAW,IAAI,CAAC;AAAA,IACtD,KAAK;AAAA,EACP,CAAC;AACH;AAUA,eAAsB,kBAAkB;AAAA,EACtC;AAAA,EACA;AACF,GAGoC;AAClC,MAAI;AACJ,MAAI;AACF,gBAAY,MAAM,oBAAoB,EAAE,gBAAgB,OAAO,CAAC;AAAA,EAClE,QAAQ;AACN,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,MAAM,qBAAqB,WAAW,EAAE,gBAAgB,UAAU,CAAC;AACpF,QAAM,WAAuB,CAAC;AAC9B,aAAW,QAAQ,2BAA2B;AAC5C,QAAI,SAAS,IAAI,EAAG,UAAS,IAAI,IAAI,SAAS,IAAI;AAAA,EACpD;AACA,SAAO,OAAO,KAAK,QAAQ,EAAE,SAAS,IAAI,WAAW;AACvD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/agents/workspace.ts"],"sourcesContent":["import fs, { existsSync } from 'node:fs';\nimport os from 'node:os';\nimport path, { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ToolsInput } from '@mastra/core/agent';\nimport type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { Workspace, LocalFilesystem, LocalSandbox, createWorkspaceTools } from '@mastra/core/workspace';\nimport type { LSPConfig } from '@mastra/core/workspace';\nimport { DEFAULT_CONFIG_DIR } from '../constants.js';\nimport { loadSettings } from '../onboarding/settings.js';\nimport type { MastraCodeState } from '../schema.js';\nimport { isPathWithinRoot } from '../utils/path-security.js';\nimport { getPlansDir } from '../utils/plans.js';\nimport { SandboxFilesystem } from './sandbox-filesystem.js';\nimport { reattachProjectSandbox } from './sandbox-reattach.js';\nimport { GOAL_JUDGE_READONLY_TOOLS, MASTRACODE_WORKSPACE_TOOLS } from './tool-availability.js';\n\n// =============================================================================\n// Sandbox Environment\n// =============================================================================\n\nfunction buildSandboxEnv(): NodeJS.ProcessEnv {\n return {\n ...process.env,\n // Explicit overrides for non-interactive subprocess execution\n FORCE_COLOR: '1',\n CLICOLOR_FORCE: '1',\n TERM: process.env.TERM || 'xterm-256color',\n CI: 'true',\n NONINTERACTIVE: '1',\n DEBIAN_FRONTEND: 'noninteractive',\n };\n}\n\n// =============================================================================\n// Create Workspace with Skills\n// =============================================================================\n\n// We support multiple skill locations for compatibility:\n// 1. Project-local: <configDir>/skills (project-specific mastracode skills)\n// 2. Project-local: .claude/skills (Claude Code compatible skills)\n// 3. Project-local: .agents/skills (Agent Skills spec compatible)\n// 4. Global: ~/<configDir>/skills (user-wide mastracode skills)\n// 5. Global: ~/.claude/skills (user-wide Claude Code skills)\n// 6. Global: ~/.agents/skills (user-wide Agent Skills spec compatible)\n\n// Mastra's LocalSkillSource.readdir uses Node's Dirent.isDirectory() which\n// returns false for symlinks. Tools like `npx skills add` install skills as\n// symlinks, so we need to resolve them. For each symlinked skill directory,\n// we add the real (resolved) parent path as an additional skill scan path.\nfunction collectSkillPaths(skillsDirs: string[], allowedRoot?: string): string[] {\n const paths: string[] = [];\n const seen = new Set<string>();\n let realAllowedRoot: string | undefined;\n\n if (allowedRoot) {\n try {\n realAllowedRoot = fs.realpathSync(allowedRoot);\n } catch {\n return [];\n }\n }\n\n for (const skillsDir of skillsDirs) {\n const skillsDirExists = fs.existsSync(skillsDir);\n if (skillsDirExists && realAllowedRoot) {\n try {\n const realSkillsDir = fs.realpathSync(skillsDir);\n if (!isPathWithinRoot(realSkillsDir, realAllowedRoot)) continue;\n } catch {\n continue;\n }\n }\n\n const resolved = path.resolve(skillsDir);\n if (!seen.has(resolved)) {\n seen.add(resolved);\n paths.push(skillsDir);\n }\n\n if (!skillsDirExists) continue;\n\n try {\n const entries = fs.readdirSync(skillsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isSymbolicLink()) {\n try {\n const linkPath = path.join(skillsDir, entry.name);\n const realPath = fs.realpathSync(linkPath);\n if (realAllowedRoot && !isPathWithinRoot(realPath, realAllowedRoot)) continue;\n const stat = fs.statSync(realPath);\n if (stat.isDirectory()) {\n const realParent = path.dirname(realPath);\n if (realAllowedRoot && !isPathWithinRoot(realParent, realAllowedRoot)) continue;\n if (!seen.has(realParent)) {\n seen.add(realParent);\n paths.push(realParent);\n }\n }\n } catch {\n continue;\n }\n }\n }\n } catch {\n // Ignore errors during symlink resolution\n }\n }\n\n return paths;\n}\n\n// Build skill paths dynamically based on configDir and projectPath\nexport function buildSkillPaths(\n projectPath: string,\n configDir: string,\n homeDir = os.homedir(),\n pluginSkillPaths: string[] = [],\n): string[] {\n const mastraCodeLocalSkillsPath = path.join(projectPath, configDir, 'skills');\n const claudeLocalSkillsPath = path.join(projectPath, '.claude', 'skills');\n const agentSkillsLocalPath = path.join(projectPath, '.agents', 'skills');\n const mastraCodeGlobalSkillsPath = path.join(homeDir, configDir, 'skills');\n const claudeGlobalSkillsPath = path.join(homeDir, '.claude', 'skills');\n const agentSkillsGlobalPath = path.join(homeDir, '.agents', 'skills');\n\n const paths = [\n ...collectSkillPaths([mastraCodeLocalSkillsPath, claudeLocalSkillsPath, agentSkillsLocalPath], projectPath),\n ...collectSkillPaths([mastraCodeGlobalSkillsPath, claudeGlobalSkillsPath, agentSkillsGlobalPath]),\n ...pluginSkillPaths.flatMap(pluginSkillPath => collectSkillPaths([pluginSkillPath], pluginSkillPath)),\n ];\n\n const seenPaths = new Set<string>();\n return paths.filter(skillPath => {\n let resolved: string;\n try {\n resolved = fs.realpathSync(skillPath);\n } catch {\n resolved = path.resolve(skillPath);\n }\n if (seenPaths.has(resolved)) return false;\n seenPaths.add(resolved);\n return true;\n });\n}\n\n/**\n * Paths the agent is always allowed to access (in addition to the project root\n * and any per-thread sandboxAllowedPaths). The OS temp directory is included\n * so the agent can use it as a scratchpad without requesting access every time.\n */\nconst DEFAULT_ALLOWED_PATHS: string[] = [os.tmpdir(), '/tmp', getPlansDir()].reduce<string[]>((acc, p) => {\n const resolved = path.resolve(p);\n if (!acc.includes(resolved)) acc.push(resolved);\n return acc;\n}, []);\n\nconst WORKSPACE_ID_PREFIX = 'mastra-code-workspace';\n\n/**\n * Detect the project's package runner from lock files.\n * Used as a fallback packageRunner for LSP when no binary is found locally or on PATH.\n */\nfunction detectPackageRunner(projectPath: string): string | undefined {\n if (existsSync(join(projectPath, 'pnpm-lock.yaml'))) return 'pnpm dlx';\n if (existsSync(join(projectPath, 'bun.lockb')) || existsSync(join(projectPath, 'bun.lock'))) return 'bunx';\n if (existsSync(join(projectPath, 'yarn.lock'))) return 'yarn dlx';\n if (existsSync(join(projectPath, 'package-lock.json'))) return 'npx --yes';\n return 'npx --yes';\n}\n\n/**\n * Build (or reuse) a sandbox-backed Workspace for a GitHub project. The sandbox\n * is reattached by its persisted provider id and a `SandboxFilesystem` is layered\n * over the in-sandbox checkout so file tools and command tools share one VM.\n */\nasync function getSandboxWorkspace({\n githubProjectId,\n sandboxId,\n workdir,\n worktreePath,\n mastra,\n}: {\n githubProjectId: string;\n sandboxId: string;\n workdir: string;\n worktreePath?: string;\n mastra?: Mastra;\n}): Promise<Workspace> {\n // Bind the workspace to the active worktree when one is set, so file tools and\n // command tools operate inside the feature branch's working tree rather than\n // the base checkout. Falls back to the repo root when no worktree is active.\n const boundWorkdir = worktreePath || workdir;\n\n // Include the sandbox id *and* worktree path in the reuse key: a new sandbox\n // (e.g. the previous one expired) or a different worktree must each get a\n // fresh Workspace/ProcessManager instead of reusing one bound to a stale\n // sandbox or the wrong working tree.\n const workspaceId = `${WORKSPACE_ID_PREFIX}-gh-${githubProjectId}-${sandboxId}-${boundWorkdir}`;\n\n // Reuse the existing remote workspace if already registered (preserves the\n // reattached sandbox + ProcessManager state across re-opens).\n try {\n const existing = mastra?.getWorkspaceById(workspaceId) as Workspace | undefined;\n if (existing) {\n existing.setToolsConfig(MASTRACODE_WORKSPACE_TOOLS);\n return existing;\n }\n } catch {\n // Not registered yet.\n }\n\n const sandbox = await reattachProjectSandbox(sandboxId);\n const filesystem = new SandboxFilesystem({ sandbox, workdir: boundWorkdir });\n\n return new Workspace({\n id: workspaceId,\n name: 'Mastra Code Sandbox Workspace',\n filesystem,\n sandbox: sandbox as unknown as ConstructorParameters<typeof Workspace>[0]['sandbox'],\n tools: MASTRACODE_WORKSPACE_TOOLS,\n });\n}\n\nexport async function getDynamicWorkspace({\n requestContext,\n mastra,\n}: {\n requestContext: RequestContext;\n mastra?: Mastra;\n}) {\n const ctx = requestContext.get('controller') as AgentControllerRequestContext<MastraCodeState> | undefined;\n const state = ctx?.getState();\n\n // GitHub/cloud-sandbox-backed project: the repo lives inside a remote sandbox,\n // not on the server host. Reattach to the already-provisioned + materialized\n // sandbox (the SPA called `.../ensure` first, persisting sandboxId/workdir on\n // controller state) and build a sandbox-backed Workspace. LSP/host skill paths\n // are skipped for these workspaces (follow-up).\n if (state?.githubProjectId && state.sandboxId && state.sandboxWorkdir) {\n return getSandboxWorkspace({\n githubProjectId: state.githubProjectId,\n sandboxId: state.sandboxId,\n workdir: state.sandboxWorkdir,\n worktreePath: state.worktreePath,\n mastra,\n });\n }\n\n const rawProjectPath = state?.projectPath;\n\n if (!rawProjectPath) {\n throw new Error('Project path is required');\n }\n\n const projectPath = path.resolve(rawProjectPath);\n const configDir = state?.configDir ?? DEFAULT_CONFIG_DIR;\n const skillPaths = buildSkillPaths(projectPath, configDir, state?.homeDir, state?.pluginSkillPaths ?? []);\n const workspaceId = `${WORKSPACE_ID_PREFIX}-${projectPath}`;\n const sandboxPaths = state?.sandboxAllowedPaths ?? [];\n const allowedPaths = [...skillPaths, ...DEFAULT_ALLOWED_PATHS, ...sandboxPaths.map((p: string) => path.resolve(p))];\n\n // All modes share the same workspace tool configuration. Per-mode tool\n // visibility is enforced at LLM-call time via `availableTools` /\n // `activeTools` on the AgentController, not by mutating workspace capabilities.\n const workspaceTools = MASTRACODE_WORKSPACE_TOOLS;\n\n // Reuse existing workspace if already registered (preserves ProcessManager state)\n let existing: Workspace<LocalFilesystem, LocalSandbox> | undefined;\n try {\n existing = mastra?.getWorkspaceById(workspaceId) as Workspace<LocalFilesystem, LocalSandbox>;\n } catch {\n // Not registered yet\n }\n\n if (existing) {\n existing.filesystem.setAllowedPaths(allowedPaths);\n existing.setToolsConfig(workspaceTools);\n return existing;\n }\n\n const userLsp = loadSettings().lsp ?? {};\n const mcModulePath = join(dirname(fileURLToPath(import.meta.url)), '..');\n const lspConfig: LSPConfig = {\n ...userLsp,\n packageRunner: userLsp.packageRunner || detectPackageRunner(projectPath), // Detected runner is the fallback — user's packageRunner always wins\n searchPaths: [mcModulePath, ...(userLsp.searchPaths ?? [])],\n };\n\n // First call for this project — create the workspace\n return new Workspace({\n id: workspaceId,\n name: 'Mastra Code Workspace',\n filesystem: new LocalFilesystem({\n basePath: projectPath,\n allowedPaths,\n }),\n sandbox: new LocalSandbox({\n workingDirectory: projectPath,\n env: buildSandboxEnv(),\n }),\n tools: workspaceTools,\n ...(skillPaths.length > 0 ? { skills: skillPaths } : {}),\n lsp: lspConfig,\n });\n}\n\n/**\n * Resolver for the agent's `goal.tools` config. Builds the request's workspace\n * (same per-request resolution as the agent's own tools) and returns only the\n * read-only verification subset, remapped to mastracode's tool names (`view`,\n * `search_content`, etc.). Returns `undefined` when no workspace can be resolved\n * (e.g. no project path), keeping the default judge text-only rather than\n * throwing inside the goal step.\n */\nexport async function getGoalJudgeTools({\n requestContext,\n mastra,\n}: {\n requestContext: RequestContext;\n mastra?: Mastra;\n}): Promise<ToolsInput | undefined> {\n let workspace: Workspace;\n try {\n workspace = await getDynamicWorkspace({ requestContext, mastra });\n } catch {\n return undefined;\n }\n\n const allTools = await createWorkspaceTools(workspace, { requestContext, workspace });\n const readonly: ToolsInput = {};\n for (const name of GOAL_JUDGE_READONLY_TOOLS) {\n if (allTools[name]) readonly[name] = allTools[name];\n }\n return Object.keys(readonly).length > 0 ? readonly : undefined;\n}\n"],"mappings":"AAAA,OAAO,MAAM,kBAAkB;AAC/B,OAAO,QAAQ;AACf,OAAO,QAAQ,SAAS,YAAY;AACpC,SAAS,qBAAqB;AAK9B,SAAS,WAAW,iBAAiB,cAAc,4BAA4B;AAE/E,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAE7B,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B,kCAAkC;AAMtE,SAAS,kBAAqC;AAC5C,SAAO;AAAA,IACL,GAAG,QAAQ;AAAA;AAAA,IAEX,aAAa;AAAA,IACb,gBAAgB;AAAA,IAChB,MAAM,QAAQ,IAAI,QAAQ;AAAA,IAC1B,IAAI;AAAA,IACJ,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,EACnB;AACF;AAkBA,SAAS,kBAAkB,YAAsB,aAAgC;AAC/E,QAAM,QAAkB,CAAC;AACzB,QAAM,OAAO,oBAAI,IAAY;AAC7B,MAAI;AAEJ,MAAI,aAAa;AACf,QAAI;AACF,wBAAkB,GAAG,aAAa,WAAW;AAAA,IAC/C,QAAQ;AACN,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AAEA,aAAW,aAAa,YAAY;AAClC,UAAM,kBAAkB,GAAG,WAAW,SAAS;AAC/C,QAAI,mBAAmB,iBAAiB;AACtC,UAAI;AACF,cAAM,gBAAgB,GAAG,aAAa,SAAS;AAC/C,YAAI,CAAC,iBAAiB,eAAe,eAAe,EAAG;AAAA,MACzD,QAAQ;AACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,WAAW,KAAK,QAAQ,SAAS;AACvC,QAAI,CAAC,K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/core/storage';
|
|
|
8
8
|
import { GithubSignals } from '@mastra/github-signals';
|
|
9
9
|
import { Observability } from '@mastra/observability';
|
|
10
10
|
import { resolveModel } from './agents/model.js';
|
|
11
|
+
import type { ToolLike } from './agents/tools.js';
|
|
11
12
|
import { AuthStorage } from './auth/storage.js';
|
|
12
13
|
import { HookManager } from './hooks/index.js';
|
|
13
14
|
import type { McpServerConfig } from './mcp/index.js';
|
|
14
15
|
import { PluginManager } from './plugins/manager.js';
|
|
15
16
|
import type { MastraCodeState } from './schema.js';
|
|
16
17
|
import type { StorageConfig } from './utils/project.js';
|
|
18
|
+
import type { StorageMaintenance } from './utils/storage-maintenance.js';
|
|
17
19
|
export interface MastraCodeConfig {
|
|
18
20
|
/** Working directory for project detection. Default: process.cwd() */
|
|
19
21
|
cwd?: string;
|
|
@@ -23,16 +25,10 @@ export interface MastraCodeConfig {
|
|
|
23
25
|
modes?: AgentControllerMode[];
|
|
24
26
|
/** Override or extend subagent definitions. Default: explore/plan/execute */
|
|
25
27
|
subagents?: AgentControllerSubagent[];
|
|
26
|
-
/** Extra tools merged into the dynamic tool set. Can be a static record or a function that receives requestContext. */
|
|
27
|
-
extraTools?: Record<string, {
|
|
28
|
-
execute?: (input: unknown, context?: unknown) => Promise<unknown> | unknown;
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
}> | ((ctx: {
|
|
28
|
+
/** Extra tools merged into the dynamic tool set. Can be a static record or a (sync or async) function that receives requestContext. */
|
|
29
|
+
extraTools?: Record<string, ToolLike> | ((ctx: {
|
|
31
30
|
requestContext: RequestContext;
|
|
32
|
-
}) => Record<string,
|
|
33
|
-
execute?: (input: unknown, context?: unknown) => Promise<unknown> | unknown;
|
|
34
|
-
[key: string]: unknown;
|
|
35
|
-
}>);
|
|
31
|
+
}) => Record<string, ToolLike> | Promise<Record<string, ToolLike>>);
|
|
36
32
|
/** Tools removed from the dynamic tool set before exposure to the model */
|
|
37
33
|
disabledTools?: string[];
|
|
38
34
|
/** Custom storage config instead of auto-detected default */
|
|
@@ -91,6 +87,7 @@ export declare function createAuthStorage(): AuthStorage;
|
|
|
91
87
|
export declare function createMastraCodeAgentController(config?: MastraCodeConfig): Promise<{
|
|
92
88
|
controller: AgentController<MastraCodeState>;
|
|
93
89
|
storage: MastraCompositeStore;
|
|
90
|
+
storageMaintenance: StorageMaintenance;
|
|
94
91
|
observability: Observability;
|
|
95
92
|
memory: import("@mastra/core/types").DynamicArgument<import("@mastra/core/memory").MastraMemory> | (({ requestContext }: {
|
|
96
93
|
requestContext: RequestContext;
|
|
@@ -137,6 +134,7 @@ export declare function bootLocalAgentController(config?: MastraCodeConfig): Pro
|
|
|
137
134
|
session: Session<MastraCodeState>;
|
|
138
135
|
controller: AgentController<MastraCodeState>;
|
|
139
136
|
storage: MastraCompositeStore;
|
|
137
|
+
storageMaintenance: StorageMaintenance;
|
|
140
138
|
observability: Observability;
|
|
141
139
|
memory: import("@mastra/core/types").DynamicArgument<import("@mastra/core/memory").MastraMemory> | (({ requestContext }: {
|
|
142
140
|
requestContext: RequestContext;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EAErB,mBAAmB,EACnB,uBAAuB,EAEvB,OAAO,EACR,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAQ7C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAmB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAI7E,OAAO,EAAE,aAA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EAAE,WAAW,CAAC,qBAAqB,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B,CAAC,CAuBD;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,iCAA2B,CAAC;AAEzD;;;;GAIG;AACH,OAAO,EACL,KAAK,EACL,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,aAAa,EACb,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,KAAK,EACL,gBAAgB,EAChB,cAAc,GACf,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { InMemoryHarness, MastraCompositeStore } from "@mastra/core/storage";
|
|
|
18
18
|
import { DEFAULT_GOAL_JUDGE_PROMPT } from "@mastra/core/tools";
|
|
19
19
|
import { DuckDBStore } from "@mastra/duckdb";
|
|
20
20
|
import { GithubSignals } from "@mastra/github-signals";
|
|
21
|
+
import { LibSQLVector } from "@mastra/libsql";
|
|
21
22
|
import {
|
|
22
23
|
Observability,
|
|
23
24
|
MastraStorageExporter,
|
|
@@ -42,7 +43,7 @@ import { createMcpManager } from "./mcp/index.js";
|
|
|
42
43
|
import { getAvailableModePacks, getAvailableOmPacks } from "./onboarding/packs.js";
|
|
43
44
|
import {
|
|
44
45
|
loadSettings,
|
|
45
|
-
|
|
46
|
+
MASTRA_GATEWAY_PROVIDER,
|
|
46
47
|
OBSERVABILITY_AUTH_PREFIX,
|
|
47
48
|
resolveModelDefaults,
|
|
48
49
|
resolveOmRoleModel,
|
|
@@ -66,6 +67,7 @@ import {
|
|
|
66
67
|
} from "./utils/project.js";
|
|
67
68
|
import { createSignalsPubSub } from "./utils/signals-pubsub.js";
|
|
68
69
|
import { createStorage, createVectorStore } from "./utils/storage-factory.js";
|
|
70
|
+
import { createStorageMaintenance, DEFAULT_RETENTION, resolveLocalDbFiles } from "./utils/storage-maintenance.js";
|
|
69
71
|
import { acquireThreadLock, releaseThreadLock } from "./utils/thread-lock.js";
|
|
70
72
|
const CODE_AGENT_ID = "code-agent";
|
|
71
73
|
const MASTRACODE_ECONNRESET_MAX_RETRIES = 2;
|
|
@@ -139,7 +141,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
139
141
|
}
|
|
140
142
|
const authStorage = createAuthStorage();
|
|
141
143
|
const globalSettings = loadSettings(config?.settingsPath);
|
|
142
|
-
const storedGatewayKey = authStorage.getStoredApiKey(
|
|
144
|
+
const storedGatewayKey = authStorage.getStoredApiKey(MASTRA_GATEWAY_PROVIDER);
|
|
143
145
|
const storedGatewayUrl = globalSettings.memoryGateway?.baseUrl;
|
|
144
146
|
if (storedGatewayKey) {
|
|
145
147
|
process.env["MASTRA_GATEWAY_API_KEY"] ??= storedGatewayKey;
|
|
@@ -154,11 +156,11 @@ async function createMastraCodeAgentController(config) {
|
|
|
154
156
|
const envVars = cfg?.apiKeyEnvVar;
|
|
155
157
|
providerEnvVars[provider] = Array.isArray(envVars) ? envVars[0] : envVars;
|
|
156
158
|
}
|
|
157
|
-
providerEnvVars[
|
|
159
|
+
providerEnvVars[MASTRA_GATEWAY_PROVIDER] ??= "MASTRA_GATEWAY_API_KEY";
|
|
158
160
|
authStorage.loadStoredApiKeysIntoEnv(providerEnvVars);
|
|
159
161
|
} catch {
|
|
160
162
|
authStorage.loadStoredApiKeysIntoEnv({
|
|
161
|
-
[
|
|
163
|
+
[MASTRA_GATEWAY_PROVIDER]: "MASTRA_GATEWAY_API_KEY",
|
|
162
164
|
anthropic: "ANTHROPIC_API_KEY",
|
|
163
165
|
openai: "OPENAI_API_KEY",
|
|
164
166
|
google: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
@@ -218,7 +220,9 @@ async function createMastraCodeAgentController(config) {
|
|
|
218
220
|
id: "mastra-code-storage",
|
|
219
221
|
default: storageResult.storage,
|
|
220
222
|
domains: {
|
|
221
|
-
|
|
223
|
+
// When local tracing is off, disable the observability domain entirely so
|
|
224
|
+
// trace/score/feedback writes never fall through to the default libsql store.
|
|
225
|
+
observability: observabilityDomain ?? false,
|
|
222
226
|
harness: harnessStorage
|
|
223
227
|
}
|
|
224
228
|
});
|
|
@@ -277,6 +281,13 @@ async function createMastraCodeAgentController(config) {
|
|
|
277
281
|
}
|
|
278
282
|
});
|
|
279
283
|
const vectorStore = await createVectorStore(storageConfig, storageResult.backend);
|
|
284
|
+
const storageMaintenance = createStorageMaintenance({
|
|
285
|
+
storage: storageResult.storage,
|
|
286
|
+
backend: storageResult.backend,
|
|
287
|
+
retention: DEFAULT_RETENTION,
|
|
288
|
+
localDbFiles: resolveLocalDbFiles(storageConfig, storageResult.backend),
|
|
289
|
+
closeVector: vectorStore instanceof LibSQLVector ? () => vectorStore.close() : void 0
|
|
290
|
+
});
|
|
280
291
|
const memory = config?.memory === false ? void 0 : config?.memory ?? getDynamicMemory(storage, vectorStore);
|
|
281
292
|
const mcpManager = config?.disableMcp ? void 0 : createMcpManager(project.rootPath, configDir, config?.mcpServers);
|
|
282
293
|
const hookManager = config?.disableHooks ? void 0 : new HookManager(project.rootPath, "session-init", configDir, homeDir);
|
|
@@ -568,6 +579,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
568
579
|
return {
|
|
569
580
|
controller,
|
|
570
581
|
storage,
|
|
582
|
+
storageMaintenance,
|
|
571
583
|
observability,
|
|
572
584
|
memory,
|
|
573
585
|
mcpManager,
|