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.

Clearer agent crash reports, gentler usage polling, relay error handling

leepokaic3a3ade427ac
diff --git a/README.md b/README.md
index e1c4ab7f..51a1a9ba 100644
--- a/README.md
+++ b/README.md
@@ -64,7 +64,7 @@ Optional: show usage in Claude Code's status line and feed live limits to the ho
| `codync-host statusline` | Claude Code status line command |
| `codync-host reset-token` | unpair every phone |
-Data lives in `~/.codync` (`codync.db`, `token`, `host.log`). The API is `POST /api/<method>` + `GET /events` (SSE), both with `Authorization: Bearer <token>`; see `host/src/api.rs`.
+Data lives in `~/.codync` (`codync.db`, `token`, `host.log`). **The token is full access** — whoever has it can run agents in any folder on your computer. Prefer Tailscale over open Wi-Fi (the API is plain HTTP; Tailscale encrypts it), and `codync-host reset-token` if a phone is lost. The API is `POST /api/<method>` + `GET /events` (SSE), both with `Authorization: Bearer <token>`; see `host/src/api.rs`.
## Repository
diff --git a/host/src/bot.rs b/host/src/bot.rs
index 14f02cbe..4792d888 100644
--- a/host/src/bot.rs
+++ b/host/src/bot.rs
@@ -47,6 +47,7 @@ pub fn spawn(hub: Arc<Hub>, cfg: BotConfig) -> BotHandle {
last_text: None,
perms: HashMap::new(),
stop_requested: false,
+ exit_tail: None,
};
tokio::spawn(actor.run(rx));
BotHandle { tx }
@@ -87,6 +88,8 @@ struct Actor {
/// permission entry id -> JSON-RPC request id
perms: HashMap<String, Value>,
stop_requested: bool,
+ /// Last stderr lines of an agent process that just exited.
+ exit_tail: Option<String>,
}
type Done = Result<Value>;
@@ -204,6 +207,7 @@ impl Actor {
}
self.turn = Some(turn);
self.stop_requested = false;
+ self.exit_tail = None;
self.seg = Seg::None;
self.tools.clear();
self.plan_entry = None;
@@ -360,7 +364,11 @@ impl Actor {
Err(_) => "error".into(),
};
match (&done, stop_reason.as_str()) {
- (Err(e), _) if !self.stop_requested => self.notice(&format!("The agent failed: {e}"), "error"),
+ (Err(e), _) if !self.stop_requested => {
+ let tail = self.exit_tail.take().filter(|t| !t.is_empty());
+ let detail = tail.map(|t| format!("\n\n{}", acp::truncate(&t, 1200))).unwrap_or_default();
+ self.notice(&format!("The agent failed: {e}{detail}"), "error")
+ }
(_, "cancelled") | (Err(_), _) => self.notice("Stopped.", "info"),
(_, "max_tokens") => self.notice("The agent hit its output limit.", "info"),
(_, "max_turn_requests") => self.notice("The agent hit its step limit for this turn.", "info"),
@@ -391,11 +399,8 @@ impl Actor {
_ => String::new(),
};
self.conn = None;
- if self.turn.is_some() {
- let detail = if tail.is_empty() { String::new() } else { format!("\n\n{}", acp::truncate(&tail, 1200)) };
- self.notice(&format!("The agent process exited.{detail}"), "error");
- }
- // The in-flight prompt request resolves with an error and finishes the turn.
+ // The in-flight prompt request resolves with an error; finish_turn reports it with this output.
+ self.exit_tail = Some(tail);
}
Some(Incoming::Notification { method, params }) => {
if method == "session/update" && params["sessionId"].as_str() == self.session_id.as_deref() && self.turn.is_some() {
diff --git a/host/src/usage.rs b/host/src/usage.rs
index 5d6badba..9a74f87d 100644
--- a/host/src/usage.rs
+++ b/host/src/usage.rs
@@ -35,11 +35,25 @@ pub async fn poll(hub: Arc<Hub>) {
}
}
+static CLAUDE_BACKOFF_UNTIL: std::sync::Mutex<Option<std::time::Instant>> = std::sync::Mutex::new(None);
+
pub async fn refresh(hub: &Hub) {
- match claude_oauth_usage().await {
- Ok(Some(p)) => merge(hub, p),
- Ok(None) => {}
- Err(e) => tracing::debug!("claude usage: {e}"),
+ // Live statusline data beats polling an undocumented endpoint.
+ let fresh_statusline = hub.usage.lock().unwrap()["providers"]
+ .as_array()
+ .into_iter()
+ .flatten()
+ .any(|p| p["id"] == "claude" && p["source"] == "statusline" && p["updatedAt"].as_i64().is_some_and(|t| crate::store::now_ms() - t < 600_000));
+ let backing_off = CLAUDE_BACKOFF_UNTIL.lock().unwrap().is_some_and(|t| std::time::Instant::now() < t);
+ if !fresh_statusline && !backing_off {
+ match claude_oauth_usage().await {
+ Ok(Some(p)) => merge(hub, p),
+ Ok(None) => {}
+ Err(e) => {
+ tracing::debug!("claude usage: {e}");
+ *CLAUDE_BACKOFF_UNTIL.lock().unwrap() = Some(std::time::Instant::now() + Duration::from_secs(3600));
+ }
+ }
}
if let Some(p) = tokio::task::spawn_blocking(codex_usage).await.ok().flatten() {
merge(hub, p);
@@ -64,8 +78,12 @@ fn claude_token() -> Option<String> {
let raw = if cfg!(target_os = "macos") {
let out = std::process::Command::new("security")
.args(["find-generic-password", "-s", "Claude Code-credentials", "-w"])
+ .stdin(std::process::Stdio::null())
.output()
.ok()?;
+ if !out.status.success() {
+ return None;
+ }
String::from_utf8(out.stdout).ok()?
} else {
std::fs::read_to_string(dirs::home_dir()?.join(".claude/.credentials.json")).ok()?
diff --git a/relay/src/index.ts b/relay/src/index.ts
index 3521b024..173fba1b 100644
--- a/relay/src/index.ts
+++ b/relay/src/index.ts
@@ -138,10 +138,12 @@ async function push(req: Request, env: Env): Promise<Response> {
}
return json({ ok: true });
} catch (err) {
- const message = err instanceof Error ? err.message : String(err);
- // 410 Unregistered / BadDeviceToken: tell the host to drop the ticket.
- const gone = /Unregistered|BadDeviceToken|ExpiredToken/.test(message);
- return json({ error: message, gone }, gone ? 410 : 502);
+ // ApnsError carries APNs' `reason` (e.g. "Unregistered") and `statusCode`.
+ const e = err as { reason?: string; statusCode?: number; message?: string };
+ const reason = e.reason ?? e.message ?? String(err);
+ // Dead device token: tell the host to drop the ticket.
+ const gone = e.statusCode === 410 || /Unregistered|BadDeviceToken|ExpiredToken/.test(reason);
+ return json({ error: reason, gone }, gone ? 410 : 502);
}
}