pi-web-ui 0.63.1 → 0.63.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,505 +1,505 @@
1
- <div align="center">
2
-
3
- # 💬 pi-web-ui
4
-
5
- **English** | [Chinese (Simplified)](https://github.com/xing-shuyin/pi-web-ui/blob/main/README.zh-CN.md)
6
-
7
- *The polished browser cockpit for the [pi coding agent](https://pi.dev).*
8
-
9
- <p>
10
- <a href="https://www.npmjs.com/package/pi-web-ui"><img src="https://img.shields.io/npm/v/pi-web-ui?color=cb3837&logo=npm&label=pi-web-ui" alt="npm version"></a>
11
- <a href="https://nodejs.org/"><img src="https://img.shields.io/node/v/pi-web-ui?logo=node.js&logoColor=white" alt="Node.js"></a>
12
- <a href="LICENSE"><img src="https://img.shields.io/github/license/xing-shuyin/pi-web-ui" alt="License"></a>
13
- <a href="https://www.npmjs.com/package/pi-web-ui"><img src="https://img.shields.io/npm/dm/pi-web-ui?label=downloads" alt="npm downloads"></a>
14
- <a href="https://github.com/xing-shuyin/pi-web-ui/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/xing-shuyin/pi-web-ui/ci.yml?branch=main&label=CI" alt="CI status"></a>
15
- <a href="https://github.com/xing-shuyin/pi-web-ui/stargazers"><img src="https://img.shields.io/github/stars/xing-shuyin/pi-web-ui?style=social" alt="GitHub stars"></a>
16
- <a href="https://github.com/xing-shuyin/pi-web-ui/fork"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen?style=flat" alt="PRs welcome"></a>
17
- </p>
18
-
19
- Stream conversations, inspect tool calls, manage files, and run your workspace — all from one place.
20
-
21
- ![Git source control panel](https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot4.jpeg)
22
-
23
- </div>
24
-
25
- A web chat interface for the [pi coding agent](https://pi.dev). The agent runs
26
- **in-process** via the pi SDK and streams events to the browser over WebSocket:
27
- thinking blocks, tool calls, file trees, a built-in terminal, model management,
28
- theme switching, and a full settings panel — tuned for daily development.
29
-
30
- > **Requirements** — Node.js ≥ 22.19 and a configured pi install.
31
-
32
- ## More from the author
33
-
34
- > **Building with DSH?**
35
- >
36
- > [**dsh-ui-tools**](https://github.com/xing-shuyin/dsh-ui-tools) is the author's companion project for building and extending UI tools in the DSH ecosystem.
37
-
38
- ## ✨ Highlights
39
-
40
- | 💬 **Chat that works like you do** | 🖼️ **Files & images** | 🧩 **Extensible by design** | 🔒 **Private by default** |
41
- | --- | --- | --- | --- |
42
- | Streaming replies, steer & follow-up queueing, slash commands, multiple conversations per project, edit-&-re-ask. | Attach files, paste images, ask about pictures (vision bridge), preview anything with GBK fallback. | Drop-in UI **plugins** (extra top-bar tabs + agent tools) and standalone **themes** — no rebuild, no restart. | Loopback-only, credential-safe: provider keys & headers never reach the browser. |
43
-
44
- ## 📚 Table of Contents
45
-
46
- - 🚀 [Features](#features)
47
- - 🖼️ [Screenshots](#screenshots)
48
- - 📦 [Install](#install)
49
- - ⚡ [Quick start](#quick-start)
50
- - 🖥️ [System service](#system-service)
51
- - 🧩 [Plugins](#plugins)
52
- - 🎨 [Themes](#themes)
53
- - 🔒 [Security](#security)
54
- - 🌐 [Reverse proxy (nginx)](#reverse-proxy-nginx)
55
- - 🤝 [Contribute](#contribute)
56
- - 📄 [License](#license)
57
-
58
- ## Features
59
-
60
- ### 💬 Chat
61
-
62
- - **Streaming agent chat over WebSocket** — the pi SDK runs in-process; events are pushed as snapshots (60 ms throttled) and the browser renders them.
63
- - Thinking blocks, tool-call cards and bash outputs with live status (running → finished · waiting for the model · duration).
64
- - **Steer (follow-up queueing)** — send a follow-up while the agent is replying; it is queued and injected as soon as the current turn's tool calls settle (the "Interrupt" equivalent of the pi CLI).
65
- - **Slash commands** — `/` opens a command picker (built-in / extension / template / skill); built-ins include `/new /model /compact /cwd /thinking /resume`, plus `/help` (command list) and `/copy` (copy last reply).
66
- - **Multiple conversations per project** — each conversation gets its own agent runtime and keeps running in the background after you switch away; the "Running conversations" list shows stream progress and lets you switch back.
67
- - **Edit & re-ask** — fork any past question into a new branch and re-prompt; the original conversation stays untouched.
68
- - Long threads auto-collapse messages older than 30 into lazy summary rows (click to expand).
69
- - Question navigation — a floating rail plus per-question tags to jump between questions.
70
-
71
- ### 🤖 Subagents & templates
72
-
73
- - **First-party subagents** — spawn independent background conversations for parallel exploration / implementation / review (`subagent_spawn`); manage them like a chat right in the left panel: view live output, inject follow-ups (steer), abort, dismiss. In-memory sessions — they never touch the history / resume list, and can be nested.
74
- - **Subagent templates** — configure reusable presets in Settings → Subagent templates: a role system prompt (append or replace) plus skills & extensions whitelists. The AI picks one via the `subagent_templates` tool and `subagent_spawn(template="…")`, or spawns without one (main-session default config). Disabled templates stay in the panel for re-enabling but become invisible to the AI tools (can't be listed or picked). Templates are shared globally across browser clients (`<dataDir>/subagent-templates.json`). Six built-in templates (review / implement / research / scout / audit / delegate, adapted from the pi-subagents community projects) seed the list on first run — marked 「Built-in」, editable and deletable like any other.
75
-
76
- ### 🖼️ Files, images & attachments
77
-
78
- - Three attachment modes: `inline` (≤12 KB), `reference` (path only), `lines` (selected ranges) — over-limit ones degrade automatically.
79
- - Paste / drag-drop / upload images — resized client-side and sent as image content when the model supports vision (warning otherwise).
80
- - **Vision bridge** — when the current model is text-only, images are transcribed into text evidence by an auto-discovered vision model (cached per batch; model & on/off configurable in Settings).
81
- - Attach arbitrary files without a workspace path — stored in a global uploads dir, inlined when small, referenced by absolute path otherwise.
82
- - File preview — line numbers, click/drag/Shift selection (add to chat as `lines`), GBK fallback decoding, binary hex view, media preview over HTTP with Range support, and a download button.
83
- - Live file tree — the server watches the listed directory (`fs.watch`) and re-lists on change; oversized directories show a truncation warning.
84
-
85
- ### 🖥️ Terminal & Git
86
-
87
- - Built-in terminal (xterm.js + node-pty) with per-client PTY management; Windows auto-selects Git Bash (busybox fallback).
88
- - **Source control (Git) panel** — status / branch / diff / untracked files via a hidden query terminal; commit, switch branch, push and pull run in the visible terminal and auto-switch to the terminal view.
89
-
90
- ### 🎛️ Models & settings
91
-
92
- - Theme switching — pick a theme in the top bar; themes are pure `:root` palette overrides on top of the single layout stylesheet (default dark + bundled light/dark palettes). See [Themes](#themes) for how to add your own or contribute one.
93
- - Model management — edit `models.json` in the UI and set per-provider API keys (keys/headers never leave the server).
94
- - Thinking level per model (only the levels the model actually supports are shown).
95
- - First-run setup wizard.
96
- - Settings panel — system prompt (append or replace), toggle skills/extensions on/off with immediate effect, save/apply/delete settings presets, and vision-bridge model & switch.
97
-
98
- ### 🎯 Goal mode
99
-
100
- - Goal bar — set a target with a review model, max rounds and a lock switch.
101
- - Goal wizard (**AI Refine**) — turns a raw request into a concrete goal through a guided questionnaire.
102
- - Automatic review loop — after each turn an independent review session checks the goal against the final text and `git diff HEAD`; on fail the feedback is injected as steer until it passes (or the round cap is hit).
103
-
104
- ### 🤖 DeepSeek Harness engine
105
-
106
- - **Switchable engine** — `PI_WEB_ENGINE=pi|dsh` (default `pi`). The pi engine runs the agent in-process via the pi SDK; the **DSH engine** runs the official [`@deepseek-ai/dsh`](https://github.com/deepseek-ai/dsh) (DeepSeek Harness) runtime as a subprocess. `/api/health` reports `engine`; the footer shows a DSH badge.
107
- - **Same wire protocol** — the DSH engine implements the same WebSocket protocol, so goal mode, SCM, background tasks, settings, plugins, terminals, message-delta & snapshots all work identically.
108
- - **Native goal machinery** — DSH's own goal state machine + round-driver auto-continues rounds; the model judges completion/blocked (no separate review session). The goal wizard drives it via the model's `ask_user_question`.
109
- - **Real image blocks** — photos are sent as true image content to vision-capable DeepSeek models (e.g. `deepseek-v4-flash-vision-exp`); text-only models get a text-transcription bridge instead.
110
- - **Question dialog** — the model's `ask_user_question` surfaces as a browser dialog (single/multi-select + free text) with queueing and a countdown.
111
- - **Tools & MCP bridge** — plugin AI tools and external MCP servers (`mcp.json`) are bridged into the DSH runtime, so the DSH model can call them (executed server-side).
112
- - **Skill enable/disable** — the DSH skill catalog is exposed in Settings; disabling a skill filters it out of the model's view at runtime.
113
- - **DSH user patches** — drop `.yml` Cordis patches into `<dataDir>/dsh-patches/` to extend the runtime and reload from Settings.
114
-
115
- ### ⚙️ Background tasks
116
-
117
- - Background-task panel — servers launched by the agent are detected via port snapshots and listed (port/pid/name); stop one or kill all.
118
- - Tool watchdog — a tool call running over 20 minutes is aborted automatically.
119
- - **Stop bash command only** — abort a running bash tool without killing the conversation.
120
-
121
- ### 🛡️ Safety & operations
122
-
123
- - Loopback-only by default; set `PI_WEB_HOST=0.0.0.0` for LAN / containers.
124
- - WebSocket Origin/Host same-authority check — cross-origin pages are rejected (403); `PI_WEB_ALLOW_ORIGINS` whitelist for reverse proxies.
125
- - Quiesce drain mode via a local control socket (`server status|quiesce|unquiesce`).
126
- - Credentials stay server-side — provider headers are never sent to the browser.
127
- - Sound alerts, Chinese/English UI, and a recent-projects list (click to switch workspace).
128
-
129
- ### 🚢 Deploy & update
130
-
131
- - Foreground, global npm install, Docker (docker-compose), macOS launchd, Linux systemd, Windows Task Scheduler, and a desktop shortcut (`server shortcut`).
132
- - In-app self-update — checks the npm registry, installs and auto-restarts the service.
133
-
134
-
135
- ## Screenshots
136
-
137
- <table>
138
- <tr>
139
- <td align="center"><img src="https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot1.png" alt="Settings panel"><br><sub>Settings panel</sub></td>
140
- <td align="center"><img src="https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot2.jpeg" alt="Built-in terminal"><br><sub>Built-in terminal</sub></td>
141
- </tr>
142
- <tr>
143
- <td align="center"><img src="https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot3.jpeg" alt="Chat interface"><br><sub>Chat interface</sub></td>
144
- <td align="center"><img src="https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot4.jpeg" alt="Git source control panel"><br><sub>Git source control panel</sub></td>
145
- </tr>
146
- </table>
147
-
148
-
149
- ## Install
150
-
151
- ```bash
152
- npm i -g pi-web-ui # global install (recommended)
153
- npx pi-web-ui # or run without installing (latest, starts on :8787)
154
- npm i -g . # or install the local checkout
155
- ```
156
-
157
- **npm ≥ 12?** npm 12+ blocks dependency install scripts by default (you'll see
158
- `npm warn install-scripts … blocked`). node-pty is a native module, so allow its
159
- script (the other two packages it lists are harmless no-ops — allowing them just
160
- silences the warning):
161
-
162
- ```bash
163
- npm i -g --allow-scripts=node-pty,@google/genai,protobufjs pi-web-ui@latest
164
- ```
165
-
166
-
167
- ## Quick start
168
-
169
- **Start (foreground)**
170
-
171
- ```bash
172
- pi-web-ui # foreground, http://localhost:8787
173
- ```
174
-
175
- **Start flags & environment variables** — every setting can be passed as a `--flag` on the command
176
- line **or** set as an environment variable (flag wins). Pick whichever you prefer:
177
-
178
- | Flag | Env var | Default | Purpose |
179
- | --- | --- | --- | --- |
180
- | `--port <n>` | `PI_WEB_PORT` | `8787` | HTTP port |
181
- | `--cwd <dir>` | `PI_WEB_CWD` | current dir | workspace root (read/write/terminal) |
182
- | `--data-dir <dir>` | `PI_WEB_DATA_DIR` | `~/.pi-web` | data dir (sessions, plugins, uploads) |
183
- | `--engine <pi\|dsh>` | `PI_WEB_ENGINE` | `pi` | agent engine; `--engine dsh` = DeepSeek Harness |
184
- | `--host <addr>` | `PI_WEB_HOST` | `127.0.0.1` | listen address (`0.0.0.0` for LAN/Docker) |
185
- | `--agent-dir <dir>` | `PI_CODING_AGENT_DIR` | `~/.pi/agent` | pi config dir (auth.json, models, skills) |
186
- | _env only_ | `PI_WEB_TOKEN` | empty | optional shared auth token |
187
- | _env only_ | `PI_WEB_DSH_*` | — | dsh runtime, patches & debug settings |
188
-
189
- The two are equivalent — pick one:
190
-
191
- ```bash
192
- pi-web-ui --engine dsh --port 9000 --cwd /path/to/project
193
- PI_WEB_ENGINE=dsh PI_WEB_PORT=9000 PI_WEB_CWD=/path/to/project pi-web-ui
194
- ```
195
-
196
- For the DSH engine also install the runtime (`npm i -g @deepseek-ai/dsh@0.1.1-rc.2`) and set a
197
- DeepSeek API key (read from `~/.pi/agent/auth.json`, set in the provider/API-key panel).
198
-
199
- **Stop**
200
-
201
- - **Foreground**: press `Ctrl+C` in the terminal running it.
202
- - **As a service**: `pi-web-ui server stop` (stops the instance; auto-start stays until `server uninstall`).
203
-
204
- **Update**
205
-
206
- ```bash
207
- npm i -g pi-web-ui@latest # upgrade to the latest published version
208
- pi-web-ui server restart # restart the service to apply it (foreground: restart manually)
209
- ```
210
-
211
- **Uninstall**
212
-
213
- ```bash
214
- npm uninstall -g pi-web-ui
215
- ```
216
-
217
- Uninstalling does **not** delete your chats — session data lives in
218
- `<cwd>/.pi-web` (or `PI_WEB_DATA_DIR`) and survives uninstall/upgrade.
219
-
220
-
221
- ## System service
222
-
223
- ```bash
224
- pi-web-ui server install --port 9000 --cwd /path/to/project # install + start
225
- pi-web-ui server status # running? auto-start?
226
- pi-web-ui server restart # restart (applies config/version changes)
227
- pi-web-ui server stop # stop (auto-start stays)
228
- pi-web-ui server start # start again
229
- pi-web-ui server uninstall # remove the service entirely
230
- pi-web-ui server shortcut # desktop one-click launch icon
231
- pi-web-ui server quiesce # drain: refuse NEW chats/messages, let running ones finish
232
- pi-web-ui server unquiesce # reopen admission
233
- ```
234
-
235
- `server status` also shows live stats via a local control socket (version,
236
- PID, quiesce state, connected browsers, running conversations) — the same
237
- socket drives `quiesce`/`unquiesce`.
238
-
239
- - **macOS** → launchd agent (no sudo), logs to `/tmp/pi-web-ui.log` / `.err`
240
- - **Linux** → systemd unit (`systemctl enable --now`), logs via `journalctl -u pi-web-ui -f`
241
- - **Windows** → Task Scheduler logon task (hidden PowerShell window, no black console)
242
-
243
- Options: `--port` (default 8787), `--cwd` (workspace), `--data-dir` (sessions),
244
- `--engine <pi|dsh>`, `--host`, `--agent-dir`, `--name` (custom service name). Rerunning
245
- `server install` with new options regenerates the config and restarts the service — that's how
246
- you change its port/cwd/engine. `--engine` / `--host` / `--agent-dir` are baked into the service
247
- automatically; env-only vars (`PI_WEB_TOKEN`, `PI_WEB_DSH_*`) must be added to the service config
248
- by hand. See the [start flags table](#quick-start) above.
249
-
250
- ```bash
251
- pi-web-ui server install --engine dsh --port 9000 --cwd /path/to/project
252
- ```
253
-
254
-
255
- ## Plugins
256
-
257
- Plugins are optional UI components (extra top-bar tabs backed by their own
258
- client view, optionally with a server-side entry and agent tools). They live in
259
- your **data-dir plugins folder** (`<dataDir>/plugins/<id>/`, default
260
- `~/.pi-web/plugins/`) — a plugin is simply a directory containing
261
- `manifest.json`, an optional server entry (`index.mjs`) and an optional view
262
- entry (`client/entry.mjs`). No plugin directories = no plugins, nothing shows
263
- up in the UI.
264
-
265
- ### Plugin catalog
266
-
267
- These plugins ship in this repository (`plugins/<id>/`) and can be installed
268
- straight from GitHub:
269
-
270
- | Plugin | What it does |
271
- | --- | --- |
272
- | 📬 [webmail](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/webmail) | IMAP inbox browsing / search / read / mark / delete + SMTP sending, new-mail notifications, and an optional "allow AI to manage my mailbox" switch (six `mail_*` agent tools). Auto-installs its npm deps on first activation. |
273
- | 🗄️ [db-client](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/db-client) | Database workbench: connection manager + schema tree for MySQL / PostgreSQL / SQLite / SQL Server / MongoDB / Redis — table structure, paginated data with sorting, SQL editor, and row editing. Drivers auto-install on first use. |
274
- | 📝 [vscode-editor](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/vscode-editor) | VS Code-like workbench: multi-root file tree (local + SSH hosts), CodeMirror multi-tab editor, Remote-SSH remote file browsing/editing, draggable multi-terminal panel (xterm.js), SFTP sync & upload/download to your computer. Auto-installs `ssh2`. |
275
- | 📬 [demo-mailbox](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/demo-mailbox) | Minimal example plugin demonstrating the server entry + client view + two-way message protocol. Doubles as the plugin test fixture — start here if you want to write your own. |
276
-
277
- Example — install the webmail plugin:
278
-
279
- ```bash
280
- pi-web-ui install https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/webmail
281
- ```
282
-
283
- Each plugin's directory in the repo has its own `README.md` with full feature
284
- lists, configuration and per-plugin caveats.
285
-
286
- ### Installing
287
-
288
- From GitHub (any of these source forms):
289
-
290
- ```bash
291
- pi-web-ui install owner/repo # shorthand
292
- pi-web-ui install https://github.com/owner/repo # full URL (.git optional)
293
- pi-web-ui install https://github.com/o/r/tree/dev/sub/dir # branch + subdirectory inside the repo
294
- pi-web-ui install owner/repo#v1.2 # pin a branch/tag (#suffix works on any form above)
295
- pi-web-ui install /path/to/plugin-dir # local directory (for development)
296
- ```
297
-
298
- Useful options:
299
-
300
- - `--name <id>` — custom plugin id / directory name (defaults to the repo or
301
- subdirectory name; letters/digits/`-`/`_` only).
302
- - `--force` — overwrite an existing installation. Your plugin's local
303
- `config.json` (credentials etc.) is preserved across upgrades.
304
- - `--data-dir <dir>` — override the data dir (default `~/.pi-web`).
305
-
306
- The CLI clones the repo (shallow; falls back to a tarball download without
307
- git), locates the `manifest.json` (including inside subdirectories) and copies
308
- the plugin into `<dataDir>/plugins/<id>/`.
309
-
310
- **No git? No network?** You can also just copy a plugin directory into
311
- `~/.pi-web/plugins/` by hand — same result.
312
-
313
- ### Updating
314
-
315
- Re-run `install` against the same source with `--force`:
316
-
317
- ```bash
318
- # example: update the webmail plugin to the latest version in the repo
319
- pi-web-ui install https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/webmail --force
320
- ```
321
-
322
- - The upgrade preserves the plugin's local `config.json` automatically.
323
- - Plugins that store other local state inside their directory (e.g. db-client's
324
- `db-connections.json`, vscode-editor's `ssh-hosts.json`) are **not** covered
325
- by that preservation — back those up before a forced reinstall.
326
- - Refresh the browser afterwards; no server restart needed.
327
-
328
- ### Activating
329
-
330
- If the server is running, just **refresh the browser** — new plugins are picked
331
- up on attach without a restart. If it isn't, they load on next start. Each
332
- plugin appears as a tab (🧩 or its own icon) in the top bar.
333
-
334
- ### Listing / disabling / uninstalling
335
-
336
- ```bash
337
- pi-web-ui plugins # list installed plugins (id / name / version / description)
338
- pi-web-ui uninstall <id> # remove a plugin
339
- ```
340
-
341
- - To temporarily hide a plugin without uninstalling, use the **Settings panel
342
- (⚙) → UI plugins** switches — stored per client, purely visual, no restart
343
- needed. Re-enable any time.
344
- - `uninstall` deletes the plugin directory; refresh the browser and its tab
345
- disappears. Plugin configuration written inside the plugin dir is removed
346
- too — back up `<dataDir>/plugins/<id>/config.json` first if you need it.
347
-
348
-
349
- ## Themes
350
-
351
- Each theme is a **pure `:root` palette override** — a small CSS file that only sets CSS variables (see the `:root` block in `web/src/styles.css` for the full variable list: base colors `--bg/--accent/--term-*` plus derived colors like `--tooltip-bg/--code-bg/--notice-*`). The layout lives ONLY in the bundled `web/src/styles.css`; picking a theme overrides the variables, so every theme works with every build and layout changes never touch themes. Built-in themes are generated by `node make-light-theme.mjs`.
352
-
353
- Built-in themes ship in the npm package (`themes/`, e.g. the bundled light theme). The theme picker lives in the top bar (🌞 icon); the current choice is stored per browser in `localStorage`.
354
-
355
- ### Using a theme
356
-
357
- Just pick it in the top bar — built-in and user themes are merged in the same menu. User themes win over built-ins on the same id.
358
-
359
- ### Providing a theme locally (no GitHub needed)
360
-
361
- Any CSS file dropped into your **data-dir themes folder** shows up in the theme menu automatically — no restart, no rebuild:
362
-
363
- 1. Find your data dir (default `~/.pi-web`, override with `PI_WEB_DATA_DIR`).
364
- 2. Create `<dataDir>/themes/` and drop your stylesheet in: e.g. `~/.pi-web/themes/my-theme.css`.
365
- 3. Reload the page and pick it in the top bar. The **file name (without `.css`)** is the theme id shown in the menu.
366
-
367
- ```
368
- ~/.pi-web/
369
- └── themes/
370
- └── my-theme.css # appears in the menu as "my-theme"
371
- ```
372
-
373
- Easiest way to write one: copy a built-in palette (e.g. `themes/white.css` from the source repo) and change the `:root` colors — list every variable you want to override; unlisted ones fall back to the dark defaults in `styles.css`. Notes:
374
-
375
- - The **terminal follows the theme** — set the `--term-*` variables (terminal ANSI palette + `--term-bg`) in your `:root` and both the xterm canvas and its padded container adapt automatically (see the defaults in `styles.css`).
376
- - Syntax-highlight colors (`highlight.js`'s `github-dark.css` is bundled) must be overridden in your theme file or code will be unreadable on light themes — see the `.hljs` overrides at the bottom of `themes/white.css` for the pattern (dark themes can skip it).
377
- - Theme ids must match `^[A-Za-z0-9_-]+$` (no dots/slashes — path-traversal guard on the server).
378
-
379
- ### Contributing a theme to the repository (GitHub)
380
-
381
- Want your theme shipped to everyone? Open a pull request at [github.com/xing-shuyin/pi-web-ui](https://github.com/xing-shuyin/pi-web-ui):
382
-
383
- 1. Fork the repo and clone it.
384
- 2. Create your theme as `themes/<id>.css` — a pure `:root` palette. Copy `themes/white.css` (or `themes/cyberpunk.css` for a dark palette) as the starting template.
385
- 3. Verify locally: run `npm run dev`, then use the top bar theme picker — your theme must be listed and render correctly (chat cards, code blocks, tool-call cards, git/terminal panels).
386
- 4. Regenerate all built-in themes with `node make-light-theme.mjs` when you changed the variable list in `styles.css`.
387
- 5. Commit (`git add themes/<id>.css`) and open the PR. The `themes/` folder is already in the npm package `files` whitelist, so once merged and released, `npm i -g pi-web-ui` will ship your theme to everyone.
388
-
389
- Rules for merged themes: the file must be a single CSS file, set the `--term-*` variables for a readable terminal, and override `.hljs` syntax colors for readable code on light themes.
390
-
391
-
392
- ## Security
393
-
394
- - **Loopback-only by default** — the server binds `127.0.0.1` and is not
395
- reachable from the network unless you explicitly set `PI_WEB_HOST=0.0.0.0`
396
- (e.g. LAN access, Docker port mapping — the compose file sets it for you).
397
- - **WebSocket origin check** — browser pages connecting to `/ws` must present
398
- an `Origin` whose hostname **and port** match the request `Host`;
399
- cross-origin pages are rejected with 403. Non-browser clients (no `Origin`)
400
- are unaffected. Add `PI_WEB_ALLOW_ORIGINS=http://your-host:port` for
401
- reverse-proxy setups.
402
- - **Quiesce** — `server quiesce` refuses new prompts/forks/session resumes
403
- until you `server unquiesce`; in-flight runs finish cleanly (useful before
404
- upgrades/backups).
405
- - **Credentials stay server-side** — provider `headers` (which may carry
406
- `Authorization` / API keys) are never sent to the browser; the model
407
- management UI edits everything else and the server preserves the headers.
408
-
409
-
410
- ## Reverse proxy (nginx)
411
-
412
- Serve pi-web-ui behind nginx on the same host (it binds loopback only, so a
413
- same-machine reverse proxy is the supported remote-access path — no
414
- `PI_WEB_HOST=0.0.0.0` needed):
415
-
416
- ```nginx
417
- # pi-web-ui on 127.0.0.1:8787, exposed as https://your-host/pi/
418
- server {
419
- listen 443 ssl;
420
- server_name your-host;
421
- # ssl_certificate ... / ssl_certificate_key ...
422
-
423
- # App entry at a sub-path (strips the /pi/ prefix)
424
- location /pi/ {
425
- proxy_pass http://127.0.0.1:8787/;
426
- proxy_http_version 1.1;
427
- # $http_host keeps the port — the server's origin check compares the
428
- # full authority (hostname AND port). $host would drop it and get 403.
429
- proxy_set_header Host $http_host;
430
- proxy_set_header X-Real-IP $remote_addr;
431
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
432
- proxy_set_header X-Forwarded-Proto $scheme;
433
- }
434
-
435
- # WebSocket — MUST forward Host identically or the upgrade is 403'd
436
- # (page loads, but chat/terminal keep reconnecting)
437
- location /ws {
438
- proxy_pass http://127.0.0.1:8787;
439
- proxy_http_version 1.1;
440
- proxy_set_header Host $http_host;
441
- proxy_set_header Upgrade $http_upgrade;
442
- proxy_set_header Connection "upgrade";
443
- proxy_read_timeout 3600s;
444
- proxy_send_timeout 3600s;
445
- }
446
-
447
- # Absolute-path assets/API the built frontend requests (root, not /pi/)
448
- location /assets/ { proxy_pass http://127.0.0.1:8787; }
449
- location = /favicon.svg { proxy_pass http://127.0.0.1:8787; }
450
- location = /favicon-streaming.svg { proxy_pass http://127.0.0.1:8787; }
451
- location = /api/file { proxy_pass http://127.0.0.1:8787; }
452
- location = /api/health { proxy_pass http://127.0.0.1:8787; }
453
- }
454
- ```
455
-
456
- Key points:
457
-
458
- - **`Host` must be `$http_host`** (keeps the port) on both `/pi/` and `/ws` —
459
- the origin check compares hostname **and** port. `proxy_set_header Host $host`
460
- or leaving it unset (defaults to the upstream `127.0.0.1:8787`) both fail with 403.
461
- - **Same-origin works automatically**: as long as the browser's `Origin` equals
462
- the forwarded `Host` (it does through a plain proxy), no
463
- `PI_WEB_ALLOW_ORIGINS` is needed. Only set it when the browser origin differs
464
- from the Host the server sees (e.g. a TLS-terminating proxy that changes the
465
- port).
466
- - **No `proxy_protocol` unless you really need real client IPs**: it makes
467
- nginx reject every connection that does not send a PROXY header, which
468
- breaks direct LAN access and any non-frp clients. With frp, drop
469
- `transport.proxyProtocolVersion` from the proxy config unless nginx listens
470
- with `proxy_protocol` too.
471
- - **LAN access without a proxy**: just set `PI_WEB_HOST=0.0.0.0` (and a
472
- firewall rule) — or put the whole server block above on port 80/443.
473
-
474
- Full working example (with an frp tunnel): `deploy/nginx-subpath.conf`.
475
-
476
-
477
- ## Contribute
478
-
479
- pi-web-ui is a small open-source project — **your contributions are what make it grow**. Code, plugins, themes, docs, translations, ideas: everything is welcome, and every merged PR ships to all users with the next `npm publish`. ❤️
480
-
481
- | Way to contribute | How to get started |
482
- | --- | --- |
483
- | 🧩 **Write a plugin** | Build your own UI tab + agent tools. Copy `plugins/demo-mailbox` as the minimal template (it doubles as the test fixture), develop locally, then either open a PR to ship it in the [catalog](#plugin-catalog) or [publish it standalone](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins). |
484
- | 🎨 **Contribute a theme** | Copy `themes/white.css` (light) or `themes/cyberpunk.css` (dark) as a pure-palette template, tweak the `:root` palette + `--term-*` + `.hljs`, verify with `npm run dev`, then open a PR — full walkthrough in [Contributing a theme](#contributing-a-theme-to-the-repository-github). |
485
- | 💻 **Fix a bug / add a feature** | Look for [open issues](https://github.com/xing-shuyin/pi-web-ui/issues) or propose something new. Fork → branch → PR. Keep the code conventions in `AGENTS.md` (tabs, i18n keys in both languages, protocol changes in `server/protocol.ts`). |
486
- | 📖 **Docs & translations** | Improve the READMEs, write plugin docs, fix typos, or help translate the UI / docs into more languages. |
487
- | 💡 **Ideas & feedback** | Open an [issue](https://github.com/xing-shuyin/pi-web-ui/issues) or start a [discussion](https://github.com/xing-shuyin/pi-web-ui/discussions) — feature requests, bug reports, UI polish ideas, deployment experience reports. |
488
-
489
- **Before opening a PR**, a quick sanity pass keeps reviewers happy:
490
-
491
- - `npm run format` — prettier formatting (tabs, width 120; CI checks it).
492
- - `npm run lint` — oxlint (unused vars, risky patterns; CI runs it).
493
- - `npm run check:protocol` + `npm test` — protocol sync and unit tests.
494
- - `npm run typecheck` — no type errors.
495
- - `npm run build` — both frontend and backend compile.
496
- - For protocol changes: add branches in both `server/index.ts` and `web/src/use-chat.ts` (see the "Protocol single source" note in `AGENTS.md`).
497
-
498
- > Enjoying pi-web-ui? Give the repo a ⭐ — it helps others find it. And if you
499
- > built something cool on top (plugin, theme, deployment recipe), tell us — we
500
- > love showcasing community work.
501
-
502
-
503
- ## License
504
-
1
+ <div align="center">
2
+
3
+ # 💬 pi-web-ui
4
+
5
+ **English** | [Chinese (Simplified)](https://github.com/xing-shuyin/pi-web-ui/blob/main/README.zh-CN.md)
6
+
7
+ *The polished browser cockpit for the [pi coding agent](https://pi.dev).*
8
+
9
+ <p>
10
+ <a href="https://www.npmjs.com/package/pi-web-ui"><img src="https://img.shields.io/npm/v/pi-web-ui?color=cb3837&logo=npm&label=pi-web-ui" alt="npm version"></a>
11
+ <a href="https://nodejs.org/"><img src="https://img.shields.io/node/v/pi-web-ui?logo=node.js&logoColor=white" alt="Node.js"></a>
12
+ <a href="LICENSE"><img src="https://img.shields.io/github/license/xing-shuyin/pi-web-ui" alt="License"></a>
13
+ <a href="https://www.npmjs.com/package/pi-web-ui"><img src="https://img.shields.io/npm/dm/pi-web-ui?label=downloads" alt="npm downloads"></a>
14
+ <a href="https://github.com/xing-shuyin/pi-web-ui/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/xing-shuyin/pi-web-ui/ci.yml?branch=main&label=CI" alt="CI status"></a>
15
+ <a href="https://github.com/xing-shuyin/pi-web-ui/stargazers"><img src="https://img.shields.io/github/stars/xing-shuyin/pi-web-ui?style=social" alt="GitHub stars"></a>
16
+ <a href="https://github.com/xing-shuyin/pi-web-ui/fork"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen?style=flat" alt="PRs welcome"></a>
17
+ </p>
18
+
19
+ Stream conversations, inspect tool calls, manage files, and run your workspace — all from one place.
20
+
21
+ ![Git source control panel](https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot4.jpeg)
22
+
23
+ </div>
24
+
25
+ A web chat interface for the [pi coding agent](https://pi.dev). The agent runs
26
+ **in-process** via the pi SDK and streams events to the browser over WebSocket:
27
+ thinking blocks, tool calls, file trees, a built-in terminal, model management,
28
+ theme switching, and a full settings panel — tuned for daily development.
29
+
30
+ > **Requirements** — Node.js ≥ 22.19 and a configured pi install.
31
+
32
+ ## More from the author
33
+
34
+ > **Building with DSH?**
35
+ >
36
+ > [**dsh-ui-tools**](https://github.com/xing-shuyin/dsh-ui-tools) is the author's companion project for building and extending UI tools in the DSH ecosystem.
37
+
38
+ ## ✨ Highlights
39
+
40
+ | 💬 **Chat that works like you do** | 🖼️ **Files & images** | 🧩 **Extensible by design** | 🔒 **Private by default** |
41
+ | --- | --- | --- | --- |
42
+ | Streaming replies, steer & follow-up queueing, slash commands, multiple conversations per project, edit-&-re-ask. | Attach files, paste images, ask about pictures (vision bridge), preview anything with GBK fallback. | Drop-in UI **plugins** (extra top-bar tabs + agent tools) and standalone **themes** — no rebuild, no restart. | Loopback-only, credential-safe: provider keys & headers never reach the browser. |
43
+
44
+ ## 📚 Table of Contents
45
+
46
+ - 🚀 [Features](#features)
47
+ - 🖼️ [Screenshots](#screenshots)
48
+ - 📦 [Install](#install)
49
+ - ⚡ [Quick start](#quick-start)
50
+ - 🖥️ [System service](#system-service)
51
+ - 🧩 [Plugins](#plugins)
52
+ - 🎨 [Themes](#themes)
53
+ - 🔒 [Security](#security)
54
+ - 🌐 [Reverse proxy (nginx)](#reverse-proxy-nginx)
55
+ - 🤝 [Contribute](#contribute)
56
+ - 📄 [License](#license)
57
+
58
+ ## Features
59
+
60
+ ### 💬 Chat
61
+
62
+ - **Streaming agent chat over WebSocket** — the pi SDK runs in-process; events are pushed as snapshots (60 ms throttled) and the browser renders them.
63
+ - Thinking blocks, tool-call cards and bash outputs with live status (running → finished · waiting for the model · duration).
64
+ - **Steer (follow-up queueing)** — send a follow-up while the agent is replying; it is queued and injected as soon as the current turn's tool calls settle (the "Interrupt" equivalent of the pi CLI).
65
+ - **Slash commands** — `/` opens a command picker (built-in / extension / template / skill); built-ins include `/new /model /compact /cwd /thinking /resume`, plus `/help` (command list) and `/copy` (copy last reply).
66
+ - **Multiple conversations per project** — each conversation gets its own agent runtime and keeps running in the background after you switch away; the "Running conversations" list shows stream progress and lets you switch back.
67
+ - **Edit & re-ask** — fork any past question into a new branch and re-prompt; the original conversation stays untouched.
68
+ - Long threads auto-collapse messages older than 30 into lazy summary rows (click to expand).
69
+ - Question navigation — a floating rail plus per-question tags to jump between questions.
70
+
71
+ ### 🤖 Subagents & templates
72
+
73
+ - **First-party subagents** — spawn independent background conversations for parallel exploration / implementation / review (`subagent_spawn`); manage them like a chat right in the left panel: view live output, inject follow-ups (steer), abort, dismiss. In-memory sessions — they never touch the history / resume list, and can be nested.
74
+ - **Subagent templates** — configure reusable presets in Settings → Subagent templates: a role system prompt (append or replace) plus skills & extensions whitelists. The AI picks one via the `subagent_templates` tool and `subagent_spawn(template="…")`, or spawns without one (main-session default config). Disabled templates stay in the panel for re-enabling but become invisible to the AI tools (can't be listed or picked). Templates are shared globally across browser clients (`<dataDir>/subagent-templates.json`). Six built-in templates (review / implement / research / scout / audit / delegate, adapted from the pi-subagents community projects) seed the list on first run — marked 「Built-in」, editable and deletable like any other.
75
+
76
+ ### 🖼️ Files, images & attachments
77
+
78
+ - Three attachment modes: `inline` (≤12 KB), `reference` (path only), `lines` (selected ranges) — over-limit ones degrade automatically.
79
+ - Paste / drag-drop / upload images — resized client-side and sent as image content when the model supports vision (warning otherwise).
80
+ - **Vision bridge** — when the current model is text-only, images are transcribed into text evidence by an auto-discovered vision model (cached per batch; model & on/off configurable in Settings).
81
+ - Attach arbitrary files without a workspace path — stored in a global uploads dir, inlined when small, referenced by absolute path otherwise.
82
+ - File preview — line numbers, click/drag/Shift selection (add to chat as `lines`), GBK fallback decoding, binary hex view, media preview over HTTP with Range support, and a download button.
83
+ - Live file tree — the server watches the listed directory (`fs.watch`) and re-lists on change; oversized directories show a truncation warning.
84
+
85
+ ### 🖥️ Terminal & Git
86
+
87
+ - Built-in terminal (xterm.js + node-pty) with per-client PTY management; Windows auto-selects Git Bash (busybox fallback).
88
+ - **Source control (Git) panel** — status / branch / diff / untracked files via a hidden query terminal; commit, switch branch, push and pull run in the visible terminal and auto-switch to the terminal view.
89
+
90
+ ### 🎛️ Models & settings
91
+
92
+ - Theme switching — pick a theme in the top bar; themes are pure `:root` palette overrides on top of the single layout stylesheet (default dark + bundled light/dark palettes). See [Themes](#themes) for how to add your own or contribute one.
93
+ - Model management — edit `models.json` in the UI and set per-provider API keys (keys/headers never leave the server).
94
+ - Thinking level per model (only the levels the model actually supports are shown).
95
+ - First-run setup wizard.
96
+ - Settings panel — system prompt (append or replace), toggle skills/extensions on/off with immediate effect, save/apply/delete settings presets, and vision-bridge model & switch.
97
+
98
+ ### 🎯 Goal mode
99
+
100
+ - Goal bar — set a target with a review model, max rounds and a lock switch.
101
+ - Goal wizard (**AI Refine**) — turns a raw request into a concrete goal through a guided questionnaire.
102
+ - Automatic review loop — after each turn an independent review session checks the goal against the final text and `git diff HEAD`; on fail the feedback is injected as steer until it passes (or the round cap is hit).
103
+
104
+ ### 🤖 DeepSeek Harness engine
105
+
106
+ - **Switchable engine** — `PI_WEB_ENGINE=pi|dsh` (default `pi`). The pi engine runs the agent in-process via the pi SDK; the **DSH engine** runs the official [`@deepseek-ai/dsh`](https://github.com/deepseek-ai/dsh) (DeepSeek Harness) runtime as a subprocess. `/api/health` reports `engine`; the footer shows a DSH badge.
107
+ - **Same wire protocol** — the DSH engine implements the same WebSocket protocol, so goal mode, SCM, background tasks, settings, plugins, terminals, message-delta & snapshots all work identically.
108
+ - **Native goal machinery** — DSH's own goal state machine + round-driver auto-continues rounds; the model judges completion/blocked (no separate review session). The goal wizard drives it via the model's `ask_user_question`.
109
+ - **Real image blocks** — photos are sent as true image content to vision-capable DeepSeek models (e.g. `deepseek-v4-flash-vision-exp`); text-only models get a text-transcription bridge instead.
110
+ - **Question dialog** — the model's `ask_user_question` surfaces as a browser dialog (single/multi-select + free text) with queueing and a countdown.
111
+ - **Tools & MCP bridge** — plugin AI tools and external MCP servers (`mcp.json`) are bridged into the DSH runtime, so the DSH model can call them (executed server-side).
112
+ - **Skill enable/disable** — the DSH skill catalog is exposed in Settings; disabling a skill filters it out of the model's view at runtime.
113
+ - **DSH user patches** — drop `.yml` Cordis patches into `<dataDir>/dsh-patches/` to extend the runtime and reload from Settings.
114
+
115
+ ### ⚙️ Background tasks
116
+
117
+ - Background-task panel — servers launched by the agent are detected via port snapshots and listed (port/pid/name); stop one or kill all.
118
+ - Tool watchdog — a tool call running over 20 minutes is aborted automatically.
119
+ - **Stop bash command only** — abort a running bash tool without killing the conversation.
120
+
121
+ ### 🛡️ Safety & operations
122
+
123
+ - Loopback-only by default; set `PI_WEB_HOST=0.0.0.0` for LAN / containers.
124
+ - WebSocket Origin/Host same-authority check — cross-origin pages are rejected (403); `PI_WEB_ALLOW_ORIGINS` whitelist for reverse proxies.
125
+ - Quiesce drain mode via a local control socket (`server status|quiesce|unquiesce`).
126
+ - Credentials stay server-side — provider headers are never sent to the browser.
127
+ - Sound alerts, Chinese/English UI, and a recent-projects list (click to switch workspace).
128
+
129
+ ### 🚢 Deploy & update
130
+
131
+ - Foreground, global npm install, Docker (docker-compose), macOS launchd, Linux systemd, Windows Task Scheduler, and a desktop shortcut (`server shortcut`).
132
+ - In-app self-update — checks the npm registry, installs and auto-restarts the service.
133
+
134
+
135
+ ## Screenshots
136
+
137
+ <table>
138
+ <tr>
139
+ <td align="center"><img src="https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot1.png" alt="Settings panel"><br><sub>Settings panel</sub></td>
140
+ <td align="center"><img src="https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot2.jpeg" alt="Built-in terminal"><br><sub>Built-in terminal</sub></td>
141
+ </tr>
142
+ <tr>
143
+ <td align="center"><img src="https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot3.jpeg" alt="Chat interface"><br><sub>Chat interface</sub></td>
144
+ <td align="center"><img src="https://raw.githubusercontent.com/xing-shuyin/pi-web-ui/main/assets/shot4.jpeg" alt="Git source control panel"><br><sub>Git source control panel</sub></td>
145
+ </tr>
146
+ </table>
147
+
148
+
149
+ ## Install
150
+
151
+ ```bash
152
+ npm i -g pi-web-ui # global install (recommended)
153
+ npx pi-web-ui # or run without installing (latest, starts on :8787)
154
+ npm i -g . # or install the local checkout
155
+ ```
156
+
157
+ **npm ≥ 12?** npm 12+ blocks dependency install scripts by default (you'll see
158
+ `npm warn install-scripts … blocked`). node-pty is a native module, so allow its
159
+ script (the other two packages it lists are harmless no-ops — allowing them just
160
+ silences the warning):
161
+
162
+ ```bash
163
+ npm i -g --allow-scripts=node-pty,@google/genai,protobufjs pi-web-ui@latest
164
+ ```
165
+
166
+
167
+ ## Quick start
168
+
169
+ **Start (foreground)**
170
+
171
+ ```bash
172
+ pi-web-ui # foreground, http://localhost:8787
173
+ ```
174
+
175
+ **Start flags & environment variables** — every setting can be passed as a `--flag` on the command
176
+ line **or** set as an environment variable (flag wins). Pick whichever you prefer:
177
+
178
+ | Flag | Env var | Default | Purpose |
179
+ | --- | --- | --- | --- |
180
+ | `--port <n>` | `PI_WEB_PORT` | `8787` | HTTP port |
181
+ | `--cwd <dir>` | `PI_WEB_CWD` | current dir | workspace root (read/write/terminal) |
182
+ | `--data-dir <dir>` | `PI_WEB_DATA_DIR` | `~/.pi-web` | data dir (sessions, plugins, uploads) |
183
+ | `--engine <pi\|dsh>` | `PI_WEB_ENGINE` | `pi` | agent engine; `--engine dsh` = DeepSeek Harness |
184
+ | `--host <addr>` | `PI_WEB_HOST` | `127.0.0.1` | listen address (`0.0.0.0` for LAN/Docker) |
185
+ | `--agent-dir <dir>` | `PI_CODING_AGENT_DIR` | `~/.pi/agent` | pi config dir (auth.json, models, skills) |
186
+ | _env only_ | `PI_WEB_TOKEN` | empty | optional shared auth token |
187
+ | _env only_ | `PI_WEB_DSH_*` | — | dsh runtime, patches & debug settings |
188
+
189
+ The two are equivalent — pick one:
190
+
191
+ ```bash
192
+ pi-web-ui --engine dsh --port 9000 --cwd /path/to/project
193
+ PI_WEB_ENGINE=dsh PI_WEB_PORT=9000 PI_WEB_CWD=/path/to/project pi-web-ui
194
+ ```
195
+
196
+ For the DSH engine also install the runtime (`npm i -g @deepseek-ai/dsh@0.1.1-rc.2`) and set a
197
+ DeepSeek API key (read from `~/.pi/agent/auth.json`, set in the provider/API-key panel).
198
+
199
+ **Stop**
200
+
201
+ - **Foreground**: press `Ctrl+C` in the terminal running it.
202
+ - **As a service**: `pi-web-ui server stop` (stops the instance; auto-start stays until `server uninstall`).
203
+
204
+ **Update**
205
+
206
+ ```bash
207
+ npm i -g pi-web-ui@latest # upgrade to the latest published version
208
+ pi-web-ui server restart # restart the service to apply it (foreground: restart manually)
209
+ ```
210
+
211
+ **Uninstall**
212
+
213
+ ```bash
214
+ npm uninstall -g pi-web-ui
215
+ ```
216
+
217
+ Uninstalling does **not** delete your chats — session data lives in
218
+ `<cwd>/.pi-web` (or `PI_WEB_DATA_DIR`) and survives uninstall/upgrade.
219
+
220
+
221
+ ## System service
222
+
223
+ ```bash
224
+ pi-web-ui server install --port 9000 --cwd /path/to/project # install + start
225
+ pi-web-ui server status # running? auto-start?
226
+ pi-web-ui server restart # restart (applies config/version changes)
227
+ pi-web-ui server stop # stop (auto-start stays)
228
+ pi-web-ui server start # start again
229
+ pi-web-ui server uninstall # remove the service entirely
230
+ pi-web-ui server shortcut # desktop one-click launch icon
231
+ pi-web-ui server quiesce # drain: refuse NEW chats/messages, let running ones finish
232
+ pi-web-ui server unquiesce # reopen admission
233
+ ```
234
+
235
+ `server status` also shows live stats via a local control socket (version,
236
+ PID, quiesce state, connected browsers, running conversations) — the same
237
+ socket drives `quiesce`/`unquiesce`.
238
+
239
+ - **macOS** → launchd agent (no sudo), logs to `/tmp/pi-web-ui.log` / `.err`
240
+ - **Linux** → systemd unit (`systemctl enable --now`), logs via `journalctl -u pi-web-ui -f`
241
+ - **Windows** → Task Scheduler logon task (hidden PowerShell window, no black console)
242
+
243
+ Options: `--port` (default 8787), `--cwd` (workspace), `--data-dir` (sessions),
244
+ `--engine <pi|dsh>`, `--host`, `--agent-dir`, `--name` (custom service name). Rerunning
245
+ `server install` with new options regenerates the config and restarts the service — that's how
246
+ you change its port/cwd/engine. `--engine` / `--host` / `--agent-dir` are baked into the service
247
+ automatically; env-only vars (`PI_WEB_TOKEN`, `PI_WEB_DSH_*`) must be added to the service config
248
+ by hand. See the [start flags table](#quick-start) above.
249
+
250
+ ```bash
251
+ pi-web-ui server install --engine dsh --port 9000 --cwd /path/to/project
252
+ ```
253
+
254
+
255
+ ## Plugins
256
+
257
+ Plugins are optional UI components (extra top-bar tabs backed by their own
258
+ client view, optionally with a server-side entry and agent tools). They live in
259
+ your **data-dir plugins folder** (`<dataDir>/plugins/<id>/`, default
260
+ `~/.pi-web/plugins/`) — a plugin is simply a directory containing
261
+ `manifest.json`, an optional server entry (`index.mjs`) and an optional view
262
+ entry (`client/entry.mjs`). No plugin directories = no plugins, nothing shows
263
+ up in the UI.
264
+
265
+ ### Plugin catalog
266
+
267
+ These plugins ship in this repository (`plugins/<id>/`) and can be installed
268
+ straight from GitHub:
269
+
270
+ | Plugin | What it does |
271
+ | --- | --- |
272
+ | 📬 [webmail](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/webmail) | IMAP inbox browsing / search / read / mark / delete + SMTP sending, new-mail notifications, and an optional "allow AI to manage my mailbox" switch (six `mail_*` agent tools). Auto-installs its npm deps on first activation. |
273
+ | 🗄️ [db-client](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/db-client) | Database workbench: connection manager + schema tree for MySQL / PostgreSQL / SQLite / SQL Server / MongoDB / Redis — table structure, paginated data with sorting, SQL editor, and row editing. Drivers auto-install on first use. |
274
+ | 📝 [vscode-editor](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/vscode-editor) | VS Code-like workbench: multi-root file tree (local + SSH hosts), CodeMirror multi-tab editor, Remote-SSH remote file browsing/editing, draggable multi-terminal panel (xterm.js), SFTP sync & upload/download to your computer. Auto-installs `ssh2`. |
275
+ | 📬 [demo-mailbox](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/demo-mailbox) | Minimal example plugin demonstrating the server entry + client view + two-way message protocol. Doubles as the plugin test fixture — start here if you want to write your own. |
276
+
277
+ Example — install the webmail plugin:
278
+
279
+ ```bash
280
+ pi-web-ui install https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/webmail
281
+ ```
282
+
283
+ Each plugin's directory in the repo has its own `README.md` with full feature
284
+ lists, configuration and per-plugin caveats.
285
+
286
+ ### Installing
287
+
288
+ From GitHub (any of these source forms):
289
+
290
+ ```bash
291
+ pi-web-ui install owner/repo # shorthand
292
+ pi-web-ui install https://github.com/owner/repo # full URL (.git optional)
293
+ pi-web-ui install https://github.com/o/r/tree/dev/sub/dir # branch + subdirectory inside the repo
294
+ pi-web-ui install owner/repo#v1.2 # pin a branch/tag (#suffix works on any form above)
295
+ pi-web-ui install /path/to/plugin-dir # local directory (for development)
296
+ ```
297
+
298
+ Useful options:
299
+
300
+ - `--name <id>` — custom plugin id / directory name (defaults to the repo or
301
+ subdirectory name; letters/digits/`-`/`_` only).
302
+ - `--force` — overwrite an existing installation. Your plugin's local
303
+ `config.json` (credentials etc.) is preserved across upgrades.
304
+ - `--data-dir <dir>` — override the data dir (default `~/.pi-web`).
305
+
306
+ The CLI clones the repo (shallow; falls back to a tarball download without
307
+ git), locates the `manifest.json` (including inside subdirectories) and copies
308
+ the plugin into `<dataDir>/plugins/<id>/`.
309
+
310
+ **No git? No network?** You can also just copy a plugin directory into
311
+ `~/.pi-web/plugins/` by hand — same result.
312
+
313
+ ### Updating
314
+
315
+ Re-run `install` against the same source with `--force`:
316
+
317
+ ```bash
318
+ # example: update the webmail plugin to the latest version in the repo
319
+ pi-web-ui install https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/webmail --force
320
+ ```
321
+
322
+ - The upgrade preserves the plugin's local `config.json` automatically.
323
+ - Plugins that store other local state inside their directory (e.g. db-client's
324
+ `db-connections.json`, vscode-editor's `ssh-hosts.json`) are **not** covered
325
+ by that preservation — back those up before a forced reinstall.
326
+ - Refresh the browser afterwards; no server restart needed.
327
+
328
+ ### Activating
329
+
330
+ If the server is running, just **refresh the browser** — new plugins are picked
331
+ up on attach without a restart. If it isn't, they load on next start. Each
332
+ plugin appears as a tab (🧩 or its own icon) in the top bar.
333
+
334
+ ### Listing / disabling / uninstalling
335
+
336
+ ```bash
337
+ pi-web-ui plugins # list installed plugins (id / name / version / description)
338
+ pi-web-ui uninstall <id> # remove a plugin
339
+ ```
340
+
341
+ - To temporarily hide a plugin without uninstalling, use the **Settings panel
342
+ (⚙) → UI plugins** switches — stored per client, purely visual, no restart
343
+ needed. Re-enable any time.
344
+ - `uninstall` deletes the plugin directory; refresh the browser and its tab
345
+ disappears. Plugin configuration written inside the plugin dir is removed
346
+ too — back up `<dataDir>/plugins/<id>/config.json` first if you need it.
347
+
348
+
349
+ ## Themes
350
+
351
+ Each theme is a **pure `:root` palette override** — a small CSS file that only sets CSS variables (see the `:root` block in `web/src/styles.css` for the full variable list: base colors `--bg/--accent/--term-*` plus derived colors like `--tooltip-bg/--code-bg/--notice-*`). The layout lives ONLY in the bundled `web/src/styles.css`; picking a theme overrides the variables, so every theme works with every build and layout changes never touch themes. Built-in themes are generated by `node make-light-theme.mjs`.
352
+
353
+ Built-in themes ship in the npm package (`themes/`, e.g. the bundled light theme). The theme picker lives in the top bar (🌞 icon); the current choice is stored per browser in `localStorage`.
354
+
355
+ ### Using a theme
356
+
357
+ Just pick it in the top bar — built-in and user themes are merged in the same menu. User themes win over built-ins on the same id.
358
+
359
+ ### Providing a theme locally (no GitHub needed)
360
+
361
+ Any CSS file dropped into your **data-dir themes folder** shows up in the theme menu automatically — no restart, no rebuild:
362
+
363
+ 1. Find your data dir (default `~/.pi-web`, override with `PI_WEB_DATA_DIR`).
364
+ 2. Create `<dataDir>/themes/` and drop your stylesheet in: e.g. `~/.pi-web/themes/my-theme.css`.
365
+ 3. Reload the page and pick it in the top bar. The **file name (without `.css`)** is the theme id shown in the menu.
366
+
367
+ ```
368
+ ~/.pi-web/
369
+ └── themes/
370
+ └── my-theme.css # appears in the menu as "my-theme"
371
+ ```
372
+
373
+ Easiest way to write one: copy a built-in palette (e.g. `themes/white.css` from the source repo) and change the `:root` colors — list every variable you want to override; unlisted ones fall back to the dark defaults in `styles.css`. Notes:
374
+
375
+ - The **terminal follows the theme** — set the `--term-*` variables (terminal ANSI palette + `--term-bg`) in your `:root` and both the xterm canvas and its padded container adapt automatically (see the defaults in `styles.css`).
376
+ - Syntax-highlight colors (`highlight.js`'s `github-dark.css` is bundled) must be overridden in your theme file or code will be unreadable on light themes — see the `.hljs` overrides at the bottom of `themes/white.css` for the pattern (dark themes can skip it).
377
+ - Theme ids must match `^[A-Za-z0-9_-]+$` (no dots/slashes — path-traversal guard on the server).
378
+
379
+ ### Contributing a theme to the repository (GitHub)
380
+
381
+ Want your theme shipped to everyone? Open a pull request at [github.com/xing-shuyin/pi-web-ui](https://github.com/xing-shuyin/pi-web-ui):
382
+
383
+ 1. Fork the repo and clone it.
384
+ 2. Create your theme as `themes/<id>.css` — a pure `:root` palette. Copy `themes/white.css` (or `themes/cyberpunk.css` for a dark palette) as the starting template.
385
+ 3. Verify locally: run `npm run dev`, then use the top bar theme picker — your theme must be listed and render correctly (chat cards, code blocks, tool-call cards, git/terminal panels).
386
+ 4. Regenerate all built-in themes with `node make-light-theme.mjs` when you changed the variable list in `styles.css`.
387
+ 5. Commit (`git add themes/<id>.css`) and open the PR. The `themes/` folder is already in the npm package `files` whitelist, so once merged and released, `npm i -g pi-web-ui` will ship your theme to everyone.
388
+
389
+ Rules for merged themes: the file must be a single CSS file, set the `--term-*` variables for a readable terminal, and override `.hljs` syntax colors for readable code on light themes.
390
+
391
+
392
+ ## Security
393
+
394
+ - **Loopback-only by default** — the server binds `127.0.0.1` and is not
395
+ reachable from the network unless you explicitly set `PI_WEB_HOST=0.0.0.0`
396
+ (e.g. LAN access, Docker port mapping — the compose file sets it for you).
397
+ - **WebSocket origin check** — browser pages connecting to `/ws` must present
398
+ an `Origin` whose hostname **and port** match the request `Host`;
399
+ cross-origin pages are rejected with 403. Non-browser clients (no `Origin`)
400
+ are unaffected. Add `PI_WEB_ALLOW_ORIGINS=http://your-host:port` for
401
+ reverse-proxy setups.
402
+ - **Quiesce** — `server quiesce` refuses new prompts/forks/session resumes
403
+ until you `server unquiesce`; in-flight runs finish cleanly (useful before
404
+ upgrades/backups).
405
+ - **Credentials stay server-side** — provider `headers` (which may carry
406
+ `Authorization` / API keys) are never sent to the browser; the model
407
+ management UI edits everything else and the server preserves the headers.
408
+
409
+
410
+ ## Reverse proxy (nginx)
411
+
412
+ Serve pi-web-ui behind nginx on the same host (it binds loopback only, so a
413
+ same-machine reverse proxy is the supported remote-access path — no
414
+ `PI_WEB_HOST=0.0.0.0` needed):
415
+
416
+ ```nginx
417
+ # pi-web-ui on 127.0.0.1:8787, exposed as https://your-host/pi/
418
+ server {
419
+ listen 443 ssl;
420
+ server_name your-host;
421
+ # ssl_certificate ... / ssl_certificate_key ...
422
+
423
+ # App entry at a sub-path (strips the /pi/ prefix)
424
+ location /pi/ {
425
+ proxy_pass http://127.0.0.1:8787/;
426
+ proxy_http_version 1.1;
427
+ # $http_host keeps the port — the server's origin check compares the
428
+ # full authority (hostname AND port). $host would drop it and get 403.
429
+ proxy_set_header Host $http_host;
430
+ proxy_set_header X-Real-IP $remote_addr;
431
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
432
+ proxy_set_header X-Forwarded-Proto $scheme;
433
+ }
434
+
435
+ # WebSocket — MUST forward Host identically or the upgrade is 403'd
436
+ # (page loads, but chat/terminal keep reconnecting)
437
+ location /ws {
438
+ proxy_pass http://127.0.0.1:8787;
439
+ proxy_http_version 1.1;
440
+ proxy_set_header Host $http_host;
441
+ proxy_set_header Upgrade $http_upgrade;
442
+ proxy_set_header Connection "upgrade";
443
+ proxy_read_timeout 3600s;
444
+ proxy_send_timeout 3600s;
445
+ }
446
+
447
+ # Absolute-path assets/API the built frontend requests (root, not /pi/)
448
+ location /assets/ { proxy_pass http://127.0.0.1:8787; }
449
+ location = /favicon.svg { proxy_pass http://127.0.0.1:8787; }
450
+ location = /favicon-streaming.svg { proxy_pass http://127.0.0.1:8787; }
451
+ location = /api/file { proxy_pass http://127.0.0.1:8787; }
452
+ location = /api/health { proxy_pass http://127.0.0.1:8787; }
453
+ }
454
+ ```
455
+
456
+ Key points:
457
+
458
+ - **`Host` must be `$http_host`** (keeps the port) on both `/pi/` and `/ws` —
459
+ the origin check compares hostname **and** port. `proxy_set_header Host $host`
460
+ or leaving it unset (defaults to the upstream `127.0.0.1:8787`) both fail with 403.
461
+ - **Same-origin works automatically**: as long as the browser's `Origin` equals
462
+ the forwarded `Host` (it does through a plain proxy), no
463
+ `PI_WEB_ALLOW_ORIGINS` is needed. Only set it when the browser origin differs
464
+ from the Host the server sees (e.g. a TLS-terminating proxy that changes the
465
+ port).
466
+ - **No `proxy_protocol` unless you really need real client IPs**: it makes
467
+ nginx reject every connection that does not send a PROXY header, which
468
+ breaks direct LAN access and any non-frp clients. With frp, drop
469
+ `transport.proxyProtocolVersion` from the proxy config unless nginx listens
470
+ with `proxy_protocol` too.
471
+ - **LAN access without a proxy**: just set `PI_WEB_HOST=0.0.0.0` (and a
472
+ firewall rule) — or put the whole server block above on port 80/443.
473
+
474
+ Full working example (with an frp tunnel): `deploy/nginx-subpath.conf`.
475
+
476
+
477
+ ## Contribute
478
+
479
+ pi-web-ui is a small open-source project — **your contributions are what make it grow**. Code, plugins, themes, docs, translations, ideas: everything is welcome, and every merged PR ships to all users with the next `npm publish`. ❤️
480
+
481
+ | Way to contribute | How to get started |
482
+ | --- | --- |
483
+ | 🧩 **Write a plugin** | Build your own UI tab + agent tools. Copy `plugins/demo-mailbox` as the minimal template (it doubles as the test fixture), develop locally, then either open a PR to ship it in the [catalog](#plugin-catalog) or [publish it standalone](https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins). |
484
+ | 🎨 **Contribute a theme** | Copy `themes/white.css` (light) or `themes/cyberpunk.css` (dark) as a pure-palette template, tweak the `:root` palette + `--term-*` + `.hljs`, verify with `npm run dev`, then open a PR — full walkthrough in [Contributing a theme](#contributing-a-theme-to-the-repository-github). |
485
+ | 💻 **Fix a bug / add a feature** | Look for [open issues](https://github.com/xing-shuyin/pi-web-ui/issues) or propose something new. Fork → branch → PR. Keep the code conventions in `AGENTS.md` (tabs, i18n keys in both languages, protocol changes in `server/protocol.ts`). |
486
+ | 📖 **Docs & translations** | Improve the READMEs, write plugin docs, fix typos, or help translate the UI / docs into more languages. |
487
+ | 💡 **Ideas & feedback** | Open an [issue](https://github.com/xing-shuyin/pi-web-ui/issues) or start a [discussion](https://github.com/xing-shuyin/pi-web-ui/discussions) — feature requests, bug reports, UI polish ideas, deployment experience reports. |
488
+
489
+ **Before opening a PR**, a quick sanity pass keeps reviewers happy:
490
+
491
+ - `npm run format` — prettier formatting (tabs, width 120; CI checks it).
492
+ - `npm run lint` — oxlint (unused vars, risky patterns; CI runs it).
493
+ - `npm run check:protocol` + `npm test` — protocol sync and unit tests.
494
+ - `npm run typecheck` — no type errors.
495
+ - `npm run build` — both frontend and backend compile.
496
+ - For protocol changes: add branches in both `server/index.ts` and `web/src/use-chat.ts` (see the "Protocol single source" note in `AGENTS.md`).
497
+
498
+ > Enjoying pi-web-ui? Give the repo a ⭐ — it helps others find it. And if you
499
+ > built something cool on top (plugin, theme, deployment recipe), tell us — we
500
+ > love showcasing community work.
501
+
502
+
503
+ ## License
504
+
505
505
  [MIT](LICENSE)