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
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Laptop route forms — the codified matrix (T0–T7)

Design record for developing-today/code#13717 (companion: #13654).
Direction: Drew, 2026-11-23 14:56 + 14:59 + 15:07 CST.

## Why a matrix, not a ladder

The platform execution-risk behaviour observed on 2026-11-23 keys on
the **literal command shape** an agent runs: the same laptop
operation returned via one route comes back clean, via another
trips the check. A single opaque command that papers over every
route would hide which form actually works for a given operation,
and would remove the raw forms an agent sometimes needs when the
wrapper itself is the obstacle. So the raw commands are first-class
tiers, not implementation details — and tier 0, the one generic
command, still reports exactly which tier served the call.

## The codified matrix

| Tier | Method | Shape | Literal command |
|---|---|---|---|
| T0 | tiered | fleet subcommand | `fleet laptop exec [--timeout S] -- cmd...` — walks T1 → T2 → T3 internally, reports the serving tier |
| T1 | commander | fleet subcommand | `fleet commander exec [--cwd D] --timeout S -- cmd...` |
| T2 | http-direct | fleet subcommand | `fleet http exec [--cwd D] --timeout S -- cmd...` |
| T3 | ssh | fleet subcommand | `fleet ssh exec [--cwd D] --timeout S -- cmd...` |
| T4 | commander | raw command | the documented curl recipe against `https://commander.security.cab/mcp` |
| T5 | http-direct | raw command | literal curl to the daemon API through the session proxy |
| T6 | ssh | raw command | the literal `ssh` invocation written out in `TOOLS.d/laptop.md` |
| T7 | wrapper | simplified tier | `laptop-ssh 'cmd...'` — final fallback, and the one-command form for an agent without the full matrix |

**Composition.** Tier 0 is the first option. It attempts T1 → T2 →
T3 in order, each attempt a literal invocation of that tier's own
implementation, advancing only when a tier fails to *serve*
(transport / auth / connect failure or a tier-level timeout) —
never on a served result, whatever its exit code — and it names
the serving tier. Tier 0 does **not** fall through to the wrapper:
when tier 0 fails, the individual forms come into play as their
own literal commands — the fleet subcommands (T1–T3) again,
because an attempt under tier 0's process shape is a different
literal invocation than the standalone subcommand — then the raw
commands (T4–T6), then the wrapper (T7).

One recorded casualty of the walk rule: ssh's own failure exit is
255, so tier 0 reads a remote command that itself exits 255 over
ssh as a tier failure. Standalone `fleet ssh` propagates 255
untouched; only the walker applies the convention.

## Endpoint-grade contracts (the commander pattern, all three methods)

