// hosts/claude-code/ux/mcp-prompts.ts — SPEC-588
// Registers Planu workflow prompts (slash-command picker entries) on the MCP server.
import { z } from 'zod';
/** Exported metadata so the sync script can document registered prompts. */
export const PLANU_PROMPT_META = [
    {
        name: 'create_spec',
        description: 'Create a new Planu spec from a feature description — facilitates requirements, drafts criteria, and returns a ready-to-review spec.',
        args: [
            { name: 'title', description: 'Short title for the feature or change', required: true },
            {
                name: 'description',
                description: 'Free-text description of what to build (as much detail as you have)',
                required: true,
            },
            {
                name: 'projectPath',
                description: 'Absolute path to the project root (defaults to current directory)',
                required: false,
            },
        ],
    },
    {
        name: 'execute_sdd_flow',
        description: 'Run the full SDD flow for an approved spec — creates branch, implements, validates, and opens a PR.',
        args: [
            {
                name: 'specId',
                description: 'The Planu spec ID to implement (e.g. SPEC-123)',
                required: true,
            },
            {
                name: 'projectPath',
                description: 'Absolute path to the project root',
                required: false,
            },
            {
                name: 'mode',
                description: 'Execution mode: "full" (branch+implement+PR) or "implement-only" (no branch/PR). Valid values: full, implement-only',
                required: false,
            },
        ],
    },
    {
        name: 'challenge_spec',
        description: 'Stress-test a Planu spec — finds gaps, contradictions, missing edge cases, and unclear criteria.',
        args: [
            {
                name: 'specId',
                description: 'The Planu spec ID to challenge (e.g. SPEC-123)',
                required: true,
            },
            {
                name: 'focus',
                description: 'Optional focus area: "security", "performance", "edge-cases", or "all". Valid values: security, performance, edge-cases, all',
                required: false,
            },
        ],
    },
];
// ---------------------------------------------------------------------------
// Prompt handlers
// ---------------------------------------------------------------------------
function buildCreateSpecPrompt(title, description, projectPath) {
    const pathHint = projectPath ? ` at \`${projectPath}\`` : '';
    return [
        `You are helping create a Planu Spec Driven Development spec${pathHint}.`,
        '',
        `**Feature title**: ${title}`,
        '',
        `**Description**: ${description}`,
        '',
        'Please:',
        '1. Call `facilitate("' +
            description +
            '")` to elicit any missing requirements via interactive questions.',
        '2. Once requirements are clear, call `create_spec` with full acceptance criteria in GIVEN/WHEN/THEN format.',
        '3. The spec will automatically run `challenge_spec` and `check_readiness` — review the findings.',
        '4. Present the spec to the user for approval.',
        '',
        'Do NOT write any production code yet. The spec must be approved before implementation begins.',
    ].join('\n');
}
function buildExecuteSddFlowPrompt(specId, projectPath, mode) {
    const pathHint = projectPath ? ` in project at \`${projectPath}\`` : '';
    const modeHint = mode === 'implement-only' ? ' (implement-only mode — skip branch creation and PR)' : '';
    const branchStep = mode !== 'implement-only'
        ? '4. Create a feature branch: `git checkout -b feat/' + specId + '-<slug>`.'
        : '4. Implement in the current branch (implement-only mode).';
    const prStep = mode !== 'implement-only' ? '10. Open a PR with `create_pr_from_spec`.' : '';
    return [
        `You are implementing Planu spec \`${specId}\`${pathHint}${modeHint} using the full SDD flow.`,
        '',
        'Steps:',
        `1. Call \`list_specs\` and read the full spec for \`${specId}\`.`,
        '2. Verify spec status is `approved`. If not, call `check_readiness` and stop with a summary.',
        '3. Call `update_status({ specId: "' +
            specId +
            '", status: "implementing" })` to signal start.',
        branchStep,
        '5. Implement all source files following Clean Architecture: types → engine → storage → tools.',
        '6. Write tests mirroring `src/` structure in `tests/`. Coverage ≥ 95% on new files.',
        '7. Run `pnpm typecheck && pnpm lint && pnpm test:coverage` — fix all failures.',
        '8. Call `validate({ specId: "' + specId + '" })` — fix any failing criteria.',
        '9. Call `update_status({ specId: "' + specId + '", status: "done" })` when all criteria pass.',
        prStep,
        '',
        'Never mark done until ALL acceptance criteria pass `validate`.',
    ]
        .filter(Boolean)
        .join('\n');
}
function buildChallengeSpecPrompt(specId, focus) {
    const focusHint = focus !== undefined && focus !== 'all' ? ` with a focus on **${focus}**` : '';
    const securityStep = focus === 'security' || focus === 'all'
        ? '5. Call `red_team` for adversarial security scenarios.'
        : '';
    return [
        `You are stress-testing Planu spec \`${specId}\`${focusHint} to find weaknesses before implementation.`,
        '',
        'Steps:',
        `1. Call \`list_specs\` and read the full spec for \`${specId}\`.`,
        `2. Call \`challenge_spec({ specId: "${specId}" })\` and read all findings.`,
        '3. Call `ears_lint` to check criterion format quality.',
        '4. Call `validate_criteria_quality` for testability gaps.',
        securityStep,
        '',
        'For each finding, provide:',
        '- Severity: 🔴 blocking | 🟡 missing edge case | 🟢 ambiguity',
        '- Root cause: why this is a problem',
        '- Suggested fix: a concrete GIVEN/WHEN/THEN criterion rewrite or addition',
        '',
        'The spec must have no blocking gaps before it can be approved.',
    ]
        .filter(Boolean)
        .join('\n');
}
// ---------------------------------------------------------------------------
// Registration
// ---------------------------------------------------------------------------
/**
 * Register Planu workflow prompts on the MCP server (slash-command picker entries).
 * Three prompts: create_spec, execute_sdd_flow, challenge_spec.
 */
