"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runChecks = runChecks;
exports.formatChecks = formatChecks;
const child_process_1 = require("child_process");
const util_1 = require("util");
const fs_1 = require("fs");
const path_1 = require("path");
const exec = (0, util_1.promisify)(child_process_1.execFile);
async function checkBinary(name, args) {
    try {
        const { stdout } = await exec(name, args);
        const version = stdout.trim().match(/[\d.]+/)?.[0] ?? 'unknown';
        return { name, ok: true, version };
    }
    catch {
        return { name, ok: false, message: 'not found' };
    }
}
async function runChecks(projectPath) {
    const results = [];
    results.push({ name: 'Node.js', ok: true, version: process.version.replace('v', '') });
    results.push(await checkBinary('claude', ['--version']));
    results.push({ ...await checkBinary('gh', ['--version']), optional: true });
    results.push(await checkBinary('git', ['--version']));
    const vsafDir = (0, path_1.join)(projectPath, '.vsaf');
    if ((0, fs_1.existsSync)(vsafDir)) {
        const workflows = (0, fs_1.existsSync)((0, path_1.join)(vsafDir, 'workflows'))
            ? (0, fs_1.readdirSync)((0, path_1.join)(vsafDir, 'workflows'), { recursive: true }).filter(f => String(f).endsWith('.yaml') || String(f).endsWith('.yml')).length
            : 0;
        const commands = (0, fs_1.existsSync)((0, path_1.join)(vsafDir, 'commands'))
            ? (0, fs_1.readdirSync)((0, path_1.join)(vsafDir, 'commands')).filter(f => f.endsWith('.md')).length
            : 0;
        results.push({ name: '.vsaf/', ok: true, message: `${workflows} workflows, ${commands} commands` });
    }
    else {
        results.push({ name: '.vsaf/', ok: false, message: 'not found — run "vsaf init"' });
    }
    return results;
}
function formatChecks(results) {
    const lines = results.map(r => {
        const icon = r.ok ? '✓' : (r.optional ? '⚠' : '✗');
        const detail = r.version ?? r.message ?? '';
        const suffix = !r.ok && r.optional ? ' (optional)' : '';
        return `${icon} ${r.name.padEnd(12)} ${detail}${suffix}`;
    });
    return `VSAF Doctor v0.1.0\n${'─'.repeat(30)}\n${lines.join('\n')}`;
}
//# sourceMappingURL=doctor.js.map