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.
Files changed (155) hide show
  1. package/CHANGELOG.md +328 -0
  2. package/LICENSE.md +15 -0
  3. package/README.md +68 -29
  4. package/dist/agents/memory.d.ts.map +1 -1
  5. package/dist/agents/model.d.ts +17 -6
  6. package/dist/agents/model.d.ts.map +1 -1
  7. package/dist/agents/prompts/index.d.ts.map +1 -1
  8. package/dist/agents/prompts/tool-guidance.d.ts +2 -0
  9. package/dist/agents/prompts/tool-guidance.d.ts.map +1 -1
  10. package/dist/agents/subagents/audit-tests.d.ts +0 -7
  11. package/dist/agents/subagents/audit-tests.d.ts.map +1 -1
  12. package/dist/agents/subagents/execute.d.ts +0 -7
  13. package/dist/agents/subagents/execute.d.ts.map +1 -1
  14. package/dist/agents/subagents/explore.d.ts +0 -7
  15. package/dist/agents/subagents/explore.d.ts.map +1 -1
  16. package/dist/agents/subagents/index.d.ts.map +1 -1
  17. package/dist/agents/subagents/plan.d.ts +0 -7
  18. package/dist/agents/subagents/plan.d.ts.map +1 -1
  19. package/dist/agents/tools.d.ts +3 -1
  20. package/dist/agents/tools.d.ts.map +1 -1
  21. package/dist/agents/workspace.d.ts +4 -1
  22. package/dist/agents/workspace.d.ts.map +1 -1
  23. package/dist/{chunk-K4WJUBEC.cjs → chunk-AJEYT7X3.cjs} +763 -429
  24. package/dist/chunk-AJEYT7X3.cjs.map +1 -0
  25. package/dist/{chunk-U5A7TFNT.js → chunk-CC2724NI.js} +46 -10
  26. package/dist/chunk-CC2724NI.js.map +1 -0
  27. package/dist/{chunk-REVOTI2T.js → chunk-JI4M5525.js} +740 -412
  28. package/dist/chunk-JI4M5525.js.map +1 -0
  29. package/dist/{chunk-Z4QRXVST.cjs → chunk-MBPGUMYQ.cjs} +325 -251
  30. package/dist/chunk-MBPGUMYQ.cjs.map +1 -0
  31. package/dist/{chunk-MT3YCFCC.cjs → chunk-OEDRHUU5.cjs} +47 -9
  32. package/dist/chunk-OEDRHUU5.cjs.map +1 -0
  33. package/dist/{chunk-M5LKPQB4.js → chunk-WKPHD54B.js} +283 -209
  34. package/dist/chunk-WKPHD54B.js.map +1 -0
  35. package/dist/{chunk-C4X3C2DL.cjs → chunk-XVYUS2EA.cjs} +2213 -1035
  36. package/dist/chunk-XVYUS2EA.cjs.map +1 -0
  37. package/dist/{chunk-X3BGE7CL.js → chunk-YQNZ7DHQ.js} +1788 -613
  38. package/dist/chunk-YQNZ7DHQ.js.map +1 -0
  39. package/dist/cli.cjs +79 -31
  40. package/dist/cli.cjs.map +1 -1
  41. package/dist/cli.js +71 -23
  42. package/dist/cli.js.map +1 -1
  43. package/dist/clipboard/index.d.ts +5 -0
  44. package/dist/clipboard/index.d.ts.map +1 -1
  45. package/dist/error-classification.d.ts +10 -0
  46. package/dist/error-classification.d.ts.map +1 -0
  47. package/dist/index.cjs +2 -2
  48. package/dist/index.d.ts +10 -3
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -1
  51. package/dist/mcp/config.d.ts +8 -0
  52. package/dist/mcp/config.d.ts.map +1 -1
  53. package/dist/mcp/index.d.ts +1 -1
  54. package/dist/mcp/index.d.ts.map +1 -1
  55. package/dist/mcp/manager.d.ts +4 -2
  56. package/dist/mcp/manager.d.ts.map +1 -1
  57. package/dist/mcp/types.d.ts +30 -3
  58. package/dist/mcp/types.d.ts.map +1 -1
  59. package/dist/onboarding/onboarding-inline.d.ts +2 -0
  60. package/dist/onboarding/onboarding-inline.d.ts.map +1 -1
  61. package/dist/onboarding/packs.d.ts +1 -0
  62. package/dist/onboarding/packs.d.ts.map +1 -1
  63. package/dist/onboarding/settings.d.ts +37 -2
  64. package/dist/onboarding/settings.d.ts.map +1 -1
  65. package/dist/permissions-S3LGXIDB.js +3 -0
  66. package/dist/{permissions-CVXKYIWR.js.map → permissions-S3LGXIDB.js.map} +1 -1
  67. package/dist/permissions-VGABAVGD.cjs +40 -0
  68. package/dist/{permissions-2HIUSRQN.cjs.map → permissions-VGABAVGD.cjs.map} +1 -1
  69. package/dist/permissions.d.ts.map +1 -1
  70. package/dist/providers/claude-max.d.ts +13 -0
  71. package/dist/providers/claude-max.d.ts.map +1 -1
  72. package/dist/providers/openai-codex.d.ts +1 -0
  73. package/dist/providers/openai-codex.d.ts.map +1 -1
  74. package/dist/tool-names.d.ts +68 -0
  75. package/dist/tool-names.d.ts.map +1 -0
  76. package/dist/tools/ast-smart-edit.d.ts +77 -5
  77. package/dist/tools/ast-smart-edit.d.ts.map +1 -1
  78. package/dist/tools/index.d.ts +2 -2
  79. package/dist/tools/index.d.ts.map +1 -1
  80. package/dist/tools/string-replace-lsp.d.ts +15 -0
  81. package/dist/tools/string-replace-lsp.d.ts.map +1 -1
  82. package/dist/tools/subagent.d.ts.map +1 -1
  83. package/dist/tools/utils.d.ts +4 -2
  84. package/dist/tools/utils.d.ts.map +1 -1
  85. package/dist/tui/command-dispatch.d.ts.map +1 -1
  86. package/dist/tui/commands/clone.d.ts +29 -0
  87. package/dist/tui/commands/clone.d.ts.map +1 -0
  88. package/dist/tui/commands/custom-providers.d.ts +8 -0
  89. package/dist/tui/commands/custom-providers.d.ts.map +1 -0
  90. package/dist/tui/commands/index.d.ts +3 -1
  91. package/dist/tui/commands/index.d.ts.map +1 -1
  92. package/dist/tui/commands/mcp.d.ts.map +1 -1
  93. package/dist/tui/commands/models-pack.d.ts +4 -0
  94. package/dist/tui/commands/models-pack.d.ts.map +1 -1
  95. package/dist/tui/commands/om.d.ts.map +1 -1
  96. package/dist/tui/commands/report-issue.d.ts +3 -0
  97. package/dist/tui/commands/report-issue.d.ts.map +1 -0
  98. package/dist/tui/commands/resource.d.ts.map +1 -1
  99. package/dist/tui/commands/settings.d.ts.map +1 -1
  100. package/dist/tui/commands/threads.d.ts +1 -0
  101. package/dist/tui/commands/threads.d.ts.map +1 -1
  102. package/dist/tui/components/ask-question-inline.d.ts +3 -0
  103. package/dist/tui/components/ask-question-inline.d.ts.map +1 -1
  104. package/dist/tui/components/custom-editor.d.ts +1 -1
  105. package/dist/tui/components/custom-editor.d.ts.map +1 -1
  106. package/dist/tui/components/help-overlay.d.ts.map +1 -1
  107. package/dist/tui/components/plan-approval-inline.d.ts.map +1 -1
  108. package/dist/tui/components/settings.d.ts +2 -0
  109. package/dist/tui/components/settings.d.ts.map +1 -1
  110. package/dist/tui/components/subagent-execution.d.ts +6 -1
  111. package/dist/tui/components/subagent-execution.d.ts.map +1 -1
  112. package/dist/tui/components/thread-selector.d.ts +6 -0
  113. package/dist/tui/components/thread-selector.d.ts.map +1 -1
  114. package/dist/tui/components/tool-execution-enhanced.d.ts +1 -0
  115. package/dist/tui/components/tool-execution-enhanced.d.ts.map +1 -1
  116. package/dist/tui/components/tool-validation-error.d.ts.map +1 -1
  117. package/dist/tui/handlers/message.d.ts.map +1 -1
  118. package/dist/tui/handlers/prompts.d.ts +6 -0
  119. package/dist/tui/handlers/prompts.d.ts.map +1 -1
  120. package/dist/tui/handlers/subagent.d.ts.map +1 -1
  121. package/dist/tui/mastra-tui.d.ts +14 -5
  122. package/dist/tui/mastra-tui.d.ts.map +1 -1
  123. package/dist/tui/render-messages.d.ts.map +1 -1
  124. package/dist/tui/setup.d.ts.map +1 -1
  125. package/dist/tui/state.d.ts +4 -5
  126. package/dist/tui/state.d.ts.map +1 -1
  127. package/dist/tui.cjs +19 -19
  128. package/dist/tui.js +2 -2
  129. package/dist/utils/debug-log.d.ts +12 -0
  130. package/dist/utils/debug-log.d.ts.map +1 -0
  131. package/dist/utils/plans.d.ts +7 -0
  132. package/dist/utils/plans.d.ts.map +1 -0
  133. package/dist/utils/update-check.d.ts +40 -0
  134. package/dist/utils/update-check.d.ts.map +1 -0
  135. package/package.json +8 -8
  136. package/dist/chunk-C4X3C2DL.cjs.map +0 -1
  137. package/dist/chunk-K4WJUBEC.cjs.map +0 -1
  138. package/dist/chunk-M5LKPQB4.js.map +0 -1
  139. package/dist/chunk-MT3YCFCC.cjs.map +0 -1
  140. package/dist/chunk-REVOTI2T.js.map +0 -1
  141. package/dist/chunk-U5A7TFNT.js.map +0 -1
  142. package/dist/chunk-X3BGE7CL.js.map +0 -1
  143. package/dist/chunk-Z4QRXVST.cjs.map +0 -1
  144. package/dist/docs/SKILL.md +0 -30
  145. package/dist/docs/assets/SOURCE_MAP.json +0 -11
  146. package/dist/docs/references/docs-mastra-code-configuration.md +0 -299
  147. package/dist/docs/references/docs-mastra-code-customization.md +0 -228
  148. package/dist/docs/references/docs-mastra-code-modes.md +0 -104
  149. package/dist/docs/references/docs-mastra-code-overview.md +0 -135
  150. package/dist/docs/references/docs-mastra-code-tools.md +0 -229
  151. package/dist/docs/references/reference-mastra-code-createMastraCode.md +0 -108
  152. package/dist/permissions-2HIUSRQN.cjs +0 -40
  153. package/dist/permissions-CVXKYIWR.js +0 -3
  154. package/dist/tui/commands/models.d.ts +0 -3
  155. package/dist/tui/commands/models.d.ts.map +0 -1
