Skip to main content

rz_cli/
bootstrap.rs

1//! Bootstrap message sent to newly spawned agents.
2
3use eyre::Result;
4
5/// Build bootstrap instructions for a multiplexer agent.
6pub fn build(surface_id: &str, name: Option<&str>, backend: &dyn crate::backend::Backend) -> Result<String> {
7    let identity = name.unwrap_or(surface_id);
8
9    let mut peers = String::new();
10    for p in backend.list_panes()? {
11        if p.is_plugin || p.id == surface_id {
12            continue;
13        }
14        let label = if p.title.is_empty() { &p.id } else { &p.title };
15        peers.push_str(&format!("  - {label}\n"));
16    }
17
18    build_common(identity, &peers)
19}
20
21/// Build bootstrap for a PTY agent (no multiplexer).
22pub fn build_pty(name: &str) -> Result<String> {
23    let mut peers = String::new();
24    if let Ok(agents) = crate::registry::list_all() {
25        for a in &agents {
26            if a.name != name {
27                peers.push_str(&format!("  - {}\n", a.name));
28            }
29        }
30    }
31
32    build_common(name, &peers)
33}
34
35fn build_common(identity: &str, peers: &str) -> Result<String> {
36    let peer_list = if peers.is_empty() { "  (none)\n" } else { peers };
37
38    Ok(format!(
39        r#"You are agent "{identity}".
40
41Peers:
42{peer_list}
43## rz commands
44rz send <name> "msg"   — message an agent
45rz send lead "DONE: <summary>"  — report completion
46rz run --name <n> claude --dangerously-skip-permissions  — spawn agent
47rz ps                  — list agents
48rz logs <name>         — read agent output
49
50Messages from other agents arrive as @@RZ: JSON in your input.
51
52## Rules
531. Do the task. Report: rz send lead "DONE: <what you did>"
542. If stuck: rz send lead "BLOCKED: <issue>"
553. Stay running after reporting — wait for next task.
564. Only do what is asked. Do not explore unrelated code.
575. Do not read rz source code — use the commands above."#
58    ))
59}