rho-coding-agent 3.13.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! The children an ACP agent starts on its own, as Claude Code starts a
//! subagent with its Task tool, which a run's host records as children of
//! the run.
//!
//! Over ACP v2 the agent announces such a child on the run's connection
//! (`subagent_update`), hands it its task (`session_message`), and streams
//! its work under the child's own session id. The run renders that work
//! into a run its host records for the child, as it renders its own into
//! the run's, and ends the child's run as the child goes `idle`, or as the
//! run ends while the child still works. Rho did not start the
//! child and its conversation is the agent's: nobody prompts it, and the
//! host only shows it (`rho_protocol::ChildRole::Runtime`). Over ACP v1 an
//! agent reports no children.

use std::{path::PathBuf, sync::Arc};

use futures_util::future::BoxFuture;

use tokio::sync::watch;

use crate::{
    cli_runtime::{status_sink::RunObserver, CliPrompt},
    run_artifacts::RunArtifactIdentity,
    subagent::RunStatus,
};

/// A host that records the children a run's agent starts on its own.
///
/// Implementors must answer promptly: the run awaits them on the task that
/// reads the agent's updates, so a child's work is not read before its run
/// is recorded.
pub(crate) trait RuntimeChildren: Send + Sync {
    /// Child `child` got its task. Answers where and as what its run is
    /// recorded, which the run opens then, marks running, and ends as the
    /// child does, or why the host could not record it, which the run shows.
    fn started(&self, child: RuntimeChild) -> StartedChild<'_>;
}

/// What [`RuntimeChildren::started`] answers.
pub(crate) type StartedChild<'a> = BoxFuture<'a, Result<ChildRecord, String>>;

/// A child the agent started, as it got its task.
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct RuntimeChild {
    /// The agent's id for the child: its ACP session id, unique on the
    /// run's connection. Not a conversation anyone can resume: the agent
    /// owns it.
    pub(crate) id: String,
    /// What the agent titles it, if anything.
    pub(crate) title: Option<String>,
    /// What the agent says it is for, such as the kind of subagent.
    pub(crate) description: Option<String>,
    /// What the agent asked it to do.
    pub(crate) task: CliPrompt,
}

/// Where a child's run is recorded, as a run's own is: its status file,
/// beside which its attach journal goes, what it runs as, and who follows
/// it. The run records no session of the agent's for it: the child's
/// conversation is the agent's, which nobody resumes.
pub(crate) struct ChildRecord {
    pub(crate) output_file: PathBuf,
    /// The session the run works for, which its status names, as a
    /// subagent's does, so deleting that session deletes the run.
    pub(crate) works_for: Option<String>,
    pub(crate) identity: RunArtifactIdentity,
    pub(crate) status_tx: Option<watch::Sender<RunStatus>>,
    pub(crate) observer: Option<Box<dyn RunObserver>>,
    /// What records the children this child starts in turn, if anything.
    pub(crate) children: Option<Arc<dyn RuntimeChildren>>,
}