// tools/generate-batch-script.ts — Handle generate_batch_script tool calls (SPEC-253)
import { z } from 'zod';
import { generateBatchScript } from '../engine/batch-script-generator/index.js';
import { SpecIdSchema } from './schemas/index.js';
export const GenerateBatchScriptInputSchema = z.object({
    projectPath: z.string().describe('Absolute path to the project root'),
    taskDescription: z.string().describe('What claude -p should do to each file'),
    fileGlob: z.string().describe("Glob pattern for files, e.g. 'src/**/*.ts'"),
    specId: SpecIdSchema.optional().describe('SPEC ID for naming the output script, e.g. SPEC-253'),
    allowedTools: z
        .array(z.string())
        .optional()
        .describe("List of allowed tools passed to claude -p, e.g. ['Edit', 'Bash(git commit *)']"),
    outputFormat: z
        .enum(['text', 'json', 'stream-json'])
        .optional()
        .describe('Output format for claude -p: text (default) | json | stream-json'),
    permissionMode: z
        .enum(['auto', 'dontAsk', 'default'])
        .optional()
        .describe('Permission mode for claude -p: auto (default, unattended) | dontAsk (pre-approved tools only) | default'),
    pilotCount: z.number().optional().describe('Number of files in the pilot script (default: 3)'),
    dryRun: z
        .boolean()
        .optional()
        .describe('Return script content without writing to disk (default: false)'),
});
/**
 * Handle the generate_batch_script tool.
 * Generates full and pilot bash scripts for fan-out batch processing with claude -p.
 */
export async function handleGenerateBatchScript(args) {
    const result = await generateBatchScript(args);
    const lines = [
        '## Batch Script Generated',
        '',
        `**Task**: ${args.taskDescription}`,
        `**File glob**: \`${args.fileGlob}\``,
        `**Estimated files**: ~${String(result.estimatedFiles)}`,
        `**Pilot size**: ${String(args.pilotCount ?? 3)} files`,
        '',
    ];
    if (args.dryRun) {
        lines.push('> **dry-run mode** — scripts not written to disk');
        lines.push('');
    }
    else {
        lines.push(`**Full script**: \`${result.fullScriptPath}\``);
        lines.push(`**Pilot script**: \`${result.pilotScriptPath}\``);
        lines.push('');
    }
    lines.push('### Recommended workflow');
    lines.push('');
    lines.push('1. **Run pilot first** (validates the task on a small sample):');
    lines.push(`   \`\`\`bash\n   ${result.suggestedPilotCommand}\n   \`\`\``);
    lines.push('2. **Scale up** (run on all files once pilot looks good):');
    lines.push(`   \`\`\`bash\n   ${result.scaleUpCommand}\n   \`\`\``);
    lines.push('');
    lines.push('### Pilot script preview');
    lines.push('');
    lines.push('```bash');
    lines.push(result.pilotScript.trimEnd());
    lines.push('```');
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
    };
}
//# sourceMappingURL=generate-batch-script.js.map