diff --git a/crates/fctl-host/src/image.rs b/crates/fctl-host/src/image.rs index 14ff2340..3630cdda 100644 --- a/crates/fctl-host/src/image.rs +++ b/crates/fctl-host/src/image.rs @@ -135,7 +135,7 @@ async fn run_inherit(program: &str, args: &[&str]) -> Result<()> { #[cfg(test)] mod tests { - use super::shell_quote; + use super::{PROVISION, shell_quote}; #[test] fn quotes_values_for_sh() { @@ -145,4 +145,37 @@ mod tests { ); assert_eq!(shell_quote("it's"), "'it'\\''s'"); } + + /// Sessions working on fctl find its toolchain already installed, rather + /// than having rustup download a second one. + #[test] + fn installs_the_rust_this_repository_builds_with() -> anyhow::Result<()> { + #[derive(serde::Deserialize)] + struct File { + toolchain: Toolchain, + } + #[derive(serde::Deserialize)] + struct Toolchain { + channel: String, + #[serde(default)] + components: Vec, + #[serde(default)] + targets: Vec, + } + let File { toolchain } = toml::from_str(include_str!("../../../rust-toolchain.toml"))?; + let mut wanted = vec![format!("RUST_VERSION:-{}}}", toolchain.channel)]; + if !toolchain.components.is_empty() { + wanted.push(format!("--component {}", toolchain.components.join(","))); + } + if !toolchain.targets.is_empty() { + wanted.push(format!("--target {}", toolchain.targets.join(","))); + } + for w in wanted { + assert!( + PROVISION.contains(&w), + "images/agent/provision.sh should have `{w}`, as rust-toolchain.toml says" + ); + } + Ok(()) + } } diff --git a/docs/architecture.md b/docs/architecture.md index 403c410c..8cc2c26d 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -42,7 +42,7 @@ before changing anything that crosses a component boundary. | `crates/fake-claude` | A scripted stand-in for `claude` that speaks stream-json. Used by tests and `cargo xtask dev`. | dev, CI | | `xtask` | Development automation (`cargo xtask dev`, `check`, `gen`, `deploy`, `dist`, `publish`). | dev, CI | | `web/` | The web app (React, Vite, TypeScript, WebGL), installable on phones and computers. Served by fctl-control. | browser | -| `images/agent` | The default sandbox image (Debian, git, gh, node, python, claude, fctl). | sandboxes | +| `images/agent` | The default sandbox image (Debian, git, gh, Python, Rust, Node.js, Bun, claude, fctl). | sandboxes | Two more repositories complete the picture: [hyperstructure/design](https://github.com/hyperstructure/design) diff --git a/docs/getting-started.md b/docs/getting-started.md index fd4726bb..eed649a3 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -78,11 +78,11 @@ Any Mac with Apple silicon (or a Linux box) can be a host. On the Mac: fctl host install --build-image ``` - This builds the sandbox image (Debian with git, gh, Node, Python, uv and - Claude Code), writes `~/.config/fctl/host.toml`, and installs a launchd - agent (`sh.fctl.host`) that starts at login, restarts if it stops, and - keeps the Mac from sleeping while it is plugged in, so it can start work - at any hour. + This builds the sandbox image (Debian with git, gh, Python, uv, Rust, + Node, TypeScript, Bun and Claude Code), writes + `~/.config/fctl/host.toml`, and installs a launchd agent (`sh.fctl.host`) + that starts at login, restarts if it stops, and keeps the Mac from + sleeping while it is plugged in, so it can start work at any hour. 3. Check it: diff --git a/images/agent/Dockerfile b/images/agent/Dockerfile index e6c3a36c..b976b5e3 100644 --- a/images/agent/Dockerfile +++ b/images/agent/Dockerfile @@ -1,5 +1,6 @@ -# The default fctl sandbox image: Debian with git, gh, Node.js, Python (uv), -# build tools, Claude Code and fctl. Sessions run as the `agent` user. +# The default fctl sandbox image: Debian with git, gh, build tools, Python and +# uv, Rust, Node.js, TypeScript, Bun, Claude Code and fctl (README.md lists +# the versions). Sessions run as the `agent` user. # # fctl host image build # builds it with your driver (apple or docker) # docker build -t fctl-agent:latest images/agent @@ -16,5 +17,6 @@ RUN bash /tmp/provision.sh && rm /tmp/provision.sh USER agent WORKDIR /home/agent -ENV PATH=/home/agent/.local/bin:/opt/fctl/bin:$PATH +# As /etc/profile.d/fctl.sh (provision.sh) sets it for login shells. +ENV PATH=/home/agent/.local/bin:/home/agent/.cargo/bin:/home/agent/.bun/bin:/opt/fctl/bin:$PATH CMD ["tail", "-f", "/dev/null"] diff --git a/images/agent/README.md b/images/agent/README.md index df9bc4f3..039cee3d 100644 --- a/images/agent/README.md +++ b/images/agent/README.md @@ -1,10 +1,41 @@ # Agent image -The default sandbox for fctl sessions: Debian bookworm with git, the GitHub -CLI, Node.js 22, Python 3 with uv, build tools, ripgrep, Claude Code -(installed for the `agent` user, who has passwordless sudo: the sandbox is -the boundary) and fctl (in `/usr/local/bin`). +The default sandbox for fctl sessions: Debian bookworm with the toolchains +agents build and test with, Claude Code (installed for the `agent` user, who +has passwordless sudo: the sandbox is the boundary) and fctl (in +`/usr/local/bin`). +- Python 3.15.0 as `python3` and `python` for every user (uv's build of + CPython, in `/opt/uv/python`), and uv 0.13.1. +- Rust 1.99.0 through rustup, with rustfmt, Clippy and the + `wasm32-unknown-unknown` target: the toolchain in this repository's + `rust-toolchain.toml`, so sessions working on fctl have nothing to + download. +- Node.js 22 with npm, TypeScript 7.0.2 (`tsc`) and Bun 1.4.3. +- build-essential (gcc, make), cmake, pkg-config and OpenSSL's headers. +- git, the GitHub CLI, ripgrep, fd, jq, ShellCheck, sqlite3, curl, wget, + rsync, lsof, fuser, tree, file, zip, xz and zstd. + +The versions are set at the top of `provision.sh`. A test in +`crates/fctl-host/src/image.rs` fails when Rust's differs from +`rust-toolchain.toml`. + +- Rust and Bun are installed for the agent user (in `~/.rustup` and + `~/.cargo`, and `~/.bun`), so agents add toolchains, targets and global + tools without sudo: `cargo install`, `bun add -g`, and for Python `uv + tool install` and `uv python install`. Images built from this one run + cargo as `agent`. +- Python is marked externally managed: packages go into a virtual + environment (`uv venv`, `python3 -m venv`) or come with `uv run --with`. + Debian's Python 3.11, which Node.js depends on, stays in `/usr/bin`, + after `/usr/local/bin` on the PATH. +- `~/.local/bin`, `~/.cargo/bin`, `~/.bun/bin` and `/opt/fctl/bin` lead the + PATH. The Dockerfile sets it, and `/etc/profile.d/fctl.sh` sets it for + login shells (setup scripts, the Lima VM). fctl-agent passes Claude the + PATH, HOME and locale but not the image's other environment variables, so + every tool here works from the PATH alone. +- npm leaves out its funding and audit notices and its update check + (`/usr/etc/npmrc`); `npm audit` still runs when asked. - `fctl host image build` builds it locally as `fctl-agent:latest` with the host's driver (Apple `container build` or `docker build`), or provisions the `fctl-base` Lima VM with the same `provision.sh`. It installs the diff --git a/images/agent/provision.sh b/images/agent/provision.sh index e68261ee..d93f1367 100644 --- a/images/agent/provision.sh +++ b/images/agent/provision.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2016 # single-quoted scripts expand in the agent's shell # Provisions an fctl agent sandbox: the tools agents need, Claude Code and # fctl. Used by the Dockerfile (container sandboxes) and by `fctl host image # build --driver lima` (the fctl-base VM). Runs as root. @@ -9,29 +10,47 @@ set -euo pipefail AGENT_USER="${AGENT_USER:-agent}" +# Toolchain versions. Rust is the release this repository builds with +# (rust-toolchain.toml; a test in crates/fctl-host/src/image.rs keeps the two +# in step), so sessions working on fctl have nothing to download. NODE_MAJOR="${NODE_MAJOR:-22}" +TYPESCRIPT_VERSION="${TYPESCRIPT_VERSION:-7.0.2}" +BUN_VERSION="${BUN_VERSION:-1.4.3}" +UV_VERSION="${UV_VERSION:-0.13.1}" +PYTHON_VERSION="${PYTHON_VERSION:-3.15.0}" +RUST_VERSION="${RUST_VERSION:-1.99.0}" FCTL_VERSION="${FCTL_VERSION:-}" FCTL_DOWNLOAD="${FCTL_DOWNLOAD:-}" export DEBIAN_FRONTEND=noninteractive apt-get update apt-get install -y --no-install-recommends \ - ca-certificates curl git gnupg less openssh-client procps sudo unzip xz-utils zip \ - build-essential pkg-config jq ripgrep fd-find tree file \ - python3 python3-venv python3-pip + ca-certificates curl wget git gnupg less openssh-client procps psmisc lsof sudo \ + rsync unzip xz-utils zip zstd \ + build-essential cmake pkg-config libssl-dev \ + jq ripgrep fd-find tree file shellcheck sqlite3 +# Debian calls fd `fdfind`. +ln -sf /usr/bin/fdfind /usr/local/bin/fd # GitHub CLI curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /usr/share/keyrings/githubcli-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \ > /etc/apt/sources.list.d/github-cli.list -# Node.js +# Node.js and TypeScript. npm leaves out its funding and audit notices and +# its update check, which only lengthen agents' output. curl -fsSL "https://deb.nodesource.com/setup_${NODE_MAJOR}.x" | bash - apt-get install -y --no-install-recommends gh nodejs corepack enable || true +npm config set --location=global fund=false audit=false update-notifier=false +npm install -g "typescript@$TYPESCRIPT_VERSION" +npm cache clean --force -# uv (Python) -curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh +# uv, and Python for everyone: uv's build of CPython in /opt/uv/python, as +# python3 and python in /usr/local/bin. +curl -LsSf "https://astral.sh/uv/$UV_VERSION/install.sh" | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh +env UV_PYTHON_INSTALL_DIR=/opt/uv/python UV_PYTHON_BIN_DIR=/usr/local/bin UV_NO_CACHE=1 \ + uv python install --default --preview-features python-install-default "$PYTHON_VERSION" rm -rf /var/lib/apt/lists/* @@ -64,6 +83,32 @@ rm -f /usr/local/bin/fctl-agent-*-linux AGENT_HOME="$(getent passwd "$AGENT_USER" | cut -d: -f6)" sudo -u "$AGENT_USER" -H bash -c 'curl -fsSL https://claude.ai/install.sh | bash' sudo -u "$AGENT_USER" -H mkdir -p "$AGENT_HOME/workspace" -grep -q '.local/bin' "$AGENT_HOME/.profile" 2>/dev/null || echo 'export PATH="$HOME/.local/bin:/opt/fctl/bin:$PATH"' >> "$AGENT_HOME/.profile" -"$AGENT_HOME/.local/bin/claude" --version -/usr/local/bin/fctl --version + +# The agent's PATH: Claude Code and uv's tools in ~/.local/bin, Rust's and +# Bun's tools, then fctl's supervisor. The Dockerfile sets the same; login +# shells (setup scripts, the Lima driver's) get it from here. +cat > /etc/profile.d/fctl.sh <<'EOF' +PATH="$HOME/.local/bin:$HOME/.cargo/bin:$HOME/.bun/bin:/opt/fctl/bin:$PATH" +EOF + +# Runs a script as the agent user in a login shell; it gets the arguments +# after the script as $1…. +as_agent() { + local script="$1" + shift + sudo -u "$AGENT_USER" -H bash -lc "set -euo pipefail; $script" bash "$@" +} + +# Rust, with the components and targets that rust-toolchain.toml lists, and +# Bun, in the agent's home: they find their files through HOME alone +# (fctl-agent passes Claude no RUSTUP_HOME or the like), and agents add +# toolchains, targets and global tools without sudo. +as_agent 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | + sh -s -- -y --no-modify-path --profile minimal --default-toolchain "$1" \ + --component rustfmt,clippy --target wasm32-unknown-unknown' "$RUST_VERSION" +as_agent 'curl -fsSL https://bun.sh/install | bash -s "bun-v$1"' "$BUN_VERSION" +as_agent 'ln -sf bun "$HOME/.bun/bin/bunx"' + +# What sessions find on the PATH. +as_agent 'claude --version; fctl --version; python3 --version; uv --version + rustc --version; cargo --version; node --version; tsc --version; bun --version'