@shgroup/dsh-serenity-hooks 1.130.3 → 1.132.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 +1 -1
- package/lib/browser/cdp.d.ts +15 -1
- package/lib/browser/coords.d.ts +36 -0
- package/lib/browser/service.d.ts +5 -0
- package/lib/index.js +220 -71
- package/package.json +1 -1
package/dsh.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-serenity-hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.132.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": {
|
package/lib/browser/cdp.d.ts
CHANGED
|
@@ -66,7 +66,9 @@ export declare function closeTab(slot: number, targetId: string, all?: boolean):
|
|
|
66
66
|
* 🔴 顺序与坐标:`mouseMoved` → `mousePressed` → `mouseReleased`,三次同一坐标。
|
|
67
67
|
* ⛔ 不发 `mousePressed` 就发 `mouseReleased` 会被 Chrome 丢弃(且**不报错**)。
|
|
68
68
|
*/
|
|
69
|
-
export declare function clickAt(slot: number, targetId: string, x: number, y: number): Promise<
|
|
69
|
+
export declare function clickAt(slot: number, targetId: string, x: number, y: number): Promise<{
|
|
70
|
+
dialogs: AutoDialog['handled'];
|
|
71
|
+
}>;
|
|
70
72
|
/** 正文(`document.body.innerText`) */
|
|
71
73
|
export declare function pageText(slot: number, targetId: string): Promise<string>;
|
|
72
74
|
/** HTML(默认截断 4000,同既有实现) */
|
|
@@ -100,9 +102,21 @@ export declare function resolveShotPath(cccRoot: string, relOrAbs: string): stri
|
|
|
100
102
|
* @param opts.events 要订阅的 CDP 事件名(例如 `Page.javascriptDialogOpening`)
|
|
101
103
|
* @param opts.onEvent 事件回调(**同步**执行;不要在里面 await CDP,那会卡住消息循环)
|
|
102
104
|
*/
|
|
105
|
+
export interface AutoDialog {
|
|
106
|
+
/** 自动处理策略:dismiss(默认,等于点「取消」)/accept(等于点「确定」)/none(交给调用方) */
|
|
107
|
+
mode: 'dismiss' | 'accept' | 'none';
|
|
108
|
+
/** 本次连接上**实际处理掉**的弹窗(回执要报出去,⛔ 不许静默) */
|
|
109
|
+
handled: Array<{
|
|
110
|
+
type: string;
|
|
111
|
+
message: string;
|
|
112
|
+
accepted: boolean;
|
|
113
|
+
}>;
|
|
114
|
+
}
|
|
103
115
|
export declare function withPage<T>(slot: number, targetId: string, fn: (send: (method: string, params?: Record<string, unknown>, timeoutMs?: number) => Promise<Record<string, unknown>>) => Promise<T>, opts?: {
|
|
104
116
|
events?: readonly string[];
|
|
105
117
|
onEvent?: (method: string, params: Record<string, unknown>) => void;
|
|
118
|
+
/** 自动处理原生弹窗(默认 **dismiss**);传 { mode: 'none' } 才交回调用方 */
|
|
119
|
+
autoDialog?: AutoDialog;
|
|
106
120
|
}): Promise<T>;
|
|
107
121
|
/** 浏览器级连接的高阶封装(`Target.*` / `Browser.*`;⛔ 页面动作不要用这个) */
|
|
108
122
|
export declare function withBrowser<T>(slot: number, fn: (send: (method: string, params?: Record<string, unknown>, timeoutMs?: number) => Promise<Record<string, unknown>>) => Promise<T>): Promise<T>;
|
|
@@ -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;
|
package/lib/browser/service.d.ts
CHANGED
|
@@ -170,6 +170,11 @@ export declare function slotClick(root: string, slot: number, sessionId: string,
|
|
|
170
170
|
}): Promise<{
|
|
171
171
|
picked: Clickable;
|
|
172
172
|
total: number;
|
|
173
|
+
dialogs: Array<{
|
|
174
|
+
type: string;
|
|
175
|
+
message: string;
|
|
176
|
+
accepted: boolean;
|
|
177
|
+
}>;
|
|
173
178
|
}>;
|
|
174
179
|
/** 列当前槽位上的 targets */
|
|
175
180
|
export declare function slotTargets(root: string, slot: number, sessionId: string): Promise<CdpTarget[]>;
|
package/lib/index.js
CHANGED
|
@@ -20197,30 +20197,48 @@ async function closeTab(slot, targetId, all = false) {
|
|
|
20197
20197
|
* ⛔ 不发 `mousePressed` 就发 `mouseReleased` 会被 Chrome 丢弃(且**不报错**)。
|
|
20198
20198
|
*/
|
|
20199
20199
|
async function clickAt(slot, targetId, x, y) {
|
|
20200
|
-
|
|
20200
|
+
/**
|
|
20201
|
+
* 🔴🔴 **点击是「会弹窗」的动作,所以自动弹窗必须挂在这条连接上**(2026-11-11 owner 现场报障)。
|
|
20202
|
+
*
|
|
20203
|
+
* 改之前:点一个 `confirm()` 按钮 ⇒ `mouseReleased` **30s 超时**,弹窗留在屏幕上,
|
|
20204
|
+
* 这个 tab 之后所有调用全超时 —— **整条自动化被原地卡死**。
|
|
20205
|
+
* 改之后:事件到达即由浏览器进程 dismiss ⇒ 点击**正常返回**,且回执写明处理了什么。
|
|
20206
|
+
*
|
|
20207
|
+
* ⚠️ 超时也保留兜底:真的 30s 没返回(页面被别的东西卡住),错误文案要说清
|
|
20208
|
+
* 「可能是同步弹窗且自动处理没接住」并给出路,⛔ 不甩一句裸超时。
|
|
20209
|
+
*/
|
|
20210
|
+
const policy = {
|
|
20211
|
+
mode: "dismiss",
|
|
20212
|
+
handled: []
|
|
20213
|
+
};
|
|
20201
20214
|
try {
|
|
20202
|
-
|
|
20203
|
-
|
|
20204
|
-
|
|
20205
|
-
|
|
20206
|
-
|
|
20207
|
-
|
|
20208
|
-
|
|
20209
|
-
|
|
20210
|
-
|
|
20211
|
-
|
|
20212
|
-
|
|
20213
|
-
|
|
20214
|
-
|
|
20215
|
-
|
|
20216
|
-
|
|
20217
|
-
|
|
20218
|
-
|
|
20219
|
-
|
|
20220
|
-
|
|
20221
|
-
|
|
20222
|
-
|
|
20215
|
+
await withPage(slot, targetId, async (send) => {
|
|
20216
|
+
const base = {
|
|
20217
|
+
x,
|
|
20218
|
+
y,
|
|
20219
|
+
button: "left",
|
|
20220
|
+
clickCount: 1
|
|
20221
|
+
};
|
|
20222
|
+
await send("Input.dispatchMouseEvent", {
|
|
20223
|
+
type: "mouseMoved",
|
|
20224
|
+
x,
|
|
20225
|
+
y
|
|
20226
|
+
}, 8e3);
|
|
20227
|
+
await send("Input.dispatchMouseEvent", {
|
|
20228
|
+
type: "mousePressed",
|
|
20229
|
+
...base
|
|
20230
|
+
}, 8e3);
|
|
20231
|
+
await send("Input.dispatchMouseEvent", {
|
|
20232
|
+
type: "mouseReleased",
|
|
20233
|
+
...base
|
|
20234
|
+
}, 2e4);
|
|
20235
|
+
}, { autoDialog: policy });
|
|
20236
|
+
} catch (e) {
|
|
20237
|
+
const msg = String(e?.message ?? e);
|
|
20238
|
+
if (/超时|timeout/i.test(msg) && policy.handled.length === 0) throw new Error(`⛔ 点击超时(${msg}),且本次**没有捕获到任何弹窗**。\n ⇒ 页面可能被同步脚本卡住(死循环 / 大计算 / 已存在的弹窗不是本连接触发的)。\n ⇒ 出路:\`browser_slot dialog\` 试一次救场;不行就 \`close\` 掉这个 tab 重来。\n ⚠️ 自动弹窗处理**只对本连接期间新出现的弹窗**生效。`);
|
|
20239
|
+
throw e;
|
|
20223
20240
|
}
|
|
20241
|
+
return { dialogs: policy.handled };
|
|
20224
20242
|
}
|
|
20225
20243
|
/** 正文(`document.body.innerText`) */
|
|
20226
20244
|
async function pageText(slot, targetId) {
|
|
@@ -20283,31 +20301,71 @@ function resolveShotPath(cccRoot, relOrAbs) {
|
|
|
20283
20301
|
return abs;
|
|
20284
20302
|
}
|
|
20285
20303
|
/**
|
|
20286
|
-
*
|
|
20304
|
+
* 🔴🔴 **自动处理原生弹窗(2026-11-11 owner 现场报障)**
|
|
20305
|
+
*
|
|
20306
|
+
* **现象**(owner 截图):点一个会 `confirm()` 的按钮 ⇒ 弹窗留在屏幕上,**整个自动化流程被原地卡死** ——
|
|
20307
|
+
* 那次 `click` 30s 超时,之后这个 tab 上**所有** CDP 调用全部超时,只能 `close` 掉重来。
|
|
20287
20308
|
*
|
|
20288
|
-
*
|
|
20289
|
-
*
|
|
20290
|
-
*
|
|
20309
|
+
* **为什么以前必须在点击之后手动调 `dialog` 是错的**:那个编排要求调用方**预知**「这一下会弹窗」,
|
|
20310
|
+
* 而真实站点里弹窗常由页面逻辑触发(离开确认、删除确认、会话过期重登)——
|
|
20311
|
+
* **没有人能在点击前知道**。⇒ 正确的形态是「**持续在场,事件一到就处理**」。
|
|
20291
20312
|
*
|
|
20292
|
-
*
|
|
20293
|
-
*
|
|
20294
|
-
*
|
|
20313
|
+
* **唯一可行的实现**(判据 D320 的反面):
|
|
20314
|
+
* · 在**同一条连接**上先 `Page.enable` ⇒ 才会收到 `Page.javascriptDialogOpening`
|
|
20315
|
+
* · 事件到达时立刻发 `Page.handleJavaScriptDialog` —— 它由**浏览器进程**处理,
|
|
20316
|
+
* **不经过被阻塞的渲染器**,所以在「点击请求还挂着」的同一时刻也能生效
|
|
20317
|
+
* · 处理完,被阻塞的点击请求才会返回
|
|
20318
|
+
* ⚠️ 顺序反了(先等点击返回再处理弹窗)就永远等不到 —— 那就是这次的卡死。
|
|
20319
|
+
*
|
|
20320
|
+
* **默认 dismiss**(判据 D318:不可逆性小的那侧)。要 accept 必须由调用方显式要求。
|
|
20295
20321
|
*/
|
|
20322
|
+
function attachAutoDialog(send, policy) {
|
|
20323
|
+
if (policy.mode === "none") return null;
|
|
20324
|
+
const accept = policy.mode === "accept";
|
|
20325
|
+
return {
|
|
20326
|
+
events: ["Page.javascriptDialogOpening"],
|
|
20327
|
+
onEvent: (method, params) => {
|
|
20328
|
+
if (method !== "Page.javascriptDialogOpening") return;
|
|
20329
|
+
const entry = {
|
|
20330
|
+
type: String(params.type ?? ""),
|
|
20331
|
+
message: String(params.message ?? ""),
|
|
20332
|
+
accepted: accept
|
|
20333
|
+
};
|
|
20334
|
+
policy.handled.push(entry);
|
|
20335
|
+
send("Page.handleJavaScriptDialog", { accept }, 8e3).catch(() => {});
|
|
20336
|
+
}
|
|
20337
|
+
};
|
|
20338
|
+
}
|
|
20296
20339
|
async function withPage(slot, targetId, fn, opts = {}) {
|
|
20297
20340
|
const conn = attach(await wsConnect(await pageWsUrl(slot, targetId)));
|
|
20298
|
-
|
|
20299
|
-
|
|
20300
|
-
|
|
20301
|
-
|
|
20302
|
-
|
|
20303
|
-
|
|
20304
|
-
|
|
20305
|
-
|
|
20306
|
-
|
|
20307
|
-
};
|
|
20308
|
-
}
|
|
20341
|
+
const send = (method, params, timeoutMs) => cdpRaw(conn, method, params, timeoutMs);
|
|
20342
|
+
/**
|
|
20343
|
+
* 🔴 **默认就是 dismiss**(判据 D318 + 2026-11-11 owner 报障)。
|
|
20344
|
+
* 只有显式 `{ mode: 'none' }` 才把弹窗交回调用方 —— 那意味着调用方承诺自己接得住。
|
|
20345
|
+
*/
|
|
20346
|
+
const policy = opts.autoDialog ?? {
|
|
20347
|
+
mode: "dismiss",
|
|
20348
|
+
handled: []
|
|
20349
|
+
};
|
|
20309
20350
|
try {
|
|
20310
|
-
|
|
20351
|
+
const auto = attachAutoDialog(send, policy);
|
|
20352
|
+
if (auto) await send("Page.enable", {}, 8e3).catch(() => {});
|
|
20353
|
+
const events = [...opts.events ?? [], ...auto?.events ?? []];
|
|
20354
|
+
if (events.length > 0) {
|
|
20355
|
+
const want = new Set(events);
|
|
20356
|
+
const prev = conn.ws.onmessage;
|
|
20357
|
+
conn.ws.onmessage = (ev) => {
|
|
20358
|
+
prev?.call(conn.ws, ev);
|
|
20359
|
+
try {
|
|
20360
|
+
const msg = JSON.parse(typeof ev.data === "string" ? ev.data : String(ev.data));
|
|
20361
|
+
if (!msg.method || !want.has(msg.method)) return;
|
|
20362
|
+
auto?.onEvent(msg.method, msg.params ?? {});
|
|
20363
|
+
if (opts.onEvent && !auto) opts.onEvent(msg.method, msg.params ?? {});
|
|
20364
|
+
if (opts.onEvent && auto && msg.method !== "Page.javascriptDialogOpening") opts.onEvent(msg.method, msg.params ?? {});
|
|
20365
|
+
} catch {}
|
|
20366
|
+
};
|
|
20367
|
+
}
|
|
20368
|
+
return await fn(send);
|
|
20311
20369
|
} finally {
|
|
20312
20370
|
conn.ws.close();
|
|
20313
20371
|
}
|
|
@@ -22033,7 +22091,7 @@ async function slotClick(root, slot, sessionId, targetId, opts) {
|
|
|
22033
22091
|
assertSlotOwned(root, slot, sessionId);
|
|
22034
22092
|
if (!opts.text && !opts.xy) throw new Error("⛔ 需要 --text=<按钮可见文字> 或 --xy=<x,y>(先 targets 拿 targetId)");
|
|
22035
22093
|
if (opts.xy) {
|
|
22036
|
-
await clickAt(slot, targetId, opts.xy.x, opts.xy.y);
|
|
22094
|
+
const r = await clickAt(slot, targetId, opts.xy.x, opts.xy.y);
|
|
22037
22095
|
pageTouched(root, slot);
|
|
22038
22096
|
return {
|
|
22039
22097
|
picked: {
|
|
@@ -22048,7 +22106,8 @@ async function slotClick(root, slot, sessionId, targetId, opts) {
|
|
|
22048
22106
|
pointerNone: false,
|
|
22049
22107
|
download: false
|
|
22050
22108
|
},
|
|
22051
|
-
total: 0
|
|
22109
|
+
total: 0,
|
|
22110
|
+
dialogs: r.dialogs
|
|
22052
22111
|
};
|
|
22053
22112
|
}
|
|
22054
22113
|
const raw = await evalInPage(slot, targetId, COLLECT_CLICKABLE, 15e3);
|
|
@@ -22060,11 +22119,12 @@ async function slotClick(root, slot, sessionId, targetId, opts) {
|
|
|
22060
22119
|
if (res.reason === "not-clickable") throw new Error(`⛔ 「${opts.text}」找到了,但${res.why}。\n ⇒ 这不是"尽力点一下"的场合:点了没反应与没点,在读数上一样。\n${renderClickables(res.hits)}`);
|
|
22061
22120
|
throw new Error(`⛔ 页面上没有可点元素匹配「${opts.text}」(匹配渲染后的可见文本,含 value/aria-label/title)。\n ⇒ 当前 ${visible.length} 个可见可点元素:\n${renderClickables(visible)}`);
|
|
22062
22121
|
}
|
|
22063
|
-
await clickAt(slot, targetId, res.el.x, res.el.y);
|
|
22122
|
+
const clicked = await clickAt(slot, targetId, res.el.x, res.el.y);
|
|
22064
22123
|
pageTouched(root, slot);
|
|
22065
22124
|
return {
|
|
22066
22125
|
picked: res.el,
|
|
22067
|
-
total: list.length
|
|
22126
|
+
total: list.length,
|
|
22127
|
+
dialogs: clicked.dialogs
|
|
22068
22128
|
};
|
|
22069
22129
|
}
|
|
22070
22130
|
/** 列当前槽位上的 targets */
|
|
@@ -22322,6 +22382,52 @@ async function slotExt(root, slot, sessionId, name, args) {
|
|
|
22322
22382
|
return res;
|
|
22323
22383
|
}
|
|
22324
22384
|
//#endregion
|
|
22385
|
+
//#region src/browser/coords.ts
|
|
22386
|
+
/**
|
|
22387
|
+
* 解析坐标。
|
|
22388
|
+
*
|
|
22389
|
+
* 判据(每条都是「宁可拒绝」):
|
|
22390
|
+
* ① 只接受三种形态;其余(布尔、裸数字、对象缺分量)⇒ null
|
|
22391
|
+
* ② 分量必须是**有限数**且 **≥ 0** —— 负数与 NaN 会让点击落到别处或直接被 CDP 丢弃
|
|
22392
|
+
* ③ 字符串形态按 `,` 或空白切;**必须正好两个分量**(`"1,2,3"` 拒绝,⛔ 不取前两个)
|
|
22393
|
+
*/
|
|
22394
|
+
function parseXY(raw) {
|
|
22395
|
+
if (raw === null || raw === void 0) return void 0;
|
|
22396
|
+
let a;
|
|
22397
|
+
let b;
|
|
22398
|
+
if (typeof raw === "string") {
|
|
22399
|
+
const parts = raw.split(/[,\s]+/).filter((s) => s !== "");
|
|
22400
|
+
if (parts.length !== 2) return void 0;
|
|
22401
|
+
a = parts[0];
|
|
22402
|
+
b = parts[1];
|
|
22403
|
+
} else if (Array.isArray(raw)) {
|
|
22404
|
+
if (raw.length !== 2) return void 0;
|
|
22405
|
+
a = raw[0];
|
|
22406
|
+
b = raw[1];
|
|
22407
|
+
} else if (typeof raw === "object") {
|
|
22408
|
+
const o = raw;
|
|
22409
|
+
a = o.x;
|
|
22410
|
+
b = o.y;
|
|
22411
|
+
if (a === void 0 || b === void 0) return void 0;
|
|
22412
|
+
} else return;
|
|
22413
|
+
const x = typeof a === "number" ? a : Number(a);
|
|
22414
|
+
const y = typeof b === "number" ? b : Number(b);
|
|
22415
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return void 0;
|
|
22416
|
+
if (x < 0 || y < 0) return void 0;
|
|
22417
|
+
return {
|
|
22418
|
+
x,
|
|
22419
|
+
y
|
|
22420
|
+
};
|
|
22421
|
+
}
|
|
22422
|
+
/** 拒绝时列给调用方的三种正确形态(⛔ 只列一种 —— 那等于又把口子收窄回去) */
|
|
22423
|
+
function xyFormHint(param = "xy") {
|
|
22424
|
+
return [
|
|
22425
|
+
` --${param}=1428,76 (字符串:逗号分隔)`,
|
|
22426
|
+
` --${param}=[1428,76] (数组:两个数字)`,
|
|
22427
|
+
` --${param}={x:1428,y:76} (对象)`
|
|
22428
|
+
].join("\n");
|
|
22429
|
+
}
|
|
22430
|
+
//#endregion
|
|
22325
22431
|
//#region src/tools/browser-slot/index.ts
|
|
22326
22432
|
/**
|
|
22327
22433
|
* tools/browser-slot/index.ts — browser_slot 工具(ACC 级浏览器槽位管理器)
|
|
@@ -22397,18 +22503,6 @@ async function needTarget(root, n, sessionId, args) {
|
|
|
22397
22503
|
match
|
|
22398
22504
|
});
|
|
22399
22505
|
}
|
|
22400
|
-
/** 解析 `--xy=x,y`(也接受 `x y`)。⛔ 非有限数、负数一律当没给 —— 越界坐标会让点击落到别处。 */
|
|
22401
|
-
function parseXY(raw) {
|
|
22402
|
-
if (!raw) return void 0;
|
|
22403
|
-
const parts = raw.split(/[,\s]+/).filter(Boolean);
|
|
22404
|
-
if (parts.length !== 2) return void 0;
|
|
22405
|
-
const x = Number(parts[0]);
|
|
22406
|
-
const y = Number(parts[1]);
|
|
22407
|
-
return Number.isFinite(x) && Number.isFinite(y) && x >= 0 && y >= 0 ? {
|
|
22408
|
-
x,
|
|
22409
|
-
y
|
|
22410
|
-
} : void 0;
|
|
22411
|
-
}
|
|
22412
22506
|
/** 取字符串参数(空串当没给) */
|
|
22413
22507
|
function str(v) {
|
|
22414
22508
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
@@ -22538,13 +22632,15 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
22538
22632
|
const n = needSlot(args);
|
|
22539
22633
|
const target = await needTarget(root, n, sessionId, args);
|
|
22540
22634
|
const text = str(args.text);
|
|
22541
|
-
const xy = parseXY(
|
|
22542
|
-
if (!text && !xy) return
|
|
22543
|
-
const { picked } = await slotClick(root, n, sessionId, target, {
|
|
22635
|
+
const xy = parseXY(args.xy);
|
|
22636
|
+
if (!text && !xy) return `⛔ 需要 --text=<按钮可见文字> 或坐标(坐标三种写法都收):\n${xyFormHint("xy")}\n 例如:--text=登录`;
|
|
22637
|
+
const { picked, dialogs } = await slotClick(root, n, sessionId, target, {
|
|
22544
22638
|
text,
|
|
22545
22639
|
xy
|
|
22546
22640
|
});
|
|
22547
|
-
|
|
22641
|
+
const base = xy ? `[browser_slot] clicked @${xy.x},${xy.y}(坐标直给;未做命中校验)` : `[browser_slot] clicked <${picked.tag}> "${picked.text.slice(0, 60)}" @${picked.x},${picked.y}`;
|
|
22642
|
+
if (dialogs.length === 0) return base;
|
|
22643
|
+
return `${base}\n${dialogs.map((d) => ` ⚠️ 自动处理弹窗 ${d.type || "(未知类型)"}:${JSON.stringify(d.message.slice(0, 100))} ⇒ ${d.accepted ? "已确定" : "已取消"}`).join("\n")}\n (默认取消;要「确定」请单独用 dialog --accept —— OK 常意味着删除/支付/发布)`;
|
|
22548
22644
|
}
|
|
22549
22645
|
case "ax": {
|
|
22550
22646
|
const n = needSlot(args);
|
|
@@ -22584,7 +22680,7 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
22584
22680
|
const n = needSlot(args);
|
|
22585
22681
|
const target = await needTarget(root, n, sessionId, args);
|
|
22586
22682
|
const refStr = str(args.ref);
|
|
22587
|
-
const xy = parseXY(
|
|
22683
|
+
const xy = parseXY(args.xy);
|
|
22588
22684
|
const toRaw = str(args.to);
|
|
22589
22685
|
const to = toRaw === "top" || toRaw === "bottom" ? toRaw : void 0;
|
|
22590
22686
|
if (!refStr && !xy && !to) return "⛔ 需要 --ref=<eNNN> / --xy=<x,y> / --to=<top|bottom> 之一";
|
|
@@ -22608,11 +22704,12 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
22608
22704
|
case "drag": {
|
|
22609
22705
|
const n = needSlot(args);
|
|
22610
22706
|
const target = await needTarget(root, n, sessionId, args);
|
|
22611
|
-
const from = parseXY(
|
|
22612
|
-
const to = parseXY(
|
|
22613
|
-
if (!from || !to) return
|
|
22614
|
-
|
|
22615
|
-
|
|
22707
|
+
const from = parseXY(args.from);
|
|
22708
|
+
const to = parseXY(args.to);
|
|
22709
|
+
if (!from || !to) return `⛔ 需要 --from 与 --to(坐标三种写法都收):\n${xyFormHint("from")}${xyFormHint("to")}\n 先 ax 拿 ref,再用 scroll/eval 量坐标`;
|
|
22710
|
+
const steps = num(args.steps) ?? 12;
|
|
22711
|
+
await slotDrag(root, n, sessionId, target, from, to, steps);
|
|
22712
|
+
return `[browser_slot] drag ${from.x},${from.y} → ${to.x},${to.y}(分 ${steps} 步;⛔ 回执不说拖成功)`;
|
|
22616
22713
|
}
|
|
22617
22714
|
case "upload": {
|
|
22618
22715
|
const n = needSlot(args);
|
|
@@ -22725,8 +22822,35 @@ function createBrowserSlotTool(ctx) {
|
|
|
22725
22822
|
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"
|
|
22726
22823
|
},
|
|
22727
22824
|
xy: {
|
|
22728
|
-
|
|
22729
|
-
|
|
22825
|
+
oneOf: [
|
|
22826
|
+
{
|
|
22827
|
+
type: "string",
|
|
22828
|
+
description: "\"x,y\" (comma or space separated)"
|
|
22829
|
+
},
|
|
22830
|
+
{
|
|
22831
|
+
type: "array",
|
|
22832
|
+
items: { type: "number" },
|
|
22833
|
+
description: "[x, y]"
|
|
22834
|
+
},
|
|
22835
|
+
{
|
|
22836
|
+
type: "object",
|
|
22837
|
+
properties: {
|
|
22838
|
+
x: {
|
|
22839
|
+
type: "number",
|
|
22840
|
+
required: true,
|
|
22841
|
+
description: "viewport x"
|
|
22842
|
+
},
|
|
22843
|
+
y: {
|
|
22844
|
+
type: "number",
|
|
22845
|
+
required: true,
|
|
22846
|
+
description: "viewport y"
|
|
22847
|
+
}
|
|
22848
|
+
},
|
|
22849
|
+
additionalProperties: false,
|
|
22850
|
+
description: "{x, y}"
|
|
22851
|
+
}
|
|
22852
|
+
],
|
|
22853
|
+
description: "click / scroll: viewport coordinates as \"x,y\" | [x,y] | {x,y}. ⛔ Not a slot or element id — pass `ref` for provenance"
|
|
22730
22854
|
},
|
|
22731
22855
|
script: {
|
|
22732
22856
|
type: "string",
|
|
@@ -22761,8 +22885,33 @@ function createBrowserSlotTool(ctx) {
|
|
|
22761
22885
|
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"
|
|
22762
22886
|
},
|
|
22763
22887
|
from: {
|
|
22764
|
-
|
|
22765
|
-
|
|
22888
|
+
oneOf: [
|
|
22889
|
+
{
|
|
22890
|
+
type: "string",
|
|
22891
|
+
description: "\"x,y\""
|
|
22892
|
+
},
|
|
22893
|
+
{
|
|
22894
|
+
type: "array",
|
|
22895
|
+
items: { type: "number" },
|
|
22896
|
+
description: "[x, y]"
|
|
22897
|
+
},
|
|
22898
|
+
{
|
|
22899
|
+
type: "object",
|
|
22900
|
+
properties: {
|
|
22901
|
+
x: {
|
|
22902
|
+
type: "number",
|
|
22903
|
+
required: true
|
|
22904
|
+
},
|
|
22905
|
+
y: {
|
|
22906
|
+
type: "number",
|
|
22907
|
+
required: true
|
|
22908
|
+
}
|
|
22909
|
+
},
|
|
22910
|
+
additionalProperties: false,
|
|
22911
|
+
description: "{x, y}"
|
|
22912
|
+
}
|
|
22913
|
+
],
|
|
22914
|
+
description: "drag: start point in viewport coords (three forms, same as xy)"
|
|
22766
22915
|
},
|
|
22767
22916
|
steps: {
|
|
22768
22917
|
type: "number",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shgroup/dsh-serenity-hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.132.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": {
|