mastracode 0.2.0 → 0.3.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 (166) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/README.md +9 -1
  3. package/dist/agents/instructions.d.ts.map +1 -1
  4. package/dist/agents/prompts/base.d.ts +2 -0
  5. package/dist/agents/prompts/base.d.ts.map +1 -1
  6. package/dist/agents/prompts/build.d.ts +1 -1
  7. package/dist/agents/prompts/build.d.ts.map +1 -1
  8. package/dist/agents/prompts/index.d.ts +1 -2
  9. package/dist/agents/prompts/index.d.ts.map +1 -1
  10. package/dist/agents/prompts/plan.d.ts +1 -1
  11. package/dist/agents/prompts/plan.d.ts.map +1 -1
  12. package/dist/agents/prompts/tool-guidance.d.ts +11 -0
  13. package/dist/agents/prompts/tool-guidance.d.ts.map +1 -0
  14. package/dist/agents/workspace.d.ts.map +1 -1
  15. package/dist/auth/storage.d.ts +0 -48
  16. package/dist/auth/storage.d.ts.map +1 -1
  17. package/dist/{chunk-LVGWM7ZS.cjs → chunk-7K5VFY2N.cjs} +768 -1373
  18. package/dist/chunk-7K5VFY2N.cjs.map +1 -0
  19. package/dist/chunk-7TFV3VBB.cjs +8823 -0
  20. package/dist/chunk-7TFV3VBB.cjs.map +1 -0
  21. package/dist/chunk-C6XKRHRK.cjs +853 -0
  22. package/dist/chunk-C6XKRHRK.cjs.map +1 -0
  23. package/dist/{chunk-7V6U7OKQ.js → chunk-HHX6BKLR.js} +234 -121
  24. package/dist/chunk-HHX6BKLR.js.map +1 -0
  25. package/dist/{chunk-FYTZFUHD.js → chunk-LYETHS2L.js} +6389 -5481
  26. package/dist/chunk-LYETHS2L.js.map +1 -0
  27. package/dist/{chunk-BYMDWH2E.js → chunk-V4HZ2AVV.js} +729 -1332
  28. package/dist/chunk-V4HZ2AVV.js.map +1 -0
  29. package/dist/chunk-VRZZSUQE.js +835 -0
  30. package/dist/chunk-VRZZSUQE.js.map +1 -0
  31. package/dist/{chunk-QDLLGD43.cjs → chunk-VZFPT5N7.cjs} +274 -161
  32. package/dist/chunk-VZFPT5N7.cjs.map +1 -0
  33. package/dist/cli.cjs +64 -21
  34. package/dist/cli.cjs.map +1 -1
  35. package/dist/cli.js +61 -18
  36. package/dist/cli.js.map +1 -1
  37. package/dist/index.cjs +2 -2
  38. package/dist/index.d.ts +6 -7
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/onboarding/index.d.ts +7 -0
  42. package/dist/onboarding/index.d.ts.map +1 -0
  43. package/dist/onboarding/onboarding-inline.d.ts +95 -0
  44. package/dist/onboarding/onboarding-inline.d.ts.map +1 -0
  45. package/dist/onboarding/packs.d.ts +46 -0
  46. package/dist/onboarding/packs.d.ts.map +1 -0
  47. package/dist/onboarding/settings.d.ts +110 -0
  48. package/dist/onboarding/settings.d.ts.map +1 -0
  49. package/dist/storage-52Y5MKTG.js +3 -0
  50. package/dist/storage-52Y5MKTG.js.map +1 -0
  51. package/dist/storage-JFFX7LJJ.cjs +24 -0
  52. package/dist/storage-JFFX7LJJ.cjs.map +1 -0
  53. package/dist/tools/string-replace-lsp.d.ts.map +1 -1
  54. package/dist/tui/command-dispatch.d.ts +8 -0
  55. package/dist/tui/command-dispatch.d.ts.map +1 -0
  56. package/dist/tui/commands/cost.d.ts +3 -0
  57. package/dist/tui/commands/cost.d.ts.map +1 -0
  58. package/dist/tui/commands/diff.d.ts +3 -0
  59. package/dist/tui/commands/diff.d.ts.map +1 -0
  60. package/dist/tui/commands/exit.d.ts +3 -0
  61. package/dist/tui/commands/exit.d.ts.map +1 -0
  62. package/dist/tui/commands/help.d.ts +3 -0
  63. package/dist/tui/commands/help.d.ts.map +1 -0
  64. package/dist/tui/commands/hooks.d.ts +3 -0
  65. package/dist/tui/commands/hooks.d.ts.map +1 -0
  66. package/dist/tui/commands/index.d.ts +27 -0
  67. package/dist/tui/commands/index.d.ts.map +1 -0
  68. package/dist/tui/commands/login.d.ts +3 -0
  69. package/dist/tui/commands/login.d.ts.map +1 -0
  70. package/dist/tui/commands/mcp.d.ts +3 -0
  71. package/dist/tui/commands/mcp.d.ts.map +1 -0
  72. package/dist/tui/commands/mode.d.ts +3 -0
  73. package/dist/tui/commands/mode.d.ts.map +1 -0
  74. package/dist/tui/commands/models-pack.d.ts +3 -0
  75. package/dist/tui/commands/models-pack.d.ts.map +1 -0
  76. package/dist/tui/commands/models.d.ts +3 -0
  77. package/dist/tui/commands/models.d.ts.map +1 -0
  78. package/dist/tui/commands/name.d.ts +3 -0
  79. package/dist/tui/commands/name.d.ts.map +1 -0
  80. package/dist/tui/commands/new.d.ts +3 -0
  81. package/dist/tui/commands/new.d.ts.map +1 -0
  82. package/dist/tui/commands/om.d.ts +3 -0
  83. package/dist/tui/commands/om.d.ts.map +1 -0
  84. package/dist/tui/commands/permissions.d.ts +3 -0
  85. package/dist/tui/commands/permissions.d.ts.map +1 -0
  86. package/dist/tui/commands/resource.d.ts +3 -0
  87. package/dist/tui/commands/resource.d.ts.map +1 -0
  88. package/dist/tui/commands/review.d.ts +3 -0
  89. package/dist/tui/commands/review.d.ts.map +1 -0
  90. package/dist/tui/commands/sandbox.d.ts +3 -0
  91. package/dist/tui/commands/sandbox.d.ts.map +1 -0
  92. package/dist/tui/commands/settings.d.ts +3 -0
  93. package/dist/tui/commands/settings.d.ts.map +1 -0
  94. package/dist/tui/commands/setup.d.ts +3 -0
  95. package/dist/tui/commands/setup.d.ts.map +1 -0
  96. package/dist/tui/commands/skills.d.ts +3 -0
  97. package/dist/tui/commands/skills.d.ts.map +1 -0
  98. package/dist/tui/commands/subagents.d.ts +3 -0
  99. package/dist/tui/commands/subagents.d.ts.map +1 -0
  100. package/dist/tui/commands/think.d.ts +3 -0
  101. package/dist/tui/commands/think.d.ts.map +1 -0
  102. package/dist/tui/commands/thread-tag-dir.d.ts +3 -0
  103. package/dist/tui/commands/thread-tag-dir.d.ts.map +1 -0
  104. package/dist/tui/commands/threads.d.ts +3 -0
  105. package/dist/tui/commands/threads.d.ts.map +1 -0
  106. package/dist/tui/commands/types.d.ts +28 -0
  107. package/dist/tui/commands/types.d.ts.map +1 -0
  108. package/dist/tui/commands/yolo.d.ts +3 -0
  109. package/dist/tui/commands/yolo.d.ts.map +1 -0
  110. package/dist/tui/components/banner.d.ts +9 -0
  111. package/dist/tui/components/banner.d.ts.map +1 -0
  112. package/dist/tui/components/help-overlay.d.ts +15 -0
  113. package/dist/tui/components/help-overlay.d.ts.map +1 -0
  114. package/dist/tui/components/model-selector.d.ts +3 -0
  115. package/dist/tui/components/model-selector.d.ts.map +1 -1
  116. package/dist/tui/components/om-progress.d.ts +4 -30
  117. package/dist/tui/components/om-progress.d.ts.map +1 -1
  118. package/dist/tui/components/settings.d.ts +5 -0
  119. package/dist/tui/components/settings.d.ts.map +1 -1
  120. package/dist/tui/components/tool-execution-enhanced.d.ts.map +1 -1
  121. package/dist/tui/display.d.ts +12 -0
  122. package/dist/tui/display.d.ts.map +1 -0
  123. package/dist/tui/event-dispatch.d.ts +11 -0
  124. package/dist/tui/event-dispatch.d.ts.map +1 -0
  125. package/dist/tui/handlers/agent-lifecycle.d.ts +6 -0
  126. package/dist/tui/handlers/agent-lifecycle.d.ts.map +1 -0
  127. package/dist/tui/handlers/index.d.ts +8 -0
  128. package/dist/tui/handlers/index.d.ts.map +1 -0
  129. package/dist/tui/handlers/message.d.ts +6 -0
  130. package/dist/tui/handlers/message.d.ts.map +1 -0
  131. package/dist/tui/handlers/om.d.ts +11 -0
  132. package/dist/tui/handlers/om.d.ts.map +1 -0
  133. package/dist/tui/handlers/prompts.d.ts +20 -0
  134. package/dist/tui/handlers/prompts.d.ts.map +1 -0
  135. package/dist/tui/handlers/subagent.d.ts +6 -0
  136. package/dist/tui/handlers/subagent.d.ts.map +1 -0
  137. package/dist/tui/handlers/tool.d.ts +30 -0
  138. package/dist/tui/handlers/tool.d.ts.map +1 -0
  139. package/dist/tui/handlers/types.d.ts +33 -0
  140. package/dist/tui/handlers/types.d.ts.map +1 -0
  141. package/dist/tui/mastra-tui.d.ts +9 -221
  142. package/dist/tui/mastra-tui.d.ts.map +1 -1
  143. package/dist/tui/render-messages.d.ts +22 -0
  144. package/dist/tui/render-messages.d.ts.map +1 -0
  145. package/dist/tui/setup.d.ts +17 -0
  146. package/dist/tui/setup.d.ts.map +1 -0
  147. package/dist/tui/shell.d.ts +3 -0
  148. package/dist/tui/shell.d.ts.map +1 -0
  149. package/dist/tui/state.d.ts +4 -24
  150. package/dist/tui/state.d.ts.map +1 -1
  151. package/dist/tui/status-line.d.ts +7 -0
  152. package/dist/tui/status-line.d.ts.map +1 -0
  153. package/dist/tui.cjs +17 -17
  154. package/dist/tui.js +2 -2
  155. package/dist/utils/project.d.ts +37 -9
  156. package/dist/utils/project.d.ts.map +1 -1
  157. package/dist/utils/storage-factory.d.ts +21 -0
  158. package/dist/utils/storage-factory.d.ts.map +1 -0
  159. package/package.json +7 -6
  160. package/dist/chunk-7V6U7OKQ.js.map +0 -1
  161. package/dist/chunk-BQ4ZKTYN.cjs +0 -7915
  162. package/dist/chunk-BQ4ZKTYN.cjs.map +0 -1
  163. package/dist/chunk-BYMDWH2E.js.map +0 -1
  164. package/dist/chunk-FYTZFUHD.js.map +0 -1
  165. package/dist/chunk-LVGWM7ZS.cjs.map +0 -1
  166. package/dist/chunk-QDLLGD43.cjs.map +0 -1
