// Planu — Agent Generator: Prompt Builders and Inference Helpers
// Generates system prompts and infers agent configuration from role/capabilities.
export function buildSystemPrompt(agentName, role, capabilities, knowledge) {
    const lines = [];
    lines.push(`You are ${agentName}, a specialized ${role} agent.`);
    lines.push('');
    lines.push('## Your Capabilities');
    for (const cap of capabilities) {
        lines.push(`- ${cap}`);
    }
    lines.push('');
    lines.push('## Project Context');
    lines.push(`- Language: ${knowledge.language}`);
    if (knowledge.framework) {
        lines.push(`- Framework: ${knowledge.framework}`);
    }
    lines.push(`- Architecture: ${knowledge.architecture.primary}`);
    lines.push(`- Database: ${knowledge.database}`);
    lines.push('');
    lines.push('## Rules');
    lines.push('- Follow the project architecture patterns.');
    lines.push('- Write clean, well-tested code.');
    lines.push('- Handle errors explicitly.');
    lines.push('- Report progress and blockers clearly.');
    if (knowledge.qualityProfile.principles.length > 0) {
        lines.push('');
        lines.push('## Quality Principles');
        for (const principle of knowledge.qualityProfile.principles) {
            lines.push(`- ${principle}`);
        }
    }
    // SPEC-022: Scope restrictions — sub-agents must NOT handle commit/push/tracking
    lines.push('');
    lines.push('## Scope Restrictions');
    lines.push('- NEVER git commit or git push changes — that is handled by the parent skill');
    lines.push('- NEVER update PROGRESS.md or spec tracking files — delegate to parent skill');
    lines.push('- NEVER run the full CI/CD pipeline — parent skill manages pipeline execution');
    lines.push('- Focus exclusively on your assigned subtask and report results clearly');
    return lines.join('\n');
}
export function buildCoordinatorPrompt(knowledge) {
    return [
        'You are the coordinator agent for the SDD workflow.',
        '',
        '## Your Role',
        'You orchestrate the development workflow:',
        '1. Receive feature requests and break them into specs.',
        '2. Assign analysis tasks to the analyst agent.',
        '3. Route implementation tasks to the implementor agent.',
        '4. Request reviews from the reviewer agent.',
        '5. Track progress and resolve conflicts.',
        '',
        '## Project Context',
        `- Language: ${knowledge.language}`,
        `- Framework: ${knowledge.framework ?? 'none'}`,
        `- Architecture: ${knowledge.architecture.primary}`,
        `- Spec location: ${knowledge.specLocation}`,
        '',
        '## Workflow',
        '1. Analyze -> 2. Spec -> 3. Filter -> 4. Implement -> 5. Validate -> 6. Complete',
        '',
        '## Rules',
        '- Always create a spec before implementation.',
        '- Validate implementation against spec criteria.',
        '- Record actuals when completing specs.',
        '- Resolve agent conflicts before proceeding.',
    ].join('\n');
}
export function inferModel(role, capabilities) {
    // Use Opus for complex reasoning tasks, Sonnet for simpler ones
    const complexRoles = ['orchestrator', 'architect', 'code-analyst', 'security-auditor'];
    const complexCapabilities = ['architecture-review', 'security-audit', 'complex-refactoring'];
    if (complexRoles.includes(role)) {
        return 'claude-sonnet-4-20250514';
    }
    if (capabilities.some((c) => complexCapabilities.includes(c))) {
        return 'claude-sonnet-4-20250514';
    }
    return 'claude-sonnet-4-20250514';
}
export function inferTools(role, _capabilities, knowledge) {
    const tools = [];
    // Base tools for all agents
    tools.push('read_file', 'write_file', 'list_directory');
    // Role-specific tools
    const roleTools = {
        orchestrator: ['sdd_init_project', 'sdd_create_spec', 'sdd_update_status', 'sdd_orchestrate'],
        'code-analyst': [
            'sdd_audit_code',
            'sdd_detect_drift',
            'sdd_reverse_engineer',
            'sdd_generate_checklist',
        ],
        'code-implementor': ['sdd_validate_spec', 'sdd_check_versions', 'bash'],
        'code-reviewer': ['sdd_audit_code', 'sdd_generate_checklist', 'sdd_detect_drift'],
        documentation: ['sdd_generate_docs', 'sdd_summarize_spec'],
        testing: ['sdd_generate_test_plan', 'sdd_validate_spec', 'bash'],
    };
    if (roleTools[role]) {
        tools.push(...(roleTools[role] ?? []));
    }
    // MCP tools if available
    for (const mcp of knowledge.availableMcps) {
        tools.push(...mcp.tools);
    }
    return [...new Set(tools)];
}
export function inferMaxTurns(role) {
    const turnsByRole = {
        orchestrator: 20,
        'code-analyst': 10,
        'code-implementor': 30,
        'code-reviewer': 15,
        documentation: 10,
        testing: 15,
    };
    return turnsByRole[role] ?? 10;
}
export function inferHandoffConditions(role) {
    const conditions = {
        orchestrator: [
            'Handoff to analyst when code analysis is needed.',
            'Handoff to implementor when spec is approved and ready for coding.',
            'Handoff to reviewer when implementation is complete.',
        ],
        'code-analyst': [
            'Handoff back to coordinator with analysis results.',
            'Handoff to reviewer if critical issues found.',
        ],
        'code-implementor': [
            'Handoff to reviewer when implementation is complete.',
            'Handoff to coordinator if blocked by dependencies.',
        ],
        'code-reviewer': [
            'Handoff back to implementor if changes needed.',
            'Handoff to coordinator when review is approved.',
        ],
    };
    return conditions[role] ?? [];
}
//# sourceMappingURL=builders.js.map