"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTaskReviewCommand = createTaskReviewCommand;
const errors_1 = require("../../../lib/errors");
const output_1 = require("../../../lib/output");
const planning_review_1 = require("../../../lib/planning/planning-review");
const review_output_contracts_1 = require("../../../lib/planning/review-output-contracts");
const runtime_contract_1 = require("../../../lib/runtime/runtime-contract");
const global_format_1 = require("../global-format");
async function createTaskReviewCommand() {
    const { Command } = await import("commander");
    const command = new Command("review");
    command
        .description("Review a task-definition artifact as a read-only, no-write evidence surface against readiness or paired execution evidence.")
        .requiredOption("--task-definition <path>", "Repository-relative path to the task-definition.md file to review.")
        .action((_, commandInstance) => {
        const format = (0, output_1.resolveOutputFormat)((0, global_format_1.getGlobalFormat)(commandInstance));
        if (format === null) {
            throw (0, errors_1.createUsageError)("Output format must be one of: text, json.", [`Received: ${String((0, global_format_1.getGlobalFormat)(commandInstance))}`]);
        }
        const repositoryContext = (0, runtime_contract_1.createRepositoryContext)((0, runtime_contract_1.detectRepositoryRoot)(), false);
        const options = commandInstance.opts();
        const result = (0, planning_review_1.reviewTaskPlanning)(repositoryContext.root, {
            taskDefinitionPath: options.taskDefinition
        });
        (0, output_1.emitSuccess)({
            command: "task review",
            format,
            text: (0, planning_review_1.renderTaskPlanningReviewResult)(result),
            data: {
                repositoryRoot: repositoryContext.root,
                detectionSource: repositoryContext.detectionSource,
                readOnly: true,
                writeCapable: false,
                noWriteBoundary: (0, review_output_contracts_1.getReviewOutputContract)("task review").noWriteBoundary,
                reviewOutputContract: (0, review_output_contracts_1.getReviewOutputContract)("task review"),
                reviewMode: result.reviewMode,
                taskDefinitionPath: result.taskDefinitionPath,
                implementationSummaryPath: result.implementationSummaryPath,
                taskReconciliationPath: result.taskReconciliationPath,
                readinessStatus: result.readinessStatus,
                closeoutEvidenceStatus: result.closeoutEvidenceStatus,
                blockingIssues: result.blockingIssues,
                warnings: result.warnings,
                metadataHygieneFollowUps: result.metadataHygieneFollowUps,
                recoveryGuidance: result.recoveryGuidance
            },
            findings: [...result.findings]
        });
    });
    return command;
}
