@glittering0717/ai-browser 2.3.1 → 2.4.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 +7 -3
- package/build/icon-dock.png +0 -0
- package/build/icon.icns +0 -0
- package/build/icon.png +0 -0
- package/llms-install.md +3 -3
- package/package.json +7 -3
- package/scripts/build_dmg.cjs +51 -1
- package/scripts/check_icon.cjs +161 -0
- package/scripts/ensure_running.cjs +3 -1
- package/scripts/icon_geometry.cjs +139 -0
- package/scripts/install_app.cjs +18 -4
- package/scripts/render_icon.cjs +49 -0
- package/skills/ai-browser/references/tabs.md +3 -0
- package/skills/ai-browser/references/tasks.md +3 -3
- package/src/main/axExtractor.js +1 -1
- package/src/main/canvas_hook_source.js +110 -2
- package/src/main/capability_probe.js +27 -2
- package/src/main/index.js +103 -12
- package/src/main/mcp_server.js +16 -4
- package/src/main/mcp_tools.js +18 -18
- package/src/main/page_manager.js +53 -2
- package/src/main/snapshot_diff.js +15 -0
- package/src/main/ws_server.js +5 -0
- package/src/shared/page_probe.js +196 -18
- package/src/shared/version.js +1 -1
- package/src/shared/window_show.js +82 -0
package/README.md
CHANGED
|
@@ -194,7 +194,7 @@ small surface, since every tool schema is injected into your agent's context on
|
|
|
194
194
|
|
|
195
195
|
| Tool | One line |
|
|
196
196
|
|---|---|
|
|
197
|
-
| `browse_navigate` | Load a URL in
|
|
197
|
+
| `browse_navigate` | Load a URL in your tab or the given tab. |
|
|
198
198
|
| `browse_get_tree` | Read the page as a semantic tree + page context (modals, messages, stats). |
|
|
199
199
|
| `browse_act` | `click` / `type` (append at caret) / `setContent` (replace all) / `clear` / `focus` / `hover` / `scroll_to` / `upload` / `get_value` (read-only) / `drag` / `press` / `wheel` on a `data-ai-id`. |
|
|
200
200
|
| `browse_diff` | `snapshot` a baseline, then `diff` to get added / removed / changed paths with before/after values. **This is how you prove an action did anything.** |
|
|
@@ -205,7 +205,7 @@ small surface, since every tool schema is injected into your agent's context on
|
|
|
205
205
|
| `browse_evaluate` | Run a JS *expression* in page context (5000-char cap, Node identifiers rejected). |
|
|
206
206
|
| `browse_scroll` | Scroll the page, or scroll an element into view. |
|
|
207
207
|
| `browse_wait` | Poll until `button_enabled` / `modal_appeared` / `text_contains` / `url_contains`. |
|
|
208
|
-
| `browse_tabs` | Tabs: `list` / `new` / `close` / `switch`. `switch`
|
|
208
|
+
| `browse_tabs` | Tabs: `list` / `new` / `close` / `switch` / `window`. `switch` = default; add `show:true`. `new` never steals the view unless `show:true`. |
|
|
209
209
|
| `browse_network` | Chrome-DevTools-style network inspection: `list` (filter by method / URL / status / type), `get` (request + response headers and bodies), `clear`, `configure`. |
|
|
210
210
|
| `browse_quit` | Shut the whole browser down and release the process. |
|
|
211
211
|
|
|
@@ -329,7 +329,7 @@ Notes that save round-trips:
|
|
|
329
329
|
- `browse_network` captures requests from the moment a tab opens, **including POST request bodies** —
|
|
330
330
|
no subscription needed. Request headers are redacted by default
|
|
331
331
|
(`authorization` / `cookie` → `[REDACTED]`); pass `include_sensitive_headers: true` to see them.
|
|
332
|
-
- Most tools take an optional `tab` for multi-tab work;
|
|
332
|
+
- Most tools take an optional `tab` for multi-tab work; omit `tab` to target your own session tab.
|
|
333
333
|
|
|
334
334
|
---
|
|
335
335
|
|
|
@@ -431,6 +431,10 @@ Each group is capped (8 by default, `AI_BROWSER_TAB_LIMIT`). Opening past the ca
|
|
|
431
431
|
data: { reason: "group-full", limit: 8, tabs: [{tab, url}, ...] }
|
|
432
432
|
```
|
|
433
433
|
|
|
434
|
+
Over MCP the agent receives this as a tool result with `isError: true` and the readable text
|
|
435
|
+
`Error: your tab group is full (8/8) — close one before opening another` — a normal tool failure it
|
|
436
|
+
acts on, not a JSON-RPC protocol error. The `data` fields above are the raw-WS detail.
|
|
437
|
+
|
|
434
438
|
Popups cannot be refused (the page's script is waiting for the window), so in that one case the least
|
|
435
439
|
recently used tab in the group — never the visible one, never one with a dialog open — is closed
|
|
436
440
|
instead, and reported in `browse_tabs {"op":"list"}` as `evicted`.
|
|
Binary file
|
package/build/icon.icns
CHANGED
|
Binary file
|
package/build/icon.png
CHANGED
|
Binary file
|
package/llms-install.md
CHANGED
|
@@ -130,7 +130,7 @@ focuses the existing window (single instance lock).
|
|
|
130
130
|
|
|
131
131
|
## The 17 tools
|
|
132
132
|
|
|
133
|
-
- `browse_navigate` — load a URL in
|
|
133
|
+
- `browse_navigate` — load a URL in your tab or the given tab.
|
|
134
134
|
- `browse_get_tree` — semantic tree + context (modals, toasts, required-field
|
|
135
135
|
hints, login state, stats). Params: `subset: "interactive"` (token saver, use by
|
|
136
136
|
default), `ax: true` (links carry urls), `mode: "diff"` (only new/hidden nodes).
|
|
@@ -161,8 +161,8 @@ focuses the existing window (single instance lock).
|
|
|
161
161
|
- `browse_repaint` — force compositor redraw when the window shows a stale page.
|
|
162
162
|
- `browse_downloads` — list downloads with on-disk paths (poll after clicking
|
|
163
163
|
export/download; downloads are asynchronous).
|
|
164
|
-
- `browse_tabs` — tab management: `{op: "list" | "new" | "close" | "switch"}`.
|
|
165
|
-
`switch`
|
|
164
|
+
- `browse_tabs` — tab management: `{op: "list" | "new" | "close" | "switch" | "window"}`.
|
|
165
|
+
`switch` = default; add `show:true`; `new` never steals the view unless `show:true`.
|
|
166
166
|
- `browse_quit` — shut the whole browser down and release the process.
|
|
167
167
|
|
|
168
168
|
**Which door should you use?** Prefer the **CLI** unless the tool list already contains
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glittering0717/ai-browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "AI-native browser — renders pixels for humans, structured semantic-tree API for agents. No screenshots, no OCR, no coordinate guessing.",
|
|
5
5
|
"main": "src/main/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"llms-install.md",
|
|
18
18
|
"LICENSE",
|
|
19
19
|
"build/icon.png",
|
|
20
|
-
"build/icon.icns"
|
|
20
|
+
"build/icon.icns",
|
|
21
|
+
"build/icon-dock.png"
|
|
21
22
|
],
|
|
22
23
|
"type": "module",
|
|
23
24
|
"license": "MIT",
|
|
@@ -90,7 +91,10 @@
|
|
|
90
91
|
"flicker": "node e2e/flicker_ws.cjs",
|
|
91
92
|
"download": "node e2e/download_ws.cjs",
|
|
92
93
|
"multiagent": "node e2e/multiagent_ws.cjs",
|
|
93
|
-
"background": "node e2e/background_ws.cjs"
|
|
94
|
+
"background": "node e2e/background_ws.cjs",
|
|
95
|
+
"icon:check": "node scripts/check_icon.cjs",
|
|
96
|
+
"icons": "env -u ELECTRON_RUN_AS_NODE node_modules/electron/dist/Electron.app/Contents/MacOS/Electron --no-sandbox --disable-gpu scripts/render_icon.cjs",
|
|
97
|
+
"icon": "node e2e/icon_ws.cjs"
|
|
94
98
|
},
|
|
95
99
|
"dependencies": {
|
|
96
100
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
package/scripts/build_dmg.cjs
CHANGED
|
@@ -28,11 +28,38 @@
|
|
|
28
28
|
// node scripts/build_dmg.cjs --skip-dmg # 只出 .app,不压 dmg
|
|
29
29
|
'use strict';
|
|
30
30
|
|
|
31
|
-
const { spawnSync } = require('node:child_process');
|
|
31
|
+
const { spawnSync, spawn } = require('node:child_process');
|
|
32
32
|
const fs = require('node:fs');
|
|
33
33
|
const os = require('node:os');
|
|
34
34
|
const path = require('node:path');
|
|
35
35
|
|
|
36
|
+
// # 为什么先把自己重启一遍(2026-10-29 实测)
|
|
37
|
+
//
|
|
38
|
+
// 某些 agent 运行环境会通过 NODE_OPTIONS 给 node 注入一个"文件系统代理"
|
|
39
|
+
// (node-brokered-fs-shim.cjs),它对 createWriteStream 做 token 校验。@electron/asar
|
|
40
|
+
// 打 app.asar 正是走 createWriteStream,于是**必然**失败,而且报错完全不提代理:
|
|
41
|
+
//
|
|
42
|
+
// Error: Brokered file token refused: modify backup failed
|
|
43
|
+
// at createFilesystemWriteStream (…/@electron/asar/lib/disk.js:321)
|
|
44
|
+
//
|
|
45
|
+
// 看起来像"备份文件写失败",会把人引去查磁盘/权限,方向全错(本脚本原来的注释
|
|
46
|
+
// 也在猜这个)。代理只包 Node 的 fs,不拦外部命令 —— 所以正确做法是把 NODE_OPTIONS
|
|
47
|
+
// 摘掉再跑自己一次,而不是在打包逻辑里绕。
|
|
48
|
+
//
|
|
49
|
+
// 只摘 NODE_OPTIONS、不动别的环境变量;用环境变量防重入。
|
|
50
|
+
//
|
|
51
|
+
// 注意判据要认 node-language-shim:brokered-fs 不是直接写在 NODE_OPTIONS 里的,
|
|
52
|
+
// 而是由 language-shim 再 require 进来的。只匹配 "node-brokered-fs-shim" 会漏
|
|
53
|
+
// (第一版就是这么漏的:日志里没有那行提示,直接失败)。
|
|
54
|
+
if (/node-(language|brokered-fs)-shim/.test(process.env.NODE_OPTIONS || '') && !process.env.AIB_BUILD_NO_SHIM) {
|
|
55
|
+
const env = { ...process.env, AIB_BUILD_NO_SHIM: '1' };
|
|
56
|
+
delete env.NODE_OPTIONS;
|
|
57
|
+
console.log('[build] 检测到文件系统代理(NODE_OPTIONS 里的 fs-shim)—— 摘掉它重启打包,否则 asar 写不进去');
|
|
58
|
+
const r = spawn(process.execPath, [__filename, ...process.argv.slice(2)], { stdio: 'inherit', env });
|
|
59
|
+
r.on('exit', (code) => process.exit(code ?? 1));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
36
63
|
const root = path.resolve(__dirname, '..');
|
|
37
64
|
const pkg = require('../package.json');
|
|
38
65
|
|
|
@@ -146,11 +173,33 @@ function installIcon(appPath) {
|
|
|
146
173
|
'-c', 'Set :CFBundleIconFile icon.icns',
|
|
147
174
|
path.join(appPath, 'Contents', 'Info.plist'),
|
|
148
175
|
]);
|
|
176
|
+
// packager 自己拷进来的 electron.icns 留着没用:plist 已经指向 icon.icns,
|
|
177
|
+
// 两份**内容相同的 icns** 会让 IconServices 建出重复的 NSImage 表示
|
|
178
|
+
// (实测 16 档各两份、共 32 个 rep),多一份缓存歧义没有任何好处。
|
|
179
|
+
// 只删主 bundle 这一份 —— Helper 们的 electron.icns 是它们自己的图标。
|
|
180
|
+
const dup = path.join(resources, 'electron.icns');
|
|
181
|
+
if (fs.existsSync(dup)) {
|
|
182
|
+
fs.rmSync(dup, { force: true });
|
|
183
|
+
console.log('[build] 已删除重复的 electron.icns(图标只留一份)');
|
|
184
|
+
}
|
|
149
185
|
// touch 让 LaunchServices / Finder 重新读图标,否则换图后仍显示旧缓存
|
|
150
186
|
run('touch', [appPath]);
|
|
151
187
|
console.log('[build] 图标已安装:icon.icns');
|
|
152
188
|
}
|
|
153
189
|
|
|
190
|
+
// 让 LaunchServices 忘掉这个 bundle。
|
|
191
|
+
//
|
|
192
|
+
// 为什么必须做:dist 里的 .app 和 /Applications 里的 .app 是**同一个 bundle id**
|
|
193
|
+
// 的两份拷贝。LS 数据库里同 id 多条记录时,Dock / Finder 有可能解析到构建目录
|
|
194
|
+
// 那一份 —— 它的图标是上一版甚至上上版的,于是"图标一会大一会小"。
|
|
195
|
+
// 卸载注册不影响 ditto 拷贝,也不影响用户手动双击(双击时会重新注册)。
|
|
196
|
+
function unregisterBundle(appPath) {
|
|
197
|
+
const lsregister = '/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister';
|
|
198
|
+
const r = spawnSync(lsregister, ['-u', appPath], { encoding: 'utf8' });
|
|
199
|
+
if (r.status === 0) console.log(`[build] 已从 LaunchServices 注销构建目录副本:${path.basename(appPath)}`);
|
|
200
|
+
else console.log('[build] 注销构建目录副本失败(不致命,继续)');
|
|
201
|
+
}
|
|
202
|
+
|
|
154
203
|
function main() {
|
|
155
204
|
const args = parseArgs(process.argv.slice(2));
|
|
156
205
|
// @electron/packager v20 是纯 ESM("type": "module" + exports 只指向 dist/index.js),
|
|
@@ -250,6 +299,7 @@ function build(packager, args) {
|
|
|
250
299
|
console.log(`[build] app bundle: ${appPath}`);
|
|
251
300
|
console.log(`[build] app size: ${mb(size)}`);
|
|
252
301
|
installIcon(appPath);
|
|
302
|
+
unregisterBundle(appPath);
|
|
253
303
|
|
|
254
304
|
if (args.skipDmg) {
|
|
255
305
|
console.log('[build] --skip-dmg,不压 dmg');
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// scripts/check_icon.cjs — 图标链路的一致性与"尺寸"闸门。
|
|
3
|
+
//
|
|
4
|
+
// # 这个脚本在防什么
|
|
5
|
+
//
|
|
6
|
+
// 用户 2026-10-29 报:"我看电脑里 icon 一会大一会小。"
|
|
7
|
+
//
|
|
8
|
+
// 根因不是一个坏文件,而是**两条渲染路径的几何不一致**:
|
|
9
|
+
//
|
|
10
|
+
// · 打包版:Info.plist → icon.icns → macOS 按统一图标网格缩放 → 内容占 ~86.7%
|
|
11
|
+
// · 源码版:app.dock.setIcon(build/icon.png) → 裸 NSImage,不经过网格 → 占 100%
|
|
12
|
+
//
|
|
13
|
+
// 于是同一个应用,从"应用程序"启动和从 `npm start` 启动,Dock 里是两个尺寸。
|
|
14
|
+
// 这类缺陷靠肉眼比是判不出来的(旁边没有参照物、每次都只看一个),必须量。
|
|
15
|
+
//
|
|
16
|
+
// 检查项:
|
|
17
|
+
// 1. icon.png 满出血(=1.0)—— 它是 icns 与 Windows/Linux 窗口图标的源
|
|
18
|
+
// 2. icon-dock.png 内容占比 ≈ 系统图标网格(0.867 ± 0.015)
|
|
19
|
+
// 3. icon.icns 十档齐全,且每一档都满出血(小尺寸不能因为留白显得更小)
|
|
20
|
+
// 4. 给定 .app 时:Info.plist 指的 icns 真的在、Resources 里只有一份 icns
|
|
21
|
+
//
|
|
22
|
+
// 用法:
|
|
23
|
+
// node scripts/check_icon.cjs # 只查 build/
|
|
24
|
+
// node scripts/check_icon.cjs "/Applications/AI Browser.app"
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
const fs = require('node:fs');
|
|
28
|
+
const os = require('node:os');
|
|
29
|
+
const path = require('node:path');
|
|
30
|
+
const { spawnSync } = require('node:child_process');
|
|
31
|
+
const { contentBox } = require('./icon_geometry.cjs');
|
|
32
|
+
|
|
33
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
34
|
+
const BUILD = path.join(ROOT, 'build');
|
|
35
|
+
|
|
36
|
+
// macOS 图标网格的内容占比。2026-10-29 在 macOS 27 上量的:
|
|
37
|
+
// 本应用 bundle 图标 86.7%、Safari 86.7%、Finder 86.7%(同一口径、256px 渲染)。
|
|
38
|
+
// 容差 1.5 个百分点 —— 足够吸收不同 macOS 版本的网格微调,但拦得住"满出血"
|
|
39
|
+
// 与"缩过头"这两类真实错误(分别是 100% 和 <75%)。
|
|
40
|
+
const GRID_CONTENT = 0.867;
|
|
41
|
+
const GRID_TOL = 0.015;
|
|
42
|
+
|
|
43
|
+
const ICNS_SLOTS = [
|
|
44
|
+
'icon_16x16.png', 'icon_16x16@2x.png', 'icon_32x32.png', 'icon_32x32@2x.png',
|
|
45
|
+
'icon_128x128.png', 'icon_128x128@2x.png', 'icon_256x256.png', 'icon_256x256@2x.png',
|
|
46
|
+
'icon_512x512.png', 'icon_512x512@2x.png',
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
let failed = 0;
|
|
50
|
+
const rows = [];
|
|
51
|
+
|
|
52
|
+
function report(name, ok, detail) {
|
|
53
|
+
rows.push({ name, ok, detail });
|
|
54
|
+
if (!ok) failed++;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function ratioOf(file) {
|
|
58
|
+
return contentBox(fs.readFileSync(file)).ratio;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function checkBuildFiles() {
|
|
62
|
+
const png = path.join(BUILD, 'icon.png');
|
|
63
|
+
const dock = path.join(BUILD, 'icon-dock.png');
|
|
64
|
+
const icns = path.join(BUILD, 'icon.icns');
|
|
65
|
+
|
|
66
|
+
for (const f of [png, dock, icns]) {
|
|
67
|
+
if (!fs.existsSync(f)) {
|
|
68
|
+
report(path.basename(f), false, '文件不存在(先跑 npm run icon)');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const full = ratioOf(png);
|
|
74
|
+
report('icon.png 满出血', full > 0.99, `内容占 ${(full * 100).toFixed(1)}%(期望 100%)`);
|
|
75
|
+
|
|
76
|
+
const d = ratioOf(dock);
|
|
77
|
+
const dOk = Math.abs(d - GRID_CONTENT) <= GRID_TOL;
|
|
78
|
+
report(
|
|
79
|
+
'icon-dock.png 对齐系统图标网格',
|
|
80
|
+
dOk,
|
|
81
|
+
`内容占 ${(d * 100).toFixed(1)}%(期望 ${(GRID_CONTENT * 100).toFixed(1)}% ±${GRID_TOL * 100}%)` +
|
|
82
|
+
(dOk ? '' : d > GRID_CONTENT ? ' —— 偏大,Dock 里会比别的图标大一圈' : ' —— 偏小')
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// icns 解回 iconset 逐档量。iconutil 只在 macOS 上有;其他平台跳过并明说,
|
|
86
|
+
// 不静默通过。
|
|
87
|
+
if (process.platform !== 'darwin') {
|
|
88
|
+
report('icon.icns 十档', true, 'SKIPPED(非 macOS,iconutil 不可用)');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'aib-icon-'));
|
|
92
|
+
const out = path.join(tmp, 'x.iconset');
|
|
93
|
+
const r = spawnSync('iconutil', ['-c', 'iconset', icns, '-o', out], { encoding: 'utf8' });
|
|
94
|
+
if (r.status !== 0) {
|
|
95
|
+
report('icon.icns 可解包', false, (r.stderr || '').trim() || `iconutil exit ${r.status}`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const missing = ICNS_SLOTS.filter((n) => !fs.existsSync(path.join(out, n)));
|
|
99
|
+
report('icon.icns 十档齐全', missing.length === 0, missing.length ? `缺 ${missing.join(', ')}` : '10/10');
|
|
100
|
+
|
|
101
|
+
const bad = [];
|
|
102
|
+
for (const n of ICNS_SLOTS) {
|
|
103
|
+
const p = path.join(out, n);
|
|
104
|
+
if (!fs.existsSync(p)) continue;
|
|
105
|
+
const ratio = ratioOf(p);
|
|
106
|
+
if (ratio < 0.99) bad.push(`${n}=${(ratio * 100).toFixed(0)}%`);
|
|
107
|
+
}
|
|
108
|
+
report('icns 每一档都满出血', bad.length === 0, bad.length ? `留白:${bad.join(', ')}` : '10/10 满出血');
|
|
109
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function checkAppBundle(appPath) {
|
|
113
|
+
if (!fs.existsSync(appPath)) {
|
|
114
|
+
report('app bundle', false, `不存在:${appPath}`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const plist = path.join(appPath, 'Contents', 'Info.plist');
|
|
118
|
+
const pb = spawnSync('/usr/libexec/PlistBuddy', ['-c', 'Print :CFBundleIconFile', plist], { encoding: 'utf8' });
|
|
119
|
+
const iconFile = (pb.stdout || '').trim();
|
|
120
|
+
const resources = path.join(appPath, 'Contents', 'Resources');
|
|
121
|
+
const named = iconFile ? path.join(resources, iconFile) : null;
|
|
122
|
+
report(
|
|
123
|
+
'Info.plist 指向的图标存在',
|
|
124
|
+
!!(named && fs.existsSync(named)),
|
|
125
|
+
iconFile ? `${iconFile}` : '读不到 CFBundleIconFile'
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
let icnsFiles = [];
|
|
129
|
+
try { icnsFiles = fs.readdirSync(resources).filter((n) => n.endsWith('.icns')); } catch (_) {}
|
|
130
|
+
report(
|
|
131
|
+
'Resources 里只有一份 icns',
|
|
132
|
+
icnsFiles.length === 1,
|
|
133
|
+
icnsFiles.length === 1 ? icnsFiles[0] : `发现 ${icnsFiles.length} 份:${icnsFiles.join(', ')}`
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (named && fs.existsSync(named)) {
|
|
137
|
+
const src = path.join(BUILD, 'icon.icns');
|
|
138
|
+
const same = fs.existsSync(src) && fs.readFileSync(named).equals(fs.readFileSync(src));
|
|
139
|
+
report('装进去的 icns 就是 build/icon.icns', same, same ? '一致' : '不一致(装的是旧图标?)');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function main() {
|
|
144
|
+
const appArg = process.argv[2];
|
|
145
|
+
checkBuildFiles();
|
|
146
|
+
if (appArg) checkAppBundle(path.resolve(appArg));
|
|
147
|
+
|
|
148
|
+
console.log('\n[icon] 检查结果');
|
|
149
|
+
for (const r of rows) {
|
|
150
|
+
console.log(` ${r.ok ? '\x1b[32m✓\x1b[0m' : '\x1b[31m✗\x1b[0m'} ${r.name.padEnd(32)} ${r.detail}`);
|
|
151
|
+
}
|
|
152
|
+
if (failed) {
|
|
153
|
+
console.log(`\n[icon] ${failed} 项不通过`);
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
console.log('\n[icon] 全部通过');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (require.main === module) main();
|
|
160
|
+
|
|
161
|
+
module.exports = { GRID_CONTENT, GRID_TOL, ICNS_SLOTS, ratioOf };
|
|
@@ -75,7 +75,9 @@ function appBundleFromBinary(bin) {
|
|
|
75
75
|
/** 用 LaunchServices 启动(macOS)。返回是否成功把进程扔出去(不代表端口会开)。 */
|
|
76
76
|
function launchViaOpen(bundle, root, log) {
|
|
77
77
|
try {
|
|
78
|
-
|
|
78
|
+
// -g:不激活 App。agent 拉起浏览器不该把用户正在做的事顶下去(同理见
|
|
79
|
+
// install_app.cjs)。配合 AI_BROWSER_LAUNCHED_BY_AGENT=1,窗口出现但不夺焦点。
|
|
80
|
+
const child = spawn('open', ['-g', '-n', '-a', bundle, '--args', root], {
|
|
79
81
|
stdio: 'ignore',
|
|
80
82
|
detached: true,
|
|
81
83
|
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// scripts/icon_geometry.cjs — 量一个图标 PNG 里「画出来的东西」占画布多大。
|
|
3
|
+
//
|
|
4
|
+
// # 为什么需要量这个
|
|
5
|
+
//
|
|
6
|
+
// macOS 26/27 给应用图标套了一层统一的图标网格(artwork 里再留出边距、套 squircle)。
|
|
7
|
+
// 于是**同一个图标经过两条渲染路径,尺寸不一样**:
|
|
8
|
+
//
|
|
9
|
+
// · bundle 的 icns(打包版) → 系统按网格缩放,实测内容占 85.9%
|
|
10
|
+
// · dock.setIcon 的裸 PNG(源码启动)→ 系统原样铺满,占 100%
|
|
11
|
+
//
|
|
12
|
+
// 85.9% 不是拍出来的:Safari / Finder 在同一口径下也都是 85.9%。所以"占 85.9%"
|
|
13
|
+
// 才是"和系统图标一样大"。100% 的那条会明显比旁边图标大一圈 —— 用户看到的就是
|
|
14
|
+
// "图标一会大一会小"(取决于这次是从 /Applications 启动还是 npm start)。
|
|
15
|
+
//
|
|
16
|
+
// 这个模块只做一件事:把 PNG 解出来,算 alpha 的包围盒占比。纯 Node,不调系统
|
|
17
|
+
// 工具,所以既能被 scripts/check_icon.cjs 用,也能被 vitest 直接跑。
|
|
18
|
+
//
|
|
19
|
+
// 支持范围:8bit、非隔行、colorType 0/2/4/6(灰/RGB/灰A/RGBA)。图标链上所有
|
|
20
|
+
// PNG 都落在这个范围里;超出范围直接抛错,不静默返回 1.0 —— 一个量不出来的
|
|
21
|
+
// 数字比一个错的数字更危险。
|
|
22
|
+
|
|
23
|
+
const zlib = require('node:zlib');
|
|
24
|
+
|
|
25
|
+
const PNG_SIG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
26
|
+
|
|
27
|
+
const CHANNELS = { 0: 1, 2: 3, 3: 1, 4: 2, 6: 4 };
|
|
28
|
+
|
|
29
|
+
function paeth(a, b, c) {
|
|
30
|
+
const p = a + b - c;
|
|
31
|
+
const pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c);
|
|
32
|
+
if (pa <= pb && pa <= pc) return a;
|
|
33
|
+
return pb <= pc ? b : c;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 解 PNG,返回 { width, height, channels, data },data 是去掉过滤后的原始像素。
|
|
38
|
+
* 位深必须 8,不能是隔行(图标链上不会出现这两种)。
|
|
39
|
+
*/
|
|
40
|
+
function decodePng(buf) {
|
|
41
|
+
if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
|
|
42
|
+
if (buf.length < 8 || !buf.subarray(0, 8).equals(PNG_SIG)) {
|
|
43
|
+
throw new Error('not a PNG (bad signature)');
|
|
44
|
+
}
|
|
45
|
+
let off = 8;
|
|
46
|
+
let ihdr = null;
|
|
47
|
+
const idat = [];
|
|
48
|
+
while (off + 8 <= buf.length) {
|
|
49
|
+
const len = buf.readUInt32BE(off);
|
|
50
|
+
const type = buf.toString('ascii', off + 4, off + 8);
|
|
51
|
+
const body = buf.subarray(off + 8, off + 8 + len);
|
|
52
|
+
if (type === 'IHDR') {
|
|
53
|
+
ihdr = {
|
|
54
|
+
width: body.readUInt32BE(0),
|
|
55
|
+
height: body.readUInt32BE(4),
|
|
56
|
+
bitDepth: body[8],
|
|
57
|
+
colorType: body[9],
|
|
58
|
+
interlace: body[12],
|
|
59
|
+
};
|
|
60
|
+
} else if (type === 'IDAT') {
|
|
61
|
+
idat.push(body);
|
|
62
|
+
} else if (type === 'IEND') {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
off += 12 + len; // len + type(4) + data + crc(4)
|
|
66
|
+
}
|
|
67
|
+
if (!ihdr) throw new Error('PNG has no IHDR');
|
|
68
|
+
if (ihdr.bitDepth !== 8) throw new Error(`unsupported PNG bit depth: ${ihdr.bitDepth}`);
|
|
69
|
+
if (ihdr.interlace !== 0) throw new Error('interlaced PNG not supported');
|
|
70
|
+
const channels = CHANNELS[ihdr.colorType];
|
|
71
|
+
if (!channels) throw new Error(`unsupported PNG color type: ${ihdr.colorType}`);
|
|
72
|
+
|
|
73
|
+
const raw = zlib.inflateSync(Buffer.concat(idat));
|
|
74
|
+
const { width, height } = ihdr;
|
|
75
|
+
const stride = width * channels;
|
|
76
|
+
const out = Buffer.alloc(stride * height);
|
|
77
|
+
let pos = 0;
|
|
78
|
+
for (let y = 0; y < height; y++) {
|
|
79
|
+
const filter = raw[pos++];
|
|
80
|
+
const line = raw.subarray(pos, pos + stride);
|
|
81
|
+
pos += stride;
|
|
82
|
+
const cur = out.subarray(y * stride, (y + 1) * stride);
|
|
83
|
+
const prev = y > 0 ? out.subarray((y - 1) * stride, y * stride) : null;
|
|
84
|
+
for (let x = 0; x < stride; x++) {
|
|
85
|
+
const a = x >= channels ? cur[x - channels] : 0;
|
|
86
|
+
const b = prev ? prev[x] : 0;
|
|
87
|
+
const c = prev && x >= channels ? prev[x - channels] : 0;
|
|
88
|
+
let v = line[x];
|
|
89
|
+
switch (filter) {
|
|
90
|
+
case 0: break;
|
|
91
|
+
case 1: v = (v + a) & 0xff; break;
|
|
92
|
+
case 2: v = (v + b) & 0xff; break;
|
|
93
|
+
case 3: v = (v + ((a + b) >> 1)) & 0xff; break;
|
|
94
|
+
case 4: v = (v + paeth(a, b, c)) & 0xff; break;
|
|
95
|
+
default: throw new Error(`unknown PNG filter type ${filter} on row ${y}`);
|
|
96
|
+
}
|
|
97
|
+
cur[x] = v;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { width, height, channels, data: out };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 内容包围盒。返回 { x, y, w, h, ratio, ratioW, ratioH }:
|
|
105
|
+
* ratio = 内容宽度 / 画布宽度(0~1)
|
|
106
|
+
* 没有 alpha 通道(colorType 0/2)时视为整块不透明 —— 调用方多半拿它比"有没有留白",
|
|
107
|
+
* 不透明图没有留白可言,返回 1 是诚实的。
|
|
108
|
+
*/
|
|
109
|
+
function contentBox(buf, { alphaThreshold = 2 } = {}) {
|
|
110
|
+
const { width, height, channels, data } = decodePng(buf);
|
|
111
|
+
const hasAlpha = channels === 4 || channels === 2;
|
|
112
|
+
if (!hasAlpha) {
|
|
113
|
+
return { x: 0, y: 0, w: width, h: height, ratio: 1, ratioW: 1, ratioH: 1, opaque: true };
|
|
114
|
+
}
|
|
115
|
+
const alphaOff = channels === 4 ? 3 : 1; // RGBA / 灰A
|
|
116
|
+
let minX = width, minY = height, maxX = -1, maxY = -1;
|
|
117
|
+
for (let y = 0; y < height; y++) {
|
|
118
|
+
const row = y * width * channels;
|
|
119
|
+
for (let x = 0; x < width; x++) {
|
|
120
|
+
if (data[row + x * channels + alphaOff] > alphaThreshold) {
|
|
121
|
+
if (x < minX) minX = x;
|
|
122
|
+
if (x > maxX) maxX = x;
|
|
123
|
+
if (y < minY) minY = y;
|
|
124
|
+
if (y > maxY) maxY = y;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (maxX < 0) return { x: 0, y: 0, w: 0, h: 0, ratio: 0, ratioW: 0, ratioH: 0, opaque: false };
|
|
129
|
+
const w = maxX - minX + 1, h = maxY - minY + 1;
|
|
130
|
+
return {
|
|
131
|
+
x: minX, y: minY, w, h,
|
|
132
|
+
ratio: w / width, // 老字段,等价于 ratioW
|
|
133
|
+
ratioW: w / width,
|
|
134
|
+
ratioH: h / height,
|
|
135
|
+
opaque: false,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = { decodePng, contentBox };
|
package/scripts/install_app.cjs
CHANGED
|
@@ -78,16 +78,30 @@ if (fs.existsSync(TARGET)) {
|
|
|
78
78
|
|
|
79
79
|
// ---- 替换 ----------------------------------------------------------------
|
|
80
80
|
if (fs.existsSync(TARGET)) {
|
|
81
|
-
|
|
81
|
+
// ⚠️ 备份必须以 .bak 结尾,不能留成 .app。
|
|
82
|
+
// .app 是一个 bundle,它的 Info.plist 里写着和 /Applications 那份**同一个
|
|
83
|
+
// bundle id**(com.glittering.ai-browser)。每装一次就往 /tmp 里多一份同 id
|
|
84
|
+
// 的 bundle,LaunchServices 会把它们全登记下来;之后 Dock / Finder 解析这个
|
|
85
|
+
// id 时可能拿到备份那份 —— 它的图标是旧版的,于是"图标一会大一会小"。
|
|
86
|
+
// .bak 不是可执行 bundle,LS 不登记。回滚就是把它改回 .app 再拷回去。
|
|
87
|
+
const backup = path.join(os.tmpdir(), `${APP_NAME}-${plistVersion(TARGET) || 'old'}-${Date.now()}.app.bak`);
|
|
82
88
|
fs.renameSync(TARGET, backup);
|
|
83
|
-
console.log(`旧包已移到 ${backup}
|
|
89
|
+
console.log(`旧包已移到 ${backup}(可回滚,未被删除;改回 .app 结尾即可)`);
|
|
84
90
|
}
|
|
85
91
|
const r = spawnSync('ditto', [srcApp, TARGET], { encoding: 'utf8' });
|
|
86
92
|
if (r.status !== 0) fail(`ditto 失败:${(r.stderr || '').trim()}`);
|
|
87
93
|
ok(`已安装 ${srcVer} → ${TARGET}`);
|
|
88
94
|
|
|
95
|
+
// 让 LaunchServices 认准新装这份 —— dist 里那份构建产物已由 build_dmg 注销,
|
|
96
|
+
// 这里显式登记 /Applications 的正式副本,避免同 id 解析到别处的旧图标。
|
|
97
|
+
spawnSync('/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister',
|
|
98
|
+
['-f', TARGET], { encoding: 'utf8' });
|
|
99
|
+
|
|
89
100
|
// ---- 启动 ----------------------------------------------------------------
|
|
90
101
|
if (!process.argv.includes('--no-open')) {
|
|
91
|
-
|
|
92
|
-
|
|
102
|
+
// -g:启动但**不激活**。装完自动把 App 顶到前台、抢走键盘焦点,对正在
|
|
103
|
+
// 用电脑的人来说就是一次打扰(2026-10-28 用户反馈"测试的时候还抢前台")。
|
|
104
|
+
// 窗口照常出现,只是不是它抢在最前面 —— 想看的时候点一下就是了。
|
|
105
|
+
spawnSync('open', ['-g', TARGET], { encoding: 'utf8' });
|
|
106
|
+
ok('已启动(不抢前台:要切过去点一下 Dock 图标)');
|
|
93
107
|
}
|
package/scripts/render_icon.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// scripts/render_icon.cjs — 从 build/icon.svg 一键重建整条图标链:
|
|
3
3
|
// SVG → 2048×2048 PNG(icon@2x.png)→ 1024 PNG(icon.png)
|
|
4
4
|
// → icon.iconset/(10 个尺寸)→ icon.icns(packager 的输入)
|
|
5
|
+
// → icon-dock.png(源码启动时 app.dock.setIcon 用,见下面 DOCK_CONTENT)
|
|
5
6
|
//
|
|
6
7
|
// # 为什么不用 qlmanage / rsvg-convert / ImageMagick
|
|
7
8
|
// qlmanage 在受限沙箱里直接 "sandbox initialization failed: Operation not permitted";
|
|
@@ -29,6 +30,24 @@ const PNG_2X = path.join(ROOT, 'build', 'icon@2x.png'); // 2048×2048,母版
|
|
|
29
30
|
const PNG = path.join(ROOT, 'build', 'icon.png'); // 1024×1024,预览用
|
|
30
31
|
const ICONSET = path.join(ROOT, 'build', 'icon.iconset');
|
|
31
32
|
const ICNS = path.join(ROOT, 'build', 'icon.icns');
|
|
33
|
+
const DOCK_PNG = path.join(ROOT, 'build', 'icon-dock.png'); // 1024×1024,Dock 专用
|
|
34
|
+
|
|
35
|
+
// ==== Dock 专用图的缩放比(2026-10-29 实测,别随手改)=======================
|
|
36
|
+
//
|
|
37
|
+
// macOS 26/27 会给 bundle 里的 icns 套一层统一图标网格:内容先缩到约 86.7%、
|
|
38
|
+
// 再套 squircle。而 `app.dock.setIcon()` 拿到的是裸 NSImage,系统**不**套这层
|
|
39
|
+
// 网格 —— 图铺满整格。于是同一个图形出现了两个尺寸:
|
|
40
|
+
//
|
|
41
|
+
// 打包版(Info.plist 的 icns) 内容占 86.7%
|
|
42
|
+
// 源码启动(dock.setIcon 裸图) 内容占 100.0%
|
|
43
|
+
//
|
|
44
|
+
// 用户看到的就是"图标一会大一会小"(从 /Applications 启动 vs npm start)。
|
|
45
|
+
// 86.7% 不是猜的:Safari、Finder 以及我们自己的 bundle 图标,按同一口径量出来
|
|
46
|
+
// 都是 86~87%(scripts/check_icon.cjs 量、tests/test_icon_geometry.js 钉住)。
|
|
47
|
+
//
|
|
48
|
+
// 所以 Dock 用的这张图**预先**按 86.7% 缩好,让两条路径落到同一个尺寸。
|
|
49
|
+
// 满出血的 icon.png 仍然是窗口图标(Windows/Linux)与 icns 的源 —— 那里不该缩。
|
|
50
|
+
const DOCK_CONTENT = 0.867;
|
|
32
51
|
|
|
33
52
|
// icns 要求的全部尺寸(源图是 2048²,一律从它缩)
|
|
34
53
|
const SIZES = [
|
|
@@ -107,6 +126,36 @@ app.whenReady().then(async () => {
|
|
|
107
126
|
fs.rmSync(ICNS, { force: true });
|
|
108
127
|
run('iconutil', ['-c', 'icns', ICONSET, '-o', ICNS]);
|
|
109
128
|
|
|
129
|
+
// 4) Dock 专用图:同一个图形按系统图标网格缩到 DOCK_CONTENT,透明居中
|
|
130
|
+
const stage = path.join(ROOT, 'build', '.dock_stage.html');
|
|
131
|
+
fs.writeFileSync(stage, [
|
|
132
|
+
'<!doctype html><meta charset="utf-8">',
|
|
133
|
+
'<style>html,body{margin:0;background:transparent;overflow:hidden}',
|
|
134
|
+
`#c{width:${SIZE}px;height:${SIZE}px;display:flex;align-items:center;justify-content:center}`,
|
|
135
|
+
`#c img{width:${(SIZE * DOCK_CONTENT).toFixed(2)}px;height:${(SIZE * DOCK_CONTENT).toFixed(2)}px;display:block}</style>`,
|
|
136
|
+
`<div id="c"><img src="icon.svg" alt=""></div>`,
|
|
137
|
+
].join('\n'));
|
|
138
|
+
let dockPng = null;
|
|
139
|
+
try {
|
|
140
|
+
const dockWin = new BrowserWindow({
|
|
141
|
+
width: SIZE, height: SIZE, show: false, transparent: true,
|
|
142
|
+
backgroundColor: '#00000000', useContentSize: true,
|
|
143
|
+
webPreferences: { offscreen: false },
|
|
144
|
+
});
|
|
145
|
+
await dockWin.loadFile(stage);
|
|
146
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
147
|
+
const shot = await dockWin.webContents.capturePage();
|
|
148
|
+
if (shot.isEmpty()) throw new Error('dock capture returned an empty image');
|
|
149
|
+
dockPng = shot.toPNG();
|
|
150
|
+
dockWin.destroy();
|
|
151
|
+
} finally {
|
|
152
|
+
fs.rmSync(stage, { force: true });
|
|
153
|
+
}
|
|
154
|
+
fs.writeFileSync(path.join(ROOT, 'build', 'icon-dock@2x.png'), dockPng);
|
|
155
|
+
run('sips', ['-Z', String(SIZE), path.join(ROOT, 'build', 'icon-dock@2x.png'), '-o', DOCK_PNG]);
|
|
156
|
+
fs.rmSync(path.join(ROOT, 'build', 'icon-dock@2x.png'), { force: true });
|
|
157
|
+
console.log(`[icon] dock 图: ${path.relative(ROOT, DOCK_PNG)}(内容占 ${(DOCK_CONTENT * 100).toFixed(1)}%,与系统图标同尺寸)`);
|
|
158
|
+
|
|
110
159
|
const icnsSize = fs.statSync(ICNS).size;
|
|
111
160
|
console.log(`[icon] iconset: ${SIZES.length} sizes -> ${path.relative(ROOT, ICNS)} (${icnsSize} bytes)`);
|
|
112
161
|
console.log('[icon] done. build_dmg.cjs 会读取 build/icon.icns');
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
data.tabs = [{tab, url}, ...]
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
(MCP / 工具层收到的这次失败,会以工具结果 `isError: true` + `Error: your tab group is full (8/8) — close one before opening another`
|
|
35
|
+
回到你 —— 照着执行就行,不是 JSON-RPC protocol error。)
|
|
36
|
+
|
|
34
37
|
先把不用的关掉(`browse_tabs {"op":"close","tab":N}`)再开。上限存在的意义不是
|
|
35
38
|
刁难:后台运行时没人看得见你的标签页,不设限就会一路开到内存告急。
|
|
36
39
|
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
|
|
20
20
|
## 多标签
|
|
21
21
|
|
|
22
|
-
- `browse_tabs {op:"list"}` 看现状;`{op:"new", url}` 新开;`{op:"switch", tab}`
|
|
23
|
-
-
|
|
24
|
-
- `window.open` / `target="_blank"`
|
|
22
|
+
- `browse_tabs {op:"list"}` 看现状;`{op:"new", url}` 新开;`{op:"switch", tab}` 切换(`switch` 可带 `show:true`:同时把这一页顶到用户眼前、并设为默认目标)。
|
|
23
|
+
- 省略 `tab` 就打你自己的工作页(一个 agent = 一块自己的组);只显式传 `tab` 才换目标。
|
|
24
|
+
- `window.open` / `target="_blank"` 派生标签页跟**打开者**的组走;后台 agent 弹窗不抢视野(不显示),活跃才顶到眼前。想留在原地(不跟随新标签)传 `keep_tab:true`。
|
|
25
25
|
|
|
26
26
|
## 证明操作生效(`browse_diff`)
|
|
27
27
|
|
package/src/main/axExtractor.js
CHANGED
|
@@ -669,4 +669,4 @@ export function diffLite(prevLite, newLite) {
|
|
|
669
669
|
return { revealed, hidden };
|
|
670
670
|
}
|
|
671
671
|
|
|
672
|
-
export default { normalizeAxTree, markAggregatedLabels, mergeFrameTrees, modalsFromAx, extractFromDebugger, axRead, axRaw, ensureHandles, attachHrefs, filterInteractive, liteSnapshot, diffLite, VERSION_TAG };
|
|
672
|
+
export default { normalizeAxTree, markAggregatedLabels, mergeFrameTrees, modalsFromAx, extractFromDebugger, axRead, axRaw, ensureHandles, attachHrefs, filterInteractive, liteSnapshot, diffLite, VERSION_TAG, summarizeEditors };
|