@@ -1,10 +1,10 @@
1
- import { AuthStorage, setAuthStorage, setAuthStorage2, detectProject, getResourceIdOverride, getUserId, getStorageConfig, getDynamicModel, createViewTool, createGrepTool, createGlobTool, createExecuteCommandTool, createWriteFileTool, releaseThreadLock, acquireThreadLock, mastra, resolveModel, exploreSubagent, planSubagent, stringReplaceLspTool, executeSubagent, astSmartEditTool, hasTavilyKey, createWebSearchTool, createWebExtractTool, requestSandboxAccessTool, getOmScope } from './chunk-BYMDWH2E.js';
1
+ import { setAuthStorage, setAuthStorage2, loadSettings, getDynamicModel, createViewTool, createGrepTool, createGlobTool, createExecuteCommandTool, createWriteFileTool, getAvailableModePacks, getAvailableOmPacks, resolveModelDefaults, resolveOmModel, mastra, exploreSubagent, planSubagent, stringReplaceLspTool, executeSubagent, releaseThreadLock, acquireThreadLock, resolveModel, astSmartEditTool, hasTavilyKey, createWebSearchTool, createWebExtractTool, requestSandboxAccessTool } from './chunk-V4HZ2AVV.js';
2
+ import { AuthStorage, detectProject, getResourceIdOverride, getStorageConfig, getOmScope, getDatabasePath } from './chunk-VRZZSUQE.js';
2
3
  import { getToolCategory } from './chunk-U5A7TFNT.js';
