@sleepinsummer/agent-browser-cli 0.2.9 → 0.3.1-beta.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.
@@ -1,238 +1,204 @@
1
1
  ---
2
2
  name: agent-browser-cli
3
- description: 使用 agent-browser-cli 进行浏览器感知与控制。适用于标签页扫描/切换、页面 JS 执行、CookieCDP、contentSettings、截图、文件上传、下拉框点击、tmwd_cdp_bridge 初始化和 Web 工具排障。
3
+ description: 使用 agent-browser-cli 进行浏览器感知与控制、页面交互、截图/PDF、Cookie/CDP 和排障。
4
4
  ---
5
5
 
6
6
  # agent-browser-cli
7
7
 
8
- 使用 `agent-browser-cli` 进行浏览器控制。底层通过 Rust 常驻服务和 Chrome 扩展接管用户浏览器,保留登录态和 Cookie;不是 Selenium/Playwright。
8
+ 使用 `agent-browser-cli` 控制用户真实 Chrome。底层是 Rust daemon + Chrome 扩展桥,保留登录态和 Cookie;不是 Selenium/Playwright。
9
9
 
10
- ## 项目路径
10
+ ## 先做健康检查
11
11
 
12
- 安装后必须把下面的占位路径替换为用户本机真实项目路径,避免 AI 在其它项目目录里误找工具:
12
+ 每次开始浏览器任务,先执行:
13
13
 
14
14
  ```bash
15
- <AGENT_BROWSER_CLI_PROJECT_DIR>
15
+ agent-browser-cli status
16
16
  ```
17
17
 
18
- 日常调用先进入用户本机真实项目路径:
19
-
20
- ```bash
21
- cd <AGENT_BROWSER_CLI_PROJECT_DIR>
22
- ```
18
+ `healthy=true` 且 `summary=ready` 时再继续操作。
23
19
 
24
- 优先通过 npm 安装 CLI:
20
+ 如果不健康,执行:
25
21
 
26
22
  ```bash
27
- npm install -g @sleepinsummer/agent-browser-cli
28
- agent-browser-cli --help
23
+ agent-browser-cli doctor
24
+ agent-browser-cli logs --tail 100
29
25
  ```
30
26
 
31
- 如果 npm 平台包不可用,再在项目根目录源码构建:
27
+ 再按 `references/operations.md` 处理。`doctor` 只检查状态,不自动启动 daemon、不改配置、不安装 skill。
32
28
 
33
- ```bash
34
- cargo build --release
35
- ./target/release/agent-browser-cli --help
36
- ```
29
+ ## 常用命令优先级
37
30
 
38
- 扩展目录:
31
+ 先区分三个入口:
39
32
 
40
33
  ```text
41
- assets/tmwd_cdp_bridge
34
+ scan:内容感知,适合看正文、列表、页面文本。
35
+ snapshot:操作定位,适合找按钮、链接、输入框并生成 @e 引用。
36
+ exec / JSON CDP:逃生口,封装命令失效或特殊页面时回退。
42
37
  ```
43
38
 
44
- 扩展配置必须存在:
39
+ 基础排障和感知:
45
40
 
46
- ```js
47
- globalThis.__agent_browser_cli_TID = '__agent_browser_cli_bridge_26c9f1';
41
+ ```bash
42
+ agent-browser-cli status
43
+ agent-browser-cli doctor
44
+ agent-browser-cli logs --tail 100
45
+ agent-browser-cli tabs
46
+ agent-browser-cli scan --tabs-only
47
+ agent-browser-cli scan --tab <tabId> --text-only
48
+ agent-browser-cli open https://example.com
49
+ agent-browser-cli close --tab <tabId>
50
+ agent-browser-cli exec --tab <tabId> 'return document.title'
48
51
  ```
49
52
 
50
- 对应文件:
53
+ 第二阶段后的推荐流程:
51
54
 
52
55
  ```text
53
- assets/tmwd_cdp_bridge/config.js
56
+ 看页面内容:scan / scan --text-only
57
+ selector 明确时:直接 click/fill selector
58
+ selector 不明确或页面复杂时:snapshot 生成 @e,再 click/fill @e
59
+ 页面结构或内容变化后:重新 snapshot
60
+ 封装命令失效或覆盖不到特殊页面时:回退 exec / JSON CDP / 自定义 JS
54
61
  ```
55
62
 
56
- ## 最小自检
57
-
58
- Chrome 必须已打开,且至少有一个正常网页标签页,不能只停留在 `about:blank`、`chrome://` 等内部页。
59
-
60
- 优先用常驻会话 CLI 自检。它会自动启动 Rust 常驻服务,复用同一个浏览器扩展连接,默认空闲 300 秒自动退出;每次请求都会续期。
63
+ 示例:
61
64
 
