"use strict";
/**
 * SSH host names created by this extension have the format:
 *   neuralinverse-vscode--<safeHostname>--<owner>--<workspace>.<agent?>
 *
 * The remote authority is:
 *   ssh-remote+neuralinverse-vscode--<safeHostname>--<owner>--<workspace>.<agent?>
 *
 * The --ssh-host-prefix passed to the CLI is:
 *   neuralinverse-vscode--<safeHostname>--
 * After stripping, the CLI sees: <owner>--<workspace>.<agent?>
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.AUTHORITY_PREFIX = void 0;
exports.parseRemoteAuthority = parseRemoteAuthority;
exports.toRemoteAuthority = toRemoteAuthority;
exports.toSshHost = toSshHost;
exports.AUTHORITY_PREFIX = 'neuralinverse-vscode--';
function parseRemoteAuthority(authority) {
    const parts = authority.split('+');
    const sshHost = parts[1];
    if (!sshHost || !sshHost.startsWith(exports.AUTHORITY_PREFIX)) {
        return null;
    }
    const rest = sshHost.slice(exports.AUTHORITY_PREFIX.length);
    const segments = rest.split('--');
    if (segments.length < 3) {
        return null;
    }
    const safeHostname = segments.slice(0, -2).join('--');
    const owner = segments[segments.length - 2];
    const workspaceAndAgent = segments[segments.length - 1];
    let workspace = workspaceAndAgent;
    let agent = 'main';
    const dotIdx = workspaceAndAgent.indexOf('.');
    if (dotIdx > 0) {
        workspace = workspaceAndAgent.slice(0, dotIdx);
        agent = workspaceAndAgent.slice(dotIdx + 1);
    }
    return { safeHostname, owner, workspace, agent, sshHost };
}
function toRemoteAuthority(safeHostname, owner, workspace, agent) {
    let host = `${exports.AUTHORITY_PREFIX}${safeHostname}--${owner}--${workspace}`;
    if (agent) {
        host += `.${agent}`;
    }
    return `ssh-remote+${host}`;
}
function toSshHost(safeHostname, owner, workspace, agent) {
    let host = `${exports.AUTHORITY_PREFIX}${safeHostname}--${owner}--${workspace}`;
    if (agent) {
        host += `.${agent}`;
    }
    return host;
}
//# sourceMappingURL=authority.js.map