3
4
  import { Mastra } from '@mastra/core';
4
5
  import { Agent } from '@mastra/core/agent';
5
- import { Harness, taskCheckTool, taskWriteTool } from '@mastra/core/harness';
6
+ import { taskCheckTool, taskWriteTool, Harness } from '@mastra/core/harness';
6
7
  import { noopLogger } from '@mastra/core/logger';
7
- import { LibSQLStore } from '@mastra/libsql';
8
8
  import * as fs4 from 'fs';
9
9
  import fs4__default, { readFileSync, existsSync } from 'fs';
10
10
  import * as os from 'os';
@@ -18,6 +18,8 @@ import { spawn } from 'child_process';
18
18
  import { MCPClient } from '@mastra/mcp';
19
19
  import { z } from 'zod';
20
20
  import { ModelsDevGateway, NetlifyGateway } from '@mastra/core/llm';
21
+ import { LibSQLStore } from '@mastra/libsql';
22
+ import { PostgresStore } from '@mastra/pg';
21
23
 
22
24
  // src/agents/prompts/base.ts
23
25
  function buildBasePrompt(ctx) {
@@ -35,83 +37,15 @@ Current mode: ${ctx.mode}
35
37
  - Your output is displayed on a command line interface. Keep responses concise.
36
38
  - Use Github-flavored markdown for formatting.
37
39
  - Only use emojis if the user explicitly requests it.
38
- - Do NOT use tools to communicate with the user. All text you output is displayed directly.
40
+ - Use tool calls for actions (editing files, running commands, searching, etc.). Use text for communication \u2014 talk to the user in text, not via tools, except for communication tools like \`submit_plan\`, \`ask_user\`, and \`task_write\`.
39
41
  - Prioritize technical accuracy over validating the user's beliefs. Be direct and objective. Respectful correction is more valuable than false agreement.
40
42
 
41
- # Tool Usage Rules
42
-
43
- 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.
44
-
45
- You have access to the following tools. Use the RIGHT tool for the job:
46
-
47
- **view** \u2014 Read file contents or list directories
48
- - Use this to read files before editing them. NEVER propose changes to code you haven't read.
49
- - Use \`view_range\` for large files to read specific sections.
50
- - For directory listings, this shows 2 levels deep.
51
- - Example: To check lines 50-100 of a large file: \`view("src/big-file.ts", { view_range: [50, 100] })\`
52
-
53
- **grep** \u2014 Search file contents using regex
54
- - Use this for ALL content search (finding functions, variables, error messages, imports, etc.)
55
- - NEVER use \`execute_command\` with grep, rg, or ag. Always use the grep tool.
56
- - Supports regex patterns, file type filtering, and context lines.
57
- - Example: Find where a function is defined: \`grep("function handleSubmit", { glob: "**/*.ts" })\`
58
- - Example: Find all imports of a module: \`grep("from ['"]express['"]", { glob: "**/*.ts" })\`
59
-
60
- **glob** \u2014 Find files by name pattern
61
- - Use this to find files matching a pattern (e.g., "**/*.ts", "src/**/test*").
62
- - NEVER use \`execute_command\` with find or ls for file search. Always use glob.
63
- - Respects .gitignore automatically.
64
- - Example: Find all test files: \`glob("**/*.test.ts")\`
65
- - Example: Find config files: \`glob("**/config.{js,ts,json}")\`
66
-
67
- **string_replace_lsp** \u2014 Edit files by replacing exact text
68
- - You MUST read a file with \`view\` before editing it.
69
- - \`old_str\` must be an exact match of existing text in the file.
70
- - Provide enough surrounding context in \`old_str\` to make it unique.
71
- - For creating new files, use \`write_file\` instead.
72
- - Good: Include 2-3 lines of surrounding context to ensure uniqueness.
73
- - Bad: Using just \`return true;\` \u2014 too common, will match multiple places.
74
-
75
- **write_file** \u2014 Create new files or overwrite existing ones
76
- - Use this to create new files.
77
- - If overwriting an existing file, you MUST have read it first with \`view\`.
78
- - NEVER create files unless necessary. Prefer editing existing files.
79
-
80
- **execute_command** \u2014 Run shell commands
81
- - Use for: git, npm/pnpm, docker, build tools, test runners, and other terminal operations.
82
- - Do NOT use for: file reading (use view), file search (use grep/glob), file editing (use string_replace_lsp/write_file).
83
- - Commands have a 30-second default timeout. Use the \`timeout\` parameter for longer-running commands.
84
- - 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.
85
- - Good: Run independent commands in parallel when possible.
86
- - Bad: Running \`cat file.txt\` \u2014 use the view tool instead.
87
-
88
- **web_search** / **web_extract** \u2014 Search the web / extract page content
89
- - Use for looking up documentation, error messages, package APIs.
90
- - Available depending on the model and API keys configured.
91
-
92
- **task_write** \u2014 Track tasks for complex multi-step work
93
- - Use when a task requires 3 or more distinct steps or actions.
94
- - Pass the FULL task list each time (replaces previous list).
95
- - Mark tasks \`in_progress\` BEFORE starting work. Only ONE task should be \`in_progress\` at a time.
96
- - Mark tasks \`completed\` IMMEDIATELY after finishing each task. Do not batch completions.
97
- - Each task has: content (imperative form), status (pending|in_progress|completed), activeForm (present continuous form shown during execution).
98
-
99
- **task_check** \u2014 Check completion status of tasks
100
- - Use this BEFORE deciding you're done with a task to verify all tasks are completed.
101
- - Returns the number of completed, in progress, and pending tasks.
102
- - If any tasks remain incomplete, continue working on them.
103
- - IMPORTANT: Always check task completion before ending work on a complex task.
104
-
105
- **ask_user** \u2014 Ask the user a structured question
106
- - Use when you need clarification, want to validate assumptions, or need the user to make a decision.
107
- - Provide clear, specific questions. End with a question mark.
108
- - Include options (2-4 choices) for structured decisions. Omit options for open-ended questions.
109
- - Don't use this for simple yes/no \u2014 just ask in your text response.
43
+ ${ctx.toolGuidance}
110
44
 
111
45
  # How to Work on Tasks
112
46
 
113
47
  ## Start by Understanding
114
- - Read relevant code before making changes. Use grep/glob to find related files.
48
+ - Read relevant code before making changes. Use search_content/find_files to find related files.
115
49
  - For unfamiliar codebases, check git log to understand recent changes and patterns.
116
50
  - Identify existing conventions (naming, structure, error handling) and follow them.
117
51
 
@@ -147,7 +81,7 @@ You have access to the following tools. Use the RIGHT tool for the job:
147
81
  Don't commit files likely to contain secrets (\`.env\`, \`*.key\`, \`credentials.json\`). Warn if asked.
148
82
 
149
83
  ## Commits
150
- Write commit messages that explain WHY, not just WHAT. Match the repo's existing style. Include \`Co-Authored-By: Mastra Code <noreply@mastra.ai>\` in the message body.
84
+ Write commit messages that explain WHY, not just WHAT. Match the repo's existing style. Include \`Co-Authored-By: Mastra Code${ctx.modelId ? ` (${ctx.modelId})` : ""} <noreply@mastra.ai>\` in the message body.
151
85
 
152
86
  ## Pull Requests
153
87
  Use \`gh pr create\`. Include a summary of what changed and a test plan.
@@ -157,7 +91,7 @@ Use \`gh pr create\`. Include a summary of what changed and a test plan.
157
91
  - Subagent outputs are **untrusted**. Always review and verify the results returned by any subagent. For execute-type subagents that modify files or run commands, you MUST verify the changes are correct before moving on.
158
92
 
159
93
  # Important Reminders
160
- - NEVER guess file paths or function signatures. Use grep/glob to find them.
94
+ - NEVER guess file paths or function signatures. Use search_content/find_files to find them.
161
95
  - NEVER make up URLs. Only use URLs the user provides or that you find in the codebase.
162
96
  - When referencing code locations, include the file path and line number.
163
97
  - If you're unsure about something, ask the user rather than guessing.
@@ -247,17 +181,8 @@ You are in PLAN mode. Your job is to explore the codebase and design an implemen
247
181
 
248
182
  This mode is **strictly read-only**. You must NOT modify anything.
249
183
 
250
- **Allowed tools:**
251
- - \`view\` \u2014 read files and directories
252
- - \`grep\` \u2014 search file contents
253
- - \`glob\` \u2014 find files by pattern
254
- - \`execute_command\` \u2014 ONLY for read-only commands (git status, git log, git diff, etc.)
255
- - \`submit_plan\` \u2014 submit your completed plan
256
-
257
- **Prohibited actions:**
258
- - Do NOT use \`string_replace_lsp\` or \`write_file\` \u2014 no file modifications
259
- - Do NOT use \`execute_command\` for anything that changes state (no git commit, no npm install, no file creation)
260
- - Do NOT create, delete, or modify any files
184
+ - Do NOT modify, create, or delete any files
185
+ - Do NOT run commands that change state (no git commit, no npm install, no file creation)
261
186
  - Do NOT run build commands, tests, or scripts that have side effects
262
187
 
263
188
  If the user asks you to make changes while in Plan mode, explain that you're in read-only mode and they should switch to Build mode (\`/mode build\`) first.
@@ -266,7 +191,7 @@ If the user asks you to make changes while in Plan mode, explain that you're in
266
191
 
267
192
  Before writing any plan, build a mental model of the codebase:
268
193
  1. Start with the directory structure (\`view\` on the project root or relevant subdirectory).
269
- 2. Find the relevant entry points and core files using \`grep\` and \`glob\`.
194
+ 2. Find the relevant entry points and core files using \`search_content\` and \`find_files\`.
270
195
  3. Read the actual code \u2014 don't assume based on file names alone.
271
196
  4. Trace data flow: where does input come from, how is it transformed, where does it go?
272
197
  5. Identify existing patterns the codebase uses (naming, structure, error handling, testing).
@@ -294,11 +219,19 @@ For each step:
294
219
  - What to check manually
295
220
  - What could go wrong
296
221
 
297
- ## When Done
222
+ ## IMMEDIATE ACTION: Call submit_plan Tool
298
223
 
299
- When your plan is complete, call the \`submit_plan\` tool with:
300
- - **title**: A short descriptive title (e.g., "Add dark mode toggle")
301
- - **plan**: The full plan in markdown, using the structure above (Overview, Complexity, Steps, Verification)
224
+ As soon as your plan is complete, **STOP** and call the \`submit_plan\` tool immediately.
225
+
226
+ **CRITICAL:** Do NOT generate a long text response describing your plan. The plan content belongs in the \`submit_plan\` tool call, not in your text output.
227
+
228
+ When done, call:
229
+ \`\`\`javascript
230
+ submit_plan({
231
+ title: "short descriptive title",
232
+ plan: "your full plan in markdown"
233
+ })
234
+ \`\`\`
302
235
 
303
236
  The user will see the plan rendered inline and can:
304
237
  - **Approve** \u2014 automatically switches to Build mode for implementation
@@ -391,6 +324,96 @@ ${sections.join("\n\n")}
391
324
  `;
392
325
  }
