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
2 changes: 1 addition & 1 deletion .agents/skills/layerfs-js-sdk/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ refusals and examples. Every option object may also carry `detail`, `with`
| [sandbox](references/methods/sandbox.md) | `create(project, name, { machine, image, mount, on_progress })`, `list({ project, machine, limit, cursor })`, `get(sandbox, { with: ["stats"] })`, `remove(sandbox, { force, on_progress })`, `files(sandbox, path?, { depth, limit, cursor, byte_offset, byte_length })`, `log(sandbox, { limit, cursor })`, `doctor(sandbox, { on_progress })` |
| [workspace](references/methods/workspace.md) | `list({ sandbox, limit, cursor })`, `mount(sandbox, branch, { name })`, `exec(workspace, command, { cwd, env, stdin, stream, stdout, stderr, on_progress })`, `cancel(workspace, { exec })`, `commit(workspace, { message, expected, force })`, `unmount(workspace, { discard, force })`, `status(workspace, { path })` |
| [machine](references/methods/machine.md) | `list({ with: ["live"] })`, `get(machine, { with: ["live"] })`, `images(machine, { with: ["docker"] })`, `load_image(machine, image, { on_progress })`, `prune(machine, image?, { unused })`, `stats(machine, { with: ["space"] })`, `files(machine, path?, { depth, limit, cursor, byte_offset, byte_length })`, `log(machine, { limit, cursor })`, `start(machine, { on_progress })`, `stop(machine, { force, on_progress })`, `create(name, platform, { cpus, memory, disk, image, os_image, on_progress })`, `remove(machine, { on_progress })`, `update(machine, { cpus, memory, image, docker, wsl, daemon })`, `doctor(machine, { on_progress })` |
| [store](references/methods/store.md) | `list({ machine, with: ["stats"] })`, `get(store, { with: ["live", "stats"] })`, `create(name, { machine })`, `connect(store, url, { auth, machine, synchronous_commit })`, `disconnect(store, { machine })`, `save_auth(auth, { user, password })`, `auths()`, `remove_auth(auth)`, `update(store, { auth, synchronous_commit })`, `move(store, machine, { on_progress })`, `remove(store)`, `compact(store, { on_progress })`, `doctor(store, { machine, on_progress })` |
| [store](references/methods/store.md) | `list({ machine, with: ["stats"] })`, `get(store, { with: ["live", "stats"] })`, `create(name, { machine })`, `connect(store, url, { user, password, synchronous_commit })`, `disconnect(store)`, `attach(store, { machine })`, `detach(store, { machine })`, `move(store, machine, { on_progress })`, `remove(store)`, `compact(store, { on_progress })`, `doctor(store, { machine, on_progress })` |
| [backup](references/methods/backup.md) | `connect(name, url, { access_key, secret_key })`, `disconnect(bucket)`, `list({ bucket })`, `create(store, bucket, { file, on_progress })`, `restore(bucket, file, store, { on_progress })`, `doctor(bucket, { full })` |

`home`, `machine`, `store` and `backup` set up where things live; an agent
Expand Down
5 changes: 3 additions & 2 deletions .agents/skills/layerfs-js-sdk/references/methods/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ found it so; else `ready`. Every broken Sandbox's `fix` is
## `sandbox.create`

Starts a named Sandbox of a project. With no `machine` it runs on its sqlite
Store's machine, else on `native`; another machine than a sqlite Store's is
`Unsupported`. `image` (a `sha256:` digest, a Docker image id or a Docker
Store's machine, or on the one machine attached to its PostgreSQL Store
(none attached, or several: `InvalidInput`; `store.attach` attaches one);
another machine than a sqlite Store's is `Unsupported`. `image` (a `sha256:` digest, a Docker image id or a Docker
reference) picks its root on every machine but macOS `native`, which refuses
it `Unsupported`; an image the machine does not hold is copied from the
host's Docker first, as [`machine.load_image`](machine.md) does, with its
Expand Down
36 changes: 18 additions & 18 deletions .agents/skills/layerfs-js-sdk/references/methods/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
store.list({ machine, with: ["stats"] })
store.get(store, { with: ["live", "stats"] })
store.create(name, { machine })
store.connect(store, url, { auth, machine, synchronous_commit })
store.disconnect(store, { machine })
store.save_auth(auth, { user, password })
store.auths()
store.remove_auth(auth)
store.update(store, { auth, synchronous_commit })
store.connect(store, url, { user, password, synchronous_commit })
store.disconnect(store)
store.attach(store, { machine })
store.detach(store, { machine })
store.move(store, machine, { on_progress })
store.remove(store)
store.compact(store, { on_progress })
Expand All @@ -28,20 +26,24 @@ store.doctor(store, { machine, on_progress })
A Store holds projects and all their history. The verb says the kind:
`create` makes a sqlite Store (one file, on one machine at a time; on
`native` unless `machine` names another); `connect` connects a PostgreSQL
database with a saved login.
database with its login, saved on this computer only, and `attach` lets a
machine (machine native too) run its Sandboxes; with no machine named, `sandbox.create` uses the one attached machine.

