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.
This commit is contained in:
yuez committed 2026-10-30 09:55:08 +08:00
1 parent 2240289426
commit 086cac8c8e
4 files changed
+183 -96

No files matched your search

+18 -16
View File
@@ -22,21 +22,10 @@ Requirements: **Node >= 20** (for the npm channel; the curl installer and system
> **Status.** The daemon CLI, the web console and the standalone installer are ready today (`npm i -g @yuez/pi2d` and `install.sh` work today). `:PiWeb` and `:PiWebInstall` land with the next pi2.nvim release, so today the flow is `pi2 daemon` + `pi2 open` (or running the daemon as a user service).
### Channel A: Global package manager (Node >= 20)
### Recommended: the standalone installer (the self-updating channel)
If your machine has Node >= 20:
```bash
npm i -g @yuez/pi2d
# or:
pnpm add -g @yuez/pi2d
bun add -g @yuez/pi2d
mise use -g npm:@yuez/pi2d
```
### Channel B: Standalone curl installer (no Node required)
For machines without Node, with an older distro Node (e.g. Debian 12 ships 18), or where you want a self-contained installation with no global npm or root access:
One self-contained binary, no Node, no root — the only channel that updates itself with
`pi2 update`. Also the right choice for an older distro Node (Debian 12 ships 18) or musl systems:
```bash
curl -fsSL https://raw.githubusercontent.com/zgs225/pi2d/main/scripts/install.sh | sh
@@ -47,6 +36,19 @@ points `~/.local/lib/pi2d/current` at it, writes an install receipt and symlinks
`~/.local/bin/pi2`. After that, `pi2 update` upgrades it in place (verified download, SLSA
provenance check, atomic `current` switch, one-step rollback).
### Or: a package manager (it owns the upgrade)
If you prefer npm-style installs (Node >= 20). Upgrades belong to that package manager —
`pi2 update` refuses npm trees and prints `npm i -g @yuez/pi2d@latest`:
```bash
npm i -g @yuez/pi2d
# or:
pnpm add -g @yuez/pi2d
bun add -g @yuez/pi2d
mise use -g npm:@yuez/pi2d
```
To uninstall, first remove the daemon's local state (runtime, service unit, and — with flags —
data/state/config), then the binaries:
@@ -60,7 +62,7 @@ On the npm / Homebrew / AUR channels the binary tree belongs to the package mana
[Complete removal](docs/install.md#uninstall) for the full table of paths and the two things
no CLI can clean (browser site data, the plugin-private copy).
### Channel C: System packages (Homebrew, AUR)
### Or: Homebrew / AUR (they own the upgrade)
*(Available once the release that publishes binaries has shipped)*:
@@ -69,7 +71,7 @@ no CLI can clean (browser site data, the plugin-private copy).
brew install zgs225/tap/pi2d
```
- **Arch Linux / Manjaro / EndeavourOS (AUR `pi2d-bin`):**
*(AUR account registration is temporarily closed upstream — until it reopens, Arch users install with the [curl installer](#channel-b-standalone-curl-installer-no-node-required) above)*:
*(AUR account registration is temporarily closed upstream — until it reopens, Arch users install with the [standalone installer](#standalone) above)*:
```bash
paru -S pi2d-bin # or: yay -S pi2d-bin
```
+6 -1
View File
@@ -1,6 +1,7 @@
# ADR 0002 — Installation and run model: CLI first, service-owned daemon, plugin attaches
- Status: accepted (implementing)
- Status: accepted (implementing), partially superseded by [ADR 0004](0004-one-self-updating-channel.md)
(the plugin no longer installs; the standalone artifact is the one self-updating channel)
- Date: 2026-10-28
- Supersedes: the implicit "the plugin installs and spawns the daemon" default in
`README.md` §Install and the resolution table (explicit path → `PATH` → plugin
@@ -108,6 +109,10 @@ The plugin's `:PiWebInstall` becomes an explicit convenience command that prompt
confirmation before installing `@yuez/pi2d@latest` (an optional `<version>` argument
pins one) into `<stdpath("data")>/pi2d`. It never runs `npx`.
> **Amended by [ADR 0004](0004-one-self-updating-channel.md)**: `:PiWebInstall` no longer installs
> anything. The npm package keeps publishing, but the package manager owns its upgrades; the
> plugin prints commands and delegates to `pi2 update` (standalone channel only).
### 2.2 Run: the daemon owns its own lifecycle
| Mode | Who starts it | When to use |
@@ -0,0 +1,79 @@
# ADR 0004 — One self-updating channel: the standalone artifact, owned by `pi2d`
- Status: accepted (implementing)
- Date: 2026-10-30
- Amends: [ADR 0002](0002-install-and-run.md) §2.1 (distribution channels) and §2.3 (the plugin is a client)
- Builds on: [ADR 0003](0003-self-update.md) (the install receipt and the versioned layout)
## Context
`pi2d` ships through four distributions — the curl installer, npm, a Homebrew tap and an AUR
`-bin` package — and ADR 0002 §2.1 kept `:PiWebInstall` in the plugin as an "explicit
convenience command" that installs the npm package into `<stdpath("data")>/pi2d`.
That gave two owners for one piece of software, and it broke in exactly the way two owners
always do. On a machine with a standalone (curl-installed) `pi2`, the plugin's npm copy sat in
`plugin-data` — a lower rung of the resolution ladder — so `:PiWebUpdate` upgraded a second copy
nobody ran, reported success, and the daemon kept serving the old version. The fix (dispatch on
`installShape`) landed first, but it papered over the design problem: the plugin should never
have been installing anything.
What the ecosystem does, checked against primary sources:
| Project | Stance |
|---|---|
| **nvim-lspconfig** | "nvim-lspconfig does not install language servers for you." The client plugin resolves a command on `PATH`. |
| **eglot** (Emacs) | Same: `eglot-server-programs` names executables; the user's package manager provides them. |
| **mason.nvim** | A *dedicated* installer ("Portable package manager for Neovim"), installing into `stdpath("data")/mason` and shelling out to `cargo`/`npm`. It exists because clients do not install. |
| **coc.nvim** | The counter-example: a Node service that owns `:CocInstall`. It pays by bundling a runtime and re-implementing a package manager. |
| **uv**, **deno**, **bun** | Upstream owns `self update`, and it *refuses* package-manager-owned trees with the command that owns them (uv reads an install receipt; deno prints "update through your package manager"). |
| **esbuild** | npm's way to ship a compiled binary: 26 `optionalDependencies` (`@esbuild/linux-x64`, …) plus a `bin` shim. |
| **pi / dsh / Claude Code / Codex / opencode / aider …** | (ADR 0002 §1) The agent is a first-class CLI installed by a package manager or `curl \| sh`; the editor plugin spawns or attaches, never installs. |
The common denominator: **whoever wrote the files owns the upgrade.** Anything else duplicates an
installer and guarantees a second, stale copy.
## Decision
### 1. One self-updating channel, owned by `pi2d`
The standalone release artifact is the only channel the project maintains end to end:
- `scripts/install.sh` installs it (versioned layout + receipt, ADR 0003),
- `pi2 update` upgrades it in place (verified digest, SLSA provenance, atomic `current` switch,
one-step rollback),
- both live in this repository, next to the artifact they manage, and are the only place that
knows the release matrix, the layout and the service unit.
### 2. npm, Homebrew and the AUR stay as *distributions*, not as install logic
They keep publishing, and their users keep upgrading with `npm i -g`, `brew upgrade pi2d` or
`paru -Syu pi2d-bin`. They are not channels we implement: `pi2 update` reads the receipt and
refuses them with their own command, which is the `uv` model and the reason a receipt exists.
### 3. The plugin is a client, and clients do not install
`pi2.nvim` resolves the daemon, uses it, and prints commands. Concretely:
- `:PiWebUpdate` drives `pi2 update` on the standalone channel, and prints the owning command on
every other channel (no execution).
- `:PiWebInstall` stops installing anything: with no `pi2` it prints the install commands
(standalone first); with a `pi2` it reports where it lives and points at `:PiWebUpdate`.
- `web.install_dir` and the `plugin-data` rung of the resolution ladder become deprecated
read-only compatibility, so an existing npm copy keeps resolving while nothing writes a new one.
### 4. Deferred: shipping the binary through npm
An `optionalDependencies` shim (the esbuild model) would let npm deliver the *same* compiled
binary, collapsing `installShape` to a single value. It is not done now: it changes the npm
publish shape and buys nothing the standalone channel does not already provide.
## Consequences
- The plugin loses its installer (~200 lines and its specs); `pi2 update` gains no new code.
- `docs/install.md` and `README.md` reorder: the standalone installer is the path, the package
managers are alternatives that own their own upgrades.
- A user who prefers npm keeps working unchanged, but upgrades with npm — and `:PiWebUpdate`
tells them so instead of silently installing a second copy.
- The `mason.nvim`-shaped answer (a dedicated installer layer) stays available as a third party
deciding to wrap `install.sh`; we do not need to build one.
+80 -79
View File
@@ -10,50 +10,37 @@ This document is the canonical reference for installing, running, configuring, u
Find your situation in the table below to choose the right installation command and run model:
Only the **standalone channel** updates itself (`pi2 update`). npm, Homebrew and the AUR stay
available, but the package manager that installed `pi2` owns its upgrades — `pi2 update` refuses
them and prints the command that does ([ADR 0004](adr/0004-one-self-updating-channel.md)).
| Situation | Recommended Command | What it gives you |
|---|---|---|
| **I have Node 20+** | `npm i -g @yuez/pi2d`<br>*(or `pnpm add -g`, `bun add -g`, `mise use -g npm:@yuez/pi2d`)* | The `pi2` CLI running directly on your existing Node.js environment, updated via standard package manager commands. |
| **no Node / old Node** | `curl -fsSL https://raw.githubusercontent.com/zgs225/pi2d/main/scripts/install.sh \| sh` | Standalone compiled binary in `~/.local/lib/pi2d` symlinked to `~/.local/bin/pi2`, upgraded in place with `pi2 update`. Requires zero Node/npm dependencies and no root access. |
| **macOS** | `brew install zgs225/tap/pi2d`<br>*(or the curl installer)* | Native Homebrew formula. Places `pi2` in `$(brew --prefix)/bin` and web assets in `$(brew --prefix)/share/pi2d/web/dist`. |
| **Arch / EndeavourOS / Manjaro** | `curl -fsSL https://raw.githubusercontent.com/zgs225/pi2d/main/scripts/install.sh \| sh`<br>*(AUR `pi2d-bin` once AUR registration reopens)* | Standalone binary in `~/.local/lib/pi2d` + `~/.local/bin/pi2`. Package-manager channels are paused: the AUR is not accepting accounts, so the curl installer is the working path today. |
| **NixOS** | `curl -fsSL https://raw.githubusercontent.com/zgs225/pi2d/main/scripts/install.sh \| sh`<br>*(or dev checkout)* | Standalone binary in user home (`~/.local/bin/pi2`). Bun's `-musl` binaries are dynamically linked against the musl loader, so running a prebuilt binary on NixOS needs `nix-ld` (or an FHS env / `steam-run`-style wrapper). |
| **Most machines (recommended)** | `curl -fsSL https://raw.githubusercontent.com/zgs225/pi2d/main/scripts/install.sh \| sh` | One self-contained binary plus the web UI in `~/.local/lib/pi2d/versions/<version>` (receipt, `current` symlink, `~/.local/bin/pi2`), upgraded in place with `pi2 update`. No Node, no npm, no root. |
| **I prefer npm / pnpm / bun / mise** | `npm i -g @yuez/pi2d`<br>*(or `pnpm add -g`, `bun add -g`, `mise use -g npm:@yuez/pi2d`)* | The `pi2` CLI on your existing Node.js environment. **The package manager owns upgrades**: `npm i -g @yuez/pi2d@latest`. |
| **no Node / old Node (Debian 12, Alpine, NixOS)** | the curl installer *(above)* | Same artifact as the recommended row: zero runtime dependencies, `-musl` builds for musl distros. On NixOS Bun's `-musl` binaries need `nix-ld` (or an FHS env). |
| **macOS** | `brew install zgs225/tap/pi2d`<br>*(or the curl installer)* | Native Homebrew formula (`pi2` in `$(brew --prefix)/bin`). **Homebrew owns upgrades**: `brew upgrade pi2d`. |
| **Arch / EndeavourOS / Manjaro** | the curl installer *(AUR `pi2d-bin` once registration reopens)* | AUR registration is paused upstream, so the curl installer is the working path today; `paru -Syu pi2d-bin` takes over once the package lands. |
| **I want it to survive reboot and logout** | `pi2 install-service --write`<br>`systemctl --user enable --now pi2.service`<br>`loginctl enable-linger $USER` | Background systemd user service (or launchd on macOS) that starts at boot and stays alive when SSH sessions disconnect. |
| **I only want to try it** | Install via curl or npm, then run:<br>`pi2 daemon` | Foreground daemon in your current terminal. Logs stream to stdout/stderr. Stop anytime with `Ctrl-C` or `pi2 stop`. |
| **I only want to try it** | the curl installer, then `pi2 daemon` | Foreground daemon in your current terminal; stop with `Ctrl-C` or `pi2 stop`. |
| **I develop pi2d itself** | `git clone https://github.com/zgs225/pi2d.git`<br>`pnpm install && pnpm --dir web install` | Source checkout with hot-reloading backend (`pnpm dev`) and Vite dev server (`pnpm --dir web dev`). |
---
## Install channels
`pi2d` distributes through four primary channels:
`pi2d` ships one **self-updating** channel (the standalone artifact below) and three
**package-manager-owned** distributions. Whoever wrote the files owns the upgrade:
`scripts/install.sh` + `pi2 update` maintain the standalone tree, and npm / Homebrew / the AUR
maintain theirs.
### Channel A: Global package manager (Node >= 20)
<a id="standalone"></a>
### Standalone installer — the self-updating channel
Best when your workstation or server already has Node.js (version 20 or later) installed.
```bash
# npm
npm i -g @yuez/pi2d
# pnpm
pnpm add -g @yuez/pi2d
# bun
bun add -g @yuez/pi2d
# mise
mise use -g npm:@yuez/pi2d
```
**Where files land**:
- Executable binary: `$(npm config get prefix)/bin/pi2`
- Node package & web assets: `$(npm config get prefix)/lib/node_modules/@yuez/pi2d/` (with web assets in `web/dist/`)
---
### Channel B: Standalone curl installer (no Node required)
Best for systems with no Node runtime, machines with older distributions (such as Debian 12 shipping Node 18), or environments where you do not want to manage global npm packages.
This is the recommended channel and the only one the project maintains end to end: one
self-contained binary, no Node runtime, no root, and `pi2 update` upgrades it in place. It is the
right choice for machines without Node, distributions with an older Node (Debian 12 ships 18),
musl systems and servers.
```bash
curl -fsSL https://raw.githubusercontent.com/zgs225/pi2d/main/scripts/install.sh | sh
@@ -102,7 +89,33 @@ PI2_VERSION=0.1.6 PI2_BIN_DIR=/usr/local/bin PI2_INSTALL_DIR=/usr/local/lib/pi2d
---
### Channel C: System packages (Homebrew & AUR)
<a id="package-managers"></a>
### Package managers (npm / pnpm / bun / mise) — they own the upgrade
Best when your workstation or server already has Node.js (version 20 or later) installed.
```bash
# npm
npm i -g @yuez/pi2d
# pnpm
pnpm add -g @yuez/pi2d
# bun
bun add -g @yuez/pi2d
# mise
mise use -g npm:@yuez/pi2d
```
**Where files land**:
- Executable binary: `$(npm config get prefix)/bin/pi2`
- Node package & web assets: `$(npm config get prefix)/lib/node_modules/@yuez/pi2d/` (with web assets in `web/dist/`)
---
<a id="brew-aur"></a>
### Homebrew & AUR — they own the upgrade
*(Note: These channels are available once the release publishing compiled binaries has shipped).*
@@ -115,7 +128,7 @@ brew install zgs225/tap/pi2d
#### Arch Linux / Manjaro / EndeavourOS (AUR)
> **AUR registration paused**: New user registration on the AUR is temporarily closed upstream (HTTP 503: "Registration on the AUR is paused while we deal with a wave of automated account creation..."). Until registration reopens and `pi2d-bin` can be submitted, the AUR channel is unavailable. Use **[Channel B: Standalone curl installer](#channel-b-standalone-curl-installer-no-node-required)** instead — it works on Arch today and `pi2 update`s with the same command.
> **AUR registration paused**: New user registration on the AUR is temporarily closed upstream (HTTP 503: "Registration on the AUR is paused while we deal with a wave of automated account creation..."). Until registration reopens and `pi2d-bin` can be submitted, the AUR channel is unavailable. Use **[the standalone installer](#standalone)** instead — it works on Arch today and `pi2 update`s with the same command.
```bash
# (When AUR registration reopens)
@@ -311,51 +324,39 @@ systemctl --user restart pi2.service
### Upgrade per channel
- **Channel A (npm / pnpm / bun / mise)**:
```bash
npm i -g @yuez/pi2d@latest
# or:
pnpm add -g @yuez/pi2d@latest
bun add -g @yuez/pi2d@latest
mise use -g npm:@yuez/pi2d@latest
```
**Standalone installer — the self-updating channel:**
- **Channel B (Standalone curl installer)**:
```bash
pi2 update
```
It downloads the release asset for this platform, checks it against the release's
`SHA256SUMS`, verifies its SLSA build provenance with `gh attestation verify` when the
GitHub CLI is installed, runs the new binary once, then switches
`~/.local/lib/pi2d/current` and rewrites the install receipt. The previous version is kept
for one-step rollback.
```bash
pi2 update
```
| Command | What it does |
|---|---|
| `pi2 update` | Upgrade to the latest release, then print the command to restart the daemon |
| `pi2 update --check` | Report the latest version and exit (24 h cached, one GitHub API call at most) |
| `pi2 update --dry-run` | Print the asset, URL and prefix it would use, change nothing |
| `pi2 update --version 0.1.6` | Pin a version (a downgrade also needs `--force`) |
| `pi2 update --force` | Reinstall even when already on that version |
| `pi2 update --require-attestation` | Fail unless the SLSA provenance verifies |
| `pi2 update --skip-attestation` | Never call `gh` (offline machines, no GitHub CLI) |
| `pi2 update --json` | Machine-readable result (stdout is pure JSON; progress goes to stderr) |
It downloads the release asset for this platform, checks it against the release's
`SHA256SUMS`, verifies its SLSA build provenance with `gh attestation verify` when the GitHub
CLI is installed, runs the new binary once, then switches `~/.local/lib/pi2d/current` and
rewrites the install receipt. The previous version is kept for one-step rollback.
Setting `PI2_BASE_URL` points the download at a mirror (`PI2_UPDATE_CACHE_TTL` changes the
version-lookup cache, default 86400 s). Re-running the installer still works and stays the
recovery path when the tree is damaged.
| Command | What it does |
|---|---|
| `pi2 update` | Upgrade to the latest release, then print the command to restart the daemon |
| `pi2 update --check` | Report the latest version and exit (24 h cached, one GitHub API call at most) |
| `pi2 update --dry-run` | Print the asset, URL and prefix it would use, change nothing |
| `pi2 update --version 0.1.6` | Pin a version (a downgrade also needs `--force`) |
| `pi2 update --force` | Reinstall even when already on that version |
| `pi2 update --require-attestation` | Fail unless the SLSA provenance verifies |
| `pi2 update --skip-attestation` | Never call `gh` (offline machines, no GitHub CLI) |
| `pi2 update --json` | Machine-readable result (stdout is pure JSON; progress goes to stderr) |
- **Channel C (Homebrew)**:
```bash
brew update && brew upgrade pi2d
```
`PI2_BASE_URL` points the download at a mirror (`PI2_UPDATE_CACHE_TTL` changes the
version-lookup cache, default 86400 s). Re-running the installer still works and stays the
recovery path when the tree is damaged.
- **Channel C (Arch AUR — when reopened)**:
```bash
paru -Syu pi2d-bin
# or:
yay -Syu pi2d-bin
```
**Package managers — they own the upgrade** (`pi2 update` refuses with the command below):
```bash
npm i -g @yuez/pi2d@latest # or: pnpm add -g / bun add -g / mise use -g npm:@yuez/pi2d@latest
brew update && brew upgrade pi2d
paru -Syu pi2d-bin # AUR, when registration reopens
```
### Uninstall
@@ -409,25 +410,25 @@ it kept, so a full wipe never requires knowing the layout.
#### Step 2 — remove the binaries (per channel)
- **Channel A (npm / pnpm / bun)**:
- **npm / pnpm / bun**:
```bash
npm rm -g @yuez/pi2d
# or: pnpm rm -g @yuez/pi2d / bun rm -g @yuez/pi2d
```
- **Channel B (curl installer)** — after `pi2 uninstall --purge`, or instead of it when the
- **Standalone installer** — after `pi2 uninstall --purge`, or instead of it when the
state does not matter:
```bash
curl -fsSL https://raw.githubusercontent.com/zgs225/pi2d/main/scripts/install.sh | sh -s -- --uninstall
```
*(Or manually delete `rm -rf ~/.local/lib/pi2d ~/.local/bin/pi2`)*.
- **Channel C (Homebrew)**:
- **Homebrew**:
```bash
brew uninstall pi2d
```
- **Channel C (Arch AUR — when reopened)**:
- **Arch AUR (when registration reopens)**:
```bash
sudo pacman -R pi2d-bin
```