/**
 * Nexus Prime — Governance Boundary Enforcement
 *
 * Central module that enforces the separation between governance layers
 * (Synapse, Architects) and execution layers (Phantom, MutationEngine).
 *
 * Rule: Governance layers may coordinate, decompose, and observe — but
 * NEVER directly mutate source code in worktrees. All mutations flow
 * through Phantom's MutationEngine.
 */
/** Operations that governance layers are forbidden from performing. */
const FORBIDDEN_OPERATIONS = new Set([
    'worktree.create',
    'worktree.delete',
    'worktree.mutate',
    'file.write',
    'file.delete',
    'file.create',
    'git.commit',
    'git.merge',
    'git.push',
    'git.reset',
]);
/** Operations that governance layers ARE allowed to perform. */
const ALLOWED_GOVERNANCE_OPERATIONS = new Set([
    'git.rev-parse',
    'git.log',
    'git.status',
    'git.branch-list',
    'db.read',
    'db.write',
    'ledger.write',
    'event.emit',
    'worktree.health-check',
]);
const violations = [];
/**
 * Assert that a caller is authorized for a given operation.
 * Throws if a governance layer attempts a forbidden operation.
 */
export function assertGovernanceBoundary(caller, operation) {
    if (caller === 'synapse' || caller === 'architects') {
        if (FORBIDDEN_OPERATIONS.has(operation)) {
            const violation = {
                caller,
                operation,
                timestamp: Date.now(),
                message: `Governance layer "${caller}" attempted forbidden operation "${operation}". Only Phantom execution modules may perform mutations.`,
            };
            violations.push(violation);
            throw new Error(`[GovernanceBoundary] ${violation.message}`);
        }
    }
}
/**
 * Check whether a caller is a governance layer.
 */
export function isGovernanceLayer(caller) {
    return caller === 'synapse' || caller === 'architects';
}
/**
 * Check whether an operation is allowed for governance layers.
 */
export function isAllowedGovernanceOperation(operation) {
    return ALLOWED_GOVERNANCE_OPERATIONS.has(operation);
}
/**
 * Get all recorded boundary violations (for dashboard trust surface).
 */
export function getBoundaryViolations() {
    return [...violations];
}
/**
 * Clear violations log (after acknowledged by operator).
 */
export function clearBoundaryViolations() {
    violations.length = 0;
}
