/** * Main thread bridge handler * * Runs on the main thread and processes filesystem, I/O, HTTP, and exec * requests from a worker thread via SharedArrayBuffer + Atomics. */ import type { IFileSystem } from "../../fs/interface.js"; import type { SecureFetch } from "../../network/fetch.js"; import type { CommandExecOptions, ExecResult } from "../../types.js"; export interface BridgeOutput { stdout: string; stderr: string; exitCode: number; } /** * Handles requests from a worker thread. */ export declare class BridgeHandler { private fs; private cwd; private commandName; private secureFetch; private maxOutputSize; private exec; private protocol; private running; private output; private outputLimitExceeded; private startTime; private timeoutMs; private writeAccumulator; private readCache; constructor(sharedBuffer: SharedArrayBuffer, fs: IFileSystem, cwd: string, commandName: string, secureFetch?: SecureFetch | undefined, maxOutputSize?: number, exec?: ((command: string, options: CommandExecOptions) => Promise) | undefined); /** * Returns remaining milliseconds before the overall execution deadline. */ private remainingMs; /** * Races a promise against the remaining execution deadline. * If the deadline expires first, sets `this.running = false` and rejects. */ private raceDeadline; /** * Run the handler loop until EXIT operation or timeout. */ run(timeoutMs: number): Promise; stop(): void; /** * Returns current captured output. */ getOutput(): BridgeOutput; private handleOperation; private resolvePath; private handleReadFile; /** * Accumulate a chunked write/append payload. Returns the fully-assembled * buffer when the final chunk arrives, or null if more chunks are expected * (in which case SUCCESS has already been set). Throws on protocol abuse. */ private accumulateChunkedPayload; private handleWriteFile; private handleStat; private handleLstat; private handleReaddir; private handleMkdir; private handleRm; private handleExists; private handleAppendFile; private handleSymlink; private handleReadlink; private handleChmod; private handleRealpath; private handleRename; private handleCopyFile; private handleWriteStdout; private handleWriteStderr; private handleExit; private tryAppendOutput; private appendOutputLimitError; private handleHttpRequest; private handleExecCommand; private setErrorFromException; }