// Mirror of `maestro-protocol` JSON shapes. Keep in sync with // crates/maestro-protocol/src/lib.rs. export type Uuid = string; export type IsoTimestamp = string; export type SessionStatus = "Running" | "Dead"; export interface Session { id: Uuid; daemon_id: string; cwd: string; command: string; env: Record; metadata: Record; status: SessionStatus; created_at: IsoTimestamp; } export interface DaemonInfo { daemon_id: string; hostname: string; version: string; daemon_url: string; } export interface WorktreeSpec { base_repo: string; branch: string; cleanup_on_kill?: boolean; } export interface CreateSessionRequest { daemon_id: string; cwd: string; command: string; env?: Record; metadata?: Record; worktree?: WorktreeSpec; } export type RegistryEvent = | { type: "Snapshot"; daemons: DaemonInfo[]; sessions: Session[]; } | { type: "DaemonAdded"; daemon: DaemonInfo } | { type: "DaemonRemoved"; daemon_id: string } | { type: "SessionAdded"; session: Session } | { type: "SessionRemoved"; daemon_id: string; id: Uuid } | { type: "SessionUpdated"; session: Session } | { type: "Lagged"; skipped: number }; export type ClientControl = | { type: "Resize"; cols: number; rows: number } | { type: "Ping" } | { type: "Pong" } | { type: "Error"; code: string; message: string }; export interface ApiError { error: { code: string; message: string }; } export function sessionName(s: Session): string { const meta = s.metadata as Record; const name = meta?.name; if (typeof name === "string" && name.length > 0) return name; return s.command; } export function sessionLabel(s: Session): string | undefined { const meta = s.metadata as Record; const label = meta?.label; return typeof label === "string" ? label : undefined; }