Skip to content

Commit fc5739a

Browse files
authored
Merge pull request #1 from hyperstructure/fctl/25-please-continue-on-https-github-com-hype
feat: add the sandbox image, its publishing workflow and docs
2 parents 688d0dd + e4aab22 commit fc5739a

17 files changed

Lines changed: 1183 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
name: change-the-image
3+
description: Add, upgrade or remove a tool in the sandbox image, or change its layout. Covers where versions live, both architectures, the Lima VM that provision.sh also provisions, what fctl and derived images rely on, the image's size, and verifying a change with a local build or the pull request's Image workflow. Use for any change to Dockerfile, provision.sh or check.sh.
4+
---
5+
6+
# Changing the image
7+
8+
- `provision.sh` installs everything, as root; the Dockerfile only runs it
9+
and sets the user and the PATH. The versions are at the top, as
10+
`NAME="${NAME:-default}"`, so a build can override one.
11+
- `check.sh` is the layout fctl and images built `FROM` this one rely on,
12+
checked in every build.
13+
- README.md lists the tools with their versions, and the layout.
14+
15+
## Adding or upgrading a tool
16+
17+
1. **Install it in `provision.sh`.** Prefer Debian's package: add it to the
18+
`apt-get install` list. Otherwise use the project's own installer or
19+
release archive, with the version pinned at the top of the script, and
20+
check the download against the checksum the project publishes, when it
21+
publishes one. A toolchain agents extend (more versions, targets, global
22+
tools) goes in the agent's home through `as_agent`, like rustup and Bun;
23+
anything else system-wide.
24+
2. **Make it work from the PATH alone.** fctl-agent passes Claude the PATH,
25+
HOME and the locale, nothing else from the image. A tool that needs an
26+
environment variable gets a wrapper or a config file instead. A new PATH
27+
entry is a layout change (below).
28+
3. **Check for it.** Add the command to `check.sh`'s list of tools, and to
29+
the `--version` runs when it could be there but broken (a proxy without
30+
its toolchain).
31+
4. **List it** in README.md's "What's inside", with its version.
32+
5. **Say what it costs.** The Image workflow's summary lists each
33+
architecture's size; put the difference in the pull request.
34+
35+
An upgrade changes the version at the top of `provision.sh` and in README.md.
36+
Rust follows fctl's `rust-toolchain.toml`; Claude Code and fctl aren't pinned
37+
here (the workflow passes the versions it builds with).
38+
39+
Removing a tool breaks images and sessions that use it: a breaking change
40+
(the `commit` skill) with a reason.
41+
42+
## What bites
43+
44+
- **Two architectures.** Every download works on amd64 and arm64: pick the
45+
file with `dpkg --print-architecture` (`amd64`, `arm64`) or `uname -m`
46+
(`x86_64`, `aarch64`).
47+
- **The Lima VM.** fctl's Lima driver runs `provision.sh` in a Debian 12 VM
48+
(Lima's cloud image, not `bookworm-slim`) as root, with `AGENT_USER` set
49+
to the VM's user, who already exists and may not be uid 1000. Use
50+
`$AGENT_USER` and `$AGENT_HOME`, never `agent` or `/home/agent`, and don't
51+
rely on what only the Dockerfile sets.
52+
- **Login shells.** Setup scripts and the Lima driver run `bash -l`, which
53+
reads `/etc/profile.d/fctl.sh`. Keep its PATH and the Dockerfile's
54+
`ENV PATH` the same.
55+
- **apt's lists** are removed after the first installs; a later
56+
`apt-get install` needs its own `apt-get update` and cleanup.
57+
- **Python is externally managed.** No `pip install` into the system: use
58+
`uv tool install` (as the agent) or a Debian package.
59+
- **No auto-updates and no daemons.** fctl turns off Claude Code's
60+
auto-updater, and sessions start only fctl-agent; a tool that expects a
61+
service running won't find one.
62+
63+
## Changing the layout
64+
65+
The user, its home, `~/workspace`, `/opt/fctl/bin` and the PATH are an
66+
interface: installed fctl hosts and images built `FROM` this one rely on
67+
them. Look for a way that keeps them first. If there is none:
68+
69+
1. Make it a breaking change (`feat!:` with a `BREAKING CHANGE:` paragraph).
70+
2. Change `check.sh` and README.md's Layout with it.
71+
3. Change fctl's Sandbox images page (`docs/sandbox-images.md` in
72+
hyperstructure/fctl) to match, and fctl itself when hosts must adapt,
73+
released before this merges. An fctl session's token covers only its own
74+
repository: name what hyperstructure/fctl needs, and tell the person.
75+
76+
The newest fctl release's tag is rebuilt from `main`, so its hosts get the
77+
change the next time they pull the image.
78+
79+
## Verifying
80+
81+
- **With Docker:** `docker build -t sandbox:dev .`, then
82+
`docker run --rm -i sandbox:dev sh -s < check.sh`, and try the tool:
83+
`docker run --rm sandbox:dev bash -lc 'psql --version'`. Add
84+
`--platform linux/amd64` (or `arm64`) to try the other architecture under
85+
emulation, slowly.
86+
- **In an fctl session** (no Docker): open the pull request. The Image
87+
workflow builds both architectures with the latest fctl and Claude Code
88+
and runs `check.sh` in each: `gh pr checks N --watch --fail-fast`, then
89+
the run's summary for the sizes.
90+
- **With fctl:** on a host, `docker build -t sandbox:dev .` and set it as a
91+
project's image (Settings → Sandbox → Image), or
92+
`fctl host image build --source .` from a checkout, which builds it under
93+
the host's image name (with Lima: provisions the base VM). Then start a
94+
session and use the tool.

