41 Commits
Author SHA1 Message Date
yuez ce87799b61 test(e2e): cover prompt-history recall end to end
A14 (API) and B15 (browser) make the feature verifiable against a real daemon,
a real headless nvim and a real `pi`.

- A14: the prompt A4 sent through `prompt.send` is in the plugin's archive
  exactly once — the console → daemon → plugin → daemon → console round trip, and
  the guard for "a web send is recorded at all"; `?limit=1` answers the newest
  entry; a freshly added workspace with no instance answers
  `{live:false, supported:false, entries:[]}` and its `/workspaces` row still
  reports `instance: null`, which is the no-spawn rule a keystroke depends on
- B15: wipes the browser mirror, reloads, checks the console fetched
  `/prompt-history`, walks ↑ back to the prompt B6 sent, walks ↓ out to the empty
  draft, recalls with Ctrl+P from a mid-line caret, and asserts that browsing
  never sends anything
- `docs/e2e.md` documents both (A0–A14, B1–B15)

Attribution done while landing this: with the plugin change stashed, A14 fails
(the capability is absent) while A5 reproduces identically and B1/B2/B3/B9/B13
fail the same way — pre-existing, not this feature. A5 is the coalesced
`text_delta` after `agent_settled` the suite already lists as a suspected
product bug; A11 is model-dependent and passed on the rerun.
2026-11-02 11:13:37 +08:00
yuez b8f1fca5bd feat(web): recall prompt history from the plugin with a browser fallback
The composer's ↑/↓ history is the web port of pi2.nvim's prompt buffer, so it
has to walk the archive nvim walks — not a copy of it. Three tiers: the plugin
owns the text, the daemon relays one live-only read, the browser keeps a mirror.

- `features/chat/prompt-history.ts`: the readline rules (`appendEntry`: blank
  ignored, consecutive dedupe, newest 500), the `localStorage` mirror
  (`pi2-prompt-history`, per workspace, 40 workspaces LRU), the
  `PromptHistorySource` seam, and `PromptHistoryNav` — the per-composer cursor
  with a stashed draft, independent positions, and a reset on edit/send
- `features/chat/prompt-history-feed.ts`: `usePromptHistory(workspaceId)` reads
  `GET /workspaces/:id/prompt-history`, appends a send optimistically, refreshes
  the mirror from every successful read, and falls back to the mirror whenever
  the relay cannot answer (no plugin, no capability, a 404 from an older daemon,
  an offline browser). One workspace-scoped read per page, never per keystroke.
- composer: ↑ recalls from the first line, ↓ from the last line or while
  browsing, `<C-p>`/`<C-n>` always recall; an IME composition and a text
  selection keep their keys; the caret lands at the end of a recalled prompt and
  a manual edit ends recall
- fixes a mirror bug found while testing it: a full list that accepts one more
  entry and drops the oldest has the same length, so the old "unchanged" check
  silently stopped recording after 500 prompts
- `docs/prompt-history.md` records the tiers, the key map, the storage contract
  and what is deliberately not shared yet (cross-host, history without nvim);
  the UI mock server answers the new endpoint so the visual harness stays honest

Version skew is boring by design: an old daemon (404) or an old plugin (no
capability) keeps recall working from the mirror.
2026-11-02 11:12:41 +08:00
yuez 32292873f9 feat(daemon): serve a live-only prompt-history read
The web composer's ↑/↓ recall needs the plugin's prompt history, so the browser
and nvim walk one list instead of two. The daemon relays it and stores nothing:
it is a router, and the plugin stays the authority (AGENTS.md rule 2).

- plugin `hello` advertises the new `promptHistory` capability; the daemon never
  relays the read to a plugin that did not advertise it
- `workspace.query{kind:"promptHistory",limit}` is answered by the plugin from
  its own `prompt.history` archive (workspace cwd), oldest-first
- `GET /api/v1/workspaces/:id/prompt-history?limit=` → `{v, workspaceId, live,
  supported, entries}`; `limit` defaults to 200 and clamps to 500, an unknown
  workspace is a 404, and malformed entries are dropped
- the read deliberately does **not** call `instances.ensure()`: recall is a
  keystroke, not a lifecycle event, so a workspace with no connected plugin
  answers `{live:false, supported:false, entries:[]}` instead of booting an nvim
- `PluginConnection.capabilities` joins the interface the daemon sees, and the
  fake connection grows a writable one so the gate is testable

No event or reducer change: `fixtures/` are untouched.
2026-11-02 11:12:21 +08:00
yuez 3a797ac3f7 feat(web): sort the workspace picker by recent use and make it searchable
The chat sidebar's workspace picker listed rows in daemon order, which says
nothing about where the user was last. It now orders by recent use and filters
as you type.

