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`.
This commit is contained in:
yuez committed 2026-10-22 15:47:48 +08:00
1 parent b02f4e9070
commit 7e780515ac
38 files changed
+295 -232

No files matched your search

+8 -6
View File
@@ -1,15 +1,15 @@
# pi2d — pi2 web console daemon
# pi2 daemon — pi2 web console daemon
The always-on web side of [pi2.nvim](https://github.com/…/pi2.nvim). It is a **router + supervisor**, not an agent runtime:
```
browser ──HTTP/WS──▶ pi2d ──JSONL unix socket──▶ one nvim per workspace (pi2.nvim)
└── one pi --mode rpc per active session
browser ──HTTP/WS──▶ pi2 daemon ──JSONL unix socket──▶ one nvim per workspace (pi2.nvim)
└── one pi --mode rpc per active session
```
Hard rules (see `docs/protocol.md`):
1. `pi2d` never spawns `pi`, never reads session JSONL, never owns session state.
1. `pi2 daemon` never spawns `pi`, never reads session JSONL, never owns session state.
2. A workspace maps to **exactly one** managed nvim instance.
3. All mutations are commands relayed to the plugin; the plugin (inside nvim) is the single source of truth.
4. The web client keeps a render cache only; a `snapshot` from the plugin replaces it wholesale.
@@ -22,7 +22,9 @@ pnpm test
pnpm dev # starts on 127.0.0.1:7676
```
The plugin starts the daemon lazily when it is not running; you normally do not start it by hand.
The daemon is the `pi2 daemon` subcommand of the single shipped `pi2` binary — there is no
separate executable. The plugin starts it lazily when it is not running; you normally do not
start it by hand.
## Layout
@@ -32,7 +34,7 @@ The plugin starts the daemon lazily when it is not running; you normally do not
| `src/daemon/` | HTTP/WS/SSE, auth, static assets, routing, event relay |
| `src/instances/` | discovery, lazy spawn, single-instance enforcement, crash handling |
| `src/workspaces/` | workspace registry, disk discovery, aliases/trust |
| `src/cli/` | `pi2d` (daemon) and `pi2` (attach/status/doctor) |
| `src/cli/` | `pi2` — the `daemon` subcommand plus `attach`/`status`/`doctor` |
| `fixtures/` | golden event streams + expected session state (shared with pi2.nvim tests) |
| `docs/protocol.md` | the wire contract (browser ↔ daemon ↔ plugin) |