Commit Graph
91 Commits
Author SHA1 Message Date
yuez 01fd7b9922 fix(daemon): sample disk usage on the filesystems pi2d uses
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.
2026-10-30 16:17:43 +08:00
yuez 1d907c08fa fix(web): merge history and live entries in transcript order
Opening a long session from the recent-activity list showed the transcript
ending at an old `edit` tool call. The plugin's snapshot carries the whole
transcript (`state.entries`), while the first REST page holds only the newest
entries; mergeEntries appended every unmatched live entry after the page, so
the older messages landed past the newest ones and scrolling to the bottom
stopped on a message from the middle of the session.

Unmatched live entries are now inserted where their live neighbours put them —
before the history entry of the next match — and appended only when they follow
every match, so both windows stay one chronologically ordered, deduped stream.
The regression test covers a live window that starts before the history page.
2026-10-30 15:15:14 +08:00
yuez 17fcf931c0 feat(workspaces): title recent-activity rows from a bounded preview
The activity column's disk-only rows had no title: the recent feed carried file
metadata only, so every session outside a live instance rendered "(unnamed)".

recentSessions() now projects a display title for the rows it returns — the
latest `session_info` name and the first user message — from a 128 KiB head +
32 KiB tail of each session file, cached by (mtime, size). Entries are never
parsed into session state: the read is bounded, opt-in, and only paid for the
≤limit rows the caller renders, so the daemon stays a router.

The web client keeps the disk title as a fallback under the live state, and the
B4 e2e scenario asserts session-first rows with their links and titles.
2026-10-30 15:15:09 +08:00
yuez 086cac8c8e docs(adr): put install and update ownership in pi2d (ADR 0004)
Two owners for one artifact broke exactly as expected: on a machine with the
standalone pi2, the plugin's npm copy sat on a lower rung of the resolution
ladder, so `:PiWebUpdate` upgraded a copy nobody ran and reported success while
the daemon kept the old version.

