@shgroup/dsh-serenity-hooks 1.131.0 → 1.133.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/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-serenity-hooks",
3
- "version": "1.131.0",
3
+ "version": "1.133.0",
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": {
@@ -24,6 +24,7 @@
24
24
  * 那些行为有真实使用与踩坑记录(4 条轨迹的手册在用)。搬的时候**不为好看改语义**。
25
25
  */
26
26
  import type { KeyStroke } from './keys.js';
27
+ import type { HitProbe } from './hit-test.js';
27
28
  import type { AxNode } from './ax.js';
28
29
  /** 一条 CDP 连接上的相关器:发出去的 id → 待兑现的 promise */
29
30
  interface CdpConn {
@@ -231,6 +232,19 @@ export declare function boxCenterByBackendId(slot: number, targetId: string, bac
231
232
  h: number;
232
233
  inViewport: boolean;
233
234
  }>;
235
+ /**
236
+ * 命中测试:**这个点上到底是谁**(`DOM.getNodeForLocation`)。
237
+ *
238
+ * 🔴 为什么是它而不是页面里的 `document.elementFromPoint`:
239
+ * 前者问的是**合成器/真实点击用的那套命中逻辑**,后者是 DOM 侧的另一份实现。
240
+ * 「点下去发生了什么」要用**与点击同一套**的答案来回答(同族判据:有宿主自带实现就别复刻语义)。
241
+ *
242
+ * ⚠️ 三条 CDP 行为必须知道(否则读数会被读反):
243
+ * ① **坐标越界不报错** —— 只回 `nodeId: 0`。所以**视口判定必须自己算**,不能靠"回了空"。
244
+ * ② `DOM.enable` 与 `Overlay.enable` 都可省;但 `DOM.enable` 之后要销毁连接,本函数走 withPage 高层封装。
245
+ * ③ 解析节点用 `DOM.describeNode`(拿 nodeName / id),⛔ 不用 `DOM.getOuterHTML`(会把整段 HTML 拉回上下文)。
246
+ */
247
+ export declare function hitTestAt(slot: number, targetId: string, x: number, y: number): Promise<HitProbe>;
234
248
  /**
235
249
  * 上传文件:`DOM.setFileInputFiles`。
236
250
  *
@@ -0,0 +1,36 @@
1
+ /**
2
+ * browser/coords.ts — 坐标参数的**纯解析**(`x,y` 字符串 / `[x,y]` 数组 / `{x,y}` 对象)。
3
+ *
4
+ * 🔴🔴 **为什么必须三种形态都收**(2026-11-13 真机事故,owner 截图):
5
+ * 坐标原本**只声明成 string**,于是模型想传两个数字时写出了「裸两个值」:
6
+ * {"xy": 1428,76} ← 坏 JSON
7
+ * 宿主在**参数 JSON 解析阶段**就拒了(`MALFORMED_RESPONSE`)⇒ **我们的工具一次都没执行**。
8
+ * 表现是「本轮运行失败」,而根因**不在点击逻辑里** —— 是 schema 把一个自然的写法挤了出去。
9
+ *
10
+ * ⇒ 判据:**schema 的形状会改变调用方的写法**。只收 string 等于强迫模型把两个数字
11
+ * 序列化进一个字符串,而「数字就是数字」是它更自然的表达。三种都收,坏写法就失去动机。
12
+ *
13
+ * ⚠️ 但**收得宽 ≠ 判得松**:形态放宽了,「解析成功」的门槛一条没降 ——
14
+ * 非有限数、负数、多于/少于两个分量,一律返回 null(调用方据此拒绝并列出正确形态)。
15
+ */
16
+ /** 一个视口坐标 */
17
+ export interface XY {
18
+ x: number;
19
+ y: number;
20
+ }
21
+ /** 坐标的三种合法入参形态(schema 与解析器必须**同时**支持这三者) */
22
+ export type XYInput = string | readonly unknown[] | {
23
+ x?: unknown;
24
+ y?: unknown;
25
+ } | null | undefined;
26
+ /**
27
+ * 解析坐标。
28
+ *
29
+ * 判据(每条都是「宁可拒绝」):
30
+ * ① 只接受三种形态;其余(布尔、裸数字、对象缺分量)⇒ null
31
+ * ② 分量必须是**有限数**且 **≥ 0** —— 负数与 NaN 会让点击落到别处或直接被 CDP 丢弃
32
+ * ③ 字符串形态按 `,` 或空白切;**必须正好两个分量**(`"1,2,3"` 拒绝,⛔ 不取前两个)
33
+ */
34
+ export declare function parseXY(raw: XYInput): XY | undefined;
35
+ /** 拒绝时列给调用方的三种正确形态(⛔ 只列一种 —— 那等于又把口子收窄回去) */
36
+ export declare function xyFormHint(param?: string): string;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * hit-test.ts — 「这一下**到底会点到谁**」的**纯判定**(取数在 cdp.ts,执行在 cdp.ts)。
3
+ *
4
+ * 🔴🔴 为什么这一格必须存在(2026-11-13,owner 令做的 B 项,属 `browser-cdp-landscape` §5 最贵的那个缺口):
5
+ *
6
+ * 直到现在,`click --xy` 的回执说的是「**我点了哪里**」,不是「**我点到了什么**」。
7
+ * 而下面这三种情况,**CDP 一行都不报**,回执照样写着 `clicked @x,y`:
8
+ *
9
+ * ① **坐标在视口外** —— 事件发出去了,但视口里没有这个点 ⇒ 什么也没发生
10
+ * ② **被别的元素盖住** —— 点到了盖在上面的那个(弹层 / 固定头 / 遮罩 / 兄弟浮层)
11
+ * ③ **点在了空白处** —— 那里根本没有元素
12
+ *
13
+ * ⇒ 判据:**「发了鼠标事件」与「点到了目标」是两件事**(D311 的坐标版)。
14
+ * 回执必须回答后者,且**答案要能在下一步被验证**(所以回执里带"实际命中是谁")。
15
+ *
16
+ * ## 取数为什么用 `DOM.getNodeForLocation` 而不用自己的 `elementFromPoint`
17
+ *
18
+ * 它问的是**合成器的真实命中测试**(与真实点击走同一套命中逻辑),而 `elementFromPoint`
19
+ * 是 DOM 侧的另一份实现(同族判据:**有宿主自带实现时,直接调用它,不要复刻语义**)。
20
+ *
21
+ * ## 三条输出语义(`hit-test` 的返回值名就是这三条)
22
+ *
23
+ * `ok` —— 点下去会落在**你指定的那个元素**上
24
+ * `blocked` —— 落在**别的元素**上(回执说清是谁;这是最常见的真故障)
25
+ * `blank` —— 那里没有元素(页面确实留白)
26
+ * `offscreen` —— 点的位置不在视口内(**先 scroll**,⛔ 不要"点一下试试")
27
+ */
28
+ /** 一次命中测试的读数(由 `cdp.ts` 的 `hitTestAt` 采集,形状与 CDP 一一对应) */
29
+ export interface HitProbe {
30
+ /** 该点是否落在视口内(CDP 对越界坐标**不报错**,只回空) */
31
+ inViewport: boolean;
32
+ /** 视口尺寸(用于回执里说清"这个点在哪之外") */
33
+ viewport?: {
34
+ w: number;
35
+ h: number;
36
+ };
37
+ /** `DOM.getNodeForLocation` 反解出的那个节点;空 = 那里没节点 */
38
+ node?: {
39
+ backendNodeId: number;
40
+ nodeName: string;
41
+ id?: string;
42
+ };
43
+ }
44
+ /** 判定结果(`kind` 就是上面那四条之一) */
45
+ export type HitVerdict = {
46
+ kind: 'ok';
47
+ node?: {
48
+ backendNodeId: number;
49
+ nodeName: string;
50
+ id?: string;
51
+ };
52
+ } | {
53
+ kind: 'blocked';
54
+ hit: {
55
+ backendNodeId: number;
56
+ nodeName: string;
57
+ id?: string;
58
+ };
59
+ why: string;
60
+ } | {
61
+ kind: 'blank';
62
+ } | {
63
+ kind: 'offscreen';
64
+ why: string;
65
+ };
66
+ /**
67
+ * 判「这一下会点到谁」。
68
+ *
69
+ * @param probe 命中测试读数
70
+ * @param expect 期望命中的节点(`--ref` 时**有**这个值;纯 `--xy` 时**没有**)。
71
+ * ⚠️ 没有 `expect` 时**永远不判 `blocked`**:调用方没说要打谁,就没有"打错了"这回事 ——
72
+ * 只能报告"打到了谁"。⛔ 不替调用方猜目标。
73
+ */
74
+ export declare function judgeHit(probe: HitProbe, expect?: {
75
+ backendNodeId: number;
76
+ }): HitVerdict;
77
+ /** 把判定渲染成一句**能被下一步验证**的回执(⛔ 不写"点击成功"这种无法证伪的话) */
78
+ export declare function renderHit(v: HitVerdict): string;
@@ -17,6 +17,7 @@ import { type Clickable } from './click-target.js';
17
17
  import { type KeyStroke } from './keys.js';
18
18
  import { type AxLine } from './ax.js';
19
19
  import { type WaitSpec } from './wait-spec.js';
20
+ import { type HitVerdict } from './hit-test.js';
20
21
  /**
21
22
  * 动作枚举(对外暴露的唯一清单)
22
23
  *
@@ -167,6 +168,7 @@ export declare function slotClick(root: string, slot: number, sessionId: string,
167
168
  x: number;
168
169
  y: number;
169
170
  };
171
+ ref?: number;
170
172
  }): Promise<{
171
173
  picked: Clickable;
172
174
  total: number;
@@ -175,6 +177,8 @@ export declare function slotClick(root: string, slot: number, sessionId: string,
175
177
  message: string;
176
178
  accepted: boolean;
177
179
  }>;
180
+ /** 「这一下**会点到谁**」的判定(B 项,D328)。⛔ 回执不说"点成功",只说它落在哪 */
181
+ hit: HitVerdict;
178
182
  }>;
