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): advertise your own HTTPS address to phones
leepokai8676e6a2fecf
diff --git a/docs/guides/linux-servers.md b/docs/guides/linux-servers.mdindex 23183ace..7cf3758a 100644--- a/docs/guides/linux-servers.md+++ b/docs/guides/linux-servers.md@@ -32,10 +32,11 @@ Other commands work the same as on a desktop: `codync-host pair`, `codync-host t## Reaching it from the phone-The phone connects over the encrypted device channel. The pairing link lists only **Tailscale** and **private (LAN/VPC)** addresses; the host never advertises a public IP.+The phone connects over the encrypted device channel. The pairing link lists only **Tailscale** and **private (LAN/VPC)** addresses, plus any you set in `CODYNC_EXTERNAL_URL`; the host never advertises a public IP on its own.- **Tailscale (recommended for VMs):** install Tailscale on the VM and on the phone, then `codync-host pair`. The Tailscale name comes first in the link. You don't need to open port 19222 in the cloud firewall.- **Cloudflare cloud:** start the host with `CODYNC_CLOUD_URL=https://…` if you run your own Codync cloud. The production cloud isn't live yet (see [environments](environments-and-deployment.md)).+- **Your own HTTPS reverse proxy:** forward only `/channel` (WebSocket upgrade) at the root of a hostname to the host; don't forward `/api`, `/events`, `/term` or `/oauth`: through a local proxy every request looks like it comes from this computer, so the loopback-only checks no longer protect them. Then set `CODYNC_EXTERNAL_URL=https://codync.example.com` (comma-separated for several) in the host's environment: `systemctl --user edit codync-host`, add `[Service]` and `Environment=CODYNC_EXTERNAL_URL=https://codync.example.com`, then `systemctl --user restart codync-host`. The host advertises those URLs first, in the pairing link and on every connection, so the phone keeps them (a phone keeps only the addresses the host advertises). Under your own supervisor, `CODYNC_EXTERNAL_URL=… codync-host serve --bind 127.0.0.1` keeps the host on loopback behind the proxy.- **Desktop app over SSH:** the desktop app (macOS or Linux) can attach an SSH computer and tunnel to its loopback API ([Accounts and SSH](accounts-and-ssh.md)). From any terminal: `ssh -L 19222:127.0.0.1:19222 vm`, then `codync-host tui` locally.The host listens on `0.0.0.0:19222`. The local API (`/api/*`, `/events`, terminals; bearer token) answers **loopback callers only**, so a public address never exposes it. From outside, only `/health` (host id, computer id, version) and the end-to-end encrypted device channel answer, and the channel only serves devices holding this host's pairing keys. Keep 19222 closed in the cloud firewall anyway unless you deliberately pair over a VPN or private network.diff --git a/docs/reference/remote-relay.md b/docs/reference/remote-relay.mdindex c11dfd2b..73320346 100644--- a/docs/reference/remote-relay.md+++ b/docs/reference/remote-relay.md@@ -134,7 +134,7 @@ codync://pair?v=3&name=<pct>&id=<computerId>&sk=<signPub>&bk=<boxPub>&code=<pair| `id` | 是 | 必須等於 `computerId(sk)`,否則拒絕 || `sk`, `bk` | 是 | host 公鑰 || `code` | 是 | 16 random bytes,b64url;一次性、10 分鐘;host 最多同時 5 組(新的擠掉最舊的) |-| `urls` | 否 | 直連候選(既有 `service::addresses`,`http://ip:port` 形式),可為空 |+| `urls` | 否 | 直連候選(`service::addresses`):先 `CODYNC_EXTERNAL_URL` 設的網址(`https://host` 等,只能是 host 根路徑),再 Tailscale,再 LAN(`http://ip:port`);可為空 || `cloud` | 否 | host 使用的 cloud base URL(`https://…`;DEBUG build 另允許 `http://127.0.0.1:*`/`http://localhost:*`);缺 = host 關閉雲端 || `name` | 否 | 顯示名稱 |@@ -417,7 +417,7 @@ Channel 訊息與 DO 訊息的 `t` 值不重疊:channel 只有 `hello`/`welcom### 7.5 Client 連線策略(Apple 與整合測試共通)-1. 平行對所有 `urls`(`http://h:p` → `ws://h:p/channel?v=1`)開 WebSocket 並握手;**1.5 秒**內第一個完成握手的勝出。+1. 平行對所有 `urls`(`http://h:p` → `ws://h:p/channel?v=1`,`https://h` → `wss://h/channel?v=1`)開 WebSocket 並握手;**1.5 秒**內第一個完成握手的勝出。2. 都失敗且有 `cloud` → 連 `{cloud}/v1/relay/device/{computerId}`。每次收到 `presence online:true` 就(重新)送 `hello`;`online:false` → 狀態 `computerOffline(lastSeen)`,保持 socket(可用 mailbox),等下一個 `online:true`。3. 兩者都不可用 → `offline("Can't reach …")`,退避重試。4. App 回前景、網路路徑改變(`NWPathMonitor`)→ 重新跑 1–3(可能從中繼換回直連);events 以當前 `rev` 重新訂閱。diff --git a/host/src/main.rs b/host/src/main.rsindex e8b68252..e3e518f9 100644--- a/host/src/main.rs+++ b/host/src/main.rs@@ -620,7 +620,9 @@ async fn pair(port: u16, as_json: bool) -> Result<()> {println!("Scan with the Codync iOS app within 10 minutes, or open this link on the phone:\n{url}\n");if hello["cloud"].is_null()&& p["urls"].as_array().is_none_or(|u| {- !u.iter().any(|u| u.as_str().is_some_and(|u| u.contains("://100.") || u.contains(".ts.net")))+ !u.iter().any(|u| {+ u.as_str().is_some_and(|u| u.contains("://100.") || u.contains(".ts.net") || u.starts_with("https://"))+ })}){println!(diff --git a/host/src/service/mod.rs b/host/src/service/mod.rsindex cdeae10d..da71ee2a 100644--- a/host/src/service/mod.rs+++ b/host/src/service/mod.rs@@ -13,7 +13,7 @@ use sha2::{Digest, Sha256};use std::fmt::Write as _;use std::path::{Path, PathBuf};use std::process::{Child, Command, Stdio};-use std::sync::OnceLock;+use std::sync::{LazyLock, OnceLock};use std::time::{Duration, Instant};#[cfg(unix)]@@ -169,8 +169,11 @@ impl KeepAwake {}}-/// Addresses the phone can try, best first: Tailscale, then LAN.+/// Addresses the phone can try, best first: the ones set in `CODYNC_EXTERNAL_URL`, Tailscale, then LAN.pub fn addresses(port: u16) -> Vec<String> {+ // Read once: every hello asks, and a bad entry warns once.+ static EXTERNAL: LazyLock<Vec<String>> =+ LazyLock::new(|| external_urls(&std::env::var("CODYNC_EXTERNAL_URL").unwrap_or_default()));let mut tailscale = vec![];let mut lan = vec![];for iface in if_addrs::get_if_addrs().unwrap_or_default() {@@ -200,7 +203,37 @@ pub fn addresses(port: u16) -> Vec<String> {tailscale.dedup();lan.sort();lan.dedup();- tailscale.into_iter().chain(lan).collect()+ EXTERNAL.iter().cloned().chain(tailscale).chain(lan).collect()+}++/// Where phones reach this host besides its own interfaces, such as an HTTPS reverse proxy that forwards+/// `/channel`: comma-separated `http(s)://` URLs at the root of a host (phones dial `<url>/channel`). The pairing+/// link and every `hello` carry them, so a phone keeps them when it refreshes its addresses.+fn external_urls(var: &str) -> Vec<String> {+ var.split(',')+ .map(str::trim)+ .filter(|u| !u.is_empty())+ .filter_map(|u| match reqwest::Url::parse(u) {+ Ok(url)+ if matches!(url.scheme(), "http" | "https")+ && url.host().is_some()+ && url.username().is_empty()+ && url.password().is_none()+ && url.path() == "/"+ && url.query().is_none()+ && url.fragment().is_none() =>+ {+ Some(url.as_str().trim_end_matches('/').to_owned())+ }+ _ => {+ tracing::warn!(+ url = u,+ "CODYNC_EXTERNAL_URL entry isn't an http(s) URL at the root of a host (no user or password); ignored"+ );+ None+ }+ })+ .collect()}pub fn host_name() -> String {@@ -387,6 +420,17 @@ mod tests {);}+ #[test]+ fn external_urls_keep_http_addresses_only() {+ assert_eq!(+ external_urls(+ " https://codync.example.com/ , ftp://x, nonsense,http://10.0.0.2:8080,https://x.com/codync,https://x.com/?a,https://u:[email protected]"+ ),+ ["https://codync.example.com", "http://10.0.0.2:8080"]+ );+ assert_eq!(external_urls(""), [] as [String; 0]);+ }+#[test]fn mac_models_map_to_devices() {assert_eq!(mac_device("MacBook Pro"), Device::Laptop);