@shgroup/dsh-serenity-hooks 1.129.3 → 1.129.5
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 +12 -0
- package/lib/browser/click-target.d.ts +60 -0
- package/lib/browser/service.d.ts +37 -1
- package/lib/browser/target-pick.d.ts +43 -0
- package/lib/index.js +379 -29
- package/lib/{observation-ryu83rOe.js → observation-VUiQdjqd.js} +1 -1
- package/lib/{scheduler-CgjLs5_S.js → scheduler-Cbz5ou-X.js} +26 -1
- package/lib/{service-CTD39Kby.js → service-B92214NE.js} +3 -3
- package/lib/{subscriptions-C4oGjnC2.js → subscriptions-CMhWkapn.js} +2 -2
- package/lib/wake/scheduler.d.ts +20 -0
- 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.129.
|
|
3
|
+
"version": "1.129.5",
|
|
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
|
@@ -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;
|
package/lib/browser/service.d.ts
CHANGED
|
@@ -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
|
@@ -8,12 +8,12 @@ import { C as runMsmAsync, S as runMsm, T as setWeixinSendEndpoint, _ as ACC_CAT
|
|
|
8
8
|
import { c as replacesDefaultIdentity, i as listTrajectoryConstraints, l as trajectoryCodeForSession, n as findDirNameByCode, o as readTrajectoryConstraintAt, r as isTrajectoryConstrained, s as readTrajectoryConstraintByCode, t as TRAJECTORY_CONSTRAINT_FILENAME } from "./profile-DpxC9HtB.js";
|
|
9
9
|
import { A as TRAJECTORY_PROMPT_FILENAME, C as recordToolUsage, D as buildResourceNameSuffix, E as buildResourceIndex, O as isSafeSkillName, S as verifyTotpCode, T as SKILL_ONTOLOGY_FILE, _ as projectKnownWorkspaces, a as trajectoryConstraintFor, b as FACE_PORTS, c as trajectoryWorkspaceMdPath, d as splitModel, f as registerCognitiveTrajectorySkillSection, g as migrateLegacyLocalstore, h as applyWirePatch, i as getTrajectoryAgent, j as hasTrajectoryPrompt, k as truncateContent, l as unregisterTrajectorySession, m as registerEntrySkillSectionGlobal, n as deliverToTrajectory, o as trajectoryConstraintMsmGate, p as registerEntrySkillSection, r as ensureWorkspacePromptSection, s as trajectoryConstraintParticipates, t as createTrajectoryAgent, u as workspaceCognitiveTrajectoryLine, v as readAdvancedSettings, w as REFERENCE_DIR, x as MECHANISM_PORTS, y as toWire } from "./session-B5CKVEIF.js";
|
|
10
10
|
import { a as ACC_MESSAGE_KIND, d as readLastBound, f as resolveSessionCognitiveTrajectoryLabel, i as toMessage, l as findTrajectoryOfSession, n as deliver, o as PLUGIN_SOURCE, r as makeInjection, s as appendBound, u as listBoundSessionIds } from "./injection-CKx49Mlf.js";
|
|
11
|
-
import { _ as WAKE_CATCH_UP_MS, c as formatPendingTools, d as listRunningSessionIds, f as registerCroTurnTracking, g as CARRIER_OPENING_MARK, i as sendToCognitiveTrajectory, l as projectDirNameForCwd, m as buildCroSnapshot, n as registerWakeScheduler, o as DEFAULT_LOOKBACK_MS, p as registerDisposer, s as createResumeOne, t as createAndBindTarget, u as scanInterruptedSessions, v as addWake } from "./scheduler-
|
|
11
|
+
import { _ as WAKE_CATCH_UP_MS, c as formatPendingTools, d as listRunningSessionIds, f as registerCroTurnTracking, g as CARRIER_OPENING_MARK, i as sendToCognitiveTrajectory, l as projectDirNameForCwd, m as buildCroSnapshot, n as registerWakeScheduler, o as DEFAULT_LOOKBACK_MS, p as registerDisposer, s as createResumeOne, t as createAndBindTarget, u as scanInterruptedSessions, v as addWake } from "./scheduler-Cbz5ou-X.js";
|
|
12
12
|
import { i as sessionsRootDir } from "./cleanup-CPl1SSaK.js";
|
|
13
13
|
import { i as hostAliveProbe, n as readSimpleSettings, r as registerSettingsSection } from "./settings-CUabGkal.js";
|
|
14
14
|
import { a as readFeishuCredential, c as readWeixinSettings, d as weixinInboundDir, f as weixinSessionIdForTrajectory, i as matchWeixinRoute, n as extractWeixinText, r as hasVoiceItem, s as readWeixinCredential, t as extractWeixinMedia, u as sanitizeFileName$1 } from "./route-C2rARdoU.js";
|
|
15
15
|
import { i as runImBridge, n as isImWiredTrajectory, r as registerImChannel, t as imChannelIds } from "./channels-w8H6l04X.js";
|
|
16
|
-
import { i as subscriptionStats, n as registerTrajectorySubscriptions, r as subscriptionEval, t as defaultSubscriptionDeps } from "./subscriptions-
|
|
16
|
+
import { i as subscriptionStats, n as registerTrajectorySubscriptions, r as subscriptionEval, t as defaultSubscriptionDeps } from "./subscriptions-CMhWkapn.js";
|
|
17
17
|
import { c as sendTextMessage, i as getUpdates, l as sendTyping, n as downloadMedia, o as markdownToPlainText, r as getConfig, s as sendFileMessage, t as TypingStatus, u as sniffImageExt } from "./ilink-CsZ-f64q.js";
|
|
18
18
|
import { a as registerImAccountImpl, i as normalizeAccountChannel, n as getImAccountImpl, r as imAccountChannels } from "./accounts-BHQbakUh.js";
|
|
19
19
|
import { createRequire } from "node:module";
|
|
@@ -515,7 +515,7 @@ const KIT_ACTIONS = [
|
|
|
515
515
|
async function runKit(root, args, hostCtx) {
|
|
516
516
|
switch (args.action) {
|
|
517
517
|
case "health": {
|
|
518
|
-
const { containerStatus } = await import("./observation-
|
|
518
|
+
const { containerStatus } = await import("./observation-VUiQdjqd.js");
|
|
519
519
|
const s = containerStatus({
|
|
520
520
|
root,
|
|
521
521
|
hostCtx
|
|
@@ -561,7 +561,7 @@ async function runKit(root, args, hostCtx) {
|
|
|
561
561
|
}
|
|
562
562
|
case "diag": {
|
|
563
563
|
if (hostCtx === void 0) throw new Error("diag requires the plugin context (live session data unavailable without it)");
|
|
564
|
-
const { runDiag, renderDiag } = await import("./service-
|
|
564
|
+
const { runDiag, renderDiag } = await import("./service-B92214NE.js");
|
|
565
565
|
return renderDiag(await runDiag(hostCtx, root ?? ""));
|
|
566
566
|
}
|
|
567
567
|
default: throw new Error(`Unknown action: ${args.action}`);
|
|
@@ -9070,7 +9070,40 @@ function queueReconstruct(ctx, opts) {
|
|
|
9070
9070
|
*/
|
|
9071
9071
|
async function performReconstruct(ctx, root, oldSessionId, pending) {
|
|
9072
9072
|
const dirName = basename(dirname(pending.mdPath));
|
|
9073
|
-
|
|
9073
|
+
/**
|
|
9074
|
+
* 🔴 **2026-11-10(owner 报障「这个东西不应当排队,应当直接进」):锚点必须在开场白之前入队。**
|
|
9075
|
+
*
|
|
9076
|
+
* 真机缺陷(platform-9047 换代日志,逐字):`seq 12` 是**开场白**落在 `next-turn`,
|
|
9077
|
+
* `seq 76` 才是**继续锚点**(也是 `next-turn`)⇒ 宿主 `inbox.claim('next-turn', …)`
|
|
9078
|
+
* **每轮只认领 1 条** ⇒ 第 1 轮只拿到开场白,而开场白正文写的就是"接着它 SESSION.md 里的
|
|
9079
|
+
* 工作往下做" ⇒ **模型在读到锚点之前就开始干活**,锚点在排队区等到第 2 轮。
|
|
9080
|
+
*
|
|
9081
|
+
* ⇒ 修法:锚点走 `agent.inject()`(`next-step`,**不唤醒**),开场白仍走 `followup`。
|
|
9082
|
+
* `claim()` **先整批取 `next-step` 再取 1 条 `next-turn`** ⇒ 第 1 轮第 1 步拿到
|
|
9083
|
+
* `[锚点, 开场白]`,锚点在前 —— 这才叫"直接进"。
|
|
9084
|
+
*
|
|
9085
|
+
* ⚠️ **`inject` 不是 `steer`**:`inject` = `send(msg,'next-step',false)`(不唤醒),
|
|
9086
|
+
* 正是我们要的(唤醒由开场白那条 `followup` 负责,一条消息只唤醒一次)。
|
|
9087
|
+
* 用 `steer` 会多唤一次,且语义上"插进正在跑的轮"在这里不成立(新 agent 没有在跑的轮)。
|
|
9088
|
+
*/
|
|
9089
|
+
const created = await createAndBindTarget(ctx, root, dirName, {
|
|
9090
|
+
takeover: true,
|
|
9091
|
+
beforeOpening: (a) => {
|
|
9092
|
+
/**
|
|
9093
|
+
* ⚠️ **必须用 `toMessage` + `agent.inject`,⛔ 不能用 `deliver(…, 'this-step')`** ——
|
|
9094
|
+
* `deliver()` 对 `this-step` 是**显式抛错**的(那一档走 `additionalContexts` 返回,
|
|
9095
|
+
* 不是调 agent 方法;见 `kernel/injection.ts` 的 `deliver` 头注)。这里要的正是
|
|
9096
|
+
* 调 agent 方法,故走 `toMessage` 那一半(它同样过 `assertInjection` + `sourceOf`)。
|
|
9097
|
+
*/
|
|
9098
|
+
a.inject?.(toMessage(makeInjection({
|
|
9099
|
+
origin: "acc",
|
|
9100
|
+
form: "instructions",
|
|
9101
|
+
summary: "reconstruct 后继续",
|
|
9102
|
+
text: pending.anchor,
|
|
9103
|
+
delivery: "this-step"
|
|
9104
|
+
})));
|
|
9105
|
+
}
|
|
9106
|
+
});
|
|
9074
9107
|
if ("error" in created) throw new Error(`创建新载体失败:${created.error}`);
|
|
9075
9108
|
const agent = created.agent;
|
|
9076
9109
|
const newSessionId = String(agent.id ?? "");
|
|
@@ -9083,13 +9116,6 @@ async function performReconstruct(ctx, root, oldSessionId, pending) {
|
|
|
9083
9116
|
mdPath: pending.mdPath
|
|
9084
9117
|
}, pending.summary));
|
|
9085
9118
|
} catch {}
|
|
9086
|
-
deliver(makeInjection({
|
|
9087
|
-
origin: "acc",
|
|
9088
|
-
form: "instructions",
|
|
9089
|
-
summary: "reconstruct 后继续",
|
|
9090
|
-
text: pending.anchor,
|
|
9091
|
-
delivery: "next-turn"
|
|
9092
|
-
}), agent);
|
|
9093
9119
|
writeReconstructDiag(root, {
|
|
9094
9120
|
sessionId: newSessionId,
|
|
9095
9121
|
event: "rebuilt",
|
|
@@ -20159,6 +20185,43 @@ async function closeTab(slot, targetId, all = false) {
|
|
|
20159
20185
|
conn.ws.close();
|
|
20160
20186
|
}
|
|
20161
20187
|
}
|
|
20188
|
+
/**
|
|
20189
|
+
* 真实鼠标点击(CDP `Input.dispatchMouseEvent`)。
|
|
20190
|
+
*
|
|
20191
|
+
* 🔴 **为什么不用 `el.click()`**:它只派发一次合成 `click`,**不产生 pointerdown/mousedown/mouseup**,
|
|
20192
|
+
* 也不做命中测试。React/Vue 之外的大量组件库(含 `choerodon-ui`、多数下拉/浮层)
|
|
20193
|
+
* 监听的是 `pointerdown`/`mousedown` ⇒ 用 `el.click()` 会得到"脚本执行成功、界面毫无反应",
|
|
20194
|
+
* 而那正是最难查的一种——**没报错,也没发生**。
|
|
20195
|
+
*
|
|
20196
|
+
* 🔴 顺序与坐标:`mouseMoved` → `mousePressed` → `mouseReleased`,三次同一坐标。
|
|
20197
|
+
* ⛔ 不发 `mousePressed` 就发 `mouseReleased` 会被 Chrome 丢弃(且**不报错**)。
|
|
20198
|
+
*/
|
|
20199
|
+
async function clickAt(slot, targetId, x, y) {
|
|
20200
|
+
const conn = attach(await wsConnect(await pageWsUrl(slot, targetId)));
|
|
20201
|
+
try {
|
|
20202
|
+
const base = {
|
|
20203
|
+
x,
|
|
20204
|
+
y,
|
|
20205
|
+
button: "left",
|
|
20206
|
+
clickCount: 1
|
|
20207
|
+
};
|
|
20208
|
+
await cdpRaw(conn, "Input.dispatchMouseEvent", {
|
|
20209
|
+
type: "mouseMoved",
|
|
20210
|
+
x,
|
|
20211
|
+
y
|
|
20212
|
+
});
|
|
20213
|
+
await cdpRaw(conn, "Input.dispatchMouseEvent", {
|
|
20214
|
+
type: "mousePressed",
|
|
20215
|
+
...base
|
|
20216
|
+
});
|
|
20217
|
+
await cdpRaw(conn, "Input.dispatchMouseEvent", {
|
|
20218
|
+
type: "mouseReleased",
|
|
20219
|
+
...base
|
|
20220
|
+
});
|
|
20221
|
+
} finally {
|
|
20222
|
+
conn.ws.close();
|
|
20223
|
+
}
|
|
20224
|
+
}
|
|
20162
20225
|
/** 正文(`document.body.innerText`) */
|
|
20163
20226
|
async function pageText(slot, targetId) {
|
|
20164
20227
|
const v = await evalInPage(slot, targetId, "document.body ? document.body.innerText : ''");
|
|
@@ -20456,6 +20519,181 @@ function buildExtPayload(opts) {
|
|
|
20456
20519
|
};
|
|
20457
20520
|
}
|
|
20458
20521
|
//#endregion
|
|
20522
|
+
//#region src/browser/target-pick.ts
|
|
20523
|
+
/**
|
|
20524
|
+
* 挑一个 target。
|
|
20525
|
+
*
|
|
20526
|
+
* @param list 当前槽位上的全部 target(`/json/list` 原样)
|
|
20527
|
+
* @param opts `id` = 直接给 targetId;`match` = URL 或 title 的子串(大小写不敏感)
|
|
20528
|
+
*/
|
|
20529
|
+
function pickTarget(list, opts) {
|
|
20530
|
+
if (opts.id) {
|
|
20531
|
+
const hit = list.find((t) => t.id === opts.id);
|
|
20532
|
+
return hit ? {
|
|
20533
|
+
ok: true,
|
|
20534
|
+
target: hit,
|
|
20535
|
+
by: "id"
|
|
20536
|
+
} : {
|
|
20537
|
+
ok: false,
|
|
20538
|
+
reason: "not-found",
|
|
20539
|
+
hits: []
|
|
20540
|
+
};
|
|
20541
|
+
}
|
|
20542
|
+
const needle = (opts.match ?? "").trim().toLowerCase();
|
|
20543
|
+
if (!needle) return {
|
|
20544
|
+
ok: false,
|
|
20545
|
+
reason: "empty",
|
|
20546
|
+
hits: []
|
|
20547
|
+
};
|
|
20548
|
+
const hits = list.filter((t) => t.type === "page").filter((t) => t.url.toLowerCase().includes(needle) || t.title.toLowerCase().includes(needle));
|
|
20549
|
+
if (hits.length === 0) return {
|
|
20550
|
+
ok: false,
|
|
20551
|
+
reason: "not-found",
|
|
20552
|
+
hits: []
|
|
20553
|
+
};
|
|
20554
|
+
if (hits.length > 1) return {
|
|
20555
|
+
ok: false,
|
|
20556
|
+
reason: "ambiguous",
|
|
20557
|
+
hits
|
|
20558
|
+
};
|
|
20559
|
+
return {
|
|
20560
|
+
ok: true,
|
|
20561
|
+
target: hits[0],
|
|
20562
|
+
by: "match"
|
|
20563
|
+
};
|
|
20564
|
+
}
|
|
20565
|
+
/** 把候选渲染成「可以照着改」的几行(多命中回执用)。 */
|
|
20566
|
+
function renderHits(hits, max = 10) {
|
|
20567
|
+
const shown = hits.slice(0, max);
|
|
20568
|
+
const lines = shown.map((t) => ` ${t.id} ${t.title.slice(0, 40)} ${t.url.slice(0, 90)}`);
|
|
20569
|
+
if (hits.length > shown.length) lines.push(` …另有 ${hits.length - shown.length} 个`);
|
|
20570
|
+
return lines.join("\n");
|
|
20571
|
+
}
|
|
20572
|
+
//#endregion
|
|
20573
|
+
//#region src/browser/click-target.ts
|
|
20574
|
+
/**
|
|
20575
|
+
* click-target.ts — 「按语义点一个元素」的**纯判定**(选中谁),执行在 cdp.ts。
|
|
20576
|
+
*
|
|
20577
|
+
* 🔴🔴 为什么这一格比 `--match`(选 tab)要求更严:
|
|
20578
|
+
* **选错 tab 只是退回来,点错元素是已经发生的事。** 少一步、少一次 `targets` 是便利,
|
|
20579
|
+
* 但便利必须由**判定**承担,不能由"猜"承担 —— 猜错点下去的按钮不会自己撤销。
|
|
20580
|
+
*
|
|
20581
|
+
* 判据(四条,都是"宁可拒绝"):
|
|
20582
|
+
* ① **0 命中 ⇒ 拒绝**,并把页面上可见的可点元素列一批(让调用方一眼改对)。
|
|
20583
|
+
* ② **多命中 ⇒ 拒绝**,列全部候选。⛔ 不选"第一个""最像的""最上层的"。
|
|
20584
|
+
* ③ **命中但不可点**(`disabled` / `aria-disabled=true` / 零尺寸 / `pointer-events:none`)
|
|
20585
|
+
* ⇒ **拒绝**,并说明是哪一条。⛔ 不"尽力点一下试试"—— 点了没反应与点了没点,
|
|
20586
|
+
* 在下一次读数里**看起来一样**,而这正是最难查的那种错。
|
|
20587
|
+
* ④ **可见文本取"渲染后的文本"**,不取 `textContent`:后者含 `display:none` 与
|
|
20588
|
+
* `<script>` 里的字,会让"匹配到了"与"屏幕上真看得见"变成两件事。
|
|
20589
|
+
*
|
|
20590
|
+
* ⛔ **刻意不做的事**:不点 `<input type="file">`(会开系统文件选择器,把自动化卡死)、
|
|
20591
|
+
* 不点带 `download` 的链接(会产生本工具不追踪的落盘)。
|
|
20592
|
+
*/
|
|
20593
|
+
/** 在页面里跑的采集器:把可点元素压成一份小表。 */
|
|
20594
|
+
const COLLECT_CLICKABLE = `(() => {
|
|
20595
|
+
const sel = 'a,button,input,textarea,select,summary,label,[role=button],[role=link],[role=tab],[role=menuitem],[onclick]';
|
|
20596
|
+
const out = [];
|
|
20597
|
+
let i = 0;
|
|
20598
|
+
for (const el of document.querySelectorAll(sel)) {
|
|
20599
|
+
if (i >= 400) break;
|
|
20600
|
+
const r = el.getBoundingClientRect();
|
|
20601
|
+
const cs = getComputedStyle(el);
|
|
20602
|
+
if (cs.display === 'none' || cs.visibility === 'hidden') continue;
|
|
20603
|
+
const type = (el.getAttribute('type') || '').toLowerCase();
|
|
20604
|
+
if (el.tagName === 'INPUT' && type === 'file') continue;
|
|
20605
|
+
const text = ((el.innerText || el.value || el.getAttribute('aria-label') || el.getAttribute('title') || '') + '')
|
|
20606
|
+
.replace(/\\s+/g, ' ').trim();
|
|
20607
|
+
out.push({
|
|
20608
|
+
tag: el.tagName.toLowerCase(),
|
|
20609
|
+
type,
|
|
20610
|
+
text: text.slice(0, 120),
|
|
20611
|
+
role: el.getAttribute('role') || '',
|
|
20612
|
+
x: Math.round(r.left + r.width / 2),
|
|
20613
|
+
y: Math.round(r.top + r.height / 2),
|
|
20614
|
+
w: Math.round(r.width),
|
|
20615
|
+
h: Math.round(r.height),
|
|
20616
|
+
disabled: el.disabled === true || el.getAttribute('aria-disabled') === 'true',
|
|
20617
|
+
pointerNone: cs.pointerEvents === 'none',
|
|
20618
|
+
download: el.hasAttribute('download'),
|
|
20619
|
+
});
|
|
20620
|
+
i++;
|
|
20621
|
+
}
|
|
20622
|
+
return out;
|
|
20623
|
+
})()`;
|
|
20624
|
+
/**
|
|
20625
|
+
* 挑一个元素。
|
|
20626
|
+
*
|
|
20627
|
+
* @param list `COLLECT_CLICKABLE` 的结果
|
|
20628
|
+
* @param opts `xy` = 直接给坐标(⛔ 不参与文本匹配);`text` = 可见文本子串(大小写不敏感)
|
|
20629
|
+
*/
|
|
20630
|
+
function pickClickable(list, opts) {
|
|
20631
|
+
if (opts.xy) return {
|
|
20632
|
+
ok: true,
|
|
20633
|
+
el: {
|
|
20634
|
+
tag: "",
|
|
20635
|
+
type: "",
|
|
20636
|
+
text: "",
|
|
20637
|
+
role: "",
|
|
20638
|
+
...opts.xy,
|
|
20639
|
+
w: 0,
|
|
20640
|
+
h: 0,
|
|
20641
|
+
disabled: false,
|
|
20642
|
+
pointerNone: false,
|
|
20643
|
+
download: false
|
|
20644
|
+
},
|
|
20645
|
+
by: "xy"
|
|
20646
|
+
};
|
|
20647
|
+
const needle = (opts.text ?? "").trim().toLowerCase();
|
|
20648
|
+
if (!needle) return {
|
|
20649
|
+
ok: false,
|
|
20650
|
+
reason: "no-candidate",
|
|
20651
|
+
hits: []
|
|
20652
|
+
};
|
|
20653
|
+
const hits = list.filter((e) => e.w > 0 && e.h > 0).filter((e) => e.text.toLowerCase().includes(needle));
|
|
20654
|
+
if (hits.length === 0) return {
|
|
20655
|
+
ok: false,
|
|
20656
|
+
reason: "not-found",
|
|
20657
|
+
hits: []
|
|
20658
|
+
};
|
|
20659
|
+
if (hits.length > 1) return {
|
|
20660
|
+
ok: false,
|
|
20661
|
+
reason: "ambiguous",
|
|
20662
|
+
hits
|
|
20663
|
+
};
|
|
20664
|
+
const el = hits[0];
|
|
20665
|
+
if (el.pointerNone) return {
|
|
20666
|
+
ok: false,
|
|
20667
|
+
reason: "not-clickable",
|
|
20668
|
+
hits,
|
|
20669
|
+
why: "pointer-events:none(点不到它,点击会穿透到下面的元素)"
|
|
20670
|
+
};
|
|
20671
|
+
if (el.disabled) return {
|
|
20672
|
+
ok: false,
|
|
20673
|
+
reason: "not-clickable",
|
|
20674
|
+
hits,
|
|
20675
|
+
why: "disabled(点它不会有任何效果)"
|
|
20676
|
+
};
|
|
20677
|
+
if (el.download) return {
|
|
20678
|
+
ok: false,
|
|
20679
|
+
reason: "not-clickable",
|
|
20680
|
+
hits,
|
|
20681
|
+
why: "download 链接(会产生本工具不追踪的落盘)"
|
|
20682
|
+
};
|
|
20683
|
+
return {
|
|
20684
|
+
ok: true,
|
|
20685
|
+
el,
|
|
20686
|
+
by: "text"
|
|
20687
|
+
};
|
|
20688
|
+
}
|
|
20689
|
+
/** 把候选渲染成「可以照着改」的几行。 */
|
|
20690
|
+
function renderClickables(list, max = 15) {
|
|
20691
|
+
const shown = list.slice(0, max);
|
|
20692
|
+
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]" : ""}`);
|
|
20693
|
+
if (list.length > shown.length) lines.push(` …另有 ${list.length - shown.length} 个`);
|
|
20694
|
+
return lines.join("\n");
|
|
20695
|
+
}
|
|
20696
|
+
//#endregion
|
|
20459
20697
|
//#region src/browser/service.ts
|
|
20460
20698
|
/**
|
|
20461
20699
|
* browser/service.ts — 槽位管理器的动作实现(ACC 级)
|
|
@@ -20498,6 +20736,7 @@ const SLOT_ACTIONS = [
|
|
|
20498
20736
|
"shot",
|
|
20499
20737
|
"reload",
|
|
20500
20738
|
"close",
|
|
20739
|
+
"click",
|
|
20501
20740
|
"ext-list",
|
|
20502
20741
|
"ext"
|
|
20503
20742
|
];
|
|
@@ -20941,6 +21180,75 @@ function assertSlotOwned(root, slot, sessionId) {
|
|
|
20941
21180
|
function pageTouched(root, slot) {
|
|
20942
21181
|
touchSlot(root, slot);
|
|
20943
21182
|
}
|
|
21183
|
+
/**
|
|
21184
|
+
* 解析「要操作哪个 target」——`--target`(身份)或 `--match`(子串线索)二选一。
|
|
21185
|
+
*
|
|
21186
|
+
* 🔴 **为什么必须有这一层**:`--match` 之前,用户要先跑 `targets` 抄一个 32 位 id 再回来
|
|
21187
|
+
* (owner 2026-11-10 反馈:`msm cdp shot --match` 少一步,`browser_slot` 非要先取 targetId)。
|
|
21188
|
+
* 但"少一步"的代价必须由**判定**承担,不能由"猜"承担 —— 见 `target-pick.ts` 的四条判据。
|
|
21189
|
+
*
|
|
21190
|
+
* 🔴 **判据优先级**:`--target` 在则不读 `--match`(身份 > 线索)。
|
|
21191
|
+
* ⛔ 不做"给了 target 找不到就回落到 match" —— 那会把打错的 id 变成"恰好相符的另一个页面"。
|
|
21192
|
+
*
|
|
21193
|
+
* @returns 解析好的 targetId(**唯一**),或抛出可读错误(0 命中 / 多命中都把候选列全)
|
|
21194
|
+
*/
|
|
21195
|
+
async function resolveTarget(root, slot, sessionId, opts) {
|
|
21196
|
+
if (!opts.target && !opts.match) throw new Error("⛔ 需要 --target=<targetId> 或 --match=<URL 或标题子串>。\n ⇒ 先 `browser_slot targets --slot b1` 看有什么,或直接给 --match=example.com");
|
|
21197
|
+
if (opts.target) return opts.target;
|
|
21198
|
+
const list = await slotTargets(root, slot, sessionId);
|
|
21199
|
+
const res = pickTarget(list, { match: opts.match });
|
|
21200
|
+
if (res.ok) return res.target.id;
|
|
21201
|
+
const pages = list.filter((t) => t.type === "page");
|
|
21202
|
+
if (res.reason === "not-found") throw new Error(`⛔ 没有页面匹配「${opts.match}」(匹配 url 或 title,大小写不敏感)。\n ⇒ 当前 ${pages.length} 个页面:\n${renderHits(pages)}`);
|
|
21203
|
+
throw new Error(`⛔ 「${opts.match}」匹配到 ${res.hits.length} 个页面 —— 拒绝替你选一个(选错会产出一张"看起来对、内容却属于别人"的图)。\n ⇒ 换个更长的子串,或用 --target=<id> 点名:\n${renderHits(res.hits)}`);
|
|
21204
|
+
}
|
|
21205
|
+
/**
|
|
21206
|
+
* 语义化点击:`--text` 子串或 `--xy` 坐标。
|
|
21207
|
+
*
|
|
21208
|
+
* 🔴 判定在 `click-target.ts`(0 命中/多命中/不可点 **全部拒绝**)。
|
|
21209
|
+
* 这一层只做两件它必须做的事:**采集**(跑一次 `COLLECT_CLICKABLE`)与**执行**(真鼠标事件)。
|
|
21210
|
+
*
|
|
21211
|
+
* ⚠️ **返回的是"点了什么"**,不是"点成功了"。⛔ 不在这里等界面变化 ——
|
|
21212
|
+
* 等多久、等什么,属于调用方的判断(本工具不知道这个按钮应该产生什么后果)。
|
|
21213
|
+
*/
|
|
21214
|
+
async function slotClick(root, slot, sessionId, targetId, opts) {
|
|
21215
|
+
assertSlotOwned(root, slot, sessionId);
|
|
21216
|
+
if (!opts.text && !opts.xy) throw new Error("⛔ 需要 --text=<按钮可见文字> 或 --xy=<x,y>(先 targets 拿 targetId)");
|
|
21217
|
+
if (opts.xy) {
|
|
21218
|
+
await clickAt(slot, targetId, opts.xy.x, opts.xy.y);
|
|
21219
|
+
pageTouched(root, slot);
|
|
21220
|
+
return {
|
|
21221
|
+
picked: {
|
|
21222
|
+
tag: "",
|
|
21223
|
+
type: "",
|
|
21224
|
+
text: "",
|
|
21225
|
+
role: "",
|
|
21226
|
+
...opts.xy,
|
|
21227
|
+
w: 0,
|
|
21228
|
+
h: 0,
|
|
21229
|
+
disabled: false,
|
|
21230
|
+
pointerNone: false,
|
|
21231
|
+
download: false
|
|
21232
|
+
},
|
|
21233
|
+
total: 0
|
|
21234
|
+
};
|
|
21235
|
+
}
|
|
21236
|
+
const raw = await evalInPage(slot, targetId, COLLECT_CLICKABLE, 15e3);
|
|
21237
|
+
const list = Array.isArray(raw) ? raw : [];
|
|
21238
|
+
const res = pickClickable(list, { text: opts.text });
|
|
21239
|
+
if (!res.ok) {
|
|
21240
|
+
const visible = list.filter((e) => e.w > 0 && e.h > 0);
|
|
21241
|
+
if (res.reason === "ambiguous") throw new Error(`⛔ 「${opts.text}」匹配到 ${res.hits.length} 个可点元素 —— 拒绝替你选(点错是已经发生的事,不会自己撤销)。\n ⇒ 换个更长的文字,或用 --xy=<x,y> 点名:\n${renderClickables(res.hits)}`);
|
|
21242
|
+
if (res.reason === "not-clickable") throw new Error(`⛔ 「${opts.text}」找到了,但${res.why}。\n ⇒ 这不是"尽力点一下"的场合:点了没反应与没点,在读数上一样。\n${renderClickables(res.hits)}`);
|
|
21243
|
+
throw new Error(`⛔ 页面上没有可点元素匹配「${opts.text}」(匹配渲染后的可见文本,含 value/aria-label/title)。\n ⇒ 当前 ${visible.length} 个可见可点元素:\n${renderClickables(visible)}`);
|
|
21244
|
+
}
|
|
21245
|
+
await clickAt(slot, targetId, res.el.x, res.el.y);
|
|
21246
|
+
pageTouched(root, slot);
|
|
21247
|
+
return {
|
|
21248
|
+
picked: res.el,
|
|
21249
|
+
total: list.length
|
|
21250
|
+
};
|
|
21251
|
+
}
|
|
20944
21252
|
/** 列当前槽位上的 targets */
|
|
20945
21253
|
async function slotTargets(root, slot, sessionId) {
|
|
20946
21254
|
assertSlotOwned(root, slot, sessionId);
|
|
@@ -21096,6 +21404,33 @@ function needSlot(args) {
|
|
|
21096
21404
|
if (n === 0) throw new Error(`⛔ 需要 --slot <b1..b20>(当前收到 ${JSON.stringify(args.slot)})。\n ⇒ 页面操作必须指明槽位:先 \`browser_slot list\` 看你租的是哪个。`);
|
|
21097
21405
|
return n;
|
|
21098
21406
|
}
|
|
21407
|
+
/**
|
|
21408
|
+
* 解析「要操作哪个 target」——`--target`(身份)或 `--match`(子串线索)二选一。
|
|
21409
|
+
*
|
|
21410
|
+
* 🔴 判据在 `browser/target-pick.ts`(0 命中不猜 / 多命中不猜 / 身份优先于线索)。
|
|
21411
|
+
* 这里只负责**把拒绝翻成人话**:多命中时把候选列全,让调用方一次就能改对。
|
|
21412
|
+
*/
|
|
21413
|
+
async function needTarget(root, n, sessionId, args) {
|
|
21414
|
+
const target = str(args.target);
|
|
21415
|
+
const match = str(args.match);
|
|
21416
|
+
if (!target && !match) throw new Error("⛔ 需要 --target=<targetId> 或 --match=<URL/标题子串>(先跑 targets 看清有什么)。\n ⇒ --match 是子串匹配,命中唯一才动手;命中多个会拒绝并列全候选。");
|
|
21417
|
+
return resolveTarget(root, n, sessionId, {
|
|
21418
|
+
target,
|
|
21419
|
+
match
|
|
21420
|
+
});
|
|
21421
|
+
}
|
|
21422
|
+
/** 解析 `--xy=x,y`(也接受 `x y`)。⛔ 非有限数、负数一律当没给 —— 越界坐标会让点击落到别处。 */
|
|
21423
|
+
function parseXY(raw) {
|
|
21424
|
+
if (!raw) return void 0;
|
|
21425
|
+
const parts = raw.split(/[,\s]+/).filter(Boolean);
|
|
21426
|
+
if (parts.length !== 2) return void 0;
|
|
21427
|
+
const x = Number(parts[0]);
|
|
21428
|
+
const y = Number(parts[1]);
|
|
21429
|
+
return Number.isFinite(x) && Number.isFinite(y) && x >= 0 && y >= 0 ? {
|
|
21430
|
+
x,
|
|
21431
|
+
y
|
|
21432
|
+
} : void 0;
|
|
21433
|
+
}
|
|
21099
21434
|
/** 取字符串参数(空串当没给) */
|
|
21100
21435
|
function str(v) {
|
|
21101
21436
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
@@ -21190,50 +21525,53 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
21190
21525
|
}
|
|
21191
21526
|
case "goto": {
|
|
21192
21527
|
const n = needSlot(args);
|
|
21193
|
-
const target = str(args.target);
|
|
21194
21528
|
const url = str(args.url);
|
|
21195
|
-
if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
|
|
21196
21529
|
if (!url) return "⛔ 需要 --url=<地址>";
|
|
21530
|
+
const target = await needTarget(root, n, sessionId, args);
|
|
21197
21531
|
await slotGoto(root, n, sessionId, target, url);
|
|
21198
21532
|
return `[browser_slot] navigate ${target} → ${url}`;
|
|
21199
21533
|
}
|
|
21200
21534
|
case "eval": {
|
|
21201
21535
|
const n = needSlot(args);
|
|
21202
|
-
const target = str(args.target);
|
|
21203
21536
|
const js = str(args.js);
|
|
21204
|
-
|
|
21537
|
+
const target = await needTarget(root, n, sessionId, args);
|
|
21205
21538
|
if (!js) return "⛔ 需要 --js=<表达式>(例如 document.title)";
|
|
21206
21539
|
const v = await slotEval(root, n, sessionId, target, js, num(args.timeout));
|
|
21207
21540
|
return typeof v === "string" ? v : JSON.stringify(v, null, 2);
|
|
21208
21541
|
}
|
|
21209
21542
|
case "text": {
|
|
21210
21543
|
const n = needSlot(args);
|
|
21211
|
-
|
|
21212
|
-
if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
|
|
21213
|
-
return await slotText(root, n, sessionId, target);
|
|
21544
|
+
return await slotText(root, n, sessionId, await needTarget(root, n, sessionId, args));
|
|
21214
21545
|
}
|
|
21215
21546
|
case "html": {
|
|
21216
21547
|
const n = needSlot(args);
|
|
21217
|
-
|
|
21218
|
-
if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
|
|
21219
|
-
return await slotHtml(root, n, sessionId, target, num(args.max));
|
|
21548
|
+
return await slotHtml(root, n, sessionId, await needTarget(root, n, sessionId, args), num(args.max));
|
|
21220
21549
|
}
|
|
21221
21550
|
case "shot": {
|
|
21222
21551
|
const n = needSlot(args);
|
|
21223
|
-
const target =
|
|
21224
|
-
if (!target) return "⛔ 需要 --target=<targetId>(先跑 targets)";
|
|
21552
|
+
const target = await needTarget(root, n, sessionId, args);
|
|
21225
21553
|
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
21554
|
}
|
|
21227
21555
|
case "reload": {
|
|
21228
21556
|
const n = needSlot(args);
|
|
21229
|
-
|
|
21230
|
-
|
|
21231
|
-
|
|
21557
|
+
return `[browser_slot] reload 完成(readyState=${await slotReload(root, n, sessionId, await needTarget(root, n, sessionId, args), str(args.script)) || "?"})`;
|
|
21558
|
+
}
|
|
21559
|
+
case "click": {
|
|
21560
|
+
const n = needSlot(args);
|
|
21561
|
+
const target = await needTarget(root, n, sessionId, args);
|
|
21562
|
+
const text = str(args.text);
|
|
21563
|
+
const xy = parseXY(str(args.xy));
|
|
21564
|
+
if (!text && !xy) return "⛔ 需要 --text=<按钮可见文字> 或 --xy=<x,y>(例如 --text=登录 / --xy=320,48)";
|
|
21565
|
+
const { picked } = await slotClick(root, n, sessionId, target, {
|
|
21566
|
+
text,
|
|
21567
|
+
xy
|
|
21568
|
+
});
|
|
21569
|
+
return xy ? `[browser_slot] clicked @${xy.x},${xy.y}(坐标直给;未做命中校验)` : `[browser_slot] clicked <${picked.tag}> "${picked.text.slice(0, 60)}" @${picked.x},${picked.y}`;
|
|
21232
21570
|
}
|
|
21233
21571
|
case "close": {
|
|
21234
21572
|
const n = needSlot(args);
|
|
21235
21573
|
const all = args.all === true;
|
|
21236
|
-
return `[browser_slot] closed ${(await slotClose(root, n, sessionId,
|
|
21574
|
+
return `[browser_slot] closed ${(await slotClose(root, n, sessionId, all ? "" : await needTarget(root, n, sessionId, args), all)).join(", ")}`;
|
|
21237
21575
|
}
|
|
21238
21576
|
case "ext-list": {
|
|
21239
21577
|
const exts = slotExtList(root);
|
|
@@ -21279,7 +21617,11 @@ function createBrowserSlotTool(ctx) {
|
|
|
21279
21617
|
},
|
|
21280
21618
|
target: {
|
|
21281
21619
|
type: "string",
|
|
21282
|
-
description: "goto / eval / text / html / shot / reload / close: the targetId from `targets` (⛔ not a slot number)"
|
|
21620
|
+
description: "goto / eval / text / html / shot / reload / close: the targetId from `targets` (⛔ not a slot number). Identity — beats `match` when both given"
|
|
21621
|
+
},
|
|
21622
|
+
match: {
|
|
21623
|
+
type: "string",
|
|
21624
|
+
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"
|
|
21283
21625
|
},
|
|
21284
21626
|
js: {
|
|
21285
21627
|
type: "string",
|
|
@@ -21310,6 +21652,14 @@ function createBrowserSlotTool(ctx) {
|
|
|
21310
21652
|
type: "number",
|
|
21311
21653
|
description: "eval: evaluate timeout in milliseconds"
|
|
21312
21654
|
},
|
|
21655
|
+
text: {
|
|
21656
|
+
type: "string",
|
|
21657
|
+
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"
|
|
21658
|
+
},
|
|
21659
|
+
xy: {
|
|
21660
|
+
type: "string",
|
|
21661
|
+
description: "click: \"x,y\" viewport coordinates to click instead of --text (no hit-testing; the receipt says so). ⛔ Omit both text and xy = refused"
|
|
21662
|
+
},
|
|
21313
21663
|
script: {
|
|
21314
21664
|
type: "string",
|
|
21315
21665
|
description: "reload: a script to run after the reload completes"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d as readCccName, i as findGitRoot, l as pathInside, s as loadSerenityConfig, t as DEFAULT_SERENITY_CONFIG_PATHS } from "./ccc-DSMqTrRU.js";
|
|
2
2
|
import { u as ACC_VERSION } from "./rules-BYeykzys.js";
|
|
3
3
|
import { n as readDshVersion, s as hostContractReport, y as checkRegistryQuality } from "./status-thzfjL_4.js";
|
|
4
|
-
import { a as wakeSchedulerState, y as listWakes } from "./scheduler-
|
|
4
|
+
import { a as wakeSchedulerState, y as listWakes } from "./scheduler-Cbz5ou-X.js";
|
|
5
5
|
import { resolve } from "node:path";
|
|
6
6
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
7
7
|
//#region src/surface/observation.ts
|
|
@@ -2388,8 +2388,26 @@ function buildContinueText(sessionId, turn, pendingTools) {
|
|
|
2388
2388
|
lines.push(" ⛔ 不要把被中断的那一轮整段重放。");
|
|
2389
2389
|
}
|
|
2390
2390
|
lines.push("");
|
|
2391
|
+
/**
|
|
2392
|
+
* 🔴🔴 **2026-11-10(owner 报障,platform-9047 现场):这句话必须显式区分两种"没跑完"。**
|
|
2393
|
+
*
|
|
2394
|
+
* 修前只有一句「请接着完成该轮未完成的工作」。实测代价(owner 截图):
|
|
2395
|
+
* 那一轮其实是**正常结束、在等 owner 拍两个问题**(删测试行 / 要不要现在发 develop),
|
|
2396
|
+
* 宿主重启把它记成 `turn/end{reason:{kind:'interrupted'}}` —— 与「干到一半被掐」
|
|
2397
|
+
* **在读数上完全同形**。于是模型把「等授权」读成「有活没干完」,并自行推理出
|
|
2398
|
+
* 「owner 之前说过要发 develop」⇒ **差点自己授权了一次对外发布**。
|
|
2399
|
+
*
|
|
2400
|
+
* 判据:**兜底能证明的只有「这一轮没收完」,它证明不了「这一轮该由我继续做」。**
|
|
2401
|
+
* 「等人拍板」的轮次同样是「没收完」⇒ 必须由读的人自己分辨,⛔ 不能由这一段文字默认放行。
|
|
2402
|
+
*/
|
|
2391
2403
|
lines.push("请接着完成该轮未完成的工作;完成后把进展写入本轨迹的 SESSION.md。");
|
|
2392
2404
|
lines.push("");
|
|
2405
|
+
lines.push("🔴 但请先自己判断这一轮是哪种\"没跑完\":");
|
|
2406
|
+
lines.push(" · 如果它是在**干到一半被掐断** ⇒ 接着做。");
|
|
2407
|
+
lines.push(" · 如果它其实是**正常结束、在等 owner 拍板**(提问、给选项、等一句\"发/不发\") ⇒ ⛔ 那不是未完成的工作。**本条消息不构成任何授权**:");
|
|
2408
|
+
lines.push(" 不要因为\"系统让我继续\"就去执行正在等待的那个动作,也不要翻历史找一句旧授权来顶替。");
|
|
2409
|
+
lines.push(" 把待拍板的问题重新摆出来等回答即可。");
|
|
2410
|
+
lines.push("");
|
|
2393
2411
|
lines.push("(说明:这是 ACC 的「中断兜底」,每 5 分钟检查一次被中断的会话并继续。");
|
|
2394
2412
|
lines.push(" 你手工点过\"停止\"的轮次**不会**被它续跑。)");
|
|
2395
2413
|
return lines.join("\n");
|
|
@@ -3177,11 +3195,18 @@ async function createAndBindTarget(ctx, root, dirName, opts = {}) {
|
|
|
3177
3195
|
...opts.takeover === true ? { takeover: true } : {},
|
|
3178
3196
|
alive: hostAliveProbe(ctx)
|
|
3179
3197
|
});
|
|
3198
|
+
let preOpeningNote = "";
|
|
3199
|
+
if (opts.beforeOpening !== void 0) try {
|
|
3200
|
+
opts.beforeOpening(agent);
|
|
3201
|
+
preOpeningNote = ", anchor-first";
|
|
3202
|
+
} catch (err) {
|
|
3203
|
+
preOpeningNote = `, ⚠️ 锚点前置失败(${String(err?.message ?? err)})`;
|
|
3204
|
+
}
|
|
3180
3205
|
const openingNote = deliverCarrierOpening(agent, buildCarrierOpening(parseTrajectoryCode(dirName) ?? dirName, trajectoryDescOf(dirName))) ? ", opening-as-user" : ", ⚠️ 开场白未投递";
|
|
3181
3206
|
const titleNote = renameCarrierTitle(ctx, agent, root, dirName);
|
|
3182
3207
|
const wsNote = workspaceId !== void 0 ? "" : await attachToWorkspace(ctx, root, sessionId);
|
|
3183
3208
|
const viaNote = workspaceId !== void 0 ? ", via-workspaceId(=用户同一形态)" : ", via-cwd+attach";
|
|
3184
|
-
const how = `auto-create(${sessionId}${bound.ok ? ", bound" : `, ⚠️ 绑定写入失败(${bound.code})`}${viaNote}${openingNote}${titleNote}${wsNote})`;
|
|
3209
|
+
const how = `auto-create(${sessionId}${bound.ok ? ", bound" : `, ⚠️ 绑定写入失败(${bound.code})`}${viaNote}${preOpeningNote}${openingNote}${titleNote}${wsNote})`;
|
|
3185
3210
|
return {
|
|
3186
3211
|
agent,
|
|
3187
3212
|
how
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { d as hostSessions, r as cccRootForCwd } from "./ccc-roots-CtNmjx5v.js";
|
|
2
2
|
import { p as readTrajectorySubscriptions } from "./ccc-DSMqTrRU.js";
|
|
3
3
|
import { F as isoLocal, w as sessionEvents } from "./bind-file-B0TuOP89.js";
|
|
4
|
-
import { _ as WAKE_CATCH_UP_MS, h as listCroCognitiveTrajectories } from "./scheduler-
|
|
4
|
+
import { _ as WAKE_CATCH_UP_MS, h as listCroCognitiveTrajectories } from "./scheduler-Cbz5ou-X.js";
|
|
5
5
|
import { n as readSimpleSettings } from "./settings-CUabGkal.js";
|
|
6
|
-
import { i as subscriptionStats, r as subscriptionEval } from "./subscriptions-
|
|
7
|
-
import { containerClocks, containerWakes } from "./observation-
|
|
6
|
+
import { i as subscriptionStats, r as subscriptionEval } from "./subscriptions-CMhWkapn.js";
|
|
7
|
+
import { containerClocks, containerWakes } from "./observation-VUiQdjqd.js";
|
|
8
8
|
//#region src/trajectory/live.ts
|
|
9
9
|
/**
|
|
10
10
|
* trajectory/live.ts — 进程内 live 会话取数 + 精简诊断
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as cccRootForCwd } from "./ccc-roots-CtNmjx5v.js";
|
|
2
2
|
import { p as readTrajectorySubscriptions } from "./ccc-DSMqTrRU.js";
|
|
3
3
|
import { L as localHuman, n as findTrajectoryHolding } from "./bind-file-B0TuOP89.js";
|
|
4
|
-
import { p as registerDisposer } from "./scheduler-
|
|
4
|
+
import { p as registerDisposer } from "./scheduler-Cbz5ou-X.js";
|
|
5
5
|
//#region src/trajectory/subscriptions.ts
|
|
6
6
|
/**
|
|
7
7
|
* trajectory/subscriptions.ts — 轨迹消息订阅(v1.107.0,owner 2026-11-01 令)
|
|
@@ -306,7 +306,7 @@ function defaultSubscriptionDeps(ctx) {
|
|
|
306
306
|
readSubs: (root) => readTrajectorySubscriptions(root),
|
|
307
307
|
dirForSession: (root, sessionId) => findTrajectoryHolding(`${root}/AGENT_SESSIONS`, sessionId),
|
|
308
308
|
deliver: async (root, target, message) => {
|
|
309
|
-
const { sendToCognitiveTrajectory } = await import("./scheduler-
|
|
309
|
+
const { sendToCognitiveTrajectory } = await import("./scheduler-Cbz5ou-X.js").then((n) => n.r);
|
|
310
310
|
const res = await sendToCognitiveTrajectory(ctx, root, target, message, "trajectory-subscription");
|
|
311
311
|
return {
|
|
312
312
|
ok: res.ok,
|
package/lib/wake/scheduler.d.ts
CHANGED
|
@@ -194,6 +194,26 @@ export declare function createAndBindTarget(ctx: unknown, root: string, dirName:
|
|
|
194
194
|
*/
|
|
195
195
|
opts?: {
|
|
196
196
|
takeover?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* 🆕 **2026-11-10(owner 报障「这个东西不应当排队,应当直接进」):把手上的继续锚点插在
|
|
199
|
+
* 开场白**之前**。**
|
|
200
|
+
*
|
|
201
|
+
* 🔴 **缺陷现场**(platform-9047,真日志):换代时先投开场白(`followup` ⇒ `next-turn`),
|
|
202
|
+
* 再投继续锚点(也是 `followup` ⇒ `next-turn`)—— 而宿主 `inbox.claim('next-turn', …)`
|
|
203
|
+
* **每个 turn 只认领 1 条**(`core/agent/src/inbox.ts`)。⇒ 新载体的**第 1 轮只拿到开场白**,
|
|
204
|
+
* 而开场白的正文就是「接着它 SESSION.md 里的工作往下做」⇒ 模型**在读到锚点之前就开始干活**,
|
|
205
|
+
* 锚点则在排队区里等到第 2 轮才被认领(owner 截图里那条被红框圈住的就是它)。
|
|
206
|
+
*
|
|
207
|
+
* ⇒ 顺序必须是「锚点进 `next-step` → 再投开场白(`next-turn`)」:`claim` 的返回顺序是
|
|
208
|
+
* **`next-step` 全部在前、`next-turn` 取 1 条在后** ⇒ 第 1 轮第 1 步同时拿到
|
|
209
|
+
* `[锚点, 开场白]`,**锚点在前**。这才叫"直接进"。
|
|
210
|
+
*
|
|
211
|
+
* ⚠️ 回调里做什么由换代方决定(它才知道自己那条 `Injection` 怎么声明)——
|
|
212
|
+
* 本函数**不引入 Injection 的知识**(否则两个模块会互相依赖)。
|
|
213
|
+
* ⚠️ 回调抛错**不阻断**建会话:锚点没插上是大问题,但"会话建了却没投递"更坏;
|
|
214
|
+
* 失败原因写进回执,不静默。
|
|
215
|
+
*/
|
|
216
|
+
beforeOpening?: (agent: Agent) => void;
|
|
197
217
|
}): Promise<{
|
|
198
218
|
agent: Agent;
|
|
199
219
|
how: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shgroup/dsh-serenity-hooks",
|
|
3
|
-
"version": "1.129.
|
|
3
|
+
"version": "1.129.5",
|
|
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": {
|