@liang-hz/agent-in-chrome 0.55.0 → 0.55.2

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/.ext-id.txt CHANGED
@@ -2,3 +2,4 @@
2
2
  # 第一行必须是开发版 ID:由 ext-key.pem 的公钥决定,「加载已解压」和本地 CRX 都是它。
3
3
  # allowed_origins 不支持通配符,拿到商店 ID 后追加一行到这里,再发 npm。
4
4
  eknmigackgheebnojadpjepdoebpfnil
5
+ menddiogpdbejmgoeikokenecambioml
package/README.en.md CHANGED
@@ -23,7 +23,7 @@ It inherits the sessions you're already logged into: intranet tools, Gmail, admi
23
23
 
24
24
  Agent in Chrome connects an AI agent (Claude Code, Claude Desktop, Trae, Codex, and others) to **the Chrome sitting in front of you**. It exposes a browser toolset over [MCP](https://modelcontextprotocol.io) so the agent can read pages, click, fill forms, and capture network traffic — all carrying your existing login state, all in background tabs that never steal your foreground.
25
25
 
26
- **How does it compare?** The table below scores only **native, out-of-the-box capability**: ✅ = works without writing code, ❌ = not available. (Most of these tools ship an arbitrary-code-execution escape hatch, so in principle anything can be rebuilt by hand — count that and every cell turns ✅ and the table stops meaning anything.) Based on a source-code read and hands-on measurement on 2026-08-18, against @playwright/mcp 0.0.79 · chrome-devtools-mcp 1.7.0 · browser-use 0.13.8 · ego lite 0.4.6.14. No recommendation implied — pick by your situation.
26
+ **How does it compare?** The table below scores only **native, out-of-the-box capability**: ✅ = works without writing code, ❌ = not available. (Most of these tools ship an arbitrary-code-execution escape hatch, so in principle anything can be rebuilt by hand — count that and every cell turns ✅ and the table stops meaning anything.) Based on a source-code read and hands-on measurement on 2026-08-18 (the Playwright MCP, browser-use, and ego lite columns re-verified on 2026-09-10 with the same task books plus targeted probes; Playwright MCP and ego lite matched agent-in-chrome / chrome-devtools-mcp on task completion, while browser-use showed real tool-surface gaps — see footnotes), against @playwright/mcp 0.0.80 · chrome-devtools-mcp 1.7.0 · browser-use 0.13.10 · ego lite 0.5.0.28. No recommendation implied — pick by your situation.
27
27
 
28
28
  | | Agent in Chrome | Playwright MCP | Chrome DevTools MCP | browser-use | ego lite |
29
29
  |---|:---:|:---:|:---:|:---:|:---:|
@@ -33,16 +33,16 @@ Agent in Chrome connects an AI agent (Claude Code, Claude Desktop, Trae, Codex,
33
33
  | Speaks MCP | ✅ | ✅ | ✅ | ✅ | ❌ |
34
34
  | Windows / Linux | ✅⁵ | ✅ | ✅ | ✅ | ❌ |
35
35
  | Firefox / WebKit | ❌ | ✅ | ❌ | ❌ | ❌ |
36
- | Raw network headers + request/response bodies | ✅ | ✅ | ✅ | ❌ | ❌ |
37
- | WebSocket frames / initiator stack / export as curl | ✅ | ❌ | ❌ | ❌ | ❌ |
38
- | Request mocking / throttling / performance traces | ❌ | ✅ | ✅ | ❌ | ❌ |
39
- | Credentials redacted by default (cookies and passwords never enter model context) | ✅ | ❌⁶ | ❌⁶ | ✅⁷ | ❌ |
40
- | No server-side arbitrary code execution enabled by default | ✅ | ❌⁸ | ✅ | ❌ | ❌ |
36
+ | Raw network headers + request/response bodies | ✅ | ✅ | ✅ | ❌ | ❌⁹ |
37
+ | WebSocket frames / initiator stack / export as curl | ✅ | ❌¹² | ❌ | ❌ | ❌⁹ |
38
+ | Request mocking / throttling / performance traces | ❌ | ❌¹² | ✅ | ❌ | ❌⁹ |
39
+ | Credentials redacted by default (cookies and passwords never enter model context) | ✅ | ❌⁶ | ❌⁶ | ✅⁷ | ❌⁹ |
40
+ | No server-side arbitrary code execution enabled by default | ✅ | ❌⁸ | ✅ | ❌¹⁰ | ❌¹⁰ |
41
41
  | Zero runtime third-party dependencies | ✅ | ❌ | ❌ | ❌ | ❌ |
42
- | Modal overlay detection (including login walls with no ARIA role) | ✅ | ❌ | ❌ | ❌ | ❌ |
43
- | Element pixel coordinates + top-level coordinates across frames | ✅ | ❌ | ❌ | ❌ | ❌ |
42
+ | Modal overlay detection (including login walls with no ARIA role) | ✅ | ❌ | ❌ | ❌¹¹ | ❌¹¹ |
43
+ | Element pixel coordinates + top-level coordinates across frames | ✅ | ❌ | ❌ | ❌¹¹ | ❌¹¹ |
44
44
 
45
- <sup>1</sup> `--extension` mode only (Chrome/Edge, requires installing their extension); the default mode is an isolated profile. <sup>2</sup> `--autoConnect` only (Chrome 144+, requires manually opening the gate in `chrome://inspect`, which exposes every window in that profile). <sup>3</sup> Either connect to a Chrome already started with a debug port, or close Chrome and let it copy the entire profile. <sup>4</sup> A separate Chromium fork; migrates your Chrome data once on first launch. <sup>5</sup> Windows supports extension mode (CLI/headless mode planned); the Linux path is written but unverified. <sup>6</sup> Playwright's `--secrets` and DevTools MCP's `--redactNetworkHeaders` are both opt-in and off by default, and the latter doesn't cover bodies. <sup>7</sup> Solid placeholder mechanism on the input side; no redaction on network responses. <sup>8</sup> `browser_run_code_unsafe` describes itself as RCE-equivalent and is on by default.
45
+ <sup>1</sup> `--extension` mode only (Chrome/Edge, requires installing their extension); the default mode is an isolated profile. <sup>2</sup> `--autoConnect` only (Chrome 144+, requires manually opening the gate in `chrome://inspect`, which exposes every window in that profile). <sup>3</sup> Either connect over CDP to a Chrome already started with a debug port, or use its bundled browser (isolated profile, no user login state). <sup>4</sup> A separate Chromium fork; login state comes from import rather than live borrowing — `ego-browser import` re-imports from Chrome/Edge/Brave (extensions included). <sup>5</sup> Windows supports extension mode (CLI/headless mode planned); the Linux path is written but unverified. <sup>6</sup> Playwright's `--secrets` and DevTools MCP's `--redactNetworkHeaders` are both opt-in and off by default, and the latter doesn't cover bodies. Measured: Playwright's `browser_network_request` filters Cookie and Set-Cookie out of request headers by default (full raw headers require run_code). <sup>7</sup> Solid placeholder mechanism on the input side; no redaction on network responses. <sup>8</sup> `browser_run_code_unsafe` describes itself as RCE-equivalent and is on by default. <sup>9</sup> ego has no native network helpers, but its `page.cdp()` escape hatch reaches everything (measured on 0.5.0.28): raw headers live in CDP ExtraInfo events and need manual pairing by requestId, WS frames are capturable, mocking/throttling/tracing all doable; cookies stay plaintext throughout, no redaction. <sup>10</sup> ego and browser-use both make code their primary interface (heredoc / Python) — arbitrary code execution is by design. <sup>11</sup> Measured: overlays without ARIA roles don't surface in ego's semantic snapshot (flattened into the same tree, no modality marker; only a click error names the intercepting element); its snapshot carries no element pixel coordinates, and top-level coordinates across frames must be computed by hand. browser-use filters buttons under an overlay out of its element list entirely and its coordinate clicks can falsely report success; its observation output likewise carries no pixel coordinates. <sup>12</sup> Measured: Playwright MCP 0.0.80 ships no mocking/throttling/tracing tools at all (the `browser_route`/tracing tools in its README were not released with this version), and it has no native WS frames, initiator stacks, or curl export either; all of these are reachable through the `browser_run_code_unsafe` escape hatch.
46
46
 
47
47
  **Speed** (same test page containing a cross-origin iframe, equivalent fresh profiles, medians; browser-use is omitted because it requires manual per-run authorization in `chrome://inspect` and can't complete the same flow unattended):
48
48
 
@@ -111,7 +111,7 @@ schema. Guessing the paths is how this usually fails: a wrong path gets you a ba
111
111
  The installer will (every step reversible, and every file it's about to touch is listed before it touches it):
112
112
 
113
113
  1. Sync the runtime into `~/.agent-in-chrome/agent-in-chrome/` and write the native host manifest into each Chromium browser's `NativeMessagingHosts/` directory.
114
- 2. Detect the agents on your machine (Claude Code, Claude Desktop, WorkBuddy, ZCode, opencode, Kimi CLI, Gemini CLI, Antigravity, Qoder CLI, Qoder IDE, Trae, Codex CLI, DeepSeek Harness, plus the China builds Qoder CN CLI / Qoder CN IDE / Trae CN — 16 in total), show you the exact file and content it would write for each, and register the MCP server after you confirm (originals backed up automatically; `--yes` skips the per-agent prompts, `--agents=claude-code,trae` narrows the set, `--no-agents` skips this entirely).
114
+ 2. Detect the agents on your machine (Claude Code, Claude Desktop, WorkBuddy, WorkBuddy AI, ZCode, opencode, Kimi CLI, Gemini CLI, Antigravity, Qoder CLI, Qoder IDE, Trae, Codex CLI, DeepSeek Harness, plus the China builds Qoder CN CLI / Qoder CN IDE / Trae CN — 17 in total), show you the exact file and content it would write for each, and register the MCP server after you confirm (originals backed up automatically; `--yes` skips the per-agent prompts, `--agents=claude-code,trae` narrows the set, `--no-agents` skips this entirely).
115
115
  3. Generate a **connection token unique to this machine** (mode `0600`, never committed, never uploaded) — see [Security and transparency](#security-and-transparency).
116
116
  4. Install **two skills and two commands**: `skills/agent-in-chrome/` (including the reference handbooks under `references/`, which teach the agent how to use the browser tools) and `skills/install-agent-in-chrome/` (which teaches it how to install this into another client) are copied to `~/.agent-in-chrome/skills/`, and the `/agent-in-chrome` and `/install-agent-in-chrome` commands to `~/.agent-in-chrome/commands/`.
117
117
 
package/README.md CHANGED
@@ -23,7 +23,7 @@ by Liang · [liangai.org](https://liangai.org)
23
23
 
24
24
  Agent in Chrome 把 AI agent(Claude Code、Claude Desktop、Trae、Codex……)接到**你自己正在用的那个 Chrome** 上。它通过 [MCP](https://modelcontextprotocol.io) 暴露一套浏览器工具,让 agent 能读页面、点按钮、填表单、抓网络请求——全部带着你现有的登录态,全部在后台进行,不抢你的前台。
25
25
 
26
- **和别的方案怎么选?** 下面只对比**开箱即有的原生能力**:✅ = 不写代码就能用,❌ = 不具备(多数工具带任意代码执行的逃生舱,理论上都能自己补——若把那也算上,所有格子都是 ✅,表格就没有意义了)。基于 2026-08-18 的源码通读与本机实测,版本:@playwright/mcp 0.0.79 · chrome-devtools-mcp 1.7.0 · browser-use 0.13.8 · ego lite 0.4.6.14。不做推荐,按你的场景自取。
26
+ **和别的方案怎么选?** 下面只对比**开箱即有的原生能力**:✅ = 不写代码就能用,❌ = 不具备(多数工具带任意代码执行的逃生舱,理论上都能自己补——若把那也算上,所有格子都是 ✅,表格就没有意义了)。基于 2026-08-18 的源码通读与本机实测(Playwright MCP、browser-use、ego lite 三列于 2026-09-10 以同一套任务书与专项探针逐格复测:Playwright MCP 与 ego lite 的任务完成度与 agent-in-chrome / chrome-devtools-mcp 同档,browser-use 实测出工具面缺口,见脚注),版本:@playwright/mcp 0.0.80 · chrome-devtools-mcp 1.7.0 · browser-use 0.13.10 · ego lite 0.5.0.28。不做推荐,按你的场景自取。
27
27
 
28
28
  | | Agent in Chrome | Playwright MCP | Chrome DevTools MCP | browser-use | ego lite |
29
29
  |---|:---:|:---:|:---:|:---:|:---:|
@@ -33,16 +33,16 @@ Agent in Chrome 把 AI agent(Claude Code、Claude Desktop、Trae、Codex……
33
33
  | 走 MCP 协议 | ✅ | ✅ | ✅ | ✅ | ❌ |
34
34
  | Windows / Linux | ✅⁵ | ✅ | ✅ | ✅ | ❌ |
35
35
  | Firefox / WebKit | ❌ | ✅ | ❌ | ❌ | ❌ |
36
- | 网络原始头 + 请求/响应体 | ✅ | ✅ | ✅ | ❌ | ❌ |
37
- | WebSocket 帧 / 发起调用栈 / 导出 curl | ✅ | ❌ | ❌ | ❌ | ❌ |
38
- | 请求 mock / 限速模拟 / 性能 trace | ❌ | ✅ | ✅ | ❌ | ❌ |
39
- | 凭据默认打码(Cookie/密码不进模型上下文) | ✅ | ❌⁶ | ❌⁶ | ✅⁷ | ❌ |
40
- | 无「服务端任意代码执行」默认开启 | ✅ | ❌⁸ | ✅ | ❌ | ❌ |
36
+ | 网络原始头 + 请求/响应体 | ✅ | ✅ | ✅ | ❌ | ❌⁹ |
37
+ | WebSocket 帧 / 发起调用栈 / 导出 curl | ✅ | ❌¹² | ❌ | ❌ | ❌⁹ |
38
+ | 请求 mock / 限速模拟 / 性能 trace | ❌ | ❌¹² | ✅ | ❌ | ❌⁹ |
39
+ | 凭据默认打码(Cookie/密码不进模型上下文) | ✅ | ❌⁶ | ❌⁶ | ✅⁷ | ❌⁹ |
40
+ | 无「服务端任意代码执行」默认开启 | ✅ | ❌⁸ | ✅ | ❌¹⁰ | ❌¹⁰ |
41
41
  | 零运行时第三方依赖 | ✅ | ❌ | ❌ | ❌ | ❌ |
42
- | 模态浮层检出(含无 ARIA 角色的登录墙) | ✅ | ❌ | ❌ | ❌ | ❌ |
43
- | 元素像素坐标 + 跨源帧顶层坐标 | ✅ | ❌ | ❌ | ❌ | ❌ |
42
+ | 模态浮层检出(含无 ARIA 角色的登录墙) | ✅ | ❌ | ❌ | ❌¹¹ | ❌¹¹ |
43
+ | 元素像素坐标 + 跨源帧顶层坐标 | ✅ | ❌ | ❌ | ❌¹¹ | ❌¹¹ |
44
44
 
45
- <sup>1</sup> 仅 `--extension` 模式(Chrome/Edge,需装其扩展);默认模式是独立 profile。 <sup>2</sup> 仅 `--autoConnect`(Chrome 144+,需在 `chrome://inspect` 手动开闸,该 profile 全部窗口暴露)。 <sup>3</sup> 二选一:目标 Chrome 带调试端口启动后直连,或关掉 Chrome 让它整份拷贝 profile。 <sup>4</sup> 独立 Chromium 分叉浏览器,首启一次性迁移 Chrome 数据。 <sup>5</sup> Windows 已支持插件模式(CLI/headless 模式规划中);Linux 路径已写未验证。 <sup>6</sup> Playwright 的 `--secrets` 与 DevTools 的 `--redactNetworkHeaders` 均为可选开关且默认关闭,后者不覆盖 body。 <sup>7</sup> 输入侧占位符机制完备;网络返回值无打码。 <sup>8</sup> `browser_run_code_unsafe` 自述 RCE-equivalent,默认开启。
45
+ <sup>1</sup> 仅 `--extension` 模式(Chrome/Edge,需装其扩展);默认模式是独立 profile。 <sup>2</sup> 仅 `--autoConnect`(Chrome 144+,需在 `chrome://inspect` 手动开闸,该 profile 全部窗口暴露)。 <sup>3</sup> 二选一:CDP 直连已开调试端口的 Chrome,或用自带浏览器(独立 profile,不带用户登录态)。 <sup>4</sup> 独立 Chromium 分叉浏览器;登录态靠导入而非实时借用——`ego-browser import` 可从 Chrome/Edge/Brave 重复导入(扩展一并迁入)。 <sup>5</sup> Windows 已支持插件模式(CLI/headless 模式规划中);Linux 路径已写未验证。 <sup>6</sup> Playwright 的 `--secrets` 与 DevTools 的 `--redactNetworkHeaders` 均为可选开关且默认关闭,后者不覆盖 body。实测 Playwright 的 `browser_network_request` 默认过滤请求头中的 Cookie 与 Set-Cookie(要完整原始头得走 run_code)。 <sup>7</sup> 输入侧占位符机制完备;网络返回值无打码。 <sup>8</sup> `browser_run_code_unsafe` 自述 RCE-equivalent,默认开启。 <sup>9</sup> ego 无网络类原生 helper,但 `page.cdp()` 逃生舱实测可达:原始头在 CDP ExtraInfo 事件里、需按 requestId 自行配对,WS 帧可抓,mock/限速/trace 均可做;全程 Cookie 明文无打码。 <sup>10</sup> ego 与 browser-use 的主接口都是代码(heredoc / Python),任意代码执行是设计使然。 <sup>11</sup> 实测无 ARIA 浮层不进 ego 的语义快照(与正文平铺同树、无模态标记,仅点击报错会点名遮挡元素),快照不含元素像素坐标,跨源帧顶层坐标需自行计算;browser-use 的元素表则会把遮罩下按钮整个过滤掉、坐标点击会误报成功,观察输出同样不含像素坐标。 <sup>12</sup> 实测 Playwright MCP 0.0.80 包内并无 mock/限速/trace 类工具(其 README 文档所载 `browser_route`/tracing 未随该版本发布),WS 帧、发起调用栈、curl 导出也无原生工具;均可用 `browser_run_code_unsafe` 逃生舱补做。
46
46
 
47
47
  **速度**(同一含跨源 iframe 的测试页、对等全新 profile、中位数;browser-use 因需人工在 `chrome://inspect` 逐次授权,无法无人值守完成同一流程,未列入):
48
48
 
@@ -107,7 +107,7 @@ schema 写进去。路径靠猜是这件事最常见的失败方式:猜错了
107
107
  安装器会(全部可逆、动手前列出将改动的文件):
108
108
 
109
109
  1. 把运行时同步到 `~/.agent-in-chrome/agent-in-chrome/`,并把 native host 清单写进你各个 Chromium 浏览器的 `NativeMessagingHosts/` 目录;
110
- 2. 探测本机的 agent(Claude Code / Claude Desktop / WorkBuddy / ZCode / opencode / Kimi CLI / Gemini CLI / Antigravity / Qoder CLI / Qoder IDE / Trae / Codex CLI / DeepSeek Harness,以及国内版 Qoder CN CLI / Qoder CN IDE / Trae CN,共 16 家),逐个展示将写入的文件和内容、确认后在各自的 MCP 配置里注册(改前自动备份;`--yes` 跳过逐个确认,`--agents=claude-code,trae` 限定范围,`--no-agents` 完全跳过);
110
+ 2. 探测本机的 agent(Claude Code / Claude Desktop / WorkBuddy / WorkBuddy AI / ZCode / opencode / Kimi CLI / Gemini CLI / Antigravity / Qoder CLI / Qoder IDE / Trae / Codex CLI / DeepSeek Harness,以及国内版 Qoder CN CLI / Qoder CN IDE / Trae CN,共 17 家),逐个展示将写入的文件和内容、确认后在各自的 MCP 配置里注册(改前自动备份;`--yes` 跳过逐个确认,`--agents=claude-code,trae` 限定范围,`--no-agents` 完全跳过);
111
111
  3. 在本机生成一个**每台机器唯一的连接令牌**(`0600`,不写进仓库、不上传)——见[安全与透明度](#安全与透明度);
112
112
  4. 把**两份 skill 和两条命令**装好:`skills/agent-in-chrome/`(含 `references/` 下的分册手册,教 agent 怎么用这些浏览器工具)和 `skills/install-agent-in-chrome/`(教 agent 怎么把它装到别的客户端上)拷到 `~/.agent-in-chrome/skills/`,`/agent-in-chrome` 与 `/install-agent-in-chrome` 两条命令拷到 `~/.agent-in-chrome/commands/`。
113
113
 
package/docs/AGENTS.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > 安装器(`npx @liang-hz/agent-in-chrome install`)会自动写好这一切,**正常情况下你不需要读这个文件**。
4
4
  > 它存在的用途:核对安装器到底写了什么、或在不能跑安装器的环境里手动登记。
5
- > 从 [README](../README.md) 挪出来,免得 16 家客户端的配置路径挡在快速开始的正路上。
5
+ > 从 [README](../README.md) 挪出来,免得 17 家客户端的配置路径挡在快速开始的正路上。
6
6
 
7
7
  安装器会自动写好这些;下面是它实际写入的文件和内容,供你核对或手动登记。把 `<RUNTIME>` 换成安装器打印的实际路径(默认 `~/.agent-in-chrome/agent-in-chrome`)。每个文件改前都会留 `.bak-<时间戳>` 备份,且只动 `agent-in-chrome` 这一个键。
8
8
 
@@ -41,6 +41,24 @@ claude mcp add --scope user agent-in-chrome -- node <RUNTIME>/server.mjs
41
41
  > 同目录那个隐藏的 `.mcp.json` 是 WorkBuddy 自己的**输出**文件(每次启动写 connector-proxy 聚合条目),
42
42
  > 往里写注册它不读;装的时候会顺带把老版本写错在那里的条目摘掉。
43
43
 
44
+ **WorkBuddy AI**(国际版,`~/.workbuddy-ai/mcp.json`,**非隐藏**那份):
45
+ ```json
46
+ { "mcpServers": { "agent-in-chrome": {
47
+ "type": "stdio", "command": "<RUNTIME>/mcp-launcher.sh", "args": [], "disabled": false
48
+ } } }
49
+ ```
50
+ > 和国内版是**同一份代码、只换数据目录**(`cli/product.json` 的 `dataFolderName`:国内版
51
+ > `.workbuddy`、国际版 `.workbuddy-ai`),所以条目形状、文件名、`readCustomMcpConfig`
52
+ > 的读法全都逐字相同——只是目录不同,**两家各写各的,互不覆盖**。
53
+ > 没有 legacy 要清:历史上写错的隐藏 `.mcp.json` 只落在国内版目录下。
54
+ >
55
+ > **国际版多一道信任闸**:第三方 MCP server 写进 `mcp.json` 后,连接器中心里会显示为
56
+ > 「需要你的授权」(`trustLevel: gray` + `status: disabled`),点一下信任才会连。
57
+ > 信任记录在 `~/.workbuddy-ai/mcp-approvals.json`,键是
58
+ > `sha256(command|args|envKeys)::serverName`——**它是进程启动时一次性加载的**,
59
+ > 所以在应用运行期间手改这个文件无效,只能在 UI 里点(或改完重启应用)。
60
+ > 国内版同一套机制,落点是 `~/.workbuddy/mcp-approvals.json`。
61
+
44
62
  **ZCode**(`~/.zcode/cli/config.json`,段落是 `mcp.servers`)、**opencode**(`~/.config/opencode/opencode.json`,段落是 `mcp`,`command` 是数组且要 `enabled: true`)、
45
63
  **Kimi CLI**(`~/.kimi/mcp.json`)、**Gemini CLI**(`~/.gemini/settings.json`)——
46
64
  后两家都是标准 `mcpServers` 形状。安装器只碰 `agent-in-chrome` 这一个键,其余内容原样保留(改前自动备份)。
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Agent in Chrome",
4
- "version": "0.55.0",
4
+ "version": "0.55.2",
5
5
  "description": "让 AI agent 操作你已经登录的那个 Chrome 标签页,复用你现有的登录态。 · by Liang (liangai.org)",
6
6
  "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6Jtdbvmd/bUVxIn9YXdLBw9idVVJwXfCHCGYkPZ0Wp8YcIRBPj10a6L4tTF6h78cLjvgowiZmCAdiUZekjBdPrKJT9nhkGIX9yER3DfRpk0NOkTxum95Eb/K6Y4U/3q1TbhFkebBFZAcPG6O5/Nh8qnTiEuN/EFB3PqlODh4UInLxYbGsHV5vp4WXxfGOt1fF3VkekS7T1gPndijbBBeriv61eb7KguMNrEbid+p07kBPDZ6D3mp4JT6eqsfoPgK01QISBMrJgou0ra9Z4t+bhPvsoe2xAkr8X5iojSAVKUs1UKyKueV2WJ1JPqdAFIRckWwZ4sqEpk/LenKFljTiQIDAQAB",
7
7
  "minimum_chrome_version": "125",
package/extension/sw.js CHANGED
@@ -9,7 +9,7 @@
9
9
  // 所有 browser_* 工具的实现都在这个文件里(工具表见 TOOLS)。
10
10
 
11
11
  const HOST_NAME = "org.liangai.agent_in_chrome";
12
- const VERSION = "0.55.0";
12
+ const VERSION = "0.55.2";
13
13
  /* 这个 service worker 实例是什么时候起来的(= 磁盘上的代码是什么时候读进来的),见 hello */
14
14
  const SW_BOOTED_AT = Date.now();
15
15
  /* agent 开的标签页统一收进这一组,跟用户自己的标签页视觉隔离 */
@@ -70,6 +70,12 @@ export function bundleMatch(command) {
70
70
  return name ? { name, appDir: `${outerHead}.app` } : null;
71
71
  }
72
72
 
73
+ function livesInBundle(command, appDir) {
74
+ if (!appDir) return false;
75
+ const s = String(command || "").trim().replace(/^"/, "");
76
+ return s.startsWith(`${appDir}/`);
77
+ }
78
+
73
79
  const bundleVersionMemo = new Map();
74
80
  export function readBundleVersion(appDir, { exec = execFileSync } = {}) {
75
81
  if (!appDir || typeof appDir !== "string") return null;
@@ -136,9 +142,13 @@ export function exePathOf(command) {
136
142
  /*
137
143
  * 沿父进程链找形态与品牌的证据,先撞见哪个算哪个:
138
144
  *
139
- * 撞见有终端的进程 → CLI(从命令行起来的)
140
- * 撞见 .app 包 → 桌面端,顺带拿到包名当品牌候选
141
- * 一路走到 launchd 都没终端 → 桌面端(GUI 进程的典型形状,如 ZCode)
145
+ * 撞见有终端的进程 → CLI(从命令行起来的)
146
+ * 撞见**客户端自己的** .app → 桌面端,顺带拿到包名当品牌候选
147
+ * 一路走到 launchd 都没终端 → 桌面端(GUI 进程的典型形状,如 ZCode)
148
+ *
149
+ * 第二条的「自己的」是必要条件:链上撞见的 `.app` 未必装着客户端——从桌面端里起的
150
+ * CLI 就会撞见**启动它的那个 app**。这种包不认,就地返回「无证据」,让上层回落到
151
+ * 客户端自报的名字(继续往上走也一样错,上面只有那个 app 的其它进程)。
142
152
  *
143
153
  * Windows 上三条证据各有对应物,判据不同、结论一模一样:
144
154
  *
@@ -158,6 +168,7 @@ export function walkSurface(startPid, snap, { maxHops = 6, platform = process.pl
158
168
  const none = { surface: null, brand: null, appDir: null, why: "无证据" };
159
169
  let pid = Number(startPid);
160
170
  let prev = null;
171
+ const startCommand = snap.get(pid)?.command;
161
172
  for (let hop = 0; hop < maxHops; hop++) {
162
173
  if (!Number.isInteger(pid) || pid <= 1) break;
163
174
  const p = snap.get(pid);
@@ -166,7 +177,10 @@ export function walkSurface(startPid, snap, { maxHops = 6, platform = process.pl
166
177
  if (win && isWinTerminal(p.name)) return { surface: "cli", brand: binShimName(p.command), appDir: null, why: `${p.name}@${pid}` };
167
178
  if (win && isWinRoot(p.name)) return prev ? guiSurface(prev, `${p.name} 直属@${pid}`) : none;
168
179
  const b = bundleMatch(p.command);
169
- if (b) return { surface: "app", brand: b.name, appDir: b.appDir, why: `${b.name}.app@${pid}` };
180
+ if (b) {
181
+ if (!livesInBundle(startCommand, b.appDir)) return none;
182
+ return { surface: "app", brand: b.name, appDir: b.appDir, why: `${b.name}.app@${pid}` };
183
+ }
170
184
  if (!Number.isInteger(p.ppid) || p.ppid <= 1) {
171
185
  return { surface: "app", brand: plainName(p.command) || binShimName(p.command), appDir: null, why: `launchd 直属、无终端@${pid}` };
172
186
  }
@@ -432,9 +446,57 @@ export function readClaudeSubagent(meta, local, { fs = fsMod, home = osMod.homed
432
446
  return null;
433
447
  }
434
448
 
435
- export function readWorkbuddySessionTitle({ env = process.env, fs = fsMod, exec = execFileSync, alive = pidAlive } = {}) {
449
+ export function readWorkbuddySessionTitle({
450
+ env = process.env,
451
+ fs = fsMod,
452
+ exec = execFileSync,
453
+ alive = pidAlive,
454
+ meta = null,
455
+ enginePid = null,
456
+ } = {}) {
436
457
  const dir = typeof env.WORKBUDDY_CONFIG_DIR === "string" ? env.WORKBUDDY_CONFIG_DIR : "";
437
458
  if (!path.isAbsolute(dir)) return null;
459
+ const id =
460
+ workbuddyConversationId(meta) ||
461
+ workbuddyEngineSession(dir, enginePid, { fs }) ||
462
+ workbuddyOnlyLiveSession(dir, { fs, alive });
463
+ if (!id) return null;
464
+ /* `${id}` 是直接拼进 SQL 字符串的(sqlite3 CLI 不好参数化),所以上面三个来源都必须
465
+ * 先过 CONV_UUID_RE 才走得到这里:把那个锚放宽就等于开一个注入口。 */
466
+ try {
467
+ const out = exec(
468
+ process.platform === "win32" ? "sqlite3" : "/usr/bin/sqlite3",
469
+ ["-readonly", path.join(dir, "workbuddy.db"), `select coalesce(custom_title, title) from sessions where id='${id}' and deleted_at is null`],
470
+ { encoding: "utf8", timeout: 2000 }
471
+ );
472
+ return clip(String(out || "").trim(), 60);
473
+ } catch {
474
+ return null;
475
+ }
476
+ }
477
+
478
+ export function workbuddyConversationId(meta) {
479
+ if (!meta || typeof meta !== "object") return null;
480
+ const direct = String(meta["workbuddy.ai/conversationId"] ?? "").trim();
481
+ const m = /(?:^|[,\s])codebuddy\.session_id=([^\s,;]+)/.exec(String(meta.baggage ?? ""));
482
+ const id = direct || (m ? m[1].trim() : "");
483
+ return CONV_UUID_RE.test(id) ? id : null;
484
+ }
485
+
486
+ function workbuddyEngineSession(dir, enginePid, { fs = fsMod } = {}) {
487
+ if (!Number.isInteger(enginePid) || enginePid <= 1) return null;
488
+ try {
489
+ const d = JSON.parse(fs.readFileSync(path.join(dir, "sessions", `${enginePid}.json`), "utf8"));
490
+ if (!d || typeof d !== "object" || Number(d.pid) !== enginePid) return null;
491
+ if (d.kind !== "interactive") return null;
492
+ const sid = String(d.sessionId || "");
493
+ return CONV_UUID_RE.test(sid) ? sid : null;
494
+ } catch {
495
+ return null;
496
+ }
497
+ }
498
+
499
+ function workbuddyOnlyLiveSession(dir, { fs = fsMod, alive = pidAlive } = {}) {
438
500
  const live = [];
439
501
  try {
440
502
  for (const f of fs.readdirSync(path.join(dir, "sessions")).slice(0, 100)) {
@@ -443,7 +505,7 @@ export function readWorkbuddySessionTitle({ env = process.env, fs = fsMod, exec
443
505
  const d = JSON.parse(fs.readFileSync(path.join(dir, "sessions", f), "utf8"));
444
506
  if (d?.kind !== "interactive") continue;
445
507
  const sid = String(d.sessionId || "");
446
- if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(sid)) continue;
508
+ if (!CONV_UUID_RE.test(sid)) continue;
447
509
  if (!Number.isInteger(d.pid) || d.pid <= 1 || !alive(d.pid)) continue;
448
510
  live.push(sid);
449
511
  } catch {}
@@ -451,17 +513,7 @@ export function readWorkbuddySessionTitle({ env = process.env, fs = fsMod, exec
451
513
  } catch {
452
514
  return null;
453
515
  }
454
- if (live.length !== 1) return null;
455
- try {
456
- const out = exec(
457
- process.platform === "win32" ? "sqlite3" : "/usr/bin/sqlite3",
458
- ["-readonly", path.join(dir, "workbuddy.db"), `select coalesce(custom_title, title) from sessions where id='${live[0]}' and deleted_at is null`],
459
- { encoding: "utf8", timeout: 2000 }
460
- );
461
- return clip(String(out || "").trim(), 60);
462
- } catch {
463
- return null;
464
- }
516
+ return live.length === 1 ? live[0] : null;
465
517
  }
466
518
 
467
519
  export function pidAlive(pid) {
@@ -527,10 +579,19 @@ const titleMemo = new Map();
527
579
  const TITLE_MISS_BACKOFF_MS = 20_000;
528
580
  const TITLE_MISS_BACKOFF_MAX_MS = 300_000;
529
581
  const TITLE_MEMO_MAX = 200;
530
- function missBackoff(misses) {
531
- return Math.min(TITLE_MISS_BACKOFF_MS * 2 ** Math.max(0, misses - 1), TITLE_MISS_BACKOFF_MAX_MS);
582
+ function missBackoff(misses, base = TITLE_MISS_BACKOFF_MS) {
583
+ return Math.min(base * 2 ** Math.max(0, misses - 1), TITLE_MISS_BACKOFF_MAX_MS);
532
584
  }
533
- function memoTitle(key, lookup, now = Date.now()) {
585
+ /*
586
+ * 记忆化。查到的值原样存着(默认是标题字符串,opencode 那条存的是
587
+ * `{title, directory}` 一个小对象——这里只管「命中就不再查」,不管值是什么形状)。
588
+ *
589
+ * `missRetryMs` 只有 opencode 那条路在改:它的「没查到」有两种成因,一种会自己好
590
+ * (对账窗口里那行 part 还没落盘,一两秒后就有了),一种不会(这个客户端根本不是
591
+ * opencode)。默认那套 20s→5min 的指数退避是为后者设计的,用在它身上会把第一种
592
+ * 挡死——而 refreshAgentInfo 的 TTL 只有 5s,退避比 TTL 长等于永远等不到重试。
593
+ */
594
+ function memoTitle(key, lookup, now = Date.now(), missRetryMs = null) {
534
595
  const hit = titleMemo.get(key);
535
596
  if (hit && (hit.title || now < hit.nextTryAt)) return hit.title;
536
597
  let title = null;
@@ -541,7 +602,7 @@ function memoTitle(key, lookup, now = Date.now()) {
541
602
  }
542
603
  if (titleMemo.size >= TITLE_MEMO_MAX) titleMemo.clear();
543
604
  const misses = title ? 0 : (hit?.misses || 0) + 1;
544
- titleMemo.set(key, { title, misses, nextTryAt: now + missBackoff(misses) });
605
+ titleMemo.set(key, { title, misses, nextTryAt: now + missBackoff(misses, missRetryMs ?? TITLE_MISS_BACKOFF_MS) });
545
606
  return title;
546
607
  }
547
608
 
@@ -837,9 +898,14 @@ export function readDshSession(local, { env = process.env, home = osMod.homedir(
837
898
  return { id, title: title || null, cwd: cwd || null };
838
899
  }
839
900
 
840
- /* 会话 id 进路径与提取流程前的锚(安全边界,勿放宽):只放行 UUID 形状,`..`、`/`、
841
- * 引号一概进不来——id 来自 MCP 调用方给的 _meta,是外部输入 */
842
- const AG_CONV_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
901
+ /* 会话 id 进路径、SQL 与提取流程前的锚(安全边界,勿放宽):只放行 UUID 形状,`..`、`/`、
902
+ * 引号一概进不来——id 来自 MCP 调用方给的 _meta,是外部输入。
903
+ *
904
+ * Antigravity 的 conversation_id、Codex 的 thread_id、WorkBuddy 的 conversationId 是同一个
905
+ * 形状,**共用这一个 RegExp 对象**:三家的 id 分别会被拼进文件路径、sqlite 的 SQL 字符串、
906
+ * 以及 server.mjs 的 sidFor 拼进扩展侧那张全局 sessions Map 的键。各写一份正则就是
907
+ * 「将来只改一边,一边收一边不收」。 */
908
+ const CONV_UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
843
909
 
844
910
  export function antigravityDataDir(clientCommand, { home = osMod.homedir() } = {}) {
845
911
  const m = /--app_data_dir[ =]([\w.-]+)/.exec(String(clientCommand || ""));
@@ -853,7 +919,7 @@ const AG_DB_MAX = 256 << 20;
853
919
 
854
920
  export function antigravityConversationId(meta) {
855
921
  const id = meta && typeof meta === "object" ? String(meta["antigravity.google/conversation_id"] || "").trim() : "";
856
- return AG_CONV_RE.test(id) ? id : null;
922
+ return CONV_UUID_RE.test(id) ? id : null;
857
923
  }
858
924
 
859
925
  function readVarint(buf, i) {
@@ -924,6 +990,226 @@ export function readAntigravityWorkspace(meta, local, { fs = fsMod, home = osMod
924
990
  return dir;
925
991
  }
926
992
 
993
+ const AG_META_STEP = 23;
994
+ const AG_META_FIELD = 30;
995
+ const AG_TITLE_FIELD = 4;
996
+ const AG_GOAL_FIELD = 19;
997
+ const AG_TMP_PREFIX = "ag-title-";
998
+ const AG_STEP_MAX = 64 << 10;
999
+ const AG_STEP_ROWS = 16;
1000
+ const AG_OUT_MAX = 8 << 20;
1001
+
1002
+ function agLenField(buf, field) {
1003
+ let i = 0;
1004
+ while (i < buf.length) {
1005
+ const tag = readVarint(buf, i);
1006
+ if (!tag) return null;
1007
+ const num = Math.floor(tag.value / 8);
1008
+ const wire = tag.value % 8;
1009
+ if (num === 0) return null;
1010
+ i = tag.next;
1011
+ if (wire === 2) {
1012
+ const len = readVarint(buf, i);
1013
+ if (!len || len.next + len.value > buf.length) return null;
1014
+ if (num === field) return buf.subarray(len.next, len.next + len.value);
1015
+ i = len.next + len.value;
1016
+ } else if (wire === 0) {
1017
+ const v = readVarint(buf, i);
1018
+ if (!v) return null;
1019
+ i = v.next;
1020
+ } else if (wire === 5) {
1021
+ i += 4;
1022
+ } else if (wire === 1) {
1023
+ i += 8;
1024
+ } else {
1025
+ return null;
1026
+ }
1027
+ }
1028
+ return null;
1029
+ }
1030
+
1031
+ function agTitleFromRows(rows) {
1032
+ let fallback = null;
1033
+ for (const row of rows) {
1034
+ const metaMsg = agLenField(row, AG_META_FIELD);
1035
+ if (!metaMsg) continue;
1036
+ const t = agLenField(metaMsg, AG_TITLE_FIELD);
1037
+ if (t) {
1038
+ const s = clip(t.toString("utf8"), 60);
1039
+ if (s) return s;
1040
+ }
1041
+ if (fallback === null) {
1042
+ const g = agLenField(metaMsg, AG_GOAL_FIELD);
1043
+ if (g) fallback = clip(g.toString("utf8"), 60);
1044
+ }
1045
+ }
1046
+ return fallback;
1047
+ }
1048
+
1049
+ export function readAntigravitySessionTitle(meta, local, { fs = fsMod, home = osMod.homedir(), exec = execFileSync, tmpdir = osMod.tmpdir } = {}) {
1050
+ const id = antigravityConversationId(meta);
1051
+ if (!id) return null;
1052
+ const db = path.join(antigravityDataDir(local?.clientCommand, { home }), "conversations", `${id}.db`);
1053
+ return memoTitle(`ag:${id}`, () => {
1054
+ if (fs.statSync(db).size > AG_DB_MAX) return null;
1055
+ const dir = fs.mkdtempSync(path.join(tmpdir(), AG_TMP_PREFIX));
1056
+ try {
1057
+ const copy = path.join(dir, "conversation.db");
1058
+ fs.copyFileSync(db, copy);
1059
+ try {
1060
+ if (fs.statSync(`${db}-wal`).size <= AG_DB_MAX) fs.copyFileSync(`${db}-wal`, `${copy}-wal`);
1061
+ } catch {}
1062
+ const out = exec(
1063
+ process.platform === "win32" ? "sqlite3" : "/usr/bin/sqlite3",
1064
+ [copy, `select hex(step_payload) from steps where step_type = ${AG_META_STEP} and length(step_payload) <= ${AG_STEP_MAX} order by idx limit ${AG_STEP_ROWS}`],
1065
+ { encoding: "utf8", timeout: 2000, maxBuffer: AG_OUT_MAX }
1066
+ );
1067
+ const rows = [];
1068
+ for (const line of String(out || "").split("\n")) {
1069
+ const hex = line.trim();
1070
+ if (hex && /^(?:[0-9a-f]{2})+$/i.test(hex)) rows.push(Buffer.from(hex, "hex"));
1071
+ }
1072
+ return agTitleFromRows(rows);
1073
+ } finally {
1074
+ try {
1075
+ fs.rmSync(dir, { recursive: true, force: true });
1076
+ } catch {}
1077
+ }
1078
+ });
1079
+ }
1080
+
1081
+ const CODEX_INDEX_MAX = 16 << 20;
1082
+ const CODEX_INDEX_TAIL = 4 << 20;
1083
+
1084
+ export function codexHome({ env = process.env, home = osMod.homedir() } = {}) {
1085
+ const d = typeof env?.CODEX_HOME === "string" ? env.CODEX_HOME.trim() : "";
1086
+ return d || path.join(home, ".codex");
1087
+ }
1088
+
1089
+ export function codexThreadId(meta) {
1090
+ if (!meta || typeof meta !== "object") return null;
1091
+ const turn = meta["x-codex-turn-metadata"];
1092
+ const nested = turn && typeof turn === "object" ? String(turn.thread_id ?? "").trim() : "";
1093
+ const id = nested || String(meta.threadId ?? "").trim();
1094
+ return CONV_UUID_RE.test(id) ? id : null;
1095
+ }
1096
+
1097
+ export function readCodexSessionTitle(meta, { env = process.env, home = osMod.homedir(), fs = fsMod } = {}) {
1098
+ const id = codexThreadId(meta);
1099
+ if (!id) return null;
1100
+ const file = path.join(codexHome({ env, home }), "session_index.jsonl");
1101
+ return memoTitle(`codex:${file}:${id}`, () => {
1102
+ let size = 0;
1103
+ try {
1104
+ size = fs.statSync(file).size;
1105
+ } catch {
1106
+ return null;
1107
+ }
1108
+ let text;
1109
+ if (size > CODEX_INDEX_MAX && fs.openSync && fs.readSync) {
1110
+ const fd = fs.openSync(file, "r");
1111
+ try {
1112
+ const buf = Buffer.alloc(CODEX_INDEX_TAIL);
1113
+ const n = fs.readSync(fd, buf, 0, CODEX_INDEX_TAIL, size - CODEX_INDEX_TAIL);
1114
+ text = buf.toString("utf8", 0, n);
1115
+ } finally {
1116
+ try {
1117
+ fs.closeSync(fd);
1118
+ } catch {}
1119
+ }
1120
+ } else {
1121
+ text = fs.readFileSync(file, "utf8");
1122
+ }
1123
+ const needle = `"id":"${id}"`;
1124
+ const lines = String(text).split("\n");
1125
+ for (let i = lines.length - 1; i >= 0; i--) {
1126
+ if (!lines[i].includes(needle)) continue;
1127
+ let d = null;
1128
+ try {
1129
+ d = JSON.parse(lines[i]);
1130
+ } catch {
1131
+ continue;
1132
+ }
1133
+ if (!d || d.id !== id) continue;
1134
+ return clip(d.thread_name, 60);
1135
+ }
1136
+ return null;
1137
+ });
1138
+ }
1139
+
1140
+ export function opencodeDataDir({ env = process.env, home = osMod.homedir() } = {}) {
1141
+ const xdg = typeof env.XDG_DATA_HOME === "string" ? env.XDG_DATA_HOME.trim() : "";
1142
+ return path.join(xdg || path.join(home, ".local", "share"), "opencode");
1143
+ }
1144
+
1145
+ export function isOpencodeClient(clientCommand) {
1146
+ const s = String(clientCommand || "");
1147
+ if (/[\\/]OpenCode\.app[\\/]Contents[\\/]MacOS[\\/]/i.test(s)) return true;
1148
+ return /(^|[\\/\s])opencode(\.exe)?(\s|$)/i.test(s);
1149
+ }
1150
+
1151
+ const OPENCODE_CALL_WINDOW_MS = 3000;
1152
+ const OPENCODE_MISS_RETRY_MS = 2000;
1153
+ const OPENCODE_PART_HEAD = 240;
1154
+
1155
+ function opencodeRealTitle(v) {
1156
+ const s = clip(v, 60);
1157
+ if (!s) return null;
1158
+ return s.startsWith("New session - ") ? null : s;
1159
+ }
1160
+
1161
+ function sameDir(a, b) {
1162
+ const norm = (p) => {
1163
+ const s = path.resolve(String(p || ""));
1164
+ return process.platform === "win32" ? s.toLowerCase() : s;
1165
+ };
1166
+ return norm(a) === norm(b);
1167
+ }
1168
+
1169
+ export function opencodeSessionOf(tool, at, { env = process.env, home = osMod.homedir(), fs = fsMod, exec = execFileSync, cwd = process.cwd() } = {}) {
1170
+ const name = typeof tool === "string" ? tool.trim() : "";
1171
+ const t = Number(at);
1172
+ if (!name || !Number.isFinite(t)) return null;
1173
+ if (!/^[a-z][a-z0-9_]{0,60}$/.test(name)) return null;
1174
+ const db = path.join(opencodeDataDir({ env, home }), "opencode.db");
1175
+ if (!fs.existsSync(db)) return null;
1176
+ return memoTitle(
1177
+ `opencode:${db}:${name}:${t}`,
1178
+ () => {
1179
+ const sql =
1180
+ `select p.session_id as sid, substr(p.data,1,${OPENCODE_PART_HEAD}) as head, ` +
1181
+ "s.title as title, s.directory as dir from part p " +
1182
+ "left join session s on s.id = p.session_id " +
1183
+ `where p.time_created between ${t - OPENCODE_CALL_WINDOW_MS} and ${t + OPENCODE_CALL_WINDOW_MS}`;
1184
+ const out = exec("/usr/bin/sqlite3", ["-readonly", "-cmd", ".mode json", db, sql], {
1185
+ encoding: "utf8",
1186
+ timeout: 2000,
1187
+ });
1188
+ let rows = null;
1189
+ try {
1190
+ rows = JSON.parse(String(out || "").trim() || "[]");
1191
+ } catch {
1192
+ return null;
1193
+ }
1194
+ if (!Array.isArray(rows)) return null;
1195
+ const toolRe = new RegExp('"tool":"[^"]*_' + name + '"');
1196
+ const hits = rows.filter((r) => r && typeof r.head === "string" && toolRe.test(r.head));
1197
+ const sids = [...new Set(hits.map((r) => String(r.sid || "")))].filter(Boolean);
1198
+ if (sids.length !== 1) return null;
1199
+ if (!/^ses_[A-Za-z0-9]+$/.test(sids[0])) return null;
1200
+ const row = hits.find((r) => String(r.sid) === sids[0]);
1201
+ if (!row) return null;
1202
+ const dir = typeof row.dir === "string" && row.dir ? row.dir : null;
1203
+ if (dir && !sameDir(dir, cwd)) return null;
1204
+ const title = opencodeRealTitle(row.title);
1205
+ if (!title && !dir) return null;
1206
+ return { title, directory: dir };
1207
+ },
1208
+ Date.now(),
1209
+ OPENCODE_MISS_RETRY_MS
1210
+ );
1211
+ }
1212
+
927
1213
  /*
928
1214
  * 现在这一刻的会话标题。
929
1215
  *
@@ -934,19 +1220,27 @@ export function readAntigravityWorkspace(meta, local, { fs = fsMod, home = osMod
934
1220
  * 分不出是哪段对话时(整个 app 共用一个 MCP 进程、帧里又没有会话身份)一律返回 null,
935
1221
  * 不拿时间窗口去猜。
936
1222
  */
937
- export function readSessionTitle(local, { fs = fsMod, home = osMod.homedir(), env = process.env, exec = execFileSync, alive = pidAlive, meta = null, dsh } = {}) {
1223
+ export function readSessionTitle(local, { fs = fsMod, home = osMod.homedir(), env = process.env, exec = execFileSync, alive = pidAlive, meta = null, dsh, tool = null, at = null } = {}) {
938
1224
  if (!local) return null;
939
1225
  const zc = readZcodeSessionTitle(meta, { env, home, fs, exec });
940
1226
  if (zc) return zc;
941
1227
  const tr = readTraeSessionTitle(meta, { fs, dataDir: traeDataDir({ userDataDir: local.userDataDir, appDir: local.brandAppDir, env, fs, home }) });
942
1228
  if (tr) return tr;
1229
+ const ag = readAntigravitySessionTitle(meta, local, { fs, home, exec });
1230
+ if (ag) return ag;
1231
+ const cx = readCodexSessionTitle(meta, { env, home, fs });
1232
+ if (cx) return cx;
1233
+ if (isOpencodeClient(local.clientCommand)) {
1234
+ const oc = opencodeSessionOf(tool, at, { env, home, fs, exec });
1235
+ if (oc?.title) return oc.title;
1236
+ }
943
1237
  const ds = dsh !== undefined ? dsh : readDshSession(local, { env, home, fs });
944
1238
  if (ds?.title) return ds.title;
945
1239
  const t = readHostSessionTitle(local.hostSessionId, { fs, home, env });
946
1240
  if (t) return t;
947
1241
  const file = readClientSessionFile(local.clientPid, { fs, home });
948
1242
  if (file && file.nameSource !== "derived") return clip(file.name, 60);
949
- const wb = readWorkbuddySessionTitle({ env, fs, exec, alive });
1243
+ const wb = readWorkbuddySessionTitle({ env, fs, exec, alive, meta, enginePid: local.clientPid });
950
1244
  if (wb) return wb;
951
1245
  return local.sessionName || null;
952
1246
  }
@@ -959,12 +1253,13 @@ export function readSessionTitle(local, { fs = fsMod, home = osMod.homedir(), en
959
1253
  * 那份工作区是进程级的、算一次就定死,所以这里另给一条会话级的出口;没有会话级证据的
960
1254
  * 客户端返回 null,调用方照用进程级的那份。
961
1255
  */
962
- export function readSessionIdentity(local, { fs = fsMod, home = osMod.homedir(), env = process.env, exec = execFileSync, alive = pidAlive, meta = null, tmp } = {}) {
1256
+ export function readSessionIdentity(local, { fs = fsMod, home = osMod.homedir(), env = process.env, exec = execFileSync, alive = pidAlive, meta = null, tmp, tool = null, at = null } = {}) {
963
1257
  if (!local) return { title: null, workspace: null, workspaceKind: null };
964
1258
  const ds = readDshSession(local, { env, home, fs });
965
- const title = readSessionTitle(local, { fs, home, env, exec, alive, meta, dsh: ds });
1259
+ const title = readSessionTitle(local, { fs, home, env, exec, alive, meta, dsh: ds, tool, at });
966
1260
  const agDir = readAntigravityWorkspace(meta, local, { fs, home });
967
- const wsDir = ds?.cwd || agDir;
1261
+ const oc = isOpencodeClient(local.clientCommand) ? opencodeSessionOf(tool, at, { env, home, fs, exec }) : null;
1262
+ const wsDir = ds?.cwd || agDir || oc?.directory;
968
1263
  const ws = wsDir ? readWorkspace(wsDir, tmp !== undefined ? { fs, home, tmp } : { fs, home }) : null;
969
1264
  return { title, workspace: ws?.name || null, workspaceKind: ws?.kind || null };
970
1265
  }