rho-coding-agent 3.7.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! A background process as the ACP v2 display-only terminal it shows as,
//! named by the process id: its `terminal_update` and its output.
//!
//! Output is bytes, base64-encoded (RFC 4648) one chunk at a time, as v2
//! requires: the host decodes each chunk and appends the bytes. The daemon
//! keeps each UTF-8 sequence a process writes whole across its reads, so
//! the bytes are the process's own; bytes that are not UTF-8 reach the host
//! as U+FFFD, as the daemon's chunks are text.

use std::path::Path;

use agent_client_protocol::v2::schema as v2;
use base64::{engine::general_purpose::STANDARD, Engine as _};
use rho_protocol::BackgroundWork;

/// The update that announces `work`, a process, as terminal `id`: its
/// command, the absolute directory it runs in, the capability to cancel
/// it, and, for a host that may have none of its output, the output the
/// daemon retains of it, which replaces whatever the host keeps.
pub(super) fn announcement(
    id: String,
    work: &BackgroundWork,
    workspace: &Path,
    output: Option<&str>,
) -> v2::TerminalUpdate {
    let mut update = v2::TerminalUpdate::new(id)
        .command(work.title.clone())
        .capabilities(
            v2::TerminalCapabilities::new().cancel(v2::TerminalCancelCapabilities::new()),
        );
    // v2 requires an absolute `cwd`; the daemon's workspaces are.
    if workspace.is_absolute() {
        update = update.cwd(v2::AbsolutePath::new(workspace.to_path_buf()));
    }
    if let Some(output) = output {
        update = update.output(v2::TerminalOutput::new(STANDARD.encode(output)));
    }
    update
}

/// What terminal `id`'s process wrote since the host last heard.
pub(super) fn output(id: &str, text: &str) -> v2::SessionUpdate {
    v2::SessionUpdate::TerminalOutputChunk(v2::TerminalOutputChunk::new(id, STANDARD.encode(text)))
}