62
65
  ```bash
63
- agent-browser-cli tabs
66
+ agent-browser-cli scan --text-only
67
+ agent-browser-cli click 'button[type=submit]'
68
+ agent-browser-cli snapshot --limit 200
69
+ agent-browser-cli snapshot --offset 200 --limit 200
70
+ agent-browser-cli snapshot --details
71
+ agent-browser-cli click '@e1'
72
+ agent-browser-cli fill '@e2' 'hello'
73
+ agent-browser-cli fill '@e2' --clear
74
+ agent-browser-cli fill '@e2' ' world' --append
75
+ agent-browser-cli send-keys --target '@e2' 'Enter'
76
+ agent-browser-cli mouse-click '@e3'
64
77
  ```
65
78
 
66
- 服务状态、停止和重载:
79
+ 所有高层操作都支持 `--tab <tabId>`;`@e` 只在当前 daemon、当前 tab、最近一次 `snapshot` 内有效。`@e` 只接受 `@e1` 这种带 `@` 的格式。
80
+
81
+ 慢页面要把等待和监控分开:
67
82
 
68
83
  ```bash
69
- agent-browser-cli status
70
- agent-browser-cli stop
71
- agent-browser-cli restart
84
+ agent-browser-cli click '@e1' --wait-js 'return document.body.innerText.includes("完成")' --wait-timeout 10 --monitor
72
85
  ```
73
86
 
74
- 常驻服务端口:
75
- - `18765`:默认插件 WebSocket 端口,Chrome 扩展连接使用,可通过插件 popup 或 `agent-browser-cli set-extension-port <port>` 修改。
76
- - `18767`:外层 `agent-browser-cli` HTTP API 端口,供 CLI 复用会话,不能作为插件端口使用。
87
+ `--wait-js` 负责等慢加载;`--monitor` 只负责操作前后页面 diff,默认关闭。
88
+
89
+ ## 端口和扩展
77
90
 
78
- 插件端口配置文件:
91
+ 固定 API 端口:
79
92
 
80
93
  ```text
81
- ~/.agent-browser-cli/config.json
94
+ 127.0.0.1:18767
95
+ ```
96
+
97
+ 默认扩展 WebSocket 端口:
98
+
99
+ ```text
100
+ 127.0.0.1:18765
82
101
  ```
83
102
 
84
- 最小配置:
103
+ 配置文件:
85
104
 
86
- ```json
87
- {
88
- "extension_port": 18765
89
- }
105
+ ```text
106
+ ~/.agent-browser-cli/config.json
90
107
  ```
91
108
 
92
- CLI 修改插件端口:
109
+ 修改扩展端口会影响 Chrome 扩展和 daemon 连接,执行前必须说明影响并取得用户确认:
93
110
 
94
111
  ```bash
95
- agent-browser-cli set-extension-port 18766
112
+ agent-browser-cli set-extension-port <port>
96
113
  ```
97
114
 
98
- Chrome 插件 popup 也可以修改插件端口并立即重连。插件端口必须和 CLI 配置中的 `extension_port` 一致。
99
115
 
100
- 成功标志:
101
- - 返回 `status=success`
102
- - 能看到 `tabs_count`
103
- - `agent-browser-cli status` 中 `ports.extension.matched=true`
104
- - `agent-browser-cli status` 中 `connection.extension_connected=true`
105
116
 
106
- ## 推荐 CLI 调用
117
+ ## 网络和控制台调试
107
118
 
108
- 日常操作优先使用 `agent-browser-cli`,避免直接操作底层协议。
119
+ `network` / `console` 需要扩展侧持续监听 CDP 事件。修改或升级扩展后,必须先让用户重载 Chrome 插件。
109
120
 
110
121
  ```bash
