/**
 * Runtime - Execute user code with shimmed Node.js globals
 *
 * ESM to CJS transformation is now handled during npm install by transform.ts
 * using esbuild-wasm. This runtime just executes the pre-transformed CJS code.
 */
import { VirtualFS } from './virtual-fs';
import type { IExecuteResult } from './runtime-interface';
import { Process } from './shims/process';
import * as childProcessShim from './shims/child_process';
import { type ModuleFormat } from './module-resolution';
import type { NetworkController, NetworkOptions } from './network/types';
export interface Module {
    id: string;
    filename: string;
    url: string;
    format: ModuleFormat;
    exports: unknown;
    namespace?: Record<string, unknown>;
    loaded: boolean;
    children: Module[];
    paths: string[];
    executionPromise?: Promise<unknown>;
}
export interface RuntimeOptions {
    cwd?: string;
    env?: Record<string, string>;
    onConsole?: (method: string, args: unknown[]) => void;
    onStdout?: (data: string) => void;
    onStderr?: (data: string) => void;
    childProcessController?: childProcessShim.ChildProcessController;
    builtinModules?: Record<string, unknown>;
    network?: NetworkOptions;
    networkController?: NetworkController;
    /**
     * Owning container id (ContainerInstance.id). Servers created through
     * this runtime's http/https modules carry it as their owner, so port
     * conflicts, server-ready routing, and dispose cleanup attribute raw
     * `http.listen` servers to the right container without consulting
     * last-write-wins ambient globals.
     */
    ownerId?: string;
}
export interface RequireFunction {
    (id: string): unknown;
    resolve: (id: string) => string;
    cache: Record<string, Module>;
}
type TimerTrackingOwner = {
    registerPendingTimer: (handle: AlmostNodeTimerHandle) => void;
    unregisterPendingTimer: (handle: AlmostNodeTimerHandle) => void;
    setPendingTimerRef: (handle: AlmostNodeTimerHandle, refed: boolean) => void;
};
type AlmostNodeTimerHandle = {
    _id: unknown;
    __almostnodeRefed: boolean;
    __almostnodeTimerOwner: TimerTrackingOwner | null;
    ref: () => AlmostNodeTimerHandle;
    unref: () => AlmostNodeTimerHandle;
    hasRef: () => boolean;
    refresh: () => AlmostNodeTimerHandle;
    [Symbol.toPrimitive]: () => number;
};
/**
 * Runtime class for executing code in virtual environment
 * Note: This class has sync methods for backward compatibility.
 * Use createRuntime() factory for IRuntime interface compliance.
 */
export declare class Runtime {
    private vfs;
    private fsShim;
    private electronShim;
    private process;
    private runtimeGlobalObject;
    private runtimeId;
    private pendingRefedTimers;
    private moduleCache;
    private builtinModules;
    private formatDetector;
    private moduleLoader;
    private options;
    private networkController;
    private readonly explicitEnvKeys;
    private projectedNetworkEnv;
    /** Cache for pre-processed code (after ESM transform) before eval */
    private processedCodeCache;
    /** Shared resolver caches to avoid per-module duplication and exception churn */
    private resolverCaches;
    constructor(vfs: VirtualFS, options?: RuntimeOptions);
    registerPendingTimer: (handle: AlmostNodeTimerHandle) => void;
    unregisterPendingTimer: (handle: AlmostNodeTimerHandle) => void;
    setPendingTimerRef: (handle: AlmostNodeTimerHandle, refed: boolean) => void;
    hasPendingRefedTimers(): boolean;
    private withTimerOwner;
    private withTimerOwnerAsync;
    /**
     * Set up a polyfilled TextDecoder that handles binary encodings
     */
    private setupTextDecoderPolyfill;
    /**
     * Polyfill V8's Error.captureStackTrace and Error.prepareStackTrace for Safari/WebKit.
     * Express's `depd` and other npm packages use these V8-specific APIs which don't
     * exist in Safari, causing "callSite.getFileName is not a function" errors.
     */
    private setupStackTracePolyfill;
    private createModuleRecord;
    private createLegacyRequire;
    private buildExecuteResult;
    private requireCommonJsModule;
    importModule(specifier: string, fromPath?: string): Promise<IExecuteResult>;
    /**
     * Execute code as a module.
     */
    execute(code: string, filename?: string): Promise<IExecuteResult>;
    /**
     * Execute code as a module (async version for IRuntime interface)
     * Alias: executeSync() is the same as execute() for backward compatibility
     */
    executeSync: (code: string, filename?: string) => {
        exports: unknown;
        module: Module;
    };
    /**
     * Execute code as a module (async - for IRuntime interface)
     */
    executeAsync(code: string, filename?: string): Promise<IExecuteResult>;
    /**
     * Run a file from the virtual file system.
     */
    runFile(filename: string): Promise<IExecuteResult>;
    /**
     * Alias for runFile (backward compatibility)
     */
    runFileSync: (filename: string) => {
        exports: unknown;
        module: Module;
    };
    /**
     * Run a file from the virtual file system (async - for IRuntime interface)
     */
    runFileAsync(filename: string): Promise<IExecuteResult>;
    loadModule(filename: string): Module;
    registerBuiltinModule(name: string, moduleExports: unknown): void;
    /**
     * Clear the module cache
     */
    clearCache(): void;
    /**
     * Get the virtual file system
     */
    getVFS(): VirtualFS;
    /**
     * Get the process object
     */
    getProcess(): Process;
    /**
     * A named builtin module instance owned by this runtime (e.g. 'electron' —
     * used by the app orchestrator to observe the shim's app lifecycle).
     */
    getBuiltin(name: string): unknown;
    getNetwork(): NetworkController;
    private applyNetworkPolicy;
    /**
     * Create a REPL context that evaluates expressions and persists state.
     *
     * Returns an object with an `eval` method that:
     * - Returns the value of the last expression (unlike `execute` which returns module.exports)
     * - Persists variables between calls (`var x = 1` then `x` works)
     * - Has access to `require`, `console`, `process`, `Buffer` (same as execute)
     *
     * Security: The eval runs inside a Generator's local scope via direct eval,
     * NOT in the global scope. Only the runtime's own require/console/process are
     * exposed — the same sandbox boundary as execute(). Variables created in the
     * REPL are confined to the generator's closure and cannot leak to the page.
     *
     * Note: `const`/`let` are transformed to `var` so they persist across calls
     * (var hoists to the generator's function scope, const/let are block-scoped
     * to each eval call and would be lost).
     */
    createREPL(): {
        eval: (code: string) => Promise<unknown>;
    };
}
/**
 * Create and execute code in a new runtime.
 */
export declare function execute(code: string, vfs: VirtualFS, options?: RuntimeOptions): Promise<IExecuteResult>;
export type { IRuntime, IExecuteResult, IRuntimeOptions } from './runtime-interface';
export default Runtime;
//# sourceMappingURL=runtime.d.ts.map