@glittering0717/ai-browser 2.5.7 → 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/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 +8 -0
- package/scripts/verify_asar.cjs +8 -2
- package/scripts/verify_build.cjs +71 -32
- 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/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/README.md
CHANGED
|
@@ -935,7 +935,7 @@ per `ui.get_tree`.
|
|
|
935
935
|
> measures every `frame-N` it can reach and **prints how many frames it could not** — an
|
|
936
936
|
> unmeasured area inside the denominator is worse than a wrong measurement. Re-measured
|
|
937
937
|
> 2026-10-19: Baidu 100%, CSDN 99% (8 cross-process frames now counted, 2 residual gaps),
|
|
938
|
-
> and the
|
|
938
|
+
> and the course page 82% with the 2 remaining gaps named explicitly. The write-up of this
|
|
939
939
|
> class of mistake — a metric that silently excludes the part that matters — is
|
|
940
940
|
> [`docs/POSTMORTEM_FRAME_VISIBILITY.md`](docs/POSTMORTEM_FRAME_VISIBILITY.md).
|
|
941
941
|
|
|
@@ -1133,7 +1133,7 @@ this browser carried, and every site paid for it while only canvas apps gained f
|
|
|
1133
1133
|
|
|
1134
1134
|
- per tab, on demand: `browse_canvas(operation: "configure", reload: true)` installs it and gives
|
|
1135
1135
|
the full history for that page;
|
|
1136
|
-
- for a whole origin: `AI_BROWSER_CANVAS_HOOK=
|
|
1136
|
+
- for a whole origin: `AI_BROWSER_CANVAS_HOOK=example.com,excalidraw.com` (comma-separated,
|
|
1137
1137
|
subdomains included);
|
|
1138
1138
|
- everywhere: `AI_BROWSER_CANVAS_HOOK=1` — what v2.4 and earlier did, and what risk controls
|
|
1139
1139
|
noticed.
|
|
@@ -1193,7 +1193,7 @@ the single source for `evaluate` limits, enforced identically on both transports
|
|
|
1193
1193
|
|---|---|
|
|
1194
1194
|
| Agents | Any MCP stdio client; alternatively raw WS from any language |
|
|
1195
1195
|
| Node | ≥ 18 |
|
|
1196
|
-
| OS | **macOS** and **Linux** —
|
|
1196
|
+
| OS | **macOS (arm64)**, **Windows (x64)** and **Linux** — all three run. macOS and Windows ship packaged installers; Linux installs from npm (no package yet). The e2e suite is developed on macOS and Linux, and the Windows build has been through a real install/uninstall cycle plus the same e2e suite on Windows 10 x64. CI runs unit tests on macOS only, so a given release is not automatically re-checked on Windows — report what breaks and it gets a real-machine repro. |
|
|
1197
1197
|
| Page frameworks | React / Vue / Angular / vanilla DOM — element locating is DOM-based, not framework-based |
|
|
1198
1198
|
| Editors | Rich editors driven through trusted input rather than per-framework code paths |
|
|
1199
1199
|
| Page types | Static and SPA; dynamic updates observable via the tree, `dom_change` / `state_changed` events |
|
package/llms-install.md
CHANGED
|
@@ -18,17 +18,20 @@ the same JSON-RPC and needs **no registration at all** — see "Fastest path" be
|
|
|
18
18
|
## Requirements
|
|
19
19
|
|
|
20
20
|
- Node.js **≥ 18**
|
|
21
|
-
- A desktop session (GUI app): macOS or
|
|
21
|
+
- A desktop session (GUI app): macOS, Linux, or Windows (x64). Windows has a packaged NSIS
|
|
22
|
+
installer (README "Option A2"); that packaged app has been installed, launched and uninstalled
|
|
23
|
+
on Windows 10 x64. Linux has no package — install from npm.
|
|
22
24
|
- ~110 MB download for the Electron engine (prepared on first launch / `npm install`, from GitHub
|
|
23
25
|
releases); it expands to ~245 MB on disk. Do not judge the install by the download size alone.
|
|
24
26
|
|
|
25
|
-
> **Installation priority.** The prebuilt macOS `.dmg` (README "Option A")
|
|
26
|
-
>
|
|
27
|
-
> and for
|
|
28
|
-
> stays necessary even when the packaged app is installed. The two
|
|
29
|
-
> is already running, the MCP server reuses it on port 9223 instead
|
|
30
|
-
> Electron. Source install is the fallback — only when no package fits,
|
|
31
|
-
> or the code itself needs changes; it pulls ~276 MB of dependencies plus
|
|
27
|
+
> **Installation priority.** The prebuilt macOS `.dmg` (README "Option A") and the Windows
|
|
28
|
+
> `Setup.exe` (README "Option A2") are the recommended installs for humans: one file, no Node.js,
|
|
29
|
+
> no dependency tree. On Linux — and for agents — use the npx path below; it is also how the MCP
|
|
30
|
+
> server gets registered, so it stays necessary even when the packaged app is installed. The two
|
|
31
|
+
> cooperate: if the packaged app is already running, the MCP server reuses it on port 9223 instead
|
|
32
|
+
> of downloading a second Electron. Source install is the fallback — only when no package fits,
|
|
33
|
+
> the package misbehaves, or the code itself needs changes; it pulls ~276 MB of dependencies plus
|
|
34
|
+
> the engine.
|
|
32
35
|
|
|
33
36
|
## Install
|
|
34
37
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glittering0717/ai-browser",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.9",
|
|
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": {
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"input_routing": "node e2e/input_routing_ws.cjs",
|
|
98
98
|
"background": "node e2e/background_ws.cjs",
|
|
99
99
|
"icon:check": "node scripts/check_icon.cjs",
|
|
100
|
-
"icons": "
|
|
100
|
+
"icons": "node scripts/render_icon.cjs",
|
|
101
101
|
"icon": "node e2e/icon_ws.cjs",
|
|
102
102
|
"security": "node e2e/security_ws.cjs",
|
|
103
103
|
"contract": "node e2e/contract_ws.cjs"
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
# 用法:bash scripts/marketing/data_snapshot.sh [备注]
|
|
4
4
|
# 输出:追加一行到 docs/marketing/DATA_LOG.md
|
|
5
5
|
set -u
|
|
6
|
-
|
|
6
|
+
# 从脚本位置推导仓库根(scripts/marketing/ → 上两级),换台机器也能跑。
|
|
7
|
+
REPO="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
7
8
|
LOG="$REPO/docs/marketing/DATA_LOG.md"
|
|
8
9
|
DATE=$(date +%Y-%m-%d)
|
|
9
10
|
TIME=$(date +%H:%M)
|
package/scripts/release.cjs
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// 打印"已完成的步骤 + 怎么补救",而不是假装整条链路都成功了。
|
|
19
19
|
'use strict';
|
|
20
20
|
|
|
21
|
-
const { execFileSync, spawnSync } = require('node:child_process');
|
|
21
|
+
const { execFileSync, spawnSync, spawn } = require('node:child_process');
|
|
22
22
|
const fs = require('node:fs');
|
|
23
23
|
const path = require('node:path');
|
|
24
24
|
|
|
@@ -41,6 +41,10 @@ const ok = (m) => console.log(`${c(32)}✓${c(0)} ${m}`);
|
|
|
41
41
|
const warn = (m) => console.log(`${c(33)}!${c(0)} ${m}`);
|
|
42
42
|
const fail = (m) => console.log(`${c(31)}✗${c(0)} ${m}`);
|
|
43
43
|
const step = (m) => console.log(`\n${c(36)}▸ ${m}${c(0)}`);
|
|
44
|
+
// 已完成步骤清单:最后摘要据此列出"这次漏了什么"。mark/done 必须在此定义,
|
|
45
|
+
// 否则第一次 mark() 就 ReferenceError(脚本会在写完版本号后直接崩,留下脏工作区)。
|
|
46
|
+
const done = [];
|
|
47
|
+
function mark(name) { done.push(name); }
|
|
44
48
|
|
|
45
49
|
function run(cmd, argv, opts = {}) {
|
|
46
50
|
const r = spawnSync(cmd, argv, { cwd: ROOT, encoding: 'utf8', ...opts });
|
|
@@ -60,8 +64,33 @@ function ghToken() {
|
|
|
60
64
|
catch { return ''; }
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
const
|
|
64
|
-
|
|
67
|
+
const sleepSync = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
68
|
+
|
|
69
|
+
// npm publish 返回 202 + exit 0 ≠ registry 立刻可读(实测约 105s)。
|
|
70
|
+
// MCP registry 在注册前会去 npm 校验"这个版本存不存在",看不见就 400/404 拒绝,
|
|
71
|
+
// 而 mcp-publisher 的错误信息只说"version not found",看起来像版本号写错。
|
|
72
|
+
// 所以真正该等的是 npm 的索引,不是隔着 mcp-publisher 盲重试。
|
|
73
|
+
//
|
|
74
|
+
// 判据用 registry 的 HTTP 状态(200 = 已索引),不用 `npm view`:
|
|
75
|
+
// 后者有本地缓存,曾在明明没同步时回报旧版本,会让人过早放弃等待。
|
|
76
|
+
function waitForNpmVersion(pkgName, version, maxMs = 300000) {
|
|
77
|
+
const url = `https://registry.npmjs.org/${pkgName.replace('/', '%2F')}/${version}`;
|
|
78
|
+
// curl -o /dev/null 在 Windows 上不认 /dev/null:用 NUL,否则每次探活都报错、白等。
|
|
79
|
+
const nullDevice = process.platform === 'win32' ? 'NUL' : '/dev/null';
|
|
80
|
+
const t0 = Date.now();
|
|
81
|
+
let wait = 2000;
|
|
82
|
+
for (;;) {
|
|
83
|
+
const r = spawnSync('curl', ['-sS', '-o', nullDevice, '-w', '%{http_code}', '--max-time', '10', url], { encoding: 'utf8' });
|
|
84
|
+
const code = (r.stdout || '').trim();
|
|
85
|
+
if (code === '200') return { ok: true, waited: Math.round((Date.now() - t0) / 1000) };
|
|
86
|
+
const left = maxMs - (Date.now() - t0);
|
|
87
|
+
if (left <= 0) return { ok: false, waited: Math.round((Date.now() - t0) / 1000), lastCode: code || 'no-response' };
|
|
88
|
+
const nap = Math.min(wait, left);
|
|
89
|
+
warn(`npm registry 还没索引到 v${version}(HTTP ${code || '无响应'}),${Math.round(nap / 1000)}s 后再查…`);
|
|
90
|
+
sleepSync(nap);
|
|
91
|
+
wait = Math.min(Math.round(wait * 1.6), 20000);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
65
94
|
|
|
66
95
|
// ---- 0. 前置检查 ----------------------------------------------------------
|
|
67
96
|
step('前置检查');
|
|
@@ -134,12 +163,17 @@ step(fullTests ? '全量测试' : '发版闸门测试');
|
|
|
134
163
|
const testFiles = fullTests
|
|
135
164
|
? []
|
|
136
165
|
: ['tests/test_version.js', 'tests/test_imports.js', 'tests/test_api_budget.js', 'tests/test_mcp_tools.js', 'tests/test_release_loop.js'];
|
|
166
|
+
// npm / npx 在 Windows 上是 .cmd 垫片,spawnSync 不带 shell 会 ENOENT
|
|
167
|
+
// (status 为 null,看起来像"测试失败")。shell 只在 Windows 打开,
|
|
168
|
+
// 其余平台保持直接 spawn,避免多一层引号解析。
|
|
169
|
+
const shellOpt = process.platform === 'win32' ? { shell: true } : {};
|
|
137
170
|
const t = spawnSync('npx', ['vitest', 'run', ...testFiles, '--no-file-parallelism'], {
|
|
138
|
-
cwd: ROOT, encoding: 'utf8',
|
|
171
|
+
cwd: ROOT, encoding: 'utf8', ...shellOpt,
|
|
139
172
|
});
|
|
140
173
|
if (t.status !== 0) {
|
|
141
174
|
fail('测试未通过,发版中止。版本号改动已写在工作区,可用 git checkout 撤销。');
|
|
142
|
-
|
|
175
|
+
if (t.error) console.log(` 启动失败:${t.error.message}`);
|
|
176
|
+
console.log((t.stdout || t.stderr || '').split('\n').slice(-25).join('\n'));
|
|
143
177
|
process.exit(1);
|
|
144
178
|
}
|
|
145
179
|
ok('测试通过');
|
|
@@ -173,7 +207,9 @@ mark('tag');
|
|
|
173
207
|
step('推送到 GitHub');
|
|
174
208
|
try {
|
|
175
209
|
git('push', 'origin', 'main');
|
|
176
|
-
git
|
|
210
|
+
// 本地没有 dev 分支时不推:`git push origin dev` 会因 refspec 不存在直接失败,
|
|
211
|
+
// 并把紧随其后的 tag 推送一起带进 catch —— 表现为"tag 明明在本地,远端却没有"。
|
|
212
|
+
if (gitOut('branch', '--list', 'dev')) git('push', 'origin', 'dev');
|
|
177
213
|
git('push', 'origin', `v${to}`);
|
|
178
214
|
ok('main / dev / tag 已推送');
|
|
179
215
|
mark('git push');
|
|
@@ -243,16 +279,39 @@ step('打包桌面 App');
|
|
|
243
279
|
// failed",且没有栈)。打包本身不联网、不碰沙箱,直接摘掉这个预加载。
|
|
244
280
|
const buildEnv = { ...process.env };
|
|
245
281
|
delete buildEnv.NODE_OPTIONS;
|
|
246
|
-
|
|
282
|
+
// 每个平台打自己的产物:macOS 出 dmg,Windows 出便携目录 + NSIS 安装器。
|
|
283
|
+
// Linux 暂未接入发版链路(build 脚本还不存在),显式说明而不是假装成功。
|
|
284
|
+
const build = (script) => spawnSync(process.execPath, [script], {
|
|
247
285
|
cwd: ROOT, encoding: 'utf8', env: buildEnv,
|
|
248
286
|
});
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
287
|
+
let assetPath = null; // 要挂到 GitHub Release 的那个文件
|
|
288
|
+
if (process.platform === 'darwin') {
|
|
289
|
+
const b = build('scripts/build_dmg.cjs');
|
|
290
|
+
if (b.status === 0) {
|
|
291
|
+
const line = (b.stdout || '').split('\n').filter((l) => /dmg:|size:/.test(l)).join(' ');
|
|
292
|
+
ok('打包完成:' + line.trim());
|
|
293
|
+
mark('打包');
|
|
294
|
+
} else {
|
|
295
|
+
fail('打包失败:' + (b.stdout || b.stderr || '').split('\n').filter(Boolean).slice(-4).join(' | '));
|
|
296
|
+
warn('补救:修好后执行 node scripts/build_dmg.cjs (npm 尚未发布,可继续发)');
|
|
297
|
+
}
|
|
298
|
+
const dmg = path.join(ROOT, 'dist', `AI-Browser-${to}-arm64.dmg`);
|
|
299
|
+
if (fs.existsSync(dmg)) assetPath = dmg;
|
|
300
|
+
} else if (process.platform === 'win32') {
|
|
301
|
+
const b = build('scripts/build_win.cjs');
|
|
302
|
+
const i = b.status === 0 ? build('scripts/build_installer.cjs') : { status: 1 };
|
|
303
|
+
if (b.status === 0 && i.status === 0) {
|
|
304
|
+
ok('打包完成:便携目录 + NSIS 安装器');
|
|
305
|
+
mark('打包');
|
|
306
|
+
} else {
|
|
307
|
+
fail('打包失败:' + `${(b.stdout || b.stderr || '')}\n${(i.stdout || i.stderr || '')}`
|
|
308
|
+
.split('\n').filter(Boolean).slice(-4).join(' | '));
|
|
309
|
+
warn('补救:修好后执行 node scripts/build_win.cjs && node scripts/build_installer.cjs');
|
|
310
|
+
}
|
|
311
|
+
const setup = path.join(ROOT, 'dist', 'installer', `AI-Browser-${to}-win32-x64-Setup.exe`);
|
|
312
|
+
if (fs.existsSync(setup)) assetPath = setup;
|
|
253
313
|
} else {
|
|
254
|
-
|
|
255
|
-
warn('补救:修好后执行 node scripts/build_dmg.cjs (npm 尚未发布,可继续发)');
|
|
314
|
+
warn(`未知平台 ${process.platform},跳过打包(发版链路目前只接了 macOS / Windows)`);
|
|
256
315
|
}
|
|
257
316
|
|
|
258
317
|
// 产物与源码逐字节比对 + 版本一致性。这一步就是"防止再出现 App 落后
|
|
@@ -269,31 +328,38 @@ step('打包桌面 App');
|
|
|
269
328
|
process.exit(1);
|
|
270
329
|
}
|
|
271
330
|
|
|
272
|
-
//
|
|
331
|
+
// 把产物挂到 Release 上 —— 否则 /releases 页面只有一段 changelog,用户还得
|
|
273
332
|
// 自己去找 App。上传放在校验之后:不一致的产物绝对不能对外发。
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
333
|
+
if (!assetPath) {
|
|
334
|
+
warn('没有可上传的产物,跳过 release asset');
|
|
335
|
+
} else if (!releaseOk) {
|
|
336
|
+
warn(`Release 未创建,跳过上传(产物在 ${path.relative(ROOT, assetPath)})`);
|
|
337
|
+
} else {
|
|
338
|
+
const up = spawnSync('gh', ['release', 'upload', `v${to}`, assetPath, '--clobber'], {
|
|
277
339
|
cwd: ROOT, encoding: 'utf8',
|
|
278
340
|
});
|
|
279
341
|
if (up.status === 0) {
|
|
280
|
-
ok(
|
|
342
|
+
ok(`${path.basename(assetPath)} 已挂到 Release(${(fs.statSync(assetPath).size / 1024 / 1024).toFixed(1)} MB)`);
|
|
281
343
|
mark('release asset');
|
|
282
344
|
} else {
|
|
283
|
-
fail('
|
|
284
|
-
warn(`补救:gh release upload v${to} ${
|
|
345
|
+
fail('产物上传失败:' + `${up.stdout || ''}${up.stderr || ''}`.trim().split('\n').slice(-2).join(' | '));
|
|
346
|
+
warn(`补救:gh release upload v${to} ${assetPath} --clobber`);
|
|
285
347
|
}
|
|
286
|
-
} else if (!fs.existsSync(dmg)) {
|
|
287
|
-
warn('dmg 不存在,跳过上传');
|
|
288
348
|
}
|
|
289
349
|
}
|
|
290
350
|
|
|
291
351
|
// ---- 6. npm ---------------------------------------------------------------
|
|
292
352
|
step('发布到 npm');
|
|
293
|
-
const
|
|
353
|
+
const PKG_NAME = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).name;
|
|
354
|
+
// npm 在 Windows 上是 .cmd 垫片,同样需要 shell(见发版闸门测试处的说明)。
|
|
355
|
+
const npm = spawnSync('npm', ['publish'], { cwd: ROOT, encoding: 'utf8', ...shellOpt });
|
|
294
356
|
if (npm.status === 0) {
|
|
295
357
|
ok(`@glittering0717/ai-browser@${to} 已发布`);
|
|
296
358
|
mark('npm publish');
|
|
359
|
+
// 在这里把传播延迟等完(见 waitForNpmVersion 注释),别让下一步去撞 404。
|
|
360
|
+
const w = waitForNpmVersion(PKG_NAME, to);
|
|
361
|
+
if (w.ok) ok(`npm registry 已索引 v${to}(等了 ${w.waited}s)`);
|
|
362
|
+
else warn(`npm registry ${w.waited}s 仍未见 v${to}(${w.lastCode}),下一步的 registry 注册可能失败`);
|
|
297
363
|
} else {
|
|
298
364
|
const out = `${npm.stdout || ''}${npm.stderr || ''}`;
|
|
299
365
|
// 三层认证失败的表现各不相同,逐条给可执行的下一步(2026-10-23 一天踩完):
|
|
@@ -318,76 +384,80 @@ if (npm.status === 0) {
|
|
|
318
384
|
|
|
319
385
|
// ---- 6. MCP registry ------------------------------------------------------
|
|
320
386
|
step('发布到 MCP registry');
|
|
321
|
-
|
|
322
|
-
|
|
387
|
+
// which 在 Windows 上不存在,用 where;候选名也补上 .exe,否则装了也判成"没装"。
|
|
388
|
+
const whichCmd = process.platform === 'win32' ? 'where' : 'which';
|
|
389
|
+
const publisher = ['mcp-publisher', 'mcp-publisher.exe', '/tmp/mcp-pub/mcp-publisher', '/opt/homebrew/bin/mcp-publisher']
|
|
390
|
+
.find((p) => { try { return fs.existsSync(p) || execFileSync(whichCmd, [p]).length > 0; } catch { return false; } });
|
|
323
391
|
if (!publisher) {
|
|
324
392
|
warn('未找到 mcp-publisher,跳过。安装:gh release download --repo modelcontextprotocol/registry \\');
|
|
325
393
|
console.log(' --pattern "mcp-publisher_darwin_arm64.tar.gz" && tar xzf ...');
|
|
326
394
|
} else {
|
|
395
|
+
const doPublish = () => spawnSync(publisher, ['publish'], { cwd: ROOT, encoding: 'utf8' });
|
|
396
|
+
const readOut = (r) => `${r.stdout || ''}${r.stderr || ''}`;
|
|
397
|
+
|
|
327
398
|
// registry 的登录态是一枚短期 JWT(几小时就过期)。过期表现是 401
|
|
328
399
|
// "token has invalid claims: token is expired" —— 不是"没登录",
|
|
329
|
-
// 所以 `login`
|
|
330
|
-
// MCP_GITHUB_TOKEN 让 login 走非交互路径(device flow 在无 TTY
|
|
331
|
-
|
|
332
|
-
let
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
400
|
+
// 所以 `login` 会直接成功、但没人会想到去重跑 publish。
|
|
401
|
+
// MCP_GITHUB_TOKEN 让 login 走非交互路径(device flow 在无 TTY 时静默卡住)。
|
|
402
|
+
// 整段只续一次:第二次还 401 说明是令牌本身无效,不是过期,多试无益。
|
|
403
|
+
let relogged = false;
|
|
404
|
+
const publishOnce = () => {
|
|
405
|
+
let r = doPublish();
|
|
406
|
+
let out = readOut(r);
|
|
407
|
+
if (r.status !== 0 && /expired|invalid or expired|status 401/i.test(out) && !relogged) {
|
|
408
|
+
relogged = true;
|
|
409
|
+
warn('registry 登录已过期,自动续期一次…');
|
|
410
|
+
const relogin = spawnSync(publisher, ['login', 'github'], {
|
|
411
|
+
cwd: ROOT,
|
|
412
|
+
encoding: 'utf8',
|
|
413
|
+
env: { ...process.env, MCP_GITHUB_TOKEN: ghToken() },
|
|
414
|
+
});
|
|
415
|
+
if (relogin.status === 0 && /logged in/i.test(readOut(relogin))) {
|
|
416
|
+
ok('已重新登录');
|
|
417
|
+
r = doPublish();
|
|
418
|
+
out = readOut(r);
|
|
419
|
+
} else {
|
|
420
|
+
warn('自动续期失败(需要 gh CLI 已登录):' + readOut(relogin).trim().split('\n').pop());
|
|
421
|
+
}
|
|
348
422
|
}
|
|
423
|
+
return { r, out };
|
|
424
|
+
};
|
|
425
|
+
const published = ({ r, out }) => r.status === 0 && /successfully published/i.test(out);
|
|
426
|
+
const notFound = ({ out }) => /was not found|status: 404/i.test(out);
|
|
427
|
+
|
|
428
|
+
let res = publishOnce();
|
|
429
|
+
|
|
430
|
+
// 404 = registry 去 npm 校验时仍看不到这个版本。上面 npm 段已经等到可见,
|
|
431
|
+
// 这里再最多补 3 轮,每轮先确认 npm 索引(避免在没同步时空转)。
|
|
432
|
+
for (let i = 1; i <= 3 && !published(res) && notFound(res); i++) {
|
|
433
|
+
warn(`mcp-publisher 仍看不到 v${to},第 ${i}/3 轮:先确认 npm 索引…`);
|
|
434
|
+
const w = waitForNpmVersion(PKG_NAME, to, 120000);
|
|
435
|
+
if (!w.ok) warn(`npm 索引侧仍未见 v${to}(${w.lastCode})`);
|
|
436
|
+
res = publishOnce();
|
|
349
437
|
}
|
|
350
|
-
|
|
438
|
+
|
|
439
|
+
if (published(res)) {
|
|
351
440
|
ok('MCP registry 已发布');
|
|
352
441
|
mark('mcp registry');
|
|
353
|
-
} else if (pub.status !== 0 && /was not found \(status: 404\)/i.test(pubOut)) {
|
|
354
|
-
// npm 刚发完,registry 的校验端还看不到新版本 —— 这是 npm CDN 的传播
|
|
355
|
-
// 延迟(实测 1-3 分钟),不是真的没发上去。连续两次发版都在这里被打断
|
|
356
|
-
// 叫回来手工重跑,所以直接自动等待重试。
|
|
357
|
-
let ok404 = false;
|
|
358
|
-
for (let i = 1; i <= 4; i++) {
|
|
359
|
-
warn(`registry 还没看到 npm 上的 v${to}(传播延迟),45s 后重试 ${i}/4…`);
|
|
360
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 45000);
|
|
361
|
-
pub = doPublish();
|
|
362
|
-
pubOut = `${pub.stdout || ''}${pub.stderr || ''}`;
|
|
363
|
-
if (pub.status === 0 && /successfully published/i.test(pubOut)) { ok404 = true; break; }
|
|
364
|
-
// 错误形态变了(不再是传播延迟)就交回统一处理,别空转
|
|
365
|
-
if (!/was not found \(status: 404\)/i.test(pubOut)) break;
|
|
366
|
-
}
|
|
367
|
-
if (ok404) { ok('MCP registry 已发布'); mark('mcp registry'); }
|
|
368
|
-
else {
|
|
369
|
-
const pkgName = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).name;
|
|
370
|
-
fail('MCP registry 发布失败:' + pubOut.split('\n').filter(Boolean).slice(-6).join(' | '));
|
|
371
|
-
warn(`补救:确认 npm 上有 ${to}(npm view ${pkgName} version)后执行 mcp-publisher publish`);
|
|
372
|
-
}
|
|
373
442
|
} else {
|
|
374
|
-
fail('MCP registry 发布失败:' +
|
|
375
|
-
if (/auth|login|token|unauthor/i.test(
|
|
443
|
+
fail('MCP registry 发布失败:' + res.out.split('\n').filter(Boolean).slice(-6).join(' | '));
|
|
444
|
+
if (/auth|login|token|unauthor/i.test(res.out)) {
|
|
376
445
|
warn('需要先登录一次:mcp-publisher login github(device flow,点一下浏览器)');
|
|
377
446
|
}
|
|
378
|
-
warn(
|
|
447
|
+
warn(
|
|
448
|
+
`补救:确认 npm 已索引(curl -s -o /dev/null -w '%{http_code}' ` +
|
|
449
|
+
`https://registry.npmjs.org/${PKG_NAME.replace('/', '%2F')}/${to})后执行 mcp-publisher publish`
|
|
450
|
+
);
|
|
379
451
|
}
|
|
380
452
|
}
|
|
381
453
|
|
|
382
|
-
// ---- 7.
|
|
454
|
+
// ---- 7. 装到本机(macOS: /Applications,Windows: %LOCALAPPDATA%)------------
|
|
383
455
|
// 这是"用户真正会打开的那个副本"。不做这一步,前面所有步骤再绿,桌面上
|
|
384
456
|
// 跑的可能还是几个版本前的包(2026-10-24 事故)。
|
|
385
|
-
step('
|
|
386
|
-
if (
|
|
387
|
-
warn('
|
|
388
|
-
} else if (
|
|
389
|
-
warn('--no-install:跳过安装,dist/ 里的 dmg 已就绪');
|
|
390
|
-
} else {
|
|
457
|
+
step('安装到本机');
|
|
458
|
+
if (args.includes('--no-install')) {
|
|
459
|
+
warn('--no-install:跳过安装,dist/ 里的产物已就绪');
|
|
460
|
+
} else if (process.platform === 'darwin') {
|
|
391
461
|
const ins = spawnSync(process.execPath, ['scripts/install_app.cjs'], {
|
|
392
462
|
cwd: ROOT, encoding: 'utf8',
|
|
393
463
|
});
|
|
@@ -399,17 +469,36 @@ if (process.platform !== 'darwin') {
|
|
|
399
469
|
fail('安装失败:' + insOut.split('\n').filter(Boolean).slice(-3).join(' | '));
|
|
400
470
|
warn('补救:node scripts/install_app.cjs 或手工拖 dist 里的 dmg');
|
|
401
471
|
}
|
|
472
|
+
} else if (process.platform === 'win32') {
|
|
473
|
+
const setup = path.join(ROOT, 'dist', 'installer', `AI-Browser-${to}-win32-x64-Setup.exe`);
|
|
474
|
+
if (!fs.existsSync(setup)) {
|
|
475
|
+
warn(`安装器不存在,跳过安装:${path.relative(ROOT, setup)}`);
|
|
476
|
+
} else {
|
|
477
|
+
// /S 静默覆盖安装,与用户双击安装同一套 NSIS 逻辑;用户数据在
|
|
478
|
+
// %APPDATA%\ai-browser,不动登录态。
|
|
479
|
+
const ins = spawnSync(setup, ['/S'], { cwd: ROOT, timeout: 180000 });
|
|
480
|
+
if (ins.status === 0) {
|
|
481
|
+
ok(`已安装:${path.join(process.env.LOCALAPPDATA || '%LOCALAPPDATA%', 'Programs', 'AI Browser')}`);
|
|
482
|
+
mark('安装');
|
|
483
|
+
} else {
|
|
484
|
+
fail(`安装失败(Setup.exe 退出码 ${ins.status})`);
|
|
485
|
+
warn(`补救:手工运行 ${setup}`);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
} else {
|
|
489
|
+
warn(`未知平台 ${process.platform},跳过安装`);
|
|
402
490
|
}
|
|
403
491
|
|
|
404
492
|
// ---- 8. 验收"装好的那个 App" ----------------------------------------------
|
|
405
493
|
// 前面每一步验的都是"仓库里的东西":测试跑 dev 树、verify_build 比 asar 里的
|
|
406
|
-
//
|
|
494
|
+
// 字节。但用户双击的是安装后的那个包,**没有人跑过它**。
|
|
407
495
|
// 2026-10-24 两次事故(App 落后 4 个版本 / 对话框修复只在 dev 生效)都出在这一层。
|
|
408
|
-
//
|
|
496
|
+
// macOS 用 e2e/shipped_ws.cjs 跑对话框与多标签关键路径;Windows 目前做启动 +
|
|
497
|
+
// WS 自检的冒烟(shipped_ws 依赖 .app 结构与 PlistBuddy,尚未跨平台)。
|
|
409
498
|
step('验收已安装的 App(在打包产物上跑,不是 dev 树)');
|
|
410
|
-
if (
|
|
411
|
-
warn('
|
|
412
|
-
} else {
|
|
499
|
+
if (args.includes('--no-install')) {
|
|
500
|
+
warn('--no-install:跳过产物验收');
|
|
501
|
+
} else if (process.platform === 'darwin') {
|
|
413
502
|
const vEnv = { ...process.env, AI_BROWSER_PORT: '9233' };
|
|
414
503
|
delete vEnv.ELECTRON_RUN_AS_NODE;
|
|
415
504
|
delete vEnv.NODE_OPTIONS;
|
|
@@ -426,6 +515,50 @@ if (process.platform !== 'darwin' || args.includes('--no-install')) {
|
|
|
426
515
|
console.log((vrOut.split('\n').filter((l) => /FAIL \||ERR|失败明细/.test(l)).slice(0, 12)).map((l) => ' ' + l).join('\n'));
|
|
427
516
|
warn('补救:npm run verify:app (默认验 /Applications/AI Browser.app,可用 AIB_APP= 指定)');
|
|
428
517
|
}
|
|
518
|
+
} else if (process.platform === 'win32') {
|
|
519
|
+
const exe = path.join(process.env.LOCALAPPDATA || '', 'Programs', 'AI Browser', 'AI Browser.exe');
|
|
520
|
+
if (!fs.existsSync(exe)) {
|
|
521
|
+
fail(`找不到已安装的 App:${exe}`);
|
|
522
|
+
warn(`补救:手工运行 dist/installer/AI-Browser-${to}-win32-x64-Setup.exe 后再验收`);
|
|
523
|
+
} else {
|
|
524
|
+
const smokePort = '9242';
|
|
525
|
+
const smokeEnv = {
|
|
526
|
+
...process.env,
|
|
527
|
+
AI_BROWSER_START_HIDDEN: '1',
|
|
528
|
+
AI_BROWSER_PORT: smokePort,
|
|
529
|
+
AI_BROWSER_USER_DATA: path.join(process.env.TEMP || '.', 'ai-browser-release-smoke'),
|
|
530
|
+
};
|
|
531
|
+
delete smokeEnv.ELECTRON_RUN_AS_NODE;
|
|
532
|
+
delete smokeEnv.NODE_OPTIONS;
|
|
533
|
+
const child = spawn(exe, [], { stdio: 'ignore', env: smokeEnv });
|
|
534
|
+
let info = null;
|
|
535
|
+
try {
|
|
536
|
+
for (let i = 0; i < 15 && !info; i++) {
|
|
537
|
+
sleepSync(1000);
|
|
538
|
+
// status 不会自动拉起浏览器(见 cli_call.cjs),探到的 pid 一定是上面那个子进程。
|
|
539
|
+
const r = spawnSync(process.execPath, ['bin/ai-browser.cjs', 'status', '--port', smokePort], {
|
|
540
|
+
cwd: ROOT, encoding: 'utf8', env: smokeEnv,
|
|
541
|
+
});
|
|
542
|
+
try {
|
|
543
|
+
const o = JSON.parse((r.stdout || '').trim());
|
|
544
|
+
if (o && o.running && o.pid) info = o;
|
|
545
|
+
} catch (_) { /* 还没起来 */ }
|
|
546
|
+
}
|
|
547
|
+
} finally {
|
|
548
|
+
spawnSync('taskkill', ['/PID', String(child.pid), '/T', '/F'], { encoding: 'utf8' });
|
|
549
|
+
// 进程刚被杀时 profile 可能还被句柄占用;清理失败不影响结论。
|
|
550
|
+
try { fs.rmSync(smokeEnv.AI_BROWSER_USER_DATA, { recursive: true, force: true }); } catch (_) {}
|
|
551
|
+
}
|
|
552
|
+
if (info) {
|
|
553
|
+
ok(`已安装的 App 启动并响应 WS(pid=${info.pid},${info.tabs ? info.tabs.length : 0} 个标签)`);
|
|
554
|
+
mark('产物验收');
|
|
555
|
+
} else {
|
|
556
|
+
fail('已安装的 App 启动后 15s 内 WS 无响应');
|
|
557
|
+
warn(`补救:手工启动 ${exe},检查是否闪退;或核对安装目录版本`);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
} else {
|
|
561
|
+
warn(`未知平台 ${process.platform},跳过产物验收`);
|
|
429
562
|
}
|
|
430
563
|
|
|
431
564
|
// ---- 摘要 -----------------------------------------------------------------
|