/**
 * normalize-agent-dir.ts — make `--agent-dir` robust to whatever path the
 * dashboard / a customer / ANY LLM pastes, on ANY OS.
 *
 * The dashboard generates the install prompt with the directory in whatever form
 * the customer's host uses. The CLI may then run on a different layer than that
 * path was expressed for — most commonly a Windows-style path handed to a CLI
 * running inside WSL (Linux). A human or a non-Claude LLM (OpenAI, DeepSeek,
 * Gemini, …) pasting the command verbatim must "just work" — so the CLI, not the
 * LLM, does the translation. Deterministic + unit-tested = no per-LLM behaviour.
 *
 * Rules (POSIX host — Linux/WSL/macOS):
 *   \\wsl.localhost\<distro>\root\x  →  /root/x      (Windows→WSL UNC)
 *   \\wsl$\<distro>\root\x           →  /root/x      (older UNC form)
 *   C:\Users\me\fleet                →  /mnt/c/Users/me/fleet   (WSL drvfs mount)
 *   \\server\share\x                 →  /x           (generic UNC, best-effort)
 *   /home/me/fleet , ./fleet         →  unchanged    (already POSIX)
 *
 * On native Windows (platform 'win32') Windows paths are LEFT ALONE — Node on
 * Windows resolves `C:\…` and `\\wsl.localhost\…` natively, and rewriting a real
 * UNC there would break it. Surrounding quotes/whitespace are always stripped.
 */
export function normalizeAgentDir(rawPath, platform = process.platform) {
    // Strip wrapping whitespace and a single layer of surrounding quotes.
    let p = rawPath.trim();
    if ((p.startsWith('"') && p.endsWith('"')) || (p.startsWith("'") && p.endsWith("'"))) {
        p = p.slice(1, -1);
    }
    // On native Windows, Windows paths are valid as-is — do not rewrite them.
    if (platform === 'win32')
        return p;
    // --- POSIX host (Linux / WSL / macOS) ---
    // 1. WSL UNC: \\wsl.localhost\<distro>\<rest>  or  \\wsl$\<distro>\<rest>
    const wslUncRe = /^\\\\wsl(?:\.localhost|\$)\\[^\\]+\\/i;
    if (wslUncRe.test(p)) {
        return '/' + p.replace(wslUncRe, '').replace(/\\/g, '/');
    }
    // Same, expressed with forward slashes (some shells/paste paths arrive this way).
    const wslUncFwdRe = /^\/\/wsl(?:\.localhost|\$)\/[^/]+\//i;
    if (wslUncFwdRe.test(p)) {
        return '/' + p.replace(wslUncFwdRe, '');
    }
    // 2. Windows drive path: C:\rest or c:/rest  →  /mnt/c/rest (WSL drvfs default).
    const driveRe = /^([A-Za-z]):[\\/](.*)$/;
    const driveMatch = driveRe.exec(p);
    if (driveMatch) {
        const drive = driveMatch[1].toLowerCase();
        const rest = driveMatch[2].replace(/\\/g, '/');
        return `/mnt/${drive}${rest ? '/' + rest : ''}`;
    }
    // 3. Generic UNC: \\server\share\rest  →  /rest (best-effort).
    if (p.startsWith('\\\\')) {
        const withFwd = p.replace(/\\/g, '/');
        const m = /^\/\/[^/]+\/[^/]+\/(.*)$/.exec(withFwd);
        if (m)
            return '/' + m[1];
    }
    // 4. Already POSIX (or a relative path) — unchanged.
    return p;
}
//# sourceMappingURL=normalize-agent-dir.js.map