## `store.list` and `store.get`

From the home's records, with no probe. A Store's `state` is `ready`, `busy`
(`op`: a move, remove, create, compaction, backup or restore), `blocked`
(its machine is not ready) or `broken` (`reason`, with a `fix` naming the
call that clears it). `get` short: `{ engine, state }` with `machine`,
`auth`, `projects`, `projects_count`, `backups`, `connections` and the
companion when they say something; long adds `binding` (16-hex prefix of the
Store's database id), `op`, `blocked_by`, `reason`, `fix`, `observed_at`,
`url`, `user`, `machines`, `projects`, `projects_count`, `backups` and the
companion when they say something; long adds `password_saved`,
`password_changed_at`, `binding` (16-hex prefix of the Store's database id),
`reach` (this computer's last reach of a PostgreSQL Store), `op`, `blocked_by`, `reason`, `fix`, `observed_at`,
`store`, `profile`, `synchronous_commit`, `sqlite_version`, `created_at`,
`last_transfer`. `list` rows are the same with `store` first; `machine` keeps
the sqlite Stores on one machine.
`last_transfer`. A PostgreSQL Store's `machines` are its attached machines,
each `{ machine, reached, reach }`. `list` rows are the same with `store`
first and `machines` as names; `machine` keeps the sqlite Stores on one
machine.

```bash
$ layerfs store list # seen
Expand Down Expand Up @@ -76,12 +78,10 @@ $ layerfs store get shop --with live,stats #
| Call | What it does | Notes |
| --- | --- | --- |
| `create(name)` | An empty sqlite Store | `{"ok":true}` (seen). A taken name is `Exists` (seen: `a Store named shop exists`). `machine` makes it on that running machine through its worker |
| `save_auth(auth, { user, password })` | Saves or replaces a PostgreSQL login in the home's secret folder (also overwrites a broken/unreadable login file) | Shell: `--user U --password-stdin`; the password is never answered, logged or traced. `{"ok":true}` |
| `auths()` | The saved logins and the Stores that use each | `{ items: [{ auth, user, stores?, stores_count?, state?, reason?, fix? }] }`; long adds `created_at`, `updated_at`; unreadable login files appear as `state: "broken"`, `reason: "failed"` rows with a `save-auth` `fix`; never a password. Seen on a fresh home: `{"items":[]}` |
| `remove_auth(auth)` | Deletes a saved login no Store uses | `InUse` (flat `stores`) while one uses it |
| `connect(store, url, …)` | Connects a PostgreSQL database as a Store (`auth` required the first time; `synchronous_commit` defaults to `local`); on a connected Store, sets its address, or with `machine` proves and records that machine's own reach | The URL holds host, port, database and TLS settings only (`sslkey`/`sslcert` allowed): one naming a user, password or `passfile` is `InvalidInput` (with a `fix` chaining `store save-auth` and `store connect`/`store update` stripped of credentials). Short `{ projects, projects_count? }`, or `{"ok":true}` |
| `update(store, …)` | A PostgreSQL Store's login (`auth`) or `synchronous_commit` | `{"ok":true}` |
| `disconnect(store)` | Forgets a PostgreSQL Store, its data staying; with `machine`, only that machine's own address | `InUse` while a Sandbox or Workspace uses it |
| `connect(store, url, …)` | Connects a PostgreSQL database as a Store (`user` and `password` required the first time, checked before anything is saved; `synchronous_commit` defaults to `local`); on a connected Store, changes its address, user, password or `synchronous_commit` (an omitted user or password keeps the saved one; the same Store must be reached) | The URL holds host, port, database and TLS settings only: one naming a user, password or `passfile` is `InvalidInput` with the `fix` `layerfs store connect <store> <url> --user <user> --password-stdin`. Shell: `--user U --password-stdin`; the password is never answered, logged or traced. Short `{ projects, projects_count? }`, or `{"ok":true}`; long `outcome` `connected` or `updated` |
| `disconnect(store)` | Forgets a PostgreSQL Store with its saved password and attachments, its data staying | `InUse` while a Sandbox or Workspace uses it |
| `attach(store, { machine })` | Lets a machine run Sandboxes of a PostgreSQL Store, checked from that machine with the saved URL and login first | Short `{ ok, outcome, latency_ms? }`; `outcome` `attached`, or `checked` when already attached. A sqlite Store is `InvalidInput`; machine native is attached like any other. `sandbox.create` on a machine not attached is refused with `layerfs store attach <store> --machine <machine>` as its `fix` |
| `detach(store, { machine })` | Stops a machine running Sandboxes of a PostgreSQL Store | `InUse` while a Sandbox of the Store's projects is on it; `NotFound` when not attached |
| `move(store, machine)` | Moves a sqlite Store between this computer and a machine | To or from `native` only (seen when already there: `store move, check: Store shop is already on native`, `InvalidInput`; moving off a machine whose record lacks `vm_name` is `Unavailable` with `blocked_by`). Progress `check`, `snapshot`, `send`, `verify`, `install`, `record`, `retire`. Short `{ moved_bytes }`. A sqlite Store's Sandboxes run only on its machine |
| `remove(store)` | Deletes a sqlite Store with every project in it | `{"ok":true}`. `NotFound` for an unknown name (seen). A PostgreSQL Store is disconnected instead. A record this build does not read, or a Store on a machine whose record has no 2.0 name, goes by its records alone, with `left` saying what may remain |
| `compact(store)` | Reclaims the dead bytes of one Store | The only byte-reclaiming call. Short `{ freed_bytes }` (seen: `{"freed_bytes":0}`); long `outcome` (`compacted` or `unchanged`), `dead_bytes`, `kept_waste`, `peak_temp_bytes`, `zero_reasons`, …. Progress `mark`, `build`, `verify`, `install` (sqlite; an `unchanged` run sends `mark` only). A sqlite Store on another machine is compacted by its worker. `InUse` while Workspaces are mounted; `Busy` (with `op`); `Unavailable`, `Unknown` and `Unresolved` (each with a `fix`) |
Expand Down
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ library's call table as ten families of functions, 83 calls in all:
| [`sandbox`](../docs/architecture/api/sdk/sandbox.md) | `create`, `list`, `get`, `remove`, `files`, `log`, `doctor` |
| [`workspace`](../docs/architecture/api/sdk/workspace.md) | `list`, `mount`, `exec`, `cancel`, `commit`, `unmount`, `status` |
| [`machine`](../docs/architecture/api/sdk/machine.md) | `list`, `get`, `images`, `load_image`, `prune`, `stats`, `files`, `log`, `start`, `stop`, `create`, `remove`, `update`, `doctor` |
| [`store`](../docs/architecture/api/sdk/store.md) | `list`, `get`, `create`, `connect`, `disconnect`, `save_auth`, `auths`, `remove_auth`, `update`, `move`, `remove`, `compact`, `doctor` |
| [`store`](../docs/architecture/api/sdk/store.md) | `list`, `get`, `create`, `connect`, `disconnect`, `attach`, `detach`, `move`, `remove`, `compact`, `doctor` |
| [`backup`](../docs/architecture/api/sdk/backup.md) | `connect`, `disconnect`, `list`, `create`, `restore`, `doctor` |

`layerfs.table` lists every call with its arguments and options; it is the
Expand Down
39 changes: 14 additions & 25 deletions api/crates/layerfs-api/src/calls/guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const ARGS: &[(&str, &str, &str)] = &[
"a Workspace, written <sandbox>:<name> as `workspace mount` answers",
),
("*", "bucket", "a connected bucket, by name"),
("*", "auth", "a saved PostgreSQL login, by name"),
(
"*",
"image",
Expand Down Expand Up @@ -296,7 +295,7 @@ const ARGS: &[(&str, &str, &str)] = &[
(
"sandbox.create",
"machine",
"the machine it runs on; the Store's machine when left out",
"the machine it runs on; when left out, a sqlite Store's machine or the one machine attached to a PostgreSQL Store",
),
(
"sandbox.create",
Expand Down Expand Up @@ -480,26 +479,24 @@ const ARGS: &[(&str, &str, &str)] = &[
),
(
"store.connect",
"auth",
"the saved login; needed on a Store's first connect",
"user",
"the PostgreSQL role; needed on a Store's first connect",
),
(
"store.connect",
"machine",
"the address is this machine's own",
"password",
"the role's password, read from stdin; needed on a Store's first connect",
),
(
"store.disconnect",
"store.attach",
"machine",
"remove only this machine's own address",
"the machine that may run the Store's Sandboxes",
),
("store.save_auth", "user", "the PostgreSQL role"),
(
"store.save_auth",
"password",
"the password, read from stdin",
"store.detach",
"machine",
"the machine that no longer runs the Store's Sandboxes",
),
("store.update", "auth", "another saved login"),
(
"store.move",
"machine",
Expand All @@ -508,7 +505,7 @@ const ARGS: &[(&str, &str, &str)] = &[
(
"store.doctor",
"machine",
"also check a PostgreSQL Store's connection from this machine",
"check a PostgreSQL Store from this attached machine only",
),
("backup.connect", "name", "the bucket's name in this home"),
(
Expand Down Expand Up @@ -678,19 +675,11 @@ const EXAMPLES: &[(&str, &str)] = &[
("store.create", "layerfs store create shop"),
(
"store.connect",
"layerfs store connect team postgresql://db.local:5432/team --auth admin",
"layerfs store connect team postgresql://db.local:5432/team --user layerfs --password-stdin",
),
("store.disconnect", "layerfs store disconnect team"),
(
"store.save_auth",
"layerfs store save-auth admin --user layerfs --password-stdin",
),
("store.auths", "layerfs store auths"),
("store.remove_auth", "layerfs store remove-auth admin"),
(
"store.update",
"layerfs store update team --synchronous-commit on",
),
("store.attach", "layerfs store attach team --machine dev"),
("store.detach", "layerfs store detach team --machine dev"),
("store.move", "layerfs store move shop docker --progress"),
("store.remove", "layerfs store remove shop"),
("store.compact", "layerfs store compact shop --progress"),
Expand Down
7 changes: 3 additions & 4 deletions api/crates/layerfs-api/src/home/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! in the home.
use crate::calls::table::{call, Call};
use crate::calls::{Context, Form, Part, Section};
use crate::store::get::CONNECTION;
use layerfs_bridge::control::SdkValue;
use layerfs_control::home::{Build, With};
use layerfs_home::outcome::Outcome;
Expand Down Expand Up @@ -55,7 +54,7 @@ const STORE: Form = Form::of(
&["store", "engine"],
&[
"projects",
"connections",
"machines",
"state",
"op",
"blocked_by",
Expand All @@ -66,7 +65,7 @@ const STORE: Form = Form::of(
"store",
"engine",
"projects",
"connections",
"machines",
"state",
"op",
"blocked_by",
Expand All @@ -76,7 +75,7 @@ const STORE: Form = Form::of(
)
.parts(&[
("projects", Part::Scalars("project")),
("connections", Part::Rows(&CONNECTION)),
("machines", Part::Scalars("machine")),
]);
const WORKSPACE: Form = Form::of(&["workspace", "branch"], &[], &["workspace", "branch"]);
const SANDBOX: Form = Form::of(
Expand Down
1 change: 1 addition & 0 deletions api/crates/layerfs-api/src/machine/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const FORM: Form = Form::of(
"machine",
"backend",
"supports",
"loopback",
"cpus",
"memory_bytes",
"disk_bytes",
Expand Down
1 change: 1 addition & 0 deletions api/crates/layerfs-api/src/machine/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const ITEM: Form = Form::of(
"observed_at",
"backend",
"supports",
"loopback",
"cpus",
"memory_bytes",
"disk_bytes",
Expand Down
42 changes: 42 additions & 0 deletions api/crates/layerfs-api/src/store/attach.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! `store.attach`: let a machine run Sandboxes of a PostgreSQL Store,
//! dialling the URL and login this computer saved; checked from it first.
use crate::calls::table::Kind::Name;
use crate::calls::table::{a, call, opt, Call};
use crate::calls::{Context, Form};
use layerfs_bridge::control::SdkValue;
use layerfs_home::names::{MachineName, StoreName};
use layerfs_home::outcome::Outcome;

/// Its answer: `ok` and the outcome (`attached`, or `checked` for an
/// attached machine checked again), with what the check measured.
const FORM: Form = Form::of(
&["ok", "outcome"],
&["latency_ms"],
&[
"ok",
"outcome",
"store",
"machine",
"latency_ms",
"server_version",
],
);

/// Its table entry.
pub(crate) const CALL: Call = call(
"store",
"attach",
&[a("store", Name)],
&[opt("machine", Name).required()],
"let a machine run Sandboxes of a PostgreSQL Store, checked from that machine first",
run,
)
.form(&FORM);

/// Runs `store.attach`.
fn run(context: &mut Context<'_>, args: &SdkValue) -> Outcome {
let store = StoreName::parse(args.get_text("store").unwrap_or(""))?;
let machine = MachineName::parse(args.get_text("machine").unwrap_or(""))?;
let (home, events) = context.parts();
layerfs_control::store::attach(home, events, &store, &machine)
}
42 changes: 0 additions & 42 deletions api/crates/layerfs-api/src/store/auths.rs

This file was deleted.

Loading