"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VALIDATION_ROLLUP_AGGREGATION_CONTRACT = exports.VALIDATION_ROLLUP_SPECIALIZED_BOUNDARIES = exports.VALIDATION_ROLLUP_EVIDENCE_SOURCE_INVENTORY = exports.PLANNING_VALIDATION_BASELINE_PATH = exports.EXPECTED_TEMPLATE_H2_HEADINGS = exports.DOCTOR_TEXT_PATH_PREVIEW_LIMIT = void 0;
exports.hasDoctorErrorFinding = hasDoctorErrorFinding;
const phase_overview_contract_1 = require("../planning/phase-overview-contract");
const reconciliation_resolution_1 = require("../planning/reconciliation-resolution");
__exportStar(require("./action-relevance"), exports);
__exportStar(require("./check-orchestration"), exports);
exports.DOCTOR_TEXT_PATH_PREVIEW_LIMIT = 12;
exports.EXPECTED_TEMPLATE_H2_HEADINGS = new Map([
    [
        '.day-shift/templates/specification.md',
        [
            '## Purpose',
            '## Problem Statement',
            '## Desired Outcome',
            '## Non-Goals',
            '## Scope',
            '## Constraints',
            '## Success Criteria',
            '## Open Questions',
        ],
    ],
    [
        '.day-shift/templates/slice-overview.md',
        [
            '## Purpose',
            '## Source Specification',
            '## Desired Outcome',
            '## Scope',
            '## Non-Goals',
            '## Planning Depth',
            '## Phases',
            '## Decisions',
            '## Risks',
            '## Validation Strategy',
            '## Open Questions',
        ],
    ],
    [
        '.day-shift/templates/phase-overview.md',
        phase_overview_contract_1.PHASE_OVERVIEW_H2_ORDER.map((heading) => `## ${heading}`),
    ],
    [
        '.day-shift/templates/milestone-overview.md',
        [
            '## Purpose',
            '## Scope',
            '## Navigation',
            '## Tasks',
            '## Acceptance Criteria',
            '## Dependencies',
            '## Risks',
            '## Validation Focus',
            '## Open Questions',
        ],
    ],
    [
        '.day-shift/templates/task-definition.md',
        [
            '## Objective',
            '## Navigation',
            '## Upstream Context',
            '## Implementation Target Paths',
            '## Current Behavior',
            '## Desired Behavior',
            '## Runtime Delta',
            '## Acceptance Criteria',
            '## Validation Commands',
            '## Rollback / Recovery',
            '## Risks',
            '## Dependencies',
            '## Constraints',
            '## Assumptions',
            '## Lifecycle / Closure Expectations',
            '## Open Questions',
        ],
    ],
    [
        '.day-shift/templates/implementation-summary.md',
        [
            '## Summary',
            '## Changed Paths',
            '## Acceptance Criteria Results',
            '## Validation Performed',
            '## Validation Exceptions',
            '## Scope Classification',
            '## Runtime Evidence Boundary',
            '## Deviations',
            '## Risks and Follow-Ups',
            '## Open Questions',
        ],
    ],
    ['.day-shift/templates/reconciliation.md', reconciliation_resolution_1.TASK_RECONCILIATION_SECTION_ORDER.map((heading) => `## ${heading}`)],
    [
        '.day-shift/templates/milestone-reconciliation.md',
        reconciliation_resolution_1.MILESTONE_RECONCILIATION_SECTION_ORDER.map((heading) => `## ${heading}`),
    ],
]);
exports.PLANNING_VALIDATION_BASELINE_PATH = '.day-shift/state/planning-validation-baseline.json';
exports.VALIDATION_ROLLUP_EVIDENCE_SOURCE_INVENTORY = [
    {
        id: 'planning-artifact-metadata',
        producer: {
            path: 'src/lib/doctor/planning-checks.ts',
            functionName: 'runPlanningArtifactMetadataCheck',
            command: 'day-shift validation smoke --scope planning',
        },
        evidenceShapes: ['checks', 'findings', 'readiness-status'],
        emitsSharedValidationFindings: true,
        commandEvidenceCategory: 'validation-rollup',
        conciseSmoke: true,
        futureRollupCandidate: true,
        readOnlyExecution: true,
        notes: 'Contributes the planning-artifact-metadata smoke check and shared validation findings when metadata drift is detected.',
    },
    {
        id: 'planning-cli-provenance',
        producer: {
            path: 'src/lib/doctor/planning-checks.ts',
            functionName: 'runPlanningCliProvenanceCheck',
            command: 'day-shift validation smoke --scope planning',
        },
        evidenceShapes: ['checks', 'findings', 'readiness-status'],
        emitsSharedValidationFindings: true,
        commandEvidenceCategory: 'validation-rollup',
        conciseSmoke: true,
        futureRollupCandidate: true,
        readOnlyExecution: true,
        notes: 'Contributes the planning-cli-provenance smoke check and shared validation findings for provenance drift.',
    },
    {
        id: 'lightweight-artifact-strictness',
        producer: {
            path: 'src/lib/doctor/planning-checks.ts',
            functionName: 'runLightweightArtifactStrictnessCheck',
            command: 'day-shift validation smoke --scope planning',
        },
        evidenceShapes: ['checks', 'findings', 'readiness-status'],
        emitsSharedValidationFindings: true,
        commandEvidenceCategory: 'validation-rollup',
        conciseSmoke: true,
        futureRollupCandidate: true,
        readOnlyExecution: true,
        notes: 'Contributes the lightweight-artifact-strictness smoke check and shared validation findings for lightweight boundary drift.',
    },
    {
        id: 'planning-inventory',
        producer: {
            path: 'src/lib/planning/planning-navigation.ts',
            functionName: 'inventoryPlanning',
            command: 'day-shift planning inventory',
        },
        evidenceShapes: ['checks', 'findings', 'inventory-findings', 'readiness-status'],
        emitsSharedValidationFindings: true,
        commandEvidenceCategory: 'validation-rollup',
        conciseSmoke: true,
        futureRollupCandidate: true,
        readOnlyExecution: true,
        notes: 'Contributes paired-artifact and stale-state inventory findings; smoke maps them into shared validation findings with source planning-inventory.',
    },
    {
        id: 'planning-gap-report',
        producer: {
            path: 'src/lib/planning/planning-navigation.ts',
            functionName: 'gapReportPlanning',
            command: 'day-shift planning gap-report',
        },
        evidenceShapes: ['checks', 'findings', 'gaps', 'readiness-status'],
        emitsSharedValidationFindings: true,
        commandEvidenceCategory: 'validation-rollup',
        conciseSmoke: true,
        futureRollupCandidate: true,
        readOnlyExecution: true,
        notes: 'Contributes expected-versus-observed planning gaps; smoke maps gaps into shared validation findings with source planning-gap-report.',
    },
    {
        id: 'validation-links-check',
        producer: {
            path: 'src/cli/commands/validation-links-check/index.ts',
            functionName: 'runValidationLinksCheckReport',
            command: 'day-shift validation links-check --scope planning --artifact <path>',
        },
        evidenceShapes: ['checks', 'findings', 'readiness-status'],
        emitsSharedValidationFindings: true,
        commandEvidenceCategory: 'validation-rollup',
        conciseSmoke: 'optional',
        futureRollupCandidate: true,
        readOnlyExecution: true,
        notes: 'Contributes selected-artifact trace-link lifecycle findings to artifact-scoped smoke and rollup without broadening repository-wide smoke traversal.',
    },
    {
        id: 'cross-artifact-alignment',
        producer: {
            path: 'src/lib/doctor/index.ts',
            functionName: 'runCrossArtifactAlignmentSmoke',
            command: 'day-shift validation smoke --scope planning',
        },
        evidenceShapes: ['checks', 'findings', 'cross-artifact-lanes', 'readiness-status'],
        emitsSharedValidationFindings: true,
        commandEvidenceCategory: 'validation-rollup',
        conciseSmoke: true,
        futureRollupCandidate: true,
        readOnlyExecution: true,
        notes: 'Contributes cross-artifact lane evidence for headings, prompt lanes, routing, handoffs, placeholder contracts, and no-write boundaries.',
    },
    {
        id: 'planning-next-action',
        producer: {
            path: 'src/lib/planning/planning-navigation.ts',
            functionName: 'suggestPlanningNextAction',
            command: 'day-shift planning next-action',
        },
        evidenceShapes: ['next-actions'],
        emitsSharedValidationFindings: false,
        commandEvidenceCategory: null,
        conciseSmoke: 'optional',
        futureRollupCandidate: true,
        readOnlyExecution: true,
        notes: 'Contributes optional artifact-specific guidance when validation smoke receives --artifact; it remains advisory and does not create findings.',
    },
    {
        id: 'existing-baseline-comparison',
        producer: {
            path: 'src/lib/doctor/index.ts',
            functionName: 'loadPlanningValidationBaseline',
            command: 'day-shift validation smoke --scope planning',
        },
        evidenceShapes: ['baseline-suppression-counts', 'findings', 'inventory-findings', 'gaps', 'readiness-status'],
        emitsSharedValidationFindings: false,
        commandEvidenceCategory: null,
        conciseSmoke: true,
        futureRollupCandidate: true,
        readOnlyExecution: true,
        notes: 'Reads an existing forward-only planning validation baseline and reports suppression counts. Checkpoint creation is excluded from read-only rollup execution and remains a separate write command.',
    },
];
exports.VALIDATION_ROLLUP_SPECIALIZED_BOUNDARIES = [
    {
        id: 'task-readiness-review',
        kind: 'specialized-review',
        command: 'day-shift task readiness-review --task-definition <path>',
        sourcePath: 'src/cli/commands/task-readiness-review/index.ts',
        rollupExecution: 'excluded',
        writeCapable: false,
        mayReferenceAs: ['recovery-guidance', 'follow-up-command'],
        duplicatesDetailedFindings: false,
        preservesSharedNoWritePolicy: true,
        notes: 'Readiness review owns task handoff evidence and remains a separate no-write review surface.',
    },
    {
        id: 'task-review',
        kind: 'specialized-review',
        command: 'day-shift task review --task-definition <path>',
        sourcePath: 'src/cli/commands/task-review/index.ts',
        rollupExecution: 'excluded',
        writeCapable: false,
        mayReferenceAs: ['recovery-guidance', 'follow-up-command'],
        duplicatesDetailedFindings: false,
        preservesSharedNoWritePolicy: true,
        notes: 'Task review owns detailed task readiness and paired-execution evidence; rollup may point to it without inlining its findings.',
    },
    {
        id: 'milestone-review',
        kind: 'specialized-review',
        command: 'day-shift milestone review --milestone-overview <path>',
        sourcePath: 'src/cli/commands/milestone-review/index.ts',
        rollupExecution: 'excluded',
        writeCapable: false,
        mayReferenceAs: ['recovery-guidance', 'follow-up-command'],
        duplicatesDetailedFindings: false,
        preservesSharedNoWritePolicy: true,
        notes: 'Milestone review owns milestone-level planning readiness and reconciliation evidence.',
    },
    {
        id: 'implementation-summary-review',
        kind: 'specialized-review',
        command: 'day-shift implementation-summary review --task-definition <path>',
        sourcePath: 'src/cli/commands/implementation-summary-review/index.ts',
        rollupExecution: 'excluded',
        writeCapable: false,
        mayReferenceAs: ['recovery-guidance', 'follow-up-command'],
        duplicatesDetailedFindings: false,
        preservesSharedNoWritePolicy: true,
        notes: 'Implementation-summary review owns task closeout evidence quality and lifecycle alignment checks.',
    },
    {
        id: 'reconciliation-review',
        kind: 'specialized-review',
        command: 'day-shift reconciliation review --milestone-overview <path>',
        sourcePath: 'src/cli/commands/reconciliation-review/index.ts',
        rollupExecution: 'excluded',
        writeCapable: false,
        mayReferenceAs: ['recovery-guidance', 'follow-up-command'],
        duplicatesDetailedFindings: false,
        preservesSharedNoWritePolicy: true,
        notes: 'Reconciliation review owns milestone reconciliation evidence and task-summary rollup quality.',
    },
    {
        id: 'metadata-validate-update',
        kind: 'metadata-validation',
        command: 'day-shift metadata validate-update --artifact <path> --field <key=value>',
        sourcePath: 'src/cli/commands/metadata-validate-update/index.ts',
        rollupExecution: 'excluded',
        writeCapable: false,
        mayReferenceAs: ['recovery-guidance', 'follow-up-command'],
        duplicatesDetailedFindings: false,
        preservesSharedNoWritePolicy: true,
        notes: 'Metadata validate-update remains a helper-backed no-write validation surface for proposed metadata mutations.',
    },
    {
        id: 'planning-guidance',
        kind: 'planning-guidance',
        command: 'day-shift planning inventory | day-shift planning gap-report | day-shift planning next-action',
        sourcePath: 'src/lib/planning/planning-navigation.ts',
        rollupExecution: 'excluded',
        writeCapable: false,
        mayReferenceAs: ['recovery-guidance', 'follow-up-command'],
        duplicatesDetailedFindings: false,
        preservesSharedNoWritePolicy: true,
        notes: 'Command-specific planning guidance remains advisory. Rollup may summarize already-supported planning evidence and recommend these commands without treating guidance as completed review evidence.',
    },
    {
        id: 'validation-checkpoint',
        kind: 'write-capable-checkpoint',
        command: 'day-shift validation checkpoint --scope planning',
        sourcePath: 'src/cli/commands/validation-checkpoint/index.ts',
        rollupExecution: 'excluded',
        writeCapable: true,
        mayReferenceAs: ['existing-baseline-evidence'],
        duplicatesDetailedFindings: false,
        preservesSharedNoWritePolicy: true,
        notes: 'Checkpoint creation writes the forward-only baseline and is never part of read-only rollup execution; only an existing baseline may be read through the existing-baseline-comparison evidence source.',
    },
];
exports.VALIDATION_ROLLUP_AGGREGATION_CONTRACT = {
    lanes: [
        {
            id: 'checks',
            reportField: 'checks',
            sourceEvidence: 'PlanningValidationSmokeReport.checks',
            preservesSourceLane: true,
            authoritativeFor: ['check ids', 'check status', 'check messages'],
            notes: 'Concise smoke checks remain a first-class lane and are not replaced by finding counts.',
        },
        {
            id: 'shared-findings',
            reportField: 'findings',
            sourceEvidence: 'PlanningValidationSmokeReport.findings',
            preservesSourceLane: true,
            authoritativeFor: [
                'ValidationFinding identity',
                'severity',
                'affected paths',
                'artifact references',
                'recovery guidance',
                'command evidence',
            ],
            notes: 'Shared findings preserve the common ValidationFinding envelope and validation-rollup command evidence when available.',
        },
        {
            id: 'inventory-findings',
            reportField: 'inventoryFindings',
            sourceEvidence: 'PlanningValidationSmokeReport.inventoryFindings',
            preservesSourceLane: true,
            authoritativeFor: ['paired artifact inventory findings'],
            notes: 'Inventory findings stay visible as their own source lane even when corresponding shared findings are emitted.',
        },
        {
            id: 'planning-gaps',
            reportField: 'gaps',
            sourceEvidence: 'PlanningValidationSmokeReport.gaps',
            preservesSourceLane: true,
            authoritativeFor: ['planning gap code', 'planning gap path', 'planning gap message'],
            notes: 'Planning gaps stay traceable to gap-report evidence instead of being flattened into anonymous text.',
        },
        {
            id: 'cross-artifact-alignment',
            reportField: 'crossArtifactAlignment',
            sourceEvidence: 'PlanningValidationSmokeReport.crossArtifactAlignment',
            preservesSourceLane: true,
            authoritativeFor: ['alignment family', 'surface mode', 'no-write flag', 'lane findings'],
            notes: 'Cross-artifact alignment preserves its nested lane evidence for headings, prompt lanes, routing, handoff, placeholders, and no-write boundaries.',
        },
        {
            id: 'baseline',
            reportField: 'baseline',
            sourceEvidence: 'PlanningValidationSmokeReport.baseline',
            preservesSourceLane: true,
            authoritativeFor: ['baseline metadata', 'suppression counts'],
            notes: 'Baseline aggregation reports existing baseline metadata and suppression counts without writing or refreshing the baseline.',
        },
        {
            id: 'next-actions',
            reportField: 'nextActions',
            sourceEvidence: 'PlanningValidationSmokeReport.nextActions',
            preservesSourceLane: true,
            authoritativeFor: ['advisory safe next actions'],
            notes: 'Next actions remain advisory guidance and do not count as acceptance, repair, synchronization, metadata mutation, status transition, or artifact generation.',
        },
        {
            id: 'summary-counts',
            reportField: 'summary',
            sourceEvidence: 'PlanningValidationSmokeReport.summary',
            preservesSourceLane: true,
            authoritativeFor: ['total check count', 'passed check count', 'finding severity counts'],
            notes: 'Summary counts are derived rollup metadata and do not replace the underlying check or finding lanes.',
        },
        {
            id: 'readiness-status',
            reportField: 'readinessStatus',
            sourceEvidence: 'PlanningValidationSmokeReport.readinessStatus',
            preservesSourceLane: true,
            authoritativeFor: ['derived readiness status'],
            notes: 'Readiness status is derived from error and warning evidence while keeping the underlying checks, findings, inventory findings, and gaps visible.',
        },
    ],
    sharedFindingFields: ['id', 'code', 'level', 'severity', 'affectedPaths', 'artifacts', 'recovery', 'evidence'],
    sourceLaneFields: [
        'checks',
        'findings',
        'inventoryFindings',
        'gaps',
        'crossArtifactAlignment',
        'baseline',
        'nextActions',
        'summary',
        'readinessStatus',
    ],
    readinessDerivation: 'Readiness status is derived from blocking/error evidence and unresolved warning lanes; it must not hide the underlying checks, findings, inventory findings, or gaps.',
    baselinePolicy: 'Existing baseline evidence may suppress already-recorded findings and report suppression counts, but aggregation never writes, refreshes, or creates a baseline.',
    nextActionPolicy: 'Advisory next actions are guidance only and do not imply repair, synchronization, metadata mutation, status transition, artifact generation, or completed specialized review.',
    noWriteBoundary: 'Validation rollup aggregation reports evidence only; it does not repair metadata, synchronize links, mutate manifests, update status, write checkpoints, or generate artifacts.',
};
function hasDoctorErrorFinding(findings) {
    return findings.some((finding) => finding.severity === 'error');
}
