rho-coding-agent 3.11.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use std::{collections::HashMap, path::PathBuf, time::Duration};

use pretty_assertions::assert_eq;
use rho_protocol::{
    AgentRuntime, Ask, ChildInfo, ChildRole, InputAsker, InputRequest, InputRequestId, JobId,
    JobKind, JobLive, JobState, JobSummary, ModelRef, SessionId,
};

use super::started_session;
use crate::tui::agent_rail::RailState;

const NOW: u64 = 1_000;

fn job(state: JobState) -> JobSummary {
    JobSummary {
        id: JobId::new("job"),
        kind: JobKind::Session,
        state,
        workspace: PathBuf::from("/work"),
        parent: Some(JobId::new("parent")),
        session: Some(SessionId::new("5054a7c5-68a7-4d13-8a3e-0f6d944aa81b")),
        run: None,
        workflow_run: None,
        result_pending: false,
        created_at: 0,
        updated_at: NOW - 4,
        error: None,
        queue: None,
        live: None,
        grant: None,
        grant_limit: None,
        worktree: None,
        worktree_stale: false,
        child: Some(ChildInfo::new(ChildRole::Started).running_as("default", AgentRuntime::Rho)),
    }
}

fn live(turn_ms: Option<u64>) -> JobLive {
    JobLive {
        title: Some("Bench the parser".into()),
        model: ModelRef {
            provider: "xai".into(),
            model: "grok-fixture".into(),
        },
        turn_elapsed_ms: turn_ms,
        usage: None,
        inputs: Vec::new(),
    }
}

// Covers: a started session's rail row says what its job is doing: queued,
// working, waiting on a person (its own request or a question its subagent
// asked), asking its parent (a question the daemon gave the session that
// started it), idle between turns, or how its turn ended; it keeps the time its
// turn ran once the turn ends, and a queued turn's time is how long it has
// waited. It is named as `/jobs` names it: by its agent unless that is the
// default, then its title, else its id; a job with no session has no row.
// Owner: daemon agent rail (pure row).
#[test]
fn a_started_sessions_row_says_what_its_job_is_doing() {
    let asked = JobLive {
        // A question its subagent asked, while its own turn runs.
        inputs: vec![InputRequest {
            id: InputRequestId(1),
            ask: Ask::Unknown,
            tool_call: None,
            timeout: None,
            asker: InputAsker::Subagent,
            subagent: None,
            told_starter: false,
        }],
        ..live(Some(9_000))
    };
    let told = JobLive {
        inputs: vec![InputRequest {
            id: InputRequestId(2),
            ask: Ask::Unknown,
            tool_call: None,
            timeout: None,
            asker: InputAsker::Turn,
            subagent: None,
            told_starter: true,
        }],
        ..live(Some(7_000))
    };
    let jobs = [
        JobSummary {
            live: Some(live(Some(12_000))),
            ..job(JobState::Running)
        },
        JobSummary {
            live: Some(asked),
            ..job(JobState::Running)
        },
        // The turn ended: the time the last list gave stays.
        job(JobState::Idle),
        job(JobState::Queued),
        JobSummary {
            child: Some(
                ChildInfo::new(ChildRole::Started)
                    .running_as("claude-cli", AgentRuntime::ClaudeCli),
            ),
            ..job(JobState::Failed)
        },
        job(JobState::Interrupted),
        JobSummary {
            live: Some(told),
            ..job(JobState::WaitingForInput)
        },
        JobSummary {
            session: None,
            ..job(JobState::Running)
        },
    ];
    let mut times = HashMap::new();
    let rows: Vec<_> = jobs
        .iter()
        .map(|job| {
            started_session(job, &mut times, NOW)
                .map(|row| (row.agent, row.title, row.state, row.elapsed))
        })
        .collect();
    let row = |agent: Option<&str>, title: &str, state, secs: Option<u64>| {
        Some((
            agent.map(str::to_owned),
            title.to_owned(),
            state,
            secs.map(Duration::from_secs),
        ))
    };

    assert_eq!(
        rows,
        [
            row(None, "Bench the parser", RailState::Working, Some(12)),
            row(None, "Bench the parser", RailState::NeedsInput, Some(9)),
            row(None, "session 5054a7c5", RailState::Idle, Some(9)),
            row(None, "session 5054a7c5", RailState::Queued, Some(4)),
            row(
                Some("Claude Code"),
                "session 5054a7c5",
                RailState::Failed,
                Some(9)
            ),
            row(None, "session 5054a7c5", RailState::Stopped, Some(9)),
            row(None, "Bench the parser", RailState::AsksParent, Some(7)),
            None,
        ]
    );
}