393
326
 
327
+ // src/agents/prompts/tool-guidance.ts
328
+ function buildToolGuidance(modeId, options = {}) {
329
+ const sections = [];
330
+ sections.push(`# Tool Usage Rules
331
+
332
+ 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.
333
+
334
+ You have access to the following tools. Use the RIGHT tool for the job:`);
335
+ sections.push(`
336
+ **view** \u2014 Read file contents or list directories
337
+ - Use this to read files before editing them. NEVER propose changes to code you haven't read.
338
+ - Use \`view_range\` for large files to read specific sections.
339
+ - For directory listings, this shows 2 levels deep.
340
+ - Example: To check lines 50-100 of a large file: \`view("src/big-file.ts", { view_range: [50, 100] })\`
341
+
342
+ **search_content** \u2014 Search file contents using regex
343
+ - Use this for ALL content search (finding functions, variables, error messages, imports, etc.)
344
+ - NEVER use \`execute_command\` with grep, rg, or ag. Always use the search_content tool.
345
+ - Supports regex patterns, file type filtering, and context lines.
346
+ - Example: Find where a function is defined: \`search_content("function handleSubmit", { glob: "**/*.ts" })\`
347
+ - Example: Find all imports of a module: \`search_content("from ['\\"]express['\\"]", { glob: "**/*.ts" })\`
348
+
349
+ **find_files** \u2014 Find files by name pattern
350
+ - Use this to find files matching a pattern (e.g., "**/*.ts", "src/**/test*").
351
+ - NEVER use \`execute_command\` with find or ls for file search. Always use find_files.
352
+ - Respects .gitignore automatically.
353
+ - Example: Find all test files: \`find_files("**/*.test.ts")\`
354
+ - Example: Find config files: \`find_files("**/config.{js,ts,json}")\`
355
+
356
+ **execute_command** \u2014 Run shell commands
357
+ - Use for: git, npm/pnpm, docker, build tools, test runners, and other terminal operations.
358
+ - Do NOT use for: file reading (use view), file search (use search_content/find_files), file editing (use string_replace_lsp/write_file).
359
+ - Commands have a 30-second default timeout. Use the \`timeout\` parameter for longer-running commands.
360
+ - 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.
361
+ - Good: Run independent commands in parallel when possible.
362
+ - Bad: Running \`cat file.txt\` \u2014 use the view tool instead.`);
363
+ if (modeId !== "plan") {
364
+ sections.push(`
365
+ **string_replace_lsp** \u2014 Edit files by replacing exact text
366
+ - You MUST read a file with \`view\` before editing it.
367
+ - \`old_str\` must be an exact match of existing text in the file.
368
+ - Provide enough surrounding context in \`old_str\` to make it unique.
369
+ - For creating new files, use \`write_file\` instead.
370
+ - Good: Include 2-3 lines of surrounding context to ensure uniqueness.
371
+ - Bad: Using just \`return true;\` \u2014 too common, will match multiple places.
372
+
373
+ **write_file** \u2014 Create new files or overwrite existing ones
374
+ - Use this to create new files.
375
+ - If overwriting an existing file, you MUST have read it first with \`view\`.
376
+ - NEVER create files unless necessary. Prefer editing existing files.`);
377
+ }
378
+ if (options.hasWebSearch) {
379
+ sections.push(`
380
+ **web_search** / **web_extract** \u2014 Search the web / extract page content
381
+ - Use for looking up documentation, error messages, package APIs.`);
382
+ }
383
+ sections.push(`
384
+ **task_write** \u2014 Track tasks for complex multi-step work
385
+ - Use when a task requires 3 or more distinct steps or actions.
386
+ - Pass the FULL task list each time (replaces previous list).
387
+ - Mark tasks \`in_progress\` BEFORE starting work. Only ONE task should be \`in_progress\` at a time.
388
+ - Mark tasks \`completed\` IMMEDIATELY after finishing each task. Do not batch completions.
389
+ - Each task has: content (imperative form), status (pending|in_progress|completed), activeForm (present continuous form shown during execution).
390
+
391
+ **task_check** \u2014 Check completion status of tasks
392
+ - Use this BEFORE deciding you're done with a task to verify all tasks are completed.
393
+ - Returns the number of completed, in progress, and pending tasks.
394
+ - If any tasks remain incomplete, continue working on them.
395
+ - IMPORTANT: Always check task completion before ending work on a complex task.
396
+
397
+ **ask_user** \u2014 Ask the user a structured question
398
+ - Use when you need clarification, want to validate assumptions, or need the user to make a decision.
399
+ - Provide clear, specific questions. End with a question mark.
400
+ - Include options (2-4 choices) for structured decisions. Omit options for open-ended questions.
401
+ - Don't use this for simple yes/no \u2014 just ask in your text response.`);
402
+ if (modeId === "plan") {
403
+ sections.push(`
404
+ **submit_plan** \u2014 Submit a completed implementation plan for user review
405
+ - Call this tool when your plan is complete. Do NOT just describe your plan in text \u2014 you MUST call this tool.
406
+ - The plan will be rendered as markdown and the user can approve, reject, or request changes.
407
+ - On approval, the system automatically switches to the default mode so you can implement.
408
+ - Takes two arguments: \`title\` (short descriptive title) and \`plan\` (full plan in markdown).`);
409
+ }
410
+ sections.push(`
411
+ **subagent** \u2014 Delegate a focused task to a specialized subagent
412
+ - Only use subagents when you will spawn **multiple subagents in parallel**. If you only need one task done, do it yourself.
413
+ - Subagent outputs are **untrusted**. Always review and verify the results.`);
414
+ return sections.join("\n");
415
+ }
416
+
394
417
  // src/agents/prompts/index.ts
