dsh-browser-cdp 1.9.51 → 1.11.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/CHANGELOG.md +19 -0
- package/README.md +43 -18
- package/bin/cdp-cast-worker.mjs +1 -1
- package/cordis.patch.yml +4 -0
- package/dsh-plugin.json +2 -2
- package/lib/client.js +39 -231
- package/lib/index.js +581 -56
- package/lib/skill/index.js +112 -0
- package/package.json +12 -1
- package/runtime/PATCHES.md +10 -0
- package/runtime/ego-browser/dist/out/index.js +148 -8
- package/runtime/ego-linux/src/chrome.mjs +152 -9
- package/runtime/ego-linux/src/cursor.mjs +13 -1
- package/runtime/ego-linux/src/shim.mjs +5 -0
- package/runtime/ego-linux/src/snapshot.mjs +10 -1
- package/runtime/ego-linux/src/task-spaces.mjs +78 -1
- package/skills/bcdp-browser/SKILL.md +68 -0
- package/skills/bcdp-browser/references/eval.md +23 -0
- package/skills/bcdp-browser/references/recipes.md +59 -0
- package/skills/bcdp-browser/references/recovery.md +63 -0
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { f as stopLocalBrowser, l as launchLocalBrowser } from "./launcher-Vz8i9ylT.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
4
|
-
import { appendFileSync, constants, createReadStream, createWriteStream, existsSync, readFileSync, readdirSync } from "node:fs";
|
|
4
|
+
import { appendFileSync, constants, createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync } from "node:fs";
|
|
5
5
|
import { homedir, tmpdir } from "node:os";
|
|
6
|
-
import { basename, dirname, join, normalize, resolve, sep } from "node:path";
|
|
6
|
+
import { basename, dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { access, chmod, copyFile, mkdir, open, readFile, readdir, rename, rm, symlink, writeFile } from "node:fs/promises";
|
|
9
9
|
import { execFile, spawn } from "node:child_process";
|
|
@@ -6122,6 +6122,327 @@ function envelopeError(code, message) {
|
|
|
6122
6122
|
};
|
|
6123
6123
|
}
|
|
6124
6124
|
|
|
6125
|
+
//#endregion
|
|
6126
|
+
//#region src/tui-command.ts
|
|
6127
|
+
const MAX_LINES = 40;
|
|
6128
|
+
const MAX_WIDTH = 80;
|
|
6129
|
+
/** 解析 `sub arg --flag --json --yes --all`(命令层不接 --key=value,够用即可)。 */
|
|
6130
|
+
function parseBcdpArgs(rawInput) {
|
|
6131
|
+
const argv = [];
|
|
6132
|
+
let json = false;
|
|
6133
|
+
let yes = false;
|
|
6134
|
+
let all = false;
|
|
6135
|
+
for (const token of String(rawInput ?? "").trim().split(/\s+/).filter(Boolean)) {
|
|
6136
|
+
if (!token.startsWith("--")) {
|
|
6137
|
+
argv.push(token);
|
|
6138
|
+
continue;
|
|
6139
|
+
}
|
|
6140
|
+
if (token === "--json") json = true;
|
|
6141
|
+
else if (token === "--yes") yes = true;
|
|
6142
|
+
else if (token === "--all") all = true;
|
|
6143
|
+
}
|
|
6144
|
+
return {
|
|
6145
|
+
argv,
|
|
6146
|
+
json,
|
|
6147
|
+
yes,
|
|
6148
|
+
all,
|
|
6149
|
+
dry: !yes
|
|
6150
|
+
};
|
|
6151
|
+
}
|
|
6152
|
+
/** 单行裁剪:notice 是单块文本,横向撑爆会折行错位。
|
|
6153
|
+
* 注意只折叠换行、不折叠内部空格 —— 两空格对齐是输出契约的一部分。 */
|
|
6154
|
+
function clip(text, width = MAX_WIDTH) {
|
|
6155
|
+
const value = String(text ?? "").replace(/[\r\n]+/g, " ").replace(/\s+$/, "");
|
|
6156
|
+
return value.length <= width ? value : `${value.slice(0, width - 1)}…`;
|
|
6157
|
+
}
|
|
6158
|
+
/** 行裁剪 + 溢出提示。 */
|
|
6159
|
+
function renderLines(lines, limit = MAX_LINES) {
|
|
6160
|
+
const clipped = lines.map((line) => clip(line));
|
|
6161
|
+
if (clipped.length <= limit) return clipped.join("\n");
|
|
6162
|
+
const kept = clipped.slice(0, limit - 1);
|
|
6163
|
+
return [...kept, `… 还有 ${clipped.length - kept.length} 行,加 --all 查看`].join("\n");
|
|
6164
|
+
}
|
|
6165
|
+
const ok = (lines) => ({
|
|
6166
|
+
kind: "success",
|
|
6167
|
+
text: renderLines(lines)
|
|
6168
|
+
});
|
|
6169
|
+
const fail = (reason, next) => ({
|
|
6170
|
+
kind: "error",
|
|
6171
|
+
text: renderLines([reason, ...next ? [` ${next}`] : []])
|
|
6172
|
+
});
|
|
6173
|
+
function ageLabel(ms) {
|
|
6174
|
+
if (ms === null) return "none";
|
|
6175
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
6176
|
+
if (ms < 6e4) return `${Math.round(ms / 1e3)}s`;
|
|
6177
|
+
return `${Math.round(ms / 6e4)}m`;
|
|
6178
|
+
}
|
|
6179
|
+
/** status — 通道 / 工具面 / 帧轮询 / watch 计数,全部读缓存,不 spawn。 */
|
|
6180
|
+
function statusCommand(deps) {
|
|
6181
|
+
const attach = deps.attach();
|
|
6182
|
+
const link = deps.link();
|
|
6183
|
+
const face = deps.surface();
|
|
6184
|
+
const cfg = deps.config();
|
|
6185
|
+
const poll = deps.poll();
|
|
6186
|
+
const watch = deps.watch();
|
|
6187
|
+
const status = attach.status || "unknown";
|
|
6188
|
+
const lines = [
|
|
6189
|
+
`bcdp status — ${status}${attach.message ? `: ${clip(attach.message, 48)}` : ""}`,
|
|
6190
|
+
` channel mode=${attach.mode || "—"} backend=${link?.kind ?? "none"} target=${attach.targetId || "—"}`,
|
|
6191
|
+
` endpoint ${attach.endpoint || "—"}${attach.endpointSource ? ` (${attach.endpointSource})` : ""}`,
|
|
6192
|
+
` cli ${attach.cliPath || cfg.egoBin || "—"}${attach.latencyMs ? ` ${attach.latencyMs}ms` : ""}`,
|
|
6193
|
+
` tools live ${face.live.length} / sealed ${face.sealed.length} injection=${cfg.toolInjection}`,
|
|
6194
|
+
` frames ${poll.running ? "polling" : "idle"} age=${ageLabel(poll.lastFrameAgeMs)} seq=${poll.frameSeq}`,
|
|
6195
|
+
` watch calls ${watch.calls} refused ${watch.refused}`
|
|
6196
|
+
];
|
|
6197
|
+
if (status !== "ready") lines.push(` next 浏览器侧未就绪:先跑任意 bcdp_* 工具唤醒通道(或 bcdp_status refresh),再回来看这里`);
|
|
6198
|
+
if (face.sealed.length > 0) lines.push(` sealed ${clip(face.sealed.slice(0, 8).join(" "), 80)}${face.sealed.length > 8 ? " …" : ""}`);
|
|
6199
|
+
return ok(lines);
|
|
6200
|
+
}
|
|
6201
|
+
/** config — 注入面开关与空间;不含任何密钥明文。 */
|
|
6202
|
+
function configCommand(deps) {
|
|
6203
|
+
const cfg = deps.config();
|
|
6204
|
+
const face = deps.surface();
|
|
6205
|
+
const flags = [
|
|
6206
|
+
`browse=${cfg.toolBrowse ? "open" : "sealed"}`,
|
|
6207
|
+
`extended=${cfg.toolExtended ? "open" : "sealed"}`,
|
|
6208
|
+
`escape=${cfg.toolEscape ? "open" : "sealed"}`,
|
|
6209
|
+
`judge=${cfg.toolJudge ? "open" : "sealed"}${cfg.judgeConfigured ? "" : " (key missing)"}`
|
|
6210
|
+
];
|
|
6211
|
+
return ok([
|
|
6212
|
+
`bcdp config — injection=${cfg.toolInjection}`,
|
|
6213
|
+
` switches ${flags.join(" ")}`,
|
|
6214
|
+
` space ${cfg.activeSpace || "—"}`,
|
|
6215
|
+
` face live ${face.live.length} / sealed ${face.sealed.length}`,
|
|
6216
|
+
` note 改开关走插件设置(Desktop 设置页 / profile 配置),命令层只读`
|
|
6217
|
+
]);
|
|
6218
|
+
}
|
|
6219
|
+
/** link — 已配置链路与激活项。 */
|
|
6220
|
+
function linkCommand(deps) {
|
|
6221
|
+
const rows = deps.links();
|
|
6222
|
+
const active = deps.link();
|
|
6223
|
+
if (rows.length === 0) return ok(["bcdp link — 未配置链路", " next 默认走内置 ego 运行时;要接管本机 Chrome/Edge 请在设置里加连接项"]);
|
|
6224
|
+
const lines = [`bcdp link — ${rows.length} 条链路,active=${active?.id ?? "—"} (${active?.kind ?? "none"})`];
|
|
6225
|
+
for (const row of rows.slice(0, 12)) lines.push(` ${row.active ? "*" : " "} ${row.id} kind=${row.kind}`);
|
|
6226
|
+
if (rows.length > 12) lines.push(` … 还有 ${rows.length - 12} 条`);
|
|
6227
|
+
return ok(lines);
|
|
6228
|
+
}
|
|
6229
|
+
/** doctor — 静态体检(不 spawn):通道、CLI、注入面、帧轮询逐项给 pass/warn。 */
|
|
6230
|
+
function doctorCommand(deps) {
|
|
6231
|
+
const attach = deps.attach();
|
|
6232
|
+
const cfg = deps.config();
|
|
6233
|
+
const face = deps.surface();
|
|
6234
|
+
const poll = deps.poll();
|
|
6235
|
+
const checks = [
|
|
6236
|
+
[
|
|
6237
|
+
"attach ready",
|
|
6238
|
+
attach.status === "ready",
|
|
6239
|
+
`status=${attach.status}${attach.code ? ` code=${attach.code}` : ""}`
|
|
6240
|
+
],
|
|
6241
|
+
[
|
|
6242
|
+
"cli resolvable",
|
|
6243
|
+
Boolean(attach.cliPath || cfg.egoBin),
|
|
6244
|
+
attach.cliPath || cfg.egoBin || "no path"
|
|
6245
|
+
],
|
|
6246
|
+
[
|
|
6247
|
+
"tool face open",
|
|
6248
|
+
face.live.length > 0,
|
|
6249
|
+
`live ${face.live.length} / sealed ${face.sealed.length}`
|
|
6250
|
+
],
|
|
6251
|
+
[
|
|
6252
|
+
"frame poller",
|
|
6253
|
+
poll.running,
|
|
6254
|
+
poll.running ? `age=${ageLabel(poll.lastFrameAgeMs)}` : "idle(无 GUI 时正常)"
|
|
6255
|
+
]
|
|
6256
|
+
];
|
|
6257
|
+
const bad = checks.filter(([, pass]) => !pass);
|
|
6258
|
+
const lines = [`bcdp doctor — ${checks.length - bad.length}/${checks.length} pass(静态检查,未 spawn 探测)`];
|
|
6259
|
+
for (const [name$1, pass, detail] of checks) lines.push(` ${pass ? "PASS" : "WARN"} ${name$1.padEnd(14)} ${detail}`);
|
|
6260
|
+
if (bad.length > 0) lines.push(" next 通道未就绪时先跑 bcdp_status 唤醒;仍失败用 bcdp_doctor 工具看完整探测");
|
|
6261
|
+
return ok(lines);
|
|
6262
|
+
}
|
|
6263
|
+
const HELP_LINES = [
|
|
6264
|
+
"bcdp — CDP 浏览器的终端面(宿主命令;Desktop 命令面板同样可见)",
|
|
6265
|
+
" /bcdp 等同 status",
|
|
6266
|
+
" /bcdp status 通道状态、工具面、帧轮询(读缓存,不 spawn)",
|
|
6267
|
+
" /bcdp tabs 已开标签页(走 bcdp_tab op=list)",
|
|
6268
|
+
" /bcdp shot [path] 截图落盘,默认 <cwd>/.dsh-tui/shots/<ts>.png",
|
|
6269
|
+
" /bcdp nav <url> 在当前 space 打开页面(走 bcdp_navigate)",
|
|
6270
|
+
" /bcdp attach <id> 切换激活连接项(默认 dry,--yes 写 activeTargetId)",
|
|
6271
|
+
" /bcdp config 注入面开关与当前空间(只读)",
|
|
6272
|
+
" /bcdp link 已配置链路与激活项",
|
|
6273
|
+
" /bcdp doctor 静态体检(attach / cli / 工具面 / 帧轮询)",
|
|
6274
|
+
" flags --json 单行 JSON 输出",
|
|
6275
|
+
" note 其它页面动作仍走 bcdp_* 工具"
|
|
6276
|
+
];
|
|
6277
|
+
/** tabs — 复用 `bcdp_tab op=list`(同一 buildScript,不另造探测)。 */
|
|
6278
|
+
async function tabsCommand(deps) {
|
|
6279
|
+
let value;
|
|
6280
|
+
try {
|
|
6281
|
+
value = await deps.runTool("bcdp_tab", { op: "list" });
|
|
6282
|
+
} catch (error) {
|
|
6283
|
+
return fail(`bcdp tabs: 调用 bcdp_tab 失败:${error.message}`, "next: /bcdp doctor");
|
|
6284
|
+
}
|
|
6285
|
+
const payload = value ?? {};
|
|
6286
|
+
if (payload.ok === false) return fail(`bcdp tabs: ${clip(payload.reason || payload.error || "bcdp_tab 返回失败", 80)}`, "next: /bcdp status");
|
|
6287
|
+
const tabs = Array.isArray(payload.tabs) ? payload.tabs : [];
|
|
6288
|
+
if (tabs.length === 0) return ok(["bcdp tabs — 没有已开标签页", " next 用 bcdp_navigate 打开一个页面"]);
|
|
6289
|
+
const lines = [`bcdp tabs — ${tabs.length} 个`];
|
|
6290
|
+
for (const tab of tabs.slice(0, 12)) {
|
|
6291
|
+
const mark = tab.active ? "*" : " ";
|
|
6292
|
+
const idx = String(tab.index ?? "").padStart(2, " ");
|
|
6293
|
+
lines.push(` ${mark}${idx} ${clip(tab.title || "(untitled)", 40)} ${clip(tab.url || "", 55)}`);
|
|
6294
|
+
}
|
|
6295
|
+
if (tabs.length > 12) lines.push(` … 还有 ${tabs.length - 12} 个,加 --all 查看`);
|
|
6296
|
+
return ok(lines);
|
|
6297
|
+
}
|
|
6298
|
+
/** shot — 复用 `bcdp_screenshot`;默认落到工作区内 `.dsh-tui/shots/`。 */
|
|
6299
|
+
async function shotCommand(deps, target) {
|
|
6300
|
+
const path = target.trim() === "" ? join(process.cwd(), ".dsh-tui", "shots", `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.png`) : isAbsolute(target.trim()) ? target.trim() : join(process.cwd(), target.trim());
|
|
6301
|
+
try {
|
|
6302
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
6303
|
+
const value = await deps.runTool("bcdp_screenshot", { path });
|
|
6304
|
+
if (value && value.ok === false) return fail(`bcdp shot: ${clip(value.reason || "截图失败", 80)}`, "next: /bcdp status");
|
|
6305
|
+
return ok([
|
|
6306
|
+
`bcdp shot — 已保存`,
|
|
6307
|
+
` ${value?.path ?? path}`,
|
|
6308
|
+
" 用图像工具读取该 PNG;本命令不再回传像素"
|
|
6309
|
+
]);
|
|
6310
|
+
} catch (error) {
|
|
6311
|
+
return fail(`bcdp shot: ${error.message}`, "next: /bcdp doctor");
|
|
6312
|
+
}
|
|
6313
|
+
}
|
|
6314
|
+
/** nav — 复用 `bcdp_navigate`。 */
|
|
6315
|
+
async function navCommand(deps, url) {
|
|
6316
|
+
const target = url.trim();
|
|
6317
|
+
if (target === "") return fail("bcdp nav: 缺少 URL", "next: /bcdp nav https://example.com");
|
|
6318
|
+
try {
|
|
6319
|
+
const value = await deps.runTool("bcdp_navigate", { url: target });
|
|
6320
|
+
if (value && value.ok === false) return fail(`bcdp nav: ${clip(value.reason || "导航失败", 80)}`, "next: /bcdp status");
|
|
6321
|
+
const page = value?.page;
|
|
6322
|
+
return ok([
|
|
6323
|
+
`bcdp nav — 已打开`,
|
|
6324
|
+
` url ${clip(page?.url ?? target, 70)}`,
|
|
6325
|
+
` title ${clip(page?.title ?? "(untitled)", 60)}`
|
|
6326
|
+
]);
|
|
6327
|
+
} catch (error) {
|
|
6328
|
+
return fail(`bcdp nav: ${error.message}`, "next: /bcdp doctor");
|
|
6329
|
+
}
|
|
6330
|
+
}
|
|
6331
|
+
/** attach — 切换激活连接项(写设置节 activeTargetId)。 */
|
|
6332
|
+
async function attachCommand(deps, target, yes) {
|
|
6333
|
+
const wanted = target.trim();
|
|
6334
|
+
const links = deps.links();
|
|
6335
|
+
if (wanted === "") {
|
|
6336
|
+
const lines = [`bcdp attach — 需要指定连接项 id${links.length === 0 ? "(当前没有任何连接项)" : ""}`];
|
|
6337
|
+
for (const row of links.slice(0, 10)) lines.push(` ${row.active ? "*" : " "} ${row.id} kind=${row.kind}`);
|
|
6338
|
+
lines.push(" next /bcdp attach <id> (默认 dry;加 --yes 才切换)");
|
|
6339
|
+
return ok(lines);
|
|
6340
|
+
}
|
|
6341
|
+
const hit = links.find((row) => row.id === wanted);
|
|
6342
|
+
if (hit === void 0) return fail(`bcdp attach: 没有 id="${wanted}" 的连接项`, "next: /bcdp link");
|
|
6343
|
+
if (hit.active) return ok([`bcdp attach — ${wanted} 已是激活项`]);
|
|
6344
|
+
const outcome = await deps.setActiveTarget(hit.id, !yes);
|
|
6345
|
+
if (!outcome.ok) return fail(`bcdp attach: ${outcome.reason ?? "写入失败"}`, "next: 在 Desktop 设置里切换连接项");
|
|
6346
|
+
return yes ? ok([`bcdp attach — 已切换到 ${hit.id}`, " next /bcdp status 看通道是否就绪"]) : ok([`bcdp attach — dry run:将切换到 ${hit.id}(当前 ${links.find((row) => row.active)?.id ?? "—"})`, " 确认后加 --yes 执行"]);
|
|
6347
|
+
}
|
|
6348
|
+
/** 纯函数入口:单测直接打这里,不挂 cordis。tabs/shot/nav/attach 走异步 runTool。 */
|
|
6349
|
+
async function runBcdpCommand(rawInput, deps) {
|
|
6350
|
+
const parsed = parseBcdpArgs(rawInput);
|
|
6351
|
+
const sub = (parsed.argv[0] ?? "status").toLowerCase();
|
|
6352
|
+
let result;
|
|
6353
|
+
switch (sub) {
|
|
6354
|
+
case "status":
|
|
6355
|
+
result = statusCommand(deps);
|
|
6356
|
+
break;
|
|
6357
|
+
case "tabs":
|
|
6358
|
+
case "tab":
|
|
6359
|
+
result = await tabsCommand(deps);
|
|
6360
|
+
break;
|
|
6361
|
+
case "shot":
|
|
6362
|
+
case "screenshot":
|
|
6363
|
+
result = await shotCommand(deps, parsed.argv.slice(1).join(" "));
|
|
6364
|
+
break;
|
|
6365
|
+
case "nav":
|
|
6366
|
+
case "navigate":
|
|
6367
|
+
case "goto":
|
|
6368
|
+
result = await navCommand(deps, parsed.argv.slice(1).join(" "));
|
|
6369
|
+
break;
|
|
6370
|
+
case "attach":
|
|
6371
|
+
result = await attachCommand(deps, parsed.argv.slice(1).join(" "), parsed.yes);
|
|
6372
|
+
break;
|
|
6373
|
+
case "config":
|
|
6374
|
+
result = configCommand(deps);
|
|
6375
|
+
break;
|
|
6376
|
+
case "link":
|
|
6377
|
+
case "links":
|
|
6378
|
+
result = linkCommand(deps);
|
|
6379
|
+
break;
|
|
6380
|
+
case "doctor":
|
|
6381
|
+
result = doctorCommand(deps);
|
|
6382
|
+
break;
|
|
6383
|
+
case "help":
|
|
6384
|
+
case "?":
|
|
6385
|
+
result = ok(HELP_LINES);
|
|
6386
|
+
break;
|
|
6387
|
+
default: result = fail(`bcdp: 未知子命令 "${sub}"`, "next: /bcdp help");
|
|
6388
|
+
}
|
|
6389
|
+
if (!parsed.json) return result;
|
|
6390
|
+
const attach = deps.attach();
|
|
6391
|
+
const face = deps.surface();
|
|
6392
|
+
const polls = deps.poll();
|
|
6393
|
+
const payload = result.kind === "error" ? {
|
|
6394
|
+
ok: false,
|
|
6395
|
+
cmd: "bcdp",
|
|
6396
|
+
sub,
|
|
6397
|
+
error: { message: result.text.split("\n")[0] ?? result.text }
|
|
6398
|
+
} : {
|
|
6399
|
+
ok: true,
|
|
6400
|
+
cmd: "bcdp",
|
|
6401
|
+
sub,
|
|
6402
|
+
data: {
|
|
6403
|
+
attach: {
|
|
6404
|
+
status: attach.status,
|
|
6405
|
+
mode: attach.mode,
|
|
6406
|
+
targetId: attach.targetId,
|
|
6407
|
+
code: attach.code,
|
|
6408
|
+
message: attach.message
|
|
6409
|
+
},
|
|
6410
|
+
link: deps.link() ? {
|
|
6411
|
+
id: deps.link().id,
|
|
6412
|
+
kind: deps.link().kind
|
|
6413
|
+
} : null,
|
|
6414
|
+
face: {
|
|
6415
|
+
live: face.live.length,
|
|
6416
|
+
sealed: face.sealed.length
|
|
6417
|
+
},
|
|
6418
|
+
frames: {
|
|
6419
|
+
running: polls.running,
|
|
6420
|
+
ageMs: polls.lastFrameAgeMs,
|
|
6421
|
+
seq: polls.frameSeq
|
|
6422
|
+
}
|
|
6423
|
+
}
|
|
6424
|
+
};
|
|
6425
|
+
return {
|
|
6426
|
+
kind: result.kind,
|
|
6427
|
+
text: JSON.stringify(payload)
|
|
6428
|
+
};
|
|
6429
|
+
}
|
|
6430
|
+
/**
|
|
6431
|
+
* 注册 `/bcdp`。调用侧保证 commands 服务存在(ctx.inject(['commands'])),
|
|
6432
|
+
* 老线没有该服务时不会走到这里 —— 也就不需要 try/catch。
|
|
6433
|
+
*/
|
|
6434
|
+
function registerBcdpCommand(ctx, deps) {
|
|
6435
|
+
const registry = ctx.commands;
|
|
6436
|
+
if (!registry || typeof registry.register !== "function") return;
|
|
6437
|
+
registry.register({
|
|
6438
|
+
definitionId: "dsh-browser-cdp",
|
|
6439
|
+
name: "bcdp",
|
|
6440
|
+
description: "CDP browser console: status / config / link / doctor (read-only; page actions stay in bcdp_* tools)",
|
|
6441
|
+
input: { hint: "[status|tabs|shot <path>|nav <url>|attach <id>|config|link|doctor] [--json] [--yes]" },
|
|
6442
|
+
handler: (invocation) => runBcdpCommand(invocation?.rawInput ?? "", deps)
|
|
6443
|
+
});
|
|
6444
|
+
}
|
|
6445
|
+
|
|
6125
6446
|
//#endregion
|
|
6126
6447
|
//#region src/help.ts
|
|
6127
6448
|
/**
|
|
@@ -6515,7 +6836,7 @@ const backendKindOf = (linkKind) => {
|
|
|
6515
6836
|
|
|
6516
6837
|
//#endregion
|
|
6517
6838
|
//#region src/toolTiers.ts
|
|
6518
|
-
const CORE = ["
|
|
6839
|
+
const CORE = ["bcdp_help"];
|
|
6519
6840
|
const ACT = [
|
|
6520
6841
|
"bcdp_space",
|
|
6521
6842
|
"bcdp_navigate",
|
|
@@ -6528,7 +6849,7 @@ const ACT = [
|
|
|
6528
6849
|
"bcdp_check",
|
|
6529
6850
|
"bcdp_drag",
|
|
6530
6851
|
"bcdp_tab",
|
|
6531
|
-
"
|
|
6852
|
+
"bcdp_status",
|
|
6532
6853
|
"bcdp_doctor"
|
|
6533
6854
|
];
|
|
6534
6855
|
const OBSERVE = [
|
|
@@ -6631,7 +6952,7 @@ const tierOpen = (tier, p) => {
|
|
|
6631
6952
|
* ③ 活动闸:`lazy` 下非 core 级要等活动,`always` 下不设时机闸;
|
|
6632
6953
|
* ④ 批次闸:只在 act/observe/wait 三批上按 batchDepth 递增放行。
|
|
6633
6954
|
*
|
|
6634
|
-
* depth=0 时连 act 也被封,所以唯一常驻的 `
|
|
6955
|
+
* depth=0 时连 act 也被封,所以唯一常驻的 `bcdp_help` 必须既置 active 又推进
|
|
6635
6956
|
* depth,否则 lazy 模式下没有任何解锁路径(决策与收益见
|
|
6636
6957
|
* `.agents/plans/bcdp-core-narrowing/`)。
|
|
6637
6958
|
*
|
|
@@ -6656,8 +6977,9 @@ function tierAllowed(tier, p) {
|
|
|
6656
6977
|
*
|
|
6657
6978
|
* 除分级闸外还叠一条 kind 闸:该通道根本翻译不了的工具不进注入面——「注入了
|
|
6658
6979
|
* 但一调就报错」比「不在列表里」更糟(模型会反复重试,错误文案还污染上下文)。
|
|
6659
|
-
* `core` 级不参与:`
|
|
6660
|
-
*
|
|
6980
|
+
* `core` 级不参与:`bcdp_help` 是 lazy 下唯一的常驻解锁入口,也是解释「工具为何
|
|
6981
|
+
* 不在」的唯一渠道。(`bcdp_status` 自 1.10.0 起降入 act 批——它要探通道,tabbit
|
|
6982
|
+
* 线还会跑 diagnose,不适合当入口。)
|
|
6661
6983
|
*/
|
|
6662
6984
|
const toolAllowed = (name$1, p) => {
|
|
6663
6985
|
const tier = tierOfTool(name$1);
|
|
@@ -6803,12 +7125,12 @@ function runFfmpegProbe(path, argv, { spawn: spawn$1 = spawn, timeoutMs = 3e3 }
|
|
|
6803
7125
|
let child;
|
|
6804
7126
|
let output = "";
|
|
6805
7127
|
let settled = false;
|
|
6806
|
-
const finish$1 = (ok) => {
|
|
7128
|
+
const finish$1 = (ok$1) => {
|
|
6807
7129
|
if (settled) return;
|
|
6808
7130
|
settled = true;
|
|
6809
7131
|
clearTimeout(timer);
|
|
6810
7132
|
resolve$1({
|
|
6811
|
-
ok,
|
|
7133
|
+
ok: ok$1,
|
|
6812
7134
|
output
|
|
6813
7135
|
});
|
|
6814
7136
|
};
|
|
@@ -7411,6 +7733,112 @@ function codedError$1(code, message) {
|
|
|
7411
7733
|
return error;
|
|
7412
7734
|
}
|
|
7413
7735
|
|
|
7736
|
+
//#endregion
|
|
7737
|
+
//#region src/errors.ts
|
|
7738
|
+
/** Schema fragment for the four fields; spread into strict output schemas. */
|
|
7739
|
+
const FAILURE_PROPS = {
|
|
7740
|
+
code: { type: "string" },
|
|
7741
|
+
retry: { type: "string" },
|
|
7742
|
+
actionSent: { type: "boolean" },
|
|
7743
|
+
hint: { type: "string" }
|
|
7744
|
+
};
|
|
7745
|
+
/**
|
|
7746
|
+
* Tools whose failure MAY have already changed the page.
|
|
7747
|
+
*
|
|
7748
|
+
* Deliberately conservative: a false `actionSent` invites a blind retry that
|
|
7749
|
+
* duplicates a submit/click, while a superfluous `true` only costs one extra
|
|
7750
|
+
* observation. Observers (snapshot / page_info / screenshot / read_element /
|
|
7751
|
+
* wait / help / doctor / http / jev_*) are absent on purpose.
|
|
7752
|
+
*/
|
|
7753
|
+
const MUTATING_TOOLS = new Set([
|
|
7754
|
+
"bcdp_navigate",
|
|
7755
|
+
"bcdp_click",
|
|
7756
|
+
"bcdp_fill",
|
|
7757
|
+
"bcdp_key",
|
|
7758
|
+
"bcdp_hover",
|
|
7759
|
+
"bcdp_select",
|
|
7760
|
+
"bcdp_check",
|
|
7761
|
+
"bcdp_drag",
|
|
7762
|
+
"bcdp_scroll",
|
|
7763
|
+
"bcdp_upload",
|
|
7764
|
+
"bcdp_download",
|
|
7765
|
+
"bcdp_dialog",
|
|
7766
|
+
"bcdp_space",
|
|
7767
|
+
"bcdp_tab",
|
|
7768
|
+
"bcdp_js",
|
|
7769
|
+
"bcdp_cdp",
|
|
7770
|
+
"bcdp_script",
|
|
7771
|
+
"bcdp_auth_flush",
|
|
7772
|
+
"bcdp_login_import",
|
|
7773
|
+
"bcdp_captcha"
|
|
7774
|
+
]);
|
|
7775
|
+
/** Heuristic classification from the legacy `error` / `text` strings. */
|
|
7776
|
+
function classifyFailure(message) {
|
|
7777
|
+
const m = message.toLowerCase();
|
|
7778
|
+
if (/not supported|unsupported|not available on|被拒/.test(m)) return "BACKEND_UNSUPPORTED";
|
|
7779
|
+
if (/locator|not found|no such element|ref .*invalid|stale ref/.test(m)) return "LOCATOR_NOT_FOUND";
|
|
7780
|
+
if (/timeout|timed out|etimedout/.test(m)) return "TIMEOUT";
|
|
7781
|
+
if (/dialog/.test(m)) return "DIALOG_BLOCKING";
|
|
7782
|
+
if (/captcha|人机验证/.test(m)) return "CAPTCHA";
|
|
7783
|
+
if (/user .*control|handoff|taking over|用户.*控制/.test(m)) return "USER_CONTROLLING";
|
|
7784
|
+
if (/space .*(stale|gone|expired)|stale space/.test(m)) return "SPACE_STALE";
|
|
7785
|
+
if (/not reachable|channel is closed|econnrefused|econnreset|browser .*down|no agent browser page/.test(m)) return "BROWSER_DOWN";
|
|
7786
|
+
if (/navigation|net::err|failed to load|err_name_not_resolved/.test(m)) return "NAVIGATION_FAILED";
|
|
7787
|
+
if (/payload|no result|sentinel|no result from/.test(m)) return "NO_PAYLOAD";
|
|
7788
|
+
if (/required|invalid arg|expected .*got|must be/.test(m)) return "INVALID_ARGS";
|
|
7789
|
+
return "UNKNOWN";
|
|
7790
|
+
}
|
|
7791
|
+
/** What the caller should do next. Four codes are terminal on purpose. */
|
|
7792
|
+
function retryAdvice(code) {
|
|
7793
|
+
if (code === "CAPTCHA" || code === "USER_CONTROLLING" || code === "BACKEND_UNSUPPORTED" || code === "INVALID_ARGS") return "never";
|
|
7794
|
+
if (code === "TIMEOUT" || code === "LOCATOR_NOT_FOUND" || code === "NO_PAYLOAD") return "reobserve";
|
|
7795
|
+
return "retry";
|
|
7796
|
+
}
|
|
7797
|
+
/**
|
|
7798
|
+
* One concrete next step per code. Generated from the code, never concatenated
|
|
7799
|
+
* from the error string: page content is untrusted data and must not end up in
|
|
7800
|
+
* the instruction position.
|
|
7801
|
+
*/
|
|
7802
|
+
const FAILURE_HINTS = {
|
|
7803
|
+
TIMEOUT: "先 bcdp_snapshot 看当前状态,再决定是否重试。",
|
|
7804
|
+
LOCATOR_NOT_FOUND: "重新 bcdp_snapshot 取新的 loc=,不要复用旧 ref。",
|
|
7805
|
+
NAVIGATION_FAILED: "核对 URL 与网络;不要连续重试同一地址。",
|
|
7806
|
+
DIALOG_BLOCKING: "先 bcdp_dialog 处理对话框,再重跑本动作。",
|
|
7807
|
+
CAPTCHA: "交给人:bcdp_captcha 或 bcdp_wait_for_human。",
|
|
7808
|
+
USER_CONTROLLING: "停下等用户交还控制权(bcdp_space op=takeover)。",
|
|
7809
|
+
SPACE_STALE: "用 bcdp_space op=open 重建空间后重试一次。",
|
|
7810
|
+
BROWSER_DOWN: "跑 bcdp_doctor,确认通道与浏览器进程。",
|
|
7811
|
+
BACKEND_UNSUPPORTED: "读 references/recovery.md 换后端,不要重试。",
|
|
7812
|
+
NO_PAYLOAD: "先 bcdp_page_info 确认页面可读。",
|
|
7813
|
+
INVALID_ARGS: "按返回的字段要求修正参数。",
|
|
7814
|
+
UNKNOWN: "先 bcdp_page_info 观察,再决定。"
|
|
7815
|
+
};
|
|
7816
|
+
/** True when `value` already carries an explicit classification. */
|
|
7817
|
+
function hasExplicitContract(v) {
|
|
7818
|
+
return typeof v.code === "string" && typeof v.retry === "string";
|
|
7819
|
+
}
|
|
7820
|
+
/**
|
|
7821
|
+
* Add the failure contract to a tool result.
|
|
7822
|
+
*
|
|
7823
|
+
* Success values, non-objects and already-classified failures pass through
|
|
7824
|
+
* untouched — this is the zero-regression guarantee, and it also makes the
|
|
7825
|
+
* wrapper idempotent when a tool (or a legacy alias) was wrapped twice.
|
|
7826
|
+
*/
|
|
7827
|
+
function normalizeFailure(toolName, value) {
|
|
7828
|
+
if (value === null || typeof value !== "object") return value;
|
|
7829
|
+
const v = value;
|
|
7830
|
+
if (v.ok !== false) return value;
|
|
7831
|
+
if (hasExplicitContract(v)) return value;
|
|
7832
|
+
const code = classifyFailure(String(v.error ?? v.text ?? v.reason ?? ""));
|
|
7833
|
+
return {
|
|
7834
|
+
...v,
|
|
7835
|
+
code,
|
|
7836
|
+
retry: retryAdvice(code),
|
|
7837
|
+
actionSent: MUTATING_TOOLS.has(toolName),
|
|
7838
|
+
hint: FAILURE_HINTS[code]
|
|
7839
|
+
};
|
|
7840
|
+
}
|
|
7841
|
+
|
|
7414
7842
|
//#endregion
|
|
7415
7843
|
//#region src/cdp/tabbit-receipts.ts
|
|
7416
7844
|
/**
|
|
@@ -10159,13 +10587,13 @@ async function ask(ledger, effects, round) {
|
|
|
10159
10587
|
})
|
|
10160
10588
|
};
|
|
10161
10589
|
}
|
|
10162
|
-
function step(ledger, index, control, n, action, ok, note, result, danger, anchor) {
|
|
10590
|
+
function step(ledger, index, control, n, action, ok$1, note, result, danger, anchor) {
|
|
10163
10591
|
return {
|
|
10164
10592
|
index,
|
|
10165
10593
|
control,
|
|
10166
10594
|
n,
|
|
10167
10595
|
action,
|
|
10168
|
-
ok,
|
|
10596
|
+
ok: ok$1,
|
|
10169
10597
|
note: danger === void 0 || danger === null ? note : `${note} (danger ${danger}/4)`,
|
|
10170
10598
|
provider: result.provider,
|
|
10171
10599
|
degraded: result.degraded,
|
|
@@ -10414,7 +10842,7 @@ function withEgoLock(fn) {
|
|
|
10414
10842
|
*
|
|
10415
10843
|
* The vendored ego-linux CLI reads EGO_LINUX_CHROME (bare Chrome binary/wrapper
|
|
10416
10844
|
* path) and EGO_LINUX_HEADLESS (=1 to run headless) from the process env. When a
|
|
10417
|
-
* host does not set them
|
|
10845
|
+
* host does not set them — the common case on root / Docker / CI boxes — Chrome
|
|
10418
10846
|
* silently fails to start, and consumers see a 20s `DevTools port` timeout.
|
|
10419
10847
|
*
|
|
10420
10848
|
* This function makes the plugin self-sufficient WITHOUT touching the host or
|
|
@@ -10430,7 +10858,7 @@ function withEgoLock(fn) {
|
|
|
10430
10858
|
* - An opt-out switch EGO_BROWSER_AUTO_ADAPT (set to "0"/"false"/"no") restores
|
|
10431
10859
|
* the original "inherit host env verbatim" behavior.
|
|
10432
10860
|
*/
|
|
10433
|
-
/** 阶段 10
|
|
10861
|
+
/** 阶段 10 — the render worker: the ONLY thing that can see a page. */
|
|
10434
10862
|
const RENDER_WORKER_BIN = fileURLToPath(new URL("../bin/cdp-render-worker.mjs", import.meta.url));
|
|
10435
10863
|
const BUNDLED_WRAPPER = fileURLToPath(new URL("../bin/cdp-chrome-wrapper.sh", import.meta.url));
|
|
10436
10864
|
const IS_WIN = process.platform === "win32";
|
|
@@ -10528,7 +10956,7 @@ function isPosixRoot(platform = process.platform) {
|
|
|
10528
10956
|
const uid = process.getuid?.();
|
|
10529
10957
|
return typeof uid === "number" && uid === 0 && platform !== "win32";
|
|
10530
10958
|
}
|
|
10531
|
-
/** No display server
|
|
10959
|
+
/** No display server — headless is required (Linux/macOS headless servers). */
|
|
10532
10960
|
function isHeadlessDetected(platform = process.platform, env = process.env) {
|
|
10533
10961
|
if (platform === "win32" || platform === "darwin") return false;
|
|
10534
10962
|
return env.DISPLAY === void 0 || env.DISPLAY === "";
|
|
@@ -10623,7 +11051,7 @@ function describeSpawnFailure(err) {
|
|
|
10623
11051
|
* session; a probe that arrives while the DevTools/CDP channel is still
|
|
10624
11052
|
* coming up can fail with one of these. Such failures are safe to retry
|
|
10625
11053
|
* briefly (the browser keeps warming up in the background). Anything else
|
|
10626
|
-
* must pass through immediately
|
|
11054
|
+
* must pass through immediately — never mask a genuine error.
|
|
10627
11055
|
*/
|
|
10628
11056
|
const COLD_START_SIGNS = [
|
|
10629
11057
|
/CDP channel is not open/i,
|
|
@@ -10674,7 +11102,7 @@ function shouldReapBrowser(nowMs, lastActivityMs, idleTimeoutMin) {
|
|
|
10674
11102
|
* runtime's `--open` subcommand replaces a headless instance with a headed
|
|
10675
11103
|
* one on the same profile (tabs restore) or just raises the existing window.
|
|
10676
11104
|
* `--open` is on the runtimeArgs blocklist only because USER-supplied args
|
|
10677
|
-
* must not steal the window
|
|
11105
|
+
* must not steal the window — here it is an explicit user action from the
|
|
10678
11106
|
* watch panel. --open stops+relaunches when headless, so give it real time.
|
|
10679
11107
|
*/
|
|
10680
11108
|
async function openAgentWindow(ctx, cfg) {
|
|
@@ -10798,7 +11226,7 @@ async function runWithTabRevive(ctx, cfg, exec, buildScript, graceOverrideMs) {
|
|
|
10798
11226
|
*
|
|
10799
11227
|
* Fallback: `bcdp_script` (with verbatim:true) runs user-authored heredocs, which
|
|
10800
11228
|
* tool descriptions tell the model to "end with console.log(JSON.stringify(...))"
|
|
10801
|
-
*
|
|
11229
|
+
* — without the sentinel prefix. A script written to that instruction used to
|
|
10802
11230
|
* succeed and still be reported as a failure ("no @@DSH_RESULT@@ payload"), so
|
|
10803
11231
|
* when no sentinel line exists we accept the last line that parses as a JSON
|
|
10804
11232
|
* object. The sentinel still wins whenever it is present (it marks the payload
|
|
@@ -10870,9 +11298,9 @@ function lastJsonObject(text) {
|
|
|
10870
11298
|
}
|
|
10871
11299
|
return best;
|
|
10872
11300
|
}
|
|
10873
|
-
/** R2/R3
|
|
11301
|
+
/** R2/R3 — sentinel + payload for the `bcdp_status` facade probe. @internal exported for tests */
|
|
10874
11302
|
const STATUS_FACADE_SENTINEL = "__BCDP_STATUS__";
|
|
10875
|
-
/** @internal exported for tests
|
|
11303
|
+
/** @internal exported for tests — the exact heredoc the status probe runs. */
|
|
10876
11304
|
const STATUS_FACADE_SCRIPT = `console.log(${JSON.stringify(STATUS_FACADE_SENTINEL)} + JSON.stringify({ taskSpaces: typeof taskSpaces, browser: typeof browser, page: typeof page }))
|
|
10877
11305
|
`;
|
|
10878
11306
|
/**
|
|
@@ -10898,7 +11326,7 @@ function parseStatusFacades(stdout) {
|
|
|
10898
11326
|
}
|
|
10899
11327
|
}
|
|
10900
11328
|
/**
|
|
10901
|
-
* R7
|
|
11329
|
+
* R7 — is the old dsh-ego-browser plugin installed anywhere under this DSH home?
|
|
10902
11330
|
*
|
|
10903
11331
|
* Reported (never enforced): the two plugins can coexist now that tool names
|
|
10904
11332
|
* and routes no longer overlap, but both driving ONE local ego browser would
|
|
@@ -10916,7 +11344,7 @@ function findUpstreamPluginInstall(home = process.env.HOME || process.env.USERPR
|
|
|
10916
11344
|
return "";
|
|
10917
11345
|
}
|
|
10918
11346
|
/**
|
|
10919
|
-
* R1
|
|
11347
|
+
* R1 — argv for one tool run. Single source of truth for the `--sdk-path`
|
|
10920
11348
|
* injection: `bcdp_status` and `runEgoScript` must probe/run under the exact
|
|
10921
11349
|
* same conditions, otherwise "available" and "actually works" diverge again.
|
|
10922
11350
|
* @internal exported for tests
|
|
@@ -11278,7 +11706,7 @@ const viewportPrelude = (spec) => {
|
|
|
11278
11706
|
};
|
|
11279
11707
|
const ensureRealTab = () => "const __tabs = await browser.listTabs()\nconst __blank = (u) => /^(about:|chrome:|chrome-extension:|edge:|devtools:|data:)/.test(String(u || ''))\nconst __real = __tabs.find(t => t.active === true && !__blank(t.url))\n ?? __tabs.find(t => !__blank(t.url))\n ?? __tabs.find(t => t.active === true)\n ?? __tabs[0]\nif (__real && __real.active !== true) await browser.switchTab(__real.targetId)\n" + (pendingViewport !== void 0 ? viewportPrelude(pendingViewport) : "");
|
|
11280
11708
|
/**
|
|
11281
|
-
* G
|
|
11709
|
+
* G — a raw heredoc (`bcdp_script` with verbatim:true) that touches `page.*` without
|
|
11282
11710
|
* first selecting a task space dies with the runtime's "no active tab to attach
|
|
11283
11711
|
* session". Structured bcdp_* tools never hit this because each wraps its body
|
|
11284
11712
|
* in `useSpace(...)` + `ensureRealTab()`; a hand-written heredoc has no such
|
|
@@ -11313,7 +11741,7 @@ const commonOutputSchema = {
|
|
|
11313
11741
|
} }
|
|
11314
11742
|
};
|
|
11315
11743
|
/**
|
|
11316
|
-
* The calling session id
|
|
11744
|
+
* The calling session id — the scope the client's sidebar auto-open binds to.
|
|
11317
11745
|
* Read structurally (`exec.agent` is typed `unknown` in this plugin's own
|
|
11318
11746
|
* seam); a call with no initiating agent simply leaves the open unscoped.
|
|
11319
11747
|
*/
|
|
@@ -12252,7 +12680,12 @@ function apply(ctx, config = {}) {
|
|
|
12252
12680
|
};
|
|
12253
12681
|
const tiers = createTierInjector({
|
|
12254
12682
|
register: (tool) => {
|
|
12255
|
-
const
|
|
12683
|
+
const original = tool.execute;
|
|
12684
|
+
const registered = typeof original === "function" ? {
|
|
12685
|
+
...tool,
|
|
12686
|
+
execute: async (args, exec) => normalizeFailure(String(tool.name ?? ""), await original(args, exec))
|
|
12687
|
+
} : tool;
|
|
12688
|
+
const dispose = ctx.tools.register(registered);
|
|
12256
12689
|
ctx.effect?.(() => dispose);
|
|
12257
12690
|
return dispose;
|
|
12258
12691
|
},
|
|
@@ -12342,7 +12775,9 @@ function apply(ctx, config = {}) {
|
|
|
12342
12775
|
active: () => browserActive,
|
|
12343
12776
|
surface: () => tiers.surface()
|
|
12344
12777
|
};
|
|
12778
|
+
const toolHandles = /* @__PURE__ */ new Map();
|
|
12345
12779
|
const reg = (tool) => {
|
|
12780
|
+
toolHandles.set(tool.name, tool);
|
|
12346
12781
|
tiers.offer(tool);
|
|
12347
12782
|
if (cfg.legacyEgoToolNames && typeof tool.name === "string" && tool.name.startsWith("bcdp_")) {
|
|
12348
12783
|
const alias = {
|
|
@@ -12371,6 +12806,73 @@ function apply(ctx, config = {}) {
|
|
|
12371
12806
|
layaKey: cfg.layaKey
|
|
12372
12807
|
})})`);
|
|
12373
12808
|
}
|
|
12809
|
+
try {
|
|
12810
|
+
const injectable = ctx.inject;
|
|
12811
|
+
if (typeof injectable === "function") {
|
|
12812
|
+
const commandDeps = {
|
|
12813
|
+
attach: () => effectiveChannel(cfg).attach,
|
|
12814
|
+
link: () => resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link ?? null,
|
|
12815
|
+
links: () => (cfg.links ?? []).map((entry) => ({
|
|
12816
|
+
id: entry.id,
|
|
12817
|
+
kind: entry.kind ?? "unknown",
|
|
12818
|
+
active: entry.id === cfg.activeTargetId
|
|
12819
|
+
})),
|
|
12820
|
+
surface: () => tierView.surface(),
|
|
12821
|
+
config: () => ({
|
|
12822
|
+
egoBin: String(cfg.egoBin ?? ""),
|
|
12823
|
+
toolInjection: cfg.toolInjection,
|
|
12824
|
+
activeSpace: String(cfg.activeSpace ?? ""),
|
|
12825
|
+
toolBrowse: cfg.toolBrowse,
|
|
12826
|
+
toolExtended: cfg.toolExtended,
|
|
12827
|
+
toolEscape: cfg.toolEscape,
|
|
12828
|
+
toolJudge: cfg.toolJudge,
|
|
12829
|
+
judgeConfigured: judgeConfigured({
|
|
12830
|
+
jevKey: cfg.jevKey,
|
|
12831
|
+
layaKey: cfg.layaKey
|
|
12832
|
+
})
|
|
12833
|
+
}),
|
|
12834
|
+
poll: getCliPollStatus,
|
|
12835
|
+
watch: getWatchCounters,
|
|
12836
|
+
runTool: async (name$1, args) => {
|
|
12837
|
+
const handle = toolHandles.get(name$1);
|
|
12838
|
+
if (!handle) throw new Error(`tool ${name$1} 未注册(可能被分级注入封印)`);
|
|
12839
|
+
return await handle.execute(args, {
|
|
12840
|
+
callId: `cmd-${name$1}-${Date.now()}`,
|
|
12841
|
+
name: name$1,
|
|
12842
|
+
arguments: args,
|
|
12843
|
+
signal: new AbortController().signal
|
|
12844
|
+
});
|
|
12845
|
+
},
|
|
12846
|
+
setActiveTarget: async (targetId, dry) => {
|
|
12847
|
+
if (dry) return { ok: true };
|
|
12848
|
+
const settings = ctx.get?.("settings");
|
|
12849
|
+
if (typeof settings?.update !== "function") return {
|
|
12850
|
+
ok: false,
|
|
12851
|
+
reason: "宿主不提供 settings.update"
|
|
12852
|
+
};
|
|
12853
|
+
let raw = [];
|
|
12854
|
+
try {
|
|
12855
|
+
raw = settings.describe?.() ?? [];
|
|
12856
|
+
} catch {
|
|
12857
|
+
raw = [];
|
|
12858
|
+
}
|
|
12859
|
+
const hit = (Array.isArray(raw) ? raw : raw?.namespaces ?? []).find((entry) => entry.ns === "dsh-browser-cdp");
|
|
12860
|
+
if (hit === void 0) return {
|
|
12861
|
+
ok: false,
|
|
12862
|
+
reason: "设置节 dsh-browser-cdp 不在 profile 文档里"
|
|
12863
|
+
};
|
|
12864
|
+
await settings.update("dsh-browser-cdp", { activeTargetId: targetId }, hit.revision ?? 0);
|
|
12865
|
+
await cfg.refreshAttach?.();
|
|
12866
|
+
return { ok: true };
|
|
12867
|
+
}
|
|
12868
|
+
};
|
|
12869
|
+
injectable.call(ctx, ["commands"], (commandCtx) => {
|
|
12870
|
+
registerBcdpCommand(commandCtx, commandDeps);
|
|
12871
|
+
});
|
|
12872
|
+
}
|
|
12873
|
+
} catch (error) {
|
|
12874
|
+
ctx.logger?.warn?.(`dsh-browser-cdp: /bcdp command unavailable: ${error.message}`);
|
|
12875
|
+
}
|
|
12374
12876
|
bridge.onChange(() => tiers.reapply());
|
|
12375
12877
|
const cliPoller = new CliFramePoller({
|
|
12376
12878
|
intervalMs: 3e3,
|
|
@@ -13185,6 +13687,7 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
|
|
|
13185
13687
|
type: "object",
|
|
13186
13688
|
additionalProperties: false,
|
|
13187
13689
|
properties: {
|
|
13690
|
+
...FAILURE_PROPS,
|
|
13188
13691
|
ok: {
|
|
13189
13692
|
type: "boolean",
|
|
13190
13693
|
required: true
|
|
@@ -13315,17 +13818,18 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
|
|
|
13315
13818
|
})
|
|
13316
13819
|
}));
|
|
13317
13820
|
}
|
|
13318
|
-
/** `bcdp_auth_flush`
|
|
13821
|
+
/** `bcdp_auth_flush` — force persistent login cookies down to the disk profile. */
|
|
13319
13822
|
function registerAuthFlush(ctx, cfg, reg) {
|
|
13320
13823
|
reg(defineTool({
|
|
13321
13824
|
name: "bcdp_auth_flush",
|
|
13322
|
-
description: "Force all persistent login cookies in the agent browser to be written to the on-disk profile. Call this after login (or before ending a browsing task) so the login survives a later DSH/browser restart
|
|
13825
|
+
description: "Force all persistent login cookies in the agent browser to be written to the on-disk profile. Call this after login (or before ending a browsing task) so the login survives a later DSH/browser restart — Chrome only flushes cookies to disk on graceful close, this nudges it to persist them now.",
|
|
13323
13826
|
parameters: {},
|
|
13324
13827
|
output: {
|
|
13325
13828
|
schema: {
|
|
13326
13829
|
type: "object",
|
|
13327
13830
|
additionalProperties: false,
|
|
13328
13831
|
properties: {
|
|
13832
|
+
...FAILURE_PROPS,
|
|
13329
13833
|
ok: {
|
|
13330
13834
|
type: "boolean",
|
|
13331
13835
|
required: true
|
|
@@ -13370,7 +13874,7 @@ function registerAuthFlush(ctx, cfg, reg) {
|
|
|
13370
13874
|
flushed: jbody.flushed ?? 0,
|
|
13371
13875
|
...degraded ? {
|
|
13372
13876
|
degraded: true,
|
|
13373
|
-
error: "engine-unsupported: Lightpanda has no Storage.flushCookies
|
|
13877
|
+
error: "engine-unsupported: Lightpanda has no Storage.flushCookies — cookies persist only while the engine process is alive"
|
|
13374
13878
|
} : {},
|
|
13375
13879
|
...!degraded && jbody.error !== void 0 ? { error: jbody.error } : {}
|
|
13376
13880
|
};
|
|
@@ -13389,7 +13893,7 @@ function registerAuthFlush(ctx, cfg, reg) {
|
|
|
13389
13893
|
})
|
|
13390
13894
|
}));
|
|
13391
13895
|
}
|
|
13392
|
-
/** `bcdp_login_import`
|
|
13896
|
+
/** `bcdp_login_import` — copy login cookies from the system browser (issue #46). */
|
|
13393
13897
|
function registerLoginImport(ctx, cfg, reg) {
|
|
13394
13898
|
reg(defineTool({
|
|
13395
13899
|
name: "bcdp_login_import",
|
|
@@ -13421,6 +13925,7 @@ function registerLoginImport(ctx, cfg, reg) {
|
|
|
13421
13925
|
type: "object",
|
|
13422
13926
|
additionalProperties: false,
|
|
13423
13927
|
properties: {
|
|
13928
|
+
...FAILURE_PROPS,
|
|
13424
13929
|
ok: {
|
|
13425
13930
|
type: "boolean",
|
|
13426
13931
|
required: true
|
|
@@ -13451,7 +13956,7 @@ function registerLoginImport(ctx, cfg, reg) {
|
|
|
13451
13956
|
"auto"
|
|
13452
13957
|
].includes(source)) return {
|
|
13453
13958
|
ok: false,
|
|
13454
|
-
error: `invalid source "${source}"
|
|
13959
|
+
error: `invalid source "${source}" — expected chrome|edge|brave|auto`
|
|
13455
13960
|
};
|
|
13456
13961
|
return await importLoginCookies({
|
|
13457
13962
|
source,
|
|
@@ -13548,7 +14053,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
13548
14053
|
const SNAP_OPTS = "includeStableLocator: true";
|
|
13549
14054
|
if (scope === "subtree") {
|
|
13550
14055
|
const rootArg = str(args.root, "").trim();
|
|
13551
|
-
if (rootArg === "") return send(`{ ok: false, reason: 'bcdp_snapshot: root (a ref such as @N, or a loc=css
|
|
14056
|
+
if (rootArg === "") return send(`{ ok: false, reason: 'bcdp_snapshot: root (a ref such as @N, or a loc=css:…) is required for scope=subtree' }`);
|
|
13552
14057
|
const resolver = `((raw, refs) => {
|
|
13553
14058
|
const want = raw.replace(/^loc=/, '').trim()
|
|
13554
14059
|
if (want !== '' && want !== 'unstable') {
|
|
@@ -13721,7 +14226,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
13721
14226
|
}));
|
|
13722
14227
|
reg(t({
|
|
13723
14228
|
name: "bcdp_page_info",
|
|
13724
|
-
description: "Return the current page info: url, title, viewport size (w, h), scroll offsets (sx, sy), device metrics (pw, ph), and whether a native dialog is open. Also reports `humanCheck`
|
|
14229
|
+
description: "Return the current page info: url, title, viewport size (w, h), scroll offsets (sx, sy), device metrics (pw, ph), and whether a native dialog is open. Also reports `humanCheck` — whether a CAPTCHA / human-verification challenge is detected on the page (so the agent can alert the user to complete it).",
|
|
13725
14230
|
parameters: { space: spaceParam },
|
|
13726
14231
|
buildScript: (args) => `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}const pginfo = await page.info()\nlet __hc = null\ntry { __hc = await page.evaluate(${j(HUMAN_CHECK_PROBE)}).catch(() => null); } catch { __hc = null }\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, page: pginfo, humanCheck: __hc }))\n`
|
|
13727
14232
|
}));
|
|
@@ -13842,7 +14347,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
13842
14347
|
if (u === "") return send(`{ ok: false, op: 'response', reason: 'bcdp_wait: url is required for op=response' }`);
|
|
13843
14348
|
const mode = str(args.body, "none");
|
|
13844
14349
|
const wantBody = mode === "text" || mode === "json";
|
|
13845
|
-
return head + `const __res = await page.waitForResponse(${j(u)}, { timeout: ${to} })\n${wantBody ? `const __body = ${mode === "json" ? "await __res.json().catch(()=>null)" : "await __res.text().catch(()=>null)"}\n` : ""}` + send(`{ ok: true, op: 'response', url: __res.url(), status: __res.status()${wantBody ? ", body: __body" : ""} }`);
|
|
14350
|
+
return head + `const __res = await page.waitForResponse(${j(u)}, { timeout: ${to}, includeBuffered: true })\n${wantBody ? `const __body = ${mode === "json" ? "await __res.json().catch(()=>null)" : "await __res.text().catch(()=>null)"}\n` : ""}` + send(`{ ok: true, op: 'response', url: __res.url(), status: __res.status()${wantBody ? ", body: __body" : ""} }`);
|
|
13846
14351
|
}
|
|
13847
14352
|
if (op === "load") return head + `const __ok = await page.waitForLoadState(${j(str(args.state, "load"))}, { timeout: ${pageTo} })\n` + send(`{ ok: !!__ok, op: 'load', state: ${j(str(args.state, "load"))}, reason: __ok ? null : 'timed out: load state not reached within ${pageTo}ms' }`);
|
|
13848
14353
|
if (op === "function") {
|
|
@@ -14083,7 +14588,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
14083
14588
|
const script = str(args.triggerScript, "");
|
|
14084
14589
|
const savePath = str(args.savePath, "");
|
|
14085
14590
|
const timeout = num(args.timeout, 3e4);
|
|
14086
|
-
const trigger = sel !== "" ? `await page.locator(${j(sel)}).click()\n` : script !== "" ? `await page.evaluate(() => { ${script} })\n` : "/* no trigger given
|
|
14591
|
+
const trigger = sel !== "" ? `await page.locator(${j(sel)}).click()\n` : script !== "" ? `await page.evaluate(() => { ${script} })\n` : "/* no trigger given — the download may be started by an earlier navigation */\n";
|
|
14087
14592
|
const save = savePath !== "" ? `const __final = await __dl.saveAs(${j(savePath)}).catch(()=>null)\n` : `const __final = await __dl.path().catch(()=>null)\n`;
|
|
14088
14593
|
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}const __dlPromise = page.waitForEvent('download', { timeout: ${timeout} })\n` + trigger + "const __dl = await __dlPromise\nconst __name = typeof __dl.suggestedFilename === 'function' ? __dl.suggestedFilename() : null\nconst __url = typeof __dl.url === 'function' ? __dl.url() : null\n" + save + `console.log('${SENTINEL}' + JSON.stringify({ ok: true, path: __final, suggestedFilename: __name, url: __url }))\n`;
|
|
14089
14594
|
}
|
|
@@ -14183,7 +14688,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
14183
14688
|
function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
14184
14689
|
reg(defineTool({
|
|
14185
14690
|
name: "bcdp_captcha",
|
|
14186
|
-
description: "Check the current page for a human-verification (CAPTCHA) challenge
|
|
14691
|
+
description: "Check the current page for a human-verification (CAPTCHA) challenge — reCAPTCHA / hCaptcha / Cloudflare / Turnstile — and return { detected, kind }. If detected=true, ALERT THE USER that they must complete the verification in the 'ego lite - agent' browser window (it is the same live session shown in the watch panel), then continue after they have.",
|
|
14187
14692
|
parameters: { space: {
|
|
14188
14693
|
type: "string",
|
|
14189
14694
|
description: "Task-space name or numeric id; defaults to the configured defaultSpace."
|
|
@@ -14193,6 +14698,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14193
14698
|
type: "object",
|
|
14194
14699
|
additionalProperties: false,
|
|
14195
14700
|
properties: {
|
|
14701
|
+
...FAILURE_PROPS,
|
|
14196
14702
|
ok: {
|
|
14197
14703
|
type: "boolean",
|
|
14198
14704
|
required: true
|
|
@@ -14264,6 +14770,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14264
14770
|
type: "object",
|
|
14265
14771
|
additionalProperties: false,
|
|
14266
14772
|
properties: {
|
|
14773
|
+
...FAILURE_PROPS,
|
|
14267
14774
|
ok: {
|
|
14268
14775
|
type: "boolean",
|
|
14269
14776
|
required: true
|
|
@@ -14335,7 +14842,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14335
14842
|
}));
|
|
14336
14843
|
reg(defineTool({
|
|
14337
14844
|
name: "bcdp_help",
|
|
14338
|
-
description: "
|
|
14845
|
+
description: "Start here before any browser work. Returns the live backend, task space and which bcdp_* tiers are unlocked, plus a per-topic guide via `topic` (a category like overview/navigate/form/wait/login/script, or a tool name such as bcdp_click). Load the `bcdp-browser` skill for workflows and recovery recipes.",
|
|
14339
14846
|
parameters: { topic: {
|
|
14340
14847
|
type: "string",
|
|
14341
14848
|
description: "Category or tool name to look up; omitted/all returns the overview index."
|
|
@@ -14345,6 +14852,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14345
14852
|
type: "object",
|
|
14346
14853
|
additionalProperties: false,
|
|
14347
14854
|
properties: {
|
|
14855
|
+
...FAILURE_PROPS,
|
|
14348
14856
|
ok: {
|
|
14349
14857
|
type: "boolean",
|
|
14350
14858
|
required: true
|
|
@@ -14356,7 +14864,10 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14356
14864
|
text: {
|
|
14357
14865
|
type: "string",
|
|
14358
14866
|
required: true
|
|
14359
|
-
}
|
|
14867
|
+
},
|
|
14868
|
+
backend: { type: "string" },
|
|
14869
|
+
space: { type: "string" },
|
|
14870
|
+
injection: { type: "string" }
|
|
14360
14871
|
}
|
|
14361
14872
|
},
|
|
14362
14873
|
render: renderText
|
|
@@ -14364,13 +14875,21 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14364
14875
|
timeoutMs: 1e4,
|
|
14365
14876
|
execute: async (args, exec) => {
|
|
14366
14877
|
tiers.pulse(callingSessionId(exec));
|
|
14878
|
+
const surface = tiers.surface();
|
|
14879
|
+
const backend$1 = resolveEffectiveLink(cfg.links, cfg.activeTargetId)?.link.kind ?? "none";
|
|
14880
|
+
const space = cfg.activeSpace;
|
|
14881
|
+
const injection = `mode=${cfg.toolInjection} live=${surface.live.length} sealed=${surface.sealed.length}`;
|
|
14882
|
+
const runtime = `backend=${backend$1} · space=${space} · ${injection}`;
|
|
14367
14883
|
const q = str(args.topic, "").trim().toLowerCase();
|
|
14368
14884
|
const key = Object.prototype.hasOwnProperty.call(EGO_HELP_INDEX, q) ? q : "";
|
|
14369
|
-
const text = key ? EGO_HELP_INDEX[key] : q ?
|
|
14885
|
+
const text = key ? EGO_HELP_INDEX[key] : q ? `未找到 topic "${q}"。可选 ` + Object.keys(EGO_HELP_INDEX).filter((k) => k !== "overview").join(", ") + "\n\noverview: " + EGO_HELP_INDEX.overview : EGO_HELP_INDEX.overview;
|
|
14370
14886
|
return {
|
|
14371
14887
|
ok: true,
|
|
14372
14888
|
topic: q || "overview",
|
|
14373
|
-
text
|
|
14889
|
+
text: `${runtime}\n\n${text}`,
|
|
14890
|
+
backend: backend$1,
|
|
14891
|
+
space,
|
|
14892
|
+
injection
|
|
14374
14893
|
};
|
|
14375
14894
|
},
|
|
14376
14895
|
presentCall: () => ({
|
|
@@ -14389,6 +14908,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14389
14908
|
type: "object",
|
|
14390
14909
|
additionalProperties: false,
|
|
14391
14910
|
properties: {
|
|
14911
|
+
...FAILURE_PROPS,
|
|
14392
14912
|
ok: {
|
|
14393
14913
|
type: "boolean",
|
|
14394
14914
|
required: true
|
|
@@ -14412,7 +14932,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14412
14932
|
jevKey: cfg.jevKey,
|
|
14413
14933
|
layaKey: cfg.layaKey
|
|
14414
14934
|
});
|
|
14415
|
-
lines.push(`tool injection: mode=${cfg.toolInjection} browse=${cfg.toolBrowse ? "open" : "sealed"} extended=${cfg.toolExtended ? "open" : "sealed"} escape=${cfg.toolEscape ? "open" : "sealed"} judge=${cfg.toolJudge ? "open" : "sealed"} judgeKey=${key ? "set" : "none"} active=${tiers.active() ? "yes" : "no"}
|
|
14935
|
+
lines.push(`tool injection: mode=${cfg.toolInjection} browse=${cfg.toolBrowse ? "open" : "sealed"} extended=${cfg.toolExtended ? "open" : "sealed"} escape=${cfg.toolEscape ? "open" : "sealed"} judge=${cfg.toolJudge ? "open" : "sealed"} judgeKey=${key ? "set" : "none"} active=${tiers.active() ? "yes" : "no"} — live ${s.live.length} / sealed ${s.sealed.length}`);
|
|
14416
14936
|
}
|
|
14417
14937
|
{
|
|
14418
14938
|
const stats = snapshotStats();
|
|
@@ -14434,7 +14954,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14434
14954
|
const chrome = findChromeBinary();
|
|
14435
14955
|
const configured = cfg.chromePath;
|
|
14436
14956
|
if (configured) lines.push(`browser binary: ${configured} (from settings)`);
|
|
14437
|
-
else lines.push(`browser binary: ${chrome || "(none found
|
|
14957
|
+
else lines.push(`browser binary: ${chrome || "(none found — set chromePath in settings, or set EGO_LINUX_CHROME, or install Chrome/Edge/Brave)"}`);
|
|
14438
14958
|
const cliArgs = filterArgs(cfg.runtimeArgs ?? "", EGO_CLI_BLOCKED);
|
|
14439
14959
|
const chrArgs = filterArgs(cfg.chromeArgs ?? "", CHROME_BLOCKED);
|
|
14440
14960
|
lines.push(`runtimeArgs (effective): ${cliArgs.length ? cliArgs.join(" ") : "(none)"}`);
|
|
@@ -14457,13 +14977,13 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14457
14977
|
}
|
|
14458
14978
|
if (attachNow.engine !== void 0) lines.push(`engine: ${attachNow.engine}`);
|
|
14459
14979
|
if (attachNow.engine === "lightpanda") lines.push("degraded on this engine: live view (no screencast) · panel pick (no Overlay/bindingCalled) · bcdp_download (no Page download events) · screenshots are PNG text-renders · auth_flush is a no-op");
|
|
14460
|
-
if (attachNow.engine === "lightpanda" || process.platform === "win32") lines.push(process.platform === "win32" ? "lightpanda on win32: no native build
|
|
14980
|
+
if (attachNow.engine === "lightpanda" || process.platform === "win32") lines.push(process.platform === "win32" ? "lightpanda on win32: no native build — use WSL2: `wsl --install` (admin), then inside WSL: `curl -fsSL https://pkg.lightpanda.io/install.sh | bash` + `lightpanda serve --host 127.0.0.1 --port 9222`; WSL2 maps the port to Windows localhost, then add http://127.0.0.1:9222 as a CDP endpoint. Docker alternative: `docker run -d -p 127.0.0.1:9222:9222 lightpanda/browser:nightly`." : "lightpanda (linux/macOS): `curl -fsSL https://pkg.lightpanda.io/install.sh | bash` (installs to ~/.local/bin) then `lightpanda serve --host 127.0.0.1 --port 9222`.");
|
|
14461
14981
|
const kindCount = (kind) => cfg.links.filter((link) => link.kind === kind).length;
|
|
14462
14982
|
const dropped = cfg.droppedEgoCli;
|
|
14463
|
-
lines.push(`links: ${cfg.links.length} (cdp ${kindCount("cdp")}, ego-cli ${kindCount(EGO_CLI_KIND)}, lightpanda ${kindCount(LP_KIND)})${dropped > 0 ? `
|
|
14983
|
+
lines.push(`links: ${cfg.links.length} (cdp ${kindCount("cdp")}, ego-cli ${kindCount(EGO_CLI_KIND)}, lightpanda ${kindCount(LP_KIND)})${dropped > 0 ? ` — ${dropped} extra ego-cli row(s) dropped (local-only singleton)` : ""}`);
|
|
14464
14984
|
if (kindCount(LP_KIND) > 0) {
|
|
14465
14985
|
const lpRow = cfg.links.find((link) => link.kind === LP_KIND);
|
|
14466
|
-
lines.push(`lightpanda row: servePath=${lpRow?.servePath === void 0 || lpRow.servePath === "" ? "(auto: PATH
|
|
14986
|
+
lines.push(`lightpanda row: servePath=${lpRow?.servePath === void 0 || lpRow.servePath === "" ? "(auto: PATH —~/.local/bin; win32 via WSL2)" : lpRow.servePath} — headless quick-trial engine; headed kinds (CDP / local Chrome / ego CLI) are the manual-fallback backstop`);
|
|
14467
14987
|
}
|
|
14468
14988
|
const cliLink = cfg.links.find((link) => link.kind === EGO_CLI_KIND);
|
|
14469
14989
|
if (cliLink && cliLink.kind === EGO_CLI_KIND) {
|
|
@@ -14471,13 +14991,13 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14471
14991
|
cliPath: cliLink.cliPath,
|
|
14472
14992
|
bundled: VENDORED_EGO_BIN
|
|
14473
14993
|
}, createSubprocessCliIo(ctx.subprocess));
|
|
14474
|
-
lines.push(resolved.ok ? `cli: ${resolved.path} (${resolved.origin}${attachNow.cliShape ? `, shape ${attachNow.cliShape}` : ""})` : `cli: (missing)
|
|
14994
|
+
lines.push(resolved.ok ? `cli: ${resolved.path} (${resolved.origin}${attachNow.cliShape ? `, shape ${attachNow.cliShape}` : ""})` : `cli: (missing) — ${resolved.message}`);
|
|
14475
14995
|
}
|
|
14476
14996
|
const toolCount = ((EGO_HELP_INDEX["tools"] ?? "").match(/bcdp_/g) ?? []).length;
|
|
14477
14997
|
const legacy = cfg.legacyEgoToolNames === true;
|
|
14478
14998
|
lines.push(`naming: ${toolCount} bcdp_* tools; legacy ego_* aliases ${legacy ? "ON (mutually exclusive with the old dsh-ego-browser plugin)" : "OFF (coexists with the old dsh-ego-browser plugin)"}`);
|
|
14479
14999
|
const upstream = findUpstreamPluginInstall();
|
|
14480
|
-
if (upstream !== "") lines.push(`conflict: old dsh-ego-browser installed at ${upstream}
|
|
15000
|
+
if (upstream !== "") lines.push(`conflict: old dsh-ego-browser installed at ${upstream} — only one plugin should drive the local ego browser (they would share its task spaces)`);
|
|
14481
15001
|
lines.push(`chromeArgs (effective, next cold start): ${chrArgs.length ? chrArgs.join(" ") : "(none)"}`);
|
|
14482
15002
|
const isWin = process.platform === "win32";
|
|
14483
15003
|
const e = process.env;
|
|
@@ -14485,7 +15005,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14485
15005
|
const stateDir = e.EGO_LINUX_STATE_DIR || (isWin ? (e.LOCALAPPDATA || `${home}\\AppData\\Local`) + "\\ego-lite-linux" : `${e.XDG_STATE_HOME || `${home}/.local/state`}/ego-lite-linux`);
|
|
14486
15006
|
lines.push(`state dir: ${stateDir} (exists: ${existsSync(stateDir)})`);
|
|
14487
15007
|
const bjson = `${stateDir}/browser.json`;
|
|
14488
|
-
let browserReport = "browser.json: (none
|
|
15008
|
+
let browserReport = "browser.json: (none — agent browser not running)";
|
|
14489
15009
|
if (existsSync(bjson)) try {
|
|
14490
15010
|
const { readFile: readFile$1 } = await import("node:fs/promises");
|
|
14491
15011
|
const b = JSON.parse(await readFile$1(bjson, "utf8"));
|
|
@@ -14535,12 +15055,12 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14535
15055
|
reg((() => {
|
|
14536
15056
|
return defineTool({
|
|
14537
15057
|
name: "bcdp_script",
|
|
14538
|
-
description: "Run an arbitrary `ego-browser nodejs` heredoc script in ONE invocation (page/…locator/browser/taskSpaces/site/fetch/cdp preloaded), and return structured {ok, stdout, stderr, result, durationMs, timedOut}. The task space is selected and a real (non-blank) tab activated for you before your script runs, so page.* works directly. Set verbatim:true runs the body with no preamble. For a single page expression use bcdp_js. On tabbit the body runs in the browser Playwright runtime: no taskSpaces/cdp()/fetch.*, verbatim refused. These scripts expose the vendored SDK (`taskSpaces`, `page.locator()`, global `cdp()`, `fetch.browser|server`)
|
|
15058
|
+
description: "Run an arbitrary `ego-browser nodejs` heredoc script in ONE invocation (page/…locator/browser/taskSpaces/site/fetch/cdp preloaded), and return structured {ok, stdout, stderr, result, durationMs, timedOut}. The task space is selected and a real (non-blank) tab activated for you before your script runs, so page.* works directly. Set verbatim:true runs the body with no preamble. For a single page expression use bcdp_js. On tabbit the body runs in the browser Playwright runtime: no taskSpaces/cdp()/fetch.*, verbatim refused. These scripts expose the vendored SDK (`taskSpaces`, `page.locator()`, global `cdp()`, `fetch.browser|server`) — NOT the official docs' `taskSpace()` / `page.click()`.",
|
|
14539
15059
|
parameters: {
|
|
14540
15060
|
script: {
|
|
14541
15061
|
type: "string",
|
|
14542
15062
|
required: true,
|
|
14543
|
-
description: "Full JS script body. You may end with console.log(JSON.stringify(payload))
|
|
15063
|
+
description: "Full JS script body. You may end with console.log(JSON.stringify(payload)) — bare or prefixed with the sentinel — and it is returned as `result`. Without one, `output` still carries everything the script printed."
|
|
14544
15064
|
},
|
|
14545
15065
|
timeoutMs: {
|
|
14546
15066
|
type: "integer",
|
|
@@ -14661,7 +15181,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14661
15181
|
stepBudget: cfg.jevStepBudget,
|
|
14662
15182
|
wallMs: cfg.jevWallMs
|
|
14663
15183
|
});
|
|
14664
|
-
/** Build the intent from tool args. Hints stay hints
|
|
15184
|
+
/** Build the intent from tool args. Hints stay hints — never selectors. */
|
|
14665
15185
|
const intentFrom = (args) => {
|
|
14666
15186
|
const hints = str(args.hints, "");
|
|
14667
15187
|
const criteria = str(args.successCriteria, "");
|
|
@@ -14717,6 +15237,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14717
15237
|
type: "object",
|
|
14718
15238
|
additionalProperties: false,
|
|
14719
15239
|
properties: {
|
|
15240
|
+
...FAILURE_PROPS,
|
|
14720
15241
|
ok: {
|
|
14721
15242
|
type: "boolean",
|
|
14722
15243
|
required: true
|
|
@@ -14754,7 +15275,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14754
15275
|
"",
|
|
14755
15276
|
`browser attach : ${attach.wsUrl === "" ? `NOT ATTACHED (status=${attach.status}${attach.code === "" ? "" : `, code=${attach.code}`})` : `${attach.endpoint} (${attach.endpointSource ?? "unknown"})`}`
|
|
14756
15277
|
];
|
|
14757
|
-
if (judge.layaKey === "") lines.push("", "laya has no key, so that hop is SKIPPED
|
|
15278
|
+
if (judge.layaKey === "") lines.push("", "laya has no key, so that hop is SKIPPED — the chain is running on the offline rule hop alone.", "laya-api has no anonymous branch, so a keyless call is a guaranteed 401; skipping it is deliberate.", "", "To bring laya up locally:", " 1. start the sidecar (it serves 8000, and JevLoop's 7789 is a different tool):", " ENGINE=laya LAYA_PRELOAD=true LAYA_DEVICE=cpu uvicorn laya_api.main:app", " with ALLOW_DEV_LOGIN=true you can sign in without Google.", " 2. open http://localhost:8000, create an API key (it is shown once, format laya_...).", " 3. paste it into this panel's Laya key field and save.");
|
|
14758
15279
|
return {
|
|
14759
15280
|
ok: true,
|
|
14760
15281
|
text: lines.join("\n")
|
|
@@ -14818,6 +15339,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14818
15339
|
type: "object",
|
|
14819
15340
|
additionalProperties: false,
|
|
14820
15341
|
properties: {
|
|
15342
|
+
...FAILURE_PROPS,
|
|
14821
15343
|
ok: {
|
|
14822
15344
|
type: "boolean",
|
|
14823
15345
|
required: true
|
|
@@ -14901,12 +15423,12 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14901
15423
|
`chunk plan : total=${round.plan.chunkTotal} size=${round.plan.chunkSize} reason=${round.plan.reason}`,
|
|
14902
15424
|
`questions : ${Object.keys(round.questions).join(", ")}`
|
|
14903
15425
|
];
|
|
14904
|
-
if (round.round === "pick" && chapterKey === "") lines.push("", "note: this pick round was assembled WITHOUT a chapter filter, so it offers every candidate in the chunk.", "During a real run the loop asks the chapter question first and then restricts the pick to that section —", "which is what keeps both questions inside a stricter threshold bucket.");
|
|
15426
|
+
if (round.round === "pick" && chapterKey === "") lines.push("", "note: this pick round was assembled WITHOUT a chapter filter, so it offers every candidate in the chunk.", "During a real run the loop asks the chapter question first and then restricts the pick to that section — ", "which is what keeps both questions inside a stricter threshold bucket.");
|
|
14905
15427
|
if (round.issues.length > 0) lines.push(`ISSUES : ${round.issues.map((issue) => `${issue.code}(${issue.questionId})`).join(", ")} <- must be fixed before sending`);
|
|
14906
15428
|
if (assembland !== null) {
|
|
14907
15429
|
lines.push(`POST : ${assembland.url}`);
|
|
14908
15430
|
lines.push("", "── assembled request body (exactly the three allowed keys) ──", JSON.stringify(assembland.body, null, 2));
|
|
14909
|
-
} else lines.push("", "(no HTTP hop configured
|
|
15431
|
+
} else lines.push("", "(no HTTP hop configured — only the rule hop is available)");
|
|
14910
15432
|
if (bool(args.dryRun, true)) {
|
|
14911
15433
|
lines.push("", "dryRun: nothing was sent.");
|
|
14912
15434
|
return {
|
|
@@ -14958,6 +15480,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
14958
15480
|
type: "object",
|
|
14959
15481
|
additionalProperties: false,
|
|
14960
15482
|
properties: {
|
|
15483
|
+
...FAILURE_PROPS,
|
|
14961
15484
|
ok: {
|
|
14962
15485
|
type: "boolean",
|
|
14963
15486
|
required: true
|
|
@@ -15011,13 +15534,13 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15011
15534
|
`budget : ${frame.image === null || frame.image.maxBytes === 0 ? "unbounded" : frame.image.maxBytes + " B"}${frame.image?.overBudget === true ? " *** OVER BUDGET ***" : ""}`,
|
|
15012
15535
|
`candidates : ${frame.dom.nodes.length} of ${frame.dom.total}${frame.dom.truncated ? " (TRUNCATED)" : ""}`
|
|
15013
15536
|
];
|
|
15014
|
-
if (defaultAttachCache.get().engine === "lightpanda") lines.push(`engine : lightpanda (rendering: text
|
|
15537
|
+
if (defaultAttachCache.get().engine === "lightpanda") lines.push(`engine : lightpanda (rendering: text — screenshot fidelity differs from Chrome)`);
|
|
15015
15538
|
if (frame.image?.overBudget === true) lines.push("", "The image exceeded the byte budget even at floor quality. Raise jevMaxImageBytes, or accept it and let the count drive chunking.");
|
|
15016
15539
|
if (bool(args.showCandidates, true)) {
|
|
15017
15540
|
lines.push("", "── candidates (the judge answers with these numbers) ──");
|
|
15018
15541
|
for (const node of frame.dom.nodes) lines.push(`${node.n}. ${node.role} "${node.name}" [${node.container}]`);
|
|
15019
15542
|
}
|
|
15020
|
-
lines.push("", "note: rects are NOT carried on this path (the AX tree has none)
|
|
15543
|
+
lines.push("", "note: rects are NOT carried on this path (the AX tree has none) — the executor re-measures before any action.");
|
|
15021
15544
|
return {
|
|
15022
15545
|
ok: true,
|
|
15023
15546
|
text: lines.join("\n")
|
|
@@ -15069,6 +15592,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15069
15592
|
type: "object",
|
|
15070
15593
|
additionalProperties: false,
|
|
15071
15594
|
properties: {
|
|
15595
|
+
...FAILURE_PROPS,
|
|
15072
15596
|
ok: {
|
|
15073
15597
|
type: "boolean",
|
|
15074
15598
|
required: true
|
|
@@ -15168,6 +15692,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15168
15692
|
type: "object",
|
|
15169
15693
|
additionalProperties: false,
|
|
15170
15694
|
properties: {
|
|
15695
|
+
...FAILURE_PROPS,
|
|
15171
15696
|
ok: {
|
|
15172
15697
|
type: "boolean",
|
|
15173
15698
|
required: true
|
|
@@ -15216,7 +15741,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15216
15741
|
const nav = await effects.navigate(url);
|
|
15217
15742
|
if (!nav.ok) return {
|
|
15218
15743
|
ok: false,
|
|
15219
|
-
text: `bcdp_jev_attempt: navigation failed
|
|
15744
|
+
text: `bcdp_jev_attempt: navigation failed — ${nav.error ?? "unknown error"}`
|
|
15220
15745
|
};
|
|
15221
15746
|
const result = await runAttempt({
|
|
15222
15747
|
intent,
|
|
@@ -15228,7 +15753,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
15228
15753
|
`reason : ${result.reason}`,
|
|
15229
15754
|
`page : ${result.lastUrl || nav.url}`,
|
|
15230
15755
|
`elapsed : ${Date.now() - started}ms candidates(last round)=${result.candidates}`,
|
|
15231
|
-
`verify via : bcdp_cdp / bcdp_screenshot on targetId=${effects.frames().at(-1)?.target.targetId ?? "unknown"}
|
|
15756
|
+
`verify via : bcdp_cdp / bcdp_screenshot on targetId=${effects.frames().at(-1)?.target.targetId ?? "unknown"} — the receipt is a report, not a proof`
|
|
15232
15757
|
];
|
|
15233
15758
|
if (effects.lastError() !== "") lines.push(`lastError : ${effects.lastError()}`);
|
|
15234
15759
|
lines.push("", result.actions.length === 0 ? "── actions ── (none)" : "── actions ──");
|