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
feat(host): a computer that moves tells its network where it is now
leepokaid965ae1a14b6
diff --git a/docs/design/codync-network.md b/docs/design/codync-network.mdindex 861587fa..f68145f5 100644--- a/docs/design/codync-network.md+++ b/docs/design/codync-network.md@@ -59,9 +59,11 @@ The connector picks the relay (`codync-host network create|join --connector …`Codync's Cloudflare relay isn't on this path: it carries the phone ↔ computer channel and the cloud assistant.-Each computer signs where it is into the roster (`Locate`) when the host starts; the roster keeps only each-computer's newest location. With a relay, a computer that moved is still found through its relay and iroh's-address lookup.+Each computer signs where it is into the roster (`Locate`) when the host starts and again whenever its addresses+change (iroh's address watcher, 2 s after a burst settles), then says hello to everyone, so a laptop that moved to+another network is found without a restart, even with the `private` connector. The roster keeps only each+computer's newest location, so moving doesn't grow the log. With a relay, a computer that moved is also found+through its relay and iroh's address lookup.The host builds iroh on aws-lc-rs, the TLS library reqwest and tokio-tungstenite use: with ring built in as well,rustls has no default provider and the relay connection panicked (found in end-to-end testing, 2026-10-26). `main`@@ -148,10 +150,8 @@ terminal UI manage the network, phones show it, and a `network` event keeps them1. Per-bot offering and inbound rules (needed before networks shared with other people).2. Codync-run iroh relays as the default connector.-3. Re-sign a computer's location when its address changes: today a `private` network without Tailscale loses a- computer that changes networks until its host restarts.-4. The cloud assistant reaching bots on the connected computer's network.-5. A local MCP server for agents that aren't Codync bots.-6. Hellos that carry only what changed, lifting the roster's per-computer cap.-7. Account networks; several networks per computer.-8. A control channel for the standalone daemon on Windows (named pipe).+3. The cloud assistant reaching bots on the connected computer's network.+4. A local MCP server for agents that aren't Codync bots.+5. Hellos that carry only what changed, lifting the roster's per-computer cap.+6. Account networks; several networks per computer.+7. A control channel for the standalone daemon on Windows (named pipe).diff --git a/docs/features/codync-network.md b/docs/features/codync-network.mdindex 2665744f..3190a31f 100644--- a/docs/features/codync-network.md+++ b/docs/features/codync-network.md@@ -42,7 +42,8 @@ event. The first ask after the host starts is left to bot listings (`list_bots`)`create` prints the **recovery code** once: the network's root key, kept on no computer. The connector picks thefallback when two computers can't connect directly: iroh's public relays (`public`, the default), the user's own-`iroh-relay` (a URL), or none (`private`: same network, Tailscale or a VPN). A computer's name defaults to its host+`iroh-relay` (a URL), or none (`private`: same network, Tailscale or a VPN). A computer that moves to another network signs+where it is again and tells the others, so it stays reachable without a restart. A computer's name defaults to its hostname; a taken name gets a number (`laptop-2`), also when two admins admit the same name before their copies meet(the later admission gets the number, on every copy). No computer's name changes when another is removed; oneadmitted after a removal can take the freed name.diff --git a/docs/plans/codync-network-next.md b/docs/plans/codync-network-next.mdindex 87cd19d9..acbcc2a1 100644--- a/docs/plans/codync-network-next.md+++ b/docs/plans/codync-network-next.md@@ -162,9 +162,13 @@ default connector points at them instead of n0's public relays, which are rate-ldefault connector, the privacy policy's third-party list, and the design doc's relay table. Ask the user beforerenting servers.-## 4. A computer's address after it moves+## 4. A computer's address after it moves (built)-A computer signs where it is into the roster only when the host starts (`refresh_my_addr`). With the `private`+Built as below: `follow_addr` in `node/mod.rs` watches `Endpoint::watch_addr`, waits 2 s for a burst to settle,+re-signs `Locate` when the address differs from the roster's and hellos everyone; the unit test moves a computer with+a watched address and checks the other computer's roster.++Before: a computer signs where it is into the roster only when the host starts (`refresh_my_addr`). With the `private`connector and no Tailscale, a laptop that changes networks can't be found until its host restarts. Watch theendpoint's addresses (iroh exposes changes), re-sign `Locate` when they change, and hello everyone. The roster keepsonly each computer's newest location, so this doesn't grow the log. Test: change addresses in a two-node test.diff --git a/host/Cargo.lock b/host/Cargo.lockindex 032d1346..6dd727a9 100644--- a/host/Cargo.lock+++ b/host/Cargo.lock@@ -777,6 +777,7 @@ dependencies = ["base64 0.23.1","getrandom 0.4.3","iroh",+ "n0-watcher","serde","serde_json","tokio",diff --git a/host/crates/network/Cargo.toml b/host/crates/network/Cargo.tomlindex 57017023..b7fc86d5 100644--- a/host/crates/network/Cargo.toml+++ b/host/crates/network/Cargo.toml@@ -23,6 +23,10 @@ serde_json = "1"tokio = { version = "1", features = ["full"] }tracing = "0.1"+[dev-dependencies]+# Moves a computer in tests: a watched address the test sets (iroh's own watcher type).+n0-watcher = "1"+# The TLS library under iroh. An app that already uses rustls with aws-lc-rs takes `tls-aws-lc-rs`# (with default-features = false): rustls can't pick a provider by itself when both are built in.[features]diff --git a/host/crates/network/src/node/mod.rs b/host/crates/network/src/node/mod.rsindex d11f367a..5b09c409 100644--- a/host/crates/network/src/node/mod.rs+++ b/host/crates/network/src/node/mod.rs@@ -13,11 +13,11 @@ use crate::wire::{self, ALPN, Agent, Request, Response, Ticket};use anyhow::{Context, Result, anyhow, bail};use iroh::endpoint::{Connection, presets};use iroh::protocol::Router;-use iroh::{Endpoint, EndpointId, RelayMode, RelayUrl, SecretKey};+use iroh::{Endpoint, EndpointAddr, EndpointId, RelayMode, RelayUrl, SecretKey, Watcher};use std::collections::{HashMap, VecDeque};use std::path::{Path, PathBuf};use std::sync::atomic::{AtomicBool, Ordering};-use std::sync::{Arc, Mutex, MutexGuard};+use std::sync::{Arc, Mutex, MutexGuard, Weak};use std::time::{Duration, Instant};use tokio::sync::{mpsc, watch};use tokio::task::JoinSet;@@ -29,6 +29,8 @@ const CONNECT_TIMEOUT: Duration = Duration::from_secs(10);/// Long enough for the other computer to knock on its agent's harness.const CALL_TIMEOUT: Duration = Duration::from_secs(20);const INBOX_SIZE: usize = 256;+/// How long addresses get to settle after a change before this computer signs where it is.+const ADDR_SETTLE: Duration = Duration::from_secs(2);/// Letters whose handoff count a reply may need, newest kept.const HEARD_MAX: usize = 1000;@@ -99,10 +101,11 @@ impl Node {});let router = Router::builder(endpoint).accept(ALPN, inbound::Handler(inner.clone())).spawn();settle(&inner.endpoint, connector).await;- inner.refresh_my_addr()?;+ inner.locate(inner.endpoint.addr())?;// Catch up with the others: a computer that was off may have missed a removal.inner.clone().hello_all();tokio::spawn(outbox::retry_loop(Arc::downgrade(&inner)));+ tokio::spawn(follow_addr(Arc::downgrade(&inner), inner.endpoint.watch_addr()));Ok((Self { inner, router }, rx))}@@ -380,16 +383,16 @@ impl Inner {Ok(())}- /// Writes this computer's current address into the roster when it moved.- fn refresh_my_addr(&self) -> Result<()> {+ /// Writes where this computer is into the roster when it moved. Returns whether it did.+ fn locate(&self, addr: EndpointAddr) -> Result<bool> {let mut guard = locked(&self.roster);- let Some(roster) = guard.as_mut() else { return Ok(()) };- let addr = self.endpoint.addr();+ let Some(roster) = guard.as_mut() else { return Ok(false) };if roster.members().get(&self.me()).is_none_or(|m| m.addr == addr) {- return Ok(());+ return Ok(false);}roster.sign(self.endpoint.secret_key(), wire::now_ms(), Change::Locate { addr })?;- self.save(roster)+ self.save(roster)?;+ Ok(true)}/// Keeps `roster` on disk and tells whoever watches [`Node::changes`]. Callers hold the roster@@ -404,7 +407,7 @@ impl Inner {let addr = locked(&self.roster).as_ref().and_then(|r| r.members().get(&id).map(|m| m.addr.clone()))- .unwrap_or_else(|| iroh::EndpointAddr::new(id));+ .unwrap_or_else(|| EndpointAddr::new(id));// ponytail: a new connection per call; keep them open when traffic makes setup cost show.Ok(tokio::time::timeout(CONNECT_TIMEOUT, self.endpoint.connect(addr, ALPN)).await??)}@@ -464,6 +467,25 @@ impl Inner {}}+/// Signs where this computer is again whenever its addresses change (a laptop that moved to+/// another network) and tells the others, so they find it without a restart: with the `private`+/// connector, nothing else would. The roster keeps only each computer's newest location.+async fn follow_addr(inner: Weak<Inner>, mut addr: impl Watcher<Value = EndpointAddr>) {+ while addr.updated().await.is_ok() {+ // Addresses change in bursts (an interface comes up, then the relay answers): sign once.+ tokio::time::sleep(ADDR_SETTLE).await;+ let Some(inner) = inner.upgrade() else { return };+ match inner.locate(addr.get()) {+ Ok(true) => {+ tracing::info!("this computer moved; telling the others");+ inner.hello_all();+ }+ Ok(false) => {}+ Err(e) => tracing::warn!(error = format!("{e:#}"), "couldn't sign where this computer is"),+ }+ }+}+async fn bind(key: SecretKey, connector: &Connector) -> Result<Endpoint> {let builder = match connector {Connector::Public => Endpoint::builder(presets::N0),@@ -523,3 +545,41 @@ fn check_name(name: &str) -> Result<String> {}Ok(name.into())}++#[cfg(test)]+mod tests {+ use super::*;++ fn temp_dir(name: &str) -> PathBuf {+ let dir = std::env::temp_dir().join(format!("codync-network-unit-{name}-{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&dir);+ dir+ }++ #[tokio::test]+ async fn a_computer_that_moves_tells_the_others_without_a_restart() {+ let (desk_dir, laptop_dir) = (temp_dir("desk"), temp_dir("laptop"));+ let (desk, _) = Node::start(&desk_dir, &Connector::Private).await.expect("desk starts");+ desk.create("desk").expect("a network");+ let (laptop, _) = Node::start(&laptop_dir, &Connector::Private).await.expect("laptop starts");+ laptop.join(&desk.invite().expect("an invite"), "laptop").await.expect("joined");++ // The laptop moves: an address it didn't have before.+ let moved = laptop.inner.endpoint.addr().with_ip_addr("192.0.2.7:4242".parse().expect("an address"));+ let watched = n0_watcher::Watchable::new(laptop.inner.endpoint.addr());+ tokio::spawn(follow_addr(Arc::downgrade(&laptop.inner), watched.watch()));+ watched.set(moved.clone()).expect("watched");+ let desk_sees =+ || locked(&desk.inner.roster).as_ref().and_then(|r| r.members().get(&laptop.id()).map(|m| m.addr.clone()));+ tokio::time::timeout(Duration::from_secs(10), async {+ while desk_sees() != Some(moved.clone()) {+ tokio::time::sleep(Duration::from_millis(50)).await;+ }+ })+ .await+ .expect("the desk hears where the laptop is now");+ for dir in [desk_dir, laptop_dir] {+ let _ = std::fs::remove_dir_all(dir);+ }+ }+}