179
183
  /** 列当前槽位上的 targets */
180
184
  export declare function slotTargets(root: string, slot: number, sessionId: string): Promise<CdpTarget[]>;
package/lib/index.js CHANGED
@@ -20687,6 +20687,82 @@ async function boxCenterByBackendId(slot, targetId, backendNodeId) {
20687
20687
  });
20688
20688
  }
20689
20689
  /**
20690
+ * 命中测试:**这个点上到底是谁**(`DOM.getNodeForLocation`)。
20691
+ *
20692
+ * 🔴 为什么是它而不是页面里的 `document.elementFromPoint`:
20693
+ * 前者问的是**合成器/真实点击用的那套命中逻辑**,后者是 DOM 侧的另一份实现。
20694
+ * 「点下去发生了什么」要用**与点击同一套**的答案来回答(同族判据:有宿主自带实现就别复刻语义)。
20695
+ *
20696
+ * ⚠️ 三条 CDP 行为必须知道(否则读数会被读反):
20697
+ * ① **坐标越界不报错** —— 只回 `nodeId: 0`。所以**视口判定必须自己算**,不能靠"回了空"。
20698
+ * ② `DOM.enable` 与 `Overlay.enable` 都可省;但 `DOM.enable` 之后要销毁连接,本函数走 withPage 高层封装。
20699
+ * ③ 解析节点用 `DOM.describeNode`(拿 nodeName / id),⛔ 不用 `DOM.getOuterHTML`(会把整段 HTML 拉回上下文)。
20700
+ */
20701
+ async function hitTestAt(slot, targetId, x, y) {
20702
+ return await withPage(slot, targetId, async (send) => {
20703
+ const vp = await send("Runtime.evaluate", {
20704
+ expression: "JSON.stringify({w:innerWidth,h:innerHeight})",
20705
+ returnByValue: true
20706
+ });
20707
+ let vw = 0;
20708
+ let vh = 0;
20709
+ try {
20710
+ const o = JSON.parse(String(vp.result?.value ?? "{}"));
20711
+ vw = Number(o.w ?? 0);
20712
+ vh = Number(o.h ?? 0);
20713
+ } catch {}
20714
+ const inViewport = vw > 0 && vh > 0 && x >= 0 && y >= 0 && x <= vw && y <= vh;
20715
+ if (!inViewport) return {
20716
+ inViewport,
20717
+ viewport: vw > 0 && vh > 0 ? {
20718
+ w: vw,
20719
+ h: vh
20720
+ } : void 0
20721
+ };
20722
+ await send("DOM.enable");
20723
+ const found = await send("DOM.getNodeForLocation", {
20724
+ x: Math.round(x),
20725
+ y: Math.round(y),
20726
+ includeUserAgentShadowDOM: false,
20727
+ ignorePointerEventsNone: false
20728
+ });
20729
+ const backend = Number(found.backendNodeId ?? 0);
20730
+ if (!Number.isFinite(backend) || backend <= 0) return {
20731
+ inViewport,
20732
+ viewport: {
20733
+ w: vw,
20734
+ h: vh
20735
+ }
20736
+ };
20737
+ let nodeName = "";
20738
+ let id = "";
20739
+ try {
20740
+ const desc = await send("DOM.describeNode", {
20741
+ backendNodeId: backend,
20742
+ depth: 0
20743
+ });
20744
+ nodeName = String(desc.node?.nodeName ?? "");
20745
+ const attrs = desc.node?.attributes ?? [];
20746
+ for (let i = 0; i + 1 < attrs.length; i += 2) if (attrs[i] === "id") {
20747
+ id = String(attrs[i + 1] ?? "");
20748
+ break;
20749
+ }
20750
+ } catch {}
20751
+ return {
20752
+ inViewport,
20753
+ viewport: {
20754
+ w: vw,
20755
+ h: vh
20756
+ },
20757
+ node: {
20758
+ backendNodeId: backend,
20759
+ nodeName: nodeName || "?",
20760
+ ...id ? { id } : {}
20761
+ }
20762
+ };
20763
+ });
20764
+ }
20765
+ /**
20690
20766
  * 上传文件:`DOM.setFileInputFiles`。
20691
20767
  *
20692
20768
  * 🔴🔴 **这是本轮唯一一个能把本地文件送进网页的动作**,所以守卫写在这里而不是工具层:
@@ -21560,6 +21636,49 @@ function explainWaitTimeout(spec, waitedMs, last) {
21560
21636
  return "⛔ 等待超时(" + String(Math.round(waitedMs / 100) / 10) + "s)—— 等的是:" + what + "\n 最后一次读数:" + lastText + "\n ⇒ 若最后一次读数是 null/false,多半是条件写错了(形态:" + spec.kind + ");若是别的值,说明条件在往别的方向走 —— 用 eval 看一眼实际状态再重试。";
21561
21637
  }
21562
21638
  //#endregion
21639
+ //#region src/browser/hit-test.ts
21640
+ /**
21641
+ * 判「这一下会点到谁」。
21642
+ *
21643
+ * @param probe 命中测试读数
21644
+ * @param expect 期望命中的节点(`--ref` 时**有**这个值;纯 `--xy` 时**没有**)。
21645
+ * ⚠️ 没有 `expect` 时**永远不判 `blocked`**:调用方没说要打谁,就没有"打错了"这回事 ——
21646
+ * 只能报告"打到了谁"。⛔ 不替调用方猜目标。
21647
+ */
21648
+ function judgeHit(probe, expect) {
21649
+ if (!probe.inViewport) {
21650
+ const vp = probe.viewport;
21651
+ return {
21652
+ kind: "offscreen",
21653
+ why: vp ? `不在视口内(视口 ${vp.w}×${vp.h})` : "不在视口内(视口尺寸未取到)"
21654
+ };
21655
+ }
21656
+ if (!probe.node || probe.node.backendNodeId <= 0) return { kind: "blank" };
21657
+ if (!expect) return {
21658
+ kind: "ok",
21659
+ node: probe.node
21660
+ };
21661
+ if (probe.node.backendNodeId === expect.backendNodeId) return {
21662
+ kind: "ok",
21663
+ node: probe.node
21664
+ };
21665
+ const who = `<${probe.node.nodeName.toLowerCase()}${probe.node.id ? ` id="${probe.node.id}"` : ""}>`;
21666
+ return {
21667
+ kind: "blocked",
21668
+ hit: probe.node,
21669
+ why: `落点被 ${who} 接住了(它的 backendNodeId=${probe.node.backendNodeId},期望的是 ${expect.backendNodeId})`
21670
+ };
21671
+ }
21672
+ /** 把判定渲染成一句**能被下一步验证**的回执(⛔ 不写"点击成功"这种无法证伪的话) */
21673
+ function renderHit(v) {
21674
+ switch (v.kind) {
21675
+ case "ok": return v.node ? `命中 <${v.node.nodeName.toLowerCase()}${v.node.id ? ` id="${v.node.id}"` : ""}>` : "命中(未取反查节点)";
21676
+ case "blocked": return `🔴 实际命中的不是你指定的元素:${v.why}`;
21677
+ case "blank": return "🔴 这个点上没有元素(页面留白/坐标算错了)";
21678
+ case "offscreen": return `🔴 ${v.why} ⇒ 先 scroll 再点,⛔ 别"点一下试试"`;
21679
+ }
21680
+ }
21681
+ //#endregion
21563
21682
  //#region src/browser/service.ts
