rho-coding-agent 2.24.0

A fast Rust agent harness with a small footprint and opinionated defaults
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
use std::path::Path;

use agent_client_protocol::schema::v1::AvailableCommandInput;
use pretty_assertions::assert_eq;
use rho_sdk::{model::ContentBlock, UserInput};
use serde_json::json;

use super::{available_commands, resolve, CommandScope, PromptAction};
use crate::{
    agent::{AgentCapabilities, ToolCapability},
    config::Config,
    diagnostics::RuntimeDiagnostics,
    tools::{
        mcp::catalog::{McpPrompt, McpPromptArgument},
        sdk_registry::{AppToolSet, ToolSetOptions},
    },
};

/// A workspace with one prompt template, one project skill, and one
/// workflow, user definitions for a Rho and an external agent, and a session
/// that can load skills, start workflows, and write files (but not delegate).
struct Fixture {
    workspace: tempfile::TempDir,
    home: tempfile::TempDir,
    tools: AppToolSet,
    config: Config,
}

impl Fixture {
    fn new() -> Self {
        let workspace = tempfile::tempdir().unwrap();
        let prompts = workspace.path().join(".rho/prompts");
        std::fs::create_dir_all(&prompts).unwrap();
        std::fs::write(prompts.join("review.md"), "Review $1 carefully").unwrap();
        let skill = workspace.path().join(".agents/skills/acp-demo");
        std::fs::create_dir_all(&skill).unwrap();
        std::fs::write(
            skill.join("SKILL.md"),
            "---\nname: acp-demo\ndescription: Demo skill.\n---\nBody\n",
        )
        .unwrap();
        let workflows = workspace.path().join(".rho/workflows/check");
        std::fs::create_dir_all(&workflows).unwrap();
        std::fs::write(workflows.join("workflow.star"), "").unwrap();
        let home = tempfile::tempdir().unwrap();
        let agents = home.path().join(".rho/agents");
        std::fs::create_dir_all(&agents).unwrap();
        for (id, contents) in [
            (
                "acp-rho",
                "---\ndescription: Rho child\ntools: [read_file]\n---\nInspect files\n",
            ),
            (
                "acp-claude",
                "---\ndescription: Claude child\nruntime: claude-cli\ntools: [Read]\n---\nInspect files\n",
            ),
        ] {
            std::fs::write(agents.join(format!("{id}.md")), contents).unwrap();
        }
        let config = Config::default();
        let tools = AppToolSet::new(
            &config,
            RuntimeDiagnostics::new(&config),
            ToolSetOptions::new(AgentCapabilities::new(
                [
                    ToolCapability::Skill,
                    ToolCapability::Workflow,
                    ToolCapability::WriteFile,
                    ToolCapability::Edit,
                ]
                .into(),
            ))
            .workflow(crate::app::workflow_cli::workflow_tool_service(
                workspace.path().to_path_buf(),
                /*config_path*/ None,
                crate::tools::workflow_tracker::WorkflowRunTracker::new(),
            )),
        );
        tools.mcp_catalog().insert_offline_prompt(
            McpPrompt {
                server: "docs".into(),
                name: "search".into(),
                title: None,
                description: Some("Search the docs".into()),
                arguments: vec![McpPromptArgument {
                    name: "query".into(),
                    description: None,
                    required: true,
                }],
            },
            /*completions*/ false,
        );
        Self {
            workspace,
            home,
            tools,
            config,
        }
    }

    fn scope(&self) -> CommandScope<'_> {
        CommandScope {
            cwd: self.workspace.path(),
            home: Some(self.home.path()),
            tools: &self.tools,
            config: &self.config,
            permission_mode: crate::permission::PermissionMode::Supervised,
        }
    }
}

/// The parts of an action a test can predict: model text, and the skills its
/// host batch loads, in order. Call ids are random.
#[derive(Debug, PartialEq)]
enum Resolved {
    Turn {
        text: String,
        skills: Vec<String>,
    },
    Compact(Option<String>),
    Workflow {
        file: String,
        inputs: serde_json::Value,
    },
    Agent {
        id: String,
        input: UserInput,
    },
    Wake(String),
    Rejected,
}

