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): follow Registry connector updates
leepokaie8af104ef4e5
diff --git a/docs/features/marketplace.md b/docs/features/marketplace.mdindex b243fdea..65857a17 100644--- a/docs/features/marketplace.md+++ b/docs/features/marketplace.md@@ -17,6 +17,8 @@ A custom connector is a command line (split like a shell), a URL, or a pasted MCA connector installed on the computer (or an app connected through Composio) is turned on for every existing bot, and a new bot starts with all of them on; each bot can turn one off in its settings. An enabled connector is passed to the agent as an MCP server when its session starts or resumes. Local connectors are spawned by the agent; remote ones always go through the host's stdio proxy (`codync-host mcp remote`, `host/src/mcp.rs`), so they work with agents that only speak stdio and always carry a fresh token. The proxy speaks streamable HTTP and falls back to the older HTTP+SSE transport when the first POST fails with 400/404/405, as the MCP spec suggests.+Registry-backed package connectors follow their upstream release. The host checks the Registry periodically after credentials are unlocked and checks again immediately before a package process starts. If a newer pinned npm, PyPI, OCI or NuGet reference is available, only that package/image argument is replaced; the running process is not interrupted, and the new version applies on its next launch. Network failures, missing packages and attempted downgrades leave the installed reference unchanged. Custom command connectors are never updated automatically.+## Sign-in for remote connectors (`host/src/market/oauth.rs`)Installing a remote connector probes it; a 401 marks it `signedOut` and bots don't get it until someone signs in. Sign-in follows the MCP authorization spec: protected-resource metadata → authorization-server metadata → dynamic client registration (both redirect URIs at once) → PKCE. Tokens stay on the computer and are refreshed on use (or after a 401).diff --git a/host/src/api/marketplace.rs b/host/src/api/marketplace.rsindex 22ab50c1..e33942d2 100644--- a/host/src/api/marketplace.rs+++ b/host/src/api/marketplace.rs@@ -88,9 +88,13 @@ pub(super) async fn call(hub: &Arc<Hub>, caller: &Caller, method: &str, b: Valuemarket::passwords::set_token(&hub.store, b["token"].as_str().unwrap_or_default()).await?}"connectorRuntime" => {+ let id = str_arg(&b, "id")?;+ // Registry-backed packages may advance between background checks;+ // refresh just before launch so the new version applies next run.+ market::refresh_connector(&hub.store, id).await;let c = market::connectors(&hub.store)?.into_iter()- .find(|c| Some(c.id.as_str()) == b["id"].as_str())+ .find(|c| c.id == id).ok_or_else(|| anyhow!("Unknown connector"))?;let mut env = serde_json::Map::new();for (k, v) in &c.env {diff --git a/host/src/background.rs b/host/src/background.rsindex 989a0b00..45695faf 100644--- a/host/src/background.rs+++ b/host/src/background.rs@@ -9,9 +9,10 @@ use crate::{};use std::sync::Arc;-pub fn start(hub: Arc<Hub>) {+pub fn start(hub: &Arc<Hub>) {tokio::spawn(registry::refresh_loop());tokio::spawn(market::refresh_first_page());+ tokio::spawn(market::automatic_loop(hub.clone()));tokio::spawn(voice::refresh_loop(hub.clone()));tokio::spawn(backends::refresh_sign_in());tokio::spawn(usage::poll(hub.clone()));diff --git a/host/src/main.rs b/host/src/main.rsindex 355d824d..15475ed6 100644--- a/host/src/main.rs+++ b/host/src/main.rs@@ -514,7 +514,7 @@ async fn serve(bind: &str, port: u16) -> Result<()> {tokio::task::spawn_blocking(backends::hydrate_path).await?;let hub = hub::Hub::new(store, host_id, identity, token, port);hub.start()?;- background::start(hub.clone());+ background::start(&hub);tracing::info!(version = env!("CARGO_PKG_VERSION"), bind, port, "codync-host listening");// Peer addresses: some settings may only be changed from this computer.let app = api::router(hub.clone()).into_make_service_with_connect_info::<std::net::SocketAddr>();diff --git a/host/src/market/install.rs b/host/src/market/install.rsindex 162a3b44..a5b3d0d6 100644--- a/host/src/market/install.rs+++ b/host/src/market/install.rs@@ -118,7 +118,7 @@ fn fill(template: Option<&str>, value: &str) -> String {/// The exact package reference passed to the runtime. OCI embeds its version in/// the identifier; server metadata cannot pin an otherwise floating image.-fn package_reference(p: &Value) -> Result<String> {+pub(super) fn package_reference(p: &Value) -> Result<String> {let id = p["identifier"].as_str().ok_or_else(|| anyhow!("package has no identifier"))?;let unpinned = || anyhow!("{id} has no pinned version in the MCP Registry, so it can't be installed safely");let pinned = |v: &str| !v.is_empty() && v != "latest" && !v.contains(['^', '~', '*', ' ']);diff --git a/host/src/market/mod.rs b/host/src/market/mod.rsindex 6ec979fc..9f2d141c 100644--- a/host/src/market/mod.rs+++ b/host/src/market/mod.rs@@ -27,11 +27,14 @@ pub mod verify;mod install;mod registry;mod skills;+mod updates;pub use install::{add_custom_connector, import_connectors, install_connector, list_connectors, remove_connector};pub use registry::{browse_connectors, connector_info, refresh_first_page};pub use skills::{add_custom_skill, browse_skills, install_skill, list_skills, remove_skill, skills_brief};+pub use updates::{automatic_loop, refresh_connector};+use crate::LockExt;use anyhow::{Result, bail};use serde::{Deserialize, Serialize};diff --git a/host/src/market/updates.rs b/host/src/market/updates.rsnew file mode 100644index 00000000..43fcf19d--- /dev/null+++ b/host/src/market/updates.rs@@ -0,0 +1,200 @@+//! Track Registry package releases without interrupting running connectors.++use super::{Connector, connectors, install::package_reference, registry::registry_server, update_connectors};+use crate::{LockExt, hub::Hub, store::Store};+use anyhow::{Result, anyhow, bail};+use serde_json::Value;+use std::{collections::HashMap, sync::Arc, time::Duration};+use tokio::time::Instant;++const CHECK_INTERVAL: Duration = Duration::from_secs(6 * 60 * 60);+const RETRY_INTERVAL: Duration = Duration::from_secs(15 * 60);+const POLL_INTERVAL: Duration = Duration::from_secs(60);++pub async fn automatic_loop(hub: Arc<Hub>) {+ let mut tracker = Tracker::default();+ loop {+ // Clients and bot sessions unlock the vault when needed. Background+ // updates must not cause an unsolicited keychain prompt at login.+ if hub.store.secret_key.locked().is_some()+ && let Err(error) = tracker.refresh_due(&hub.store, Instant::now(), registry_server).await+ {+ tracing::warn!(error = format!("{error:#}"), "connector update check failed");+ }+ tokio::time::sleep(POLL_INTERVAL).await;+ }+}++/// Refresh one connector immediately before its process is launched. A failed+/// lookup is deliberately ignored by callers so an installed version remains+/// usable while the Registry or network is unavailable.+pub async fn refresh_connector(store: &Store, id: &str) {+ let Some(before) = connectors(store).ok().and_then(|all| all.into_iter().find(|c| c.id == id)) else {+ return;+ };+ let Some(name) = before.registry_name.as_deref().filter(|_| PackageKind::for_connector(&before).is_some()) else {+ return;+ };+ match registry_server(name).await.and_then(|server| apply_latest(store, &before, &server)) {+ Ok(true) => tracing::info!(connector = id, "connector updated for its next launch"),+ Ok(false) => {}+ Err(error) => tracing::debug!(connector = id, error = format!("{error:#}"), "connector update unavailable"),+ }+}++#[derive(Default)]+struct Tracker {+ next_check: HashMap<String, Instant>,+}++impl Tracker {+ async fn refresh_due(+ &mut self,+ store: &Store,+ now: Instant,+ lookup: impl AsyncFn(&str) -> Result<Value>,+ ) -> Result<()> {+ let installed = connectors(store)?;+ self.next_check.retain(|id, _| installed.iter().any(|c| c.id == *id));+ for c in installed {+ let Some(name) = c.registry_name.as_deref().filter(|_| PackageKind::for_connector(&c).is_some()) else {+ continue;+ };+ if self.next_check.get(&c.id).is_some_and(|next| *next > now) {+ continue;+ }+ let result = match lookup(name).await {+ Ok(server) => apply_latest(store, &c, &server),+ Err(error) => Err(error),+ };+ let interval = match result {+ Ok(changed) => {+ if changed {+ tracing::info!(connector = c.id, "connector updated for its next launch");+ }+ CHECK_INTERVAL+ }+ Err(error) => {+ tracing::warn!(+ connector = c.id,+ error = format!("{error:#}"),+ "keeping installed connector version"+ );+ RETRY_INTERVAL+ }+ };+ self.next_check.insert(c.id, now + interval);+ }+ Ok(())+ }+}++#[derive(Clone, Copy, PartialEq)]+enum PackageKind {+ Npm,+ Pypi,+ Oci,+ Nuget,+}++impl PackageKind {+ fn for_connector(c: &Connector) -> Option<Self> {+ match c.command.as_deref()? {+ "npx" => Some(Self::Npm),+ "uvx" => Some(Self::Pypi),+ "docker" => Some(Self::Oci),+ "dnx" => Some(Self::Nuget),+ _ => None,+ }+ }++ fn registry_type(self) -> &'static str {+ match self {+ Self::Npm => "npm",+ Self::Pypi => "pypi",+ Self::Oci => "oci",+ Self::Nuget => "nuget",+ }+ }++ fn split_reference(self, reference: &str) -> Option<(&str, &str)> {+ match self {+ Self::Npm | Self::Nuget => reference.rsplit_once('@'),+ Self::Pypi => reference.split_once("=="),+ Self::Oci => {+ reference.split_once('@').or_else(|| reference.rsplit_once(':').filter(|(_, tag)| !tag.contains('/')))+ }+ }+ }+}++struct Replacement {+ index: usize,+ reference: String,+}++/// Match by runtime and package identity, never by the Registry array index.+/// Only the version-bearing argument changes; credentials and user flags stay put.+fn replacement(c: &Connector, server: &Value) -> Result<Option<Replacement>> {+ let Some(kind) = PackageKind::for_connector(c) else { return Ok(None) };+ let mut matched = None;+ for p in server["packages"].as_array().into_iter().flatten() {+ if p["registryType"] != kind.registry_type() || p["transport"]["type"].as_str().is_some_and(|t| t != "stdio") {+ continue;+ }+ let Some(id) = p["identifier"].as_str() else { continue };+ let identity =+ if kind == PackageKind::Oci { kind.split_reference(id).map_or(id, |(name, _)| name) } else { id };+ for (index, arg) in c.args.iter().enumerate() {+ let Some((name, old_version)) = kind.split_reference(arg) else { continue };+ if name != identity {+ continue;+ }+ if matched.is_some() {+ bail!("Registry package selection is ambiguous; keeping installed version");+ }+ let reference = package_reference(p)?;+ let (_, new_version) =+ kind.split_reference(&reference).ok_or_else(|| anyhow!("invalid package reference"))?;+ // Avoid downgrades when a stale Registry replica serves an older release.+ let parse = |v: &str| semver::Version::parse(v.strip_prefix('v').unwrap_or(v));+ if let (Ok(old), Ok(new)) = (parse(old_version), parse(new_version))+ && new < old+ {+ bail!("Registry returned an older package version; keeping installed version");+ }+ matched = Some(Replacement { index, reference });+ }+ }+ matched.map(Some).ok_or_else(|| anyhow!("installed package is no longer offered by the Registry"))+}++fn apply_latest(store: &Store, before: &Connector, server: &Value) -> Result<bool> {+ if before.registry_name.is_none() || before.command.is_none() {+ return Ok(false);+ }+ if server["name"].as_str() != before.registry_name.as_deref() {+ bail!("Registry returned a different server");+ }+ let Some(change) = replacement(before, server)? else { return Ok(false) };+ if before.args[change.index] == change.reference {+ return Ok(false);+ }+ update_connectors(store, |all| {+ let Some(current) = all.iter_mut().find(|c| c.id == before.id) else { return Ok(false) };+ // A concurrent credential edit is preserved. A removal or replacement+ // must never be undone by a lookup that started before it.+ if current.registry_name != before.registry_name+ || current.command != before.command+ || current.args != before.args+ {+ return Ok(false);+ }+ current.args[change.index] = change.reference;+ Ok(true)+ })+}++#[cfg(test)]+#[path = "updates_tests.rs"]+mod tests;diff --git a/host/src/market/updates_tests.rs b/host/src/market/updates_tests.rsnew file mode 100644index 00000000..a2428209--- /dev/null+++ b/host/src/market/updates_tests.rs@@ -0,0 +1,72 @@+use super::*;+use crate::market::save_connectors;+use serde_json::json;+use std::collections::BTreeMap;++fn connector(command: &str, args: &[&str]) -> Connector {+ Connector {+ id: "github".into(),+ name: "GitHub".into(),+ description: String::new(),+ registry_name: Some("io.github.github/github-mcp-server".into()),+ command: Some(command.into()),+ args: args.iter().map(|arg| (*arg).into()).collect(),+ env: BTreeMap::from([("TOKEN".into(), "secret".into())]),+ url: None,+ headers: BTreeMap::new(),+ oauth: None,+ }+}++fn server(kind: &str, identifier: &str, version: Option<&str>) -> Value {+ let mut package = json!({+ "registryType": kind,+ "identifier": identifier,+ "transport": {"type": "stdio"}+ });+ if let Some(version) = version {+ package["version"] = json!(version);+ }+ json!({+ "name": "io.github.github/github-mcp-server",+ "packages": [package]+ })+}++#[test]+fn updates_the_matching_package_argument_and_keeps_other_arguments() {+ let c = connector("npx", &["-y", "@scope/[email protected]", "--mode", "safe"]);+ let change = replacement(&c, &server("npm", "@scope/github-mcp", Some("1.3.0")))+ .expect("matching package")+ .expect("new version");+ assert_eq!(change.index, 1);+ assert_eq!(change.reference, "@scope/[email protected]");+}++#[test]+fn updates_oci_images_when_package_version_is_omitted() {+ let c = connector("docker", &["run", "-i", "--rm", "ghcr.io/github/github-mcp-server:2.0.2"]);+ let change = replacement(&c, &server("oci", "ghcr.io/github/github-mcp-server:2.0.3", None))+ .expect("matching image")+ .expect("new image");+ assert_eq!(change.index, 3);+ assert_eq!(change.reference, "ghcr.io/github/github-mcp-server:2.0.3");+}++#[test]+fn refuses_registry_downgrades() {+ let c = connector("npx", &["-y", "[email protected]"]);+ let result = replacement(&c, &server("npm", "github-mcp", Some("2.0.1")));+ assert!(result.is_err());+}++#[test]+fn apply_latest_preserves_credentials() {+ let store = Store::open(std::path::Path::new(":memory:")).expect("store");+ let before = connector("npx", &["-y", "[email protected]"]);+ save_connectors(&store, std::slice::from_ref(&before)).expect("save");+ assert!(apply_latest(&store, &before, &server("npm", "github-mcp", Some("1.1.0"))).expect("update"));+ let after = connectors(&store).expect("read").pop().expect("connector");+ assert_eq!(after.args, ["-y", "[email protected]"]);+ assert_eq!(after.env, before.env);+}