feat(daemon)!: phone-first binding and a two-step pairing flow
Implements ADR 0001 (docs/adr/0001-phone-first-pairing.md): the console is
meant to be opened from a phone, so reachability stops being a mode and the
pairing link becomes the only access control that matters.
Binding / CORS
- `PI2_HOST` defaults to `0.0.0.0`; `PI2_ACCESS_MODE` (local|lan|tailscale) is
deleted, together with its parser, `AccessMode` type and LAN probe.
- `src/core/network.ts` is the single source of truth for reachable addresses:
kind classification, ordering (public → lan → other → tailscale → loopback,
physical NICs first, link-local skipped), bind-aware `networkBases()`,
`primaryBase()` and `localOrigins()`. Config, the pairing route, doctor and
the CLI all consume it, so the CORS allowlist always matches the pairing URL.
- `/api/v1/info` and `daemon.json` report `host` instead of `access`; doctor's
`access` check becomes `bind` (loopback ok, wildcard warns unless an `https:`
public URL is configured).
Pairing
- `POST /api/v1/pair` only mints, requires a token, and returns the code, the
chosen URL, the expiry, the nonce, the QR matrix and every usable base.
`base` may pin one of those bases; anything else is a 400.
- `POST /api/v1/pair/redeem` is the public half, rate limited per client
(5/min) and globally (50/h) → 429 `E_RATE_LIMITED` with `retry-after`.
- `GET /pair/:code` answers 302 to `/connect?code=…&auto=1`, so a scanned link
needs no JavaScript to reach the console.
- `src/core/qr.ts` (moved out of the CLI) is the one encoder: byte mode, EC
level M, versions 1–10, rows without a quiet zone, shared by the HTTP mint
response and the terminal renderer.
- `pi2 pairing` prints a human report plus a half-block terminal QR and keeps
`--base`; `--json` and `--public-url` are gone (the Neovim client calls the
HTTP mint directly).
Device scopes
- `Scope`, `SCOPES`, `DEFAULT_SCOPES`, `DeviceRecord.scopes` and the `scopes`
field in device/hello payloads are removed: nothing enforced them, and a
paired device now holds the same rights as the local browser. A permission
model, if wanted, gets its own ADR.
Breaking: `PI2_ACCESS_MODE`, `info.access`, `pi2 status --json`'s `access`,
`pi2 pairing --json`/`--public-url`, `POST /api/v1/pair {code}`, and the
`scopes` field. All in-repo callers and the e2e drivers are updated; the plugin
side (`:PiWebAccess`, `env.PI2_ACCESS_MODE`, text-format parsing) follows in
pi2.nvim.
Verification: root typecheck clean; 369/370 tests (the one failure is the
pre-existing supervisor timing flake, 24/24 in isolation ×3); `smoke.sh` green;
web suite 299/299; visual matrix 24/24.
This commit is contained in:
1 parent
3789394c85
commit
a57c874095
34 files changed
+2157
-488
No files matched your search
@@ -0,0 +1,108 @@
|
||||
# ADR 0001 — Phone-first binding and zero-input pairing
|
||||
|
||||
- Status: accepted (implementing)
|
||||
- Date: 2026-10-26
|
||||
- Supersedes: `PI2_ACCESS_MODE` (`local` / `lan` / `tailscale`)
|
||||
|
||||
## Context
|
||||
|
||||
The console has to be usable from a phone: open the link, done. Two things blocked
|
||||
that:
|
||||
|
||||
1. **Reachability was an opt-in mode.** `PI2_ACCESS_MODE` picked the bind address
|
||||
(`local` → loopback), and CORS only allowed the single detected LAN address in
|
||||
`lan` mode. A phone that typed `http://192.168.2.10:7676` was refused by the
|
||||
origin check, and the default pairing URL was `http://127.0.0.1:7676/pair/…`,
|
||||
which is unscannable from another device.
|
||||
2. **Pairing was a form, not a link.** The QR on the status page was a *fake*
|
||||
pattern (`web/src/features/status/qr.ts` derived it from a seed), so scanning
|
||||
it did nothing. The redemption endpoint and the mint endpoint shared one path
|
||||
(`POST /api/v1/pair`), distinguished by whether `body.code` was present — the
|
||||
authorization rule was implied by a field, not by the route.
|
||||
|
||||
Access control is already carried by the device token that a pairing code mints.
|
||||
The bind address is not a security boundary we want to maintain.
|
||||
|
||||
## Decision
|
||||
|
||||
### 1. Bind every interface by default
|
||||
|
||||
- `PI2_HOST` defaults to `0.0.0.0`; setting it (e.g. `127.0.0.1`) narrows the bind.
|
||||
- CORS derives from the addresses the daemon is actually reachable on: loopback plus
|
||||
every non-internal IPv4 at the bound port, plus `PI2_PUBLIC_URL`'s origin, plus
|
||||
`PI2_ORIGINS`. `PI2_ACCESS_MODE` and its three modes are deleted outright (the
|
||||
repo is pre-1.0 and the plugin that set the env var ships from the same project).
|
||||
- `/api/v1/info` and `daemon.json` report `host` instead of `access`.
|
||||
|
||||
### 2. One network source of truth
|
||||
|
||||
`src/core/network.ts` owns address classification and ordering:
|
||||
|
||||
| kind | rule |
|
||||
|---|---|
|
||||
| `public` | the configured `PI2_PUBLIC_URL` (never a NIC) |
|
||||
| `lan` | private IPv4 (10/8, 172.16/12, 192.168/16) |
|
||||
| `other` | any other routed IPv4 |
|
||||
| `tailscale` | `tailscale*` interface or 100.64/10 address |
|
||||
| `loopback` | 127/8 |
|
||||
|
||||
Ordering: `public` → `lan` → `other` → `tailscale` → `loopback`, physical interface
|
||||
names before virtual ones (`docker*`, `veth*`, `br-*`, `virbr*`, `tun*`, `wg*`, …),
|
||||
link-local (169.254/16) never advertised. `networkBases()` respects `bindHost`:
|
||||
a loopback bind advertises only loopback, a specific address advertises that
|
||||
address plus loopback, `0.0.0.0`/`::` advertises everything reachable.
|
||||
|
||||
Config (CORS), the pairing route (URL + `bases[]`) and `pi2 doctor` all consume it.
|
||||
|
||||
### 3. Pairing is mint → link → redeem
|
||||
|
||||
```
|
||||
POST /api/v1/pair (authenticated) → {code,url,expiresAt,nonce,qr,bases[]}
|
||||
POST /api/v1/pair/redeem (public, rate limited) → {token,device}
|
||||
GET /pair/:code (public) → 302 /connect?code=…&auto=1
|
||||
```
|
||||
|
||||
- The mint picks the URL server-side (`base` may be supplied, but only a value
|
||||
present in `bases[]` is accepted) and returns the QR matrix, so no client
|
||||
re-derives either.
|
||||
- `qr` is byte-mode, EC level M, versions 1–10, `rows` without a quiet zone;
|
||||
renderers own margin and colours. One encoder in `src/core/qr.ts`.
|
||||
- Redeem is unauthenticated by design (the code *is* the capability) and now
|
||||
rate limited: 5 attempts/minute/IP and 50/hour globally, over the limit → 429.
|
||||
- Codes stay 8 characters from a 32-symbol alphabet, single use, 10 minutes.
|
||||
|
||||
### 4. Devices carry no scope list
|
||||
|
||||
Scopes were declared (`read`/`steer`/`control`/`admin`, plus a bogus `apply` in the
|
||||
web client) but never enforced anywhere — HTTP and WS only checked that the token
|
||||
was valid. Rather than invent an enforcement matrix, this ADR drops the concept:
|
||||
a paired device and the local browser hold the same rights as `local-cli`, and any
|
||||
fine-grained permission model is a separate feature with its own ADR.
|
||||
|
||||
Removed with it: `Scope`, `SCOPES`, `DEFAULT_SCOPES`, `DeviceRecord.scopes`,
|
||||
`CreateDeviceInput.scopes`, `web`'s `PAIR_SCOPES`/`DEFAULT_DEVICE_SCOPES`, and the
|
||||
`scopes` field in `/api/v1/devices` responses and the stored pair metadata.
|
||||
|
||||
### 5. Zero-input web flow
|
||||
|
||||
`/pair/<CODE>` (both the daemon's 302 and the SPA `/#/pair/CODE` route) lands on
|
||||
`/connect?code=<CODE>&auto=1`, which redeems against its own origin with the
|
||||
localized default device name and redirects to `next`/`/workspaces`. The code and
|
||||
`auto` flag are stripped from the URL afterwards. A rejected or expired code falls
|
||||
back to the manual form with host, port and code prefilled.
|
||||
|
||||
The in-console camera scanner (`web/src/features/connect/scan-dialog.tsx`) is
|
||||
deleted: phones scan with the system camera, desktops type the code.
|
||||
|
||||
## Consequences
|
||||
|
||||
- A daemon started without configuration is reachable from the LAN. `pi2 doctor`
|
||||
reports the bind, and warns (not fails) when a non-loopback bind has no `https:`
|
||||
public URL.
|
||||
- `pi2 pairing` prints a human-readable report and a terminal QR; it no longer
|
||||
emits `--json`. The Neovim client calls `POST /api/v1/pair` directly.
|
||||
- Breaking for anyone parsing `info.access`, `pi2 status --json`'s `access`,
|
||||
`pi2 pairing --json`, or `POST /api/v1/pair {code}`; all in-repo callers are
|
||||
updated in the same change.
|
||||
- `docs/protocol.md` no longer claims `E_FORBIDDEN` covers scopes; it covers
|
||||
origins and `PI2_WORKSPACE_ROOTS` only.
|
||||
+67
-30
@@ -111,8 +111,7 @@ Everything is environment-driven (`src/config.ts` + `src/core/paths.ts`):
|
||||
| Variable | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `PI2_PORT` | `7676` | HTTP/WS port, `0` = ephemeral |
|
||||
| `PI2_HOST` | `127.0.0.1` (`0.0.0.0` in `lan` mode) | bind address; wins over the mode default |
|
||||
| `PI2_ACCESS_MODE` | `local` | `local` / `lan` / `tailscale` (see below) |
|
||||
| `PI2_HOST` | `0.0.0.0` | bind address (all interfaces); set `127.0.0.1` for a loopback-only daemon |
|
||||
| `PI2_PUBLIC_URL` | – | external base URL, e.g. `https://myhost.tail1234.ts.net` (no trailing slash) |
|
||||
| `PI2_ORIGINS` | – | **extra** CORS/Origin allowlist entries (comma separated), added to the derived origins |
|
||||
| `PI2_STATIC_DIR` | `<repo>/web/dist` | built web UI |
|
||||
@@ -158,21 +157,35 @@ page lists `default` rows only behind a persisted “Show N hidden” toggle
|
||||
secondary rows dimmed with a reason badge; any workspace picker offers
|
||||
`default` rows only, while lookups by id ignore `visibility` entirely.
|
||||
|
||||
### Access modes
|
||||
### Binding and reachability
|
||||
|
||||
| `PI2_ACCESS_MODE` | bind (unless `PI2_HOST`) | derived `corsOrigins` |
|
||||
The daemon listens on **all interfaces** (`0.0.0.0`) by default: the console is meant to
|
||||
be opened from a phone as well as from the desktop, and it is the **pairing code** — not
|
||||
the bind address — that grants access (each device then holds its own revocable token).
|
||||
`PI2_HOST` narrows the bind:
|
||||
|
||||
| `PI2_HOST` | Reachable from | Use when |
|
||||
|---|---|---|
|
||||
| `local` (default) | `127.0.0.1` | `http://127.0.0.1:<port>`, `http://localhost:<port>`, `http://[::1]:<port>` |
|
||||
| `lan` | `0.0.0.0` | loopback three **plus** `http://<detected-lan-ip>:<port>` |
|
||||
| `tailscale` | `127.0.0.1` | loopback three **plus** the origin of `PI2_PUBLIC_URL` |
|
||||
| unset (default `0.0.0.0`) | this machine, the LAN, a tailnet | the normal homelab setup |
|
||||
| `127.0.0.1` | this machine only | you always put `tailscale serve` (or another proxy) in front, or you want the console strictly local |
|
||||
|
||||
Origins are normalized (trailing `/` stripped, empties dropped) and
|
||||
`PI2_ORIGINS` is appended — never a replacement. LAN detection is best effort:
|
||||
when the address is unknown that extra origin is simply skipped. `tailscale`
|
||||
assumes `tailscale serve` terminates TLS in front of the loopback daemon; the
|
||||
daemon never does TLS itself. An unknown mode fails startup with one line:
|
||||
`pi2: PI2_ACCESS_MODE must be local, lan or tailscale`. Changing the mode
|
||||
requires restarting `pi2 daemon`.
|
||||
`corsOrigins` are *derived*, not configured: loopback plus **every IPv4 address of this
|
||||
host** at the bound port, plus the origin of `PI2_PUBLIC_URL`, plus anything in
|
||||
`PI2_ORIGINS`. A browser that loaded the console from `http://192.168.11.7:7676` sends an
|
||||
`Origin` header that is not loopback, so the allowlist has to cover the address the user
|
||||
actually typed. Origins are normalized (trailing `/` stripped, empties dropped) and
|
||||
deduped; `PI2_ORIGINS` never replaces the derived list.
|
||||
|
||||
The daemon never terminates TLS. For a tailnet, point `PI2_PUBLIC_URL` at the
|
||||
`tailscale serve` URL (`https://host.tail1234.ts.net`): the origin is then allowed,
|
||||
`pi2 pairing` advertises that base, and `pi2 doctor` reports the bind as `ok` instead of
|
||||
warning about the missing TLS.
|
||||
|
||||
The pairing link follows the same preference (public URL → LAN address → loopback) and
|
||||
is chosen by the **daemon**, not the client: `POST /api/v1/pair` returns the URL together
|
||||
with the QR matrix and every base a browser could use, and accepts `base` to pin a
|
||||
different entry. `:PiWebPair` renders that list as the "pick the interface" menu; the
|
||||
reasoning is in [ADR 0001](adr/0001-phone-first-pairing.md).
|
||||
|
||||
## 5. Runtime files
|
||||
|
||||
@@ -182,7 +195,7 @@ All of these live in `PI2_RUNTIME_DIR` (created `0700`):
|
||||
|---|---|---|
|
||||
| `d.sock` | `0600` | plugin ↔ daemon JSONL socket (nvim dials it) |
|
||||
| `d.sock.token` | `0600` | handshake token for `hello`; rotated per daemon start |
|
||||
| `daemon.lock` | `0600` | singleton lock: `{pid, bootId, port, daemonId, startedAt, protocolVersion, access?, publicUrl?}` |
|
||||
| `daemon.lock` | `0600` | singleton lock: `{pid, bootId, port, daemonId, startedAt, protocolVersion, host?, publicUrl?}` |
|
||||
| `daemon.json` | `0600` | same payload, written **after** `listen()` so tools learn the real port |
|
||||
| `cli.token` | `0600` | 32-byte hex local admin token, rotated per daemon start |
|
||||
|
||||
@@ -216,7 +229,7 @@ Two token kinds:
|
||||
`PI2_DATA_DIR/devices.json`.
|
||||
2. **Local CLI token**: `PI2_RUNTIME_DIR/cli.token`, minted by `pi2 daemon` on
|
||||
each start. Any request carrying it authenticates as the synthetic device
|
||||
`{id:"local-cli", name:"local CLI", scopes:["read","steer","control","admin"]}`
|
||||
`{id:"local-cli", name:"local CLI", kind:"laptop"}`
|
||||
(constant-time compare, never persisted, not revocable, not listed by
|
||||
`GET /api/v1/devices`). Rotating the file invalidates the old value
|
||||
immediately.
|
||||
@@ -230,7 +243,7 @@ authenticated (auth runs before routing).
|
||||
|
||||
`pi2 open` calls this endpoint (loopback **and** local CLI token required) to
|
||||
sign the browser in without a pairing code: it rotates the single
|
||||
`local browser` device (`kind:"laptop"`, all four scopes) and answers
|
||||
`local browser` device (`kind:"laptop"`) and answers
|
||||
`{token, device, url}` with
|
||||
`url = http://127.0.0.1:<actual bound port>/#t=<token>`. The token lives in the
|
||||
fragment, so it never reaches a request line, a `Referer` header or a proxy
|
||||
@@ -303,7 +316,7 @@ object `{daemon, instances, resources, health}`.
|
||||
| `socket` | `d.sock` missing (and no daemon) | missing but daemon answers |
|
||||
| `daemon` | `/api/v1/info` unreachable | – |
|
||||
| `port` | – (reports bound/free) | – |
|
||||
| `access` | `lan`/`tailscale` with a non-loopback bind and no `PI2_PUBLIC_URL` | `lan`/`tailscale` (adds `— no TLS, prefer \`tailscale serve\`` without an `https:` public URL) |
|
||||
| `bind` | – | non-loopback bind without an `https:` `PI2_PUBLIC_URL` (`all interfaces/7676 — no TLS; pairing codes gate access, set PI2_HOST=127.0.0.1 to restrict`) |
|
||||
| `service-manager` | – | systemd/launchd not found |
|
||||
| `linger` (Linux) | – | `Linger=no` |
|
||||
| `web-dist` | – | missing |
|
||||
@@ -327,23 +340,47 @@ the command: if it is missing or fails, `pi2 open` prints the URL and still
|
||||
exits `0`. This is a local-only shortcut; use `pi2 pairing` for LAN/Tailscale
|
||||
browsers.
|
||||
|
||||
### 8.5 `pi2 pairing [--public-url <url>]`
|
||||
### 8.5 `pi2 pairing [--base <url>]`
|
||||
|
||||
`POST /api/v1/pair` with the local token and prints:
|
||||
`POST /api/v1/pair` with the local token, then prints a scannable report:
|
||||
|
||||
```
|
||||
url http://127.0.0.1:7676/pair/ABCD2345
|
||||
url http://192.168.2.10:7676/pair/ABCD2345
|
||||
code ABCD2345
|
||||
expires 2026-10-21T04:30:15.085Z (600s)
|
||||
qr {"v":1,"code":"ABCD2345","url":"…","expiresAt":…,"nonce":"…"}
|
||||
expires in 600s (2026-10-21T04:30:15.085Z)
|
||||
|
||||
▄▄▄▄▄▄▄ ▄▄ ▄▄▄▄▄▄▄
|
||||
█ ▄▄▄ █ ▀█▄▀█ ▄▄▄ █
|
||||
█ ███ █ ▄▀▄ █ ███ █
|
||||
…
|
||||
```
|
||||
|
||||
The URL is rebuilt from the *actual* daemon base URL because the daemon's own
|
||||
`url` field is derived from the configured port (stale after a retry or
|
||||
`--port 0`). `--public-url <url>` rebuilds both the printed `url` and the QR
|
||||
payload's `url` on that base (e.g. `https://host.ts.net/pair/ABCD2345`); it
|
||||
defaults to `daemon.json`'s `publicUrl`, then `PI2_PUBLIC_URL`. The code, expiry
|
||||
and nonce are unchanged.
|
||||
The daemon owns the URL, the QR matrix and the base list (see
|
||||
[ADR 0001](adr/0001-phone-first-pairing.md) §3); the CLI only renders them. The base is
|
||||
chosen for reachability, first non-empty wins:
|
||||
|
||||
| # | Base (`kind`) | When |
|
||||
|---|---|---|
|
||||
| 1 | `PI2_PUBLIC_URL` (`public`) | behind `tailscale serve` or another proxy |
|
||||
| 2 | primary LAN address (`lan`) | the default — the daemon binds `0.0.0.0` |
|
||||
| 3 | other routed / tailnet address (`other`, `tailscale`) | multi-homed hosts |
|
||||
| 4 | `http://127.0.0.1:<port>` (`loopback`) | `PI2_HOST=127.0.0.1`, or a host with no LAN address |
|
||||
|
||||
`--base <url>` pins a different address; the daemon validates it against the list it
|
||||
just returned and answers `400` for anything else, so a link can never point at an
|
||||
address nothing listens on.
|
||||
|
||||
`GET /pair/<code>` answers `302` to `/connect?code=<code>&auto=1`, which is what makes a
|
||||
scanned link zero-input: the console redeems the code against its own origin and lands on
|
||||
`/workspaces` without a form.
|
||||
|
||||
`qr` is byte mode, EC level M, versions 1–10, and lives in `src/core/qr.ts`; `rows` is the
|
||||
raw module matrix without a quiet zone (`size` strings of `size` `1`/`0` characters). The
|
||||
HTTP mint response carries the same matrix, so the console and a terminal draw the same
|
||||
symbol. A URL too long for version 10 is printed without a QR, with a note.
|
||||
|
||||
Machines call `POST /api/v1/pair` directly — that is what `:PiWebPair` does — so the CLI
|
||||
keeps only this human report; there is no `--json`.
|
||||
|
||||
### 8.6 `pi2 install-service` / `pi2 uninstall-service`
|
||||
|
||||
@@ -455,7 +492,7 @@ debugging.
|
||||
| `EADDRINUSE` on an explicit port | pick another `--port` (only the default port retries) |
|
||||
| `403` with the browser console | origin not in `PI2_ORIGINS` (derived from the port) |
|
||||
| `pi2 open` → `403 console login is loopback-only` | the request came from a non-loopback address; pair the device instead |
|
||||
| `pi2 doctor` → `access FAIL` | `PI2_ACCESS_MODE=lan/tailscale` binds a non-loopback address without `PI2_PUBLIC_URL`; set it or use `tailscale serve` |
|
||||
| `pi2 doctor` → `bind warn` | the daemon listens on a non-loopback address without TLS; that is the default posture — pair each device, or set `PI2_HOST=127.0.0.1` / `PI2_PUBLIC_URL=https://…` |
|
||||
| `health: static=FAIL` | `web/dist` missing — build the web UI or set `PI2_STATIC_DIR` |
|
||||
| Browser console loads but no workspaces | no nvim with the plugin has connected yet; run `pi2 attach` in a project |
|
||||
| `pi2 doctor` → `plugin FAIL` | install pi2.nvim, or point `PI2_PLUGIN_DIR` at the checkout |
|
||||
|
||||
+21
-11
@@ -139,7 +139,7 @@ The plan's original intent below is unchanged; the legend **P0**/**P1**/**P2** s
|
||||
- `GET /api/v1/health` → `ok=true`, `static` item ok (web/dist served).
|
||||
- `GET /` → 200 HTML containing the app root.
|
||||
- unauthenticated `GET /api/v1/workspaces` → 401 `E_UNAUTHORIZED`; bogus bearer → 401.
|
||||
- `POST /api/v1/pair` redeem: valid code → `{token, device}`; same code again → 401;
|
||||
- `POST /api/v1/pair/redeem`: valid code → `{token, device}`; same code again → 401;
|
||||
the token authorizes the API; `DELETE /api/v1/devices/:id` revokes it (next call 401).
|
||||
|
||||
**A1 Workspaces**
|
||||
@@ -222,7 +222,7 @@ The plan's original intent below is unchanged; the legend **P0**/**P1**/**P2** s
|
||||
|
||||
**A13 Console login handoff**
|
||||
- `POST /api/v1/console/session` with the CLI token → 200, one `local browser`/`laptop`
|
||||
device with every scope, and a `http://127.0.0.1:<port>/#t=<token>` URL (fragment only,
|
||||
device, and a `http://127.0.0.1:<port>/#t=<token>` URL (fragment only,
|
||||
never `?t=`).
|
||||
- the handed-off token authenticates; a second login returns the **same** token so a second
|
||||
`:PiWeb` does not log the open tab out.
|
||||
@@ -244,8 +244,8 @@ The plan's original intent below is unchanged; the legend **P0**/**P1**/**P2** s
|
||||
allow-listed `next`.
|
||||
|
||||
**B2 Pairing (manual)**
|
||||
- enter host/port/pairing code/device name → `POST /api/v1/pair` succeeds; the summary
|
||||
shows server/endpoint/device/scopes; localStorage keys are written; redirect to `next`.
|
||||
- enter host/port/pairing code/device name → `POST /api/v1/pair/redeem` succeeds; the summary
|
||||
shows server/endpoint/device; localStorage keys are written; redirect to `next`.
|
||||
- wrong code → inline localized error, still unpaired, form stays usable.
|
||||
- while paired, `/connect` shows the summary, not the form; disconnect asks for
|
||||
confirmation and clears the connection (returns to `/connect`).
|
||||
@@ -254,6 +254,12 @@ The plan's original intent below is unchanged; the legend **P0**/**P1**/**P2** s
|
||||
- paste a `pi2://pair?host=…&port=…&code=…` link in the scan fallback → confirmation
|
||||
modal shows the masked token → confirm pairs; cancel changes nothing.
|
||||
- the daemon's own `http://host:port/pair/<code>` URL is accepted by the parser.
|
||||
- opening that URL directly is **zero-input**: `/pair/<code>` redirects to
|
||||
`/connect?code=<code>&auto=1`, which redeems against its own origin with the
|
||||
localized default device name and lands on `/workspaces` (or `next`) without the
|
||||
form ever being shown; the device then appears on the status page.
|
||||
- a rejected/expired code falls back to the manual form with host, port and code
|
||||
prefilled from the link, plus the inline pairing error.
|
||||
|
||||
**B4 Workspaces**
|
||||
- seeded W1/W2 render as `[data-workspace-id]` rows, pinned/last-active order, context
|
||||
@@ -284,11 +290,14 @@ The plan's original intent below is unchanged; the legend **P0**/**P1**/**P2** s
|
||||
- change the thinking select to `low` → API command sent, state/toast update, value
|
||||
survives a reload; change the model select → the same, and the tree subtitle updates.
|
||||
|
||||
**B9 Chat: panels (Subagents / Todo / Tasks)**
|
||||
- panel tabs switch; each renders either real data or its empty state; no mock copy.
|
||||
- Dispatch modal creates a real batch (`items[]`), the subagent row/batch appears, and
|
||||
the preview modal opens (real tail or an explicit empty state); “Back to parent” works.
|
||||
- Tasks tab shows real tasks or the empty state; the task output modal shows the real
|
||||
**B9 Chat: session tray (Todo / Tasks) + subagent child view**
|
||||
- the stream-head chips (`计划` / `任务`) open the session tray; the two tabs switch and
|
||||
each renders either real data or its empty state; no mock copy; the right panel is gone
|
||||
(`.panel-pane` count is 0) and Esc returns focus to the chip.
|
||||
- the row `…` popover dispatches a subagent: a real batch (`items[]`) appears, the row
|
||||
shows the child in the tree, and the in-place child view renders the synthesized
|
||||
timeline (`sub-timeline`) or an explicit empty state; `← 父级` / Esc works.
|
||||
- the Tasks tab shows real tasks or the empty state; the task output modal shows the real
|
||||
output tail or an explicit unsupported state (no fake pid).
|
||||
|
||||
**B10 Attention**
|
||||
@@ -296,8 +305,9 @@ The plan's original intent below is unchanged; the legend **P0**/**P1**/**P2** s
|
||||
title/options; Accept writes the file; the dialog closes; a second client cannot answer.
|
||||
|
||||
**B11 Status**
|
||||
- `/status` renders info/health/resources/models/tasks/devices/connection cards from the
|
||||
API; no server/workspace selector; resources refresh; health items show pass/fail.
|
||||
- `/status` renders the four metric tiles + info/health/models/tasks/devices/connection
|
||||
cards from the API; no server/workspace selector; metrics refresh; health items show
|
||||
pass/fail. The page has zero primary actions.
|
||||
- paired devices come from the API and can be revoked with confirmation; a revoked
|
||||
device token stops working.
|
||||
- disconnect clears connection and returns to `/connect`.
|
||||
|
||||
+6
-2
@@ -85,7 +85,10 @@ Plugin obligations:
|
||||
| `GET /api/v1/workspaces/:id/sessions` | relayed `workspace.query{kind:"sessions"}` (row fields below) |
|
||||
| `GET /api/v1/sessions/:sid/entries?before=&limit=` | relayed; plugin paginates |
|
||||
| `GET /api/v1/attention?workspaceId=` | pending attention for one workspace |
|
||||
| `GET /api/v1/devices` | paired devices (daemon-owned) |
|
||||
| `GET /api/v1/devices` | paired devices (daemon-owned; `{id, name, kind, createdAt, lastSeenAt, revokedAt}`) |
|
||||
| `POST /api/v1/pair` | **authenticated**; mints `{code, url, expiresAt, nonce, qr, bases}` |
|
||||
| `POST /api/v1/pair/redeem` | public + rate limited (`E_RATE_LIMITED`); `{code, kind, deviceName}` → `{token, device}` |
|
||||
| `GET /pair/:code` | public; `302 /connect?code=<code>&auto=1` (scanned links) |
|
||||
| `GET /api/v1/models?workspaceId=` | relayed to the instance |
|
||||
| `GET /api/v1/resources` | instances, sessions, RSS totals for the soft-limit notice |
|
||||
| `GET /api/v1/diagnostics` | connections, event rates, slow queries, instance table |
|
||||
@@ -276,7 +279,8 @@ browser cmd(sessionId=s1)
|
||||
|---|---|---|
|
||||
| `E_BAD_REQUEST` | 400 | malformed JSON / missing field |
|
||||
| `E_UNAUTHORIZED` | 401 | missing/invalid device token |
|
||||
| `E_FORBIDDEN` | 403 | bad `Origin`, insufficient scope, cwd outside `PI2_WORKSPACE_ROOTS` |
|
||||
| `E_FORBIDDEN` | 403 | bad `Origin`, cwd outside `PI2_WORKSPACE_ROOTS` |
|
||||
| `E_RATE_LIMITED` | 429 | too many pairing attempts (per client and globally) |
|
||||
| `E_NOT_FOUND` | 404 | unknown workspace/session/instance |
|
||||
| `E_PROTOCOL_VERSION` | 426 | `v` unsupported |
|
||||
| `E_PAYLOAD_TOO_LARGE` | 413 | body/frame > limits |
|
||||
|
||||
Reference in new issue
Block a user