openprototype 1.0.2 → 1.2.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
@@ -11,7 +11,7 @@ Let product managers run "requirements → PRD → HTML prototype" as a single c
11
11
  *A local prototyping workbench: navigation tree · live preview · an AI agent that edits your HTML prototypes against their PRD.*
12
12
 
13
13
  ![License](https://img.shields.io/badge/license-MIT-blue)
14
- ![Node](https://img.shields.io/badge/node-%3E%3D16-brightgreen)
14
+ ![Node Core](https://img.shields.io/badge/node_core-%3E%3D16-brightgreen)
15
15
  ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-orange)
16
16
  ![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey)
17
17
 
@@ -37,7 +37,7 @@ The recurring pain points when a PM builds prototypes:
37
37
 
38
38
  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
39
  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.
40
+ 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
41
 
42
42
  > In one sentence: **a local workbench with guardrails, built for "PM + AI prototyping."**
43
43
 
@@ -47,11 +47,12 @@ The recurring pain points when a PM builds prototypes:
47
47
 
48
48
  - 🌲 **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
49
  - 👁 **Live preview** — the middle iframe renders the prototype page directly; click on the left and see it instantly.
50
+ - 🧭 **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
51
  - 🤖 **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
52
  - 🧱 **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.
53
+ - ✅ **Automated red-line checks** — static rules work out of the box; install Playwright and Chromium to add real-browser smoke tests.
54
+ - 📦 **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.
55
+ - 🖥 **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
56
 
56
57
  ---
57
58
 
@@ -77,7 +78,7 @@ The recurring pain points when a PM builds prototypes:
77
78
 
78
79
  ## 🚀 Quick start
79
80
 
80
- > Prerequisite: Node ≥ 16. The AI panel additionally needs local [OpenCode](https://opencode.ai) (see the next section; can be installed later).
81
+ > 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
82
 
82
83
  ### Scenario ①: Start a project from scratch
83
84
 
@@ -85,22 +86,44 @@ The recurring pain points when a PM builds prototypes:
85
86
  npx openprototype create myapp
86
87
  cd myapp
87
88
  npm install
88
- npm run serve
89
89
  # Open http://127.0.0.1:8082/product/demo/pc/index.html
90
90
  ```
91
91
 
92
- The first run ships with an interactive demo product (customer list + form + PRD); just follow it to add your own pages.
92
+ 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:
93
+
94
+ ```bash
95
+ npm run serve
96
+ ```
97
+
98
+ The first run ships with an interactive demo product (customer list + form + PRD); follow it to add your own pages.
93
99
 
94
- ### Scenario ②: Graft into an existing project (non-destructive)
100
+ ### Scenario ②: Graft into an existing project
95
101
 
96
102
  ```bash
97
103
  cd your-project
98
104
  npm i openprototype
99
- npx openprototype init # Only adds missing files and merges package.json scripts; never overwrites your existing content
105
+ npx openprototype init
100
106
  npx openprototype add-product shop
101
- npm run serve
107
+ # Open http://127.0.0.1:8082/product/shop/pc/index.html
108
+ ```
109
+
110
+ `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.
111
+
112
+ ### Background service
113
+
114
+ 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.
115
+
116
+ ```bash
117
+ npx openprototype service status
118
+ npx openprototype service restart
119
+ npx openprototype service logs
120
+ npx openprototype service uninstall
102
121
  ```
103
122
 
123
+ - 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.
124
+ - `service stop` stops the current process only; it will start again at the next login. Use `service uninstall` to remove it permanently.
125
+ - 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.
126
+
104
127
  ---
105
128
 
106
129
  ## 🤖 How the AI Agent works
@@ -115,7 +138,8 @@ You type in the panel ──▶ local server (/api/agent) ──▶ OpenCode
115
138
 
116
139
  - **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
140
  - **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.
141
+ - **Local by default**: the server listens on `127.0.0.1` by default; all writes and the Agent interface (`/api/*`) accept local requests only.
142
+ - **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
143
 
120
144
  ### Install OpenCode (prerequisite for the AI panel)
121
145
 
@@ -138,7 +162,7 @@ your-project/
138
162
  ├─ proto-kit.config.json # Ports / OpenCode / product list (the single config entry)
139
163
  ├─ AGENTS.md # Collaboration conventions for the AI (a generic template you own and can edit)
140
164
  ├─ 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)
165
+ ├─ skills/ # xiaojia (restrained editing) + auto-test (requires checks after editing)
142
166
  ├─ rules/ # Empty directory: put your team's own PRD templates / UI guidelines here
143
167
  └─ product/<id>/pc/
144
168
  ├─ index.html # Navigation shell (thin, references the /_kit runtime)
@@ -150,10 +174,14 @@ The three-layer separation determines **who is responsible for updates**, which
150
174
 
151
175
  | Layer | Content | Ownership | Update method |
152
176
  |-------|---------|-----------|---------------|
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 |
177
+ | **Runtime** | Server / shared engine / Agent panel / first-run tour / check scripts | Framework (mounted at `/_kit/`) | `npm update openprototype` |
178
+ | **Editable assets** | `AGENTS.md` `CONVENTIONS.md` `skills/` + your own `rules/` | You own them | `npx openprototype update` prints manual comparison and merge guidance |
155
179
  | **Business content** | Your product PRDs / prototypes / data | You own them | You maintain them yourself |
156
180
 
181
+ > **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.
182
+ >
183
+ > 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.
184
+
157
185
  > 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
186
 
159
187
  **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 +194,25 @@ The three-layer separation determines **who is responsible for updates**, which
166
194
 
167
195
  ## 🧪 Quality assurance: the red-line checker
168
196
 
169
- `openprototype check` enforces these page red lines (see [CONVENTIONS.md](templates/CONVENTIONS.md) for details):
197
+ `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
198
 
171
199
  - Fixed script load order · data must go through `BaseDataManager` (no page-level localStorage)
172
200
  - Status labels as constants (no hardcoded `<option>`) · no Google Fonts (system font stack)
173
201
  - `?mode=view` physical hiding (`display:none`, not `disabled`) · no console errors when opening a page
174
202
 
175
203
  ```bash
176
- openprototype check # Scan all pages
177
- openprototype check --changed # Scan only git changes
204
+ npm run check # Scan all pages
205
+ npm run check:changed # Scan only git changes
178
206
  ```
179
207
 
180
- The companion `auto-test` skill reminds the AI: **run the checks automatically after every prototype edit, and fix ERRORs before delivering.**
208
+ Enable the browser layer once:
209
+
210
+ ```bash
211
+ npm i -D playwright
212
+ npx playwright install chromium
213
+ ```
214
+
215
+ 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
216
 
182
217
  ---
183
218
 
@@ -186,13 +221,17 @@ The companion `auto-test` skill reminds the AI: **run the checks automatically a
186
221
  ```json
187
222
  {
188
223
  "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)
224
+ "host": "127.0.0.1",
225
+ "service": {
226
+ "autoInstall": true
227
+ },
190
228
  "opencode": {
191
- "bin": "auto", // 'auto' auto-detects; you can also write an absolute path
229
+ "bin": "auto",
192
230
  "model": "deepseek/deepseek-v4-flash",
193
231
  "agent": "build",
194
232
  "host": "127.0.0.1",
195
- "port": 4097
233
+ "port": 4097,
234
+ "startTimeoutMs": 15000
196
235
  },
197
236
  "products": [
198
237
  { "id": "demo", "roots": ["pc"] }
@@ -200,23 +239,29 @@ The companion `auto-test` skill reminds the AI: **run the checks automatically a
200
239
  }
201
240
  ```
202
241
 
242
+ `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`.
243
+
203
244
  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.
245
+ You can also use `npx openprototype serve --port 9000 --host 0.0.0.0` to specify the port / listen address ad hoc.
205
246
 
206
247
  ---
207
248
 
208
249
  ## 📟 Commands
209
250
 
251
+ 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`.
252
+
210
253
  | Command | Purpose |
211
254
  |---------|---------|
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 |
255
+ | `npx openprototype create <dir>` | Create a new project from scratch with a runnable demo |
256
+ | `npx openprototype init` | Add missing assets, merge scripts, and install the background service when configured |
257
+ | `npx openprototype add-product <id> [--title <name>]` | Add a PC product shell with an optional display name |
258
+ | `npx openprototype serve [--port <port>] [--host <address>]` | Start the foreground server with optional temporary listen overrides |
259
+ | `npx openprototype service <action>` | Manage the background service: `install/start/stop/restart/status/logs/uninstall/prune` |
260
+ | `npx openprototype check [--changed] [--static-only] [path]` | Check all pages, Git changes, or a path; optionally run static rules only |
261
+ | `npx openprototype nav:sync` | Scan product directories and rebuild `nav-tree.json` |
262
+ | `npx openprototype doctor` | Check Node / OpenCode / config / Playwright / background service health |
263
+ | `npm update openprototype` | Upgrade the runtime package within the version range in `package.json` |
264
+ | `npx openprototype update` | Print manual editable-asset comparison and merge guidance; does not upgrade |
220
265
 
221
266
  ---
222
267
 
@@ -236,6 +281,7 @@ Feature requests and feedback are welcome in Issues.
236
281
  PRs welcome. Development conventions:
237
282
 
238
283
  - Use only Node built-in modules; the runtime has zero dependencies (the checker's Playwright is a devDependency).
284
+ - The core runtime supports Node ≥ 16; installing the current Playwright dependency and running the full checks requires Node ≥ 18.
239
285
  - 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
286
  - Keep the repository **free of any private information** (company / personal / intranet addresses / secrets).
241
287
 
package/README.zh-CN.md CHANGED
@@ -11,7 +11,7 @@
11
11
  *A local prototyping workbench: navigation tree · live preview · an AI agent that edits your HTML prototypes against their PRD.*
12
12
 
13
13
  ![License](https://img.shields.io/badge/license-MIT-blue)
14
- ![Node](https://img.shields.io/badge/node-%3E%3D16-brightgreen)
14
+ ![Node Core](https://img.shields.io/badge/node_core-%3E%3D16-brightgreen)
15
15
  ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-orange)
16
16
  ![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey)
17
17
 
@@ -37,7 +37,7 @@
37
37
 
38
38
  1. **PRD(`.md`)和原型(`.html`)同目录并排放**,一处浏览、一处对齐。
39
39
  2. **右侧 AI Agent 自动携带「当前页面 + 当前 PRD」上下文**,你说"把某字段改成 XX",它只改相关部分、不整页重写;还能识别 PRD 里**标红**的增量改动精准落地。
40
- 3. **内置红线检查器**(脚本顺序、数据层、状态常量化、字体栈、`mode=view` 物理隐藏)在每次改动后自动跑,AI 产出想跑偏都难。
40
+ 3. **内置红线检查器**覆盖脚本顺序、数据层、状态常量化、字体栈与 `mode=view` 物理隐藏;配套 `auto-test` skill 会要求 Agent 在改完原型后执行检查。
41
41
 
42
42
  > 一句话:**给"PM + AI 做原型"这件事,配一套有护栏的本地工作台。**
43
43
 
@@ -47,11 +47,12 @@
47
47
 
48
48
  - 🌲 **树形导航** —— 扫描产品目录自动生成页面树,支持标题模糊搜索、版本号徽标(从 PRD 版本表读取)、审核标记。
49
49
  - 👁 **即时预览** —— 中间 iframe 直接渲染原型页面,点左侧即看。
50
+ - 🧭 **新手引导** —— 首次打开工作台自动弹出 5 步气泡,把「新建页面 → 找页面 → 预览 → Agent 改页面 → 按 PRD 更新」走一遍;看过一次就不再出现,侧栏标题旁的「?」可随时重看。
50
51
  - 🤖 **上下文感知的 AI Agent** —— 接本机 [OpenCode](https://opencode.ai),每条消息自动带当前页面 + PRD 路径;一键"按 PRD 标红内容更新页面"。
51
52
  - 🧱 **零后端的数据层** —— `BaseDataManager` 用 localStorage 做 CRUD,原型自带可交互假数据,不用起数据库。
52
- - ✅ **自动化红线检查** —— 静态规则 + Playwright 冒烟,改完即测,把 AI 拉回规范。
53
- - 📦 **脚手架分发** —— `create` 从零起项目、`init` 植入已有项目、`add-product` 加产品,`npm update` 升级框架。
54
- - 🖥 **跨平台** —— macOS / Windows / Linux;OpenCode 路径自动探测。
53
+ - ✅ **自动化红线检查** —— 静态规则开箱可用;安装 Playwright 与 Chromium 后可增加真实浏览器冒烟测试。
54
+ - 📦 **脚手架分发** —— `create` 从零起项目、`init` 植入已有项目、`add-product` 加产品,`npm update openprototype` 升级框架运行时。
55
+ - 🖥 **跨平台** —— macOS / Windows / Linux 均可手动启动;常驻服务目前仅支持 macOS / Windows,OpenCode 路径自动探测。
55
56
 
56
57
  ---
57
58
 
@@ -77,7 +78,7 @@
77
78
 
78
79
  ## 🚀 快速开始
79
80
 
80
- > 前置:Node ≥ 16。AI 面板另需本机 [OpenCode](https://opencode.ai)(见下节,可后装)。
81
+ > 前置:核心运行时需要 Node ≥ 16;若要运行 Playwright 冒烟测试或参与仓库开发,请使用 Node ≥ 18。AI 面板另需本机 [OpenCode](https://opencode.ai)(见后文,可后装)。
81
82
 
82
83
  ### 场景 ①:从零建项目
83
84
 
@@ -85,22 +86,44 @@
85
86
  npx openprototype create myapp
86
87
  cd myapp
87
88
  npm install
88
- npm run serve
89
89
  # 打开 http://127.0.0.1:8082/product/demo/pc/index.html
90
90
  ```
91
91
 
92
+ macOS / Windows 上,`npm install` 默认会注册并启动项目常驻服务,安装完成后直接打开上面的地址;不要再执行 `npm run serve`,否则会与常驻服务争用端口。Linux、禁用常驻服务或自动安装失败时,再执行:
93
+
94
+ ```bash
95
+ npm run serve
96
+ ```
97
+
92
98
  首跑就带一个可交互的 demo 产品(客户列表 + 表单 + PRD),照着它加自己的页面即可。
93
99
 
94
- ### 场景 ②:植入已有项目(非破坏式)
100
+ ### 场景 ②:植入已有项目
95
101
 
96
102
  ```bash
97
103
  cd 你的项目
98
104
  npm i openprototype
99
- npx openprototype init # 只补缺失文件、合并 package.json 脚本,不覆盖你已有内容
105
+ npx openprototype init
100
106
  npx openprototype add-product shop
101
- npm run serve
107
+ # 打开 http://127.0.0.1:8082/product/shop/pc/index.html
108
+ ```
109
+
110
+ `init` 不覆盖已有模板文件,会补充缺失资产并合并 `package.json` 脚本;但它也会修改 `package.json`,且默认在 macOS / Windows 上注册并启动系统常驻服务。Linux 或未启用常驻服务时,运行 `npm run serve` 手动启动。如果常驻服务已经运行,`add-product` 修改配置后执行一次 `npx openprototype service restart`,让 Agent 加载新产品的写入范围。
111
+
112
+ ### 常驻服务
113
+
114
+ 常驻服务让工作台在登录后自动运行,每个项目独立注册。它目前仅支持 macOS LaunchAgent 与 Windows 计划任务;Linux 请使用 `npm run serve`。
115
+
116
+ ```bash
117
+ npx openprototype service status
118
+ npx openprototype service restart
119
+ npx openprototype service logs
120
+ npx openprototype service uninstall
102
121
  ```
103
122
 
123
+ - 不想自动注册:在首次 `npm install` / `init` 前设置 `OPENPROTOTYPE_SERVICE_AUTO_INSTALL=0`,或提前在配置中设置 `"service": { "autoInstall": false }`。
124
+ - `service stop` 只停止本次运行,下次登录仍会启动;永久取消请用 `service uninstall`。
125
+ - 新增产品、修改端口或 Node 路径后,运行 `service restart` 让常驻服务加载新配置;升级包的安装钩子未自动重启成功时也应执行它。
126
+
104
127
  ---
105
128
 
106
129
  ## 🤖 AI Agent 怎么工作
@@ -115,7 +138,8 @@ npm run serve
115
138
 
116
139
  - **自动带上下文**:点左侧任一页面,面板顶部就显示「本条消息将携带:页面 X / PRD Y」,无需你手动贴路径。
117
140
  - **按 PRD 标红增量更新**:一键把 PRD 里 `<span style="color:red">…</span>` 标红的内容作为**唯一改动范围**发给 Agent —— 只改标红处,未标红的历史内容当背景,不重写、不"顺手优化"。
118
- - **本机私有**:服务器默认只监听 `127.0.0.1`;所有写入与 Agent 接口(`/api/*`)只接受本机请求——即使你用 `--host 0.0.0.0` 把预览开放给局域网同事,别人也只能看页面,改不了文件、动不了 Agent。
141
+ - **默认仅本机访问**:服务器默认只监听 `127.0.0.1`;所有写入与 Agent 接口(`/api/*`)只接受本机请求。
142
+ - **局域网开放边界**:使用 `--host 0.0.0.0` 后,局域网设备虽然不能调用写入与 Agent 接口,但能读取项目根目录下服务器可访问的非隐藏文件,不仅是原型页面。只应在可信网络和专用原型项目中使用,并确保项目中没有密钥或其他敏感文件。
119
143
 
120
144
  ### 安装 OpenCode(AI 面板前置)
121
145
 
@@ -138,7 +162,7 @@ npx openprototype doctor # 一键体检 Node / OpenCode / 配置 / Playwright
138
162
  ├─ proto-kit.config.json # 端口 / OpenCode / 产品列表(唯一配置入口)
139
163
  ├─ AGENTS.md # 给 AI 的协作规范(通用模板,你拥有可改)
140
164
  ├─ CONVENTIONS.md # 检查器强制的页面红线说明(和运行时耦合)
141
- ├─ skills/ # xiaojia(编码克制)+ auto-test(改完自动跑检查)
165
+ ├─ skills/ # xiaojia(编码克制)+ auto-test(要求改完运行检查)
142
166
  ├─ rules/ # 空目录:放你团队自己的 PRD 模板 / UI 规范
143
167
  └─ product/<id>/pc/
144
168
  ├─ index.html # 导航壳(薄,引用 /_kit 运行时)
@@ -150,10 +174,16 @@ npx openprototype doctor # 一键体检 Node / OpenCode / 配置 / Playwright
150
174
 
151
175
  | 层 | 内容 | 归属 | 更新方式 |
152
176
  |----|------|------|----------|
153
- | **运行时** | 服务器 / shared 引擎 / Agent 面板 / 检查脚本 | 框架(挂在 `/_kit/`) | `npm update` 一键升 |
154
- | **可编辑资产** | `AGENTS.md` `CONVENTIONS.md` `skills/` + 你自建的 `rules/` | 你拥有 | `openprototype update` 对比后按需合并 |
177
+ | **运行时** | 服务器 / shared 引擎 / Agent 面板 / 新手引导 / 检查脚本 | 框架(挂在 `/_kit/`) | `npm update openprototype` |
178
+ | **可编辑资产** | `AGENTS.md` `CONVENTIONS.md` `skills/` + 你自建的 `rules/` | 你拥有 | `npx openprototype update` 输出手工对比与合并指引 |
155
179
  | **业务内容** | 你的产品 PRD / 原型 / 数据 | 你拥有 | 你自己维护 |
156
180
 
181
+ > **产品壳(`product/<id>/pc/index.html`)是脚手架时复制的,不随包升级。** 框架给壳加了新入口(比如新手引导)时,
182
+ > 升级后跑一次 `npx openprototype init` 即可补上——幂等,已有的会跳过,你自己改过的部分不动。
183
+ >
184
+ > 新手引导的开关:URL 加 `?tour=off` 本次不弹;浏览器控制台执行 `window.ProtoTour.reset()` 可重置"已看过"标记,
185
+ > `window.ProtoTour.start()` 直接手动开一次。
186
+
157
187
  > 框架只带**最小通用规范**(页面红线 + 编码克制)。PRD 模板、UI 规范、业务术语这类**方法论属于你**,放进 `rules/` 与 `product/<id>/`,不随框架分发、也不被升级覆盖。
158
188
 
159
189
  **引擎回退解析**:页面用相对路径引用 `../shared/xxx.js` 时,若 `product/<id>/shared/` 下没有该文件,服务器自动回退到框架内置引擎(等价 `/_kit/shared/`)。因此:
@@ -166,18 +196,25 @@ npx openprototype doctor # 一键体检 Node / OpenCode / 配置 / Playwright
166
196
 
167
197
  ## 🧪 质量保障:红线检查器
168
198
 
169
- `openprototype check` 会强制这些页面红线(详见 [CONVENTIONS.md](templates/CONVENTIONS.md)):
199
+ `npx openprototype check` 会执行静态红线检查;安装 Playwright 与 Chromium 后,还会执行真实浏览器冒烟测试(详见 [CONVENTIONS.md](templates/CONVENTIONS.md)):
170
200
 
171
201
  - 脚本加载顺序固定 · 数据必须走 `BaseDataManager`(禁页面级 localStorage)
172
202
  - 状态文案常量化(禁硬编码 `<option>`)· 禁 Google Fonts(系统字体栈)
173
203
  - `?mode=view` 物理隐藏(`display:none`,非 `disabled`)· 打开页面无 console 报错
174
204
 
175
205
  ```bash
176
- openprototype check # 扫全部页面
177
- openprototype check --changed # 只扫 git 改动
206
+ npm run check # 扫全部页面
207
+ npm run check:changed # 只扫 git 改动
178
208
  ```
179
209
 
180
- 配套的 `auto-test` skill 会提醒 AI:**每次改完原型自动跑检查、修完 ERROR 再交付。**
210
+ 首次启用浏览器层:
211
+
212
+ ```bash
213
+ npm i -D playwright
214
+ npx playwright install chromium
215
+ ```
216
+
217
+ 未安装 Playwright 或 Chromium 时不能依赖浏览器层结果;安装完成后再把 `check` 视为完整检查。配套的 `auto-test` skill 会要求 Agent 在每次改完原型后运行检查并修完 ERROR;这是一条 Agent 工作流约定,不是服务器文件监听器。
181
218
 
182
219
  ---
183
220
 
@@ -186,13 +223,17 @@ openprototype check --changed # 只扫 git 改动
186
223
  ```json
187
224
  {
188
225
  "port": 8082,
189
- "host": "127.0.0.1", // 默认仅本机;'0.0.0.0' 可让局域网看预览(/api/* 仍仅限本机)
226
+ "host": "127.0.0.1",
227
+ "service": {
228
+ "autoInstall": true
229
+ },
190
230
  "opencode": {
191
- "bin": "auto", // 'auto' 自动探测;也可写绝对路径
231
+ "bin": "auto",
192
232
  "model": "deepseek/deepseek-v4-flash",
193
233
  "agent": "build",
194
234
  "host": "127.0.0.1",
195
- "port": 4097
235
+ "port": 4097,
236
+ "startTimeoutMs": 15000
196
237
  },
197
238
  "products": [
198
239
  { "id": "demo", "roots": ["pc"] }
@@ -200,23 +241,29 @@ openprototype check --changed # 只扫 git 改动
200
241
  }
201
242
  ```
202
243
 
244
+ `host` 默认为 `127.0.0.1`。设为 `0.0.0.0` 会向局域网开放静态文件读取,请先阅读上面的安全边界;长期运行的常驻服务还需显式执行 `npx openprototype service install --allow-lan`。
245
+
203
246
  环境变量可临时覆盖:`PROTO_KIT_PORT` · `PROTO_KIT_HOST` · `OPENCODE_BIN` · `OPENCODE_MODEL` · `OPENCODE_PORT`。
204
- 也可用 `node runtime/server.js --port 9000 --host 0.0.0.0` 临时指定端口 / 监听地址。
247
+ 也可用 `npx openprototype serve --port 9000 --host 0.0.0.0` 临时指定端口 / 监听地址。
205
248
 
206
249
  ---
207
250
 
208
251
  ## 📟 命令
209
252
 
253
+ 下表按“项目本地安装 `openprototype`”的默认场景统一使用 `npx`;如果已全局安装,可以省略 `npx`。`create` 会写入常用 npm scripts,`init` 在项目已有 `package.json` 时也会补充,因此日常可使用 `npm run serve`、`npm run check`、`npm run check:changed` 和 `npm run nav:sync`。
254
+
210
255
  | 命令 | 作用 |
211
256
  |------|------|
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` | 如何更新框架 |
257
+ | `npx openprototype create <dir>` | 从零创建新项目(含可运行 demo) |
258
+ | `npx openprototype init` | 补充缺失资产、合并脚本,并按配置安装常驻服务 |
259
+ | `npx openprototype add-product <id> [--title <名称>]` | 新增一个 PC 产品壳,可指定显示名称 |
260
+ | `npx openprototype serve [--port <端口>] [--host <地址>]` | 前台启动本地服务器,可临时覆盖监听配置 |
261
+ | `npx openprototype service <action>` | 管理常驻服务:`install/start/stop/restart/status/logs/uninstall/prune` |
262
+ | `npx openprototype check [--changed] [--static-only] [路径]` | 检查全部、Git 改动或指定范围;可只跑静态规则 |
263
+ | `npx openprototype nav:sync` | 扫描产品目录并重建 `nav-tree.json` |
264
+ | `npx openprototype doctor` | 体检 Node / OpenCode / 配置 / Playwright / 常驻服务 |
265
+ | `npm update openprototype` | 按 `package.json` 的版本范围升级框架运行时包 |
266
+ | `npx openprototype update` | 仅打印可编辑资产的手工对比与合并指引,不执行升级 |
220
267
 
221
268
  ---
222
269
 
@@ -236,6 +283,7 @@ openprototype check --changed # 只扫 git 改动
236
283
  欢迎 PR。开发约定:
237
284
 
238
285
  - 只用 Node 内置模块,运行时零依赖(检查器的 Playwright 是 devDependency)。
286
+ - 核心运行时支持 Node ≥ 16;完整安装当前 Playwright 依赖并跑检查需 Node ≥ 18。
239
287
  - 改运行时后跑 `npm run check`;改壳 / Agent 面板后本地起服务实测三栏。
240
288
  - 保持仓库**无任何私有信息**(公司 / 个人 / 内网地址 / 密钥)。
241
289
 
package/bin/cli.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * openprototype CLI
6
6
  *
7
7
  * openprototype create <dir> 从零创建一个新项目(场景①)
8
- * openprototype init 把框架植入当前已有项目(场景②,非破坏式)
8
+ * openprototype init 把框架植入当前已有项目(保留已有模板,可能安装常驻服务)
9
9
  * openprototype add-product <id> 新增一个产品壳(默认 pc)
10
10
  * openprototype serve 启动本地服务器
11
11
  * openprototype service <action> 管理本地常驻服务
@@ -97,6 +97,69 @@ function scaffoldProductShell(projectRoot, productId, productTitle) {
97
97
  writeFileSafe(path.join(dir, 'nav-tree.json'), '[]\n');
98
98
  }
99
99
 
100
+ // 新手引导的两行引用标签。壳 HTML 是脚手架时复制的、不会随 npm update 升级,
101
+ // 所以老项目的壳里没有这两行;这里在 init 时补进去(真正的逻辑在 /_kit/shell/onboarding.*,会随包升级)。
102
+ const ONBOARDING_MARK = 'onboarding:start';
103
+ const ONBOARDING_HEAD = [
104
+ '<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->',
105
+ '<link rel="stylesheet" href="/_kit/shell/onboarding.css">',
106
+ '<!-- onboarding:end -->'
107
+ ].join('\n');
108
+ const ONBOARDING_BODY = [
109
+ '<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->',
110
+ '<script src="/_kit/shell/onboarding.js"></script>',
111
+ '<!-- onboarding:end -->'
112
+ ].join('\n');
113
+
114
+ /** 列出 product/<id>/<root>/index.html —— 已生成的产品壳 */
115
+ function listProductShells(projectRoot) {
116
+ const shells = [];
117
+ const productDir = path.join(projectRoot, 'product');
118
+ if (!fs.existsSync(productDir)) return shells;
119
+ for (const productId of fs.readdirSync(productDir)) {
120
+ const dir = path.join(productDir, productId);
121
+ if (!fs.statSync(dir).isDirectory()) continue;
122
+ for (const rootName of fs.readdirSync(dir)) {
123
+ const shell = path.join(dir, rootName, 'index.html');
124
+ if (fs.existsSync(shell)) shells.push(shell);
125
+ }
126
+ }
127
+ return shells;
128
+ }
129
+
130
+ /**
131
+ * 给已有的产品壳补上新手引导的引用标签。
132
+ * 幂等:见到 onboarding:start 就跳过;壳里没有 agent-panel 标记的一律不动(不是本框架的壳)。
133
+ * 引导的 <script> 必须排在 agent-panel.js 之后,那里才定义了 window.PROTO_KIT。
134
+ */
135
+ function patchShellOnboarding(projectRoot) {
136
+ let patched = 0;
137
+ for (const shell of listProductShells(projectRoot)) {
138
+ const rel = path.relative(projectRoot, shell);
139
+ let html = fs.readFileSync(shell, 'utf8');
140
+ if (html.includes(ONBOARDING_MARK)) { info(C.dim(' 跳过(已有引导入口): ') + rel); continue; }
141
+ if (!html.includes('/_kit/shell/agent-panel.js')) { info(C.dim(' 跳过(非本框架的壳): ') + rel); continue; }
142
+
143
+ const headAnchor = '<!-- agent-panel:end -->';
144
+ const bodyAnchor = '<script src="/_kit/shell/agent-panel.js"></script>';
145
+ const headAt = html.indexOf(headAnchor);
146
+ const bodyAt = html.indexOf(bodyAnchor);
147
+ if (headAt === -1 || bodyAt === -1) { info(C.dim(' 跳过(壳结构不认识): ') + rel); continue; }
148
+
149
+ // 先补后面的、再补前面的,免得插入把后一个位置的下标顶偏
150
+ const bodyEnd = html.indexOf(headAnchor, bodyAt);
151
+ const bodyInsertAt = bodyEnd === -1 ? bodyAt + bodyAnchor.length : bodyEnd + headAnchor.length;
152
+ html = html.slice(0, bodyInsertAt) + '\n' + ONBOARDING_BODY + html.slice(bodyInsertAt);
153
+ const headInsertAt = headAt + headAnchor.length;
154
+ html = html.slice(0, headInsertAt) + '\n' + ONBOARDING_HEAD + html.slice(headInsertAt);
155
+
156
+ fs.writeFileSync(shell, html);
157
+ ok('已补上新手引导入口 ' + rel);
158
+ patched++;
159
+ }
160
+ return patched;
161
+ }
162
+
100
163
  /** 新项目 package.json 里本框架的依赖版本(已发布 npm,语义化版本管理) */
101
164
  function kitDependencySpec() {
102
165
  const pkg = readJson(path.join(PKG_ROOT, 'package.json'), {});
@@ -168,7 +231,7 @@ function cmdCreate(argv) {
168
231
  async function cmdInit() {
169
232
  const root = process.cwd();
170
233
  let serviceInstallDenied = false;
171
- info(C.b('\n把 openprototype 植入当前项目(非破坏式)…\n'));
234
+ info(C.b('\n把 openprototype 植入当前项目(保留已有模板,按配置安装常驻服务)…\n'));
172
235
 
173
236
  copyIfAbsent(path.join(TPL, 'skills'), path.join(root, 'skills'));
174
237
  copyIfAbsent(path.join(TPL, 'AGENTS.md'), path.join(root, 'AGENTS.md'));
@@ -178,6 +241,8 @@ async function cmdInit() {
178
241
  ok('写入 ' + CONFIG_FILENAME);
179
242
  } else info(C.dim(' 跳过(已存在): ') + CONFIG_FILENAME);
180
243
 
244
+ patchShellOnboarding(root);
245
+
181
246
  // 合并 package.json 脚本(不覆盖用户已有脚本)
182
247
  const pkgPath = path.join(root, 'package.json');
183
248
  if (fs.existsSync(pkgPath)) {
@@ -396,6 +461,9 @@ function cmdUpdate() {
396
461
  info(C.b('\n更新 openprototype\n'));
397
462
  info('运行时(服务器 / shared 引擎 / Agent 面板 / 检查脚本)随包升级:');
398
463
  info(C.g(' npm update openprototype\n'));
464
+ info('产品壳(product/*/*/index.html)是脚手架时复制的,不随包升级。');
465
+ info('升级后跑一次下面这条,可给已有的壳补上新功能入口(幂等,已有的会跳过):');
466
+ info(C.g(' npx openprototype init\n'));
399
467
  info('可编辑资产(rules / prompts / workflow / AGENTS.md)由你拥有,不会被自动覆盖。');
400
468
  info('想同步最新模板时,对比这些目录后按需合并:');
401
469
  info(C.dim(' node_modules/openprototype/templates/ → 你项目里的 AGENTS.md / CONVENTIONS.md / skills/'));
@@ -409,11 +477,11 @@ ${C.b('openprototype')} — 本地原型工作台脚手架
409
477
 
410
478
  用法:
411
479
  ${C.g('openprototype create <dir>')} 从零创建新项目
412
- ${C.g('openprototype init')} 把框架植入当前已有项目(非破坏式)
480
+ ${C.g('openprototype init')} 补充缺失资产、合并脚本,并按配置安装常驻服务
413
481
  ${C.g('openprototype add-product <id>')} 新增一个产品壳(默认 pc)
414
482
  ${C.g('openprototype serve')} 启动本地服务器
415
483
  ${C.g('openprototype service <action>')} 管理常驻服务(install/start/stop/restart/status/logs/uninstall/prune)
416
- ${C.g('openprototype check [--changed]')} 自动化检查(静态红线 + 冒烟)
484
+ ${C.g('openprototype check [--changed]')} 自动化检查(静态红线;安装 Playwright 后增加冒烟)
417
485
  ${C.g('openprototype nav:sync')} 重建各产品 nav-tree.json
418
486
  ${C.g('openprototype doctor')} 体检(Node / OpenCode / 配置 / Playwright)
419
487
  ${C.g('openprototype update')} 如何更新框架
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openprototype",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "description": "本地原型工作台:左侧树形导航 + 中间原型预览 + 右侧 AI Agent(OpenCode)。PRD 与 HTML/JS 原型协作,含自动化检查。",
5
5
  "keywords": [
6
6
  "prototype",
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>订单列表</title>
7
+ <style>
8
+ *, *::before, *::after { box-sizing: border-box; }
9
+ body {
10
+ margin: 0;
11
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
12
+ font-size: 13px; color: #20242d; background: #f3f5f8; padding: 20px;
13
+ }
14
+ .page-title { font-size: 18px; font-weight: 600; margin: 0 0 16px; }
15
+ .panel { background: #fff; border: 1px solid #e6ebf2; border-radius: 8px; padding: 20px; }
16
+ .placeholder { color: #7b8495; margin: 0; }
17
+ </style>
18
+ </head>
19
+ <body>
20
+ <h1 class="page-title">订单列表</h1>
21
+ <div class="panel">
22
+ <p class="placeholder">「订单列表」原型待完善:可直接编辑本文件,或在导航页选中该页面后通过右侧 Agent 生成内容。</p>
23
+ </div>
24
+ </body>
25
+ </html>
@@ -0,0 +1,18 @@
1
+ # 订单列表 PRD
2
+
3
+ ## 一、页面信息
4
+
5
+ | 项 | 内容 |
6
+ |----|------|
7
+ | 页面名称 | 订单列表 |
8
+ | 页面文件 | order_list.html |
9
+
10
+ ## 二、需求说明
11
+
12
+ (待补充)
13
+
14
+ ## 修订记录
15
+
16
+ | 版本 | 日期 | 修订人 | 说明 |
17
+ |------|------|--------|------|
18
+ | V1.0.0 | 2026-07-24 | | 新建页面 |