retach 0.10.0

Persistent terminal sessions with native scrollback passthrough
Documentation
use serde::{Deserialize, Serialize};

/// Wire protocol version. Bumped on any incompatible change to the message
/// layout. Carried in every conversation-opening client message (Connect,
/// ListSessions, KillSession) so a freshly upgraded client talking to an old
/// running daemon (or vice versa) fails loudly instead of misinterpreting frames.
pub const PROTOCOL_VERSION: u32 = 1;

/// Connection mode for Connect message.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum ConnectMode {
    /// Create or attach (Open subcommand)
    CreateOrAttach,
    /// Create only, fail if exists (New subcommand)
    CreateOnly,
    /// Attach only, fail if doesn't exist (Attach subcommand)
    AttachOnly,
}

/// Message sent from a client to the server.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub enum ClientMsg {
    /// Keyboard input from client
    Input(Vec<u8>),
    /// Terminal resized
    Resize { cols: u16, rows: u16 },
    /// Client wants to detach
    Detach,
    /// Request session list
    ListSessions { version: u32 },
    /// Create or attach to session
    Connect {
        version: u32,
        name: String,
        history: usize,
        cols: u16,
        rows: u16,
        mode: ConnectMode,
    },
    /// Kill a session
    KillSession { version: u32, name: String },
    /// Request a full screen refresh (e.g. on focus-in)
    RefreshScreen,
}

/// Message sent from the server to a client.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub enum ServerMsg {
    /// Full screen redraw (ANSI bytes)
    ScreenUpdate(Vec<u8>),
    /// Scrollback history on reattach
    History(Vec<Vec<u8>>),
    /// Session list response
    SessionList(Vec<SessionInfo>),
    /// Session ended (shell exited). `exit_code` is the child's exit status, or
    /// `None` when unknown (e.g. killed by a signal without a numeric code).
    SessionEnded { exit_code: Option<i32> },
    /// Error
    Error(String),
    /// Connected successfully
    Connected { name: String, new_session: bool },
    /// Session killed successfully
    SessionKilled { name: String },
    /// OSC passthrough (notifications, clipboard, etc.) — written directly to outer terminal
    Passthrough(Vec<u8>),
}

/// Snapshot of a session's metadata, used in list responses.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct SessionInfo {
    pub name: String,
    pub pid: u32,
    pub cols: u16,
    pub rows: u16,
}