// tools/ci-planu-handler.ts — Handle generate_planu_ci tool calls (SPEC-066 AC-02..07, SPEC-201)
import { generatePlanuCI } from '../engine/ci-generator/planu-steps.js';
/**
 * Handle the generate_planu_ci tool.
 * Always generates a local planu-check.sh script (no GitHub billing required).
 * Optionally generates a GitHub Actions workflow YAML for cloud CI.
 */
export function handleGeneratePlanuCI(args) {
    const includeGithubActions = args.includeGithubActions ?? true;
    const result = generatePlanuCI(args);
    const lines = [
        '## Planu CI Workflow Generated',
        '',
        `**Features enabled**: ${result.features.join(', ')}`,
        '',
        '---',
        '',
        '### Option 1 — Local script (no GitHub billing required)',
        '',
        'Save `planu-check.sh` to your project root and run it directly:',
        '',
        '```bash',
        'chmod +x planu-check.sh',
        './planu-check.sh',
        '```',
        '',
        '```bash',
        result.localScript.trimEnd(),
        '```',
        '',
        '**Optional: run as git pre-push hook** (catches issues before pushing):',
        '',
        '```bash',
        'ln -s ../../planu-check.sh .git/hooks/pre-push',
        '```',
        '',
        '---',
        '',
        '### Option 2 — Run GitHub Actions locally with act (no billing)',
        '',
        '[act](https://github.com/nektos/act) runs GitHub Actions workflows on your machine.',
        'The generated workflow is fully compatible with act:',
        '',
        '```bash',
        '# Install act (macOS)',
        'brew install act',
        '',
        '# Run the Planu check locally',
        'act -j planu-check',
        '```',
        '',
    ];
    if (includeGithubActions && result.workflowYaml) {
        lines.push('---', '', `### Option 3 — GitHub Actions (requires billing for private repos)`, '', `**Workflow path**: \`${result.workflowPath}\``, '', '```yaml', result.workflowYaml.trimEnd(), '```', '');
    }
    // .planu.yml config
    lines.push('---', '', '### Generated .planu.yml Configuration', '', '```yaml');
    lines.push(result.planuConfigYaml.trimEnd());
    lines.push('```', '');
    // Badge (only if GitHub Actions enabled)
    if (includeGithubActions && result.badgeMarkdown) {
        lines.push('### Badge for README', '');
        lines.push('Add this to your README.md (replace `{owner}` and `{repo}` with your values):');
        lines.push('', '```markdown');
        lines.push(result.badgeMarkdown);
        lines.push('```', '');
    }
    lines.push(`> **Save**: \`${result.localScriptPath}\` (local script, always)`);
    if (includeGithubActions && result.workflowPath) {
        lines.push(`> **Save**: \`${result.workflowPath}\` (GitHub Actions, optional)`);
    }
    lines.push('> **Save**: `.planu.yml` (shared config for both modes)');
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
    };
}
//# sourceMappingURL=ci-planu-handler.js.map