diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 13b4fcf..d4b3fb7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,33 +1,71 @@ -# A tag v builds isbell for Apple silicon Macs and publishes it as a GitHub release, with -# the isbell-tools skill of that version, which is then mirrored to isbell.fmap.dev/releases for -# install.sh and the skill's update.sh to download (docs/development.md). The asset names carry no -# version, so a version's directory, or latest, finds them. +# A tag v builds isbell for Apple silicon Macs and for Linux (x86_64 and arm64, static with +# musl, for any distribution) and publishes them as a GitHub release, with the isbell-tools skill of +# that version, which is then mirrored to isbell.fmap.dev/releases for install.sh and the skill's +# update.sh to download (docs/development.md). The asset names carry no version, so a version's +# directory, or latest, finds them. A pull request that changes this file builds them too, without +# publishing, to see them build before a tag does. name: Release on: push: tags: ["v*"] + pull_request: + paths: [".github/workflows/release.yml"] permissions: contents: write jobs: - macos-arm64: - runs-on: macos-latest + build: + strategy: + matrix: + include: + - os: macos-latest + target: aarch64-apple-darwin + - os: ubuntu-24.04 + target: x86_64-unknown-linux-musl + - os: ubuntu-24.04-arm + target: aarch64-unknown-linux-musl + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Check the tag names the crate's version + if: startsWith(github.ref, 'refs/tags/') run: | version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "isbell") | .version') test "${GITHUB_REF_NAME#v}" = "$version" || { echo "tag $GITHUB_REF_NAME, crate $version"; exit 1; } - - run: cargo build --release --locked -p isbell + # ring, the one dependency with C in it, builds for musl with musl-gcc. + - name: Add musl + if: runner.os == 'Linux' + run: | + sudo apt-get update && sudo apt-get install -y musl-tools + rustup target add ${{ matrix.target }} + + - run: cargo build --release --locked -p isbell --target ${{ matrix.target }} - name: Package run: | - tar -C target/release -czf isbell-aarch64-apple-darwin.tar.gz isbell - shasum -a 256 isbell-aarch64-apple-darwin.tar.gz > isbell-aarch64-apple-darwin.tar.gz.sha256 + asset=isbell-${{ matrix.target }}.tar.gz + tar -C target/${{ matrix.target }}/release -czf "$asset" isbell + shasum -a 256 "$asset" > "$asset.sha256" + + - uses: actions/upload-artifact@v4 + with: + name: isbell-${{ matrix.target }} + path: isbell-${{ matrix.target }}.tar.gz* + + publish: + if: startsWith(github.ref, 'refs/tags/') + needs: build + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + merge-multiple: true # VERSION, only in the package, tells the skill which isbell it goes with: a checkout has none. - name: Package the skill @@ -40,7 +78,4 @@ jobs: - name: Publish env: GH_TOKEN: ${{ github.token }} - run: | - gh release create "$GITHUB_REF_NAME" --generate-notes \ - isbell-aarch64-apple-darwin.tar.gz isbell-aarch64-apple-darwin.tar.gz.sha256 \ - isbell-tools.tar.gz isbell-tools.tar.gz.sha256 + run: gh release create "$GITHUB_REF_NAME" --generate-notes isbell-*.tar.gz isbell-*.tar.gz.sha256 diff --git a/README.md b/README.md index d70f9fc..e741659 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,14 @@ guarantee of availability; you can [run your own](docs/self-hosting.md). ## Get started -You need a Mac with Apple silicon ([other systems](docs/install.md#from-source)) and an agent: -Claude Code, Codex and pi are fully supported; any other works through the terminal. +You need a Mac with Apple silicon or a Linux machine, x86_64 or arm64 +([other systems](docs/install.md#from-source)), and an agent: Claude Code, Codex and pi are fully +supported; any other works through the terminal. -Paste this to the agent on your Mac: +Paste this to the agent on your machine: ```text -Set up Isbell on this Mac: read https://raw.githubusercontent.com/bencode/Isbell/main/docs/setup.md and follow it. +Set up Isbell on this machine: read https://raw.githubusercontent.com/bencode/Isbell/main/docs/setup.md and follow it. ``` It installs `isbell` (and herdr, if you agree) and runs the gateway. It never sees your space key. @@ -35,7 +36,7 @@ Then: 3. Run `herdr` and start your agents in it: Isbell only sees what runs there. The key is the only credential for your space: anyone who has it can reach the agents on your -machines, so keep it to yourself. For another Mac, paste the same text to the agent there, and run +machines, so keep it to yourself. For another machine, paste the same text to the agent there, and run `isbell space join ` yourself when it asks. To do it all by hand: [docs/install.md](docs/install.md). ## What it does diff --git a/crates/isbell/src/cli/gateway.rs b/crates/isbell/src/cli/gateway.rs index 26a9ddc..6c2e901 100644 --- a/crates/isbell/src/cli/gateway.rs +++ b/crates/isbell/src/cli/gateway.rs @@ -14,7 +14,8 @@ use crate::service; pub enum GatewayCmd { /// Run the gateway in the foreground. Run, - /// Run the gateway as a login service (macOS): now, at every login, and again after a failure. + /// Run the gateway as a login service (launchd on macOS, systemd on Linux): now, at every login, + /// and again after a failure. Install, /// Stop the service and remove it; the herdr server keeps running. Uninstall, @@ -23,8 +24,11 @@ pub enum GatewayCmd { } pub async fn run(ctx: Ctx, cmd: GatewayCmd) -> Result<(), CliError> { - if !matches!(cmd, GatewayCmd::Run) && !cfg!(target_os = "macos") { - return Err(CliError::new("unsupported", "the gateway service needs macOS (launchd)")); + if !matches!(cmd, GatewayCmd::Run) && !service::SUPPORTED { + return Err(CliError::new( + "unsupported", + "the gateway service needs macOS (launchd) or Linux (systemd); elsewhere, run `isbell gateway run` under a supervisor of your own", + )); } match cmd { GatewayCmd::Run => run_gateway(ctx).await, @@ -77,10 +81,20 @@ fn install(ctx: &Ctx) -> Result<(), CliError> { true => ctx.out.json(&files), false => println!( "gateway service installed and started\n {}\n log: {}", - files.plist.display(), + files.file.display(), files.log.display() ), } + // On standard error, which leaves the JSON alone. + match service::stops_at_logout() { + Ok(true) => eprintln!( + "It runs while you are logged in. To keep it running after you log out, and start it at boot:\n sudo loginctl enable-linger $USER" + ), + Ok(false) => {} + Err(err) => { + eprintln!("cannot tell whether the service keeps running after you log out: {err:#}") + } + } Ok(()) } diff --git a/crates/isbell/src/gateway/upgrade.rs b/crates/isbell/src/gateway/upgrade.rs index ea14156..68c6b3c 100644 --- a/crates/isbell/src/gateway/upgrade.rs +++ b/crates/isbell/src/gateway/upgrade.rs @@ -19,7 +19,7 @@ pub async fn upgrade() -> Result { |what: &str, err: std::io::Error| RpcError::new("upgrade_failed", format!("{what}: {err}")); let home = env_path("HOME").ok_or_else(|| RpcError::new("upgrade_failed", "HOME is not set"))?; - let dir = home.join("Library/Logs/isbell"); + let dir = crate::service::log_dir(&home); std::fs::create_dir_all(&dir).map_err(|err| failed("cannot create the log directory", err))?; let path = dir.join("upgrade.log"); let log = File::create(&path).map_err(|err| failed("cannot write upgrade.log", err))?; diff --git a/crates/isbell/src/service.rs b/crates/isbell/src/service/launchd.rs similarity index 65% rename from crates/isbell/src/service.rs rename to crates/isbell/src/service/launchd.rs index 33b38c0..01d6436 100644 --- a/crates/isbell/src/service.rs +++ b/crates/isbell/src/service/launchd.rs @@ -9,23 +9,10 @@ use std::process::{Command, Output}; use anyhow::{Context, Result, bail}; use serde::Serialize; -use crate::env_path; +use super::Status; const LABEL: &str = "dev.fmap.isbell.gateway"; -#[derive(Debug, Serialize)] -pub struct Files { - pub plist: PathBuf, - pub log: PathBuf, -} - -#[derive(Debug, Serialize)] -pub struct Status { - pub installed: bool, - pub running: bool, - pub pid: Option, -} - /// What launchd runs; see launchd.plist(5). #[derive(Serialize)] #[serde(rename_all = "PascalCase")] @@ -50,37 +37,37 @@ struct KeepAlive { successful_exit: bool, } -/// Writes the service for `exe` with `path_env` as its PATH, and (re)starts it. -pub fn install(exe: &Path, path_env: &OsStr) -> Result { - let home = home()?; - let files = files(&home); - for dir in [files.plist.parent(), files.log.parent()].into_iter().flatten() { - std::fs::create_dir_all(dir).with_context(|| format!("cannot create {}", dir.display()))?; - } +pub(super) fn file(home: &Path) -> PathBuf { + home.join("Library/LaunchAgents").join(format!("{LABEL}.plist")) +} + +/// Writes the service to `plist` for `exe` with `path_env` as its PATH, logging to `log`, and +/// (re)starts it. +pub(super) fn install( + exe: &Path, + path_env: &OsStr, + home: &Path, + plist: &Path, + log: &Path, +) -> Result<()> { if loaded()? { launchctl(&["bootout", &target()])?; } - let agent = agent(exe, path_env, &home, &files.log); - plist::to_file_xml(&files.plist, &agent).context("cannot write the service file")?; - launchctl(&["bootstrap", &domain(), &files.plist.to_string_lossy()])?; - Ok(files) + plist::to_file_xml(plist, &agent(exe, path_env, home, log)) + .context("cannot write the service file")?; + launchctl(&["bootstrap", &domain(), &plist.to_string_lossy()]) } -/// Stops the service and removes it; false when it was not installed. -pub fn uninstall() -> Result { +/// Stops the service, when it is loaded. +pub(super) fn stop() -> Result<()> { if loaded()? { launchctl(&["bootout", &target()])?; } - let plist = files(&home()?).plist; - match std::fs::remove_file(&plist) { - Ok(()) => Ok(true), - Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(false), - Err(err) => Err(err).with_context(|| format!("cannot remove {}", plist.display())), - } + Ok(()) } -pub fn status() -> Result { - let installed = files(&home()?).plist.exists(); +pub(super) fn status(file: &Path) -> Result { + let installed = file.exists(); let printed = print()?; let pid = match printed.status.success() { true => pid(&String::from_utf8_lossy(&printed.stdout)), @@ -103,17 +90,6 @@ fn agent(exe: &Path, path_env: &OsStr, home: &Path, log: &Path) -> Agent { } } -fn files(home: &Path) -> Files { - Files { - plist: home.join("Library/LaunchAgents").join(format!("{LABEL}.plist")), - log: home.join("Library/Logs/isbell/gateway.log"), - } -} - -fn home() -> Result { - env_path("HOME").context("HOME is not set") -} - /// This user's login session, where user agents run. fn domain() -> String { format!("gui/{}", rustix::process::getuid().as_raw()) diff --git a/crates/isbell/src/service/mod.rs b/crates/isbell/src/service/mod.rs new file mode 100644 index 0000000..b652e3d --- /dev/null +++ b/crates/isbell/src/service/mod.rs @@ -0,0 +1,103 @@ +//! The gateway as a login service: a launchd user agent on macOS, a systemd user unit on Linux. +//! Either starts it now and again after a failure, and leaves it stopped after a clean exit (another +//! gateway took the machine over). Both are built everywhere, for their tests to run on any system. + +mod launchd; +mod systemd; + +use std::ffi::OsStr; +use std::path::{Path, PathBuf}; + +use anyhow::{Context, Result}; +use serde::Serialize; + +use crate::env_path; + +/// Whether this system has a service manager isbell knows. +pub const SUPPORTED: bool = cfg!(any(target_os = "macos", target_os = "linux")); +const LINUX: bool = cfg!(target_os = "linux"); + +#[derive(Debug, Serialize)] +pub struct Files { + /// What the service manager reads: the launchd plist, or the systemd unit. + pub file: PathBuf, + pub log: PathBuf, +} + +#[derive(Debug, Serialize)] +pub struct Status { + pub installed: bool, + pub running: bool, + pub pid: Option, +} + +/// Writes the service for `exe` with `path_env` as its PATH, and (re)starts it. +pub fn install(exe: &Path, path_env: &OsStr) -> Result { + let home = home()?; + let files = Files { file: file(&home), log: log_dir(&home).join("gateway.log") }; + for dir in [files.file.parent(), files.log.parent()].into_iter().flatten() { + std::fs::create_dir_all(dir).with_context(|| format!("cannot create {}", dir.display()))?; + } + match LINUX { + true => systemd::install(exe, path_env, &home, &files.file, &files.log)?, + false => launchd::install(exe, path_env, &home, &files.file, &files.log)?, + } + Ok(files) +} + +/// Stops the service and removes it; false when it was not installed. +pub fn uninstall() -> Result { + let file = file(&home()?); + match LINUX { + true => systemd::stop(&file)?, + false => launchd::stop()?, + } + match std::fs::remove_file(&file) { + Ok(()) => {} + Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(false), + Err(err) => return Err(err).with_context(|| format!("cannot remove {}", file.display())), + } + if LINUX { + systemd::reload()?; + } + Ok(true) +} + +pub fn status() -> Result { + let file = file(&home()?); + match LINUX { + true => systemd::status(&file), + false => launchd::status(&file), + } +} + +/// Whether the service stops when the user logs out, and waits for them to log in after a boot: +/// a systemd user unit does unless the user lingers. +pub fn stops_at_logout() -> Result { + match LINUX { + true => systemd::lingers().map(|lingers| !lingers), + false => Ok(false), + } +} + +/// Where isbell writes its logs: ~/Library/Logs/isbell on macOS, $XDG_STATE_HOME/isbell (by default +/// ~/.local/state/isbell) on Linux. +pub fn log_dir(home: &Path) -> PathBuf { + match LINUX { + true => { + env_path("XDG_STATE_HOME").unwrap_or_else(|| home.join(".local/state")).join("isbell") + } + false => home.join("Library/Logs/isbell"), + } +} + +fn file(home: &Path) -> PathBuf { + match LINUX { + true => systemd::file(home), + false => launchd::file(home), + } +} + +fn home() -> Result { + env_path("HOME").context("HOME is not set") +} diff --git a/crates/isbell/src/service/systemd.rs b/crates/isbell/src/service/systemd.rs new file mode 100644 index 0000000..f0d3121 --- /dev/null +++ b/crates/isbell/src/service/systemd.rs @@ -0,0 +1,148 @@ +//! The gateway as a systemd user unit (Linux): started with the user's session, restarted after a +//! failure, and left stopped after a clean exit (another gateway took the machine over). + +use std::ffi::OsStr; +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; + +use anyhow::{Context, Result, bail}; + +use super::Status; +use crate::env_path; + +const UNIT: &str = "isbell-gateway.service"; + +pub(super) fn file(home: &Path) -> PathBuf { + env_path("XDG_CONFIG_HOME") + .unwrap_or_else(|| home.join(".config")) + .join("systemd/user") + .join(UNIT) +} + +/// Writes the unit to `file` for `exe` with `path_env` as its PATH, logging to `log`, enables it +/// and (re)starts it. +pub(super) fn install( + exe: &Path, + path_env: &OsStr, + home: &Path, + file: &Path, + log: &Path, +) -> Result<()> { + std::fs::write(file, unit(exe, path_env, home, log)) + .with_context(|| format!("cannot write {}", file.display()))?; + systemctl(&["daemon-reload"])?; + systemctl(&["enable", UNIT])?; + systemctl(&["restart", UNIT]) +} + +/// Stops the service and disables it, when its unit is there. +pub(super) fn stop(file: &Path) -> Result<()> { + if file.exists() { + systemctl(&["disable", "--now", UNIT])?; + } + Ok(()) +} + +/// Has systemd read the units again, after one was removed. +pub(super) fn reload() -> Result<()> { + systemctl(&["daemon-reload"]) +} + +pub(super) fn status(file: &Path) -> Result { + let installed = file.exists(); + let pid = match installed { + true => { + let shown = output(&["show", "--property", "MainPID", "--value", UNIT])?; + // 0 while it is not running. + shown.trim().parse().ok().filter(|&pid| pid != 0) + } + false => None, + }; + Ok(Status { installed, running: pid.is_some(), pid }) +} + +/// Whether this user's services run without them logged in (loginctl enable-linger). +pub(super) fn lingers() -> Result { + let uid = rustix::process::getuid().as_raw().to_string(); + let output = Command::new("loginctl") + .args(["show-user", &uid, "--property", "Linger", "--value"]) + .output() + .context("cannot run loginctl")?; + if !output.status.success() { + bail!("loginctl show-user failed: {}", String::from_utf8_lossy(&output.stderr).trim()); + } + Ok(String::from_utf8_lossy(&output.stdout).trim() == "yes") +} + +/// The unit; see systemd.service(5). `%` starts a specifier everywhere, and `$` a variable in +/// ExecStart, so both are doubled; the quoted values escape `\` and `"`. +fn unit(exe: &Path, path_env: &OsStr, home: &Path, log: &Path) -> String { + let exe = quoted(&exe.to_string_lossy()).replace('$', "$$"); + let path = quoted(&format!("PATH={}", path_env.to_string_lossy())); + let home = plain(&home.to_string_lossy()); + let log = plain(&log.to_string_lossy()); + format!( + "[Unit] +Description=Isbell gateway + +[Service] +ExecStart={exe} gateway run +# systemd's own PATH would find neither herdr nor the agents. +Environment={path} +WorkingDirectory={home} +# Not after a clean exit: another gateway took the machine over. +Restart=on-failure +# The herdr server the gateway started outlives the service, and so does the install script that +# restarts it after an upgrade. +KillMode=process +StandardOutput=append:{log} +StandardError=append:{log} + +[Install] +WantedBy=default.target +" + ) +} + +fn plain(value: &str) -> String { + value.replace('%', "%%") +} + +fn quoted(value: &str) -> String { + format!("\"{}\"", plain(value).replace('\\', "\\\\").replace('"', "\\\"")) +} + +fn systemctl(args: &[&str]) -> Result<()> { + output(args).map(drop) +} + +fn output(args: &[&str]) -> Result { + let Output { status, stdout, stderr } = Command::new("systemctl") + .arg("--user") + .args(args) + .output() + .context("cannot run systemctl")?; + if !status.success() { + bail!("systemctl --user {} failed: {}", args[0], String::from_utf8_lossy(&stderr).trim()); + } + Ok(String::from_utf8_lossy(&stdout).into_owned()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_unit_keeps_paths_and_path_as_given() { + let unit = unit( + Path::new("/home/ada/my $bin/isbell"), + OsStr::new("/home/ada/100%/bin:/usr/bin"), + Path::new("/home/ada"), + Path::new("/home/ada/.local/state/isbell/gateway.log"), + ); + assert!(unit.contains("ExecStart=\"/home/ada/my $$bin/isbell\" gateway run\n")); + assert!(unit.contains("Environment=\"PATH=/home/ada/100%%/bin:/usr/bin\"\n")); + assert!(unit.contains("StandardOutput=append:/home/ada/.local/state/isbell/gateway.log\n")); + assert!(unit.contains("KillMode=process\n")); + } +} diff --git a/docs/development.md b/docs/development.md index c2a9e81..0e07650 100644 --- a/docs/development.md +++ b/docs/development.md @@ -88,9 +88,10 @@ pnpm typecheck && pnpm test && pnpm lint && pnpm build - Release when the gateway or the CLI changed; a change to the web app alone needs none. - Bump `version` in the root `Cargo.toml` (the patch for fixes, the minor for features), commit, then push the tag `v`. -- `.github/workflows/release.yml` builds isbell for Apple silicon and publishes it as a GitHub - release, with `integrations/isbell-tools` packaged as `isbell-tools.tar.gz`; it fails when the tag - and the version differ. A change to the skill reaches users with the next release: their agents' +- `.github/workflows/release.yml` builds isbell for Apple silicon and for Linux (x86_64 and arm64, + static with musl) and publishes them as a GitHub release, with `integrations/isbell-tools` + packaged as `isbell-tools.tar.gz`; it fails when the tag and the version differ. A pull request + that changes the workflow builds them too, without publishing. A change to the skill reaches users with the next release: their agents' `update.sh` fetches the skill of the isbell installed. A skill linked from a checkout, as on a development Mac, has no `VERSION` and follows the checkout instead. - Mirror the release to the server, which serves `/root/isbell-releases` at diff --git a/docs/install.md b/docs/install.md index 48242d8..a931371 100644 --- a/docs/install.md +++ b/docs/install.md @@ -13,9 +13,13 @@ herdr's own installer when herdr is missing. Then: 4. On each other machine: `isbell space join `, then `isbell gateway install`. - `isbell space show` prints the key again on any machine in the space. -- `gateway install` makes a launchd user agent: started at login, restarted after a failure, logging - to `~/Library/Logs/isbell/gateway.log`. It keeps the `PATH` of the shell it ran in, so herdr and - the agents are found; run it again after changing `PATH`. +- `gateway install` makes a service that is started at login and restarted after a failure. It + keeps the `PATH` of the shell it ran in, so herdr and the agents are found; run it again after + changing `PATH`. + - On a Mac, a launchd user agent, logging to `~/Library/Logs/isbell/gateway.log`. + - On Linux, a systemd user unit, `~/.config/systemd/user/isbell-gateway.service`, logging to + `~/.local/state/isbell/gateway.log`. Like any user unit, it stops when you log out and waits for + you to log in after a boot, unless you linger: `sudo loginctl enable-linger $USER`. - `gateway status` and `gateway uninstall` check and remove it. ## Upgrade and uninstall @@ -27,7 +31,8 @@ herdr's own installer when herdr is missing. Then: ## From source -On other systems, or to run `main`, with Rust () and herdr installed: +On other systems, such as an Intel Mac or Windows through WSL, or to run `main`, with Rust +() and herdr installed: ```bash cargo install --git https://github.com/bencode/Isbell --locked isbell diff --git a/docs/setup.md b/docs/setup.md index d5e3d0d..c86e95d 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -1,7 +1,8 @@ -# Set up Isbell on this Mac +# Set up Isbell on this machine -For the agent doing the setup. Isbell lets its user reach the agents on their Macs from a browser: -`isbell` runs a gateway on each Mac, beside [herdr](https://herdr.dev), where the agents run. +For the agent doing the setup. Isbell lets its user reach the agents on their machines from a +browser: `isbell` runs a gateway on each machine, beside [herdr](https://herdr.dev), where the agents +run. ## Rules @@ -11,18 +12,21 @@ For the agent doing the setup. Isbell lets its user reach the agents on their Ma ## Checklist -- [ ] `uname -sm` is `Darwin arm64`. Otherwise stop: the installer is for Macs with Apple silicon; - [install.md](install.md#from-source) says how to build from source. +- [ ] `uname -sm` is `Darwin arm64`, `Linux x86_64` or `Linux aarch64`. Otherwise stop: the + installer is for Macs with Apple silicon and for Linux; [install.md](install.md#from-source) + says how to build from source. - [ ] Install or upgrade: `curl -fsSL https://isbell.fmap.dev/install.sh | sh`. Make sure `~/.local/bin` is on the user's `PATH`. - [ ] herdr is installed: `command -v herdr` in a login shell. If not, with the user's yes: `curl -fsSL https://herdr.dev/install.sh | sh`. - [ ] The space: if `isbell space show >/dev/null 2>&1` succeeds, there is one already. If not, ask - the user whether this is their first Mac: - - first Mac: `isbell space init >/dev/null`; - - another Mac: the user runs `isbell space join ` themselves. + the user whether this is their first machine: + - first machine: `isbell space init >/dev/null`; + - another machine: the user runs `isbell space join ` themselves. - [ ] Gateway service, from the user's login shell, so it finds herdr and the agents: - `$SHELL -lc 'isbell gateway install'`. + `$SHELL -lc 'isbell gateway install'`. On Linux, if it says the service runs only while the + user is logged in, ask whether it should keep running after they log out and start at boot; + if so, the user runs `sudo loginctl enable-linger $USER` themselves. - [ ] Optional, if the user runs Claude Code, Codex or pi: with their yes, the hook that lets the board show what each agent is asked and doing, and records each session in `~/.isbell/sessions` so a project's Sessions can resume it after its pane is closed. A machine with an older hook @@ -39,7 +43,8 @@ For the agent doing the setup. Isbell lets its user reach the agents on their Ma `~/.codex/hooks.json`. Tell the user that Codex asks to trust the new hooks when it next starts (choose Trust all), and that they report only from Codex started with `--no-daemon`: Isbell starts it so. A session's chat is read from the agent's own record, so for Codex - started by hand in herdr suggest `alias codex='codex --no-daemon'` in `~/.zshrc`. Without it, + started by hand in herdr suggest `alias codex='codex --no-daemon'` in their shell's startup file + (`~/.zshrc`, `~/.bashrc`). Without it, the chat finds the record by the pane's directory and when its Codex started, as long as no other Codex works in that directory. - pi: `sh /tmp/agent-hook.sh install pi`. It writes an extension to @@ -50,18 +55,19 @@ For the agent doing the setup. Isbell lets its user reach the agents on their Ma agents to name themselves, talk to each other and keep the user's goals, tasks and messages. - [ ] Check: - `isbell gateway status` says `running`; - - `isbell machine list` shows this Mac `online`. + - `isbell machine list` shows this machine `online`. - If either check fails, look at the end of `~/Library/Logs/isbell/gateway.log`. + If either check fails, look at the end of the gateway's log: `~/Library/Logs/isbell/gateway.log` + on a Mac, `~/.local/state/isbell/gateway.log` on Linux. - [ ] Tell the user: 1. Run `isbell space show` in your own terminal and copy the key. 2. Open and paste it. 3. Start agents inside herdr (run `herdr`); Isbell sees what runs there. - 4. For another Mac, give its agent this same file. + 4. For another machine, give its agent this same file. ## The isbell-tools skill -It teaches the agents on this Mac to use `isbell` and to talk to each other. Each release of isbell +It teaches the agents on this machine to use `isbell` and to talk to each other. Each release of isbell carries its own version: install the one of the isbell installed, which needs isbell 0.9.2 or later. ```sh diff --git a/install.sh b/install.sh index ccd4ce3..2a3bb73 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,6 @@ #!/bin/sh -# Installs isbell on a Mac with Apple silicon, or upgrades it; the same command does both: +# Installs isbell on a Mac with Apple silicon or on Linux (x86_64 or arm64), or upgrades it; the same +# command does both: # # curl -fsSL https://isbell.fmap.dev/install.sh | sh # @@ -7,8 +8,8 @@ set -eu REPO=bencode/Isbell -ASSET=isbell-aarch64-apple-darwin.tar.gz LABEL=dev.fmap.isbell.gateway +UNIT=isbell-gateway.service BIN_DIR=$HOME/.local/bin BIN=$BIN_DIR/isbell @@ -18,20 +19,30 @@ fail() { exit 1 } -[ "$(uname -s)" = Darwin ] && [ "$(uname -m)" = arm64 ] || - fail "only Macs with Apple silicon are supported for now; elsewhere, build from source (see https://github.com/$REPO#from-source)" +# Linux's builds are static (musl), for any distribution. +case "$(uname -s) $(uname -m)" in +"Darwin arm64") TARGET=aarch64-apple-darwin ;; +"Linux x86_64") TARGET=x86_64-unknown-linux-musl ;; +"Linux aarch64" | "Linux arm64") TARGET=aarch64-unknown-linux-musl ;; +*) fail "there is no ready-made isbell for $(uname -sm); build it from source (see https://github.com/$REPO/blob/main/docs/install.md#from-source)" ;; +esac +ASSET=isbell-$TARGET.tar.gz # The releases, mirrored here from GitHub's, which many networks reach too slowly to download from. url=https://isbell.fmap.dev/releases/${ISBELL_VERSION:-latest} # Fails rather than hangs where the network does not get through: no connection in 15 s, or under # 1 KB/s for 30 s. fetch() { curl -fsSL --connect-timeout 15 --speed-limit 1024 --speed-time 30 "$1" -o "$2"; } +# Linux has sha256sum; a Mac, and many Linux systems too, shasum. +sha256_check() { + if command -v sha256sum >/dev/null 2>&1; then sha256sum -c "$1"; else shasum -a 256 -c "$1"; fi +} tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT fetch "$url/$ASSET" "$tmp/$ASSET" || fail "cannot download $url/$ASSET" fetch "$url/$ASSET.sha256" "$tmp/$ASSET.sha256" || fail "cannot download $url/$ASSET.sha256" -(cd "$tmp" && shasum -a 256 -c "$ASSET.sha256" >/dev/null 2>&1) || fail "the download does not match its checksum" +(cd "$tmp" && sha256_check "$ASSET.sha256" >/dev/null 2>&1) || fail "the download does not match its checksum" tar -xzf "$tmp/$ASSET" -C "$tmp" # Copied beside the old one first, so the move that replaces it is atomic. @@ -49,12 +60,22 @@ else say "Upgraded $before -> $after at $BIN" fi -# A gateway service runs the binary it was installed with; restart it when that is this one. -plist=$HOME/Library/LaunchAgents/$LABEL.plist -if [ -f "$plist" ]; then - runs=$(/usr/libexec/PlistBuddy -c 'Print :ProgramArguments:0' "$plist" 2>/dev/null || true) +# A gateway service runs the binary it was installed with; restart it when that is this one. The +# service is a launchd agent on a Mac, a systemd user unit on Linux (see `isbell gateway install`). +runs= +if [ "$TARGET" = aarch64-apple-darwin ]; then + service=$HOME/Library/LaunchAgents/$LABEL.plist + [ -f "$service" ] && runs=$(/usr/libexec/PlistBuddy -c 'Print :ProgramArguments:0' "$service" 2>/dev/null || true) + restart() { launchctl kickstart -k "gui/$(id -u)/$LABEL"; } +else + service=${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/$UNIT + # ExecStart="" gateway run + [ -f "$service" ] && runs=$(sed -n 's/^ExecStart="\(.*\)" gateway run$/\1/p' "$service") + restart() { systemctl --user restart "$UNIT"; } +fi +if [ -f "$service" ]; then if [ "$runs" = "$BIN" ]; then - if launchctl kickstart -k "gui/$(id -u)/$LABEL"; then + if restart; then say "Restarted the gateway" else say "Could not restart the gateway; run: $BIN gateway install" @@ -83,9 +104,14 @@ fi case ":$PATH:" in *":$BIN_DIR:"*) ;; *) + case ${SHELL:-} in + */zsh) rc='~/.zshrc' ;; + */bash) rc='~/.bashrc' ;; + *) rc='~/.profile' ;; + esac say "" - say "$BIN_DIR is not on your PATH. To add it:" - say " echo 'export PATH=\"$BIN_DIR:\$PATH\"' >> ~/.zshrc && exec zsh" + say "$BIN_DIR is not on your PATH. To add it, then open a new terminal:" + say " echo 'export PATH=\"$BIN_DIR:\$PATH\"' >> $rc" ;; esac diff --git a/integrations/isbell-tools/update.sh b/integrations/isbell-tools/update.sh index 4c69d77..f77d809 100644 --- a/integrations/isbell-tools/update.sh +++ b/integrations/isbell-tools/update.sh @@ -29,13 +29,17 @@ fi url=https://isbell.fmap.dev/releases/v$want asset=isbell-tools.tar.gz fetch() { curl -fsSL --connect-timeout 15 --speed-limit 1024 --speed-time 30 "$1" -o "$2"; } +# Linux has sha256sum; a Mac, and many Linux systems too, shasum. +sha256_check() { + if command -v sha256sum >/dev/null 2>&1; then sha256sum -c "$1"; else shasum -a 256 -c "$1"; fi +} # Beside the skill, so the moves that swap it stay on one disk. tmp=$(mktemp -d "$dir.update.XXXXXX") trap 'rm -rf "$tmp"' EXIT fetch "$url/$asset" "$tmp/$asset" || fail "no $asset for isbell $want at $url: upgrade isbell" fetch "$url/$asset.sha256" "$tmp/$asset.sha256" || fail "cannot download $url/$asset.sha256" -(cd "$tmp" && shasum -a 256 -c "$asset.sha256" >/dev/null 2>&1) || fail "the download does not match its checksum" +(cd "$tmp" && sha256_check "$asset.sha256" >/dev/null 2>&1) || fail "the download does not match its checksum" tar -xzf "$tmp/$asset" -C "$tmp" [ -f "$tmp/isbell-tools/SKILL.md" ] || fail "$asset holds no isbell-tools/SKILL.md" diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index 8ae1cb4..50df06f 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -261,7 +261,7 @@ export const en = { 'upgrade.failed': 'The update did not go through.', 'upgrade.notRestarted': 'Installed, but the gateway was not restarted.', 'upgrade.timeout': - 'The machine did not come back within 3 minutes. See ~/Library/Logs/isbell/upgrade.log there.', + 'The machine did not come back within 3 minutes. See upgrade.log there, in ~/Library/Logs/isbell on a Mac or ~/.local/state/isbell on Linux.', 'upgrade.manual': "This machine's isbell cannot be updated from here yet. On it, run:", 'upgrade.manualAfter': 'Or, on that machine, run:', 'facts.hostname': 'Hostname', @@ -320,7 +320,7 @@ export const en = { 'join.new': 'New to Isbell?', 'join.what': 'Isbell opens the AI agents you run in herdr on your own machines from any browser: chat with them, answer what they ask, or take over their terminal.', - 'join.install': 'Install isbell (and herdr, if it is missing) on a Mac with Apple silicon.', + 'join.install': 'Install isbell (and herdr, if it is missing) on a Mac with Apple silicon or on Linux.', 'join.readme': 'How to install', 'join.init': 'Create your space; it prints the key.', 'join.gateway': "Let your browser reach that machine's agents.", @@ -395,7 +395,7 @@ export const en = { 'landing.start.title': 'Three steps, one of them for your agent.', 'landing.start.agent': 'Let your agent set it up', 'landing.start.agentText': - 'Paste this to the agent on your Mac. It installs Isbell and runs it, without ever seeing your key.', + 'Paste this to the agent on your machine. It installs Isbell and runs it, without ever seeing your key.', 'landing.start.key': 'Copy your key', 'landing.start.keyText': "In your own terminal, run isbell space show. The key is your space's only credential: keep it to yourself.", @@ -403,7 +403,7 @@ export const en = { 'landing.start.pasteText': 'Then start your agents in herdr. They show up here, and on any machine you add to the same space.', 'landing.start.systems': - 'Ready-made for Macs with Apple silicon today. Linux, and Windows through WSL, *build from source*: it is all Rust, though not yet tried there.', + 'Ready-made for Macs with Apple silicon and for Linux, x86_64 or arm64. Windows, through WSL, and other systems *build from source*.', 'landing.foot.how': 'How it works', 'landing.foot.self': 'Self-hosting', 'landing.foot.status': 'Early development · provided as is', diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts index f8c3bc1..2bc74a2 100644 --- a/web/src/locales/zh.ts +++ b/web/src/locales/zh.ts @@ -260,7 +260,8 @@ export const zh: Record = { 'upgrade.latest': '这仍是最新的 release。', 'upgrade.failed': '没有更新成功。', 'upgrade.notRestarted': '装好了,但 gateway 没有重启。', - 'upgrade.timeout': '3 分钟内机器没有回来。请在那台机器上看 ~/Library/Logs/isbell/upgrade.log。', + 'upgrade.timeout': + '3 分钟内机器没有回来。请在那台机器上看 upgrade.log:Mac 在 ~/Library/Logs/isbell,Linux 在 ~/.local/state/isbell。', 'upgrade.manual': '这台机器的 isbell 还不能从这里更新。在它上面运行:', 'upgrade.manualAfter': '也可以在那台机器上运行:', 'facts.hostname': '主机名', @@ -316,7 +317,7 @@ export const zh: Record = { 'join.new': '第一次用 Isbell?', 'join.what': 'Isbell 让你在任何浏览器里使用自己机器上、跑在 herdr 里的 AI agent:和它们对话、回答它们的提问,或者直接接管终端。', - 'join.install': '在 Apple 芯片的 Mac 上安装 isbell(缺少 herdr 时会一起装上)。', + 'join.install': '在 Apple 芯片的 Mac 或 Linux 上安装 isbell(缺少 herdr 时会一起装上)。', 'join.readme': '安装说明', 'join.init': '创建你的空间,它会打印出密钥。', 'join.gateway': '让浏览器能连到这台机器上的 agent。', @@ -385,14 +386,14 @@ export const zh: Record = { 'landing.start.eyebrow': '开始使用', 'landing.start.title': '三步,其中一步交给 agent。', 'landing.start.agent': '让 agent 帮你装', - 'landing.start.agentText': '把这句话发给你 Mac 上的 agent。它会安装并运行 Isbell,全程看不到你的密钥。', + 'landing.start.agentText': '把这句话发给你机器上的 agent。它会安装并运行 Isbell,全程看不到你的密钥。', 'landing.start.key': '复制你的密钥', 'landing.start.keyText': '在你自己的终端里运行 isbell space show。密钥是你这个空间唯一的凭证,不要给别人。', 'landing.start.paste': '粘贴到这里', 'landing.start.pasteText': '然后在 herdr 里启动 agent。它们会出现在这里,加入同一个空间的其他机器上的也会。', 'landing.start.systems': - '目前只有 Apple silicon 的 Mac 有现成安装包。Linux 和 Windows(通过 WSL)可以*从源码构建*:全是 Rust 写的,只是还没在那里试过。', + 'Apple silicon 的 Mac 和 Linux(x86_64、arm64)都有现成安装包。Windows(通过 WSL)和其他系统可以*从源码构建*。', 'landing.foot.how': '工作原理', 'landing.foot.self': '自托管', 'landing.foot.status': '早期开发中 · 按现状提供', diff --git a/web/src/shell/landing/landing.tsx b/web/src/shell/landing/landing.tsx index e30c117..c27072c 100644 --- a/web/src/shell/landing/landing.tsx +++ b/web/src/shell/landing/landing.tsx @@ -15,7 +15,7 @@ import { Switchboard } from './switchboard' const REPO = 'https://github.com/bencode/Isbell' const DOCS = `${REPO}/blob/main/docs` const SETUP = - 'Set up Isbell on this Mac: read https://raw.githubusercontent.com/bencode/Isbell/main/docs/setup.md and follow it.' + 'Set up Isbell on this machine: read https://raw.githubusercontent.com/bencode/Isbell/main/docs/setup.md and follow it.' /** The page's copy marks its emphasis with *stars*; each starred part comes out as `mark`. */ const rich = (text: string, mark: (part: string, key: number) => ReactNode) =>