{"version":3,"file":"remote-protocol.d.ts","sourceRoot":"","sources":["../../../src/core/remote-execution/remote-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,uBAAuB,GAAa,CAAC;AAElD,MAAM,MAAM,uBAAuB,GAChC,gBAAgB,GAChB,kBAAkB,GAClB,eAAe,GACf,eAAe,GACf,iBAAiB,GACjB,eAAe,GACf,aAAa,GACb,cAAc,CAAC;AAElB,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACpC,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,OAAO,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IACpD,QAAQ,EAAE,sBAAsB,CAAC;IACjC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IACnC,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,qBAAqB;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE;QACN,IAAI,EAAE,WAAW,GAAG,cAAc,GAAG,WAAW,CAAC;QACjD,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;KAChB,EAAE,CAAC;CACJ;AAED,MAAM,WAAW,mBAAmB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;CACjB;AAED,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAE5F;AAED,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAa5E","sourcesContent":["/**\n * Remote Execution — wire protocol (2.14.0).\n *\n * The control protocol over SSH/stdIO is a strict JSONL frame stream. Remote\n * application/tool stdout is relayed INSIDE frames (`REMOTE_STDOUT`/`REMOTE_STDERR`),\n * never interleaved raw on the transport, so it cannot corrupt control frames.\n *\n * Protocol version is explicit and pinned: the parent rejects a runner with an\n * incompatible version structurally (REMOTE_PROTOCOL_MISMATCH), never silently\n * misparses a changed schema.\n */\n\nexport const REMOTE_PROTOCOL_VERSION = 1 as const;\n\nexport type RemoteProtocolFrameType =\n\t| \"REMOTE_STARTED\"\n\t| \"REMOTE_HEARTBEAT\"\n\t| \"REMOTE_STDOUT\"\n\t| \"REMOTE_STDERR\"\n\t| \"REMOTE_EVIDENCE\"\n\t| \"REMOTE_RESULT\"\n\t| \"REMOTE_EXIT\"\n\t| \"REMOTE_ERROR\";\n\nexport interface RemoteLocationIdentity {\n\thost: string;\n\tuser: string;\n\tcwd: string;\n\tpid: number;\n\tplatform: string;\n}\n\nexport interface RemoteStartedPayload {\n\tprotocolVersion: number;\n\texecutionId: string;\n\tremoteTargetId: string;\n\tlaunchId: string;\n\t/** Fencing identity carried across the boundary (echoed, never an authority). */\n\tfencing?: { leaseId: string; fencingToken: number };\n\tlocation: RemoteLocationIdentity;\n\tcommand: { argv: string[]; cwd: string };\n\tstartedAtMs: number;\n}\n\nexport interface RemoteHeartbeatPayload {\n\tatMs: number;\n\telapsedMs: number;\n\talive: boolean;\n}\n\nexport interface RemoteStreamPayload {\n\tchunk: string;\n}\n\nexport interface RemoteEvidencePayload {\n\texecutionId: string;\n\t/** Remote file/process proof: host, user, path, hashes, command results. */\n\thost: string;\n\tuser: string;\n\tcwd: string;\n\titems: {\n\t\tkind: \"file_hash\" | \"command_exit\" | \"workspace\";\n\t\tpath?: string;\n\t\tsha256Before?: string;\n\t\tsha256After?: string;\n\t\tcommand?: string;\n\t\texitCode?: number;\n\t\tstdout?: string;\n\t}[];\n}\n\nexport interface RemoteResultPayload {\n\texecutionId: string;\n\tsuccess: boolean;\n\tsummary?: string;\n}\n\nexport interface RemoteExitPayload {\n\texecutionId: string;\n\texitCode: number | null;\n\tsignal?: string;\n\t/** True when the child was terminated by the controller (cancellation). */\n\tcancelled?: boolean;\n}\n\nexport interface RemoteErrorPayload {\n\tcode: string;\n\tmessage: string;\n}\n\nexport interface RemoteProtocolFrame {\n\ttype: RemoteProtocolFrameType;\n\tpayload: unknown;\n}\n\n/** Serialize one protocol frame to a single JSON line (no trailing ambiguity). */\nexport function serializeRemoteFrame(type: RemoteProtocolFrameType, payload: unknown): string {\n\treturn `${JSON.stringify({ type, payload })}\\n`;\n}\n\nexport interface ParsedRemoteFrame {\n\ttype: RemoteProtocolFrameType;\n\tpayload: Record<string, unknown>;\n}\n\n/**\n * Parse one raw line into a protocol frame. Returns `undefined` for blank or\n * non-JSON lines (e.g. stray child bytes accidentally emitted outside a frame);\n * the transport treats those as protocol noise, never as control frames.\n */\nexport function parseRemoteFrame(line: string): ParsedRemoteFrame | undefined {\n\tconst trimmed = line.trim();\n\tif (trimmed.length === 0) return undefined;\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(trimmed);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) return undefined;\n\tconst doc = parsed as Record<string, unknown>;\n\tif (typeof doc.type !== \"string\" || typeof doc.payload !== \"object\" || doc.payload === null) return undefined;\n\treturn { type: doc.type as RemoteProtocolFrameType, payload: doc.payload as Record<string, unknown> };\n}\n"]}