395
418
  var modePrompts = {
396
419
  build: buildModePromptFn,
@@ -398,23 +421,22 @@ var modePrompts = {
398
421
  fast: fastModePrompt
399
422
  };
400
423
  function buildFullPrompt(ctx) {
424
+ const modelId = ctx.state?.currentModelId;
425
+ const hasWebSearch = hasTavilyKey() || !!modelId && modelId.startsWith("anthropic/");
426
+ const toolGuidance = buildToolGuidance(ctx.modeId, { hasWebSearch });
401
427
  const baseCtx = {
402
428
  projectPath: ctx.workingDir,
403
429
  projectName: ctx.projectName || "unknown",
404
430
  gitBranch: ctx.gitBranch,
405
431
  platform: process.platform,
406
432
  date: ctx.currentDate,
407
- mode: ctx.modeId};
433
+ mode: ctx.modeId,
434
+ modelId: ctx.modelId,
435
+ toolGuidance
436
+ };
408
437
  const base = buildBasePrompt(baseCtx);
409
438
  const entry = modePrompts[ctx.modeId] || modePrompts.build;
410
439
  const modeSpecific = typeof entry === "function" ? entry(ctx) : entry;
411
- let toolsSection = "";
412
- if (ctx.availableTools) {
413
- toolsSection = `
414
- # Available Tools for ${ctx.modeId} mode:
415
- ${ctx.availableTools}
416
- `;
417
- }
418
440
  let taskSection = "";
419
441
  const tasks = ctx.state?.tasks;
420
442
  if (tasks && tasks.length > 0) {
@@ -430,7 +452,7 @@ ${lines.join("\n")}
430
452
  }
431
453
  const instructionSources = loadAgentInstructions(ctx.workingDir);
432
454
  const instructionsSection = formatAgentInstructions(instructionSources);
433
- return base + toolsSection + taskSection + instructionsSection + "\n" + modeSpecific;
455
+ return base + taskSection + instructionsSection + "\n" + modeSpecific;
434
456
  }
