@glittering0717/ai-browser 2.2.0 → 2.3.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 CHANGED
@@ -398,6 +398,46 @@ the write-verification will honestly report `input not verified` rather than pre
398
398
  `npm run multiagent` drives two connections against one browser and asserts all of the above,
399
399
  including 10 interleaved actions with no cross-contamination.
400
400
 
401
+ ### Tab groups: every agent gets its own corner
402
+
403
+ Targets are per-connection, but tabs still shared one strip — you could not tell whose tab was whose,
404
+ and nothing stopped an agent from opening twenty of them. Both are fixed by **ownership**:
405
+
406
+ ```
407
+ group = 'human' | 'agent:<session>'
408
+ ```
409
+
410
+ An agent declares itself with `ui.hello` (the MCP server and the CLI both do it on connect). From then
411
+ on, the **first** call that touches a page and has no target yet gets a blank tab of its own, in its own
412
+ group, and a one-time hint in the result:
413
+
414
+ ```json
415
+ {"workspace": {"tab": 7, "group": "Claude", "created": true, "hint": "..."}}
416
+ ```
417
+
418
+ So an agent **never** defaults to the tab you are looking at. Reading your page is still possible and
419
+ still cheap — `browse_tabs {"op":"list"}`, find the entry with `group: "human"`, pass its `tab`
420
+ explicitly. Reading does not take it over.
421
+
422
+ In the tab strip your tabs stay as they were; each agent group collapses into a pill (its colour, name
423
+ and tab count), expands on hover, pins on click, and stays expanded while you are looking at one of its
424
+ tabs. Clicking a tab inside a group only changes what **you** see — it does not change the agent's target.
425
+
426
+ Each group is capped (8 by default, `AI_BROWSER_TAB_LIMIT`). Opening past the cap is **refused**, not
427
+ "quietly evicted", with the list of tabs you could close:
428
+
429
+ ```
430
+ -32001 your tab group is full (8/8) — close one before opening another
431
+ data: { reason: "group-full", limit: 8, tabs: [{tab, url}, ...] }
432
+ ```
433
+
434
+ Popups cannot be refused (the page's script is waiting for the window), so in that one case the least
435
+ recently used tab in the group — never the visible one, never one with a dialog open — is closed
436
+ instead, and reported in `browse_tabs {"op":"list"}` as `evicted`.
437
+
438
+ `npm run multiagent` (46 checks) covers it, M7–M9: auto workspace, the cap and its refusal payload,
439
+ and that one full group does not affect anybody else's.
440
+
401
441
  ---
402
442
 
403
443
  This is the part most easily misunderstood, so plainly: **the agent drives the browser, and the human
@@ -742,7 +782,7 @@ not bugs. The full write-up, including why the first measurement of this was wro
742
782
  ## Test & dev
743
783
 
744
784
  ```bash
745
- npm test # vitest — 988 tests across 70 files
785
+ npm test # vitest — 1024 tests across 73 files
746
786
  npm run smoke # Electron contract layer, offline fixture — 31 checks
747
787
  npm run capabilities # text fields, canvas, page source, network, DOM editing — 54 checks
748
788
  npm run richtext # rich-text editors, nested menus, forms, errors, tags, upload — 117 checks
@@ -752,7 +792,7 @@ npm run canvas # canvas draw-call capture — 13 checks
752
792
  npm run modeldiff # canvas app data-model diff (the "unchanged" false green) — 12 checks
753
793
  npm run audit # every advertised action must exist; wait/downloads/permissions/quit — 35 checks
754
794
  npm run nav # address bar + load-failure error page (the "white screen" report) — 19 checks
755
- npm run focus # no focus stealing + full capability while backgrounded — 32 checks
795
+ npm run focus # no focus stealing + full capability while backgrounded — 33 checks
756
796
  npm run interact # trusted drag / key press / wheel (pointer gestures) — 31 checks
757
797
  npm run view # viewport repaint budget + snapshot/diff verification — 29 checks
758
798
  npm run dialog # browser-level dialogs (native sheet blocks the renderer) — 15 checks
@@ -760,10 +800,10 @@ npm run wrapper # "in the tree but won't click" = matched a container, not
760
800
  npm run paint # blank-page self-check: verdicts, bounded ladder, no false alarms — 23 checks
761
801
  npm run layout # geometry invariants + "no twitching" (zero extra repaints on nav) — 25 checks
762
802
  npm run download # "clicked download": viewable media must display, the rest must save — 23 checks
763
- npm run multiagent # several agents at once: own tab each, no cross-talk, gone tab errors — 32 checks
803
+ npm run multiagent # several agents at once: own tab each, no cross-talk, gone tab errors — 46 checks
764
804
  npm run background # window hidden/minimized: every capability still works (headless-like) — 37 checks
765
805
  npm run flicker # frame-level: no frame may render the page shrunk (needs screen recording) — 6 checks
766
- npm run e2e:all # 一次跑完上面全部 22 个套件(每个独立端口)+ 可信汇总 — 728 checks
806
+ npm run e2e:all # 一次跑完上面全部 22 个套件(每个独立端口)+ 可信汇总 — 743 checks
767
807
  npm run verify:app # boot the packaged /Applications app and assert on it — 22 checks
768
808
  npm run realsites # navigate/read/act against a matrix of real sites
769
809
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glittering0717/ai-browser",
3
- "version": "2.2.0",
3
+ "version": "2.3.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": {
@@ -92,6 +92,15 @@ function rpcCall({ port, timeout, method, params }) {
92
92
  }, timeout);
93
93
 
94
94
  ws.on('open', () => {
95
+ // 自报家门,但**不要**自动工作区:CLI 是人坐在终端前敲的,"不传 tab
96
+ // 就打当前页"才是他期望的语义。auto_workspace:false 只关掉"自动开一页",
97
+ // 分组照旧 —— 它自己 new_tab 出来的页仍然归到 "Terminal" 组里。
98
+ try {
99
+ ws.send(JSON.stringify({
100
+ jsonrpc: '2.0', method: 'ui.hello',
101
+ params: { label: 'Terminal', auto_workspace: false },
102
+ }));
103
+ } catch (_) { /* 发不出去就退化成匿名连接 */ }
95
104
  ws.send(JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }));
96
105
  });
97
106
  ws.on('message', (data) => {
@@ -9,25 +9,25 @@ description: >-
9
9
 
10
10
  ## 两条路
11
11
 
12
- 工具在就 `browse_navigate {"url":"https://example.com"}`;**不在也不用配任何东西**,走 CLI(同一引擎):
12
+ 工具在就 `browse_navigate {"url":"https://example.com"}`。不在也不用配,走 CLI(同一引擎):
13
13
 
14
14
  ```
15
15
  ai-browser call ui.get_tree '{"subset":"interactive"}' # 读页面,拿 e:xxx
16
16
  ai-browser call ui.act '{"action":"click","target":"e:a-3"}' # 点它
17
17
  ```
18
18
 
19
- 没这个命令就加前缀 `npx -y @glittering0717/ai-browser`;浏览器没开会自动拉起。
19
+ 没这个命令就加 `npx -y @glittering0717/ai-browser`,浏览器没开会自动拉起。
20
+ 方法名 = 工具名把 `browse_` 换成 `ui.`(tabs 等例外)。
20
21
 
21
- CLI 方法 = 工具名去掉 `browse_` 换 `ui.`(`get_tree` `act` `navigate` … 一一对应)。
22
- 不一一对应的 4 个(tabs/network/canvas/diff)见 `references/cli.md`。
22
+ ## 你的标签组
23
23
 
24
- ## 多 agent / 后台
25
- 省略 `tab` = 操作你自己的页(`list` 里 `mine`);新页默认不抢用户视野(`show:true` 才显示)。
26
- `tabs {"op":"window","visible":false}` → 后台运行,能力不变;要人登录再打开。
24
+ 第一次动手会给你一页**空白工作页**,归在你自己的标签组;多 agent 各一组,互不相干。
25
+ 省略 `tab` 就打它;用户的页不会被碰也不会被顶掉。组有上限,满了先关再开。
26
+ 看用户的页 / 人登录扫码 / 全程后台:`references/tabs.md`。
27
27
 
28
28
  ## 点东西只认 id
29
29
 
30
- `act` 的 `target` 只接受 `get_tree` 给的 id(如 `e:a-3`);传页面文字会报 `target_not_found`。
30
+ `act` 的 `target` 只认 `get_tree` 给的 id;传文字会报 `target_not_found`。
31
31
 
32
32
  ## 操作后先看 effect_state
33
33
 
@@ -46,10 +46,11 @@ CLI 方法 = 工具名去掉 `browse_` 换 `ui.`(`get_tree` `act` `navigate`
46
46
 
47
47
  ## 需要人帮忙
48
48
 
49
- 登录/扫码/滑块/支付:请用户在窗口里操作,他说"好了"再重读树确认;不要编造密码。
49
+ 登录、扫码、滑块、支付:请用户在窗口里操作,说"好了"再重读树;不要编造密码。
50
50
 
51
51
  ## 按需深挖
52
52
 
53
+ - `references/tabs.md` — 标签组、上限、把页面交给人的正确姿势
53
54
  - `references/cli.md` — CLI 全部方法与参数对照
54
55
  - `references/troubleshooting.md` — 失败排查顺序
55
56
  - `references/hard-pages.md` — canvas / 富文本 / iframe / 上传
@@ -0,0 +1,66 @@
1
+ # 标签组:每个 agent 一块自己的空间
2
+
3
+ 浏览器里同时有两个人在干活:**用户**,和**每一个 agent**。他们的标签页不混在一起。
4
+
5
+ ## 你的工作页从哪来
6
+
7
+ 第一次真正动手(读树、导航、点击…)而还没指定过目标时,浏览器会给你开一页
8
+ **空白标签**并归到你自己的组里。回执里会出现一次:
9
+
10
+ ```json
11
+ {"workspace": {"tab": 7, "group": "Agent 2", "created": true, "hint": "..."}}
12
+ ```
13
+
14
+ 从那以后,**省略 `tab` 就等于打这一页**。这不是"当前显示的那一页" —— 用户切到哪
15
+ 都不会改变你的目标。
16
+
17
+ ## 三条容易踩的
18
+
19
+ | 情况 | 会发生什么 |
20
+ |---|---|
21
+ | 你显式传了 `tab` | 就按你点的来(不会因此把目标钉住;只有 `new` / `switch` 才会改默认目标) |
22
+ | 你的页被别人关了 | 下一次调用报 `-32001 ... is gone`,**不会**悄悄换到别人的页上。自己 `new` 一页继续 |
23
+ | 你想同时干两件事 | 开多个 tab,并发调用时各自带 `tab`。同一页上的并发写不做协调(值校验会如实报 `input not verified`) |
24
+
25
+ ## 上限
26
+
27
+ 每个组默认 **8 页**(`AI_BROWSER_TAB_LIMIT` 可调)。满了:
28
+
29
+ ```
30
+ -32001 your tab group is full (8/8) — close one before opening another
31
+ data.tabs = [{tab, url}, ...]
32
+ ```
33
+
34
+ 先把不用的关掉(`browse_tabs {"op":"close","tab":N}`)再开。上限存在的意义不是
35
+ 刁难:后台运行时没人看得见你的标签页,不设限就会一路开到内存告急。
36
+
37
+ 页面自己弹的窗口(`window.open` / `target=_blank`)不能拒绝 —— 站点的脚本在等它。
38
+ 那种情况下会顶掉本组里**最久没用、不在人眼前、也没有挂着对话框**的那一页,
39
+ 并在下一次 `browse_tabs {"op":"list"}` 的 `evicted` 里告诉你。
40
+
41
+ ## 把页面交给用户
42
+
43
+ 用户要用自己的眼睛/手介入时(登录、扫码、滑块、确认支付、看结果):
44
+
45
+ ```
46
+ browse_tabs {"op":"switch","tab":7,"show":true}
47
+ ```
48
+
49
+ `switch` 同时做两件事:把这一页顶到用户眼前,并把它设成你的默认目标。
50
+ 只想让用户**看**、不想改自己的目标,就不要用它 —— 用户自己点标签页就行。
51
+
52
+ 用户点开你那一页只是"看",**不会**抢走你的目标;你继续在上面操作,他看到的是
53
+ 实时画面。要避免"我正要输入他却盯着看"的尴尬,就提前说一句。
54
+
55
+ ## 关于"后台"
56
+
57
+ ```json
58
+ {"op": "window", "visible": false}
59
+ ```
60
+
61
+ 窗口隐藏后所有能力照旧:读树、点击、输入、滚动、上传、对话框、抓包、截图、白屏自检。
62
+ 单实例启动时也可以用 `AI_BROWSER_START_HIDDEN=1` 让窗口从头就不出现。
63
+ 用户点 Dock 图标随时叫回来,落在他上次看的那一页,你的任务不受影响。
64
+
65
+ ⚠️ 只有隐藏窗口**不等于**没人看:用户可能正盯着你那一页。别在页面上做会让人
66
+ 误解的连续操作(比如连续删除)。
@@ -44,8 +44,25 @@ const wsClient = createWsClient({
44
44
  url: WS_URL,
45
45
  timeout: WS_TIMEOUT,
46
46
  ensureRunning: () => ensureBrowser(),
47
+ // 自报家门:告诉浏览器"我是一个 agent",于是它会给我一块自己的标签组
48
+ // (默认目标永远是组里我自己的页,绝不开在人眼前那一页上)。
49
+ // 名字只用于标签栏上那个小圆点旁边的文字,猜不出来就留空让服务端编号。
50
+ hello: { label: agentLabel(), auto_workspace: true },
47
51
  });
48
52
 
53
+ /** 从环境推断是哪个客户端在驱动我。猜不出来就返回空串(服务端会编 "Agent N")。 */
54
+ function agentLabel() {
55
+ const env = process.env;
56
+ const explicit = String(env.AI_BROWSER_AGENT_NAME || '').trim();
57
+ if (explicit) return explicit.slice(0, 24);
58
+ if (env.CLAUDECODE || env.CLAUDE_CODE_ENTRYPOINT) return 'Claude';
59
+ if (env.CURSOR_TRACE_ID || env.CURSOR_AGENT) return 'Cursor';
60
+ if (env.TRAE_ENV || env.TRAE_AGENT) return 'Trae';
61
+ if (env.CODEX_HOME || env.OPENAI_CODEX) return 'Codex';
62
+ if (env.CLINE_ACTIVE) return 'Cline';
63
+ return '';
64
+ }
65
+
49
66
  /** 拉起浏览器(幂等)。失败时抛带原因的 Error,由 mcp_ws 并进最终错误信息。 */
50
67
  async function ensureBrowser() {
51
68
  const info = await ensureRunning({
@@ -210,7 +210,7 @@ export const MCP_TOOLS = [
210
210
  {
211
211
  name: 'browse_tabs',
212
212
  title: 'Tabs',
213
- description: 'Tabs: list/new/close/switch/window. switch = your default target (then omit tab). new never steals the user\'s view unless show:true. window = hide/show; work continues while hidden.',
213
+ description: 'Tabs: list/new/close/switch/window. Yours are grouped and capped (list: count/limit). Full → close one. switch = default target. new never steals the view unless show:true. window = hide/show.',
214
214
  // 合并前是 4 个工具(list / new / close / set_active),每个只承载一个动词。
215
215
  // 合并后 destructiveHint 只能是 false —— 否则 op=list 也会被标成破坏性操作;
216
216
  // close 的破坏性写在 description 里。这是合并的唯一语义代价,接受。
@@ -289,7 +289,7 @@ export const MCP_TOOLS = [
289
289
  {
290
290
  name: 'browse_canvas',
291
291
  title: 'Read canvas',
292
- description: 'Read <canvas> through captured draw calls (not pixels): list canvases, read texts/regions, configure, or capture a PNG fallback. 2D canvas text comes from fillText, so no OCR needed; WebGL is opaque.',
292
+ 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.',
293
293
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
294
294
  inputSchema: {
295
295
  type: 'object',
@@ -354,7 +354,7 @@ export const MCP_TOOLS = [
354
354
  {
355
355
  name: 'browse_downloads',
356
356
  title: 'List downloads',
357
- description: 'List downloads for a tab with their on-disk paths. Use after clicking an export/download button — downloads are asynchronous, so poll this rather than expecting the path in the click response.',
357
+ 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.',
358
358
  annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
359
359
  inputSchema: {
360
360
  type: 'object',
@@ -29,6 +29,11 @@ export function createWsClient({
29
29
  maxRetryDelay = 10000,
30
30
  ensureRunning = null, // Lazy launch hook: async; called on connection
31
31
  // failure so the server can spawn Electron on demand.
32
+ hello = null, // 连接建立后立刻发的自报家门(ui.hello 通知)。
33
+ // 为什么必须发:服务端只看得到一个 socket,分不清
34
+ // 对面是"一个 agent"还是"一段脚本"。而"要不要给你
35
+ // 自己的工作区/标签组"必须区分这两者 —— 脚本期望
36
+ // 老行为(不传 tab 就打当前页),agent 期望隔离。
32
37
  } = {}) {
33
38
  let _ws = null; // current OPEN socket (or null)
34
39
  let _connecting = null; // in-flight getWs() promise (dedupes concurrent callers)
@@ -97,6 +102,12 @@ export function createWsClient({
97
102
  if (open) {
98
103
  _ws = ws;
99
104
  attachPersistent(ws);
105
+ // 自报家门必须在**第一条 RPC 之前**发出去:TCP/WS 保序,服务端会先
106
+ // 处理它,于是第一条业务调用就已经带着身份(能拿到自己的标签组)。
107
+ if (hello) {
108
+ try { ws.send(JSON.stringify({ jsonrpc: '2.0', method: 'ui.hello', params: hello })); }
109
+ catch (_e) { /* 发不出去就退化成匿名连接,不影响调用 */ }
110
+ }
100
111
  return ws;
101
112
  }
102
113
 
@@ -42,6 +42,7 @@ import { MediaInline } from './media_inline.js';
42
42
  // 默认目标标签页的判据(explicit > session > active > first)与"新标签页要不要
43
43
  // 切到人眼前"的策略。见 shared/tab_route.cjs 顶部(多 agent 并用的三条事故)。
44
44
  import tabRoute, { shouldShowChildTab } from '../shared/tab_route.cjs';
45
+ import tabGroup from '../shared/tab_group.cjs';
45
46
  import { probeCapabilities } from './capability_probe.js';
46
47
  import valueContract from '../shared/value_contract.cjs';
47
48
  // 输入成功与否的判定口径(纯函数,独立模块便于单测)。详见文件内注释:
@@ -210,6 +211,17 @@ class PageManager {
210
211
  // 所有人的默认目标都变成它;B 说"点提交",点在 A 的页面上。判据与优先级见
211
212
  // shared/tab_route.cjs(explicit > session > active > first)。
212
213
  this._sessionTab = new Map();
214
+ // ---- 标签页归属(人的一组,每个 agent 一组)----
215
+ //
216
+ // 为什么需要它:会话级目标解决了"动作落在哪一页",但标签条上仍然是一锅粥 ——
217
+ // 人看不出哪些页是自己的、哪些是哪个 agent 的;也没有任何东西**约束** agent
218
+ // 开页面的数量,一个跑长任务的 agent 能悄悄开二十个,内存被无声吃掉。
219
+ // 归属同时承担三件事:标签栏怎么归拢、上限算谁的、人点开 agent 的页只是"看"。
220
+ this._tabGroup = new Map(); // tabId -> groupId
221
+ this._groups = new Map(); // groupId -> { id, kind, label, color, limit, createdAt }
222
+ this._tabUsedAt = new Map(); // tabId -> 最后一次被导航/动作的时间(LRU 淘汰用)
223
+ this._groupSeq = 0; // 组编号(Agent 1 / Agent 2 …)
224
+ this.evictions = []; // 被上限挤掉的标签页(最多 20 条,ui.list_tabs 回采后清空)
213
225
  this._openedTabs = new Map(); // sourceTabId -> { id, url } (new tab opened by window.open)
214
226
  this._windowOpenTokens = new Map(); // token -> { tabId, sourceTabId } (window.open shim, preload bridge.cjs)
215
227
  this._windowOpenShimTabs = new Set(); // 已注入 window.open 垫片的 tabId
@@ -502,6 +514,132 @@ class PageManager {
502
514
  * 把这个连接"自己的工作标签页"记下来。
503
515
  * 断开连接时**不关页面**:agent 进程退出后,人可能正想看看它干到哪了。
504
516
  */
517
+ // ---- 标签页归属 ----------------------------------------------------------
518
+ //
519
+ // 组 id 有两条来源:HUMAN_GROUP(人点「+」、启动页、人点链接派生出来的页)
520
+ // 和 groupIdForSession(sessionId)(一个 agent 连接一组)。
521
+ // 一个组没有标签页了就删掉 —— 否则标签栏会积一堆空的分组。
522
+
523
+ /** 建(或取)一个 agent 的组。label 是给人看的("Agent 2" / 客户端名)。 */
524
+ ensureGroup(sessionId, label, opts) {
525
+ const id = tabGroup.groupIdForSession(sessionId);
526
+ let g = this._groups.get(id);
527
+ if (!g) {
528
+ this._groupSeq += 1;
529
+ g = {
530
+ id,
531
+ kind: 'agent',
532
+ label: String(label || '').trim().slice(0, 24) || ('Agent ' + this._groupSeq),
533
+ // 颜色按组的诞生顺序取,不按 sessionId 哈希:人记的是"紫色的那个",
534
+ // 哈希出来每组都可能撞色。
535
+ color: tabGroup.colorFor(this._groupSeq - 1),
536
+ limit: tabGroup.limitFromEnv(process.env),
537
+ // capped = 这个组受限额约束。只有**声明过自己是 agent** 的连接才有
538
+ // (ui.hello);裸 WS(e2e / 脚本 / 调试)拿到组只是为了让标签页有归属,
539
+ // 不受限 —— 否则一次性开二十个标签的回归套件会突然报 group-full。
540
+ capped: false,
541
+ createdAt: Date.now(),
542
+ };
543
+ this._groups.set(id, g);
544
+ } else if (label) {
545
+ g.label = String(label).trim().slice(0, 24) || g.label;
546
+ }
547
+ if (opts && opts.capped === true) g.capped = true;
548
+ return g;
549
+ }
550
+
551
+ groupOfTab(tabId) {
552
+ return this._tabGroup.get(tabId) || tabGroup.HUMAN_GROUP;
553
+ }
554
+
555
+ groupMeta(groupId) {
556
+ const id = groupId || tabGroup.HUMAN_GROUP;
557
+ if (id === tabGroup.HUMAN_GROUP) {
558
+ return { id, kind: 'human', label: '我的标签页', color: null, limit: null };
559
+ }
560
+ return this._groups.get(id) || { id, kind: 'agent', label: id, color: null, limit: null };
561
+ }
562
+
563
+ /** 组里还有哪些页(按 tabId 升序 = 创建顺序)。 */
564
+ tabsInGroup(groupId) {
565
+ const out = [];
566
+ for (const [id] of this.tabs) {
567
+ if (this.groupOfTab(id) === groupId) {
568
+ out.push({
569
+ id,
570
+ url: this.tabs.get(id).webContents.getURL(),
571
+ usedAt: this._tabUsedAt.get(id) || 0,
572
+ dialog: this._openDialogs.has(id) ? true : undefined,
573
+ });
574
+ }
575
+ }
576
+ return out;
577
+ }
578
+
579
+ /** 这个组还能不能再开一页。 */
580
+ canOpenInGroup(groupId) {
581
+ const meta = this.groupMeta(groupId);
582
+ // 没被标记 capped 的组(裸 WS / 脚本拿到的组)不限量:组只是个归属标签。
583
+ if (meta.capped !== true) return { allowed: true, count: this.tabsInGroup(groupId).length, limit: null, remaining: null };
584
+ return tabGroup.decideOpen({
585
+ group: groupId,
586
+ count: this.tabsInGroup(groupId).length,
587
+ limit: meta.limit,
588
+ });
589
+ }
590
+
591
+ /** 组满时的牺牲品:最久没用、不在看、没有等人点的对话框。没有就返回 null。 */
592
+ pickEvictableInGroup(groupId, exceptTabId) {
593
+ const meta = this.groupMeta(groupId);
594
+ if (tabGroup.isHumanGroup(groupId)) return null;
595
+ if (meta.capped !== true) return null; // 不受限的组永远不需要牺牲谁
596
+ if (meta.limit && this.tabsInGroup(groupId).length < meta.limit) return null;
597
+ return tabGroup.pickEvictable({
598
+ tabs: this.tabsInGroup(groupId),
599
+ except: exceptTabId,
600
+ activeTab: this.activeTab,
601
+ });
602
+ }
603
+
604
+ /**
605
+ * 记录"这一页刚被用过",供 LRU 淘汰排序。
606
+ * 只在导航/动作这类**作用于页面**的地方调:读一次树不算用过,
607
+ * 否则 agent 循环读树会让真正在用的页被判定为"新",反而淘汰掉该留的。
608
+ */
609
+ touchTab(tabId) {
610
+ if (tabId === undefined || tabId === null) return;
611
+ this._tabUsedAt.set(tabId, Date.now());
612
+ }
613
+
614
+ /** 标签栏/接口用的分组清单(空组已在上面的清理里去掉,这里再滤一遍保险)。 */
615
+ listGroups() {
616
+ const out = [];
617
+ for (const [gid, meta] of this._groups) {
618
+ const tabs = this.tabsInGroup(gid);
619
+ if (!tabs.length) continue;
620
+ out.push({ ...meta, count: tabs.length });
621
+ }
622
+ out.sort((a, b) => a.createdAt - b.createdAt);
623
+ return out;
624
+ }
625
+
626
+ _forgetTab(tabId) {
627
+ const gid = this._tabGroup.get(tabId);
628
+ this._tabGroup.delete(tabId);
629
+ this._tabUsedAt.delete(tabId);
630
+ if (!gid || gid === tabGroup.HUMAN_GROUP) return;
631
+ // 组空了就删:留在 Map 里会让标签栏出现一个 0 页的分组,下次同名 agent
632
+ // 重连还会复用那个组的编号/颜色,看起来像"上一轮的残留"。
633
+ if (!this.tabsInGroup(gid).length) this._groups.delete(gid);
634
+ }
635
+
636
+ /** 把一页挪进某个组(人"接手" agent 的页 / 反向都走这条)。 */
637
+ moveToGroup(tabId, groupId) {
638
+ if (!this.tabs.has(tabId)) return false;
639
+ this._tabGroup.set(tabId, groupId || tabGroup.HUMAN_GROUP);
640
+ return true;
641
+ }
642
+
505
643
  bindSessionTab(sessionId, tabId) {
506
644
  if (!sessionId) return;
507
645
  if (tabId === undefined || tabId === null) this._sessionTab.delete(sessionId);
@@ -807,6 +945,7 @@ class PageManager {
807
945
  const tid = tabId !== undefined ? tabId : this.activeTab;
808
946
  const view = this._getView(tid);
809
947
  if (!view) return { ok: false, error: 'Tab not found' };
948
+ this.touchTab(tid);
810
949
  // 一旦有人在这一页上导航过,它就不再是"还没人动过的启动页"了 —— 新标签页
811
950
  // 也就不该再顶替它(否则 agent 每开一页都把上一页顶掉,等于一直抢视野)。
812
951
  this._spendStartupPrivilege();
@@ -1679,6 +1818,7 @@ class PageManager {
1679
1818
  async executeAction(action, target, params = {}, tabId) {
1680
1819
  const ms = actionDeadlineMs(action, params);
1681
1820
  const tid = tabId !== undefined ? tabId : this.activeTab;
1821
+ this.touchTab(tid);
1682
1822
  // 见 navigate 里的同一句:动过手的页面不再是"启动页"。
1683
1823
  this._spendStartupPrivilege();
1684
1824
  // 本次动作的起始时刻:用来判断"有没有对话框是在这一次动作里被应答的",
@@ -3505,6 +3645,10 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
3505
3645
  },
3506
3646
  });
3507
3647
  this.tabs.set(tabId, view);
3648
+ // 归属在最早的这一刻定下来:后面所有涉及"组"的判断(上限、标签栏、关闭
3649
+ // 后清理空组)都读这一条,晚设一步就会出现"页已经在了、但没人认领"的窗口期。
3650
+ this._tabGroup.set(tabId, opts.group || tabGroup.HUMAN_GROUP);
3651
+ this._tabUsedAt.set(tabId, Date.now());
3508
3652
  // 每个标签页、从出生起就关掉后台节流。以前只在 setActive 里设,于是"从没
3509
3653
  // 被显示过"的标签页永远带着节流:定时器被拉长到 1s、rAF 停摆,站点的轮询/
3510
3654
  // 动画/自动保存全部变慢,而 agent 看起来只是"这一页有点慢"。
@@ -3537,8 +3681,25 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
3537
3681
  // 派生标签页跟**打开它的那一个**走:可见页里弹出来的照旧弹到人眼前
3538
3682
  // (浏览器惯例),后台页里弹出来的留在后台 —— agent 流程里登录/预览/
3539
3683
  // 下载这类弹窗极多,每弹一个就抢一次视野等于人没法用电脑。
3684
+ //
3685
+ // 归属也跟打开者走:agent 的页弹出来的子页仍然属于那个 agent,否则它会
3686
+ // 悄悄跑到"人的标签页"里,下次人清理自己的标签就把 agent 的流程删了。
3687
+ const parentGroup = self.groupOfTab(tabId);
3688
+ // 弹窗把组撑满时不能拒绝(站点的脚本在等这个窗口),只能牺牲一页:
3689
+ // 最久没用、不在人眼前、没有挂着对话框的那个。
3690
+ if (!self.canOpenInGroup(parentGroup).allowed) {
3691
+ const victim = self.pickEvictableInGroup(parentGroup, tabId);
3692
+ if (victim !== null) {
3693
+ const deadUrl = (self._getView(victim) || {}).webContents
3694
+ ? self._getView(victim).webContents.getURL() : '';
3695
+ self.evictions.push({ tab: victim, url: deadUrl, at: Date.now(), reason: 'group-full' });
3696
+ if (self.evictions.length > 20) self.evictions.shift();
3697
+ self.closeTab(victim);
3698
+ }
3699
+ }
3540
3700
  const childId = self.newTab(urlToOpen, {
3541
3701
  show: shouldShowChildTab({ openerIsVisible: tabId === self.activeTab }),
3702
+ group: parentGroup,
3542
3703
  });
3543
3704
  // Track which source tab opened a new tab so `executeAction` can report the
3544
3705
  // resulting tab and auto-follow it. Generic (any target=_blank / window.open).
@@ -3600,6 +3761,8 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
3600
3761
  let signalReady = () => {};
3601
3762
  const ready = new Promise((resolve) => { signalReady = resolve; });
3602
3763
  this._windowOpenShimReady.set(tabId, ready);
3764
+ // 占位页地址:proceed 要用它判断"这一页还在不在等我"。
3765
+ const placeholderUrl = this._loadingPlaceholderUrl(targetUrl);
3603
3766
  let proceeded = false;
3604
3767
  const proceed = () => {
3605
3768
  if (proceeded) return;
@@ -3608,6 +3771,20 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
3608
3771
  // 失败也放行:宁可这个 tab 没有垫片,也不能把它卡在占位页。
3609
3772
  signalReady();
3610
3773
  if (targetUrl && wc0 && !wc0.isDestroyed()) {
3774
+ // ⚠️ 延迟到达的 proceed **绝不能覆盖已经发生的真实导航**。
3775
+ //
3776
+ // 实测(2026-10-28,npm run background 在 v2.2.0 上同样复现):
3777
+ // 垫片安装偶尔会挂十几秒,这期间 agent 已经把这一页导航走了;
3778
+ // 等它终于 resolve,下面这行 loadURL(启动页) 又把页面盖回去 ——
3779
+ // 表现是"打开的是目标页,下一刻自己跳回首页",读到的树也成了首页的。
3780
+ // 判据只看一句:现在还在占位页上吗?不在就什么都不做。
3781
+ // 判据要宽松:空 / about:blank 都还算"还没开始",只有**明确导航
3782
+ // 到别处**(另一个 http/file 地址)才放弃 —— 收紧成"必须等于占位页"
3783
+ // 会在占位页刚发起、getURL() 还返回 about:blank 的那一瞬误判,
3784
+ // 结果是新标签页永远停在占位页(wrapper 套件当场 red)。
3785
+ const cur = wc0.getURL();
3786
+ const stillMine = !cur || cur === 'about:blank' || cur === placeholderUrl;
3787
+ if (!stillMine) return;
3611
3788
  // 让"正在加载"可被观测:白屏最贵的地方不是慢,是慢得无法和
3612
3789
  // "开错了"区分(见 listTabs 的 state 字段)。
3613
3790
  this._tabNavState.set(tabId, 'loading');
@@ -3636,7 +3813,7 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
3636
3813
  // loading.html 只做展示(目标地址 + 转圈),不发请求不跳转,真实导航
3637
3814
  // 仍由上面的 proceed 发起。无目标 URL 的占位 tab(window.open("") 的
3638
3815
  // 老站模式)保持 about:blank:它本来就要停在这里等 location 赋值。
3639
- wc0.loadURL(this._loadingPlaceholderUrl(targetUrl)).catch(() => {});
3816
+ wc0.loadURL(placeholderUrl).catch(() => {});
3640
3817
  wc0.once('did-finish-load', () => { clearTimeout(guard); proceed(); });
3641
3818
  }
3642
3819
 
@@ -4353,6 +4530,7 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
4353
4530
  view.webContents.close();
4354
4531
  }
4355
4532
  this.tabs.delete(tabId);
4533
+ this._forgetTab(tabId);
4356
4534
  // window.open 垫片记账:这个 tab 若是某次 window.open 的目标,token 已
4357
4535
  // 失去意义(nav 到达也只会在上面打一行 warn),清掉防止 Map 无限增长。
4358
4536
  for (const [token, entry] of this._windowOpenTokens) {
@@ -4442,11 +4620,20 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
4442
4620
  listTabs() {
4443
4621
  const list = [];
4444
4622
  for (const [id, view] of this.tabs) {
4623
+ const gid = this.groupOfTab(id);
4624
+ const g = this.groupMeta(gid);
4445
4625
  list.push({
4446
4626
  id,
4447
4627
  url: view.webContents.getURL(),
4448
4628
  title: view.webContents.getTitle(),
4449
4629
  active: id === this.activeTab,
4630
+ // 归属:'human' = 人的页,'agent:<session>' = 某个 agent 的工作区。
4631
+ // agent 靠它判断"这一页是不是我的",人靠它在标签栏归拢。
4632
+ group: gid,
4633
+ group_label: g.label,
4634
+ ...(g.color ? { group_color: g.color } : {}),
4635
+ ...(g.capped === true && g.limit ? { group_limit: g.limit } : {}),
4636
+ ...(g.kind === 'agent' ? { group_kind: 'agent' } : {}),
4450
4637
  // 'pending' = 停在占位页等脚本注入(真实导航还没发起)
4451
4638
  // 'loading' = 真实导航已发起、还没完成 —— 这时候页面多半还是空的,
4452
4639
  // 是"正在打开"而不是"开错了",等它,不要重试
@@ -14,6 +14,7 @@ import { recordError, noteCall, recentErrors } from './error_log.js';
14
14
  // 默认目标标签页的判据(explicit > session > active > first),理由与两条不可
15
15
  // 退让的约束见 shared/tab_route.cjs 顶部(多 agent 并用时"目标被别人改掉")。
16
16
  import tabRoute from '../shared/tab_route.cjs';
17
+ import tabGroup from '../shared/tab_group.cjs';
17
18
 
18
19
  // Each startWSServer() owns a private WebSocketServer. Keeping it local (not a
19
20
  // module global) means multiple servers can coexist — required by tests that
@@ -56,6 +57,12 @@ const TABLESS_METHODS = new Set([
56
57
  'ui.window', 'ui.window_bounds', 'ui.window_shown', 'ui.quit',
57
58
  'ui.subscribe', 'ui.unsubscribe',
58
59
  ]);
60
+ // 这些方法本来就在"管理标签页",不能先替调用方开一个工作页再执行。
61
+ const TAB_OWN_METHODS = new Set([
62
+ 'ui.new_tab', 'ui.list_tabs', 'ui.close_tab', 'ui.set_active_tab',
63
+ 'ui.server_info', 'ui.errors', 'ui.window', 'ui.window_bounds',
64
+ 'ui.window_shown', 'ui.quit', 'ui.subscribe', 'ui.unsubscribe', 'ui.hello',
65
+ ]);
59
66
 
60
67
  export function startWSServer(pageManager, port = config.wsPort, onQuit = null) {
61
68
  // Bind loopback only — the protocol carries no auth. ws' default (host
@@ -78,6 +85,29 @@ export function startWSServer(pageManager, port = config.wsPort, onQuit = null)
78
85
  wss.on('connection', (ws, _req) => {
79
86
  const sessionId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
80
87
  const subscriptions = new Set();
88
+ // 连接的身份与工作区。isAgentConn 只有 ui.hello 才会置真 —— 裸 WS(e2e、
89
+ // 脚本、调试)保持老行为:不传 tab 就打当前页。
90
+ let clientName = null;
91
+ let isAgentConn = false;
92
+ // 声明自己是 agent 的连接默认获得自动工作区;CLI 这类"人就坐在终端前"的
93
+ // 入口显式关掉(auto_workspace:false),它想打当前页就是打当前页。
94
+ let autoWorkspace = true;
95
+ // 自报家门的两种写法都要认:MCP 发**通知**(无 id),有些客户端会发成
96
+ // 普通请求(带 id 等回执)。只认通知的话,带 id 的那种会掉进 switch 变成
97
+ // "Method not found",而调用方通常只看结果不看错误 —— 表现就是"自动工作区
98
+ // 有时生效有时不生效",这类半生效最难查。
99
+ const applyHello = (p) => {
100
+ const params = p || {};
101
+ clientName = String(params.label || params.client || '').trim().slice(0, 24) || null;
102
+ isAgentConn = true;
103
+ if (params.auto_workspace === false) autoWorkspace = false;
104
+ if (process.env.AI_BROWSER_AUTO_WORKSPACE === '0') autoWorkspace = false;
105
+ // capped:true —— 声明自己是 agent 才受"每组上限"约束(见 canOpenInGroup)。
106
+ if (typeof pageManager.ensureGroup === 'function') {
107
+ pageManager.ensureGroup(sessionId, clientName, { capped: true });
108
+ }
109
+ return { ok: true, agent: clientName || true, auto_workspace: autoWorkspace };
110
+ };
81
111
 
82
112
  pageManager.registerClient(sessionId, ws);
83
113
 
@@ -102,6 +132,15 @@ export function startWSServer(pageManager, port = config.wsPort, onQuit = null)
102
132
  events.forEach(ev => subscriptions.delete(ev));
103
133
  pageManager.removeSubscription(sessionId, events);
104
134
  }
135
+ // ui.hello:连接自报家门。MCP / CLI 在拿到 socket 后立刻发。
136
+ //
137
+ // 为什么需要它:WS 是纯 JSON-RPC,服务端只看到一个 socket,不知道对面
138
+ // 是"一个 agent"还是"某段脚本"。而"要不要给你一块自己的工作区"必须
139
+ // 区分这两种人 —— 脚本(e2e、调试)期望的是老行为:不传 tab 就打当前页。
140
+ // 所以只有**主动声明自己是 agent**的连接才自动获得工作区。
141
+ if (msg.method === 'ui.hello') {
142
+ applyHello(msg.params);
143
+ }
105
144
  return;
106
145
  }
107
146
 
@@ -136,8 +175,14 @@ export function startWSServer(pageManager, port = config.wsPort, onQuit = null)
136
175
  } catch (_) {
137
176
  routed = { tab: params.tab === undefined ? null : params.tab, source: 'unknown' };
138
177
  }
139
- const tabId = routed.tab;
178
+ let tabId = routed.tab;
179
+ // 本次回复要附带的一次性提示(只在本连接刚拿到工作区时出现一次)。
180
+ let workspaceNote = null;
140
181
  const send = (payload) => {
182
+ if (workspaceNote && payload && payload.result &&
183
+ typeof payload.result === 'object' && !Array.isArray(payload.result)) {
184
+ if (!payload.result.workspace) payload.result.workspace = workspaceNote;
185
+ }
141
186
  if (ws.readyState === 1) ws.send(JSON.stringify(payload));
142
187
  };
143
188
  // 会话标签页没了 → 必须在这一层拦住(否则会退回到别人的页面继续执行)。
@@ -153,6 +198,43 @@ export function startWSServer(pageManager, port = config.wsPort, onQuit = null)
153
198
  };
154
199
 
155
200
  const t0 = Date.now();
201
+ // ---- 自动工作区 ----------------------------------------------------
202
+ //
203
+ // agent 第一次要动页面、而它还没指定过任何目标时,给它一页**自己的**空标签,
204
+ // 归到它自己的组里。这是"agent 的操作与人的操作完全隔离"的地基:默认目标
205
+ // 再也不会落在人眼前那一页上(那是 v2.2.0 留下的最后一个口子 —— 会话没有
206
+ // 绑定时就 fallback 到 active,而 active 永远是人正在看的页)。
207
+ //
208
+ // 四条不触发,缺一不可:
209
+ // 1. 不是 agent(没发 ui.hello):裸 WS(e2e / 脚本 / 调试)保持老行为,
210
+ // 不传 tab 就打当前页 —— 否则所有回归和临时脚本都会突然对着一片空白。
211
+ // 2. 方法本身在管标签页(new_tab / list_tabs / window …):先开一页再列
212
+ // 标签页是荒谬的。
213
+ // 3. 调用方显式点了 tab,或本连接已经有绑定:那是明确意图,不许覆盖。
214
+ // 4. AI_BROWSER_AUTO_WORKSPACE=0:留着给"我就想让它打当前页"的场景。
215
+ if (isAgentConn && autoWorkspace && !TAB_OWN_METHODS.has(method) &&
216
+ (params.tab === undefined || params.tab === null) &&
217
+ typeof pageManager.newTab === 'function' &&
218
+ typeof pageManager.sessionTabOf === 'function' &&
219
+ pageManager.sessionTabOf(sessionId) === null) {
220
+ try {
221
+ const g = typeof pageManager.ensureGroup === 'function'
222
+ ? pageManager.ensureGroup(sessionId, clientName) : null;
223
+ const wid = pageManager.newTab(null, { show: false, group: g ? g.id : undefined });
224
+ pageManager.bindSessionTab(sessionId, wid);
225
+ tabId = wid;
226
+ // 这条提示只出现一次(本连接第一次动手),所以可以写得具体些:
227
+ // 它同时解释了"你拿到了一页空白"和"想看人的页面该怎么做"。
228
+ workspaceNote = {
229
+ tab: wid,
230
+ group: g ? g.label : null,
231
+ created: true,
232
+ hint: 'Your own blank tab. The user\'s visible page was left untouched and is NOT your target — navigate here. To just LOOK at the user\'s page: browse_tabs {op:"list"}, find the tab with group "human", pass its tab explicitly (reading does not take it over).',
233
+ };
234
+ } catch (_) {
235
+ // 建不出来就退回原目标:不能因为"想隔离"反而把这次调用打死。
236
+ }
237
+ }
156
238
  try {
157
239
  if (!TABLESS_METHODS.has(method) && routingError()) return;
158
240
  switch (method) {
@@ -345,10 +427,41 @@ export function startWSServer(pageManager, port = config.wsPort, onQuit = null)
345
427
  visibleIsStartup: pageManager.activeTab !== null &&
346
428
  pageManager.activeTab === pageManager.startupTab,
347
429
  });
348
- const newTabId = pageManager.newTab(params.url || null, { show });
430
+ // 归属:这一页算谁的。agent 开的页进它自己的组(上限按组算),
431
+ // 人点「+」开的页进 human 组(没有上限)。
432
+ const g = typeof pageManager.ensureGroup === 'function'
433
+ ? pageManager.ensureGroup(sessionId, clientName) : null;
434
+ const groupId = g ? g.id : undefined;
435
+ // 上限:**拒绝**而不是偷偷挤掉一页。挤掉是破坏性的(agent 可能正
436
+ // 在那一页上跑流程),而拒绝是一次必须做的决定 —— 这正是上限存在
437
+ // 的目的:逼 agent 把没用的页关掉,而不是无限开。
438
+ //
439
+ // 只对**声明过自己是 agent** 的连接生效:裸 WS(e2e / 脚本 / 调试)
440
+ // 不受限,否则那些一次性开二十个标签的回归套件会突然开始报 group-full。
441
+ const cap = (isAgentConn && g && typeof pageManager.canOpenInGroup === 'function')
442
+ ? pageManager.canOpenInGroup(groupId) : { allowed: true };
443
+ if (!cap.allowed) {
444
+ const open = typeof pageManager.tabsInGroup === 'function'
445
+ ? pageManager.tabsInGroup(groupId) : [];
446
+ send({
447
+ jsonrpc: '2.0', id,
448
+ error: {
449
+ code: -32001,
450
+ message: `your tab group is full (${cap.count}/${cap.limit}) — close one before opening another`,
451
+ data: {
452
+ reason: 'group-full',
453
+ group: g.label, limit: cap.limit, count: cap.count,
454
+ tabs: open.map((t) => ({ tab: t.id, url: t.url })),
455
+ hint: 'browse_tabs {op:"close", tab:<id>} on one you no longer need',
456
+ },
457
+ },
458
+ });
459
+ break;
460
+ }
461
+ const newTabId = pageManager.newTab(params.url || null, { show, group: groupId });
349
462
  // 新标签页立刻成为**这个连接的**工作目标(不影响别的连接、也不影响人)。
350
463
  if (typeof pageManager.bindSessionTab === 'function') pageManager.bindSessionTab(sessionId, newTabId);
351
- send({ jsonrpc: '2.0', id, result: { tab: newTabId, shown: show } });
464
+ send({ jsonrpc: '2.0', id, result: { tab: newTabId, shown: show, group: g ? g.label : null } });
352
465
  break;
353
466
  }
354
467
  case 'ui.close_tab': {
@@ -373,7 +486,27 @@ export function startWSServer(pageManager, port = config.wsPort, onQuit = null)
373
486
  if (mine !== null && mine !== undefined) {
374
487
  for (const t of tabs) if (t.id === mine) t.mine = true;
375
488
  }
376
- send({ jsonrpc: '2.0', id, result: { tabs } });
489
+ // groups:每组的页数与上限。agent 要能**事先**知道自己还有几个名额,
490
+ // 而不是撞到 group-full 才知道 —— 那时代码已经写到一半了。
491
+ const groups = typeof pageManager.listGroups === 'function' ? pageManager.listGroups() : [];
492
+ // evicted:被上限挤掉(只可能是页面自己弹窗撑爆的时候)的页,
493
+ // 回采一次就清空 —— 不说的话 agent 会以为那一页"自己消失了"。
494
+ const evicted = Array.isArray(pageManager.evictions) ? pageManager.evictions.splice(0) : [];
495
+ send({
496
+ jsonrpc: '2.0', id,
497
+ result: {
498
+ tabs,
499
+ ...(groups.length ? {
500
+ groups: groups.map((g) => ({
501
+ id: g.id, label: g.label, count: g.count,
502
+ // limit 只对受约束的组有意义;不限量的组别报一个假的 8
503
+ limit: g.capped === true ? g.limit : null,
504
+ ...(g.id === tabGroup.groupIdForSession(sessionId) ? { mine: true } : {}),
505
+ })),
506
+ } : {}),
507
+ ...(evicted.length ? { evicted } : {}),
508
+ },
509
+ });
377
510
  break;
378
511
  }
379
512
  // 窗口首次显示的时刻与当时页面状态。
@@ -437,6 +570,11 @@ export function startWSServer(pageManager, port = config.wsPort, onQuit = null)
437
570
  // ui.evaluate / ui.get_tree 却毫不知情:测的是别人的实例,结果毫无
438
571
  // 意义,而且不报错,只给出一堆莫名其妙的失败。
439
572
  // 有了 pid,调用方就能核对"是不是我 spawn 的那个进程"。
573
+ // 自报家门的"请求"写法(带 id):报完立刻回执,调用方好确认身份已生效。
574
+ case 'ui.hello': {
575
+ send({ jsonrpc: '2.0', id, result: applyHello(params) });
576
+ break;
577
+ }
440
578
  case 'ui.server_info': {
441
579
  send({
442
580
  jsonrpc: '2.0', id,
@@ -61,6 +61,34 @@
61
61
  #new-tab:hover { background: #2a2a2a; color: #fff; }
62
62
  .tab-id { color: #555; font-size: 10px; margin-right: 4px; flex: none; }
63
63
 
64
+ /* ---- agent 分组 ----
65
+ 一个 agent 的一组标签页折叠成一个 pill(带组色和页数),悬停展开。
66
+ 为什么不做成"竖着掉下来的下拉菜单":标签栏是一个固定高度(74px)的
67
+ BrowserView,往下弹会被自己裁掉;要能弹就得每次悬停都把标签栏长高、把页面
68
+ 往下推 —— 那正是本项目历史上闪烁/几何脱节的来源(见 SPEC 的渲染三宗罪)。
69
+ 就地展开没有这个代价:一行之内把这一组的标签摊开,鼠标移开自动收起。 */
70
+ .group-pill {
71
+ display: flex; align-items: center; gap: 6px; flex: none;
72
+ height: 36px; padding: 0 10px; cursor: pointer;
73
+ background: #232326; border-right: 1px solid #2a2a2a;
74
+ -webkit-app-region: no-drag; max-width: 190px;
75
+ }
76
+ .group-pill:hover { background: #2c2c30; }
77
+ .group-pill.open { background: #303036; }
78
+ .g-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
79
+ .g-label {
80
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
81
+ font-size: 11px; color: #9a9a9a; max-width: 110px;
82
+ }
83
+ .group-pill.open .g-label { color: #e8e8e8; }
84
+ .g-count {
85
+ font-size: 10px; color: #999; background: #333338;
86
+ border-radius: 8px; padding: 1px 5px; flex: none;
87
+ }
88
+ .g-count.full { color: #f0b46a; background: #3a2f1e; }
89
+ /* 组内的标签:左侧一条组色,一眼看出"这页是那个 agent 的" */
90
+ .tab.in-group { box-shadow: inset 3px 0 0 var(--g, #555); }
91
+
64
92
  /* ---- 第二行:工具栏(地址栏 + 导航按钮)---- */
65
93
  #toolbar {
66
94
  display: flex; align-items: center; gap: 6px;
@@ -119,6 +147,7 @@
119
147
  <span id="status"></span>
120
148
  </div>
121
149
 
150
+ <script src="tab_bar_layout.js"></script>
122
151
  <script>
123
152
  // ipcRenderer 在 Electron 主窗口里才有。直接用浏览器/测试页打开本文件时
124
153
  // require 会抛错——以前这会让整个 <script> 中断,连布局和滚动监听都不生效
@@ -178,8 +207,12 @@ function shortName(name) {
178
207
  return s.length > 18 ? s.slice(0, 12) + '…' + s.slice(-5) : s;
179
208
  }
180
209
 
181
- let lastIds = ''; // 上次渲染的 tab id 序列 —— 只有它变了才重建 DOM
210
+ let lastSig = ''; // 上次渲染的结构签名(标签 + 分组 + 展开态)
182
211
  let lastActiveId = null;
212
+ // 分组折叠状态(哪些组展开、哪些被钉住)。判据在 tab_bar_layout.js —— 纯函数,
213
+ // 由 tests/test_tab_bar_layout.js 钉住;这里只管画。
214
+ let layoutState = TabBarLayout.empty();
215
+ let currentActiveGroup = null;
183
216
 
184
217
  // 把指定 tab 滚进可视区(只在它确实在视区外时才动,避免无谓跳动)。
185
218
  // 用 getBoundingClientRect 而不是 offsetLeft:后者依赖 offsetParent,
@@ -192,41 +225,69 @@ function scrollTabIntoView(id) {
192
225
  else if (er.right > cr.right) tabsEl.scrollLeft += (er.right - cr.right) + 8;
193
226
  }
194
227
 
228
+ // 服务端会给每个组配色;万一没给(老版本),按组 id 哈希出一个稳定颜色,
229
+ // 至少保证同一组每次都是同一个色,而不是随机闪。
230
+ const FALLBACK_COLORS = ['#7c6cf0', '#3fb6a8', '#e0a33e', '#e06c75', '#5aa9e6', '#c678dd'];
231
+ function colorFor(id) {
232
+ if (!id) return '#666';
233
+ let h = 0;
234
+ for (let i = 0; i < id.length; i++) h = (h * 31 + id.charCodeAt(i)) >>> 0;
235
+ return FALLBACK_COLORS[h % FALLBACK_COLORS.length];
236
+ }
237
+
238
+ /** 造一个标签元素。inGroup 时左侧带一条组色,表示"这页属于某个 agent"。 */
239
+ function makeTabEl(tab, groupColor) {
240
+ const el = document.createElement('div');
241
+ el.className = 'tab' + (tab.active ? ' active' : '') + (groupColor ? ' in-group' : '');
242
+ el.dataset.id = tab.id;
243
+ if (groupColor) el.style.setProperty('--g', groupColor);
244
+ // 标题在 UI 上被截断到 30 字(标签宽度有限),完整标题 + 地址放 tooltip:
245
+ // 否则长标题站点的标签永远看不出是哪一篇("【第 12 章】…"全一样)。
246
+ el.title = tabTooltip(tab);
247
+ el.innerHTML = '<span class="tab-id">[' + tab.id + ']</span>' +
248
+ '<span class="tab-title">' + escapeHtml((tab.title || tab.url || 'New Tab').slice(0, 30)) + '</span>' +
249
+ '<span class="tab-close" data-id="' + tab.id + '">&times;</span>';
250
+ return el;
251
+ }
252
+
253
+ /** 一个折叠组:组色圆点 + 名字 + 页数(满额时数字变暖色,提示该关了)。 */
254
+ function makePillEl(item) {
255
+ const el = document.createElement('div');
256
+ el.className = 'group-pill' + (item.open ? ' open' : '');
257
+ el.dataset.group = item.id; // 存**组 id**:颜色表与展开状态都以 id 为键
258
+ el.title = 'agent 的标签组:' + item.label + '\n悬停展开,点击钉住(' +
259
+ item.count + '/' + (item.limit || '∞') + ')';
260
+ el.innerHTML = '<span class="g-dot" style="background:' + (item.color || colorFor(item.id)) + '"></span>' +
261
+ '<span class="g-label">' + escapeHtml(item.label) + '</span>' +
262
+ '<span class="g-count' + (item.limit && item.count >= item.limit ? ' full' : '') + '">' + item.count + '</span>';
263
+ return el;
264
+ }
265
+
195
266
  async function renderTabs() {
196
267
  try {
197
268
  const tabs = await invoke('tab:list');
198
- const ids = tabs.map(function (t) { return t.id; }).join(',');
269
+ const view = TabBarLayout.build(tabs, layoutState);
270
+ layoutState = view.state;
271
+ currentActiveGroup = view.activeGroup;
199
272
 
200
- if (ids !== lastIds) {
201
- // 结构变了(增/删 tab):重建 DOM,但必须保住横向滚动位置 ——
202
- // 否则在右端关掉一个标签后视图会跳回最左,后面的标签又摸不着了。
273
+ const sig = TabBarLayout.signature(tabs, view.state) + '#' + view.activeGroup;
274
+ if (sig !== lastSig) {
275
+ // 结构变了(增/删 tab、分组变化、展开态变化):重建 DOM,但必须保住
276
+ // 横向滚动位置 —— 否则在右端关掉一个标签后视图会跳回最左。
203
277
  const prevScroll = tabsEl.scrollLeft;
204
278
  tabsEl.innerHTML = '';
205
- for (const tab of tabs) {
206
- const el = document.createElement('div');
207
- el.className = 'tab' + (tab.active ? ' active' : '');
208
- el.dataset.id = tab.id;
209
- // 标题在 UI 上被截断到 30 字(标签宽度有限),完整标题 + 地址放 tooltip:
210
- // 否则长标题站点的标签永远看不出是哪一篇("【第 12 章】…"全一样)。
211
- el.title = tabTooltip(tab);
212
- el.innerHTML = '<span class="tab-id">[' + tab.id + ']</span>' +
213
- '<span class="tab-title">' + escapeHtml((tab.title || tab.url || 'New Tab').slice(0, 30)) + '</span>' +
214
- '<span class="tab-close" data-id="' + tab.id + '">&times;</span>';
215
- el.addEventListener('click', function (e) {
216
- // 从 this.dataset 取 id,不用闭包里的 tab —— 增量更新时闭包会过期。
217
- const id = parseInt(this.dataset.id);
218
- if (e.target.classList.contains('tab-close')) send('tab:close', id);
219
- else send('tab:activate', id);
220
- });
221
- tabsEl.appendChild(el);
279
+ for (const item of view.items) {
280
+ if (item.type === 'group') tabsEl.appendChild(makePillEl(item));
281
+ else tabsEl.appendChild(makeTabEl(item.tab, item.inGroup ? (item.color || colorFor(item.tab.group)) : null));
222
282
  }
223
- lastIds = ids;
283
+ lastSig = sig;
224
284
  tabsEl.scrollLeft = prevScroll;
225
285
  } else {
226
286
  // 结构没变:只改标题和激活态。绝不重建 —— 这里每 1.5s 就跑一次,
227
287
  // 一旦重建,用户刚滚到的位置就被重置,标签一多就永远滚不回去。
228
- for (let i = 0; i < tabs.length && i < tabsEl.children.length; i++) {
229
- const t = tabs[i], el = tabsEl.children[i];
288
+ for (const t of tabs) {
289
+ const el = tabsEl.querySelector('.tab[data-id="' + t.id + '"]');
290
+ if (!el) continue;
230
291
  el.classList.toggle('active', !!t.active);
231
292
  const titleEl = el.querySelector('.tab-title');
232
293
  const title = (t.title || t.url || 'New Tab').slice(0, 30);
@@ -245,6 +306,38 @@ async function renderTabs() {
245
306
  } catch (e) { /* ipcRenderer 尚未就绪 */ }
246
307
  }
247
308
 
309
+ // ---- 分组的交互(事件委托:标签是增量更新的,逐个挂监听重建后就会丢)----
310
+ tabsEl.addEventListener('click', function (e) {
311
+ const pill = e.target.closest ? e.target.closest('.group-pill') : null;
312
+ if (pill) {
313
+ layoutState = TabBarLayout.toggle(layoutState, pill.dataset.group);
314
+ renderTabs();
315
+ return;
316
+ }
317
+ const el = e.target.closest ? e.target.closest('.tab') : null;
318
+ if (!el || !el.dataset.id) return;
319
+ const id = parseInt(el.dataset.id);
320
+ if (e.target.classList.contains('tab-close')) send('tab:close', id);
321
+ else send('tab:activate', id);
322
+ });
323
+
324
+ tabsEl.addEventListener('mouseover', function (e) {
325
+ const pill = e.target.closest ? e.target.closest('.group-pill') : null;
326
+ if (!pill) return;
327
+ const g = pill.dataset.group;
328
+ if (layoutState.expanded.indexOf(g) >= 0) return; // 已展开:再重建会自己触发自己
329
+ layoutState = TabBarLayout.hover(layoutState, g);
330
+ renderTabs();
331
+ });
332
+
333
+ // 鼠标离开标签条:收起没被钉住、也不是"正在看的那一组"的组。
334
+ tabsEl.addEventListener('mouseleave', function () {
335
+ const next = TabBarLayout.leave(layoutState, currentActiveGroup);
336
+ if (next.expanded.join(',') === layoutState.expanded.join(',')) return;
337
+ layoutState = next;
338
+ renderTabs();
339
+ });
340
+
248
341
  // 横向滚动:鼠标滚轮是垂直的,标签栏要的是左右滚(浏览器惯例)。
249
342
  // overflow 改成 auto 只是"能滚",没有这一条仍然只能拖滚动条/用触控板横扫。
250
343
  tabsEl.addEventListener('wheel', function (e) {
@@ -0,0 +1,136 @@
1
+ // renderer/tab_bar_layout.js — 标签栏的分组布局(纯函数,无 DOM)。
2
+ //
3
+ // 为什么单独一个文件:把"哪些标签页属于哪个组、哪个组展开着、展开后长什么样"
4
+ // 从 DOM 里抽出来,才能在 vitest 里钉住行为(tests/test_tab_bar_layout.js)。
5
+ // 靠人肉把鼠标移上去验证一个折叠交互,等于没验证 —— 它挂了也只会在某个没人
6
+ // 注意的下午被发现。
7
+ //
8
+ // 两种加载方式:<script src> 挂到 window.TabBarLayout(标签栏),
9
+ // require() 拿到同一份对象(单测)。逻辑只有一处。
10
+ (function (root, factory) {
11
+ const api = factory();
12
+ if (typeof module === 'object' && module.exports) module.exports = api;
13
+ if (root) root.TabBarLayout = api;
14
+ })(typeof globalThis !== 'undefined' ? globalThis : this, function () {
15
+ const HUMAN = 'human';
16
+
17
+ /** 初始状态。用数组而不是 Set:状态要能比较、能打印、能断言。 */
18
+ function empty() {
19
+ return { expanded: [], pinned: [] };
20
+ }
21
+
22
+ function norm(s) {
23
+ s = s || {};
24
+ return { expanded: new Set(s.expanded || []), pinned: new Set(s.pinned || []) };
25
+ }
26
+
27
+ function dump(s) {
28
+ return { expanded: Array.from(s.expanded).sort(), pinned: Array.from(s.pinned).sort() };
29
+ }
30
+
31
+ /** 鼠标悬停到某个组:展开它。人的组没有可展开的东西。 */
32
+ function hover(state, group) {
33
+ const s = norm(state);
34
+ if (group && group !== HUMAN) s.expanded.add(group);
35
+ return dump(s);
36
+ }
37
+
38
+ /** 点击 pill:钉住(鼠标移开也不收起) / 取消钉住。 */
39
+ function toggle(state, group) {
40
+ const s = norm(state);
41
+ if (!group || group === HUMAN) return dump(s);
42
+ if (s.pinned.has(group)) {
43
+ s.pinned.delete(group);
44
+ s.expanded.delete(group);
45
+ } else {
46
+ s.pinned.add(group);
47
+ s.expanded.add(group);
48
+ }
49
+ return dump(s);
50
+ }
51
+
52
+ /**
53
+ * 鼠标离开标签条:收起没被钉住的组 —— 但**正在看的那一组不收起**。
54
+ * 否则人切到某个 agent 的页面后,鼠标一移开那一页就从标签条上消失了,
55
+ * 只能对着地址栏猜"这是谁的页面"。
56
+ */
57
+ function leave(state, activeGroup) {
58
+ const s = norm(state);
59
+ for (const g of Array.from(s.expanded)) {
60
+ if (s.pinned.has(g) || g === activeGroup) continue;
61
+ s.expanded.delete(g);
62
+ }
63
+ return dump(s);
64
+ }
65
+
66
+ /**
67
+ * 渲染清单:把标签页数组摊平成"先人的页、再每个组一个 pill(展开时后面跟它的页)"。
68
+ *
69
+ * 返回 { items, state, activeGroup }:
70
+ * items: {type:'tab'|'group', ...} 顺序即标签条上的顺序
71
+ * state: 归一化后的展开/钉住状态("正在看的那一组"会被强制展开)
72
+ */
73
+ function build(tabs, state) {
74
+ const s = norm(state);
75
+ const list0 = Array.isArray(tabs) ? tabs : [];
76
+ const active = list0.find((t) => t.active);
77
+ const activeGroup = active ? (active.group || HUMAN) : null;
78
+ // 正在看的那一页所在的组必须展开,理由见 leave()。
79
+ if (activeGroup && activeGroup !== HUMAN) s.expanded.add(activeGroup);
80
+
81
+ // 按组归拢,组的顺序 = 每组第一页出现的顺序(人的页在它自己的位置上)。
82
+ const order = [];
83
+ const byGroup = new Map();
84
+ for (const t of list0) {
85
+ const g = t.group || HUMAN;
86
+ if (!byGroup.has(g)) {
87
+ byGroup.set(g, []);
88
+ order.push(g);
89
+ }
90
+ byGroup.get(g).push(t);
91
+ }
92
+
93
+ const items = [];
94
+ for (const g of order) {
95
+ const list = byGroup.get(g);
96
+ if (g === HUMAN) {
97
+ for (const tab of list) items.push({ type: 'tab', tab: tab });
98
+ continue;
99
+ }
100
+ const head = list[0];
101
+ const open = s.expanded.has(g);
102
+ items.push({
103
+ type: 'group',
104
+ id: g,
105
+ label: head.group_label || g,
106
+ count: list.length,
107
+ limit: head.group_limit || null,
108
+ color: head.group_color || null,
109
+ open: open,
110
+ });
111
+ if (open) {
112
+ for (const tab of list) {
113
+ items.push({ type: 'tab', tab: tab, inGroup: true, color: head.group_color || null });
114
+ }
115
+ }
116
+ }
117
+ return { items: items, state: dump(s), activeGroup: activeGroup };
118
+ }
119
+
120
+ /** 结构签名:只有它变了才重建 DOM(每 1.5s 重画会把滚动位置冲掉)。 */
121
+ function signature(tabs, state) {
122
+ const list = Array.isArray(tabs) ? tabs : [];
123
+ const exp = state && state.expanded ? Array.from(state.expanded).slice().sort().join(',') : '';
124
+ return list.map((t) => t.id + ':' + (t.group || HUMAN)).join(',') + '#' + exp;
125
+ }
126
+
127
+ return {
128
+ HUMAN: HUMAN,
129
+ empty: empty,
130
+ hover: hover,
131
+ toggle: toggle,
132
+ leave: leave,
133
+ build: build,
134
+ signature: signature,
135
+ };
136
+ });
@@ -104,6 +104,9 @@ export const VALID_METHODS = [
104
104
  // 服务端进程身份(pid + 启动时刻)。调用方据此核对"我连上的是不是我拉起的
105
105
  // 那个实例" —— 连错实例时结果毫无意义但不会报错,是最难查的一类。
106
106
  'ui.server_info',
107
+ // 连接自报家门(label / auto_workspace)。声明自己是 agent 的连接会拿到一块
108
+ // 自己的标签组与自动工作区 —— 这是"agent 的操作与人的操作隔离"的入口。
109
+ 'ui.hello',
107
110
  'ui.canvas_configure',
108
111
  'ui.canvas_list',
109
112
  'ui.canvas_read',
@@ -0,0 +1,112 @@
1
+ // shared/tab_group.cjs — 标签页归属:人的一组,每个 agent 一组。
2
+ //
3
+ // 解决的是"多 agent 同时用同一个浏览器"的最后一公里:v2.2.0 已经把**默认目标**
4
+ // 从全局 activeTab 改成会话级,但 agent 的页仍然混在人的标签条里,看不出谁是谁的;
5
+ // 更麻烦的是没有上限 —— 一个跑长任务的 agent 能开二十个标签页,内存被无声吃掉。
6
+ //
7
+ // 这里只有纯函数,不碰 Electron:判据能被单测钉住(tests/test_tab_group.js)。
8
+ //
9
+ // 三个概念分清楚,不要混:
10
+ // group —— 归属(人的 / 某个 agent 的),决定标签栏怎么归拢、上限算谁的
11
+ // active —— 人眼前看的是哪一页。**看**不等于**拥有**:人点开 agent 的页看它
12
+ // 干活,那一页仍然属于 agent,agent 的目标不受影响
13
+ // 目标 —— 某次调用作用在哪一页(shared/tab_route.cjs 的 explicit>session>…)
14
+ 'use strict';
15
+
16
+ /** 人的标签页统一归这一组。它不是"某个会话",而是"没有会话"。 */
17
+ const HUMAN_GROUP = 'human';
18
+
19
+ /** 默认每组上限。8 是权衡:一个正常流程(登录页 + 列表 + 详情 + 后台)留得下,
20
+ * 再多的多半是没关的中间页。环境变量 AI_BROWSER_TAB_LIMIT 可调。 */
21
+ const DEFAULT_LIMIT = 8;
22
+
23
+ /** 组色板。只用于标签栏上那个小圆点,不承载语义。 */
24
+ const COLORS = ['#7c6cf0', '#3fb6a8', '#e0a33e', '#e06c75', '#5aa9e6', '#c678dd'];
25
+
26
+ function groupIdForSession(sessionId) {
27
+ return sessionId ? 'agent:' + sessionId : HUMAN_GROUP;
28
+ }
29
+
30
+ function isAgentGroup(group) {
31
+ return typeof group === 'string' && group.indexOf('agent:') === 0;
32
+ }
33
+
34
+ function isHumanGroup(group) {
35
+ return !isAgentGroup(group);
36
+ }
37
+
38
+ /**
39
+ * 每 agent 的标签页上限。
40
+ *
41
+ * 为什么要上限:这是唯一能**自动**约束 agent 的机制。一个跑长任务的 agent 会
42
+ * 用"再开一个标签页"来回避"这一页怎么办"的决定(人也是这样),几十个标签页在
43
+ * 无头式后台运行里完全不可见,直到内存告急。硬上限把"要不要留这一页"提前变成
44
+ * 一次必须做的决定。
45
+ */
46
+ function limitFromEnv(env) {
47
+ const src = env || (typeof process !== 'undefined' ? process.env : {}) || {};
48
+ const raw = Number(src.AI_BROWSER_TAB_LIMIT);
49
+ if (!Number.isFinite(raw) || raw < 1) return DEFAULT_LIMIT;
50
+ return Math.min(Math.floor(raw), 64);
51
+ }
52
+
53
+ function colorFor(index) {
54
+ const n = COLORS.length;
55
+ return COLORS[((index % n) + n) % n];
56
+ }
57
+
58
+ /**
59
+ * 还能不能再开一页。
60
+ *
61
+ * 只对 agent 组生效:人的标签页不受任何限制(限制人会让产品变得没法用,而且
62
+ * 人要开多少页是他自己的事)。limit<=0 视为不限。
63
+ */
64
+ function decideOpen({ group, count, limit }) {
65
+ if (!isAgentGroup(group)) return { allowed: true, count, limit: null, remaining: null };
66
+ const cap = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : DEFAULT_LIMIT;
67
+ const used = Number.isFinite(count) && count > 0 ? count : 0;
68
+ return {
69
+ allowed: used < cap,
70
+ count: used,
71
+ limit: cap,
72
+ remaining: Math.max(0, cap - used),
73
+ };
74
+ }
75
+
76
+ /**
77
+ * 弹窗(页面里 window.open / target=_blank)把组撑满时,牺牲哪一页。
78
+ *
79
+ * 为什么弹窗不能像 ui.new_tab 一样直接拒绝:这个弹窗是**页面脚本要的**,拒绝
80
+ * 等于让站点的流程断在半路(OAuth 回调、打印预览、编辑器子窗口)。所以这里退一步,
81
+ * 挑一页最不心疼的关掉。三条排除:
82
+ * - 正在被打开的那个(except,关了自己等于什么都没发生)
83
+ * - 人眼前那一页(activeTab,人正在看)
84
+ * - 有对话框挂着的(那是"等人点"的状态,关掉就把人的操作吞了)
85
+ * 剩下的按"最久没用"排序(usedAt 由 page_manager 在导航/动作时刷新)。
86
+ * 没有候选就返回 null,调用方只好允许超限 —— 宁可多一页,不要吞掉正在用的页。
87
+ */
88
+ function pickEvictable({ tabs, except, activeTab }) {
89
+ const list = Array.isArray(tabs) ? tabs : [];
90
+ let best = null;
91
+ for (const t of list) {
92
+ if (!t || t.id === undefined || t.id === null) continue;
93
+ if (t.id === except || t.id === activeTab) continue;
94
+ if (t.dialog) continue;
95
+ const at = Number(t.usedAt) || 0;
96
+ if (!best || at < best.usedAt) best = { id: t.id, usedAt: at, url: t.url || '' };
97
+ }
98
+ return best ? best.id : null;
99
+ }
100
+
101
+ module.exports = {
102
+ HUMAN_GROUP,
103
+ DEFAULT_LIMIT,
104
+ COLORS,
105
+ groupIdForSession,
106
+ isAgentGroup,
107
+ isHumanGroup,
108
+ limitFromEnv,
109
+ colorFor,
110
+ decideOpen,
111
+ pickEvictable,
112
+ };
@@ -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.2.0';
5
+ export const VERSION = '2.3.0';