@shgroup/dsh-serenity-hooks 1.129.2 → 1.129.4

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/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-serenity-hooks",
3
- "version": "1.129.2",
3
+ "version": "1.129.4",
4
4
  "main": "lib/index.js",
5
5
  "description": "宁静号 ACC harness(Native Cordis 插件):给 DSH 装一个「AI 工作区」——14 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin/browser_slot;另三个 im-bridge/diagram/reconstruct 按条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/IM 桥/认知轨迹唤醒注册表 + 浏览器槽位管理(≤20 个独立 profile 的 Chrome 槽位,带占用归属与异常时向所属会话反向注入提醒)。轨迹声明 = 轨迹目录下的 trajectory.json(约束面 + 旧标识 uid + CRO 机器绑定 cro.host;旧名 trajectory-constraint.json / skiff.json 仍在读取族里);轨迹提示词 = 轨迹目录下的 PROMPT.md(一条轨迹「是谁、按什么章程工作」,所有轨迹通用,追加在容器层与质量层之后,不替换它们)。适配 DSH 0.1.7-rc.1 / 0.2.0-rc.1 / 0.2.1-rc.1(三档,deepseek-ai/deepseek-harness)。",
6
6
  "engines": {
@@ -53,6 +53,18 @@ export declare function navigate(slot: number, targetId: string, url: string): P
53
53
  export declare function openTab(slot: number, url: string): Promise<string>;
54
54
  /** 关标签页(`all=true` 关全部 page 类型的) */
55
55
  export declare function closeTab(slot: number, targetId: string, all?: boolean): Promise<string[]>;
56
+ /**
57
+ * 真实鼠标点击(CDP `Input.dispatchMouseEvent`)。
58
+ *
59
+ * 🔴 **为什么不用 `el.click()`**:它只派发一次合成 `click`,**不产生 pointerdown/mousedown/mouseup**,
60
+ * 也不做命中测试。React/Vue 之外的大量组件库(含 `choerodon-ui`、多数下拉/浮层)
61
+ * 监听的是 `pointerdown`/`mousedown` ⇒ 用 `el.click()` 会得到"脚本执行成功、界面毫无反应",
62
+ * 而那正是最难查的一种——**没报错,也没发生**。
63
+ *
64
+ * 🔴 顺序与坐标:`mouseMoved` → `mousePressed` → `mouseReleased`,三次同一坐标。
65
+ * ⛔ 不发 `mousePressed` 就发 `mouseReleased` 会被 Chrome 丢弃(且**不报错**)。
66
+ */
67
+ export declare function clickAt(slot: number, targetId: string, x: number, y: number): Promise<void>;
56
68
  /** 正文(`document.body.innerText`) */
57
69
  export declare function pageText(slot: number, targetId: string): Promise<string>;
58
70
  /** HTML(默认截断 4000,同既有实现) */
@@ -0,0 +1,60 @@
1
+ /**
2
+ * click-target.ts — 「按语义点一个元素」的**纯判定**(选中谁),执行在 cdp.ts。
3
+ *
4
+ * 🔴🔴 为什么这一格比 `--match`(选 tab)要求更严:
5
+ * **选错 tab 只是退回来,点错元素是已经发生的事。** 少一步、少一次 `targets` 是便利,
6
+ * 但便利必须由**判定**承担,不能由"猜"承担 —— 猜错点下去的按钮不会自己撤销。
7
+ *
8
+ * 判据(四条,都是"宁可拒绝"):
9
+ * ① **0 命中 ⇒ 拒绝**,并把页面上可见的可点元素列一批(让调用方一眼改对)。
10
+ * ② **多命中 ⇒ 拒绝**,列全部候选。⛔ 不选"第一个""最像的""最上层的"。
11
+ * ③ **命中但不可点**(`disabled` / `aria-disabled=true` / 零尺寸 / `pointer-events:none`)
12
+ * ⇒ **拒绝**,并说明是哪一条。⛔ 不"尽力点一下试试"—— 点了没反应与点了没点,
13
+ * 在下一次读数里**看起来一样**,而这正是最难查的那种错。
14
+ * ④ **可见文本取"渲染后的文本"**,不取 `textContent`:后者含 `display:none` 与
15
+ * `<script>` 里的字,会让"匹配到了"与"屏幕上真看得见"变成两件事。
16
+ *
17
+ * ⛔ **刻意不做的事**:不点 `<input type="file">`(会开系统文件选择器,把自动化卡死)、
18
+ * 不点带 `download` 的链接(会产生本工具不追踪的落盘)。
19
+ */
20
+ /** 在页面里跑的采集器:把可点元素压成一份小表。 */
21
+ export declare const COLLECT_CLICKABLE = "(() => {\n const sel = 'a,button,input,textarea,select,summary,label,[role=button],[role=link],[role=tab],[role=menuitem],[onclick]';\n const out = [];\n let i = 0;\n for (const el of document.querySelectorAll(sel)) {\n if (i >= 400) break;\n const r = el.getBoundingClientRect();\n const cs = getComputedStyle(el);\n if (cs.display === 'none' || cs.visibility === 'hidden') continue;\n const type = (el.getAttribute('type') || '').toLowerCase();\n if (el.tagName === 'INPUT' && type === 'file') continue;\n const text = ((el.innerText || el.value || el.getAttribute('aria-label') || el.getAttribute('title') || '') + '')\n .replace(/\\s+/g, ' ').trim();\n out.push({\n tag: el.tagName.toLowerCase(),\n type,\n text: text.slice(0, 120),\n role: el.getAttribute('role') || '',\n x: Math.round(r.left + r.width / 2),\n y: Math.round(r.top + r.height / 2),\n w: Math.round(r.width),\n h: Math.round(r.height),\n disabled: el.disabled === true || el.getAttribute('aria-disabled') === 'true',\n pointerNone: cs.pointerEvents === 'none',\n download: el.hasAttribute('download'),\n });\n i++;\n }\n return out;\n})()";
22
+ /** 采集器回来的一个元素。 */
23
+ export interface Clickable {
24
+ tag: string;
25
+ type: string;
26
+ text: string;
27
+ role: string;
28
+ x: number;
29
+ y: number;
30
+ w: number;
31
+ h: number;
32
+ disabled: boolean;
33
+ pointerNone: boolean;
34
+ download: boolean;
35
+ }
36
+ export type ClickPick = {
37
+ ok: true;
38
+ el: Clickable;
39
+ by: 'xy' | 'text';
40
+ } | {
41
+ ok: false;
42
+ reason: 'no-candidate' | 'not-found' | 'ambiguous' | 'not-clickable';
43
+ hits: Clickable[];
44
+ why?: string;
45
+ };
46
+ /**
47
+ * 挑一个元素。
48
+ *
49
+ * @param list `COLLECT_CLICKABLE` 的结果
50
+ * @param opts `xy` = 直接给坐标(⛔ 不参与文本匹配);`text` = 可见文本子串(大小写不敏感)
51
+ */
52
+ export declare function pickClickable(list: Clickable[], opts: {
53
+ xy?: {
54
+ x: number;
55
+ y: number;
56
+ };
57
+ text?: string;
58
+ }): ClickPick;
59
+ /** 把候选渲染成「可以照着改」的几行。 */
60
+ export declare function renderClickables(list: Clickable[], max?: number): string;
@@ -13,6 +13,7 @@
13
13
  import { type SlotPolicy, type SlotState } from './state.js';
14
14
  import { type CdpTarget } from './cdp.js';
15
15
  import { type ExtEntry, type ExtRunResult } from './extend.js';
16
+ import { type Clickable } from './click-target.js';
16
17
  /**
17
18
  * 动作枚举(对外暴露的唯一清单)
18
19
  *
@@ -26,7 +27,7 @@ import { type ExtEntry, type ExtRunResult } from './extend.js';
26
27
  * 裸端口会让「这是谁的浏览器」变成一个隐含状态。
27
28
  * 先例 `browser` MSM 收 `--port=` —— 那正是它和槽位体系断开的那个口子。
28
29
  */
29
- export declare const SLOT_ACTIONS: readonly ["acquire", "release", "list", "status", "reap", "doctor", "targets", "open", "goto", "eval", "text", "html", "shot", "reload", "close", "ext-list", "ext"];
30
+ export declare const SLOT_ACTIONS: readonly ["acquire", "release", "list", "status", "reap", "doctor", "targets", "open", "goto", "eval", "text", "html", "shot", "reload", "close", "click", "ext-list", "ext"];
30
31
  export type SlotAction = (typeof SLOT_ACTIONS)[number];
31
32
  /** 哪些动作需要 `--slot`(页面层 + ext 需要,槽位层不需要) */
32
33
  export declare const ACTIONS_NEED_SLOT: ReadonlySet<SlotAction>;
@@ -132,6 +133,41 @@ export declare function doctorSlots(root: string, policy?: SlotPolicy): Record<s
132
133
  * —— 一旦放宽,归属就从"机制"退回成"习惯"。
133
134
  */
134
135
  export declare function assertSlotOwned(root: string, slot: number, sessionId: string): void;
136
+ /**
137
+ * 解析「要操作哪个 target」——`--target`(身份)或 `--match`(子串线索)二选一。
138
+ *
139
+ * 🔴 **为什么必须有这一层**:`--match` 之前,用户要先跑 `targets` 抄一个 32 位 id 再回来
140
+ * (owner 2026-11-10 反馈:`msm cdp shot --match` 少一步,`browser_slot` 非要先取 targetId)。
141
+ * 但"少一步"的代价必须由**判定**承担,不能由"猜"承担 —— 见 `target-pick.ts` 的四条判据。
142
+ *
143
+ * 🔴 **判据优先级**:`--target` 在则不读 `--match`(身份 > 线索)。
144
+ * ⛔ 不做"给了 target 找不到就回落到 match" —— 那会把打错的 id 变成"恰好相符的另一个页面"。
145
+ *
146
+ * @returns 解析好的 targetId(**唯一**),或抛出可读错误(0 命中 / 多命中都把候选列全)
147
+ */
148
+ export declare function resolveTarget(root: string, slot: number, sessionId: string, opts: {
149
+ target?: string;
150
+ match?: string;
151
+ }): Promise<string>;
152
+ /**
153
+ * 语义化点击:`--text` 子串或 `--xy` 坐标。
154
+ *
155
+ * 🔴 判定在 `click-target.ts`(0 命中/多命中/不可点 **全部拒绝**)。
156
+ * 这一层只做两件它必须做的事:**采集**(跑一次 `COLLECT_CLICKABLE`)与**执行**(真鼠标事件)。
157
+ *
158
+ * ⚠️ **返回的是"点了什么"**,不是"点成功了"。⛔ 不在这里等界面变化 ——
159
+ * 等多久、等什么,属于调用方的判断(本工具不知道这个按钮应该产生什么后果)。
160
+ */
161
+ export declare function slotClick(root: string, slot: number, sessionId: string, targetId: string, opts: {
162
+ text?: string;
163
+ xy?: {
164
+ x: number;
165
+ y: number;
166
+ };
167
+ }): Promise<{
168
+ picked: Clickable;
169
+ total: number;
170
+ }>;
135
171
  /** 列当前槽位上的 targets */
136
172
  export declare function slotTargets(root: string, slot: number, sessionId: string): Promise<CdpTarget[]>;
137
173
  /** 新开标签页 */
@@ -0,0 +1,43 @@
1
+ /**
2
+ * target-pick.ts — 「按 URL / 标题子串挑一个 target」的**纯判定**。
3
+ *
4
+ * 🔴 为什么要单独一个文件、且必须是纯函数:
5
+ * `browser_slot shot --match <子串>` 的第一诉求是"少一步 `targets`",
6
+ * 而**最坏的结果是多挑了一个 tab 去截图** —— 那会产出一张**看起来对、内容却属于别人**的图,
7
+ * 零报错、零信号。所以判定规则要能单测,且判据必须写得下"我不猜"。
8
+ *
9
+ * 判据(每条都是被否方案换来的):
10
+ * ① **0 个命中 ⇒ 不猜**(不回落"唯一那个 tab",也不算"当前激活页")。
11
+ * ② **多个命中 ⇒ 不猜**(要求更长的子串),且回执把候选**列全**。
12
+ * ③ ⛔ **不静默优先级**("优先 title 再 url"这类)—— 命中语义不同的两处仍算多命中。
13
+ * ④ `exact`(`--target` 直接给 id)永远优先,且**不参与子串匹配** ——
14
+ * id 是身份,子串是线索,两者的可信度不同级。
15
+ */
16
+ /** 一个 target 的最小视图(与 cdp.ts 的 CdpTarget 同形,这里不 import 以免循环依赖)。 */
17
+ export interface PickableTarget {
18
+ id: string;
19
+ type: string;
20
+ title: string;
21
+ url: string;
22
+ }
23
+ export type PickResult = {
24
+ ok: true;
25
+ target: PickableTarget;
26
+ by: 'id' | 'match';
27
+ } | {
28
+ ok: false;
29
+ reason: 'empty' | 'not-found' | 'ambiguous';
30
+ hits: PickableTarget[];
31
+ };
32
+ /**
33
+ * 挑一个 target。
34
+ *
35
+ * @param list 当前槽位上的全部 target(`/json/list` 原样)
36
+ * @param opts `id` = 直接给 targetId;`match` = URL 或 title 的子串(大小写不敏感)
37
+ */
38
+ export declare function pickTarget(list: PickableTarget[], opts: {
39
+ id?: string;
40
+ match?: string;
41
+ }): PickResult;
42
+ /** 把候选渲染成「可以照着改」的几行(多命中回执用)。 */
43
+ export declare function renderHits(hits: PickableTarget[], max?: number): string;
package/lib/index.js CHANGED
@@ -20159,6 +20159,43 @@ async function closeTab(slot, targetId, all = false) {
20159
20159
  conn.ws.close();
20160
20160
  }
20161
20161
  }