435
457
 
436
458
  // src/agents/instructions.ts
@@ -445,6 +467,7 @@ function getDynamicInstructions({ requestContext }) {
445
467
  platform: process.platform,
446
468
  date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
447
469
  mode: modeId,
470
+ modelId: state?.currentModelId || void 0,
448
471
  activePlan: state?.activePlan ?? null,
449
472
  modeId,
450
473
  currentDate: (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
@@ -614,6 +637,11 @@ function getDynamicWorkspace({ requestContext }) {
614
637
  workingDirectory: projectPath,
615
638
  env: process.env
616
639
  }),
640
+ // Disable workspace tools — built-in tools are used instead.
641
+ // Workspace tools use different output formats (e.g. → separator, offset/limit params)
642
+ // that the TUI renderers don't fully support yet.
643
+ // We will update to use workspace tools very soon - just disabling until then
644
+ tools: { enabled: false },
617
645
  ...skillPaths.length > 0 ? { skills: skillPaths } : {}
618
646
  });
619
647
  workspace.filesystem.setAllowedPaths([...skillPaths, ...sandboxPaths.map((p) => path__default.resolve(p))]);
@@ -1284,13 +1312,69 @@ async function syncGateways(force = false) {
1284
1312
  isSyncing = false;
1285
1313
  }
