@glittering0717/ai-browser 2.5.6 → 2.5.9
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 +3 -3
- package/examples/AGENT_INSTRUCTIONS.md +1 -2
- package/llms-install.md +11 -8
- package/package.json +2 -2
- package/scripts/marketing/data_snapshot.sh +2 -1
- package/scripts/release.cjs +213 -80
- package/scripts/render_icon.cjs +51 -28
- package/scripts/skill.cjs +104 -9
- package/scripts/verify_asar.cjs +8 -2
- package/scripts/verify_build.cjs +71 -32
- package/skills/ai-browser/SKILL.md +20 -15
- package/skills/ai-browser/references/network.md +34 -12
- package/skills/ai-browser/references/tasks.md +3 -3
- package/skills/content-publish/SKILL.md +10 -3
- package/skills/read-webpage/SKILL.md +10 -3
- package/src/main/axExtractor.js +1 -1
- package/src/main/capability_probe.js +2 -2
- package/src/main/error_log.js +102 -0
- package/src/main/index.js +24 -4
- package/src/main/mcp_server.js +7 -3
- package/src/main/mcp_tools.js +3 -2
- package/src/main/page_manager.js +30 -11
- package/src/main/window_open_shim_source.js +2 -2
- package/src/main/ws_server.js +14 -1
- package/src/preload/extractor.cjs +2 -2
- package/src/renderer/download.html +1 -1
- package/src/shared/browser_identity.cjs +1 -1
- package/src/shared/doc_coverage.js +6 -6
- package/src/shared/frame_probe.cjs +1 -1
- package/src/shared/frame_read_source.js +4 -4
- package/src/shared/media_doc.cjs +1 -1
- package/src/shared/opened_tab.js +1 -1
- package/src/shared/version.js +1 -1
- package/src/shared/view_liveness.cjs +31 -1
- package/tools/coverage_probe.cjs +4 -4
- package/skills/web-network-monitor/SKILL.md +0 -52
package/scripts/render_icon.cjs
CHANGED
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
// build_dmg.cjs 的 icon 选项只读 build/icon.icns;icon.svg 是母版;
|
|
15
15
|
// 其余 png/iconset 都是本脚本的再生产物,改了 SVG 重跑本脚本即可。
|
|
16
16
|
//
|
|
17
|
-
// # 用法(必须在 Electron 下运行,不是 node
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
17
|
+
// # 用法(必须在 Electron 下运行,不是 node)
|
|
18
|
+
// npm run icons
|
|
19
|
+
// 等价于 node scripts/render_icon.cjs —— 脚本检测到自己在普通 node 下,
|
|
20
|
+
// 会用 require('electron') 返回的二进制路径把**自己**重新拉进 Electron 跑,
|
|
21
|
+
// 所以 macOS / Windows / Linux 同一条命令,不写死 *.app 路径。
|
|
21
22
|
'use strict';
|
|
22
23
|
|
|
23
24
|
const fs = require('node:fs');
|
|
@@ -63,19 +64,30 @@ const SIZES = [
|
|
|
63
64
|
[1024, 'icon_512x512@2x.png'],
|
|
64
65
|
];
|
|
65
66
|
|
|
66
|
-
//
|
|
67
|
+
// 普通 node 下 require('electron') 拿到的是**二进制路径字符串**(三平台一致)。
|
|
68
|
+
// 用它把本脚本重新拉进 Electron:这样入口不再依赖 macOS 的 Electron.app 结构。
|
|
67
69
|
let electron;
|
|
68
70
|
try {
|
|
69
71
|
electron = require('electron');
|
|
70
72
|
} catch (_) {
|
|
71
73
|
electron = null;
|
|
72
74
|
}
|
|
75
|
+
if (typeof electron === 'string') {
|
|
76
|
+
const env = { ...process.env };
|
|
77
|
+
// 只要这个变量存在(哪怕空串),Electron 都会按 node 模式启动,必须删掉。
|
|
78
|
+
delete env.ELECTRON_RUN_AS_NODE;
|
|
79
|
+
const r = spawnSync(electron, ['--no-sandbox', '--disable-gpu', __filename], {
|
|
80
|
+
stdio: 'inherit',
|
|
81
|
+
env,
|
|
82
|
+
});
|
|
83
|
+
process.exit(r.status ?? 1);
|
|
84
|
+
}
|
|
73
85
|
if (!electron || typeof electron.app === 'undefined') {
|
|
74
|
-
console.error('[icon]
|
|
86
|
+
console.error('[icon] 找不到 Electron 运行时(node_modules/electron 没装好?)。');
|
|
75
87
|
process.exit(2);
|
|
76
88
|
}
|
|
77
89
|
|
|
78
|
-
const { app, BrowserWindow } = electron;
|
|
90
|
+
const { app, BrowserWindow, nativeImage } = electron;
|
|
79
91
|
|
|
80
92
|
app.commandLine.appendSwitch('disable-gpu'); // 无头环境没有 GL,别让 GPU 进程拖后腿
|
|
81
93
|
|
|
@@ -86,8 +98,15 @@ function run(cmd, args) {
|
|
|
86
98
|
}
|
|
87
99
|
}
|
|
88
100
|
|
|
101
|
+
// 用 Electron 自带的 nativeImage 缩放,替代 macOS 专属的 sips —— 三平台同一套。
|
|
102
|
+
function resizedPng(img, size) {
|
|
103
|
+
return img.resize({ width: size, height: size, quality: 'best' }).toPNG();
|
|
104
|
+
}
|
|
105
|
+
|
|
89
106
|
app.whenReady().then(async () => {
|
|
90
|
-
// 窗口 1024,capturePage 在 Retina 下返回 2x(2048×2048
|
|
107
|
+
// 窗口 1024,capturePage 在 Retina 下返回 2x(2048×2048)——这就是母版位图。
|
|
108
|
+
// offscreen: 离屏渲染不受"窗口不能大于屏幕可用高度"的限制;否则在 1080p
|
|
109
|
+
// 笔记本上 1024×1024 会被裁成 1024×1001,图被纵向拉伸(实测)。
|
|
91
110
|
const SIZE = 1024;
|
|
92
111
|
const win = new BrowserWindow({
|
|
93
112
|
width: SIZE,
|
|
@@ -96,7 +115,7 @@ app.whenReady().then(async () => {
|
|
|
96
115
|
transparent: true,
|
|
97
116
|
backgroundColor: '#00000000',
|
|
98
117
|
useContentSize: true,
|
|
99
|
-
webPreferences: { offscreen:
|
|
118
|
+
webPreferences: { offscreen: true },
|
|
100
119
|
});
|
|
101
120
|
|
|
102
121
|
try {
|
|
@@ -108,23 +127,31 @@ app.whenReady().then(async () => {
|
|
|
108
127
|
if (img.isEmpty()) throw new Error('capturePage returned an empty image');
|
|
109
128
|
|
|
110
129
|
const png = img.toPNG();
|
|
111
|
-
fs.writeFileSync(PNG_2X, png);
|
|
112
130
|
const w = img.getSize().width;
|
|
113
131
|
const h = img.getSize().height;
|
|
132
|
+
// 非正方形说明截取被窗口约束裁过,再缩放会把图形拉变形 —— 宁可失败。
|
|
133
|
+
if (w !== h) throw new Error(`capturePage 返回 ${w}x${h},不是正方形(窗口被屏幕尺寸限制?)`);
|
|
134
|
+
fs.writeFileSync(PNG_2X, png);
|
|
135
|
+
const master = nativeImage.createFromBuffer(png);
|
|
114
136
|
console.log(`[icon] ${path.relative(ROOT, SVG)} -> ${path.relative(ROOT, PNG_2X)} (${w}x${h}, ${png.length} bytes)`);
|
|
115
137
|
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// 2)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
138
|
+
// 1) 1024 预览图 / Windows·Linux 窗口图标源(三平台都要)
|
|
139
|
+
fs.writeFileSync(PNG, resizedPng(master, 1024));
|
|
140
|
+
|
|
141
|
+
// 2) icns 只有 macOS 打包读;Windows 读 build/icon.ico,Linux 直接读 png。
|
|
142
|
+
if (process.platform === 'darwin') {
|
|
143
|
+
fs.rmSync(ICONSET, { recursive: true, force: true });
|
|
144
|
+
fs.mkdirSync(ICONSET, { recursive: true });
|
|
145
|
+
for (const [size, name] of SIZES) {
|
|
146
|
+
fs.writeFileSync(path.join(ICONSET, name), resizedPng(master, size));
|
|
147
|
+
}
|
|
148
|
+
fs.rmSync(ICNS, { force: true });
|
|
149
|
+
run('iconutil', ['-c', 'icns', ICONSET, '-o', ICNS]);
|
|
150
|
+
const icnsSize = fs.statSync(ICNS).size;
|
|
151
|
+
console.log(`[icon] iconset: ${SIZES.length} sizes -> ${path.relative(ROOT, ICNS)} (${icnsSize} bytes)`);
|
|
152
|
+
} else {
|
|
153
|
+
console.log(`[icon] 跳过 icns(${process.platform} 打包不读它;Windows 用 build/icon.ico)`);
|
|
124
154
|
}
|
|
125
|
-
// 3) 打 icns
|
|
126
|
-
fs.rmSync(ICNS, { force: true });
|
|
127
|
-
run('iconutil', ['-c', 'icns', ICONSET, '-o', ICNS]);
|
|
128
155
|
|
|
129
156
|
// 4) Dock 专用图:同一个图形按系统图标网格缩到 DOCK_CONTENT,透明居中
|
|
130
157
|
const stage = path.join(ROOT, 'build', '.dock_stage.html');
|
|
@@ -140,7 +167,7 @@ app.whenReady().then(async () => {
|
|
|
140
167
|
const dockWin = new BrowserWindow({
|
|
141
168
|
width: SIZE, height: SIZE, show: false, transparent: true,
|
|
142
169
|
backgroundColor: '#00000000', useContentSize: true,
|
|
143
|
-
webPreferences: { offscreen:
|
|
170
|
+
webPreferences: { offscreen: true },
|
|
144
171
|
});
|
|
145
172
|
await dockWin.loadFile(stage);
|
|
146
173
|
await new Promise((r) => setTimeout(r, 300));
|
|
@@ -151,14 +178,10 @@ app.whenReady().then(async () => {
|
|
|
151
178
|
} finally {
|
|
152
179
|
fs.rmSync(stage, { force: true });
|
|
153
180
|
}
|
|
154
|
-
fs.writeFileSync(
|
|
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 });
|
|
181
|
+
fs.writeFileSync(DOCK_PNG, resizedPng(nativeImage.createFromBuffer(dockPng), SIZE));
|
|
157
182
|
console.log(`[icon] dock 图: ${path.relative(ROOT, DOCK_PNG)}(内容占 ${(DOCK_CONTENT * 100).toFixed(1)}%,与系统图标同尺寸)`);
|
|
158
183
|
|
|
159
|
-
|
|
160
|
-
console.log(`[icon] iconset: ${SIZES.length} sizes -> ${path.relative(ROOT, ICNS)} (${icnsSize} bytes)`);
|
|
161
|
-
console.log('[icon] done. build_dmg.cjs 会读取 build/icon.icns');
|
|
184
|
+
console.log('[icon] done.');
|
|
162
185
|
app.exit(0);
|
|
163
186
|
} catch (e) {
|
|
164
187
|
console.error(`[icon] FAILED: ${e.message}`);
|
package/scripts/skill.cjs
CHANGED
|
@@ -14,16 +14,25 @@
|
|
|
14
14
|
const fs = require('node:fs');
|
|
15
15
|
const os = require('node:os');
|
|
16
16
|
const path = require('node:path');
|
|
17
|
+
const crypto = require('node:crypto');
|
|
17
18
|
const pkg = require('../package.json');
|
|
18
19
|
|
|
19
20
|
const SKILLS_ROOT = path.join(__dirname, '..', 'skills');
|
|
20
21
|
const MARKER = '.ai-browser-skill';
|
|
21
22
|
|
|
22
23
|
// 已知客户端的技能目录。宁可只列确定正确的几个,也不猜。
|
|
24
|
+
// 每个客户端从自己的目录扫 SKILL.md(frontmatter 里 name + description),
|
|
25
|
+
// 格式一致,所以同一份文件能直接拷。目录不存在说明没装那个客户端,跳过。
|
|
26
|
+
//
|
|
27
|
+
// Trae CN 是 2026-11-28 补上的:之前只装 WorkBuddy / Claude / Codex,
|
|
28
|
+
// 用户在 Trae 里让 agent「用 ai-browser」,agent 根本看不到这个技能 ——
|
|
29
|
+
// 而 Trae 索引里恰好有一个 Vercel 的 `agent-browser`(名字相近、场景重叠),
|
|
30
|
+
// 于是它要么匹配到那个,要么退回去用 Trae 内置的 Chrome 通道。
|
|
23
31
|
const TARGETS = [
|
|
24
32
|
{ id: 'workbuddy', label: 'WorkBuddy', dir: path.join(os.homedir(), '.workbuddy', 'skills') },
|
|
25
33
|
{ id: 'claude', label: 'Claude Code', dir: path.join(os.homedir(), '.claude', 'skills') },
|
|
26
34
|
{ id: 'codex', label: 'Codex', dir: path.join(os.homedir(), '.codex', 'skills') },
|
|
35
|
+
{ id: 'trae', label: 'Trae CN', dir: path.join(os.homedir(), '.trae-cn', 'skills') },
|
|
27
36
|
];
|
|
28
37
|
|
|
29
38
|
function listSkills() {
|
|
@@ -56,6 +65,63 @@ function readMarker(dest) {
|
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
67
|
|
|
68
|
+
// 内容指纹。为什么需要它(2026-11-25 当晚就踩到):
|
|
69
|
+
// 只比版本号时,"同一版本里改了技能文案"这类改动永远装不上去 —— install 判定
|
|
70
|
+
// up-to-date 直接跳过,用户看到的是"改了描述但 agent 行为没变",而且没有任何
|
|
71
|
+
// 报错。所以标记里再存一份内容 hash,版本相同但内容变了也要重装。
|
|
72
|
+
function skillSignature(dir) {
|
|
73
|
+
if (!fs.existsSync(dir)) return '';
|
|
74
|
+
const h = crypto.createHash('sha256');
|
|
75
|
+
const walk = (cur) => {
|
|
76
|
+
const entries = fs.readdirSync(cur, { withFileTypes: true })
|
|
77
|
+
.sort((a, b) => (a.name < b.name ? -1 : 1));
|
|
78
|
+
for (const e of entries) {
|
|
79
|
+
if (e.name === MARKER) continue;
|
|
80
|
+
const p = path.join(cur, e.name);
|
|
81
|
+
if (e.isDirectory()) walk(p);
|
|
82
|
+
else {
|
|
83
|
+
h.update(path.relative(dir, p));
|
|
84
|
+
h.update(fs.readFileSync(p));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
walk(dir);
|
|
89
|
+
return h.digest('hex').slice(0, 8);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function readSignature(dest) {
|
|
93
|
+
const marker = path.join(dest, MARKER);
|
|
94
|
+
if (!fs.existsSync(marker)) return null;
|
|
95
|
+
try {
|
|
96
|
+
const m = fs.readFileSync(marker, 'utf8').match(/ai-browser\s+\S+\s+([0-9a-f]{4,})/);
|
|
97
|
+
return m ? m[1] : '';
|
|
98
|
+
} catch {
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function markerText(sig) {
|
|
104
|
+
return `ai-browser ${pkg.version} ${sig}\n`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 包里已经删掉的技能,在用户目录里不会自己消失 —— 它会继续被客户端发现、
|
|
108
|
+
// 继续按旧描述触发。2026-11-25 合并 web-network-monitor 时踩到的就是这个:
|
|
109
|
+
// 新版明明不带了,老用户那边还在跑。所以 install 必须负责收尸。
|
|
110
|
+
// 只删带 marker 的目录(= 本工具装的),用户自己写的同名技能永远不碰。
|
|
111
|
+
function removeOrphans(targetDir) {
|
|
112
|
+
if (!fs.existsSync(targetDir)) return [];
|
|
113
|
+
const current = new Set(listSkills());
|
|
114
|
+
const removed = [];
|
|
115
|
+
for (const e of fs.readdirSync(targetDir, { withFileTypes: true })) {
|
|
116
|
+
if (!e.isDirectory() || current.has(e.name)) continue;
|
|
117
|
+
const dir = path.join(targetDir, e.name);
|
|
118
|
+
if (!fs.existsSync(path.join(dir, MARKER))) continue;
|
|
119
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
120
|
+
removed.push(e.name);
|
|
121
|
+
}
|
|
122
|
+
return removed;
|
|
123
|
+
}
|
|
124
|
+
|
|
59
125
|
// 已装副本与当前包的版本差。为什么需要它(2026-11-25):
|
|
60
126
|
// install 只在有人手动跑的时候写盘,`npm i -g` / `npx` 升级都不会碰用户目录,
|
|
61
127
|
// 于是"包装到了 2.4.1、技能还停在 2.1.1"是**静默**发生的 —— 用户看到的现象是
|
|
@@ -66,8 +132,19 @@ function drift() {
|
|
|
66
132
|
for (const t of detectTargets()) {
|
|
67
133
|
if (!t.exists) continue;
|
|
68
134
|
for (const s of t.installed) {
|
|
69
|
-
const
|
|
70
|
-
|
|
135
|
+
const dest = path.join(t.dir, s);
|
|
136
|
+
const v = readMarker(dest);
|
|
137
|
+
const sig = readSignature(dest);
|
|
138
|
+
const want = skillSignature(path.join(SKILLS_ROOT, s));
|
|
139
|
+
if (v !== pkg.version || sig !== want) {
|
|
140
|
+
out.push({
|
|
141
|
+
target: t.label,
|
|
142
|
+
dir: t.dir,
|
|
143
|
+
skill: s,
|
|
144
|
+
from: v || '?',
|
|
145
|
+
contentOnly: v === pkg.version,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
71
148
|
}
|
|
72
149
|
}
|
|
73
150
|
return out;
|
|
@@ -83,8 +160,11 @@ function installOne(skill, targetDir) {
|
|
|
83
160
|
if (fs.existsSync(dest) && installedVersion === null) {
|
|
84
161
|
return { skill, status: 'skipped-user-owned' };
|
|
85
162
|
}
|
|
86
|
-
|
|
87
|
-
|
|
163
|
+
|
|
164
|
+
const srcSig = skillSignature(src);
|
|
165
|
+
// 版本 + 内容都一致才算最新:只比版本会把"同版本改了文案"判成 up-to-date,
|
|
166
|
+
// 改动永远装不上去,而且不报错。
|
|
167
|
+
if (installedVersion === pkg.version && readSignature(dest) === srcSig) {
|
|
88
168
|
return { skill, status: 'up-to-date' };
|
|
89
169
|
}
|
|
90
170
|
|
|
@@ -94,9 +174,10 @@ function installOne(skill, targetDir) {
|
|
|
94
174
|
// 而且 agent 会继续读到已经作废的 reference。
|
|
95
175
|
if (fs.existsSync(dest)) fs.rmSync(dest, { recursive: true, force: true });
|
|
96
176
|
fs.cpSync(src, dest, { recursive: true });
|
|
97
|
-
fs.writeFileSync(path.join(dest, MARKER),
|
|
177
|
+
fs.writeFileSync(path.join(dest, MARKER), markerText(srcSig), 'utf8');
|
|
98
178
|
|
|
99
|
-
|
|
179
|
+
const status = installedVersion ? 'upgraded' : 'installed';
|
|
180
|
+
return { skill, status, from: installedVersion || null };
|
|
100
181
|
}
|
|
101
182
|
|
|
102
183
|
function install({ dir, all }) {
|
|
@@ -129,7 +210,10 @@ function install({ dir, all }) {
|
|
|
129
210
|
note = `✓ ${s}`;
|
|
130
211
|
changed++;
|
|
131
212
|
} else if (r.status === 'upgraded') {
|
|
132
|
-
note =
|
|
213
|
+
note =
|
|
214
|
+
r.from === pkg.version
|
|
215
|
+
? `↻ ${s} 内容变了(版本仍是 ${pkg.version})`
|
|
216
|
+
: `↑ ${s} ${r.from} → ${pkg.version}`;
|
|
133
217
|
changed++;
|
|
134
218
|
} else if (r.status === 'up-to-date') {
|
|
135
219
|
note = `· ${s} 已是最新(${pkg.version})`;
|
|
@@ -138,6 +222,11 @@ function install({ dir, all }) {
|
|
|
138
222
|
}
|
|
139
223
|
console.log(' ' + note);
|
|
140
224
|
}
|
|
225
|
+
const removed = removeOrphans(t.dir);
|
|
226
|
+
if (removed.length) {
|
|
227
|
+
console.log(` − 已移除 ${removed.join('、')}(包里不再带这个技能了)`);
|
|
228
|
+
changed++;
|
|
229
|
+
}
|
|
141
230
|
}
|
|
142
231
|
if (changed) {
|
|
143
232
|
console.log(`\n更新了 ${changed} 个技能(共 ${skills.length} 个 × ${dirs.length} 个位置)。新开会话时客户端会自动发现它们。`);
|
|
@@ -171,8 +260,11 @@ function run(argv) {
|
|
|
171
260
|
// 版本漂移必须在人主动查看时就能看见,而不是等 agent 用旧技能出错。
|
|
172
261
|
const stale = drift();
|
|
173
262
|
if (stale.length) {
|
|
174
|
-
console.log(`\n! ${stale.length}
|
|
175
|
-
for (const d of stale)
|
|
263
|
+
console.log(`\n! ${stale.length} 个副本需要刷新:`);
|
|
264
|
+
for (const d of stale) {
|
|
265
|
+
const why = d.contentOnly ? `内容变了(版本仍是 ${pkg.version})` : `${d.from} → ${pkg.version}`;
|
|
266
|
+
console.log(` ${d.target}/${d.skill} ${why}`);
|
|
267
|
+
}
|
|
176
268
|
console.log(' 运行 `ai-browser skill install` 刷新。');
|
|
177
269
|
}
|
|
178
270
|
console.log('\n装上:ai-browser skill install 只装到已存在的客户端目录');
|
|
@@ -198,7 +290,10 @@ module.exports = {
|
|
|
198
290
|
detectTargets,
|
|
199
291
|
drift,
|
|
200
292
|
readMarker,
|
|
293
|
+
readSignature,
|
|
294
|
+
skillSignature,
|
|
201
295
|
installOne,
|
|
296
|
+
removeOrphans,
|
|
202
297
|
SKILLS_ROOT,
|
|
203
298
|
MARKER,
|
|
204
299
|
};
|
package/scripts/verify_asar.cjs
CHANGED
|
@@ -99,7 +99,13 @@ function verifyAsarDeps(target, opts = {}) {
|
|
|
99
99
|
return { ok: false, asar: null, checked: 0, typesOnly: 0, violations: [{ pkg: '(app.asar)', entry: '找不到 app.asar', why: '' }] };
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
// listPackage 返回的是**宿主平台**的路径(Windows 是 `\a\b`,POSIX 是 `/a/b`)。
|
|
103
|
+
// 内部统一成 `/` 形式做比较;需要回传给 @electron/asar 时再按 path.sep 还原,
|
|
104
|
+
// 因为它的 Filesystem 用 path.sep 拆目录,两边都得说得通。
|
|
105
|
+
const toNative = (rel) => rel.split('/').join(path.sep);
|
|
106
|
+
const entries = new Set(
|
|
107
|
+
asarMod.listPackage(asarPath).map((p) => p.replace(/[\\/]+/g, '/').replace(/^\/+/, ''))
|
|
108
|
+
);
|
|
103
109
|
|
|
104
110
|
// 与 Node 的解析规则一致:无扩展名要试 .js/.json/.node,目录要退到 index.*
|
|
105
111
|
const SUFFIX = ['', '.js', '.json', '.node', '/index.js', '/index.json', '/index.node'];
|
|
@@ -155,7 +161,7 @@ function verifyAsarDeps(target, opts = {}) {
|
|
|
155
161
|
checked++;
|
|
156
162
|
let meta = null;
|
|
157
163
|
try {
|
|
158
|
-
meta = JSON.parse(asarMod.extractFile(asarPath, pj).toString('utf8'));
|
|
164
|
+
meta = JSON.parse(asarMod.extractFile(asarPath, toNative(pj)).toString('utf8'));
|
|
159
165
|
} catch (_) {
|
|
160
166
|
violations.push({ pkg: pkgName, entry: '(package.json 无法解析)', why: '' });
|
|
161
167
|
continue;
|
package/scripts/verify_build.cjs
CHANGED
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
//
|
|
10
10
|
// 这类漂移(source ≠ package)是所有桌面分发共同的问题,靠"记得重新打包"
|
|
11
11
|
// 解决不了,必须能机器判定。这里做三件事:
|
|
12
|
-
// 1.
|
|
12
|
+
// 1. 版本一致:产物里声明的版本 == package.json 版本
|
|
13
|
+
// (macOS 看 Info.plist,Windows/Linux 看 asar 内的 package.json)
|
|
13
14
|
// 2. 内容一致:asar 里的 src/** 与磁盘上的 src/** 逐字节相同(少一个文件、
|
|
14
15
|
// 多一个文件、内容有 diff 都算失败)
|
|
15
|
-
// 3.
|
|
16
|
+
// 3. 产物存在:当前平台的安装产物在 dist/
|
|
17
|
+
// (macOS: *.dmg,Windows: dist/installer/*-Setup.exe)
|
|
16
18
|
//
|
|
17
19
|
// # 用法
|
|
18
20
|
// node scripts/verify_build.cjs # 失败退出码 1
|
|
@@ -36,48 +38,73 @@ function sha(buf) {
|
|
|
36
38
|
return crypto.createHash('sha256').update(buf).digest('hex').slice(0, 16);
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
// ---- 1.
|
|
41
|
+
// ---- 1. 找到打包后的 asar(macOS: *.app,Windows/Linux: 便携目录)----------
|
|
40
42
|
const distDir = path.join(ROOT, 'dist');
|
|
41
43
|
if (!fs.existsSync(distDir)) {
|
|
42
|
-
fail('dist/ 不存在 ——
|
|
44
|
+
fail('dist/ 不存在 —— 还没打过包');
|
|
43
45
|
process.exit(1);
|
|
44
46
|
}
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const asar = require('@electron/asar');
|
|
48
|
+
const platform = process.platform;
|
|
49
|
+
let appPath = null;
|
|
50
|
+
let asarPath = null;
|
|
51
|
+
if (platform === 'darwin') {
|
|
52
|
+
const appDirName = fs.readdirSync(distDir).find((n) => n.endsWith('-darwin-arm64'));
|
|
53
|
+
if (!appDirName) {
|
|
54
|
+
fail('dist/ 里没有 *-darwin-arm64 目录');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
appPath = path.join(distDir, appDirName, 'AI Browser.app');
|
|
58
|
+
asarPath = path.join(appPath, 'Contents', 'Resources', 'app.asar');
|
|
59
|
+
} else if (platform === 'win32') {
|
|
60
|
+
const appDirName = fs.readdirSync(distDir).find((n) => n.endsWith('-win32-x64'));
|
|
61
|
+
if (!appDirName) {
|
|
62
|
+
fail('dist/ 里没有 *-win32-x64 目录');
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
asarPath = path.join(distDir, appDirName, 'resources', 'app.asar');
|
|
66
|
+
} else {
|
|
67
|
+
const appDirName = fs.readdirSync(distDir).find((n) => n.endsWith('-linux-x64'));
|
|
68
|
+
if (!appDirName) {
|
|
69
|
+
fail('dist/ 里没有 *-linux-x64 目录');
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
asarPath = path.join(distDir, appDirName, 'resources', 'app.asar');
|
|
49
73
|
}
|
|
50
|
-
const appPath = path.join(distDir, appDirName, 'AI Browser.app');
|
|
51
|
-
const asarPath = path.join(appPath, 'Contents', 'Resources', 'app.asar');
|
|
52
74
|
if (!fs.existsSync(asarPath)) {
|
|
53
75
|
fail(`asar 不存在:${asarPath}`);
|
|
54
76
|
process.exit(1);
|
|
55
77
|
}
|
|
56
78
|
|
|
57
79
|
// ---- 2. 版本一致 -----------------------------------------------------------
|
|
58
|
-
|
|
59
|
-
|
|
80
|
+
// macOS 读 bundle 的 Info.plist(用户在"关于"里看到的就是它);Windows/Linux
|
|
81
|
+
// 没有 plist,读 asar 里 package.json 的 version —— 都是"产物自己声明的版本"。
|
|
82
|
+
let appVer = null;
|
|
83
|
+
if (platform === 'darwin') {
|
|
60
84
|
try {
|
|
61
|
-
|
|
85
|
+
appVer = require('node:child_process').execFileSync(
|
|
62
86
|
'/usr/libexec/PlistBuddy',
|
|
63
|
-
['-c', 'Print :CFBundleShortVersionString',
|
|
87
|
+
['-c', 'Print :CFBundleShortVersionString', path.join(appPath, 'Contents', 'Info.plist')],
|
|
64
88
|
{ encoding: 'utf8' }
|
|
65
89
|
).trim();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
90
|
+
} catch { appVer = null; }
|
|
91
|
+
} else {
|
|
92
|
+
try {
|
|
93
|
+
appVer = JSON.parse(asar.extractFile(asarPath, 'package.json').toString('utf8')).version;
|
|
94
|
+
} catch { appVer = null; }
|
|
95
|
+
}
|
|
69
96
|
|
|
70
|
-
if (
|
|
71
|
-
ok(
|
|
97
|
+
if (appVer === pkg.version) {
|
|
98
|
+
ok(`打包产物版本 ${appVer} 与 package.json 一致`);
|
|
72
99
|
} else {
|
|
73
|
-
problems.push(
|
|
74
|
-
fail(
|
|
100
|
+
problems.push(`打包产物版本 ${appVer || '?'} ≠ package.json ${pkg.version} —— 产物是旧版,需要重新打包`);
|
|
101
|
+
fail(`打包产物版本 ${appVer || '?'} ≠ package.json ${pkg.version}`);
|
|
75
102
|
}
|
|
76
103
|
|
|
77
104
|
// ---- 3. 内容一致:asar 里的 src/** vs 磁盘 src/** --------------------------
|
|
78
105
|
// @electron/asar 的 extractFile 只接受 asar 内的相对路径,且对不存在的路径抛错;
|
|
79
106
|
// 用它既能比对内容,也能发现"asar 里少了某个新文件"。
|
|
80
|
-
|
|
107
|
+
// 路径用 path.join 拼(Windows 需要 `\`,POSIX 需要 `/`),两边都对。
|
|
81
108
|
|
|
82
109
|
function walk(dir, base = dir, out = []) {
|
|
83
110
|
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -117,15 +144,26 @@ if (!missing.length && !drifted.length) {
|
|
|
117
144
|
ok(`asar 内 src/** 与源码逐字节一致(${same} 个文件)`);
|
|
118
145
|
}
|
|
119
146
|
|
|
120
|
-
// ---- 4.
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
147
|
+
// ---- 4. 安装产物存在且版本正确 ---------------------------------------------
|
|
148
|
+
const artifact = platform === 'darwin'
|
|
149
|
+
? {
|
|
150
|
+
name: `AI-Browser-${pkg.version}-arm64.dmg`,
|
|
151
|
+
full: path.join(distDir, `AI-Browser-${pkg.version}-arm64.dmg`),
|
|
152
|
+
label: 'dmg',
|
|
153
|
+
}
|
|
154
|
+
: platform === 'win32'
|
|
155
|
+
? {
|
|
156
|
+
name: `AI-Browser-${pkg.version}-win32-x64-Setup.exe`,
|
|
157
|
+
full: path.join(distDir, 'installer', `AI-Browser-${pkg.version}-win32-x64-Setup.exe`),
|
|
158
|
+
label: '安装器',
|
|
159
|
+
}
|
|
160
|
+
: null;
|
|
161
|
+
if (artifact && fs.existsSync(artifact.full)) {
|
|
162
|
+
const mb = (fs.statSync(artifact.full).size / 1024 / 1024).toFixed(1);
|
|
163
|
+
ok(`${artifact.label}就绪:${artifact.name}(${mb} MB)`);
|
|
164
|
+
} else if (artifact) {
|
|
165
|
+
problems.push(`${path.relative(ROOT, artifact.full)} 不存在`);
|
|
166
|
+
fail(`缺 ${artifact.name}`);
|
|
129
167
|
}
|
|
130
168
|
|
|
131
169
|
// ---- 结论 -----------------------------------------------------------------
|
|
@@ -134,7 +172,8 @@ if (problems.length) {
|
|
|
134
172
|
fail(`打包产物与源码不同步(${problems.length} 项)`);
|
|
135
173
|
if (!quiet) {
|
|
136
174
|
console.log(' 用户装上的是旧代码,任何"已修复"的说法都不成立。');
|
|
137
|
-
console.log(' 修复:node scripts/
|
|
175
|
+
console.log(' 修复:node scripts/build_win.cjs && node scripts/build_installer.cjs(Windows)');
|
|
176
|
+
console.log(' node scripts/build_dmg.cjs(macOS)');
|
|
138
177
|
}
|
|
139
178
|
process.exit(1);
|
|
140
179
|
}
|
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ai-browser
|
|
3
3
|
description: >-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
ai-browser —— 真实、可见、带登录态、跑 JS、人可随时接管的浏览器。
|
|
5
|
+
触发词:要打开网址、要操作网站。反过来——不打开网址(本地文件、命令、代码、纯写作、跑测试)就别用我。
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# ai-browser
|
|
9
9
|
|
|
10
|
+
> 任务根本不碰网页?直接回用户「这个不需要浏览器」,别硬用。
|
|
11
|
+
|
|
12
|
+
## 兄弟技能(并列,不在本文件里)
|
|
13
|
+
|
|
14
|
+
- 发文章(CSDN / 知乎 / 掘金 / 公众号)→ `content-publish` 技能
|
|
15
|
+
- 提取文章正文 → `read-webpage` 技能
|
|
16
|
+
- 抓请求 / 看登录后的接口 → `references/network.md`
|
|
17
|
+
|
|
10
18
|
## 两条路
|
|
11
19
|
|
|
12
|
-
工具在就 `browse_navigate {"url":"https://example.com"}
|
|
20
|
+
工具在就 `browse_navigate {"url":"https://example.com"}`;不在走 CLI(没这命令就加 `npx -y @glittering0717/ai-browser`):
|
|
13
21
|
|
|
14
22
|
```
|
|
15
|
-
ai-browser call ui.get_tree '{"subset":"interactive"}' #
|
|
23
|
+
ai-browser call ui.get_tree '{"subset":"interactive"}' # 读页面
|
|
16
24
|
ai-browser call ui.act '{"action":"click","target":"e:a-3"}' # 点它
|
|
17
25
|
```
|
|
18
26
|
|
|
19
|
-
没这个命令就加 `npx -y @glittering0717/ai-browser`,浏览器没开会自动拉起。
|
|
20
27
|
方法名 = 工具名把 `browse_` 换成 `ui.`(tabs 等例外)。
|
|
21
28
|
|
|
22
29
|
## 你的标签组
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
省略 `tab` 就打它;用户的页不会被碰也不会被顶掉。组有上限,满了先关再开。
|
|
26
|
-
看用户的页 / 人登录扫码 / 全程后台:`references/tabs.md`。
|
|
31
|
+
第一次动手给你一页**空白工作页**,归你的标签组;省略 `tab` 就打它,用户的页不会被碰。
|
|
27
32
|
|
|
28
33
|
## 点东西只认 id
|
|
29
34
|
|
|
@@ -46,13 +51,13 @@ ai-browser call ui.act '{"action":"click","target":"e:a-3"}' # 点它
|
|
|
46
51
|
|
|
47
52
|
## 需要人帮忙
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
登录扫码滑块支付:请人操作,好了再读树;没有 chat 工具,勿编密码。
|
|
50
55
|
|
|
51
56
|
## 按需深挖
|
|
52
57
|
|
|
53
|
-
- `references/tabs.md` —
|
|
54
|
-
- `references/cli.md` — CLI
|
|
55
|
-
- `references/troubleshooting.md` —
|
|
56
|
-
- `references/hard-pages.md` —
|
|
57
|
-
- `references/network.md` —
|
|
58
|
-
- `references/tasks.md` —
|
|
58
|
+
- `references/tabs.md` — 标签组 / 人接管
|
|
59
|
+
- `references/cli.md` — CLI 全量
|
|
60
|
+
- `references/troubleshooting.md` — 排查
|
|
61
|
+
- `references/hard-pages.md` — 难搞页面
|
|
62
|
+
- `references/network.md` — 抓请求 / 接口
|
|
63
|
+
- `references/tasks.md` — 发文章 / 读正文
|
|
@@ -1,21 +1,43 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 网络与接口(抓请求 / 取数据)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
抓包**从 tab 打开那一刻就开始**,不需要订阅、不需要写脚本,POST 请求体也在。
|
|
4
|
+
**登录后才看得到的接口正是它的用武之地** —— 浏览器的登录态就是请求的登录态。
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
## 什么时候该看网络,而不是看树
|
|
7
|
+
|
|
8
|
+
- 点了提交没反应,想知道到底发了什么、返回了什么
|
|
9
|
+
- 想知道某个列表页背后的 API(比解析 DOM 稳一个数量级)
|
|
10
|
+
- 排查 4xx / 5xx、怀疑"页面没数据"是接口没回
|
|
11
|
+
- 需要结构化数据,而 DOM 只是渲染后的残缺版本
|
|
12
|
+
|
|
13
|
+
## 标准四步
|
|
6
14
|
|
|
7
15
|
```
|
|
8
|
-
browse_network { operation:"
|
|
9
|
-
|
|
10
|
-
browse_network { operation:"
|
|
16
|
+
browse_network { operation:"clear" } # 1 先清,别混进旧请求
|
|
17
|
+
browse_act { action:"click", target:"e:button-7" } # 2 触发请求
|
|
18
|
+
browse_network { operation:"list", filters:{ method:["POST"] } } # 3 找到 id
|
|
19
|
+
browse_network { operation:"get", network_id:"<id>",
|
|
20
|
+
include:{ response_body:true, request_body:true } } # 4 取 headers 与 body
|
|
11
21
|
```
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
## 参数形态(按 op 分组,不是拍平的)
|
|
24
|
+
|
|
25
|
+
| op | 参数 |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `list` | `filters:{ method[], url_contains, status_min, status_max, resource_type[], state[], started_after, started_before, limit(默认 50 / 最多 200), before_seq }` |
|
|
28
|
+
| `get` | `network_id` + `include:{ request_headers, response_headers, request_body, response_body, sensitive_headers, body_limit }` + `body_offset:{ request, response }` |
|
|
29
|
+
| `clear` | 无需参数(只清当前 tab) |
|
|
30
|
+
| `configure` | `configure:{ enabled, capture_bodies:"none"|"api"|"all" }` |
|
|
31
|
+
|
|
32
|
+
## 关键事实(不按这个来会白等)
|
|
16
33
|
|
|
17
|
-
|
|
18
|
-
|
|
34
|
+
- 记录**只从现在起累积**;`clear` 只清当前 tab,tab 一关记录就没了,跨 tab 各自独立
|
|
35
|
+
- `response_body` 要请求**已完成**才有;`state:"pending"` 时先 `browse_wait` 或稍等再 `get`
|
|
36
|
+
- 敏感头(`cookie` / `authorization`)默认打码;要看真值需启动时 `AI_BROWSER_NETWORK_SENSITIVE=1`
|
|
37
|
+
- body 很大:先用 `filters` 收窄,再用 `include.body_limit` + `body_offset` 分页取
|
|
38
|
+
- 省内存可关抓包:`browse_network { operation:"configure", configure:{ enabled:false } }`
|
|
39
|
+
- `browse_evaluate` 替代不了它:evaluate 只看页面 JS 上下文,看不到网络层
|
|
40
|
+
- 页面自身 JS 报错(不是接口)看 `browse_errors`
|
|
19
41
|
|
|
20
42
|
## 从页面取结构化数据
|
|
21
43
|
|
|
@@ -24,7 +46,7 @@ browse_network { operation:"get", network_id:"<id>", include_response_body:true
|
|
|
24
46
|
1. **页面自己的数据模型**。很多 SPA 把数据挂在全局对象上:
|
|
25
47
|
`browse_evaluate { js: "JSON.stringify(window.__NUXT__?.data ?? null)" }`
|
|
26
48
|
拿到的是原始结构,比从 DOM 反推可靠一个数量级。
|
|
27
|
-
2. **背后的 API**。用 `browse_network`
|
|
49
|
+
2. **背后的 API**。用 `browse_network` 抓到接口,再在 `browse_evaluate` 里 `fetch` 同一接口
|
|
28
50
|
(注意带凭据:`credentials:'include'`)。
|
|
29
51
|
3. **语义树**。`browse_get_tree {subset:"interactive"}` 逐节点取 `label`/`value`。
|
|
30
52
|
适合表格、列表这类结构规整的页面。
|
|
@@ -39,6 +39,6 @@ browse_diff { operation:"diff", snapshot:"<基线>" } // verdict: changed |
|
|
|
39
39
|
|
|
40
40
|
这三类别在这里硬做,用对应的技能(它们带更细的校验步骤):
|
|
41
41
|
|
|
42
|
-
- 把文章发布到 CSDN / 知乎 / 掘金 → `content-publish`
|
|
43
|
-
- 读一篇文章的正文并总结 → `read-webpage`
|
|
44
|
-
-
|
|
42
|
+
- 把文章发布到 CSDN / 知乎 / 掘金 → `content-publish` 技能
|
|
43
|
+
- 读一篇文章的正文并总结 → `read-webpage` 技能
|
|
44
|
+
- 盯某个页面的请求 / 看登录后的接口 → `references/network.md`(本技能内,不用另找)
|