@glittering0717/ai-browser 2.5.5 → 2.5.6

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.
@@ -16,7 +16,8 @@ npx -y @glittering0717/ai-browser skill install
16
16
  | `read-webpage` | 读一篇文章正文并总结 |
17
17
  | `web-network-monitor` | 长时间盯某个页面的请求 |
18
18
 
19
- 不装技能也能用——20 个 `browse_*` 工具的 schema 本身自带说明。技能只是把"怎么组合"讲清楚。
19
+ 不装技能也能用——17 个工具的 schema 之外,MCP 初始化时还会给客户端一段 `instructions`
20
+ (我是谁、什么时候用我、最小循环)。技能只是把"怎么组合"讲得更细。
20
21
 
21
22
  ---
22
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glittering0717/ai-browser",
3
- "version": "2.5.5",
3
+ "version": "2.5.6",
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": {
package/scripts/skill.cjs CHANGED
@@ -42,19 +42,61 @@ function detectTargets() {
42
42
  }));
43
43
  }
44
44
 
45
+ // 标记文件里记的是"装它的那个包版本"。返回值语义必须分清:
46
+ // null = 这个目录没有标记(不是本工具装的,绝不碰)
47
+ // '' = 有标记但读不出/格式旧(当作需要重装,不要当成"已是最新")
48
+ function readMarker(dest) {
49
+ const marker = path.join(dest, MARKER);
50
+ if (!fs.existsSync(marker)) return null;
51
+ try {
52
+ const m = fs.readFileSync(marker, 'utf8').match(/ai-browser\s+(\S+)/);
53
+ return m ? m[1] : '';
54
+ } catch {
55
+ return '';
56
+ }
57
+ }
58
+
59
+ // 已装副本与当前包的版本差。为什么需要它(2026-11-25):
60
+ // install 只在有人手动跑的时候写盘,`npm i -g` / `npx` 升级都不会碰用户目录,
61
+ // 于是"包装到了 2.4.1、技能还停在 2.1.1"是**静默**发生的 —— 用户看到的现象是
62
+ // "模型还是照着旧说明乱来",而没有任何地方提示这件事。实测就有一台机器停在
63
+ // 2.1.1,缺 references/tabs.md 整节。
64
+ function drift() {
65
+ const out = [];
66
+ for (const t of detectTargets()) {
67
+ if (!t.exists) continue;
68
+ for (const s of t.installed) {
69
+ const v = readMarker(path.join(t.dir, s));
70
+ if (v !== pkg.version) out.push({ target: t.label, dir: t.dir, skill: s, from: v || '?' });
71
+ }
72
+ }
73
+ return out;
74
+ }
75
+
45
76
  function installOne(skill, targetDir) {
46
77
  const src = path.join(SKILLS_ROOT, skill);
47
78
  const dest = path.join(targetDir, skill);
48
- const marker = path.join(dest, MARKER);
49
79
 
50
- if (fs.existsSync(dest) && !fs.existsSync(marker)) {
80
+ const installedVersion = fs.existsSync(dest) ? readMarker(dest) : null;
81
+
82
+ // 没有标记 = 用户自己写的同名技能,跳过(这条永远优先)
83
+ if (fs.existsSync(dest) && installedVersion === null) {
51
84
  return { skill, status: 'skipped-user-owned' };
52
85
  }
86
+ // 同版本:不重复写盘。幂等让 install 可以随便跑,也让"是否需要升级"可判断。
87
+ if (installedVersion === pkg.version) {
88
+ return { skill, status: 'up-to-date' };
89
+ }
53
90
 
54
91
  fs.mkdirSync(targetDir, { recursive: true });
92
+ // 必须先删干净再拷:cpSync 只会覆盖同名文件,包里**已经删掉**的文件会一直
93
+ // 留在用户目录里。那样"升级成功"和"还是旧版"在文件系统上无法区分,
94
+ // 而且 agent 会继续读到已经作废的 reference。
95
+ if (fs.existsSync(dest)) fs.rmSync(dest, { recursive: true, force: true });
55
96
  fs.cpSync(src, dest, { recursive: true });
56
- fs.writeFileSync(marker, `ai-browser ${pkg.version}\n`, 'utf8');
57
- return { skill, status: 'installed' };
97
+ fs.writeFileSync(path.join(dest, MARKER), `ai-browser ${pkg.version}\n`, 'utf8');
98
+
99
+ return { skill, status: installedVersion ? 'upgraded' : 'installed', from: installedVersion || null };
58
100
  }
59
101
 
60
102
  function install({ dir, all }) {
@@ -77,18 +119,31 @@ function install({ dir, all }) {
77
119
  }
78
120
 
79
121
  let failed = 0;
122
+ let changed = 0;
80
123
  for (const t of dirs) {
81
124
  console.log(`\n→ ${t.label} (${t.dir})`);
82
125
  for (const s of skills) {
83
126
  const r = installOne(s, t.dir);
84
- const note =
85
- r.status === 'installed'
86
- ? `✓ ${s}`
87
- : `! ${s} —— 这个目录已有同名技能且不是本工具装的,跳过(要覆盖请先手动删掉)`;
127
+ let note;
128
+ if (r.status === 'installed') {
129
+ note = `✓ ${s}`;
130
+ changed++;
131
+ } else if (r.status === 'upgraded') {
132
+ note = `↑ ${s} ${r.from} → ${pkg.version}`;
133
+ changed++;
134
+ } else if (r.status === 'up-to-date') {
135
+ note = `· ${s} 已是最新(${pkg.version})`;
136
+ } else {
137
+ note = `! ${s} —— 这个目录已有同名技能且不是本工具装的,跳过(要覆盖请先手动删掉)`;
138
+ }
88
139
  console.log(' ' + note);
89
140
  }
90
141
  }
91
- console.log(`\n装了 ${skills.length} 个技能。新开会话时客户端会自动发现它们,不需要再贴说明书。`);
142
+ if (changed) {
143
+ console.log(`\n更新了 ${changed} 个技能(共 ${skills.length} 个 × ${dirs.length} 个位置)。新开会话时客户端会自动发现它们。`);
144
+ } else {
145
+ console.log('\n全部已是最新,没有写盘。');
146
+ }
92
147
  return failed;
93
148
  }
94
149
 
@@ -113,6 +168,13 @@ function run(argv) {
113
168
  const state = !t.exists ? '目录不存在' : t.installed.length ? `已装 ${t.installed.length} 个` : '未装';
114
169
  console.log(` ${t.label.padEnd(12)} ${state.padEnd(12)} ${t.dir}`);
115
170
  }
171
+ // 版本漂移必须在人主动查看时就能看见,而不是等 agent 用旧技能出错。
172
+ const stale = drift();
173
+ if (stale.length) {
174
+ console.log(`\n! ${stale.length} 个副本是旧版(当前包 ${pkg.version}):`);
175
+ for (const d of stale) console.log(` ${d.target}/${d.skill} ${d.from} → ${pkg.version}`);
176
+ console.log(' 运行 `ai-browser skill install` 刷新。');
177
+ }
116
178
  console.log('\n装上:ai-browser skill install 只装到已存在的客户端目录');
117
179
  console.log(' ai-browser skill install --all 三个位置都装');
118
180
  console.log(' ai-browser skill print 打印入口 SKILL.md(手动粘贴用)');
@@ -130,4 +192,13 @@ function run(argv) {
130
192
  return 2;
131
193
  }
132
194
 
133
- module.exports = { run, listSkills, detectTargets, SKILLS_ROOT };
195
+ module.exports = {
196
+ run,
197
+ listSkills,
198
+ detectTargets,
199
+ drift,
200
+ readMarker,
201
+ installOne,
202
+ SKILLS_ROOT,
203
+ MARKER,
204
+ };
@@ -0,0 +1,37 @@
1
+ // main/mcp_instructions.js — MCP 初始化时交给客户端的那段自我介绍。
2
+ //
3
+ // 为什么单独成文件(2026-11-25):
4
+ //
5
+ // MCP 的 InitializeResult 有一个 `instructions` 字段,客户端会把它拼进 system
6
+ // prompt —— 这是**协议里唯一**能让服务端主动说"我是什么、什么时候该用我"的地方。
7
+ // 此前它是空的,于是 agent 对这个 server 的全部认知只剩一份 17 个
8
+ // `browse_*` 工具清单:名字像通用动词,描述是写给人看的机制说明
9
+ // (data-ai-id、subset、milestone)。实测后果很直接 —— 用户说"用 ai-browser",
10
+ // 新会话里的 agent 不知道那是什么,得被点名 GitHub 仓库才肯去查。
11
+ //
12
+ // 判据不是"描述够不够详细",而是"只拿到工具清单的模型能不能判断该不该用"。
13
+ // 所以这段文字只回答四件事,不重复 schema 里的参数细节:
14
+ // 1. 它是什么(真窗口,不是无头/截图驱动)
15
+ // 2. 什么意图下必须用它,以及为什么要用它而不是别的浏览器工具
16
+ // 3. 最小循环,且把 success 只代表"发出去了"这条硬规矩放在这里
17
+ // 4. 需要人时的正确姿势
18
+ //
19
+ // 成本:这段文字每个会话注入一次(不是每轮),但仍要克制。预算见
20
+ // tests/test_mcp_instructions.js 的 MAX_CHARS,超了 CI 红。
21
+ //
22
+ // 为什么没有做成 MCP prompt / resource:tests/test_invariants.js 把
23
+ // "prompts/resources 三个 list 必须应答空集合"钉成了不变量(目录扫描器会把
24
+ // Method not found 记为健康检查失败),那是刻意保留的,不在这轮改动范围内。
25
+
26
+ export const MCP_INSTRUCTIONS = [
27
+ 'AI Browser is a real, visible browser that you drive on the user\'s behalf.',
28
+ 'Use it whenever a task involves a website: open a page, read what it says, click, fill a form, log in, publish, upload or download, or pull data that sits behind a login.',
29
+ '',
30
+ 'Prefer it over headless or screenshot-driven browser tools when the page needs JS to render, when a session is already logged in, or when the user should be able to watch and take over. The window is a normal app window: the user can click and type in it at any time.',
31
+ '',
32
+ 'Loop: browse_navigate {url} -> browse_get_tree {subset:"interactive"} -> browse_act {action, target:<id from the tree>}. Repeat. success:true means the action was dispatched, not that anything changed - use browse_diff when the outcome matters.',
33
+ '',
34
+ 'Never invent a target id or a password. For login, QR scan, captcha or payment, ask the user to do it in the window and continue once they confirm.',
35
+ '',
36
+ 'If these tools are not registered in this client, the same engine is reachable from a shell: `ai-browser call ui.get_tree \'{"subset":"interactive"}\'`.',
37
+ ].join('\n');
@@ -14,7 +14,9 @@ import { fileURLToPath } from 'node:url';
14
14
  // 启动逻辑与 CLI 共用一份(scripts/ensure_running.cjs)。曾经这里有一份私有实现,
15
15
  // 结果 MCP 能自动拉起浏览器、CLI 不能 —— 同一件事两个行为。
16
16
  import ensureMod from '../../scripts/ensure_running.cjs';
17
+ import skillMod from '../../scripts/skill.cjs';
17
18
  import { MCP_TOOLS } from './mcp_tools.js';
19
+ import { MCP_INSTRUCTIONS } from './mcp_instructions.js';
18
20
  import { actParams, networkParams } from './mcp_args.js';
19
21
  import { evaluateGuardError } from '../shared/guards.js';
20
22
  import { timeoutForTool } from '../shared/tool_timeout.js';
@@ -78,7 +80,12 @@ const server = new Server(
78
80
  // resources/prompts 声明为空能力:协议要求即使一个都没有也要正常应答这两个
79
81
  // list 请求(部分目录扫描器,如 Smithery,会把 "Method not found" 记为健康
80
82
  // 检查失败)。能力清单保留声明,客户端据此知道服务端支持该方法族。
81
- { capabilities: { tools: {}, resources: {}, prompts: {} } }
83
+ //
84
+ // instructions:客户端会把它拼进 system prompt,是协议里唯一能让服务端主动
85
+ // 说"我是什么、什么时候用我"的地方。此前这一位是空的,agent 只看到一份
86
+ // 名字像通用动词的工具清单 —— 用户说"用 ai-browser",新会话根本不知道那是
87
+ // 什么。内容与成本见 ./mcp_instructions.js。
88
+ { capabilities: { tools: {}, resources: {}, prompts: {} }, instructions: MCP_INSTRUCTIONS }
82
89
  );
83
90
 
84
91
  // Tool definitions — curated minimal MCP_TOOLS (see mcp_tools.js). Kept small
@@ -400,6 +407,24 @@ async function main() {
400
407
  // up on first use, inside wsClient's connection-retry loop (via ensureRunning).
401
408
  const listening = await checkPort(ELECTRON_PORT);
402
409
  if (!listening) console.error('[mcp] ai-browser not running — will auto-start on first browse_* call');
410
+
411
+ // 技能漂移提示:package upgrade 不会刷新用户目录里的技能副本,agent 会继续
412
+ // 照着旧说明操作(实测有机器停在 2.1.1 而包已 2.4.1,缺 tabs.md 整节)。
413
+ // 只提示、不自动写盘 —— 启动过程不该有副作用,也可能根本没有写权限。
414
+ try {
415
+ const stale = skillMod.drift();
416
+ if (stale.length) {
417
+ const s = stale[0];
418
+ console.error(
419
+ `[mcp] skills out of date (${s.target}/${s.skill} ${s.from} -> ${VERSION})` +
420
+ (stale.length > 1 ? ` and ${stale.length - 1} more` : '') +
421
+ ' — run `ai-browser skill install` to refresh'
422
+ );
423
+ }
424
+ } catch {
425
+ // 技能目录存在与否绝不能影响 MCP 启动
426
+ }
427
+
403
428
  const transport = new StdioServerTransport();
404
429
  await server.connect(transport);
405
430
  // stderr is for logging only; stdout is the MCP protocol
@@ -11,7 +11,7 @@ export const MCP_TOOLS = [
11
11
  {
12
12
  name: 'browse_navigate',
13
13
  title: 'Navigate tab',
14
- description: 'Navigate your tab to a URL. Returns at the requested milestone (default: DOM ready) — it does not wait for load, which SPAs often never fire.',
14
+ description: 'Use when the user wants to open a page or reach a URL in your tab, before reading or acting. Returns at the milestone (default: DOM ready), not load, which SPAs never fire.',
15
15
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
16
16
  inputSchema: {
17
17
  type: 'object',
@@ -26,7 +26,7 @@ export const MCP_TOOLS = [
26
26
  {
27
27
  name: 'browse_get_tree',
28
28
  title: 'Read semantic tree',
29
- description: 'Return the page semantic tree (roles, labels, actions, bounds). Root adds editors (primary) when 2+ editable.',
29
+ description: 'Use to read the page: every element as a node with role, label, id and its actions. This is how you see the screen and find click targets. subset:"interactive" saves tokens.',
30
30
  annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: true },
31
31
  inputSchema: {
32
32
  type: 'object',
@@ -42,7 +42,7 @@ export const MCP_TOOLS = [
42
42
  {
43
43
  name: 'browse_act',
44
44
  title: 'Act on element',
45
- description: 'Act on a data-ai-id element. type appends at caret, setContent replaces all. page_changed:false = dispatched but page unchanged (wrapper).',
45
+ description: 'Use to click, type, fill, select, upload or press keys — the act that does the work. target = an id from browse_get_tree, never visible text. type appends at caret; setContent replaces all.',
46
46
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
47
47
  inputSchema: {
48
48
  type: 'object',
@@ -172,7 +172,7 @@ export const MCP_TOOLS = [
172
172
  {
173
173
  name: 'browse_auth_state',
174
174
  title: 'Check login / auth-wall state',
175
- description: 'Is this tab still logged in, or bounced to a login wall? auth_wall.detected=true means stop debugging and re-authenticate first. logged_in is heuristic; auth_wall is the signal to trust.',
175
+ description: 'Is this tab still logged in, or bounced to a wall? auth_wall.detected=true means stop debugging and re-authenticate first. logged_in is heuristic; auth_wall is the signal.',
176
176
  annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: true },
177
177
  inputSchema: {
178
178
  type: 'object',
@@ -184,7 +184,7 @@ export const MCP_TOOLS = [
184
184
  {
185
185
  name: 'browse_screenshot',
186
186
  title: 'Screenshot the viewport',
187
- description: 'Screenshot the viewport (base64). Use FIRST when an action misbehaves: the tree cannot show overlays, canvas, occlusion or glitches. Warns about visible password inputs.',
187
+ description: 'Screenshot the viewport (base64). Use FIRST when an action misbehaves — the tree cannot show overlays, occlusion or glitches. Warns about password inputs.',
188
188
  annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: true },
189
189
  inputSchema: {
190
190
  type: 'object',
@@ -235,7 +235,7 @@ export const MCP_TOOLS = [
235
235
  {
236
236
  name: 'browse_network',
237
237
  title: 'Inspect network',
238
- description: 'Query captured HTTP requests: list/get/clear/configure. Captures headers and POST bodies; sensitive headers redacted. Each op reads its own group: filters / include / body_offset / configure.',
238
+ description: 'Query captured HTTP requests: list/get/clear/configure. Headers and POST bodies captured; sensitive headers redacted. Each op reads its own group.',
239
239
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
240
240
  inputSchema: {
241
241
  type: 'object',
@@ -294,7 +294,7 @@ export const MCP_TOOLS = [
294
294
  {
295
295
  name: 'browse_canvas',
296
296
  title: 'Read canvas',
297
- description: 'Read <canvas> via captured draw calls (not pixels): list, read texts/regions, configure, or capture a PNG fallback. 2D text comes from fillText, so no OCR; WebGL is opaque.',
297
+ description: 'Read <canvas> from captured draw calls, not pixels: list/read/configure/capture. 2D text comes from fillText, so no OCR; WebGL is opaque.',
298
298
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
299
299
  inputSchema: {
300
300
  type: 'object',
@@ -333,7 +333,7 @@ export const MCP_TOOLS = [
333
333
  {
334
334
  name: 'browse_capabilities',
335
335
  title: 'Probe capabilities',
336
- description: 'Probe how to operate a page: DOM vs canvas, iframes, app objects on window, JSON endpoints, plus a plan. deep=true also probes closure-hidden models (canvas editors that report none).',
336
+ description: 'Probe how to operate a page: DOM vs canvas, iframes, window objects, JSON endpoints, plus a plan. deep=true also probes closure-hidden models.',
337
337
  annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: true },
338
338
  inputSchema: {
339
339
  type: 'object',
@@ -360,7 +360,7 @@ export const MCP_TOOLS = [
360
360
  {
361
361
  name: 'browse_downloads',
362
362
  title: 'List downloads',
363
- description: 'List a tab\'s downloads with on-disk paths. Downloads are async: poll this after clicking export/download instead of expecting the path in the click response.',
363
+ description: 'List a tab\'s downloads with on-disk paths. Downloads are async: poll this after clicking export, not in the click response.',
364
364
  annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
365
365
  inputSchema: {
366
366
  type: 'object',
@@ -372,7 +372,7 @@ export const MCP_TOOLS = [
372
372
  {
373
373
  name: 'browse_errors',
374
374
  title: 'Read error log',
375
- description: 'Read the main-process error log: uncaught exceptions, crashes, failed navigations, RPC errors. Each entry includes recent calls as context. Returns the on-disk JSONL path.',
375
+ description: 'Read the main-process error log: uncaught exceptions, crashes, failed navigations, RPC errors. Returns the on-disk JSONL path.',
376
376
  annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
377
377
  inputSchema: {
378
378
  type: 'object',
@@ -2,4 +2,4 @@
2
2
  // Kept in JS (not imported from package.json) to avoid Node import-attribute
3
3
  // (JSON module) compatibility issues inside Electron. package.json "version"
4
4
  // is manually synced to this value; tests assert they match.
5
- export const VERSION = '2.5.5';
5
+ export const VERSION = '2.5.6';