// engine/ai-integration/mastra/config-generator.ts — Mastra config template generator (SPEC-274)
import { writeFileSync, mkdirSync, existsSync } from 'node:fs';
import { join } from 'node:path';
/**
 * Generates the content of a `planu.mastra.ts` config file for the user's project.
 * This is a TypeScript template — not Planu's own code.
 */
export function generateMastraConfig(options) {
    const { projectName, stack, activeSpecId, mcpServerPath } = options;
    const mcpPath = mcpServerPath ?? 'npx @planu/cli start';
    const activeSpec = activeSpecId ? `\n  // Active spec: ${activeSpecId}` : '';
    const stackComment = stack.length > 0 ? `\n  // Stack: ${stack.join(', ')}` : '';
    return [
        `// planu.mastra.ts — Generated by Planu for project: ${projectName}`,
        `// Edit this file to customize the Planu agent for your workflow.`,
        `// Docs: https://planu.dev/docs/mastra-integration`,
        ``,
        `import { Agent } from '@mastra/core/agent';`,
        `import { MCPClient } from '@mastra/mcp';`,
        ``,
        `// Initialize Planu MCP client`,
        `const planuMcp = new MCPClient({`,
        `  servers: {`,
        `    planu: {`,
        `      command: '${mcpPath}',`,
        `    },`,
        `  },`,
        `});`,
        ``,
        `// Planu implementer agent${activeSpec}${stackComment}`,
        `export const planuImplementer = new Agent({`,
        `  name: 'planu-implementer',`,
        `  instructions: [`,
        `    'Use Planu specs as the single source of truth.',`,
        `    'Before writing any code, call mcp__planu__list_specs to find the approved spec.',`,
        `    'After implementation, call mcp__planu__validate to verify compliance.',`,
        `    'Never implement without an approved spec — create one first with mcp__planu__create_spec.',`,
        `  ].join(' '),`,
        `  tools: await planuMcp.getTools(),`,
        `  model: {`,
        `    provider: 'ANTHROPIC',`,
        `    name: 'claude-sonnet-4-5',`,
        `  },`,
        `});`,
        ``,
        `export const mastra = {`,
        `  agents: { planuImplementer },`,
        `};`,
    ].join('\n');
}
/**
 * Writes `planu.mastra.ts` to the given project path.
 * Creates the directory if it does not exist.
 */
export function writeMastraConfig(projectPath, options) {
    /* v8 ignore start */
    if (!existsSync(projectPath)) {
        mkdirSync(projectPath, { recursive: true });
    }
    /* v8 ignore stop */
    const configPath = join(projectPath, 'planu.mastra.ts');
    writeFileSync(configPath, generateMastraConfig(options), 'utf8');
}
//# sourceMappingURL=config-generator.js.map