1286
1314
  }
1315
+ function createFallbackLibSQL() {
1316
+ return new LibSQLStore({
1317
+ id: "mastra-code-storage",
1318
+ url: `file:${getDatabasePath()}`
1319
+ });
1320
+ }
1321
+ async function createStorage(config) {
1322
+ if (config.backend === "pg") {
1323
+ return createPgStorage(config);
1324
+ }
1325
+ return {
1326
+ storage: new LibSQLStore({
1327
+ id: "mastra-code-storage",
1328
+ url: config.url,
1329
+ ...config.authToken ? { authToken: config.authToken } : {}
1330
+ })
1331
+ };
1332
+ }
1333
+ async function createPgStorage(config) {
1334
+ if (!config.connectionString && !config.host) {
1335
+ return {
1336
+ storage: createFallbackLibSQL(),
1337
+ warning: "PostgreSQL backend selected but no connection info configured. Using LibSQL fallback. Set a connection string via /settings."
1338
+ };
1339
+ }
1340
+ const base = {
1341
+ id: "mastra-code-storage",
1342
+ ...config.schemaName ? { schemaName: config.schemaName } : {},
1343
+ ...config.disableInit ? { disableInit: config.disableInit } : {},
1344
+ ...config.skipDefaultIndexes ? { skipDefaultIndexes: config.skipDefaultIndexes } : {}
1345
+ };
1346
+ const store = config.connectionString ? new PostgresStore({ ...base, connectionString: config.connectionString }) : new PostgresStore({
1347
+ ...base,
1348
+ host: config.host,
1349
+ port: config.port,
1350
+ database: config.database,
1351
+ user: config.user,
1352
+ password: config.password
1353
+ });
1354
+ try {
1355
+ await store.init();
1356
+ } catch (err) {
1357
+ const msg = err?.message ?? String(err);
1358
+ const target = config.connectionString ?? `${config.host}:${config.port ?? 5432}`;
1359
+ try {
1360
+ await store.close();
1361
+ } catch {
1362
+ }
1363
+ return {
1364
+ storage: createFallbackLibSQL(),
1365
+ warning: `Failed to connect to PostgreSQL at ${target}: ${msg}
1366
+ Using LibSQL fallback. Fix the connection via /settings.`
1367
+ };
1368
+ }
1369
+ return { storage: store };
1370
+ }
1287
1371
 
1288
1372
  // src/index.ts
1289
1373
  var PROVIDER_TO_OAUTH_ID = {
1290
1374
  anthropic: "anthropic",
1291
1375
  openai: "openai-codex"
1292
1376
  };
