openprototype 1.1.0 → 1.3.0

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,28 +1,39 @@
1
1
  <div align="center">
2
2
 
3
- # OpenPrototype
3
+ <h1>OpenPrototype</h1>
4
4
 
5
- **English** | [简体中文](README.zh-CN.md)
5
+ <p><strong>English</strong> | <a href="README.zh-CN.md">简体中文</a></p>
6
6
 
7
- **A local prototyping workbench — navigation tree on the left · live preview in the middle · an AI Agent on the right**
7
+ <h2>Keep PRDs, HTML prototypes, and mock data in sync while AI edits them.</h2>
8
8
 
9
- Let product managers run "requirements → PRD → HTML prototype" as a single closed loop, with the AI sitting right next to the prototype and editing pages against their PRD.
9
+ <p>OpenPrototype is a local workbench for technical PMs and small product teams. It gives the Agent the current page and its PRD, applies only the requirement delta you marked, and checks the result before review.</p>
10
10
 
11
- *A local prototyping workbench: navigation tree · live preview · an AI agent that edits your HTML prototypes against their PRD.*
12
-
13
- ![License](https://img.shields.io/badge/license-MIT-blue)
14
- ![Node](https://img.shields.io/badge/node-%3E%3D16-brightgreen)
15
- ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-orange)
16
- ![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey)
11
+ <p>
12
+ <img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license">
13
+ <img src="https://img.shields.io/badge/node_core-%3E%3D16-brightgreen" alt="Node.js 16 or later">
14
+ <img src="https://img.shields.io/badge/PRs-welcome-orange" alt="Pull requests welcome">
15
+ <img src="https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey" alt="macOS, Windows and Linux">
16
+ </p>
17
17
 
18
18
  </div>
19
19
 
20
- <table>
21
- <tr>
22
- <td><img src="image/README/workbench-overview.png" alt="openprototype workbench preview" width="440"></td>
23
- <td><img src="image/README/workbench-prd.png" alt="openprototype workbench prd preview" width="440"></td>
24
- </tr>
25
- </table>
20
+ <p align="center">
21
+ <img src="image/README/core-loop.gif" alt="Mark a PRD change, apply only the delta, keep the prototype and mock data aligned, then verify with guardrails" width="100%">
22
+ </p>
23
+
24
+ <p align="center">
25
+ <a href="https://lightdoodleh.github.io/OpenPrototype/"><strong>Try the read-only demo</strong></a>
26
+ ·
27
+ <a href="https://github.com/lightdoodleh/OpenPrototype/issues">Share feedback</a>
28
+ </p>
29
+
30
+ ```bash
31
+ npx openprototype create myapp
32
+ cd myapp
33
+ npm install
34
+ ```
35
+
36
+ **The loop:** mark the PRD change → let the Agent update the relevant files → preview the real interaction → run the guardrail checks.
26
37
 
27
38
 
28
39
  ## Why it exists
@@ -33,13 +44,13 @@ The recurring pain points when a PM builds prototypes:
33
44
  - **AI can write code, but doesn't know your rules** — hand a prototype to a general-purpose AI and it rewrites whole pages, names things inconsistently, hardcodes status labels, and breaks existing interactions.
34
45
  - **Pages are scattered at review time** — dozens of prototype pages with no unified entry point; you find pages and track versions from memory.
35
46
 
36
- `openprototype` folds these three things into **one local workbench**:
47
+ `openprototype` folds these three things into **one controlled loop**:
37
48
 
38
49
  1. **PRD (`.md`) and prototype (`.html`) sit side by side in the same directory** — browse in one place, keep them aligned in one place.
39
50
  2. **The AI Agent on the right automatically carries "current page + current PRD" context.** Say "change field X to XX" and it edits only the relevant part instead of rewriting the whole page; it can also pick up the **red-marked** incremental changes in the PRD and land them precisely.
40
- 3. **A built-in red-line checker** (script order, data layer, status constants, font stack, `mode=view` physical hiding) runs automatically after every change, making it hard for the AI's output to drift off-spec.
51
+ 3. **A built-in red-line checker** covers script order, the data layer, status constants, the font stack, and `mode=view` physical hiding. The companion `auto-test` skill tells the Agent to run it after prototype edits.
41
52
 
42
- > In one sentence: **a local workbench with guardrails, built for "PM + AI prototyping."**
53
+ > In one sentence: **AI can move fast without letting the PRD, prototype, and mock data drift apart.**
43
54
 
44
55
  ---
45
56
 
@@ -47,18 +58,19 @@ The recurring pain points when a PM builds prototypes:
47
58
 
48
59
  - 🌲 **Navigation tree** — scans the product directory to auto-generate a page tree, with fuzzy title search, version badges (read from the PRD version table), and review markers.
49
60
  - 👁 **Live preview** — the middle iframe renders the prototype page directly; click on the left and see it instantly.
61
+ - 🧭 **First-run tour** — the first time you open the workbench, a 5-step bubble walkthrough covers create a page → find it → preview it → change it with the Agent → update it from the PRD. It shows once, and the "?" next to the sidebar title replays it anytime.
50
62
  - 🤖 **Context-aware AI Agent** — connects to your local [OpenCode](https://opencode.ai); every message automatically carries the current page + PRD path, with one-click "update the page per the PRD's red-marked content."
51
63
  - 🧱 **Zero-backend data layer** — `BaseDataManager` does CRUD via localStorage, so prototypes ship with interactive fake data and no database to spin up.
52
- - ✅ **Automated red-line checks** — static rules + Playwright smoke tests run right after you edit, pulling the AI back to spec.
53
- - 📦 **Scaffold distribution** — `create` starts a project from scratch, `init` grafts it into an existing project, `add-product` adds a product, and `npm update` upgrades the framework.
54
- - 🖥 **Cross-platform** — macOS / Windows / Linux; the OpenCode path is auto-detected.
64
+ - ✅ **Automated red-line checks** — static rules work out of the box; install Playwright and Chromium to add real-browser smoke tests.
65
+ - 📦 **Scaffold distribution** — `create` starts a project from scratch, `init` grafts it into an existing project, `add-product` adds a product, and `npm update openprototype` upgrades the framework runtime.
66
+ - 🖥 **Cross-platform** — manual serving works on macOS / Windows / Linux; the background service currently supports macOS / Windows only, and the OpenCode path is auto-detected.
55
67
 
56
68
  ---
57
69
 
58
70
  ## 🎯 Who it's for / Use cases
59
71
 
60
72
  **A good fit for**
61
- - **B2B / back-office product managers**: need to quickly build high-fidelity, interactive prototypes and keep the PRD and prototype always in sync.
73
+ - **Technical B2B / back-office product managers**: already use AI coding tools and need interactive prototypes without letting requirements and pages drift apart.
62
74
  - **Small teams / solo developers**: want AI to speed up prototype iteration without letting it rewrite things randomly or drift in style.
63
75
  - **Teams that want to codify their standards**: put your own PRD templates and UI guidelines into `rules/` and have the AI produce work to your standard.
64
76
 
@@ -77,7 +89,7 @@ The recurring pain points when a PM builds prototypes:
77
89
 
78
90
  ## 🚀 Quick start
79
91
 
80
- > Prerequisite: Node ≥ 16. The AI panel additionally needs local [OpenCode](https://opencode.ai) (see the next section; can be installed later).
92
+ > Prerequisite: the core runtime needs Node ≥ 16. Use Node ≥ 18 for Playwright smoke tests or repository development. The AI panel additionally needs local [OpenCode](https://opencode.ai) (see below; it can be installed later).
81
93
 
82
94
  ### Scenario ①: Start a project from scratch
83
95
 
@@ -85,22 +97,44 @@ The recurring pain points when a PM builds prototypes:
85
97
  npx openprototype create myapp
86
98
  cd myapp
87
99
  npm install
88
- npm run serve
89
100
  # Open http://127.0.0.1:8082/product/demo/pc/index.html
90
101
  ```
91
102
 
92
- The first run ships with an interactive demo product (customer list + form + PRD); just follow it to add your own pages.
103
+ On macOS / Windows, `npm install` registers and starts the project's background service by default. Open the URL above when installation finishes; do not run `npm run serve` as well, or the two processes will compete for the same port. On Linux, when the background service is disabled, or if automatic installation fails, run:
104
+
105
+ ```bash
106
+ npm run serve
107
+ ```
108
+
109
+ The first run ships with an interactive demo product (customer list + form + PRD); follow it to add your own pages.
93
110
 
94
- ### Scenario ②: Graft into an existing project (non-destructive)
111
+ ### Scenario ②: Graft into an existing project
95
112
 
96
113
  ```bash
97
114
  cd your-project
98
115
  npm i openprototype
99
- npx openprototype init # Only adds missing files and merges package.json scripts; never overwrites your existing content
116
+ npx openprototype init
100
117
  npx openprototype add-product shop
101
- npm run serve
118
+ # Open http://127.0.0.1:8082/product/shop/pc/index.html
102
119
  ```
103
120
 
121
+ `init` does not overwrite existing template files. It adds missing assets and merges `package.json` scripts, but it also rewrites `package.json` and, by default, registers and starts an OS background service on macOS / Windows. On Linux or with the service disabled, run `npm run serve` manually. If the background service is already running, run `npx openprototype service restart` after `add-product` so the Agent loads the new product's write scope.
122
+
123
+ ### Background service
124
+
125
+ The background service keeps the workbench available after login and is registered separately for each project. It currently supports macOS LaunchAgent and Windows Task Scheduler; use `npm run serve` on Linux.
126
+
127
+ ```bash
128
+ npx openprototype service status
129
+ npx openprototype service restart
130
+ npx openprototype service logs
131
+ npx openprototype service uninstall
132
+ ```
133
+
134
+ - To prevent automatic registration, set `OPENPROTOTYPE_SERVICE_AUTO_INSTALL=0` before the first `npm install` / `init`, or set `"service": { "autoInstall": false }` in the config beforehand.
135
+ - `service stop` stops the current process only; it will start again at the next login. Use `service uninstall` to remove it permanently.
136
+ - After adding a product or changing the port or Node path, run `service restart` to load the new configuration. Run it after a package upgrade too if the install hook did not restart the service successfully.
137
+
104
138
  ---
105
139
 
106
140
  ## 🤖 How the AI Agent works
@@ -115,7 +149,8 @@ You type in the panel ──▶ local server (/api/agent) ──▶ OpenCode
115
149
 
116
150
  - **Context carried automatically**: click any page on the left and the top of the panel shows "This message will carry: page X / PRD Y" — no need to paste paths manually.
117
151
  - **Incremental update per PRD red-marks**: one click sends the PRD content marked `<span style="color:red">…</span>` as the **only edit scope** to the Agent — it edits only the red-marked parts, treats un-marked history as background, and won't rewrite or "optimize on the side."
118
- - **Local and private**: the server listens on `127.0.0.1` by default; all writes and the Agent interface (`/api/*`) accept local requests only — even if you open the preview to the LAN with `--host 0.0.0.0`, others can only view pages, not edit files or touch the Agent.
152
+ - **Local by default**: the server listens on `127.0.0.1` by default; all writes and the Agent interface (`/api/*`) accept local requests only.
153
+ - **LAN exposure boundary**: with `--host 0.0.0.0`, LAN clients still cannot call write or Agent endpoints, but they can read non-hidden files that the static server can reach under the project root—not only prototype pages. Use this only on a trusted network and in a dedicated prototype project with no secrets or other sensitive files.
119
154
 
120
155
  ### Install OpenCode (prerequisite for the AI panel)
121
156
 
@@ -138,7 +173,7 @@ your-project/
138
173
  ├─ proto-kit.config.json # Ports / OpenCode / product list (the single config entry)
139
174
  ├─ AGENTS.md # Collaboration conventions for the AI (a generic template you own and can edit)
140
175
  ├─ CONVENTIONS.md # Explanation of the page red lines the checker enforces (coupled to the runtime)
141
- ├─ skills/ # xiaojia (restrained editing) + auto-test (auto-run checks after editing)
176
+ ├─ skills/ # xiaojia (restrained editing) + auto-test (requires checks after editing)
142
177
  ├─ rules/ # Empty directory: put your team's own PRD templates / UI guidelines here
143
178
  └─ product/<id>/pc/
144
179
  ├─ index.html # Navigation shell (thin, references the /_kit runtime)
@@ -150,10 +185,14 @@ The three-layer separation determines **who is responsible for updates**, which
150
185
 
151
186
  | Layer | Content | Ownership | Update method |
152
187
  |-------|---------|-----------|---------------|
153
- | **Runtime** | Server / shared engine / Agent panel / check scripts | Framework (mounted at `/_kit/`) | `npm update`, one command |
154
- | **Editable assets** | `AGENTS.md` `CONVENTIONS.md` `skills/` + your own `rules/` | You own them | `openprototype update` compares and merges as needed |
188
+ | **Runtime** | Server / shared engine / Agent panel / first-run tour / check scripts | Framework (mounted at `/_kit/`) | `npm update openprototype` |
189
+ | **Editable assets** | `AGENTS.md` `CONVENTIONS.md` `skills/` + your own `rules/` | You own them | `npx openprototype update` prints manual comparison and merge guidance |
155
190
  | **Business content** | Your product PRDs / prototypes / data | You own them | You maintain them yourself |
156
191
 
192
+ > **The product shell (`product/<id>/pc/index.html`) is copied at scaffold time and does not upgrade with the package.** When the framework adds a new shell entry point (such as the first-run tour), run `npx openprototype init` once after upgrading to patch it in — the patch is idempotent, skips shells that already have it, and leaves your own edits alone.
193
+ >
194
+ > First-run tour switches: add `?tour=off` to the URL to suppress it for that load; in the browser console, `window.ProtoTour.reset()` clears the "already seen" flag and `window.ProtoTour.start()` replays it on demand.
195
+
157
196
  > The framework ships only the **minimal generic conventions** (page red lines + editing restraint). Methodology like PRD templates, UI guidelines, and business terminology **belongs to you** — put it in `rules/` and `product/<id>/`; it's not distributed with the framework and won't be overwritten on upgrade.
158
197
 
159
198
  **Engine fallback resolution**: when a page references `../shared/xxx.js` by relative path and that file doesn't exist under `product/<id>/shared/`, the server automatically falls back to the framework's built-in engine (equivalent to `/_kit/shared/`). Therefore:
@@ -166,18 +205,25 @@ The three-layer separation determines **who is responsible for updates**, which
166
205
 
167
206
  ## 🧪 Quality assurance: the red-line checker
168
207
 
169
- `openprototype check` enforces these page red lines (see [CONVENTIONS.md](templates/CONVENTIONS.md) for details):
208
+ `npx openprototype check` always runs the static red-line checks. After Playwright and Chromium are installed, it also runs real-browser smoke tests (see [CONVENTIONS.md](templates/CONVENTIONS.md) for details):
170
209
 
171
210
  - Fixed script load order · data must go through `BaseDataManager` (no page-level localStorage)
172
211
  - Status labels as constants (no hardcoded `<option>`) · no Google Fonts (system font stack)
173
212
  - `?mode=view` physical hiding (`display:none`, not `disabled`) · no console errors when opening a page
174
213
 
175
214
  ```bash
176
- openprototype check # Scan all pages
177
- openprototype check --changed # Scan only git changes
215
+ npm run check # Scan all pages
216
+ npm run check:changed # Scan only git changes
178
217
  ```
179
218
 
180
- The companion `auto-test` skill reminds the AI: **run the checks automatically after every prototype edit, and fix ERRORs before delivering.**
219
+ Enable the browser layer once:
220
+
221
+ ```bash
222
+ npm i -D playwright
223
+ npx playwright install chromium
224
+ ```
225
+
226
+ When Playwright or Chromium is missing, do not rely on browser-layer results; install both before treating `check` as the full check suite. The companion `auto-test` skill tells the Agent to run checks after every prototype edit and fix all ERRORs before delivery; this is an Agent workflow rule, not a server-side file watcher.
181
227
 
182
228
  ---
183
229
 
@@ -186,13 +232,17 @@ The companion `auto-test` skill reminds the AI: **run the checks automatically a
186
232
  ```json
187
233
  {
188
234
  "port": 8082,
189
- "host": "127.0.0.1", // Local-only by default; '0.0.0.0' lets the LAN see the preview (/api/* stays local-only)
235
+ "host": "127.0.0.1",
236
+ "service": {
237
+ "autoInstall": true
238
+ },
190
239
  "opencode": {
191
- "bin": "auto", // 'auto' auto-detects; you can also write an absolute path
240
+ "bin": "auto",
192
241
  "model": "deepseek/deepseek-v4-flash",
193
242
  "agent": "build",
194
243
  "host": "127.0.0.1",
195
- "port": 4097
244
+ "port": 4097,
245
+ "startTimeoutMs": 15000
196
246
  },
197
247
  "products": [
198
248
  { "id": "demo", "roots": ["pc"] }
@@ -200,23 +250,29 @@ The companion `auto-test` skill reminds the AI: **run the checks automatically a
200
250
  }
201
251
  ```
202
252
 
253
+ `host` defaults to `127.0.0.1`. Setting it to `0.0.0.0` exposes static file reads to the LAN, so review the security boundary above first. A long-running background service also requires an explicit `npx openprototype service install --allow-lan`.
254
+
203
255
  Environment variables can override temporarily: `PROTO_KIT_PORT` · `PROTO_KIT_HOST` · `OPENCODE_BIN` · `OPENCODE_MODEL` · `OPENCODE_PORT`.
204
- You can also use `node runtime/server.js --port 9000 --host 0.0.0.0` to specify the port / listen address ad hoc.
256
+ You can also use `npx openprototype serve --port 9000 --host 0.0.0.0` to specify the port / listen address ad hoc.
205
257
 
206
258
  ---
207
259
 
208
260
  ## 📟 Commands
209
261
 
262
+ The table uses `npx` for the default local-project installation. You can omit `npx` after a global installation. `create` adds npm script aliases, and `init` does the same when the project already has a `package.json`, so day-to-day commands can use `npm run serve`, `npm run check`, `npm run check:changed`, and `npm run nav:sync`.
263
+
210
264
  | Command | Purpose |
211
265
  |---------|---------|
212
- | `openprototype create <dir>` | Create a new project from scratch (with a runnable demo) |
213
- | `openprototype init` | Graft the framework into the current existing project (non-destructive) |
214
- | `openprototype add-product <id>` | Add a product shell (pc by default) |
215
- | `openprototype serve` | Start the local server |
216
- | `openprototype check [--changed]` | Automated checks (static red lines + smoke tests) |
217
- | `openprototype nav:sync` | Scan the product directory and rebuild `nav-tree.json` |
218
- | `openprototype doctor` | Health check (Node / OpenCode / config / Playwright) |
219
- | `openprototype update` | How to update the framework |
266
+ | `npx openprototype create <dir>` | Create a new project from scratch with a runnable demo |
267
+ | `npx openprototype init` | Add missing assets, merge scripts, and install the background service when configured |
268
+ | `npx openprototype add-product <id> [--title <name>]` | Add a PC product shell with an optional display name |
269
+ | `npx openprototype serve [--port <port>] [--host <address>]` | Start the foreground server with optional temporary listen overrides |
270
+ | `npx openprototype service <action>` | Manage the background service: `install/start/stop/restart/status/logs/uninstall/prune` |
271
+ | `npx openprototype check [--changed] [--static-only] [path]` | Check all pages, Git changes, or a path; optionally run static rules only |
272
+ | `npx openprototype nav:sync` | Scan product directories and rebuild `nav-tree.json` |
273
+ | `npx openprototype doctor` | Check Node / OpenCode / config / Playwright / background service health |
274
+ | `npm update openprototype` | Upgrade the runtime package within the version range in `package.json` |
275
+ | `npx openprototype update` | Print manual editable-asset comparison and merge guidance; does not upgrade |
220
276
 
221
277
  ---
222
278
 
@@ -236,6 +292,7 @@ Feature requests and feedback are welcome in Issues.
236
292
  PRs welcome. Development conventions:
237
293
 
238
294
  - Use only Node built-in modules; the runtime has zero dependencies (the checker's Playwright is a devDependency).
295
+ - The core runtime supports Node ≥ 16; installing the current Playwright dependency and running the full checks requires Node ≥ 18.
239
296
  - Run `npm run check` after changing the runtime; after changing the shell / Agent panel, start the server locally and test the three columns for real.
240
297
  - Keep the repository **free of any private information** (company / personal / intranet addresses / secrets).
241
298
 
package/README.zh-CN.md CHANGED
@@ -1,28 +1,39 @@
1
1
  <div align="center">
2
2
 
3
- # OpenPrototype
3
+ <h1>OpenPrototype</h1>
4
4
 
5
- [English](README.md) | **简体中文**
5
+ <p><a href="README.md">English</a> | <strong>简体中文</strong></p>
6
6
 
7
- **本地原型工作台 —— 左侧树形导航 · 中间原型预览 · 右侧 AI Agent**
7
+ <h2>AI 改需求时,让 PRD、HTML 原型和 mock 数据始终一致。</h2>
8
8
 
9
- 让产品经理把「需求 → PRD → HTML 原型」跑成一个闭环,AI 就坐在原型旁边按 PRD 改页面。
9
+ <p>OpenPrototype 是面向技术型产品经理和小型产品团队的本地工作台。它把当前页面和对应 PRD 自动交给 Agent,只执行你标出的需求增量,并在评审前检查结果。</p>
10
10
 
11
- *A local prototyping workbench: navigation tree · live preview · an AI agent that edits your HTML prototypes against their PRD.*
12
-
13
- ![License](https://img.shields.io/badge/license-MIT-blue)
14
- ![Node](https://img.shields.io/badge/node-%3E%3D16-brightgreen)
15
- ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-orange)
16
- ![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey)
11
+ <p>
12
+ <img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT 许可证">
13
+ <img src="https://img.shields.io/badge/node_core-%3E%3D16-brightgreen" alt="Node.js 16 或更高版本">
14
+ <img src="https://img.shields.io/badge/PRs-welcome-orange" alt="欢迎提交 Pull Request">
15
+ <img src="https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey" alt="macOS、Windows 与 Linux">
16
+ </p>
17
17
 
18
18
  </div>
19
19
 
20
- <table>
21
- <tr>
22
- <td><img src="image/README/workbench-overview.png" alt="openprototype workbench preview" width="440"></td>
23
- <td><img src="image/README/workbench-prd.png" alt="openprototype workbench prd preview" width="440"></td>
24
- </tr>
25
- </table>
20
+ <p align="center">
21
+ <img src="image/README/core-loop.gif" alt="标出 PRD 增量、精准更新相关文件、同步原型与 mock 数据并通过红线检查" width="100%">
22
+ </p>
23
+
24
+ <p align="center">
25
+ <a href="https://lightdoodleh.github.io/OpenPrototype/"><strong>在线体验只读 Demo</strong></a>
26
+ ·
27
+ <a href="https://github.com/lightdoodleh/OpenPrototype/issues">提交反馈</a>
28
+ </p>
29
+
30
+ ```bash
31
+ npx openprototype create myapp
32
+ cd myapp
33
+ npm install
34
+ ```
35
+
36
+ **核心闭环:**标出 PRD 增量 → Agent 更新相关文件 → 预览真实交互 → 运行红线检查。
26
37
 
27
38
 
28
39
  ## 为什么要有它
@@ -33,13 +44,13 @@
33
44
  - **AI 会写代码,但不懂你的规矩** —— 直接让通用 AI 改原型,它会整页重写、命名混乱、把状态文案写死、破坏既有交互。
34
45
  - **评审时页面散落各处** —— 几十个原型页没有统一入口,找页面、对版本靠记忆。
35
46
 
36
- `openprototype` 把这三件事收进**一个本地工作台**:
47
+ `openprototype` 把这三件事收进**一个受控闭环**:
37
48
 
38
49
  1. **PRD(`.md`)和原型(`.html`)同目录并排放**,一处浏览、一处对齐。
39
50
  2. **右侧 AI Agent 自动携带「当前页面 + 当前 PRD」上下文**,你说"把某字段改成 XX",它只改相关部分、不整页重写;还能识别 PRD 里**标红**的增量改动精准落地。
40
- 3. **内置红线检查器**(脚本顺序、数据层、状态常量化、字体栈、`mode=view` 物理隐藏)在每次改动后自动跑,AI 产出想跑偏都难。
51
+ 3. **内置红线检查器**覆盖脚本顺序、数据层、状态常量化、字体栈与 `mode=view` 物理隐藏;配套 `auto-test` skill 会要求 Agent 在改完原型后执行检查。
41
52
 
42
- > 一句话:**给"PM + AI 做原型"这件事,配一套有护栏的本地工作台。**
53
+ > 一句话:**让 AI 快速改原型,同时不让 PRD、页面和 mock 数据互相漂移。**
43
54
 
44
55
  ---
45
56
 
@@ -47,18 +58,19 @@
47
58
 
48
59
  - 🌲 **树形导航** —— 扫描产品目录自动生成页面树,支持标题模糊搜索、版本号徽标(从 PRD 版本表读取)、审核标记。
49
60
  - 👁 **即时预览** —— 中间 iframe 直接渲染原型页面,点左侧即看。
61
+ - 🧭 **新手引导** —— 首次打开工作台自动弹出 5 步气泡,把「新建页面 → 找页面 → 预览 → Agent 改页面 → 按 PRD 更新」走一遍;看过一次就不再出现,侧栏标题旁的「?」可随时重看。
50
62
  - 🤖 **上下文感知的 AI Agent** —— 接本机 [OpenCode](https://opencode.ai),每条消息自动带当前页面 + PRD 路径;一键"按 PRD 标红内容更新页面"。
51
63
  - 🧱 **零后端的数据层** —— `BaseDataManager` 用 localStorage 做 CRUD,原型自带可交互假数据,不用起数据库。
52
- - ✅ **自动化红线检查** —— 静态规则 + Playwright 冒烟,改完即测,把 AI 拉回规范。
53
- - 📦 **脚手架分发** —— `create` 从零起项目、`init` 植入已有项目、`add-product` 加产品,`npm update` 升级框架。
54
- - 🖥 **跨平台** —— macOS / Windows / Linux;OpenCode 路径自动探测。
64
+ - ✅ **自动化红线检查** —— 静态规则开箱可用;安装 Playwright 与 Chromium 后可增加真实浏览器冒烟测试。
65
+ - 📦 **脚手架分发** —— `create` 从零起项目、`init` 植入已有项目、`add-product` 加产品,`npm update openprototype` 升级框架运行时。
66
+ - 🖥 **跨平台** —— macOS / Windows / Linux 均可手动启动;常驻服务目前仅支持 macOS / Windows,OpenCode 路径自动探测。
55
67
 
56
68
  ---
57
69
 
58
70
  ## 🎯 适合谁 / 使用场景
59
71
 
60
72
  **适合**
61
- - **B 端 / 中后台产品经理**:需要快速做高保真、可交互原型,并让 PRD 与原型始终一致。
73
+ - **会使用 AI 编码工具的 B 端 / 中后台产品经理**:需要快速做可交互原型,又不希望需求、页面和数据越改越散。
62
74
  - **小团队 / 独立开发**:想用 AI 加速原型迭代,又不希望 AI 每次乱改、风格漂移。
63
75
  - **需要沉淀规范的团队**:把自己的 PRD 模板、UI 规范放进 `rules/`,让 AI 按你的标准产出。
64
76
 
@@ -77,7 +89,7 @@
77
89
 
78
90
  ## 🚀 快速开始
79
91
 
80
- > 前置:Node ≥ 16。AI 面板另需本机 [OpenCode](https://opencode.ai)(见下节,可后装)。
92
+ > 前置:核心运行时需要 Node ≥ 16;若要运行 Playwright 冒烟测试或参与仓库开发,请使用 Node ≥ 18。AI 面板另需本机 [OpenCode](https://opencode.ai)(见后文,可后装)。
81
93
 
82
94
  ### 场景 ①:从零建项目
83
95
 
@@ -85,22 +97,44 @@
85
97
  npx openprototype create myapp
86
98
  cd myapp
87
99
  npm install
88
- npm run serve
89
100
  # 打开 http://127.0.0.1:8082/product/demo/pc/index.html
90
101
  ```
91
102
 
103
+ macOS / Windows 上,`npm install` 默认会注册并启动项目常驻服务,安装完成后直接打开上面的地址;不要再执行 `npm run serve`,否则会与常驻服务争用端口。Linux、禁用常驻服务或自动安装失败时,再执行:
104
+
105
+ ```bash
106
+ npm run serve
107
+ ```
108
+
92
109
  首跑就带一个可交互的 demo 产品(客户列表 + 表单 + PRD),照着它加自己的页面即可。
93
110
 
94
- ### 场景 ②:植入已有项目(非破坏式)
111
+ ### 场景 ②:植入已有项目
95
112
 
96
113
  ```bash
97
114
  cd 你的项目
98
115
  npm i openprototype
99
- npx openprototype init # 只补缺失文件、合并 package.json 脚本,不覆盖你已有内容
116
+ npx openprototype init
100
117
  npx openprototype add-product shop
101
- npm run serve
118
+ # 打开 http://127.0.0.1:8082/product/shop/pc/index.html
102
119
  ```
103
120
 
121
+ `init` 不覆盖已有模板文件,会补充缺失资产并合并 `package.json` 脚本;但它也会修改 `package.json`,且默认在 macOS / Windows 上注册并启动系统常驻服务。Linux 或未启用常驻服务时,运行 `npm run serve` 手动启动。如果常驻服务已经运行,`add-product` 修改配置后执行一次 `npx openprototype service restart`,让 Agent 加载新产品的写入范围。
122
+
123
+ ### 常驻服务
124
+
125
+ 常驻服务让工作台在登录后自动运行,每个项目独立注册。它目前仅支持 macOS LaunchAgent 与 Windows 计划任务;Linux 请使用 `npm run serve`。
126
+
127
+ ```bash
128
+ npx openprototype service status
129
+ npx openprototype service restart
130
+ npx openprototype service logs
131
+ npx openprototype service uninstall
132
+ ```
133
+
134
+ - 不想自动注册:在首次 `npm install` / `init` 前设置 `OPENPROTOTYPE_SERVICE_AUTO_INSTALL=0`,或提前在配置中设置 `"service": { "autoInstall": false }`。
135
+ - `service stop` 只停止本次运行,下次登录仍会启动;永久取消请用 `service uninstall`。
136
+ - 新增产品、修改端口或 Node 路径后,运行 `service restart` 让常驻服务加载新配置;升级包的安装钩子未自动重启成功时也应执行它。
137
+
104
138
  ---
105
139
 
106
140
  ## 🤖 AI Agent 怎么工作
@@ -115,7 +149,8 @@ npm run serve
115
149
 
116
150
  - **自动带上下文**:点左侧任一页面,面板顶部就显示「本条消息将携带:页面 X / PRD Y」,无需你手动贴路径。
117
151
  - **按 PRD 标红增量更新**:一键把 PRD 里 `<span style="color:red">…</span>` 标红的内容作为**唯一改动范围**发给 Agent —— 只改标红处,未标红的历史内容当背景,不重写、不"顺手优化"。
118
- - **本机私有**:服务器默认只监听 `127.0.0.1`;所有写入与 Agent 接口(`/api/*`)只接受本机请求——即使你用 `--host 0.0.0.0` 把预览开放给局域网同事,别人也只能看页面,改不了文件、动不了 Agent。
152
+ - **默认仅本机访问**:服务器默认只监听 `127.0.0.1`;所有写入与 Agent 接口(`/api/*`)只接受本机请求。
153
+ - **局域网开放边界**:使用 `--host 0.0.0.0` 后,局域网设备虽然不能调用写入与 Agent 接口,但能读取项目根目录下服务器可访问的非隐藏文件,不仅是原型页面。只应在可信网络和专用原型项目中使用,并确保项目中没有密钥或其他敏感文件。
119
154
 
120
155
  ### 安装 OpenCode(AI 面板前置)
121
156
 
@@ -138,7 +173,7 @@ npx openprototype doctor # 一键体检 Node / OpenCode / 配置 / Playwright
138
173
  ├─ proto-kit.config.json # 端口 / OpenCode / 产品列表(唯一配置入口)
139
174
  ├─ AGENTS.md # 给 AI 的协作规范(通用模板,你拥有可改)
140
175
  ├─ CONVENTIONS.md # 检查器强制的页面红线说明(和运行时耦合)
141
- ├─ skills/ # xiaojia(编码克制)+ auto-test(改完自动跑检查)
176
+ ├─ skills/ # xiaojia(编码克制)+ auto-test(要求改完运行检查)
142
177
  ├─ rules/ # 空目录:放你团队自己的 PRD 模板 / UI 规范
143
178
  └─ product/<id>/pc/
144
179
  ├─ index.html # 导航壳(薄,引用 /_kit 运行时)
@@ -150,10 +185,16 @@ npx openprototype doctor # 一键体检 Node / OpenCode / 配置 / Playwright
150
185
 
151
186
  | 层 | 内容 | 归属 | 更新方式 |
152
187
  |----|------|------|----------|
153
- | **运行时** | 服务器 / shared 引擎 / Agent 面板 / 检查脚本 | 框架(挂在 `/_kit/`) | `npm update` 一键升 |
154
- | **可编辑资产** | `AGENTS.md` `CONVENTIONS.md` `skills/` + 你自建的 `rules/` | 你拥有 | `openprototype update` 对比后按需合并 |
188
+ | **运行时** | 服务器 / shared 引擎 / Agent 面板 / 新手引导 / 检查脚本 | 框架(挂在 `/_kit/`) | `npm update openprototype` |
189
+ | **可编辑资产** | `AGENTS.md` `CONVENTIONS.md` `skills/` + 你自建的 `rules/` | 你拥有 | `npx openprototype update` 输出手工对比与合并指引 |
155
190
  | **业务内容** | 你的产品 PRD / 原型 / 数据 | 你拥有 | 你自己维护 |
156
191
 
192
+ > **产品壳(`product/<id>/pc/index.html`)是脚手架时复制的,不随包升级。** 框架给壳加了新入口(比如新手引导)时,
193
+ > 升级后跑一次 `npx openprototype init` 即可补上——幂等,已有的会跳过,你自己改过的部分不动。
194
+ >
195
+ > 新手引导的开关:URL 加 `?tour=off` 本次不弹;浏览器控制台执行 `window.ProtoTour.reset()` 可重置"已看过"标记,
196
+ > `window.ProtoTour.start()` 直接手动开一次。
197
+
157
198
  > 框架只带**最小通用规范**(页面红线 + 编码克制)。PRD 模板、UI 规范、业务术语这类**方法论属于你**,放进 `rules/` 与 `product/<id>/`,不随框架分发、也不被升级覆盖。
158
199
 
159
200
  **引擎回退解析**:页面用相对路径引用 `../shared/xxx.js` 时,若 `product/<id>/shared/` 下没有该文件,服务器自动回退到框架内置引擎(等价 `/_kit/shared/`)。因此:
@@ -166,18 +207,25 @@ npx openprototype doctor # 一键体检 Node / OpenCode / 配置 / Playwright
166
207
 
167
208
  ## 🧪 质量保障:红线检查器
168
209
 
169
- `openprototype check` 会强制这些页面红线(详见 [CONVENTIONS.md](templates/CONVENTIONS.md)):
210
+ `npx openprototype check` 会执行静态红线检查;安装 Playwright 与 Chromium 后,还会执行真实浏览器冒烟测试(详见 [CONVENTIONS.md](templates/CONVENTIONS.md)):
170
211
 
171
212
  - 脚本加载顺序固定 · 数据必须走 `BaseDataManager`(禁页面级 localStorage)
172
213
  - 状态文案常量化(禁硬编码 `<option>`)· 禁 Google Fonts(系统字体栈)
173
214
  - `?mode=view` 物理隐藏(`display:none`,非 `disabled`)· 打开页面无 console 报错
174
215
 
175
216
  ```bash
176
- openprototype check # 扫全部页面
177
- openprototype check --changed # 只扫 git 改动
217
+ npm run check # 扫全部页面
218
+ npm run check:changed # 只扫 git 改动
178
219
  ```
179
220
 
180
- 配套的 `auto-test` skill 会提醒 AI:**每次改完原型自动跑检查、修完 ERROR 再交付。**
221
+ 首次启用浏览器层:
222
+
223
+ ```bash
224
+ npm i -D playwright
225
+ npx playwright install chromium
226
+ ```
227
+
228
+ 未安装 Playwright 或 Chromium 时不能依赖浏览器层结果;安装完成后再把 `check` 视为完整检查。配套的 `auto-test` skill 会要求 Agent 在每次改完原型后运行检查并修完 ERROR;这是一条 Agent 工作流约定,不是服务器文件监听器。
181
229
 
182
230
  ---
183
231
 
@@ -186,13 +234,17 @@ openprototype check --changed # 只扫 git 改动
186
234
  ```json
187
235
  {
188
236
  "port": 8082,
189
- "host": "127.0.0.1", // 默认仅本机;'0.0.0.0' 可让局域网看预览(/api/* 仍仅限本机)
237
+ "host": "127.0.0.1",
238
+ "service": {
239
+ "autoInstall": true
240
+ },
190
241
  "opencode": {
191
- "bin": "auto", // 'auto' 自动探测;也可写绝对路径
242
+ "bin": "auto",
192
243
  "model": "deepseek/deepseek-v4-flash",
193
244
  "agent": "build",
194
245
  "host": "127.0.0.1",
195
- "port": 4097
246
+ "port": 4097,
247
+ "startTimeoutMs": 15000
196
248
  },
197
249
  "products": [
198
250
  { "id": "demo", "roots": ["pc"] }
@@ -200,23 +252,29 @@ openprototype check --changed # 只扫 git 改动
200
252
  }
201
253
  ```
202
254
 
255
+ `host` 默认为 `127.0.0.1`。设为 `0.0.0.0` 会向局域网开放静态文件读取,请先阅读上面的安全边界;长期运行的常驻服务还需显式执行 `npx openprototype service install --allow-lan`。
256
+
203
257
  环境变量可临时覆盖:`PROTO_KIT_PORT` · `PROTO_KIT_HOST` · `OPENCODE_BIN` · `OPENCODE_MODEL` · `OPENCODE_PORT`。
204
- 也可用 `node runtime/server.js --port 9000 --host 0.0.0.0` 临时指定端口 / 监听地址。
258
+ 也可用 `npx openprototype serve --port 9000 --host 0.0.0.0` 临时指定端口 / 监听地址。
205
259
 
206
260
  ---
207
261
 
208
262
  ## 📟 命令
209
263
 
264
+ 下表按“项目本地安装 `openprototype`”的默认场景统一使用 `npx`;如果已全局安装,可以省略 `npx`。`create` 会写入常用 npm scripts,`init` 在项目已有 `package.json` 时也会补充,因此日常可使用 `npm run serve`、`npm run check`、`npm run check:changed` 和 `npm run nav:sync`。
265
+
210
266
  | 命令 | 作用 |
211
267
  |------|------|
212
- | `openprototype create <dir>` | 从零创建新项目(含可运行 demo) |
213
- | `openprototype init` | 把框架植入当前已有项目(非破坏式) |
214
- | `openprototype add-product <id>` | 新增一个产品壳(默认 pc) |
215
- | `openprototype serve` | 启动本地服务器 |
216
- | `openprototype check [--changed]` | 自动化检查(静态红线 + 冒烟) |
217
- | `openprototype nav:sync` | 扫描产品目录重建 `nav-tree.json` |
218
- | `openprototype doctor` | 体检(Node / OpenCode / 配置 / Playwright) |
219
- | `openprototype update` | 如何更新框架 |
268
+ | `npx openprototype create <dir>` | 从零创建新项目(含可运行 demo) |
269
+ | `npx openprototype init` | 补充缺失资产、合并脚本,并按配置安装常驻服务 |
270
+ | `npx openprototype add-product <id> [--title <名称>]` | 新增一个 PC 产品壳,可指定显示名称 |
271
+ | `npx openprototype serve [--port <端口>] [--host <地址>]` | 前台启动本地服务器,可临时覆盖监听配置 |
272
+ | `npx openprototype service <action>` | 管理常驻服务:`install/start/stop/restart/status/logs/uninstall/prune` |
273
+ | `npx openprototype check [--changed] [--static-only] [路径]` | 检查全部、Git 改动或指定范围;可只跑静态规则 |
274
+ | `npx openprototype nav:sync` | 扫描产品目录并重建 `nav-tree.json` |
275
+ | `npx openprototype doctor` | 体检 Node / OpenCode / 配置 / Playwright / 常驻服务 |
276
+ | `npm update openprototype` | 按 `package.json` 的版本范围升级框架运行时包 |
277
+ | `npx openprototype update` | 仅打印可编辑资产的手工对比与合并指引,不执行升级 |
220
278
 
221
279
  ---
222
280
 
@@ -236,6 +294,7 @@ openprototype check --changed # 只扫 git 改动
236
294
  欢迎 PR。开发约定:
237
295
 
238
296
  - 只用 Node 内置模块,运行时零依赖(检查器的 Playwright 是 devDependency)。
297
+ - 核心运行时支持 Node ≥ 16;完整安装当前 Playwright 依赖并跑检查需 Node ≥ 18。
239
298
  - 改运行时后跑 `npm run check`;改壳 / Agent 面板后本地起服务实测三栏。
240
299
  - 保持仓库**无任何私有信息**(公司 / 个人 / 内网地址 / 密钥)。
241
300