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
6 changes: 3 additions & 3 deletions .agents/skills/layerfs-js-sdk/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Branch, your Sandbox and how to reach the package or the command.
you find there may be an old copy, not the project.
- **`main` is read-only.** Read it and fork from it. A write to it, a merge
into it (without `into`) and a mount of it are refused `InvalidInput`; the
mount's refusal was seen with
`"fix":"layerfs branch fork shop/api <name> main"`. Work on a Branch, then
`branch.publish` it.
mount's refusal gives a runnable `fix`
(`"layerfs branch fork shop/api work && layerfs workspace mount <sandbox> work"`).
Work on a Branch, then `branch.publish` it.
- **Always unmount.** Put every `workspace.unmount` in a `finally` block. A
forgotten Workspace stays mounted and its Sandbox cannot be removed.

Expand Down
21 changes: 15 additions & 6 deletions .agents/skills/layerfs-js-sdk/references/methods/doctor.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ entries.
- A `not_checked` entry names a thing, or one of its checks, that gave no
verdict: `blocked_by` (the thing at the root of the block and its state) or
`reason` (`timeout`, `busy`, `lost`), never both.
- The long form (`detail: true`) adds `status` (the worst of `error`,
- The long form (`detail: true`) adds `evidence` on each finding (e.g.
`{ step: "handshake" | "authentication" | "transport" }`, retained backup
keys, or reclaimable image bytes), plus `status` (the worst of `error`,
`warning`, `not_checked`, `notice`, `ok`), `counts`, `observed_at` and
`tree`: the doctor's own thing with `status`, `coverage` (`none`,
`shallow` or `full`), its `checks` (`{ check, outcome, from }`),
Expand Down Expand Up @@ -78,12 +80,19 @@ for (const n of report.not_checked) console.log("not checked:", JSON.stringify(n
`project.data`: everything `main`'s head and each Branch's head reach is
read and checked where the Store's calls run. It writes nothing to the
Store.
- **`store.doctor`**: `store.record`, `store.operation` (an operation left
- **`store.doctor`**: `store.record` (for a PostgreSQL Store whose record
lacks a saved login, names a missing login, or holds outdated pre-2.0
fields, `store.record` fails with the `fix` from `store list`/`store get`
while remaining checks still run), `store.operation` (an operation left
with its outcome unknown is an error whose `fix` clears it),
`store.connection`, `store.identity`, `store.schema` and, for a sqlite
Store, `store.backups` (a notice per bucket whose backup is behind, `fix`
`layerfs backup create <store> <bucket>`). No Store data is scanned.
`machine` is for a PostgreSQL Store: it also probes from that machine.
`store.connection` (for PostgreSQL, probes from this computer and from each
machine with an own address, recorded reach, or Sandbox of the Store — plus
`machine` when given — with a 5 s connect-and-login handshake limit so a
silent server fails `store.connection` with `evidence: { step: "handshake" }`
and records reach `failed` without a second dial), `store.identity`,
`store.schema` and, for a sqlite Store, `store.backups` (a notice per
bucket whose backup is behind, `fix` `layerfs backup create <store> <bucket>`).
No Store data is scanned.
- **`sandbox.doctor`**: the Sandbox's record and references, its operation,
runtime, route and daemon (`sandbox.record` … `sandbox.observation`), then one
node per Workspace (`workspace.mounted`, `workspace.activity`); a failed or
Expand Down
25 changes: 15 additions & 10 deletions .agents/skills/layerfs-js-sdk/references/methods/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ 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`,
`projects`, `backups`, `connections` and the companion when they say
something; long adds `auth`, `projects_count`, `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.
`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`,
`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.

```bash
$ layerfs store list # seen
Expand All @@ -55,7 +56,11 @@ Sections of `get`:
and `observed_at` from that read, and `live: { holders, phases, behind,
server_version, latency_ms }` (`holders`: pids of other live processes
holding the Store; `phases`: a running compaction's; `behind`: the
buckets whose backup is behind).
buckets whose backup is behind). For PostgreSQL, every connect-and-login
handshake is bounded to 5 s (`POSTGRESQL_HANDSHAKE` or the URL's
`connect_timeout`), one attempt, no retry: a silent server yields
`state: "broken"`, `reason: "unreachable"` (`"the server did not answer
within 5 s (connect and login)"`).
- `with: ["stats"]` opens the Store for its counters: `stats: { size,
logical_bytes, canonical_bytes, stored_bytes, metadata_bytes, file_bytes,
reusable_bytes, dedupe, compression, init }` (ratios as text, six
Expand All @@ -71,13 +76,13 @@ $ 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 | 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? }] }`; never a password. Seen on a fresh home: `{"items":[]}` |
| `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` that machine's own | The URL holds host, port, database and TLS settings only: one naming a user or password is `InvalidInput`. Short `{ projects }`, or `{"ok":true}` |
| `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 |
| `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`). Progress `check`, `snapshot`, `send`, `verify`, `install`, `record`, `retire`. Short `{ moved_bytes }`. A sqlite Store's Sandboxes run only on its machine |
| `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`) |
| `doctor(store)` | Checks the Store, then each of its projects | See [doctors](doctor.md); seen: `{"ok":true}` |
4 changes: 2 additions & 2 deletions .agents/skills/layerfs-js-sdk/references/methods/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ trimmed from the ends (`Feature/Login` mounts as `feature-login`).
$ layerfs workspace mount tests agent # seen
{"workspace":"tests:agent","path":"/tmp/demo/home/machine/native/run/layerfs-8a7387b2-tests/workspaces/1"}
$ layerfs workspace mount tests main # seen, exit 125
{"error":"InvalidInput","message":"main is the project's published line, not a Branch, and is not mounted: fork a Branch from it and mount that","fix":"layerfs branch fork shop/api <name> main"}
{"error":"InvalidInput","message":"main is the project's published line, not a Branch, and is not mounted: fork a Branch from it and mount that","fix":"layerfs branch fork shop/api work && layerfs workspace mount tests work"}
```

| `error` | When | Do |
Expand Down Expand Up @@ -124,7 +124,7 @@ $ layerfs workspace exec tests:agent 'exit 3' #
`unmount` deletes it). Output that is not UTF-8 is bytes.
- **Node and Python** also take `stdout` and `stderr` functions, called with
the output's pieces, and `stream: true`, which writes it to your process's
own stdout and stderr. When the pieces arrive was not checked in this pass.
own stdout and stderr. Output is delivered after the command ends, never live.
- **Shell:** the command exits with the command's own code and prints the
answer on stdout; `--stream` writes the output to stdout and stderr and
prints no answer; a refusal exits 125.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
> `machine.log` outputs were printed by the built `layerfs` command on a
> throwaway home on 2026-11-18 (macOS, a `native` Sandbox). What the daemon
> writes is read from source
> (`control/crates/layerfs-sandbox-backend/src/backend/native/`), not run.
> (`control/crates/layerfs-sandbox-backend/src/backend/{host_process,namespaces}/`), not run.
> 1.x `logs.sandbox` and `logs.machine` are now `sandbox.log` and
> `machine.log`, with no alias.

Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/layerfs-sdk-observe/references/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ outcome. Written by `layerfs-home/src/trace.rs` (`stepped`, `step`),
| --- | --- | --- |
| Settings `LAYERFS_TRACE`, `LAYERFS_TRACE_STEP`, `LAYERFS_TRACE_START` | read by `@layerfs/agent` (`api/agent/sdk/src/trace.js` at tag `v1.1.0`) | kept as the only settings besides `LAYERFS_HOME` (S §2.5); `LAYERFS_TRACE` is read for the worker-connection line, and with `LAYERFS_TRACE_STEP` for the step lines; `LAYERFS_TRACE_START` is not read |
| The trace line writer | in that JavaScript file | deleted with `@layerfs/agent` (#533 step 14); the call log (#659, `layerfs-home/src/logs.rs`, read with `home.log`) is its per-call replacement, without daemon telemetry |
| In-process collector | `host/trace.rs` in the Node binding | `api/crates/layerfs-api/src/host/trace.rs`: takes a 64-hex scope from an `observe` argument, traces the call's daemon control exchanges under it and collects up to 64 telemetry values. **No front end calls it** (`take_scope` and `run` have no callers) |
| In-process collector | `host/trace.rs` in the Node binding | retired when `api/crates/layerfs-api/src/host/` was removed in 2.0 (no front end or API module collects in-process daemon telemetry) |
| The home's `trace/` folder | `traces/` | `paths::trace_dir` (a 1.1.0 `traces/` folder is renamed to it); O26 makes trace files there the feed. Holds the call log, `calls.jsonl` and `calls.1.jsonl` (#659) |

So, today: the call log records every call's outcome and time; turning
Expand Down
58 changes: 48 additions & 10 deletions api/crates/layerfs-api/tests/project_doctor_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,51 @@ fn sqlite_full_reads_main_and_each_branch_and_names_a_damaged_object_in_each_pro
let _ = std::fs::remove_dir_all(&home);
}

fn split_pg_store_url(raw: &str, database: &str) -> (String, String, String) {
if let Some(rest) = raw
.strip_prefix("postgresql://")
.or_else(|| raw.strip_prefix("postgres://"))
{
let (base, query) = rest.split_once('?').unwrap_or((rest, ""));
let (server, _) = base.rsplit_once('/').unwrap_or((base, ""));
let (user, host_part) = match server.split_once('@') {
Some((creds, hp)) => (creds.split(':').next().unwrap_or("postgres"), hp),
None => ("postgres", server),
};
let suffix = if query.is_empty() {
format!("/{database}")
} else {
format!("/{database}?{query}")
};
return (
user.to_owned(),
format!("postgresql://{server}{suffix}"),
format!("postgresql://{host_part}{suffix}"),
);
}
let mut host = "127.0.0.1";
let mut port = "5432";
let mut user = "postgres";
let mut sslmode = "disable";
for token in raw.split_whitespace() {
if let Some((k, v)) = token.split_once('=') {
let v = v.trim_matches('\'').trim_matches('"');
match k {
"host" => host = v,
"port" => port = v,
"user" => user = v,
"sslmode" => sslmode = v,
_ => {}
}
}
}
(
user.to_owned(),
format!("postgresql://{user}@{host}:{port}/{database}?sslmode={sslmode}"),
format!("postgresql://{host}:{port}/{database}?sslmode={sslmode}"),
)
}

/// The same on a PostgreSQL Store, in a database of its own (a 2.0 Store
/// lives in that database's fixed `layerfs` schema), dropped at the end.
/// `LAYERFS_TEST_POSTGRES_URL` is `postgresql://user@host:port/db?...`.
Expand All @@ -160,23 +205,16 @@ fn postgresql_full_reads_main_and_each_branch_and_names_a_damaged_object_in_each
};
admin(&format!("DROP DATABASE IF EXISTS {database}"));
admin(&format!("CREATE DATABASE {database}"));
let (base, query) = url.split_once('?').unwrap_or((url.as_str(), ""));
let (server, _) = base.rsplit_once('/').unwrap();
let store_url = match query {
"" => format!("{server}/{database}"),
query => format!("{server}/{database}?{query}"),
};
let (user, store_url, clean_url) = split_pg_store_url(&url, &database);
let home = folder("pg-home");
// the URL's user becomes a saved login (a trust-auth server takes any
// password); the address is connected without it
let (scheme, rest) = store_url.split_once("://").unwrap();
let (user, address) = rest.split_once('@').unwrap();
call(
&home,
"store.save_auth",
&[
("auth", t("pg")),
("user", t(user)),
("user", t(&user)),
("password", t("unused")),
],
);
Expand All @@ -185,7 +223,7 @@ fn postgresql_full_reads_main_and_each_branch_and_names_a_damaged_object_in_each
"store.connect",
&[
("store", t("shop")),
("url", t(&format!("{scheme}://{address}"))),
("url", t(&clean_url)),
("auth", t("pg")),
("synchronous_commit", t("off")),
],
Expand Down
42 changes: 38 additions & 4 deletions api/crates/layerfs-api/tests/store_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,41 @@ fn native_sqlite_and_worker_statistics_use_the_same_counters() {
std::fs::remove_dir_all(root).unwrap();
}