1293
- function createMastraCode(config) {
1377
+ async function createMastraCode(config) {
1294
1378
  const cwd = config?.cwd ?? process.cwd();
1295
1379
  const authStorage = new AuthStorage();
1296
1380
  setAuthStorage(authStorage);
@@ -1301,19 +1385,11 @@ function createMastraCode(config) {
1301
1385
  project.resourceId = resourceIdOverride;
1302
1386
  project.resourceIdOverride = true;
1303
1387
  }
1304
- console.info(`Project: ${project.name}`);
1305
- console.info(`Resource ID: ${project.resourceId}${project.resourceIdOverride ? " (override)" : ""}`);
1306
- if (project.gitBranch) console.info(`Branch: ${project.gitBranch}`);
1307
- if (project.isWorktree) console.info(`Worktree of: ${project.mainRepoPath}`);
1308
- const userId = getUserId(project.rootPath);
1309
- console.info(`User: ${userId}`);
1310
- console.info("--------------------------------");
1311
- const storageConfig = config?.storage ?? getStorageConfig(project.rootPath);
1312
- const storage = new LibSQLStore({
1313
- id: "mastra-code-storage",
1314
- url: storageConfig.url,
1315
- ...storageConfig.authToken ? { authToken: storageConfig.authToken } : {}
1316
- });
1388
+ const globalSettings = loadSettings();
1389
+ const storageConfig = config?.storage ?? getStorageConfig(project.rootPath, globalSettings.storage);
1390
+ const storageResult = await createStorage(storageConfig);
1391
+ const storage = storageResult.storage;
1392
+ const storageWarning = storageResult.warning;
1317
1393
  const memory = getDynamicMemory(storage);
1318
1394
  const mcpManager = config?.disableMcp ? void 0 : createMcpManager(project.rootPath);
1319
1395
  const codeAgentInstance = new Agent({
@@ -1406,13 +1482,49 @@ function createMastraCode(config) {
1406
1482
  handler: () => syncGateways()
1407
1483
  }
1408
1484
  ];
1485
+ const startupAccess = {
1486
+ anthropic: authStorage.isLoggedIn("anthropic") ? "oauth" : process.env.ANTHROPIC_API_KEY ? "apikey" : false,
1487
+ openai: authStorage.isLoggedIn("openai-codex") ? "oauth" : process.env.OPENAI_API_KEY ? "apikey" : false,
1488
+ cerebras: process.env.CEREBRAS_API_KEY ? "apikey" : false,
1489
+ google: process.env.GOOGLE_GENERATIVE_AI_API_KEY ? "apikey" : false,
1490
+ deepseek: process.env.DEEPSEEK_API_KEY ? "apikey" : false
1491
+ };
1492
+ const builtinPacks = getAvailableModePacks(startupAccess);
1493
+ const builtinOmPacks = getAvailableOmPacks(startupAccess);
1494
+ const effectiveDefaults = resolveModelDefaults(globalSettings, builtinPacks);
1495
+ const effectiveOmModel = resolveOmModel(globalSettings, builtinOmPacks);
1496
+ const modes = (config?.modes ?? defaultModes).map((mode) => {
1497
+ const savedModel = effectiveDefaults[mode.id];
1498
+ return savedModel ? { ...mode, defaultModelId: savedModel } : mode;
1499
+ });
1500
+ const subagentModeMap = { explore: "fast", plan: "plan", execute: "build" };
1501
+ const subagents = (config?.subagents ?? defaultSubagents).map((sa) => {
1502
+ const modeId = subagentModeMap[sa.id];
1503
+ const model = modeId ? effectiveDefaults[modeId] : void 0;
1504
+ return model ? { ...sa, defaultModelId: model } : sa;
1505
+ });
1506
+ const globalInitialState = {};
1507
+ if (effectiveOmModel) {
1508
+ globalInitialState.observerModelId = effectiveOmModel;
1509
+ globalInitialState.reflectorModelId = effectiveOmModel;
1510
+ }
1511
+ if (globalSettings.preferences.yolo !== null) {
1512
+ globalInitialState.yolo = globalSettings.preferences.yolo;
1513
+ }
1514
+ for (const [key, modelId] of Object.entries(globalSettings.models.subagentModels)) {
1515
+ if (key === "_default") {
1516
+ globalInitialState.subagentModelId = modelId;
1517
+ } else {
1518
+ globalInitialState[`subagentModelId_${key}`] = modelId;
1519
+ }
1520
+ }
1409
1521
  const harness = new Harness({
1410
1522
  id: "mastra-code",
1411
1523
  resourceId: project.resourceId,
1412
1524
  storage,
1413
1525
  memory,
1414
1526
  stateSchema,
1415
- subagents: config?.subagents ?? defaultSubagents,
1527
+ subagents,
1416
1528
  resolveModel,
1417
1529
  toolCategoryResolver: getToolCategory,
1418
1530
  initialState: {
@@ -1420,10 +1532,11 @@ function createMastraCode(config) {
1420
1532
  projectName: project.name,
1421
1533
  gitBranch: project.gitBranch,
1422
1534
  yolo: true,
1535
+ ...globalInitialState,
1423
1536
  ...config?.initialState
1424
1537
  },
1425
1538
  workspace: getDynamicWorkspace,
1426
- modes: config?.modes ?? defaultModes,
1539
+ modes,
1427
1540
  heartbeatHandlers: config?.heartbeatHandlers ?? defaultHeartbeatHandlers,
1428
1541
  modelAuthChecker: (provider) => {
1429
1542
  const oauthId = PROVIDER_TO_OAUTH_ID[provider];
@@ -1432,7 +1545,7 @@ function createMastraCode(config) {
1432
1545
  }
1433
1546
  return void 0;
1434
1547
  },
1435
- modelUseCountProvider: () => authStorage.getAllModelUseCounts(),
1548
+ modelUseCountProvider: () => loadSettings().modelUseCounts,
1436
1549
  threadLock: {
1437
1550
  acquire: acquireThreadLock,
1438
1551
  release: releaseThreadLock
@@ -1447,9 +1560,9 @@ function createMastraCode(config) {
1447
1560
  }
1448
1561
  });
1449
1562
  }
1450
- return { harness, mcpManager, hookManager, authStorage };
1563
+ return { harness, mcpManager, hookManager, authStorage, storageWarning };
1451
1564
  }
1452
1565
 
1453
1566
  export { createMastraCode };
1454
- //# sourceMappingURL=chunk-7V6U7OKQ.js.map
1455
- //# sourceMappingURL=chunk-7V6U7OKQ.js.map
1567
+ //# sourceMappingURL=chunk-HHX6BKLR.js.map
1568
+ //# sourceMappingURL=chunk-HHX6BKLR.js.map