async fn resolved(text: &str, scope: &CommandScope<'_>) -> Resolved {
    match resolve(UserInput::text(text), scope).await {
        Ok(PromptAction::Turn { input, calls }) => Resolved::Turn {
            text: match input.blocks() {
                [ContentBlock::Text(text)] => text.clone(),
                blocks => panic!("unexpected blocks {blocks:?}"),
            },
            skills: calls
                .into_iter()
                .map(|call| {
                    assert_eq!(call.name, "skill");
                    call.arguments["name"].as_str().unwrap().to_string()
                })
                .collect(),
        },
        Ok(PromptAction::Compact { instructions }) => Resolved::Compact(instructions),
        Ok(PromptAction::StartWorkflow(start)) => Resolved::Workflow {
            file: start.workflow.relative_path,
            inputs: json!(start.inputs),
        },
        Ok(PromptAction::RunAsAgent { agent_id, input }) => Resolved::Agent {
            id: agent_id,
            input,
        },
        Ok(PromptAction::AwaitWake(signal)) => Resolved::Wake(signal.token().to_owned()),
        Err(_) => Resolved::Rejected,
    }
}

fn init_prompt(workspace: &Path) -> String {
    crate::commands::init_turn::model_prompt(
        workspace,
        crate::permission::PermissionMode::Supervised,
        |_| true,
    )
    .unwrap()
}

fn turn(text: &str, skills: &[&str]) -> Resolved {
    Resolved::Turn {
        text: text.into(),
        skills: skills.iter().map(|skill| (*skill).to_owned()).collect(),
    }
}

fn workflow(inputs: serde_json::Value) -> Resolved {
    Resolved::Workflow {
        file: ".rho/workflows/check/workflow.star".into(),
        inputs,
    }
}

// Covers: each prompt shape must reach its command, and anything else the model unchanged
// Owner: acp commands
#[tokio::test]
async fn resolve_routes_prompts_to_commands() {
    let fixture = Fixture::new();
    let scope = fixture.scope();
    let cases = [
        ("compact", "/compact", Resolved::Compact(None)),
        (
            "compact with instructions",
            "/compact keep the API notes",
            Resolved::Compact(Some("keep the API notes".into())),
        ),
        (
            "init",
            "/init",
            turn(&init_prompt(fixture.workspace.path()), &["rho-init"]),
        ),
        (
            "prompt template",
            "/prompt:review src/lib.rs",
            turn("Review src/lib.rs carefully", &[]),
        ),
        (
            "template expansion loads a mentioned skill",
            "/prompt:review $acp-demo",
            turn("Review $acp-demo carefully", &["acp-demo"]),
        ),
        (
            "skill picked as a slash command",
            "/$acp-demo please",
            turn("/$acp-demo please", &["acp-demo"]),
        ),
        (
            "slash command skill batches with later mentions",
            "/$acp-demo with $rho-config and $acp-demo",
            turn(
                "/$acp-demo with $rho-config and $acp-demo",
                &["acp-demo", "rho-config"],
            ),
        ),
        (
            "skill mention",
            "use $acp-demo please",
            turn("use $acp-demo please", &["acp-demo"]),
        ),
        ("tui-only command", "/model gpt-5", Resolved::Rejected),
        (
            "mcp prompt missing arguments",
            "/mcp:docs:search",
            Resolved::Rejected,
        ),
        (
            "mcp prompt on a disconnected server",
            "/mcp:docs:search rust",
            Resolved::Rejected,
        ),
        (
            "unknown template passes through",
            "/prompt:missing x",
            turn("/prompt:missing x", &[]),
        ),
        (
            "workflow with default inputs",
            "/workflow:check",
            workflow(json!({})),
        ),
        (
            "workflow with inputs",
            r#"/workflow:check {"target": "src"}"#,
            workflow(json!({"target": "src"})),
        ),
        ("unknown workflow", "/workflow:missing", Resolved::Rejected),
        (
            "agent definition",
            "/agent:acp-rho inspect the parser",
            Resolved::Agent {
                id: "acp-rho".into(),
                input: UserInput::text("inspect the parser"),
            },
        ),
        ("agent missing task", "/agent:acp-rho", Resolved::Rejected),
        (
            "multiline delegated brief",
            "/agent:acp-rho\n\nGoal: inspect the parser.\n\nReport findings.\n",
            Resolved::Agent {
                id: "acp-rho".into(),
                input: UserInput::text("Goal: inspect the parser.\n\nReport findings."),
            },
        ),
        ("agent missing name", "/agent: inspect", Resolved::Rejected),
        (
            "unknown agent",
            "/agent:missing inspect",
            Resolved::Rejected,
        ),
        (
            "external agent",
            "/agent:acp-claude inspect",
            Resolved::Rejected,
        ),
        (
            "workflow inputs that are not an object",
            "/workflow:check src",
            Resolved::Rejected,
        ),
        (
            "path-like text passes through",
            "/usr/bin/env is odd",
            turn("/usr/bin/env is odd", &[]),
        ),
        (
            "wake watcher",
            "/rho-wake 0F4E2C3A-9B1D-4E5F-8A7B-6C5D4E3F2A1B",
            Resolved::Wake("0f4e2c3a-9b1d-4e5f-8a7b-6c5d4e3f2a1b".into()),
        ),
        (
            "wake token that could name a path",
            "/rho-wake ../config.toml",
            Resolved::Rejected,
        ),
        (
            "wake prefix of a longer word",
            "/rho-wakeup now",
            turn("/rho-wakeup now", &[]),
        ),
    ];

    for (label, text, expected) in cases {
        assert_eq!(resolved(text, &scope).await, expected, "{label}");
    }
    let plan = CommandScope {
        permission_mode: crate::permission::PermissionMode::Plan,
        ..fixture.scope()
    };
    assert_eq!(
        resolved("/workflow:check", &plan).await,
        Resolved::Rejected,
        "plan mode cannot start workflows"
    );
}