ADR 0004 records the fix. The standalone artifact is the one self-updating
channel (`install.sh` + `pi2 update`, built on ADR 0003's receipt); npm, Homebrew
and the AUR stay as distributions whose upgrades belong to their package
manager — `pi2 update` refuses them with the right command, the uv model. The
plugin becomes a pure client: resolve, delegate, print.

docs/install.md and README.md are reordered to match: the standalone installer is
the recommended path, the package managers are alternatives that upgrade
themselves. ADR 0002 §2.1 keeps its survey but is marked amended where it had
left `:PiWebInstall` as a plugin-side npm installer.
2026-10-30 09:55:08 +08:00
yuez 2240289426 feat(cli): add pi2 uninstall for cross-channel state cleanup
`install.sh --uninstall`, `brew uninstall`, `npm rm -g` and
`pi2 uninstall-service` each own one slice; none of them removed the
runtime directory, and deleting the binary left a running daemon behind.

`pi2 uninstall` now owns the state for every channel: disable and remove
the unit, stop the daemon, delete the runtime dir, and — with `--purge` /
`--purge-config` — the data, state and env file. On the curl channel
`--purge` also deletes the install tree, last, because the running binary
lives inside it; npm/brew/AUR trees stay with their package manager, and
the command to remove them is printed instead.

Destructive by design: the plan is always printed, `--yes` (or an
interactive `y`) is required, non-TTY runs refuse without it, and
everything a reinstall would silently lose is an explicit opt-in. The
next-steps footer names what no CLI can clean: the browser's site data and
the plugin-private copy from `:PiWebInstall`.

Docs: rewrite the install.md uninstall section around the two layers
(state vs. binaries) with a table of every path, point deployment.md at
the new command, and update the README.
2026-10-30 09:40:05 +08:00
yuez c2d1f1d960 chore: release 0.1.7 v0.1.7 2026-10-29 16:54:54 +08:00
yuez 8fb535f7f3 feat(cli): add pi2 update with a versioned install layout
The standalone (curl installer) channel had no upgrade path of its own: the
documented one was 're-run the installer', which the Neovim plugin cannot do
safely and which re-downloads 35 MB without version arithmetic, provenance or
rollback. ADR 0003 records the design; this is the implementation.

- install.sh now installs one immutable tree per version
  (`<prefix>/versions/<v>/{bin,share,LICENSE}`) behind a single atomically
  swapped `current` symlink, writes `<prefix>/install.json` as the install
  receipt, and migrates a pre-0.1.7 flat layout in place. Keeping `current` plus
  one previous tree gives a one-step rollback for free.
- `pi2 update` (native TypeScript, no `curl | sh` subprocess) resolves the
  release with an ETag-cached GitHub lookup, picks the asset from the
  build-time `PI2_BUILD_TARGET` define instead of re-probing libc, verifies
  SHA256SUMS, verifies SLSA provenance with `gh attestation verify`, runs the
  new binary once, then swaps `current` and rewrites the receipt. Flags:
  --check/--dry-run/--version/--force/--json/--require-attestation/
  --skip-attestation. Downgrades need --force; restarts stay manual.
- the receipt is the only channel detection: npm, Homebrew and the AUR are
  refused with the command that owns their tree, and a flat install is told to
  re-run the installer once. No heuristics on `process.execPath`.
- `pi2 install-service` renders `<prefix>/current/bin/pi2`, so an update no
  longer invalidates the unit.
- `scripts/build-binary.sh` injects `PI2_BUILD_TARGET`; `tarball.ts` is a
  dependency-free ustar/PAX reader with traversal and symlink rejection.

Verified against the real release: install.sh into a scratch prefix, update
--check/--dry-run, a local 0.1.7 mirror upgrade (attestation warn path), then
`pi2 update --version 0.1.6 --force` (real download, real attestation
verified), plus boot-check and the refusal paths. typecheck + 567 daemon tests
+ web typecheck + 537 web tests + smoke are green.
2026-10-29 16:42:57 +08:00
yuez 29aee26733 ci(release): unstick the asset pipeline and add SLSA attestations
- darwin-x64/darwin-arm64 move to macos-15-intel/macos-15: `macos-13` is
  retired, which left the v0.1.6 `darwin-x64` leg queued for 21h+ so
  `checksums` never ran and no tarballs or SHA256SUMS were attached.
- assert the exact six platform assets instead of a literal line count, which
  passed while a dropped leg was silently missing.
- `workflow_dispatch` with a `tag` input rebuilds assets for an existing
  release without touching npm, Homebrew or the AUR (publish/packaging stay on
  the tag-push path); `TAG` replaces `github.ref_name` throughout.
- `actions/attest-build-provenance` over the tarballs, so `pi2 update` can
  verify provenance with `gh attestation verify` rather than trusting a
  checksum shipped in the same release.
2026-10-29 15:28:15 +08:00
yuez d529b4cda7 docs(protocol): document the plugin bye record
§2 now shows the frame (`{"v":1,"type":"bye","payload":{"reason":"stopped"}}`)
and states the obligation: a plugin that stops on purpose writes one `bye` before
closing a live socket, so the daemon records `plugin said bye` instead of a
generic `socket closed` — which is what `src/instances/connection.ts` already does.
2026-10-29 14:32:47 +08:00
yuez 7130c69523 docs: document pi2 pairing --json
§8.5 said the CLI keeps only the human report; it now also emits the normalised
mint payload that :PiWebPair renders.
2026-10-29 14:11:10 +08:00
yuez 8a39e65def feat(cli): add --json to pi2 pairing
The Neovim plugin needs the mint payload (URL, code, expiry, QR matrix, every
advertised base) to draw a scannable code, but the CLI only printed a human
report — so `:PiWebPair` spoke HTTP itself, duplicating the CLI token handling
and requiring `curl` in the editor.

`pi2 pairing --json` prints the normalised payload instead:

  { url, code, expiresAt?, qr: { version, ecc, mask, size, rows }, bases[] }

Same fields the human report renders, so the terminal QR and the float always
agree, and `--base` still pins the link.
2026-10-29 14:11:10 +08:00
yuez f854ba8d4f docs: document pi2 service and the CLI-owned service control
- README/install: the plugin attaches → `pi2 service start` → spawn ladder,
  `:PiWebStop` detaches only the bridge, `:PiWebService`/`:PiWebLog` exist.
- deployment §8.6/§9: the new subcommand, its exit-code contract and the
  one-command `pi2 service enable` after `install-service --write`.
- ADR 0002: service-manager commands belong to the CLI (`pi2 service …`), the
  plugin's ladder gains $PI2_DAEMON_BIN, `:PiWebStop` never signals a
  service-managed daemon, and `:PiWebInstall` installs `@yuez/pi2d@latest`
  (optionally pinned by a <version> argument) after confirmation.
2026-10-29 14:00:48 +08:00
yuez 4eda2b9420 feat(cli): add pi2 service status|start|stop|enable|disable
`install-service` only renders the unit file; nothing in the CLI talked to
systemd/launchd. The editor plugin had no supported way to start a
service-managed daemon (it would have had to shell out to `systemctl` itself),
so add the explicit control surface ADR 0002 §2.2 assumes:

  pi2 service status [--json]   manager, unit path, installed/enabled/active, linger
  pi2 service start|stop        systemctl --user start|stop / launchctl kickstart|kill
  pi2 service enable|disable    systemctl --user enable|disable --now / launchctl bootstrap|bootout

`status` never fails: no manager, no unit and a dead service are reports, and
`--json` carries the same shape the plugin decodes. The four mutating actions
exit 1 with the manager's first stderr line, and refuse to run when the unit
file is missing. Every probe is injectable (exec/exists/platform/paths/uid/user)
so the tests never touch a real service manager.
2026-10-29 14:00:41 +08:00
yuez e775b09037 docs: opening a project from the console needs no :PiWebStart
`workspace.add`/`instance.ensure` now spawn a host-capable headless nvim on
demand, so the documented flow is the browser, not the editor.

protocol.md gains the missing normative bodies for the three daemon-owned writes
(including `~` expansion, `name`-as-`alias`, and the ordered error codes), states
that `hello` requires `lua/pi/host.lua`, and records that any relayed read
implicitly ensures. deployment.md documents `PI2_NVIM_INIT`, `PI2_PLUGIN_DIR`,
`PI2_NVIM_BIN` and `PI2_ENSURE_TIMEOUT_MS`, where spawn output goes, and a
symptom-ordered "opening a project fails" section. README says it out loud.
v0.1.6
2026-10-28 17:32:53 +08:00
yuez d5d205a7eb feat(web): explain a failed open, keep the dialog, and follow instance_state
Opening a project showed a toast on success and a bare code (`E_FORBIDDEN`) on
failure: no reason, no retry, and a workspace card that kept claiming "Instance
stopped" because `instance_state` frames were dropped by the socket layer.

- The dialog validates a non-absolute path inline, sends `alias` (the field the
  daemon persists), maps the daemon's status/code/message to a specific sentence
  (`~` expansions, missing directory, roots allowlist, permissions), and keeps
  itself open on a spawn failure with the daemon's reason plus a retry that
  re-sends only `instance.ensure`.
- `lib/ws` handles `instance_state` by invalidating `workspaces`/`health`
  (coalesced at 250 ms across sockets) so the grid reflects reality.
- A never-started workspace renders as "not started · opens on demand" instead
  of "stopped", and a degraded/stopped instance shows `instance.reason`.
2026-10-28 17:32:53 +08:00
yuez b95ff6055b 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.
2026-10-28 17:32:41 +08:00
yuez 85faacb0ba feat(workspaces): accept ~ paths and name as alias in workspace.add
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
2026-10-28 17:32:23 +08:00
yuez db387ae248 feat(instances): spawn a host-capable nvim without the user's config
Opening a project from the console needed `:PiWebStart` first because the
managed spawn loaded the *user's* nvim config and ran with `stdio:"ignore"`.
When that config did not resolve pi2.nvim (lazy.nvim, a dev worktree behind
`PI_DEV_DIR`, a service with a frozen PATH) or the checkout lacked
`lua/pi/host.lua`, nvim stayed alive and silent and `instance.ensure` could only
report a bare 5 s timeout: nothing to read, nothing to fix.

- `core/plugin`: discover the plugin (`PI2_PLUGIN_DIR`, lazy.nvim,
  `site/pack/*/{start,opt}`, system dirs) and require both `lua/pi/host.lua` and
  `lua/pi/web/bridge.lua`; name a misconfigured `PI2_PLUGIN_DIR` first.
- `instances/host-init`: generate a minimal init (prepend the plugin, prepend
  nothing else, `cquit 1` when `pi.host` is missing) so a spawn fails with a real
  exit code instead of silence. `PI2_NVIM_INIT` keeps `user` (the old
  behaviour) and any explicit path.
- supervisor: refuse to spawn when no host-capable plugin exists, route the
  child's stdout/stderr into `instances/<id>.log`, and fold the log tail into
  `instance_state.reason` and the thrown error. `PI2_ENSURE_TIMEOUT_MS`
  (default 10000) replaces the fixed 5 s.
- `core/paths`: one shared `expandTilde` for the plugin probe, the workspace
  allowlist and `pi2 doctor`.
2026-10-28 17:32:16 +08:00
yuez c933eb39ad fix(ci): boot-check musl artifacts on Alpine, not the glibc runner 2026-10-28 16:36:34 +08:00
yuez 118f24e1ba docs: drop the self-hosted pacman channel; install and update via the curl installer 2026-10-28 16:30:25 +08:00
yuez 605280d8dc chore: bump version to 0.1.6 2026-10-28 16:30:25 +08:00
yuez cbe73b9aa4 fix(ci): gate secret steps on env, not the secrets context (invalid in if:) 2026-10-28 14:16:07 +08:00
yuez a50bb6e8e3 ci: add verify-secrets workflow for the Homebrew tap token and AUR key 2026-10-28 14:14:32 +08:00
yuez d2e20d428a feat: session-first workspace activity and installable daemon
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
2026-10-28 10:53:48 +08:00
yuez fc51c3be37 chore: release 0.1.5 v0.1.5 2026-10-28 08:16:14 +08:00
yuez 7f9ce543d2 feat(web): parse and apply pushed workspace_update frames
The workspace list only changes when a query refetches — a new workspace, a name
change or a session count from another browser waits for a poll, and the socket
carries the same information unused.

`parseWorkspaceUpdate` narrows a `workspace_update` frame defensively (hostile
or half-filled payloads return null rather than throwing), and
`applyWorkspaceUpdate` merges one row into the `["workspaces"]` and
`["chat-workspaces"]` caches, upserts the zustand store and invalidates
`["health"]` so the status page re-reads instance state.

Not wired yet: `src/instances/connection.ts` still drops `workspace_update` on
the floor, so the daemon never relays it to a browser and the module has no
caller. This lands the validated reducer and its tests so the daemon-side relay
has something to plug into; the queries.ts fallback (poll only while the socket
is down) covers the gap meanwhile.
2026-10-28 08:14:44 +08:00
yuez c08e0c7e94 fix(web): keep touch text controls at 16px so mobile Safari stops zooming
Every text control in the console was deliberately smaller than 16px — `input`,
`select` and `textarea` inherit `--fs-body` (14px), `.composer__ta` is 15px — and
on iOS focusing one of those makes Mobile Safari zoom the visual viewport in,
which it does not undo when the keyboard closes. The page stays scaled for the
rest of the session.

app.css now puts the floor in one place: a `@media (hover: none), (max-width:
599px)` rule pins `input/select/textarea/[contenteditable]` at 16px. `hover:
none` covers landscape phones that are wider than 600px, and `!important` is
required because a bare element selector loses to the single-class utilities
that style those controls. `html { text-size-adjust: 100% }` stops the same
kind of resizing on rotation. Desktop (a real pointer) is untouched.

The UI shot harness counts the smallest visible text control per page and fails
a shot under 600px if it is under 16px, so the regression cannot come back
silently; docs/ui-parity.md records the check and why the rule lives in app.css.
2026-10-28 08:14:34 +08:00
yuez 2c44a19d57 docs: rewrite the session dot contract around DotView.blink
The old page documented the matrices but not the rule that kept breaking them:
blinking looked like a property of the colour, so a dim rule scoped to a
component was a valid reading of it. It now says outright that the rate is part
of the view — `{status, blink?, current?}` — that omitting `blink` means solid,
that `dot--steady` is gone, and that CSS may only decide when the shared clock
dims a blinking dot.

Adds what the code now covers and the page was missing: the task matrix
(`:PiTasks` parity, only `running` blinks), the head dot rendering the selected
row's `DotView` so one session cannot show two rates, a viewed failure being
solid, and a manifest-only `active` subagent being amber but steady because
nothing would ever acknowledge its blink.
2026-10-28 08:14:29 +08:00
yuez e7ce064817 fix(web): let the view decide the blink, not the CSS colour class
A dot's animation was keyed on its colour class plus a component wrapper:
`html[data-pi-blink-fast="dim"] .tree-row .dot--ok` made green blink only inside
the session tree, `.dot--busy`/`.dot--err` blazed everywhere they appeared, and
`dot--steady` existed only to subtract what that selector had just added. Two
consequences the matrix in docs/session-dot.md already forbids: a failed task's
red blinked forever with no gesture to acknowledge it, and the same session
could blink in the list and sit solid in the stream head.

`DotView` now carries the rate (`blink: "fast" | "slow"`, omitted = solid) next
to the colour, and `<StatusDot>` renders it as `dot--blink-fast` /
`dot--blink-slow`. `dot--steady` is gone — to make a dot solid you omit `blink`.
app.css keeps exactly two dim rules, with no colour or component scoping and no
knowledge of *whether* anything blinks, only of when the shared clock dims it.

Filling in the matrix this exposed: parent `err`/`ok`/`busy` blink fast and
`compacting` slow; a viewed child or subagent failure is solid while an unviewed
one blinks; `interrupted` is the same solid dead red as `exited` (the plugin has
no interrupted, and in the plugin `exited` outranks its own unread flags —
`sessionDot(active)` is now rendered `viewed: true` for the stream head, so one
session can never show two different rates); task dots follow `:PiTasks`
(`taskDotView`, shared by the tray and the output modal) where only `running`
blinks, `completed` is solid green and `stopped` is amber attention. The
`/status` task card renders the same colours, solid, since nothing there
acknowledges anything.
2026-10-28 08:14:25 +08:00
yuez 604fec5ea0 feat(web): read host stats and the bare models endpoint on the status page
The metrics tiles now prefer the daemon's own sample (`resources.system`, then
`info.cpu/mem/disk`) over the old RSS-over-physical-memory guess, and each tile
gained the detail that makes the number actionable: cores and 1-minute load,
used/total bytes, the filesystem the disk figure describes.

