rho-coding-agent 3.7.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use agent_client_protocol::{schema::ProtocolVersion, v1::schema as v1, v2::schema as v2};
use pretty_assertions::assert_eq;
use serde_json::json;

use super::{initialize_request, permission_request, permission_response};

// Covers: v1 Rho carries the approval's copy in the tool call title. In v2
// the subject is an upsert of the card, so leaving the copy there would
// rename the tool's card; it must move to the request's own title.
// Owner: ACP v2 boundary, permission request mapping
#[test]
fn permission_copy_moves_off_the_tool_card() {
    let request = v1::RequestPermissionRequest::new(
        "s",
        v1::ToolCallUpdate::new(
            "call-1",
            v1::ToolCallUpdateFields::new().title("Allow writing outside the workspace?"),
        ),
        vec![v1::PermissionOption::new(
            "allow-once",
            "Allow once",
            v1::PermissionOptionKind::AllowOnce,
        )],
    );
    assert_eq!(
        serde_json::to_value(permission_request(request).unwrap()).unwrap(),
        json!({
            "sessionId": "s",
            "title": "Allow writing outside the workspace?",
            "subject": {"type": "tool_call", "toolCall": {"toolCallId": "call-1"}},
            "options": [{"optionId": "allow-once", "name": "Allow once", "kind": "allow_once"}],
        })
    );
}

// Covers: notices are baseline on v2, including T3 Code, without an opt-in
// capability. Falling back to agent messages pollutes the conversation.
// Owner: ACP v2 boundary, initialize mapping
#[test]
fn v2_notices_need_no_host_opt_in() {
    for client in ["zed", "t3-code"] {
        let request = v2::InitializeRequest::new(
            ProtocolVersion::V2,
            v2::Implementation::new(client, "1.0.0"),
        );
        let session = initialize_request(&request)
            .unwrap()
            .client_capabilities
            .session
            .expect("v2 baseline session features");
        assert_eq!(
            session.notices,
            Some(v1::NoticeCapabilities::new()),
            "{client}"
        );
    }
}

// Covers: a v2 host answers `cancelled` when it dismisses or declines a
// prompt, and may answer an outcome this version doesn't know. Neither may
// approve, and neither may leave the tool waiting (v1's `cancelled`
// answers nothing): both take the prompt's rejection. A pick passes
// through.
// Owner: ACP v2 boundary, permission response mapping
#[test]
fn unanswered_permission_outcomes_reject() {
    let option = |id: &str, kind| v2::PermissionOption::new(id, id, kind);
    let approval = [
        option("allow_once", v2::PermissionOptionKind::AllowOnce),
        option("allow_always", v2::PermissionOptionKind::AllowAlways),
        option("reject_once", v2::PermissionOptionKind::RejectOnce),
    ];
    let plan = [
        option("allow_edits", v2::PermissionOptionKind::AllowAlways),
        option("supervised", v2::PermissionOptionKind::AllowOnce),
        option("keep_planning", v2::PermissionOptionKind::RejectOnce),
    ];
    let outcome = |wire| serde_json::from_value::<v2::RequestPermissionOutcome>(wire).unwrap();
    let cases = [
        (
            "cancelled approval",
            &approval[..],
            json!({"outcome": "cancelled"}),
            json!({"outcome": "selected", "optionId": "reject_once"}),
        ),
        (
            "unknown outcome",
            &approval[..],
            json!({"outcome": "_tck_unknown"}),
            json!({"outcome": "selected", "optionId": "reject_once"}),
        ),
        (
            "cancelled plan approval",
            &plan[..],
            json!({"outcome": "cancelled"}),
            json!({"outcome": "selected", "optionId": "keep_planning"}),
        ),
        (
            "a pick",
            &approval[..],
            json!({"outcome": "selected", "optionId": "allow_once"}),
            json!({"outcome": "selected", "optionId": "allow_once"}),
        ),
        (
            "no reject offered",
            &approval[..2],
            json!({"outcome": "cancelled"}),
            json!({"outcome": "cancelled"}),
        ),
    ];
    for (label, offered, answered, expected) in cases {
        let response = v2::RequestPermissionResponse::new(outcome(answered));
        assert_eq!(
            serde_json::to_value(permission_response(response, offered).outcome).unwrap(),
            expected,
            "{label}"
        );
    }
}