dsh-browser-cdp 1.14.10 → 1.14.12

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/CHANGELOG.md CHANGED
@@ -1,3 +1,36 @@
1
+ ## 1.14.12 (2026-11-25)
2
+
3
+ **引导重开入口从分节底部移到上方。**
4
+
5
+ - 「重新查看引导」现在排在分节首位(`GuidePanel` 之前),与其余八个接了统一引导的插件同形态——跳过之后不必滚到分节底才能重开。跳过标记、十语外壳与三步正文逐字未动(`dsh.guide.browser-cdp.skipped`)。
6
+
7
+ ## 1.14.11 (2026-11-24)
8
+
9
+ **三件事同版出厂:① 页面动作药丸(页面与面板说同一句话)② 首次使用引导(设置分节三步教学)③ 侧栏元数据面(8 项:这页什么状态、谁在驱动)。**
10
+
11
+ ### 一、页面动作药丸
12
+
13
+ 每个 `bcdp_*` 调用前 4s,页面内角标与侧栏/浮窗药丸显示同一句话「DSH · 正在点击」,先把动作说清楚,模型只需补 WHY。
14
+
15
+ - **host 侧单一真源**:`TOOL_ACTION_LABELS`(18 个碰页面的工具)+ `markEgoToolCall(sessionId, toolName)` 把 `{zh,en}` 随 `tool-call` SSE 下发;客户端只选词、不自带第二份表;`bcdp_status`/`bcdp_help` 这类元工具不给动作词("正在读取页面"对它们是假话)。
16
+ - **`withPageOverlay`**:除 `bcdp_wait`(本身就在等人)外的页面工具先打一次页面角标;`bcdp_status` 返回体新增 `overlay` 指引(一条英文说明模型该在批次前后各说一句,不做常驻噪声)。
17
+ - **契约测试**:`action-label-contract`(词表覆盖/长度/双语成对)、`page-overlay`(覆盖层表达式)、`locale-guard` 三档棘轮(C-ui/A-pair/B-log,基线 148/82)。
18
+
19
+ ### 二、首次使用引导
20
+
21
+ 沿 guide-kit 统一契约(与 session-guard / thinking-levels 同形):`guide.tsx` 是 kit 生成副本(会被 sync 覆盖),本插件专属文案只放 `guide-steps.ts`。三步:先连一个浏览器 → 工具是懒注入的(默认只常驻 `bcdp_status`)→ agent 动页面时你能看见。本地标记 `dsh.guide.browser-cdp.skipped` 持久化:跳过/看完都不再自动弹,分节底部恒定留「重新查看引导」。零外部依赖、全程 try/catch,不参与设置数据臂。
22
+
23
+ ### 三、侧栏元数据面(8 项)
24
+
25
+ - **M1–M3/M8(免费项)**:`viewportW/H`、`capturing`、`lastActive` 早已在 spaces 行里推送却无人消费。状态行现在串出 `1200×800 · 3s 前 · agent · 会话 a1b2`;`capturing===false` 追加「未截流」(`true`/未知是常态,不占位);tab 条尾部补 `N 页`。`lastActive<=0` 一律**不显示**——0 是「worker 没采到帧」,不是 1970。
26
+ - **M4**:某 tab 命中人机验证时该行加 `⚠` 角标(title 用既有 captcha 文案),Tab 与浮窗两处都加。
27
+ - **M5/M6(宿主 1 处签名)**:ownership 与「哪个会话在驱动」都走**已有的** `focus` 事件——`TargetFocus` 补 `sessionId?`,`pushFocus(targetId, source, sessionId?)` 第三参可选,`noteToolFocus` 把已握在手里的 `sid` 传下去。客户端首次监听 `event: focus`,维护 `targetId→{source,sessionId}`,同值不触发重渲染,随 spaces 的 live ids 剪枝(不落 localStorage:targetId 是运行时句柄)。
28
+ - **M7(worker 采集)**:`HUMAN_PROBE_JS` 的返回体扩为 `{detected,kind,readyState,dpr}`(同一次 `Runtime.evaluate`,零额外调用);活动 tab 额外一次 `Page.getLayoutMetrics`,用 `layoutViewport.clientWidth / cssLayoutViewport.clientWidth` 推页面 zoom(`outerWidth/innerWidth` 在嵌入/远程场景不准,不采用)。`getLayoutMetrics` 缺席时 try/catch 后 zoom 置 null,spaces 行照旧完整。zoom=100% 与 DPR=1 不显示。
29
+ - **通道治理(只治元数据,帧缓存不动)**:`lastActive` 进渲染前截断到秒;两处 `spaces` SSE 监听包 300ms **尾部合并**(连推 5 条 → 1 次 `store.update`);`frame` 事件仍是零元数据。
30
+ - **实现注记**:格式化抽 `src/client/space-meta.ts`(零中文纯函数,Tab 与浮窗共用同一份字符串),词条放 `src/client/locales.ts` 后 `Object.assign` 进 `watchEn`/`watchZh`——直接写进 `index.ts` 的中文字面量会撞 locale 守卫的硬编码棘轮(基线 148/82 不动)。
31
+
32
+ 门禁:`npm run typecheck` 双 project 干净;`npm test` **1398 passed / 13 skipped**(+27:`space-meta` 单测覆盖 `lastActive=0`、四档距今、`capturing` 三态、zoom=100/80/null、readyState 三态、owner 四种组合、合并器与词条成对;另含 action-label-contract / page-overlay / locale-guard);`npm run build` 后 `lib/client.js` 含 `formatSpaceMeta`/`createSpacesCoalescer`/`truncateLastActive`/`GuidePanel` 与新增文案,`bin/cdp-cast-worker.mjs` 含 `devicePixelRatio`/`Page.getLayoutMetrics`/`cssLayoutViewport`。
33
+
1
34
  ## 1.14.10 (2026-11-22)
