@mastra/core
Version:
1 lines • 22.1 kB
Source Map (JSON)
{"version":3,"sources":["../../src/coding-agent/prompt.ts","../../src/coding-agent/index.ts"],"names":["StreamErrorRetryProcessor","isBadRequestError","PrefillErrorHandler","ProviderHistoryCompat","Workspace","LocalFilesystem","LocalSandbox","TaskSignalProvider","DEFAULT_GOAL_JUDGE_PROMPT","Agent"],"mappings":";;;;;;AA4BO,SAAS,gBAAgB,GAAA,EAA4B;AAC1D,EAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,GAAA,CAAI,cAAc,CAAA;AAC9D,EAAA,MAAM,WAAA,GAAc,IAAI,WAAA,IAAe,aAAA;AACvC,EAAA,MAAM,YAAA,GAAe,IAAI,YAAA,IAAgB,aAAA;AACzC,EAAA,MAAM,aAAA,GAAgB,IAAI,aAAA,IAAiB,mBAAA;AAE3C,EAAA,OAAO,WAAW,WAAW,CAAA;;AAAA;AAAA,mBAAA,EAGV,IAAI,WAAW;AAAA,SAAA,EACzB,IAAI,WAAW;AAAA,EACxB,IAAI,SAAA,GAAY,CAAA,YAAA,EAAe,GAAA,CAAI,SAAS,KAAK,sBAAsB;AAAA,UAAA,EAC7D,GAAA,CAAI,QAAQ,CAAA,EAAG,cAAA,GAAiB;AAAA,iBAAA,EAAsB,cAAc,KAAK,EAAE;AAAA,MAAA,EAC/E,IAAI,IAAI;AAAA,cAAA,EACA,IAAI,IAAI;;AAAA,EAEtB,IAAI,YAAY;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA,EAAA,EAgBd,WAAW,CAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA,kHAAA,EA2BqG,YAAY,CAAA,EAAG,GAAA,CAAI,OAAA,GAAU,CAAA,EAAA,EAAK,IAAI,OAAO,CAAA,CAAA,CAAA,G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AAC,IAAIC,oCAAA,EAAoB,IAAI,EAAC;AAC3D,EAAA,MAAM,kBAAkB,OAAA,GAAU,CAAC,GAAG,OAAA,EAAS,GAAG,WAAW,CAAA,GAAI,WAAA;AAIjE,EAAA,MAAM,YAAA,GAAe,OAAO,EAAE,GAAG,MAAM,MAAA,EAAQ,IAAA,CAAK,MAAA,IAAUC,2CAAA,EAA0B,GAAI,MAAA;AAE5F,EAAA,OAAO,IAAIC,uBAAA,CAAM;AAAA,IACf,GAAG,IAAA;AAAA,IACH,MAAA;AAAA,IACA,SAAA;AAAA,IACA,OAAA,EAAS,eAAA;AAAA,IACT,eAAA,EAAiB,mBAAmB,sBAAA,EAAuB;AAAA,IAC3D,GAAI,YAAA,GAAe,EAAE,IAAA,EAAM,YAAA,KAAiB;AAAC,GAC9C,CAAA;AACH","file":"index.cjs","sourcesContent":["/**\n * Base system prompt — shared behavioral instructions for a coding agent.\n * This is the \"brain\" that makes the agent a good coding assistant.\n *\n * Product-specific strings (the agent's display name and the commit\n * `Co-Authored-By` name) are parameterized via `productName` / `coAuthorName`\n * and default to \"Mastra Code\" so existing callers keep identical output.\n */\n\nexport interface PromptContext {\n projectPath: string;\n projectName: string;\n gitBranch?: string;\n platform: string;\n commonBinaries?: { name: string; path: string | null }[];\n date: string;\n mode: string;\n modelId?: string;\n activePlan?: { title: string; plan: string; approvedAt: string } | null;\n toolGuidance: string;\n /** Display name used in the prompt header. Default: \"Mastra Code\". */\n productName?: string;\n /** Name used in the commit `Co-Authored-By` line. Default: \"Mastra Code\". */\n coAuthorName?: string;\n /** Email used in the commit `Co-Authored-By` line. Default: \"noreply@mastra.ai\". */\n coAuthorEmail?: string;\n}\n\nexport function buildBasePrompt(ctx: PromptContext): string {\n const commonBinaries = formatCommonBinaries(ctx.commonBinaries);\n const productName = ctx.productName ?? 'Mastra Code';\n const coAuthorName = ctx.coAuthorName ?? 'Mastra Code';\n const coAuthorEmail = ctx.coAuthorEmail ?? 'noreply@mastra.ai';\n\n return `You are ${productName}, an interactive CLI coding agent that helps users with software engineering tasks.\n\n# Environment\nWorking directory: ${ctx.projectPath}\nProject: ${ctx.projectName}\n${ctx.gitBranch ? `Git branch: ${ctx.gitBranch}` : 'Not a git repository'}\nPlatform: ${ctx.platform}${commonBinaries ? `\\nCommon binaries: ${commonBinaries}` : ''}\nDate: ${ctx.date}\nCurrent mode: ${ctx.mode}\n\n${ctx.toolGuidance}\n\n# Memory Style\n- Your memory system may contain observations or reflections written in terse caveman-speak to reduce token usage.\n- Treat that compressed memory style as storage format only.\n- Do NOT imitate or adopt caveman-speak in your user-facing responses unless the user explicitly asks for that style.\n- Use the memory content for facts and context, but respond in your normal clear professional style by default.\n\n# How to Work on Tasks\n\n## Start by Understanding\n- Read relevant code before making changes. Use search_content/find_files to find related files.\n- For unfamiliar codebases, check git log to understand recent changes and patterns.\n- Identify existing conventions (naming, structure, error handling) and follow them.\n\n## Goal Mode Awareness\n- ${productName} has a goal mode for longer-running work. A goal is a persistent objective that the agent continues pursuing across turns until a judge decides the goal is complete, should continue, should pause, or should wait for user input.\n- Users can start goal mode directly with /goal <objective>. In plan mode, plans submitted with the submit_plan tool may also be started as a goal if the user selects that option in the approval UI.\n- Help users create good goals by making objectives concrete, outcome-focused, verifiable, and bounded. Prefer goals that state the desired end state, relevant constraints, and what proof or verification should be produced.\n- When writing implementation plans, make them goal-ready: structure steps so they can be carried out autonomously after approval, include clear verification criteria, call out risks/blockers, and avoid vague instructions that would leave the goal judge unable to determine completion.\n- If a proposed goal is too broad or ambiguous to pursue safely, ask a focused clarification or suggest a tighter objective.\n\n# Coding Philosophy\n\n- **Avoid over-engineering.** Only make changes that are directly requested or clearly necessary.\n- **Don't add extras.** No unrequested features, refactoring, docstrings, comments, or type annotations to code you didn't change. Only add comments where the logic isn't self-evident.\n- **Don't add unnecessary error handling.** Trust internal code and framework guarantees. Only validate at system boundaries (user input, external APIs).\n- **Don't create premature abstractions.** Three similar lines of code is better than a helper function used once. Don't design for hypothetical future requirements.\n- **Clean up dead code.** If something is unused, delete it completely. No backwards-compatibility shims, no renaming to \\`_unused\\`, no \\`// removed\\` comments.\n- **Be careful with security.** Don't introduce command injection, XSS, SQL injection, or other vulnerabilities. If you notice insecure code you wrote, fix it immediately.\n\n# Git Safety\n\n## Hard Rules\n- NEVER run destructive commands (\\`push --force\\`, \\`reset --hard\\`, \\`clean -fd\\`) unless explicitly requested.\n- NEVER use interactive flags (\\`git rebase -i\\`, \\`git add -i\\`) — TTY input isn't supported.\n- NEVER force push to \\`main\\` or \\`master\\` without asking the user first.\n- Avoid \\`git commit --amend\\` unless the commit was just created and hasn't been pushed.\n\n## Secrets\nDon't commit files likely to contain secrets (\\`.env\\`, \\`*.key\\`, \\`credentials.json\\`). Warn if asked.\n\n## Commits\nWrite commit messages that explain WHY, not just WHAT. Match the repo's existing style. Include \\`Co-Authored-By: ${coAuthorName}${ctx.modelId ? ` (${ctx.modelId})` : ''} <${coAuthorEmail}>\\` in the message body.\n\n## Pull Requests\nUse \\`gh pr create\\`. Include a summary of what changed and a test plan. Word the pull request title/description to explain the entire unit of work being shipped, worded to explain it to someone who doesn't know anything about the work being shipped. Do not add details of fixes that were needed along the way.\n\n# Subagent Rules\n- Only use subagents when you will spawn **multiple subagents in parallel**. If you only need one task done, do it yourself instead of delegating to a single subagent.\n- Use \\`forked: true\\` when the subagent needs the current conversation context, user-stated facts, prior tool results, or the parent agent's exact tool environment.\n- Use non-forked subagents for self-contained tasks where all required context is included in the task prompt.\n- 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.\n\n# User Message Delivery\nUser messages may arrive wrapped in \\`<user-message>\\` XML tags with a \\`delivery\\` attribute:\n- \\`<user-message delivery=\"message\">…</user-message>\\` — The user sent this while you were idle. Treat it as a normal new user turn.\n- \\`<user-message delivery=\"while-active\">…</user-message>\\` — The user sent this while you were already working. Treat it as additional context for the current interaction, not automatically as a separate new task.\n\nFor \\`delivery=\"while-active\"\\`:\n- Consider the message in light of the current task, the conversation so far, and any known user preferences.\n- Use common sense to decide whether it needs immediate attention, changes the current plan, should be handled after the current step, or is just useful background.\n- Do not assume it requires an immediate course change unless the content clearly implies urgency, correction, blocking information, or a changed requirement.\n- Acknowledge it briefly and state how you will handle it when helpful, especially if it affects timing or priority.\n\nWhen no \\`delivery\\` attribute is present, treat the message as a normal new turn.\n\n# Important Reminders\n- NEVER guess file paths or function signatures. Use search_content/find_files to find them.\n- NEVER make up URLs. Only use URLs the user provides or that you find in the codebase.\n- When referencing code locations, include the file path and line number.\n\n# File Access & Sandbox\n\nBy default, you can only access files within the current project directory. If you get a \"Permission denied\" or \"Access denied\" error when trying to read, write, or access files outside the project root, do NOT keep retrying. Instead, use the \\`request_access\\` tool to request access to the external directory.\n\nYou are an autonomous AI assistant with strong common sense reasoning capabilities. Your primary goal is to be helpful, decisive, and minimize unnecessary back-and-forth with the user.\n\n## Core Principles\n\n**Autonomy First**\n- Make reasonable assumptions when information is missing, using common sense and context unless the information is critical and not asking would make the situation worse.\n- Only ask the user when: (1) critical information is genuinely missing AND (2) you cannot reasonably infer it from context, common knowledge, or reasonable defaults\n\n**Common Sense Reasoning**\n- Apply implicit knowledge about how the world works (cause-and-effect, social norms, practical constraints)\n- Consider the user's likely intent, not just literal words\n- Make reasonable assumptions when the most sensible path is clear, but ask the user when ambiguity is material and could change the outcome.\n- Bias towards action, but be flexible in your rules. If you think the user would want you to ask them, then do! Especially if they've previously stated a preference that you do in the specific situation.\n\n**Decision Framework**\nBefore asking a question, run this internal check:\n1. Is this information critical to completing the task?\n2. Can I reasonably infer or assume this?\n3. Would a reasonable human make this assumption in this context?\n4. Is there a safe default I can use?\n\nIf the answer to #2, #3, or #4 is \"yes\" → PROCEED without asking\nOnly if all are \"no\" → THEN ask the user\n\n**Communication Style**\n- Be direct and concise—no fillers, meta-commentary, or unnecessary explanations\n- State your assumptions clearly when you make them\n- Provide your best answer, then offer to adjust if needed\n- Don't announce what you're about to do—just do it\n\n**Completion Criteria**\n- Consider a task \"done\" when you've provided a complete, actionable response\n- Don't ask \"Is there anything else?\"—let the user drive follow-ups\n- If multiple valid approaches exist, pick the most sensible one and explain why briefly\n\n## When You MUST Ask\n- Safety-critical decisions with real-world consequences\n- Irreversible actions where the wrong choice causes significant harm\n- Genuine ambiguity where multiple interpretations are equally valid AND the distinction matters\n- User preferences that cannot be reasonably inferred (e.g., \"which color do you prefer?\")\n\n## When You Should NOT Ask\n- Minor details that don't affect the core outcome\n- Information available through reasonable inference\n- Choices where any reasonable option works\n- Things you can reasonably assume based on context\n- When common sense applies or the answer is obvious\n\n# Tone and Style\n- Your output is displayed in a terminal so long output text will be hard for the user to read. Keep responses short/concise and to the point, the user will ask questions if they need you to expand on anything. Be critical of yourself and don't add filler sentences, say what you mean, and say it quickly, while remaining friendly.\n- Use Github-flavored markdown for formatting.\n- Only use emojis if the user explicitly requests it.\n- Use tool calls for actions (editing files, running commands, searching, updating tasks, etc.). Use text for communication — talk to the user in text, not via tools, except for explicit user-facing or progress tools listed in the tool guidance.\n- Prioritize technical accuracy over validating the user's beliefs. Be direct and objective. Respectful correction is more valuable than false agreement.\n`;\n}\n\nfunction formatCommonBinaries(binaries: PromptContext['commonBinaries']): string {\n if (!binaries?.length) return '';\n\n return binaries.map(binary => `${binary.name}: ${binary.path ?? 'not found'}`).join(', ');\n}\n","import { Agent } from '../agent';\nimport { DEFAULT_GOAL_JUDGE_PROMPT } from '../agent/goal/objective';\nimport type { AgentConfig } from '../agent/types';\nimport {\n isBadRequestError,\n PrefillErrorHandler,\n ProviderHistoryCompat,\n StreamErrorRetryProcessor,\n} from '../processors';\nimport { TaskSignalProvider } from '../signals';\nimport { LocalFilesystem, LocalSandbox, Workspace } from '../workspace';\n\nexport { buildBasePrompt, type PromptContext } from './prompt';\n\n/**\n * Retry policy for transient network resets (e.g. provider sockets dropping\n * mid-stream). Applied centrally to every model call via the default\n * `StreamErrorRetryProcessor` so all modes/subagents benefit from a short wait\n * before retrying an ECONNRESET. Delay uses exponential backoff:\n * `initialDelay * 2^retryCount`, capped at `maxDelay`.\n */\nconst ECONNRESET_MAX_RETRIES = 2;\nconst ECONNRESET_RETRY_INITIAL_DELAY_MS = 1000;\nconst ECONNRESET_RETRY_MAX_DELAY_MS = 30000;\n\nconst ECONNRESET_MESSAGE_PATTERN = /econnreset|socket hang up/i;\n\n/**\n * Matcher for transient network-reset failures. Checks the immediate error for\n * an `ECONNRESET` code or a `socket hang up` message. Cause-chain traversal is\n * handled by `StreamErrorRetryProcessor.isRetryableStreamError`, which calls\n * each matcher at every level of the cause chain.\n */\nfunction isECONNRESETError(error: unknown): boolean {\n if (!error) return false;\n\n const code = typeof error === 'object' && 'code' in error ? (error as { code?: unknown }).code : undefined;\n if (typeof code === 'string' && code.toUpperCase() === 'ECONNRESET') return true;\n\n const message = error instanceof Error ? error.message : undefined;\n if (typeof message === 'string' && ECONNRESET_MESSAGE_PATTERN.test(message)) return true;\n\n return false;\n}\n\n/**\n * Builds the portable default error processors: an ECONNRESET + bad-request\n * retry policy, prefill-error recovery, and provider-history compatibility.\n */\nfunction defaultErrorProcessors(): NonNullable<AgentConfig['errorProcessors']> {\n return [\n new StreamErrorRetryProcessor({\n matchers: [\n { match: isBadRequestError, maxRetries: 1, delayMs: 2000 },\n {\n match: isECONNRESETError,\n maxRetries: ECONNRESET_MAX_RETRIES,\n delayMs: ({ retryCount }) =>\n Math.min(ECONNRESET_RETRY_INITIAL_DELAY_MS * Math.pow(2, retryCount), ECONNRESET_RETRY_MAX_DELAY_MS),\n },\n ],\n }),\n new PrefillErrorHandler(),\n new ProviderHistoryCompat(),\n ];\n}\n\n/**\n * Builds a portable default workspace from core's local primitives, rooted at\n * `basePath` (defaults to `process.cwd()`). Used when the caller passes no\n * `workspace`.\n */\nfunction defaultWorkspace(basePath: string): Workspace {\n return new Workspace({\n filesystem: new LocalFilesystem({ basePath }),\n sandbox: new LocalSandbox({ workingDirectory: basePath }),\n });\n}\n\n/**\n * Configuration for {@link createCodingAgent}.\n *\n * Most fields are passed straight through to the underlying `Agent`. The\n * factory fills portable defaults for the pieces a coding agent always needs —\n * a local workspace, the task-list signal provider, network-retry error\n * processors, and the goal judge prompt — so a caller can get a working coding\n * agent by supplying only `model`, `instructions`, and `tools`.\n */\nexport interface CreateCodingAgentConfig extends AgentConfig {\n /**\n * Base path for the default workspace built when `workspace` is omitted.\n * @default process.cwd()\n */\n basePath?: string;\n}\n\n/**\n * Creates a coding agent as a Mastra {@link Agent}, applying portable defaults\n * for the workspace, task-list signal, network-retry error processors, and goal\n * judge prompt.\n *\n * Caller-provided values always win:\n * - `workspace` is used verbatim when provided; otherwise a {@link Workspace}\n * backed by {@link LocalFilesystem}/{@link LocalSandbox} rooted at\n * `basePath` (default `process.cwd()`) is built.\n * - `signals` are merged with a {@link TaskSignalProvider} when `memory` is\n * configured; otherwise the caller-provided signals are used verbatim (or\n * an empty array when none are provided). This avoids wiring\n * {@link TaskSignalProvider} — which requires a memory-backed thread — into\n * agents that have no memory.\n * - `errorProcessors` is used verbatim when provided; otherwise it defaults to\n * the ECONNRESET/bad-request retry stack plus prefill + provider-history\n * compatibility processors.\n * - `goal.prompt` defaults to {@link DEFAULT_GOAL_JUDGE_PROMPT} when a goal is\n * configured without one.\n *\n * @example\n * ```typescript\n * import { createCodingAgent } from '@mastra/core/coding-agent';\n *\n * const agent = createCodingAgent({\n * id: 'my-coding-agent',\n * name: 'My Coding Agent',\n * model: 'openai/gpt-5',\n * instructions: 'You are a helpful coding assistant.',\n * tools: {},\n * });\n * ```\n */\nexport function createCodingAgent(config: CreateCodingAgentConfig): Agent {\n const { basePath, workspace: _workspace, signals, errorProcessors, goal, memory, ...rest } = config;\n\n // Distinguish an absent `workspace` key (build the default) from an explicit\n // `workspace: undefined` (caller opts out — e.g. when the workspace is wired\n // elsewhere, such as at a controller/request-context level).\n const workspace = 'workspace' in config ? config.workspace : defaultWorkspace(basePath ?? process.cwd());\n\n // TaskSignalProvider needs a memory-backed thread to function. Only include\n // it when the caller has configured memory; merge it into caller-provided\n // signals so custom signal providers don't drop task tracking.\n const taskSignals = memory ? [new TaskSignalProvider()] : [];\n const resolvedSignals = signals ? [...signals, ...taskSignals] : taskSignals;\n\n // Treat an explicit `prompt: undefined` the same as an omitted prompt so the\n // documented default is preserved.\n const resolvedGoal = goal ? { ...goal, prompt: goal.prompt ?? DEFAULT_GOAL_JUDGE_PROMPT } : undefined;\n\n return new Agent({\n ...rest,\n memory,\n workspace,\n signals: resolvedSignals,\n errorProcessors: errorProcessors ?? defaultErrorProcessors(),\n ...(resolvedGoal ? { goal: resolvedGoal } : {}),\n });\n}\n"]}