yunti-browser-runtime 0.1.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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +256 -0
  3. package/bin/yunti-browser-runtime.js +86 -0
  4. package/docs/EXECUTION_PLAN.md +1278 -0
  5. package/docs/INSTALL.md +205 -0
  6. package/docs/PROJECT_INTENT.md +44 -0
  7. package/docs/PROJECT_STATUS.md +263 -0
  8. package/docs/PUBLISHING_BLOCKERS.md +110 -0
  9. package/docs/RELEASE.md +148 -0
  10. package/docs/ROADMAP.md +42 -0
  11. package/docs/SECURITY.md +56 -0
  12. package/docs/TOOL_GUIDE.md +69 -0
  13. package/extension/background.js +55 -0
  14. package/extension/cdp.js +582 -0
  15. package/extension/content.css +9 -0
  16. package/extension/content.js +946 -0
  17. package/extension/manifest.json +35 -0
  18. package/extension/network-monitor.js +140 -0
  19. package/extension/popup.css +66 -0
  20. package/extension/popup.html +30 -0
  21. package/extension/popup.js +55 -0
  22. package/extension/session-manager.js +332 -0
  23. package/extension/settings.js +94 -0
  24. package/extension/tool-handlers.js +1158 -0
  25. package/lib/runtime-paths.js +39 -0
  26. package/mcp/bridge-hub.js +604 -0
  27. package/mcp/http-server.js +326 -0
  28. package/mcp/json-rpc.js +35 -0
  29. package/mcp/memory.js +126 -0
  30. package/mcp/redaction.js +94 -0
  31. package/mcp/server.js +269 -0
  32. package/mcp/tools.js +1092 -0
  33. package/package.json +60 -0
  34. package/scripts/check-package-metadata.js +131 -0
  35. package/scripts/check-published-package.js +113 -0
  36. package/scripts/doctor.js +163 -0
  37. package/scripts/package-extension.js +137 -0
  38. package/scripts/print-config.js +116 -0
  39. package/scripts/release-check.js +472 -0
  40. package/skills/yunti-browser-runtime/SKILL.md +77 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yunti Browser Runtime contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,256 @@
