/**
 * Doctor Command
 *
 * Comprehensive health check for SpecWeave projects.
 * Runs diagnostic checks without modifying anything.
 */
import { runDoctor, formatDoctorReport } from '../../core/doctor/doctor.js';
import { consoleLogger as logger } from '../../utils/logger.js';
/**
 * Execute doctor command
 *
 * @param projectRoot - Project root directory (defaults to cwd)
 * @param options - Command options
 * @returns Doctor report
 */
export async function doctor(projectRoot = process.cwd(), options = {}) {
    const report = await runDoctor(projectRoot, options);
    // 0796 / T-001 — `--quiet` suppresses all stdout but preserves exit code.
    // Useful for hook-based callers that consume the returned `report` and
    // don't want to pollute the user's terminal.
    if (!options.quiet) {
        if (options.json) {
            console.log(JSON.stringify(report, null, 2));
        }
        else {
            console.log(formatDoctorReport(report, options.verbose));
        }
    }
    return report;
}
/**
 * Register doctor command
 *
 * @param program - Commander program
 */
export function registerDoctorCommand(program) {
    program
        .command('doctor')
        .description('Run comprehensive health check on SpecWeave project')
        .option('--verbose', 'Show detailed output for each check')
        .option('--json', 'Output as JSON')
        .option('--quick', 'Skip slow checks (network, hook execution)')
        .option('--quiet', 'Suppress all stdout (exit code still reflects failures)')
        .option('--skip-external', 'Skip external tool connectivity checks')
        .option('--fix', 'Apply inline fixes (remove ghost files, stale cache, update lockfile hashes)')
        .action(async (options) => {
        try {
            const report = await doctor(process.cwd(), {
                verbose: options.verbose,
                json: options.json,
                quick: options.quick,
                quiet: options.quiet,
                skipExternal: options.skipExternal,
                fix: options.fix,
            });
            // Exit with appropriate code
            if (report.summary.failures > 0) {
                process.exit(1);
            }
        }
        catch (error) {
            logger.error(`Doctor command failed: ${error}`);
            process.exit(1);
        }
    });
}
//# sourceMappingURL=doctor.js.map