- **Commander (T1)** — `crates/fleet/src/commander.rs`. Bearer
resolved in-process from the secrets broker by name
(`desktop-commander.machine-bearer`), never stored; browser UA
(the edge 1010-blocks non-browser agents, #13404); one MCP
session per invocation; `timeout_ms` always sent; spawned
processes polled to completion or force-terminated on the
deadline — no orphaned processes on the laptop; the remote exit
code is read from the endpoint's own completion line.
- **HTTP (T2)** — `crates/fleet/src/http.rs` over the
fleet-laptop-agent client. The daemon is the endpoint; this is
its contract surface: token auth from the token file, the
primary-checkout guard applied before anything is sent (a guard
refusal is a *served* result — tier 0 must not route around it),
daemon `timeout_s` plus the transport grace as the local
deadline, exit codes from the daemon reply. The ladder is built
HTTP-only (`legs::http_ladder`: broker socket → Cloudflare
tunnel → Tailscale CONNECT) — the SSH leg is excluded by
construction, so T2 can never silently become T3.
- **SSH (T3)** — `crates/fleet/src/ssh.rs`. The endpoint-grade
shape for SSH is a **binary-owned client contract**: the binary
constructs the ssh invocation itself (pinned host key in
`~/.ssh/known_hosts_laptop`, `StrictHostKeyChecking=yes`, proxy
CONNECT helper, `IdentitiesOnly`, `ConnectTimeout`) instead of
delegating to a shell script; a mandatory overall deadline
enforced by the binary (child kill → exit 124). Honest limit:
sshd owns the remote process, so a client-side kill ends the
session but cannot cancel the remote command protocol-side.
Session hygiene: a fleet-owned ControlMaster path
(`~/.ssh/cm-fleet-…`, persist 600 s — separate from laptop-ssh's
master) and `fleet ssh close` to tear it down. A native
in-process SSH protocol implementation is the recorded horizon,
not this build.

Timeouts are required by construction on every fleet-shape form:
there is no invocation path without one (T0 sets a per-attempt
timeout, default 120 s; T1 default 120 s; T2 and T3 default 300 s).

## Selection doctrine

- Circumstance decides which form is the right way through. There
is no single blessed invocation.
- An agent tries each form as **its own literal command** — never
a blended invocation.
- **Form visibility**: every result and log line names the exact
form used, as method × shape (`form T2 http/fleet`,
`form T4 commander/raw`). The fleet forms announce themselves on
stderr; tier 0 narrates each attempt and the serving tier.
- Raw forms must exist, stay documented, and stay exercised —
they are the route around a wrapper that has itself become the
obstacle. Their literal recipes live in `TOOLS.d/laptop.md`.

## The demotion of `laptop-ssh` (T7)

Documentation-and-defaults, not removal. `laptop-ssh` keeps working
for every existing caller — it is load-bearing in the heal/init
stack (the channel-heal and init-ensure scripts delegate through
it), in crons, and in lane habits. What changes: the mechanics doc
and the shim's own header teach the matrix and the tier-0-first
order, and name `laptop-ssh` as tier T7 — the fallback when the
fleet tiers fail, and the simplified tier for an agent that
doesn't carry the full list: one command that does something sane.

## Recorded horizon (Drew, 2026-11-23)

Longer-term design threads named alongside this codification, not
part of this build: host selection and access without Tailscale; a
direct iroh transport for non-Muse agents; a generic pooling
system.

## Verification (2026-11-23)

Built in the `pkgs/fleet` workspace (features `commander`, `http`,
`ssh`, `laptop`, all in `full`); `cargo test` green across
fleet-registry, fleet-laptop-agent and the fleet binary (including
the DOC-01 inventory test, which now lists the four new domains).
Smoke from the sandbox with the built binary: every fleet form ran
`hostname` → `amd`, read `/etc/hostname`, and propagated a remote
`exit 3` as exit 3, naming its form; the raw forms ran as written
in `TOOLS.d/laptop.md`. The seat-wide install rides the next
fleet-static publish; nothing was installed over the seat binary.
5 changes: 4 additions & 1 deletion pkgs/fleet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ and every build compiles it, so no build can know a domain another
build forgot. The registered domains are `fleet queue`, `fleet serve`,
`fleet proxy`, `fleet dispatch`, `fleet dispatch-test`,
`fleet secrets`, `fleet gh`, `fleet bridge`, `fleet agent`,
`fleet shell`, `fleet search`, `fleet laptop-agent` and `fleet cert`, plus the
`fleet shell`, `fleet search`, `fleet laptop-agent` and `fleet cert`, and the
laptop route forms (#13717): `fleet laptop` (tier T0, the generic
tiered command), `fleet commander` (T1), `fleet http` (T2) and
`fleet ssh` (T3), plus the
built-ins `fleet init`, `fleet session`, `fleet version`,
`fleet capabilities` and `fleet help`.

Expand Down
1 change: 1 addition & 0 deletions pkgs/fleet/book/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- [fleet shell](reference/shell.md)
- [fleet search](reference/search.md)
- [fleet laptop-agent](reference/laptop-agent.md)
- [fleet laptop route forms](reference/laptop-route-forms.md)

- [Tutorial: enrol a new seat](tutorials/enrol-a-seat.md)
- [Tutorial: claim and complete a queue task](tutorials/claim-and-complete.md)
Expand Down
79 changes: 79 additions & 0 deletions pkgs/fleet/book/reference/laptop-route-forms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# fleet laptop route forms

The four Fleet domains that reach the laptop, codified as one
matrix by #13717: **tier 0** (`fleet laptop`), the generic tiered
command; **T1** (`fleet commander`), the Desktop Commander MCP
endpoint; **T2** (`fleet http`), the laptop-agent daemon's HTTP
API; **T3** (`fleet ssh`), real SSH. Outside the binary, the same
methods exist as raw commands (T4–T6, literal recipes in the
laptop mechanics doc) and the `laptop-ssh` script is T7 — the
fallback / simplified tier.

Why forms at all: the platform's execution-risk behaviour keys on
the literal command shape an agent runs, so each form stays a
first-class, separately invocable command, and every result names
the form that served it. Circumstance decides the form; there is
no single blessed invocation.

## fleet laptop — tier T0

`fleet laptop tiers` prints the matrix. `fleet laptop exec
[--form T1|T2|T3] [--timeout SECS] [--cwd DIR] -- CMD...` walks
T1 → T2 → T3 in order (or attempts one pinned tier), each attempt
a literal invocation of that tier's own implementation. It
advances only when a tier fails to *serve* — transport, auth or
connect failure, or a tier-level timeout — never on a served
result, whatever its exit code, and it reports the serving tier
on stderr (`fleet: served by form T1 commander/fleet`). The
per-attempt `--timeout` always applies (default 120 s). Tier 0
deliberately does not fall through to the `laptop-ssh` wrapper:
reaching T7 is the caller's own final step.

One recorded casualty of the walk rule: ssh's own failure exit is
255, so the walker reads a remote command that itself exits 255
over ssh as a tier failure. Standalone `fleet ssh` propagates 255
untouched.

## fleet commander — tier T1

A client for the self-hosted Desktop Commander MCP endpoint
(#13404, #13654). The bearer is resolved from the secrets broker
by name (`desktop-commander.machine-bearer`) at call time and
never stored; requests carry a browser user agent (the edge
1010-blocks non-browser agents). One MCP session per invocation.
`exec` starts the command via `start_process` (the schema's
`timeout_ms` is always sent), polls `read_process_output` to
completion, and propagates the remote exit code from the
endpoint's own completion line; on the deadline (default 120 s)
it force-terminates the process and exits 124 — an exec never
leaves a running process behind on the laptop. `health`
initializes a session, runs `hostname`, and reports
`{"ok":true,"form":"T1 commander/fleet",...}`.

## fleet http — tier T2

The laptop-agent daemon's HTTP API as a route-form surface: the
same verbs as [fleet laptop-agent](laptop-agent.md), over a
ladder built from the client's HTTP legs only (`http_ladder`:
broker socket → Cloudflare tunnel → Tailscale CONNECT). The SSH
leg is excluded by construction, so this tier can never silently
become the ssh tier. The primary-checkout guard is applied before
anything is sent; a guard refusal is a served result (exit 1),
never something tier 0 may route around. Timeouts always apply:
the daemon's `timeout_s` (default 300) plus the transport grace
as the local deadline; a daemon-side timeout exits 124.

## fleet ssh — tier T3

SSH's endpoint-grade shape is a binary-owned client contract: the
binary constructs the ssh invocation itself — pinned host key
(`~/.ssh/known_hosts_laptop`, `StrictHostKeyChecking=yes`),
proxy CONNECT helper, `IdentitiesOnly`, `ConnectTimeout` —
instead of delegating to a shell script, and enforces a mandatory
overall deadline (default 300 s; the ssh child is killed on
expiry, exit 124). Connections multiplex over a fleet-owned
ControlMaster socket (`~/.ssh/cm-fleet-…`, persist 600 s,
separate from laptop-ssh's master); `fleet ssh close` tears it
down. The honest limit: sshd owns the remote process, so a
client-side kill ends the session but cannot cancel the remote
command protocol-side.
22 changes: 22 additions & 0 deletions pkgs/fleet/crates/fleet-laptop-agent/src/legs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,28 @@ pub fn ladder(config: &fleet_config::Config) -> Result<Ladder, String> {
Ok(Ladder::new(legs))
}

/// The HTTP-only ladder for tier T2 (`fleet http`, #13717): the same
/// legs as [`ladder`] minus the SSH leg, by construction — the http
/// form can never silently become the ssh form.
pub fn http_ladder(config: &fleet_config::Config) -> Result<Ladder, String> {
let token = read_token(&token_file())?;
let legs: Vec<Box<dyn Leg>> = vec![
Box::new(BrokerLeg {
socket: broker_socket(),
}),
Box::new(CfLeg {
token: token.clone(),
config: config.clone(),
cf_host: config.cf_host().to_string(),
cache: Mutex::new(CfCache::default()),
}),
Box::new(TailscaleLeg {
token: token.clone(),
}),
];
Ok(Ladder::new(legs))
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
53 changes: 53 additions & 0 deletions pkgs/fleet/crates/fleet-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ pub enum Capability {
/// the next piece of work down the intake ladder, and run a command
/// where builds belong. Composes the other domains' verbs.
Agent,
/// `fleet commander …` — tier T1 (commander/fleet) of the laptop
/// route forms (#13717): the Desktop Commander MCP endpoint.
Commander,
/// `fleet http …` — tier T2 (http/fleet) of the laptop route
/// forms (#13717): the laptop-agent daemon HTTP API, HTTP legs
/// only.
LaptopHttp,
/// `fleet ssh …` — tier T3 (ssh/fleet) of the laptop route forms
/// (#13717): real SSH under a binary-owned client contract.
LaptopSsh,
/// `fleet laptop …` — tier T0 (tiered/fleet) of the laptop route
/// forms (#13717): the generic tiered command and the form index.
Laptop,
/// `fleet cert …` (alias `fleet pki …`) — the PKI/X.509 domain:
/// roots, issuers, leaves, chains and bundles (code#9157, fleet CA
/// program #9155). A working-seat client surface, so full only.
Expand All @@ -91,6 +104,10 @@ impl Capability {
Capability::Gh => "gh",
Capability::Bridge => "bridge",
Capability::Agent => "agent",
Capability::Commander => "commander",
Capability::LaptopHttp => "laptop-http",
Capability::LaptopSsh => "laptop-ssh",
Capability::Laptop => "laptop",
Capability::Cert => "cert",
}
}
Expand All @@ -113,6 +130,10 @@ impl Capability {
Capability::Gh,
Capability::Bridge,
Capability::Agent,
Capability::Commander,
Capability::LaptopHttp,
Capability::LaptopSsh,
Capability::Laptop,
Capability::Cert,
];
}
Expand Down Expand Up @@ -383,6 +404,38 @@ pub const DOMAINS: &[Domain] = &[
aliases: &["laptop-agent"],
subcommands: &["health", "jobs", "kill", "exec", "run", "poll", "fetch"],
},
Domain {
name: "commander",
summary: "Tier T1 (commander/fleet) of the laptop route forms (#13717): run commands on the laptop through the Desktop Commander MCP endpoint.",
capabilities: &[Capability::Commander],
primary: Capability::Commander,
aliases: &[],
subcommands: &["health", "exec"],
},
Domain {
name: "http",
summary: "Tier T2 (http/fleet) of the laptop route forms (#13717): the laptop-agent daemon HTTP API as a fleet subcommand (HTTP legs only; never ssh).",
capabilities: &[Capability::LaptopHttp],
primary: Capability::LaptopHttp,
aliases: &[],
subcommands: &["health", "jobs", "kill", "exec", "run", "poll", "fetch"],
},
Domain {
name: "ssh",
summary: "Tier T3 (ssh/fleet) of the laptop route forms (#13717): real SSH to the laptop under a binary-owned client contract (pinned host key, proxy CONNECT, fleet-owned multiplexing).",
capabilities: &[Capability::LaptopSsh],
primary: Capability::LaptopSsh,
aliases: &[],
subcommands: &["health", "exec", "close"],
},
Domain {
name: "laptop",
summary: "Tier T0 (tiered/fleet) of the laptop route forms (#13717): the generic tiered command - walks T1 -> T2 -> T3 and reports the serving tier; `fleet laptop tiers` prints the matrix.",
capabilities: &[Capability::Laptop],
primary: Capability::Laptop,
aliases: &[],
subcommands: &["tiers", "exec"],
},
];

/// Look a domain up by canonical name.
Expand Down
12 changes: 12 additions & 0 deletions pkgs/fleet/crates/fleet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ full = [
"dispatch",
"dispatch-test",
"laptop-agent",
"commander",
"http",
"ssh",
"laptop",
"secrets",
"gh",
"bridge",
Expand Down Expand Up @@ -134,6 +138,14 @@ gh = [
"dep:rusqlite",
]
laptop-agent = ["dep:fleet-secrets", "dep:fleet-laptop-agent"]
# The laptop route forms (developing-today/code#13717): T1 commander
# (an MCP client over ureq; the bearer comes from fleet-secrets), T2
# http (the daemon client, HTTP legs only), T3 ssh (no deps: the
# binary owns the ssh argv), T0 the tiered walker composing T1-T3.
commander = ["dep:fleet-secrets", "dep:ureq"]
http = ["dep:fleet-laptop-agent"]
ssh = []
laptop = ["commander", "http", "ssh"]
# Ask the local OpenCode server whether a worktree's recorded session
# is live before reusing it (session_state.rs). In full and serve;
# never in connect, where ureq+rustls would break the D7 2 MiB gate
Expand Down
Loading