// engine/ai-integration/kiro/steering-generator.ts — Kiro steering document generator (SPEC-270)
import { writeFileSync, mkdirSync, existsSync } from 'node:fs';
import { join } from 'node:path';
function buildActiveSpecSection(options) {
    if (!options.activeSpecId) {
        return '';
    }
    const lines = ['', '## Active Spec', '', `- **ID**: ${options.activeSpecId}`];
    if (options.activeSpecTitle) {
        lines.push(`- **Title**: ${options.activeSpecTitle}`);
    }
    lines.push('- **Branch**: `feat/' + options.activeSpecId + '-*`');
    return lines.join('\n');
}
function buildApprovedSpecsSection(options) {
    if (options.approvedSpecs.length === 0) {
        return '';
    }
    const lines = ['', '## Approved Specs (ready to implement)', ''];
    for (const spec of options.approvedSpecs) {
        lines.push(`- **${spec.id}**: ${spec.title}`);
    }
    return lines.join('\n');
}
function buildStackSection(options) {
    if (options.stack.length === 0) {
        return '';
    }
    const lines = ['', '## Stack', ''];
    for (const tech of options.stack) {
        lines.push(`- ${tech}`);
    }
    return lines.join('\n');
}
function buildArchitectureSection(options) {
    if (!options.architectureStyle) {
        return '';
    }
    return [
        '',
        '## Architecture',
        '',
        `- **Style**: ${options.architectureStyle}`,
        '- **Dependency rule**: types → engine → storage → tools (no reverse imports)',
    ].join('\n');
}
/** Generates the content for .kiro/steering/planu-sdd.md */
export function generateKiroSteering(options) {
    const sections = [
        '# Planu SDD — Kiro Steering Document',
        '',
        `> Project: **${options.projectName}**`,
        '',
        '## SDD Workflow',
        '',
        '1. Always create or reference a Planu spec before writing production code',
        '2. Branch naming: `feat/SPEC-XXX-short-description` (from `develop`)',
        '3. After implementation run `validate` to check spec compliance',
        '4. Merge path: `feat/SPEC-XXX` → `develop` → `main`',
        '',
        '## Planu Commands',
        '',
        '- `create_spec` — create a new spec (brainstorm first)',
        '- `list_specs` — show all specs with status',
        '- `update_status` — move spec through: draft → review → approved → implementing → done',
        '- `validate` — check implementation against spec acceptance criteria',
        '- `challenge_spec` — stress-test a spec before approving',
        '- `check_readiness` — verify detail level before implementing',
        '',
        '## Branch Conventions',
        '',
        '- `feat/SPEC-XXX-*` — spec implementation',
        '- `fix/SPEC-XXX-*` — spec bugfix',
        '- `develop` — integration branch (never commit directly)',
        '- `main` — stable branch (only merges from develop)',
    ];
    const activeSection = buildActiveSpecSection(options);
    if (activeSection) {
        sections.push(activeSection);
    }
    const approvedSection = buildApprovedSpecsSection(options);
    if (approvedSection) {
        sections.push(approvedSection);
    }
    const stackSection = buildStackSection(options);
    if (stackSection) {
        sections.push(stackSection);
    }
    const archSection = buildArchitectureSection(options);
    if (archSection) {
        sections.push(archSection);
    }
    sections.push('');
    return sections.join('\n');
}
/** Writes .kiro/steering/planu-sdd.md to the given project path */
export function writeKiroSteering(projectPath, options) {
    const steeringDir = join(projectPath, '.kiro', 'steering');
    /* v8 ignore start */
    if (!existsSync(steeringDir)) {
        mkdirSync(steeringDir, { recursive: true });
    }
    /* v8 ignore stop */
    const content = generateKiroSteering(options);
    writeFileSync(join(steeringDir, 'planu-sdd.md'), content, 'utf8');
}
//# sourceMappingURL=steering-generator.js.map