Skip to main content

rz_cli/
bootstrap.rs

1//! Bootstrap message sent to newly spawned agents.
2
3use eyre::Result;
4
5use crate::zellij;
6
7/// Build bootstrap instructions for a newly spawned agent.
8///
9/// Includes: identity, how to communicate, who else is running.
10pub fn build(pane_id: &str, name: Option<&str>, rz_path: &str) -> Result<String> {
11    let panes = zellij::list_panes()?;
12    let identity = name.unwrap_or(pane_id);
13
14    let mut peers = String::new();
15    for p in &panes {
16        if p.is_plugin || p.pane_id() == pane_id {
17            continue;
18        }
19        let cmd = p.pane_command.as_deref().unwrap_or("shell");
20        let tab = p.tab_name.as_deref().unwrap_or("-");
21        peers.push_str(&format!("  - {} ({}, tab: {})\n", p.pane_id(), cmd, tab));
22    }
23    if peers.is_empty() {
24        peers.push_str("  (none)\n");
25    }
26
27    Ok(format!(
28        r#"## Multi-Agent Environment
29
30You are agent "{identity}" (pane: {pane_id}) in a multi-agent Zellij session.
31
32### Communication
33
34You have `rz` at `{rz_path}`. Use it to talk to other agents:
35
36```bash
37# Send a message to another agent
38{rz_path} send <pane_id> "your message"
39
40# Send raw text (no protocol envelope)
41{rz_path} send --raw <pane_id> "raw text"
42
43# List all agents
44{rz_path} list
45
46# Read another agent's scrollback
47{rz_path} dump <pane_id>
48
49# Stream another agent's output in real-time
50{rz_path} watch <pane_id>
51
52# Spawn a new agent
53{rz_path} spawn <command>
54
55# Broadcast to all agents
56{rz_path} broadcast "message"
57```
58
59### Active agents
60
61{peers}
62### Protocol
63
64When you receive a message starting with `@@RZ:` it is a protocol envelope.
65The JSON inside has `from`, `kind`, and `ts` fields. Respond by using
66`{rz_path} send <from_pane_id> "your response"`.
67
68Plain text messages (no @@RZ: prefix) are direct human-style instructions."#
69    ))
70}