21564
21683
  /**
21565
21684
  * browser/service.ts — 槽位管理器的动作实现(ACC 级)
@@ -22089,8 +22208,11 @@ async function resolveTarget(root, slot, sessionId, opts) {
22089
22208
  */
22090
22209
  async function slotClick(root, slot, sessionId, targetId, opts) {
22091
22210
  assertSlotOwned(root, slot, sessionId);
22092
- if (!opts.text && !opts.xy) throw new Error("⛔ 需要 --text=<按钮可见文字> 或 --xy=<x,y>(先 targets 拿 targetId)");
22211
+ if (!opts.text && !opts.xy) throw new Error("⛔ 需要 --text=<按钮可见文字> 或坐标(先 targets 拿 targetId)");
22093
22212
  if (opts.xy) {
22213
+ const hit = judgeHit(await hitTestAt(slot, targetId, opts.xy.x, opts.xy.y), opts.ref !== void 0 ? { backendNodeId: opts.ref } : void 0);
22214
+ if (hit.kind === "offscreen" || hit.kind === "blank") throw new Error(`⛔ 不点:${renderHit(hit)}\n ⇒ 坐标 ${opts.xy.x},${opts.xy.y}。先用 \`ax\` 拿 ref(更稳)或 \`scroll\` 把目标滚进视口。`);
22215
+ if (hit.kind === "blocked") throw new Error(`⛔ 不点:${renderHit(hit)}\n ⇒ 被挡住时点下去会**执行另一个元素**的处理逻辑(而回执若是"clicked"就无从发现)。\n ⇒ 出路:先用 \`ax\` 看那一层是什么(弹层/固定头/遮罩),关掉它;或改用 \`--ref\` 点名目标。`);
22094
22216
  const r = await clickAt(slot, targetId, opts.xy.x, opts.xy.y);
22095
22217
  pageTouched(root, slot);
22096
22218
  return {
@@ -22107,7 +22229,8 @@ async function slotClick(root, slot, sessionId, targetId, opts) {
22107
22229
  download: false
22108
22230
  },
22109
22231
  total: 0,
22110
- dialogs: r.dialogs
22232
+ dialogs: r.dialogs,
22233
+ hit
22111
22234
  };
22112
22235
  }
22113
22236
  const raw = await evalInPage(slot, targetId, COLLECT_CLICKABLE, 15e3);
@@ -22119,12 +22242,15 @@ async function slotClick(root, slot, sessionId, targetId, opts) {
22119
22242
  if (res.reason === "not-clickable") throw new Error(`⛔ 「${opts.text}」找到了,但${res.why}。\n ⇒ 这不是"尽力点一下"的场合:点了没反应与没点,在读数上一样。\n${renderClickables(res.hits)}`);
22120
22243
  throw new Error(`⛔ 页面上没有可点元素匹配「${opts.text}」(匹配渲染后的可见文本,含 value/aria-label/title)。\n ⇒ 当前 ${visible.length} 个可见可点元素:\n${renderClickables(visible)}`);
22121
22244
  }
22245
+ const hit = judgeHit(await hitTestAt(slot, targetId, res.el.x, res.el.y));
22246
+ if (hit.kind === "offscreen" || hit.kind === "blank") throw new Error(`⛔ 不点「${opts.text}」:${renderHit(hit)}\n ⇒ 「找得到」与「点得到」是两件事:元素在 DOM 里可见、可点,不代表这一下会落在它上面。`);
22122
22247
  const clicked = await clickAt(slot, targetId, res.el.x, res.el.y);
22123
22248
  pageTouched(root, slot);
22124
22249
  return {
22125
22250
  picked: res.el,
22126
22251
  total: list.length,
22127
- dialogs: clicked.dialogs
22252
+ dialogs: clicked.dialogs,
22253
+ hit
22128
22254
  };
22129
22255
  }
