Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions .claude/skills/issues/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ links in someone else's text.

## Other repositories

hyperstructure has three repositories: fctl (this one), fctl-site (fctl.sh)
and design (`@hyperstructure/design`). An fctl session's GitHub token covers
hyperstructure has four repositories: fctl (this one), fctl-site (fctl.sh),
design (`@hyperstructure/design`) and sandbox (the default sandbox image,
public). An fctl session's GitHub token covers
only its own repository. When a change needs work in another one, name it
in your pull request or issue ("fctl-site needs the new docs page in
`PAGES`") and tell the person. Only open the change there yourself when you
Expand Down
22 changes: 21 additions & 1 deletion .claude/skills/release/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: release
description: Release a new version of fctl through the Release workflow, which publishes the archives to GitHub and fctl.sh/releases, updates the CHANGELOG and redeploys app.fctl.sh. Only for people and agents with release access (write access to Actions on hyperstructure/fctl). Use when asked to release, publish or ship fctl, to preview what the next release contains, or to fix a failed release.
description: Release a new version of fctl through the Release workflow, which publishes the archives to GitHub and fctl.sh/releases, updates the CHANGELOG and redeploys app.fctl.sh; hyperstructure/sandbox then publishes the release's sandbox image to GHCR. Only for people and agents with release access (write access to Actions on hyperstructure/fctl). Use when asked to release, publish or ship fctl, to preview what the next release contains, or to fix a failed release.
---

# Releasing fctl
Expand Down Expand Up @@ -59,6 +59,14 @@ It runs in three steps:
the installer as a check, and starts CI on `main`, which redeploys
app.fctl.sh.

Within the hour, the Image workflow of
[hyperstructure/sandbox](https://github.com/hyperstructure/sandbox) finds
the release on fctl.sh and publishes its sandbox image,
`ghcr.io/hyperstructure/sandbox:X.Y.Z`, for arm64 and amd64, moving `X.Y`
and `latest`. Hosts of the new version pull it; until it is there, their
sessions start from `latest`. To publish it at once:
`gh workflow run image.yml -R hyperstructure/sandbox`.

Follow it with `gh run watch` or in the Actions tab; it takes about 10
minutes.

Expand All @@ -68,6 +76,10 @@ minutes.
`fctl self update --check` sees it.
- The GitHub release and `CHANGELOG.md` on `main` have the notes.
- `https://app.fctl.sh/api/v1/health` reports the version once CI is done.
- Within the hour, `docker buildx imagetools inspect
ghcr.io/hyperstructure/sandbox:X.Y.Z` lists linux/amd64 and linux/arm64
(`gh run list -R hyperstructure/sandbox --workflow image.yml` shows the
runs).
- Hosts update with `fctl self update` (it restarts the host service;
running sessions keep going).

Expand All @@ -82,6 +94,12 @@ minutes.
tag from the start with
`gh workflow run release.yml --ref main -f tag=vX.Y.Z`. If the code is
broken, fix it and release a patch.
- **The image** (hyperstructure/sandbox's Image workflow failed, or the
release has no image after an hour): its `publish` skill says what to do.
Start it for the release with
`gh workflow run image.yml -R hyperstructure/sandbox -f version=X.Y.Z`.
The image is built from that repository's `main`, so fixing it takes a
pull request there, not an fctl release.
- Never move or delete a published tag or its files on fctl.sh: installed
CLIs and hosts download releases by version.

Expand All @@ -90,3 +108,5 @@ minutes.
- **hyperstructure/design** releases are tags as well; see its AGENTS.md
and release skill.
- **hyperstructure/fctl-site** deploys from `main` and has no releases.
- **hyperstructure/sandbox** publishes the sandbox image from `main`, for
every fctl release; see its AGENTS.md and publish skill.
10 changes: 6 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
# then cross-compile the release binaries, all at once (`cargo xtask dist
# build`), and "Publish" makes the archives from them, makes the GitHub
# release with the notes, publishes to https://fctl.sh/releases and starts CI
# on main, which redeploys app.fctl.sh. `tag` rebuilds an existing release tag
# from main; `dry_run` only shows what would ship. Tags pushed by hand do not
# publish anything: starting this workflow takes write access to Actions,
# which agents running in fctl sessions do not have.
# on main, which redeploys app.fctl.sh. Within the hour, hyperstructure/sandbox
# publishes the release's sandbox image, ghcr.io/hyperstructure/sandbox:<version>.
# `tag` rebuilds an existing release tag from main; `dry_run` only shows what
# would ship. Tags pushed by hand do not publish anything: starting this
# workflow takes write access to Actions, which agents running in fctl
# sessions do not have.
name: Release

on:
Expand Down
18 changes: 13 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,17 @@ fake-claude's behaviors are listed in [docs/development.md](docs/development.md)
policy (`legal/privacy.md`) says what app.fctl.sh stores, who receives it
and how long it is kept: a change here that alters any of that needs a
matching change there.

Both are private for now: `npm ci` reaches the design package over git, so
it needs GitHub access (CI uses a read-only deploy key).
- [hyperstructure/sandbox](https://github.com/hyperstructure/sandbox): the
default sandbox image, `ghcr.io/hyperstructure/sandbox`, published for
every release. Hosts pull it, and `fctl host image build` builds its
`main`. The host relies on its layout (the `agent` user, the PATH,
`/opt/fctl/bin`) and on `Dockerfile` and `provision.sh` at its root:
change those there, together with `docs/sandbox-images.md` here. Its Rust
is the one in `rust-toolchain.toml`; bump the two together.

design and fctl-site are private for now: `npm ci` reaches the design
package over git, so it needs GitHub access (CI uses a read-only deploy
key). sandbox is public.

## Commits, pull requests and releases

Expand Down Expand Up @@ -137,8 +145,8 @@ it needs GitHub access (CI uses a read-only deploy key).
#13, and add labels. Add to other people's issues (a comment or a new
section) instead of rewriting them.
- An fctl session's token covers only this repository: name what
hyperstructure/fctl-site or hyperstructure/design need, and tell the
person.
hyperstructure/fctl-site, hyperstructure/design or hyperstructure/sandbox
need, and tell the person.
- The procedures: [.claude/skills/issues/SKILL.md](.claude/skills/issues/SKILL.md).

## After opening a pull request
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ anyhow = "1.0.104"
base64 = "0.23.1"
bytes = "1.12.1"
clap = { version = "4.6.7", features = ["derive", "env", "wrap_help"] }
flate2 = "1.1.10"
futures = "0.3.34"
getrandom = "0.4.3"
hex = "0.4.3"
Expand All @@ -60,6 +61,7 @@ serde = { version = "1.0.229", features = ["derive"] }
serde_json = "1.0.154"
serde_with = { version = "3", default-features = false, features = ["macros"] }
sha2 = "0.11.1"
tar = "0.4.46"
thiserror = "2.0.21"
tokio = { version = "1.53.3", features = ["full"] }
toml = "1.1.8"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sessions with your team.
```sh
curl -fsSL https://fctl.sh/install | sh
fctl login app.fctl.sh
fctl host install --build-image # this machine now runs agents
fctl host install # this machine now runs agents
fctl run -p my-app "Add a dark mode toggle"
```

Expand Down
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ this file is the overview. Order within a section is priority.
container driver (DNS, clock, disk, caches) from what they show (#1)
- [x] CI on GitHub Actions: checks on pull requests, deploys from `main`,
releases from tags
- [ ] Prebuilt sandbox images (GHCR) so `fctl host image build` is a pull (#2)
- [x] Prebuilt sandbox images (GHCR) so `fctl host image build` is a pull (#2)
- [ ] Shared caches per project (npm, cargo, uv) mounted into sandboxes (#3)
- [x] Notifications when a session waits for you or fails: web push, with
followers, per-person settings and digests (#4)
Expand Down
2 changes: 1 addition & 1 deletion crates/fctl-agent/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ impl Supervisor {
self.log(
LogSource::Agent,
LogLevel::Info,
"This sandbox has no fctl that can rename the session, so it keeps the title it started with. Rebuilding the default image (fctl host image build) installs one.",
"This sandbox has no fctl that can rename the session, so it keeps the title it started with. The default image, ghcr.io/hyperstructure/sandbox, has one; an image of your own needs fctl on the PATH.",
);
}
let setting_sources = match claude::project_settings_are_unsafe(&paths.workdir) {
Expand Down
2 changes: 2 additions & 0 deletions crates/fctl-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ base64.workspace = true
fctl-client.workspace = true
fctl-domain.workspace = true
fctl-proto.workspace = true
flate2.workspace = true
futures.workspace = true
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
sha2.workspace = true
tar.workspace = true
hex.workspace = true
tokio.workspace = true
tokio-tungstenite.workspace = true
Expand Down
77 changes: 72 additions & 5 deletions crates/fctl-host/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! name = "studio-mac"
//! driver = "auto" # apple | docker | lima | process | auto
//! capacity = 4
//! image = "fctl-agent:latest"
//! image = "ghcr.io/acme/agent:1" # unset: the published image of this version
//! cpus = 4 # per sandbox, when its project sets none
//! memory_mb = 8192 # per sandbox, when its project sets none
//! max_cpus = 8 # per sandbox (default: what the machine has)
Expand All @@ -19,6 +19,26 @@ use fctl_proto::runner::{SandboxLimits, SandboxSize};
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};

/// Where the default sandbox image is published, by the Image workflow of
/// https://github.com/hyperstructure/sandbox: a tag for every release.
pub const IMAGE_REPOSITORY: &str = "ghcr.io/hyperstructure/sandbox";

/// The default image before it was published, which hosts installed until
/// then have in host.toml.
const OLD_DEFAULT_IMAGE: &str = "fctl-agent:latest";

/// The published sandbox image of this version of fctl.
pub fn default_image() -> String {
format!("{IMAGE_REPOSITORY}:{}", crate::agentbin::VERSION)
}

/// Whether an image setting, the host's or a project's, means the host's
/// default: empty, or the name the default had before it was published.
pub fn means_default_image(image: &str) -> bool {
let image = image.trim();
image.is_empty() || image == OLD_DEFAULT_IMAGE
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct HostConfig {
Expand All @@ -29,8 +49,9 @@ pub struct HostConfig {
pub driver: String,
/// Maximum concurrent sessions.
pub capacity: u32,
/// Sandbox image for sessions whose project sets none.
pub image: String,
/// Sandbox image for sessions whose project sets none. Unset: the
/// published image of this host's version ([`default_image`]).
pub image: Option<String>,
/// CPUs and memory (MiB) for sandboxes whose project sets none.
pub cpus: u32,
pub memory_mb: u32,
Expand Down Expand Up @@ -62,7 +83,7 @@ impl Default for HostConfig {
name: hostname(),
driver: "auto".into(),
capacity: 4,
image: "fctl-agent:latest".into(),
image: None,
cpus: 4,
memory_mb: 8192,
max_cpus: None,
Expand Down Expand Up @@ -142,7 +163,13 @@ impl HostConfig {
path.display()
)
})?;
toml::from_str(&text).with_context(|| format!("parsing {}", path.display()))
Self::from_toml(&text).with_context(|| format!("parsing {}", path.display()))
}

fn from_toml(text: &str) -> Result<Self> {
let mut cfg: Self = toml::from_str(text)?;
cfg.image = cfg.image.filter(|i| !means_default_image(i));
Ok(cfg)
}

pub fn save(&self) -> Result<()> {
Expand Down Expand Up @@ -182,6 +209,21 @@ impl HostConfig {
self.data_dir.clone().unwrap_or_else(default_data_dir)
}

/// The sandbox image for sessions whose project sets none.
pub fn image(&self) -> String {
self.image.clone().unwrap_or_else(default_image)
}

/// What sandboxes use when [`image`](Self::image) can't be pulled: on
/// the default image, the latest published one. A release's own image is
/// published a few minutes after the release, and development builds may
/// have a version with none.
pub fn fallback_image(&self) -> Option<String> {
self.image
.is_none()
.then(|| format!("{IMAGE_REPOSITORY}:latest"))
}

/// What this host gives each sandbox: the configured defaults and
/// maximums, within `runtime`, what the sandboxes run on has (0: unknown).
pub fn sandbox_limits(&self, runtime: SandboxSize) -> SandboxLimits {
Expand Down Expand Up @@ -225,6 +267,31 @@ mod tests {
SandboxSize { cpus, memory_mb }
}

#[test]
fn hosts_on_the_default_image_follow_their_version() -> Result<()> {
let published = format!(
"ghcr.io/hyperstructure/sandbox:{}",
crate::agentbin::VERSION
);
// Unset, empty, or the default's name from before it was published.
for text in ["", "image = \"\"", "image = \"fctl-agent:latest\""] {
let cfg = HostConfig::from_toml(text)?;
assert_eq!(cfg.image, None, "{text}");
assert_eq!(cfg.image(), published);
assert_eq!(
cfg.fallback_image().as_deref(),
Some("ghcr.io/hyperstructure/sandbox:latest")
);
}
let cfg = HostConfig::from_toml("image = \"ghcr.io/acme/agent:1\"")?;
assert_eq!(cfg.image(), "ghcr.io/acme/agent:1");
assert_eq!(cfg.fallback_image(), None);
// host.toml leaves the default out, so the next version brings its own.
let saved = toml::to_string_pretty(&HostConfig::default())?;
assert!(!saved.lines().any(|l| l.starts_with("image")), "{saved}");
Ok(())
}

#[test]
fn sandboxes_get_at_most_what_the_runtime_has() {
let docker_vm = size(10, 15_990);
Expand Down
24 changes: 23 additions & 1 deletion crates/fctl-host/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ impl Daemon {
})
}

/// Pulls the host's sandbox image in the background when it isn't here
/// yet, so that the first session after an upgrade doesn't wait for it.
fn prefetch_image(&self) {
if !self.ctx.driver.uses_images() {
return;
}
let ctx = self.ctx.clone();
tokio::spawn(async move {
let image = ctx.cfg.image();
if ctx.driver.has_image(&image).await {
return;
}
tracing::info!("pulling {image}");
match ctx.driver.pull(&image, false).await {
Ok(()) => tracing::info!("pulled {image}"),
Err(e) => tracing::warn!("pulling {image}: {e:#} (sessions try again)"),
}
});
}

/// Re-attaches to sandboxes that survived a restart. False when the
/// runtime doesn't answer: the hello must not tell the control plane
/// that sessions are gone (it would stop them) when they may still run.
Expand Down Expand Up @@ -284,7 +304,7 @@ impl Daemon {
capacity: self.ctx.cfg.capacity,
labels: self.ctx.cfg.labels.clone(),
sessions: self.reports(),
image: Some(self.ctx.cfg.image.clone()),
image: Some(self.ctx.cfg.image()),
sandbox: Some(self.ctx.sandbox_limits()),
}
}
Expand Down Expand Up @@ -321,6 +341,8 @@ impl Daemon {
}
wait = (wait * 2).min(Duration::from_secs(60));
}
// Once the runtime answers.
self.prefetch_image();
self.start_sweep();
refresh_facts_every(self.ctx.clone(), FACTS_EVERY);
let url = format!(
Expand Down
Loading