// Shared message types between main thread and session worker. export interface InitMessage { type: "init"; sessionId: string; cwd: string; initialFiles: Record; capabilities: { network: boolean; python: boolean; javascript: boolean; }; networkConfig?: { dangerouslyAllowFullInternetAccess: boolean; allowedUrlPrefixes: string[]; allowedMethods: string[]; }; executionLimits: { maxCallDepth: number; maxCommandCount: number; maxLoopIterations: number; maxAwkIterations: number; maxSedIterations: number; }; maxSessionFsBytes: number; maxSingleFileBytes: number; maxWriteBatchBytes: number; maxReadBytesPerCall: number; maxCapturedOutputBytesExec: number; } export interface ExecRequest { type: "exec"; requestId: string; execId: string; script: string; stdin?: string; cwd?: string; env?: Record; replaceEnv?: boolean; timeoutMs: number; maxStdoutBytes: number; maxStderrBytes: number; } export interface AbortRequest { type: "abort"; requestId: string; } export interface FilesWriteRequest { type: "files_write"; requestId: string; files: Array<{ path: string; content: string; encoding: "utf8" | "base64"; }>; overwrite: boolean; createDirs: boolean; } export interface FilesReadRequest { type: "files_read"; requestId: string; path: string; offset: number; maxBytes: number; encoding: "utf8" | "base64" | "auto"; } export interface FilesListRequest { type: "files_list"; requestId: string; path: string; recursive: boolean; glob?: string; maxEntries: number; cursor?: string; } export interface FsBytesRequest { type: "fs_bytes"; requestId: string; } export type ParentMessage = | InitMessage | ExecRequest | AbortRequest | FilesWriteRequest | FilesReadRequest | FilesListRequest | FsBytesRequest; export interface ReadyMessage { type: "ready"; } export interface ExecResult { type: "exec_result"; requestId: string; execId: string; exitCode: number; stdout: string; stderr: string; durationMs: number; timedOut: boolean; truncatedStdout: boolean; truncatedStderr: boolean; // Total captured byte counts for resource link bookkeeping (>= embedded length). capturedStdoutBytes: number; capturedStderrBytes: number; // Optional retained full bytes when above the embed cap (capped by maxCapturedOutputBytesExec). retainedStdout?: string; retainedStderr?: string; commands: string[]; sessionFsBytes: number; } export interface FilesWriteResult { type: "files_write_result"; requestId: string; written: Array<{ path: string; bytes: number }>; sessionFsBytes: number; } export interface FilesReadResult { type: "files_read_result"; requestId: string; path: string; content: string; encoding: "utf8" | "base64"; bytesRead: number; nextOffset: number | null; } export interface FilesListEntry { path: string; type: "file" | "directory" | "symlink"; bytes?: number; } export interface FilesListResult { type: "files_list_result"; requestId: string; entries: FilesListEntry[]; nextCursor: string | null; } export interface FsBytesResult { type: "fs_bytes_result"; requestId: string; sessionFsBytes: number; } export interface ErrorResult { type: "error_result"; requestId: string; code: string; message: string; } export type WorkerMessage = | ReadyMessage | ExecResult | FilesWriteResult | FilesReadResult | FilesListResult | FsBytesResult | ErrorResult;