20162
+ /**
20163
+ * 真实鼠标点击(CDP `Input.dispatchMouseEvent`)。
20164
+ *
20165
+ * 🔴 **为什么不用 `el.click()`**:它只派发一次合成 `click`,**不产生 pointerdown/mousedown/mouseup**,
20166
+ * 也不做命中测试。React/Vue 之外的大量组件库(含 `choerodon-ui`、多数下拉/浮层)
20167
+ * 监听的是 `pointerdown`/`mousedown` ⇒ 用 `el.click()` 会得到"脚本执行成功、界面毫无反应",
20168
+ * 而那正是最难查的一种——**没报错,也没发生**。
20169
+ *
20170
+ * 🔴 顺序与坐标:`mouseMoved` → `mousePressed` → `mouseReleased`,三次同一坐标。
20171
+ * ⛔ 不发 `mousePressed` 就发 `mouseReleased` 会被 Chrome 丢弃(且**不报错**)。
20172
+ */
20173
+ async function clickAt(slot, targetId, x, y) {
20174
+ const conn = attach(await wsConnect(await pageWsUrl(slot, targetId)));
20175
+ try {
20176
+ const base = {
20177
+ x,
20178
+ y,
20179
+ button: "left",
20180
+ clickCount: 1
20181
+ };
20182
+ await cdpRaw(conn, "Input.dispatchMouseEvent", {
20183
+ type: "mouseMoved",
20184
+ x,
20185
+ y
20186
+ });
20187
+ await cdpRaw(conn, "Input.dispatchMouseEvent", {
20188
+ type: "mousePressed",
20189
+ ...base
20190
+ });
20191
+ await cdpRaw(conn, "Input.dispatchMouseEvent", {
20192
+ type: "mouseReleased",
20193
+ ...base
20194
+ });
20195
+ } finally {
20196
+ conn.ws.close();
20197
+ }
20198
+ }
20162
20199
  /** 正文(`document.body.innerText`) */