export function registerPlanuMcpPrompts(server) {
    server.registerPrompt('create_spec', {
        description: 'Create a new Planu spec from a feature description — facilitates requirements, drafts criteria, returns a ready-to-review spec.',
        argsSchema: {
            title: z.string().describe('Short title for the feature or change'),
            description: z.string().describe('Free-text description of what to build'),
            projectPath: z.string().optional().describe('Absolute path to the project root (optional)'),
        },
    }, ({ title, description, projectPath }) => ({
        messages: [
            {
                role: 'user',
                content: {
                    type: 'text',
                    text: buildCreateSpecPrompt(title, description, projectPath),
                },
            },
        ],
    }));
    server.registerPrompt('execute_sdd_flow', {
        description: 'Run the full SDD flow for an approved spec — creates branch, implements, validates, and opens a PR.',
        argsSchema: {
            specId: z.string().describe('The Planu spec ID to implement (e.g. SPEC-123)'),
            projectPath: z.string().optional().describe('Absolute path to the project root (optional)'),
            mode: z
                .enum(['full', 'implement-only'])
                .optional()
                .describe('Execution mode. Valid values: full, implement-only'),
        },
    }, ({ specId, projectPath, mode }) => ({
        messages: [
            {
                role: 'user',
                content: {
                    type: 'text',
                    text: buildExecuteSddFlowPrompt(specId, projectPath, mode),
                },
            },
        ],
    }));
    server.registerPrompt('challenge_spec', {
        description: 'Stress-test a Planu spec — finds gaps, contradictions, missing edge cases, and unclear criteria.',
        argsSchema: {
            specId: z.string().describe('The Planu spec ID to challenge (e.g. SPEC-123)'),
            focus: z
                .enum(['security', 'performance', 'edge-cases', 'all'])
                .optional()
                .describe('Optional focus area. Valid values: security, performance, edge-cases, all'),
        },
    }, ({ specId, focus }) => ({
        messages: [
            {
                role: 'user',
                content: {
                    type: 'text',
                    text: buildChallengeSpecPrompt(specId, focus),
                },
            },
        ],
    }));
}
//# sourceMappingURL=mcp-prompts.js.map