The models card stops asking for a workspace it does not have. It calls the bare
endpoint (no spawn), polls every 1.5 s while the plugin's cache is still filling
(bounded to 12 rounds), and tells the three empty states apart instead of showing
one generic "no models": still fetching, no live instance, no live session. With
no workspace to key on, `fetchModels` also tolerates a legacy daemon that
requires the parameter, retrying with the first visible workspace.

Smaller fixes that fell out of the same read: `formatBytes` printed "4.00 GiB"
for a whole number of GiB, and the workspaces query now polls every 5 s only
while the socket is down, so a dropped connection still refreshes the page.
2026-10-28 08:14:17 +08:00
yuez b577e15f6d docs(protocol): document the host stats and the bare models endpoint
Additive only, and written as such: `/info`'s `cpu`/`mem`/`disk`/`cpuCores`/
`loadAvg` and `/resources`' `system` object are absent on daemons older than
0.1.5, so clients must tolerate their absence. Records what each figure means
(host, not instance; `totalRssBytes` stays the soft-limit input), that the disk
sample describes the state dir, and that `cpuPercent` is null on the first read
because it is a delta.

The models section spells out the fork in the endpoint: `workspaceId` present
relays and may spawn; absent scans ready instances only, never spawns, and
answers `pending` + `pendingReason`. It also records the plugin-side contract
underneath — a lazy first answer and a session that can stay pending
indefinitely — because that is what makes client polling a requirement rather
than an optimisation.
2026-10-28 08:14:11 +08:00
yuez 22de7dcc9c feat(daemon): resolve /api/v1/models without spawning an instance
`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.
2026-10-28 08:14:05 +08:00
yuez 88354ec078 feat(daemon): sample host cpu, memory and disk for /info and /resources
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.
2026-10-28 08:13:58 +08:00
yuez 1664227c3b chore: release 0.1.4 v0.1.4 2026-10-27 19:21:49 +08:00
yuez dcbda60165 docs: write down the session dot contract
The dot is a view of the plugin, and it drifted once already because the rule
lived only in code. docs/session-dot.md now records the parent/sub-session/
subagent matrices, the current marker, the unread-flag lifetime and the single
blink clock, with the pi2.nvim functions each rule mirrors.
2026-10-27 19:18:07 +08:00
yuez 668f77bf51 fix(web): a dead process outranks its own unread flags
Review caught two holes in the previous commit.

interrupted was ranked below error/attention/done, so an interrupted session
with a stale error flag still blinked red, one with pending attention still
wore the amber dot, and one with a done flag still turned green. In the
plugin there is no interrupted at all: any non-running row is exited
(sessions.lua:75-78) and exited sits at the top of dot_hl. interrupted now
shares that slot.

The subagent tables were not actually consolidated: subagent-view.tsx and
telemetry.tsx each kept their own SUB_DOT, still painting interrupted amber
and completed green. All three now go through subagentDot(); in a subagent
view the row is the one you have open, so a failed child is steady red there.
2026-10-27 19:13:35 +08:00
yuez b6335a21a4 docs(protocol): document the session list ordering contract
Sessions rows now document `tabRank`, the console's ranking rule, which
parts are console-side determinism rather than :PiSessions behaviour, and
the remaining gaps (history parent retained, manifest existence not
consulted, child ownership without conversation_epoch).
2026-10-27 19:08:47 +08:00
yuez 2712c6c76c test(web): pin the :PiSessions session ordering
Covers root ranking by tab/tabRank (including a child-view parent inheriting
its viewing child's tab and a lineage taking its earliest slot), the root
tie-break chain, sibling order by createdAt desc + id asc, the manifest
entry winning the sort key over the row, cycle/duplicate/self-parent safety
and determinism under input shuffles.
2026-10-27 19:08:47 +08:00
yuez 37941aea19 feat(web): order the chat session list like :PiSessions
The sidebar rendered whatever order the plugin payload happened to carry
(disk mtime desc, then Lua hash order). It now mirrors pi2.nvim:

- roots ranked by the tab's visual position (`tabRank`, falling back to the
  `tab` handle), a lineage occupying the earliest tab it occupies;
- siblings (real sub-session rows and manifest subagents merged into one list)
  by `createdAt` desc with the id as tie-break, a session row inheriting its
  manifest entry's `createdAt`, matching `manifest.lua`;
- deterministic code-unit comparisons plus a root tie-break chain, so WS
  arrivals and payload order can no longer shuffle rows.

`session-order.ts` is the single owner of the rule; the tree model renders it
and the /chat index default is the sidebar's top root.
2026-10-27 19:08:47 +08:00
yuez 92f844d694 feat(protocol): carry tab, tabRank, createdAt and lastActiveAt on SessionState
List metadata the web console needs to order the chat session list like
pi2.nvim's :PiSessions: the tab handle, its 1-based visual tabline position,
and the creation/last-activity timestamps. Never emitted by the reducer; the
web normalizer and the sessions store preserve them across snapshot and live
event updates.
2026-10-27 19:08:47 +08:00
yuez c4d0057b0b test(web): pin the dot matrix, the shared blink clock and markSeen
sessionDot had no test at all, which is how its priority order drifted away
from the plugin. session-dot.test.ts locks the whole matrix: the parent
order (exited > error > attention > done > busy > compacting > idle), every
collision that used to be wrong, the viewed -> current overlay, the separate
child matrix (steady red while viewed, never green, never attention) and the
subagent table.

blink.test.ts covers the one shared clock: phase lockstep, ref counting
(two subscribers, one interval), idempotent unsubscribe, and
prefers-reduced-motion pinning the dots solid.

chat.tree.test.tsx grows up from "a .dot exists" to the actual classes;
sessions-store.test.ts covers markSeen; components.test.tsx covers the dead
status and the steady/current modifiers.

Also makes the current-tab overlay a positive check (idle | busy |
compacting), matching the plugin markable list: a session that has not
reported a status yet ("starting") no longer claims the blue marker.
2026-10-27 19:00:26 +08:00
yuez bf01fd549d fix(web): rebuild the session dot matrix from pi2.nvim
The Chat session list dot did not follow the plugin it mirrors
(:PiSessions in pi2.nvim, lua/pi/ui/sessions.lua). Four things were wrong:

- priority: attention outranked error and exited; the plugin order is
  exited > error > attention > done > busy > compacting > idle.
- interrupted wore the attention amber, the same colour as "waiting for you";
  it is a dead process, so it takes the solid exited red (dot--dead).
- exited and dormant were collapsed into the hollow grey ring; a dead parent
  is the solid red one, the hollow ring is the dormant sub-session.
- sub-sessions reused the parent matrix. They now follow child_dot_hl: a
  failed child is steady red while you are looking at it and blinking red
  while you are not, busy/compacting blink at the busy rate, and a child
  never shows green (the plugin forces done=false there).

The current-tab marker (PiSessionsListCurrent) was missing entirely: the row
the console has open now carries dot--current, steady on idle and blinking
on busy, and never on top of a notification colour - same guard as
refresh_current_markers. It is the browser analogue of the focused nvim tab,
so no wire change is needed.

Also drops the unreachable sessionDotClass() dead code, whose second mapping
was the reason the divergence went unnoticed, and consolidates the three
subagent dot tables into subagentDot().

Unread notifications now expire like the plugin's: done/error are unread
markers, not states (on_agent_end only raises done for a tab that is not
current, clear_flags wipes both on TabEnter). The store gained markSeen(),
called when the routed session carries done/error, so a session you open
stops being green or red. The canonical reducer and fixtures/ are untouched:
this is a client-side view concern.
2026-10-27 18:43:13 +08:00
yuez 81e7f96a64 feat(web): drive every status dot from one shared blink clock
Each dot used its own CSS animation ("pulse" in app.css, "tree-dot-blink" in
chat.css), so dots drifted out of phase and the tree looked noisy. One
ref-counted 500ms clock in lib/blink.ts now writes data-pi-blink-fast and
data-pi-blink-slow on <html>, and CSS derives the dim phase from those
attributes: one timer for the whole app, no React re-renders, and
prefers-reduced-motion pins every dot solid.
2026-10-27 18:42:54 +08:00
yuez 48411dccd2 feat(cli): add stop command to shut down running daemon 2026-10-27 18:37:21 +08:00
yuez 2b8171cc37 test(web): lock the server chip's status and version fallbacks
Assert the chip renders `dot--idle` / Unknown for the initial `unknown` store
value, and that a bogus `status` carried by a `server` override can no longer
override the store's `online` verdict.
2026-10-27 18:07:16 +08:00
yuez 611c405439 fix(web): read the live server status in the page sheet
The navigation sheet took its status from `server.status` on the cached /info
payload, which stays `"online"` (or `"offline"` once stored) regardless of the
live probe, and rendered an empty version when `pluginVersion` was "". Use the
connection store's `serverStatus` and fall back through `version` with `||`, and
cover both the localized status fact and the empty-`pluginVersion` path.
2026-10-27 18:07:16 +08:00
yuez ec80ee4bab fix(web): stop doubling the dot modifier on the status page head
`serverDotClass()` already returns the full `dot--<status>` class, but the head
fed it to a `DotStatus` prop that prepends `dot--` again, so the dot never
matched a status color. Strip the prefix and assert the concrete class
(`dot--attention` / `dot--ok`) in the page tests instead of just the size.
2026-10-27 18:07:11 +08:00
yuez f549045ed2 fix(web): degrade server status when the /health probe fails
`resolveServerStatus` only degraded on `healthOk === false`, so a /health
request that errored outright (network error, 5xx) left the console claiming
"online" off a cached /info. Add `healthError` as its own step, ahead of the
subsystem check, and feed `health.isError` from the shell, the status page and
the workspaces page so all three derive a single verdict.
2026-10-27 18:07:04 +08:00
yuez 5139adf915 perf(web): optimize vitest performance and add testing guide 2026-10-27 17:30:40 +08:00
yuez e910e75849 feat: session-scoped entries query, session title tree and message stream updates 2026-10-27 17:30:28 +08:00