111
- cd <AGENT_BROWSER_CLI_PROJECT_DIR>
112
- agent-browser-cli status
113
- agent-browser-cli tabs
114
- agent-browser-cli scan --tabs-only
115
- agent-browser-cli scan --tab 303987837 --text-only
116
- agent-browser-cli open https://www.baidu.com
117
- agent-browser-cli exec --tab 303987837 'return document.title'
118
- agent-browser-cli exec --tab 303987837 '{"cmd":"tabs"}'
119
- agent-browser-cli restart
120
- agent-browser-cli stop
122
+ agent-browser-cli network start --tab <tabId>
123
+ agent-browser-cli network list --tab <tabId> --filter api
124
+ agent-browser-cli network detail <requestId> --tab <tabId>
125
+ agent-browser-cli network clear --tab <tabId>
126
+ agent-browser-cli network stop --tab <tabId>
127
+
128
+ agent-browser-cli console start --tab <tabId>
129
+ agent-browser-cli console list --tab <tabId>
130
+ agent-browser-cli console list --tab <tabId> --level error
131
+ agent-browser-cli console clear --tab <tabId>
132
+ agent-browser-cli console stop --tab <tabId>
121
133
  ```
122
134
 
123
- 执行较复杂 JS 时,把脚本写入文件再调用:
135
+ `network detail` 会截断大响应体并标记 `base64Encoded`,不要把巨大 body 粘到对话里。`network clear` 清请求缓存;`network stop` 会停止监听并清请求缓存。`console clear` 清日志缓存;`console stop` 会停止监听并清日志缓存。
124
136
 
125
- ```bash
126
- agent-browser-cli exec --tab 303987837 --file /tmp/script.js
127
- ```
128
137
 
129
- `exec` 默认只执行 JS,不做执行前后 DOM 扫描。需要页面变化摘要时显式加 `--monitor`。
138
+ `agent-browser-cli stop` / daemon idle 退出时会额外清理 daemon 内的 snapshot/@e 缓存,并通知扩展清理 network/console 调试缓存。
130
139
 
131
- ```bash
132
- agent-browser-cli exec --tab 303987837 --monitor 'return document.title'
133
- ```
140
+ ## 标签分组
134
141
 
135
- 需要等待页面变化时,不要在脚本里固定 `setTimeout`。优先用 `--wait-js` 做条件等待,条件满足会立即返回;普通页面 JS 会把主脚本和等待条件合并到同一次浏览器执行里,减少往返:
142
+ 多任务开新标签时可以用 session 或 group-title 把标签放入 Chrome 原生标签组。分组只是整理浏览器标签,失败不影响开 tab 主流程。
136
143
 
137
144
  ```bash
138
- agent-browser-cli exec --tab 303987837 'document.querySelector("button").click()' --wait-js 'return document.body.innerText.includes("完成")' --wait-timeout 3
145
+ agent-browser-cli open https://example.com --session research
146
+ agent-browser-cli open https://example.com
147
+ agent-browser-cli close --tab <tabId> --group-title "任务A"
139
148
  ```
140
149
 
141
- ## 基础调用
150
+ `--session` 和 `--group-title` 都会作为标签组标题;两者同时传时优先使用 `--group-title`。
142
151
 
143
- `scan` 负责感知,`exec` 负责精确操作。能精确操作时,不做全量扫描。
152
+ ## 截图和 PDF
153
+
154
+ 截图/PDF 必须让 CLI 写文件,不要把 base64 大段塞进上下文。命令只返回路径、字节数和少量元信息。
144
155
 
145
156
  ```bash
