// Planu — Agent Spec Generator: Project Detector
// SPEC-016a: Detects agent/MCP project types and builds facilitate helpers.
/**
 * Detect if the project is an AI agent project.
 * Criteria 20: activate specialized agent flow in facilitate.
 */
export function isAgentProject(knowledge) {
    if (!knowledge) {
        return false;
    }
    const agentSignals = [
        '@anthropic-ai/sdk',
        '@mastra/core',
        'langgraph',
        'crewai',
        'autogen',
        'openai',
        'langchain',
    ];
    const hasAgentPackage = knowledge.stack.some((s) => agentSignals.some((sig) => s.toLowerCase().includes(sig)));
    const hasAgentFramework = (knowledge.framework ?? '').toLowerCase().includes('agent');
    return hasAgentPackage || hasAgentFramework;
}
/**
 * Check if the project is an MCP server.
 * Criteria 24: route to SPEC-016b flow.
 */
export function isMcpServerProject(knowledge) {
    if (!knowledge) {
        return false;
    }
    return knowledge.stack.some((s) => s.includes('@modelcontextprotocol/sdk') || s.includes('mcp-server'));
}
/**
 * Build agent facilitate questions for pre-filling create_spec.
 * Criteria 21: specific questions for agent projects.
 */
export function buildAgentFacilitateQuestions(title) {
    return [
        `What is the primary objective of "${title}"? (e.g., "Review contracts for compliance issues")`,
        'What tools does the agent need? (e.g., web_search, database_query, send_email, file_read)',
        'What external systems does it integrate with? (e.g., CRM, Slack, Google Drive, database)',
        'What should the agent do when it does not know the answer or has low confidence?',
        'How will users interact with it? (chat interface, email, automated trigger, dashboard)',
        'What is the maximum number of tool calls allowed per request? (prevents infinite loops)',
        'What data should never appear in agent outputs? (PII, credentials, internal data)',
    ];
}
/**
 * Build expert voice warnings about agent failure modes.
 * Criteria 23: warn before generating first spec.
 */
export function buildAgentFailureModeWarnings() {
    const lines = [
        '## Expert Advisory: AI Agent Failure Modes',
        '',
        '> Before generating this spec, review these critical failure modes:',
        '',
        '**Prompt Injection** — Malicious content in tool outputs (web results, database records)',
        'can embed instructions like "Ignore all previous instructions" to hijack the agent.',
        '_Mitigation: Sanitize tool outputs; use structured schemas; distrust tool output content._',
        '',
        '**Infinite Loops** — Agent enters a cycle where tool A triggers tool B triggers tool A.',
        'Without a hard iteration limit, this generates unbounded API costs.',
        '_Mitigation: Enforce max_iterations strictly; track call history; detect cycles early._',
        '',
        '**Hallucinations in Critical Tools** — Agent fabricates plausible tool parameters',
        '(wrong IDs, fake URLs, invalid enum values) leading to silent data corruption.',
        '_Mitigation: Validate ALL tool inputs against strict schemas before execution._',
        '',
        '**Data Leaks** — Agent includes PII, credentials or business-sensitive data in responses.',
        '_Mitigation: Output filtering; scrub PII patterns; context isolation per user session._',
        '',
        '**Cost Explosion** — Runaway agent makes excessive API calls; billing spikes unexpectedly.',
        '_Mitigation: Token budget enforcement; rate limiting; cost alerting at threshold._',
    ];
    return lines.join('\n');
}
//# sourceMappingURL=project-detector.js.map