/**
 * User-facing effective permission view.
 *
 * This is a read model over the compiled runtime policy for showing what the
 * current session can do right now without exposing internal enforcement state.
 */
import { RUNTIME_CAPABILITY } from '../../core/permission-policy.js';
function summarizeFilesystem(policy) {
    const readStatus = policy.filesystem.defaultReadScope === 'none' ? 'denied' : 'enabled';
    const writeStatus = policy.filesystem.defaultWriteScope === 'none'
        ? 'denied'
        : policy.filesystem.requireApprovalOutsideWorkspace
            ? 'approval_required'
            : 'enabled';
    return [
        {
            capabilityId: RUNTIME_CAPABILITY.FILESYSTEM_READ,
            label: 'Filesystem read',
            status: readStatus,
            summary: readStatus === 'enabled'
                ? `Read files inside ${policy.filesystem.workspaceRoots.length} approved workspace root${policy.filesystem.workspaceRoots.length === 1 ? '' : 's'}.`
                : 'Filesystem reads are denied.'
        },
        {
            capabilityId: RUNTIME_CAPABILITY.FILESYSTEM_WRITE,
            label: 'Filesystem write',
            status: writeStatus,
            summary: writeStatus === 'denied'
                ? 'Filesystem writes are denied.'
                : policy.filesystem.requireApprovalOutsideWorkspace
                    ? 'Writes inside approved workspaces are allowed; writes outside them require approval.'
                    : 'Filesystem writes are allowed.'
        }
    ];
}
function summarizeShell(policy) {
    if (!policy.shell.enabled || policy.shell.mutationBehavior === 'deny') {
        return {
            capabilityId: RUNTIME_CAPABILITY.SHELL_EXECUTE,
            label: 'Shell',
            status: 'denied',
            summary: 'Shell execution is denied.'
        };
    }
    if (policy.shell.mutationBehavior === 'require_approval') {
        return {
            capabilityId: RUNTIME_CAPABILITY.SHELL_EXECUTE,
            label: 'Shell',
            status: 'approval_required',
            summary: 'Shell commands require explicit approval.'
        };
    }
    return {
        capabilityId: RUNTIME_CAPABILITY.SHELL_EXECUTE,
        label: 'Shell',
        status: 'enabled',
        summary: 'Shell execution is allowed.'
    };
}
function summarizeSpreadsheet(policy) {
    if (!policy.spreadsheet.enabled || policy.spreadsheet.mutationBehavior === 'deny') {
        return {
            capabilityId: RUNTIME_CAPABILITY.SPREADSHEET_MUTATE,
            label: 'Spreadsheet',
            status: 'denied',
            summary: 'Spreadsheet changes are denied.'
        };
    }
    if (policy.spreadsheet.mutationBehavior === 'require_approval') {
        return {
            capabilityId: RUNTIME_CAPABILITY.SPREADSHEET_MUTATE,
            label: 'Spreadsheet',
            status: 'approval_required',
            summary: 'Spreadsheet changes require approval.'
        };
    }
    return {
        capabilityId: RUNTIME_CAPABILITY.SPREADSHEET_MUTATE,
        label: 'Spreadsheet',
        status: 'enabled',
        summary: 'Spreadsheet changes are allowed.'
    };
}
function summarizeSubagents(policy) {
    return {
        capabilityId: RUNTIME_CAPABILITY.SUBAGENT_SPAWN,
        label: 'Subagents',
        status: policy.subagents.enabled ? 'enabled' : 'denied',
        summary: policy.subagents.enabled
            ? 'Subagents inherit the parent permission boundary and cannot escalate privileges.'
            : 'Subagent spawning is denied.'
    };
}
export function buildEffectivePermissionView(policy) {
    return {
        modeName: policy.modeName,
        dangerouslySkipRuntimePermissions: policy.dangerouslySkipRuntimePermissions,
        headlessApprovalsDenied: !policy.approvals.allowHeadlessApproval,
        headlessSpreadsheetApprovalsDenied: !policy.spreadsheet.allowHeadlessApproval,
        capabilities: [
            ...summarizeFilesystem(policy),
            summarizeShell(policy),
            summarizeSpreadsheet(policy),
            summarizeSubagents(policy)
        ]
    };
}
export function formatEffectivePermissionView(view) {
    const lines = [
        `Effective permissions${view.modeName ? ` (${view.modeName})` : ''}:`,
        `Runtime permissions bypass: ${view.dangerouslySkipRuntimePermissions ? 'enabled' : 'disabled'}`,
        `Headless runtime approval-gated actions: ${view.headlessApprovalsDenied ? 'deny' : 'policy-controlled'}`,
        `Headless spreadsheet approvals: ${view.headlessSpreadsheetApprovalsDenied ? 'deny' : 'auto-approve eligible'}`
    ];
    for (const capability of view.capabilities) {
        lines.push(`- ${capability.label}: ${capability.status} — ${capability.summary}`);
    }
    return lines.join('\n');
}
//# sourceMappingURL=effective-view.js.map