// Covers: a command must keep the images attached to its prompt
// Owner: acp commands
#[tokio::test]
async fn resolve_keeps_blocks_after_the_command() {
    let fixture = Fixture::new();
    let image = ContentBlock::Image(rho_sdk::model::ImageContent {
        mime_type: "image/png".into(),
        data: "AAAA".into(),
    });
    for (command, expected) in [
        (
            "/prompt:review this",
            PromptAction::Turn {
                input: UserInput::content(vec![
                    ContentBlock::Text("Review this carefully".into()),
                    image.clone(),
                ])
                .unwrap(),
                calls: Vec::new(),
            },
        ),
        (
            "/agent:acp-rho inspect this",
            PromptAction::RunAsAgent {
                agent_id: "acp-rho".into(),
                input: UserInput::content(vec![
                    ContentBlock::Text("inspect this".into()),
                    image.clone(),
                ])
                .unwrap(),
            },
        ),
    ] {
        let input =
            UserInput::content(vec![ContentBlock::Text(command.into()), image.clone()]).unwrap();
        assert_eq!(resolve(input, &fixture.scope()).await.unwrap(), expected);
    }
}

// Covers: the host menu must list every runnable command with its argument hint
// Owner: acp commands
#[test]
fn available_commands_list_every_command_kind() {
    let fixture = Fixture::new();

    let commands = available_commands(&fixture.scope())
        .into_iter()
        .map(|command| {
            let hint = command.input.map(|input| match input {
                AvailableCommandInput::Unstructured(input) => input.hint,
                _ => unreachable!("rho only sends unstructured input"),
            });
            json!([command.name, hint])
        })
        .collect::<Vec<_>>();

    assert_eq!(
        commands,
        [
            json!(["compact", "[instructions]"]),
            json!(["init", null]),
            json!(["prompt:review", "[$1]"]),
            json!(["mcp:docs:search", "<query>"]),
            json!(["workflow:check", "[inputs JSON]"]),
            json!(["$acp-demo", null]),
            json!(["$rho-agent-creator", null]),
            json!(["$rho-config", null]),
            json!(["$rho-init", null]),
            json!(["$rho-workflow-authoring", null]),
            json!(["agent:acp-rho", "<task>"]),
            json!(["agent:default", "<task>"]),
            json!(["agent:explorer", "<task>"]),
            json!(["agent:reviewer", "<task>"]),
            json!(["agent:worker", "<task>"]),
        ]
    );
}