The status tile labelled "uptime" showed the age of the daemon *process*
(`/info.uptimeMs`), and `/info` was fetched once with a 30 s staleTime and no
refetch interval, so the figure also froze: on a box five days up, a
`pi2 update` restart made the tile read "3m" and it never moved again.
`os.uptime()` is now sampled with the other host figures and served as
`system.hostUptimeSec` — which the 3 s `/resources` poll already refreshes —
plus an additive `/info.hostUptimeMs`. The tile renders it through a
`LiveUptime` label that anchors the reported snapshot once and ticks locally,
so the counter advances without a refetch and cannot rewind on a re-render.
The daemon's own process age stays in the server card, relabelled
`status.daemonUptime`, next to the `pid`/`daemonId` that give it meaning.
The status tile read `—` on a fresh machine: the sampler ran `statfs` on the
daemon's state dir, which is created lazily on the first instance log, so the
call failed with ENOENT and `diskUsedBytes`/`diskTotalBytes`/`diskPercent` all
came back null — `/info` then dropped `disk` altogether and the failure was
indistinguishable from a full disk.
`probeMount()` now walks up to the nearest existing ancestor and then to the
filesystem boundary (`st_dev` change), so a sample describes a volume, not a
directory. Candidates are pi2d's own write targets — `/` (the home volume on
macOS, where `/` is the sealed read-only system volume), the pi session store
and the visible workspace roots — never a mount-table dump: an unrelated or
hung network mount must not stall the sampler. Rows are deduped by `st_dev`,
sorted most-constrained first, capped at four, and reported as `system.disks[]`
with the legacy scalars aliasing the worst row. A sample that yields nothing
now carries `diskError` instead of silent nulls.
The status tile shows the worst filesystem and, when several are in play, one
quiet row per mount instead of a single percentage that hides the full volume.
The console's open dialog advertises `~/Workspace/...` and sends `name`, but the
daemon only accepted an absolute `cwd` and only read `alias`, so the most likely
first action failed with a generic `E_BAD_REQUEST` and the typed name vanished.
`add()` now expands `~`/`~/…` against the store's home before the absolute-path
check (a leading `~user` stays an error, and the message names both accepted
forms), and `workspace.add` treats `name` as an alias when `alias` is absent,
answering `workspaceId` so a client does not need a follow-up list call.
feat(cli): tell users when pi2.nvim cannot host a spawned instance
`checkPlugin` only looked for `lua/pi/web/bridge.lua`, so a checkout that can
drive an existing nvim but cannot be spawned reported `ok` and the failure
surfaced later as an unexplained "did not say hello".
The probe now also requires `lua/pi/host.lua`: both present is `ok`, bridge only
is `warn` with the update hint, neither is `fail`. `pi2 daemon --help` lists the
instance knobs (`PI2_NVIM_BIN`, `PI2_NVIM_INIT`, `PI2_PLUGIN_DIR`,
`PI2_ENSURE_TIMEOUT_MS`) it previously kept to itself.
MSG2
Workspaces page:
- list the newest sessions across workspaces in the activity column; the
daemon exposes GET /api/v1/sessions/recent as a disk projection and the
browser enriches live rows from the per-workspace session relay
- put recent activity first below 1100px and fix the mobile page-header
flex-basis gap
Smoke:
- pin PI2_HOST=127.0.0.1 in both smoke scripts and make the startup-line
assertion follow the configured host; the daemon default stays 0.0.0.0
Install:
- standalone binary build/install scripts, packaging templates, CI/release
hooks, CLI-first install docs and the supporting config/doctor changes
`GET /api/v1/models?workspaceId=` could only answer for a named workspace, and
naming one is enough to spawn its Neovim — fine for the chat picker, wrong for
the status page, which has no session to offer and would sit in
E_INSTANCE_STARTING forever.
The parameter is now optional. With one, the read is relayed exactly as before.
Without one, src/daemon/models.ts scans only instances that are already `ready`,
prefers the one with live sessions and the longest uptime, and relays
`workspace.query{kind:"models"}` to it, falling through to the next candidate on
failure. No instance is ever created.
The plugin's answer is lazy: the first call returns
`{providers:[], pending:true}` while its cache fills. The response therefore
carries `pending`, the `workspaceId` that answered (or null) and a
`pendingReason` of `fetching`, `no-instance` or `no-live-session`, so a client
can poll with a bound and explain itself instead of showing an empty list. The
workspaceId-scoped answer now also echoes `workspaceId` back.
The status page had no host figures: `/api/v1/info` only carried identity and
`/api/v1/resources` only carried instance RSS, so the CPU/mem/disk tiles fell
back to "—" and the memory tile faked its percentage from RSS over physical
memory.
src/core/sysinfo.ts is a zero-dependency sampler: CPU from the /proc/stat delta
(null on the first read, since it needs two samples), load average from
os.loadavg(), memory from os.freemem/os.totalmem, and disk via statfs on the
daemon's state dir. One sample is cached for ~1 s and shared between /info and
/resources, so polling both does not double the syscalls. /info gains additive
`cpu`, `mem`, `disk` percentages plus `cpuCores` and `loadAvg`; /resources gains
a `system` object with the byte counts, the disk path and `sampledAt`.
Every field is optional on the client side: an older daemon simply omits them.
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.
`PI2_ACCESS_MODE` (local|lan|tailscale) picks the bind address and the derived
CORS origins, `PI2_PUBLIC_URL` adds the external origin, and `PI2_ORIGINS` is now
additive instead of replacing the derived list. `daemon.json` and
`/api/v1/info` carry the mode and the public URL.
`POST /api/v1/console/session` is the `:PiWeb` handshake: loopback + the local
CLI token only, it mints or reuses the single "local browser" device and answers
`http://127.0.0.1:<port>/#t=<token>`. The token is stored plaintext next to
`devices.json` (0600) so repeated logins return the same credentials instead of
logging the already-open tab out; revoking the device drops it.
`pi2 daemon [start] [flags]` now starts the web-console daemon. The
`pi2d` executable, its bin entry and its entry module are removed: the
daemon keeps its lock -> token -> plugin socket -> listen -> daemon.json
lifecycle, its single stdout line (`pi2 daemon listening on ...`) and the
signal handling that leaves managed nvim instances running.
Service files are renamed to `pi2.service` / `com.pi2.daemon`, and the
smoke and e2e harnesses start the daemon through `pi2 daemon`.
BREAKING CHANGE: the `pi2d` command no longer exists; use `pi2 daemon`
(or `pi2 daemon start`). Existing systemd/launchd units installed under
the old names must be reinstalled with `pi2 install-service --write`.
- Preserve the snapshot entries tail in the cache and WS frames (cold,
cached and bus paths), so the browser receives {state, entries}.
- Await a plugin snapshot on the first subscribe of a fresh session.
- Return E_FORBIDDEN (403) for workspace paths outside PI2_WORKSPACE_ROOTS.
- Mint cli.token only after the singleton lock is held, so a second daemon
cannot invalidate the running one.
- Add hostname/os/version/uptimeMs/pid/port to /api/v1/info and make
/health reflect instance, workspace and auth state.