From d82b24c371594f0b240cb64b9028de476024326f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9A=E5=87=B1=20=E6=9D=8E?= Date: Sat, 5 Dec 2026 15:55:03 +0800 Subject: [PATCH 1/4] Add Codync as an ADE that opens in a terminal Codync runs coding agents as persistent bots you message from a phone, a desktop app or a terminal. Install Codync puts its host on the sandbox with Codync's own install script, runs it as a systemd user service with lingering, and Open in Codync opens Codync's terminal UI there over SSH, like Amp. Co-Authored-By: Claude Opus 5.5 --- CONTRIBUTING.md | 2 +- DEVELOPMENT.md | 6 +- README.md | 6 +- docs/ades.md | 36 ++++++- src-tauri/src/ade/codync.rs | 200 +++++++++++++++++++++++++++++++++++ src-tauri/src/ade/mod.rs | 86 ++++++++++++++- src-tauri/src/app.rs | 6 +- src/AdeCards.tsx | 2 +- src/ade.ts | 1 + src/ades.tsx | 8 +- src/assets/ade/codync.svg | 1 + src/assets/ade/sources.json | 3 +- src/hero/ade-logo.ts | 3 +- src/hero/hero-atmosphere.css | 7 ++ src/mode.ts | 2 +- src/preview.test.tsx | 5 +- src/preview.ts | 7 +- src/styles.css | 8 ++ src/types.ts | 6 +- 19 files changed, 367 insertions(+), 28 deletions(-) create mode 100644 src-tauri/src/ade/codync.rs create mode 100644 src/assets/ade/codync.svg diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 955ecb0..cee33c0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,7 +29,7 @@ An ADE fits InstaADE when it has a desktop app on macOS or Windows, or runs in a | Link | Opens a link from InstaADE and connects to the sandbox over SSH | cmux | | SSH host | Reaches the sandbox through a host in `~/.ssh/config`, which it imports or you add by its address | Orca, Paseo, Rex | | Host | Runs the sandbox as one of its hosts, set up in the ADE | Paradev | -| Terminal | Runs on the sandbox, and InstaADE opens it in your terminal over SSH | Herdr, Amp | +| Terminal | Runs on the sandbox, and InstaADE opens it in your terminal over SSH | Herdr, Amp, Codync | 1. Read [How InstaADE works with each ADE](docs/ades.md) to see how the ADEs differ. 2. Follow [Adding an ADE](DEVELOPMENT.md#adding-an-ade) for the files to change. diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 61197e1..ea6cad6 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -9,7 +9,7 @@ Read this before you change the code, open a pull request, build a preview or cu - `api/`: the instabox API client. `auth.rs`: device sign-in and token storage. - `sandbox/`: create, connect, sync and lifecycle of sandboxes. - `ade/`: the ADE registry (`mod.rs`) and one module per ADE (`t3.rs`, `cmux.rs`, `orca.rs`, `paradev.rs`, `paseo.rs`, `herdr.rs`, `amp.rs`, `rex.rs`), plus `herdr_desktop.rs`, the app Herdr opens in when it is installed. - - `ssh.rs`: the two SSH tokens of a sandbox (`Kind`: background and ordinary, see [SSH tokens](docs/ades.md#ssh-tokens)) and the login commands, and the terminal that Open in Terminal, Herdr and Amp open. `ssh_config.rs`: the SSH hosts InstaADE writes for Orca, Paseo and Herdr Desktop, with the background token, and the one line it adds to `~/.ssh/config`. + - `ssh.rs`: the two SSH tokens of a sandbox (`Kind`: background and ordinary, see [SSH tokens](docs/ades.md#ssh-tokens)) and the login commands, and the terminal that Open in Terminal, Herdr, Amp and Codync open. `ssh_config.rs`: the SSH hosts InstaADE writes for Orca, Paseo and Herdr Desktop, with the background token, and the one line it adds to `~/.ssh/config`. - `clipboard.rs`: copies a secret the user pastes once (Paradev's SSH address) and clears it a minute later, and copies Paseo's and Rex's host address, which holds no secret and stays. - `old_app.rs`: finds a copy of the app from before it was InstaADE, and moves it to the Trash (see [The old app](#the-old-app)). - `agents.rs`: signing Claude Code or Codex in on a sandbox. `github.rs`: signing GitHub's CLI in on a sandbox and setting up git there (see [GitHub sign-in](docs/ades.md#github-sign-in)). `repos.rs`: the GitHub repos `gh` lists on a sandbox, the repo names InstaADE takes, and the check of a repo's folder there (see [Bring your repo](docs/ades.md#bring-your-repo)). `settings.rs`: the app's saved settings, `settings.json`, which keep Later on that sign-in and Done on Orca's and Paseo's next steps (see [Next steps](docs/ades.md#next-steps)). `tray.rs`: the menu bar popover. `login.rs`: start at login. @@ -62,8 +62,8 @@ cargo test Pull requests that add an ADE are welcome. Read [How InstaADE works with each ADE](docs/ades.md) first to see how the current ADEs differ. - Registry: `src-tauri/src/ade/mod.rs` defines `Ade` and lists every ADE in `ALL`. Add a variant and fill in its match arms. -- ADE modules: `src-tauri/src/ade/t3.rs` finds T3 Code and reads its version, and holds the install, version and pairing scripts. `src-tauri/assets/t3-probe` is the idle probe. `src-tauri/src/ade/cmux.rs` finds cmux, reads its version from its app bundle, tells whether it runs, and builds its link. `src-tauri/src/ade/orca.rs` finds Orca and reads its version, from its app bundle on macOS and from `Orca.exe` on Windows, and holds the setup that installs its probe. `src-tauri/assets/orca-probe` is its idle probe. `src-tauri/src/ade/paradev.rs` finds Paradev like cmux, as `Paradev.app` or `Superset.app`, and holds its host check, host id and links, and the call to its CLI that adds the host. `src-tauri/src/ade/paseo.rs` finds Paseo like Orca (it uses Orca's reader for `.exe` files), and holds its daemon setup and host address. `src-tauri/assets/paseo-probe` is its idle probe. `src-tauri/src/ade/herdr.rs` finds the OpenSSH client and reads its version, and holds Herdr's install script and version check. `src-tauri/src/ade/herdr_desktop.rs` finds Herdr Desktop and herdr-core and checks them, and holds the calls to their CLIs that add the sandbox as a machine and show its space. `src-tauri/src/ade/amp.rs` holds Amp's install script and version check, and finds the OpenSSH client with Herdr's code. `src-tauri/src/ade/rex.rs` finds Rex like cmux, checks its signature like Paseo, tells whether this Mac can run it (Apple silicon, macOS 15 or later, which `Ade::runs_here` asks), and holds its server setup, its host address and the calls to its CLI that show the sandbox's session. When an app can be installed more than once, its module picks the newest real copy with `ade::newest_app`, so the version shown is the copy that opens. -- How it opens (`Open`): `Pair` for an app that pairs with a server on the sandbox (T3), `Link` for an app that reaches the sandbox over SSH from a link (cmux), `SshHost` for an app that reaches the sandbox through a host in `~/.ssh/config`, which it imports (Orca) or the user adds by its address (Paseo, Rex), `Host` for an app that runs the sandbox as one of its hosts, set up in the app (Paradev), `Terminal` for an ADE that runs on the sandbox and opens in the user's terminal over SSH (Herdr, Amp). A terminal ADE can have an app of its own (`Terminal::app`, Herdr Desktop): when it is installed, Open uses it in place of the terminal, and `Core::open_ade_in_terminal` keeps the terminal one click away. `src-tauri/src/ssh_config.rs` writes the hosts of Orca, Paseo, Rex and Herdr Desktop, and `ssh::open_in_terminal` opens the terminal. +- ADE modules: `src-tauri/src/ade/t3.rs` finds T3 Code and reads its version, and holds the install, version and pairing scripts. `src-tauri/assets/t3-probe` is the idle probe. `src-tauri/src/ade/cmux.rs` finds cmux, reads its version from its app bundle, tells whether it runs, and builds its link. `src-tauri/src/ade/orca.rs` finds Orca and reads its version, from its app bundle on macOS and from `Orca.exe` on Windows, and holds the setup that installs its probe. `src-tauri/assets/orca-probe` is its idle probe. `src-tauri/src/ade/paradev.rs` finds Paradev like cmux, as `Paradev.app` or `Superset.app`, and holds its host check, host id and links, and the call to its CLI that adds the host. `src-tauri/src/ade/paseo.rs` finds Paseo like Orca (it uses Orca's reader for `.exe` files), and holds its daemon setup and host address. `src-tauri/assets/paseo-probe` is its idle probe. `src-tauri/src/ade/herdr.rs` finds the OpenSSH client and reads its version, and holds Herdr's install script and version check. `src-tauri/src/ade/herdr_desktop.rs` finds Herdr Desktop and herdr-core and checks them, and holds the calls to their CLIs that add the sandbox as a machine and show its space. `src-tauri/src/ade/amp.rs` holds Amp's install script and version check, and finds the OpenSSH client with Herdr's code. `src-tauri/src/ade/rex.rs` finds Rex like cmux, checks its signature like Paseo, tells whether this Mac can run it (Apple silicon, macOS 15 or later, which `Ade::runs_here` asks), and holds its server setup, its host address and the calls to its CLI that show the sandbox's session. `src-tauri/src/ade/codync.rs` holds Codync's install and service setup and version check, and finds the OpenSSH client with Herdr's code. When an app can be installed more than once, its module picks the newest real copy with `ade::newest_app`, so the version shown is the copy that opens. +- How it opens (`Open`): `Pair` for an app that pairs with a server on the sandbox (T3), `Link` for an app that reaches the sandbox over SSH from a link (cmux), `SshHost` for an app that reaches the sandbox through a host in `~/.ssh/config`, which it imports (Orca) or the user adds by its address (Paseo, Rex), `Host` for an app that runs the sandbox as one of its hosts, set up in the app (Paradev), `Terminal` for an ADE that runs on the sandbox and opens in the user's terminal over SSH (Herdr, Amp, Codync). A terminal ADE can have an app of its own (`Terminal::app`, Herdr Desktop): when it is installed, Open uses it in place of the terminal, and `Core::open_ade_in_terminal` keeps the terminal one click away. `src-tauri/src/ssh_config.rs` writes the hosts of Orca, Paseo, Rex and Herdr Desktop, and `ssh::open_in_terminal` opens the terminal. - Flow: `src-tauri/src/sandbox/connect.rs` sets the ADE up and adds its id to the sandbox's mark. `src-tauri/src/sandbox/sync.rs` keeps the versions in step for an ADE that pins them. `open_in_ade` in `src-tauri/src/app.rs` opens it. - UI: `src/ades.tsx` holds what the app does with each ADE (its badge, names and text), `src/NextSteps.tsx` the words of each ADE's next step, `src/mode.ts` the ADE the user picked, and `src/ade.ts` with `src/hero/` each ADE's look (logo and background). The switcher is `src/AdeSwitcher.tsx`, the first-run picker `src/AdePicker.tsx` and the tip under the switcher `src/AdeTip.tsx`. - Docs: add the ADE to the README's Supported ADEs and give it a section in `docs/ades.md`. diff --git a/README.md b/README.md index 5348845..eaa3a0c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@

InstaADE

-

Run your ADE (agentic development environment) on an instabox sandbox, from your menu bar or system tray.
Works with T3 Code, cmux, Orca, Paradev, Paseo, Herdr, Amp and Rex.

+

Run your ADE (agentic development environment) on an instabox sandbox, from your menu bar or system tray.
Works with T3 Code, cmux, Orca, Paradev, Paseo, Herdr, Amp, Rex and Codync.

License: MIT @@ -83,6 +83,10 @@ Every **Open in** wakes the sandbox first. - Installs Rex's server on the sandbox, adds it as an SSH host, copies its address and starts Rex. - First time: in Rex, open **Settings** → **Remote Hosts** → **Add Remote Host…**, paste the address as the URL and click **Add**. - With **Remote Control** on in Rex (**Settings** → **General**), Open in Rex goes straight to the sandbox's session. +- **[Codync](docs/ades.md#codync)** · no app needed here, runs in your terminal + - Installs Codync's host on the sandbox as a service and opens Codync's terminal UI in your terminal over SSH. + - First time: sign in to the agents your bots use on the sandbox (such as `claude` or `codex login` in **Open in Terminal**). To message the bots from your phone, open **Pair phone…** in Codync's terminal UI and scan the code with the Codync app. + - Closing the terminal leaves the host and its bots running on the sandbox. > [!NOTE] > If a sandbox stays awake while cmux, Orca, Paseo or T3 Code is open, update InstaADE to 0.1.14 or later, then open the sandbox from InstaADE again. diff --git a/docs/ades.md b/docs/ades.md index cef092a..73400d1 100644 --- a/docs/ades.md +++ b/docs/ades.md @@ -40,7 +40,7 @@ For Orca, Paseo, Rex, a first Paradev setup that Paradev's CLI does not do, and InstaADE keeps two SSH tokens for each sandbox, in two keychain entries. Each token lasts 30 days. InstaADE uses the stored one while it has more than a day left, else it makes a new one. - The **background token** is for an app that stays connected by itself and checks the connection every few seconds: cmux, Orca, Paseo, Herdr Desktop and Rex. When instabox applies background tokens to the sandbox, the connections of this token do not wake the sandbox and do not count as activity. So an idle app does not keep the sandbox awake. An agent at work still keeps it awake, through the ADE's activity probe and the sandbox's terminals and CPU. InstaADE asks for this token with `background: true`. An instabox that does not know background tokens makes an ordinary token. InstaADE then uses that token in its place, and writes this to its log once. -- The **ordinary token** is for a login that you start: the SSH command in the sandbox's details, **Open in Terminal**, Herdr, Amp, Paradev's host setup (its CLI and its SSH address) and the sign-in of Claude Code or Codex. Its connections wake the sandbox and count as activity. +- The **ordinary token** is for a login that you start: the SSH command in the sandbox's details, **Open in Terminal**, Herdr, Amp, Codync, Paradev's host setup (its CLI and its SSH address) and the sign-in of Claude Code or Codex. Its connections wake the sandbox and count as activity. The SSH host that Orca, Paseo, Herdr Desktop and Rex use holds the background token. An older InstaADE wrote that host with its one token, which is now the ordinary one. The host keeps its alias. Its `User` changes to the background token the next time InstaADE starts, or at the next **Open**. So you do not add the host again in Orca or Paseo. @@ -378,6 +378,40 @@ Rex reads the host, which holds an SSH token, so InstaADE starts only the real R Rex has no idle probe. Its agents run in terminals of the Rex server on the sandbox, so the sandbox sleeps by its terminals and CPU, as with Herdr. A Rex that stays connected, with idle sessions, does not keep the sandbox awake. +## Codync + +[Codync](https://codync.dev) runs coding agents (Claude Code, Codex and others) as persistent, named bots that you message from a phone, a desktop app or a terminal. Its host, `codync-host`, runs on the machine the bots work on and drives the agents there over ACP. Like Amp, it runs on the sandbox, and InstaADE opens it in your terminal over SSH. Nothing of Codync has to run on your computer, and no app gets an SSH token. + +**Install Codync** wakes the sandbox and runs one command on it: + +- When an SSH command cannot find `codync-host`, the command runs Codync's install script, `https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh`, with `--host-only`. It puts the latest host in `~/.local/bin/codync-host` and checks its SHA-256. The host is one static binary. An SSH command's PATH lacks `~/.local/bin`, so InstaADE links it as `/usr/local/bin/codync-host`. A host the sandbox already has stays as it is. +- It writes `/usr/local/bin/codync-tui`, which runs `codync-host tui`, since the SSH session runs one plain word. +- It turns on lingering for the sandbox's user, so the host starts at boot with no login. When the sandbox has no `codync-host` service yet, it runs `codync-host install` from a login shell, which writes and starts a systemd user service that keeps the login PATH, where the agents are. When the service is there, it only starts it, so a **Reconnect** never restarts bots at work. +- The host must answer on `127.0.0.1:19222` within 30 seconds. Then it prints `codync-host --version`. When the command fails or prints no version, the sandbox does not get `codync` in its mark. +- The download stops after 60 seconds and the install script after 5 minutes. When the download fails, the error ends with "Could not download Codync's install script." When the script fails or runs out of time, the error shows its last 3 lines and one line that says which. When the service does not start, the error ends with "Codync could not start its host." or "The Codync host did not start." + +Then Codync opens, as with **Open in Codync**. **Reconnect** runs the same command again, which installs nothing while the host is there, and opens Codync. + +**Open in Codync** opens your terminal as **Open in Amp** does, with the same checks and the same [ordinary token](#ssh-tokens). The SSH session runs `codync-tui`: + +``` + -t -o StrictHostKeyChecking=accept-new -p 2222 @ssh.instabox.sh codync-tui +``` + +The first time: + +1. Sign in to the agents your bots will use, on the sandbox, as you would for any terminal use: for example `claude` or `codex login` in **Open in Terminal**, or **Sign in to Claude Code or Codex** in the sandbox's details. Claude Code and Codex run through ACP adapters fetched with `npx`, so they need Node.js on the sandbox. Without it, Codync offers to add its own copy. +2. In Codync's terminal UI, make a bot and message it. +3. To message the bots from your phone, open **Pair phone…** in the terminal UI and scan the QR code with the Codync app (iPhone or Android). Away from the sandbox's network, the phone reaches the host through Codync's end-to-end encrypted relay, which needs the host and the phone signed in to the same Codync account. + +- Codync keeps its data on the sandbox, in `~/.codync` under `/data/home`, which a pause or a stop keeps. +- Closing the terminal ends only the terminal UI. The host and its bots keep running on the sandbox. +- The host updates itself in place, so the link follows. InstaADE never updates it. + +On your computer, InstaADE needs only the OpenSSH client, as for Herdr and Amp. Settings shows its version next to Codync. Without it, nothing wakes or changes, and InstaADE asks you to install the OpenSSH client. + +Codync has no idle probe yet, so the sandbox sleeps by its terminals and CPU. A bot that works with no terminal open can have the sandbox pause under it, and a phone cannot reach a sandbox that sleeps until something wakes it, such as **Open in Codync**. + ## Several ADEs on one sandbox A sandbox can have several ADEs, and its details list each one with **Open**. The sandbox's metadata records which ADEs it has, in a form older releases (named Instabox) still read. [ADEs and the sandbox mark](../DEVELOPMENT.md#ades-and-the-sandbox-mark) has the rules. diff --git a/src-tauri/src/ade/codync.rs b/src-tauri/src/ade/codync.rs new file mode 100644 index 0000000..a43a49e --- /dev/null +++ b/src-tauri/src/ade/codync.rs @@ -0,0 +1,200 @@ +//! Codync, persistent coding-agent bots you message from a phone, a desktop app or a terminal +//! (codync.dev). Its host, `codync-host`, runs on the machine the bots work on and drives the +//! agents there (Claude Code, Codex and others) over ACP. Like Amp, it has no app here that +//! InstaADE opens: InstaADE installs the host on the sandbox with Codync's own install script, +//! runs it as a systemd user service, and opens the user's terminal with an SSH session that +//! starts Codync's terminal UI there. The terminal UI pairs a phone (**Pair phone…**), and the +//! bots keep running after the terminal closes. +//! On this computer: the OpenSSH client that the terminal runs, found as for Herdr. + +use crate::ade::{Platform, Terminal}; + +pub use crate::ade::herdr::{DOWNLOAD_URL, locate, version}; + +pub const ID: &str = "codync"; +pub const NAME: &str = "Codync"; +pub const SHORT_NAME: &str = "Codync"; +/// Where InstaADE opens a terminal (`ssh::open_in_terminal`). +pub const PLATFORMS: &[Platform] = &[Platform::MacOs, Platform::Windows]; +/// Codync takes no links from InstaADE, so the app opens none for it. +pub const URL_SCHEME: &str = ""; + +/// Codync has no app of its own that InstaADE opens: it always opens in the terminal. The SSH +/// session runs one plain word (`ssh::terminal_args`), so the setup puts `codync-tui`, which +/// runs `codync-host tui`, on an SSH command's PATH. +pub const TERMINAL: Terminal = Terminal { + command: "codync-tui", + app: None, +}; + +/// What the app says when this computer has no OpenSSH client. +pub const MISSING: &str = "Codync opens in a terminal over SSH, and this computer has no OpenSSH client. Install it first."; + +// ---- the sandbox ---- + +/// Prints the host's version on the sandbox, such as `codync-host 2.56.0`, or nothing when it +/// is not installed. +pub const VERSION_SCRIPT: &str = "codync-host --version 2>/dev/null || true"; + +/// Installs Codync's host on the sandbox when an SSH command cannot find it, runs it as a +/// service, then prints its version. Codync's install script puts `codync-host` in +/// `~/.local/bin` and checks its SHA-256; `--host-only` leaves out the desktop app. An SSH +/// command runs with sshd's PATH, which lacks that folder, so the script links it as +/// `/usr/local/bin/codync-host`, and writes `/usr/local/bin/codync-tui` for the terminal. +/// `codync-host install` writes and starts a systemd user service, from a login shell so the +/// service gets the PATH where the agents are; a sandbox that has the service only starts it, +/// so a Reconnect never restarts the bots. Lingering keeps the service up from boot, with no +/// login. The host updates itself in place. The download stops after 60 s, the install script +/// after 5 minutes, and the host must answer on its port within 30 s. A failure prints the +/// last lines of what failed and one short line. +pub const SETUP_SCRIPT: &str = r#"set -eu +export PATH=/usr/local/bin:/usr/bin:/bin +export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +if ! command -v codync-host >/dev/null 2>&1; then + if [ ! -x "$HOME/.local/bin/codync-host" ]; then + if ! curl -fsSL --max-time 60 https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh -o "$tmp/install.sh"; then + echo "Could not download Codync's install script." >&2 + exit 1 + fi + rc=0 + CODYNC_BIN_DIR="$HOME/.local/bin" timeout 300 sh "$tmp/install.sh" --host-only "$tmp/log" 2>&1 || rc=$? + if [ "$rc" -ne 0 ]; then + tail -n 3 "$tmp/log" >&2 + if [ "$rc" -eq 124 ]; then + echo "Codync's install script did not finish in 5 minutes." >&2 + else + echo "Codync's install script failed." >&2 + fi + exit 1 + fi + fi + sudo -n ln -sfn "$HOME/.local/bin/codync-host" /usr/local/bin/codync-host +fi +if [ ! -x /usr/local/bin/codync-tui ]; then + printf '#!/bin/sh\nexec codync-host tui "$@"\n' >"$tmp/codync-tui" + sudo -n install -m 0755 "$tmp/codync-tui" /usr/local/bin/codync-tui +fi +sudo -n loginctl enable-linger "$(id -un)" >/dev/null 2>&1 || true +rc=0 +if [ -f "$HOME/.config/systemd/user/codync-host.service" ]; then + timeout -k 10 60 systemctl --user start codync-host "$tmp/log" 2>&1 || rc=$? +else + timeout -k 10 60 bash -lc 'exec codync-host install' "$tmp/log" 2>&1 || rc=$? +fi +if [ "$rc" -ne 0 ]; then + tail -n 3 "$tmp/log" >&2 + echo "Codync could not start its host." >&2 + exit 1 +fi +end=$(( $(date +%s) + 30 )) +until curl -fsS --max-time 2 http://127.0.0.1:19222/health >/dev/null 2>&1; do + if [ "$(date +%s)" -ge "$end" ]; then + echo "The Codync host did not start." >&2 + exit 1 + fi + sleep 1 +done +codync-host --version 2>/dev/null || true +"#; + +/// Parses `codync-host 2.56.0` into `2.56.0`: the version on the last line that has one. +pub fn parse_version(out: &str) -> Option { + out.lines().rev().find_map(|line| { + let v = line.trim().strip_prefix("codync-host ")?.trim(); + let ok = v.starts_with(|c: char| c.is_ascii_digit()) + && v.chars() + .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '-' | '+')); + ok.then(|| v.to_string()) + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn reads_the_version_codync_prints() { + assert_eq!( + parse_version("codync-host 2.56.0\n").as_deref(), + Some("2.56.0") + ); + assert_eq!( + parse_version("codync-host 2.57.0-dev.1\r\n").as_deref(), + Some("2.57.0-dev.1") + ); + assert_eq!( + parse_version("codync-host 2.55.0\ncodync-host 2.56.0\n").as_deref(), + Some("2.56.0"), + "the last line" + ); + for bad in [ + "", + "codync-host\n", + "bash: codync-host: command not found", + "codync-host v2.56.0", + "codync-host 2.56.0;rm", + "herdr 0.9.5", + "2.56.0", + ] { + assert_eq!(parse_version(bad), None, "{bad}"); + } + } + + #[test] + fn setup_installs_only_when_an_ssh_command_cannot_find_the_host() { + let s = SETUP_SCRIPT; + assert!(s.starts_with("set -eu\nexport PATH=/usr/local/bin:/usr/bin:/bin\n")); + let check = s.find("if ! command -v codync-host").unwrap(); + let installed = s + .find("if [ ! -x \"$HOME/.local/bin/codync-host\" ]") + .unwrap(); + let download = s + .find("curl -fsSL --max-time 60 https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh -o") + .unwrap(); + let install = s + .find("timeout 300 sh \"$tmp/install.sh\" --host-only") + .unwrap(); + let link = s + .find("sudo -n ln -sfn \"$HOME/.local/bin/codync-host\" /usr/local/bin/codync-host") + .unwrap(); + let tui = s + .find("sudo -n install -m 0755 \"$tmp/codync-tui\" /usr/local/bin/codync-tui") + .unwrap(); + let service = s.find("bash -lc 'exec codync-host install'").unwrap(); + let health = s.find("http://127.0.0.1:19222/health").unwrap(); + assert!( + check < installed + && installed < download + && download < install + && install < link + && link < tui + && tui < service + && service < health + ); + // The script's output stays out of what the version is read from, and asks nothing. + assert!(s.contains("\"$tmp/log\" 2>&1")); + // A failure says so in one plain line, after the script's last lines. + assert!(s.contains("tail -n 3 \"$tmp/log\" >&2")); + assert!(s.contains("echo \"Codync's install script failed.\" >&2")); + assert!(s.contains("echo \"The Codync host did not start.\" >&2")); + // A sandbox with the service only starts it, so a Reconnect never restarts the bots. + assert!(s.contains("systemctl --user start codync-host")); + // The last line prints the version. + assert!(s.ends_with(&format!("{VERSION_SCRIPT}\n"))); + } + + #[test] + fn the_terminal_runs_the_tui_and_needs_only_the_ssh_client_here() { + assert_eq!(TERMINAL.command, "codync-tui"); + assert!(TERMINAL.app.is_none()); + assert!(SETUP_SCRIPT.contains("exec codync-host tui")); + assert_eq!(DOWNLOAD_URL, crate::ade::herdr::DOWNLOAD_URL); + assert!(MISSING.contains("no OpenSSH client")); + assert!(version(std::path::Path::new("/nonexistent/ssh")).is_err()); + if cfg!(target_os = "macos") { + assert_eq!(locate(), crate::ade::herdr::locate()); + } + } +} diff --git a/src-tauri/src/ade/mod.rs b/src-tauri/src/ade/mod.rs index d3a1513..33184cf 100644 --- a/src-tauri/src/ade/mod.rs +++ b/src-tauri/src/ade/mod.rs @@ -4,6 +4,7 @@ pub mod amp; pub mod cmux; +pub mod codync; pub mod herdr; pub mod herdr_desktop; pub mod orca; @@ -31,6 +32,7 @@ pub const ALL: &[Ade] = &[ Ade::Herdr, Ade::Amp, Ade::Rex, + Ade::Codync, ]; /// Exit code of every ADE's setup script when the ADE is busy and its update waits. @@ -39,7 +41,7 @@ pub const SETUP_EXIT_BUSY: i32 = 3; /// Where an ADE's setup puts its idle probe. instabox-guest-agent runs every file here. pub const ACTIVITY_DIR: &str = "/usr/local/lib/instabox/activity.d"; -/// An ADE. Its id (`t3`, `cmux`, `orca`, `paradev`, `paseo`, `herdr`, `amp`, `rex`) is its JSON form and an entry of a connected sandbox's mark. +/// An ADE. Its id (`t3`, `cmux`, `orca`, `paradev`, `paseo`, `herdr`, `amp`, `rex`, `codync`) is its JSON form and an entry of a connected sandbox's mark. #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum Ade { @@ -52,6 +54,7 @@ pub enum Ade { Herdr, Amp, Rex, + Codync, } /// A platform the desktop side of an ADE runs on. @@ -445,6 +448,7 @@ impl Ade { Ade::Paseo => paseo::ID, Ade::Herdr => herdr::ID, Ade::Amp => amp::ID, + Ade::Codync => codync::ID, Ade::Rex => rex::ID, } } @@ -459,6 +463,7 @@ impl Ade { Ade::Paseo => paseo::NAME, Ade::Herdr => herdr::NAME, Ade::Amp => amp::NAME, + Ade::Codync => codync::NAME, Ade::Rex => rex::NAME, } } @@ -473,6 +478,7 @@ impl Ade { Ade::Paseo => paseo::SHORT_NAME, Ade::Herdr => herdr::SHORT_NAME, Ade::Amp => amp::SHORT_NAME, + Ade::Codync => codync::SHORT_NAME, Ade::Rex => rex::SHORT_NAME, } } @@ -486,6 +492,7 @@ impl Ade { Ade::Paseo => paseo::PLATFORMS, Ade::Herdr => herdr::PLATFORMS, Ade::Amp => amp::PLATFORMS, + Ade::Codync => codync::PLATFORMS, Ade::Rex => rex::PLATFORMS, } } @@ -507,6 +514,7 @@ impl Ade { Ade::Paseo => paseo::DOWNLOAD_URL, Ade::Herdr => herdr::DOWNLOAD_URL, Ade::Amp => amp::DOWNLOAD_URL, + Ade::Codync => codync::DOWNLOAD_URL, Ade::Rex => rex::DOWNLOAD_URL, } } @@ -521,6 +529,7 @@ impl Ade { Ade::Paseo => paseo::URL_SCHEME, Ade::Herdr => herdr::URL_SCHEME, Ade::Amp => amp::URL_SCHEME, + Ade::Codync => codync::URL_SCHEME, Ade::Rex => rex::URL_SCHEME, } } @@ -538,6 +547,7 @@ impl Ade { Ade::Paseo => paseo::locate(), Ade::Herdr => herdr::locate(), Ade::Amp => amp::locate(), + Ade::Codync => codync::locate(), Ade::Rex => rex::locate(), } } @@ -553,6 +563,7 @@ impl Ade { Ade::Paseo => paseo::version(path), Ade::Herdr => herdr::version(path), Ade::Amp => amp::version(path), + Ade::Codync => codync::version(path), Ade::Rex => rex::version(path), } } @@ -576,6 +587,7 @@ impl Ade { Ade::Paseo => paseo::verify(path), Ade::Herdr => true, Ade::Amp => true, + Ade::Codync => true, Ade::Rex => rex::verify(path), } } @@ -586,6 +598,7 @@ impl Ade { match self { Ade::Herdr => herdr::MISSING.to_string(), Ade::Amp => amp::MISSING.to_string(), + Ade::Codync => codync::MISSING.to_string(), _ => format!("{} is not installed. Install it first.", self.name()), } } @@ -608,6 +621,7 @@ impl Ade { Ade::Paseo => None, Ade::Herdr => herdr::parse_version(out), Ade::Amp => amp::parse_version(out), + Ade::Codync => codync::parse_version(out), Ade::Rex => None, } } @@ -623,6 +637,7 @@ impl Ade { Ade::Paseo => false, Ade::Herdr => false, Ade::Amp => false, + Ade::Codync => false, Ade::Rex => false, } } @@ -642,6 +657,7 @@ impl Ade { Ade::Paseo => None, Ade::Herdr => Some(herdr::VERSION_SCRIPT), Ade::Amp => Some(amp::VERSION_SCRIPT), + Ade::Codync => Some(codync::VERSION_SCRIPT), Ade::Rex => None, } } @@ -663,6 +679,7 @@ impl Ade { Ade::Paseo => paseo::setup_script(version), Ade::Herdr => herdr::SETUP_SCRIPT.to_string(), Ade::Amp => amp::SETUP_SCRIPT.to_string(), + Ade::Codync => codync::SETUP_SCRIPT.to_string(), Ade::Rex => rex::setup_script(version), } } @@ -680,6 +697,7 @@ impl Ade { Ade::Paseo => None, Ade::Herdr => None, Ade::Amp => None, + Ade::Codync => None, Ade::Rex => None, } } @@ -695,6 +713,7 @@ impl Ade { Ade::Paseo => true, Ade::Herdr => true, Ade::Amp => true, + Ade::Codync => true, Ade::Rex => true, } } @@ -710,6 +729,7 @@ impl Ade { Ade::Paseo => false, Ade::Herdr => false, Ade::Amp => false, + Ade::Codync => false, Ade::Rex => false, } } @@ -724,6 +744,7 @@ impl Ade { Ade::Paseo => None, Ade::Herdr => None, Ade::Amp => None, + Ade::Codync => None, Ade::Rex => None, } } @@ -739,6 +760,7 @@ impl Ade { Ade::Paseo => Some(paseo::PROBE), Ade::Herdr => None, Ade::Amp => None, + Ade::Codync => None, Ade::Rex => None, } } @@ -755,6 +777,7 @@ impl Ade { Ade::Paseo => Some(paseo::OPEN_PROBE), Ade::Herdr => None, Ade::Amp => None, + Ade::Codync => None, Ade::Rex => None, } } @@ -771,6 +794,7 @@ impl Ade { Ade::Paseo => false, Ade::Herdr => true, Ade::Amp => false, + Ade::Codync => false, Ade::Rex => true, } } @@ -790,6 +814,7 @@ impl Ade { Ade::Paseo => Open::SshHost(paseo::SSH_HOST), Ade::Herdr => Open::Terminal(herdr::TERMINAL), Ade::Amp => Open::Terminal(amp::TERMINAL), + Ade::Codync => Open::Terminal(codync::TERMINAL), Ade::Rex => Open::SshHost(rex::SSH_HOST), } } @@ -809,6 +834,7 @@ impl Ade { Ade::Paseo => Some(Kind::Background), Ade::Herdr => Some(Kind::Ordinary), Ade::Amp => Some(Kind::Ordinary), + Ade::Codync => Some(Kind::Ordinary), Ade::Rex => Some(Kind::Background), } } @@ -923,7 +949,8 @@ mod tests { Ade::Paseo, Ade::Herdr, Ade::Amp, - Ade::Rex + Ade::Rex, + Ade::Codync ] ); assert_eq!(Ade::default(), Ade::T3); @@ -934,6 +961,7 @@ mod tests { assert_eq!(Ade::from_id("paseo"), Some(Ade::Paseo)); assert_eq!(Ade::from_id("herdr"), Some(Ade::Herdr)); assert_eq!(Ade::from_id("amp"), Some(Ade::Amp)); + assert_eq!(Ade::from_id("codync"), Some(Ade::Codync)); assert_eq!(Ade::from_id("rex"), Some(Ade::Rex)); assert_eq!(Ade::from_id("superset"), None, "one entry, by its new name"); assert_eq!(Ade::from_id("other"), None); @@ -1279,6 +1307,48 @@ mod tests { assert!(a.missing().starts_with("Amp opens in a terminal")); } + #[test] + fn codync_parts() { + let a = Ade::Codync; + assert_eq!( + (a.id(), a.name(), a.short_name()), + ("codync", "Codync", "Codync") + ); + assert_eq!(a.url_scheme(), "", "Codync takes no links"); + // Like Amp: its host updates itself, and InstaADE pins no version and has no probe, so + // there is nothing to keep in step or reinstall. Reconnect runs the setup again, which + // only starts the host when its service is there. + assert!(!a.pins_local_version()); + assert!(!a.reinstalls()); + assert_eq!(a.port(), None); + assert_eq!(a.version_script(), Some(codync::VERSION_SCRIPT)); + assert_eq!(a.stop_script(), None); + assert_eq!(a.probe(), None); + assert_eq!(a.probe_on_open(), None); + assert_eq!(a.refresh_script(), None); + assert!(a.setup_current("")); + assert!(!a.pairing_needs_setup("0.1.12", Some("0.1.12"))); + assert_eq!(a.setup_script("ignored"), codync::SETUP_SCRIPT); + assert_eq!( + a.parse_version("codync-host 2.56.0\n").as_deref(), + Some("2.56.0") + ); + let Open::Terminal(t) = a.open() else { + panic!("Codync opens in a terminal") + }; + assert_eq!(t.command, "codync-tui"); + // The terminal runs Codync's own UI, not a shell where the user starts Claude Code. + assert!(!a.agents_in_terminal()); + // The token goes to the OpenSSH client, not to an app to check, as for Herdr and Amp. + assert!(a.verify(Path::new("/nonexistent"))); + assert_eq!(a.ssh_token(), Some(Kind::Ordinary)); + assert_eq!(a.download_url(), Ade::Herdr.download_url()); + assert_eq!(a.platforms(), Ade::Herdr.platforms()); + assert_eq!(a.runs_here(), cfg!(any(target_os = "macos", windows))); + assert_eq!(a.missing(), codync::MISSING); + assert!(a.missing().starts_with("Codync opens in a terminal")); + } + #[test] fn t3_runs_on_every_platform_the_app_ships_for_and_cmux_on_macos_only() { for p in [Platform::MacOs, Platform::Windows] { @@ -1301,13 +1371,21 @@ mod tests { if rex::this_mac_runs_rex() { all.push(Ade::Rex); } + all.push(Ade::Codync); assert_eq!(local(), all); } if cfg!(windows) { assert!(Ade::T3.runs_here() && !Ade::Cmux.runs_here() && !Ade::Paradev.runs_here()); assert_eq!( local(), - vec![Ade::T3, Ade::Orca, Ade::Paseo, Ade::Herdr, Ade::Amp], + vec![ + Ade::T3, + Ade::Orca, + Ade::Paseo, + Ade::Herdr, + Ade::Amp, + Ade::Codync + ], "no cmux, Paradev or Rex on Windows" ); } @@ -1488,7 +1566,7 @@ mod tests { ); assert_eq!( of(Some(Kind::Ordinary)), - [Ade::Paradev, Ade::Herdr, Ade::Amp] + [Ade::Paradev, Ade::Herdr, Ade::Amp, Ade::Codync] ); assert_eq!(of(None), [Ade::T3]); for a in ALL { diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index 08895e9..6b3ebb3 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -7259,7 +7259,8 @@ mod tests { AdeView::new(Ade::Paseo, None), AdeView::new(Ade::Herdr, None), AdeView::new(Ade::Amp, None), - AdeView::new(Ade::Rex, None) + AdeView::new(Ade::Rex, None), + AdeView::new(Ade::Codync, None) ] ); } @@ -7271,7 +7272,8 @@ mod tests { AdeView::new(Ade::Orca, None), AdeView::new(Ade::Paseo, None), AdeView::new(Ade::Herdr, None), - AdeView::new(Ade::Amp, None) + AdeView::new(Ade::Amp, None), + AdeView::new(Ade::Codync, None) ] ); } diff --git a/src/AdeCards.tsx b/src/AdeCards.tsx index 60dd421..822fd5b 100644 --- a/src/AdeCards.tsx +++ b/src/AdeCards.tsx @@ -25,7 +25,7 @@ export function CheckAdesButton({ run, text }: { run: Run; text?: boolean }) { ); } -/** The selected ADE is not on this computer: shown at the top of the list. For Herdr and Amp, +/** The selected ADE is not on this computer: shown at the top of the list. For Herdr, Amp and Codync, * which run on the sandbox, that is the OpenSSH client. */ export function AdeMissing({ state, ade, run }: { state: AppState; ade: AdeId; run: Run }) { const name = adeName(state, ade); diff --git a/src/ade.ts b/src/ade.ts index 3eba41c..6cf0ed3 100644 --- a/src/ade.ts +++ b/src/ade.ts @@ -16,6 +16,7 @@ export const ADES: { id: Ade; name: string }[] = [ { id: "herdr", name: "Herdr" }, { id: "amp", name: "Amp" }, { id: "rex", name: "Rex" }, + { id: "codync", name: "Codync" }, ]; export const adeName = (ade: Ade) => ADES.find((item) => item.id === ade)!.name; diff --git a/src/ades.tsx b/src/ades.tsx index d5a6d0a..449346f 100644 --- a/src/ades.tsx +++ b/src/ades.tsx @@ -23,7 +23,7 @@ export function AdeBadge({ id, size = 20 }: { id: Mode | SoonId; size?: number } ); } -const NAMES: Record = { t3: "T3 Code", cmux: "cmux", orca: "Orca", paradev: "Paradev", paseo: "Paseo", herdr: "Herdr", amp: "Amp", rex: "Rex" }; +const NAMES: Record = { t3: "T3 Code", cmux: "cmux", orca: "Orca", paradev: "Paradev", paseo: "Paseo", herdr: "Herdr", amp: "Amp", rex: "Rex", codync: "Codync" }; /** The desktop app's name, such as "T3 Code". */ export const adeName = (state: AppState, id: AdeId) => state.ades.find((a) => a.id === id)?.name ?? NAMES[id]; @@ -51,12 +51,12 @@ export const stepShows = (step: NextStepView, mode: Mode) => mode === step.ade | /** T3 pairs with a server it installs, and keeps its version in step; cmux opens a link; Orca * connects an SSH host InstaADE writes; Paradev runs the sandbox as a host it sets up; Paseo * connects to a daemon InstaADE runs, and Rex to a server InstaADE installs, each through an - * SSH host the user adds once; Herdr and Amp run on the sandbox, in a terminal. */ + * SSH host the user adds once; Herdr, Amp and Codync run on the sandbox, in a terminal. */ export const pairs = (id: AdeId) => id === "t3"; -/** Herdr and Amp run on the sandbox and open in a terminal over SSH: this computer needs only +/** Herdr, Amp and Codync run on the sandbox and open in a terminal over SSH: this computer needs only * the OpenSSH client, which the back end reports as the ADE's version. */ -export const inTerminal = (id: AdeId) => id === "herdr" || id === "amp"; +export const inTerminal = (id: AdeId) => id === "herdr" || id === "amp" || id === "codync"; /** The ADE's own app on this computer (Herdr Desktop), verified or not; null when Open uses the * terminal. While it is here, Open goes to it, or fails with the reason when it is not verified, diff --git a/src/assets/ade/codync.svg b/src/assets/ade/codync.svg new file mode 100644 index 0000000..b0bc6aa --- /dev/null +++ b/src/assets/ade/codync.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/ade/sources.json b/src/assets/ade/sources.json index f5631b1..710a2d8 100644 --- a/src/assets/ade/sources.json +++ b/src/assets/ade/sources.json @@ -5,5 +5,6 @@ "paseo.svg": "https://github.com/getpaseo/paseo/blob/ad068bd21d462d5845035a394c0ba055d98c4a60/assets/brand/marks/paseo-white.svg", "herdr.svg": "https://github.com/herdrdev/herdr/blob/master/assets/logo.svg", "amp.svg": "https://ampcode.com/app-icon.svg", - "rex.png": "Rex.app 1.0.0, Contents/Resources/App Icon.icns (256 px), cropped to the icon's tile" + "rex.png": "Rex.app 1.0.0, Contents/Resources/App Icon.icns (256 px), cropped to the icon's tile", + "codync.svg": "https://www.codync.dev/icon.svg" } diff --git a/src/hero/ade-logo.ts b/src/hero/ade-logo.ts index 16e65ec..f1bfaa5 100644 --- a/src/hero/ade-logo.ts +++ b/src/hero/ade-logo.ts @@ -7,8 +7,9 @@ import paseoLogo from '../assets/ade/paseo.svg'; import herdrLogo from '../assets/ade/herdr.svg'; import ampLogo from '../assets/ade/amp.svg'; import rexLogo from '../assets/ade/rex.png'; +import codyncLogo from '../assets/ade/codync.svg'; -const logoUrls: Partial> = { t3: t3Logo, orca: orcaLogo, cmux: cmuxLogo, paradev: paradevLogo, paseo: paseoLogo, herdr: herdrLogo, amp: ampLogo, rex: rexLogo }; +const logoUrls: Partial> = { t3: t3Logo, orca: orcaLogo, cmux: cmuxLogo, paradev: paradevLogo, paseo: paseoLogo, herdr: herdrLogo, amp: ampLogo, rex: rexLogo, codync: codyncLogo }; export const adeLogoUrl = (ade: Ade): string | undefined => logoUrls[ade]; export type CubeLogo = { canvas: HTMLCanvasElement; pixels: Uint8ClampedArray; width: number; height: number }; diff --git a/src/hero/hero-atmosphere.css b/src/hero/hero-atmosphere.css index 751a30c..c6fcbda 100644 --- a/src/hero/hero-atmosphere.css +++ b/src/hero/hero-atmosphere.css @@ -122,6 +122,13 @@ linear-gradient(#17121c 0%, #0e0b12 65%, #000 100%); } +/* Codync's app icon: white dots on black, lit softly from above. */ +.hero-atmosphere[data-theme='codync'] { + background: + radial-gradient(ellipse 70% 90% at 50% -30%, #ffffff1f 0%, transparent 70%), + linear-gradient(#18181a 0%, #0c0c0d 60%, #000 100%); +} + .paradev-pixels { position: relative; width: 100%; diff --git a/src/mode.ts b/src/mode.ts index e90eb06..8210f77 100644 --- a/src/mode.ts +++ b/src/mode.ts @@ -8,7 +8,7 @@ export const modeKey = (login: string) => `instabox.ade.${login}`; /** Where it is kept that a user saw the tip under the ADE switcher, per instabox login. */ export const tipKey = (login: string) => `instabox.adeTip.${login}`; -const MODES: Mode[] = ["instabox", "t3", "cmux", "orca", "paradev", "paseo", "herdr", "amp", "rex"]; +const MODES: Mode[] = ["instabox", "t3", "cmux", "orca", "paradev", "paseo", "herdr", "amp", "rex", "codync"]; function read(key: string): string | null { try { diff --git a/src/preview.test.tsx b/src/preview.test.tsx index 10ec196..ceeb754 100644 --- a/src/preview.test.tsx +++ b/src/preview.test.tsx @@ -66,7 +66,7 @@ test("preview update and connect actions preserve other connected ADEs", async ( expect(design.getByRole("img", { name: "T3 Code" })).toBeTruthy(); }); -test("preview shows every ADE: all eight in the switcher, Orca, Paradev, Paseo, Herdr, Amp and Rex on sample sandboxes", async () => { +test("preview shows every ADE: all nine in the switcher, Orca, Paradev, Paseo, Herdr, Amp, Rex and Codync on sample sandboxes", async () => { render(); await screen.findByText("mobile-app"); const mobile = within(screen.getByText("mobile-app").closest("li")!); @@ -78,9 +78,10 @@ test("preview shows every ADE: all eight in the switcher, Orca, Paradev, Paseo, const staging = within(screen.getByText("staging").closest("li")!); expect(staging.getByRole("img", { name: "Amp" })).toBeTruthy(); expect(staging.getByRole("img", { name: "Rex" })).toBeTruthy(); + expect(staging.getByRole("img", { name: "Codync" })).toBeTruthy(); await userEvent.click(screen.getByRole("button", { name: /Switch ADE/ })); const names = screen.getAllByRole("menuitemradio").map((item) => item.querySelector(".strong")?.textContent); - expect(names).toEqual(["No ADE", "T3 Code", "cmux", "Orca", "Paradev", "Paseo", "Herdr", "Amp", "Rex"]); + expect(names).toEqual(["No ADE", "T3 Code", "cmux", "Orca", "Paradev", "Paseo", "Herdr", "Amp", "Rex", "Codync"]); }); test("preview: Connect in Orca mode marks the sandbox, and its row says how to connect it until Done", async () => { diff --git a/src/preview.ts b/src/preview.ts index 4b098f0..fc1ff48 100644 --- a/src/preview.ts +++ b/src/preview.ts @@ -61,7 +61,7 @@ if (adeError) { } } -/** Every ADE a Mac can have. The shared fixture has no Paradev, Paseo, Herdr, Amp or Rex. */ +/** Every ADE a Mac can have. The shared fixture has no Paradev, Paseo, Herdr, Amp, Rex or Codync. */ const ADES = [ ...fixture.ades, { id: "paradev", name: "Paradev", shortName: "Paradev", version: "2.0.11", downloadUrl: "https://github.com/paradevai/paradev/releases/latest", app: null }, @@ -69,6 +69,7 @@ const ADES = [ { id: "herdr", name: "Herdr", shortName: "Herdr", version: "OpenSSH 10.3p1", downloadUrl: "https://learn.microsoft.com/windows-server/administration/openssh/openssh_install_firstuse", app: null }, { id: "amp", name: "Amp", shortName: "Amp", version: "OpenSSH 10.3p1", downloadUrl: "https://learn.microsoft.com/windows-server/administration/openssh/openssh_install_firstuse", app: null }, { id: "rex", name: "Rex", shortName: "Rex", version: "1.0.0", downloadUrl: "https://superlogical.com/rex", app: null }, + { id: "codync", name: "Codync", shortName: "Codync", version: "OpenSSH 10.3p1", downloadUrl: "https://learn.microsoft.com/windows-server/administration/openssh/openssh_install_firstuse", app: null }, ] as AdeView[]; /** `?step=paradev-repo` shows Paradev's repo step on dev-workspace, as on a new sandbox: Sign in @@ -136,7 +137,7 @@ let state: AppState = { { id: "preview-api", name: "api-server", state: "running", connected: true, ades: ["t3", "cmux"] }, { id: "preview-mobile", name: "mobile-app", state: "paused", connected: false, ades: ["orca", "paradev"] }, { id: "preview-design", name: "design-system", state: "running", connected: false, ades: ["cmux", "paseo", "herdr"] }, - { id: "preview-staging", name: "staging", state: "paused", connected: true, ades: ["t3", "amp", "rex"] }, + { id: "preview-staging", name: "staging", state: "paused", connected: true, ades: ["t3", "amp", "rex", "codync"] }, ].map((machine) => ({ ...fixture.sandboxes[2], ...machine, @@ -306,7 +307,7 @@ export async function invokePreview(command: string, args: Record s.id === args.id); const ade = args.ade; - if (!sandbox || (ade !== "t3" && ade !== "cmux" && ade !== "orca" && ade !== "paradev" && ade !== "paseo" && ade !== "herdr" && ade !== "amp" && ade !== "rex")) throw { kind: "other", message: "Unknown sandbox or ADE in this preview." }; + if (!sandbox || (ade !== "t3" && ade !== "cmux" && ade !== "orca" && ade !== "paradev" && ade !== "paseo" && ade !== "herdr" && ade !== "amp" && ade !== "rex" && ade !== "codync")) throw { kind: "other", message: "Unknown sandbox or ADE in this preview." }; connected(sandbox.id, ade); break; } diff --git a/src/styles.css b/src/styles.css index 26ac547..733ab39 100644 --- a/src/styles.css +++ b/src/styles.css @@ -237,6 +237,8 @@ pre { .first-sandbox > .ade-logo[data-ade="cmux"] img { width: 40px; height: 40px; } .first-sandbox > .ade-logo[data-ade="herdr"] img { width: 100%; height: 100%; } .first-sandbox > .ade-logo[data-ade="rex"] img { width: 100%; height: 100%; } +.ade-logo[data-ade="codync"] img { width: 100%; height: 100%; } +.first-sandbox > .ade-logo[data-ade="codync"] img { width: 100%; height: 100%; } .empty .first-steps { align-self: stretch; gap: 8px; @@ -295,6 +297,8 @@ pre { .ade-logo[data-ade="amp"] { overflow: hidden; background: #061615; } /* Rex's app icon is its own rounded tile. */ .ade-logo[data-ade="rex"] { background: transparent; } +/* So is Codync's. */ +.ade-logo[data-ade="codync"] { background: transparent; } .ade-picker:focus-visible { outline: 2px solid var(--muted); @@ -1826,6 +1830,10 @@ ul.group { width: 16px; height: 16px; } +.card-ade-logo[data-ade="codync"] img { + width: 16px; + height: 16px; +} .machine-ade-row > .btn { min-width: 0; } diff --git a/src/types.ts b/src/types.ts index 8639c50..30f1e45 100644 --- a/src/types.ts +++ b/src/types.ts @@ -11,7 +11,7 @@ export type ViewState = | "deleting"; /** An ADE's id. */ -export type AdeId = "t3" | "cmux" | "orca" | "paradev" | "paseo" | "herdr" | "amp" | "rex"; +export type AdeId = "t3" | "cmux" | "orca" | "paradev" | "paseo" | "herdr" | "amp" | "rex" | "codync"; export type ErrorKind = | "freeLimit" @@ -45,7 +45,7 @@ export interface SandboxView { name: string; state: ViewState; size: string; - /** T3 was paired with it from this computer. cmux, Orca, Paradev, Paseo, Herdr, Amp and Rex never set it. */ + /** T3 was paired with it from this computer. cmux, Orca, Paradev, Paseo, Herdr, Amp, Rex and Codync never set it. */ connected: boolean; /** The ADEs set up on the sandbox (its mark), in the order they were added. */ ades: AdeId[]; @@ -76,7 +76,7 @@ export interface AdeView { id: AdeId; name: string; shortName: string; - /** The desktop app's version; null when it is not found on this computer. For Herdr and Amp, + /** The desktop app's version; null when it is not found on this computer. For Herdr, Amp and Codync, * which run on the sandbox, the OpenSSH client's, such as "OpenSSH 10.3p1". */ version: string | null; downloadUrl: string; From 0b76dcbb1f0b5a7663921ac3c97d2da5f8d3c861 Mon Sep 17 00:00:00 2001 From: leepokai <109857817+leepokai@users.noreply.github.com> Date: Sat, 5 Dec 2026 16:27:33 +0800 Subject: [PATCH 2/4] Move Codync's host to a free port when another user's host holds 19222 On a sandbox that is also a Codync cloud computer, codync-agent's host owns port 19222. The setup's host crash-looped on it, the health wait passed on the other host, and codync-tui showed "invalid token". The setup now installs the service on the next free port, codync-tui reads the port from the service, and the host counts as started only once it takes this user's token. Co-Authored-By: Claude Opus 5.5 --- src-tauri/src/ade/codync.rs | 57 +++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/ade/codync.rs b/src-tauri/src/ade/codync.rs index a43a49e..d7d1b4b 100644 --- a/src-tauri/src/ade/codync.rs +++ b/src-tauri/src/ade/codync.rs @@ -44,9 +44,12 @@ pub const VERSION_SCRIPT: &str = "codync-host --version 2>/dev/null || true"; /// `codync-host install` writes and starts a systemd user service, from a login shell so the /// service gets the PATH where the agents are; a sandbox that has the service only starts it, /// so a Reconnect never restarts the bots. Lingering keeps the service up from boot, with no -/// login. The host updates itself in place. The download stops after 60 s, the install script -/// after 5 minutes, and the host must answer on its port within 30 s. A failure prints the -/// last lines of what failed and one short line. +/// login. Another user's Codync host can already hold port 19222 (a Codync cloud computer runs +/// one as `codync-agent`): then the service is installed on the next free port, `codync-tui` +/// reads the port from the service, and the host counts as started only once it takes this +/// user's token, not when anything answers on the port. The host updates itself in place. The +/// download stops after 60 s, the install script after 5 minutes, and the host must answer +/// within 30 s. A failure prints the last lines of what failed and one short line. pub const SETUP_SCRIPT: &str = r#"set -eu export PATH=/usr/local/bin:/usr/bin:/bin export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" @@ -72,16 +75,35 @@ if ! command -v codync-host >/dev/null 2>&1; then fi sudo -n ln -sfn "$HOME/.local/bin/codync-host" /usr/local/bin/codync-host fi -if [ ! -x /usr/local/bin/codync-tui ]; then - printf '#!/bin/sh\nexec codync-host tui "$@"\n' >"$tmp/codync-tui" +cat >"$tmp/codync-tui" <<'TUI' +#!/bin/sh +port="$(sed -n 's/.* --port \([0-9][0-9]*\).*/\1/p' "$HOME/.config/systemd/user/codync-host.service" 2>/dev/null)" +exec codync-host tui --port "${port:-19222}" "$@" +TUI +if ! cmp -s "$tmp/codync-tui" /usr/local/bin/codync-tui; then sudo -n install -m 0755 "$tmp/codync-tui" /usr/local/bin/codync-tui fi sudo -n loginctl enable-linger "$(id -un)" >/dev/null 2>&1 || true +unit="$HOME/.config/systemd/user/codync-host.service" +had="$(sed -n 's/.* --port \([0-9][0-9]*\).*/\1/p' "$unit" 2>/dev/null || true)" +port="${had:-19222}" +if ! systemctl --user is-active --quiet codync-host; then + while :; do + rc=0 + curl -s -o /dev/null --max-time 2 "http://127.0.0.1:$port/" || rc=$? + [ "$rc" -eq 7 ] && break + port=$((port + 1)) + if [ "$port" -ge 19300 ]; then + echo "Codync found no free port for its host." >&2 + exit 1 + fi + done +fi rc=0 -if [ -f "$HOME/.config/systemd/user/codync-host.service" ]; then +if [ -n "$had" ] && [ "$port" = "$had" ]; then timeout -k 10 60 systemctl --user start codync-host "$tmp/log" 2>&1 || rc=$? else - timeout -k 10 60 bash -lc 'exec codync-host install' "$tmp/log" 2>&1 || rc=$? + timeout -k 10 60 bash -lc "exec codync-host install --port $port" "$tmp/log" 2>&1 || rc=$? fi if [ "$rc" -ne 0 ]; then tail -n 3 "$tmp/log" >&2 @@ -89,7 +111,7 @@ if [ "$rc" -ne 0 ]; then exit 1 fi end=$(( $(date +%s) + 30 )) -until curl -fsS --max-time 2 http://127.0.0.1:19222/health >/dev/null 2>&1; do +until curl -fsS --max-time 2 -X POST -H "Authorization: Bearer $(cat "$HOME/.codync/token" 2>/dev/null)" -H 'Content-Type: application/json' -d '{}' "http://127.0.0.1:$port/api/hello" >/dev/null 2>&1; do if [ "$(date +%s)" -ge "$end" ]; then echo "The Codync host did not start." >&2 exit 1 @@ -162,16 +184,20 @@ mod tests { let tui = s .find("sudo -n install -m 0755 \"$tmp/codync-tui\" /usr/local/bin/codync-tui") .unwrap(); - let service = s.find("bash -lc 'exec codync-host install'").unwrap(); - let health = s.find("http://127.0.0.1:19222/health").unwrap(); + let free = s.find("[ \"$rc\" -eq 7 ] && break").unwrap(); + let service = s + .find("bash -lc \"exec codync-host install --port $port\"") + .unwrap(); + let ready = s.find("\"http://127.0.0.1:$port/api/hello\"").unwrap(); assert!( check < installed && installed < download && download < install && install < link && link < tui - && tui < service - && service < health + && tui < free + && free < service + && service < ready ); // The script's output stays out of what the version is read from, and asks nothing. assert!(s.contains("\"$tmp/log\" 2>&1")); @@ -181,6 +207,13 @@ mod tests { assert!(s.contains("echo \"The Codync host did not start.\" >&2")); // A sandbox with the service only starts it, so a Reconnect never restarts the bots. assert!(s.contains("systemctl --user start codync-host")); + // Another user's Codync host can hold 19222 (a Codync cloud computer runs one): the + // service moves to a free port, the terminal UI reads it from the service, and the host + // counts as started only once it takes this user's token. + assert!(s.contains("if ! systemctl --user is-active --quiet codync-host; then")); + assert!(s.contains("exec codync-host tui --port \"${port:-19222}\"")); + assert!(s.contains("Authorization: Bearer $(cat \"$HOME/.codync/token\"")); + assert!(!s.contains("/health")); // The last line prints the version. assert!(s.ends_with(&format!("{VERSION_SCRIPT}\n"))); } From eff3c05bea08024c53bfbfd08e6efd0dcda1880c Mon Sep 17 00:00:00 2001 From: leepokai <109857817+leepokai@users.noreply.github.com> Date: Sun, 6 Dec 2026 23:03:57 +0800 Subject: [PATCH 3/4] Update an older Codync host on the sandbox to the latest release The setup installed the host only when the sandbox had none, so a sandbox with an old codync-host kept it: one test sandbox ran 2.24.0 while the release was 2.57.2. It now reads the latest release's version from its codync-host-compat.json and runs the install script for that release when the host is missing or older. A newer host, such as a dev build, stays, and so does any host when the version cannot be read. The link in /usr/local/bin is made only when nothing is there. Co-Authored-By: Claude Opus 5.5 --- docs/ades.md | 12 ++-- src-tauri/src/ade/codync.rs | 121 ++++++++++++++++++++++++++---------- 2 files changed, 94 insertions(+), 39 deletions(-) diff --git a/docs/ades.md b/docs/ades.md index 73400d1..a0434dd 100644 --- a/docs/ades.md +++ b/docs/ades.md @@ -325,7 +325,7 @@ Amp is a coding agent whose CLI runs in a terminal. Like Herdr, it runs on the s **Install Amp** wakes the sandbox and runs one command on it: - When an SSH command cannot find `amp`, the command runs Amp's install script, `https://ampcode.com/install.sh`. It puts the latest Amp in `~/.amp/bin/amp`, checks its SHA-256 and links it as `~/.local/bin/amp`. Amp is one binary and needs no Node.js. InstaADE runs the script with `~/.local/bin` on its PATH, so the script changes no shell profile. An SSH command's PATH has neither folder, so InstaADE links Amp as `/usr/local/bin/amp`. An Amp the sandbox already has stays as it is. -- The download stops after 60 seconds and the install script after 5 minutes. When the download fails, the error ends with "Could not download Amp's install script." When the script fails or runs out of time, the error shows its last 3 lines and one line that says which. +- The version check stops after 20 seconds, the download after 60 seconds and the install script after 5 minutes. When the download fails, the error ends with "Could not download Amp's install script." When the script fails or runs out of time, the error shows its last 3 lines and one line that says which. - Then it prints `amp --version`. When the command fails or prints no version, the sandbox does not get `amp` in its mark. Then Amp opens, as with **Open in Amp**. **Reconnect** runs the same command again, which installs nothing while Amp is there, and opens Amp. @@ -384,13 +384,13 @@ Rex has no idle probe. Its agents run in terminals of the Rex server on the sand **Install Codync** wakes the sandbox and runs one command on it: -- When an SSH command cannot find `codync-host`, the command runs Codync's install script, `https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh`, with `--host-only`. It puts the latest host in `~/.local/bin/codync-host` and checks its SHA-256. The host is one static binary. An SSH command's PATH lacks `~/.local/bin`, so InstaADE links it as `/usr/local/bin/codync-host`. A host the sandbox already has stays as it is. +- It reads the version of Codync's latest release from the release's `codync-host-compat.json`. When the sandbox has no `codync-host`, or one older than that release, the command runs Codync's install script, `https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh`, with `--host-only` and that release. It puts the host in `~/.local/bin/codync-host` and checks its SHA-256, and restarts a service that runs that file. The host is one static binary. An SSH command's PATH lacks `~/.local/bin`, so InstaADE links it as `/usr/local/bin/codync-host` when nothing is there. A host as new as the release or newer, such as a dev build, stays as it is, and so does any host when the release's version cannot be read. - It writes `/usr/local/bin/codync-tui`, which runs `codync-host tui`, since the SSH session runs one plain word. -- It turns on lingering for the sandbox's user, so the host starts at boot with no login. When the sandbox has no `codync-host` service yet, it runs `codync-host install` from a login shell, which writes and starts a systemd user service that keeps the login PATH, where the agents are. When the service is there, it only starts it, so a **Reconnect** never restarts bots at work. -- The host must answer on `127.0.0.1:19222` within 30 seconds. Then it prints `codync-host --version`. When the command fails or prints no version, the sandbox does not get `codync` in its mark. -- The download stops after 60 seconds and the install script after 5 minutes. When the download fails, the error ends with "Could not download Codync's install script." When the script fails or runs out of time, the error shows its last 3 lines and one line that says which. When the service does not start, the error ends with "Codync could not start its host." or "The Codync host did not start." +- It turns on lingering for the sandbox's user, so the host starts at boot with no login. When the sandbox has no `codync-host` service yet, it runs `codync-host install` from a login shell, which writes and starts a systemd user service that keeps the login PATH, where the agents are. When the service is there, it only starts it, so a **Reconnect** restarts bots at work only to update an older host. +- The service uses port 19222, or the next free port when another user's Codync host holds it (a Codync cloud computer runs one), and `codync-tui` reads the port from the service. The host must take this user's token on that port within 30 seconds. Then it prints `codync-host --version`. When the command fails or prints no version, the sandbox does not get `codync` in its mark. +- The version check stops after 20 seconds, the download after 60 seconds and the install script after 5 minutes. When the download fails, the error ends with "Could not download Codync's install script." When the script fails or runs out of time, the error shows its last 3 lines and one line that says which. When the service does not start, the error ends with "Codync could not start its host." or "The Codync host did not start." -Then Codync opens, as with **Open in Codync**. **Reconnect** runs the same command again, which installs nothing while the host is there, and opens Codync. +Then Codync opens, as with **Open in Codync**. **Reconnect** runs the same command again, which installs nothing while the host is current, and opens Codync. **Open in Codync** opens your terminal as **Open in Amp** does, with the same checks and the same [ordinary token](#ssh-tokens). The SSH session runs `codync-tui`: diff --git a/src-tauri/src/ade/codync.rs b/src-tauri/src/ade/codync.rs index d7d1b4b..0ac95f7 100644 --- a/src-tauri/src/ade/codync.rs +++ b/src-tauri/src/ade/codync.rs @@ -36,43 +36,52 @@ pub const MISSING: &str = "Codync opens in a terminal over SSH, and this compute /// is not installed. pub const VERSION_SCRIPT: &str = "codync-host --version 2>/dev/null || true"; -/// Installs Codync's host on the sandbox when an SSH command cannot find it, runs it as a -/// service, then prints its version. Codync's install script puts `codync-host` in -/// `~/.local/bin` and checks its SHA-256; `--host-only` leaves out the desktop app. An SSH +/// Installs Codync's host on the sandbox when it has none, or updates it when it is older than +/// Codync's latest release, runs it as a service, then prints its version. The latest release's +/// version comes from its `codync-host-compat.json`; when that cannot be read, a host the sandbox +/// has stays as it is. A host newer than the release, such as a dev build, stays too. Codync's +/// install script puts `codync-host` in `~/.local/bin` and checks its SHA-256; `--host-only` +/// leaves out the desktop app; updating, it restarts a service that runs that file. An SSH /// command runs with sshd's PATH, which lacks that folder, so the script links it as -/// `/usr/local/bin/codync-host`, and writes `/usr/local/bin/codync-tui` for the terminal. +/// `/usr/local/bin/codync-host` when nothing is there, and writes +/// `/usr/local/bin/codync-tui` for the terminal. /// `codync-host install` writes and starts a systemd user service, from a login shell so the -/// service gets the PATH where the agents are; a sandbox that has the service only starts it, -/// so a Reconnect never restarts the bots. Lingering keeps the service up from boot, with no +/// service gets the PATH where the agents are; a sandbox that has the service and a current host +/// only starts it, so a Reconnect restarts the bots only to update the host. Lingering keeps the +/// service up from boot, with no /// login. Another user's Codync host can already hold port 19222 (a Codync cloud computer runs /// one as `codync-agent`): then the service is installed on the next free port, `codync-tui` /// reads the port from the service, and the host counts as started only once it takes this -/// user's token, not when anything answers on the port. The host updates itself in place. The -/// download stops after 60 s, the install script after 5 minutes, and the host must answer +/// user's token, not when anything answers on the port. The version check stops after 20 s, the +/// download after 60 s, the install script after 5 minutes, and the host must answer /// within 30 s. A failure prints the last lines of what failed and one short line. pub const SETUP_SCRIPT: &str = r#"set -eu export PATH=/usr/local/bin:/usr/bin:/bin export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT -if ! command -v codync-host >/dev/null 2>&1; then - if [ ! -x "$HOME/.local/bin/codync-host" ]; then - if ! curl -fsSL --max-time 60 https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh -o "$tmp/install.sh"; then - echo "Could not download Codync's install script." >&2 - exit 1 - fi - rc=0 - CODYNC_BIN_DIR="$HOME/.local/bin" timeout 300 sh "$tmp/install.sh" --host-only "$tmp/log" 2>&1 || rc=$? - if [ "$rc" -ne 0 ]; then - tail -n 3 "$tmp/log" >&2 - if [ "$rc" -eq 124 ]; then - echo "Codync's install script did not finish in 5 minutes." >&2 - else - echo "Codync's install script failed." >&2 - fi - exit 1 +older() { [ "$1" != "$2" ] && [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | head -n 1)" = "$1" ]; } +have="$("$HOME/.local/bin/codync-host" --version 2>/dev/null || codync-host --version 2>/dev/null || true)" +have="${have##* }" +latest="$(curl -fsSL --max-time 20 https://github.com/leepokai/Codync/releases/latest/download/codync-host-compat.json 2>/dev/null | sed -n 's/.*"version" *: *"\([0-9][0-9A-Za-z.+-]*\)".*/\1/p' || true)" +if [ -z "$have" ] || { [ -n "$latest" ] && older "$have" "$latest"; }; then + if ! curl -fsSL --max-time 60 https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh -o "$tmp/install.sh"; then + echo "Could not download Codync's install script." >&2 + exit 1 + fi + rc=0 + CODYNC_VERSION="${latest:+v$latest}" CODYNC_BIN_DIR="$HOME/.local/bin" timeout 300 sh "$tmp/install.sh" --host-only "$tmp/log" 2>&1 || rc=$? + if [ "$rc" -ne 0 ]; then + tail -n 3 "$tmp/log" >&2 + if [ "$rc" -eq 124 ]; then + echo "Codync's install script did not finish in 5 minutes." >&2 + else + echo "Codync's install script failed." >&2 fi + exit 1 fi +fi +if [ -x "$HOME/.local/bin/codync-host" ] && [ ! -e /usr/local/bin/codync-host ]; then sudo -n ln -sfn "$HOME/.local/bin/codync-host" /usr/local/bin/codync-host fi cat >"$tmp/codync-tui" <<'TUI' @@ -165,21 +174,28 @@ mod tests { } #[test] - fn setup_installs_only_when_an_ssh_command_cannot_find_the_host() { + fn setup_installs_the_host_when_it_is_missing_or_older_than_the_release() { let s = SETUP_SCRIPT; assert!(s.starts_with("set -eu\nexport PATH=/usr/local/bin:/usr/bin:/bin\n")); - let check = s.find("if ! command -v codync-host").unwrap(); - let installed = s - .find("if [ ! -x \"$HOME/.local/bin/codync-host\" ]") + let have = s + .find("have=\"$(\"$HOME/.local/bin/codync-host\" --version 2>/dev/null || codync-host --version") + .unwrap(); + let latest = s + .find("curl -fsSL --max-time 20 https://github.com/leepokai/Codync/releases/latest/download/codync-host-compat.json") + .unwrap(); + let check = s + .find("if [ -z \"$have\" ] || { [ -n \"$latest\" ] && older \"$have\" \"$latest\"; }; then") .unwrap(); let download = s .find("curl -fsSL --max-time 60 https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh -o") .unwrap(); + // The release it read is the one installed, not whatever is latest a moment later. let install = s - .find("timeout 300 sh \"$tmp/install.sh\" --host-only") + .find("CODYNC_VERSION=\"${latest:+v$latest}\" CODYNC_BIN_DIR=\"$HOME/.local/bin\" timeout 300 sh \"$tmp/install.sh\" --host-only") .unwrap(); + // The link never replaces another file there. let link = s - .find("sudo -n ln -sfn \"$HOME/.local/bin/codync-host\" /usr/local/bin/codync-host") + .find("if [ -x \"$HOME/.local/bin/codync-host\" ] && [ ! -e /usr/local/bin/codync-host ]; then\n sudo -n ln -sfn \"$HOME/.local/bin/codync-host\" /usr/local/bin/codync-host") .unwrap(); let tui = s .find("sudo -n install -m 0755 \"$tmp/codync-tui\" /usr/local/bin/codync-tui") @@ -190,8 +206,9 @@ mod tests { .unwrap(); let ready = s.find("\"http://127.0.0.1:$port/api/hello\"").unwrap(); assert!( - check < installed - && installed < download + have < latest + && latest < check + && check < download && download < install && install < link && link < tui @@ -205,7 +222,7 @@ mod tests { assert!(s.contains("tail -n 3 \"$tmp/log\" >&2")); assert!(s.contains("echo \"Codync's install script failed.\" >&2")); assert!(s.contains("echo \"The Codync host did not start.\" >&2")); - // A sandbox with the service only starts it, so a Reconnect never restarts the bots. + // A sandbox with the service and a current host only starts it. assert!(s.contains("systemctl --user start codync-host")); // Another user's Codync host can hold 19222 (a Codync cloud computer runs one): the // service moves to a free port, the terminal UI reads it from the service, and the host @@ -218,6 +235,44 @@ mod tests { assert!(s.ends_with(&format!("{VERSION_SCRIPT}\n"))); } + /// Runs the setup's own version check and release parsing: an older host is updated, the + /// same or a newer one (a dev build) is kept, and versions compare by number. + #[test] + fn setup_updates_only_a_host_older_than_the_release() { + let line = |start: &str| { + SETUP_SCRIPT + .lines() + .find(|l| l.starts_with(start)) + .unwrap() + .to_string() + }; + let older = line("older() "); + for (have, latest, want) in [ + ("2.24.0", "2.57.2", true), + ("2.9.0", "2.10.0", true), + ("2.57.2", "2.57.2", false), + ("2.58.1", "2.57.2", false), + ] { + let out = std::process::Command::new("sh") + .arg("-c") + .arg(format!("{older}\nolder \"$1\" \"$2\"")) + .args(["sh", have, latest]) + .status() + .unwrap(); + assert_eq!(out.success(), want, "{have} older than {latest}"); + } + let read = line("latest="); + let sed = &read[read.find("sed -n").unwrap()..read.rfind(" || true").unwrap()]; + let out = std::process::Command::new("sh") + .arg("-c") + .arg(format!( + "printf '%s' '{{\"version\":\"2.57.2\",\"minApp\":\"2.57.0\"}}' | {sed}" + )) + .output() + .unwrap(); + assert_eq!(String::from_utf8_lossy(&out.stdout).trim(), "2.57.2"); + } + #[test] fn the_terminal_runs_the_tui_and_needs_only_the_ssh_client_here() { assert_eq!(TERMINAL.command, "codync-tui"); From cca07ec2102a299aa85aafcacca3361b3a050f49 Mon Sep 17 00:00:00 2001 From: leepokai <109857817+leepokai@users.noreply.github.com> Date: Sun, 6 Dec 2026 23:19:54 +0800 Subject: [PATCH 4/4] Use one Codync host throughout the setup, and read its port from systemd After an update to ~/.local/bin, an older codync-host earlier on the PATH kept running the service, the terminal UI and the version check. The setup now picks one host, the one in ~/.local/bin or else the one on the PATH, and uses it for all three; a service that runs another file is installed again on its port. codync-tui and the setup read the service's port from `systemctl --user cat`, so a custom XDG_CONFIG_HOME no longer hides it, and reading the host's version stops after 10 s. The docs say the setup updates an older host, and README says an idle sandbox can sleep and pause the bots. Amp's timeouts line, changed by mistake in the last commit, is as before. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- docs/ades.md | 12 ++-- src-tauri/src/ade/codync.rs | 127 +++++++++++++++++++++++++++--------- 3 files changed, 103 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index eaa3a0c..0579608 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Every **Open in** wakes the sandbox first. - **[Codync](docs/ades.md#codync)** · no app needed here, runs in your terminal - Installs Codync's host on the sandbox as a service and opens Codync's terminal UI in your terminal over SSH. - First time: sign in to the agents your bots use on the sandbox (such as `claude` or `codex login` in **Open in Terminal**). To message the bots from your phone, open **Pair phone…** in Codync's terminal UI and scan the code with the Codync app. - - Closing the terminal leaves the host and its bots running on the sandbox. + - Closing the terminal leaves the host and its bots on the sandbox, but the sandbox may sleep when idle and pause them. A sleeping sandbox cannot reach your phone until something wakes it, such as **Open in Codync**. > [!NOTE] > If a sandbox stays awake while cmux, Orca, Paseo or T3 Code is open, update InstaADE to 0.1.14 or later, then open the sandbox from InstaADE again. diff --git a/docs/ades.md b/docs/ades.md index a0434dd..7f091ff 100644 --- a/docs/ades.md +++ b/docs/ades.md @@ -325,7 +325,7 @@ Amp is a coding agent whose CLI runs in a terminal. Like Herdr, it runs on the s **Install Amp** wakes the sandbox and runs one command on it: - When an SSH command cannot find `amp`, the command runs Amp's install script, `https://ampcode.com/install.sh`. It puts the latest Amp in `~/.amp/bin/amp`, checks its SHA-256 and links it as `~/.local/bin/amp`. Amp is one binary and needs no Node.js. InstaADE runs the script with `~/.local/bin` on its PATH, so the script changes no shell profile. An SSH command's PATH has neither folder, so InstaADE links Amp as `/usr/local/bin/amp`. An Amp the sandbox already has stays as it is. -- The version check stops after 20 seconds, the download after 60 seconds and the install script after 5 minutes. When the download fails, the error ends with "Could not download Amp's install script." When the script fails or runs out of time, the error shows its last 3 lines and one line that says which. +- The download stops after 60 seconds and the install script after 5 minutes. When the download fails, the error ends with "Could not download Amp's install script." When the script fails or runs out of time, the error shows its last 3 lines and one line that says which. - Then it prints `amp --version`. When the command fails or prints no version, the sandbox does not get `amp` in its mark. Then Amp opens, as with **Open in Amp**. **Reconnect** runs the same command again, which installs nothing while Amp is there, and opens Amp. @@ -384,11 +384,11 @@ Rex has no idle probe. Its agents run in terminals of the Rex server on the sand **Install Codync** wakes the sandbox and runs one command on it: -- It reads the version of Codync's latest release from the release's `codync-host-compat.json`. When the sandbox has no `codync-host`, or one older than that release, the command runs Codync's install script, `https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh`, with `--host-only` and that release. It puts the host in `~/.local/bin/codync-host` and checks its SHA-256, and restarts a service that runs that file. The host is one static binary. An SSH command's PATH lacks `~/.local/bin`, so InstaADE links it as `/usr/local/bin/codync-host` when nothing is there. A host as new as the release or newer, such as a dev build, stays as it is, and so does any host when the release's version cannot be read. +- It reads the version of Codync's latest release from the release's `codync-host-compat.json`. When the sandbox has no `codync-host`, or one older than that release, the command runs Codync's install script, `https://raw.githubusercontent.com/leepokai/Codync/main/packaging/install.sh`, with `--host-only` and that release. It puts the host in `~/.local/bin/codync-host` and checks its SHA-256, and restarts a service that runs that file. The host is one static binary. An SSH command's PATH lacks `~/.local/bin`, so InstaADE links it as `/usr/local/bin/codync-host` when nothing is there. A host as new as the release or newer, such as a dev build, stays as it is, and so does any host when the release's version cannot be read. The setup then uses one host throughout, the one in `~/.local/bin` or else the one on the PATH, for the service, `codync-tui` and the version it prints, so an older `codync-host` elsewhere on the PATH is not used after an update. - It writes `/usr/local/bin/codync-tui`, which runs `codync-host tui`, since the SSH session runs one plain word. -- It turns on lingering for the sandbox's user, so the host starts at boot with no login. When the sandbox has no `codync-host` service yet, it runs `codync-host install` from a login shell, which writes and starts a systemd user service that keeps the login PATH, where the agents are. When the service is there, it only starts it, so a **Reconnect** restarts bots at work only to update an older host. -- The service uses port 19222, or the next free port when another user's Codync host holds it (a Codync cloud computer runs one), and `codync-tui` reads the port from the service. The host must take this user's token on that port within 30 seconds. Then it prints `codync-host --version`. When the command fails or prints no version, the sandbox does not get `codync` in its mark. -- The version check stops after 20 seconds, the download after 60 seconds and the install script after 5 minutes. When the download fails, the error ends with "Could not download Codync's install script." When the script fails or runs out of time, the error shows its last 3 lines and one line that says which. When the service does not start, the error ends with "Codync could not start its host." or "The Codync host did not start." +- It turns on lingering for the sandbox's user, so the host starts at boot with no login. When the sandbox has no `codync-host` service yet, it runs `codync-host install` from a login shell, which writes and starts a systemd user service that keeps the login PATH, where the agents are. When the service is there and runs that host, it only starts it, so a **Reconnect** restarts bots at work only to update an older host. A service that runs another file is installed again, on its port. +- The service uses port 19222, or the next free port when another user's Codync host holds it (a Codync cloud computer runs one), and `codync-tui` reads the port from the service as systemd reports it (`systemctl --user cat`), wherever its unit file is. The host must take this user's token on that port within 30 seconds. Then it prints `codync-host --version`. When the command fails or prints no version, the sandbox does not get `codync` in its mark. +- Reading the host's version stops after 10 seconds, the release's version after 20 seconds, the download after 60 seconds and the install script after 5 minutes. When the download fails, the error ends with "Could not download Codync's install script." When the script fails or runs out of time, the error shows its last 3 lines and one line that says which. When the service does not start, the error ends with "Codync could not start its host." or "The Codync host did not start." Then Codync opens, as with **Open in Codync**. **Reconnect** runs the same command again, which installs nothing while the host is current, and opens Codync. @@ -406,7 +406,7 @@ The first time: - Codync keeps its data on the sandbox, in `~/.codync` under `/data/home`, which a pause or a stop keeps. - Closing the terminal ends only the terminal UI. The host and its bots keep running on the sandbox. -- The host updates itself in place, so the link follows. InstaADE never updates it. +- The host updates itself in place, so the link follows. **Install Codync** and **Reconnect** also update a host older than Codync's latest release. On your computer, InstaADE needs only the OpenSSH client, as for Herdr and Amp. Settings shows its version next to Codync. Without it, nothing wakes or changes, and InstaADE asks you to install the OpenSSH client. diff --git a/src-tauri/src/ade/codync.rs b/src-tauri/src/ade/codync.rs index 0ac95f7..45cd82f 100644 --- a/src-tauri/src/ade/codync.rs +++ b/src-tauri/src/ade/codync.rs @@ -34,34 +34,39 @@ pub const MISSING: &str = "Codync opens in a terminal over SSH, and this compute /// Prints the host's version on the sandbox, such as `codync-host 2.56.0`, or nothing when it /// is not installed. -pub const VERSION_SCRIPT: &str = "codync-host --version 2>/dev/null || true"; +pub const VERSION_SCRIPT: &str = "\"$HOME/.local/bin/codync-host\" --version 2>/dev/null || codync-host --version 2>/dev/null || true"; /// Installs Codync's host on the sandbox when it has none, or updates it when it is older than /// Codync's latest release, runs it as a service, then prints its version. The latest release's /// version comes from its `codync-host-compat.json`; when that cannot be read, a host the sandbox -/// has stays as it is. A host newer than the release, such as a dev build, stays too. Codync's -/// install script puts `codync-host` in `~/.local/bin` and checks its SHA-256; `--host-only` -/// leaves out the desktop app; updating, it restarts a service that runs that file. An SSH -/// command runs with sshd's PATH, which lacks that folder, so the script links it as -/// `/usr/local/bin/codync-host` when nothing is there, and writes -/// `/usr/local/bin/codync-tui` for the terminal. -/// `codync-host install` writes and starts a systemd user service, from a login shell so the -/// service gets the PATH where the agents are; a sandbox that has the service and a current host -/// only starts it, so a Reconnect restarts the bots only to update the host. Lingering keeps the -/// service up from boot, with no -/// login. Another user's Codync host can already hold port 19222 (a Codync cloud computer runs -/// one as `codync-agent`): then the service is installed on the next free port, `codync-tui` -/// reads the port from the service, and the host counts as started only once it takes this -/// user's token, not when anything answers on the port. The version check stops after 20 s, the -/// download after 60 s, the install script after 5 minutes, and the host must answer -/// within 30 s. A failure prints the last lines of what failed and one short line. +/// has stays as it is. A host newer than the release, such as a dev build, stays too. The setup +/// then uses that one host throughout (the one in `~/.local/bin`, else the one on the PATH): for +/// the service, which it installs again when the service runs another file, for `codync-tui` and +/// for the version it prints. The port comes from the unit as systemd reports it, wherever it is. +/// Codync's install script puts `codync-host` in `~/.local/bin` and checks its SHA-256; +/// `--host-only` leaves out the desktop app; updating, it restarts a service that runs that file. +/// An SSH command runs with sshd's PATH, which lacks that folder, so the script links it as +/// `/usr/local/bin/codync-host` when nothing is there, and writes `/usr/local/bin/codync-tui` for +/// the terminal. `codync-host install` writes and starts a systemd user service, from a login +/// shell so the service gets the PATH where the agents are; a sandbox whose service runs a current +/// host only starts it, so a Reconnect restarts the bots only to update the host. Lingering keeps +/// the service up from boot, with no login. Another user's Codync host can already hold port 19222 +/// (a Codync cloud computer runs one as `codync-agent`): then the service is installed on the next +/// free port, `codync-tui` reads the port from the service, and the host counts as started only +/// once it takes this user's token, not when anything answers on the port. Reading the host's +/// version stops after 10 s, the release's version after 20 s, the download after 60 s, the +/// install script after 5 minutes, and the host must answer within 30 s. A failure prints the last +/// lines of what failed and one short line. pub const SETUP_SCRIPT: &str = r#"set -eu export PATH=/usr/local/bin:/usr/bin:/bin export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT older() { [ "$1" != "$2" ] && [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | head -n 1)" = "$1" ]; } -have="$("$HOME/.local/bin/codync-host" --version 2>/dev/null || codync-host --version 2>/dev/null || true)" +host="$HOME/.local/bin/codync-host" +[ -x "$host" ] || host="$(command -v codync-host || true)" +have="" +[ -z "$host" ] || have="$(timeout 10 "$host" --version 2>/dev/null || true)" have="${have##* }" latest="$(curl -fsSL --max-time 20 https://github.com/leepokai/Codync/releases/latest/download/codync-host-compat.json 2>/dev/null | sed -n 's/.*"version" *: *"\([0-9][0-9A-Za-z.+-]*\)".*/\1/p' || true)" if [ -z "$have" ] || { [ -n "$latest" ] && older "$have" "$latest"; }; then @@ -80,21 +85,26 @@ if [ -z "$have" ] || { [ -n "$latest" ] && older "$have" "$latest"; }; then fi exit 1 fi + host="$HOME/.local/bin/codync-host" fi if [ -x "$HOME/.local/bin/codync-host" ] && [ ! -e /usr/local/bin/codync-host ]; then sudo -n ln -sfn "$HOME/.local/bin/codync-host" /usr/local/bin/codync-host fi cat >"$tmp/codync-tui" <<'TUI' #!/bin/sh -port="$(sed -n 's/.* --port \([0-9][0-9]*\).*/\1/p' "$HOME/.config/systemd/user/codync-host.service" 2>/dev/null)" -exec codync-host tui --port "${port:-19222}" "$@" +export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" +port="$(systemctl --user cat codync-host 2>/dev/null | sed -n 's/.* --port \([0-9][0-9]*\).*/\1/p' | head -n 1)" +host="$HOME/.local/bin/codync-host" +[ -x "$host" ] || host=codync-host +exec "$host" tui --port "${port:-19222}" "$@" TUI if ! cmp -s "$tmp/codync-tui" /usr/local/bin/codync-tui; then sudo -n install -m 0755 "$tmp/codync-tui" /usr/local/bin/codync-tui fi sudo -n loginctl enable-linger "$(id -un)" >/dev/null 2>&1 || true -unit="$HOME/.config/systemd/user/codync-host.service" -had="$(sed -n 's/.* --port \([0-9][0-9]*\).*/\1/p' "$unit" 2>/dev/null || true)" +unit="$(systemctl --user cat codync-host 2>/dev/null || true)" +had="$(printf '%s\n' "$unit" | sed -n 's/.* --port \([0-9][0-9]*\).*/\1/p' | head -n 1)" +real="$(readlink -f "$host")" port="${had:-19222}" if ! systemctl --user is-active --quiet codync-host; then while :; do @@ -109,10 +119,10 @@ if ! systemctl --user is-active --quiet codync-host; then done fi rc=0 -if [ -n "$had" ] && [ "$port" = "$had" ]; then +if [ -n "$had" ] && [ "$port" = "$had" ] && printf '%s' "$unit" | grep -qF -e "$host" -e "$real"; then timeout -k 10 60 systemctl --user start codync-host "$tmp/log" 2>&1 || rc=$? else - timeout -k 10 60 bash -lc "exec codync-host install --port $port" "$tmp/log" 2>&1 || rc=$? + timeout -k 10 60 bash -lc "exec '$host' install --port $port" "$tmp/log" 2>&1 || rc=$? fi if [ "$rc" -ne 0 ]; then tail -n 3 "$tmp/log" >&2 @@ -127,7 +137,7 @@ until curl -fsS --max-time 2 -X POST -H "Authorization: Bearer $(cat "$HOME/.cod fi sleep 1 done -codync-host --version 2>/dev/null || true +"$HOME/.local/bin/codync-host" --version 2>/dev/null || codync-host --version 2>/dev/null || true "#; /// Parses `codync-host 2.56.0` into `2.56.0`: the version on the last line that has one. @@ -177,9 +187,12 @@ mod tests { fn setup_installs_the_host_when_it_is_missing_or_older_than_the_release() { let s = SETUP_SCRIPT; assert!(s.starts_with("set -eu\nexport PATH=/usr/local/bin:/usr/bin:/bin\n")); + // One host is used throughout: the one in ~/.local/bin, else the one on the PATH. A + // host that hangs holds the setup up for 10 s at most. let have = s - .find("have=\"$(\"$HOME/.local/bin/codync-host\" --version 2>/dev/null || codync-host --version") + .find("host=\"$HOME/.local/bin/codync-host\"\n[ -x \"$host\" ] || host=\"$(command -v codync-host || true)\"") .unwrap(); + assert!(s.contains("have=\"$(timeout 10 \"$host\" --version 2>/dev/null || true)\"")); let latest = s .find("curl -fsSL --max-time 20 https://github.com/leepokai/Codync/releases/latest/download/codync-host-compat.json") .unwrap(); @@ -202,7 +215,7 @@ mod tests { .unwrap(); let free = s.find("[ \"$rc\" -eq 7 ] && break").unwrap(); let service = s - .find("bash -lc \"exec codync-host install --port $port\"") + .find("bash -lc \"exec '$host' install --port $port\"") .unwrap(); let ready = s.find("\"http://127.0.0.1:$port/api/hello\"").unwrap(); assert!( @@ -222,13 +235,19 @@ mod tests { assert!(s.contains("tail -n 3 \"$tmp/log\" >&2")); assert!(s.contains("echo \"Codync's install script failed.\" >&2")); assert!(s.contains("echo \"The Codync host did not start.\" >&2")); - // A sandbox with the service and a current host only starts it. - assert!(s.contains("systemctl --user start codync-host")); + // After an update the setup uses the new host, and a service that runs another file is + // installed again; a sandbox whose service runs this host only starts it. + assert!(s.contains(" host=\"$HOME/.local/bin/codync-host\"\nfi\n")); + assert!(s.contains("&& printf '%s' \"$unit\" | grep -qF -e \"$host\" -e \"$real\"; then\n timeout -k 10 60 systemctl --user start codync-host")); + // systemd says where the service is, so a custom XDG_CONFIG_HOME does not hide its port. + assert!(s.contains("unit=\"$(systemctl --user cat codync-host 2>/dev/null || true)\"")); + assert!(!s.contains(".config/systemd")); // Another user's Codync host can hold 19222 (a Codync cloud computer runs one): the // service moves to a free port, the terminal UI reads it from the service, and the host // counts as started only once it takes this user's token. assert!(s.contains("if ! systemctl --user is-active --quiet codync-host; then")); - assert!(s.contains("exec codync-host tui --port \"${port:-19222}\"")); + assert!(s.contains("port=\"$(systemctl --user cat codync-host 2>/dev/null | sed")); + assert!(s.contains("exec \"$host\" tui --port \"${port:-19222}\"")); assert!(s.contains("Authorization: Bearer $(cat \"$HOME/.codync/token\"")); assert!(!s.contains("/health")); // The last line prints the version. @@ -273,11 +292,57 @@ mod tests { assert_eq!(String::from_utf8_lossy(&out.stdout).trim(), "2.57.2"); } + /// Runs the `codync-tui` the setup writes, with a fake `systemctl` and host: it takes the + /// port from the unit systemd reports and runs the host in ~/.local/bin, and falls back to + /// 19222 when there is no unit. + #[test] + fn the_terminal_ui_runs_the_setups_host_on_the_services_port() { + let tui = SETUP_SCRIPT + .split("<<'TUI'\n") + .nth(1) + .and_then(|rest| rest.split("\nTUI\n").next()) + .unwrap(); + let dir = std::env::temp_dir().join(format!("codync-tui-{}", std::process::id())); + let bin = dir.join("bin"); + let local = dir.join(".local/bin"); + std::fs::create_dir_all(&bin).unwrap(); + std::fs::create_dir_all(&local).unwrap(); + let write = |path: std::path::PathBuf, body: &str| { + std::fs::write(&path, body).unwrap(); + let status = std::process::Command::new("chmod") + .arg("+x") + .arg(&path) + .status() + .unwrap(); + assert!(status.success()); + }; + write(dir.join("codync-tui"), tui); + write(local.join("codync-host"), "#!/bin/sh\necho \"local $*\"\n"); + let run = |unit: &str| { + write( + bin.join("systemctl"), + &format!("#!/bin/sh\n[ -n '{unit}' ] || exit 1\nprintf '%s\\n' '{unit}'\n"), + ); + let out = std::process::Command::new(dir.join("codync-tui")) + .env("HOME", &dir) + .env("PATH", format!("{}:/usr/bin:/bin", bin.display())) + .output() + .unwrap(); + String::from_utf8_lossy(&out.stdout).trim().to_string() + }; + assert_eq!( + run("ExecStart=\"/data/home/.local/bin/codync-host\" serve --port 19223"), + "local tui --port 19223" + ); + assert_eq!(run(""), "local tui --port 19222"); + std::fs::remove_dir_all(&dir).unwrap(); + } + #[test] fn the_terminal_runs_the_tui_and_needs_only_the_ssh_client_here() { assert_eq!(TERMINAL.command, "codync-tui"); assert!(TERMINAL.app.is_none()); - assert!(SETUP_SCRIPT.contains("exec codync-host tui")); + assert!(SETUP_SCRIPT.contains("exec \"$host\" tui")); assert_eq!(DOWNLOAD_URL, crate::ade::herdr::DOWNLOAD_URL); assert!(MISSING.contains("no OpenSSH client")); assert!(version(std::path::Path::new("/nonexistent/ssh")).is_err());