rho-coding-agent 3.12.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! Bind ACP subagent runtimes (Antigravity).
//!
//! Antigravity runs as a delegated child or a daemon session's root, takes a
//! pass-through model string, and supports only Plan and Bypass, which bind
//! checks so launch never reaches spawn. A daemon session's open checks the
//! mode instead (`acp_turns`), since the session may keep another.

use crate::{
    agent::{AgentDefinition, AgentRuntime, AntigravityAgentConfig, AntigravityTool},
    antigravity_runtime::fence::AntigravityFence,
    config::Config,
    permission::PermissionMode,
    workflow::ResolvedAgent,
};

use super::{AgentInvocation, AgentRole, BoundRuntime};

pub(super) fn bind_antigravity_runtime(
    definition: &AgentDefinition,
    config: &AntigravityAgentConfig,
    invocation: &AgentInvocation,
    host_config: &Config,
) -> anyhow::Result<BoundRuntime> {
    check_delegated_pass_through(
        definition,
        AgentRuntime::Antigravity,
        config.model.as_deref(),
        invocation,
        "gemini-3.8-flash",
    )?;
    match invocation.role {
        // A daemon session's open checks the mode it runs in, which may be
        // one the session keeps rather than this one.
        AgentRole::DaemonRoot => {}
        AgentRole::Delegated
        | AgentRole::Workflow
        | AgentRole::InteractiveRoot
        | AgentRole::AutomationRoot => {
            AntigravityFence::new(host_config.permission_mode, &config.tools)
                .map_err(|error| anyhow::anyhow!("agent '{}': {error}", definition.id))?;
        }
    }
    Ok(BoundRuntime::Antigravity {
        model: config.model.clone(),
        tools: config.tools.clone(),
        permission_mode: host_config.permission_mode,
    })
}

/// A delegated or daemon session role, and no Rho `@alias` model. Parse already rejects
/// aliases; constructed configs (tests, future loaders) must not slip past.
fn check_delegated_pass_through(
    definition: &AgentDefinition,
    runtime: AgentRuntime,
    model: Option<&str>,
    invocation: &AgentInvocation,
    model_example: &str,
) -> anyhow::Result<()> {
    match invocation.role {
        AgentRole::Delegated | AgentRole::Workflow | AgentRole::DaemonRoot => {}
        AgentRole::InteractiveRoot | AgentRole::AutomationRoot => {
            anyhow::bail!(
                "agent '{}': runtime {runtime} runs through the agent tool or as a daemon session, not as an interactive or automation root",
                definition.id
            );
        }
    }
    if let Some(model) = model.filter(|model| model.starts_with('@')) {
        anyhow::bail!(
            "agent '{}': runtime {runtime} does not resolve Rho model aliases; \
set a {runtime} model name (for example {model_example}), not '{model}'",
            definition.id
        );
    }
    Ok(())
}

pub(super) fn frozen_antigravity_runtime(
    frozen: &ResolvedAgent,
    permission_mode: PermissionMode,
) -> anyhow::Result<BoundRuntime> {
    // Plans frozen for agy_acp_server recorded its own arguments and froze
    // its executable, which `agy acp` argv cannot drive.
    if frozen.arguments != crate::antigravity_runtime::executable::SERVER_ARGS {
        anyhow::bail!(
            "frozen agent '{}' was planned for the retired agy_acp_server runtime; plan the workflow again",
            frozen.agent_id
        );
    }
    let tools = frozen_tools::<AntigravityTool>(frozen)?;
    AntigravityFence::new(permission_mode, &tools)
        .map_err(|error| anyhow::anyhow!("agent '{}': {error}", frozen.agent_id))?;
    Ok(BoundRuntime::Antigravity {
        model: frozen.model.clone(),
        tools,
        permission_mode,
    })
}

/// A frozen plan's capability names in a closed tool vocabulary.
fn frozen_tools<T>(frozen: &ResolvedAgent) -> anyhow::Result<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Display,
{
    frozen
        .capabilities
        .iter()
        .map(|name| {
            name.parse::<T>()
                .map_err(|error| anyhow::anyhow!("frozen agent '{}': {error}", frozen.agent_id))
        })
        .collect()
}