rho-coding-agent 3.13.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use pretty_assertions::assert_eq;
use rho_protocol::{ModelRef, PermissionMode as WireMode};
use tokio::sync::mpsc;

use super::{ChildEvent, ExternalRun, ExternalRunFeed};
use crate::{
    agent::AgentRuntime,
    cli_runtime::status_sink::RunObserver,
    permission::PermissionMode,
    run_artifacts::{AttachmentEvent, RunArtifactIdentity},
    session::{SessionOrigin, SessionPersistence},
};

// Covers: an external run's feed opens its session once, before the
// session's first event, as the agent with the model and mode it was bound
// with; an agent that pins no model shows its runtime's default.
#[test]
fn an_external_runs_session_opens_once_with_its_binding() {
    let told = |model: Option<&str>| {
        let identity = RunArtifactIdentity {
            agent_id: "worker".into(),
            agent_fingerprint: "fingerprint".into(),
            provider: "antigravity".into(),
            model: model.map(str::to_owned),
            runtime: AgentRuntime::Antigravity,
            reasoning: None,
        };
        let (events, mut told) = mpsc::unbounded_channel();
        let mut feed = ExternalRunFeed::new(
            events,
            &identity,
            PermissionMode::AllowEdits,
            /*file*/ None,
        );
        feed.recorded(&AttachmentEvent::Prompt("Go.".into()));
        feed.recorded(&AttachmentEvent::Notice("acp: note".into()));
        std::iter::from_fn(|| told.try_recv().ok())
            .map(|event| match event {
                ChildEvent::Opened { options, agent, .. } => Some((
                    agent,
                    options.model.current,
                    options.permission_mode.current,
                )),
                ChildEvent::Session(_) | ChildEvent::RuntimeChild(_) => None,
            })
            .collect::<Vec<_>>()
    };
    let opened = |model: &str| {
        Some((
            "worker".to_owned(),
            ModelRef {
                provider: "antigravity".into(),
                model: model.into(),
            },
            WireMode::AllowEdits,
        ))
    };

    assert_eq!(
        [told(Some("gemini-3.8-flash")), told(None)],
        [
            vec![opened("gemini-3.8-flash"), None, None],
            vec![opened("default"), None, None],
        ]
    );
}

// Covers: a run whose session file could not be created, here for a
// status outside the rho home, which no header may name, says so in its
// session once it opens, after its prompt, so a client learns it will not
// replay once the run ends.
#[test]
fn an_unsaved_runs_session_says_so_once_it_opens() {
    let identity = RunArtifactIdentity {
        agent_id: "worker".into(),
        agent_fingerprint: "fingerprint".into(),
        provider: "antigravity".into(),
        model: None,
        runtime: AgentRuntime::Antigravity,
        reasoning: None,
    };
    let (events, mut told) = mpsc::unbounded_channel();
    let run = ExternalRun {
        events,
        session: rho_sdk::SessionId::new(),
        cwd: std::env::temp_dir(),
        provenance: SessionOrigin::Subagent.into(),
        run: "abc123".into(),
        status: std::path::PathBuf::from("/nowhere/abc123/result.json"),
        prompt: "Go.".into(),
        persistence: SessionPersistence::Saved,
    };
    let mut observer = run.observer(&identity, PermissionMode::Bypass);
    observer.recorded(&AttachmentEvent::Prompt("Go.".into()));
    observer.recorded(&AttachmentEvent::AssistantTextDelta("Done.".into()));

    let kinds: Vec<_> = std::iter::from_fn(|| told.try_recv().ok())
        .map(|event| match event {
            ChildEvent::Opened { .. } => "opened",
            ChildEvent::Session(rho_protocol::SessionEvent::UserMessage { .. }) => "prompt",
            ChildEvent::Session(rho_protocol::SessionEvent::Notice { .. }) => "notice",
            ChildEvent::Session(_) | ChildEvent::RuntimeChild(_) => "other",
        })
        .collect();
    assert_eq!(kinds, ["opened", "prompt", "notice", "other"]);
}