146
- agent-browser-cli scan --tabs-only
147
- agent-browser-cli scan
148
- agent-browser-cli scan --text-only
149
- agent-browser-cli scan --tab 303987837
157
+ agent-browser-cli screenshot --out /tmp/page.png
158
+ agent-browser-cli screenshot --full-page --out /tmp/full.png
159
+ agent-browser-cli screenshot --target '@e1' --out /tmp/button.png
160
+ agent-browser-cli screenshot --selector 'button[type=submit]' --format jpeg --quality 70 --out /tmp/button.jpg
161
+ agent-browser-cli save-pdf --out /tmp/page.pdf
162
+ agent-browser-cli save-pdf --paper a4 --landscape --scale 0.9 --out /tmp/page.pdf
150
163
  ```
151
164
 
152
- 普通页面 JS:
165
+ `screenshot` 默认截当前视口;`--full-page` 截全页;`--target` 和兼容别名 `--selector` 二选一,目标既可以是 `@e` 也可以是 CSS selector。没有 `--out` 时,截图写到 `/tmp/agent-browser-cli-screenshots/`。
153
166
 
154
- ```bash
155
- agent-browser-cli exec 'return document.title'
156
- agent-browser-cli exec 'return { title: document.title, url: location.href }'
157
- ```
167
+ `save-pdf` 默认 `paper=a4`、`scale=1.0`、`print-background=true`;需要关闭背景时用 `--no-print-background`。没有 `--out` 时,PDF 写到 `/tmp/agent-browser-cli-pdfs/`,默认文件名来自清理后的页面标题。
158
168
 
159
- `exec` 内使用 `await` 时必须显式 `return`,否则结果可能是 `null`。
169
+ 如果封装命令失效,用 `exec` CDP 后由脚本落盘,仍然避免把 base64 粘到对话里。
160
170
 
161
- `scan` 只读取当前页,不负责导航。切换网站用 `open` 或 `exec` 执行:
171
+ ## exec 使用规则
172
+
173
+ 执行复杂 JS 时写入临时文件:
162
174
 
163
175
  ```bash
164
- agent-browser-cli open https://example.com
165
- agent-browser-cli exec "location.href='https://example.com'; return location.href"
176
+ agent-browser-cli exec --tab <tabId> --file /tmp/script.js
166
177
  ```
167
178
 
168
- 新开标签页优先使用原生 `open` 命令,不要用 `window.open` 加 `--monitor`。`open` 底层走扩展 `chrome.tabs.create`,不会触发 CDP debugger attach。
179
+ 需要等待页面变化时使用 `--wait-js`,不要在脚本里固定 `setTimeout`:
169
180
 
170
181
  ```bash
171
- agent-browser-cli open www.baidu.com
172
- agent-browser-cli new-tab https://example.com --background
182
+ agent-browser-cli exec --tab <tabId> 'document.querySelector("button").click()' --wait-js 'return document.body.innerText.includes("完成")' --wait-timeout 3
173
183
  ```
174
184
 
175
- JS 事件的 `isTrusted=false`,敏感操作可能被页面拦截。JS 点击按钮打不开新 tab 时,优先改用 CDP 点击。
185
+ `exec` 中使用 `await` 必须显式 `return`,否则结果可能是 `null`。
176
186
 
177
- ## 扩展 JSON 指令
187
+ ## JSON/CDP 逃生口
178
188
 
179
- 跨标签页、Cookie、CDP、扩展管理、浏览器内容权限时,优先用 JSON 字符串直传,不要自己拼 DOM 节点。
189
+ 跨标签页、Cookie、CDP、扩展管理、浏览器内容权限时,用 JSON 指令:
180
190
 
181
191
  ```bash
182
192
  agent-browser-cli exec '{"cmd":"tabs"}'
183
193
  agent-browser-cli exec '{"cmd":"cookies"}'
184
194
  agent-browser-cli exec '{"cmd":"cdp","tabId":303987837,"method":"Page.captureScreenshot","params":{"format":"png"}}'
