Skip to content

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.

feat(host): tell clients the oldest app version it serves

leepokai8871a3103a0f
diff --git a/host/src/api/mod.rs b/host/src/api/mod.rs
index 5fd995de..77e560fd 100644
--- a/host/src/api/mod.rs
+++ b/host/src/api/mod.rs
@@ -400,10 +400,10 @@ pub async fn dispatch(hub: &Arc<Hub>, caller: &Caller, method: &str, b: Value) -
"computerId": hub.identity.computer_id(),
"signKey": hub.identity.sign_pub_b64(),
"boxKey": hub.identity.box_pub_b64(),
- "protocol": 1,
"cloud": crate::remote::cloud::url(&hub.store),
"name": crate::service::host_name(),
"version": env!("CARGO_PKG_VERSION"),
+ "minApp": crate::compat::MIN_APP,
"os": std::env::consts::OS,
"device": tokio::task::spawn_blocking(crate::service::device).await?,
"home": dirs::home_dir().map(|p| p.to_string_lossy().into_owned()),
diff --git a/host/src/compat.rs b/host/src/compat.rs
new file mode 100644
index 00000000..5ad1ea1a
--- /dev/null
+++ b/host/src/compat.rs
@@ -0,0 +1,120 @@
+//! Phone/host compatibility: each side names the oldest version of the other it still works
+//! with (docs/reference/compatibility.md). The host sends `MIN_APP` in `hello`; clients keep
+//! their own oldest-host floor (`MIN_HOST` here for the terminal client).
+
+use serde_json::Value;
+
+/// The oldest client (iPhone, Mac, Linux app, terminal client) this host still serves correctly.
+/// Raise it only after that client version is out (App Store included), and only when this
+/// host stops sending or accepting something older clients depend on.
+pub const MIN_APP: &str = "2.3.0";
+
+/// The oldest host the terminal client works with.
+pub const MIN_HOST: &str = "2.3.0";
+
+/// Which side has to update before a client and a host can work together.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum Mismatch {
+ /// The client is older than the host's `minApp`.
+ UpdateApp { minimum: String },
+ /// The host is older than the client's floor.
+ UpdateHost { version: String, minimum: String },
+}
+
+/// `major.minor.patch`, ignoring a leading `v` and any pre-release or build suffix; missing
+/// parts count as 0. `None` for anything else, which never blocks a connection.
+pub fn parse(version: &str) -> Option<(u64, u64, u64)> {
+ let core = version.trim().trim_start_matches('v');
+ let core = core.split(['-', '+']).next()?;
+ let mut parts = core.split('.');
+ let mut next = |required: bool| match parts.next() {
+ Some(p) => p.parse::<u64>().ok(),
+ None if required => None,
+ None => Some(0),
+ };
+ let v = (next(true)?, next(false)?, next(false)?);
+ parts.next().is_none().then_some(v)
+}
+
+/// Whether `version` is below `minimum`; unreadable versions never are.
+pub fn below(version: &str, minimum: &str) -> bool {
+ matches!((parse(version), parse(minimum)), (Some(v), Some(m)) if v < m)
+}
+
+/// Checks a client of version `app` with floor `min_host` against a host's `hello`.
+/// Hosts that predate `minApp` only get the floor check.
+pub fn check(app: &str, min_host: &str, hello: &Value) -> Option<Mismatch> {
+ if let Some(minimum) = hello["minApp"].as_str()
+ && below(app, minimum)
+ {
+ return Some(Mismatch::UpdateApp { minimum: minimum.to_owned() });
+ }
+ let version = hello["version"].as_str().unwrap_or_default();
+ below(version, min_host).then(|| Mismatch::UpdateHost { version: version.to_owned(), minimum: min_host.to_owned() })
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use serde_json::json;
+
+ #[test]
+ fn floors_never_exceed_this_release() {
+ // A floor above the version that ships it would lock out even matching builds.
+ let own = env!("CARGO_PKG_VERSION");
+ assert!(!below(own, MIN_APP), "MIN_APP {MIN_APP} is above {own}");
+ assert!(!below(own, MIN_HOST), "MIN_HOST {MIN_HOST} is above {own}");
+ assert!(parse(MIN_APP).is_some() && parse(MIN_HOST).is_some());
+ }
+
+ #[test]
+ fn parses_leniently() {
+ assert_eq!(parse("2.4.1"), Some((2, 4, 1)));
+ assert_eq!(parse(" v2.4 "), Some((2, 4, 0)));
+ assert_eq!(parse("3"), Some((3, 0, 0)));
+ assert_eq!(parse("2.4.0-beta.1+77"), Some((2, 4, 0)));
+ assert_eq!(parse("2.10.0").cmp(&parse("2.9.9")), std::cmp::Ordering::Greater);
+ for bad in ["", "abc", "2.x", "2.4.0.1", "-1.0.0", "2..0"] {
+ assert_eq!(parse(bad), None, "{bad}");
+ }
+ }
+
+ #[test]
+ fn unreadable_versions_never_block() {
+ assert!(!below("", "2.4.0"));
+ assert!(!below("2.0.0", "garbage"));
+ assert!(below("2.3.9", "2.4.0"));
+ assert!(!below("2.4.0", "2.4.0"));
+ assert!(!below("2.4.0-dev", "2.4.0"));
+ }
+
+ #[test]
+ fn decides_which_side_updates() {
+ let host = |version: &str, min_app: Option<&str>| {
+ let mut h = json!({"version": version});
+ if let Some(m) = min_app {
+ h["minApp"] = json!(m);
+ }
+ h
+ };
+ assert_eq!(check("2.4.0", "2.3.0", &host("2.4.0", Some("2.3.0"))), None);
+ assert_eq!(
+ check("2.4.0", "2.3.0", &host("2.6.0", Some("2.5.0"))),
+ Some(Mismatch::UpdateApp { minimum: "2.5.0".into() })
+ );
+ assert_eq!(
+ check("2.6.0", "2.5.0", &host("2.4.0", Some("2.3.0"))),
+ Some(Mismatch::UpdateHost { version: "2.4.0".into(), minimum: "2.5.0".into() })
+ );
+ // Older hosts send no minApp; only the floor applies.
+ assert_eq!(check("2.4.0", "2.3.0", &host("2.3.1", None)), None);
+ assert_eq!(
+ check("2.4.0", "2.3.0", &host("2.2.3", None)),
+ Some(Mismatch::UpdateHost { version: "2.2.3".into(), minimum: "2.3.0".into() })
+ );
+ // A hello without a version can't be judged.
+ assert_eq!(check("2.4.0", "2.3.0", &json!({})), None);
+ // A development client with no readable version isn't locked out.
+ assert_eq!(check("dev", "2.3.0", &host("2.6.0", Some("2.5.0"))), None);
+ }
+}
diff --git a/host/src/main.rs b/host/src/main.rs
index 01c79963..ee0ad8ed 100644
--- a/host/src/main.rs
+++ b/host/src/main.rs
@@ -3,6 +3,7 @@
mod agent;
mod api;
mod chat;
+mod compat;
mod hub;
mod market;
mod mcp;
diff --git a/host/src/remote/channel.rs b/host/src/remote/channel.rs
index 5376442b..c5f481fc 100644
--- a/host/src/remote/channel.rs
+++ b/host/src/remote/channel.rs
@@ -746,7 +746,7 @@ mod tests {
let hello = p.call(1, "hello", json!({})).await;
assert_eq!(hello["ok"]["computerId"], hub.identity.computer_id());
assert_eq!(hello["ok"]["signKey"], hub.identity.sign_pub_b64());
- assert_eq!(hello["ok"]["protocol"], 1);
+ assert_eq!(hello["ok"]["minApp"], crate::compat::MIN_APP);
assert_eq!(hub.connected.locked().get(&p.dk()), Some(&1));
assert!(hub.store.device(&p.dk()).unwrap().last_seen_at.is_some());
diff --git a/host/src/tui/app.rs b/host/src/tui/app.rs
index 459ba604..3f4ffbe0 100644
--- a/host/src/tui/app.rs
+++ b/host/src/tui/app.rs
@@ -665,6 +665,8 @@ pub struct App {
pub home: String,
pub online: bool,
pub error: Option<String>,
+ /// This client and the host can't work together until one of them updates.
+ pub mismatch: Option<crate::compat::Mismatch>,
pub bots: HashMap<String, Bot>,
pub entries: HashMap<String, BTreeMap<i64, Entry>>,
pub usage: Value,
@@ -724,6 +726,7 @@ impl App {
home: String::new(),
online: false,
error: None,
+ mismatch: None,
bots: HashMap::new(),
entries: HashMap::new(),
usage: Value::Null,
@@ -988,9 +991,8 @@ impl App {
}
if on {
self.error = None;
- if self.host.is_empty() {
- self.call("hello", json!({}), After::Hello);
- }
+ // Every reconnect: the host may have been updated (or replaced) meanwhile.
+ self.call("hello", json!({}), After::Hello);
}
}
Msg::Rewind => {
@@ -1114,6 +1116,7 @@ impl App {
self.call("hello", json!({}), After::Hello);
}
After::Hello => {
+ self.mismatch = crate::compat::check(env!("CARGO_PKG_VERSION"), crate::compat::MIN_HOST, &v);
v["name"].as_str().unwrap_or("computer").clone_into(&mut self.host);
v["home"].as_str().unwrap_or_default().clone_into(&mut self.home);
self.backends = v["backends"].as_array().cloned().unwrap_or_default();
@@ -1306,6 +1309,12 @@ impl App {
if text.is_empty() && files.is_empty() {
return;
}
+ if let Some(m) = &self.mismatch {
+ // The draft stays; it sends once the update is done.
+ let why = mismatch_text(m, &self.host);
+ self.flash(&why);
+ return;
+ }
if self.sends.get(&key).is_some_and(|s| s.busy) {
self.flash("Sending…");
return;
@@ -2413,6 +2422,19 @@ const NAMES: [&str; 24] = [
"Gus", "Hal", "Ida", "Jin", "Kai", "Lux", "Nia", "Otto",
];
+/// What to update, in the words every client uses (docs/reference/compatibility.md).
+pub fn mismatch_text(m: &crate::compat::Mismatch, host: &str) -> String {
+ let host = if host.is_empty() { "the computer" } else { host };
+ match m {
+ crate::compat::Mismatch::UpdateApp { minimum } => {
+ format!("Update this app: {host} needs Codync {minimum} or newer here.")
+ }
+ crate::compat::Mismatch::UpdateHost { version, minimum } => format!(
+ "Update Codync on {host}: it runs {version}, this app needs {minimum} or newer. ^k → Check for updates."
+ ),
+ }
+}
+
/// OSC 52: the terminal puts it on the clipboard, over SSH too.
pub fn copy(text: &str) {
let mut out = std::io::stdout();
diff --git a/host/src/tui/view.rs b/host/src/tui/view.rs
index cfe4f103..fd3f51cd 100644
--- a/host/src/tui/view.rs
+++ b/host/src/tui/view.rs
@@ -470,6 +470,8 @@ fn status_line(buf: &mut Buffer, r: Rect, app: &mut App) {
}
if !app.online {
x = put(buf, x, r.y, 20, "offline", t.amber.patch(t.panel)) + 2;
+ } else if app.mismatch.is_some() {
+ x = put(buf, x, r.y, 20, "needs update", t.red.patch(t.panel)) + 2;
}
let hint = if insert { "↵ send · esc nav" } else { "? keys" };
let mut right = rput(buf, r.right() - 1, r.y, hint, t.dim.patch(t.panel)).saturating_sub(3);
@@ -498,9 +500,11 @@ fn status_line(buf: &mut Buffer, r: Rect, app: &mut App) {
edge = rput(buf, right + 1, r.y, &name, t.dim.patch(t.panel)).saturating_sub(2);
}
// A flash gets the room between the host and the usage, cut short to fit.
- if let Some((h, _)) = &app.hint {
+ // Otherwise what to update stays in view until it's done.
+ let standing = app.mismatch.as_ref().filter(|_| app.online).map(|m| super::app::mismatch_text(m, &app.host));
+ if let Some(h) = app.hint.as_ref().map(|(h, _)| h.clone()).or(standing) {
let room = edge.saturating_sub(x);
- put(buf, x, r.y, room, &truncate(h, usize::from(room)), t.amber.patch(t.panel));
+ put(buf, x, r.y, room, &truncate(&h, usize::from(room)), t.amber.patch(t.panel));
}
}
diff --git a/host/tests/e2e.rs b/host/tests/e2e.rs
index 7de8af5d..46a2f4d5 100644
--- a/host/tests/e2e.rs
+++ b/host/tests/e2e.rs
@@ -286,6 +286,8 @@ async fn phone_pairs_and_chats_over_the_direct_channel() {
let mut phone = Phone::connect(&host, &key, &sk, false).await;
let hello = phone.call(1, "hello", json!({})).await;
assert_eq!(hello["boxKey"], query_param(url, "bk"));
+ // Phones check themselves against it (docs/reference/compatibility.md).
+ assert!(hello["minApp"].as_str().is_some_and(|v| !v.is_empty()));
let agent = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fake_agent.py");
let bot = phone
.call(