import { evaluateImplementationContract } from '../../engine/implementation-contract/index.js';
import { parseFrontmatterScenarios } from '../../engine/validator/spec-compliance-runner.js';
export function generateImplementationContractChallengeScenarios(spec, specContent) {
    const criteria = parseFrontmatterScenarios(specContent).map((scenario) => scenario.title);
    const issues = evaluateImplementationContract(stripFrontmatter(specContent), criteria);
    if (issues.length === 0) {
        return [];
    }
    const missingEdges = !/\b(edge cases?|failure modes?)\b/i.test(specContent);
    const missingBoundaries = !/\b(no-touch|forbidden|non-goals?|out of scope)\b/i.test(specContent);
    const scenarios = [];
    scenarios.push({
        scenario: `[${spec.id}] Implementation Contract Gap: spec leaves the implementer to infer required behavior, file scope, verification, or missing decisions.`,
        probability: 'high',
        impact: 'high',
        currentHandling: issues
            .map((issue) => issue.message)
            .slice(0, 3)
            .join('; '),
        requiredHandling: 'Add or repair ## Implementation Contract before coding: user outcome, behavior contract, file-level work plan, acceptance-to-verification map, edge cases, non-goals, and verification commands.',
        dataConsistency: 'Do not start implementation until the spec states what persistent files or state may change.',
        userExperience: 'The planner should ask for concrete missing decisions instead of sending an ambiguous spec to the implementer.',
    });
    if (missingEdges) {
        scenarios.push({
            scenario: `[${spec.id}] Missing Edge Cases: implementation may pass happy-path criteria while failing required failure modes.`,
            probability: 'medium',
            impact: 'high',
            currentHandling: 'Edge cases and failure modes are not explicit in the spec.',
            requiredHandling: 'Add concrete edge cases and failure modes to ## Implementation Contract before approval.',
            dataConsistency: 'State-changing behavior must define rollback or no-write behavior for failures.',
            userExperience: 'Users should not discover undefined behavior during implementation review.',
        });
    }
    if (missingBoundaries) {
        scenarios.push({
            scenario: `[${spec.id}] Missing No-Touch Boundaries: implementer may refactor unrelated code or satisfy the wording with an architecture-violating shortcut.`,
            probability: 'medium',
            impact: 'high',
            currentHandling: 'No non-goals, forbidden approaches, or no-touch areas are explicit.',
            requiredHandling: 'Add non-goals, forbidden approaches, and no-touch areas to the implementation contract.',
            dataConsistency: 'Unrelated persistent formats and stores must not change without explicit scope.',
            userExperience: 'The implementer receives bounded work instead of open-ended refactoring permission.',
        });
    }
    return scenarios;
}
function stripFrontmatter(raw) {
    return raw.replace(/^---\n[\s\S]*?\n---\n?/, '');
}
//# sourceMappingURL=implementation-contract-challenge-scenarios.js.map