@mastra/code-sdk 1.19.0-alpha.10 → 1.19.0-alpha.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"agent-instructions.js","names":[],"sources":["../../../src/agents/prompts/agent-instructions.ts"],"sourcesContent":["/**\n * Load project and global agent instruction files (AGENTS.md, CLAUDE.md).\n * Prefers AGENTS.md over CLAUDE.md when multiple exist at the same location.\n */\n\nimport { execFileSync } from 'node:child_process';\nimport { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { dirname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path';\nimport { DEFAULT_CONFIG_DIR } from '../../constants.js';\n\n// Filenames to check, in order of preference\nconst INSTRUCTION_FILES = ['AGENTS.md', 'CLAUDE.md'];\n\n// Locations to scan (relative to project root or home)\nconst PROJECT_LOCATIONS = [\n '', // project root\n '.claude',\n '.mastracode',\n];\n\nconst GLOBAL_LOCATIONS = ['.claude', '.mastracode', '.config/claude', '.config/mastracode'];\n\nexport interface InstructionSource {\n path: string;\n content: string;\n scope: 'global' | 'project';\n /** Git ref the content was read from, when not read off the working tree. */\n ref?: string;\n}\n\n/**\n * Reads project-scope instruction files. The default implementation reads the\n * working tree via `fs`; alternative readers can serve content from another\n * source (e.g. a trusted git ref) while keeping working-tree paths as the\n * addressing scheme.\n */\nexport interface InstructionFileReader {\n exists(path: string): boolean;\n read(path: string): string;\n /** Git ref backing this reader, recorded on the loaded sources. */\n ref?: string;\n}\n\nconst fsInstructionReader: InstructionFileReader = {\n exists: path => existsSync(path),\n read: path => readFileSync(path, 'utf-8'),\n};\n\nfunction realpathOrResolved(path: string): string {\n try {\n return realpathSync(path);\n } catch {\n return resolve(path);\n }\n}\n\nfunction createProjectPathResolver(projectPath: string): (path: string) => string | null {\n const canonicalRoot = realpathOrResolved(projectPath);\n return path => {\n const rel = relative(projectPath, path);\n if (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)) return rel.split(sep).join('/');\n\n // Match an alias of the project root, not the target of a checkout-controlled\n // descendant symlink. Missing descendants must still resolve against the ref.\n let ancestor = resolve(path);\n let projectRelativePath: string | null = null;\n while (true) {\n if (realpathOrResolved(ancestor) === canonicalRoot) {\n projectRelativePath = relative(ancestor, path).split(sep).join('/');\n }\n const parent = dirname(ancestor);\n if (parent === ancestor) return projectRelativePath;\n ancestor = parent;\n }\n };\n}\n\n/**\n * Create a reader that serves instruction files from a git ref instead of the\n * working tree. Paths are still addressed as working-tree paths under\n * `projectPath`; content comes from `git show <ref>:<relpath>` so an untrusted\n * checkout (e.g. a PR branch under review) cannot influence what is loaded.\n * Tries `origin/<ref>` first (remote truth), then the local ref. Any git\n * failure (missing ref, missing file, no repo) reports the file as absent.\n */\nexport function createGitRefInstructionReader(projectPath: string, ref: string): InstructionFileReader {\n const toRelative = createProjectPathResolver(projectPath);\n const show = (path: string): string | null => {\n const rel = toRelative(path);\n if (!rel) return null;\n for (const candidate of [`origin/${ref}`, ref]) {\n try {\n return execFileSync('git', ['-C', projectPath, 'show', `${candidate}:${rel}`], {\n encoding: 'utf-8',\n stdio: ['ignore', 'pipe', 'ignore'],\n maxBuffer: 1024 * 1024,\n });\n } catch {\n // Ref or file missing at this candidate — try the next one.\n }\n }\n return null;\n };\n return {\n ref,\n exists: path => show(path) !== null,\n read: path => {\n const content = show(path);\n if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);\n return content;\n },\n };\n}\n\n/**\n * Reader for the reactive reminder channel (AgentsMDInjector) that serves\n * paths under `projectPath` from a trusted git ref. Paths outside the project\n * fall back to the operator machine's filesystem (those are trusted); paths\n * inside the project are only ever resolved against the ref, never the\n * working tree, so an untrusted checkout cannot feed content in.\n */\nexport function createGitRefReminderReader(\n projectPath: string,\n ref: string,\n): {\n pathExists: (path: string) => boolean;\n isDirectory: (path: string) => boolean;\n readFile: (path: string) => string;\n getPathIdentity: (path: string) => string;\n} {\n const gitReader = createGitRefInstructionReader(projectPath, ref);\n const toRelative = createProjectPathResolver(projectPath);\n const canonicalRoot = realpathOrResolved(projectPath);\n const objectType = (rel: string): string | null => {\n if (rel === '') return 'tree'; // project root\n for (const candidate of [`origin/${ref}`, ref]) {\n try {\n return execFileSync('git', ['-C', projectPath, 'cat-file', '-t', `${candidate}:${rel}`], {\n encoding: 'utf-8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim();\n } catch {\n // Ref or object missing at this candidate — try the next one.\n }\n }\n return null;\n };\n return {\n pathExists: path => {\n const rel = toRelative(path);\n if (rel === null) return existsSync(path);\n return objectType(rel) !== null;\n },\n isDirectory: path => {\n const rel = toRelative(path);\n if (rel === null) {\n try {\n return statSync(path).isDirectory();\n } catch {\n return false;\n }\n }\n return objectType(rel) === 'tree';\n },\n readFile: path => {\n const rel = toRelative(path);\n if (rel === null) return readFileSync(path, 'utf-8');\n return gitReader.read(path);\n },\n getPathIdentity: path => {\n const rel = toRelative(path);\n // Only canonicalize the project root: checkout symlinks do not define\n // file identity in the trusted ref, including files missing on disk.\n return rel === null ? realpathOrResolved(path) : join(canonicalRoot, rel);\n },\n };\n}\n\n/**\n * Find the first existing instruction file at a given base path.\n * Prefers AGENTS.md over CLAUDE.md.\n */\nfunction findInstructionFile(basePath: string, reader: InstructionFileReader = fsInstructionReader): string | null {\n for (const filename of INSTRUCTION_FILES) {\n const fullPath = join(basePath, filename);\n if (reader.exists(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\n/**\n * Load all agent instruction files from global and project locations.\n * Returns an array of instruction sources, with global ones first.\n *\n * `projectReader` controls where project-scope content comes from (defaults to\n * the working tree). Global instructions read the operator machine's\n * filesystem, unless `skipGlobal` keeps them out entirely.\n */\nexport function loadAgentInstructions(\n projectPath: string,\n configDirName = DEFAULT_CONFIG_DIR,\n projectReader: InstructionFileReader = fsInstructionReader,\n { skipGlobal = false }: { skipGlobal?: boolean } = {},\n): InstructionSource[] {\n const sources: InstructionSource[] = [];\n const home = homedir();\n\n // Derive location arrays from the base constants, substituting the config dir name\n const projectLocations = PROJECT_LOCATIONS.map(loc => (loc === '.mastracode' ? configDirName : loc));\n const globalLocations = skipGlobal\n ? []\n : GLOBAL_LOCATIONS.map(loc => {\n if (loc === '.mastracode') return configDirName;\n // XDG-style path (~/.config/<name>): strip the leading dot since the\n // .config/ prefix already signals a hidden/config directory.\n if (loc === '.config/mastracode') return '.config/' + configDirName.replace(/^\\./, '');\n return loc;\n });\n\n // Load global instructions first\n for (const location of globalLocations) {\n const basePath = join(home, location);\n const filePath = findInstructionFile(basePath);\n if (filePath) {\n try {\n const content = readFileSync(filePath, 'utf-8').trim();\n if (content) {\n sources.push({ path: filePath, content, scope: 'global' });\n break; // Only use first found global instruction file\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n\n // Load project instructions\n for (const location of projectLocations) {\n const basePath = location ? join(projectPath, location) : projectPath;\n const filePath = findInstructionFile(basePath, projectReader);\n if (filePath) {\n try {\n const content = projectReader.read(filePath).trim();\n if (content) {\n sources.push({\n path: filePath,\n content,\n scope: 'project',\n ...(projectReader.ref ? { ref: projectReader.ref } : {}),\n });\n break; // Only use first found project instruction file\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n\n return sources;\n}\n\nexport function getStaticallyLoadedInstructionPaths(\n projectPath: string,\n configDirName = DEFAULT_CONFIG_DIR,\n projectReader?: InstructionFileReader,\n): string[] {\n return instructionSourcePaths(loadAgentInstructions(projectPath, configDirName, projectReader), [projectPath]);\n}\n\n/**\n * Directories a session's project instructions load from: the host's\n * `instructionRoots` (resolved against the working directory, the session's\n * own checkout first) when it sets any, else the working directory itself.\n */\nexport function sessionInstructionRoots(workingDir: string, instructionRoots?: readonly string[]): string[] {\n if (!instructionRoots?.length) return [workingDir];\n return [...new Set(instructionRoots.map(root => resolve(workingDir, root)))];\n}\n\n/**\n * The instruction files a session's system prompt carries. Global files load\n * once (unless `skipGlobal`), then each instruction root's project files, in\n * root order. An untrusted checkout never reads project files off the working\n * tree: with a `baseRef` the first root (the session's own checkout) is served\n * from that ref and the other roots are skipped; without one no project files\n * load.\n */\nexport function loadSessionInstructions({\n workingDir,\n instructionRoots,\n configDir,\n untrustedCheckout = false,\n baseRef,\n skipGlobal = false,\n}: {\n workingDir: string;\n instructionRoots?: readonly string[];\n configDir?: string;\n untrustedCheckout?: boolean;\n baseRef?: string;\n skipGlobal?: boolean;\n}): InstructionSource[] {\n const [primary, ...others] = sessionInstructionRoots(workingDir, instructionRoots);\n const primaryReader = untrustedCheckout\n ? baseRef\n ? createGitRefInstructionReader(primary!, baseRef)\n : { exists: () => false, read: () => '' }\n : undefined;\n const sources = loadAgentInstructions(primary!, configDir, primaryReader, { skipGlobal });\n if (untrustedCheckout) return sources;\n for (const root of others) {\n sources.push(...loadAgentInstructions(root, configDir, undefined, { skipGlobal: true }));\n }\n return sources;\n}\n\n/**\n * Paths of loaded instruction sources, each project source also under its\n * root's canonical path, so reactive reminders never repeat a file the\n * system prompt already carries.\n */\nexport function instructionSourcePaths(sources: InstructionSource[], roots: readonly string[]): string[] {\n return sources.flatMap(source => {\n const path = normalize(source.path);\n if (source.scope !== 'project') return [path];\n const root = roots.find(candidate => {\n const rel = relative(candidate, path);\n return rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);\n });\n if (!root) return [path];\n const canonicalPath = join(realpathOrResolved(root), relative(root, path));\n return path === canonicalPath ? [path] : [path, canonicalPath];\n });\n}\n\n/** Heading the agent-instructions block is introduced by in the system prompt. */\nexport const AGENT_INSTRUCTIONS_HEADING = '# Agent Instructions';\n\n/**\n * Format a single instruction source as it appears in the system prompt.\n *\n * Exported so callers that attribute prompt cost per source (the `/context`\n * audit) measure the exact block that is sent rather than reconstructing it.\n */\nexport function formatInstructionSource(source: InstructionSource): string {\n const label = source.scope === 'global' ? 'Global' : 'Project';\n const origin = source.ref ? `${source.path} (at ref ${source.ref})` : source.path;\n return `<!-- ${label} instructions from ${origin} -->\\n${source.content}`;\n}\n\n/**\n * Format loaded instructions into a string for the system prompt.\n */\nexport function formatAgentInstructions(sources: InstructionSource[]): string {\n if (sources.length === 0) return '';\n\n const sections = sources.map(formatInstructionSource);\n\n return `\\n${AGENT_INSTRUCTIONS_HEADING}\\n\\n${sections.join('\\n\\n')}\\n`;\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,oBAAoB,CAAC,aAAa,WAAW;AAGnD,MAAM,oBAAoB;CACxB;CACA;CACA;AACF;AAEA,MAAM,mBAAmB;CAAC;CAAW;CAAe;CAAkB;AAAoB;AAuB1F,MAAM,sBAA6C;CACjD,SAAQ,SAAQ,WAAW,IAAI;CAC/B,OAAM,SAAQ,aAAa,MAAM,OAAO;AAC1C;AAEA,SAAS,mBAAmB,MAAsB;CAChD,IAAI;EACF,OAAO,aAAa,IAAI;CAC1B,QAAQ;EACN,OAAO,QAAQ,IAAI;CACrB;AACF;AAEA,SAAS,0BAA0B,aAAsD;CACvF,MAAM,gBAAgB,mBAAmB,WAAW;CACpD,QAAO,SAAQ;EACb,MAAM,MAAM,SAAS,aAAa,IAAI;EACtC,IAAI,QAAQ,QAAQ,CAAC,IAAI,WAAW,KAAK,KAAK,KAAK,CAAC,WAAW,GAAG,GAAG,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;EAInG,IAAI,WAAW,QAAQ,IAAI;EAC3B,IAAI,sBAAqC;EACzC,OAAO,MAAM;GACX,IAAI,mBAAmB,QAAQ,MAAM,eACnC,sBAAsB,SAAS,UAAU,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;GAEpE,MAAM,SAAS,QAAQ,QAAQ;GAC/B,IAAI,WAAW,UAAU,OAAO;GAChC,WAAW;EACb;CACF;AACF;;;;;;;;;AAUA,SAAgB,8BAA8B,aAAqB,KAAoC;CACrG,MAAM,aAAa,0BAA0B,WAAW;CACxD,MAAM,QAAQ,SAAgC;EAC5C,MAAM,MAAM,WAAW,IAAI;EAC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AM,MAAM,SAAS,WAAW,IAAI;GACpC,OAAO,QAAQ,QAAQ,CAAC,IAAI,WAAW,KAAK,KAAK,KAAK,CAAC,WAAW,GAAG;EACvE,CAAC;EACD,IAAI,CAAC,MAAM,OAAO,CAAC,IAAI;EACvB,MAAM,gBAAgB,KAAK,mBAAmB,IAAI,GAAG,SAAS,MAAM,IAAI,CAAC;EACzE,OAAO,SAAS,gBAAgB,CAAC,IAAI,IAAI,CAAC,MAAM,aAAa;CAC/D,CAAC;AACH;;AAGA,MAAa,6BAA6B;;;;;;;AAQ1C,SAAgB,wBAAwB,QAAmC;CAGzE,OAAO,QAFO,OAAO,UAAU,WAAW,WAAW,UAEhC,qBADN,OAAO,MAAM,GAAG,OAAO,KAAK,WAAW,OAAO,IAAI,KAAK,OAAO,KAC5B,QAAQ,OAAO;AAClE;;;;AAKA,SAAgB,wBAAwB,SAAsC;CAC5E,IAAI,QAAQ,WAAW,GAAG,OAAO;CAEjC,MAAM,WAAW,QAAQ,IAAI,uBAAuB;CAEpD,OAAO,KAAK,2BAA2B,MAAM,SAAS,KAAK,MAAM,EAAE;AACrE"}
1
+ {"version":3,"file":"agent-instructions.js","names":[],"sources":["../../../src/agents/prompts/agent-instructions.ts"],"sourcesContent":["/**\n * Load project and global agent instruction files (AGENTS.md, CLAUDE.md).\n * Prefers AGENTS.md over CLAUDE.md when multiple exist at the same location.\n */\n\nimport { execFileSync, spawn } from 'node:child_process';\nimport { createHash } from 'node:crypto';\nimport { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';\nimport { readFile, realpath, stat } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path';\nimport { DEFAULT_CONFIG_DIR } from '../../constants.js';\n\n// Filenames to check, in order of preference\nconst INSTRUCTION_FILES = ['AGENTS.md', 'CLAUDE.md'];\n\n// Locations to scan (relative to project root or home)\nconst PROJECT_LOCATIONS = [\n '', // project root\n '.claude',\n '.mastracode',\n];\n\nconst GLOBAL_LOCATIONS = ['.claude', '.mastracode', '.config/claude', '.config/mastracode'];\n\nexport interface InstructionSource {\n path: string;\n content: string;\n scope: 'global' | 'project';\n /** Git ref the content was read from, when not read off the working tree. */\n ref?: string;\n}\n\n/**\n * Reads project-scope instruction files. The default implementation reads the\n * working tree via `fs`; alternative readers can serve content from another\n * source (e.g. a trusted git ref) while keeping working-tree paths as the\n * addressing scheme.\n */\nexport interface InstructionFileReader {\n exists(path: string): boolean;\n read(path: string): string;\n /** Git ref backing this reader, recorded on the loaded sources. */\n ref?: string;\n}\n\nconst fsInstructionReader: InstructionFileReader = {\n exists: path => existsSync(path),\n read: path => readFileSync(path, 'utf-8'),\n};\n\nfunction realpathOrResolved(path: string): string {\n try {\n return realpathSync(path);\n } catch {\n return resolve(path);\n }\n}\n\nfunction createProjectPathResolver(projectPath: string): (path: string) => string | null {\n const canonicalRoot = realpathOrResolved(projectPath);\n return path => {\n const rel = relative(projectPath, path);\n if (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)) return rel.split(sep).join('/');\n\n // Match an alias of the project root, not the target of a checkout-controlled\n // descendant symlink. Missing descendants must still resolve against the ref.\n let ancestor = resolve(path);\n let projectRelativePath: string | null = null;\n while (true) {\n if (realpathOrResolved(ancestor) === canonicalRoot) {\n projectRelativePath = relative(ancestor, path).split(sep).join('/');\n }\n const parent = dirname(ancestor);\n if (parent === ancestor) return projectRelativePath;\n ancestor = parent;\n }\n };\n}\n\n// Keys count towards the limit too: a path a folder lacks is cached as an empty listing.\nconst GIT_OBJECT_CACHE_MAX_CHARS = 16 * 1024 * 1024;\nconst gitObjectOutputs = new Map<string, string>();\nlet gitObjectCacheChars = 0;\n\n// The cache is shared by every checkout in the process, so a read is kept only once it is known to\n// match its id: git checks the tree it is asked to list, and `matchesId` covers what git does not check.\n// A blobless clone fetches file content over the network, so a failed read is never cached.\nfunction gitObjectRead(\n projectPath: string,\n args: string[],\n matchesId: (output: Buffer) => boolean = () => true,\n): string | null {\n const key = args.join('\\0');\n const cached = gitObjectOutputs.get(key);\n if (cached !== undefined) return cached;\n try {\n const raw = execFileSync('git', ['--no-replace-objects', '-C', projectPath, '--literal-pathspecs', ...args], {\n stdio: ['ignore', 'pipe', 'ignore'],\n maxBuffer: 1024 * 1024,\n });\n if (!matchesId(raw)) return null;\n const output = raw.toString('utf-8');\n gitObjectOutputs.set(key, output);\n gitObjectCacheChars += key.length + output.length;\n for (const [oldest, evicted] of gitObjectOutputs) {\n if (gitObjectCacheChars <= GIT_OBJECT_CACHE_MAX_CHARS) break;\n gitObjectOutputs.delete(oldest);\n gitObjectCacheChars -= oldest.length + evicted.length;\n }\n return output;\n } catch {\n return null;\n }\n}\n\nfunction blobMatchesId(id: string, content: Buffer): boolean {\n const hash = createHash(id.length === 40 ? 'sha1' : 'sha256');\n return hash.update(`blob ${content.length}\\0`).update(content).digest('hex') === id;\n}\n\nfunction createGitRefLookup(projectPath: string, ref: string) {\n // Resolved on first use and kept, so a lookup reads the ref as it stood then: build one per model step.\n let trees: string[] | undefined;\n const resolveTrees = (): string[] => {\n // A ref name never holds a space or control character, and each line of the batch below names\n // one object, so a line break in `ref` would add names of its own, such as the checkout's `HEAD`.\n if ([...ref].some(char => char <= ' ' || char === '\\x7f')) return [];\n try {\n const output = execFileSync('git', ['-C', projectPath, 'cat-file', '--batch-check=%(objectname)'], {\n encoding: 'utf-8',\n input: `origin/${ref}^{tree}\\n${ref}^{tree}\\n`,\n stdio: ['pipe', 'pipe', 'ignore'],\n });\n return [...new Set(output.split('\\n').filter(line => /^[0-9a-f]+$/.test(line)))];\n } catch {\n return [];\n }\n };\n // One folder level per call: git hash-checks the tree it lists, not the trees it walks through.\n const entryAt = (tree: string, rel: string): string[] => {\n let entry = ['', 'tree', tree];\n for (const name of rel.split('/')) {\n if (entry[1] !== 'tree') return [];\n entry = gitObjectRead(projectPath, ['ls-tree', '--full-tree', entry[2]!, '--', name])?.split(/\\s/) ?? [];\n }\n return entry;\n };\n return {\n type: (rel: string): string | null => {\n for (const tree of (trees ??= resolveTrees())) {\n const [, type] = entryAt(tree, rel);\n if (type) return type;\n }\n return null;\n },\n show: (rel: string): string | null => {\n for (const tree of (trees ??= resolveTrees())) {\n const [, type, blob] = entryAt(tree, rel);\n if (type !== 'blob' || !blob) continue;\n const content = gitObjectRead(projectPath, ['cat-file', 'blob', blob], raw => blobMatchesId(blob, raw));\n if (content !== null) return content;\n }\n return null;\n },\n };\n}\n\n/**\n * Create a reader that serves instruction files from a git ref instead of the\n * working tree. Paths are still addressed as working-tree paths under\n * `projectPath`; content comes from the blob at `<ref>:<relpath>` so an untrusted\n * checkout (e.g. a PR branch under review) cannot influence what is loaded.\n * Tries `origin/<ref>` first (remote truth), then the local ref. Any git\n * failure (missing ref, missing file, no repo) reports the file as absent.\n */\nexport function createGitRefInstructionReader(projectPath: string, ref: string): InstructionFileReader {\n const toRelative = createProjectPathResolver(projectPath);\n const lookup = createGitRefLookup(projectPath, ref);\n const show = (path: string): string | null => {\n const rel = toRelative(path);\n return rel ? lookup.show(rel) : null;\n };\n return {\n ref,\n exists: path => show(path) !== null,\n read: path => {\n const content = show(path);\n if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);\n return content;\n },\n };\n}\n\n/**\n * Reader for the reactive reminder channel (AgentsMDInjector) that serves\n * paths under `projectPath` from a trusted git ref. Paths outside the project\n * fall back to the operator machine's filesystem (those are trusted); paths\n * inside the project are only ever resolved against the ref, never the\n * working tree, so an untrusted checkout cannot feed content in.\n */\nexport function createGitRefReminderReader(\n projectPath: string,\n ref: string,\n): {\n pathExists: (path: string) => boolean;\n isDirectory: (path: string) => boolean;\n readFile: (path: string) => string;\n getPathIdentity: (path: string) => string;\n} {\n const toRelative = createProjectPathResolver(projectPath);\n const canonicalRoot = realpathOrResolved(projectPath);\n const lookup = createGitRefLookup(projectPath, ref);\n const objectType = (rel: string): string | null => {\n if (rel === '') return 'tree'; // project root\n return lookup.type(rel);\n };\n return {\n pathExists: path => {\n const rel = toRelative(path);\n if (rel === null) return existsSync(path);\n return objectType(rel) !== null;\n },\n isDirectory: path => {\n const rel = toRelative(path);\n if (rel === null) {\n try {\n return statSync(path).isDirectory();\n } catch {\n return false;\n }\n }\n return objectType(rel) === 'tree';\n },\n readFile: path => {\n const rel = toRelative(path);\n if (rel === null) return readFileSync(path, 'utf-8');\n const content = rel ? lookup.show(rel) : null;\n if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);\n return content;\n },\n getPathIdentity: path => {\n const rel = toRelative(path);\n // Only canonicalize the project root: checkout symlinks do not define\n // file identity in the trusted ref, including files missing on disk.\n return rel === null ? realpathOrResolved(path) : join(canonicalRoot, rel);\n },\n };\n}\n\n// Keep in-flight object reads shared across concurrent prompt and reminder lookups.\nconst pendingGitObjects = new Map<string, Promise<string | null>>();\n\nfunction gitAsync(args: string[], input?: string): Promise<Buffer | null> {\n return new Promise(resolveOutput => {\n let child: ReturnType<typeof spawn>;\n try {\n child = spawn('git', args, { stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'ignore'] });\n } catch {\n resolveOutput(null);\n return;\n }\n const chunks: Buffer[] = [];\n let size = 0;\n let failed = false;\n child.stdout?.on('data', (chunk: Buffer) => {\n size += chunk.length;\n if (size > 1024 * 1024) {\n failed = true;\n child.kill();\n } else chunks.push(chunk);\n });\n child.on('error', () => {\n failed = true;\n });\n child.on('close', code => resolveOutput(!failed && code === 0 ? Buffer.concat(chunks) : null));\n if (input !== undefined) {\n child.stdin?.on('error', () => {\n failed = true;\n });\n child.stdin?.end(input);\n }\n });\n}\n\nasync function gitObjectReadAsync(\n projectPath: string,\n args: string[],\n matchesId: (raw: Buffer) => boolean = () => true,\n): Promise<string | null> {\n const key = args.join('\\0');\n const cached = gitObjectOutputs.get(key);\n if (cached !== undefined) return cached;\n const pendingKey = `${projectPath}\\0${key}`;\n let pending = pendingGitObjects.get(pendingKey);\n if (!pending) {\n pending = (async () => {\n const raw = await gitAsync(['--no-replace-objects', '-C', projectPath, '--literal-pathspecs', ...args]);\n if (!raw || !matchesId(raw)) return null;\n const output = raw.toString('utf-8');\n gitObjectOutputs.set(key, output);\n gitObjectCacheChars += key.length + output.length;\n for (const [oldest, evicted] of gitObjectOutputs) {\n if (gitObjectCacheChars <= GIT_OBJECT_CACHE_MAX_CHARS) break;\n gitObjectOutputs.delete(oldest);\n gitObjectCacheChars -= oldest.length + evicted.length;\n }\n return output;\n })();\n pendingGitObjects.set(pendingKey, pending);\n void pending.then(\n () => pendingGitObjects.delete(pendingKey),\n () => pendingGitObjects.delete(pendingKey),\n );\n }\n return pending;\n}\n\nasync function realpathOrResolvedAsync(path: string): Promise<string> {\n try {\n return await realpath(path);\n } catch {\n return resolve(path);\n }\n}\n\nasync function createProjectPathResolverAsync(projectPath: string): Promise<(path: string) => Promise<string | null>> {\n const canonicalRoot = await realpathOrResolvedAsync(projectPath);\n return async path => {\n const rel = relative(projectPath, path);\n if (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)) return rel.split(sep).join('/');\n let ancestor = resolve(path);\n let projectRelativePath: string | null = null;\n while (true) {\n if ((await realpathOrResolvedAsync(ancestor)) === canonicalRoot) {\n projectRelativePath = relative(ancestor, path).split(sep).join('/');\n }\n const parent = dirname(ancestor);\n if (parent === ancestor) return projectRelativePath;\n ancestor = parent;\n }\n };\n}\n\nfunction createGitRefLookupAsync(projectPath: string, ref: string) {\n let trees: Promise<string[]> | undefined;\n const resolveTrees = async (): Promise<string[]> => {\n if ([...ref].some(char => char <= ' ' || char === '\\x7f')) return [];\n const raw = await gitAsync(\n ['-C', projectPath, 'cat-file', '--batch-check=%(objectname)'],\n `origin/${ref}^{tree}\\n${ref}^{tree}\\n`,\n );\n return raw\n ? [\n ...new Set(\n raw\n .toString('utf-8')\n .split('\\n')\n .filter(line => /^[0-9a-f]+$/.test(line)),\n ),\n ]\n : [];\n };\n const entryAt = async (tree: string, rel: string): Promise<string[]> => {\n let entry = ['', 'tree', tree];\n for (const name of rel.split('/')) {\n if (entry[1] !== 'tree') return [];\n entry =\n (await gitObjectReadAsync(projectPath, ['ls-tree', '--full-tree', entry[2]!, '--', name]))?.split(/\\s/) ?? [];\n }\n return entry;\n };\n return {\n type: async (rel: string): Promise<string | null> => {\n for (const tree of await (trees ??= resolveTrees())) {\n const [, type] = await entryAt(tree, rel);\n if (type) return type;\n }\n return null;\n },\n show: async (rel: string): Promise<string | null> => {\n for (const tree of await (trees ??= resolveTrees())) {\n const [, type, blob] = await entryAt(tree, rel);\n if (type !== 'blob' || !blob) continue;\n const content = await gitObjectReadAsync(projectPath, ['cat-file', 'blob', blob], raw =>\n blobMatchesId(blob, raw),\n );\n if (content !== null) return content;\n }\n return null;\n },\n };\n}\n\nexport async function createGitRefInstructionReaderAsync(\n projectPath: string,\n ref: string,\n): Promise<AsyncInstructionFileReader> {\n const toRelative = await createProjectPathResolverAsync(projectPath);\n const lookup = createGitRefLookupAsync(projectPath, ref);\n const show = async (path: string) => {\n const rel = await toRelative(path);\n return rel ? lookup.show(rel) : null;\n };\n return {\n ref,\n exists: async path => (await show(path)) !== null,\n read: async path => {\n const content = await show(path);\n if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);\n return content;\n },\n };\n}\n\nexport function createGitRefReminderReaderAsync(projectPath: string, ref: string) {\n const toRelative = createProjectPathResolverAsync(projectPath);\n const canonicalRoot = realpathOrResolvedAsync(projectPath);\n const lookup = createGitRefLookupAsync(projectPath, ref);\n const objectType = (rel: string) => (rel === '' ? Promise.resolve('tree') : lookup.type(rel));\n return {\n pathExists: async (path: string) => {\n const rel = await (await toRelative)(path);\n if (rel === null) {\n try {\n await stat(path);\n return true;\n } catch {\n return false;\n }\n }\n return (await objectType(rel)) !== null;\n },\n isDirectory: async (path: string) => {\n const rel = await (await toRelative)(path);\n if (rel === null) {\n try {\n return (await stat(path)).isDirectory();\n } catch {\n return false;\n }\n }\n return (await objectType(rel)) === 'tree';\n },\n readFile: async (path: string) => {\n const rel = await (await toRelative)(path);\n if (rel === null) return readFile(path, 'utf-8');\n const content = rel ? await lookup.show(rel) : null;\n if (content === null) throw new Error(`Not found at ref ${ref}: ${path}`);\n return content;\n },\n getPathIdentity: async (path: string) => {\n const rel = await (await toRelative)(path);\n return rel === null ? realpathOrResolvedAsync(path) : join(await canonicalRoot, rel);\n },\n };\n}\n\nexport interface AsyncInstructionFileReader {\n exists(path: string): Promise<boolean>;\n read(path: string): Promise<string>;\n ref?: string;\n}\n\nconst fsInstructionReaderAsync: AsyncInstructionFileReader = {\n exists: async path => {\n try {\n await stat(path);\n return true;\n } catch {\n return false;\n }\n },\n read: path => readFile(path, 'utf-8'),\n};\n\nexport async function loadAgentInstructionsAsync(\n projectPath: string,\n configDirName = DEFAULT_CONFIG_DIR,\n projectReader: AsyncInstructionFileReader = fsInstructionReaderAsync,\n { skipGlobal = false }: { skipGlobal?: boolean } = {},\n): Promise<InstructionSource[]> {\n const sources: InstructionSource[] = [];\n const projectLocations = PROJECT_LOCATIONS.map(loc => (loc === '.mastracode' ? configDirName : loc));\n const globalLocations = skipGlobal\n ? []\n : GLOBAL_LOCATIONS.map(loc => {\n if (loc === '.mastracode') return configDirName;\n if (loc === '.config/mastracode') return '.config/' + configDirName.replace(/^\\./, '');\n return loc;\n });\n for (const location of globalLocations) {\n const base = join(homedir(), location);\n for (const filename of INSTRUCTION_FILES) {\n const path = join(base, filename);\n if (!(await fsInstructionReaderAsync.exists(path))) continue;\n try {\n const content = (await fsInstructionReaderAsync.read(path)).trim();\n if (content) {\n sources.push({ path, content, scope: 'global' });\n break;\n }\n } catch {\n /* Skip unreadable instructions. */\n }\n break;\n }\n if (sources.length) break;\n }\n for (const location of projectLocations) {\n const base = location ? join(projectPath, location) : projectPath;\n for (const filename of INSTRUCTION_FILES) {\n const path = join(base, filename);\n if (!(await projectReader.exists(path))) continue;\n try {\n const content = (await projectReader.read(path)).trim();\n if (content) {\n sources.push({ path, content, scope: 'project', ...(projectReader.ref ? { ref: projectReader.ref } : {}) });\n break;\n }\n } catch {\n /* Skip unreadable instructions. */\n }\n break;\n }\n if (sources.some(source => source.scope === 'project')) break;\n }\n return sources;\n}\n\nexport async function loadSessionInstructionsAsync({\n workingDir,\n instructionRoots,\n configDir,\n untrustedCheckout = false,\n baseRef,\n skipGlobal = false,\n}: {\n workingDir: string;\n instructionRoots?: readonly string[];\n configDir?: string;\n untrustedCheckout?: boolean;\n baseRef?: string;\n skipGlobal?: boolean;\n}): Promise<InstructionSource[]> {\n const [primary, ...others] = sessionInstructionRoots(workingDir, instructionRoots);\n const reader = untrustedCheckout\n ? baseRef\n ? await createGitRefInstructionReaderAsync(primary!, baseRef)\n : { exists: async () => false, read: async () => '' }\n : undefined;\n const sources = await loadAgentInstructionsAsync(primary!, configDir, reader, { skipGlobal });\n if (!untrustedCheckout) {\n for (const root of others)\n sources.push(...(await loadAgentInstructionsAsync(root, configDir, undefined, { skipGlobal: true })));\n }\n return sources;\n}\n\n/**\n * Find the first existing instruction file at a given base path.\n * Prefers AGENTS.md over CLAUDE.md.\n */\nfunction findInstructionFile(basePath: string, reader: InstructionFileReader = fsInstructionReader): string | null {\n for (const filename of INSTRUCTION_FILES) {\n const fullPath = join(basePath, filename);\n if (reader.exists(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\n/**\n * Load all agent instruction files from global and project locations.\n * Returns an array of instruction sources, with global ones first.\n *\n * `projectReader` controls where project-scope content comes from (defaults to\n * the working tree). Global instructions read the operator machine's\n * filesystem, unless `skipGlobal` keeps them out entirely.\n */\nexport function loadAgentInstructions(\n projectPath: string,\n configDirName = DEFAULT_CONFIG_DIR,\n projectReader: InstructionFileReader = fsInstructionReader,\n { skipGlobal = false }: { skipGlobal?: boolean } = {},\n): InstructionSource[] {\n const sources: InstructionSource[] = [];\n const home = homedir();\n\n // Derive location arrays from the base constants, substituting the config dir name\n const projectLocations = PROJECT_LOCATIONS.map(loc => (loc === '.mastracode' ? configDirName : loc));\n const globalLocations = skipGlobal\n ? []\n : GLOBAL_LOCATIONS.map(loc => {\n if (loc === '.mastracode') return configDirName;\n // XDG-style path (~/.config/<name>): strip the leading dot since the\n // .config/ prefix already signals a hidden/config directory.\n if (loc === '.config/mastracode') return '.config/' + configDirName.replace(/^\\./, '');\n return loc;\n });\n\n // Load global instructions first\n for (const location of globalLocations) {\n const basePath = join(home, location);\n const filePath = findInstructionFile(basePath);\n if (filePath) {\n try {\n const content = readFileSync(filePath, 'utf-8').trim();\n if (content) {\n sources.push({ path: filePath, content, scope: 'global' });\n break; // Only use first found global instruction file\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n\n // Load project instructions\n for (const location of projectLocations) {\n const basePath = location ? join(projectPath, location) : projectPath;\n const filePath = findInstructionFile(basePath, projectReader);\n if (filePath) {\n try {\n const content = projectReader.read(filePath).trim();\n if (content) {\n sources.push({\n path: filePath,\n content,\n scope: 'project',\n ...(projectReader.ref ? { ref: projectReader.ref } : {}),\n });\n break; // Only use first found project instruction file\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n\n return sources;\n}\n\nexport function getStaticallyLoadedInstructionPaths(\n projectPath: string,\n configDirName = DEFAULT_CONFIG_DIR,\n projectReader?: InstructionFileReader,\n): string[] {\n return instructionSourcePaths(loadAgentInstructions(projectPath, configDirName, projectReader), [projectPath]);\n}\n\n/**\n * Directories a session's project instructions load from: the host's\n * `instructionRoots` (resolved against the working directory, the session's\n * own checkout first) when it sets any, else the working directory itself.\n */\nexport function sessionInstructionRoots(workingDir: string, instructionRoots?: readonly string[]): string[] {\n if (!instructionRoots?.length) return [workingDir];\n return [...new Set(instructionRoots.map(root => resolve(workingDir, root)))];\n}\n\n/**\n * The instruction files a session's system prompt carries. Global files load\n * once (unless `skipGlobal`), then each instruction root's project files, in\n * root order. An untrusted checkout never reads project files off the working\n * tree: with a `baseRef` the first root (the session's own checkout) is served\n * from that ref and the other roots are skipped; without one no project files\n * load.\n */\nexport function loadSessionInstructions({\n workingDir,\n instructionRoots,\n configDir,\n untrustedCheckout = false,\n baseRef,\n skipGlobal = false,\n}: {\n workingDir: string;\n instructionRoots?: readonly string[];\n configDir?: string;\n untrustedCheckout?: boolean;\n baseRef?: string;\n skipGlobal?: boolean;\n}): InstructionSource[] {\n const [primary, ...others] = sessionInstructionRoots(workingDir, instructionRoots);\n const primaryReader = untrustedCheckout\n ? baseRef\n ? createGitRefInstructionReader(primary!, baseRef)\n : { exists: () => false, read: () => '' }\n : undefined;\n const sources = loadAgentInstructions(primary!, configDir, primaryReader, { skipGlobal });\n if (untrustedCheckout) return sources;\n for (const root of others) {\n sources.push(...loadAgentInstructions(root, configDir, undefined, { skipGlobal: true }));\n }\n return sources;\n}\n\n/**\n * Paths of loaded instruction sources, each project source also under its\n * root's canonical path, so reactive reminders never repeat a file the\n * system prompt already carries.\n */\nexport function instructionSourcePaths(sources: InstructionSource[], roots: readonly string[]): string[] {\n return sources.flatMap(source => {\n const path = normalize(source.path);\n if (source.scope !== 'project') return [path];\n const root = roots.find(candidate => {\n const rel = relative(candidate, path);\n return rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);\n });\n if (!root) return [path];\n const canonicalPath = join(realpathOrResolved(root), relative(root, path));\n return path === canonicalPath ? [path] : [path, canonicalPath];\n });\n}\n\n/** Heading the agent-instructions block is introduced by in the system prompt. */\nexport const AGENT_INSTRUCTIONS_HEADING = '# Agent Instructions';\n\n/**\n * Format a single instruction source as it appears in the system prompt.\n *\n * Exported so callers that attribute prompt cost per source (the `/context`\n * audit) measure the exact block that is sent rather than reconstructing it.\n */\nexport function formatInstructionSource(source: InstructionSource): string {\n const label = source.scope === 'global' ? 'Global' : 'Project';\n const origin = source.ref ? `${source.path} (at ref ${source.ref})` : source.path;\n return `<!-- ${label} instructions from ${origin} -->\\n${source.content}`;\n}\n\n/**\n * Format loaded instructions into a string for the system prompt.\n */\nexport function formatAgentInstructions(sources: InstructionSource[]): string {\n if (sources.length === 0) return '';\n\n const sections = sources.map(formatInstructionSource);\n\n return `\\n${AGENT_INSTRUCTIONS_HEADING}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AK,cAAa;GACnC,MAAM,MAAM,SAAS,WAAW,IAAI;GACpC,OAAO,QAAQ,QAAQ,CAAC,IAAI,WAAW,KAAK,KAAK,KAAK,CAAC,WAAW,GAAG;EACvE,CAAC;EACD,IAAI,CAAC,MAAM,OAAO,CAAC,IAAI;EACvB,MAAM,gBAAgB,KAAK,mBAAmB,IAAI,GAAG,SAAS,MAAM,IAAI,CAAC;EACzE,OAAO,SAAS,gBAAgB,CAAC,IAAI,IAAI,CAAC,MAAM,aAAa;CAC/D,CAAC;AACH;;AAGA,MAAa,6BAA6B;;;;;;;AAQ1C,SAAgB,wBAAwB,QAAmC;CAGzE,OAAO,QAFO,OAAO,UAAU,WAAW,WAAW,UAEhC,qBADN,OAAO,MAAM,GAAG,OAAO,KAAK,WAAW,OAAO,IAAI,KAAK,OAAO,KAC5B,QAAQ,OAAO;AAClE;;;;AAKA,SAAgB,wBAAwB,SAAsC;CAC5E,IAAI,QAAQ,WAAW,GAAG,OAAO;CAEjC,MAAM,WAAW,QAAQ,IAAI,uBAAuB;CAEpD,OAAO,KAAK,2BAA2B,MAAM,SAAS,KAAK,MAAM,EAAE;AACrE"}
@@ -6,6 +6,7 @@ export { planModePrompt } from './plan.js';
6
6
  export { fastModePrompt } from './fast.js';
7
7
  import type { PromptContext as BasePromptContext } from '@mastra/core/coding-agent';
8
8
  import type { RequestContextReader } from '../../auth/account-routing-context.js';
9
+ import type { InstructionSource } from './agent-instructions.js';
9
10
  export interface PromptContext extends Omit<BasePromptContext, 'toolGuidance'> {
10
11
  modeId: string;
11
12
  state?: any;
@@ -51,9 +52,10 @@ export declare function joinPromptSections(sections: PromptSection[]): string;
51
52
  * Combines the base prompt with mode-specific instructions.
52
53
  */
53
54
  export declare function buildFullPrompt(ctx: PromptContext): string;
55
+ export declare function buildFullPromptSectionsAsync(ctx: PromptContext): Promise<PromptSection[]>;
54
56
  /**
55
57
  * Build the system prompt as labeled sections. `buildFullPrompt` is the join of
56
58
  * these, so the two can never disagree about what the model receives.
57
59
  */
58
- export declare function buildFullPromptSections(ctx: PromptContext): PromptSection[];
60
+ export declare function buildFullPromptSections(ctx: PromptContext, loadedInstructions?: InstructionSource[]): PromptSection[];
59
61
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/prompts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAclF,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,iBAAiB,EAAE,cAAc,CAAC;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0FAA0F;IAC1F,cAAc,CAAC,EAAE,oBAAoB,CAAC;IACtC,sFAAsF;IACtF,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,6FAA6F;IAC7F,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAQD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,EAAE,EAAE,MAAM,CAAC;IACX,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,MAA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;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAQD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,EAAE,EAAE,MAAM,CAAC;IACX,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,gEAAgE;AAChE,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAM,CAKpE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAE1D;AAED,wBAAsB,4BAA4B,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAY/F;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,aAAa,EAAE,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,GAAG,aAAa,EAAE,CAgIrH"}
@@ -7,7 +7,7 @@ import "../../tools/index.js";
7
7
  import { getLocalPlansRelativeDir } from "../../utils/plans.js";
8
8
  import { hasParallelKey, hasTavilyKey } from "../../tools/web-search.js";
9
9
  import { resolveProviderWebSearchRoute } from "../model.js";
10
- import { AGENT_INSTRUCTIONS_HEADING, formatInstructionSource, loadSessionInstructions } from "./agent-instructions.js";
10
+ import { AGENT_INSTRUCTIONS_HEADING, formatInstructionSource, loadSessionInstructions, loadSessionInstructionsAsync } from "./agent-instructions.js";
11
11
  import { modelSpecificPrompts } from "./model.js";
12
12
  import { buildToolGuidance } from "./tool-guidance.js";
13
13
  import { buildBasePrompt } from "@mastra/core/coding-agent";
@@ -28,11 +28,21 @@ function joinPromptSections(sections) {
28
28
  function buildFullPrompt(ctx) {
29
29
  return joinPromptSections(buildFullPromptSections(ctx));
30
30
  }
31
+ async function buildFullPromptSectionsAsync(ctx) {
32
+ return buildFullPromptSections(ctx, ctx.workingDir ? await loadSessionInstructionsAsync({
33
+ workingDir: ctx.workingDir,
34
+ instructionRoots: Array.isArray(ctx.state?.instructionRoots) ? ctx.state.instructionRoots : void 0,
35
+ configDir: ctx.state?.configDir,
36
+ untrustedCheckout: ctx.state?.untrustedCheckout === true,
37
+ baseRef: typeof ctx.state?.baseRef === "string" ? ctx.state.baseRef : void 0,
38
+ skipGlobal: ctx.state?.skipGlobalInstructions === true
39
+ }) : []);
40
+ }
31
41
  /**
32
42
  * Build the system prompt as labeled sections. `buildFullPrompt` is the join of
33
43
  * these, so the two can never disagree about what the model receives.
34
44
  */
35
- function buildFullPromptSections(ctx) {
45
+ function buildFullPromptSections(ctx, loadedInstructions) {
36
46
  const hasWebExtract = hasParallelKey() || hasTavilyKey();
37
47
  const hasWebSearch = hasWebExtract || resolveProviderWebSearchRoute(ctx.modelId, { requestContext: ctx.requestContext }) !== void 0;
38
48
  const deniedTools = /* @__PURE__ */ new Set();
@@ -80,14 +90,14 @@ function buildFullPromptSections(ctx) {
80
90
  const configDir = ctx.state?.configDir;
81
91
  const baseRef = typeof ctx.state?.baseRef === "string" ? ctx.state.baseRef : void 0;
82
92
  const instructionRoots = Array.isArray(ctx.state?.instructionRoots) ? ctx.state.instructionRoots : void 0;
83
- const instructionSources = ctx.workingDir ? loadSessionInstructions({
93
+ const instructionSources = loadedInstructions ?? (ctx.workingDir ? loadSessionInstructions({
84
94
  workingDir: ctx.workingDir,
85
95
  instructionRoots,
86
96
  configDir,
87
97
  untrustedCheckout: ctx.state?.untrustedCheckout === true,
88
98
  baseRef,
89
99
  skipGlobal: ctx.state?.skipGlobalInstructions === true
90
- }) : [];
100
+ }) : []);
91
101
  const instructionSections = instructionSources.map((source, index) => {
92
102
  const isFirst = index === 0;
93
103
  const isLast = index === instructionSources.length - 1;
@@ -128,6 +138,6 @@ function buildFullPromptSections(ctx) {
128
138
  }
129
139
  ].filter((section) => Boolean(section.content));
130
140
  }
131
- export { buildFullPrompt, buildFullPromptSections, buildModePrompt, buildModePromptFn, fastModePrompt, joinPromptSections, planModePrompt };
141
+ export { buildFullPrompt, buildFullPromptSections, buildFullPromptSectionsAsync, buildModePrompt, buildModePromptFn, fastModePrompt, joinPromptSections, planModePrompt };
132
142
 
133
143
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/agents/prompts/index.ts"],"sourcesContent":["/**\n * Prompt system — exports the prompt builder and mode-specific prompts.\n */\n\nexport { buildModePrompt, buildModePromptFn } from './build.js';\nexport { planModePrompt } from './plan.js';\nexport { fastModePrompt } from './fast.js';\n\nimport { buildBasePrompt } from '@mastra/core/coding-agent';\nimport type { PromptContext as BasePromptContext } from '@mastra/core/coding-agent';\nimport type { RequestContextReader } from '../../auth/account-routing-context.js';\nimport { loadSettings, resolveLspSetting } from '../../onboarding/settings.js';\nimport { MC_TOOLS } from '../../tool-names.js';\nimport { hasParallelKey, hasTavilyKey } from '../../tools/index.js';\nimport { getLocalPlansRelativeDir } from '../../utils/plans.js';\nimport { resolveProviderWebSearchRoute } from '../model.js';\nimport { loadSessionInstructions, formatInstructionSource, AGENT_INSTRUCTIONS_HEADING } from './agent-instructions.js';\nimport { buildModePromptFn } from './build.js';\nimport { fastModePrompt } from './fast.js';\nimport { modelSpecificPrompts } from './model.js';\nimport { planModePrompt } from './plan.js';\nimport { buildToolGuidance } from './tool-guidance.js';\n\n// Extended prompt context that includes runtime information\nexport interface PromptContext extends Omit<BasePromptContext, 'toolGuidance'> {\n modeId: string;\n state?: any;\n hostInstructions?: string;\n /** Request whose credentials decide the model's transport, and so its web search tool. */\n requestContext?: RequestContextReader;\n /** Controller built-in tools removed via `disableBuiltinTools`; treated as denied. */\n disabledBuiltinTools?: readonly string[];\n /** Host-configured workspace-relative plans directory (see `MastraCodeConfig.plansDir`). */\n plansDir?: string;\n /** Agent tools removed via `disabledTools` (e.g. `web_search`); treated as denied. */\n disabledTools?: readonly string[];\n /** Resolved in `buildFullPromptSections`; false when `submit_plan` is denied or disabled. */\n submitPlanAvailable?: boolean;\n currentDate: string;\n workingDir: string;\n}\n\nconst modePrompts: Record<string, string | ((ctx: PromptContext) => string)> = {\n build: buildModePromptFn,\n plan: planModePrompt,\n fast: fastModePrompt,\n};\n\n/**\n * One labeled piece of the assembled system prompt.\n *\n * The system prompt is a single string by the time it reaches the model, which\n * makes it impossible to say which configuration source is responsible for\n * which share of the context window. Building it as labeled sections and\n * joining them at the end keeps that attribution available to the `/context`\n * audit while guaranteeing the audit measures the exact text that is sent —\n * a parallel \"describe the prompt\" path would drift and report numbers for a\n * prompt that is no longer assembled this way.\n */\nexport interface PromptSection {\n /** Stable identifier, unique within a single build. */\n id: string;\n /** Human-readable label for display. */\n label: string;\n /** Optional provenance (e.g. the instruction file path). */\n detail?: string;\n /** The exact text contributed to the prompt. */\n content: string;\n}\n\n/** Join prompt sections into the final system prompt string. */\nexport function joinPromptSections(sections: PromptSection[]): string {\n return sections\n .map(section => section.content)\n .filter(Boolean)\n .join('\\n\\n');\n}\n\n/**\n * Build the full system prompt for a given mode and context.\n * Combines the base prompt with mode-specific instructions.\n */\nexport function buildFullPrompt(ctx: PromptContext): string {\n return joinPromptSections(buildFullPromptSections(ctx));\n}\n\n/**\n * Build the system prompt as labeled sections. `buildFullPrompt` is the join of\n * these, so the two can never disagree about what the model receives.\n */\nexport function buildFullPromptSections(ctx: PromptContext): PromptSection[] {\n // Determine whether web search tools are available\n // Parallel/Tavily register web_search and web_extract; provider search registers only web_search.\n const hasWebExtract = hasParallelKey() || hasTavilyKey();\n const hasWebSearch =\n hasWebExtract || resolveProviderWebSearchRoute(ctx.modelId, { requestContext: ctx.requestContext }) !== undefined;\n\n // Collect per-tool deny rules so guidance omits denied tools\n const deniedTools = new Set<string>();\n const permRules = ctx.state?.permissionRules as { tools?: Record<string, string> } | undefined;\n if (permRules?.tools) {\n for (const [name, policy] of Object.entries(permRules.tools)) {\n if (policy === 'deny') deniedTools.add(name);\n }\n }\n\n // Disabled built-ins are never registered, so they are denied for guidance too.\n for (const name of ctx.disabledBuiltinTools ?? []) deniedTools.add(name);\n // `createDynamicTools` drops disabled agent tools (such as web_search), so omit their guidance too.\n for (const name of ctx.disabledTools ?? []) deniedTools.add(name);\n\n // LSP is opt-in — when it is off the tool is never registered, so its\n // guidance must not be advertised either.\n if (resolveLspSetting(loadSettings().lsp) === false) deniedTools.add(MC_TOOLS.LSP_INSPECT);\n\n // Build mode-aware tool guidance\n const factoryProjectId = typeof ctx.state?.factoryProjectId === 'string' ? ctx.state.factoryProjectId : undefined;\n const toolGuidance = buildToolGuidance(ctx.modeId, {\n hasWebSearch,\n hasWebExtract,\n hasSubagents: ctx.hasSubagents,\n deniedTools,\n plansDir: getLocalPlansRelativeDir({ factoryProjectId, plansDir: ctx.plansDir }),\n });\n\n // Map new context to base context\n const baseCtx: BasePromptContext = {\n projectPath: ctx.workingDir || '(no workspace attached)',\n projectName: ctx.projectName || 'unknown',\n gitBranch: ctx.gitBranch,\n platform: process.platform,\n commonBinaries: ctx.commonBinaries,\n date: ctx.currentDate,\n mode: ctx.modeId,\n modelId: ctx.modelId,\n coAuthorName: ctx.coAuthorName,\n coAuthorEmail: ctx.coAuthorEmail,\n activePlan: ctx.state?.activePlan,\n hasSubagents: ctx.hasSubagents !== false && !deniedTools.has('subagent'),\n planApprovalStartsGoal: ctx.planApprovalStartsGoal,\n toolGuidance,\n };\n\n const base = buildBasePrompt(baseCtx);\n const entry = modePrompts[ctx.modeId] || modePrompts.build;\n const modeSpecific =\n (typeof entry === 'function' ? entry({ ...ctx, submitPlanAvailable: !deniedTools.has('submit_plan') }) : entry) ??\n '';\n const modelSpecific = ctx.modelId\n ? (modelSpecificPrompts[ctx.modelId as keyof typeof modelSpecificPrompts] ?? '')\n : '';\n\n // The current task list is carried on the agent state-signal lane (see\n // TaskStateProcessor) rather than injected into the cached system prompt. This\n // keeps the prompt prefix stable across task updates (preserving prompt cache)\n // while still surviving observational-memory truncation.\n\n // Load and inject agent instructions from AGENTS.md/CLAUDE.md files.\n // Untrusted checkouts (e.g. a PR branch under review) never read\n // project-scope files off the working tree: their AGENTS.md is\n // attacker-writable and would otherwise land in the system prompt as\n // trusted configuration. When the session carries a trusted base ref, the\n // project instructions are served from that ref instead (`git show`);\n // without one, project-scope files are skipped entirely. Home-directory\n // (global) instructions belong to whoever owns the machine, so hosts that\n // run sessions for someone else opt out of them entirely.\n // A host booting several checkouts under one working directory names them\n // as `instructionRoots`, so each checkout's own files load.\n const configDir = ctx.state?.configDir as string | undefined;\n const baseRef = typeof ctx.state?.baseRef === 'string' ? ctx.state.baseRef : undefined;\n const instructionRoots = Array.isArray(ctx.state?.instructionRoots)\n ? (ctx.state.instructionRoots as string[])\n : undefined;\n // No working directory means a hosted session with no project attached:\n // load NO instruction files at all — project locations would resolve\n // against the server's own cwd, and global locations against the server's\n // homedir. Neither belongs in a hosted session's prompt.\n const instructionSources = ctx.workingDir\n ? loadSessionInstructions({\n workingDir: ctx.workingDir,\n instructionRoots,\n configDir,\n untrustedCheckout: ctx.state?.untrustedCheckout === true,\n baseRef,\n skipGlobal: ctx.state?.skipGlobalInstructions === true,\n })\n : [];\n // Emitted per source so each AGENTS.md/CLAUDE.md can be costed individually.\n // The heading rides on the first source's section, which is exactly how\n // `formatAgentInstructions` lays the block out, so joining the sections\n // reproduces its output byte for byte.\n const instructionSections: PromptSection[] = instructionSources.map((source, index) => {\n const isFirst = index === 0;\n const isLast = index === instructionSources.length - 1;\n let content = formatInstructionSource(source);\n if (isFirst) content = `${AGENT_INSTRUCTIONS_HEADING}\\n\\n${content}`;\n // The block as a whole used to be trimmed, which only ever affected the\n // trailing whitespace of the final source's content.\n if (isLast) content = content.trimEnd();\n return {\n id: `agent-instructions:${source.path}:${index}`,\n label: `${source.scope === 'global' ? 'Global' : 'Project'} instructions`,\n detail: source.ref ? `${source.path} (at ref ${source.ref})` : source.path,\n content,\n };\n });\n\n const hostInstructions = ctx.hostInstructions?.trim() ?? '';\n\n return [\n { id: 'base-prompt', label: 'Base system prompt', content: base },\n { id: 'host-instructions', label: 'Host instructions', content: hostInstructions },\n ...instructionSections,\n { id: 'model-prompt', label: 'Model-specific prompt', detail: ctx.modelId, content: modelSpecific.trim() },\n { id: 'mode-prompt', label: 'Mode prompt', detail: ctx.modeId, content: modeSpecific.trim() },\n ].filter(section => Boolean(section.content));\n}\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAM,cAAyE;CAC7E,OAAO;CACP,MAAM;CACN,MAAM;AACR;;AAyBA,SAAgB,mBAAmB,UAAmC;CACpE,OAAO,SACJ,KAAI,YAAW,QAAQ,OAAO,CAAC,CAC/B,OAAO,OAAO,CAAC,CACf,KAAK,MAAM;AAChB;;;;;AAMA,SAAgB,gBAAgB,KAA4B;CAC1D,OAAO,mBAAmB,wBAAwB,GAAG,CAAC;AACxD;;;;;AAMA,SAAgB,wBAAwB,KAAqC;CAG3E,MAAM,gBAAgB,eAAe,KAAK,aAAa;CACvD,MAAM,eACJ,iBAAiB,8BAA8B,IAAI,SAAS,EAAE,gBAAgB,IAAI,eAAe,CAAC,MAAM,KAAA;CAG1G,MAAM,8BAAc,IAAI,IAAY;CACpC,MAAM,YAAY,IAAI,OAAO;CAC7B,IAAI,WAAW,OACR;OAAA,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,UAAU,KAAK,GACzD,IAAI,WAAW,QAAQ,YAAY,IAAI,IAAI;CAAA;CAK/C,KAAK,MAAM,QAAQ,IAAI,wBAAwB,CAAC,GAAG,YAAY,IAAI,IAAI;CAEvE,KAAK,MAAM,QAAQ,IAAI,iBAAiB,CAAC,GAAG,YAAY,IAAI,IAAI;CAIhE,IAAI,kBAAkB,aAAa,CAAC,CAAC,GAAG,MAAM,OAAO,YAAY,IAAI,SAAS,WAAW;CAGzF,MAAM,mBAAmB,OAAO,IAAI,OAAO,qBAAqB,WAAW,IAAI,MAAM,mBAAmB,KAAA;CACxG,MAAM,eAAe,kBAA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BAA2B,MAAM;EAG3D,IAAI,QAAQ,UAAU,QAAQ,QAAQ;EACtC,OAAO;GACL,IAAI,sBAAsB,OAAO,KAAK,GAAG;GACzC,OAAO,GAAG,OAAO,UAAU,WAAW,WAAW,UAAU;GAC3D,QAAQ,OAAO,MAAM,GAAG,OAAO,KAAK,WAAW,OAAO,IAAI,KAAK,OAAO;GACtE;EACF;CACF,CAAC;CAED,MAAM,mBAAmB,IAAI,kBAAkB,KAAK,KAAK;CAEzD,OAAO;EACL;GAAE,IAAI;GAAe,OAAO;GAAsB,SAAS;EAAK;EAChE;GAAE,IAAI;GAAqB,OAAO;GAAqB,SAAS;EAAiB;EACjF,GAAG;EACH;GAAE,IAAI;GAAgB,OAAO;GAAyB,QAAQ,IAAI;GAAS,SAAS,cAAc,KAAK;EAAE;EACzG;GAAE,IAAI;GAAe,OAAO;GAAe,QAAQ,IAAI;GAAQ,SAAS,aAAa,KAAK;EAAE;CAC9F,CAAC,CAAC,QAAO,YAAW,QAAQ,QAAQ,OAAO,CAAC;AAC9C"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/agents/prompts/index.ts"],"sourcesContent":["/**\n * Prompt system — exports the prompt builder and mode-specific prompts.\n */\n\nexport { buildModePrompt, buildModePromptFn } from './build.js';\nexport { planModePrompt } from './plan.js';\nexport { fastModePrompt } from './fast.js';\n\nimport { buildBasePrompt } from '@mastra/core/coding-agent';\nimport type { PromptContext as BasePromptContext } from '@mastra/core/coding-agent';\nimport type { RequestContextReader } from '../../auth/account-routing-context.js';\nimport { loadSettings, resolveLspSetting } from '../../onboarding/settings.js';\nimport { MC_TOOLS } from '../../tool-names.js';\nimport { hasParallelKey, hasTavilyKey } from '../../tools/index.js';\nimport { getLocalPlansRelativeDir } from '../../utils/plans.js';\nimport { resolveProviderWebSearchRoute } from '../model.js';\nimport {\n loadSessionInstructions,\n loadSessionInstructionsAsync,\n formatInstructionSource,\n AGENT_INSTRUCTIONS_HEADING,\n} from './agent-instructions.js';\nimport type { InstructionSource } from './agent-instructions.js';\nimport { buildModePromptFn } from './build.js';\nimport { fastModePrompt } from './fast.js';\nimport { modelSpecificPrompts } from './model.js';\nimport { planModePrompt } from './plan.js';\nimport { buildToolGuidance } from './tool-guidance.js';\n\n// Extended prompt context that includes runtime information\nexport interface PromptContext extends Omit<BasePromptContext, 'toolGuidance'> {\n modeId: string;\n state?: any;\n hostInstructions?: string;\n /** Request whose credentials decide the model's transport, and so its web search tool. */\n requestContext?: RequestContextReader;\n /** Controller built-in tools removed via `disableBuiltinTools`; treated as denied. */\n disabledBuiltinTools?: readonly string[];\n /** Host-configured workspace-relative plans directory (see `MastraCodeConfig.plansDir`). */\n plansDir?: string;\n /** Agent tools removed via `disabledTools` (e.g. `web_search`); treated as denied. */\n disabledTools?: readonly string[];\n /** Resolved in `buildFullPromptSections`; false when `submit_plan` is denied or disabled. */\n submitPlanAvailable?: boolean;\n currentDate: string;\n workingDir: string;\n}\n\nconst modePrompts: Record<string, string | ((ctx: PromptContext) => string)> = {\n build: buildModePromptFn,\n plan: planModePrompt,\n fast: fastModePrompt,\n};\n\n/**\n * One labeled piece of the assembled system prompt.\n *\n * The system prompt is a single string by the time it reaches the model, which\n * makes it impossible to say which configuration source is responsible for\n * which share of the context window. Building it as labeled sections and\n * joining them at the end keeps that attribution available to the `/context`\n * audit while guaranteeing the audit measures the exact text that is sent —\n * a parallel \"describe the prompt\" path would drift and report numbers for a\n * prompt that is no longer assembled this way.\n */\nexport interface PromptSection {\n /** Stable identifier, unique within a single build. */\n id: string;\n /** Human-readable label for display. */\n label: string;\n /** Optional provenance (e.g. the instruction file path). */\n detail?: string;\n /** The exact text contributed to the prompt. */\n content: string;\n}\n\n/** Join prompt sections into the final system prompt string. */\nexport function joinPromptSections(sections: PromptSection[]): string {\n return sections\n .map(section => section.content)\n .filter(Boolean)\n .join('\\n\\n');\n}\n\n/**\n * Build the full system prompt for a given mode and context.\n * Combines the base prompt with mode-specific instructions.\n */\nexport function buildFullPrompt(ctx: PromptContext): string {\n return joinPromptSections(buildFullPromptSections(ctx));\n}\n\nexport async function buildFullPromptSectionsAsync(ctx: PromptContext): Promise<PromptSection[]> {\n const sources = ctx.workingDir\n ? await loadSessionInstructionsAsync({\n workingDir: ctx.workingDir,\n instructionRoots: Array.isArray(ctx.state?.instructionRoots) ? ctx.state.instructionRoots : undefined,\n configDir: ctx.state?.configDir,\n untrustedCheckout: ctx.state?.untrustedCheckout === true,\n baseRef: typeof ctx.state?.baseRef === 'string' ? ctx.state.baseRef : undefined,\n skipGlobal: ctx.state?.skipGlobalInstructions === true,\n })\n : [];\n return buildFullPromptSections(ctx, sources);\n}\n\n/**\n * Build the system prompt as labeled sections. `buildFullPrompt` is the join of\n * these, so the two can never disagree about what the model receives.\n */\nexport function buildFullPromptSections(ctx: PromptContext, loadedInstructions?: InstructionSource[]): PromptSection[] {\n // Determine whether web search tools are available\n // Parallel/Tavily register web_search and web_extract; provider search registers only web_search.\n const hasWebExtract = hasParallelKey() || hasTavilyKey();\n const hasWebSearch =\n hasWebExtract || resolveProviderWebSearchRoute(ctx.modelId, { requestContext: ctx.requestContext }) !== undefined;\n\n // Collect per-tool deny rules so guidance omits denied tools\n const deniedTools = new Set<string>();\n const permRules = ctx.state?.permissionRules as { tools?: Record<string, string> } | undefined;\n if (permRules?.tools) {\n for (const [name, policy] of Object.entries(permRules.tools)) {\n if (policy === 'deny') deniedTools.add(name);\n }\n }\n\n // Disabled built-ins are never registered, so they are denied for guidance too.\n for (const name of ctx.disabledBuiltinTools ?? []) deniedTools.add(name);\n // `createDynamicTools` drops disabled agent tools (such as web_search), so omit their guidance too.\n for (const name of ctx.disabledTools ?? []) deniedTools.add(name);\n\n // LSP is opt-in — when it is off the tool is never registered, so its\n // guidance must not be advertised either.\n if (resolveLspSetting(loadSettings().lsp) === false) deniedTools.add(MC_TOOLS.LSP_INSPECT);\n\n // Build mode-aware tool guidance\n const factoryProjectId = typeof ctx.state?.factoryProjectId === 'string' ? ctx.state.factoryProjectId : undefined;\n const toolGuidance = buildToolGuidance(ctx.modeId, {\n hasWebSearch,\n hasWebExtract,\n hasSubagents: ctx.hasSubagents,\n deniedTools,\n plansDir: getLocalPlansRelativeDir({ factoryProjectId, plansDir: ctx.plansDir }),\n });\n\n // Map new context to base context\n const baseCtx: BasePromptContext = {\n projectPath: ctx.workingDir || '(no workspace attached)',\n projectName: ctx.projectName || 'unknown',\n gitBranch: ctx.gitBranch,\n platform: process.platform,\n commonBinaries: ctx.commonBinaries,\n date: ctx.currentDate,\n mode: ctx.modeId,\n modelId: ctx.modelId,\n coAuthorName: ctx.coAuthorName,\n coAuthorEmail: ctx.coAuthorEmail,\n activePlan: ctx.state?.activePlan,\n hasSubagents: ctx.hasSubagents !== false && !deniedTools.has('subagent'),\n planApprovalStartsGoal: ctx.planApprovalStartsGoal,\n toolGuidance,\n };\n\n const base = buildBasePrompt(baseCtx);\n const entry = modePrompts[ctx.modeId] || modePrompts.build;\n const modeSpecific =\n (typeof entry === 'function' ? entry({ ...ctx, submitPlanAvailable: !deniedTools.has('submit_plan') }) : entry) ??\n '';\n const modelSpecific = ctx.modelId\n ? (modelSpecificPrompts[ctx.modelId as keyof typeof modelSpecificPrompts] ?? '')\n : '';\n\n // The current task list is carried on the agent state-signal lane (see\n // TaskStateProcessor) rather than injected into the cached system prompt. This\n // keeps the prompt prefix stable across task updates (preserving prompt cache)\n // while still surviving observational-memory truncation.\n\n // Load and inject agent instructions from AGENTS.md/CLAUDE.md files.\n // Untrusted checkouts (e.g. a PR branch under review) never read\n // project-scope files off the working tree: their AGENTS.md is\n // attacker-writable and would otherwise land in the system prompt as\n // trusted configuration. When the session carries a trusted base ref, the\n // project instructions are served from that ref instead (`git show`);\n // without one, project-scope files are skipped entirely. Home-directory\n // (global) instructions belong to whoever owns the machine, so hosts that\n // run sessions for someone else opt out of them entirely.\n // A host booting several checkouts under one working directory names them\n // as `instructionRoots`, so each checkout's own files load.\n const configDir = ctx.state?.configDir as string | undefined;\n const baseRef = typeof ctx.state?.baseRef === 'string' ? ctx.state.baseRef : undefined;\n const instructionRoots = Array.isArray(ctx.state?.instructionRoots)\n ? (ctx.state.instructionRoots as string[])\n : undefined;\n // No working directory means a hosted session with no project attached:\n // load NO instruction files at all — project locations would resolve\n // against the server's own cwd, and global locations against the server's\n // homedir. Neither belongs in a hosted session's prompt.\n const instructionSources =\n loadedInstructions ??\n (ctx.workingDir\n ? loadSessionInstructions({\n workingDir: ctx.workingDir,\n instructionRoots,\n configDir,\n untrustedCheckout: ctx.state?.untrustedCheckout === true,\n baseRef,\n skipGlobal: ctx.state?.skipGlobalInstructions === true,\n })\n : []);\n // Emitted per source so each AGENTS.md/CLAUDE.md can be costed individually.\n // The heading rides on the first source's section, which is exactly how\n // `formatAgentInstructions` lays the block out, so joining the sections\n // reproduces its output byte for byte.\n const instructionSections: PromptSection[] = instructionSources.map((source, index) => {\n const isFirst = index === 0;\n const isLast = index === instructionSources.length - 1;\n let content = formatInstructionSource(source);\n if (isFirst) content = `${AGENT_INSTRUCTIONS_HEADING}\\n\\n${content}`;\n // The block as a whole used to be trimmed, which only ever affected the\n // trailing whitespace of the final source's content.\n if (isLast) content = content.trimEnd();\n return {\n id: `agent-instructions:${source.path}:${index}`,\n label: `${source.scope === 'global' ? 'Global' : 'Project'} instructions`,\n detail: source.ref ? `${source.path} (at ref ${source.ref})` : source.path,\n content,\n };\n });\n\n const hostInstructions = ctx.hostInstructions?.trim() ?? '';\n\n return [\n { id: 'base-prompt', label: 'Base system prompt', content: base },\n { id: 'host-instructions', label: 'Host instructions', content: hostInstructions },\n ...instructionSections,\n { id: 'model-prompt', label: 'Model-specific prompt', detail: ctx.modelId, content: modelSpecific.trim() },\n { id: 'mode-prompt', label: 'Mode prompt', detail: ctx.modeId, content: modeSpecific.trim() },\n ].filter(section => Boolean(section.content));\n}\n"],"mappings":";;;;;;;;;;;;;;AAgDA,MAAM,cAAyE;CAC7E,OAAO;CACP,MAAM;CACN,MAAM;AACR;;AAyBA,SAAgB,mBAA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,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,aAAa,EACb,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,KAAK,EACL,gBAAgB,EAChB,cAAc,GACf,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { canUseProvider, createMastraCodeGateway, getDynamicModel, getGoalJudgeM
9
9
  import { buildMode } from "./agents/modes/build.js";
10
10
  import { fastMode } from "./agents/modes/explore.js";
11
11
  import { createPlanMode } from "./agents/modes/plan.js";
12
- import { createGitRefReminderReader, instructionSourcePaths, loadSessionInstructions, sessionInstructionRoots } from "./agents/prompts/agent-instructions.js";
12
+ import { createGitRefReminderReader, createGitRefReminderReaderAsync, instructionSourcePaths, loadSessionInstructions, loadSessionInstructionsAsync, sessionInstructionRoots } from "./agents/prompts/agent-instructions.js";
13
13
  import { builtinSubagents, resolveSubagentsSetting } from "./agents/subagents/index.js";
14
14
  import { attachOMThreadStatePersistence, restoreOMThreadStateForCurrentThread } from "./agents/thread-caveman-state.js";
15
15
  import { createDynamicTools, createToolHooks } from "./agents/tools.js";
@@ -632,7 +632,7 @@ async function createMastraCodeAgentController(config) {
632
632
  if (state?.untrustedCheckout !== true || typeof state?.baseRef !== "string") return void 0;
633
633
  const projectPath = state?.projectPath ?? project.rootPath;
634
634
  const [primary] = sessionInstructionRoots(projectPath, state.instructionRoots);
635
- const reader = createGitRefReminderReader(primary, state.baseRef);
635
+ const reader = "supportsAsyncInstructionReaders" in AgentsMDInjector ? createGitRefReminderReaderAsync(primary, state.baseRef) : createGitRefReminderReader(primary, state.baseRef);
636
636
  if (primary === projectPath) return reader;
637
637
  const outsidePrimary = (filePath) => {
638
638
  const inProject = path.relative(projectPath, filePath);
@@ -643,7 +643,11 @@ async function createMastraCodeAgentController(config) {
643
643
  return {
644
644
  ...reader,
645
645
  pathExists: (filePath) => !outsidePrimary(filePath) && reader.pathExists(filePath),
646
- isDirectory: (filePath) => !outsidePrimary(filePath) && reader.isDirectory(filePath)
646
+ isDirectory: (filePath) => !outsidePrimary(filePath) && reader.isDirectory(filePath),
647
+ readFile: (filePath) => {
648
+ if (outsidePrimary(filePath)) throw new Error(`Not found at ref ${state.baseRef}: ${filePath}`);
649
+ return reader.readFile(filePath);
650
+ }
647
651
  };
648
652
  },
649
653
  getIgnoredInstructionPaths: ({ requestContext }) => {
@@ -651,13 +655,14 @@ async function createMastraCodeAgentController(config) {
651
655
  const projectPath = state?.projectPath ?? project.rootPath;
652
656
  const untrusted = state?.untrustedCheckout === true && typeof state?.baseRef === "string";
653
657
  const roots = sessionInstructionRoots(projectPath, state?.instructionRoots);
654
- const sources = loadSessionInstructions({
658
+ const options = {
655
659
  workingDir: projectPath,
656
660
  instructionRoots: state?.instructionRoots,
657
661
  untrustedCheckout: untrusted,
658
662
  baseRef: untrusted ? state?.baseRef : void 0
659
- });
660
- return instructionSourcePaths(sources, roots);
663
+ };
664
+ if (!("supportsAsyncInstructionReaders" in AgentsMDInjector)) return instructionSourcePaths(loadSessionInstructions(options), roots);
665
+ return loadSessionInstructionsAsync(options).then((sources) => instructionSourcePaths(sources, roots));
661
666
  }
662
667
  })
663
668
  ];