22130
22256
  /** 列当前槽位上的 targets */
@@ -22382,6 +22508,52 @@ async function slotExt(root, slot, sessionId, name, args) {
22382
22508
  return res;
22383
22509
  }
22384
22510
  //#endregion
22511
+ //#region src/browser/coords.ts
22512
+ /**
22513
+ * 解析坐标。
22514
+ *
22515
+ * 判据(每条都是「宁可拒绝」):
22516
+ * ① 只接受三种形态;其余(布尔、裸数字、对象缺分量)⇒ null
22517
+ * ② 分量必须是**有限数**且 **≥ 0** —— 负数与 NaN 会让点击落到别处或直接被 CDP 丢弃
22518
+ * ③ 字符串形态按 `,` 或空白切;**必须正好两个分量**(`"1,2,3"` 拒绝,⛔ 不取前两个)
22519
+ */
22520
+ function parseXY(raw) {
22521
+ if (raw === null || raw === void 0) return void 0;
22522
+ let a;
22523
+ let b;
22524
+ if (typeof raw === "string") {
22525
+ const parts = raw.split(/[,\s]+/).filter((s) => s !== "");
22526
+ if (parts.length !== 2) return void 0;
22527
+ a = parts[0];
22528
+ b = parts[1];
22529
+ } else if (Array.isArray(raw)) {
22530
+ if (raw.length !== 2) return void 0;
22531
+ a = raw[0];
22532
+ b = raw[1];
22533
+ } else if (typeof raw === "object") {
22534
+ const o = raw;
22535
+ a = o.x;
22536
+ b = o.y;
22537
+ if (a === void 0 || b === void 0) return void 0;
22538
+ } else return;
22539
+ const x = typeof a === "number" ? a : Number(a);
22540
+ const y = typeof b === "number" ? b : Number(b);
22541
+ if (!Number.isFinite(x) || !Number.isFinite(y)) return void 0;
22542
+ if (x < 0 || y < 0) return void 0;
22543
+ return {
22544
+ x,
22545
+ y
22546
+ };
22547
+ }
22548
+ /** 拒绝时列给调用方的三种正确形态(⛔ 只列一种 —— 那等于又把口子收窄回去) */
22549
+ function xyFormHint(param = "xy") {
22550
+ return [
22551
+ ` --${param}=1428,76 (字符串:逗号分隔)`,
22552
+ ` --${param}=[1428,76] (数组:两个数字)`,
22553
+ ` --${param}={x:1428,y:76} (对象)`
22554
+ ].join("\n");
22555
+ }
22556
+ //#endregion
22385
22557
  //#region src/tools/browser-slot/index.ts