- new `features/chat/workspace-order.ts`: recency = browser-local stamp
  (`pi2-workspace-recency`, written whenever a workspace becomes active) >
  daemon `lastActiveAt` > name/id, so the order is deterministic and stable;
  search matches name, alias, cwd, directory name and id, whitespace-split
  terms all required
- `WorkspaceSwitch` becomes a filterable listbox: fixed search field on top
  (focused on open, cleared on close), scrolling row list, empty state,
  arrow/Home/End focus, Enter takes the first match, Esc returns focus to the
  trigger; rows are `role=option` + `aria-selected`
- pages/chat.tsx stamps whichever workspace is active (deep link, picker,
  default), styles and en/zh strings for the search field
- tests for ordering, matching, persistence and the keyboard/selection paths;
  the B5 UI e2e scenario follows the ARIA change and asserts the filter
2026-10-30 16:41:42 +08:00
yuez 00c81a56f4 feat(web): persist session-dot acknowledgements across reloads
`flags.done`/`flags.error` are unread markers: the plugin keeps raising them
until nvim's own TabEnter, while `markSeen` only cleared them in the in-memory
store. The next snapshot — a reload, or a reconnect's resync — replayed the
flag, so a notification the user had already consumed blinked again and the
dot looked stuck on unread.

The acknowledgement is now durable in `localStorage` (`pi2-seen-sessions`, per
browser), recorded under the occurrence it was given for: the id of the
transcript's newest entry. A replayed snapshot ends on the same entry, so
ingress clears the flag; the next completed turn appends entries first, so its
token differs and that new notification blinks again. A row with no entries
cannot be scoped and keeps the in-memory-only behaviour. `removeSession`
forgets the ledger row and the `tmp-N` → real-id migration moves it. This stays
a client-side view concern — the wire, the reducer and `fixtures/` are
untouched.
2026-10-30 16:19:40 +08:00
yuez 2f2f1bb518 feat(daemon): report host uptime, not only the daemon's process age
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.
2026-10-30 16:18:48 +08:00
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 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 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 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 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 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.
2026-10-28 17:32:53 +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 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 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 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 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 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 48411dccd2 feat(cli): add stop command to shut down running daemon 2026-10-27 18:37:21 +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
yuez a57c874095 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.
2026-10-27 10:44:08 +08:00
yuez 3789394c85 refactor(web): remove the dead right-panel and subagent-preview code
v0.1.1 replaced both surfaces: the session tray took the right panel's
todo/tasks, and the in-place `?sub=` child view took the subagent preview.

- delete `features/chat/side-panel.tsx` (nothing imported it since the tray
  landed)
- delete `SubagentModal` and its private helpers (`SUB_BADGE`, `SUB_DOT`,
  `SubagentEntry`, `parseSubagentLines`, `SUB_ROLES`); the child view builds its
  timeline from the parent's entries instead of `subagent.read`
- drop `chatCommands.readSubagent` (its only caller is gone)
- drop the deprecated store slice `PreviewTarget` / `preview` / `setPreview`,
  including the session-migration re-key and the `PanelTab` alias
- drop their exclusive CSS (`.sub-item*`, `.sub-preview*`, `.sub-steer`) and the
  6 orphan catalog keys (chat.subagentTitle, chat.preview, chat.previewNote,
  chat.task, chat.currentSubagents, chat.steerRequired)
- tests: remove the two SubagentModal cases and the preview/readSubagent
  expectations (295 tests, down from 297 — exactly the deleted cases)

Verification: typecheck clean, vitest 295/295, vite build green, visual matrix
24/24 clean.
2026-10-27 09:26:36 +08:00
yuez bcf50b516f refactor(web): drop the v0.1.0 leftovers from chat.css
The port left two generations of chat rules in one file. The newer owners are
now the only source of truth: tool-core/tool-file/tool-shell/tool-search own
tool rows and diffs, chat-msg owns message blocks, chat-stream owns the reading
column and spacing, chat-composer owns the pending bar, chat-tray owns the tray
and head chips, chat-telemetry owns the status line.

Removed (293 lines):
- the whole `.tool` card + `.diff` review block (`.tool--done`/`--error`,
  `.tool__name/__sum/__ico/__pre`, `.diff__*`), superseded by `[data-kind]`
- queued-message chips (`.chip--queue`, `.chip--sending`, `.q-steer*`) and the
  old `.composer__queue`, replaced by the composer `role=status` bar
- stream spacing/width from v0.1.0 (`max-width: 68rem`, 16px gaps, virtual
  `padding-bottom`) — chat-stream.css owns 52rem + 18/28px now