@@ -1,22 +1,20 @@
1
1
  'use strict';
2
2
 
3
- var chunkK4WJUBEC_cjs = require('./chunk-K4WJUBEC.cjs');
3
+ var chunkAJEYT7X3_cjs = require('./chunk-AJEYT7X3.cjs');
4
4
  var chunkS5ZLN7DR_cjs = require('./chunk-S5ZLN7DR.cjs');
5
- var chunkMT3YCFCC_cjs = require('./chunk-MT3YCFCC.cjs');
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 logger = require('@mastra/core/logger');
10
- var fs4 = require('fs');
8
+ var llm = require('@mastra/core/llm');
9
+ var fs3 = require('fs');
11
10
  var os = require('os');
12
- var path = require('path');
11
+ var path3 = require('path');
13
12
  var memory = require('@mastra/memory');
14
13
  var anthropic = require('@ai-sdk/anthropic');
15
- var workspace = require('@mastra/core/workspace');
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 fs4__namespace = /*#__PURE__*/_interopNamespace(fs4);
39
+ var fs3__namespace = /*#__PURE__*/_interopNamespace(fs3);
42
40
  var os__namespace = /*#__PURE__*/_interopNamespace(os);
43
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
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 = path.join(basePath, filename);
295
- if (fs4.existsSync(fullPath)) {
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 = path.join(home, location);
303
+ const basePath = path3.join(home, location);
306
304
  const filePath = findInstructionFile(basePath);
307
305
  if (filePath) {
308
306
  try {
309
- const content = fs4.readFileSync(filePath, "utf-8").trim();
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 ? path.join(projectPath, location) : projectPath;
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 = fs4.readFileSync(filePath, "utf-8").trim();
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
- sections.push(`
357
- **view** \u2014 Read file contents or list directories
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 \`view_range\` for large files to read specific sections.
360
- - For directory listings, this shows 2 levels deep.
361
- - Example: To check lines 50-100 of a large file: \`view("src/big-file.ts", { view_range: [50, 100] })\`
362
-
363
- **search_content** \u2014 Search file contents using regex
364
- - Use this for ALL content search (finding functions, variables, error messages, imports, etc.)
365
- - NEVER use \`execute_command\` with grep, rg, or ag. Always use the search_content tool.
366
- - Supports regex patterns, file type filtering, and context lines.
367
- - Example: Find where a function is defined: \`search_content("function handleSubmit", { glob: "**/*.ts" })\`
368
- - Example: Find all imports of a module: \`search_content("from ['\\"]express['\\"]", { glob: "**/*.ts" })\`
369
-
370
- **find_files** \u2014 Find files by name pattern
371
- - Use this to find files matching a pattern (e.g., "**/*.ts", "src/**/test*").
372
- - NEVER use \`execute_command\` with find or ls for file search. Always use find_files.
373
- - Respects .gitignore automatically.
374
- - Example: Find all test files: \`find_files("**/*.test.ts")\`
375
- - Example: Find config files: \`find_files("**/config.{js,ts,json}")\`
376
-
377
- **execute_command** \u2014 Run shell commands
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
- - Do NOT use for: file reading (use view), file search (use search_content/find_files), file editing (use string_replace_lsp/write_file).
380
- - Commands have a 30-second default timeout. Use the \`timeout\` parameter for longer-running commands.
381
- - Pipe to \`| tail -N\` for commands with long output \u2014 the full output streams to the user, only the last N lines are returned to you. If you're building any kind of package you should be tailing.
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 view tool instead.`);
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
- sections.push(`
386
- **string_replace_lsp** \u2014 Edit files by replacing exact text
387
- - You MUST read a file with \`view\` before editing it.
388
- - \`old_str\` must be an exact match of existing text in the file.
389
- - Provide enough surrounding context in \`old_str\` to make it unique.
390
- - For creating new files, use \`write_file\` instead.
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
- **write_file** \u2014 Create new files or overwrite existing ones
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 \`view\`.
397
- - NEVER create files unless necessary. Prefer editing existing files.`);
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
- sections.push(`
401
- **web_search** / **web_extract** \u2014 Search the web / extract page content
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
- sections.push(`
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
- if (modeId === "plan") {
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
- sections.push(`
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 = chunkK4WJUBEC_cjs.hasTavilyKey() || !!modelId && modelId.startsWith("anthropic/");
447
- const toolGuidance = buildToolGuidance(ctx.modeId, { hasWebSearch });
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 chunkK4WJUBEC_cjs.resolveModel(state?.observerModelId ?? DEFAULT_OM_MODEL_ID);
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 chunkK4WJUBEC_cjs.resolveModel(state?.reflectorModelId ?? DEFAULT_OM_MODEL_ID);
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 projectPath = state?.projectPath ?? "";
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
- view: viewTool,
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 (modeId !== "plan") {
584
- tools.string_replace_lsp = chunkK4WJUBEC_cjs.stringReplaceLspTool;
585
- tools.ast_smart_edit = chunkK4WJUBEC_cjs.astSmartEditTool;
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
- return tools;
600
- };
601
- }
602
- var mastraCodeLocalSkillsPath = path__namespace.default.join(process.cwd(), ".mastracode", "skills");
603
- var claudeLocalSkillsPath = path__namespace.default.join(process.cwd(), ".claude", "skills");
604
- var mastraCodeGlobalSkillsPath = path__namespace.default.join(os__namespace.default.homedir(), ".mastracode", "skills");
605
- var claudeGlobalSkillsPath = path__namespace.default.join(os__namespace.default.homedir(), ".claude", "skills");
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
- try {
617
- const entries = fs4__namespace.default.readdirSync(skillsDir, { withFileTypes: true });
618
- for (const entry of entries) {
619
- if (entry.isSymbolicLink()) {
620
- const linkPath = path__namespace.default.join(skillsDir, entry.name);
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
- return paths;
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 path__namespace.join(projectDir, ".mastracode", "hooks.json");
660
+ return path3__namespace.join(projectDir, ".mastracode", "hooks.json");
695
661
  }
696
662
  function getGlobalHooksPath() {
697
- return path__namespace.join(os__namespace.homedir(), ".mastracode", "hooks.json");
663
+ return path3__namespace.join(os__namespace.homedir(), ".mastracode", "hooks.json");
698
664
  }
699
665
  function loadSingleConfig(filePath) {
700
666
  try {
701
- if (!fs4__namespace.existsSync(filePath)) return {};
702
- const raw = fs4__namespace.readFileSync(filePath, "utf-8");
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 path__namespace.join(projectDir, ".mastracode", "mcp.json");
965
+ return path3__namespace.join(projectDir, ".mastracode", "mcp.json");
1000
966
  }
1001
967
  function getGlobalMcpPath() {
1002
- return path__namespace.join(os__namespace.homedir(), ".mastracode", "mcp.json");
968
+ return path3__namespace.join(os__namespace.homedir(), ".mastracode", "mcp.json");
1003
969
  }
1004
970
  function getClaudeSettingsPath(projectDir) {
1005
- return path__namespace.join(projectDir, ".claude", "settings.local.json");
971
+ return path3__namespace.join(projectDir, ".claude", "settings.local.json");
1006
972
  }
1007
973
  function loadSingleConfig2(filePath) {
1008
974
  try {
1009
- if (!fs4__namespace.existsSync(filePath)) return {};
1010
- const raw = fs4__namespace.readFileSync(filePath, "utf-8");
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 (!fs4__namespace.existsSync(filePath)) return {};
1020
- const raw = fs4__namespace.readFileSync(filePath, "utf-8");
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
- if (isValidServerConfig(entry)) {
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
- command: entry.command,
1040
- args: Array.isArray(entry.args) ? entry.args : void 0,
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
- if (Object.keys(servers).length === 0) return {};
1046
- return { mcpServers: servers };
1047
- }
1048
- function isValidServerConfig(raw) {
1049
- if (!raw || typeof raw !== "object") return false;
1050
- const obj = raw;
1051
- return typeof obj.command === "string";
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 (Object.keys(merged).length === 0) return {};
1063
- return { mcpServers: merged };
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
- defs[name] = { command: cfg.command, args: cfg.args, env: cfg.env };
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
- return config.mcpServers !== void 0 && Object.keys(config.mcpServers).length > 0;
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 = path__namespace.default.join(os__namespace.default.homedir(), ".cache", "mastra");
1207
- var CACHE_FILE = path__namespace.default.join(CACHE_DIR, "gateway-refresh-time");
1208
- var GLOBAL_PROVIDER_REGISTRY_JSON = path__namespace.default.join(CACHE_DIR, "provider-registry.json");
1209
- var GLOBAL_PROVIDER_TYPES_DTS = path__namespace.default.join(CACHE_DIR, "provider-types.generated.d.ts");
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 fs4__namespace.default.promises.writeFile(tempPath, content, "utf-8");
1217
- await fs4__namespace.default.promises.rename(tempPath, filePath);
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 fs4__namespace.default.promises.unlink(tempPath);
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 (!fs4__namespace.default.existsSync(CACHE_FILE)) {
1320
+ if (!fs3__namespace.default.existsSync(CACHE_FILE)) {
1286
1321
  return null;
1287
1322
  }
1288
- const timestamp = fs4__namespace.default.readFileSync(CACHE_FILE, "utf-8").trim();
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 (!fs4__namespace.default.existsSync(CACHE_DIR)) {
1297
- fs4__namespace.default.mkdirSync(CACHE_DIR, { recursive: true });
1331
+ if (!fs3__namespace.default.existsSync(CACHE_DIR)) {
1332
+ fs3__namespace.default.mkdirSync(CACHE_DIR, { recursive: true });
1298
1333
  }
1299
- fs4__namespace.default.writeFileSync(CACHE_FILE, date.getTime().toString(), "utf-8");
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 fs4__namespace.default.promises.mkdir(CACHE_DIR, { recursive: true });
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
- chunkK4WJUBEC_cjs.setAuthStorage(authStorage);
1403
- chunkK4WJUBEC_cjs.setAuthStorage2(authStorage);
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 = chunkK4WJUBEC_cjs.loadSettings();
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 codeAgentInstance = new agent.Agent({
1452
+ const codeAgent = new agent.Agent({
1418
1453
  id: "code-agent",
1419
1454
  name: "Code Agent",
1420
1455
  instructions: getDynamicInstructions,
1421
- model: chunkK4WJUBEC_cjs.getDynamicModel,
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 = chunkK4WJUBEC_cjs.createViewTool(project.rootPath);
1437
- const grepTool = chunkK4WJUBEC_cjs.createGrepTool(project.rootPath);
1438
- const globTool = chunkK4WJUBEC_cjs.createGlobTool(project.rootPath);
1439
- const executeCommandTool = chunkK4WJUBEC_cjs.createExecuteCommandTool(project.rootPath);
1440
- const writeFileTool = chunkK4WJUBEC_cjs.createWriteFileTool(project.rootPath);
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: chunkK4WJUBEC_cjs.exploreSubagent.id,
1449
- name: chunkK4WJUBEC_cjs.exploreSubagent.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: chunkK4WJUBEC_cjs.exploreSubagent.instructions,
1481
+ instructions: chunkAJEYT7X3_cjs.exploreSubagent.instructions,
1452
1482
  tools: readOnlyTools
1453
1483
  },
1454
1484
  {
1455
- id: chunkK4WJUBEC_cjs.planSubagent.id,
1456
- name: chunkK4WJUBEC_cjs.planSubagent.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: chunkK4WJUBEC_cjs.planSubagent.instructions,
1488
+ instructions: chunkAJEYT7X3_cjs.planSubagent.instructions,
1459
1489
  tools: readOnlyTools
1460
1490
  },
1461
1491
  {
1462
- id: chunkK4WJUBEC_cjs.executeSubagent.id,
1463
- name: chunkK4WJUBEC_cjs.executeSubagent.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: chunkK4WJUBEC_cjs.executeSubagent.instructions,
1495
+ instructions: chunkAJEYT7X3_cjs.executeSubagent.instructions,
1466
1496
  tools: {
1467
1497
  ...readOnlyTools,
1468
- string_replace_lsp: chunkK4WJUBEC_cjs.stringReplaceLspTool,
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: chunkK4WJUBEC_cjs.mastra.purple,
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: chunkK4WJUBEC_cjs.mastra.blue,
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: chunkK4WJUBEC_cjs.mastra.green,
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
- const builtinPacks = chunkK4WJUBEC_cjs.getAvailableModePacks(startupAccess);
1515
- const builtinOmPacks = chunkK4WJUBEC_cjs.getAvailableOmPacks(startupAccess);
1516
- const effectiveDefaults = chunkK4WJUBEC_cjs.resolveModelDefaults(globalSettings, builtinPacks);
1517
- const effectiveOmModel = chunkK4WJUBEC_cjs.resolveOmModel(globalSettings, builtinOmPacks);
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: chunkK4WJUBEC_cjs.resolveModel,
1551
- toolCategoryResolver: chunkMT3YCFCC_cjs.getToolCategory,
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: () => chunkK4WJUBEC_cjs.loadSettings().modelUseCounts,
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: chunkK4WJUBEC_cjs.acquireThreadLock,
1573
- release: chunkK4WJUBEC_cjs.releaseThreadLock
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-Z4QRXVST.cjs.map
1590
- //# sourceMappingURL=chunk-Z4QRXVST.cjs.map
1663
+ //# sourceMappingURL=chunk-MBPGUMYQ.cjs.map
1664
+ //# sourceMappingURL=chunk-MBPGUMYQ.cjs.map