22386
22558
  /**
22387
22559
  * tools/browser-slot/index.ts — browser_slot 工具(ACC 级浏览器槽位管理器)
@@ -22457,18 +22629,6 @@ async function needTarget(root, n, sessionId, args) {
22457
22629
  match
22458
22630
  });
22459
22631
  }
22460
- /** 解析 `--xy=x,y`(也接受 `x y`)。⛔ 非有限数、负数一律当没给 —— 越界坐标会让点击落到别处。 */
22461
- function parseXY(raw) {
22462
- if (!raw) return void 0;
22463
- const parts = raw.split(/[,\s]+/).filter(Boolean);
22464
- if (parts.length !== 2) return void 0;
22465
- const x = Number(parts[0]);
22466
- const y = Number(parts[1]);
22467
- return Number.isFinite(x) && Number.isFinite(y) && x >= 0 && y >= 0 ? {
22468
- x,
22469
- y
22470
- } : void 0;
22471
- }
22472
22632
  /** 取字符串参数(空串当没给) */
22473
22633
  function str(v) {
22474
22634
  return typeof v === "string" && v !== "" ? v : void 0;
@@ -22598,13 +22758,17 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
22598
22758
  const n = needSlot(args);
22599
22759
  const target = await needTarget(root, n, sessionId, args);
22600
22760
  const text = str(args.text);
22601
- const xy = parseXY(str(args.xy));
22602
- if (!text && !xy) return "⛔ 需要 --text=<按钮可见文字> 或 --xy=<x,y>(例如 --text=登录 / --xy=320,48)";
22603
- const { picked, dialogs } = await slotClick(root, n, sessionId, target, {
22761
+ const xy = parseXY(args.xy);
22762
+ if (!text && !xy) return `⛔ 需要 --text=<按钮可见文字> 或坐标(坐标三种写法都收):\n${xyFormHint("xy")}\n 例如:--text=登录`;
22763
+ const refRaw = str(args.ref);
22764
+ const refId = refRaw === void 0 ? void 0 : refToBackendId(refRaw) ?? void 0;
22765
+ if (refRaw !== void 0 && refId === void 0) return `⛔ --ref 格式不对:${JSON.stringify(refRaw)}(要 \`ax\` 给出的 eNNN)`;
22766
+ const { picked, dialogs, hit } = await slotClick(root, n, sessionId, target, {
22604
22767
  text,
22605
- xy
22768
+ xy,
22769
+ ref: refId
22606
22770
  });
22607
- const base = xy ? `[browser_slot] clicked @${xy.x},${xy.y}(坐标直给;未做命中校验)` : `[browser_slot] clicked <${picked.tag}> "${picked.text.slice(0, 60)}" @${picked.x},${picked.y}`;
22771
+ const base = `[browser_slot] clicked ${xy ? `@${xy.x},${xy.y}` : `<${picked.tag}> "${picked.text.slice(0, 60)}" @${picked.x},${picked.y}`}|命中:${renderHit(hit)}`;
22608
22772
  if (dialogs.length === 0) return base;
22609
22773
  return `${base}\n${dialogs.map((d) => ` ⚠️ 自动处理弹窗 ${d.type || "(未知类型)"}:${JSON.stringify(d.message.slice(0, 100))} ⇒ ${d.accepted ? "已确定" : "已取消"}`).join("\n")}\n (默认取消;要「确定」请单独用 dialog --accept —— OK 常意味着删除/支付/发布)`;
22610
22774
  }
@@ -22646,7 +22810,7 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
22646
22810
  const n = needSlot(args);
22647
22811
  const target = await needTarget(root, n, sessionId, args);
22648
22812
  const refStr = str(args.ref);
22649
- const xy = parseXY(str(args.xy));
22813
+ const xy = parseXY(args.xy);
22650
22814
  const toRaw = str(args.to);
22651
22815
  const to = toRaw === "top" || toRaw === "bottom" ? toRaw : void 0;
22652
22816
  if (!refStr && !xy && !to) return "⛔ 需要 --ref=<eNNN> / --xy=<x,y> / --to=<top|bottom> 之一";
@@ -22670,11 +22834,12 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
22670
22834
  case "drag": {
22671
22835
  const n = needSlot(args);
22672
22836
  const target = await needTarget(root, n, sessionId, args);
22673
- const from = parseXY(str(args.from));
22674
- const to = parseXY(str(args.to));
22675
- if (!from || !to) return "⛔ 需要 --from=<x,y> 与 --to=<x,y>(先 ax 拿 ref,再用 scroll/eval 量坐标)";
22676
- await slotDrag(root, n, sessionId, target, from, to, num(args.steps) ?? 12);
22677
- return `[browser_slot] drag ${from.x},${from.y} → ${to.x},${to.y}(分 ${num(args.steps) ?? 12} 步;⛔ 回执不说拖成功)`;
22837
+ const from = parseXY(args.from);
22838
+ const to = parseXY(args.to);
22839
+ if (!from || !to) return `⛔ 需要 --from 与 --to(坐标三种写法都收):\n${xyFormHint("from")}${xyFormHint("to")}\n 先 ax 拿 ref,再用 scroll/eval 量坐标`;
22840
+ const steps = num(args.steps) ?? 12;
22841
+ await slotDrag(root, n, sessionId, target, from, to, steps);
22842
+ return `[browser_slot] drag ${from.x},${from.y} → ${to.x},${to.y}(分 ${steps} 步;⛔ 回执不说拖成功)`;
22678
22843
  }
22679
22844
  case "upload": {
22680
22845
  const n = needSlot(args);
@@ -22787,8 +22952,35 @@ function createBrowserSlotTool(ctx) {
22787
22952
  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"
22788
22953
  },
22789
22954
  xy: {
22790
- type: "string",
22791
- description: "click: \"x,y\" viewport coordinates to click instead of --text (no hit-testing; the receipt says so). ⛔ Omit both text and xy = refused"
22955
+ oneOf: [
22956
+ {
22957
+ type: "string",
22958
+ description: "\"x,y\" (comma or space separated)"
22959
+ },
22960
+ {
22961
+ type: "array",
22962
+ items: { type: "number" },
22963
+ description: "[x, y]"
22964
+ },
22965
+ {
22966
+ type: "object",
22967
+ properties: {
22968
+ x: {
22969
+ type: "number",
22970
+ required: true,
22971
+ description: "viewport x"
22972
+ },
22973
+ y: {
22974
+ type: "number",
22975
+ required: true,
22976
+ description: "viewport y"
22977
+ }
22978
+ },
22979
+ additionalProperties: false,
22980
+ description: "{x, y}"
22981
+ }
22982
+ ],
22983
+ description: "click / scroll: viewport coordinates as \"x,y\" | [x,y] | {x,y}. ⛔ Not a slot or element id — pass `ref` for provenance"
22792
22984
  },
22793
22985
  script: {
22794
22986
  type: "string",
@@ -22823,8 +23015,33 @@ function createBrowserSlotTool(ctx) {
22823
23015
  description: "wait: REQUIRED PREFIX — selector:<css> | text:<substring> | url:<substring> | gone:<css> | js:<expr>. A bare value is refused because \"which form\" would be a guess"
22824
23016
  },
22825
23017
  from: {
22826
- type: "string",
22827
- description: "drag: \"x,y\" start point in viewport coords"
23018
+ oneOf: [
23019
+ {
23020
+ type: "string",
23021
+ description: "\"x,y\""
23022
+ },
23023
+ {
23024
+ type: "array",
23025
+ items: { type: "number" },
23026
+ description: "[x, y]"
23027
+ },
23028
+ {
23029
+ type: "object",
23030
+ properties: {
23031
+ x: {
23032
+ type: "number",
23033
+ required: true
23034
+ },
23035
+ y: {
23036
+ type: "number",
23037
+ required: true
23038
+ }
23039
+ },
23040
+ additionalProperties: false,
23041
+ description: "{x, y}"
23042
+ }
23043
+ ],
23044
+ description: "drag: start point in viewport coords (three forms, same as xy)"
22828
23045
  },
22829
23046
  steps: {
22830
23047
  type: "number",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgroup/dsh-serenity-hooks",
3
- "version": "1.131.0",
3
+ "version": "1.133.0",
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": {