mastracode 0.4.0 → 0.5.0
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 +328 -0
- package/LICENSE.md +15 -0
- package/README.md +68 -29
- package/dist/agents/memory.d.ts.map +1 -1
- package/dist/agents/model.d.ts +17 -6
- package/dist/agents/model.d.ts.map +1 -1
- package/dist/agents/prompts/index.d.ts.map +1 -1
- package/dist/agents/prompts/tool-guidance.d.ts +2 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -1
- package/dist/agents/subagents/audit-tests.d.ts +0 -7
- package/dist/agents/subagents/audit-tests.d.ts.map +1 -1
- package/dist/agents/subagents/execute.d.ts +0 -7
- package/dist/agents/subagents/execute.d.ts.map +1 -1
- package/dist/agents/subagents/explore.d.ts +0 -7
- package/dist/agents/subagents/explore.d.ts.map +1 -1
- package/dist/agents/subagents/index.d.ts.map +1 -1
- package/dist/agents/subagents/plan.d.ts +0 -7
- package/dist/agents/subagents/plan.d.ts.map +1 -1
- package/dist/agents/tools.d.ts +3 -1
- package/dist/agents/tools.d.ts.map +1 -1
- package/dist/agents/workspace.d.ts +4 -1
- package/dist/agents/workspace.d.ts.map +1 -1
- package/dist/{chunk-K4WJUBEC.cjs → chunk-AJEYT7X3.cjs} +763 -429
- package/dist/chunk-AJEYT7X3.cjs.map +1 -0
- package/dist/{chunk-U5A7TFNT.js → chunk-CC2724NI.js} +46 -10
- package/dist/chunk-CC2724NI.js.map +1 -0
- package/dist/{chunk-REVOTI2T.js → chunk-JI4M5525.js} +740 -412
- package/dist/chunk-JI4M5525.js.map +1 -0
- package/dist/{chunk-Z4QRXVST.cjs → chunk-MBPGUMYQ.cjs} +325 -251
- package/dist/chunk-MBPGUMYQ.cjs.map +1 -0
- package/dist/{chunk-MT3YCFCC.cjs → chunk-OEDRHUU5.cjs} +47 -9
- package/dist/chunk-OEDRHUU5.cjs.map +1 -0
- package/dist/{chunk-M5LKPQB4.js → chunk-WKPHD54B.js} +283 -209
- package/dist/chunk-WKPHD54B.js.map +1 -0
- package/dist/{chunk-C4X3C2DL.cjs → chunk-XVYUS2EA.cjs} +2213 -1035
- package/dist/chunk-XVYUS2EA.cjs.map +1 -0
- package/dist/{chunk-X3BGE7CL.js → chunk-YQNZ7DHQ.js} +1788 -613
- package/dist/chunk-YQNZ7DHQ.js.map +1 -0
- package/dist/cli.cjs +79 -31
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +71 -23
- package/dist/cli.js.map +1 -1
- package/dist/clipboard/index.d.ts +5 -0
- package/dist/clipboard/index.d.ts.map +1 -1
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.d.ts.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp/config.d.ts +8 -0
- package/dist/mcp/config.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/manager.d.ts +4 -2
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/types.d.ts +30 -3
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/onboarding/onboarding-inline.d.ts +2 -0
- package/dist/onboarding/onboarding-inline.d.ts.map +1 -1
- package/dist/onboarding/packs.d.ts +1 -0
- package/dist/onboarding/packs.d.ts.map +1 -1
- package/dist/onboarding/settings.d.ts +37 -2
- package/dist/onboarding/settings.d.ts.map +1 -1
- package/dist/permissions-S3LGXIDB.js +3 -0
- package/dist/{permissions-CVXKYIWR.js.map → permissions-S3LGXIDB.js.map} +1 -1
- package/dist/permissions-VGABAVGD.cjs +40 -0
- package/dist/{permissions-2HIUSRQN.cjs.map → permissions-VGABAVGD.cjs.map} +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/providers/claude-max.d.ts +13 -0
- package/dist/providers/claude-max.d.ts.map +1 -1
- package/dist/providers/openai-codex.d.ts +1 -0
- package/dist/providers/openai-codex.d.ts.map +1 -1
- package/dist/tool-names.d.ts +68 -0
- package/dist/tool-names.d.ts.map +1 -0
- package/dist/tools/ast-smart-edit.d.ts +77 -5
- package/dist/tools/ast-smart-edit.d.ts.map +1 -1
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/string-replace-lsp.d.ts +15 -0
- package/dist/tools/string-replace-lsp.d.ts.map +1 -1
- package/dist/tools/subagent.d.ts.map +1 -1
- package/dist/tools/utils.d.ts +4 -2
- package/dist/tools/utils.d.ts.map +1 -1
- package/dist/tui/command-dispatch.d.ts.map +1 -1
- package/dist/tui/commands/clone.d.ts +29 -0
- package/dist/tui/commands/clone.d.ts.map +1 -0
- package/dist/tui/commands/custom-providers.d.ts +8 -0
- package/dist/tui/commands/custom-providers.d.ts.map +1 -0
- package/dist/tui/commands/index.d.ts +3 -1
- package/dist/tui/commands/index.d.ts.map +1 -1
- package/dist/tui/commands/mcp.d.ts.map +1 -1
- package/dist/tui/commands/models-pack.d.ts +4 -0
- package/dist/tui/commands/models-pack.d.ts.map +1 -1
- package/dist/tui/commands/om.d.ts.map +1 -1
- package/dist/tui/commands/report-issue.d.ts +3 -0
- package/dist/tui/commands/report-issue.d.ts.map +1 -0
- package/dist/tui/commands/resource.d.ts.map +1 -1
- package/dist/tui/commands/settings.d.ts.map +1 -1
- package/dist/tui/commands/threads.d.ts +1 -0
- package/dist/tui/commands/threads.d.ts.map +1 -1
- package/dist/tui/components/ask-question-inline.d.ts +3 -0
- package/dist/tui/components/ask-question-inline.d.ts.map +1 -1
- package/dist/tui/components/custom-editor.d.ts +1 -1
- package/dist/tui/components/custom-editor.d.ts.map +1 -1
- package/dist/tui/components/help-overlay.d.ts.map +1 -1
- package/dist/tui/components/plan-approval-inline.d.ts.map +1 -1
- package/dist/tui/components/settings.d.ts +2 -0
- package/dist/tui/components/settings.d.ts.map +1 -1
- package/dist/tui/components/subagent-execution.d.ts +6 -1
- package/dist/tui/components/subagent-execution.d.ts.map +1 -1
- package/dist/tui/components/thread-selector.d.ts +6 -0
- package/dist/tui/components/thread-selector.d.ts.map +1 -1
- package/dist/tui/components/tool-execution-enhanced.d.ts +1 -0
- package/dist/tui/components/tool-execution-enhanced.d.ts.map +1 -1
- package/dist/tui/components/tool-validation-error.d.ts.map +1 -1
- package/dist/tui/handlers/message.d.ts.map +1 -1
- package/dist/tui/handlers/prompts.d.ts +6 -0
- package/dist/tui/handlers/prompts.d.ts.map +1 -1
- package/dist/tui/handlers/subagent.d.ts.map +1 -1
- package/dist/tui/mastra-tui.d.ts +14 -5
- package/dist/tui/mastra-tui.d.ts.map +1 -1
- package/dist/tui/render-messages.d.ts.map +1 -1
- package/dist/tui/setup.d.ts.map +1 -1
- package/dist/tui/state.d.ts +4 -5
- package/dist/tui/state.d.ts.map +1 -1
- package/dist/tui.cjs +19 -19
- package/dist/tui.js +2 -2
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.d.ts.map +1 -0
- package/dist/utils/plans.d.ts +7 -0
- package/dist/utils/plans.d.ts.map +1 -0
- package/dist/utils/update-check.d.ts +40 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/package.json +8 -8
- package/dist/chunk-C4X3C2DL.cjs.map +0 -1
- package/dist/chunk-K4WJUBEC.cjs.map +0 -1
- package/dist/chunk-M5LKPQB4.js.map +0 -1
- package/dist/chunk-MT3YCFCC.cjs.map +0 -1
- package/dist/chunk-REVOTI2T.js.map +0 -1
- package/dist/chunk-U5A7TFNT.js.map +0 -1
- package/dist/chunk-X3BGE7CL.js.map +0 -1
- package/dist/chunk-Z4QRXVST.cjs.map +0 -1
- package/dist/docs/SKILL.md +0 -30
- package/dist/docs/assets/SOURCE_MAP.json +0 -11
- package/dist/docs/references/docs-mastra-code-configuration.md +0 -299
- package/dist/docs/references/docs-mastra-code-customization.md +0 -228
- package/dist/docs/references/docs-mastra-code-modes.md +0 -104
- package/dist/docs/references/docs-mastra-code-overview.md +0 -135
- package/dist/docs/references/docs-mastra-code-tools.md +0 -229
- package/dist/docs/references/reference-mastra-code-createMastraCode.md +0 -108
- package/dist/permissions-2HIUSRQN.cjs +0 -40
- package/dist/permissions-CVXKYIWR.js +0 -3
- package/dist/tui/commands/models.d.ts +0 -3
- package/dist/tui/commands/models.d.ts.map +0 -1
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkAJEYT7X3_cjs = require('./chunk-AJEYT7X3.cjs');
|
|
4
4
|
var chunkS5ZLN7DR_cjs = require('./chunk-S5ZLN7DR.cjs');
|
|
5
|
-
var
|
|
6
|
-
var core = require('@mastra/core');
|
|
5
|
+
var chunkOEDRHUU5_cjs = require('./chunk-OEDRHUU5.cjs');
|
|
7
6
|
var agent = require('@mastra/core/agent');
|
|
8
7
|
var harness = require('@mastra/core/harness');
|
|
9
|
-
var
|
|
10
|
-
var
|
|
8
|
+
var llm = require('@mastra/core/llm');
|
|
9
|
+
var fs3 = require('fs');
|
|
11
10
|
var os = require('os');
|
|
12
|
-
var
|
|
11
|
+
var path3 = require('path');
|
|
13
12
|
var memory = require('@mastra/memory');
|
|
14
13
|
var anthropic = require('@ai-sdk/anthropic');
|
|
15
|
-
var
|
|
14
|
+
var openai = require('@ai-sdk/openai');
|
|
16
15
|
var child_process = require('child_process');
|
|
17
16
|
var mcp = require('@mastra/mcp');
|
|
18
17
|
var zod = require('zod');
|
|
19
|
-
var llm = require('@mastra/core/llm');
|
|
20
18
|
var libsql = require('@mastra/libsql');
|
|
21
19
|
var pg = require('@mastra/pg');
|
|
22
20
|
|
|
@@ -38,9 +36,9 @@ function _interopNamespace(e) {
|
|
|
38
36
|
return Object.freeze(n);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
var
|
|
39
|
+
var fs3__namespace = /*#__PURE__*/_interopNamespace(fs3);
|
|
42
40
|
var os__namespace = /*#__PURE__*/_interopNamespace(os);
|
|
43
|
-
var
|
|
41
|
+
var path3__namespace = /*#__PURE__*/_interopNamespace(path3);
|
|
44
42
|
|
|
45
43
|
// src/agents/prompts/base.ts
|
|
46
44
|
function buildBasePrompt(ctx) {
|
|
@@ -291,8 +289,8 @@ var PROJECT_LOCATIONS = [
|
|
|
291
289
|
var GLOBAL_LOCATIONS = [".claude", ".mastracode", ".config/claude", ".config/mastracode"];
|
|
292
290
|
function findInstructionFile(basePath) {
|
|
293
291
|
for (const filename of INSTRUCTION_FILES) {
|
|
294
|
-
const fullPath =
|
|
295
|
-
if (
|
|
292
|
+
const fullPath = path3.join(basePath, filename);
|
|
293
|
+
if (fs3.existsSync(fullPath)) {
|
|
296
294
|
return fullPath;
|
|
297
295
|
}
|
|
298
296
|
}
|
|
@@ -302,11 +300,11 @@ function loadAgentInstructions(projectPath) {
|
|
|
302
300
|
const sources = [];
|
|
303
301
|
const home = os.homedir();
|
|
304
302
|
for (const location of GLOBAL_LOCATIONS) {
|
|
305
|
-
const basePath =
|
|
303
|
+
const basePath = path3.join(home, location);
|
|
306
304
|
const filePath = findInstructionFile(basePath);
|
|
307
305
|
if (filePath) {
|
|
308
306
|
try {
|
|
309
|
-
const content =
|
|
307
|
+
const content = fs3.readFileSync(filePath, "utf-8").trim();
|
|
310
308
|
if (content) {
|
|
311
309
|
sources.push({ path: filePath, content, scope: "global" });
|
|
312
310
|
break;
|
|
@@ -316,11 +314,11 @@ function loadAgentInstructions(projectPath) {
|
|
|
316
314
|
}
|
|
317
315
|
}
|
|
318
316
|
for (const location of PROJECT_LOCATIONS) {
|
|
319
|
-
const basePath = location ?
|
|
317
|
+
const basePath = location ? path3.join(projectPath, location) : projectPath;
|
|
320
318
|
const filePath = findInstructionFile(basePath);
|
|
321
319
|
if (filePath) {
|
|
322
320
|
try {
|
|
323
|
-
const content =
|
|
321
|
+
const content = fs3.readFileSync(filePath, "utf-8").trim();
|
|
324
322
|
if (content) {
|
|
325
323
|
sources.push({ path: filePath, content, scope: "project" });
|
|
326
324
|
break;
|
|
@@ -347,80 +345,117 @@ ${sections.join("\n\n")}
|
|
|
347
345
|
|
|
348
346
|
// src/agents/prompts/tool-guidance.ts
|
|
349
347
|
function buildToolGuidance(modeId, options = {}) {
|
|
348
|
+
const denied = options.deniedTools ?? /* @__PURE__ */ new Set();
|
|
350
349
|
const sections = [];
|
|
351
350
|
sections.push(`# Tool Usage Rules
|
|
352
351
|
|
|
353
352
|
IMPORTANT: You can ONLY call tools by their exact registered names listed below. Shell commands like \`git\`, \`npm\`, \`ls\`, etc. are NOT tools \u2014 they must be run via the \`execute_command\` tool.
|
|
354
353
|
|
|
355
354
|
You have access to the following tools. Use the RIGHT tool for the job:`);
|
|
356
|
-
|
|
357
|
-
|
|
355
|
+
const readTools = [];
|
|
356
|
+
if (!denied.has(chunkOEDRHUU5_cjs.MC_TOOLS.VIEW)) {
|
|
357
|
+
readTools.push(`
|
|
358
|
+
**${chunkOEDRHUU5_cjs.MC_TOOLS.VIEW}** \u2014 Read file contents
|
|
358
359
|
- Use this to read files before editing them. NEVER propose changes to code you haven't read.
|
|
359
|
-
- Use \`
|
|
360
|
-
-
|
|
361
|
-
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
-
|
|
367
|
-
-
|
|
368
|
-
- Example: Find
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
-
|
|
376
|
-
|
|
377
|
-
|
|
360
|
+
- Use \`offset\` (1-indexed start line) and \`limit\` (number of lines) for large files.
|
|
361
|
+
- Example: Read lines 50-100: \`{ path: "src/big-file.ts", offset: 50, limit: 51 }\`
|
|
362
|
+
- To list directories, use \`${chunkOEDRHUU5_cjs.MC_TOOLS.FIND_FILES}\` instead.`);
|
|
363
|
+
}
|
|
364
|
+
if (!denied.has(chunkOEDRHUU5_cjs.MC_TOOLS.SEARCH_CONTENT)) {
|
|
365
|
+
readTools.push(`
|
|
366
|
+
**${chunkOEDRHUU5_cjs.MC_TOOLS.SEARCH_CONTENT}** \u2014 Search file contents using regex
|
|
367
|
+
- Preferred for content search (finding functions, variables, error messages, imports, etc.)
|
|
368
|
+
- Use \`path\` to filter by directory or glob pattern. Supports \`contextLines\`, \`caseSensitive\`, and \`maxCount\`.
|
|
369
|
+
- Example: Find a function: \`{ pattern: "function handleSubmit", path: "**/*.ts" }\`
|
|
370
|
+
- Example: Find imports: \`{ pattern: "from ['\\"\\]express['\\"\\]", path: "**/*.ts" }\`
|
|
371
|
+
- Respects .gitignore by default.`);
|
|
372
|
+
}
|
|
373
|
+
if (!denied.has(chunkOEDRHUU5_cjs.MC_TOOLS.FIND_FILES)) {
|
|
374
|
+
readTools.push(`
|
|
375
|
+
**${chunkOEDRHUU5_cjs.MC_TOOLS.FIND_FILES}** \u2014 List files and directories as a tree
|
|
376
|
+
- Preferred for exploring project structure and finding files by pattern.
|
|
377
|
+
- Returns tree-style output. Respects .gitignore by default.
|
|
378
|
+
- Example: List project root: \`{ path: "./" }\`
|
|
379
|
+
- Example: Find test files: \`{ path: "./src", pattern: "**/*.test.ts" }\`
|
|
380
|
+
- Example: Find config files: \`{ pattern: "*.config.{js,ts,json}" }\``);
|
|
381
|
+
}
|
|
382
|
+
if (!denied.has(chunkOEDRHUU5_cjs.MC_TOOLS.EXECUTE_COMMAND)) {
|
|
383
|
+
readTools.push(`
|
|
384
|
+
**${chunkOEDRHUU5_cjs.MC_TOOLS.EXECUTE_COMMAND}** \u2014 Run shell commands
|
|
378
385
|
- Use for: git, npm/pnpm, docker, build tools, test runners, and other terminal operations.
|
|
379
|
-
-
|
|
380
|
-
- Commands have a 30-second default timeout. Use
|
|
381
|
-
-
|
|
386
|
+
- Prefer dedicated tools for: file reading (${chunkOEDRHUU5_cjs.MC_TOOLS.VIEW}), file search (${chunkOEDRHUU5_cjs.MC_TOOLS.SEARCH_CONTENT}/${chunkOEDRHUU5_cjs.MC_TOOLS.FIND_FILES}), file editing (${chunkOEDRHUU5_cjs.MC_TOOLS.STRING_REPLACE_LSP}/${chunkOEDRHUU5_cjs.MC_TOOLS.WRITE_FILE}).
|
|
387
|
+
- Commands have a 30-second default timeout. Use \`timeout\` for longer commands, \`cwd\` for working directory.
|
|
388
|
+
- Use the \`tail\` parameter or pipe to \`| tail -N\` to limit output \u2014 the full output streams to the user, only the tail is returned to you. If you're building any kind of package you should be tailing.
|
|
382
389
|
- Good: Run independent commands in parallel when possible.
|
|
383
|
-
- Bad: Running \`cat file.txt\` \u2014 use the
|
|
390
|
+
- Bad: Running \`cat file.txt\` \u2014 use the ${chunkOEDRHUU5_cjs.MC_TOOLS.VIEW} tool instead.`);
|
|
391
|
+
}
|
|
392
|
+
if (readTools.length > 0) {
|
|
393
|
+
sections.push(readTools.join("\n"));
|
|
394
|
+
}
|
|
384
395
|
if (modeId !== "plan") {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
-
|
|
390
|
-
-
|
|
396
|
+
const writeTools = [];
|
|
397
|
+
if (!denied.has(chunkOEDRHUU5_cjs.MC_TOOLS.STRING_REPLACE_LSP)) {
|
|
398
|
+
writeTools.push(`
|
|
399
|
+
**${chunkOEDRHUU5_cjs.MC_TOOLS.STRING_REPLACE_LSP}** \u2014 Edit files by replacing exact text
|
|
400
|
+
- You MUST read a file with \`${chunkOEDRHUU5_cjs.MC_TOOLS.VIEW}\` before editing it.
|
|
401
|
+
- \`old_string\` must be an exact match of existing text in the file.
|
|
402
|
+
- Provide enough surrounding context in \`old_string\` to make it unique.
|
|
403
|
+
- Use \`replace_all: true\` to replace all occurrences (default: false, requires unique match).
|
|
404
|
+
- For creating new files, use \`${chunkOEDRHUU5_cjs.MC_TOOLS.WRITE_FILE}\` instead.
|
|
391
405
|
- Good: Include 2-3 lines of surrounding context to ensure uniqueness.
|
|
392
|
-
- Bad: Using just \`return true;\` \u2014 too common, will match multiple places
|
|
393
|
-
|
|
394
|
-
|
|
406
|
+
- Bad: Using just \`return true;\` \u2014 too common, will match multiple places.`);
|
|
407
|
+
}
|
|
408
|
+
if (!denied.has(chunkOEDRHUU5_cjs.MC_TOOLS.WRITE_FILE)) {
|
|
409
|
+
writeTools.push(`
|
|
410
|
+
**${chunkOEDRHUU5_cjs.MC_TOOLS.WRITE_FILE}** \u2014 Create new files or overwrite existing ones
|
|
395
411
|
- Use this to create new files.
|
|
396
|
-
- If overwriting an existing file, you MUST have read it first with
|
|
397
|
-
-
|
|
412
|
+
- If overwriting an existing file, you MUST have read it first with \`${chunkOEDRHUU5_cjs.MC_TOOLS.VIEW}\`.
|
|
413
|
+
- Prefer editing existing files over creating new ones.`);
|
|
414
|
+
}
|
|
415
|
+
if (writeTools.length > 0) {
|
|
416
|
+
sections.push(writeTools.join("\n"));
|
|
417
|
+
}
|
|
398
418
|
}
|
|
399
419
|
if (options.hasWebSearch) {
|
|
400
|
-
|
|
401
|
-
|
|
420
|
+
const webTools = [];
|
|
421
|
+
if (!denied.has("web_search")) webTools.push("**web_search**");
|
|
422
|
+
if (!denied.has("web_extract")) webTools.push("**web_extract**");
|
|
423
|
+
if (webTools.length > 0) {
|
|
424
|
+
sections.push(`
|
|
425
|
+
${webTools.join(" / ")} \u2014 Search the web / extract page content
|
|
402
426
|
- Use for looking up documentation, error messages, package APIs.`);
|
|
427
|
+
}
|
|
403
428
|
}
|
|
404
|
-
|
|
429
|
+
const taskTools = [];
|
|
430
|
+
if (!denied.has("task_write")) {
|
|
431
|
+
taskTools.push(`
|
|
405
432
|
**task_write** \u2014 Track tasks for complex multi-step work
|
|
406
433
|
- Use when a task requires 3 or more distinct steps or actions.
|
|
407
434
|
- Pass the FULL task list each time (replaces previous list).
|
|
408
435
|
- Mark tasks \`in_progress\` BEFORE starting work. Only ONE task should be \`in_progress\` at a time.
|
|
409
436
|
- Mark tasks \`completed\` IMMEDIATELY after finishing each task. Do not batch completions.
|
|
410
|
-
- Each task has: content (imperative form), status (pending|in_progress|completed), activeForm (present continuous form shown during execution)
|
|
411
|
-
|
|
437
|
+
- Each task has: content (imperative form), status (pending|in_progress|completed), activeForm (present continuous form shown during execution).`);
|
|
438
|
+
}
|
|
439
|
+
if (!denied.has("task_check")) {
|
|
440
|
+
taskTools.push(`
|
|
412
441
|
**task_check** \u2014 Check completion status of tasks
|
|
413
442
|
- Use this BEFORE deciding you're done with a task to verify all tasks are completed.
|
|
414
443
|
- Returns the number of completed, in progress, and pending tasks.
|
|
415
444
|
- If any tasks remain incomplete, continue working on them.
|
|
416
|
-
- IMPORTANT: Always check task completion before ending work on a complex task
|
|
417
|
-
|
|
445
|
+
- IMPORTANT: Always check task completion before ending work on a complex task.`);
|
|
446
|
+
}
|
|
447
|
+
if (!denied.has("ask_user")) {
|
|
448
|
+
taskTools.push(`
|
|
418
449
|
**ask_user** \u2014 Ask the user a structured question
|
|
419
450
|
- Use when you need clarification, want to validate assumptions, or need the user to make a decision.
|
|
420
451
|
- Provide clear, specific questions. End with a question mark.
|
|
421
452
|
- Include options (2-4 choices) for structured decisions. Omit options for open-ended questions.
|
|
422
453
|
- Don't use this for simple yes/no \u2014 just ask in your text response.`);
|
|
423
|
-
|
|
454
|
+
}
|
|
455
|
+
if (taskTools.length > 0) {
|
|
456
|
+
sections.push(taskTools.join("\n"));
|
|
457
|
+
}
|
|
458
|
+
if (modeId === "plan" && !denied.has("submit_plan")) {
|
|
424
459
|
sections.push(`
|
|
425
460
|
**submit_plan** \u2014 Submit a completed implementation plan for user review
|
|
426
461
|
- Call this tool when your plan is complete. Do NOT just describe your plan in text \u2014 you MUST call this tool.
|
|
@@ -428,10 +463,12 @@ You have access to the following tools. Use the RIGHT tool for the job:`);
|
|
|
428
463
|
- On approval, the system automatically switches to the default mode so you can implement.
|
|
429
464
|
- Takes two arguments: \`title\` (short descriptive title) and \`plan\` (full plan in markdown).`);
|
|
430
465
|
}
|
|
431
|
-
|
|
466
|
+
if (!denied.has("subagent")) {
|
|
467
|
+
sections.push(`
|
|
432
468
|
**subagent** \u2014 Delegate a focused task to a specialized subagent
|
|
433
469
|
- Only use subagents when you will spawn **multiple subagents in parallel**. If you only need one task done, do it yourself.
|
|
434
470
|
- Subagent outputs are **untrusted**. Always review and verify the results.`);
|
|
471
|
+
}
|
|
435
472
|
return sections.join("\n");
|
|
436
473
|
}
|
|
437
474
|
|
|
@@ -443,8 +480,15 @@ var modePrompts = {
|
|
|
443
480
|
};
|
|
444
481
|
function buildFullPrompt(ctx) {
|
|
445
482
|
const modelId = ctx.state?.currentModelId;
|
|
446
|
-
const hasWebSearch =
|
|
447
|
-
const
|
|
483
|
+
const hasWebSearch = chunkAJEYT7X3_cjs.hasTavilyKey() || !!modelId && modelId.startsWith("anthropic/");
|
|
484
|
+
const deniedTools = /* @__PURE__ */ new Set();
|
|
485
|
+
const permRules = ctx.state?.permissionRules;
|
|
486
|
+
if (permRules?.tools) {
|
|
487
|
+
for (const [name, policy] of Object.entries(permRules.tools)) {
|
|
488
|
+
if (policy === "deny") deniedTools.add(name);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const toolGuidance = buildToolGuidance(ctx.modeId, { hasWebSearch, deniedTools });
|
|
448
492
|
const baseCtx = {
|
|
449
493
|
projectPath: ctx.workingDir,
|
|
450
494
|
projectName: ctx.projectName || "unknown",
|
|
@@ -512,11 +556,11 @@ function getHarnessState(requestContext) {
|
|
|
512
556
|
}
|
|
513
557
|
function getObserverModel({ requestContext }) {
|
|
514
558
|
const state = getHarnessState(requestContext);
|
|
515
|
-
return
|
|
559
|
+
return chunkAJEYT7X3_cjs.resolveModel(state?.observerModelId ?? DEFAULT_OM_MODEL_ID, { remapForCodexOAuth: true });
|
|
516
560
|
}
|
|
517
561
|
function getReflectorModel({ requestContext }) {
|
|
518
562
|
const state = getHarnessState(requestContext);
|
|
519
|
-
return
|
|
563
|
+
return chunkAJEYT7X3_cjs.resolveModel(state?.reflectorModelId ?? DEFAULT_OM_MODEL_ID, { remapForCodexOAuth: true });
|
|
520
564
|
}
|
|
521
565
|
function getDynamicMemory(storage) {
|
|
522
566
|
return ({ requestContext }) => {
|
|
@@ -539,19 +583,13 @@ function getDynamicMemory(storage) {
|
|
|
539
583
|
bufferActivation: 2e3,
|
|
540
584
|
model: getObserverModel,
|
|
541
585
|
messageTokens: obsThreshold,
|
|
542
|
-
blockAfter: 2
|
|
543
|
-
modelSettings: {
|
|
544
|
-
maxOutputTokens: 6e4
|
|
545
|
-
}
|
|
586
|
+
blockAfter: 2
|
|
546
587
|
},
|
|
547
588
|
reflection: {
|
|
548
589
|
bufferActivation: 1 / 2,
|
|
549
590
|
blockAfter: 1.1,
|
|
550
591
|
model: getReflectorModel,
|
|
551
|
-
observationTokens: refThreshold
|
|
552
|
-
modelSettings: {
|
|
553
|
-
maxOutputTokens: 6e4
|
|
554
|
-
}
|
|
592
|
+
observationTokens: refThreshold
|
|
555
593
|
}
|
|
556
594
|
}
|
|
557
595
|
}
|
|
@@ -560,120 +598,48 @@ function getDynamicMemory(storage) {
|
|
|
560
598
|
return cachedMemory;
|
|
561
599
|
};
|
|
562
600
|
}
|
|
563
|
-
function createDynamicTools(mcpManager) {
|
|
601
|
+
function createDynamicTools(mcpManager, extraTools) {
|
|
564
602
|
return function getDynamicTools({ requestContext }) {
|
|
565
603
|
const ctx = requestContext.get("harness");
|
|
566
604
|
const state = ctx?.getState?.();
|
|
567
|
-
const modeId = ctx?.modeId ?? "build";
|
|
568
605
|
const modelId = state?.currentModelId;
|
|
569
606
|
const isAnthropicModel = modelId?.startsWith("anthropic/");
|
|
570
|
-
const
|
|
571
|
-
const viewTool = chunkK4WJUBEC_cjs.createViewTool(projectPath);
|
|
572
|
-
const grepTool = chunkK4WJUBEC_cjs.createGrepTool(projectPath);
|
|
573
|
-
const globTool = chunkK4WJUBEC_cjs.createGlobTool(projectPath);
|
|
574
|
-
const executeCommandTool = chunkK4WJUBEC_cjs.createExecuteCommandTool(projectPath);
|
|
575
|
-
const writeFileTool = chunkK4WJUBEC_cjs.createWriteFileTool(projectPath);
|
|
607
|
+
const isOpenAIModel = modelId?.startsWith("openai/");
|
|
576
608
|
const tools = {
|
|
577
|
-
|
|
578
|
-
search_content: grepTool,
|
|
579
|
-
find_files: globTool,
|
|
580
|
-
execute_command: executeCommandTool,
|
|
581
|
-
request_sandbox_access: chunkK4WJUBEC_cjs.requestSandboxAccessTool
|
|
609
|
+
request_sandbox_access: chunkAJEYT7X3_cjs.requestSandboxAccessTool
|
|
582
610
|
};
|
|
583
|
-
if (
|
|
584
|
-
tools.
|
|
585
|
-
tools.
|
|
586
|
-
tools.write_file = writeFileTool;
|
|
587
|
-
}
|
|
588
|
-
if (chunkK4WJUBEC_cjs.hasTavilyKey()) {
|
|
589
|
-
tools.web_search = chunkK4WJUBEC_cjs.createWebSearchTool();
|
|
590
|
-
tools.web_extract = chunkK4WJUBEC_cjs.createWebExtractTool();
|
|
611
|
+
if (chunkAJEYT7X3_cjs.hasTavilyKey()) {
|
|
612
|
+
tools.web_search = chunkAJEYT7X3_cjs.createWebSearchTool();
|
|
613
|
+
tools.web_extract = chunkAJEYT7X3_cjs.createWebExtractTool();
|
|
591
614
|
} else if (isAnthropicModel) {
|
|
592
615
|
const anthropic$1 = anthropic.createAnthropic({});
|
|
593
616
|
tools.web_search = anthropic$1.tools.webSearch_20250305();
|
|
617
|
+
} else if (isOpenAIModel) {
|
|
618
|
+
const openai$1 = openai.createOpenAI({});
|
|
619
|
+
tools.web_search = openai$1.tools.webSearch();
|
|
594
620
|
}
|
|
595
621
|
if (mcpManager) {
|
|
596
622
|
const mcpTools = mcpManager.getTools();
|
|
597
623
|
Object.assign(tools, mcpTools);
|
|
598
624
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
function collectSkillPaths(skillsDirs) {
|
|
607
|
-
const paths = [];
|
|
608
|
-
const seen = /* @__PURE__ */ new Set();
|
|
609
|
-
for (const skillsDir of skillsDirs) {
|
|
610
|
-
if (!fs4__namespace.default.existsSync(skillsDir)) continue;
|
|
611
|
-
const resolved = fs4__namespace.default.realpathSync(skillsDir);
|
|
612
|
-
if (!seen.has(resolved)) {
|
|
613
|
-
seen.add(resolved);
|
|
614
|
-
paths.push(skillsDir);
|
|
625
|
+
if (extraTools) {
|
|
626
|
+
const resolved = typeof extraTools === "function" ? extraTools({ requestContext }) : extraTools;
|
|
627
|
+
for (const [name, tool] of Object.entries(resolved)) {
|
|
628
|
+
if (!(name in tools)) {
|
|
629
|
+
tools[name] = tool;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
615
632
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
for (const
|
|
619
|
-
if (
|
|
620
|
-
|
|
621
|
-
const realPath = fs4__namespace.default.realpathSync(linkPath);
|
|
622
|
-
const stat = fs4__namespace.default.statSync(realPath);
|
|
623
|
-
if (stat.isDirectory()) {
|
|
624
|
-
const realParent = path__namespace.default.dirname(realPath);
|
|
625
|
-
if (!seen.has(realParent)) {
|
|
626
|
-
seen.add(realParent);
|
|
627
|
-
paths.push(realParent);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
633
|
+
const permissionRules = state?.permissionRules;
|
|
634
|
+
if (permissionRules?.tools) {
|
|
635
|
+
for (const [name, policy] of Object.entries(permissionRules.tools)) {
|
|
636
|
+
if (policy === "deny") {
|
|
637
|
+
delete tools[name];
|
|
630
638
|
}
|
|
631
639
|
}
|
|
632
|
-
} catch {
|
|
633
640
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
var skillPaths = collectSkillPaths([
|
|
638
|
-
mastraCodeLocalSkillsPath,
|
|
639
|
-
claudeLocalSkillsPath,
|
|
640
|
-
mastraCodeGlobalSkillsPath,
|
|
641
|
-
claudeGlobalSkillsPath
|
|
642
|
-
]);
|
|
643
|
-
function getDynamicWorkspace({ requestContext }) {
|
|
644
|
-
const ctx = requestContext.get("harness");
|
|
645
|
-
const state = ctx?.getState?.();
|
|
646
|
-
const projectPath = state?.projectPath;
|
|
647
|
-
if (!projectPath) {
|
|
648
|
-
throw new Error("Project path is required");
|
|
649
|
-
}
|
|
650
|
-
const sandboxPaths = state?.sandboxAllowedPaths ?? [];
|
|
651
|
-
const workspace$1 = new workspace.Workspace({
|
|
652
|
-
id: "mastra-code-workspace",
|
|
653
|
-
name: "Mastra Code Workspace",
|
|
654
|
-
filesystem: new workspace.LocalFilesystem({
|
|
655
|
-
basePath: projectPath,
|
|
656
|
-
allowedPaths: skillPaths
|
|
657
|
-
}),
|
|
658
|
-
sandbox: new workspace.LocalSandbox({
|
|
659
|
-
workingDirectory: projectPath,
|
|
660
|
-
env: process.env
|
|
661
|
-
}),
|
|
662
|
-
// Disable workspace tools — built-in tools are used instead.
|
|
663
|
-
// Workspace tools use different output formats (e.g. → separator, offset/limit params)
|
|
664
|
-
// that the TUI renderers don't fully support yet.
|
|
665
|
-
// We will update to use workspace tools very soon - just disabling until then
|
|
666
|
-
tools: { enabled: false },
|
|
667
|
-
...skillPaths.length > 0 ? { skills: skillPaths } : {}
|
|
668
|
-
});
|
|
669
|
-
workspace$1.filesystem.setAllowedPaths([...skillPaths, ...sandboxPaths.map((p) => path__namespace.default.resolve(p))]);
|
|
670
|
-
return workspace$1;
|
|
671
|
-
}
|
|
672
|
-
if (skillPaths.length > 0) {
|
|
673
|
-
console.info(`Skills loaded from:`);
|
|
674
|
-
for (const p of skillPaths) {
|
|
675
|
-
console.info(` - ${p}`);
|
|
676
|
-
}
|
|
641
|
+
return tools;
|
|
642
|
+
};
|
|
677
643
|
}
|
|
678
644
|
var VALID_EVENTS = [
|
|
679
645
|
"PreToolUse",
|
|
@@ -691,15 +657,15 @@ function loadHooksConfig(projectDir) {
|
|
|
691
657
|
return mergeConfigs(globalConfig, projectConfig);
|
|
692
658
|
}
|
|
693
659
|
function getProjectHooksPath(projectDir) {
|
|
694
|
-
return
|
|
660
|
+
return path3__namespace.join(projectDir, ".mastracode", "hooks.json");
|
|
695
661
|
}
|
|
696
662
|
function getGlobalHooksPath() {
|
|
697
|
-
return
|
|
663
|
+
return path3__namespace.join(os__namespace.homedir(), ".mastracode", "hooks.json");
|
|
698
664
|
}
|
|
699
665
|
function loadSingleConfig(filePath) {
|
|
700
666
|
try {
|
|
701
|
-
if (!
|
|
702
|
-
const raw =
|
|
667
|
+
if (!fs3__namespace.existsSync(filePath)) return {};
|
|
668
|
+
const raw = fs3__namespace.readFileSync(filePath, "utf-8");
|
|
703
669
|
return validateConfig(JSON.parse(raw));
|
|
704
670
|
} catch {
|
|
705
671
|
return {};
|
|
@@ -996,18 +962,18 @@ function loadMcpConfig(projectDir) {
|
|
|
996
962
|
return mergeConfigs2(claudeConfig, globalConfig, projectConfig);
|
|
997
963
|
}
|
|
998
964
|
function getProjectMcpPath(projectDir) {
|
|
999
|
-
return
|
|
965
|
+
return path3__namespace.join(projectDir, ".mastracode", "mcp.json");
|
|
1000
966
|
}
|
|
1001
967
|
function getGlobalMcpPath() {
|
|
1002
|
-
return
|
|
968
|
+
return path3__namespace.join(os__namespace.homedir(), ".mastracode", "mcp.json");
|
|
1003
969
|
}
|
|
1004
970
|
function getClaudeSettingsPath(projectDir) {
|
|
1005
|
-
return
|
|
971
|
+
return path3__namespace.join(projectDir, ".claude", "settings.local.json");
|
|
1006
972
|
}
|
|
1007
973
|
function loadSingleConfig2(filePath) {
|
|
1008
974
|
try {
|
|
1009
|
-
if (!
|
|
1010
|
-
const raw =
|
|
975
|
+
if (!fs3__namespace.existsSync(filePath)) return {};
|
|
976
|
+
const raw = fs3__namespace.readFileSync(filePath, "utf-8");
|
|
1011
977
|
return validateConfig2(JSON.parse(raw));
|
|
1012
978
|
} catch {
|
|
1013
979
|
return {};
|
|
@@ -1016,8 +982,8 @@ function loadSingleConfig2(filePath) {
|
|
|
1016
982
|
function loadClaudeSettings(projectDir) {
|
|
1017
983
|
try {
|
|
1018
984
|
const filePath = getClaudeSettingsPath(projectDir);
|
|
1019
|
-
if (!
|
|
1020
|
-
const raw =
|
|
985
|
+
if (!fs3__namespace.existsSync(filePath)) return {};
|
|
986
|
+
const raw = fs3__namespace.readFileSync(filePath, "utf-8");
|
|
1021
987
|
const parsed = JSON.parse(raw);
|
|
1022
988
|
if (parsed?.mcpServers && typeof parsed.mcpServers === "object") {
|
|
1023
989
|
return validateConfig2({ mcpServers: parsed.mcpServers });
|
|
@@ -1027,43 +993,97 @@ function loadClaudeSettings(projectDir) {
|
|
|
1027
993
|
return {};
|
|
1028
994
|
}
|
|
1029
995
|
}
|
|
996
|
+
function classifyServerEntry(raw) {
|
|
997
|
+
if (!raw || typeof raw !== "object") {
|
|
998
|
+
return { kind: "skip", reason: "Invalid entry: expected an object" };
|
|
999
|
+
}
|
|
1000
|
+
const obj = raw;
|
|
1001
|
+
const hasCommand = typeof obj.command === "string";
|
|
1002
|
+
const hasUrl = typeof obj.url === "string";
|
|
1003
|
+
if (hasCommand && hasUrl) {
|
|
1004
|
+
return { kind: "skip", reason: 'Cannot specify both "command" and "url"' };
|
|
1005
|
+
}
|
|
1006
|
+
if (hasCommand) {
|
|
1007
|
+
return { kind: "stdio" };
|
|
1008
|
+
}
|
|
1009
|
+
if (hasUrl) {
|
|
1010
|
+
try {
|
|
1011
|
+
new URL(obj.url);
|
|
1012
|
+
} catch {
|
|
1013
|
+
return { kind: "skip", reason: `Invalid URL: "${obj.url}"` };
|
|
1014
|
+
}
|
|
1015
|
+
return { kind: "http" };
|
|
1016
|
+
}
|
|
1017
|
+
return { kind: "skip", reason: 'Missing required field: "command" (stdio) or "url" (http)' };
|
|
1018
|
+
}
|
|
1030
1019
|
function validateConfig2(raw) {
|
|
1031
1020
|
if (!raw || typeof raw !== "object") return {};
|
|
1032
1021
|
const obj = raw;
|
|
1033
1022
|
if (!obj.mcpServers || typeof obj.mcpServers !== "object") return {};
|
|
1034
1023
|
const servers = {};
|
|
1024
|
+
const skippedServers = [];
|
|
1035
1025
|
const rawServers = obj.mcpServers;
|
|
1036
1026
|
for (const [name, entry] of Object.entries(rawServers)) {
|
|
1037
|
-
|
|
1027
|
+
const classification = classifyServerEntry(entry);
|
|
1028
|
+
if (classification.kind === "stdio") {
|
|
1029
|
+
const e = entry;
|
|
1030
|
+
servers[name] = {
|
|
1031
|
+
command: e.command,
|
|
1032
|
+
args: Array.isArray(e.args) ? e.args : void 0,
|
|
1033
|
+
env: typeof e.env === "object" && e.env !== null ? e.env : void 0
|
|
1034
|
+
};
|
|
1035
|
+
} else if (classification.kind === "http") {
|
|
1036
|
+
const e = entry;
|
|
1038
1037
|
servers[name] = {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
env: typeof entry.env === "object" && entry.env !== null ? entry.env : void 0
|
|
1038
|
+
url: e.url,
|
|
1039
|
+
headers: typeof e.headers === "object" && e.headers !== null ? e.headers : void 0
|
|
1042
1040
|
};
|
|
1041
|
+
} else {
|
|
1042
|
+
skippedServers.push({ name, reason: classification.reason });
|
|
1043
1043
|
}
|
|
1044
1044
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
if (
|
|
1050
|
-
|
|
1051
|
-
|
|
1045
|
+
const result = {};
|
|
1046
|
+
if (Object.keys(servers).length > 0) {
|
|
1047
|
+
result.mcpServers = servers;
|
|
1048
|
+
}
|
|
1049
|
+
if (skippedServers.length > 0) {
|
|
1050
|
+
result.skippedServers = skippedServers;
|
|
1051
|
+
}
|
|
1052
|
+
return result;
|
|
1052
1053
|
}
|
|
1053
1054
|
function mergeConfigs2(...configs) {
|
|
1054
1055
|
const merged = {};
|
|
1056
|
+
const allSkipped = [];
|
|
1055
1057
|
for (const config of configs) {
|
|
1056
1058
|
if (config.mcpServers) {
|
|
1057
1059
|
for (const [name, server] of Object.entries(config.mcpServers)) {
|
|
1058
1060
|
merged[name] = server;
|
|
1059
1061
|
}
|
|
1060
1062
|
}
|
|
1063
|
+
if (config.skippedServers) {
|
|
1064
|
+
allSkipped.push(...config.skippedServers);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
const validNames = new Set(Object.keys(merged));
|
|
1068
|
+
const filteredSkipped = allSkipped.filter((s) => !validNames.has(s.name));
|
|
1069
|
+
const skippedMap = /* @__PURE__ */ new Map();
|
|
1070
|
+
for (const s of filteredSkipped) {
|
|
1071
|
+
skippedMap.set(s.name, s);
|
|
1072
|
+
}
|
|
1073
|
+
const result = {};
|
|
1074
|
+
if (Object.keys(merged).length > 0) {
|
|
1075
|
+
result.mcpServers = merged;
|
|
1061
1076
|
}
|
|
1062
|
-
if (
|
|
1063
|
-
|
|
1077
|
+
if (skippedMap.size > 0) {
|
|
1078
|
+
result.skippedServers = Array.from(skippedMap.values());
|
|
1079
|
+
}
|
|
1080
|
+
return result;
|
|
1064
1081
|
}
|
|
1065
1082
|
|
|
1066
1083
|
// src/mcp/manager.ts
|
|
1084
|
+
function getTransport(cfg) {
|
|
1085
|
+
return "url" in cfg ? "http" : "stdio";
|
|
1086
|
+
}
|
|
1067
1087
|
function createMcpManager(projectDir) {
|
|
1068
1088
|
let config = loadMcpConfig(projectDir);
|
|
1069
1089
|
let client = null;
|
|
@@ -1073,7 +1093,15 @@ function createMcpManager(projectDir) {
|
|
|
1073
1093
|
function buildServerDefs(servers) {
|
|
1074
1094
|
const defs = {};
|
|
1075
1095
|
for (const [name, cfg] of Object.entries(servers)) {
|
|
1076
|
-
|
|
1096
|
+
if ("url" in cfg) {
|
|
1097
|
+
const httpCfg = cfg;
|
|
1098
|
+
defs[name] = {
|
|
1099
|
+
url: new URL(httpCfg.url),
|
|
1100
|
+
requestInit: httpCfg.headers ? { headers: httpCfg.headers } : void 0
|
|
1101
|
+
};
|
|
1102
|
+
} else {
|
|
1103
|
+
defs[name] = { command: cfg.command, args: cfg.args, env: cfg.env };
|
|
1104
|
+
}
|
|
1077
1105
|
}
|
|
1078
1106
|
return defs;
|
|
1079
1107
|
}
|
|
@@ -1096,7 +1124,8 @@ function createMcpManager(projectDir) {
|
|
|
1096
1124
|
name,
|
|
1097
1125
|
connected: true,
|
|
1098
1126
|
toolCount: serverToolNames.length,
|
|
1099
|
-
toolNames: serverToolNames
|
|
1127
|
+
toolNames: serverToolNames,
|
|
1128
|
+
transport: getTransport(servers[name])
|
|
1100
1129
|
});
|
|
1101
1130
|
}
|
|
1102
1131
|
} catch (error) {
|
|
@@ -1107,6 +1136,7 @@ function createMcpManager(projectDir) {
|
|
|
1107
1136
|
connected: false,
|
|
1108
1137
|
toolCount: 0,
|
|
1109
1138
|
toolNames: [],
|
|
1139
|
+
transport: getTransport(servers[name]),
|
|
1110
1140
|
error: errMsg
|
|
1111
1141
|
});
|
|
1112
1142
|
}
|
|
@@ -1141,11 +1171,16 @@ function createMcpManager(projectDir) {
|
|
|
1141
1171
|
return { ...tools };
|
|
1142
1172
|
},
|
|
1143
1173
|
hasServers() {
|
|
1144
|
-
|
|
1174
|
+
const hasConfigured = config.mcpServers !== void 0 && Object.keys(config.mcpServers).length > 0;
|
|
1175
|
+
const hasSkipped = config.skippedServers !== void 0 && config.skippedServers.length > 0;
|
|
1176
|
+
return hasConfigured || hasSkipped;
|
|
1145
1177
|
},
|
|
1146
1178
|
getServerStatuses() {
|
|
1147
1179
|
return Array.from(serverStatuses.values());
|
|
1148
1180
|
},
|
|
1181
|
+
getSkippedServers() {
|
|
1182
|
+
return [...config.skippedServers ?? []];
|
|
1183
|
+
},
|
|
1149
1184
|
getConfigPaths() {
|
|
1150
1185
|
return {
|
|
1151
1186
|
project: getProjectMcpPath(projectDir),
|
|
@@ -1203,21 +1238,21 @@ var stateSchema = zod.z.object({
|
|
|
1203
1238
|
approvedAt: zod.z.string()
|
|
1204
1239
|
}).nullable().default(null)
|
|
1205
1240
|
});
|
|
1206
|
-
var CACHE_DIR =
|
|
1207
|
-
var CACHE_FILE =
|
|
1208
|
-
var GLOBAL_PROVIDER_REGISTRY_JSON =
|
|
1209
|
-
var GLOBAL_PROVIDER_TYPES_DTS =
|
|
1241
|
+
var CACHE_DIR = path3__namespace.default.join(os__namespace.default.homedir(), ".cache", "mastra");
|
|
1242
|
+
var CACHE_FILE = path3__namespace.default.join(CACHE_DIR, "gateway-refresh-time");
|
|
1243
|
+
var GLOBAL_PROVIDER_REGISTRY_JSON = path3__namespace.default.join(CACHE_DIR, "provider-registry.json");
|
|
1244
|
+
var GLOBAL_PROVIDER_TYPES_DTS = path3__namespace.default.join(CACHE_DIR, "provider-types.generated.d.ts");
|
|
1210
1245
|
var DEFAULT_SYNC_INTERVAL_MS = 5 * 60 * 1e3;
|
|
1211
1246
|
var isSyncing = false;
|
|
1212
1247
|
async function atomicWriteFile(filePath, content) {
|
|
1213
1248
|
const randomSuffix = Math.random().toString(36).substring(2, 15);
|
|
1214
1249
|
const tempPath = `${filePath}.${process.pid}.${Date.now()}.${randomSuffix}.tmp`;
|
|
1215
1250
|
try {
|
|
1216
|
-
await
|
|
1217
|
-
await
|
|
1251
|
+
await fs3__namespace.default.promises.writeFile(tempPath, content, "utf-8");
|
|
1252
|
+
await fs3__namespace.default.promises.rename(tempPath, filePath);
|
|
1218
1253
|
} catch (error) {
|
|
1219
1254
|
try {
|
|
1220
|
-
await
|
|
1255
|
+
await fs3__namespace.default.promises.unlink(tempPath);
|
|
1221
1256
|
} catch {
|
|
1222
1257
|
}
|
|
1223
1258
|
throw error;
|
|
@@ -1282,10 +1317,10 @@ export type ModelForProvider<P extends Provider> = ProviderModelsMap[P][number];
|
|
|
1282
1317
|
}
|
|
1283
1318
|
function getLastSyncTime() {
|
|
1284
1319
|
try {
|
|
1285
|
-
if (!
|
|
1320
|
+
if (!fs3__namespace.default.existsSync(CACHE_FILE)) {
|
|
1286
1321
|
return null;
|
|
1287
1322
|
}
|
|
1288
|
-
const timestamp =
|
|
1323
|
+
const timestamp = fs3__namespace.default.readFileSync(CACHE_FILE, "utf-8").trim();
|
|
1289
1324
|
return new Date(parseInt(timestamp, 10));
|
|
1290
1325
|
} catch {
|
|
1291
1326
|
return null;
|
|
@@ -1293,10 +1328,10 @@ function getLastSyncTime() {
|
|
|
1293
1328
|
}
|
|
1294
1329
|
function saveLastSyncTime(date) {
|
|
1295
1330
|
try {
|
|
1296
|
-
if (!
|
|
1297
|
-
|
|
1331
|
+
if (!fs3__namespace.default.existsSync(CACHE_DIR)) {
|
|
1332
|
+
fs3__namespace.default.mkdirSync(CACHE_DIR, { recursive: true });
|
|
1298
1333
|
}
|
|
1299
|
-
|
|
1334
|
+
fs3__namespace.default.writeFileSync(CACHE_FILE, date.getTime().toString(), "utf-8");
|
|
1300
1335
|
} catch (error) {
|
|
1301
1336
|
console.warn("[GatewaySync] Failed to save sync time:", error);
|
|
1302
1337
|
}
|
|
@@ -1317,7 +1352,7 @@ async function syncGateways(force = false) {
|
|
|
1317
1352
|
isSyncing = true;
|
|
1318
1353
|
try {
|
|
1319
1354
|
const { providers, models } = await fetchProvidersFromGateways();
|
|
1320
|
-
await
|
|
1355
|
+
await fs3__namespace.default.promises.mkdir(CACHE_DIR, { recursive: true });
|
|
1321
1356
|
const registryData = {
|
|
1322
1357
|
providers,
|
|
1323
1358
|
models,
|
|
@@ -1399,45 +1434,40 @@ var PROVIDER_TO_OAUTH_ID = {
|
|
|
1399
1434
|
async function createMastraCode(config) {
|
|
1400
1435
|
const cwd = config?.cwd ?? process.cwd();
|
|
1401
1436
|
const authStorage = new chunkS5ZLN7DR_cjs.AuthStorage();
|
|
1402
|
-
|
|
1403
|
-
|
|
1437
|
+
chunkAJEYT7X3_cjs.setAuthStorage(authStorage);
|
|
1438
|
+
chunkAJEYT7X3_cjs.setAuthStorage2(authStorage);
|
|
1404
1439
|
const project = chunkS5ZLN7DR_cjs.detectProject(cwd);
|
|
1405
1440
|
const resourceIdOverride = chunkS5ZLN7DR_cjs.getResourceIdOverride(project.rootPath);
|
|
1406
1441
|
if (resourceIdOverride) {
|
|
1407
1442
|
project.resourceId = resourceIdOverride;
|
|
1408
1443
|
project.resourceIdOverride = true;
|
|
1409
1444
|
}
|
|
1410
|
-
const globalSettings =
|
|
1445
|
+
const globalSettings = chunkAJEYT7X3_cjs.loadSettings();
|
|
1411
1446
|
const storageConfig = config?.storage ?? chunkS5ZLN7DR_cjs.getStorageConfig(project.rootPath, globalSettings.storage);
|
|
1412
1447
|
const storageResult = await createStorage(storageConfig);
|
|
1413
1448
|
const storage = storageResult.storage;
|
|
1414
1449
|
const storageWarning = storageResult.warning;
|
|
1415
1450
|
const memory = getDynamicMemory(storage);
|
|
1416
1451
|
const mcpManager = config?.disableMcp ? void 0 : createMcpManager(project.rootPath);
|
|
1417
|
-
const
|
|
1452
|
+
const codeAgent = new agent.Agent({
|
|
1418
1453
|
id: "code-agent",
|
|
1419
1454
|
name: "Code Agent",
|
|
1420
1455
|
instructions: getDynamicInstructions,
|
|
1421
|
-
model:
|
|
1422
|
-
tools: createDynamicTools(mcpManager)
|
|
1423
|
-
});
|
|
1424
|
-
const mastraInstance = new core.Mastra({
|
|
1425
|
-
agents: { codeAgentInstance },
|
|
1426
|
-
logger: logger.noopLogger,
|
|
1427
|
-
storage
|
|
1456
|
+
model: chunkAJEYT7X3_cjs.getDynamicModel,
|
|
1457
|
+
tools: createDynamicTools(mcpManager, config?.extraTools)
|
|
1428
1458
|
});
|
|
1429
|
-
const codeAgent = mastraInstance.getAgent("codeAgentInstance");
|
|
1430
1459
|
const hookManager = config?.disableHooks ? void 0 : new HookManager(project.rootPath, "session-init");
|
|
1431
1460
|
if (hookManager?.hasHooks()) {
|
|
1432
1461
|
const hookConfig = hookManager.getConfig();
|
|
1433
1462
|
const hookCount = Object.values(hookConfig).reduce((sum, hooks) => sum + (hooks?.length ?? 0), 0);
|
|
1434
1463
|
console.info(`Hooks: ${hookCount} hook(s) configured`);
|
|
1435
1464
|
}
|
|
1436
|
-
const viewTool =
|
|
1437
|
-
const grepTool =
|
|
1438
|
-
const globTool =
|
|
1439
|
-
const executeCommandTool =
|
|
1440
|
-
const writeFileTool =
|
|
1465
|
+
const viewTool = chunkAJEYT7X3_cjs.createViewTool(project.rootPath);
|
|
1466
|
+
const grepTool = chunkAJEYT7X3_cjs.createGrepTool(project.rootPath);
|
|
1467
|
+
const globTool = chunkAJEYT7X3_cjs.createGlobTool(project.rootPath);
|
|
1468
|
+
const executeCommandTool = chunkAJEYT7X3_cjs.createExecuteCommandTool(project.rootPath);
|
|
1469
|
+
const writeFileTool = chunkAJEYT7X3_cjs.createWriteFileTool(project.rootPath);
|
|
1470
|
+
const stringReplaceLspTool = chunkAJEYT7X3_cjs.createStringReplaceLspTool(project.rootPath);
|
|
1441
1471
|
const readOnlyTools = {
|
|
1442
1472
|
view: viewTool,
|
|
1443
1473
|
search_content: grepTool,
|
|
@@ -1445,27 +1475,27 @@ async function createMastraCode(config) {
|
|
|
1445
1475
|
};
|
|
1446
1476
|
const defaultSubagents = [
|
|
1447
1477
|
{
|
|
1448
|
-
id:
|
|
1449
|
-
name:
|
|
1478
|
+
id: chunkAJEYT7X3_cjs.exploreSubagent.id,
|
|
1479
|
+
name: chunkAJEYT7X3_cjs.exploreSubagent.name,
|
|
1450
1480
|
description: "Read-only codebase exploration. Use for questions like 'find all usages of X', 'how does module Y work'.",
|
|
1451
|
-
instructions:
|
|
1481
|
+
instructions: chunkAJEYT7X3_cjs.exploreSubagent.instructions,
|
|
1452
1482
|
tools: readOnlyTools
|
|
1453
1483
|
},
|
|
1454
1484
|
{
|
|
1455
|
-
id:
|
|
1456
|
-
name:
|
|
1485
|
+
id: chunkAJEYT7X3_cjs.planSubagent.id,
|
|
1486
|
+
name: chunkAJEYT7X3_cjs.planSubagent.name,
|
|
1457
1487
|
description: "Read-only analysis and planning. Use for 'create an implementation plan for X', 'analyze the architecture of Y'.",
|
|
1458
|
-
instructions:
|
|
1488
|
+
instructions: chunkAJEYT7X3_cjs.planSubagent.instructions,
|
|
1459
1489
|
tools: readOnlyTools
|
|
1460
1490
|
},
|
|
1461
1491
|
{
|
|
1462
|
-
id:
|
|
1463
|
-
name:
|
|
1492
|
+
id: chunkAJEYT7X3_cjs.executeSubagent.id,
|
|
1493
|
+
name: chunkAJEYT7X3_cjs.executeSubagent.name,
|
|
1464
1494
|
description: "Task execution with write capabilities. Use for 'implement feature X', 'fix bug Y', 'refactor module Z'.",
|
|
1465
|
-
instructions:
|
|
1495
|
+
instructions: chunkAJEYT7X3_cjs.executeSubagent.instructions,
|
|
1466
1496
|
tools: {
|
|
1467
1497
|
...readOnlyTools,
|
|
1468
|
-
string_replace_lsp:
|
|
1498
|
+
string_replace_lsp: stringReplaceLspTool,
|
|
1469
1499
|
write_file: writeFileTool,
|
|
1470
1500
|
execute_command: executeCommandTool,
|
|
1471
1501
|
task_write: harness.taskWriteTool,
|
|
@@ -1479,21 +1509,21 @@ async function createMastraCode(config) {
|
|
|
1479
1509
|
name: "Build",
|
|
1480
1510
|
default: true,
|
|
1481
1511
|
defaultModelId: "anthropic/claude-opus-4-6",
|
|
1482
|
-
color:
|
|
1512
|
+
color: chunkAJEYT7X3_cjs.mastra.purple,
|
|
1483
1513
|
agent: codeAgent
|
|
1484
1514
|
},
|
|
1485
1515
|
{
|
|
1486
1516
|
id: "plan",
|
|
1487
1517
|
name: "Plan",
|
|
1488
1518
|
defaultModelId: "openai/gpt-5.2-codex",
|
|
1489
|
-
color:
|
|
1519
|
+
color: chunkAJEYT7X3_cjs.mastra.blue,
|
|
1490
1520
|
agent: codeAgent
|
|
1491
1521
|
},
|
|
1492
1522
|
{
|
|
1493
1523
|
id: "fast",
|
|
1494
1524
|
name: "Fast",
|
|
1495
1525
|
defaultModelId: "cerebras/zai-glm-4.7",
|
|
1496
|
-
color:
|
|
1526
|
+
color: chunkAJEYT7X3_cjs.mastra.green,
|
|
1497
1527
|
agent: codeAgent
|
|
1498
1528
|
}
|
|
1499
1529
|
];
|
|
@@ -1511,10 +1541,22 @@ async function createMastraCode(config) {
|
|
|
1511
1541
|
google: process.env.GOOGLE_GENERATIVE_AI_API_KEY ? "apikey" : false,
|
|
1512
1542
|
deepseek: process.env.DEEPSEEK_API_KEY ? "apikey" : false
|
|
1513
1543
|
};
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1544
|
+
try {
|
|
1545
|
+
const registry = llm.PROVIDER_REGISTRY;
|
|
1546
|
+
for (const [provider, config2] of Object.entries(registry)) {
|
|
1547
|
+
if (startupAccess[provider] && startupAccess[provider] !== false) continue;
|
|
1548
|
+
const envVars = config2?.apiKeyEnvVar;
|
|
1549
|
+
const envVarList = Array.isArray(envVars) ? envVars : envVars ? [envVars] : [];
|
|
1550
|
+
if (envVarList.some((envVar) => process.env[envVar])) {
|
|
1551
|
+
startupAccess[provider] = "apikey";
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
} catch {
|
|
1555
|
+
}
|
|
1556
|
+
const builtinPacks = chunkAJEYT7X3_cjs.getAvailableModePacks(startupAccess);
|
|
1557
|
+
const builtinOmPacks = chunkAJEYT7X3_cjs.getAvailableOmPacks(startupAccess);
|
|
1558
|
+
const effectiveDefaults = chunkAJEYT7X3_cjs.resolveModelDefaults(globalSettings, builtinPacks);
|
|
1559
|
+
const effectiveOmModel = chunkAJEYT7X3_cjs.resolveOmModel(globalSettings, builtinOmPacks);
|
|
1518
1560
|
const modes = (config?.modes ?? defaultModes).map((mode) => {
|
|
1519
1561
|
const savedModel = effectiveDefaults[mode.id];
|
|
1520
1562
|
return savedModel ? { ...mode, defaultModelId: savedModel } : mode;
|
|
@@ -1547,8 +1589,8 @@ async function createMastraCode(config) {
|
|
|
1547
1589
|
memory,
|
|
1548
1590
|
stateSchema,
|
|
1549
1591
|
subagents,
|
|
1550
|
-
resolveModel:
|
|
1551
|
-
toolCategoryResolver:
|
|
1592
|
+
resolveModel: chunkAJEYT7X3_cjs.resolveModel,
|
|
1593
|
+
toolCategoryResolver: chunkOEDRHUU5_cjs.getToolCategory,
|
|
1552
1594
|
initialState: {
|
|
1553
1595
|
projectPath: project.rootPath,
|
|
1554
1596
|
projectName: project.name,
|
|
@@ -1557,7 +1599,7 @@ async function createMastraCode(config) {
|
|
|
1557
1599
|
...globalInitialState,
|
|
1558
1600
|
...config?.initialState
|
|
1559
1601
|
},
|
|
1560
|
-
workspace: getDynamicWorkspace,
|
|
1602
|
+
workspace: config?.workspace ?? chunkAJEYT7X3_cjs.getDynamicWorkspace,
|
|
1561
1603
|
modes,
|
|
1562
1604
|
heartbeatHandlers: config?.heartbeatHandlers ?? defaultHeartbeatHandlers,
|
|
1563
1605
|
modelAuthChecker: (provider) => {
|
|
@@ -1565,12 +1607,44 @@ async function createMastraCode(config) {
|
|
|
1565
1607
|
if (oauthId && authStorage.isLoggedIn(oauthId)) {
|
|
1566
1608
|
return true;
|
|
1567
1609
|
}
|
|
1610
|
+
const customProvider = chunkAJEYT7X3_cjs.loadSettings().customProviders.find((entry) => {
|
|
1611
|
+
return provider === chunkAJEYT7X3_cjs.getCustomProviderId(entry.name);
|
|
1612
|
+
});
|
|
1613
|
+
if (customProvider) {
|
|
1614
|
+
return true;
|
|
1615
|
+
}
|
|
1568
1616
|
return void 0;
|
|
1569
1617
|
},
|
|
1570
|
-
modelUseCountProvider: () =>
|
|
1618
|
+
modelUseCountProvider: () => chunkAJEYT7X3_cjs.loadSettings().modelUseCounts,
|
|
1619
|
+
modelUseCountTracker: (modelId) => {
|
|
1620
|
+
try {
|
|
1621
|
+
const settings = chunkAJEYT7X3_cjs.loadSettings();
|
|
1622
|
+
settings.modelUseCounts[modelId] = (settings.modelUseCounts[modelId] ?? 0) + 1;
|
|
1623
|
+
chunkAJEYT7X3_cjs.saveSettings(settings);
|
|
1624
|
+
} catch (error) {
|
|
1625
|
+
console.error("Failed to persist model usage count", error);
|
|
1626
|
+
}
|
|
1627
|
+
},
|
|
1628
|
+
customModelCatalogProvider: () => {
|
|
1629
|
+
const settings = chunkAJEYT7X3_cjs.loadSettings();
|
|
1630
|
+
const customModels = [];
|
|
1631
|
+
for (const provider of settings.customProviders) {
|
|
1632
|
+
const providerId = chunkAJEYT7X3_cjs.getCustomProviderId(provider.name);
|
|
1633
|
+
for (const modelName of provider.models) {
|
|
1634
|
+
customModels.push({
|
|
1635
|
+
id: chunkAJEYT7X3_cjs.toCustomProviderModelId(provider.name, modelName),
|
|
1636
|
+
provider: providerId,
|
|
1637
|
+
modelName,
|
|
1638
|
+
hasApiKey: true,
|
|
1639
|
+
apiKeyEnvVar: void 0
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
return customModels;
|
|
1644
|
+
},
|
|
1571
1645
|
threadLock: {
|
|
1572
|
-
acquire:
|
|
1573
|
-
release:
|
|
1646
|
+
acquire: chunkAJEYT7X3_cjs.acquireThreadLock,
|
|
1647
|
+
release: chunkAJEYT7X3_cjs.releaseThreadLock
|
|
1574
1648
|
}
|
|
1575
1649
|
});
|
|
1576
1650
|
if (hookManager) {
|
|
@@ -1582,9 +1656,9 @@ async function createMastraCode(config) {
|
|
|
1582
1656
|
}
|
|
1583
1657
|
});
|
|
1584
1658
|
}
|
|
1585
|
-
return { harness: harness$1, mcpManager, hookManager, authStorage, storageWarning };
|
|
1659
|
+
return { harness: harness$1, mcpManager, hookManager, authStorage, resolveModel: chunkAJEYT7X3_cjs.resolveModel, storageWarning };
|
|
1586
1660
|
}
|
|
1587
1661
|
|
|
1588
1662
|
exports.createMastraCode = createMastraCode;
|
|
1589
|
-
//# sourceMappingURL=chunk-
|
|
1590
|
-
//# sourceMappingURL=chunk-
|
|
1663
|
+
//# sourceMappingURL=chunk-MBPGUMYQ.cjs.map
|
|
1664
|
+
//# sourceMappingURL=chunk-MBPGUMYQ.cjs.map
|