fn split_pg_test_url(raw: &str) -> (String, String) {
if let Some(rest) = raw
.strip_prefix("postgresql://")
.or_else(|| raw.strip_prefix("postgres://"))
{
if let Some((creds, address)) = rest.split_once('@') {
let user = creds.split(':').next().unwrap_or("postgres");
return (user.to_owned(), format!("postgresql://{address}"));
}
return ("postgres".to_owned(), format!("postgresql://{rest}"));
}
let mut host = "127.0.0.1";
let mut port = "5432";
let mut user = "postgres";
let mut dbname = "postgres";
let mut sslmode = "disable";
for token in raw.split_whitespace() {
if let Some((k, v)) = token.split_once('=') {
let v = v.trim_matches('\'').trim_matches('"');
match k {
"host" => host = v,
"port" => port = v,
"user" => user = v,
"dbname" => dbname = v,
"sslmode" => sslmode = v,
_ => {}
}
}
}
(
user.to_owned(),
format!("postgresql://{host}:{port}/{dbname}?sslmode={sslmode}"),
)
}

#[test]
fn postgresql_statistics_have_null_free_and_count_publications() {
let Ok(url) = std::env::var("LAYERFS_TEST_POSTGRES_URL") else {
Expand All @@ -186,14 +221,13 @@ fn postgresql_statistics_have_null_free_and_count_publications() {
let home = folder("pg-home");
// the URL's user becomes a saved login (a trust-auth server takes any
// password); the address is connected without it
let (scheme, rest) = url.split_once("://").unwrap();
let (user, address) = rest.split_once('@').unwrap();
let (user, clean_url) = split_pg_test_url(&url);
call(
&home,
"store.save_auth",
&[
("auth", t("pg")),
("user", t(user)),
("user", t(&user)),
("password", t("unused")),
],
);
Expand All @@ -202,7 +236,7 @@ fn postgresql_statistics_have_null_free_and_count_publications() {
"store.connect",
&[
("store", t("stats")),
("url", t(&format!("{scheme}://{address}"))),
("url", t(&clean_url)),
("auth", t("pg")),
("synchronous_commit", t("off")),
],
Expand Down
Loading