dsh-browser-cdp 1.14.10 → 1.14.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/bin/cdp-cast-worker.mjs +59 -4
- package/dsh-plugin.json +1 -1
- package/lib/client.js +943 -149
- package/lib/index.js +189 -21
- package/package.json +1 -1
- package/skills/bcdp-browser/SKILL.md +105 -68
package/lib/index.js
CHANGED
|
@@ -2164,15 +2164,16 @@ function createFocusStore(now = () => Date.now()) {
|
|
|
2164
2164
|
};
|
|
2165
2165
|
return {
|
|
2166
2166
|
get: () => focus,
|
|
2167
|
-
set(targetId, source, at) {
|
|
2167
|
+
set(targetId, source, at, sessionId) {
|
|
2168
2168
|
const id = String(targetId ?? "").trim();
|
|
2169
|
+
const sid = typeof sessionId === "string" && sessionId.trim() !== "" ? sessionId.trim() : void 0;
|
|
2169
2170
|
if (id === "") {
|
|
2170
2171
|
if (focus === null) return null;
|
|
2171
2172
|
focus = null;
|
|
2172
2173
|
emit();
|
|
2173
2174
|
return null;
|
|
2174
2175
|
}
|
|
2175
|
-
if (focus !== null && focus.targetId === id && focus.source === source) {
|
|
2176
|
+
if (focus !== null && focus.targetId === id && focus.source === source && focus.sessionId === sid) {
|
|
2176
2177
|
focus = {
|
|
2177
2178
|
...focus,
|
|
2178
2179
|
at: at ?? now()
|
|
@@ -2180,6 +2181,7 @@ function createFocusStore(now = () => Date.now()) {
|
|
|
2180
2181
|
return focus;
|
|
2181
2182
|
}
|
|
2182
2183
|
focus = {
|
|
2184
|
+
...sid === void 0 ? {} : { sessionId: sid },
|
|
2183
2185
|
targetId: id,
|
|
2184
2186
|
source,
|
|
2185
2187
|
at: at ?? now()
|
|
@@ -2261,7 +2263,7 @@ function focusIdFrom(value) {
|
|
|
2261
2263
|
*
|
|
2262
2264
|
* Keep in sync with package.json — `node scripts/bump.mjs <version>` writes both.
|
|
2263
2265
|
*/
|
|
2264
|
-
const CLIENT_BUILD = "1.14.
|
|
2266
|
+
const CLIENT_BUILD = "1.14.11";
|
|
2265
2267
|
|
|
2266
2268
|
//#endregion
|
|
2267
2269
|
//#region src/cast-server.ts
|
|
@@ -2413,6 +2415,91 @@ function getLastEgoActivity() {
|
|
|
2413
2415
|
}
|
|
2414
2416
|
const activityListeners = /* @__PURE__ */ new Set();
|
|
2415
2417
|
/**
|
|
2418
|
+
* 面板活动药丸的动作词(与页面内覆盖层的词表同义,但**故意分开维护**)。
|
|
2419
|
+
*
|
|
2420
|
+
* 为什么 host 侧也要一份:客户端 bundle 与 host 是两条独立产物,客户端不能
|
|
2421
|
+
* `import` 这个模块;而让两边各自硬编码又必然漂移。取舍是——**host 侧是唯一
|
|
2422
|
+
* 真源**(它查表后把 {zh,en} 塞进 SSE payload),客户端只负责显示,
|
|
2423
|
+
* 所以客户端的词永远跟着 host 走,页面角标那份则是独立的、只影响页面。
|
|
2424
|
+
*
|
|
2425
|
+
* 未列入的工具(`bcdp_status`、`bcdp_help` 这类元工具)没有动作词:它们不改
|
|
2426
|
+
* 页面,"正在读取页面"对它们来说是假话,宁可不显示药丸。
|
|
2427
|
+
*/
|
|
2428
|
+
const TOOL_ACTION_LABELS = {
|
|
2429
|
+
bcdp_snapshot: {
|
|
2430
|
+
zh: "正在读取页面",
|
|
2431
|
+
en: "Reading page"
|
|
2432
|
+
},
|
|
2433
|
+
bcdp_page_info: {
|
|
2434
|
+
zh: "正在读取页面",
|
|
2435
|
+
en: "Reading page"
|
|
2436
|
+
},
|
|
2437
|
+
bcdp_js: {
|
|
2438
|
+
zh: "正在执行脚本",
|
|
2439
|
+
en: "Running script"
|
|
2440
|
+
},
|
|
2441
|
+
bcdp_script: {
|
|
2442
|
+
zh: "正在执行脚本",
|
|
2443
|
+
en: "Running script"
|
|
2444
|
+
},
|
|
2445
|
+
bcdp_click: {
|
|
2446
|
+
zh: "正在点击",
|
|
2447
|
+
en: "Clicking"
|
|
2448
|
+
},
|
|
2449
|
+
bcdp_fill: {
|
|
2450
|
+
zh: "正在输入",
|
|
2451
|
+
en: "Typing"
|
|
2452
|
+
},
|
|
2453
|
+
bcdp_key: {
|
|
2454
|
+
zh: "正在按键",
|
|
2455
|
+
en: "Pressing keys"
|
|
2456
|
+
},
|
|
2457
|
+
bcdp_scroll: {
|
|
2458
|
+
zh: "正在滚动",
|
|
2459
|
+
en: "Scrolling"
|
|
2460
|
+
},
|
|
2461
|
+
bcdp_navigate: {
|
|
2462
|
+
zh: "正在打开页面",
|
|
2463
|
+
en: "Navigating"
|
|
2464
|
+
},
|
|
2465
|
+
bcdp_screenshot: {
|
|
2466
|
+
zh: "正在截图",
|
|
2467
|
+
en: "Screenshot"
|
|
2468
|
+
},
|
|
2469
|
+
bcdp_hover: {
|
|
2470
|
+
zh: "正在悬停",
|
|
2471
|
+
en: "Hovering"
|
|
2472
|
+
},
|
|
2473
|
+
bcdp_select: {
|
|
2474
|
+
zh: "正在选择",
|
|
2475
|
+
en: "Selecting"
|
|
2476
|
+
},
|
|
2477
|
+
bcdp_check: {
|
|
2478
|
+
zh: "正在勾选",
|
|
2479
|
+
en: "Checking"
|
|
2480
|
+
},
|
|
2481
|
+
bcdp_drag: {
|
|
2482
|
+
zh: "正在拖拽",
|
|
2483
|
+
en: "Dragging"
|
|
2484
|
+
},
|
|
2485
|
+
bcdp_wait: {
|
|
2486
|
+
zh: "正在等待",
|
|
2487
|
+
en: "Waiting"
|
|
2488
|
+
},
|
|
2489
|
+
bcdp_tab: {
|
|
2490
|
+
zh: "正在切换标签页",
|
|
2491
|
+
en: "Tab"
|
|
2492
|
+
},
|
|
2493
|
+
bcdp_upload: {
|
|
2494
|
+
zh: "正在上传",
|
|
2495
|
+
en: "Uploading"
|
|
2496
|
+
},
|
|
2497
|
+
bcdp_download: {
|
|
2498
|
+
zh: "正在下载",
|
|
2499
|
+
en: "Downloading"
|
|
2500
|
+
}
|
|
2501
|
+
};
|
|
2502
|
+
/**
|
|
2416
2503
|
* Subscribe to "one bcdp_* call just landed".
|
|
2417
2504
|
* @returns the unsubscribe function.
|
|
2418
2505
|
*/
|
|
@@ -2422,16 +2509,21 @@ function onEgoActivity(cb) {
|
|
|
2422
2509
|
activityListeners.delete(cb);
|
|
2423
2510
|
};
|
|
2424
2511
|
}
|
|
2425
|
-
function markEgoToolCall(sessionId) {
|
|
2512
|
+
function markEgoToolCall(sessionId, toolName) {
|
|
2426
2513
|
toolCallCount += 1;
|
|
2427
2514
|
lastEgoActivity = Date.now();
|
|
2428
2515
|
for (const cb of [...activityListeners]) try {
|
|
2429
2516
|
cb(sessionId);
|
|
2430
2517
|
} catch {}
|
|
2431
|
-
const
|
|
2518
|
+
const label = toolName === void 0 ? void 0 : TOOL_ACTION_LABELS[toolName];
|
|
2519
|
+
let payload = sessionId === void 0 || sessionId === "" ? { count: toolCallCount } : {
|
|
2432
2520
|
count: toolCallCount,
|
|
2433
2521
|
sessionId
|
|
2434
2522
|
};
|
|
2523
|
+
if (label !== void 0) payload = {
|
|
2524
|
+
...payload,
|
|
2525
|
+
label
|
|
2526
|
+
};
|
|
2435
2527
|
const frame = `event: tool-call\ndata: ${JSON.stringify(payload)}\n\n`;
|
|
2436
2528
|
for (const res of sseClients) try {
|
|
2437
2529
|
res.write(frame);
|
|
@@ -2495,7 +2587,8 @@ function broadcastFocus(focus) {
|
|
|
2495
2587
|
const payload = focus === null ? null : {
|
|
2496
2588
|
targetId: focus.targetId,
|
|
2497
2589
|
source: focus.source,
|
|
2498
|
-
at: focus.at
|
|
2590
|
+
at: focus.at,
|
|
2591
|
+
...focus.sessionId === void 0 ? {} : { sessionId: focus.sessionId }
|
|
2499
2592
|
};
|
|
2500
2593
|
const chunk = `event: focus\ndata: ${JSON.stringify(payload)}\n\n`;
|
|
2501
2594
|
for (const client of sseClients) try {
|
|
@@ -2519,10 +2612,14 @@ function setFocusPusher(fn) {
|
|
|
2519
2612
|
*
|
|
2520
2613
|
* This is the single entry point for BOTH producers: an operator click and a
|
|
2521
2614
|
* tool result that reports the tab it just drove.
|
|
2615
|
+
*
|
|
2616
|
+
* A tool result also knows WHICH session drove it (`sessionId`), so the panel can
|
|
2617
|
+
* answer "who is driving this page" instead of guessing from the tool-call
|
|
2618
|
+
* counter. Operator paths leave it out and read as "you".
|
|
2522
2619
|
*/
|
|
2523
|
-
async function pushFocus(targetId, source = "agent") {
|
|
2620
|
+
async function pushFocus(targetId, source = "agent", sessionId) {
|
|
2524
2621
|
const id = String(targetId ?? "").trim();
|
|
2525
|
-
const focus = defaultFocusStore.set(id, source);
|
|
2622
|
+
const focus = defaultFocusStore.set(id, source, void 0, sessionId);
|
|
2526
2623
|
broadcastFocus(focus);
|
|
2527
2624
|
if (id !== "" && focusPusher !== null) {
|
|
2528
2625
|
const result = await focusPusher(id).catch(() => null);
|
|
@@ -10897,6 +10994,62 @@ const AUTO_SPACE_PREFIX = "dsh-agent-";
|
|
|
10897
10994
|
const DEFAULT_MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
10898
10995
|
const DEFAULT_GRACE_MS = 15e3;
|
|
10899
10996
|
const TOOL_TIMEOUT_MS = 12e4;
|
|
10997
|
+
/**
|
|
10998
|
+
* 页面内活动覆盖层(CDP 路径):agent 每次真正碰页面前,先在页面右上角挂一个
|
|
10999
|
+
* 「DSH · 正在读取页面 / 点击 / 输入 …」的小徽标,让正在看同一屏的人知道
|
|
11000
|
+
* 浏览器正在被谁驱动、在做什么。
|
|
11001
|
+
*
|
|
11002
|
+
* 约束(都是为了不污染 agent 自己的读取面):
|
|
11003
|
+
* - **closed shadow DOM**:页面 innerText / 正文抽取看不到覆盖层文字;
|
|
11004
|
+
* - `aria-hidden="true"`:AX 树 / bcdp_snapshot 的元素编号不会把徽标算进去;
|
|
11005
|
+
* - `pointer-events:none`:绝不挡住真实点击;
|
|
11006
|
+
* - 全部 try/catch + 4s 自动淡出:覆盖层失败绝不影响工具本身。
|
|
11007
|
+
*
|
|
11008
|
+
* 只在 ego/CDP 通道的 buildScript 前缀里注入(tabbit 的 exec 面不走此路径)。
|
|
11009
|
+
*/
|
|
11010
|
+
const OVERLAY_ACTIONS = TOOL_ACTION_LABELS;
|
|
11011
|
+
/** 页面内覆盖层更新表达式(`page.evaluate` 的字符串形式)。 */
|
|
11012
|
+
function pageOverlayExpr(zh, en) {
|
|
11013
|
+
return `(function(){
|
|
11014
|
+
try {
|
|
11015
|
+
var __zh = ((navigator.language||'').toLowerCase().indexOf('zh') === 0);
|
|
11016
|
+
var __label = __zh ? ${j(zh)} : ${j(en)};
|
|
11017
|
+
var host = document.getElementById('__dsh_overlay__');
|
|
11018
|
+
if (!host) {
|
|
11019
|
+
host = document.createElement('div');
|
|
11020
|
+
host.id = '__dsh_overlay__';
|
|
11021
|
+
host.setAttribute('aria-hidden', 'true');
|
|
11022
|
+
host.style.cssText = 'position:fixed;right:16px;top:16px;z-index:2147483647;pointer-events:none;transition:opacity .25s;';
|
|
11023
|
+
var root = host.attachShadow ? host.attachShadow({ mode: 'closed' }) : host;
|
|
11024
|
+
root.innerHTML = '<style>#b{display:flex;align-items:center;gap:6px;padding:6px 10px;border-radius:999px;background:rgba(17,24,39,.92);color:#fff;font:12px/1.4 -apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;box-shadow:0 4px 16px rgba(0,0,0,.28);white-space:nowrap}#d{width:6px;height:6px;border-radius:50%;background:#60a5fa;display:inline-block}</style><div id="b"><span id="d"></span><span id="t"></span></div>';
|
|
11025
|
+
document.documentElement.appendChild(host);
|
|
11026
|
+
window.__dshOverlayRoot = root;
|
|
11027
|
+
}
|
|
11028
|
+
var r = window.__dshOverlayRoot || host;
|
|
11029
|
+
var t = r.querySelector ? r.querySelector('#t') : null;
|
|
11030
|
+
if (t) t.textContent = 'DSH · ' + __label;
|
|
11031
|
+
host.style.opacity = '1';
|
|
11032
|
+
clearTimeout(window.__dshOverlayTimer);
|
|
11033
|
+
window.__dshOverlayTimer = setTimeout(function(){ try { host.style.opacity = '0'; } catch(e){} }, 4000);
|
|
11034
|
+
} catch (e) {}
|
|
11035
|
+
})()`;
|
|
11036
|
+
}
|
|
11037
|
+
/** 给脚本加一行覆盖层更新前缀;未知工具原样返回(零开销)。 */
|
|
11038
|
+
/**
|
|
11039
|
+
* 页面覆盖层**不接**的工具(词表里仍有它们,见下方注释)。
|
|
11040
|
+
*
|
|
11041
|
+
* `bcdp_wait` 的 `op=function` 脚本必须让 `waitForFunction(...)` 处在最外层——
|
|
11042
|
+
* 包裹在 try 里会撞 SDK 的 "Object reference chain is too long"(P0-2 实测)。
|
|
11043
|
+
* 覆盖层前缀本身就是一个 try 块,两者不能共存;因此页面侧让位,
|
|
11044
|
+
* 而**面板药丸照旧显示「正在等待」**——面板不往页面里塞脚本,没有这条约束。
|
|
11045
|
+
*/
|
|
11046
|
+
const PAGE_OVERLAY_EXCLUDED = new Set(["bcdp_wait"]);
|
|
11047
|
+
function withPageOverlay(name$1, script) {
|
|
11048
|
+
if (PAGE_OVERLAY_EXCLUDED.has(name$1)) return script;
|
|
11049
|
+
const action = OVERLAY_ACTIONS[name$1];
|
|
11050
|
+
if (action === void 0) return script;
|
|
11051
|
+
return `try { await page.evaluate(${j(pageOverlayExpr(action.zh, action.en))}) } catch (__ov) {}\n` + script;
|
|
11052
|
+
}
|
|
10900
11053
|
/** Build the script that runs the probe and emits a sentinel payload. */
|
|
10901
11054
|
function humanCheckScript(space) {
|
|
10902
11055
|
return `${useSpace(space)}${ensureRealTab()}let __hc = null\ntry { __hc = await page.evaluate(${j(HUMAN_CHECK_PROBE)}) } catch { __hc = null }\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, humanCheck: __hc }))\n`;
|
|
@@ -12008,13 +12161,17 @@ const commonOutputSchema = {
|
|
|
12008
12161
|
* #15 — a session id scopes the write into that session's focus slot; a call
|
|
12009
12162
|
* with no session (operator paths, old clients) keeps the global store. The
|
|
12010
12163
|
* global write stays best-effort exactly as before.
|
|
12164
|
+
*
|
|
12165
|
+
* The same session id also rides on the focus EVENT (M6): this function is the
|
|
12166
|
+
* only place that holds a targetId and its sessionId at the same time, so it is
|
|
12167
|
+
* the only place that can pair them for the panel's "who is driving" line.
|
|
12011
12168
|
*/
|
|
12012
12169
|
function noteToolFocus(value, sessionId) {
|
|
12013
12170
|
const targetId = focusIdFrom(value);
|
|
12014
12171
|
if (targetId === null) return;
|
|
12015
12172
|
const sid = typeof sessionId === "string" ? sessionId.trim() : "";
|
|
12016
12173
|
if (sid !== "") sessionFocusStores.for(sid).set(targetId, "agent");
|
|
12017
|
-
pushFocus(targetId, "agent").catch(() => null);
|
|
12174
|
+
pushFocus(targetId, "agent", sid === "" ? void 0 : sid).catch(() => null);
|
|
12018
12175
|
}
|
|
12019
12176
|
function callingSessionId(exec) {
|
|
12020
12177
|
const id = (exec?.agent)?.session?.id;
|
|
@@ -12713,7 +12870,7 @@ function defineEgoTool(ctx, cfg, opts) {
|
|
|
12713
12870
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
12714
12871
|
execute: async (args, exec) => withEgoLock(async () => {
|
|
12715
12872
|
cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
|
|
12716
|
-
markEgoToolCall(callingSessionId(exec));
|
|
12873
|
+
markEgoToolCall(callingSessionId(exec), opts.name);
|
|
12717
12874
|
pendingViewport = cfg;
|
|
12718
12875
|
if (typeof opts.gate === "function") {
|
|
12719
12876
|
const blocked = opts.gate(args);
|
|
@@ -12744,14 +12901,14 @@ function defineEgoTool(ctx, cfg, opts) {
|
|
|
12744
12901
|
}
|
|
12745
12902
|
}
|
|
12746
12903
|
if (opts.tabRevive) {
|
|
12747
|
-
const { result: result$1, recoveredFrom } = await runWithTabRevive(ctx, cfg, exec, () => opts.buildScript(args));
|
|
12904
|
+
const { result: result$1, recoveredFrom } = await runWithTabRevive(ctx, cfg, exec, () => withPageOverlay(opts.name, opts.buildScript(args)));
|
|
12748
12905
|
if (!result$1.ok) throw new Error(recoveredFrom ? `${result$1.error}\n${recoveredFrom}` : result$1.error);
|
|
12749
12906
|
if (result$1.value && typeof result$1.value === "object") result$1.value.recoveredFrom = recoveredFrom;
|
|
12750
12907
|
if (typeof opts.afterExecute === "function") opts.afterExecute(args, result$1.value);
|
|
12751
12908
|
noteToolFocus(result$1.value, callingSessionId(exec));
|
|
12752
12909
|
return toolPayload(result$1);
|
|
12753
12910
|
}
|
|
12754
|
-
const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => opts.buildScript(args));
|
|
12911
|
+
const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => withPageOverlay(opts.name, opts.buildScript(args)));
|
|
12755
12912
|
if (!result.ok) throw new Error(result.error);
|
|
12756
12913
|
if (typeof opts.afterExecute === "function") opts.afterExecute(args, result.value);
|
|
12757
12914
|
noteToolFocus(result.value, callingSessionId(exec));
|
|
@@ -14115,6 +14272,14 @@ function apply(ctx, config = {}) {
|
|
|
14115
14272
|
* Tabbit 激活时被封在注入面之外的工具清单 + 兜底路径。由 `bcdp_status` 的
|
|
14116
14273
|
* `guidance` 字段带出——工具「不在列表」时模型需要知道它不是坏了。
|
|
14117
14274
|
*/
|
|
14275
|
+
/**
|
|
14276
|
+
* 覆盖层的行为提示(随 `bcdp_status` 返回体下发一次)。
|
|
14277
|
+
*
|
|
14278
|
+
* 为什么需要它:页面角标说明"机器在做什么",但模型并不知道角标存在,
|
|
14279
|
+
* 于是会出现「静默连发 5 个调用、用户看着屏幕自己动」这种最坏形态。
|
|
14280
|
+
* 一条英文(模型侧语言)说明就够,别做成每次调用都推的常驻噪声。
|
|
14281
|
+
*/
|
|
14282
|
+
const OVERLAY_GUIDANCE = "Each bcdp_* call shows a \"DSH · reading/clicking/typing\" pill on the page and beside the panel title for ~4s. The pill says WHAT the machine is doing; you owe the WHY — say one line before a batch of actions and one line after (result + next step), including read-only calls. Never fire three or more calls in a row silently. Ask before actions that need the human (login, CAPTCHA, payment, delete, submit).";
|
|
14118
14283
|
const TABBIT_SEALED_GUIDANCE = "On the tabbit backend these tools are sealed (not broken): bcdp_cdp, bcdp_key, bcdp_scroll, hover/select/check/drag, bcdp_wait, upload/download/dialog, captcha/auth/login_import, bcdp_jev_*. Use bcdp_js for a single expression (e.g. window.scrollBy(0,600)) or bcdp_script for multi-step work.";
|
|
14119
14284
|
function registerEgoStatus(ctx, cfg, reg, tiers) {
|
|
14120
14285
|
reg(defineTool({
|
|
@@ -14149,6 +14314,7 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
|
|
|
14149
14314
|
}
|
|
14150
14315
|
},
|
|
14151
14316
|
guidance: { type: "string" },
|
|
14317
|
+
overlay: { type: "string" },
|
|
14152
14318
|
cached: { type: "boolean" },
|
|
14153
14319
|
facades: {
|
|
14154
14320
|
type: "object",
|
|
@@ -14185,6 +14351,7 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
|
|
|
14185
14351
|
live: face.live.length,
|
|
14186
14352
|
sealed: face.sealed.length
|
|
14187
14353
|
},
|
|
14354
|
+
overlay: OVERLAY_GUIDANCE,
|
|
14188
14355
|
...kind === "tabbit-cli" ? { guidance: TABBIT_SEALED_GUIDANCE } : {}
|
|
14189
14356
|
};
|
|
14190
14357
|
}
|
|
@@ -14202,6 +14369,7 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
|
|
|
14202
14369
|
live: face.live.length,
|
|
14203
14370
|
sealed: face.sealed.length
|
|
14204
14371
|
},
|
|
14372
|
+
overlay: OVERLAY_GUIDANCE,
|
|
14205
14373
|
...kind === "tabbit-cli" ? { guidance: TABBIT_SEALED_GUIDANCE } : {}
|
|
14206
14374
|
};
|
|
14207
14375
|
const statusRuntime = runtimeOfLink(resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link);
|
|
@@ -15161,7 +15329,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15161
15329
|
timeoutMs: 15e3,
|
|
15162
15330
|
execute: async (args, exec) => withEgoLock(async () => {
|
|
15163
15331
|
cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
|
|
15164
|
-
markEgoToolCall(callingSessionId(exec));
|
|
15332
|
+
markEgoToolCall(callingSessionId(exec), "bcdp_captcha");
|
|
15165
15333
|
pendingViewport = cfg;
|
|
15166
15334
|
const result = await runWithStaleSpaceRetry(ctx, cfg, { signal: exec?.signal }, () => humanCheckScript(str(args.space, cfg.activeSpace)));
|
|
15167
15335
|
if (!result.ok) return {
|
|
@@ -15243,7 +15411,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15243
15411
|
timeoutMs: 32e4,
|
|
15244
15412
|
execute: async (args, exec) => withEgoLock(async () => {
|
|
15245
15413
|
cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
|
|
15246
|
-
markEgoToolCall(callingSessionId(exec));
|
|
15414
|
+
markEgoToolCall(callingSessionId(exec), "bcdp_wait_for_human");
|
|
15247
15415
|
pendingViewport = cfg;
|
|
15248
15416
|
const timeoutMs = Math.max(1e3, Math.min(3e5, num(args.timeoutMs, 12e4)));
|
|
15249
15417
|
const selector = str(args.selector, "");
|
|
@@ -15547,7 +15715,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15547
15715
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
15548
15716
|
execute: async (args, exec) => {
|
|
15549
15717
|
cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
|
|
15550
|
-
markEgoToolCall(callingSessionId(exec));
|
|
15718
|
+
markEgoToolCall(callingSessionId(exec), "bcdp_script");
|
|
15551
15719
|
pendingViewport = cfg;
|
|
15552
15720
|
{
|
|
15553
15721
|
const scriptRuntime = runtimeOfLink(resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link);
|
|
@@ -15697,7 +15865,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15697
15865
|
timeoutMs: 1e4,
|
|
15698
15866
|
execute: async (_args, exec) => {
|
|
15699
15867
|
cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
|
|
15700
|
-
markEgoToolCall(callingSessionId(exec));
|
|
15868
|
+
markEgoToolCall(callingSessionId(exec), "bcdp_jev_status");
|
|
15701
15869
|
pendingViewport = cfg;
|
|
15702
15870
|
const judge = judgeCfg();
|
|
15703
15871
|
const runtime = judgeRuntimeOf();
|
|
@@ -15799,7 +15967,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15799
15967
|
timeoutMs: 6e4,
|
|
15800
15968
|
execute: async (args, exec) => {
|
|
15801
15969
|
cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
|
|
15802
|
-
markEgoToolCall(callingSessionId(exec));
|
|
15970
|
+
markEgoToolCall(callingSessionId(exec), "bcdp_jev_ask");
|
|
15803
15971
|
pendingViewport = cfg;
|
|
15804
15972
|
const blocked = attachGate();
|
|
15805
15973
|
if (blocked !== "") return {
|
|
@@ -15940,7 +16108,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15940
16108
|
timeoutMs: 6e4,
|
|
15941
16109
|
execute: async (args, exec) => {
|
|
15942
16110
|
cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
|
|
15943
|
-
markEgoToolCall(callingSessionId(exec));
|
|
16111
|
+
markEgoToolCall(callingSessionId(exec), "bcdp_jev_frame");
|
|
15944
16112
|
pendingViewport = cfg;
|
|
15945
16113
|
const blocked = attachGate();
|
|
15946
16114
|
if (blocked !== "") return {
|
|
@@ -16052,7 +16220,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
16052
16220
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
16053
16221
|
execute: async (args, exec) => {
|
|
16054
16222
|
cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
|
|
16055
|
-
markEgoToolCall(callingSessionId(exec));
|
|
16223
|
+
markEgoToolCall(callingSessionId(exec), "bcdp_jev_run");
|
|
16056
16224
|
pendingViewport = cfg;
|
|
16057
16225
|
const blocked = attachGate();
|
|
16058
16226
|
if (blocked !== "") return {
|
|
@@ -16152,7 +16320,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
16152
16320
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
16153
16321
|
execute: async (args, exec) => {
|
|
16154
16322
|
cfg.spaceTracker.setCurrentSession(callingSessionId(exec), resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.id ?? "");
|
|
16155
|
-
markEgoToolCall(callingSessionId(exec));
|
|
16323
|
+
markEgoToolCall(callingSessionId(exec), "bcdp_jev_attempt");
|
|
16156
16324
|
pendingViewport = cfg;
|
|
16157
16325
|
const blocked = attachGate();
|
|
16158
16326
|
if (blocked !== "") return {
|
|
@@ -16219,4 +16387,4 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
16219
16387
|
}
|
|
16220
16388
|
|
|
16221
16389
|
//#endregion
|
|
16222
|
-
export { ATTACH_SESSION_HINT, CDP_CONNECT_FAIL_RE, Config, GLOBAL_SESSION_KEY, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, TAB_STUCK_RE, apply, attachSessionHint, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, createSessionSpaceTracker, decideCdpAttach, deriveSlotDefaultName, effectiveChannel, egoLockBusy, findChromeBinary, findUpstreamPluginInstall, getCliFrameDiag, inject, isTabStuckFailure, localBrowserPowerState, name, parseSentinel, parseStatusFacades, resolveCliPanelSpace, resolveEgoEnv, rowsWithPrimaryActive, runWithStaleSpaceRetry, runWithTabRevive, sessionSpaceToken, setLocalBrowserPower, shouldReapBrowser, tabbitSpaceRows, waitForHumanScript };
|
|
16390
|
+
export { ATTACH_SESSION_HINT, CDP_CONNECT_FAIL_RE, Config, GLOBAL_SESSION_KEY, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, TAB_STUCK_RE, apply, attachSessionHint, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, createSessionSpaceTracker, decideCdpAttach, deriveSlotDefaultName, effectiveChannel, egoLockBusy, findChromeBinary, findUpstreamPluginInstall, getCliFrameDiag, inject, isTabStuckFailure, localBrowserPowerState, name, pageOverlayExpr, parseSentinel, parseStatusFacades, resolveCliPanelSpace, resolveEgoEnv, rowsWithPrimaryActive, runWithStaleSpaceRetry, runWithTabRevive, sessionSpaceToken, setLocalBrowserPower, shouldReapBrowser, tabbitSpaceRows, waitForHumanScript };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-browser-cdp",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.12",
|
|
4
4
|
"description": "dsh-browser-cdp: visible agent browser for DSH — drives the vendored ego-compatible Chromium over CDP, and can also attach to a running Chrome/Edge/Brave or route through egolite, Tabbit and Lightpanda backends. 35 structured bcdp_* tools; only bcdp_status stays resident by default (lazy injection, −91.9% schema per turn for non-browser sessions). Realtime watch panel with direct click/scroll/IME input, element picks quoted into the composer, human-verification notices; non-CDP channels sync frames by 3s polling. Web shell: floating watch ball without dsh-better-sidebar, sidebar tab with it. Headless/TUI hosts: tools-only. [DSH 0.1.0-rc.2 ~ 0.2.2-rc.1: declarative settings via Config .volatile() fields on 0.1.7+; imperative installSection / module-level registration + describe/mutate bridge on 0.1.0 ~ 0.1.5 (experimental, pending farm). Client peers stay optional so gen-1 hosts without dsh-client-store still load; for a production install on the current line use the 0.17.x line]",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -1,68 +1,105 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: bcdp-browser
|
|
3
|
-
description: Drive a visible agent browser (ego / Chrome / Edge / Tabbit / Lightpanda) with bcdp_* tools — navigate, click, fill forms, screenshot, read page data, manage tabs, verify results. Use whenever a task needs a real browser, a logged-in page, or visual confirmation.
|
|
4
|
-
whenToUse: The user asks to open or inspect a page, fill a form, click through a flow, screenshot or verify a web UI, or read data that only exists behind a login.
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# bcdp-browser
|
|
8
|
-
|
|
9
|
-
## 两个入口,别搞混
|
|
10
|
-
|
|
11
|
-
| 入口 | 给你什么 | 什么时候调 |
|
|
12
|
-
|---|---|---|
|
|
13
|
-
| `bcdp_help`(常驻工具) | **运行态**:激活的后端、当前 space、已解锁批次、单工具提示(`topic`) | 每个浏览器任务的第一步;拿不准参数时再调一次 |
|
|
14
|
-
| 本 skill | **流程**:循环、铁律、配方、降级表 | 已加载就够,不要反复读 |
|
|
15
|
-
|
|
16
|
-
只看到 `bcdp_help` 一个 `bcdp_*` 工具是正常现象:其余工具按批次解锁,调一次 `bcdp_help` 就会铺开下一批。**不要把"工具不在列表里"当成坏了。**
|
|
17
|
-
|
|
18
|
-
## 一次循环
|
|
19
|
-
|
|
20
|
-
1. `bcdp_help` —— 看后端是哪条通道、space 叫什么、有没有坑
|
|
21
|
-
2. `bcdp_navigate {url}` —— 等 DOM 就绪
|
|
22
|
-
3. `bcdp_snapshot` —— 拿到带 `[ref=N, loc=...]` 的语义树
|
|
23
|
-
4. `bcdp_click` / `bcdp_fill` / `bcdp_check` / `bcdp_select` —— 用 `loc=`
|
|
24
|
-
5. `bcdp_snapshot` 或 `bcdp_page_info` —— 验证页面真的变了,而不是假设它变了
|
|
25
|
-
6. 需要交给人:`bcdp_space {op:'handoff'}`;拿回来:`op:'takeover'`
|
|
26
|
-
|
|
27
|
-
## 选择器:永远优先 `loc=`
|
|
28
|
-
|
|
29
|
-
`bcdp_snapshot` 返回两种标记:
|
|
30
|
-
|
|
31
|
-
- `loc=...` —— **跨调用稳定**,用它
|
|
32
|
-
- `@N` / `ref=N` —— 每次快照重新编号,只在本次快照内有效
|
|
33
|
-
|
|
34
|
-
`bcdp_click` 也接受坐标(`x`、`y`),只在确实拿不到选择器时用。
|
|
35
|
-
|
|
36
|
-
## 三条铁律
|
|
37
|
-
|
|
38
|
-
1. **一次调用只做一件事。** 导航和提交不要塞进同一次调用,否则失败后说不清哪一步挂了。
|
|
39
|
-
2. **等状态用 `bcdp_wait`**(`op=selector|url|response|load|function`),不要在 `bcdp_js` 里写 sleep。
|
|
40
|
-
3. **看到 `actionSent=true` 就停。** 先 `bcdp_snapshot` 核实页面到底变没变,禁止原样重试——盲跑第二遍会把一次提交变成两次。
|
|
41
|
-
|
|
42
|
-
## 六条禁令
|
|
43
|
-
|
|
44
|
-
- 不在 `retry=never` 的失败后重试:`BACKEND_UNSUPPORTED` / `INVALID_ARGS` / `CAPTCHA` / `USER_CONTROLLING` 都是终点,换路或交人。
|
|
45
|
-
- 不复用上一轮快照的 `ref=` / `@N`——它们只在本次快照内有效,跨调用一律用 `loc=`。
|
|
46
|
-
- 不在 lightpanda 后端尝试登录 / CAPTCHA:没有窗口,必须换后端。
|
|
47
|
-
- 不对 `ownership=user` 的标签页做破坏性动作(关闭 / 提交 / 删除 / 清空),要动先问。
|
|
48
|
-
- 不猜密码、不暴力重试、不绕过登录与人机验证。
|
|
49
|
-
- 不把整页截图当默认观察手段——先 `bcdp_snapshot` 拿语义树,只在需要视觉证据时再截图。
|
|
50
|
-
|
|
51
|
-
##
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
1
|
+
---
|
|
2
|
+
name: bcdp-browser
|
|
3
|
+
description: Drive a visible agent browser (ego / Chrome / Edge / Tabbit / Lightpanda) with bcdp_* tools — navigate, click, fill forms, screenshot, read page data, manage tabs, verify results. Use whenever a task needs a real browser, a logged-in page, or visual confirmation.
|
|
4
|
+
whenToUse: The user asks to open or inspect a page, fill a form, click through a flow, screenshot or verify a web UI, or read data that only exists behind a login.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# bcdp-browser
|
|
8
|
+
|
|
9
|
+
## 两个入口,别搞混
|
|
10
|
+
|
|
11
|
+
| 入口 | 给你什么 | 什么时候调 |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| `bcdp_help`(常驻工具) | **运行态**:激活的后端、当前 space、已解锁批次、单工具提示(`topic`) | 每个浏览器任务的第一步;拿不准参数时再调一次 |
|
|
14
|
+
| 本 skill | **流程**:循环、铁律、配方、降级表 | 已加载就够,不要反复读 |
|
|
15
|
+
|
|
16
|
+
只看到 `bcdp_help` 一个 `bcdp_*` 工具是正常现象:其余工具按批次解锁,调一次 `bcdp_help` 就会铺开下一批。**不要把"工具不在列表里"当成坏了。**
|
|
17
|
+
|
|
18
|
+
## 一次循环
|
|
19
|
+
|
|
20
|
+
1. `bcdp_help` —— 看后端是哪条通道、space 叫什么、有没有坑
|
|
21
|
+
2. `bcdp_navigate {url}` —— 等 DOM 就绪
|
|
22
|
+
3. `bcdp_snapshot` —— 拿到带 `[ref=N, loc=...]` 的语义树
|
|
23
|
+
4. `bcdp_click` / `bcdp_fill` / `bcdp_check` / `bcdp_select` —— 用 `loc=`
|
|
24
|
+
5. `bcdp_snapshot` 或 `bcdp_page_info` —— 验证页面真的变了,而不是假设它变了
|
|
25
|
+
6. 需要交给人:`bcdp_space {op:'handoff'}`;拿回来:`op:'takeover'`
|
|
26
|
+
|
|
27
|
+
## 选择器:永远优先 `loc=`
|
|
28
|
+
|
|
29
|
+
`bcdp_snapshot` 返回两种标记:
|
|
30
|
+
|
|
31
|
+
- `loc=...` —— **跨调用稳定**,用它
|
|
32
|
+
- `@N` / `ref=N` —— 每次快照重新编号,只在本次快照内有效
|
|
33
|
+
|
|
34
|
+
`bcdp_click` 也接受坐标(`x`、`y`),只在确实拿不到选择器时用。
|
|
35
|
+
|
|
36
|
+
## 三条铁律
|
|
37
|
+
|
|
38
|
+
1. **一次调用只做一件事。** 导航和提交不要塞进同一次调用,否则失败后说不清哪一步挂了。
|
|
39
|
+
2. **等状态用 `bcdp_wait`**(`op=selector|url|response|load|function`),不要在 `bcdp_js` 里写 sleep。
|
|
40
|
+
3. **看到 `actionSent=true` 就停。** 先 `bcdp_snapshot` 核实页面到底变没变,禁止原样重试——盲跑第二遍会把一次提交变成两次。
|
|
41
|
+
|
|
42
|
+
## 六条禁令
|
|
43
|
+
|
|
44
|
+
- 不在 `retry=never` 的失败后重试:`BACKEND_UNSUPPORTED` / `INVALID_ARGS` / `CAPTCHA` / `USER_CONTROLLING` 都是终点,换路或交人。
|
|
45
|
+
- 不复用上一轮快照的 `ref=` / `@N`——它们只在本次快照内有效,跨调用一律用 `loc=`。
|
|
46
|
+
- 不在 lightpanda 后端尝试登录 / CAPTCHA:没有窗口,必须换后端。
|
|
47
|
+
- 不对 `ownership=user` 的标签页做破坏性动作(关闭 / 提交 / 删除 / 清空),要动先问。
|
|
48
|
+
- 不猜密码、不暴力重试、不绕过登录与人机验证。
|
|
49
|
+
- 不把整页截图当默认观察手段——先 `bcdp_snapshot` 拿语义树,只在需要视觉证据时再截图。
|
|
50
|
+
|
|
51
|
+
## 覆盖层:页面上一直有块「DSH · 正在…」的角标
|
|
52
|
+
|
|
53
|
+
在 ego / CDP 通道上,**每次真正碰页面的调用都会先在页面右上角挂一块角标**
|
|
54
|
+
(`DSH · 正在读取页面 / 点击 / 输入 / 截图 …`,4 秒后自动淡出)。同一句话也会
|
|
55
|
+
同步出现在侧栏面板的标题旁(活动药丸)。两处都由本插件在运行时产生,
|
|
56
|
+
**不需要你调用任何工具去画**,也不会污染你的读取面:
|
|
57
|
+
|
|
58
|
+
- 它挂在 closed shadow DOM 里且 `aria-hidden` → `bcdp_snapshot` / 正文抽取
|
|
59
|
+
**看不到**它的文字,语义树也不会把它编号成一个可点元素;
|
|
60
|
+
- `pointer-events:none` → 永远不挡真实点击;
|
|
61
|
+
- 注入失败被吞掉 → 角标坏了也不影响工具本身。
|
|
62
|
+
|
|
63
|
+
### 你要学的行为:查看前后都要「说出来」
|
|
64
|
+
|
|
65
|
+
角标说明**机器在做什么**,你的说明负责**为什么**——两件事都要有,缺一半用户就懵。
|
|
66
|
+
用户可能正盯着那块屏幕,他看到画面自己动了却不知道是谁、为什么,那是最坏的体验。
|
|
67
|
+
|
|
68
|
+
**操作前**(一次动作一批,不是每一步都念):
|
|
69
|
+
|
|
70
|
+
> 我去 `example.com` 找登录入口,先读一下页面结构。
|
|
71
|
+
|
|
72
|
+
**操作后**(结果 + 下一步,别只报"成功"):
|
|
73
|
+
|
|
74
|
+
> 页面里有个「Sign in」按钮,我点了,现在跳到了 `/login`——需要你在那个窗口里登录,登录完告诉我继续。
|
|
75
|
+
|
|
76
|
+
**纯查看也要说**(这是最容易被跳过的,也是最需要的):
|
|
77
|
+
|
|
78
|
+
> 我读一下当前页面,确认表单填对了没有。
|
|
79
|
+
|
|
80
|
+
### 三条硬规矩
|
|
81
|
+
|
|
82
|
+
1. **不要静默连发**:连续 3 个以上 `bcdp_*` 调用之间没有任何一句人话 = 用户在看着
|
|
83
|
+
一个自己动的屏幕。每批动作前后各一句。
|
|
84
|
+
2. **覆盖层的话不要背**:不要说"系统正在显示覆盖层"这种元描述,说你在干什么。
|
|
85
|
+
3. **需要人接手的动作必须先说再做**:登录、人机验证、付款、删除、提交表单——
|
|
86
|
+
这些不能说"我点了,需要你…",要**先说**再点。
|
|
87
|
+
|
|
88
|
+
## 后端差异(会静默降级,必须看)
|
|
89
|
+
|
|
90
|
+
`bcdp_help` 会报 `backend:`,各通道能力不同:
|
|
91
|
+
|
|
92
|
+
| 后端 | 缺口 |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `tabbit-cli` | 无标签枚举 / 窗口关闭、无 overlay 点选、无下载事件;`bcdp_script` 里没有 `taskSpaces` / `cdp()` / `fetch.*`,`verbatim` 被拒;`snapshot` 上限 20000 字符 |
|
|
95
|
+
| `lightpanda` | 无头无窗口:登录、CAPTCHA 没有可操作的地方,必须换后端 |
|
|
96
|
+
| `ego-cli` | 无直接 CDP:`bcdp_cdp` 不可用 |
|
|
97
|
+
| CDP 端点 / 内置运行时 | 全能力 |
|
|
98
|
+
|
|
99
|
+
撞到"工具报不支持"时**不要重试**,读 `references/recovery.md` 换路。
|
|
100
|
+
|
|
101
|
+
## 按需读(不要预加载这三册)
|
|
102
|
+
|
|
103
|
+
- `references/recipes.md` —— 表单、多 tab、上传下载、iframe、分页取数
|
|
104
|
+
- `references/recovery.md` —— 断连、后端切换、CAPTCHA、前台抢占、ref 失效
|
|
105
|
+
- `references/eval.md` —— JEV 判定链(实验性,默认别碰)
|