20163
20200
  async function pageText(slot, targetId) {
20164
20201
  const v = await evalInPage(slot, targetId, "document.body ? document.body.innerText : ''");
@@ -20456,6 +20493,181 @@ function buildExtPayload(opts) {
20456
20493
  };
20457
20494
  }
20458
20495
  //#endregion
20496
+ //#region src/browser/target-pick.ts
20497
+ /**
20498
+ * 挑一个 target。
20499
+ *
20500
+ * @param list 当前槽位上的全部 target(`/json/list` 原样)
20501
+ * @param opts `id` = 直接给 targetId;`match` = URL 或 title 的子串(大小写不敏感)
20502
+ */
20503
+ function pickTarget(list, opts) {
20504
+ if (opts.id) {
20505
+ const hit = list.find((t) => t.id === opts.id);
20506
+ return hit ? {
20507
+ ok: true,
20508
+ target: hit,
20509
+ by: "id"
20510
+ } : {
20511
+ ok: false,
20512
+ reason: "not-found",
20513
+ hits: []
20514
+ };
20515
+ }
20516
+ const needle = (opts.match ?? "").trim().toLowerCase();
20517
+ if (!needle) return {
20518
+ ok: false,
20519
+ reason: "empty",
20520
+ hits: []
20521
+ };
20522
+ const hits = list.filter((t) => t.type === "page").filter((t) => t.url.toLowerCase().includes(needle) || t.title.toLowerCase().includes(needle));
20523
+ if (hits.length === 0) return {
20524
+ ok: false,
20525
+ reason: "not-found",
20526
+ hits: []
20527
+ };
20528
+ if (hits.length > 1) return {
20529
+ ok: false,
20530
+ reason: "ambiguous",
20531
+ hits
20532
+ };
20533
+ return {
20534
+ ok: true,
20535
+ target: hits[0],
20536
+ by: "match"
20537
+ };
20538
+ }
20539
+ /** 把候选渲染成「可以照着改」的几行(多命中回执用)。 */
20540
+ function renderHits(hits, max = 10) {
20541
+ const shown = hits.slice(0, max);
20542
+ const lines = shown.map((t) => ` ${t.id} ${t.title.slice(0, 40)} ${t.url.slice(0, 90)}`);
20543
+ if (hits.length > shown.length) lines.push(` …另有 ${hits.length - shown.length} 个`);
20544
+ return lines.join("\n");
20545
+ }
20546
+ //#endregion
20547
+ //#region src/browser/click-target.ts
20548
+ /**
20549
+ * click-target.ts — 「按语义点一个元素」的**纯判定**(选中谁),执行在 cdp.ts。
20550
+ *
20551
+ * 🔴🔴 为什么这一格比 `--match`(选 tab)要求更严:
20552
+ * **选错 tab 只是退回来,点错元素是已经发生的事。** 少一步、少一次 `targets` 是便利,
20553
+ * 但便利必须由**判定**承担,不能由"猜"承担 —— 猜错点下去的按钮不会自己撤销。
20554
+ *
20555
+ * 判据(四条,都是"宁可拒绝"):
20556
+ * ① **0 命中 ⇒ 拒绝**,并把页面上可见的可点元素列一批(让调用方一眼改对)。
20557
+ * ② **多命中 ⇒ 拒绝**,列全部候选。⛔ 不选"第一个""最像的""最上层的"。
20558
+ * ③ **命中但不可点**(`disabled` / `aria-disabled=true` / 零尺寸 / `pointer-events:none`)
20559
+ * ⇒ **拒绝**,并说明是哪一条。⛔ 不"尽力点一下试试"—— 点了没反应与点了没点,
20560
+ * 在下一次读数里**看起来一样**,而这正是最难查的那种错。
20561
+ * ④ **可见文本取"渲染后的文本"**,不取 `textContent`:后者含 `display:none` 与
20562
+ * `<script>` 里的字,会让"匹配到了"与"屏幕上真看得见"变成两件事。
20563
+ *
20564
+ * ⛔ **刻意不做的事**:不点 `<input type="file">`(会开系统文件选择器,把自动化卡死)、
20565
+ * 不点带 `download` 的链接(会产生本工具不追踪的落盘)。
20566
+ */
20567
+ /** 在页面里跑的采集器:把可点元素压成一份小表。 */
20568
+ const COLLECT_CLICKABLE = `(() => {
20569
+ const sel = 'a,button,input,textarea,select,summary,label,[role=button],[role=link],[role=tab],[role=menuitem],[onclick]';
20570
+ const out = [];
20571
+ let i = 0;
20572
+ for (const el of document.querySelectorAll(sel)) {
20573
+ if (i >= 400) break;
20574
+ const r = el.getBoundingClientRect();
20575
+ const cs = getComputedStyle(el);
20576
+ if (cs.display === 'none' || cs.visibility === 'hidden') continue;
20577
+ const type = (el.getAttribute('type') || '').toLowerCase();
20578
+ if (el.tagName === 'INPUT' && type === 'file') continue;
20579
+ const text = ((el.innerText || el.value || el.getAttribute('aria-label') || el.getAttribute('title') || '') + '')
20580
+ .replace(/\\s+/g, ' ').trim();
20581
+ out.push({
20582
+ tag: el.tagName.toLowerCase(),
20583
+ type,
20584
+ text: text.slice(0, 120),
20585
+ role: el.getAttribute('role') || '',
20586
+ x: Math.round(r.left + r.width / 2),
20587
+ y: Math.round(r.top + r.height / 2),
20588
+ w: Math.round(r.width),
20589
+ h: Math.round(r.height),
20590
+ disabled: el.disabled === true || el.getAttribute('aria-disabled') === 'true',
20591
+ pointerNone: cs.pointerEvents === 'none',
20592
+ download: el.hasAttribute('download'),
20593
+ });
20594
+ i++;
20595
+ }
20596
+ return out;
20597
+ })()`;
20598
+ /**
20599
+ * 挑一个元素。
20600
+ *
20601
+ * @param list `COLLECT_CLICKABLE` 的结果
20602
+ * @param opts `xy` = 直接给坐标(⛔ 不参与文本匹配);`text` = 可见文本子串(大小写不敏感)
20603
+ */
20604
+ function pickClickable(list, opts) {
20605
+ if (opts.xy) return {
20606
+ ok: true,
20607
+ el: {
20608
+ tag: "",
20609
+ type: "",
20610
+ text: "",
20611
+ role: "",
20612
+ ...opts.xy,
20613
+ w: 0,
20614
+ h: 0,
20615
+ disabled: false,
20616
+ pointerNone: false,
20617
+ download: false
20618
+ },
20619
+ by: "xy"
20620
+ };
20621
+ const needle = (opts.text ?? "").trim().toLowerCase();
20622
+ if (!needle) return {
20623
+ ok: false,
20624
+ reason: "no-candidate",
20625
+ hits: []
20626
+ };
20627
+ const hits = list.filter((e) => e.w > 0 && e.h > 0).filter((e) => e.text.toLowerCase().includes(needle));
20628
+ if (hits.length === 0) return {
20629
+ ok: false,
20630
+ reason: "not-found",
20631
+ hits: []
20632
+ };
20633
+ if (hits.length > 1) return {
20634
+ ok: false,
20635
+ reason: "ambiguous",
20636
+ hits
20637
+ };
20638
+ const el = hits[0];
20639
+ if (el.pointerNone) return {
20640
+ ok: false,
20641
+ reason: "not-clickable",
20642
+ hits,
20643
+ why: "pointer-events:none(点不到它,点击会穿透到下面的元素)"
20644
+ };
20645
+ if (el.disabled) return {
20646
+ ok: false,
20647
+ reason: "not-clickable",
20648
+ hits,
20649
+ why: "disabled(点它不会有任何效果)"
20650
+ };
20651
+ if (el.download) return {
20652
+ ok: false,
20653
+ reason: "not-clickable",
20654
+ hits,
20655
+ why: "download 链接(会产生本工具不追踪的落盘)"
20656
+ };
20657
+ return {
20658
+ ok: true,
20659
+ el,
20660
+ by: "text"
20661
+ };
20662
+ }
20663
+ /** 把候选渲染成「可以照着改」的几行。 */
20664
+ function renderClickables(list, max = 15) {
20665
+ const shown = list.slice(0, max);
20666
+ const lines = shown.map((e) => ` <${e.tag}${e.type ? ` type=${e.type}` : ""}> "${e.text.slice(0, 50)}" @${e.x},${e.y} ${e.w}x${e.h}${e.disabled ? " [disabled]" : ""}`);
20667
+ if (list.length > shown.length) lines.push(` …另有 ${list.length - shown.length} 个`);
20668
+ return lines.join("\n");
20669
+ }
20670
+ //#endregion
20459
20671
  //#region src/browser/service.ts