2
35
 
3
36
  **插件卫生审计三模式加强:P1 双清单漂移收尾(#19 家族第二轮)× P2 面板散文本地化(search-index#5 家族)× P3 stale build 重建。**
@@ -6660,15 +6660,29 @@ try {
6660
6660
  ...JSON.parse(process.argv[2] || "{}")
6661
6661
  };
6662
6662
  } catch {}
6663
+ /**
6664
+ * One Runtime.evaluate answers three questions the panel used to guess at:
6665
+ * `humanCheck` (unchanged), `readyState` (a page still loading looks dead in a
6666
+ * screenshot) and `dpr` (a 1.25 phone-preview layout explains "why is the text
6667
+ * smaller"). All three ride the SAME 5s-throttled probe — no extra CDP call.
6668
+ */
6663
6669
  const HUMAN_PROBE_JS = `(() => {
6670
+ const readyState=document.readyState,dpr=(window.devicePixelRatio||1);
6664
6671
  const el=document.querySelector('iframe[src*="recaptcha"],.g-recaptcha,.h-captcha,iframe[src*="hcaptcha"],.cf-turnstile,iframe[src*="turnstile"],iframe[src*="cloudflare"],#challenge-form,.challenge-form,#captcha,.captcha');
6665
- if(el)return{detected:true,kind:/recaptcha/i.test(el.outerHTML)?'recaptcha':/hcaptcha/i.test(el.outerHTML)?'hcaptcha':/turnstile/i.test(el.outerHTML)?'turnstile':'captcha'};
6672
+ if(el)return{detected:true,kind:/recaptcha/i.test(el.outerHTML)?'recaptcha':/hcaptcha/i.test(el.outerHTML)?'hcaptcha':/turnstile/i.test(el.outerHTML)?'turnstile':'captcha',readyState:readyState,dpr:dpr};
6666
6673
  const t=((document.body&&document.body.innerText)||'').slice(0,120000).toLowerCase();
6667
- return /verify you are human|your activity looks unusual|captcha|i.?m not a robot|人机验证|安全验证|我是人类|验证码|滑块验证/.test(t)?{detected:true,kind:'captcha'}:{detected:false,kind:null};
6674
+ return /verify you are human|your activity looks unusual|captcha|i.?m not a robot|人机验证|安全验证|我是人类|验证码|滑块验证/.test(t)?{detected:true,kind:'captcha',readyState:readyState,dpr:dpr}:{detected:false,kind:null,readyState:readyState,dpr:dpr};
6668
6675
  })()`;
6669
6676
  const sseClients = /* @__PURE__ */ new Set();
6670
6677
  const videoClients = /* @__PURE__ */ new Set();
6671
6678
  const probeCache = /* @__PURE__ */ new Map();
6679
+ /**
6680
+ * Page zoom per target, kept apart from `probeCache` on purpose: the two are
6681
+ * written by different round-trips and must not overwrite each other.
6682
+ * `zoom: null` = "asked and could not know" (a backend without
6683
+ * Page.getLayoutMetrics) — the panel then shows nothing rather than a guess.
6684
+ */
6685
+ const zoomCache = /* @__PURE__ */ new Map();
6672
6686
  const frameCache = /* @__PURE__ */ new Map();
6673
6687
  const winCache = /* @__PURE__ */ new Map();
6674
6688
  const chromeFrameCache = /* @__PURE__ */ new Map();
