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.

fix(host): stop reporting a signed-out Claude as signed in on slow machines

leepokaif95b9fffd948
diff --git a/docs/architecture/file-structure.md b/docs/architecture/file-structure.md
index f0df9f43..f4a5c7ff 100644
--- a/docs/architecture/file-structure.md
+++ b/docs/architecture/file-structure.md
@@ -95,7 +95,7 @@ Codync/
| Prompt snapshots and memory | `host/src/chat/context.rs`, `memory/` (`api.rs`, `tools.rs`, `notices.rs`, `dream.rs`, `import.rs`; long-form files in `files.rs`, `file_api.rs`, `file_tools.rs`, `file_notices.rs`); the rules in `host/crates/memory` (`codync-mem`, files in `files.rs`, dreaming in `dream/`); harnesses' own memory turned off in `host/src/agent/own_memory.rs` |
| Identity, encryption and direct channel | `host/src/remote/identity.rs`, `crypto.rs`, `channel.rs` |
| Host cloud state and relay connection | `host/src/remote/cloud.rs`, `relay.rs` |
-| Agent discovery, sign-in, setup terminal, Node.js for npm agents | `host/src/agent/backends.rs`, `registry.rs`, `auth.rs`, `term.rs`, `node.rs` |
+| Agent discovery, sign-in, setup terminal, Node.js for npm agents | `host/src/agent/backends.rs` (+ `backends/sign_in.rs`), `registry.rs`, `auth.rs`, `term.rs`, `node.rs` |
| Fast mode (session config option) | `host/src/agent/config.rs`, `agent/bot/fast_mode.rs` |
| Marketplace, Composio, connector OAuth | `host/src/market/` |
| Screen bridge and built-in MCP tools | `host/src/screen/`, `mcp.rs` |
diff --git a/host/src/agent/auth.rs b/host/src/agent/auth.rs
index 49516043..c928f913 100644
--- a/host/src/agent/auth.rs
+++ b/host/src/agent/auth.rs
@@ -1,9 +1,11 @@
//! Signing agents in the ACP way, so every agent that speaks ACP can be set up
//! from Codync, not just the ones we know by name.
//!
-//! A check starts the agent, reads the `authMethods` it advertises and takes the
-//! login it reports (`_auth/status_update`), or else tries `session/new`: `-32000`
-//! means it needs signing in. Methods come in three kinds:
+//! A check starts the agent and reads the `authMethods` it advertises. An agent that
+//! reports its login (`_auth/status_update`) is believed; when its report doesn't
+//! come, the harness's own CLI check decides, else it can't tell (a session proves
+//! nothing for it). Other agents get `session/new`: `-32000` means it needs signing
+//! in. Methods come in three kinds:
//! - terminal: a command (the agent's `_meta.terminal-auth`, or its own binary
//! with `args`), run in a setup terminal (`term`);
//! - agent: the agent signs itself in on `authenticate` (usually a browser on
@@ -21,6 +23,7 @@ use anyhow::{Context, Result, anyhow, bail};
use serde::Serialize;
use serde_json::{Map, Value, json};
use std::collections::BTreeMap;
+use std::ops::ControlFlow;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::time::Duration;
@@ -222,13 +225,11 @@ fn model_options(options: &Value, model: &str) -> Vec<Value> {
async fn probe(store: &Store, backend: &str) -> Result<Status> {
let (acp, mut inbox, init, cmd) = start(store, backend).await?;
let methods = methods(backend, &init, &cmd);
- // An agent that reports its login is believed over a session: Claude's adapter opens one
- // without checking the login, which then fails at the first prompt.
- if init["agentCapabilities"]["_meta"]["authStatus"].is_object()
- && let Some(signed_in) = reported_login(&mut inbox).await
+ if let ControlFlow::Break(signed_in) =
+ login_without_session(&init, &mut inbox, backend, &env(store, backend)?).await
{
acp.kill().await;
- return Ok(Status { signed_in: Some(signed_in), detail: None, methods });
+ return Ok(Status { signed_in, detail: None, methods });
}
let dir = probe_dir();
tokio::fs::create_dir_all(&dir).await?;
@@ -249,6 +250,29 @@ async fn probe(store: &Store, backend: &str) -> Result<Status> {
Ok(Status { signed_in, detail, methods })
}
+/// `Break`: the login of an agent that reports it, never judged by a session: Claude's adapter
+/// opens one without checking the login, which then fails at the first prompt. When its report
+/// doesn't come (the adapter gives its own `claude auth status` 5 s, too few on many Windows
+/// computers), the harness's CLI check decides, with more time and the agent's `env`, else it
+/// can't tell. `Continue`: the agent doesn't report its login, so a session tells.
+async fn login_without_session(
+ init: &Value,
+ inbox: &mut mpsc::UnboundedReceiver<Incoming>,
+ backend: &str,
+ env: &[(String, String)],
+) -> ControlFlow<Option<bool>> {
+ if !init["agentCapabilities"]["_meta"]["authStatus"].is_object() {
+ return ControlFlow::Continue(());
+ }
+ if let Some(reported) = reported_login(inbox).await {
+ return ControlFlow::Break(Some(reported));
+ }
+ ControlFlow::Break(match backends::harness(backend) {
+ Some(h) => backends::cli_signed_in(h, env).await,
+ None => None,
+ })
+}
+
/// The agent's first `_auth/status_update` (ACP `authStatus` extension): `kind: "none"` is signed
/// out, any other kind signed in. `None`: it can't tell (it stays silent then).
async fn reported_login(inbox: &mut mpsc::UnboundedReceiver<Incoming>) -> Option<bool> {
@@ -563,6 +587,22 @@ mod tests {
assert_eq!(reported_login(&mut rx).await, None, "an agent that goes quiet can't tell");
}
+ #[tokio::test]
+ async fn an_agent_that_reports_its_login_is_never_judged_by_a_session() {
+ let reports = json!({"agentCapabilities": {"_meta": {"authStatus": {}}}});
+ let (tx, mut rx) = mpsc::unbounded_channel();
+ tx.send(Incoming::Notification {
+ method: "_auth/status_update".into(),
+ params: json!({"authStatus": {"kind": "none"}}),
+ })
+ .unwrap();
+ assert_eq!(login_without_session(&reports, &mut rx, "x", &[]).await, ControlFlow::Break(Some(false)));
+ drop(tx);
+ // No report and no CLI check: it can't tell, and still opens no session.
+ assert_eq!(login_without_session(&reports, &mut rx, "x", &[]).await, ControlFlow::Break(None));
+ assert_eq!(login_without_session(&json!({}), &mut rx, "x", &[]).await, ControlFlow::Continue(()));
+ }
+
#[test]
fn skips_terminal_commands_of_another_harness() {
let init = json!({"authMethods": [{"id": "k", "name": "Kilo", "_meta": {"terminal-auth": {"command": "opencode", "args": ["auth", "login"]}}}]});
diff --git a/host/src/agent/backends.rs b/host/src/agent/backends.rs
index a87d465e..e1cc0069 100644
--- a/host/src/agent/backends.rs
+++ b/host/src/agent/backends.rs
@@ -13,7 +13,10 @@ use serde_json::{Value, json};
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
-use std::time::Duration;
+
+mod sign_in;
+pub use sign_in::{SignInCheck, cli_signed_in, refresh_sign_in, set_signed_in, signed_in};
+use sign_in::{claude_signed_in, exit_ok, qoder_signed_in, says_logged_in};
pub struct Harness {
pub id: &'static str,
@@ -58,30 +61,6 @@ impl Install {
}
}
-/// `<bin> <args>`, judged by exit code and stdout.
-#[derive(Clone, Copy)]
-pub struct SignInCheck {
- pub args: &'static str,
- pub ok: fn(bool, &str) -> bool,
-}
-
-fn exit_ok(success: bool, _: &str) -> bool {
- success
-}
-
-fn claude_signed_in(_: bool, out: &str) -> bool {
- serde_json::from_str::<Value>(out).is_ok_and(|v| v["loggedIn"] == true)
-}
-
-fn qoder_signed_in(_: bool, out: &str) -> bool {
- serde_json::from_str::<Value>(out).is_ok_and(|v| v["logged_in"] == true)
-}
-
-fn says_logged_in(_: bool, out: &str) -> bool {
- let out = out.to_lowercase();
- out.contains("logged in") && !out.contains("not logged in")
-}
-
pub const HARNESSES: &[Harness] = &[
Harness {
id: "claude",
@@ -613,53 +592,6 @@ pub fn list() -> Vec<Value> {
out
}
-// MARK: sign-in
-
-/// Last sign-in check per harness id; missing = can't tell.
-static SIGNED_IN: Mutex<Vec<(String, bool)>> = Mutex::new(Vec::new());
-
-pub fn signed_in(id: &str) -> Option<bool> {
- SIGNED_IN.locked().iter().find(|(h, _)| h == id).map(|(_, ok)| *ok)
-}
-
-/// Records what a check found (`None`: can't tell).
-pub fn set_signed_in(id: &str, state: Option<bool>) {
- let mut map = SIGNED_IN.locked();
- map.retain(|(h, _)| h != id);
- if let Some(ok) = state {
- map.push((id.to_owned(), ok));
- }
-}
-
-/// Re-checks every installed harness that can report its sign-in state.
-pub async fn refresh_sign_in() {
- let checks = HARNESSES.iter().filter_map(|h| {
- let check = h.signed_in?;
- let bin = h.bins.iter().find_map(|b| which(b))?;
- Some(async move {
- let run = tokio::process::Command::new(bin)
- .args(check.args.split_whitespace())
- .stdin(std::process::Stdio::null())
- .stderr(std::process::Stdio::null())
- .kill_on_drop(true)
- .output();
- let ok = match tokio::time::timeout(Duration::from_secs(15), run).await {
- Ok(Ok(out)) => Some((check.ok)(out.status.success(), &String::from_utf8_lossy(&out.stdout))),
- Ok(Err(e)) => {
- tracing::info!(backend = h.id, error = %e, "sign-in check failed");
- None
- }
- Err(_) => None,
- };
- (h.id, ok)
- })
- });
- let results = futures::future::join_all(checks).await;
- for (id, ok) in results {
- set_signed_in(id, ok);
- }
-}
-
/// `program` is some other harness's CLI (not `backend`'s own).
pub fn belongs_to_other(backend: &str, program: &str) -> bool {
let name = Path::new(program).file_name().and_then(|n| n.to_str()).unwrap_or(program);
diff --git a/host/src/agent/backends/sign_in.rs b/host/src/agent/backends/sign_in.rs
new file mode 100644
index 00000000..78601001
--- /dev/null
+++ b/host/src/agent/backends/sign_in.rs
@@ -0,0 +1,79 @@
+//! Whether each harness is signed in, as its own CLI tells it.
+
+use super::{HARNESSES, Harness, on_path, which};
+use crate::LockExt;
+use serde_json::Value;
+use std::sync::Mutex;
+use std::time::Duration;
+
+/// `<bin> <args>`, judged by exit code and stdout.
+#[derive(Clone, Copy)]
+pub struct SignInCheck {
+ pub args: &'static str,
+ pub ok: fn(bool, &str) -> bool,
+}
+
+pub(super) fn exit_ok(success: bool, _: &str) -> bool {
+ success
+}
+
+pub(super) fn claude_signed_in(_: bool, out: &str) -> bool {
+ serde_json::from_str::<Value>(out).is_ok_and(|v| v["loggedIn"] == true)
+}
+
+pub(super) fn qoder_signed_in(_: bool, out: &str) -> bool {
+ serde_json::from_str::<Value>(out).is_ok_and(|v| v["logged_in"] == true)
+}
+
+pub(super) fn says_logged_in(_: bool, out: &str) -> bool {
+ let out = out.to_lowercase();
+ out.contains("logged in") && !out.contains("not logged in")
+}
+
+/// Last sign-in check per harness id; missing = can't tell.
+static SIGNED_IN: Mutex<Vec<(String, bool)>> = Mutex::new(Vec::new());
+
+pub fn signed_in(id: &str) -> Option<bool> {
+ SIGNED_IN.locked().iter().find(|(h, _)| h == id).map(|(_, ok)| *ok)
+}
+
+/// Records what a check found (`None`: can't tell).
+pub fn set_signed_in(id: &str, state: Option<bool>) {
+ let mut map = SIGNED_IN.locked();
+ map.retain(|(h, _)| h != id);
+ if let Some(ok) = state {
+ map.push((id.to_owned(), ok));
+ }
+}
+
+/// Re-checks every installed harness that can report its sign-in state.
+pub async fn refresh_sign_in() {
+ let installed = HARNESSES.iter().filter(|h| h.signed_in.is_some() && h.bins.iter().any(|b| on_path(b)));
+ let results =
+ futures::future::join_all(installed.map(|h| async move { (h.id, cli_signed_in(h, &[]).await) })).await;
+ for (id, ok) in results {
+ set_signed_in(id, ok);
+ }
+}
+
+/// What `h`'s own CLI says about its sign-in, run with `env` (the keys its agent gets, so both
+/// judge the same login). `None`: it has no such check, isn't installed or didn't answer.
+pub async fn cli_signed_in(h: &Harness, env: &[(String, String)]) -> Option<bool> {
+ let check = h.signed_in?;
+ let bin = h.bins.iter().find_map(|b| which(b))?;
+ let run = tokio::process::Command::new(bin)
+ .args(check.args.split_whitespace())
+ .envs(env.iter().map(|(k, v)| (k, v)))
+ .stdin(std::process::Stdio::null())
+ .stderr(std::process::Stdio::null())
+ .kill_on_drop(true)
+ .output();
+ match tokio::time::timeout(Duration::from_secs(15), run).await {
+ Ok(Ok(out)) => Some((check.ok)(out.status.success(), &String::from_utf8_lossy(&out.stdout))),
+ Ok(Err(e)) => {
+ tracing::info!(backend = h.id, error = %e, "sign-in check failed");
+ None
+ }
+ Err(_) => None,
+ }
+}