/**
 * Nexus Prime — Mutation Engine
 *
 * SOLE MUTATION AUTHORITY.
 * All file mutations go through this engine. No other module may
 * directly create, modify, or delete files in worktrees.
 *
 * Synapse and Architects are explicitly forbidden from calling mutation methods.
 */
import { assertGovernanceBoundary, isGovernanceLayer } from '../../engines/governance-boundary.js';
export class MutationEngine {
    repoRoot;
    artifactsRoot;
    mutations = [];
    constructor(deps) {
        this.repoRoot = deps.repoRoot;
        this.artifactsRoot = deps.artifactsRoot;
    }
    /**
     * Assert that the caller is authorized to mutate.
     * Governance layers (Synapse, Architects) must NOT call mutation methods.
     */
    static assertNotFromGovernance(caller) {
        // Use central governance boundary for consistent enforcement
        if (isGovernanceLayer(caller.toLowerCase())) {
            assertGovernanceBoundary(caller.toLowerCase(), 'worktree.mutate');
        }
    }
    /** Record a mutation (file create/modify/delete). */
    recordMutation(record, caller = 'phantom') {
        MutationEngine.assertNotFromGovernance(caller);
        this.mutations.push(record);
    }
    /** Apply mutations in a worktree. */
    async applyInWorktree(_worktreeId, _mutations, caller = 'phantom') {
        MutationEngine.assertNotFromGovernance(caller);
        // TODO: extract from SubAgentRuntime — worktree mutation logic
        return { applied: 0, errors: ['not yet implemented — skeleton module'] };
    }
    /** Rollback mutations in a worktree. */
    async rollback(_worktreeId, caller = 'phantom') {
        MutationEngine.assertNotFromGovernance(caller);
        // TODO: extract from SubAgentRuntime — rollback logic
        return { rolledBack: 0 };
    }
    /** Get all recorded mutations for a run. */
    getMutations() {
        return [...this.mutations];
    }
}
