"use strict";
// Trust ladder permission gate — pure overlay over PermissionEngine.
//
// Rather than mutating the existing PermissionEngine (which is load-bearing),
// callers consult `evaluatePermissionGate` BEFORE handing off to the engine.
// The gate translates the trust rung into one of four high-level decisions:
//
//   shadow   — never execute; log only as proposed action
//   suggest  — surface a Mission Control card; user clicks to execute
//   confirm  — require typed confirmation token (kill-switch style)
//   allow    — let the underlying PermissionEngine make the final call
//
// The web server and autonomy loop can opt into the gate by wrapping the
// permission check. Existing callers keep working unchanged.
Object.defineProperty(exports, "__esModule", { value: true });
exports.evaluatePermissionGate = evaluatePermissionGate;
exports.shouldDeferToEngine = shouldDeferToEngine;
const trustLadder_1 = require("./trustLadder");
function evaluatePermissionGate(snap, input) {
    const rung = (0, trustLadder_1.getRung)(snap, input.capability);
    if (rung === 0)
        return { decision: 'shadow', rung, rationale: 'Capability is at rung 0 (shadow) — observe only.' };
    if (rung === 1)
        return { decision: 'suggest', rung, rationale: 'Capability is at rung 1 (suggest) — surface a card, do not execute.' };
    if (rung === 2)
        return { decision: 'allow', rung, rationale: 'Capability is at rung 2 (ask) — defer to PermissionEngine for the standard prompt.' };
    if ((0, trustLadder_1.requiresConfirmation)(snap, input.capability))
        return { decision: 'confirm', rung, rationale: 'Capability is at rung 3 (confirm) — typed confirmation required.' };
    if ((0, trustLadder_1.canActAutonomously)(snap, input.capability))
        return { decision: 'allow', rung, rationale: 'Capability is at rung 4 (act) — autonomous execution permitted.' };
    return { decision: 'allow', rung, rationale: 'Default: defer to PermissionEngine.' };
}
/** Convenience: resolve "should I even bother asking PermissionEngine?" */
function shouldDeferToEngine(result) {
    return result.decision === 'allow' || result.decision === 'confirm';
}
//# sourceMappingURL=permissionGate.js.map