‎.claude/skills/commit/SKILL.md‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
name: commit
3+
description: Commit and open pull requests in hyperstructure/sandbox. Covers Conventional Commit titles, breaking changes, what goes in the description, branch names, waiting for the checks, answering reviews, and what happens after the merge. Use when committing, naming a branch, writing a pull request title or description, or getting a change merged.
4+
---
5+
6+
# Commits and pull requests
7+
8+
Every change reaches `main` as one squash-merged pull request. Its **title
9+
becomes the commit subject** and its description the commit body. Merging a
10+
change to the image publishes it (the `publish` skill), so `main` is always
11+
what's published.
12+
13+
## The title
14+
15+
`type(scope): what changed`, at most 72 characters, no full stop, in the
16+
imperative. The Commits workflow checks every title, and again when you
17+
edit it.
18+
19+
| Type | For |
20+
|---|---|
21+
| `feat` | a tool the image didn't have, or a new major version of one |
22+
| `fix` | something broken in the image or in publishing it |
23+
| `perf` | a smaller or faster image with the same tools |
24+
| `docs` | documentation only |
25+
| `build` | other version upgrades |
26+
| `refactor`, `test`, `ci`, `chore`, `revert` | restructuring; checks; workflows; upkeep; reverts |
27+
28+
The scope is optional: `image`, `ci`, `deps`, `docs`.
29+
30+
- `feat: add PostgreSQL's client`
31+
- `build: upgrade Bun to 1.5.0`
32+
- `fix: put Bun on login shells' PATH`
33+
- `ci: rebuild the image when Claude Code moves on`
34+
35+
A **breaking change** changes what fctl or images built `FROM` this one rely
36+
on (the layout in README.md, a tool removed, a file fctl downloads). It gets
37+
a `!` and a `BREAKING CHANGE:` paragraph in the description that says what
38+
people must do: `feat!: drop Node.js 20`. Check with AGENTS.md whether fctl
39+
must change first.
40+
41+
## The description
42+
43+
Plain prose for someone reading `git log` in a year: what was missing or
44+
wrong, what changed and why this way, what it adds to the image's size, and
45+
how you verified it (the Image workflow's run, `check.sh`, a local build).
46+
Link the issue: `Fixes #12` only when the pull request does everything it
47+
asks, `Refs #12` otherwise.
48+
49+
The description ends with the content: no "Generated with …" footers. A link
50+
to the fctl session that made the change is welcome.
51+
52+
## The flow
53+
54+
1. Branch from an up-to-date `main`: `<type>/<topic>` (`feat/postgres`), or
55+
`fctl/<number>-<topic>` when an fctl session makes the branch.
56+
2. Commit as you go; the commits are squashed, so the title is what lasts.
57+
3. Run `shellcheck provision.sh check.sh` and `actionlint` if you have them;
58+
the Lint workflow runs both anyway.
59+
4. Open the pull request with a conventional title and a description. One
60+
change per pull request.
61+
5. Wait for the checks in the same turn and fix failures (below).
62+
6. A person merges it (squash) when the checks pass, unless they asked you
63+
to merge it yourself.
64+
65+
Never push to `main` directly, and never commit secrets: the repository and
66+
the image are public.
67+
68+
## The checks
69+
70+
```sh
71+
gh pr checks N --watch --fail-fast
72+
```
73+
74+
- **Image** builds the pull request's image for amd64 and arm64 with the
75+
latest fctl and Claude Code and runs `check.sh` in each. It runs when the
76+
image's files or the workflow change, and takes a few minutes.
77+
- **Lint** runs ShellCheck and actionlint.
78+
- **Commits** checks the title. When only it fails, fix the title:
79+
`gh pr edit N --title "fix: …"`.
80+
81+
Read a failure with `gh run view ID --log-failed`. Something that looks like
82+
infrastructure (a timeout, a registry or download error) gets one rerun
83+
(`gh run rerun ID --failed`); if it fails again, treat it as real. Don't ask
84+
anyone to merge a pull request with failing checks, and don't weaken a check
85+
to make it pass.
86+
87+
## Reviews
88+
89+
Read the conversation and the comments on lines:
90+
91+
```sh
92+
gh pr view N --comments
93+
gh api repos/hyperstructure/sandbox/pulls/N/comments --jq '.[] | {id, path, line, user: .user.login, body}'
94+
```
95+
96+
Answer every comment in its own thread: fix it, push, and reply with what
97+
changed, or say plainly why not. Leave resolving threads to the reviewer.
98+
After changes, update the description so it still says what the pull
99+
request does: it becomes the commit message.
100+
101+
## After the merge
102+
103+
- Don't push to the merged branch; follow-ups go in a new pull request from
104+
the updated `main`.
105+
- A change to the image starts the Image workflow on `main`. Check that it
106+
published (the `publish` skill), and say so where the change was asked
107+
for.

‎.claude/skills/publish/SKILL.md‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
name: publish
3+
description: How the sandbox image reaches ghcr.io/hyperstructure/sandbox, and how to rebuild or repair it. Covers what starts the Image workflow (fctl releases, merges, Claude Code releases, the weekly rebuild), its tags and labels, running it by hand, checking a published image with or without Docker, and what to do when a run fails or the schedule stops. Use when asked to publish, rebuild or check the image, after merging a change to it, or when an fctl release has no image.
4+
---
5+
6+
# Publishing the image
7+
8+
The Image workflow (`.github/workflows/image.yml`) publishes
9+
`ghcr.io/hyperstructure/sandbox` from `main` only. Its first job, "What to
10+
build", decides whether there is anything to do and says why in the run's
11+
summary; then each architecture builds on a runner of its own (amd64 on
12+
`ubuntu-24.04`, arm64 on `ubuntu-24.04-arm`), is pushed by digest and
13+
checked with `check.sh`, and the last job tags the two as one image.
14+
15+
## When it runs
16+
17+
| Trigger | Builds the newest fctl release's image when |
18+
|---|---|
19+
| A push to `main` that changes the image | the published one predates the change |
20+
| Every hour (minute 11) | there is none yet (a new fctl release), or it predates a change |
21+
| Every day (05:41 UTC) | as hourly, or Claude Code has a newer release, or the image is a week old |
22+
| `gh workflow run image.yml` | as daily; `-f version=…` for another release, `-f force=true` always |
23+
| A pull request that changes the image | always, with the latest fctl, without publishing |
24+
25+
Every build installs that fctl release from https://fctl.sh/releases and
26+
the newest Claude Code (https://downloads.claude.ai), and passes both
27+
versions to `check.sh`.
28+
29+
## Tags and labels
30+
31+
- `<version>` (`0.4.0`): the release's image. Hosts of that version pull it.
32+
- `<major>.<minor>` (`0.4`): moves only when the build is the newest patch
33+
of its minor. fctl's releases count up one patch at a time and fctl.sh
34+
keeps them all, so the workflow asks fctl.sh for the next patch.
35+
- `latest`: moves only for the newest release.
36+
37+
The image and its index carry `org.opencontainers.image.version` (fctl's
38+
version), `sh.fctl.claude-code.version`, `org.opencontainers.image.revision`
39+
(the commit built) and `org.opencontainers.image.created`. The workflow reads
40+
them back to decide whether an image is current.
41+
42+
## Running it by hand
43+
44+
It takes write access to Actions on this repository (people have it; fctl
45+
sessions don't, so ask a person):
46+
47+
```sh
48+
gh workflow run image.yml -R hyperstructure/sandbox # the newest release, if needed
49+
gh workflow run image.yml -R hyperstructure/sandbox -f version=0.3.0 # another release
50+
gh workflow run image.yml -R hyperstructure/sandbox -f force=true # even when current
51+
gh run list -R hyperstructure/sandbox --workflow image.yml --limit 3
52+
gh run watch -R hyperstructure/sandbox ID --exit-status
53+
```
54+
55+
## Checking what's published
56+
57+
With Docker:
58+
59+
```sh
60+
docker buildx imagetools inspect ghcr.io/hyperstructure/sandbox:0.3.0 # linux/amd64 and linux/arm64
61+
docker buildx imagetools inspect --raw ghcr.io/hyperstructure/sandbox:0.3.0 | jq .annotations
62+
docker run --rm -i ghcr.io/hyperstructure/sandbox:0.3.0 sh -s < check.sh
63+
```
64+
65+
Without Docker (an fctl session), from the registry's API:
66+
67+
```sh
68+
token=$(curl -fsS "https://ghcr.io/token?scope=repository:hyperstructure/sandbox:pull" | jq -r .token)
69+
curl -fsS -H "Authorization: Bearer $token" \
70+
-H "Accept: application/vnd.oci.image.index.v1+json" \
71+
https://ghcr.io/v2/hyperstructure/sandbox/manifests/latest |
72+
jq '{annotations, platforms: [.manifests[].platform | "\(.os)/\(.architecture)"]}'
73+
curl -fsS -H "Authorization: Bearer $token" https://ghcr.io/v2/hyperstructure/sandbox/tags/list
74+
```
75+
76+
## When something fails
77+
78+
Publishing happens only after both architectures passed `check.sh`, so a
79+
failed run leaves the published tags as they were (and an untagged digest
80+
behind, which is harmless).
81+
82+
- **"What to build" fails**: fctl.sh or downloads.claude.ai didn't answer
83+
as expected; the error says what came back. Rerun it later.
84+
- **`check.sh` says the Claude Code version differs**: a Claude Code release
85+
landed between planning and building. Rerun the run.
86+
- **`check.sh` fails otherwise, or the build does**: the image is broken,
87+
often by a change upstream (an installer or a package moved). Fix it in a
88+
pull request (the `change-the-image` skill); its own Image run shows the
89+
fix works.
90+
- **The push is denied**: the package must give this repository write
91+
access (the package's settings → Manage Actions access). It has it when
92+
this workflow created the package.
93+
- **Hosts can't pull it** ("unauthorized", "denied"): the package must be
94+
public. A package starts private when the workflow first creates it; a
95+
person makes it public in the package's settings (Danger zone → Change
96+
visibility), and the organization must allow public packages.
97+
- **The schedule stopped**: GitHub turns off scheduled workflows in a public
98+
repository after 60 days without activity, and emails a warning first.
99+
A person turns it back on with
100+
`gh workflow enable image.yml -R hyperstructure/sandbox`, then runs it by
101+
hand. Meanwhile a new fctl release has no image of its own, and its hosts
102+
start sessions from `latest`.
103+
104+
Never delete a published version that has a tag: hosts pull by tag, and a
105+
broken one is fixed by a rebuild.

‎.dockerignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The build needs only provision.sh, which the Dockerfile copies in.
2+
*
3+
!provision.sh

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

‎.github/dependabot.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Keeps the workflows' actions current: one pull request a month for all of
2+
# them, titled as a Conventional Commit (ci(deps): …).
3+
version: 2
4+
updates:
5+
- package-ecosystem: github-actions
6+
directory: /
7+
schedule:
8+
interval: monthly
9+
groups:
10+
actions:
11+
patterns: ["*"]
12+
commit-message:
13+
prefix: ci
14+
include: scope

‎.github/workflows/commits.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Pull request titles must be Conventional Commits: they become the
2+
# squash-merged commits on main (.claude/skills/commit/SKILL.md). The rules
3+
# are fctl's (xtask/src/release.rs in hyperstructure/fctl); keep them in step.
4+
# Separate from the other checks, so that editing a title reruns only this.
5+
name: Commits
6+
7+
on:
8+
pull_request:
9+
types: [opened, edited, synchronize, reopened]
10+
11+
concurrency:
12+
group: commits-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
conventional:
20+
name: Conventional Commits
21+
runs-on: ubuntu-24.04
22+
timeout-minutes: 5
23+
steps:
24+
- name: The pull request title (it becomes the commit on main)
25+
env:
26+
TITLE: ${{ github.event.pull_request.title }}
27+
run: |
28+
types="feat fix perf docs refactor test build ci chore revert"
29+
fail() { echo "::error::$1"; exit 1; }
30+
title=$(sed -E 's/ \(#[0-9]+\)$//' <<<"$TITLE")
31+
shape='^([a-z0-9/-]+)(\([a-z0-9/-]+\))?!?: (.*[^[:space:]].*)$'
32+
[[ $title =~ $shape ]] || fail "\`$title\` is not \`type(scope): what changed\`; types: ${types// /, }"
33+
kind=${BASH_REMATCH[1]} text=${BASH_REMATCH[3]}
34+
[[ " $types " == *" $kind "* ]] || fail "\`$kind\` is not a commit type; use one of: ${types// /, }"
35+
[[ $text != *. ]] || fail "drop the full stop at the end"
36+
(( ${#title} <= 72 )) || fail "keep it to 72 characters (${#title} now); details go in the body"
37+
echo "\`$title\` is a Conventional Commit." >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)