// System-information collectors for the debug dump.
//
// Pure synchronous reads of `os` and `process`. No I/O, no spawns.
// Output is consumed by `render.ts` and `index.ts` only.
import os from "node:os";
import { redactArgv } from "./redact.js";
export function collectSystemInfo() {
    const cpus = (() => {
        try {
            return os.cpus() || [];
        }
        catch {
            return [];
        }
    })();
    const first = cpus[0];
    const timezone = (() => {
        try {
            return Intl.DateTimeFormat().resolvedOptions().timeZone || "<unknown>";
        }
        catch {
            return "<unknown>";
        }
    })();
    return {
        platform: os.platform(),
        arch: os.arch(),
        release: os.release(),
        osVersion: safe(() => os.version(), "<unknown>"),
        cpuCount: cpus.length,
        cpuModel: first?.model || "<unknown>",
        cpuSpeedMhz: first?.speed || 0,
        totalMemoryMb: Math.round(os.totalmem() / (1024 * 1024)),
        freeMemoryMb: Math.round(os.freemem() / (1024 * 1024)),
        uptimeSeconds: Math.round(os.uptime()),
        hostname: safe(() => os.hostname(), "<unknown>"),
        wallclockIso: new Date().toISOString(),
        timezone,
        pid: process.pid,
        ppid: process.ppid,
        cwd: safe(() => process.cwd(), "<unknown>"),
        // Redact credentials that may ride in CLI args — `--token=…`, the split
        // `--password hunter2` form, or an embedded URL with userinfo — so the
        // dump stays safe to paste.
        argv: redactArgv(process.argv),
        execPath: process.execPath,
        isTTY: Boolean(process.stdout.isTTY),
        ci: process.env.CI,
    };
}
function safe(fn, fallback) {
    try {
        return fn();
    }
    catch {
        return fallback;
    }
}
//# sourceMappingURL=system.js.map