/**
 * Debugger Bridge for Ag-Bash.
 *
 * Provides interactive execution control for shell scripts.
 */
export class DebuggerBridge {
    breakpoints = new Set();
    paused = false;
    stepRequested = false;
    /**
     * Registers a breakpoint at a specific line.
     */
    setBreakpoint(line) {
        this.breakpoints.add(line);
    }
    /**
     * Removes a breakpoint.
     */
    clearBreakpoint(line) {
        this.breakpoints.delete(line);
    }
    /**
     * Called by the interpreter at each statement boundary.
     * If a breakpoint is hit or a step is active, pauses execution.
     */
    async onBeforeStatement(node, _state) {
        const currentLine = node.line ?? 0;
        if (this.breakpoints.has(currentLine) || this.stepRequested) {
            this.paused = true;
            this.stepRequested = false;
            await this.waitForResume();
        }
    }
    /**
     * Resumes execution until the next breakpoint.
     */
    continue() {
        this.paused = false;
    }
    /**
     * Executes only the next statement.
     */
    step() {
        this.stepRequested = true;
        this.paused = false;
    }
    /**
     * Internal loop to block execution while paused.
     */
    async waitForResume() {
        while (this.paused) {
            // In a real implementation, this would yield to an event loop
            // or wait for a specific signal/promise resolve.
            await new Promise((resolve) => setTimeout(resolve, 100));
        }
    }
    /**
     * Returns current execution context for inspection.
     */
    getInspectState(state) {
        return {
            cwd: state.cwd,
            env: Object.assign(Object.create(null), Object.fromEntries(state.env)),
            localScopes: state.localScopes.map((s) => Object.assign(Object.create(null), Object.fromEntries(s))),
            lastExitCode: state.lastExitCode,
        };
    }
}