- dead stream-head furniture (`.chat-conn`, `.stream-meta`, `.chat-btn--*`) and
  the `.sub-d2/.sub-d3` indent modifiers; `.stream-status` stays hidden in the
  head below 840px via a scoped rule
- `.icon-btn--danger:hover`, `.composer__note`

Audit: a selector/class scan over 184 top-level blocks reports 0 rules whose
classes are unused; nothing overrides the new files any more.

Verification: typecheck clean, vitest 297/297 (the two 5s timeouts seen while a
Playwright matrix ran in parallel reproduce as passes on a quiet run), vite
build green, visual matrix 24/24 clean, and r3→r5 screenshots differ by
<0.1% pixels (anti-aliasing only).
2026-10-27 09:14:53 +08:00
yuez 88e73c7737 feat(web): port the pi2-web-ui-design v0.1.1 UI
Sync the React console with the v0.1.1 prototype (20 CHGs): Quiet Workbench
shell, Chat IA v3, tool-family rendering, and the mobile page pill.

Shell / tokens (CHG-01/04/15/20):
- tokens.css rewritten from the prototype (three-layer light/dark/system),
  `--tabbar-h` removed, new faint/border-subtle/surface-1-2/fs-*/dur-*/reading-max
- 56px icon-only nav rail/sidebar (44x44 hit targets, CSS tooltips, active is a
  solid primary fill, no left bar), 52px topbar, merged preferences menu,
  ⌘K/Cmd-K palette
- `<600` gets a topbar page pill + page sheet; the bottom tabbar is gone

Pages (CHG-01): workspaces becomes a card grid with whole-card links and a
320px recent-activity column; status gets four metric tiles + a zero-primary
layout; connect gets a two-column hero, one primary per state and a collapsed
manual form.

Chat IA v3 (CHG-02/10-14/16-19): two columns, single-workspace tree with a
workspace switch, single-line rows with attention, body-level row popover,
session tray (todo/tasks) replacing the right panel, context ring moved into a
composer telemetry line, right-aligned user messages, queued messages as one
stream entity plus a composer status bar, and an in-place subagent child view.

Tool rendering (CHG-05/06/09): new `features/chat/tools` module — one row per
call, DTO adapter for the daemon's block shape, 11 kind families, state
semantics ("one state, one meaning"), 44px touch targets and the diff row
contrast fix.

i18n: 729 keys per language (zh/en parity checked), 0 unresolved keys.

Verification: web typecheck + 297 vitest + vite build green, root typecheck
green, `scripts/smoke.sh` green, and a new visual harness
(`scripts/ui-mock-server.mjs` + `scripts/ui-shots.mjs`, docs/ui-parity.md)
shoots 4 pages x 3 viewports x 2 themes = 24 screenshots clean with
overflow/console/primary/tabbar assertions. `scripts/e2e/ui-e2e.mjs` selectors
are updated to the new DOM; that suite still needs a real pi + nvim to run.
2026-10-26 20:28:47 +08:00
yuez 2589e6df72 build: publish the npm package as @yuez/pi2d
The unscoped name was rejected by the registry's similarity filter ("too similar
to existing packages pify, ping, pino, pm2, uid"), so the package moves under the
maintainer's npm scope, which is not subject to that heuristic.

The executable is still `pi2`, the GitHub repository is still `zgs225/pi2d` (the
trusted publisher matches on owner/repo/workflow filename, not the npm name), and
the tarball contents are unchanged. The releasing checklist also had the npm
account wrong: the registry account is `yuez`, while `zgs225` is the GitHub owner
the trusted publisher is configured against.
2026-10-23 10:31:32 +08:00
yuez 9eb7075d70 docs: document the workspace visibility knobs and the curl check 2026-10-23 10:08:15 +08:00
yuez ef0d9b9125 ci: publish npm with Trusted Publishing instead of a token
The release job now authenticates with the GitHub OIDC token: `id-token: write`,
no NPM_TOKEN anywhere near the publish step, and a guard that fails when a
leftover repository secret is still mapped in. npm 11.5.1+ is required for
trusted publishing and setup-node's node 22 ships npm 10, so the job upgrades npm
and asserts npm/node versions plus the presence of the OIDC endpoint before
publishing. Provenance then comes for free.

docs/releasing.md documents the unavoidable bootstrap: npm only offers the
trusted-publisher settings page once the package exists, so the first version is
published from the maintainer's machine and every later one from CI.
2026-10-23 10:08:15 +08:00
yuez 64a1a98c1f feat(daemon): collapse workspace noise into a "show hidden" section
Discovery returns every pi session directory ever seen, so the console opened on
47 rows on this machine: 20 ghosts (cwd deleted) and 21 scratch dirs under /tmp
next to the real projects. Every row now carries a derived, non-persisted
`visibility`/`visibilityReason`; nothing is filtered server-side, so
`/workspace/<id>` deep links and the chat page's id lookup still resolve.