1
+ # Yunti Browser Runtime
2
+
3
+ 面向 AI Agent 的本地浏览器运行时。
4
+
5
+ English summary: Yunti Browser Runtime is a local-first browser automation
6
+ runtime for MCP-capable AI agents. It lets agents inspect and operate a user's
7
+ own Chromium browser through a local bridge and an unpacked extension, without
8
+ requiring a remote service.
9
+
10
+ Yunti Browser Runtime 让任何支持 MCP 的 Agent 都可以操作用户本地
11
+ Chrome/Edge 浏览器:查看标签页、读取页面、点击输入、截图、上传文件、
12
+ 监听网络/控制台日志,以及发送 Chrome DevTools Protocol CDP 命令。
13
+
14
+ 它的第一目标是:**部署简单、执行高效、和具体 Agent/平台解耦**。
15
+
16
+ ## 当前定位
17
+
18
+ 当前版本是本地单用户 MVP:
19
+
20
+ - MCP stdio server:给 Agent 注册工具。
21
+ - 本地 bridge:默认监听 `127.0.0.1:48887`。
22
+ - Chrome/Edge 扩展:负责在用户真实浏览器中执行动作。
23
+ - 工具前缀:`yunti_*`。
24
+ - 默认用户:`local`,Agent 通常不需要手动传 `userId`。
25
+ - 无远程服务器、平台账号依赖。
26
+
27
+ ## 项目结构
28
+
29
+ ```text
30
+ yunti-browser-runtime/
31
+ mcp/ # MCP stdio server + local bridge
32
+ extension/ # Chrome/Edge unpacked extension
33
+ skills/yunti-browser-runtime # 给 Agent 使用的浏览器操作 skill
34
+ docs/ # 项目文档
35
+ scripts/ # doctor / 辅助脚本
36
+ tests/ # bridge 和 MCP 测试
37
+ ```
38
+
39
+ ## 快速启动
40
+
41
+ ```bash
42
+ cd yunti-browser-runtime
43
+ npm install
44
+ npm run bridge
45
+ ```
46
+
47
+ 安装为 npm 包后,也可以使用 CLI:
48
+
49
+ ```bash
50
+ yunti-browser-runtime bridge
51
+ yunti-browser-runtime doctor
52
+ yunti-browser-runtime print-config -- --agent codex --human
53
+ yunti-browser-runtime package-extension
54
+ ```
55
+
56
+ 默认 bridge 地址:
57
+
58
+ ```text
59
+ http://127.0.0.1:48887
60
+ ```
61
+
62
+ bridge 会在启动时生成或读取本地访问 token,并打印到 stderr。也可以显式配置:
63
+
64
+ ```bash
65
+ YUNTI_BROWSER_BRIDGE_TOKEN="$(openssl rand -hex 24)" npm run bridge
66
+ ```
67
+
68
+ 健康检查:
69
+
70
+ ```bash
71
+ npm run doctor
72
+ ```
73
+
74
+ `doctor` 会输出机器可读 JSON,并在 stderr 打印人类可读诊断摘要。只需要 JSON
75
+ 时可执行:
76
+
77
+ ```bash
78
+ npm run doctor:json
79
+ ```
80
+
81
+ ## 安装浏览器扩展
82
+
83
+ 开发加载方式:
84
+
85
+ 1. 打开 `chrome://extensions` 或 `edge://extensions`。
86
+ 2. 开启开发者模式。
87
+ 3. 点击“加载已解压的扩展程序”。
88
+ 4. 选择本项目的 `extension/` 目录。
89
+ 5. 打开任意 `http` 或 `https` 页面。
90
+ 6. 点击扩展图标,填写 bridge token,保存设置。
91
+ 7. 刷新目标页面,确认页面已连接。
92
+
93
+ 扩展只负责把页面注册到本地 bridge,并执行 Agent 发来的浏览器动作。
94
+
95
+ 也可以生成 zip 包用于分发或归档:
96
+
97
+ ```bash
98
+ npm run package:extension
99
+ ```
100
+
101
+ 输出文件位于 `dist/yunti-browser-runtime-extension-<version>.zip`,zip 内只包含扩展运行所需文件。
102
+
103
+ ## 给 Agent 注册 MCP
104
+
105
+ 按目标 Agent 打印 MCP 配置,再加入你的 Agent MCP 配置中:
106
+
107
+ ```bash
108
+ npm run print-config -- --agent codex --human
109
+ npm run print-config -- --agent claude-code --human
110
+ npm run print-config -- --agent cursor --human
111
+ npm run print-config -- --agent cline --human
112
+ ```
113
+
114
+ 大多数 Agent 启动 MCP server 时会自动启动或复用本地 bridge。开发调试时也可以
115
+ 手动执行:
116
+
117
+ ```bash
118
+ npm run bridge
119
+ ```
120
+
121
+ 更详细的 Codex、Claude Code、Cursor、Cline 接入示例见
122
+ [安装说明](docs/INSTALL.md#agent-examples)。
123
+
124
+ ## 给 Agent 安装浏览器操作 Skill
125
+
126
+ 项目内置了一个可分发的 skill:
127
+
128
+ ```text
129
+ skills/yunti-browser-runtime/SKILL.md
130
+ ```
131
+
132
+ 推荐把整个目录复制到 Agent 的 skills 目录,例如 Codex:
133
+
134
+ ```bash
135
+ mkdir -p ~/.codex/skills
136
+ cp -R skills/yunti-browser-runtime ~/.codex/skills/
137
+ ```
138
+
139
+ 安装后,新会话遇到浏览器操作任务时,Agent 应先读取该 skill,再调用
140
+ `yunti_*` 工具。
141
+
142
+ 如果你的 Agent 不支持自动加载 skills,也可以把
143
+ `skills/yunti-browser-runtime/SKILL.md` 的内容加入 Agent 的系统提示或项目提示中。
144
+
145
+ ## Agent 使用原则
146
+
147
+ 浏览器任务建议遵循这个顺序:
148
+
149
+ 1. 先调用 `yunti_get_tool_usage_hints`,确认工具规则。
150
+ 2. 调用 `yunti_list_browser_targets` 获取浏览器全貌。
151
+ 3. 保存当前页面返回的 `browserSessionId`。
152
+ 4. 后续页面/CDP 操作都带同一个 `browserSessionId`。
153
+ 5. 如果旧 `browserSessionId` 失效,重新调用 `yunti_list_browser_targets` 获取最新路由。
154
+ 6. CDP 命令必须通过 `yunti_cdp_send_command` 调用,不要把 `Target.activateTarget` 之类的 CDP method 当 shell 命令执行。
155
+ 7. 涉及提交、删除、付款、上传敏感文件等写操作前,Agent 必须获得用户确认。
156
+
157
+ ### 参数规则速查
158
+
159
+ - `yunti_click` / `yunti_hover` 需要 `uid`、`selector`,或同时提供 `x` 和 `y`。
160
+ - `yunti_fill` 必须提供 `value`,并用 `uid` 或 `selector` 定位;不支持只传坐标。
161
+ - `yunti_close_page` 按 `browserSessionId` 关闭页面;如只有 `tabId` / `targetId`,请用 `yunti_cdp_send_command` + `Target.closeTarget`。
162
+ - `yunti_cdp_send_command` 必须提供 `method`;`params` 可选,但传入时必须是 object。
163
+ - `yunti_forget_learning_memory` 需要 memory `id`,或使用 `all=true` 且 `confirmed=true` 删除全部。
164
+
165
+ ## 常用工具
166
+
167
+ - `yunti_list_browser_targets`:浏览器标签页和 target 总览。
168
+ - `yunti_get_page_snapshot`:读取当前页面轻量状态。
169
+ - `yunti_take_snapshot`:获取适合点击/输入的元素快照。
170
+ - `yunti_click` / `yunti_fill` / `yunti_hover`:页面交互。
171
+ - `yunti_take_screenshot`:截图。
172
+ - `yunti_cdp_send_command`:发送 CDP 命令。
173
+ - `yunti_get_network_log` / `yunti_list_network_requests`:网络日志。
174
+ - `yunti_list_console_messages`:控制台日志。
175
+ - `yunti_remember_learning` / `yunti_get_learning_memory`:本地经验记忆。
176
+
177
+ ## 文档
178
+
179
+ - [安装说明](docs/INSTALL.md)
180
+ - [工具指南](docs/TOOL_GUIDE.md)
181
+ - [权限和隐私说明](docs/SECURITY.md)
182
+ - [发布运行手册](docs/RELEASE.md)
183
+ - [发布阻塞处理](docs/PUBLISHING_BLOCKERS.md)
184
+ - [项目初衷](docs/PROJECT_INTENT.md)
185
+ - [项目状态](docs/PROJECT_STATUS.md)
186
+ - [执行计划](docs/EXECUTION_PLAN.md)
187
+ - [路线图](docs/ROADMAP.md)
188
+
189
+ ## 验证
190
+
191
+ ```bash
192
+ npm run check
193
+ npm test
194
+ npm run release:check
195
+ npm pack --dry-run
196
+ ```
197
+
198
+ 当前测试覆盖 bridge 路由、MCP 工具列表、浏览器 session 隔离、网络/控制台日志、
199
+ learning memory 和核心工具分发。
200
+
201
+ `npm run release:check` 会串行执行公开文档残留检查、语法检查、单元测试和
202
+ `npm pack --dry-run`,适合作为发布前门禁。
203
+
204
+ 仓库 URL 和 npm metadata 已确认公开可达。发布前运行:
205
+
206
+ ```bash
207
+ npm run release:dry-run
208
+ ```
209
+
210
+ `release:dry-run` 会先执行 `npm run check:metadata` 和 `npm run release:check`,
211
+ 再显式使用官方 npm registry,避免本机 registry mirror 影响发布预览。
212
+
213
+ 正式发布前先登录官方 npm registry:
214
+
215
+ ```bash
216
+ npm adduser --registry=https://registry.npmjs.org/
217
+ npm run release:whoami
218
+ ```
219
+
220
+ 发布后运行:
221
+
222
+ ```bash
223
+ npm run release:verify-published
224
+ ```
225
+
226
+ 真实浏览器 E2E smoke test 默认跳过;需要本机安装 Playwright / Chromium 后显式启用:
227
+
228
+ ```bash
229
+ YUNTI_E2E=1 npm run test:e2e
230
+ ```
231
+
232
+ 失败时测试会在系统临时目录写入截图和错误日志路径,便于排查扩展消息链路。
233
+
234
+ ## FAQ
235
+
236
+ ### 为什么需要浏览器扩展?
237
+
238
+ 扩展负责在用户已经打开的真实浏览器页面中注册 session、执行页面动作,并把安全处理后的网络、控制台和 CDP 观察结果交给本地 bridge。
239
+
240
+ ### bridge token 是什么?
241
+
242
+ bridge token 是本地 HTTP bridge 的访问凭证。MCP server、extension 和 doctor 使用同一个 token,避免普通网页误调用本地接口。
243
+
244
+ ### 会读取 cookie 或密码吗?
245
+
246
+ 工具不会返回原始 cookie、authorization header、密码或疑似 token 字段。网络日志、请求体预览和学习记忆都会做敏感字段脱敏。
247
+
248
+ ### 旧的 `browserSessionId` 失效怎么办?
249
+
250
+ 调用 `yunti_list_browser_targets` 获取最新浏览器路由,再用返回的 `browserSessionId` 继续操作。
251
+
252
+ ## 当前未完成项
253
+
254
+ - 如确认要发布 `0.1.0`,运行 `npm run release:publish`。
255
+ - 当前 `npm view yunti-browser-runtime` 返回 E404;如 `0.1.0` 是首次发布,这是预期状态。
256
+ - 发布前如要上架浏览器扩展商店,需要再次审查 broad host permissions。
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process"
3
+ import { dirname, join, resolve } from "node:path"
4
+ import { fileURLToPath } from "node:url"
5
+
6
+ const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), "..")
7
+ const command = process.argv[2] || "mcp"
8
+ const passThroughArgs = process.argv.slice(3)
9
+
10
+ const commands = {
11
+ mcp: {
12
+ script: join(rootDir, "mcp", "server.js"),
13
+ env: {},
14
+ },
15
+ bridge: {
16
+ script: join(rootDir, "mcp", "server.js"),
17
+ env: { YUNTI_BROWSER_BRIDGE_ONLY: "1" },
18
+ },
19
+ doctor: {
20
+ script: join(rootDir, "scripts", "doctor.js"),
21
+ env: {},
22
+ },
23
+ "print-config": {
24
+ script: join(rootDir, "scripts", "print-config.js"),
25
+ env: {},
26
+ },
27
+ "package-extension": {
28
+ script: join(rootDir, "scripts", "package-extension.js"),
29
+ env: {},
30
+ },
31
+ }
32
+
33
+ if (command === "--help" || command === "-h" || command === "help") {
34
+ printHelp()
35
+ process.exit(0)
36
+ }
37
+
38
+ if (command === "--version" || command === "-v") {
39
+ const packageJson = await import("../package.json", { with: { type: "json" } })
40
+ console.log(packageJson.default.version)
41
+ process.exit(0)
42
+ }
43
+
44
+ const selected = commands[command]
45
+ if (!selected) {
46
+ console.error(`Unknown command: ${command}`)
47
+ printHelp()
48
+ process.exit(1)
49
+ }
50
+
51
+ const child = spawn(process.execPath, [selected.script, ...passThroughArgs], {
52
+ stdio: "inherit",
53
+ env: {
54
+ ...process.env,
55
+ ...selected.env,
56
+ },
57
+ })
58
+
59
+ child.on("exit", (code, signal) => {
60
+ if (signal) {
61
+ process.kill(process.pid, signal)
62
+ return
63
+ }
64
+ process.exit(code ?? 0)
65
+ })
66
+
67
+ function printHelp() {
68
+ console.log(`Yunti Browser Runtime
69
+
70
+ Usage:
71
+ yunti-browser-runtime [command] [args]
72
+
73
+ Commands:
74
+ mcp Start the stdio MCP server (default)
75
+ bridge Start only the local HTTP bridge
76
+ doctor Run install and bridge diagnostics
77
+ print-config Print MCP configuration for an agent
78
+ package-extension Build the browser extension zip
79
+
80
+ Examples:
81
+ yunti-browser-runtime
82
+ yunti-browser-runtime bridge
83
+ yunti-browser-runtime doctor
84
+ yunti-browser-runtime print-config -- --agent codex --human
85
+ yunti-browser-runtime package-extension`)
86
+ }