@@ -7054,6 +7068,36 @@ async function activeTargetInfo(known, sessionId) {
7054
7068
  async function activeTargetId(sessionId) {
7055
7069
  return (await activeTargetInfo(void 0, sessionId)).id;
7056
7070
  }
7071
+ /**
7072
+ * Page zoom for one target, on the same 5s cadence as the probe.
7073
+ *
7074
+ * Why the ratio of two viewports: `layoutViewport.clientWidth` is in CSS pixels
7075
+ * BEFORE zoom and `cssLayoutViewport.clientWidth` is the visual width, so their
7076
+ * ratio IS the zoom factor (1 = 100%). `outerWidth/innerWidth` was rejected — it
7077
+ * reports the browser chrome and is wrong for embedded/remote targets.
7078
+ *
7079
+ * Never throws into the caller: `Page.getLayoutMetrics` is absent on some CDP
7080
+ * variants, and a metadata probe must not cost a spaces row.
7081
+ */
7082
+ function probeZoom(browser, targetId, now) {
7083
+ const cached = zoomCache.get(targetId);
7084
+ if (cached !== void 0 && now - cached.at <= 5e3) return;
7085
+ browser.sessions.call(targetId, "Page.getLayoutMetrics", {}, 3e3).then((raw) => {
7086
+ const metrics = raw || {};
7087
+ const layoutW = Number(metrics.layoutViewport?.clientWidth);
7088
+ const cssW = Number(metrics.cssLayoutViewport?.clientWidth);
7089
+ const pct = Number.isFinite(layoutW) && Number.isFinite(cssW) && cssW > 0 ? Math.round(layoutW / cssW * 100) : 0;
7090
+ zoomCache.set(targetId, {
7091
+ at: Date.now(),
7092
+ zoom: pct > 0 ? pct : null
7093
+ });
7094
+ }).catch(() => {
7095
+ zoomCache.set(targetId, {
7096
+ at: Date.now(),
7097
+ zoom: null
7098
+ });
7099
+ });
7100
+ }
7057
7101
  async function snapshotSpaces(sessionId) {
7058
7102
  const browser = active;
7059
7103
  if (browser === null) return [];
@@ -7062,11 +7106,12 @@ async function snapshotSpaces(sessionId) {
7062
7106
  const activeId = activeInfo.id;
7063
7107
  const capturingIds = new Set(currentStatus.targetIds ?? (currentStatus.targetId ? [currentStatus.targetId] : []));
7064
7108
  const spaces = [];
7109
+ const now = Date.now();
7065
7110
  for (const target of targets.slice(0, 30)) {
7066
7111
  const frame = frameCache.get(target.targetId);
7067
7112
  const session = browser.sessions.get(target.targetId);
7068
7113
  const cached = probeCache.get(target.targetId);
7069
- if (!cached || Date.now() - cached.at > 5e3) browser.sessions.call(target.targetId, "Runtime.evaluate", {
7114
+ if (!cached || now - cached.at > 5e3) browser.sessions.call(target.targetId, "Runtime.evaluate", {
7070
7115
  expression: HUMAN_PROBE_JS,
7071
7116
  returnByValue: true,
7072
7117
  awaitPromise: false
@@ -7077,6 +7122,8 @@ async function snapshotSpaces(sessionId) {
7077
7122
  human: r.result?.value || null
7078
7123
  });
7079
7124
  }).catch(() => {});
7125
+ if (target.targetId === activeId) probeZoom(browser, target.targetId, now);
7126
+ const probe = cached?.human ?? null;
7080
7127
  spaces.push({
7081
7128
  targetId: target.targetId,
7082
7129
  url: target.url,
@@ -7087,9 +7134,17 @@ async function snapshotSpaces(sessionId) {
7087
7134
  lastActive: frame?.lastActive || 0,
7088
7135
  viewportW: frame?.viewportW || session?.viewportW,
7089
7136
  viewportH: frame?.viewportH || session?.viewportH,
7090
- humanCheck: cached?.human || null
7137
+ humanCheck: probe === null ? null : {
7138
+ detected: probe.detected === true,
7139
+ kind: probe.kind ?? null
7140
+ },
7141
+ readyState: probe?.readyState,
7142
+ dpr: probe?.dpr,
7143
+ zoom: zoomCache.get(target.targetId)?.zoom ?? null
7091
7144
  });
7092
7145
  }
7146
+ const liveIds = new Set(targets.map((target) => target.targetId));
7147
+ for (const id of [...zoomCache.keys()]) if (!liveIds.has(id)) zoomCache.delete(id);
7093
7148
  spaces.sort((a, b) => Number(b.active) - Number(a.active) || b.lastActive - a.lastActive);
7094
7149
  return spaces;
7095
7150
  }
package/dsh-plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
3
3
  "id": "dsh-browser-cdp",
4
4
  "name": "dsh-browser-cdp",
5
- "version": "1.14.10",
5
+ "version": "1.14.12",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {