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): hold updates until the App Store has the iPhone app
leepokaifad80ef89bfb
diff --git a/host/src/api/mod.rs b/host/src/api/mod.rsindex 77e560fd..03a480d7 100644--- a/host/src/api/mod.rs+++ b/host/src/api/mod.rs@@ -262,10 +262,11 @@ pub async fn dispatch(hub: &Arc<Hub>, caller: &Caller, method: &str, b: Value) -"installHostUpdate" => {let port = hub.port;let force = b["force"].as_bool().unwrap_or(false);+ let skip_app_check = b["skipAppCheck"].as_bool().unwrap_or(false);if !force && hub.busy() {bail!("host is busy; retry when idle or explicitly allow interruption");}- tokio::task::spawn_blocking(move || crate::update::spawn_worker(port, force)).await??;+ tokio::task::spawn_blocking(move || crate::update::spawn_worker(port, force, skip_app_check)).await??;json!({"scheduled": true})}"credentialUpdateConnector" => {diff --git a/host/src/compat.rs b/host/src/compat.rsindex 5ad1ea1a..9c8d97af 100644--- a/host/src/compat.rs+++ b/host/src/compat.rs@@ -12,6 +12,49 @@ pub const MIN_APP: &str = "2.3.0";/// The oldest host the terminal client works with.pub const MIN_HOST: &str = "2.3.0";+/// The iPhone app in the App Store, looked up to hold back host updates that need a newer+/// app than the store has (still in review).+pub const APP_STORE_ID: &str = "6760984418";++/// The iPhone app version live in the App Store; `None` when the lookup has no result.+pub async fn app_store_version() -> anyhow::Result<Option<String>> {+ let url = format!("https://itunes.apple.com/lookup?id={APP_STORE_ID}");+ let res: Value = crate::http()+ .get(url)+ .timeout(std::time::Duration::from_secs(10))+ .send()+ .await?+ .error_for_status()?+ .json()+ .await?;+ Ok(res["results"][0]["version"].as_str().map(str::to_owned))+}++/// Whether installing a release that needs `new_min_app` would lock out iPhones.+#[derive(Debug, PartialEq, Eq)]+pub enum Gate {+ Proceed,+ /// The App Store doesn't have that app yet (`store`), or couldn't be asked (`None`).+ WaitForApp {+ required: String,+ store: Option<String>,+ },+}++/// Decides a host update: only a release that raises `minApp`, on a computer with iPhones,+/// waits until the App Store has an app that new. An unanswered lookup waits too: going ahead+/// on a guess is what this gate exists to prevent (a person can still choose to).+pub fn gate(current_min_app: &str, new_min_app: &str, iphones: bool, store: &anyhow::Result<Option<String>>) -> Gate {+ if !below(current_min_app, new_min_app) || !iphones {+ return Gate::Proceed;+ }+ match store {+ Ok(Some(version)) if !below(version, new_min_app) && parse(version).is_some() => Gate::Proceed,+ Ok(Some(version)) => Gate::WaitForApp { required: new_min_app.to_owned(), store: Some(version.clone()) },+ _ => Gate::WaitForApp { required: new_min_app.to_owned(), store: None },+ }+}+/// Which side has to update before a client and a host can work together.#[derive(Debug, Clone, PartialEq, Eq)]pub enum Mismatch {@@ -88,6 +131,23 @@ mod tests {assert!(!below("2.4.0-dev", "2.4.0"));}+ #[test]+ fn host_updates_wait_for_the_iphone_app_only_when_needed() {+ let ok = |v: &str| -> anyhow::Result<Option<String>> { Ok(Some(v.to_owned())) };+ let wait = |store: Option<&str>| Gate::WaitForApp { required: "2.6.0".into(), store: store.map(Into::into) };+ // Same floor, or no iPhone here: the App Store doesn't matter.+ assert_eq!(gate("2.6.0", "2.6.0", true, &Err(anyhow::anyhow!("offline"))), Gate::Proceed);+ assert_eq!(gate("2.3.0", "2.6.0", false, &ok("2.2.1")), Gate::Proceed);+ // A raised floor waits for the App Store.+ assert_eq!(gate("2.3.0", "2.6.0", true, &ok("2.6.0")), Gate::Proceed);+ assert_eq!(gate("2.3.0", "2.6.0", true, &ok("2.7.1")), Gate::Proceed);+ assert_eq!(gate("2.3.0", "2.6.0", true, &ok("2.5.9")), wait(Some("2.5.9")));+ // No answer, or one that can't be read, isn't permission.+ assert_eq!(gate("2.3.0", "2.6.0", true, &Err(anyhow::anyhow!("offline"))), wait(None));+ assert_eq!(gate("2.3.0", "2.6.0", true, &Ok(None)), wait(None));+ assert_eq!(gate("2.3.0", "2.6.0", true, &ok("soon")), wait(Some("soon")));+ }+#[test]fn decides_which_side_updates() {let host = |version: &str, min_app: Option<&str>| {diff --git a/host/src/main.rs b/host/src/main.rsindex ee0ad8ed..b7ae7236 100644--- a/host/src/main.rs+++ b/host/src/main.rs@@ -138,6 +138,10 @@ enum Sub {/// Allow a manual update to interrupt active bots (their sessions resume).#[arg(long)]force: bool,+ /// Install even if the App Store doesn't have the iPhone app this release needs yet+ /// (paired iPhones then ask for an update they may not get until review is done).+ #[arg(long)]+ skip_app_check: bool,#[arg(long, default_value_t = service::DEFAULT_PORT)]port: u16,#[arg(long)]@@ -145,6 +149,9 @@ enum Sub {#[arg(long, hide = true)]worker: bool,},+ /// The versions this host works with (JSON), asked of a downloaded update before installing it.+ #[command(hide = true)]+ Compat,/// Show whether the host is installed and running.Status {#[arg(long, default_value_t = service::DEFAULT_PORT)]@@ -364,7 +371,11 @@ async fn main() -> Result<()> {println!("Codync host installed and started on port {port}. Run `codync-host pair` to connect your phone.");Ok(())}- Sub::Update { check, status, auto, force, port, json, worker } => {+ Sub::Compat => {+ println!("{}", serde_json::json!({"version": env!("CARGO_PKG_VERSION"), "minApp": compat::MIN_APP}));+ Ok(())+ }+ Sub::Update { check, status, auto, force, skip_app_check, port, json, worker } => {let status = if let Some(auto) = auto {update::set_automatic(auto == "on")?} else if status {@@ -372,10 +383,10 @@ async fn main() -> Result<()> {} else if check {update::check().await?} else if !worker && service::installed() {- tokio::task::spawn_blocking(move || update::spawn_worker(port, force)).await??;+ tokio::task::spawn_blocking(move || update::spawn_worker(port, force, skip_app_check)).await??;update::status()?} else {- update::apply(port, force, worker).await?+ update::apply(port, force, skip_app_check, worker).await?};if json {println!("{}", serde_json::to_string_pretty(&status)?);@@ -389,6 +400,18 @@ async fn main() -> Result<()> {if let Some(version) = status["state"]["availableVersion"].as_str() {println!("Available version: {version}");}+ if let Some(required) = status["state"]["requiredApp"].as_str() {+ match status["state"]["appStoreVersion"].as_str() {+ Some(store) => println!(+ "Waiting for the iPhone app {required} (the App Store has {store}); \+ it installs once that passes review"+ ),+ None => println!(+ "Waiting for the iPhone app {required}: couldn't check the App Store. \+ `codync-host update --skip-app-check` installs anyway"+ ),+ }+ }if let Some(error) = status["state"]["error"].as_str() {println!("Last error: {error}");}diff --git a/host/src/tui/app.rs b/host/src/tui/app.rsindex 3f4ffbe0..35aec245 100644--- a/host/src/tui/app.rs+++ b/host/src/tui/app.rs@@ -1117,6 +1117,16 @@ impl App {}After::Hello => {self.mismatch = crate::compat::check(env!("CARGO_PKG_VERSION"), crate::compat::MIN_HOST, &v);+ // Still compatible but behind this client: there's a newer host release.+ if self.mismatch.is_none()+ && let Some(version) = v["version"].as_str()+ && crate::compat::below(version, env!("CARGO_PKG_VERSION"))+ {+ self.flash(&format!(+ "Codync {} is available for this host (it runs {version}): ^k → Check for updates",+ env!("CARGO_PKG_VERSION")+ ));+ }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();@@ -1125,9 +1135,18 @@ impl App {self.backends = v["backends"].as_array().cloned().unwrap_or_default();self.flash("Agents refreshed");}- After::Update => match v["state"]["availableVersion"].as_str() {- Some(version) => self.flash(&format!("Version {version} is available: run codync-host update")),- None => self.flash("The host is up to date."),+ After::Update => match (v["state"]["availableVersion"].as_str(), v["state"]["requiredApp"].as_str()) {+ (Some(version), Some(app)) => self.flash(&match v["state"]["appStoreVersion"].as_str() {+ Some(store) => format!(+ "Version {version} waits for the iPhone app {app} (App Store has {store}); it installs after review"+ ),+ None => format!(+ "Version {version} waits: couldn't check the App Store for the iPhone app {app}. \+ codync-host update --skip-app-check installs anyway"+ ),+ }),+ (Some(version), None) => self.flash(&format!("Version {version} is available: run codync-host update")),+ (None, _) => self.flash("The host is up to date."),},After::Thread => {for e in v["entries"].as_array().into_iter().flatten() {diff --git a/host/src/update/install.rs b/host/src/update/install.rsindex a136a316..69465213 100644--- a/host/src/update/install.rs+++ b/host/src/update/install.rs@@ -107,7 +107,44 @@ whereOk(())}-pub async fn apply(release: &release::Release, target: &Path, port: u16, force: bool) -> Result<()> {+/// Whether iPhones use this host: asked of the running host, assumed when it can't answer.+async fn iphones_paired(port: u16) -> bool {+ let devices = async {+ let token = std::fs::read_to_string(service::data_dir().join("token")).ok()?;+ let res: serde_json::Value = crate::http()+ .post(format!("http://127.0.0.1:{port}/api/devices"))+ .bearer_auth(token.trim())+ .json(&serde_json::json!({}))+ .timeout(Duration::from_secs(5))+ .send()+ .await+ .ok()?+ .error_for_status()+ .ok()?+ .json()+ .await+ .ok()?;+ Some(res["devices"].as_array()?.iter().any(|d| d["platform"] == "ios"))+ };+ devices.await.unwrap_or(true)+}++/// The `minApp` a downloaded (verified) executable declares.+async fn staged_min_app(stage: &Path) -> Result<String> {+ let output = tokio::process::Command::new(stage).arg("compat").kill_on_drop(true).output();+ let output = tokio::time::timeout(Duration::from_secs(10), output).await??;+ ensure!(output.status.success(), "the downloaded host couldn't report the iPhone app it needs");+ let compat: serde_json::Value = serde_json::from_slice(&output.stdout)?;+ compat["minApp"].as_str().map(str::to_owned).context("the downloaded host reported no minimum app version")+}++pub async fn apply(+ release: &release::Release,+ target: &Path,+ port: u16,+ force: bool,+ skip_app_check: bool,+) -> Result<crate::compat::Gate> {require_standalone(target)?;let managed = service::installed();if managed {@@ -134,6 +171,19 @@ pub async fn apply(release: &release::Release, target: &Path, port: u16, force:&& String::from_utf8_lossy(&output.stdout).trim() == format!("codync-host {}", release.version),"downloaded executable reported the wrong version");+ // Before anything stops: a release that needs a newer iPhone app than the App Store+ // has waits, so paired iPhones aren't asked for an update they can't get yet.+ if !skip_app_check {+ let new_min_app = staged_min_app(&stage).await?;+ if crate::compat::below(crate::compat::MIN_APP, &new_min_app) {+ let iphones = iphones_paired(port).await;+ let store = if iphones { crate::compat::app_store_version().await } else { Ok(None) };+ let gate = crate::compat::gate(crate::compat::MIN_APP, &new_min_app, iphones, &store);+ if gate != crate::compat::Gate::Proceed {+ return Ok(gate);+ }+ }+ }let old_hash = release::sha256(&std::fs::read(target)?);let new_hash = release::sha256(&std::fs::read(&stage)?);let identity = old_health.as_ref().and_then(|h| h["computerId"].as_str());@@ -167,7 +217,8 @@ pub async fn apply(release: &release::Release, target: &Path, port: u16, force:Ok(())},)- .await+ .await?;+ Ok(crate::compat::Gate::Proceed)}.await;let _ = std::fs::remove_file(stage);diff --git a/host/src/update/mod.rs b/host/src/update/mod.rsindex 4ace831f..2fd87e69 100644--- a/host/src/update/mod.rs+++ b/host/src/update/mod.rs@@ -23,6 +23,10 @@ struct State {available_version: Option<String>,checked_at: Option<i64>,error: Option<String>,+ /// `waitingForApp`: the iPhone app the available release needs.+ required_app: Option<String>,+ /// `waitingForApp`: what the App Store has (`None`: couldn't ask it).+ app_store_version: Option<String>,}fn read<T: serde::de::DeserializeOwned + Default>(name: &str) -> Result<T> {@@ -86,10 +90,17 @@ pub async fn check() -> Result<Value> {state.checked_at = Some(crate::store::now_ms());match release::latest().await {Ok(release) => {- state.available_version = (semver::Version::parse(&release.version)?+ let available = (semver::Version::parse(&release.version)?> semver::Version::parse(env!("CARGO_PKG_VERSION"))?).then_some(release.version);- state.phase = if state.available_version.is_some() { "available" } else { "upToDate" }.into();+ // Still the release that waits for the iPhone app: keep saying why.+ let waiting = state.phase == "waitingForApp" && available.is_some() && available == state.available_version;+ if !waiting {+ state.phase = if available.is_some() { "available" } else { "upToDate" }.into();+ state.required_app = None;+ state.app_store_version = None;+ }+ state.available_version = available;state.error = None;}Err(error) => {@@ -103,7 +114,7 @@ pub async fn check() -> Result<Value> {status()}-pub async fn apply(port: u16, force: bool, worker: bool) -> Result<Value> {+pub async fn apply(port: u16, force: bool, skip_app_check: bool, worker: bool) -> Result<Value> {let deadline = tokio::time::Instant::now() + Duration::from_secs(5);let _lock = loop {match lock() {@@ -127,8 +138,15 @@ pub async fn apply(port: u16, force: bool, worker: bool) -> Result<Value> {state.available_version = Some(release.version.clone());state.phase = "installing".into();write("update-state.json", &state)?;- install::apply(&release, &target, port, force).await?;- state.phase = "complete".into();+ match install::apply(&release, &target, port, force, skip_app_check).await? {+ crate::compat::Gate::Proceed => state.phase = "complete".into(),+ // Not a failure: the next check installs it once the App Store has that app.+ crate::compat::Gate::WaitForApp { required, store } => {+ state.phase = "waitingForApp".into();+ state.required_app = Some(required);+ state.app_store_version = store;+ }+ }Ok::<_, anyhow::Error>(())}.await;@@ -149,7 +167,7 @@ pub async fn apply(port: u16, force: bool, worker: bool) -> Result<Value> {/// The updater must live outside the daemon's job/cgroup. Otherwise stopping/// the host would also kill the process responsible for starting its replacement.-pub fn spawn_worker(port: u16, force: bool) -> Result<()> {+pub fn spawn_worker(port: u16, force: bool, skip_app_check: bool) -> Result<()> {let _lock = lock()?;let previous: State = read("update-state.json")?;ensure!(!awaiting_worker(&previous), "a host update is already starting");@@ -164,8 +182,13 @@ pub fn spawn_worker(port: u16, force: bool) -> Result<()> {if force {args.push("--force".to_owned());}+ if skip_app_check {+ args.push("--skip-app-check".to_owned());+ }let mut state = State { phase: "scheduled".into(), checked_at: Some(crate::store::now_ms()), ..previous };state.error = None;+ state.required_app = None;+ state.app_store_version = None;write("update-state.json", &state)?;if let Err(error) = spawn_job(&executable, &args) {state.phase = "failed".into();@@ -225,7 +248,7 @@ pub async fn automatic_loop(hub: Arc<Hub>) {match check().await {Ok(status) if status["state"]["availableVersion"].is_string() => {let port = hub.port;- match tokio::task::spawn_blocking(move || spawn_worker(port, false)).await {+ match tokio::task::spawn_blocking(move || spawn_worker(port, false, false)).await {Ok(Ok(())) => {}result => tracing::warn!(?result, "could not start automatic host update"),}