185
- agent-browser-cli exec '{"cmd":"batch","tabId":303987837,"commands":[{"cmd":"tabs"},{"cmd":"cookies"}]}'
186
195
  ```
187
196
 
188
- 常用命令:
189
- - `{"cmd":"tabs"}`:读取或切换标签页。
190
- - `{"cmd":"openTab","url":"https://example.com","active":true}`:原生创建标签页。
191
- - `{"cmd":"cookies"}`:读取当前页 Cookie。
192
- - `{"cmd":"cdp","tabId":N,"method":"...","params":{}}`:执行单个 CDP 命令。
193
- - `{"cmd":"batch","tabId":N,"commands":[...]}`:同一链路内批量执行,支持 `$N.path` 引用前序结果。
194
- - `{"cmd":"management","method":"list|reload|disable|enable","extId":"..."}`:管理扩展。
195
- - `{"cmd":"contentSettings","type":"automaticDownloads","pattern":"https://*/*","setting":"allow"}`:设置内容权限。
196
-
197
- `contentSettings` 用于绕过 Chrome “下载多个文件”对话框,该对话框会阻塞浏览器 JS 执行。可选 `type` 包括 `automaticDownloads`、`popups`、`notifications` 等;`setting` 包括 `allow`、`block`、`ask`。CDP 的 `Browser.setDownloadBehavior` 在当前扩展环境不可用,因为 `chrome.debugger` 是 tab 级权限。
198
-
199
- `batch` 前序命令失败时,后续 `$N.path` 引用会静默变成 `undefined`,必须检查 `results` 数组中每项的 `ok` 状态。同一条 CDP 链路内保持 `nodeId` 来源一致,不要混用 `querySelector` 路径和 `performSearch` 路径。
200
-
201
- CDP 默认使用当前注入页的 `sender.tab.id`,跨 tab 操作必须显式传 `tabId`,或先在 `batch` 里通过 `tabs` 查询目标标签。
202
-
203
- ## CDP 操作要点
204
-
205
- 通用点击使用三事件序列:
206
-
207
- ```text
208
- mouseMoved -> mousePressed -> mouseReleased
209
- ```
210
-
211
- 省略 `mouseMoved` 可能导致 MUI Tooltip、Ant Design Dropdown 等 hover 依赖组件失效。稳定状态下 CDP 坐标等于 `getBoundingClientRect()` 坐标,不需要修正。
212
-
213
- 首次 CDP attach 会触发 Chrome infobar,页面内容可能下移约 20px。首次操作前先发无害 `mouseMoved(0,0)` 预热,再测量元素坐标。
214
-
215
- Vue3 自定义 Select/Dropdown 优先走 vnode 实例调用;CDP 坐标点击适合选项少且可见的场景。CDP 下拉框流程是先点击 select 打开下拉,再测量动态 option,再点击 option。
216
-
217
- 某些 SPA 后台标签不会加载数据,需要先用 CDP `Page.bringToFront` 切到前台。跨标签页操作时显式传 `tabId`,不依赖当前页。
218
-
219
- 页面存在 `transform: scale` 或 CSS `zoom` 时,坐标需要按页面缩放修正:
220
-
221
- ```js
222
- const scale = window.visualViewport ? window.visualViewport.scale : 1;
223
- const zoom = parseFloat(getComputedStyle(document.documentElement).zoom) || 1;
224
- const realX = x * zoom;
225
- const realY = y * zoom;
226
- return { scale, zoom, realX, realY };
227
- ```
228
-
229
- 需要转物理坐标时:`physX = (screenX + rect中心x) * dpr`,`physY = (screenY + chromeH + rect中心y) * dpr`,其中 `chromeH = outerHeight - innerHeight`。
230
-
231
- CDP 文本输入:`Input.insertText` 快但没有完整 key 事件,受控组件需要补发 `input` 事件;需要完整键盘模拟时用 `Input.dispatchKeyEvent` 逐键派发。
197
+ CDP 点击优先三事件序列:`mouseMoved -> mousePressed -> mouseReleased`。首次 attach 可能出现 Chrome infobar,先发无害 `mouseMoved(0,0)` 预热。
232
198
 
233
199
  ## 文件上传
234
200
 
235
- 文件上传优先用 DataTransfer API,纯 JS、无 CDP 依赖:
201
+ 文件上传优先用 DataTransfer API,不优先使用 CDP `DOM.setFileInputFiles`:
236
202
 
237
203
  ```js
238
204
  const input = document.querySelector('input[type=file]');
@@ -245,61 +211,8 @@ input.dispatchEvent(new Event('change', { bubbles: true }));
245
211
  return input.files.length;
