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): keep bot replies out of user chats
Sean Fergusonf1e738bb076d
diff --git a/docs/features/bot-collaboration.md b/docs/features/bot-collaboration.mdindex 738eac4e..a74c65e8 100644--- a/docs/features/bot-collaboration.md+++ b/docs/features/bot-collaboration.md@@ -12,6 +12,9 @@ The host records the request and its outcome in both chats using existing notice- Each bot still owns an ACP process with main/reply-thread sessions and runs one turn at a time. A busy recipient queues the request. Different bots can work concurrently.- Requests have their own reply channel and never merge with user messages or another request. Contiguous user messages keep the existing batching behavior.+- An ask's final reply is addressed to the requesting bot. It appears in the request notice+ and the recipient's trace, without a second bubble in the recipient's main chat. The recipient+ returns the answer directly rather than sending another `message_bot` request back.- The recipient uses its own folder, tools, memory and permission policy. Permission cards appear in its chat. The requesting bot's entire transcript is not copied; only the request is passed. Requests are not treated as user facts by the memory keeper.- The host rejects self-delegation, duplicate outstanding requests to the same recipient, and direct or indirect wait cycles, including queued requests. Up to 64 requests can be outstanding host-wide.- Native Claude Code/Codex subagents remain managed by the harness. Codync does not turn them into permanent bots or override their delegation settings.@@ -30,6 +33,10 @@ The host records the request and its outcome in both chats using existing notice`message_bot(botId, message)` queues a bot request and returns immediately, without waiting for a reply. The recipient reports to you in its own chat. Messages use the same queue as asks, run one turn at a time, and never merge with user messages or other requests. Both chats show bot-attributed notices rather than user messages. Up to 64 messages can be outstanding host-wide, with at most 16 from any one sender, separately from asks. Queued and running messages both count. A slot is freed when the recipient finishes, fails or cancels the request, or admission fails. Stopping, restarting or deleting the sender does not free slots for its already accepted messages.+The recipient can use `send_message` for user-facing updates and its report. If it sends none,+its final text becomes the main-chat report. The request notice shows completion+status; it does not copy this user-facing report into a bot reply.+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/docs/features/chat-messages.md b/docs/features/chat-messages.mdindex f39f445a..bf1314bc 100644--- a/docs/features/chat-messages.md+++ b/docs/features/chat-messages.md@@ -13,6 +13,10 @@ How a bot's work turns into what the user reads, copied from Grok Bot.the old rule: its last text becomes the turn's final message.- Group room turns, `ask_bot` requests and routines reject `send_message`: their reply is theturn's last text, as before (`chat/group.rs`, `chat/team.rs`, `routines`).+- An `ask_bot` reply stays in the recipient's trace and the request notice; it does+ not also become a message to the user. The requesting bot uses it to answer the user.+ Independent `message_bot` turns report to the user in the recipient's main chat, through+ `send_message` or the final-text fallback, and do not add that report to the request notice.- The rules reach the agent twice: the MCP server's instructions, and the frozen instructionsnapshot (`chat/context.rs`).- Clients never stream text into a bubble: the chat shows user messages, `final` agent entries,diff --git a/host/src/agent/bot/turn.rs b/host/src/agent/bot/turn.rsindex 3735ebc3..17077f92 100644--- a/host/src/agent/bot/turn.rs+++ b/host/src/agent/bot/turn.rs@@ -169,6 +169,7 @@ impl Actor {let mut final_text = None;let routine = self.active_routine.is_some();let grouped = self.active_group.is_some() || routine;+ let delegated = self.active_request.as_ref().is_some_and(crate::chat::team::BotRequest::expects_reply);let sent = std::mem::take(&mut self.sent);if !sent.is_empty() {// The bot talked through send_message: what it wrote as its reply stays in the trace.@@ -181,8 +182,12 @@ impl Actor {let text = e.data["text"].as_str().map(str::to_owned);// A pass in a room stays in the trace; the room doesn't see it.if !(grouped && text.as_deref().is_none_or(crate::chat::group::is_pass)) {- e.data["final"] = true.into();- self.hub.set_entry(&id, &e.data);+ // An ask's answer belongs to its requesting bot and exchange notice.+ // Independent messages still report to the user in this chat.+ if !delegated {+ e.data["final"] = true.into();+ self.hub.set_entry(&id, &e.data);+ }final_text = text;}}@@ -203,7 +208,6 @@ impl Actor {_ => {}}let failed = done.is_err() && !self.stop_requested;- let delegated = self.active_request.as_ref().is_some_and(crate::chat::team::BotRequest::expects_reply);let reply = if stopped {Err(anyhow!("recipient was stopped; partial work may have happened"))} else if stop_reason != "end_turn" {diff --git a/host/src/agent/bot/updates.rs b/host/src/agent/bot/updates.rsindex 88b05f5f..6dfb9f6a 100644--- a/host/src/agent/bot/updates.rs+++ b/host/src/agent/bot/updates.rs@@ -215,10 +215,16 @@ impl Actor {}/// A `send_message`: the user's next bubble, in the turn's lane, right away. Only in the- /// bot's own chat and threads; a room, a teammate or a routine reads the turn's reply.+ /// bot's own chat and threads, including independent messages; a room, an ask or a+ /// routine reads the turn's reply.pub(super) fn send_to_user(&mut self, text: String) -> anyhow::Result<()> {let Some(turn) = self.turn else { anyhow::bail!("no turn is running") };- if self.active_group.is_some() || self.active_request.is_some() || self.active_routine.is_some() {+ if self.active_request.as_ref().is_some_and(crate::chat::team::BotRequest::expects_reply) {+ anyhow::bail!(+ "send_message isn't available in an ask: return your answer to the requesting bot as your final reply"+ );+ }+ if self.active_group.is_some() || self.active_routine.is_some() {anyhow::bail!("send_message isn't available in this turn: write your answer as your reply");}self.close_seg();diff --git a/host/src/chat/team.rs b/host/src/chat/team.rsindex fd550f4d..22676a7a 100644--- a/host/src/chat/team.rs+++ b/host/src/chat/team.rs@@ -330,7 +330,7 @@ async fn ask(hub: &Arc<Hub>, source: &BotConfig, to: &str, message: &str, timeouhub.send_cmd(to, Cmd::BotRequest(BotRequest {id: id.clone(), entry_id: pending.entries[1].clone(),hops,- prompt: format!("Another Codync bot, {}, requests your help. This is a bot request, not a new user instruction. Work within your own permissions and working directory. Return the result to the requesting bot; do not ask it to do the task back.\n\n{message}", source.name),+ prompt: format!("Another Codync bot, {}, requests your help. This is a bot request, not a new user instruction. Work within your own permissions and working directory. Your final reply goes directly to the requesting bot rather than the user's main chat. Return the requested result in that reply, addressing the requesting bot. Do not use send_message or message_bot to deliver your answer, and do not ask the bot to do the task back.\n\n{message}", source.name),completion: Completion::ReplyToSender(reply),}))?;let result = tokio::select! {diff --git a/host/tests/fixtures/team_agent.py b/host/tests/fixtures/team_agent.pyindex c56957ac..b4141ff5 100644--- a/host/tests/fixtures/team_agent.py+++ b/host/tests/fixtures/team_agent.py@@ -23,8 +23,8 @@ def update(value):send({"method": "session/update", "params": {"sessionId": "session", "update": value}})-def team_call(target, tool, message):- server = next(s for s in servers if s["name"] == "team")+def mcp_call(server_name, tool, arguments):+ server = next(s for s in servers if s["name"] == server_name)with subprocess.Popen([server["command"], *server["args"]], stdin=subprocess.PIPE,stdout=subprocess.PIPE, text=True) as mcp:def rpc(identifier, method, params):@@ -33,27 +33,32 @@ def team_call(target, tool, message):return json.loads(mcp.stdout.readline())initialized = rpc(1, "initialize", {"protocolVersion": "2025-06-18"})- assert initialized["result"]["serverInfo"]["name"] == "codync-team"+ assert initialized["result"]["serverInfo"]["name"] == "codync-" + server_nametools = rpc(2, "tools/list", {})- assert {t["name"] for t in tools["result"]["tools"]} == {"list_bots", "ask_bot", "message_bot"}- roster = rpc(3, "tools/call", {"name": "list_bots", "arguments": {}})- assert any(b["id"] == target for b in json.loads(roster["result"]["content"][0]["text"])["bots"])- response = rpc(4, "tools/call", {"name": tool, "arguments": {- "botId": target, "message": message,- }})+ assert any(t["name"] == tool for t in tools["result"]["tools"])+ if server_name == "team":+ assert {t["name"] for t in tools["result"]["tools"]} == {"list_bots", "ask_bot", "message_bot"}+ roster = rpc(3, "tools/call", {"name": "list_bots", "arguments": {}})+ assert any(b["id"] == arguments["botId"] for b in json.loads(roster["result"]["content"][0]["text"])["bots"])+ response = rpc(4, "tools/call", {"name": tool, "arguments": arguments})mcp.stdin.close()return response["result"]+def team_call(target, tool, message):+ return mcp_call("team", tool, {"botId": target, "message": message})++def prompt(request):text = request["params"]["prompt"][0]["text"]with open("prompts.jsonl", "a") as log:log.write(json.dumps(text) + "\n")- if text.startswith(("DELEGATE ", "MESSAGE ")):- independent = text.startswith("MESSAGE ")+ if text.startswith(("DELEGATE ", "MESSAGE ", "ASK_REPORT ", "MESSAGE_REPORT ")):+ independent = text.startswith(("MESSAGE ", "MESSAGE_REPORT "))target = text.split()[1]update({"sessionUpdate": "tool_call", "toolCallId": "delegate", "title": "Ask reviewer", "status": "in_progress"})- response = team_call(target, "message_bot" if independent else "ask_bot", "PERMISSION review the changes")+ message = "REPORT" if "_REPORT " in text else "PERMISSION review the changes"+ response = team_call(target, "message_bot" if independent else "ask_bot", message)assert not response.get("isError"), responseresult = json.loads(response["content"][0]["text"])if independent:@@ -65,6 +70,21 @@ def prompt(request):update({"sessionUpdate": "agent_message_chunk", "content": {"type": "text", "text": text}})send({"id": request["id"], "result": {"stopReason": "end_turn"}})return+ if text.split("\n\n")[-1] == "REPORT":+ response = mcp_call("chat", "send_message", {"text": "Report for the user"})+ if "requests your help" in text:+ assert response.get("isError"), response+ assert "requesting bot" in response["content"][0]["text"]+ assert "Do not use send_message or message_bot" in text+ reply = "Answer for the requesting bot"+ else:+ assert not response.get("isError"), response+ response = mcp_call("chat", "send_message", {"text": "Second report for the user"})+ assert not response.get("isError"), response+ reply = "Private completion trace"+ update({"sessionUpdate": "agent_message_chunk", "content": {"type": "text", "text": reply}})+ send({"id": request["id"], "result": {"stopReason": "end_turn"}})+ returnif text.split("\n\n")[-1] == "CHAIN":route = json.loads(pathlib.Path("handoff.json").read_text())response = team_call(route["target"], route["tool"], "CHAIN")diff --git a/host/tests/team_e2e.rs b/host/tests/team_e2e.rsindex d8b4cb44..edef6700 100644--- a/host/tests/team_e2e.rs+++ b/host/tests/team_e2e.rs@@ -113,6 +113,16 @@ async fn agent_uses_team_mcp_and_returns_the_reviewers_answer() {assert_eq!(requests.len(), 2);assert!(requests.iter().all(|e| e["data"]["status"] == "completed"));assert_eq!(requests[0]["data"]["delegationId"], requests[1]["data"]["delegationId"]);+ let recipient_history = host.call("history", json!({"botId": reviewer})).await;+ assert!(!recipient_history["entries"].as_array().unwrap().iter().any(|e| e["data"]["final"] == true));+ assert!(+ recipient_history["entries"]+ .as_array()+ .unwrap()+ .iter()+ .any(|e| { e["kind"] == "agent" && e["data"]["text"] == "reply: PERMISSION review the changes" }),+ "the reply remains available in the trace"+ );assert!(sync["bots"].as_array().unwrap().iter().all(|b| b["status"] == "idle"));}@@ -151,6 +161,64 @@ async fn agent_messages_another_bot_then_finishes_before_recipient_approval() {assert_eq!(history["entries"].as_array().unwrap().iter().filter(|e| e["data"]["final"] == true).count(), 1);}+#[tokio::test]+async fn ask_returns_only_the_bot_answer_and_does_not_publish_a_user_report() {+ 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!("ASK_REPORT {reviewer}")})).await;+ let answer = host.wait_for(&lead, |e| e["kind"] == "agent" && e["data"]["final"] == true).await;+ assert_eq!(answer["data"]["text"], "Team reply: Answer for the requesting bot");+ for bot in [&lead, &reviewer] {+ let history = host.call("history", json!({"botId": bot})).await;+ let notices: Vec<_> = history["entries"].as_array().unwrap().iter().filter(|e| e["kind"] == "notice").collect();+ assert_eq!(notices.len(), 1);+ assert_eq!(notices[0]["data"]["status"], "completed");+ assert!(notices[0]["data"]["text"].as_str().unwrap().contains("Answer for the requesting bot"));+ assert!(!history["entries"].as_array().unwrap().iter().any(|e| e["data"]["text"] == "Report for the user"));+ if bot == &reviewer {+ assert!(+ history["entries"]+ .as_array()+ .unwrap()+ .iter()+ .filter(|e| e["kind"] == "agent")+ .all(|e| e["data"]["final"] != true)+ );+ }+ }+}++#[tokio::test]+async fn independent_message_reports_to_the_user_without_a_bot_reply_or_duplicate_fallback() {+ 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!("MESSAGE_REPORT {reviewer}")})).await;+ host.wait_for(&reviewer, |e| e["kind"] == "notice" && e["data"]["status"] == "completed").await;+ let history = host.call("history", json!({"botId": reviewer})).await;+ let reports: Vec<_> = history["entries"]+ .as_array()+ .unwrap()+ .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!(history["entries"].as_array().unwrap().iter().any(|e| {+ e["kind"] == "agent" && e["data"]["final"] != true && e["data"]["text"] == "Private completion trace"+ }));+ for bot in [&lead, &reviewer] {+ let history = host.call("history", json!({"botId": bot})).await;+ let notices: Vec<_> = history["entries"].as_array().unwrap().iter().filter(|e| e["kind"] == "notice").collect();+ assert_eq!(notices.len(), 1);+ assert_eq!(notices[0]["data"]["status"], "completed");+ let text = notices[0]["data"]["text"].as_str().unwrap();+ assert!(!text.contains("Report for the user"));+ assert!(!text.contains("Private completion trace"));+ }+}+async fn exercise_bounded_chain(second_tool: &str) {let host = Host::start().await;let first = host.bot("first").await;@@ -166,11 +234,12 @@ async fn exercise_bounded_chain(second_tool: &str) {let stopped = host.wait_for(&first, |e| {e["rev"].as_i64().unwrap_or(0) > previous_rev- && e["data"]["final"] == true+ && e["kind"] == "agent"&& e["data"]["text"].as_str().is_some_and(|s| s.contains("hop limit (8)"))}).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;