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): cloud assistants turn on only for a computer in an account
leepokai974b5e97abdf
diff --git a/docs/features/cloud-assistants.md b/docs/features/cloud-assistants.mdindex bfea25b1..d3f6ebe0 100644--- a/docs/features/cloud-assistants.md+++ b/docs/features/cloud-assistants.md@@ -48,7 +48,11 @@ The cloud sees these calls in plain text, and a bot can run anything on its comp- **Off by default.** The **Cloud assistants** switch on the computer turns it on for that computer: the desktopapp (Settings → Computers, beside the account rows, shown while the computer is in the account) and the terminal- UI's network sheet (`N`, then `a`), or `codync-host cloud --assistants on`. All go through the local API+ UI's network sheet (`N`, then `a`), or `codync-host cloud --assistants on`. It turns on only while the computer+ is in a Codync account (`setAssistants` refuses otherwise, or says the account isn't known yet when no state pull+ worked on this connection; off always works), and a state pull with no owner turns it off, so the account the+ computer joins next is asked again. A computer reached through the network needs this too: its own switch decides+ its letters. All go through the local API`setAssistants`, loopback only. The setting is the `assistants` field of `cloudStatus` and of `networkView`, whichphones read (they show it in the network sheet and can't change it); the `network` event carries a change. Theview's `assistantsAvailable` says whether the computer is in a Codync account: the terminal UI and the phones showdiff --git a/docs/features/codync-network.md b/docs/features/codync-network.mdindex 7972f4a2..0ee03576 100644--- a/docs/features/codync-network.md+++ b/docs/features/codync-network.md@@ -166,7 +166,8 @@ and nothing new crosses the wire beyond a refusal's reason.- **Reachable by cloud assistants**, per bot (`reachableByAssistants`, on by default): `list_bots` from the cloudassistant leaves it out and `message_bot` refuses it (`chat/team/assistant.rs`). A letter from the cloudassistant through another computer (`cloud-assistant@desk`) meets the same checks here, and this computer's own- Cloud assistants switch: off, it refuses them all (`remote::take`).+ Cloud assistants switch: off, it refuses them all (`remote::take`). The switch turns on only while this computer+ is in the Codync account, so the receiving computer needs the account too.- **Rules**, per network: an ordered list of `{fromComputer, fromAgent, toAgent, access}` (`allow`/`deny`, `*`for any). The first rule that matches decides; with none, everyone may write (`codync_network::rules`). The cratechecks them in `node/inbound.rs` before it takes a letter, so the standalone daemon has them too (`rules.json`diff --git a/docs/reference/remote-relay.md b/docs/reference/remote-relay.mdindex 5e79110d..c180f206 100644--- a/docs/reference/remote-relay.md+++ b/docs/reference/remote-relay.md@@ -470,7 +470,7 @@ Close code 總表:`1000` 正常、`1011` 內部錯誤/逾時、`4001 unautho- **登入**:Clerk 是 authorization server,Worker 只是 protected resource。未帶有效 token → `401`,`WWW-Authenticate: Bearer resource_metadata="<origin>/.well-known/oauth-protected-resource/mcp", scope="profile email"`;metadata 指向 Clerk issuer(`/.well-known/oauth-authorization-server` 也代轉 Clerk 的,給舊 client)。Client 以 CIMD 註冊(DCR 關閉)。Token 必須是 Clerk 發的 OAuth access token(`at+jwt`,或 opaque 時向 Clerk 驗),`aud` 必須等於 `<origin>/mcp`;App 的 session token 不算。`ASSISTANT_LIMITER`:每帳號每分鐘 120 次。- **路由**:Worker 只把呼叫送到 token 帳號擁有、`active` 的 computer。`list_computers` 由 Worker 從 D1 回答;其餘工具:指定 `computer`(名稱或 id)→ 該台;未指定時帳號只有一台、或只有一台在線 → 該台;`list_bots`/`read_replies` 在多台在線時每台都問並合併成 `{computers:[{computer, …}]}`;`message_bot` 則要求指定。- **DO**:`POST /internal/assistant {user, tool, args}` → host 不在線 `503 {"ok":false,"code":"offline"}`;否則送 `assistant.call`,在 request 存活期間等同 `id` 的 `assistant.result`,最多 10 秒(逾時 `{"ok":false,"code":"timeout"}`,舊 host 會忽略這個訊息)。host 斷線時等待中的呼叫一律 `offline`。只在 request 存活時佔用 DO,不排隊、不存任何內容。-- **Host**(`chat::team::assistant`):預設關閉,`setAssistants`(loopback only:桌面 app 與 TUI 的 Cloud assistants 開關,或 `codync-host cloud --assistants on|off`)才開;`user` 必須等於 host 的 owner(`/v1/host/state`);private relay 上不處理。`message_bot` 走一般 bot request(`Back::Assistant`),回覆留在 host 記憶體給 `read_replies`(最新 50 則,同時最多 16 則執行中,重啟即忘)。`reachableByAssistants` 關掉的 bot 不列出、不收。`list_bots` 也列同一 network 裡其他電腦提供的 bot(`reviewer@laptop`);對它們的 `message_bot` 是一封由 `cloud-assistant@<這台>` 寄出的 codync-network 信,結果回到同一份 replies。收信的電腦自己再檢查:它的 Cloud assistants 開關、該 bot 的 `reachableByAssistants` 與 network rules。Host 在 relay session 外另起 task 回答 `assistant.call`(第一次列出時可能要等其他電腦最多 5 秒),不會卡住同一條連線上的裝置訊息。+- **Host**(`chat::team::assistant`):預設關閉,`setAssistants`(loopback only:桌面 app 與 TUI 的 Cloud assistants 開關,或 `codync-host cloud --assistants on|off`)才開,且電腦不在 Codync 帳號裡時拒絕打開(這條連線還沒有成功的 state pull 時回「帳號還不知道」;關永遠可以),state pull 回 `owner: null` 時自動關掉,下次加入的帳號要重新同意;`user` 必須等於 host 的 owner(`/v1/host/state`);private relay 上不處理。`message_bot` 走一般 bot request(`Back::Assistant`),回覆留在 host 記憶體給 `read_replies`(最新 50 則,同時最多 16 則執行中,重啟即忘)。`reachableByAssistants` 關掉的 bot 不列出、不收。`list_bots` 也列同一 network 裡其他電腦提供的 bot(`reviewer@laptop`);對它們的 `message_bot` 是一封由 `cloud-assistant@<這台>` 寄出的 codync-network 信,結果回到同一份 replies。收信的電腦自己再檢查:它的 Cloud assistants 開關(所以它也要在帳號裡)、該 bot 的 `reachableByAssistants` 與 network rules。Host 在 relay session 外另起 task 回答 `assistant.call`(第一次列出時可能要等其他電腦最多 5 秒),不會卡住同一條連線上的裝置訊息。- **信任邊界**:和 §7.8 一樣,雲端以 HTTPS 解開並看得到這些呼叫與回覆的明文,不是 §6 的端對端加密。因此要電腦本機同意(開關)才放行,雲端無法自行替電腦打開;App 與文件都需明講。---diff --git a/host/src/chat/team/assistant.rs b/host/src/chat/team/assistant.rsindex eb45e50d..c4277173 100644--- a/host/src/chat/team/assistant.rs+++ b/host/src/chat/team/assistant.rs@@ -19,6 +19,7 @@ use crate::remote::cloud::{self, CloudStatus};use crate::store::{BotConfig, Store, now_ms};use anyhow::{Result, anyhow, bail};use serde_json::{Value, json};+use std::sync::atomic::Ordering;use std::sync::{Arc, Mutex};/// How it shows in a bot's chat, and its id there (`sourceBotId`).@@ -35,7 +36,9 @@ const MAX_RUNNING: usize = 16;const KEEP: usize = 50;const SHOW: usize = 20;const OFF: &str = "Cloud assistants are off on this computer. To let ChatGPT or Claude message its bots, \-turn on Cloud assistants in Codync's settings on it (or run `codync-host cloud --assistants on`).";+turn on Cloud assistants in Codync's settings on it (or run `codync-host cloud --assistants on`); \+it has to be in your Codync account.";+const NOT_IN_ACCOUNT: &str = "This computer isn't in your Codync account.";pub fn enabled(store: &Store) -> bool {store.kv_get(KV).as_deref() == Some("on")@@ -65,7 +68,18 @@ fn closed(bot: &BotConfig) -> anyhow::Error {/// `setAssistants`: whether the cloud assistant may reach this computer's bots. Local only.pub fn set_enabled(hub: &Hub, on: bool) -> Result<CloudStatus> {- cloud::require_accounts(&hub.store)?;+ // Off always works; on needs the account the cloud routes the assistant's calls from.+ if on && !available(hub) {+ cloud::require_accounts(&hub.store)?;+ // Until a state pull on this connection works, no owner may only mean "not known yet".+ if !hub.cloud_synced.load(Ordering::Acquire) {+ bail!(+ "This computer isn't connected to the Codync cloud yet, so its account isn't known. \+ Turn on Reach from anywhere, then try again once it's connected."+ );+ }+ bail!("{NOT_IN_ACCOUNT} Sign in on the desktop app or a phone and add this computer to your account first.");+ }hub.store.kv_set(KV, if on { "on" } else { "off" })?;tracing::info!(on, "cloud assistants changed");cloud::update_status(hub, |s| s.assistants = on);@@ -93,7 +107,7 @@ async fn cloud_call(hub: &Arc<Hub>, user: &str, tool: &str, args: &Value) -> Res}// The cloud only routes the account's own calls here; this computer checks that too.if user.is_empty() || hub.cloud.status().owner.map(|o| o.user_id).as_deref() != Some(user) {- bail!("This computer isn't in your Codync account.");+ bail!(NOT_IN_ACCOUNT);}run(hub, &Asker::cloud(), tool, args).await}diff --git a/host/src/chat/team/assistant/tests.rs b/host/src/chat/team/assistant/tests.rsindex 48899c75..eea6c508 100644--- a/host/src/chat/team/assistant/tests.rs+++ b/host/src/chat/team/assistant/tests.rs@@ -2,6 +2,7 @@ use super::super::tests::Fixture;use super::*;use crate::agent::bot::Cmd;use crate::remote::cloud::Owner;+use std::sync::atomic::Ordering;async fn call(hub: &Arc<Hub>, user: &str, tool: &str, args: &Value) -> Value {answer(hub, &json!({"t": "assistant.call", "id": "c1", "user": user, "tool": tool, "args": args})).await@@ -11,15 +12,26 @@ fn refused(v: &Value, why: &str) {assert!(v["ok"] == false && v["error"].as_str().unwrap().contains(why), "{v}");}+/// What a state pull that found this computer in `user_1`'s account leaves.+fn in_account(hub: &Hub) {+ cloud::update_status(hub, |s| s.owner = Some(Owner { user_id: "user_1".into(), email: None }));+}+#[tokio::test]async fn the_cloud_assistant_needs_the_switch_and_the_account_and_reads_replies_later() {let f = Fixture::new();let hub = &f.hub;refused(&call(hub, "user_1", "list_bots", &json!({})).await, "Cloud assistants are off");+ // Only a computer in an account can turn it on; off always works.+ let turn_on = || set_enabled(hub, true).unwrap_err().to_string();+ assert!(turn_on().contains("isn't connected to the Codync cloud yet"), "no state pull yet: {}", turn_on());+ hub.cloud_synced.store(true, Ordering::Release);+ assert!(turn_on().contains("isn't in your Codync account"), "{}", turn_on());+ assert!(!hub.cloud.status().assistants);+ set_enabled(hub, false).unwrap();+ in_account(hub);set_enabled(hub, true).unwrap();assert!(hub.cloud.status().assistants);- refused(&call(hub, "user_1", "list_bots", &json!({})).await, "isn't in your Codync account");- cloud::update_status(hub, |s| s.owner = Some(Owner { user_id: "user_1".into(), email: None }));refused(&call(hub, "user_2", "list_bots", &json!({})).await, "isn't in your Codync account");let listed = call(hub, "user_1", "list_bots", &json!({"query": "b"})).await;@@ -37,6 +49,25 @@ async fn the_cloud_assistant_needs_the_switch_and_the_account_and_reads_replies_&call(hub, "user_1", "message_bot", &json!({"botId": "nobody", "message": "hi"})).await,"unknown or hidden bot",);+ // A computer that left the account answers no one, even with the switch still on.+ cloud::update_status(hub, |s| s.owner = None);+ refused(&call(hub, "user_1", "list_bots", &json!({})).await, "isn't in your Codync account");+ f.shutdown().await;+}++#[tokio::test]+async fn off_works_on_a_private_relay_too() {+ let f = Fixture::new();+ let hub = &f.hub;+ in_account(hub);+ set_enabled(hub, true).unwrap();+ // Moved to a private relay, as the relay restart shows it: no account there.+ hub.store.kv_set("test_cloud_url", "http://127.0.0.1:9").unwrap();+ hub.store.kv_set("test_cloud_token", "s3cret-token-value").unwrap();+ cloud::update_status(hub, |s| cloud::show(s, cloud::current(&hub.store).as_ref()));+ assert!(set_enabled(hub, true).unwrap_err().to_string().contains("private relay"));+ set_enabled(hub, false).unwrap();+ assert!(!enabled(&hub.store));f.shutdown().await;}@@ -44,8 +75,8 @@ async fn the_cloud_assistant_needs_the_switch_and_the_account_and_reads_replies_async fn read_replies_tells_a_failed_request_from_a_stopped_one() {let f = Fixture::new();let hub = &f.hub;+ in_account(hub);set_enabled(hub, true).unwrap();- cloud::update_status(hub, |s| s.owner = Some(Owner { user_id: "user_1".into(), email: None }));let ask = async |message: &str| {let sent = call(hub, "user_1", "message_bot", &json!({"botId": "b", "message": message})).await;sent["result"]["requestId"].as_str().unwrap().to_owned()@@ -71,17 +102,17 @@ async fn phones_hear_the_switch_through_the_network_view() {let switched = |events: &mut tokio::sync::broadcast::Receiver<Value>| {std::iter::from_fn(|| events.try_recv().ok()).find(|e| e["type"] == "network").expect("a network event")};- set_enabled(hub, true).unwrap();+ set_enabled(hub, false).unwrap();let view = &switched(&mut events)["network"];assert_eq!((&view["assistants"], &view["assistantsAvailable"]),- (&json!(true), &json!(false)),+ (&json!(false), &json!(false)),"not in an account yet");- cloud::update_status(hub, |s| s.owner = Some(Owner { user_id: "user_1".into(), email: None }));- set_enabled(hub, false).unwrap();+ in_account(hub);+ set_enabled(hub, true).unwrap();let view = &switched(&mut events)["network"];- assert_eq!((&view["assistants"], &view["assistantsAvailable"]), (&json!(false), &json!(true)));+ assert_eq!((&view["assistants"], &view["assistantsAvailable"]), (&json!(true), &json!(true)));f.shutdown().await;}@@ -89,8 +120,8 @@ async fn phones_hear_the_switch_through_the_network_view() {async fn a_bot_closed_to_cloud_assistants_is_neither_listed_nor_reached() {let f = Fixture::new();let hub = &f.hub;+ in_account(hub);set_enabled(hub, true).unwrap();- cloud::update_status(hub, |s| s.owner = Some(Owner { user_id: "user_1".into(), email: None }));hub.update_bot(&json!({"id": "b", "reachableByAssistants": false})).unwrap();let listed = call(hub, "user_1", "list_bots", &json!({})).await;let ids: Vec<&Value> = listed["result"]["bots"].as_array().unwrap().iter().map(|b| &b["id"]).collect();diff --git a/host/src/cloud_cli.rs b/host/src/cloud_cli.rsindex 060a8a84..af5e1f8a 100644--- a/host/src/cloud_cli.rs+++ b/host/src/cloud_cli.rs@@ -20,7 +20,7 @@ pub struct CloudArgs {approval: Option<String>,/// Whether the cloud assistant (ChatGPT, Claude…) you connect to Codync through/// mcp.codync.dev may message this computer's bots: `on` or `off` (the default). Its calls- /// reach this computer through the cloud unencrypted.+ /// reach this computer through the cloud unencrypted. `on` needs this computer in a Codync account.#[arg(long, value_parser = ["on", "off"])]assistants: Option<String>,/// Cloud base URL for this computer. `https://…`, or `http://127.0.0.1` / `localhost` for a relay on this machine.@@ -53,15 +53,16 @@ pub async fn run(args: CloudArgs) -> Result<()> {}status = Some(local_call(port, "setCloudUrl", body).await?);}+ // Before the account settings, so a refused one doesn't keep the cloud from turning on.+ if enable || disable {+ status = Some(local_call(port, "setCloud", json!({"enabled": !disable})).await?);+ }if let Some(approval) = approval {status = Some(local_call(port, "setApproval", json!({ "approval": approval })).await?);}if let Some(assistants) = assistants {status = Some(local_call(port, "setAssistants", json!({ "enabled": assistants == "on" })).await?);}- if enable || disable {- status = Some(local_call(port, "setCloud", json!({"enabled": !disable})).await?);- }let status = match status {Some(status) => status,None => local_call(port, "cloudStatus", json!({})).await?,diff --git a/host/src/remote/cloud.rs b/host/src/remote/cloud.rsindex 23e5e1da..f4042538 100644--- a/host/src/remote/cloud.rs+++ b/host/src/remote/cloud.rs@@ -4,6 +4,7 @@//! SAS. Which cloud this host uses lives in `cloud_url`, the relay socket in `relay`.use crate::LockExt;+use crate::chat::team::assistant;use crate::hub::Hub;use crate::remote::crypto::{self, b64};use crate::store::{Device, DeviceSource, Scope, Store, now_ms};@@ -331,11 +332,16 @@ pub async fn pull(hub: &Hub, base: &str) -> Result<()> {let state: State = serde_json::from_value(call(hub, base, Method::GET, "/v1/host/state", None).await?).context("reading the cloud state")?;apply_grants(hub, &state.grants)?;+ let in_account = state.owner.is_some();// A pull that works also settles an earlier failed one.update_status(hub, |s| {s.owner = state.owner;s.last_error = None;});+ // Out of an account, cloud assistants go off: the account this computer joins next is asked again.+ if !in_account && assistant::enabled(&hub.store) {+ assistant::set_enabled(hub, false)?;+ }sync_requests(hub, base, state.requests).await;if approval(&hub.store) == Approval::Auto {// The SAS exchange still runs (the device's commit must match); only the user's comparison is skipped.@@ -786,6 +792,19 @@ mod tests {assert_eq!(hub.cloud.status().last_error, None, "Settings stops showing a relay error that's gone");}+ #[tokio::test]+ async fn leaving_the_account_turns_cloud_assistants_off() {+ let hub = temp_hub();+ let fake = Arc::new(FakeCloud::default());+ let base = fake_cloud(fake.clone()).await;+ *fake.state.lock().unwrap() = json!({"owner": {"userId": "user_1"}, "grants": [], "requests": []});+ pull(&hub, &base).await.unwrap();+ assistant::set_enabled(&hub, true).unwrap();+ *fake.state.lock().unwrap() = json!({"owner": null, "grants": [], "requests": []});+ pull(&hub, &base).await.unwrap();+ assert!(!assistant::enabled(&hub.store) && !hub.cloud.status().assistants, "the next account is asked again");+ }+#[tokio::test]async fn host_nonces_are_rationed() {let hub = temp_hub();diff --git a/web/content/docs/cloud-assistants.mdx b/web/content/docs/cloud-assistants.mdxindex a6756c20..fb23bd33 100644--- a/web/content/docs/cloud-assistants.mdx+++ b/web/content/docs/cloud-assistants.mdx@@ -8,7 +8,7 @@ Cloud assistants are off on every computer until you turn them on there, at the- **Terminal UI:** `N` opens the network sheet; `a` switches **Cloud assistants** (shown once the computer is in your Codync account).- **Command line:** `codync-host cloud --assistants on` (`off` turns it off; `codync-host cloud` shows it as `assistants: on`). On a Mac where you installed the app from the disk image rather than with Homebrew, `codync-host` is inside the app: `/Applications/Codync.app/Contents/Resources/codync-host`.-The switch carries the same warning as [Privacy](#privacy) below: Codync's cloud can read these calls. Phones show whether it's on (**Network** on the computer's card in **Manage computers**) but can't change it. The computer has to be in your Codync account (signed in) and use the Codync relay.+The switch carries the same warning as [Privacy](#privacy) below: Codync's cloud can read these calls. Phones show whether it's on (**Network** on the computer's card in **Manage computers**) but can't change it. The switch turns on only while the computer is in your Codync account (signed in) and uses the Codync relay, and it turns off if the computer leaves the account.To keep one bot away from cloud assistants while they're on, turn off **Reachable by cloud assistants** in its settings.@@ -37,7 +37,7 @@ In the bot's chat, the request shows as a row saying **Message from Cloud assist- **The computer needs Codync 2.28.0 or later.** An older one doesn't answer the assistant.- **Turned on at the computer.** The desktop app, the terminal UI or `codync-host` changes it; phones only show it.-- **Only through computers in your Codync account that use the Codync relay.** A computer that uses your own relay can't be reached directly. Through one that can, the assistant also reaches the bots your other computers offer in your [network of computers](/docs/teamwork#bots-on-your-other-computers), as `name@computer`; each of those computers decides with its own rules, its Cloud assistants switch and each bot's **Reachable by cloud assistants** whether it takes the message.+- **Only through computers in your Codync account that use the Codync relay.** A computer that uses your own relay can't be reached directly. Through one that can, the assistant also reaches the bots your other computers offer in your [network of computers](/docs/teamwork#bots-on-your-other-computers), as `name@computer`; each of those computers decides with its own rules, its Cloud assistants switch and each bot's **Reachable by cloud assistants** whether it takes the message, so it has to be in your Codync account too.- **No hidden bots or group chats.** The assistant sees the same bots another bot can message.- **It can't be told when a reply is ready.** A hosted assistant only acts when you write to it, so ask it to check on the task later.- **Replies don't last.** The computer keeps the newest 50 requests, at most 16 of them running at once, and forgets them all when Codync restarts.