246
212
  ```
247
213
 
248
- 不优先使用 CDP `DOM.setFileInputFiles`,因为在 tmwd 桥环境里 `nodeId` 跨调用容易失效。若必须用 CDP,尽量在同一个 `batch` 内完成 `getDocument -> querySelector -> setFileInputFiles`,不要混用不同来源的 `nodeId`。
249
-
250
- 上传前检查 `input.accept`。页面有多个文件 input 时,用 `accept`、父容器文案、相邻 label 区分目标 input。上传后前端框架可能不感知,必要时补发 `input` / `change` 事件。
251
-
252
- 瞬态 input 的核心是缩短“发现 input -> set files”的时间窗:优先同 batch 完成;再不行用 DOM 事件监听;猴子补丁只作兜底思路。
253
-
254
- ## 下载与图片搜索
255
-
256
- PDF 链接在浏览器内预览而非下载时,用页面 JS 触发 Blob 下载。该方式要求同源或 CORS 允许;跨域时先导航到目标域再执行。
257
-
258
- ```js
259
- return fetch('PDF_URL').then(r => r.blob()).then(b => {
260
- const a = document.createElement('a');
261
- a.href = URL.createObjectURL(b);
262
- a.download = 'filename.pdf';
263
- a.click();
264
- return true;
265
- });
266
- ```
267
-
268
- Google 图搜场景不要硬编码混淆 class。点击结果优先找 `[role=button]` 容器;`scan` 可能过滤边栏,弹出后用 JS 读 `document.body.innerText`;大图遍历 `img` 按 `naturalWidth` 最大取 `src`;“访问”链接遍历 `a` 找 `textContent.includes('访问')` 的 `href`;缩略图直接提取 `img[src^="data:image"]`。
269
-
270
- ## iframe、Shadow DOM 与截图
271
-
272
- 同源 iframe 会被 `scan` 自动穿透。跨域 iframe 优先走 CDP:`Page.getFrameTree` 找 `frameId`,再 `Page.createIsolatedWorld` 获取 `contextId`,最后用 `Runtime.evaluate` 在 iframe 上下文执行。
273
-
274
- iframe 内元素做 CDP 点击时,坐标需要合成:`finalX = iframeRect.x + elRect.x`,`finalY = iframeRect.y + elRect.y`。`Target.getTargets` / `Target.attachToTarget` 在当前 CDP 桥里通常会返回 `Not allowed`,不要优先走这条路。postMessage 中继只在 content script 已注入 iframe 时可靠,第三方支付 iframe 通常不可用。
275
-
276
- closed Shadow DOM 使用 `DOM.getDocument({depth:-1,pierce:true})`,再逐级 `DOM.querySelector`。`nodeId` 在 DOM 变更后会失效,必要时重新 `getDocument`。
277
-
278
- `DOM.getBoxModel` 返回 content 四点坐标,中心点用四点平均,不要简化成对角线平均;元素存在 rotate/skew 时四点不一定是矩形。`DOM.querySelector` 不能跨 Shadow 边界写组合选择器,要先找 host,再在 shadow 内找子元素。
279
-
280
- 截图优先 CDP:
281
-
282
- ```bash
283
- agent-browser-cli exec '{"cmd":"cdp","method":"Page.captureScreenshot","params":{"format":"png"}}'
284
- ```
285
-
286
- 验证码 canvas/img 优先用 JS `canvas.toDataURL()` 或直接读取图片 `src`。
287
-
288
- ## Autofill 与登录
289
-
290
- `scan` 输出的 input 若带 `data-autofilled="true"`,value 可能显示为受保护提示,不是真实值。Chrome 只在前台 tab 释放 autofill 保护值,所以必须先 CDP `Page.bringToFront`。
291
-
292
- 一键释放流程:`Page.bringToFront` -> `mousePressed` 点任一字段,通常不需要 `mouseReleased` -> 等 500ms -> 补发 `input/change` 事件 -> 点登录。
293
-
294
- ## 调试
295
-
296
- 页面简化调试必须注入 JS 到真实浏览器,本地静态解析无法模拟 DOM。优先用 `scan --text-only` 和小段 `exec` 缩小问题范围。
297
-
298
- ## 排障顺序
214
+ ## 运维入口
299
215
 
300
- 1. 先跑最小自检,确认 `agent-browser-cli` 是否可执行。
301
- 2. npm 安装失败,检查当前平台是否有对应二进制包,必要时用 `cargo build --release`。
302
- 3. 若提示无法加载 `config.js` 或清单,检查 `assets/tmwd_cdp_bridge/config.js`。
303
- 4. 若提示没有可用标签页,先打开正常网页,不要只开内部页。
304
- 5. 若扩展没装,加载 `assets/tmwd_cdp_bridge`。
305
- 6. 仍失败时检查 Chrome 扩展后台日志和 `.agent-browser-cli.log`。
216
+ - daemon 未运行、扩展未连接、端口不一致、无可用标签页:看 `references/operations.md`。
217
+ - skill 安装:先 `agent-browser-cli install-skill --dry-run` 展示计划,用户确认后再 `agent-browser-cli install-skill`。
218
+ - 可自动执行的排障命令:`status`、`doctor`、`logs --tail`、`restart`、`stop`、`tabs`。
@@ -0,0 +1,145 @@
1
+ # agent-browser-cli 运维排障
2
+
3
+ ## 基本顺序
4
+
5
+ 先看轻量状态:
6
+
7
+ ```bash
8
+ agent-browser-cli status
9
+ ```
10
+
11
+ 再做完整自检:
12
+
13
+ ```bash
14
+ agent-browser-cli doctor
15
+ agent-browser-cli logs --tail 100
16
+ ```
17
+
18
+ `status` 的 `ok=true` 只表示命令执行成功;是否可用看 `healthy` 和 `summary`。
19
+
20
+ ## daemon 未运行
21
+
22
+ 典型状态:
23
+
24
+ ```json
25
+ { "summary": "daemon_not_running", "running": false }
26
+ ```
27
+
28
+ 处理:
29
+
30
+ ```bash
31
+ agent-browser-cli restart
32
+ agent-browser-cli status
33
+ ```
34
+
35
+ 也可以执行 `tabs/open/exec/scan` 自动启动 daemon。`doctor` 不会自动启动 daemon。
36
+
37
+ ## 扩展未连接
38
+
39
+ 典型状态:
40
+
41
+ ```json
42
+ { "summary": "extension_not_connected", "connection": { "extension_connected": false } }
43
+ ```
44
+
45
+ 处理:
46
+
47
+ 1. 确认 Chrome 已打开。
48
+ 2. 确认已加载 `assets/tmwd_cdp_bridge` 扩展。
49
+ 3. 确认扩展 popup 中的端口等于 `doctor` 输出的 `configured_port`。
50
+ 4. 在 `chrome://extensions` 点击扩展“重新加载”。
51
+ 5. 执行:
52
+
53
+ ```bash
54
+ agent-browser-cli status
55
+ ```
56
+
57
+ ## 没有可用标签页
58
+
59
+ 典型状态:
60
+
61
+ ```json
62
+ { "summary": "no_active_tabs", "connection": { "active_tabs": 0 } }
63
+ ```
64
+
65
+ 处理:打开一个普通 `http/https` 页面。不要只停留在 `about:blank`、`chrome://` 或扩展页。
66
+
67
+ ## 端口不一致
68
+
69
+ 典型状态:
70
+
71
+ ```json
72
+ { "summary": "port_mismatch" }
73
+ ```
74
+
75
+ 处理:
76
+
77
+ ```bash
78
+ agent-browser-cli restart
79
+ agent-browser-cli doctor
80
+ ```
81
+
82
+ 如果需要修改扩展端口,必须先说明影响并取得用户确认:该命令会写入 `~/.agent-browser-cli/config.json`,运行中的 daemon 会重启。
83
+
84
+ ```bash
85
+ agent-browser-cli set-extension-port <port>
86
+ ```
87
+
88
+ ## 查看日志
89
+
90
+ 日志固定在:
91
+
92
+ ```text
93
+ ~/.agent-browser-cli/logs/daemon.log
94
+ ```
95
+
96
+ 查看最近 100 行:
97
+
98
+ ```bash
99
+ agent-browser-cli logs
100
+ ```
101
+
102
+ 查看最近 N 行:
103
+
104
+ ```bash
105
+ agent-browser-cli logs --tail 200
106
+ ```
107
+
108
+ `logs` 只输出纯文本日志,不输出 JSON,也不支持 `--follow`。
109
+
110
+ ## 重启和停止
111
+
112
+ ```bash
113
+ agent-browser-cli restart
114
+ agent-browser-cli stop
115
+ ```
116
+
117
+ `restart` 会重新读取配置并启动 daemon;`stop` 只停止 daemon。
118
+
119
+ ## 重新安装 skill
120
+
121
+ 安装命令会写用户目录并创建软链接。必须先 dry-run 展示真实计划:
122
+
123
+ ```bash
124
+ agent-browser-cli install-skill --dry-run
125
+ ```
126
+
127
+ 用户确认后执行:
128
+
129
+ ```bash
130
+ agent-browser-cli install-skill
131
+ ```
132
+
133
+ 脚本化场景可用:
134
+
135
+ ```bash
136
+ agent-browser-cli install-skill --yes
137
+ ```
138
+
139
+ 默认实体安装目录:
140
+
141
+ ```text
142
+ ~/.agents/skills/agent-browser-cli
143
+ ```
144
+
145
+ Codex、Claude、Kimi CLI、Cursor、Gemini 等已存在的 skill 父目录只创建软链接,不复制多份实体文件。已存在且不是软链接的目标不会被覆盖,`--yes` 也不会覆盖。