Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion crates/fctl-host/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<String>,
#[serde(default)]
targets: Vec<String>,
}
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(())
}
}
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 5 additions & 3 deletions images/agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
39 changes: 35 additions & 4 deletions images/agent/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
63 changes: 54 additions & 9 deletions images/agent/provision.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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/*

Expand Down Expand Up @@ -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'