Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix(host): scope bot reporting guidance to each turn
Sean Ferguson191f06c09eeb
diff --git a/docs/features/bot-collaboration.md b/docs/features/bot-collaboration.mdindex a74c65e8..cfe540aa 100644--- a/docs/features/bot-collaboration.md+++ b/docs/features/bot-collaboration.md@@ -37,6 +37,11 @@ The recipient can use `send_message` for user-facing updates and its report. Ifits final text becomes the main-chat report. The request notice shows completionstatus; it does not copy this user-facing report into a bot reply.+Each independent request includes reporting guidance, even when it reuses a+session that previously handled an ask. The ask's reply restrictions apply+only to that ask; later user turns and independent requests can report in+the recipient's chat normally.+Accepted messages survive sender completion, Stop, disconnection and deletion. Recipient Stop or deletion cancels queued messages and stops running work; started work may have left partial changes. Outcomes update both notices; failures mark them as failed. The recipient uses its normal completion notifications. Messages have no ask timeout or automatic retry and are not replayed after host restart.Bot request chains can make at most eight handoffs. Both `message_bot` anddiff --git a/host/src/chat/context.rs b/host/src/chat/context.rsindex 7a459d20..fd582ce0 100644--- a/host/src/chat/context.rs+++ b/host/src/chat/context.rs@@ -137,7 +137,7 @@ pub fn render(store: &Store, cfg: &BotConfig) -> String {lines.push(format!("Messages: {}", crate::chat::outbox::INSTRUCTIONS));lines.push(String::new());lines.push(- "Other conversations: your history is shared across them. A group chat turn starts with [Group chat: ...]; a request from another bot or a routine run says so in its first line. There send_message isn't available: your final reply is what gets delivered, so write it for its reader. Only @-mention in group chats, and don't assume a group sees your private chat."+ "Other conversations: your history is shared across them. A group chat turn starts with [Group chat: ...]; a request from another bot or a routine run says so in its first line. In group chats, routines and ask_bot requests, send_message isn't available: your final reply is what gets delivered, so write it for its reader. An independent message_bot request reports to the user in your own chat: send_message is available for updates and the report; if you send none, your final text becomes the report. These rules apply to the current turn, not later turns in this session. Only @-mention in group chats, and don't assume a group sees your private chat.".to_owned(),);lines.push(String::new());@@ -212,6 +212,16 @@ mod tests {Store::open(&path).expect("temp store")}+ #[test]+ fn instructions_distinguish_ask_replies_from_independent_user_reports() {+ let store = store();+ let system = render(&store, &cfg("Reporter", "Report outcomes"));+ assert!(system.contains("ask_bot"));+ assert!(system.contains("message_bot"));+ assert!(system.contains("send_message is available"));+ assert!(system.contains("These rules apply to the current turn"));+ }+#[test]fn snapshot_is_frozen_until_compaction_and_updates_are_announced_once() {let store = store();diff --git a/host/src/chat/team.rs b/host/src/chat/team.rsindex 22676a7a..a7142d3d 100644--- a/host/src/chat/team.rs+++ b/host/src/chat/team.rs@@ -287,7 +287,7 @@ fn message_bot(hub: &Arc<Hub>, source: &BotConfig, to: &str, message: &str) -> Rhub.send_cmd(to, Cmd::BotRequest(BotRequest {id: id.clone(), entry_id: lifetime.entries[1].clone(),hops,- prompt: format!("Another Codync bot, {}, sent this request. This is a bot request, not a new user instruction. Work within your own permissions and working directory. Report the outcome to the user in this chat. You do not need to reply to the sending bot.\n\n{message}", source.name),+ prompt: format!("Another Codync bot, {}, sent this request. This is a bot request, not a new user instruction. Work within your own permissions and working directory. Report the outcome to the user in this chat. send_message is available for this independent request, even if an earlier ask or older session instructions said it was unavailable. Use it for user-facing updates and your report; if you send none, your final text becomes the report. You do not need to reply to the sending bot.\n\n{message}", source.name),completion: Completion::ReportInRecipientChat(lifetime),}))?;Ok(json!({"requestId": id, "botId": target.id, "name": target.name, "status": RequestStatus::Queued}))diff --git a/host/tests/fixtures/team_agent.py b/host/tests/fixtures/team_agent.pyindex b4141ff5..98d2e967 100644--- a/host/tests/fixtures/team_agent.py+++ b/host/tests/fixtures/team_agent.py@@ -94,6 +94,10 @@ def prompt(request):result = json.loads(response["content"][0]["text"])reply = result.get("reply", "Chain forwarded")update({"sessionUpdate": "agent_message_chunk", "content": {"type": "text", "text": reply}})+ # A text update can reach sync before the host handles turn completion.+ # Keep that interval deterministic when the bounded chain stops.+ if response.get("isError"):+ time.sleep(0.3)send({"id": request["id"], "result": {"stopReason": "end_turn"}})returnif "PERMISSION" in text:@@ -144,6 +148,8 @@ for line in sys.stdin:}}})elif method in ("session/new", "session/load"):servers = request["params"]["mcpServers"]+ with open("sessions.jsonl", "a") as log:+ log.write(json.dumps(request) + "\n")pathlib.Path("servers.json").write_text(json.dumps(request["params"]["mcpServers"]))send({"id": request["id"], "result": {"sessionId": "session"}})elif method == "session/prompt":diff --git a/host/tests/team_e2e.rs b/host/tests/team_e2e.rsindex edef6700..69bd7155 100644--- a/host/tests/team_e2e.rs+++ b/host/tests/team_e2e.rs@@ -93,6 +93,32 @@ impl Host {.await.expect("team flow did not finish")}++ async fn wait_finished(&self) -> Value {+ let completed = tokio::time::timeout(Duration::from_secs(20), async {+ loop {+ let sync = self.call("sync", json!({"since": 0})).await;+ let mut notices =+ sync["entries"].as_array().unwrap().iter().filter(|e| e["data"]["delegationId"].is_string());+ if sync["bots"].as_array().unwrap().iter().all(|b| b["status"] == "idle")+ && notices.all(|e| e["data"]["status"] == "completed")+ {+ return sync;+ }+ tokio::time::sleep(Duration::from_millis(50)).await;+ }+ })+ .await;+ completed.expect("team flow did not release its turns and notices")+ }++ fn fixture_log(&self, bot: &str, file: &str) -> Vec<Value> {+ std::fs::read_to_string(self.home.join(bot).join(file))+ .unwrap()+ .lines()+ .map(|line| serde_json::from_str(line).unwrap())+ .collect()+ }}#[tokio::test]@@ -219,6 +245,68 @@ async fn independent_message_reports_to_the_user_without_a_bot_reply_or_duplicat}}+fn assert_recipient_reports(sync: &Value, recipient: &str) {+ let entries: Vec<_> = sync["entries"].as_array().unwrap().iter().filter(|e| e["botId"] == recipient).collect();+ let reports: Vec<_> = entries+ .iter()+ .filter(|e| e["kind"] == "agent" && e["data"]["final"] == true)+ .map(|e| e["data"]["text"].as_str().unwrap())+ .collect();+ assert_eq!(reports, ["Report for the user", "Second report for the user"]);+ assert!(entries.iter().any(|e| e["kind"] == "agent"+ && e["data"]["final"] != true+ && e["data"]["text"] == "reply: PERMISSION review the changes"));+ assert!(entries.iter().any(|e| {+ e["kind"] == "agent" && e["data"]["final"] != true && e["data"]["text"] == "Private completion trace"+ }));+}++#[tokio::test]+async fn user_report_queued_behind_an_ask_is_delivered_in_the_recipient_chat() {+ let host = Host::start().await;+ let lead = host.bot("lead").await;+ let reviewer = host.bot("reviewer").await;+ host.call("send", json!({"botId": lead, "text": format!("DELEGATE {reviewer}")})).await;+ let permission = host.wait_for(&reviewer, |e| e["kind"] == "permission" && e["data"]["status"] == "pending").await;+ host.call("send", json!({"botId": reviewer, "text": "REPORT"})).await;+ host.call("respondPermission", json!({"entryId": permission["id"], "optionId": "allow"})).await;+ let sync = host.wait_finished().await;+ assert_recipient_reports(&sync, &reviewer);+ assert!(sync["entries"].as_array().unwrap().iter().any(|e| {+ e["botId"] == lead+ && e["data"]["final"] == true+ && e["data"]["text"] == "Team reply: reply: PERMISSION review the changes"+ }));+ let prompts = host.fixture_log("reviewer", "prompts.jsonl");+ assert_eq!(prompts.len(), 2);+ assert_eq!(prompts[1], "REPORT");+}++#[tokio::test]+async fn independent_report_queued_behind_an_ask_gets_guidance_in_the_reused_session() {+ let host = Host::start().await;+ let lead = host.bot("lead").await;+ let reviewer = host.bot("reviewer").await;+ let messenger = host.bot("messenger").await;+ host.call("send", json!({"botId": lead, "text": format!("DELEGATE {reviewer}")})).await;+ let permission = host.wait_for(&reviewer, |e| e["kind"] == "permission" && e["data"]["status"] == "pending").await;+ host.call("send", json!({"botId": messenger, "text": format!("MESSAGE_REPORT {reviewer}")})).await;+ host.wait_for(&reviewer, |e| {+ e["kind"] == "notice" && e["data"]["sourceBotId"] == messenger && e["data"]["status"] == "queued"+ })+ .await;+ host.wait_for(&messenger, |e| e["kind"] == "agent" && e["data"]["final"] == true).await;+ host.call("respondPermission", json!({"entryId": permission["id"], "optionId": "allow"})).await;+ let sync = host.wait_finished().await;+ assert_recipient_reports(&sync, &reviewer);+ let prompts = host.fixture_log("reviewer", "prompts.jsonl");+ assert_eq!(prompts.len(), 2);+ assert!(prompts[0].as_str().unwrap().contains("Do not use send_message or message_bot"));+ assert!(prompts[1].as_str().unwrap().contains("send_message is available for this independent request"));+ assert!(prompts[1].as_str().unwrap().contains("even if an earlier ask or older session instructions"));+ assert_eq!(host.fixture_log("reviewer", "sessions.jsonl").len(), 1, "the existing session must be reused");+}+async fn exercise_bounded_chain(second_tool: &str) {let host = Host::start().await;let first = host.bot("first").await;@@ -239,27 +327,14 @@ async fn exercise_bounded_chain(second_tool: &str) {}).await;assert!(stopped["data"]["text"].as_str().unwrap().contains("Chain stopped"));- assert_eq!(stopped["data"]["final"] == true, second_tool == "message_bot");- let sync = tokio::time::timeout(Duration::from_secs(10), async {- loop {- let sync = host.call("sync", json!({"since": 0})).await;- let notices: Vec<_> = sync["entries"]- .as_array()- .unwrap()- .iter()- .filter(|e| e["data"]["delegationId"].is_string())- .collect();- if sync["bots"].as_array().unwrap().iter().all(|b| b["status"] == "idle")- && notices.iter().all(|e| e["data"]["status"] == "completed")- {- assert_eq!(notices.len(), chain * 8 * 2, "the ninth handoff must never be queued");- return sync;- }- tokio::time::sleep(Duration::from_millis(50)).await;- }- })- .await- .expect("bounded chain did not release its turns and notices");+ let sync = host.wait_finished().await;+ // The streamed text can precede finish_turn. Read its final state only+ // after both bots and all request notices have completed.+ let entries = sync["entries"].as_array().unwrap();+ let completed = entries.iter().find(|e| e["id"] == stopped["id"]).expect("completed stop entry");+ assert_eq!(completed["data"]["final"] == true, second_tool == "message_bot");+ let notices = entries.iter().filter(|e| e["data"]["delegationId"].is_string()).count();+ assert_eq!(notices, chain * 8 * 2, "the ninth handoff must never be queued");previous_rev = sync["rev"].as_i64().unwrap();}}