@@ -16,8 +16,7 @@ A Vite plugin that lets AI agents (Claude Code, Cursor, etc.) **see, interact wi
1616- ** Zero Config** — Drop-in Vite plugin, works with any Vite project (Vue, React, vanilla JS, etc.)
1717- ** Compact Snapshot** — Page state serialized into ~ 80 lines of text, optimized for LLM context windows
1818- ** Multi-Instance** — Each browser tab is independently tracked, switch freely with ` PILOT_INSTANCE `
19- - ** Dual Channel** — File I/O CLI (` bin/pilot.js ` ) + HTTP API (` /__pilot/* ` )
20- - ** Auto Reload** — Browser auto-refreshes when dev server restarts (v132)
19+ - ** Auto Reload** — Browser auto-refreshes when dev server restarts
2120- ** Vue/React Aware** — ` typeByPlaceholder ` dispatches input events for v-model compatibility
2221
2322## Installation
@@ -48,105 +47,42 @@ pnpm dev
4847# Open http://localhost:5173 in your browser
4948```
5049
51- ### 3. Use the CLI to interact
50+ ### 3. Configure your AI agent
5251
53- ``` bash
54- # See the current page state (compact snapshot)
55- node bin/pilot.js page
56-
57- # Execute JS and see the result + updated page
58- node bin/pilot.js run ' __pilot_clickByText("Submit")' page
59-
60- # Execute JS and see console logs
61- node bin/pilot.js run ' document.title' logs
62- ```
63-
64- That's it! The agent can now read the compact snapshot, decide what to do, execute actions, and verify results — all in a single tool call.
52+ Copy the following into your AI agent's instruction file:
6553
66- ## Compact Snapshot Format
67-
68- The page is serialized into a compact text format designed for LLM consumption:
69-
70- ```
71- # url: http://localhost:5173/
72- # title: My App
73- sections Overview|Settings|Users
74- button #3 Save|#4 Cancel
75- input #10 ph:Username
76- select #12 check=1 <Admin|Editor|Viewer>
77- checkbox check=agree I agree
78- textarea #15 ph:Description...
79- th Name|Role|Actions
80- tr Alice|Admin|Delete
81- ```
54+ ** Claude Code** → paste into project ` CLAUDE.md ` :
8255
83- Format: ` tag#idx[val=V][check=N][type:T][ph=P][disabled] text `
56+ ``` markdown
57+ <!-- vite-plugin-pilot:start -->
58+ # vite-plugin-pilot
8459
85- - ` #idx ` — Element index for precise operations: ` __pilot_click(10) `
86- - ` [val=V] ` — Current value
87- - ` [check=N] ` — Selected option index (0-based)
88- - ` [ph=P] ` — Placeholder text
89- - ` [disabled] ` — Element is disabled
60+ 辅助 AI agent 测试浏览器页面。通过文件 I/O 在浏览器执行 JS。` pnpm dev ` 启动,浏览器打开页面即可使用。
9061
91- ## CLI Reference
62+ ## 工作流
9263
9364``` bash
94- node bin/pilot.js page # View page (compact snapshot)
95- node bin/pilot.js page cached # View cached snapshot (0.03s, no browser round-trip)
96- node bin/pilot.js run ' code' page # Execute JS + view result + page (one step, recommended)
97- node bin/pilot.js run ' code' logs # Execute JS + view result + logs
98- node bin/pilot.js logs # View recent console logs
99- node bin/pilot.js status # List connected browser tabs
100-
101- # Target a specific tab
102- PILOT_INSTANCE=xxxxxxxx node bin/pilot.js page
65+ npx pilot page # 看页面(compact 格式)
66+ npx pilot run ' 代码' page # 操作+看结果(一步完成)
67+ npx pilot run ' 代码' logs # 操作+看日志
68+ npx pilot logs # 看最近日志
69+ npx pilot status # 查看连接的 tab 列表
70+ npx pilot help # 查看辅助函数列表
10371```
10472
105- ** Recommended pattern** : ` page ` → read snapshot → ` run 'code' page ` → verify. Prefer ` run 'code' page ` (one step) to avoid two ~ 5s polling delays.
106-
107- ## Helper Functions
108-
109- ### Text Matching (recommended, refreshes element references each time)
110-
111- | Function | Description |
112- | ----------| -------------|
113- | ` __pilot_clickByText(text, nth?) ` | Click element by text content |
114- | ` __pilot_typeByPlaceholder(ph, value) ` | Type into input (triggers input events for v-model) |
115- | ` __pilot_setValueByPlaceholder(ph, value, nth?) ` | Set input value |
116- | ` __pilot_selectValueByText(text, nth?) ` | Select dropdown option |
117- | ` __pilot_checkByText(text, nth?) ` | Check checkbox |
118- | ` __pilot_findByText(text) ` | Find elements → ` [{idx, tag, text}] ` |
119- | ` __pilot_waitFor(text, timeout?, disappear?) ` | Wait for text to appear/disappear |
120- | ` __pilot_waitEnabled(text, timeout?) ` | Wait for disabled element to become enabled |
73+ ** 使用模式** :` page ` 看 compact → 读取 ` #idx ` 或用文本匹配 → ` run '操作代码' page ` → 验证结果。优先用 ` run 'code' page ` 一步完成(避免两次 ~ 5s 轮询延迟)。
12174
122- ### Index-Based (read ` #N ` from compact)
123-
124- | Function | Description |
125- | ----------| -------------|
126- | ` __pilot_click(i) ` | Click element by index |
127- | ` __pilot_setValue(i, value) ` | Set input value |
128- | ` __pilot_type(i, value) ` | Type into input by index |
129- | ` __pilot_dblclick(i) ` | Double-click element |
130- | ` __pilot_hover(i) ` | Hover over element |
131-
132- ### Other
133-
134- | Function | Description |
135- | ----------| -------------|
136- | ` __pilot_wait(ms) ` | Wait for milliseconds |
137- | ` __pilot_snapshot() ` | Get full JSON snapshot |
138- | ` __pilot_scrollIntoView(i) ` | Scroll element into view |
139- | ` __pilot_getRect(i) ` | Get element bounding rect |
140- | ` __pilot_checkMultipleByText([t1, t2]) ` | Check multiple checkboxes |
141- | ` __pilot_uncheckByText(text, nth?) ` | Uncheck checkbox |
142- | ` __pilot_keydownByText(text, key) ` | Trigger keydown on element |
75+ ** 关键注意** :
76+ - ** 同一 exec 完成相关操作** (填写+提交),跨 exec Vue/React 状态可能丢失
77+ - 多步操作间 ` await __pilot_wait(0) ` 让 Vue scheduler 处理响应式更新
78+ - ** 始终用 ` typeByPlaceholder ` ** :Vue/React v-model 需要 input 事件,` type ` 触发 input 事件,` setValue ` 只改 DOM
79+ - ` page cached ` 读缓存(0.03s),不需要最新状态时用
80+ <!-- vite-plugin-pilot:end -->
81+ ```
14382
144- ## Important Notes
83+ ** Cursor / Other agents ** → paste into ` .cursorrules ` or project rules, content same as above.
14584
146- - ** Complete related operations in one exec** (fill + submit) — Vue/React state may be lost across execs
147- - ** Always use ` typeByPlaceholder ` ** over ` setValueByPlaceholder ` — Vue/React v-model needs input events
148- - ** Use ` await __pilot_wait(0) ` ** between multi-step operations to let Vue scheduler process reactive updates
149- - ** Use ` __pilot_waitFor ` ** instead of ` __pilot_wait(N) ` — poll-based condition checking is more reliable than guessing wait times
85+ That's it! The agent can now autonomously develop and verify features for you.
15086
15187## How It Works
15288
@@ -166,7 +102,7 @@ PILOT_INSTANCE=xxxxxxxx node bin/pilot.js page
166102
167103## Playground
168104
169- The project includes a multi-framework playground for dogfooding :
105+ The project includes a multi-framework playground:
170106
171107``` bash
172108pnpm dev
0 commit comments