pi-web-ui 0.1.1 → 0.2.1

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
@@ -43,15 +43,122 @@ npm run build # compiles server (tsc) + frontend (vite)
43
43
  npm start # serves everything on http://localhost:8787
44
44
  ```
45
45
 
46
+ ## npm package (install / start / stop / update / uninstall)
47
+
48
+ The package is published on npm as [`pi-web-ui`](https://www.npmjs.com/package/pi-web-ui).
49
+
50
+ ### Install
51
+
52
+ ```bash
53
+ # install globally (recommended)
54
+ npm i -g pi-web-ui
55
+
56
+ # or run without installing (pulls the latest, starts on :8787)
57
+ npx pi-web-ui
58
+
59
+ # or install the local checkout (for testing changes before publishing)
60
+ npm i -g .
61
+ ```
62
+
63
+ > **pi-managed npm?** If your `npm` is the pi wrapper that blocks dependency
64
+ > install scripts, approve node-pty's native build once after installing:
65
+ > `npm approve-scripts node-pty@1.1.0` (standard npm does this automatically).
66
+
67
+ ### Start
68
+
69
+ ```bash
70
+ pi-web-ui # foreground, http://localhost:8787
71
+ PORT=9000 PI_WEB_CWD=/path/to/project pi-web-ui # custom port / workspace
72
+ ```
73
+
74
+ To run it in the background or auto-start on boot, use a system service —
75
+ see [Deploy & auto-start on boot](#deploy--auto-start-on-boot) (systemd /
76
+ launchd / Docker).
77
+
78
+ The `pi-web-ui` command serves the built frontend and the WebSocket API from
79
+ wherever the package is installed — no repo checkout needed. It uses **your**
80
+ `~/.pi/agent` config (auth/models/skills) and stores per-client sessions under
81
+ `<PI_WEB_CWD>/.pi-web`.
82
+
83
+ ### Stop
84
+
85
+ - **Foreground**: press `Ctrl+C` in the terminal running it.
86
+ - **systemd**: `sudo systemctl stop pi-web-ui`
87
+ - **launchd**: `launchctl bootout gui/$(id -u)/com.xingshuyin.pi-web-ui`
88
+ - **Windows (scheduled task)**: `pi-web-ui server stop` (or
89
+ `schtasks /End /TN pi-web-ui`; stops the running instance, auto-start stays
90
+ until `server uninstall`)
91
+ - **Docker**: `docker compose stop` (stop + remove the container: `docker compose down`)
92
+
93
+ (Background processes should be managed by a system service, not `nohup` —
94
+ service stop commands above also stop and disable auto-start.)
95
+
96
+ ### Verify / version
97
+
98
+ ```bash
99
+ pi-web-ui --version # CLI version
100
+ npm ls -g pi-web-ui # installed? which version?
101
+ which pi-web-ui # executable location
102
+ ```
103
+
104
+ ### Update
105
+
106
+ ```bash
107
+ npm i -g pi-web-ui@latest # upgrade to the latest published version
108
+ # restart the server afterwards for the new version to take effect
109
+ ```
110
+
111
+ ### Uninstall
112
+
113
+ ```bash
114
+ npm uninstall -g pi-web-ui
115
+ ```
116
+
117
+ Uninstalling does **not** delete your chats: session data lives in
118
+ `<PI_WEB_CWD>/.pi-web` (or `PI_WEB_DATA_DIR`) and survives uninstall/upgrade.
119
+
120
+ ### Manage as a system service (auto-start)
121
+
122
+ Install the server as a system service that starts on boot, with a custom
123
+ port and workspace:
124
+
125
+ ```bash
126
+ pi-web-ui server install --port 9000 --cwd /path/to/project # install + start
127
+ pi-web-ui server status # running? auto-start?
128
+ pi-web-ui server restart # restart (also applies config changes)
129
+ pi-web-ui server stop # stop + disable auto-start
130
+ pi-web-ui server start # start again
131
+ pi-web-ui server uninstall # remove the service entirely
132
+ ```
133
+
134
+ - **macOS** → launchd agent (no sudo): writes and loads
135
+ `~/Library/LaunchAgents/com.xingshuyin.pi-web-ui.plist`, restarts on crash
136
+ (`KeepAlive`), logs to `/tmp/pi-web-ui.log` / `/tmp/pi-web-ui.err`.
137
+ - **Linux** → systemd unit (auto-sudo): writes
138
+ `/etc/systemd/system/pi-web-ui.service` and runs `systemctl enable --now`,
139
+ logs via `journalctl -u pi-web-ui -f`.
140
+ - **Windows** → Task Scheduler (no admin): creates a user task that starts at
141
+ logon (same as a launchd agent). It runs a `.cmd` wrapper generated at
142
+ `%APPDATA%\pi-web-ui\pi-web-ui.cmd` (sets env, cd's to the workspace,
143
+ launches node, appends logs to `%USERPROFILE%\pi-web-ui.log`). The task XML
144
+ is saved next to it; restarts on failure.
145
+ - Options: `--port` (default 8787 or `$PORT`), `--cwd` (default `$PI_WEB_CWD`
146
+ or the current directory), `--data-dir` (sessions), `--name` (custom service
147
+ name; on macOS the label is `com.xingshuyin.pi-web-ui`, custom names become
148
+ `com.<name>.server`). `--print` previews the generated unit/plist/task files
149
+ without applying it.
150
+ - Rerunning `install` with new options regenerates the config and restarts the
151
+ service — that's how you change the port/cwd of an installed service.
152
+
46
153
  ## Configuration
47
154
 
48
- | Env var | Default | Description |
49
- | --- | --- | --- |
50
- | `PORT` | `8787` | HTTP/WebSocket port |
51
- | `PI_WEB_CWD` | server's cwd | The workspace directory the agent operates in (read/edit/bash/write) |
52
- | `PI_WEB_DATA_DIR` | `<cwd>/.pi-web` | Where per-client session dirs are stored |
53
- | `PI_WEB_INLINE_FILE_MAX` | `12288` (12KB) | Text attachments at or below this size are inlined into the model context; larger files are passed as path references and the model reads them on demand (saves tokens for small edits) |
54
- | `PI_CODING_AGENT_DIR` | `~/.pi/agent` | pi config dir (auth.json, models.json, skills, extensions) |
155
+ | Env var | Default | Description |
156
+ | -------------------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
157
+ | `PORT` | `8787` | HTTP/WebSocket port |
158
+ | `PI_WEB_CWD` | server's cwd | The workspace directory the agent operates in (read/edit/bash/write) |
159
+ | `PI_WEB_DATA_DIR` | `<cwd>/.pi-web` | Where per-client session dirs are stored |
160
+ | `PI_WEB_INLINE_FILE_MAX` | `12288` (12KB) | Text attachments at or below this size are inlined into the model context; larger files are passed as path references and the model reads them on demand (saves tokens for small edits) |
161
+ | `PI_CODING_AGENT_DIR` | `~/.pi/agent` | pi config dir (auth.json, models.json, skills, extensions) |
55
162
 
56
163
  Example — point the agent at a project:
57
164
 
@@ -83,6 +190,12 @@ Key design points:
83
190
  event it schedules a throttled (60 ms) full-state snapshot, and the browser
84
191
  renders purely from snapshots. Reconnects just re-request `get_state`. Large
85
192
  payloads (tool output, text) are capped during serialization (`server/serialize.ts`).
193
+ - **Live assistant streaming.** The in-progress message (SDK
194
+ `agent.state.streamingMessage`) is serialized into every snapshot, so thinking
195
+ blocks and answer text appear in the browser as they are generated — with a
196
+ blinking cursor — instead of only after the turn finishes. The partial message
197
+ gets a stable `stream-<ts>` id so it stays mounted (open thinking/tool blocks
198
+ keep their state) across snapshots.
86
199
  - **Size-aware attachments.** Clicking + on a file queues it as an attachment
87
200
  (shown as chips above the input). On send, the server attaches each file as an
88
201
  independent custom message (SDK `sendCustomMessage` + `nextTurn` asides) — the
@@ -123,10 +236,10 @@ with three panes:
123
236
  `${pwd}` resolves to the agent's current working directory (the one shown in the chat
124
237
  view's file panel, changeable via set_cwd); `~` and relative paths also work. The `+`
125
238
  button at the top of the command panel creates a new entry.
126
-
127
- - **Middle the terminal**: each tab is a real PTY (your `$SHELL`); output streams live
128
- and you can type, Ctrl+C, resize, etc. exactly like a desktop terminal.
129
-
239
+ - **Middle — the terminal**: each tab is a real PTY (your `$SHELL` on
240
+ macOS/Linux; PowerShell or cmd.exe `$COMSPEC` on Windows); output
241
+ streams live and you can type, Ctrl+C, resize, etc. exactly like a desktop
242
+ terminal. Git Bash users on Windows get their `$SHELL` automatically.
130
243
  - **Right — 终端 (tabs)**: VSCode-style vertical tab strip. `+` opens a plain shell in the
131
244
  current directory. Closing a tab kills its process.
132
245
 
@@ -149,15 +262,89 @@ Server → client: `ready`, `snapshot` (full `UiState`), `tool_delta`, `notice`,
149
262
 
150
263
  ## Scripts
151
264
 
152
- | Script | What it does |
153
- | --- | --- |
154
- | `npm run dev` | server (tsx watch) + Vite dev server with WS proxy |
155
- | `npm run build` | type-check + build frontend and server |
156
- | `npm start` | run the production server (serves `web/dist`) |
157
- | `npm run typecheck` | `tsc --noEmit` for both server and web |
158
- | `node terminal-smoke-test.mjs` | WS-level terminal/commands protocol test (build first) |
265
+ | Script | What it does |
266
+ | ---------------------------------- | ------------------------------------------------------- |
267
+ | `npm run dev` | server (tsx watch) + Vite dev server with WS proxy |
268
+ | `npm run build` | type-check + build frontend and server |
269
+ | `npm start` | run the production server (serves`web/dist`) |
270
+ | `npm run typecheck` | `tsc --noEmit` for both server and web |
271
+ | `node terminal-smoke-test.mjs` | WS-level terminal/commands protocol test (build first) |
159
272
  | `node terminal-browser-test.mjs` | headless-browser E2E of the terminal view (build first) |
160
273
 
274
+ ## Deploy & auto-start on boot
275
+
276
+ Quickest path: `pi-web-ui server install --port 8787 --cwd /path` — installs
277
+ and starts the service on boot (see [Manage as a system service](#manage-as-a-system-service-auto-start)).
278
+ The manual alternatives below are kept for reference / non-standard setups.
279
+
280
+ ### Docker (one command)
281
+
282
+ ```bash
283
+ docker compose up -d # builds, starts on :8787, auto-restarts on boot
284
+ docker compose stop # stop (keeps the container)
285
+ docker compose down # stop and remove the container
286
+ ```
287
+
288
+ `restart: unless-stopped` in `docker-compose.yml` brings the server back up
289
+ whenever the Docker daemon starts (boot, crashes, reboots). Mount a volume for
290
+ `/app/.pi-web` (sessions persist) and, optionally, your `~/.pi/agent` config
291
+ and a workspace — see the comments in `docker-compose.yml`.
292
+
293
+ ### Linux — systemd
294
+
295
+ ```bash
296
+ sudo npm i -g pi-web-ui
297
+ sudo cp deploy/pi-web-ui.service /etc/systemd/system/
298
+ # edit User/WorkingDirectory/Environment in the unit first
299
+ sudo systemctl daemon-reload
300
+ sudo systemctl enable --now pi-web-ui # starts now + on every boot
301
+ sudo systemctl stop pi-web-ui # stop
302
+ sudo systemctl disable pi-web-ui # stop auto-start on boot
303
+ journalctl -u pi-web-ui -f # logs
304
+ ```
305
+
306
+ ### macOS — launchd
307
+
308
+ ```bash
309
+ npm i -g pi-web-ui
310
+ cp deploy/com.xingshuyin.pi-web-ui.plist ~/Library/LaunchAgents/
311
+ # edit ProgramArguments / WorkingDirectory / PI_WEB_CWD (which pi-web-ui)
312
+ launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.xingshuyin.pi-web-ui.plist
313
+ launchctl bootout gui/$(id -u)/com.xingshuyin.pi-web-ui # stop + remove auto-start
314
+ # logs: /tmp/pi-web-ui.log, /tmp/pi-web-ui.err
315
+ ```
316
+
317
+ ### Windows — Task Scheduler
318
+
319
+ Easiest path (no admin, generates everything):
320
+
321
+ ```bat
322
+ npm i -g pi-web-ui
323
+ pi-web-ui server install --port 8787 --cwd C:\path\to\project
324
+ pi-web-ui server status
325
+ pi-web-ui server restart
326
+ pi-web-ui server stop :: stop the running instance (auto-start stays)
327
+ pi-web-ui server uninstall :: remove the task entirely
328
+ ```
329
+
330
+ What it does: writes `%APPDATA%\pi-web-ui\pi-web-ui.cmd` (a `.cmd` wrapper
331
+ that sets `PORT`/`PI_WEB_CWD`, cd's to the workspace, launches node and
332
+ appends output to `%USERPROFILE%\pi-web-ui.log`) plus the Task Scheduler XML,
333
+ then registers a **logon** task (`schtasks /Create /XML` — the task runs when
334
+ you log in, same as a launchd agent; no admin needed). Preview both generated
335
+ files without installing: `pi-web-ui server install --print`.
336
+
337
+ Manual alternative with `deploy/pi-web-ui-task.xml`: edit the paths, save the
338
+ file as **UTF-16 LE** (schtasks requires it), then
339
+ `schtasks /Create /TN "pi-web-ui" /XML pi-web-ui-task.xml /F` and
340
+ `schtasks /Run /TN "pi-web-ui"`.
341
+
342
+ > **Boot-start without login?** A logon task needs an interactive session, just
343
+ > like a launchd agent. For headless/always-on Windows use Docker (see above).
344
+
345
+ The three templates use `KeepAlive` / `Restart=on-failure` / `RestartOnFailure`
346
+ so the server survives crashes, and start at login/boot automatically.
347
+
161
348
  ## License
162
349
 
163
350
  MIT