/**
 * SDK permission mapping — projects vauban-auth `cc:*` scopes onto the
 * capability surface exposed to agent loops.
 *
 * Contract: scope hierarchy mirrors cc-scope-middleware.ts
 *   admin > execute > read
 *
 * Worker boot MUST call `mapScopesToSdkPermissions` once at init. Tools that
 * declare a capability absent from the derived permissions are refused at
 * dispatch time — fail-closed, never silently downgrade.
 */
const EMPTY_PERMISSIONS = Object.freeze({
    bash: false,
    fileIO: "none",
    web: false,
    mcp: Object.freeze([]),
});
const READ_ONLY_PERMISSIONS = Object.freeze({
    bash: false,
    fileIO: "ro",
    web: false,
    mcp: Object.freeze([
        "brain:read",
        "citadel:read",
    ]),
});
const EXECUTE_PERMISSIONS = Object.freeze({
    bash: "restricted",
    fileIO: "sandboxed",
    web: false,
    mcp: Object.freeze([
        "brain:read",
        "brain:write",
        "citadel:read",
        "citadel:write",
    ]),
});
const ADMIN_PERMISSIONS = Object.freeze({
    bash: "restricted",
    fileIO: "sandboxed",
    web: true,
    mcp: Object.freeze([
        "brain:read",
        "brain:write",
        "brain:admin",
        "citadel:read",
        "citadel:write",
        "citadel:admin",
    ]),
});
/**
 * Project a JWT scope list onto SDK capabilities. Unknown scopes are ignored.
 *
 * Rules:
 * - `cc:admin` → full surface (bash restricted, fileIO sandboxed, web, mcp *)
 * - `cc:execute` → bash:restricted + fileIO:sandboxed + web:false + mcp R/W
 * - `cc:read` → bash:false + fileIO:ro + web:false + mcp R only
 * - no `cc:*` scope → fail-closed: no capabilities at all
 */
export function mapScopesToSdkPermissions(scopes) {
    if (scopes.includes("cc:admin"))
        return ADMIN_PERMISSIONS;
    if (scopes.includes("cc:execute"))
        return EXECUTE_PERMISSIONS;
    if (scopes.includes("cc:read"))
        return READ_ONLY_PERMISSIONS;
    return EMPTY_PERMISSIONS;
}
/**
 * Returns true iff `permissions` authorises `capability`. Canonical gate
 * used by the SDK loop before dispatching a tool.
 */
export function permitsCapability(permissions, capability) {
    switch (capability) {
        case "bash":
            return permissions.bash !== false;
        case "fileIO":
            return permissions.fileIO !== "none";
        case "web":
            return permissions.web;
        case "mcp":
            return permissions.mcp.length > 0;
    }
}
/**
 * Returns true iff the caller holds every MCP permission in `required`.
 * Used when a tool declares a specific MCP sub-scope (e.g. "brain:write").
 */
export function permitsMcpScopes(permissions, required) {
    if (required.length === 0)
        return true;
    return required.every((r) => permissions.mcp.includes(r));
}
//# sourceMappingURL=sdk-permissions.js.map