gent-link 0.2.24

Connect Codex and Claude Code chats across machines with the Gent CLI and desktop companion.
//! One private JSON line per supervisor operation. Only the trusted shell can submit UI actions.
use serde_json::Value;
use std::io::{self, Write};

pub(crate) fn write(value: &Value) -> io::Result<()> {
    let mut out = io::stdout().lock();
    serde_json::to_writer(&mut out, value)?;
    out.write_all(b"\n")?;
    out.flush()
}

pub(crate) fn line(text: &str) -> io::Result<()> {
    let mut out = io::stdout().lock();
    writeln!(out, "{text}")?;
    out.flush()
}

pub(crate) fn send(value: &Value) -> Result<(), &'static str> {
    let result = match value {
        Value::String(line_value)
            if matches!(
                line_value.as_str(),
                "refresh" | "start" | "stop" | "restart"
            ) =>
        {
            line(line_value)
        }
        Value::Object(_)
            if value["op"]
                .as_str()
                .is_some_and(|op| !op.starts_with("notification_") && op != "save_tray_size") =>
        {
            write(value)
        }
        _ => return Err("Unknown supervisor operation"),
    };
    result.map_err(|_| "Supervisor disconnected")
}