20460
20672
  /**
20461
20673
  * browser/service.ts — 槽位管理器的动作实现(ACC 级)
@@ -20498,6 +20710,7 @@ const SLOT_ACTIONS = [
20498
20710
  "shot",
20499
20711
  "reload",
20500
20712
  "close",
20713
+ "click",
20501
20714
  "ext-list",
20502
20715
  "ext"
20503
20716
  ];
@@ -20941,6 +21154,75 @@ function assertSlotOwned(root, slot, sessionId) {
20941
21154
  function pageTouched(root, slot) {
20942
21155
  touchSlot(root, slot);
20943
21156
  }
21157
+ /**
21158
+ * 解析「要操作哪个 target」——`--target`(身份)或 `--match`(子串线索)二选一。
21159
+ *
21160
+ * 🔴 **为什么必须有这一层**:`--match` 之前,用户要先跑 `targets` 抄一个 32 位 id 再回来
21161
+ * (owner 2026-11-10 反馈:`msm cdp shot --match` 少一步,`browser_slot` 非要先取 targetId)。
21162
+ * 但"少一步"的代价必须由**判定**承担,不能由"猜"承担 —— 见 `target-pick.ts` 的四条判据。
21163
+ *
21164
+ * 🔴 **判据优先级**:`--target` 在则不读 `--match`(身份 > 线索)。
21165
+ * ⛔ 不做"给了 target 找不到就回落到 match" —— 那会把打错的 id 变成"恰好相符的另一个页面"。
21166
+ *
21167
+ * @returns 解析好的 targetId(**唯一**),或抛出可读错误(0 命中 / 多命中都把候选列全)
21168
+ */
21169
+ async function resolveTarget(root, slot, sessionId, opts) {
21170
+ if (!opts.target && !opts.match) throw new Error("⛔ 需要 --target=<targetId> 或 --match=<URL 或标题子串>。\n ⇒ 先 `browser_slot targets --slot b1` 看有什么,或直接给 --match=example.com");
21171
+ if (opts.target) return opts.target;
21172
+ const list = await slotTargets(root, slot, sessionId);
21173
+ const res = pickTarget(list, { match: opts.match });
21174
+ if (res.ok) return res.target.id;
21175
+ const pages = list.filter((t) => t.type === "page");
21176
+ if (res.reason === "not-found") throw new Error(`⛔ 没有页面匹配「${opts.match}」(匹配 url 或 title,大小写不敏感)。\n ⇒ 当前 ${pages.length} 个页面:\n${renderHits(pages)}`);
21177
+ throw new Error(`⛔ 「${opts.match}」匹配到 ${res.hits.length} 个页面 —— 拒绝替你选一个(选错会产出一张"看起来对、内容却属于别人"的图)。\n ⇒ 换个更长的子串,或用 --target=<id> 点名:\n${renderHits(res.hits)}`);
21178
+ }
21179
+ /**
21180
+ * 语义化点击:`--text` 子串或 `--xy` 坐标。
21181
+ *
21182
+ * 🔴 判定在 `click-target.ts`(0 命中/多命中/不可点 **全部拒绝**)。
21183
+ * 这一层只做两件它必须做的事:**采集**(跑一次 `COLLECT_CLICKABLE`)与**执行**(真鼠标事件)。
21184
+ *
21185
+ * ⚠️ **返回的是"点了什么"**,不是"点成功了"。⛔ 不在这里等界面变化 ——
21186
+ * 等多久、等什么,属于调用方的判断(本工具不知道这个按钮应该产生什么后果)。
21187
+ */
21188
+ async function slotClick(root, slot, sessionId, targetId, opts) {
21189
+ assertSlotOwned(root, slot, sessionId);
21190
+ if (!opts.text && !opts.xy) throw new Error("⛔ 需要 --text=<按钮可见文字> 或 --xy=<x,y>(先 targets 拿 targetId)");
21191
+ if (opts.xy) {
21192
+ await clickAt(slot, targetId, opts.xy.x, opts.xy.y);
21193
+ pageTouched(root, slot);
21194
+ return {
21195
+ picked: {
21196
+ tag: "",
21197
+ type: "",
21198
+ text: "",
21199
+ role: "",
21200
+ ...opts.xy,
21201
+ w: 0,
21202
+ h: 0,
21203
+ disabled: false,
21204
+ pointerNone: false,
21205
+ download: false
21206
+ },
21207
+ total: 0
21208
+ };
21209
+ }
21210
+ const raw = await evalInPage(slot, targetId, COLLECT_CLICKABLE, 15e3);
21211
+ const list = Array.isArray(raw) ? raw : [];
21212
+ const res = pickClickable(list, { text: opts.text });
21213
+ if (!res.ok) {
21214
+ const visible = list.filter((e) => e.w > 0 && e.h > 0);
21215
+ if (res.reason === "ambiguous") throw new Error(`⛔ 「${opts.text}」匹配到 ${res.hits.length} 个可点元素 —— 拒绝替你选(点错是已经发生的事,不会自己撤销)。\n ⇒ 换个更长的文字,或用 --xy=<x,y> 点名:\n${renderClickables(res.hits)}`);
21216
+ if (res.reason === "not-clickable") throw new Error(`⛔ 「${opts.text}」找到了,但${res.why}。\n ⇒ 这不是"尽力点一下"的场合:点了没反应与没点,在读数上一样。\n${renderClickables(res.hits)}`);
21217
+ throw new Error(`⛔ 页面上没有可点元素匹配「${opts.text}」(匹配渲染后的可见文本,含 value/aria-label/title)。\n ⇒ 当前 ${visible.length} 个可见可点元素:\n${renderClickables(visible)}`);
21218
+ }
21219
+ await clickAt(slot, targetId, res.el.x, res.el.y);
21220
+ pageTouched(root, slot);
21221
+ return {
21222
+ picked: res.el,
21223
+ total: list.length
21224
+ };
21225
+ }
20944
21226
  /** 列当前槽位上的 targets */