Precedence: explicit `hidden` wins; a live instance, `pinned` or `trusted`
rescues a row; then temp paths (`PI2_WORKSPACE_HIDE_TEMP`, on), ghosts
(`PI2_WORKSPACE_HIDE_GHOSTS`, on), outside roots (`PI2_WORKSPACE_HIDE_OUTSIDE_ROOTS`,
off) and staleness (`PI2_WORKSPACE_STALE_DAYS`, off). Measured on real data:
47 → 26 default rows, 0 openable rows lost.

The browser collapses the secondary rows behind a persisted toggle and dims them
with a reason badge; `workspace.add` now clears `hidden`.
2026-10-23 10:08:15 +08:00
yuez 84869f3dc6 test(e2e): cover the console login handoff (A13) 2026-10-23 08:34:48 +08:00
yuez 9ab0830223 feat(cli): add pi2 open, pi2 pairing --public-url and the access check
`pi2 open [--print] [--no-browser]` mints a loopback browser session and hands
the URL to the platform opener without waiting for it, so "open the console" is
one command that never hangs. `pi2 pairing --public-url` (or `daemon.json.publicUrl`
/ `PI2_PUBLIC_URL`) rebuilds the printed URL and QR payload for a tailnet or
reverse-proxy base.

`pi2 doctor` gains an `access` check: ok on loopback, warn for `lan`/`tailscale`,
fail when a non-loopback bind has neither a public URL nor TLS.
2026-10-23 08:34:48 +08:00
yuez 06e70204e7 fix(web): render the chat session tree from parent/sub-session lineage
The sidebar treated every workspace session as a root and only nested the
manifest sub-agents, so sub-session files showed up as siblings (the same child
twice); sub-sessions the plugin marked hidden were listed anyway.

- build the tree from `parentId` in a pure `buildSessionTree` model: orphans are
  promoted to roots, cycles and duplicate ids are guarded, real child-session
  rows win over the manifest projection, and the routed row force-opens its
  ancestors
- honour the plugin's `:PiSessions` visibility (`visible: false`) with a "show
  hidden sub-sessions" toggle, the routed-row exception and a dedicated
  all-hidden empty state
- keep tree metadata across WS snapshots, reducer events, id migration and
  parent removal; prefer a root row for the `/chat` index and add a "back to
  parent" action
- document the session-row and `pi2:subagents` list metadata in the protocol
2026-10-22 16:45:09 +08:00
yuez 7e780515ac feat(cli)!: merge the daemon into pi2 as the daemon subcommand
`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`.
2026-10-22 15:47:48 +08:00
yuez b02f4e9070 test(e2e): add the full web-console end-to-end gate
- API/WS driver A0–A12: auth/pairing, workspaces, instances, session create,
  real model streaming, abort, model/thinking, history paging, resync,
  multi-workspace isolation, subagents and a deterministic attention/diff
  trigger (attention-ext.ts).
- Playwright driver B1–B14 + C1–C4: guard/pairing, workspaces, chat streaming,
  abort, panels, attention, status/devices, reconnect, deep links, i18n/theme,
  responsive overflow and console errors.
- lib.sh isolates every run (runtime/data/state/agent dirs, ephemeral port,
  fresh workspaces) and reaps by /proc env; run-all.sh builds both sides.
  Document the plan and the 31/31 acceptance run.
2026-10-21 20:42:34 +08:00
yuez 5572ac0d84 fix(daemon): forward snapshot entries and map workspace errors
- 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.
2026-10-21 20:42:02 +08:00
yuez 18e3e0ab4e feat(cli): runnable daemon, local CLI, doctor, service files and smoke test
- composition root wiring config/auth/workspaces/instances/http
- singleton lock + daemon.json + port retry + local cli.token (admin scope)
- pi2 attach/status/doctor/pairing/install-service
- systemd user unit + launchd plist rendering (never auto-enabled)
- smoke.sh boots the real daemon on an ephemeral port and asserts auth/static/lifecycle
- 93 new tests (263 total), tsc + build + smoke green
2026-10-21 12:45:11 +08:00
yuez 9d817f35b7 feat(protocol): wire contract, canonical reducer and golden fixtures
- v1 envelope across browser/daemon/plugin
- SessionState model + reducer rules (pi events + pi2:* derived events)
- fixtures for basic turn, queue/todo/attention and abort/exit
- 9 conformance tests pinning the reducer
2026-10-21 10:58:46 +08:00