/** * The message format the HQ desktop app and the box session host speak. * * One JSON object per line, in both directions. The app sends hello, list, * start, attach, detach, input, end and ping; the host answers with welcome, * sessions, started, attached, frame, truncated, log, exited, pong and error. * * Everything the app sends is validated here before the host acts on it. The * rule that matters most: the host builds `claude`'s argument list itself, from * checked fields, so no value the app sends can turn into an extra flag. A * value that starts with "-" is refused outright. */ import type { SessionSummary, SessionOutbound } from "./session-host-sessions.js"; export declare const SESSION_HOST_PROTOCOL_VERSION = 1; /** * The loopback port the host listens on, and the desktop app forwards to. Fixed * so the Mac side needs no discovery step: it opens the Outpost port-forward to * this port and dials the local end. */ export declare const DEFAULT_SESSION_HOST_PORT = 47821; /** A Cognito ID token is ~1–2 KB; this leaves generous room without inviting a flood. */ export declare const MAX_TOKEN_BYTES: number; export type PermissionMode = "default" | "acceptEdits" | "plan" | "bypassPermissions"; export interface HelloMessage { t: "hello"; v: number; token: string; client?: string; } export interface ListMessage { t: "list"; id: string; } export interface StartMessage { t: "start"; id: string; permissionMode: PermissionMode; cwd?: string; sessionId?: string; resume?: string; model?: string; effort?: string; thinkingDisplay?: string; } export interface AttachMessage { t: "attach"; id: string; session: string; sinceSeq: number; } export interface DetachMessage { t: "detach"; session: string; } export interface InputMessage { t: "input"; session: string; frame: Record; } export interface EndMessage { t: "end"; session: string; } export interface PingMessage { t: "ping"; id?: string; } export type ClientMessage = HelloMessage | ListMessage | StartMessage | AttachMessage | DetachMessage | InputMessage | EndMessage | PingMessage; export type ParseFailureCode = "bad-json" | "bad-message" | "bad-request"; export type ParseResult = { ok: true; message: ClientMessage; } | { ok: false; code: ParseFailureCode; message: string; id?: string; }; export type ServerErrorCode = ParseFailureCode | "bad-hello" | "unsupported-version" | "unauthorized" | "line-too-long" | "unknown-session" | "session-exited" | "session-busy" | "too-many-sessions" | "bad-cwd" | "spawn-failed" | "shutting-down" | "internal"; export type ServerMessage = { t: "welcome"; v: number; host: string; version: string; } | { t: "sessions"; id: string; sessions: SessionSummary[]; } | { t: "started"; id: string; session: string; claudeSessionId: string; } | { t: "attached"; id: string; session: string; lastSeq: number; } | { t: "pong"; id?: string; } | { t: "error"; code: ServerErrorCode; message: string; id?: string; session?: string; } | SessionOutbound; /** * Validate one line from the desktop app. * * `bad-json` means the line was not a JSON object at all — which is also how a * browser's `GET / HTTP/1.1` lands here. `bad-message` is an unknown command, * and `bad-request` is a known command with a field the host will not accept. */ export declare function parseClientMessage(line: string): ParseResult; export interface ClaudeArgsSpec { permissionMode: PermissionMode; sessionId?: string; resume?: string; model?: string; effort?: string; thinkingDisplay?: string; } /** * Build `claude`'s arguments for one session. * * These are the desktop app's own flags for a local session (see the Mac side's * `build_args`), so a box session behaves exactly like one started on the Mac: * stream-json in and out, partial messages on, and tool approvals routed over * stdio instead of a terminal prompt. A fresh run pins the id we minted; a * resume adopts the CLI's own id — the CLI rejects both together. */ export declare function buildClaudeArgs(spec: ClaudeArgsSpec): string[]; /** One server message as a single line, newline included. */ export declare function encodeServerMessage(message: ServerMessage): string; //# sourceMappingURL=session-host-protocol.d.ts.map