20945
21227
  async function slotTargets(root, slot, sessionId) {
20946
21228
  assertSlotOwned(root, slot, sessionId);
@@ -21096,6 +21378,33 @@ function needSlot(args) {
21096
21378
  if (n === 0) throw new Error(`⛔ 需要 --slot <b1..b20>(当前收到 ${JSON.stringify(args.slot)})。\n ⇒ 页面操作必须指明槽位:先 \`browser_slot list\` 看你租的是哪个。`);
21097
21379
  return n;
21098
21380
  }
21381
+ /**
21382
+ * 解析「要操作哪个 target」——`--target`(身份)或 `--match`(子串线索)二选一。
21383
+ *
21384
+ * 🔴 判据在 `browser/target-pick.ts`(0 命中不猜 / 多命中不猜 / 身份优先于线索)。
21385
+ * 这里只负责**把拒绝翻成人话**:多命中时把候选列全,让调用方一次就能改对。
21386
+ */
21387
+ async function needTarget(root, n, sessionId, args) {
21388
+ const target = str(args.target);
21389
+ const match = str(args.match);
21390
+ if (!target && !match) throw new Error("⛔ 需要 --target=<targetId> 或 --match=<URL/标题子串>(先跑 targets 看清有什么)。\n ⇒ --match 是子串匹配,命中唯一才动手;命中多个会拒绝并列全候选。");
21391
+ return resolveTarget(root, n, sessionId, {
21392
+ target,
21393
+ match
21394
+ });
21395
+ }
21396
+ /** 解析 `--xy=x,y`(也接受 `x y`)。⛔ 非有限数、负数一律当没给 —— 越界坐标会让点击落到别处。 */
21397
+ function parseXY(raw) {
21398
+ if (!raw) return void 0;
21399
+ const parts = raw.split(/[,\s]+/).filter(Boolean);
21400
+ if (parts.length !== 2) return void 0;
21401
+ const x = Number(parts[0]);
21402
+ const y = Number(parts[1]);
21403
+ return Number.isFinite(x) && Number.isFinite(y) && x >= 0 && y >= 0 ? {
21404
+ x,
21405
+ y
21406
+ } : void 0;
21407
+ }
21099
21408
  /** 取字符串参数(空串当没给) */
21100
21409
  function str(v) {
21101
21410
  return typeof v === "string" && v !== "" ? v : void 0;
@@ -21190,55 +21499,58 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
21190
21499
  }
21191
21500
  case "goto": {
21192
21501
  const n = needSlot(args);
21193
- const target = str(args.target);
21194
21502
  const url = str(args.url);
21195
- if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
21196
21503
  if (!url) return "⛔ 需要 --url=<地址>";
21504
+ const target = await needTarget(root, n, sessionId, args);
21197
21505
  await slotGoto(root, n, sessionId, target, url);
21198
21506
  return `[browser_slot] navigate ${target} → ${url}`;
21199
21507
  }
21200
21508
  case "eval": {
21201
21509
  const n = needSlot(args);
21202
- const target = str(args.target);
21203
21510
  const js = str(args.js);
21204
- if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
21511
+ const target = await needTarget(root, n, sessionId, args);
21205
21512
  if (!js) return "⛔ 需要 --js=<表达式>(例如 document.title)";
21206
21513
  const v = await slotEval(root, n, sessionId, target, js, num(args.timeout));
21207
21514
  return typeof v === "string" ? v : JSON.stringify(v, null, 2);
21208
21515
  }
21209
21516
  case "text": {
21210
21517
  const n = needSlot(args);
21211
- const target = str(args.target);
21212
- if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
21213
- return await slotText(root, n, sessionId, target);
21518
+ return await slotText(root, n, sessionId, await needTarget(root, n, sessionId, args));
21214
21519
  }
21215
21520
  case "html": {
21216
21521
  const n = needSlot(args);
21217
- const target = str(args.target);
21218
- if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
21219
- return await slotHtml(root, n, sessionId, target, num(args.max));
21522
+ return await slotHtml(root, n, sessionId, await needTarget(root, n, sessionId, args), num(args.max));
21220
21523
  }
21221
21524
  case "shot": {
21222
21525
  const n = needSlot(args);
21223
- const target = str(args.target);
21224
- if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
21526
+ const target = await needTarget(root, n, sessionId, args);
21225
21527
  return `[browser_slot] shot → ${await slotShot(root, n, sessionId, target, str(args.out) ?? `_tmp/browser-shots/shot-${target.slice(0, 8)}-${Date.now()}.png`)}`;
21226
21528
  }
21227
21529
  case "reload": {
21228
21530
  const n = needSlot(args);
21229
- const target = str(args.target);
21230
- if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
21231
- return `[browser_slot] reload 完成(readyState=${await slotReload(root, n, sessionId, target, str(args.script)) || "?"})`;
21531
+ return `[browser_slot] reload 完成(readyState=${await slotReload(root, n, sessionId, await needTarget(root, n, sessionId, args), str(args.script)) || "?"})`;
21532
+ }
21533
+ case "click": {
21534
+ const n = needSlot(args);
21535
+ const target = await needTarget(root, n, sessionId, args);
21536
+ const text = str(args.text);
21537
+ const xy = parseXY(str(args.xy));
21538
+ if (!text && !xy) return "⛔ 需要 --text=<按钮可见文字> 或 --xy=<x,y>(例如 --text=登录 / --xy=320,48)";
21539
+ const { picked } = await slotClick(root, n, sessionId, target, {
21540
+ text,
21541
+ xy
21542
+ });
21543
+ return xy ? `[browser_slot] clicked @${xy.x},${xy.y}(坐标直给;未做命中校验)` : `[browser_slot] clicked <${picked.tag}> "${picked.text.slice(0, 60)}" @${picked.x},${picked.y}`;
21232
21544
  }
21233
21545
  case "close": {
21234
21546
  const n = needSlot(args);
21235
21547
  const all = args.all === true;
21236
- return `[browser_slot] closed ${(await slotClose(root, n, sessionId, str(args.target) ?? "", all)).join(", ")}`;
21548
+ return `[browser_slot] closed ${(await slotClose(root, n, sessionId, all ? "" : await needTarget(root, n, sessionId, args), all)).join(", ")}`;
21237
21549
  }
21238
21550
  case "ext-list": {
21239
21551
  const exts = slotExtList(root);
21240
21552
  if (exts.length === 0) return `本 CCC 还没有任何扩展。\n 写一个:在 <CCC 根>/${EXT_DIR_REL}/ 下放一个 .ts 文件,文件名即扩展名。\n 契约:stdin 收 {slot,port,cccRoot,args};stdout **最后一个非空行**给 {"ok":true,"result":…}。\n ⚠️ ACC 只 spawn、⛔ 从不 import —— 你的语法错不会放倒宿主。`;
21241
- return `本 CCC 的浏览器扩展 ${exts.length} 个(<CCC 根>/${EXT_DIR_REL}/):\n` + exts.map((e) => ` · ${e.name}`).join("\n") + `\n\n调用:browser_slot ext --slot b1 --name <名> [--eslot …/--earg key=value]`;
21553
+ return `本 CCC 的浏览器扩展 ${exts.length} 个(<CCC 根>/${EXT_DIR_REL}/):\n` + exts.map((e) => ` · ${e.name}`).join("\n") + `\n\n调用:browser_slot ext --slot b1 --name <名> [--earg key=value …(可重复)]`;
21242
21554
  }
21243
21555
  case "ext": {
21244
21556
  const n = needSlot(args);
@@ -21272,6 +21584,59 @@ function createBrowserSlotTool(ctx) {
21272
21584
  reason: {
21273
21585
  type: "string",
21274
21586
  description: "reap: why this slot is being force-reclaimed (recorded)."
21587
+ },
21588
+ url: {
21589
+ type: "string",
21590
+ description: "open / goto: the address to open or navigate to (http(s)://…)"
21591
+ },
21592
+ target: {
21593
+ type: "string",
21594
+ description: "goto / eval / text / html / shot / reload / close: the targetId from `targets` (⛔ not a slot number). Identity — beats `match` when both given"
21595
+ },
21596
+ match: {
21597
+ type: "string",
21598
+ description: "goto / eval / text / html / shot / reload / close: URL or title SUBSTRING (case-insensitive) instead of a targetId — saves the `targets` round-trip. Refuses unless exactly ONE page matches; on ambiguity it lists the candidates instead of guessing"
21599
+ },
21600
+ js: {
21601
+ type: "string",
21602
+ description: "eval: a JavaScript expression to evaluate in the page (e.g. document.title); uses Runtime.evaluate"
21603
+ },
21604
+ out: {
21605
+ type: "string",
21606
+ description: "shot: output path for the PNG, relative to the CCC root. Omit = auto-named under _tmp/browser-shots/"
21607
+ },
21608
+ max: {
21609
+ type: "number",
21610
+ description: "html: truncate the returned HTML after this many characters"
21611
+ },
21612
+ all: {
21613
+ type: "boolean",
21614
+ description: "close: close every target in the slot instead of one (then `target` is not needed)"
21615
+ },
21616
+ name: {
21617
+ type: "string",
21618
+ description: "ext: extension name = the .ts file name under <CCC>/browser-ext/ (run `ext-list` to see them)"
21619
+ },
21620
+ earg: {
21621
+ type: "array",
21622
+ items: { type: "string" },
21623
+ description: "ext: repeatable key=value pairs passed to the extension as strings (e.g. [\"city=Suzhou\"])"
21624
+ },
21625
+ timeout: {
21626
+ type: "number",
21627
+ description: "eval: evaluate timeout in milliseconds"
21628
+ },
21629
+ text: {
21630
+ type: "string",
21631
+ description: "click: visible-text SUBSTRING of the element to click (matched against rendered text + value + aria-label + title). Refuses when 0 or >1 elements match, or the single hit is disabled/zero-size/pointer-events:none — never guesses, because a wrong click has already happened"
21632
+ },
21633
+ xy: {
21634
+ type: "string",
21635
+ description: "click: \"x,y\" viewport coordinates to click instead of --text (no hit-testing; the receipt says so). ⛔ Omit both text and xy = refused"
21636
+ },
21637
+ script: {
21638
+ type: "string",
21639
+ description: "reload: a script to run after the reload completes"
21275
21640
  }
21276
21641
  },
21277
21642
  output: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgroup/dsh-serenity-hooks",
3
- "version": "1.129.2",
3
+ "version": "1.129.4",
4
4
  "description": "宁静号 ACC harness(Native Cordis 插件)——给 DeepSeek Harness 装一个「AI 工作区」:14 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin/browser_slot;另三个 im-bridge/diagram/reconstruct 按条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫/对外输出守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/IM 桥/认知轨迹唤醒注册表 + 浏览器槽位管理(≤20 个独立 profile 的 Chrome 槽位,带占用归属与异常时向所属会话反向注入提醒)。轨迹声明 = 轨迹目录下的 trajectory.json(约束面 + 旧标识 uid + CRO 机器绑定 cro.host;旧名 trajectory-constraint.json / skiff.json 仍在读取族里);轨迹提示词 = 轨迹目录下的 PROMPT.md(一条轨迹「是谁、按什么章程工作」,所有轨迹通用,追加在容器层与质量层之后,不替换它们)。适配 DSH 0.1.7-rc.1 / 0.2.0-rc.1 / 0.2.1-rc.1(三档)。",
5
5
  "license": "MIT",
6
6
  "repository": {