/**
 * System diagnostics collection for issue reports.
 *
 * Extracted from CLI issue command to core for shared use
 * by both CLI and dispatch layer.
 *
 * @task T4555
 * @epic T4820
 */
import { execFileSync } from 'node:child_process';
import { getCleoHome } from '../paths.js';
import { getSystemInfo } from '../system/platform-paths.js';
/**
 * Collect system diagnostics for bug reports.
 */
export function collectDiagnostics() {
    const getVersion = (cmd, args) => {
        try {
            return execFileSync(cmd, args, {
                encoding: 'utf-8',
                stdio: ['pipe', 'pipe', 'pipe'],
            }).trim();
        }
        catch {
            return 'not installed';
        }
    };
    const cleoLocation = getVersion('which', ['cleo']);
    const ghVersion = getVersion('gh', ['--version']).split('\n')[0] ?? 'not installed';
    const sysInfo = getSystemInfo();
    return {
        cleoVersion: '2026.2.1',
        nodeVersion: process.version,
        os: `${sysInfo.platform} ${sysInfo.release} ${sysInfo.arch}`,
        arch: sysInfo.arch,
        shell: process.env['SHELL'] ?? 'unknown',
        cleoHome: getCleoHome(),
        ghVersion,
        installLocation: cleoLocation || 'not found',
    };
}
/**
 * Format diagnostics as markdown table.
 */
export function formatDiagnosticsTable(diag) {
    const rows = [
        '## Environment',
        '| Component | Version |',
        '|-----------|---------|',
        `| CLEO | ${diag.cleoVersion} |`,
        `| Node.js | ${diag.nodeVersion} |`,
        `| OS | ${diag.os}${diag.arch ? ` (${diag.arch})` : ''} |`,
        `| Shell | ${diag.shell} |`,
        `| gh CLI | ${diag.ghVersion} |`,
        `| Install | ${diag.installLocation} |`,
    ];
    return rows.join('\n');
}
//# sourceMappingURL=diagnostics.js.map