dsh-browser-cdp 1.3.2 → 1.5.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/README.de.md +3 -3
- package/README.es.md +3 -3
- package/README.fr.md +3 -3
- package/README.it.md +3 -3
- package/README.md +58 -25
- package/README.ru.md +3 -3
- package/dsh-plugin.json +1 -1
- package/lib/index.js +442 -229
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -2606,6 +2606,8 @@ const cdpMode = z.union([
|
|
|
2606
2606
|
"remote"
|
|
2607
2607
|
]);
|
|
2608
2608
|
const toolInjection = z.union(["lazy", "always"]);
|
|
2609
|
+
const DEFAULT_SPACE = "default";
|
|
2610
|
+
const AUTO_SPACE_SENTINEL = ":auto";
|
|
2609
2611
|
const encoder = z.union([
|
|
2610
2612
|
"auto",
|
|
2611
2613
|
"software",
|
|
@@ -2618,6 +2620,7 @@ const encoder = z.union([
|
|
|
2618
2620
|
]);
|
|
2619
2621
|
const Config$1 = z.object({
|
|
2620
2622
|
isolateSpaces: z.boolean().description("Space isolation: false = persistent profile (keep logins across restarts); true = isolated sandbox.").volatile(),
|
|
2623
|
+
defaultSpace: z.string().description("Default task-space name when a bcdp_* call omits `space`. Persistent-profile mode reuses this single named slot — set it to the same value across sessions to share login state. Set `:auto` in isolated-sandbox mode to derive a per-session name (dsh-agent-<sessionId8>). Leave default (\"default\") unless you are running multiple agents in parallel.").volatile(),
|
|
2621
2624
|
idleTimeoutMin: z.number().min(0).max(1440).step(1).description("Auto-stop the backing browser after N minutes without an bcdp_* call (0 = off). Relaunches on demand at the next call.").volatile(),
|
|
2622
2625
|
chromePath: z.string().description("Path to Chrome/Chromium. Empty = auto-detect.").volatile(),
|
|
2623
2626
|
captureBackend: backend.description("Capture backend: auto, cdp, or ffmpeg.").volatile(),
|
|
@@ -2964,6 +2967,7 @@ function resolveConfig(config = {}) {
|
|
|
2964
2967
|
runtimeArgs: typeof config.runtimeArgs === "string" ? config.runtimeArgs : typeof config.egoCliArgs === "string" ? config.egoCliArgs : "",
|
|
2965
2968
|
chromeArgs: typeof config.chromeArgs === "string" ? config.chromeArgs : "",
|
|
2966
2969
|
isolateSpaces: typeof config.isolateSpaces === "boolean" ? config.isolateSpaces : config.isolateSpaces === "true" || config.isolateSpaces === "1" || config.isolateSpaces === 1,
|
|
2970
|
+
defaultSpace: typeof config.defaultSpace === "string" && config.defaultSpace.trim() !== "" ? config.defaultSpace.trim() : "default",
|
|
2967
2971
|
idleTimeoutMin: finiteIn(config.idleTimeoutMin, 0, 1440) ? config.idleTimeoutMin : 0,
|
|
2968
2972
|
links: sanitizeLinks(config.links ?? config.cdpTargets).links.map(normalizeProbeState),
|
|
2969
2973
|
activeTargetId: typeof config.activeTargetId === "string" ? config.activeTargetId : "",
|
|
@@ -3227,22 +3231,22 @@ function envelopeError(code, message) {
|
|
|
3227
3231
|
* add/change a tool, remember to sync an entry here or bcdp_help won't find it.
|
|
3228
3232
|
*/
|
|
3229
3233
|
const EGO_HELP_INDEX = {
|
|
3230
|
-
overview: "CDP 浏览器代理:结构化浏览器工具。导航/交互/观察/表单/网络/等待/键鼠皆有专项工具,另提供 bcdp_help(本索引)、bcdp_doctor(体检)、
|
|
3231
|
-
tools: "工具清单: bcdp_status,
|
|
3234
|
+
overview: "CDP 浏览器代理:结构化浏览器工具。导航/交互/观察/表单/网络/等待/键鼠皆有专项工具,另提供 bcdp_help(本索引)、bcdp_doctor(体检)、bcdp_script(自由脚本逃生舱;verbatim:true 为裸 heredoc)。连接与激活见 topic=links。分类见: tools / navigate / observe / input / keyboard-mouse / form / wait / network / login / script / doctor / lightpanda / injection。用 `topic` 查询,或直接给工具名。",
|
|
3235
|
+
tools: "工具清单: bcdp_status, bcdp_space(+op:open/close/list/handoff/takeover), bcdp_snapshot, bcdp_navigate, bcdp_tab, bcdp_click(+double), bcdp_fill, bcdp_js, bcdp_cdp, bcdp_screenshot(+selector), bcdp_page_info, bcdp_wait(+op:duration/selector/url/response/load/function/request/event), bcdp_key(+text/type/insert), bcdp_hover, bcdp_read_element, bcdp_select, bcdp_drag, bcdp_scroll, bcdp_upload, bcdp_check, bcdp_dialog, bcdp_download, bcdp_http, bcdp_captcha, bcdp_auth_flush, bcdp_login_import, bcdp_help, bcdp_doctor, bcdp_script(+verbatim), bcdp_jev_status, bcdp_jev_frame, bcdp_jev_attempt, bcdp_jev_ask, bcdp_jev_run。",
|
|
3232
3236
|
links: "连接序列(设置面板):有序列表,顺序即优先级,被激活的一项驱动每一次 bcdp_* 调用。两种类型——CDP 端点(注入 EGO_LINUX_CDP_URL,指向已开调试端口的浏览器)与 本机 ego CLI(不注入端点,由本机 ego CLI 直接驱动 ego-lite 浏览器;仅限本机,全局至多一条)。cdpMode: auto=按激活项;remote=仅接受 CDP 端点;local=受管本地启动器。cdpMode=remote 与「本机 ego CLI」组合会显式报 mode-kind-mismatch。remoteEnabled 只管远端 CDP,不影响本机 CLI 连接。",
|
|
3233
|
-
navigate: "bcdp_navigate: 打开URL或切tab(同任务复用当前tab)。
|
|
3237
|
+
navigate: "bcdp_navigate: 打开URL或切tab(同任务复用当前tab)。bcdp_wait op=url: 等跳转(登录/分页)。",
|
|
3234
3238
|
observe: "bcdp_snapshot: 整页语义树(带[ref]/loc供点击); bcdp_page_info: url/标题/视口/滚动/对话框/人机验证; bcdp_read_element: 读单元素文本/HTML/值/属性/可见性/计数; bcdp_screenshot(+selector): 整页或元素截图。",
|
|
3235
3239
|
input: "bcdp_click(selector/坐标, double双击); bcdp_fill(填框); bcdp_key(press组合键 或 text连续键入); bcdp_check(勾选/取消); bcdp_select(下拉); bcdp_upload(文件上传); bcdp_dialog(接受/取消JS对话框)。",
|
|
3236
3240
|
"keyboard-mouse": "bcdp_key: 键盘(press/text); bcdp_hover: 悬停; bcdp_drag: 拖拽(元素或坐标); bcdp_scroll: 滚轮/滚到元素; bcdp_click: 点击/双击。",
|
|
3237
3241
|
form: "bcdp_fill 填输入框; bcdp_select 下拉; bcdp_check checkbox/radio; bcdp_upload 文件; bcdp_key 回车/Tab导航; bcdp_dialog 处理提交弹窗。",
|
|
3238
|
-
wait: "bcdp_wait(固定毫秒);
|
|
3239
|
-
network: "bcdp_http: 发HTTP请求(默认浏览器上下文 fetch.browser, mode=server走Node fetch.server);
|
|
3242
|
+
wait: "bcdp_wait 一个工具八个 op:duration(固定毫秒); selector(等元素出现/消失, 可带 state); url(等跳转); response(等网络响应, body=text|json 可读体); load(等加载状态); function(页内表达式变真); request(等请求); event(等下载)。",
|
|
3243
|
+
network: "bcdp_http: 发HTTP请求(默认浏览器上下文 fetch.browser, mode=server走Node fetch.server); bcdp_wait op=response: 等并读接口响应。",
|
|
3240
3244
|
download: "bcdp_download: 等下载事件并落到指定路径(triggerSelector/triggerScript + 可选 savePath)。",
|
|
3241
3245
|
captcha: "bcdp_captcha: 检测页面人机验证(CAPTCHA)并返回{detected,kind}; 检测到请让用户去 ego 浏览器完成; bcdp_page_info 也附带 humanCheck。",
|
|
3242
3246
|
login: "bcdp_auth_flush: 把登录cookie落盘到ego profile; 观察窗登录引导条+『已登录,保存』按钮触发同一动作。bcdp_login_import: 从系统浏览器(Chrome/Edge/Brave)按域名导入登录cookie(source/domains/dryRun; 先dryRun看可导入项; ego浏览器须已在运行)。",
|
|
3243
|
-
script: "
|
|
3247
|
+
script: "bcdp_script: 原样运行任意内置运行时 heredoc 脚本(page/browser/taskSpaces/site/fetch/cdp预载)。默认加 preamble(选区+激活真实 tab)并额外返回 duration/timedOut; verbatim:true 则完全原样、无 preamble(原 bcdp_cli 行为, 需自行 taskSpaces.useOrCreate)。",
|
|
3244
3248
|
doctor: "bcdp_doctor: 体检环境(浏览器候选、vendored runtime、状态目录、CDP端口、任务空间、引擎与降级清单);首行附工具注入面快照。",
|
|
3245
|
-
injection: "工具分级注入(不是工具,是出现时机):
|
|
3249
|
+
injection: "工具分级注入(不是工具,是出现时机):34 个 bcdp_* 分八批——core(status/doctor/help/space/navigate/snapshot,常驻不可封印)/ act(点击填写键鼠拖拽+tab 标签管理)/ observe(截图页面信息读取js)/ wait(bcdp_wait 全 op)/ power(裸CDP/HTTP/上传/下载/对话框)/ session(验证码/登录落盘/登录导入)/ escape(script 逃生舱)/ judge(bcdp_jev_*)。设置旋钮(全 volatile):toolInjection = lazy(默认,常驻 core + escape,首次 bcdp_* 调用后铺开其余)/ always(挂载即全量,历史行为);toolBrowse(act+observe+wait,内部按 act→observe→wait 三波放行)/ toolExtended(power+session)/ toolEscape(script)/ toolJudge 四把开关——开 = 开放注册,关 = 该批从工具列表移除(core 级不给开关,封了就没解锁入口);judge 级即使开了仍需配 JEV/Laya Key。**escape 批不吃活动闸**:script 是唯一的「一次调用干完任意多步任务」的入口,必须始终可达,不排在首次活动之后。封印 = 从工具列表里反注册,不是执行期报错;lazy 下闲置回收会把扩展面收回。**若某个 bcdp_* 工具不在你的工具列表里**:它被分级封印了——先跑 bcdp_status 或 bcdp_doctor(两者也算浏览器活动,会把面铺开),或让用户在设置页「工具封印」里打开对应档位的开关;别猜测不存在的工具名。",
|
|
3246
3250
|
lightpanda: "Lightpanda 作为后端(无头文本渲染引擎,beta):设置面板「添加 Lightpanda(受管)」——受管 serve 行(本机单例,插件负责拉起/复用/停止;win32 经 WSL2,linux/mac 本机直装),激活后 probe 自动识别 engine 并全链降级;也可用普通 CDP 端点接已自起的 serve(http://127.0.0.1:9222)。**有头/无头与顺序语义**:CDP 端点/本机 Chrome/ego CLI 是有头类型——可人工兜底(手动输账号、过验证码),是兜底主力;Lightpanda 是无头类型——无法人工介入,只适合快速试验。顺序即优先级:把 Lightpanda 排在前面 = 快速场景优先用它;排在有头类型后面 = 有头兜底优先,Lightpanda 实际不会被启用。安装——linux/macOS:`curl -fsSL https://pkg.lightpanda.io/install.sh | bash`(装入 ~/.local/bin,确保 PATH 含它),`lightpanda serve --host 127.0.0.1 --port 9222`;Windows:无原生版,用 WSL2(管理员 `wsl --install`,WSL 内同上;WSL2 自动把端口映射到宿主 localhost)或 Docker(`docker run -d -p 127.0.0.1:9222:9222 lightpanda/browser:nightly`)。可用:navigate/js/click/fill/key/snapshot(AX树)/http/login_import 等;降级:截图=PNG 文本渲染(jev 输出带 engine/rendering 元数据);关闭:观察窗实时画面、面板点选、bcdp_download(调用即结构化报错)、auth_flush(返回 degraded)",
|
|
3247
3251
|
judge: "JEV/Laya 判定(阶段 10):机械采集「截图 + 编号 DOM + 意图 + 操作进度」→ 组装问题 → 取选择 → 执行 → 验证。判定器只能回传编号,绝不给选择器(幻觉选择器在结构上不可能)。四件套:bcdp_jev_status(先跑这个:判定链可用性 + 配置体检,不发任何请求)/ bcdp_jev_frame(采一帧,看判定器会看到什么)/bcdp_jev_ask(组装请求体;dryRun 默认 true,可指定 round=control|chapter|pick|evaluate 逐级看)/ bcdp_jev_run(跑循环,返回逐步 trace)。bcdp_jev_attempt(平的尝试循环):给 url + goal,开页后每轮选项 = DOM 候选 + end 项,判定模型在 maxActions(默认 5)预算内行动或自选 end 结束,回执含每步 anchor;判定上下文只走 DOM 树文本(模型不读截图),完成后你用 bcdp_cdp/bcdp_screenshot 按 targetId 自行核验——回执是报告不是证明。**三级缩小**:control(要不要动手,固定 5 项)→ chapter(哪个章节,按 AX 容器聚簇)→ pick(章节内哪个编号 + 风险度)。分章节不是装饰:阈值按候选数分桶,把 20 选 1 拆成「几选 1 × 几选 1」会让两轮都落在更严的桶里。单章节时不问章节轮。**判定上下文是隔离的**:只允许 INTENT / PROGRESS / FRAME / HISTORY 四段,**绝不带 agent 会话 session 前缀**;多出任何一段都会在组装时直接抛错(不靠约定,靠断言)。PROGRESS 由循环自己机械生成,不让模型写(模型写的进度是第二个人幻觉通道)。**评估开关 jevEvaluate(默认开)**:每步执行后判定器再判进度 inprogress/done/fail;fail 或「未验真的 done」不猜下一步,直接 escalate——带有序 RecoveryOption(reload 排第一,因陈旧渲染会藏住已写入的确认),交回你来恢复或停手。被操作元素会保留 class 等定位特征(只剥离检视器外壳 token)随 escalate 回传,便于恢复。**默认链路是 laya -> rule**:JEV 目前无法注册,所以默认不写它;将来可用时把 jev 加回跳序并填 URL 即可。不可用的跳**跳过不调用**(laya-api 强制鉴权无匿名分支,缺 key 必然 401),每一跳的跳过与失败都记进 trace,绝不静默回落;refuse 是结果不是异常。阈值一律用选中项概率 top(不是 confidence:后者是归一化熵,2 选 1 与 20 选 1 不可比)。设置面板键:layaUrl/layaKey/layaModel(laya 端口 8000,不是 7789)、judgePrefer、jevChunkSize、jevMaxImageBytes、jevHistoryLimit、jevArchiveImage、jevStepBudget、jevWallMs;jevUrl/jevKey/jevModel 留空即可(JEV 未开放注册)。"
|
|
3248
3252
|
};
|
|
@@ -3551,8 +3555,7 @@ const CORE = [
|
|
|
3551
3555
|
"bcdp_status",
|
|
3552
3556
|
"bcdp_doctor",
|
|
3553
3557
|
"bcdp_help",
|
|
3554
|
-
"
|
|
3555
|
-
"bcdp_space_close",
|
|
3558
|
+
"bcdp_space",
|
|
3556
3559
|
"bcdp_navigate",
|
|
3557
3560
|
"bcdp_snapshot"
|
|
3558
3561
|
];
|
|
@@ -3564,7 +3567,8 @@ const ACT = [
|
|
|
3564
3567
|
"bcdp_scroll",
|
|
3565
3568
|
"bcdp_select",
|
|
3566
3569
|
"bcdp_check",
|
|
3567
|
-
"bcdp_drag"
|
|
3570
|
+
"bcdp_drag",
|
|
3571
|
+
"bcdp_tab"
|
|
3568
3572
|
];
|
|
3569
3573
|
const OBSERVE = [
|
|
3570
3574
|
"bcdp_screenshot",
|
|
@@ -3572,12 +3576,7 @@ const OBSERVE = [
|
|
|
3572
3576
|
"bcdp_read_element",
|
|
3573
3577
|
"bcdp_js"
|
|
3574
3578
|
];
|
|
3575
|
-
const WAIT = [
|
|
3576
|
-
"bcdp_wait",
|
|
3577
|
-
"bcdp_wait_for_selector",
|
|
3578
|
-
"bcdp_wait_for_url",
|
|
3579
|
-
"bcdp_wait_for_response"
|
|
3580
|
-
];
|
|
3579
|
+
const WAIT = ["bcdp_wait"];
|
|
3581
3580
|
const POWER = [
|
|
3582
3581
|
"bcdp_cdp",
|
|
3583
3582
|
"bcdp_http",
|
|
@@ -3590,7 +3589,7 @@ const SESSION = [
|
|
|
3590
3589
|
"bcdp_auth_flush",
|
|
3591
3590
|
"bcdp_login_import"
|
|
3592
3591
|
];
|
|
3593
|
-
const ESCAPE = ["
|
|
3592
|
+
const ESCAPE = ["bcdp_script"];
|
|
3594
3593
|
const JUDGE = [
|
|
3595
3594
|
"bcdp_jev_status",
|
|
3596
3595
|
"bcdp_jev_ask",
|
|
@@ -4438,6 +4437,32 @@ const num = (v, fallback) => typeof v === "number" && Number.isFinite(v) ? v : f
|
|
|
4438
4437
|
const bool = (v, fallback) => typeof v === "boolean" ? v : fallback;
|
|
4439
4438
|
/** Inline helper making arbitrary helper results JSON-safe for the payload. */
|
|
4440
4439
|
const SAFE_FN = "function safe(v){try{return JSON.parse(JSON.stringify(v))}catch{return String(v)}}\n";
|
|
4440
|
+
/**
|
|
4441
|
+
* Build an IN-PAGE wrapper that resolves a JS expression to a value that is
|
|
4442
|
+
* already safe to cross the CDP boundary.
|
|
4443
|
+
*
|
|
4444
|
+
* WHY in-page, not outer: `page.evaluate` / `page.waitForFunction` serialize
|
|
4445
|
+
* their result INSIDE the runtime's `handleMessage` (ego SDK index.js:539 — a
|
|
4446
|
+
* hard reject, not a catchable throw), so a deeply-cyclic global like
|
|
4447
|
+
* `window.top` kills the whole subprocess with "Object reference chain is too
|
|
4448
|
+
* long" before any outer `safe()` could see the value. Doing the stringify/
|
|
4449
|
+
* toString degradation inside the page (where the object graph actually lives)
|
|
4450
|
+
* is the only place the reference chain can be bounded.
|
|
4451
|
+
*
|
|
4452
|
+
* Semantics preserved per-call:
|
|
4453
|
+
* - primitives and plain (non-cyclic) objects round-trip UNCHANGED;
|
|
4454
|
+
* - cyclic/DOM/global handles degrade to `Object.prototype.toString` or a
|
|
4455
|
+
* `<tagName>` hint;
|
|
4456
|
+
* - with `preserveFalsy`, a falsy result is returned as-is (the waitForFunction
|
|
4457
|
+
* truthiness contract depends on falsy meaning "not satisfied yet"), and a
|
|
4458
|
+
* truthy handle is always degraded to a TRUTHY string so the wait still
|
|
4459
|
+
* resolves.
|
|
4460
|
+
*
|
|
4461
|
+
* @internal exported for tests
|
|
4462
|
+
*/
|
|
4463
|
+
function safeEvalWrap(expr, preserveFalsy = false) {
|
|
4464
|
+
return `(() => {\nconst __v = (${expr});\n${preserveFalsy ? "if (!__v) return __v;\n" : ""}if (__v === null || typeof __v !== 'object') return __v;\ntry { const __s = JSON.stringify(__v); return __s === undefined ? Object.prototype.toString.call(__v) : JSON.parse(__s); }\ncatch { try { if (__v.tagName) return '<' + String(__v.tagName).toLowerCase() + '>' + (typeof __v.getAttribute === 'function' && __v.getAttribute('id') ? '#' + __v.getAttribute('id') : ''); return Object.prototype.toString.call(__v); } catch { return String(__v); } }\n})()`;
|
|
4465
|
+
}
|
|
4441
4466
|
/** Read an entire subprocess reader's buffered output. */
|
|
4442
4467
|
function readAll(reader) {
|
|
4443
4468
|
if (!reader) return "";
|
|
@@ -7098,7 +7123,7 @@ const Config = Config$1;
|
|
|
7098
7123
|
/** Vendored ego-linux CLI shipped inside this plugin (runtime/ego-linux/bin/). */
|
|
7099
7124
|
const VENDORED_EGO_BIN = fileURLToPath(new URL("../runtime/ego-linux/bin/ego-browser.mjs", import.meta.url));
|
|
7100
7125
|
const DEFAULT_EGO_BIN = VENDORED_EGO_BIN;
|
|
7101
|
-
const
|
|
7126
|
+
const AUTO_SPACE_PREFIX = "dsh-agent-";
|
|
7102
7127
|
const DEFAULT_MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
7103
7128
|
const DEFAULT_GRACE_MS = 15e3;
|
|
7104
7129
|
const TOOL_TIMEOUT_MS = 12e4;
|
|
@@ -7132,6 +7157,75 @@ function createActiveSpaceTracker(defaultSpace = DEFAULT_SPACE) {
|
|
|
7132
7157
|
}
|
|
7133
7158
|
};
|
|
7134
7159
|
}
|
|
7160
|
+
const GLOBAL_SESSION_KEY = "__global__";
|
|
7161
|
+
/**
|
|
7162
|
+
* C — resolve the fallback slot name for a session. `:auto` only expands to a
|
|
7163
|
+
* per-session `dsh-agent-<sid8>` in isolated-sandbox mode; persistent mode
|
|
7164
|
+
* (and the no-session global slot) collapse to the single named `default`,
|
|
7165
|
+
* protecting login reuse. Any other configured value passes through verbatim.
|
|
7166
|
+
* @internal exported for tests
|
|
7167
|
+
*/
|
|
7168
|
+
function deriveSlotDefaultName(rc, sessionKey) {
|
|
7169
|
+
const name$1 = rc.defaultSpace;
|
|
7170
|
+
if (name$1 === AUTO_SPACE_SENTINEL) {
|
|
7171
|
+
if (!rc.isolateSpaces) return DEFAULT_SPACE;
|
|
7172
|
+
return sessionKey === GLOBAL_SESSION_KEY ? DEFAULT_SPACE : AUTO_SPACE_PREFIX + sessionKey.slice(0, 8);
|
|
7173
|
+
}
|
|
7174
|
+
return name$1;
|
|
7175
|
+
}
|
|
7176
|
+
function createSessionSpaceTracker(defaultNameFor = () => DEFAULT_SPACE) {
|
|
7177
|
+
const slots = /* @__PURE__ */ new Map();
|
|
7178
|
+
let sessionKey = GLOBAL_SESSION_KEY;
|
|
7179
|
+
let session;
|
|
7180
|
+
const slotOf = (key) => {
|
|
7181
|
+
let s = slots.get(key);
|
|
7182
|
+
if (!s) {
|
|
7183
|
+
const def = defaultNameFor(key);
|
|
7184
|
+
s = {
|
|
7185
|
+
activeSpace: def,
|
|
7186
|
+
activeName: typeof def === "string" ? def : null
|
|
7187
|
+
};
|
|
7188
|
+
slots.set(key, s);
|
|
7189
|
+
}
|
|
7190
|
+
return s;
|
|
7191
|
+
};
|
|
7192
|
+
const withSlot = (fn) => {
|
|
7193
|
+
fn(slotOf(sessionKey), defaultNameFor(sessionKey));
|
|
7194
|
+
};
|
|
7195
|
+
return {
|
|
7196
|
+
setCurrentSession: (id) => {
|
|
7197
|
+
session = id;
|
|
7198
|
+
sessionKey = id ?? GLOBAL_SESSION_KEY;
|
|
7199
|
+
},
|
|
7200
|
+
currentSession: () => session,
|
|
7201
|
+
current: () => slotOf(sessionKey).activeSpace,
|
|
7202
|
+
opened: (args, result) => {
|
|
7203
|
+
withSlot((s, def) => {
|
|
7204
|
+
s.activeName = result?.name ?? str(args?.name, def) ?? null;
|
|
7205
|
+
s.activeSpace = result?.id ?? s.activeName ?? def;
|
|
7206
|
+
});
|
|
7207
|
+
},
|
|
7208
|
+
selected: (space) => {
|
|
7209
|
+
if (space !== void 0 && space !== "") withSlot((s) => {
|
|
7210
|
+
s.activeSpace = space;
|
|
7211
|
+
s.activeName = typeof space === "string" ? space : null;
|
|
7212
|
+
});
|
|
7213
|
+
},
|
|
7214
|
+
closed: (space, done) => {
|
|
7215
|
+
withSlot((s, def) => {
|
|
7216
|
+
if (done && (String(space) === String(s.activeSpace) || s.activeName !== null && String(space) === String(s.activeName))) {
|
|
7217
|
+
s.activeSpace = def;
|
|
7218
|
+
s.activeName = typeof def === "string" ? def : null;
|
|
7219
|
+
}
|
|
7220
|
+
});
|
|
7221
|
+
},
|
|
7222
|
+
resetToName: () => {
|
|
7223
|
+
withSlot((s, def) => {
|
|
7224
|
+
s.activeSpace = s.activeName ?? def;
|
|
7225
|
+
});
|
|
7226
|
+
}
|
|
7227
|
+
};
|
|
7228
|
+
}
|
|
7135
7229
|
/**
|
|
7136
7230
|
* The ego-lite host is a single persistent browser shared by every tool call;
|
|
7137
7231
|
* concurrent tool executions would race on the same task space / tabs. All
|
|
@@ -7150,7 +7244,7 @@ function withEgoLock(fn) {
|
|
|
7150
7244
|
*
|
|
7151
7245
|
* The vendored ego-linux CLI reads EGO_LINUX_CHROME (bare Chrome binary/wrapper
|
|
7152
7246
|
* path) and EGO_LINUX_HEADLESS (=1 to run headless) from the process env. When a
|
|
7153
|
-
* host does not set them
|
|
7247
|
+
* host does not set them �?the common case on root / Docker / CI boxes �?Chrome
|
|
7154
7248
|
* silently fails to start, and consumers see a 20s `DevTools port` timeout.
|
|
7155
7249
|
*
|
|
7156
7250
|
* This function makes the plugin self-sufficient WITHOUT touching the host or
|
|
@@ -7166,7 +7260,7 @@ function withEgoLock(fn) {
|
|
|
7166
7260
|
* - An opt-out switch EGO_BROWSER_AUTO_ADAPT (set to "0"/"false"/"no") restores
|
|
7167
7261
|
* the original "inherit host env verbatim" behavior.
|
|
7168
7262
|
*/
|
|
7169
|
-
/** 阶段 10
|
|
7263
|
+
/** 阶段 10 �?the render worker: the ONLY thing that can see a page. */
|
|
7170
7264
|
const RENDER_WORKER_BIN = fileURLToPath(new URL("../bin/cdp-render-worker.mjs", import.meta.url));
|
|
7171
7265
|
const BUNDLED_WRAPPER = fileURLToPath(new URL("../bin/cdp-chrome-wrapper.sh", import.meta.url));
|
|
7172
7266
|
const IS_WIN = process.platform === "win32";
|
|
@@ -7235,7 +7329,7 @@ function isPosixRoot(platform = process.platform) {
|
|
|
7235
7329
|
const uid = process.getuid?.();
|
|
7236
7330
|
return typeof uid === "number" && uid === 0 && platform !== "win32";
|
|
7237
7331
|
}
|
|
7238
|
-
/** No display server
|
|
7332
|
+
/** No display server �?headless is required (Linux/macOS headless servers). */
|
|
7239
7333
|
function isHeadlessDetected(platform = process.platform, env = process.env) {
|
|
7240
7334
|
if (platform === "win32" || platform === "darwin") return false;
|
|
7241
7335
|
return env.DISPLAY === void 0 || env.DISPLAY === "";
|
|
@@ -7267,7 +7361,7 @@ function resolveEgoEnv(cfg, { platform = process.platform, baseEnv = process.env
|
|
|
7267
7361
|
}
|
|
7268
7362
|
/**
|
|
7269
7363
|
* Read the attach decision for the CURRENTLY configured mode/activation.
|
|
7270
|
-
* Pure over (cfg, cache)
|
|
7364
|
+
* Pure over (cfg, cache) �?the decision table itself lives in cdp-targets.ts.
|
|
7271
7365
|
*/
|
|
7272
7366
|
function decideCdpAttach(cfg) {
|
|
7273
7367
|
const attach = defaultAttachCache.get();
|
|
@@ -7311,7 +7405,7 @@ function describeSpawnFailure(err) {
|
|
|
7311
7405
|
* session; a probe that arrives while the DevTools/CDP channel is still
|
|
7312
7406
|
* coming up can fail with one of these. Such failures are safe to retry
|
|
7313
7407
|
* briefly (the browser keeps warming up in the background). Anything else
|
|
7314
|
-
* must pass through immediately
|
|
7408
|
+
* must pass through immediately �?never mask a genuine error.
|
|
7315
7409
|
*/
|
|
7316
7410
|
const COLD_START_SIGNS = [
|
|
7317
7411
|
/CDP channel is not open/i,
|
|
@@ -7362,7 +7456,7 @@ function shouldReapBrowser(nowMs, lastActivityMs, idleTimeoutMin) {
|
|
|
7362
7456
|
* runtime's `--open` subcommand replaces a headless instance with a headed
|
|
7363
7457
|
* one on the same profile (tabs restore) or just raises the existing window.
|
|
7364
7458
|
* `--open` is on the runtimeArgs blocklist only because USER-supplied args
|
|
7365
|
-
* must not steal the window
|
|
7459
|
+
* must not steal the window �?here it is an explicit user action from the
|
|
7366
7460
|
* watch panel. --open stops+relaunches when headless, so give it real time.
|
|
7367
7461
|
*/
|
|
7368
7462
|
async function openAgentWindow(ctx, cfg) {
|
|
@@ -7410,11 +7504,55 @@ async function runWithStaleSpaceRetry(ctx, cfg, exec, buildScript, graceOverride
|
|
|
7410
7504
|
return result;
|
|
7411
7505
|
}
|
|
7412
7506
|
/**
|
|
7507
|
+
* F — navigate self-heal. A page whose renderer/main thread is wedged makes
|
|
7508
|
+
* `page.goto`/`page.reload` hang until the subprocess times out, and the SAME
|
|
7509
|
+
* stuck target is re-selected on the next call, so a plain retry never helps.
|
|
7510
|
+
* This revives the tab FIRST (open a fresh blank target, then close the wedged
|
|
7511
|
+
* active one — order matters: closing last would trip the last-tab guard and
|
|
7512
|
+
* leave the dead tab in place), then retries buildScript exactly once.
|
|
7513
|
+
*
|
|
7514
|
+
* Hard cap is one revive: a second hung attempt is returned verbatim rather
|
|
7515
|
+
* than looping, so a genuine error is never masked by tab churn.
|
|
7516
|
+
* @internal exported for tests
|
|
7517
|
+
*/
|
|
7518
|
+
const TAB_STUCK_RE = /no active tab|navigation (?:timed out|timeout)|page\.goto[\s\S]*timeout|timed out after \d+ms|net::ERR_|waiting for (?:document|load) timed out|TimeoutError|target closed/i;
|
|
7519
|
+
/** True when a failed run looks like a wedged/absent tab rather than a cold start. */
|
|
7520
|
+
function isTabStuckFailure(result) {
|
|
7521
|
+
const hay = `${result.error ?? ""}\n${result.stderr ?? ""}`;
|
|
7522
|
+
return TAB_STUCK_RE.test(hay);
|
|
7523
|
+
}
|
|
7524
|
+
/** Heredoc that swaps the stuck target for a fresh blank one (see runWithTabRevive). */
|
|
7525
|
+
function tabReviveScript() {
|
|
7526
|
+
return `const __before = await browser.listTabs()
|
|
7527
|
+
const __stuck = __before.find(t => t.active) ?? __before[0]
|
|
7528
|
+
await browser.openOrReuseTab('about:blank', { wait: true, timeout: 8000 })
|
|
7529
|
+
if (__stuck) { await browser.closeTab(__stuck.targetId) }
|
|
7530
|
+
console.log('${SENTINEL}' + JSON.stringify({ ok: true, revived: true, closed: __stuck?.targetId ?? null }))\n`;
|
|
7531
|
+
}
|
|
7532
|
+
/**
|
|
7533
|
+
* @internal exported for tests. Returns the final WarmupResult plus what it
|
|
7534
|
+
* recovered from (null on the normal path, so the tool result always carries
|
|
7535
|
+
* a `recoveredFrom` field the model can see).
|
|
7536
|
+
*/
|
|
7537
|
+
async function runWithTabRevive(ctx, cfg, exec, buildScript, graceOverrideMs) {
|
|
7538
|
+
const first = await runWithStaleSpaceRetry(ctx, cfg, exec, buildScript, graceOverrideMs);
|
|
7539
|
+
if (first.ok || !isTabStuckFailure(first)) return {
|
|
7540
|
+
result: first,
|
|
7541
|
+
recoveredFrom: null
|
|
7542
|
+
};
|
|
7543
|
+
const recoveredFrom = (first.error ?? first.stderr ?? "tab stuck").trim().slice(0, 500);
|
|
7544
|
+
await runEgoScript(ctx.subprocess, tabReviveScript(), exec, cfg, graceOverrideMs);
|
|
7545
|
+
return {
|
|
7546
|
+
result: await runWithStaleSpaceRetry(ctx, cfg, exec, buildScript, graceOverrideMs),
|
|
7547
|
+
recoveredFrom
|
|
7548
|
+
};
|
|
7549
|
+
}
|
|
7550
|
+
/**
|
|
7413
7551
|
* Find the last line carrying the sentinel and JSON-parse its payload.
|
|
7414
7552
|
*
|
|
7415
|
-
* Fallback: `bcdp_script`
|
|
7553
|
+
* Fallback: `bcdp_script` (with verbatim:true) runs user-authored heredocs, which
|
|
7416
7554
|
* tool descriptions tell the model to "end with console.log(JSON.stringify(...))"
|
|
7417
|
-
*
|
|
7555
|
+
* �?without the sentinel prefix. A script written to that instruction used to
|
|
7418
7556
|
* succeed and still be reported as a failure ("no @@DSH_RESULT@@ payload"), so
|
|
7419
7557
|
* when no sentinel line exists we accept the last line that parses as a JSON
|
|
7420
7558
|
* object. The sentinel still wins whenever it is present (it marks the payload
|
|
@@ -7486,9 +7624,9 @@ function lastJsonObject(text) {
|
|
|
7486
7624
|
}
|
|
7487
7625
|
return best;
|
|
7488
7626
|
}
|
|
7489
|
-
/** R2/R3
|
|
7627
|
+
/** R2/R3 �?sentinel + payload for the `bcdp_status` facade probe. @internal exported for tests */
|
|
7490
7628
|
const STATUS_FACADE_SENTINEL = "__BCDP_STATUS__";
|
|
7491
|
-
/** @internal exported for tests
|
|
7629
|
+
/** @internal exported for tests �?the exact heredoc the status probe runs. */
|
|
7492
7630
|
const STATUS_FACADE_SCRIPT = `console.log(${JSON.stringify(STATUS_FACADE_SENTINEL)} + JSON.stringify({ taskSpaces: typeof taskSpaces, browser: typeof browser, page: typeof page }))
|
|
7493
7631
|
`;
|
|
7494
7632
|
/**
|
|
@@ -7514,7 +7652,7 @@ function parseStatusFacades(stdout) {
|
|
|
7514
7652
|
}
|
|
7515
7653
|
}
|
|
7516
7654
|
/**
|
|
7517
|
-
* R7
|
|
7655
|
+
* R7 �?is the upstream plugin installed anywhere under this DSH home?
|
|
7518
7656
|
*
|
|
7519
7657
|
* Reported (never enforced): the two plugins can coexist now that tool names
|
|
7520
7658
|
* and routes no longer overlap, but both driving ONE local ego-lite would
|
|
@@ -7532,7 +7670,7 @@ function findUpstreamPluginInstall(home = process.env.HOME || process.env.USERPR
|
|
|
7532
7670
|
return "";
|
|
7533
7671
|
}
|
|
7534
7672
|
/**
|
|
7535
|
-
* R1
|
|
7673
|
+
* R1 �?argv for one tool run. Single source of truth for the `--sdk-path`
|
|
7536
7674
|
* injection: `bcdp_status` and `runEgoScript` must probe/run under the exact
|
|
7537
7675
|
* same conditions, otherwise "available" and "actually works" diverge again.
|
|
7538
7676
|
* @internal exported for tests
|
|
@@ -7630,6 +7768,22 @@ const useSpace = (name$1) => `const task = await taskSpaces.useOrCreate(${j(name
|
|
|
7630
7768
|
* before acting makes cross-process tool calls deterministic.
|
|
7631
7769
|
*/
|
|
7632
7770
|
const ensureRealTab = () => "const __tabs = await browser.listTabs()\nconst __real = __tabs.find(t => !t.url.startsWith('about:') && !t.url.startsWith('chrome://')) ?? __tabs[0]\nif (__real) await browser.switchTab(__real.targetId)\n";
|
|
7771
|
+
/**
|
|
7772
|
+
* G �?a raw heredoc (`bcdp_script` with verbatim:true) that touches `page.*` without
|
|
7773
|
+
* first selecting a task space dies with the runtime's "no active tab to attach
|
|
7774
|
+
* session". Structured bcdp_* tools never hit this because each wraps its body
|
|
7775
|
+
* in `useSpace(...)` + `ensureRealTab()`; a hand-written heredoc has no such
|
|
7776
|
+
* preamble. Detect the signature and append a one-line how-to-fix, so the error
|
|
7777
|
+
* names the escape (call `taskSpaces.useOrCreate(name)` first) instead of
|
|
7778
|
+
* leaving the model to rediscover it.
|
|
7779
|
+
* @internal exported for tests
|
|
7780
|
+
*/
|
|
7781
|
+
const ATTACH_SESSION_HINT = "hint: call `await taskSpaces.useOrCreate(name)` (and `browser.switchTab(...)` if the space has no real tab) before using page.* in a raw heredoc — structured bcdp_* tools do this for you.";
|
|
7782
|
+
function attachSessionHint(errorText) {
|
|
7783
|
+
const t = errorText ?? "";
|
|
7784
|
+
if (!/no active tab to attach session/.test(t)) return t;
|
|
7785
|
+
return t.includes(ATTACH_SESSION_HINT) ? t : `${t}\n${ATTACH_SESSION_HINT}`;
|
|
7786
|
+
}
|
|
7633
7787
|
function renderText(_args, value) {
|
|
7634
7788
|
const v = value;
|
|
7635
7789
|
if (v !== null && typeof v === "object" && v.ok === true && typeof v.text === "string") return [{
|
|
@@ -7650,7 +7804,7 @@ const commonOutputSchema = {
|
|
|
7650
7804
|
} }
|
|
7651
7805
|
};
|
|
7652
7806
|
/**
|
|
7653
|
-
* The calling session id
|
|
7807
|
+
* The calling session id �?the scope the client's sidebar auto-open binds to.
|
|
7654
7808
|
* Read structurally (`exec.agent` is typed `unknown` in this plugin's own
|
|
7655
7809
|
* seam); a call with no initiating agent simply leaves the open unscoped.
|
|
7656
7810
|
*/
|
|
@@ -7669,6 +7823,7 @@ function defineEgoTool(ctx, cfg, opts) {
|
|
|
7669
7823
|
},
|
|
7670
7824
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
7671
7825
|
execute: async (args, exec) => withEgoLock(async () => {
|
|
7826
|
+
cfg.spaceTracker.setCurrentSession(callingSessionId(exec));
|
|
7672
7827
|
markEgoToolCall(callingSessionId(exec));
|
|
7673
7828
|
if (typeof opts.gate === "function") {
|
|
7674
7829
|
const blocked = opts.gate(args);
|
|
@@ -7677,6 +7832,13 @@ function defineEgoTool(ctx, cfg, opts) {
|
|
|
7677
7832
|
text: blocked
|
|
7678
7833
|
};
|
|
7679
7834
|
}
|
|
7835
|
+
if (opts.tabRevive) {
|
|
7836
|
+
const { result: result$1, recoveredFrom } = await runWithTabRevive(ctx, cfg, exec, () => opts.buildScript(args));
|
|
7837
|
+
if (!result$1.ok) throw new Error(recoveredFrom ? `${result$1.error}\n${recoveredFrom}` : result$1.error);
|
|
7838
|
+
if (result$1.value && typeof result$1.value === "object") result$1.value.recoveredFrom = recoveredFrom;
|
|
7839
|
+
if (typeof opts.afterExecute === "function") opts.afterExecute(args, result$1.value);
|
|
7840
|
+
return result$1.value;
|
|
7841
|
+
}
|
|
7680
7842
|
const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => opts.buildScript(args));
|
|
7681
7843
|
if (!result.ok) throw new Error(result.error);
|
|
7682
7844
|
if (typeof opts.afterExecute === "function") opts.afterExecute(args, result.value);
|
|
@@ -7698,12 +7860,17 @@ function apply(ctx, config = {}) {
|
|
|
7698
7860
|
configuredPath: initialFfmpegConfig.ffmpegPath,
|
|
7699
7861
|
requestedEncoder: initialFfmpegConfig.ffmpegEncoder
|
|
7700
7862
|
}).catch(() => {});
|
|
7701
|
-
const spaceTracker =
|
|
7863
|
+
const spaceTracker = createSessionSpaceTracker((sessionKey) => deriveSlotDefaultName(resolveConfig(bridge.source()), sessionKey));
|
|
7702
7864
|
const cfg = {
|
|
7703
7865
|
egoBin: typeof config.egoBin === "string" && config.egoBin !== "" ? config.egoBin : DEFAULT_EGO_BIN,
|
|
7704
|
-
configuredDefaultSpace
|
|
7866
|
+
get configuredDefaultSpace() {
|
|
7867
|
+
return resolveConfig(bridge.source()).defaultSpace;
|
|
7868
|
+
},
|
|
7705
7869
|
spaceTracker,
|
|
7706
7870
|
get defaultSpace() {
|
|
7871
|
+
return resolveConfig(bridge.source()).defaultSpace;
|
|
7872
|
+
},
|
|
7873
|
+
get activeSpace() {
|
|
7707
7874
|
return this.spaceTracker.current();
|
|
7708
7875
|
},
|
|
7709
7876
|
maxOutputBytes: config.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES,
|
|
@@ -7886,9 +8053,8 @@ function apply(ctx, config = {}) {
|
|
|
7886
8053
|
logger: ctx.logger
|
|
7887
8054
|
});
|
|
7888
8055
|
/**
|
|
7889
|
-
*
|
|
7890
|
-
*
|
|
7891
|
-
*/
|
|
8056
|
+
* 活动信号:每�?bcdp_* 调用推进 browse 批次(act �?observe �?wait),
|
|
8057
|
+
* 到顶即止。只有注入面真的变了�?reapply�? */
|
|
7892
8058
|
const pulseActivity = () => {
|
|
7893
8059
|
const before = browseBatchDepth;
|
|
7894
8060
|
browserActive = true;
|
|
@@ -7900,9 +8066,8 @@ function apply(ctx, config = {}) {
|
|
|
7900
8066
|
ctx.effect?.(() => offActivity);
|
|
7901
8067
|
}
|
|
7902
8068
|
/**
|
|
7903
|
-
*
|
|
7904
|
-
* 面上留着 30
|
|
7905
|
-
*/
|
|
8069
|
+
* 闲置回收后把注入面收�?core 级(lazy 模式专属):浏览器已经停了,模型
|
|
8070
|
+
* 面上留着 30 多个驱动它的工具只是白付。下一次活动会重新铺开�? */
|
|
7906
8071
|
const sealAfterReap = () => {
|
|
7907
8072
|
if (cfg.toolInjection !== "lazy" || !browserActive) return;
|
|
7908
8073
|
browserActive = false;
|
|
@@ -7910,9 +8075,7 @@ function apply(ctx, config = {}) {
|
|
|
7910
8075
|
tiers.reapply();
|
|
7911
8076
|
};
|
|
7912
8077
|
/**
|
|
7913
|
-
* 常驻级工具看到的分级视图:`pulse` =
|
|
7914
|
-
* `surface` = 当前注入面(doctor 直接打出来,开关状态得看得见)。
|
|
7915
|
-
*/
|
|
8078
|
+
* 常驻级工具看到的分级视图:`pulse` = 把本次调用当成一次浏览器活动�? * `surface` = 当前注入面(doctor 直接打出来,开关状态得看得见)�? */
|
|
7916
8079
|
const tierView = {
|
|
7917
8080
|
pulse: pulseActivity,
|
|
7918
8081
|
active: () => browserActive,
|
|
@@ -8104,7 +8267,7 @@ function apply(ctx, config = {}) {
|
|
|
8104
8267
|
}).done.catch(() => {});
|
|
8105
8268
|
} catch {}
|
|
8106
8269
|
});
|
|
8107
|
-
ctx.logger?.info?.(`dsh-browser-cdp: mounted (egoBin=${cfg.egoBin}, defaultSpace=${cfg.
|
|
8270
|
+
ctx.logger?.info?.(`dsh-browser-cdp: mounted (egoBin=${cfg.egoBin}, defaultSpace=${cfg.activeSpace})`);
|
|
8108
8271
|
}
|
|
8109
8272
|
/** `bcdp_status` probes the SAME channel work uses: a `nodejs` heredoc. */
|
|
8110
8273
|
function registerEgoStatus(ctx, cfg, reg, tiers) {
|
|
@@ -8188,11 +8351,11 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
|
|
|
8188
8351
|
})
|
|
8189
8352
|
}));
|
|
8190
8353
|
}
|
|
8191
|
-
/** `bcdp_auth_flush`
|
|
8354
|
+
/** `bcdp_auth_flush` �?force persistent login cookies down to the disk profile. */
|
|
8192
8355
|
function registerAuthFlush(ctx, cfg, reg) {
|
|
8193
8356
|
reg(defineTool({
|
|
8194
8357
|
name: "bcdp_auth_flush",
|
|
8195
|
-
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
|
|
8358
|
+
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.",
|
|
8196
8359
|
parameters: {},
|
|
8197
8360
|
output: {
|
|
8198
8361
|
schema: {
|
|
@@ -8243,7 +8406,7 @@ function registerAuthFlush(ctx, cfg, reg) {
|
|
|
8243
8406
|
flushed: jbody.flushed ?? 0,
|
|
8244
8407
|
...degraded ? {
|
|
8245
8408
|
degraded: true,
|
|
8246
|
-
error: "engine-unsupported: Lightpanda has no Storage.flushCookies
|
|
8409
|
+
error: "engine-unsupported: Lightpanda has no Storage.flushCookies �?cookies persist only while the engine process is alive"
|
|
8247
8410
|
} : {},
|
|
8248
8411
|
...!degraded && jbody.error !== void 0 ? { error: jbody.error } : {}
|
|
8249
8412
|
};
|
|
@@ -8262,7 +8425,7 @@ function registerAuthFlush(ctx, cfg, reg) {
|
|
|
8262
8425
|
})
|
|
8263
8426
|
}));
|
|
8264
8427
|
}
|
|
8265
|
-
/** `bcdp_login_import`
|
|
8428
|
+
/** `bcdp_login_import` �?copy login cookies from the system browser (issue #46). */
|
|
8266
8429
|
function registerLoginImport(ctx, cfg, reg) {
|
|
8267
8430
|
reg(defineTool({
|
|
8268
8431
|
name: "bcdp_login_import",
|
|
@@ -8324,7 +8487,7 @@ function registerLoginImport(ctx, cfg, reg) {
|
|
|
8324
8487
|
"auto"
|
|
8325
8488
|
].includes(source)) return {
|
|
8326
8489
|
ok: false,
|
|
8327
|
-
error: `invalid source "${source}"
|
|
8490
|
+
error: `invalid source "${source}" �?expected chrome|edge|brave|auto`
|
|
8328
8491
|
};
|
|
8329
8492
|
return await importLoginCookies({
|
|
8330
8493
|
source,
|
|
@@ -8354,9 +8517,11 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8354
8517
|
...opts,
|
|
8355
8518
|
afterExecute: (args, result) => {
|
|
8356
8519
|
if (!result || result.ok === false) return;
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8520
|
+
const a = args;
|
|
8521
|
+
const op = typeof a?.op === "string" ? a.op.trim() : "";
|
|
8522
|
+
if (opts.name === "bcdp_space" && op === "open") cfg.spaceTracker.opened(args, result);
|
|
8523
|
+
else if (opts.name === "bcdp_space" && op === "close") cfg.spaceTracker.closed(a.name, result.done);
|
|
8524
|
+
else if (a && a.space !== void 0 && a.space !== "") cfg.spaceTracker.selected(a.space);
|
|
8360
8525
|
opts.afterExecute?.(args, result);
|
|
8361
8526
|
}
|
|
8362
8527
|
});
|
|
@@ -8365,61 +8530,90 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8365
8530
|
description: "Task-space name or numeric id; defaults to the most recently opened or explicitly selected space."
|
|
8366
8531
|
};
|
|
8367
8532
|
reg(t({
|
|
8368
|
-
name: "
|
|
8369
|
-
|
|
8370
|
-
return cfg.isolateSpaces ? "Open (or reuse) an ego-lite task space in isolated sandbox mode." : "Open (or reuse) the ego-lite task space. In persistent profile mode (default), ALWAYS use or reuse the single 'default' space. Login credentials automatically persist on disk across restarts — if a page requires login, prompt user to log in manually in the opened window. DO NOT create numbered spaces like #4, #5.";
|
|
8371
|
-
},
|
|
8372
|
-
parameters: { name: {
|
|
8373
|
-
type: "string",
|
|
8374
|
-
required: true,
|
|
8375
|
-
get description() {
|
|
8376
|
-
return cfg.isolateSpaces ? "Task-space name or numeric id." : "Task-space name. In persistent mode, ALWAYS specify 'default'. Reuse this single space for all browsing tasks.";
|
|
8377
|
-
}
|
|
8378
|
-
} },
|
|
8379
|
-
buildScript: (args) => `${useSpace(str(args.name, cfg.defaultSpace))}console.log('${SENTINEL}' + JSON.stringify({ ok: true, id: task.id ?? null, name: task.name ?? ${j(str(args.name, cfg.defaultSpace))} }))\n`
|
|
8380
|
-
}));
|
|
8381
|
-
reg(t({
|
|
8382
|
-
name: "bcdp_space_close",
|
|
8383
|
-
get description() {
|
|
8384
|
-
return cfg.isolateSpaces ? "Complete (close) an ego-lite task space in sandbox mode." : "Close an ego-lite task space. WARNING: In persistent profile mode, DO NOT call this tool when finishing tasks! Keep the space, tabs, and browser window alive so login sessions and streams remain intact. Conclude tasks by replying to the user directly without closing the space.";
|
|
8385
|
-
},
|
|
8533
|
+
name: "bcdp_space",
|
|
8534
|
+
description: "Task space: op=open (or reuse) | close | list | handoff | takeover. In persistent profile mode (default) ALWAYS use or reuse the single 'default' space — credentials persist on disk across restarts, so do NOT create numbered spaces like #4/#5; if a page needs login, prompt the user to log in manually. Omitting `space` targets THIS session's own active slot (persistent: 'default'; isolated mode: dsh-agent-<sessionId8>), so concurrent sessions never drift into each other's spaces. handoff yields control to the human (stop driving until they hand back); takeover resumes agent control.",
|
|
8386
8535
|
parameters: {
|
|
8387
|
-
|
|
8536
|
+
op: {
|
|
8388
8537
|
type: "string",
|
|
8389
8538
|
required: true,
|
|
8390
|
-
description: "
|
|
8539
|
+
description: "\"open\" | \"close\" | \"list\" | \"handoff\" | \"takeover\"."
|
|
8540
|
+
},
|
|
8541
|
+
name: {
|
|
8542
|
+
type: "string",
|
|
8543
|
+
description: "op=open/close: task-space name (persistent mode: ALWAYS specify 'default' and reuse it for all browsing tasks). op=handoff/takeover: default = the configured space."
|
|
8391
8544
|
},
|
|
8392
8545
|
keep: {
|
|
8393
8546
|
type: "boolean",
|
|
8394
|
-
description: "
|
|
8395
|
-
}
|
|
8547
|
+
description: "op=close: keep the live page open (default false: close it)."
|
|
8548
|
+
},
|
|
8549
|
+
space: spaceParam
|
|
8396
8550
|
},
|
|
8397
|
-
buildScript: (args) =>
|
|
8551
|
+
buildScript: (args) => {
|
|
8552
|
+
const send = (expr) => `console.log('${SENTINEL}' + JSON.stringify(${expr}))\n`;
|
|
8553
|
+
const op = str(args.op, "").trim();
|
|
8554
|
+
const name$1 = str(args.name, str(args.space, cfg.activeSpace));
|
|
8555
|
+
if (op === "open") return `${useSpace(str(args.name, cfg.activeSpace))}` + send(`{ ok: true, op: 'open', id: task.id ?? null, name: task.name ?? ${j(str(args.name, cfg.activeSpace))} }`);
|
|
8556
|
+
if (op === "close") return `const res = await taskSpaces.complete(${j(name$1)}, { keep: ${bool(args.keep, false)} })\n` + send(`{ ok: true, op: 'close', done: !!res.done, skipped: !!res.skipped, reason: res.skipped ? ${j("target space was not agent-owned")} : null }`);
|
|
8557
|
+
if (op === "list") return `const __sp = await taskSpaces.list()\n` + send(`{ ok: true, op: 'list', spaces: __sp.map(s => ({ id: s.id ?? null, name: s.name ?? null, ownership: s.ownership ?? null })) }`);
|
|
8558
|
+
if (op === "handoff") return `${useSpace(name$1)}const __h = await taskSpaces.handOff(${j(name$1)})\n` + send(`{ ok: true, op: 'handoff', name: ${j(name$1)}, done: !!__h.done, skipped: __h.skipped ?? null, hint: 'user now has control; ask them to confirm before calling op=takeover' }`);
|
|
8559
|
+
if (op === "takeover") return `await taskSpaces.takeOver(${j(name$1)})\nconst __info = await page.info()\n` + send(`{ ok: true, op: 'takeover', name: ${j(name$1)}, page: __info }`);
|
|
8560
|
+
return send(`{ ok: false, reason: ${j("bcdp_space: op must be one of open|close|list|handoff|takeover")} }`);
|
|
8561
|
+
}
|
|
8398
8562
|
}));
|
|
8399
8563
|
reg(t({
|
|
8400
8564
|
name: "bcdp_snapshot",
|
|
8401
|
-
description: "Read the current page as text: the full-page semantic tree annotated with [ref=N, loc=...] selectors that bcdp_click / bcdp_fill can target.
|
|
8565
|
+
description: "Read the current page as text: the full-page semantic tree annotated with [ref=N, loc=...] selectors that bcdp_click / bcdp_fill can target. To target across calls prefer a `loc=` over `@N`: a loc is stable, a ref is renumbered every snapshot.",
|
|
8402
8566
|
parameters: {
|
|
8403
8567
|
space: spaceParam,
|
|
8404
8568
|
scope: {
|
|
8405
8569
|
type: "string",
|
|
8406
|
-
description: "
|
|
8570
|
+
description: "scope: 'full_page' (default) | 'only_within_viewport'; 'subtree' captures only `root`'s subtree."
|
|
8571
|
+
},
|
|
8572
|
+
root: {
|
|
8573
|
+
type: "string",
|
|
8574
|
+
description: "scope='subtree': the node to capture - a `loc=` token (stable across calls) or a ref like '@12' from a fresh snapshot."
|
|
8407
8575
|
}
|
|
8408
8576
|
},
|
|
8409
8577
|
buildScript: (args) => {
|
|
8410
8578
|
const scope = str(args.scope, "");
|
|
8411
|
-
const
|
|
8412
|
-
|
|
8579
|
+
const send = (expr) => `console.log('${SENTINEL}' + JSON.stringify(${expr}))\n`;
|
|
8580
|
+
const SNAP_OPTS = "includeStableLocator: true";
|
|
8581
|
+
if (scope === "subtree") {
|
|
8582
|
+
const rootArg = str(args.root, "").trim();
|
|
8583
|
+
if (rootArg === "") return send(`{ ok: false, reason: 'bcdp_snapshot: root (a ref such as @N, or a loc=css:�? is required for scope=subtree' }`);
|
|
8584
|
+
const resolver = `((raw, refs) => {
|
|
8585
|
+
const want = raw.replace(/^loc=/, '').trim()
|
|
8586
|
+
if (want !== '' && want !== 'unstable') {
|
|
8587
|
+
const byLoc = refs.find(r => r.loc != null && String(r.loc).replace(/^loc=/, '') === want)
|
|
8588
|
+
if (byLoc && byLoc.backendNodeId != null) return byLoc.backendNodeId
|
|
8589
|
+
}
|
|
8590
|
+
const id = raw.replace(/^@/, '').trim()
|
|
8591
|
+
const byRef = refs.find(r => String(r.refId) === id)
|
|
8592
|
+
return byRef ? byRef.backendNodeId ?? null : null
|
|
8593
|
+
})(${j(rootArg)}, s.refs ?? [])`;
|
|
8594
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}let s = await page.snapshotRaw({ ${SNAP_OPTS} })\nlet tries = 0\nwhile (!(s.content ?? '') && tries < 3) { await page.waitForTimeout(400); s = await page.snapshotRaw({ ${SNAP_OPTS} }); tries++ }\nconst __bn = ${resolver}\nif (__bn === null) { ${send(`{ ok: false, root: ${j(rootArg)}, reason: 'subtree root not present in the current snapshot; take a fresh full snapshot and use a loc= (survives across calls) or a ref @N from it' }`)} }\nelse { const sub = await page.snapshotRaw({ scope: 'subtree', root: __bn, ${SNAP_OPTS} }); const stext = sub.content ?? '';\nconsole.log('${SENTINEL}' + JSON.stringify(stext === ''\n ? { ok: false, root: ${j(rootArg)}, backendNodeId: __bn, text: stext, reason: 'subtree capture came back empty' }\n : { ok: true, root: ${j(rootArg)}, backendNodeId: __bn, text: stext, tries })) }\n`;
|
|
8595
|
+
}
|
|
8596
|
+
const call = scope === "" ? `await page.snapshotRaw({ ${SNAP_OPTS} })` : `await page.snapshotRaw({ scope: ${j(scope)}, ${SNAP_OPTS} })`;
|
|
8597
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}let s = ${call}\nlet tries = 0\nwhile (!(s.content ?? '') && tries < 3) { await page.waitForTimeout(400); s = ${call}; tries++ }\nconst text = s.content ?? ''\nconsole.log('${SENTINEL}' + JSON.stringify(text === ''\n ? { ok: false, text, tries, reason: 'snapshot returned no content after retries (page may be blank, still loading, or the browser dropped)' }\n : { ok: true, text, tries }))\n`;
|
|
8413
8598
|
}
|
|
8414
8599
|
}));
|
|
8415
8600
|
reg(t({
|
|
8416
8601
|
name: "bcdp_navigate",
|
|
8417
|
-
description: "Open a URL in the task space, or switch to the existing tab for it
|
|
8602
|
+
description: "Open a URL in the task space, or switch to the existing tab for it (prefer reuse over duplicates). Waits for document load, returns page info.",
|
|
8603
|
+
tabRevive: true,
|
|
8418
8604
|
parameters: {
|
|
8419
8605
|
url: {
|
|
8420
8606
|
type: "string",
|
|
8421
8607
|
required: true,
|
|
8422
|
-
description: "Absolute URL to open
|
|
8608
|
+
description: "Absolute URL to open (omit if reload)."
|
|
8609
|
+
},
|
|
8610
|
+
reload: {
|
|
8611
|
+
type: "boolean",
|
|
8612
|
+
description: "Reload the current tab (no url needed)."
|
|
8613
|
+
},
|
|
8614
|
+
ignoreCache: {
|
|
8615
|
+
type: "boolean",
|
|
8616
|
+
description: "With reload: bypass cache."
|
|
8423
8617
|
},
|
|
8424
8618
|
wait: {
|
|
8425
8619
|
type: "boolean",
|
|
@@ -8433,8 +8627,9 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8433
8627
|
},
|
|
8434
8628
|
buildScript: (args) => {
|
|
8435
8629
|
const u = str(args.url, "");
|
|
8630
|
+
if (bool(args.reload, false)) return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}const __ok = await page.reload({ ignoreCache: ${bool(args.ignoreCache, false)}, waitUntil: ${j(bool(args.wait, true) ? "load" : "commit")}, timeout: ${num(args.timeout, 2e4)} })\nconst pginfo = await page.info()\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, reloaded: true, loaded: __ok !== false, page: pginfo }))\n`;
|
|
8436
8631
|
if (u === "") return `console.log('${SENTINEL}' + JSON.stringify({ ok: false, reused: false, page: null, reason: 'bcdp_navigate: url is required' }))\n`;
|
|
8437
|
-
return `${useSpace(str(args.space, cfg.
|
|
8632
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}const __existing = __tabs.find(t => t.url.split('#')[0] === ${j(u.split("#")[0])})\nconst tab = __existing ? await browser.switchTab(__existing.targetId) : await page.goto(${j(u)}, { wait: ${bool(args.wait, true)}, timeout: ${num(args.timeout, 2e4)} })\nconst pginfo = await page.info()\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, reused: !!__existing, page: pginfo }))\n`;
|
|
8438
8633
|
}
|
|
8439
8634
|
}));
|
|
8440
8635
|
reg(t({
|
|
@@ -8474,7 +8669,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8474
8669
|
const labelOpt = str(args.label, "") !== "" ? `{ label: ${j(str(args.label, ""))} }` : "";
|
|
8475
8670
|
action = dbl ? `await page.locator(${j(sel)}).dblclick(${labelOpt})` : `await page.locator(${j(sel)}).click(${labelOpt})`;
|
|
8476
8671
|
} else action = dbl ? `await page.mouse.dblclick(${x}, ${y})` : `await page.mouse.click(${x}, ${y})`;
|
|
8477
|
-
return `${useSpace(str(args.space, cfg.
|
|
8672
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}${action}\nconst pginfo = await page.info()\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, double: ${dbl}, page: pginfo }))\n`;
|
|
8478
8673
|
}
|
|
8479
8674
|
}));
|
|
8480
8675
|
reg(t({
|
|
@@ -8493,7 +8688,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8493
8688
|
},
|
|
8494
8689
|
space: spaceParam
|
|
8495
8690
|
},
|
|
8496
|
-
buildScript: (args) => `${useSpace(str(args.space, cfg.
|
|
8691
|
+
buildScript: (args) => `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}await page.locator(${j(str(args.selector, ""))}).fill(${j(str(args.text, ""))})\nconst pginfo = await page.info()\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, page: pginfo }))\n`
|
|
8497
8692
|
}));
|
|
8498
8693
|
reg(t({
|
|
8499
8694
|
name: "bcdp_js",
|
|
@@ -8506,7 +8701,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8506
8701
|
},
|
|
8507
8702
|
space: spaceParam
|
|
8508
8703
|
},
|
|
8509
|
-
buildScript: (args) => `${useSpace(str(args.space, cfg.
|
|
8704
|
+
buildScript: (args) => `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}${SAFE_FN}const result = await page.evaluate(${j(safeEvalWrap(str(args.expression, "")))})\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, result: safe(result) }))\n`
|
|
8510
8705
|
}));
|
|
8511
8706
|
reg(t({
|
|
8512
8707
|
name: "bcdp_cdp",
|
|
@@ -8527,7 +8722,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8527
8722
|
buildScript: (args) => {
|
|
8528
8723
|
const params = args.params;
|
|
8529
8724
|
const call = params !== void 0 && params !== null ? `await cdp(${j(str(args.method, ""))}, ${j(params)})` : `await cdp(${j(str(args.method, ""))})`;
|
|
8530
|
-
return `${useSpace(str(args.space, cfg.
|
|
8725
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}${SAFE_FN}const result = ${call}\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, result: safe(result) }))\n`;
|
|
8531
8726
|
}
|
|
8532
8727
|
}));
|
|
8533
8728
|
reg(t({
|
|
@@ -8548,95 +8743,147 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8548
8743
|
const sel = str(args.selector, "");
|
|
8549
8744
|
const pth = str(args.path, "");
|
|
8550
8745
|
const shot = sel !== "" ? `await page.locator(${j(sel)}).screenshot(${pth ? `{ path: ${j(pth)} }` : ""})` : `await page.screenshot(${pth ? `{ path: ${j(pth)} }` : ""})`;
|
|
8551
|
-
return `${useSpace(str(args.space, cfg.
|
|
8746
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}const path = ${shot}\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, path }))\n`;
|
|
8552
8747
|
}
|
|
8553
8748
|
}));
|
|
8554
8749
|
reg(t({
|
|
8555
8750
|
name: "bcdp_page_info",
|
|
8556
|
-
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`
|
|
8751
|
+
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).",
|
|
8557
8752
|
parameters: { space: spaceParam },
|
|
8558
|
-
buildScript: (args) => `${useSpace(str(args.space, cfg.
|
|
8559
|
-
}));
|
|
8560
|
-
reg(t({
|
|
8561
|
-
name: "bcdp_wait",
|
|
8562
|
-
description: "Pause for a fixed number of milliseconds (e.g. for animations or partial loads). For load waits prefer bcdp_navigate's wait option.",
|
|
8563
|
-
parameters: { ms: {
|
|
8564
|
-
type: "number",
|
|
8565
|
-
required: true,
|
|
8566
|
-
description: "Milliseconds to wait."
|
|
8567
|
-
} },
|
|
8568
|
-
buildScript: (args) => `await page.waitForTimeout(${Math.max(0, num(args.ms, 1e3))})\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, waitedMs: ${Math.max(0, num(args.ms, 1e3))} }))\n`
|
|
8753
|
+
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`
|
|
8569
8754
|
}));
|
|
8570
8755
|
reg(t({
|
|
8571
|
-
name: "
|
|
8572
|
-
description: "
|
|
8756
|
+
name: "bcdp_tab",
|
|
8757
|
+
description: "Manage tabs: op=list|current|new|switch|close. new opens/reuses a tab at url; switch/close take a `target` (targetId or URL substring). Will not close the last tab.",
|
|
8573
8758
|
parameters: {
|
|
8574
|
-
|
|
8759
|
+
op: {
|
|
8575
8760
|
type: "string",
|
|
8576
8761
|
required: true,
|
|
8577
|
-
description: "
|
|
8762
|
+
description: "\"list\" | \"current\" | \"new\" | \"switch\" | \"close\"."
|
|
8578
8763
|
},
|
|
8579
|
-
|
|
8764
|
+
url: {
|
|
8580
8765
|
type: "string",
|
|
8581
|
-
description: "
|
|
8766
|
+
description: "Absolute URL for op=new (reuses a matching tab)."
|
|
8767
|
+
},
|
|
8768
|
+
target: {
|
|
8769
|
+
type: "string",
|
|
8770
|
+
description: "targetId or URL substring for switch / close."
|
|
8771
|
+
},
|
|
8772
|
+
wait: {
|
|
8773
|
+
type: "boolean",
|
|
8774
|
+
description: "op=new: wait for load (default true)."
|
|
8582
8775
|
},
|
|
8583
8776
|
timeout: {
|
|
8584
8777
|
type: "number",
|
|
8585
|
-
description: "
|
|
8778
|
+
description: "op=new: load timeout ms (default 20000)."
|
|
8586
8779
|
},
|
|
8587
8780
|
space: spaceParam
|
|
8588
8781
|
},
|
|
8589
8782
|
buildScript: (args) => {
|
|
8590
|
-
const
|
|
8591
|
-
|
|
8592
|
-
|
|
8783
|
+
const send = (expr) => `console.log('${SENTINEL}' + JSON.stringify(${expr}))\n`;
|
|
8784
|
+
const op = str(args.op, "").trim();
|
|
8785
|
+
const head = useSpace(str(args.space, cfg.activeSpace));
|
|
8786
|
+
if (op === "list") return head + `const __tabs = await browser.listTabs()\n` + send(`{ ok: true, tabs: __tabs.map(t => ({ targetId: t.targetId, title: t.title, url: t.url, active: !!t.active, index: t.index })) }`);
|
|
8787
|
+
if (op === "current") return head + `const __cur = await browser.currentTab()\n` + send(`{ ok: true, tab: __cur }`);
|
|
8788
|
+
if (op === "new") {
|
|
8789
|
+
const u = str(args.url, "");
|
|
8790
|
+
if (u === "") return send(`{ ok: false, reason: 'bcdp_tab: url is required for op=new' }`);
|
|
8791
|
+
return head + `const __t = await browser.openOrReuseTab(${j(u)}, { wait: ${bool(args.wait, true)}, timeout: ${num(args.timeout, 2e4)} })\n` + send(`{ ok: true, tab: __t }`);
|
|
8792
|
+
}
|
|
8793
|
+
if (op === "switch" || op === "close") {
|
|
8794
|
+
const t$1 = str(args.target, "");
|
|
8795
|
+
if (t$1 === "") return send(`{ ok: false, reason: ${j("bcdp_tab: target (targetId or URL substring) is required for op=" + op)} }`);
|
|
8796
|
+
const find = `const __tabs = await browser.listTabs()\nconst __t = __tabs.find(x => x.targetId === ${j(t$1)}) ?? __tabs.find(x => (x.url || '').includes(${j(t$1)}))\n`;
|
|
8797
|
+
if (op === "switch") return head + find + `if (!__t) { ${send(`{ ok: false, reason: 'bcdp_tab: no tab matches switch target ' + ${j(t$1)} }`)} }\nelse { await browser.switchTab(__t.targetId); const pginfo = await page.info(); ${send(`{ ok: true, tab: { ...__t, active: true }, page: pginfo }`)} }\n`;
|
|
8798
|
+
return head + find + `if (!__t) { ${send(`{ ok: false, reason: 'bcdp_tab: no tab matches close target ' + ${j(t$1)} }`)} }\nelse if (__tabs.length <= 1) { ${send(`{ ok: false, reason: 'refusing to close the last tab: open another tab first' }`)} }\nelse { const __closed = await browser.closeTab(__t.targetId); const __after = await browser.listTabs(); ${send(`{ ok: true, closed: __closed, count: __after.length, tabs: __after.map(t => ({ targetId: t.targetId, url: t.url, active: !!t.active })) }`)} }\n`;
|
|
8799
|
+
}
|
|
8800
|
+
return send(`{ ok: false, reason: ${j("bcdp_tab: op must be one of list|current|new|switch|close")} }`);
|
|
8593
8801
|
}
|
|
8594
8802
|
}));
|
|
8595
8803
|
reg(t({
|
|
8596
|
-
name: "
|
|
8597
|
-
description: "Wait
|
|
8804
|
+
name: "bcdp_wait",
|
|
8805
|
+
description: "Wait. op=duration (fixed ms) | selector (element appears/disappears) | url (navigation) | response (network reply) | load (page load state) | function (in-page expression becomes truthy) | request (network request) | event (a download). selector takes `selector` + optional `state` (visible|attached|hidden|detached); url takes `pattern`; response takes `url` + optional `body` (none|text|json); load takes `state` (load|domcontentloaded|networkidle); function takes `expression`; request takes `url`. `timeout` in ms (default 10000; page-level ops load/function/request/event default 30000). Every op except duration accepts `space`.",
|
|
8598
8806
|
parameters: {
|
|
8599
|
-
|
|
8807
|
+
op: {
|
|
8600
8808
|
type: "string",
|
|
8601
8809
|
required: true,
|
|
8602
|
-
description: "
|
|
8810
|
+
description: "\"duration\" | \"selector\" | \"url\" | \"response\" | \"load\" | \"function\" | \"request\" | \"event\"."
|
|
8603
8811
|
},
|
|
8604
|
-
|
|
8812
|
+
ms: {
|
|
8605
8813
|
type: "number",
|
|
8606
|
-
description: "
|
|
8814
|
+
description: "op=duration: milliseconds to wait (default 1000)."
|
|
8607
8815
|
},
|
|
8608
|
-
|
|
8609
|
-
},
|
|
8610
|
-
buildScript: (args) => {
|
|
8611
|
-
const p = str(args.pattern, "").trim();
|
|
8612
|
-
if (p === "") return `console.log('${SENTINEL}' + JSON.stringify({ ok: false, reached: false, reason: 'bcdp_wait_for_url: pattern is required' }))\n`;
|
|
8613
|
-
return `${useSpace(str(args.space, cfg.defaultSpace))}${ensureRealTab()}const __ok = await page.waitForURL(${j(p)}, { timeout: ${num(args.timeout, 1e4)} }).catch(() => false)\nconst __u = await page.url()\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: !!__ok, reached: !!__ok, url: __u }))\n`;
|
|
8614
|
-
}
|
|
8615
|
-
}));
|
|
8616
|
-
reg(t({
|
|
8617
|
-
name: "bcdp_wait_for_response",
|
|
8618
|
-
description: "Wait for a network response matching a URL/glob/regex and return it; optionally return the body (text or JSON).",
|
|
8619
|
-
parameters: {
|
|
8620
|
-
url: {
|
|
8816
|
+
selector: {
|
|
8621
8817
|
type: "string",
|
|
8622
|
-
|
|
8623
|
-
description: "URL/glob/regex, e.g. '/api/search' or 'https://*.com/data'."
|
|
8818
|
+
description: "op=selector: CSS selector to wait for, e.g. '.results' or '[data-id=done]'."
|
|
8624
8819
|
},
|
|
8625
|
-
|
|
8626
|
-
type: "
|
|
8627
|
-
description: "
|
|
8820
|
+
state: {
|
|
8821
|
+
type: "string",
|
|
8822
|
+
description: "op=selector: \"visible\" (default) | \"attached\" | \"hidden\" | \"detached\". op=load: \"load\" (default) | \"domcontentloaded\" | \"networkidle\"."
|
|
8823
|
+
},
|
|
8824
|
+
pattern: {
|
|
8825
|
+
type: "string",
|
|
8826
|
+
description: "op=url: URL/glob to match (e.g. '/login?done', 'https://*/post/*', or a /regex/)."
|
|
8827
|
+
},
|
|
8828
|
+
url: {
|
|
8829
|
+
type: "string",
|
|
8830
|
+
description: "op=response: URL/glob/regex, e.g. '/api/search'. op=request: URL substring / glob / regex."
|
|
8628
8831
|
},
|
|
8629
8832
|
body: {
|
|
8630
8833
|
type: "string",
|
|
8631
|
-
description: "'none' (default) | 'text' | 'json'."
|
|
8834
|
+
description: "op=response: 'none' (default) | 'text' | 'json'."
|
|
8835
|
+
},
|
|
8836
|
+
expression: {
|
|
8837
|
+
type: "string",
|
|
8838
|
+
description: "op=function: in-page JS expression evaluated until truthy."
|
|
8839
|
+
},
|
|
8840
|
+
timeout: {
|
|
8841
|
+
type: "number",
|
|
8842
|
+
description: "Wait in ms (default 10000; page-level ops default 30000)."
|
|
8632
8843
|
},
|
|
8633
8844
|
space: spaceParam
|
|
8634
8845
|
},
|
|
8635
8846
|
buildScript: (args) => {
|
|
8636
|
-
const
|
|
8637
|
-
const
|
|
8638
|
-
const
|
|
8639
|
-
|
|
8847
|
+
const send = (expr) => `console.log('${SENTINEL}' + JSON.stringify(${expr}))\n`;
|
|
8848
|
+
const op = str(args.op, "").trim();
|
|
8849
|
+
const asked = num(args.timeout, 0);
|
|
8850
|
+
const to = asked > 0 ? asked : 1e4;
|
|
8851
|
+
const pageTo = asked > 0 ? asked : 3e4;
|
|
8852
|
+
const head = `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}`;
|
|
8853
|
+
if (op === "duration") {
|
|
8854
|
+
const ms = Math.max(0, num(args.ms, 1e3));
|
|
8855
|
+
return `await page.waitForTimeout(${ms})\n` + send(`{ ok: true, op: 'duration', waitedMs: ${ms} }`);
|
|
8856
|
+
}
|
|
8857
|
+
if (op === "selector") {
|
|
8858
|
+
const sel = str(args.selector, "").trim();
|
|
8859
|
+
if (sel === "") return send(`{ ok: false, op: 'selector', waited: false, reason: 'bcdp_wait: selector is required for op=selector' }`);
|
|
8860
|
+
return head + `await page.waitForSelector(${j(sel)}, { state: ${j(str(args.state, "visible"))}, timeout: ${to} })\n` + send(`{ ok: true, op: 'selector', waited: true, selector: ${j(sel)}, state: ${j(str(args.state, "visible"))} }`);
|
|
8861
|
+
}
|
|
8862
|
+
if (op === "url") {
|
|
8863
|
+
const p = str(args.pattern, "").trim();
|
|
8864
|
+
if (p === "") return send(`{ ok: false, op: 'url', reached: false, reason: 'bcdp_wait: pattern is required for op=url' }`);
|
|
8865
|
+
return head + `const __ok = await page.waitForURL(${j(p)}, { timeout: ${to} }).catch(() => false)\nconst __u = await page.url()\n` + send(`{ ok: !!__ok, op: 'url', reached: !!__ok, url: __u }`);
|
|
8866
|
+
}
|
|
8867
|
+
if (op === "response") {
|
|
8868
|
+
const u = str(args.url, "").trim();
|
|
8869
|
+
if (u === "") return send(`{ ok: false, op: 'response', reason: 'bcdp_wait: url is required for op=response' }`);
|
|
8870
|
+
const mode = str(args.body, "none");
|
|
8871
|
+
const wantBody = mode === "text" || mode === "json";
|
|
8872
|
+
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" : ""} }`);
|
|
8873
|
+
}
|
|
8874
|
+
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' }`);
|
|
8875
|
+
if (op === "function") {
|
|
8876
|
+
const expr = str(args.expression, "").trim();
|
|
8877
|
+
if (expr === "") return send(`{ ok: false, op: 'function', reason: 'bcdp_wait: expression is required for op=function' }`);
|
|
8878
|
+
return head + `const __v = await page.waitForFunction(${j(safeEvalWrap(expr, true))}, undefined, { timeout: ${pageTo} })\n` + send(`{ ok: !!__v, op: 'function', value: __v === false ? null : __v, reason: __v === false ? 'timed out: expression never became truthy within ${pageTo}ms' : null }`);
|
|
8879
|
+
}
|
|
8880
|
+
if (op === "request") {
|
|
8881
|
+
const u = str(args.url, "").trim();
|
|
8882
|
+
if (u === "") return send(`{ ok: false, op: 'request', reason: 'bcdp_wait: url is required for op=request' }`);
|
|
8883
|
+
return head + `try { const __req = await page.waitForRequest(${j(u)}, { timeout: ${pageTo} })\n` + send(`{ ok: true, op: 'request', url: __req.url(), method: __req.method() }`) + `} catch (e) { ${send(`{ ok: false, op: 'request', reason: String(e && e.message || e) }`)} }\n`;
|
|
8884
|
+
}
|
|
8885
|
+
if (op === "event") return head + `try { const __ev = await page.waitForEvent('download', { timeout: ${pageTo} })\nconst __p = await __ev.path().catch(() => null)\n` + send(`{ ok: true, op: 'event', event: 'download', suggestedFilename: __ev.suggestedFilename(), url: __ev.url(), path: __p }`) + `} catch (e) { ${send(`{ ok: false, op: 'event', reason: String(e && e.message || e) }`)} }\n`;
|
|
8886
|
+
return send(`{ ok: false, reason: ${j("bcdp_wait: op must be one of duration|selector|url|response|load|function|request|event")} }`);
|
|
8640
8887
|
}
|
|
8641
8888
|
}));
|
|
8642
8889
|
reg(t({
|
|
@@ -8651,14 +8898,21 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8651
8898
|
type: "string",
|
|
8652
8899
|
description: "Type this text instead (keyboard.type)."
|
|
8653
8900
|
},
|
|
8901
|
+
via: {
|
|
8902
|
+
type: "string",
|
|
8903
|
+
description: "text mode: 'type' (default, per-character) | 'insert' (keyboard.insertText, faster for long strings)."
|
|
8904
|
+
},
|
|
8654
8905
|
space: spaceParam
|
|
8655
8906
|
},
|
|
8656
8907
|
buildScript: (args) => {
|
|
8657
8908
|
const txt = str(args.text, "");
|
|
8658
8909
|
const k = str(args.key, "").trim();
|
|
8659
|
-
if (txt !== "")
|
|
8910
|
+
if (txt !== "") {
|
|
8911
|
+
const method = str(args.via, "type") === "insert" ? "insertText" : "type";
|
|
8912
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}await page.keyboard.${method}(${j(txt)})\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, typed: ${j(txt)} }))\n`;
|
|
8913
|
+
}
|
|
8660
8914
|
if (k === "") return `console.log('${SENTINEL}' + JSON.stringify({ ok: false, reason: 'bcdp_key: provide key or text to type' }))\n`;
|
|
8661
|
-
return `${useSpace(str(args.space, cfg.
|
|
8915
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}await page.keyboard.press(${j(k)})\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, key: ${j(k)} }))\n`;
|
|
8662
8916
|
}
|
|
8663
8917
|
}));
|
|
8664
8918
|
reg(t({
|
|
@@ -8683,7 +8937,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8683
8937
|
const sel = str(args.selector, "");
|
|
8684
8938
|
const hasXY = typeof args.x === "number" && typeof args.y === "number";
|
|
8685
8939
|
if (sel === "" && !hasXY) return `console.log('${SENTINEL}' + JSON.stringify({ ok: false, reason: 'bcdp_hover: provide selector or both x and y' }))\n`;
|
|
8686
|
-
return `${useSpace(str(args.space, cfg.
|
|
8940
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}` + (sel !== "" ? `await page.locator(${j(sel)}).hover()\n` : `await page.mouse.move(${args.x}, ${args.y})\n`) + `console.log('${SENTINEL}' + JSON.stringify({ ok: true }))\n`;
|
|
8687
8941
|
}
|
|
8688
8942
|
}));
|
|
8689
8943
|
reg(t({
|
|
@@ -8732,7 +8986,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8732
8986
|
break;
|
|
8733
8987
|
default: expr = `await ${selExpr}.textContent()`;
|
|
8734
8988
|
}
|
|
8735
|
-
return `${useSpace(str(args.space, cfg.
|
|
8989
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}${SAFE_FN}const __v = ${expr}\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, what: ${j(what)}, selector: ${j(sel)}, value: safe(__v) }))\n`;
|
|
8736
8990
|
}
|
|
8737
8991
|
}));
|
|
8738
8992
|
reg(t({
|
|
@@ -8750,7 +9004,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8750
9004
|
},
|
|
8751
9005
|
space: spaceParam
|
|
8752
9006
|
},
|
|
8753
|
-
buildScript: (args) => `${useSpace(str(args.space, cfg.
|
|
9007
|
+
buildScript: (args) => `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}await page.locator(${j(str(args.selector, ""))}).selectOption(${j(args.value ?? "")})\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, select: ${j(str(args.selector, ""))} }))\n`
|
|
8754
9008
|
}));
|
|
8755
9009
|
reg(t({
|
|
8756
9010
|
name: "bcdp_drag",
|
|
@@ -8776,7 +9030,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8776
9030
|
const hasEl = str(args.from, "") !== "" && str(args.to, "") !== "";
|
|
8777
9031
|
if (!hasEl && pts.length < 4) return `console.log('${SENTINEL}' + JSON.stringify({ ok: false, reason: 'bcdp_drag: provide from+to selectors, or at least 4 points (x1,y1,x2,y2)' }))\n`;
|
|
8778
9032
|
const action = hasEl ? `await page.locator(${j(str(args.from, ""))}).dragTo(page.locator(${j(str(args.to, ""))}))\n` : `const __pts = ${j(pts)}\nconst __coords=[];for(let __i=0;__i<__pts.length;__i+=2){__coords.push([__pts[__i],__pts[__i+1]])}\nawait page.mouse.drag(__coords)\n`;
|
|
8779
|
-
return `${useSpace(str(args.space, cfg.
|
|
9033
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}` + action + `console.log('${SENTINEL}' + JSON.stringify({ ok: true }))\n`;
|
|
8780
9034
|
}
|
|
8781
9035
|
}));
|
|
8782
9036
|
reg(t({
|
|
@@ -8802,7 +9056,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8802
9056
|
const hasDelta = Number.isFinite(args.deltaX) || Number.isFinite(args.deltaY);
|
|
8803
9057
|
if (!hasSelector && !hasDelta) return `console.log('${SENTINEL}' + JSON.stringify({ ok: false, reason: 'bcdp_scroll: provide deltaX/deltaY or a selector' }))\n`;
|
|
8804
9058
|
const action = hasSelector ? `await page.locator(${j(str(args.selector, ""))}).scrollIntoViewIfNeeded()\n` : `await page.mouse.wheel(${num(args.deltaX, 0)}, ${num(args.deltaY, 300)})\n`;
|
|
8805
|
-
return `${useSpace(str(args.space, cfg.
|
|
9059
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}` + action + `const __p = await page.info()\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, scrollX: __p.sx ?? null, scrollY: __p.sy ?? null }))\n`;
|
|
8806
9060
|
}
|
|
8807
9061
|
}));
|
|
8808
9062
|
reg(t({
|
|
@@ -8821,7 +9075,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8821
9075
|
},
|
|
8822
9076
|
space: spaceParam
|
|
8823
9077
|
},
|
|
8824
|
-
buildScript: (args) => `${useSpace(str(args.space, cfg.
|
|
9078
|
+
buildScript: (args) => `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}await page.locator(${j(str(args.selector, ""))}).setInputFiles(${j(str(args.path, ""))})\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, upload: ${j(str(args.selector, ""))} }))\n`
|
|
8825
9079
|
}));
|
|
8826
9080
|
reg(t({
|
|
8827
9081
|
name: "bcdp_download",
|
|
@@ -8845,15 +9099,15 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8845
9099
|
},
|
|
8846
9100
|
space: spaceParam
|
|
8847
9101
|
},
|
|
8848
|
-
gate: () => defaultAttachCache.get().engine === "lightpanda" ? "engine-unsupported: the attached browser is Lightpanda, which has no Page download events
|
|
9102
|
+
gate: () => defaultAttachCache.get().engine === "lightpanda" ? "engine-unsupported: the attached browser is Lightpanda, which has no Page download events �?bcdp_download cannot capture files on this engine. Trigger the download another way (e.g. fetch() the URL in-page and return the bytes)." : null,
|
|
8849
9103
|
buildScript: (args) => {
|
|
8850
9104
|
const sel = str(args.triggerSelector, "");
|
|
8851
9105
|
const script = str(args.triggerScript, "");
|
|
8852
9106
|
const savePath = str(args.savePath, "");
|
|
8853
9107
|
const timeout = num(args.timeout, 3e4);
|
|
8854
|
-
const trigger = sel !== "" ? `await page.locator(${j(sel)}).click()\n` : script !== "" ? `await page.evaluate(() => { ${script} })\n` : "/* no trigger given
|
|
9108
|
+
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";
|
|
8855
9109
|
const save = savePath !== "" ? `const __final = await __dl.saveAs(${j(savePath)}).catch(()=>null)\n` : `const __final = await __dl.path().catch(()=>null)\n`;
|
|
8856
|
-
return `${useSpace(str(args.space, cfg.
|
|
9110
|
+
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`;
|
|
8857
9111
|
}
|
|
8858
9112
|
}));
|
|
8859
9113
|
reg(t({
|
|
@@ -8873,7 +9127,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8873
9127
|
},
|
|
8874
9128
|
buildScript: (args) => {
|
|
8875
9129
|
const chk = bool(args.checked, true);
|
|
8876
|
-
return `${useSpace(str(args.space, cfg.
|
|
9130
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}await page.locator(${j(str(args.selector, ""))}).${chk ? "check" : "uncheck"}()\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, checked: ${chk} }))\n`;
|
|
8877
9131
|
}
|
|
8878
9132
|
}));
|
|
8879
9133
|
reg(t({
|
|
@@ -8894,7 +9148,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8894
9148
|
const accept = bool(args.accept, true);
|
|
8895
9149
|
const text = str(args.text, "");
|
|
8896
9150
|
const params = `{ accept: ${accept}${text !== "" ? `, promptText: ${j(text)}` : ""} }`;
|
|
8897
|
-
return `${useSpace(str(args.space, cfg.
|
|
9151
|
+
return `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}const __r = await cdp("Page.handleJavaScriptDialog", ${params}).catch((e) => ({ error: String(e) }))\nconst __ok = !!(__r && !__r.error)\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, handled: __ok, accept: ${accept}, error: __r?.error ?? null }))\n`;
|
|
8898
9152
|
}
|
|
8899
9153
|
}));
|
|
8900
9154
|
reg(t({
|
|
@@ -8943,69 +9197,15 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8943
9197
|
const mode = str(args.mode, "browser");
|
|
8944
9198
|
const cred = str(args.credentials, "");
|
|
8945
9199
|
if (mode !== "server" && (cred === "include" || cred === "omit" || cred === "same-origin")) opts.credentials = cred;
|
|
8946
|
-
return `${mode === "server" ? "" : `${useSpace(str(args.space, cfg.
|
|
9200
|
+
return `${mode === "server" ? "" : `${useSpace(str(args.space, cfg.activeSpace))}${ensureRealTab()}`}${SAFE_FN}const __r = await fetch.${mode === "server" ? "server" : "browser"}(${j(str(args.url, ""))}, ${j(opts)})\nconst __status = typeof __r.status !== "undefined" ? __r.status : 200\nlet __body = null\ntry { __body = typeof __r.text === "function" ? await __r.text() : (typeof __r === "string" ? __r : JSON.stringify(safe(__r))) } catch { __body = null }\nconsole.log('${SENTINEL}' + JSON.stringify({ ok: true, mode: ${j(mode)}, status: __status, body: __body, url: ${j(str(args.url, ""))} }))\n`;
|
|
8947
9201
|
}
|
|
8948
9202
|
}));
|
|
8949
|
-
reg((() => {
|
|
8950
|
-
return defineTool({
|
|
8951
|
-
name: "bcdp_cli",
|
|
8952
|
-
description: "Escape hatch: run an arbitrary `ego-browser nodejs` heredoc script VERBATIM (facades page/browser/taskSpaces/site/fetch and the raw cdp() are preloaded; no preamble is added, so select the task space yourself before touching page.*). Use when the structured bcdp_* tools do not cover the task. Returns the raw output plus the parsed console.log payload when present.",
|
|
8953
|
-
parameters: { script: {
|
|
8954
|
-
type: "string",
|
|
8955
|
-
required: true,
|
|
8956
|
-
description: "Full JS script body for the heredoc; ego-browser helpers are preloaded. Runs verbatim — call `await taskSpaces.useOrCreate(name)` first if your script uses page.*. End with console.log(JSON.stringify(payload)) to get it back as `result`."
|
|
8957
|
-
} },
|
|
8958
|
-
output: {
|
|
8959
|
-
schema: {
|
|
8960
|
-
type: "object",
|
|
8961
|
-
additionalProperties: false,
|
|
8962
|
-
properties: {
|
|
8963
|
-
ok: {
|
|
8964
|
-
type: "boolean",
|
|
8965
|
-
required: true
|
|
8966
|
-
},
|
|
8967
|
-
stdout: {
|
|
8968
|
-
type: "string",
|
|
8969
|
-
required: true
|
|
8970
|
-
},
|
|
8971
|
-
stderr: { type: "string" },
|
|
8972
|
-
output: {
|
|
8973
|
-
type: "string",
|
|
8974
|
-
description: "Merged stdout+stderr text of the CLI run. The ego CLI writes script output to stderr on Windows, so read this when `stdout` looks empty."
|
|
8975
|
-
},
|
|
8976
|
-
result: { type: "json" }
|
|
8977
|
-
}
|
|
8978
|
-
},
|
|
8979
|
-
render: renderText
|
|
8980
|
-
},
|
|
8981
|
-
timeoutMs: TOOL_TIMEOUT_MS,
|
|
8982
|
-
execute: async (args, exec) => {
|
|
8983
|
-
markEgoToolCall(callingSessionId(exec));
|
|
8984
|
-
const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => str(args.script, ""));
|
|
8985
|
-
if (!result.ok) throw new Error(result.error);
|
|
8986
|
-
const parsed = parseSentinel(mergeCliOutput(result));
|
|
8987
|
-
return {
|
|
8988
|
-
ok: true,
|
|
8989
|
-
stdout: result.stdout,
|
|
8990
|
-
stderr: result.stderr,
|
|
8991
|
-
output: mergeCliOutput(result),
|
|
8992
|
-
result: parsed ?? null
|
|
8993
|
-
};
|
|
8994
|
-
},
|
|
8995
|
-
presentCall: () => ({
|
|
8996
|
-
card: "generic",
|
|
8997
|
-
title: "bcdp_cli",
|
|
8998
|
-
kind: "other",
|
|
8999
|
-
rawInput: null
|
|
9000
|
-
})
|
|
9001
|
-
});
|
|
9002
|
-
})());
|
|
9003
9203
|
}
|
|
9004
9204
|
/** Register bcdp_help / bcdp_doctor / bcdp_script. */
|
|
9005
9205
|
function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
9006
9206
|
reg(defineTool({
|
|
9007
9207
|
name: "bcdp_captcha",
|
|
9008
|
-
description: "Check the current page for a human-verification (CAPTCHA) challenge
|
|
9208
|
+
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.",
|
|
9009
9209
|
parameters: { space: {
|
|
9010
9210
|
type: "string",
|
|
9011
9211
|
description: "Task-space name or numeric id; defaults to the configured defaultSpace."
|
|
@@ -9032,8 +9232,9 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9032
9232
|
},
|
|
9033
9233
|
timeoutMs: 15e3,
|
|
9034
9234
|
execute: async (args, exec) => withEgoLock(async () => {
|
|
9235
|
+
cfg.spaceTracker.setCurrentSession(callingSessionId(exec));
|
|
9035
9236
|
markEgoToolCall(callingSessionId(exec));
|
|
9036
|
-
const result = await runWithStaleSpaceRetry(ctx, cfg, { signal: exec?.signal }, () => humanCheckScript(str(args.space, cfg.
|
|
9237
|
+
const result = await runWithStaleSpaceRetry(ctx, cfg, { signal: exec?.signal }, () => humanCheckScript(str(args.space, cfg.activeSpace)));
|
|
9037
9238
|
if (!result.ok) return {
|
|
9038
9239
|
ok: false,
|
|
9039
9240
|
detected: false,
|
|
@@ -9091,7 +9292,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9091
9292
|
tiers.pulse();
|
|
9092
9293
|
const q = str(args.topic, "").trim().toLowerCase();
|
|
9093
9294
|
const key = Object.prototype.hasOwnProperty.call(EGO_HELP_INDEX, q) ? q : "";
|
|
9094
|
-
const text = key ? EGO_HELP_INDEX[key] : q ?
|
|
9295
|
+
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;
|
|
9095
9296
|
return {
|
|
9096
9297
|
ok: true,
|
|
9097
9298
|
topic: q || "overview",
|
|
@@ -9136,7 +9337,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9136
9337
|
jevKey: cfg.jevKey,
|
|
9137
9338
|
layaKey: cfg.layaKey
|
|
9138
9339
|
});
|
|
9139
|
-
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"}
|
|
9340
|
+
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}`);
|
|
9140
9341
|
}
|
|
9141
9342
|
lines.push(`egoBin: ${cfg.egoBin}`);
|
|
9142
9343
|
try {
|
|
@@ -9147,7 +9348,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9147
9348
|
const chrome = findChromeBinary();
|
|
9148
9349
|
const configured = cfg.chromePath;
|
|
9149
9350
|
if (configured) lines.push(`browser binary: ${configured} (from settings)`);
|
|
9150
|
-
else lines.push(`browser binary: ${chrome || "(none found
|
|
9351
|
+
else lines.push(`browser binary: ${chrome || "(none found �?set chromePath in settings, or set EGO_LINUX_CHROME, or install Chrome/Edge/Brave)"}`);
|
|
9151
9352
|
const cliArgs = filterArgs(cfg.runtimeArgs ?? "", EGO_CLI_BLOCKED);
|
|
9152
9353
|
const chrArgs = filterArgs(cfg.chromeArgs ?? "", CHROME_BLOCKED);
|
|
9153
9354
|
lines.push(`runtimeArgs (effective): ${cliArgs.length ? cliArgs.join(" ") : "(none)"}`);
|
|
@@ -9156,13 +9357,13 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9156
9357
|
lines.push(`attach: ${attachNow.status}${attachNow.endpointSource ? ` (source: ${attachNow.endpointSource})` : ""}${attachNow.endpoint ? ` @ ${attachNow.endpoint}` : ""}`);
|
|
9157
9358
|
if (attachNow.engine !== void 0) lines.push(`engine: ${attachNow.engine}`);
|
|
9158
9359
|
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");
|
|
9159
|
-
if (attachNow.engine === "lightpanda" || process.platform === "win32") lines.push(process.platform === "win32" ? "lightpanda on win32: no native build
|
|
9360
|
+
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`.");
|
|
9160
9361
|
const kindCount = (kind) => cfg.links.filter((link) => link.kind === kind).length;
|
|
9161
9362
|
const dropped = cfg.droppedEgoCli;
|
|
9162
|
-
lines.push(`links: ${cfg.links.length} (cdp ${kindCount("cdp")}, ego-cli ${kindCount(EGO_CLI_KIND)}, lightpanda ${kindCount(LP_KIND)})${dropped > 0 ? `
|
|
9363
|
+
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)` : ""}`);
|
|
9163
9364
|
if (kindCount(LP_KIND) > 0) {
|
|
9164
9365
|
const lpRow = cfg.links.find((link) => link.kind === LP_KIND);
|
|
9165
|
-
lines.push(`lightpanda row: servePath=${lpRow?.servePath === void 0 || lpRow.servePath === "" ? "(auto: PATH
|
|
9366
|
+
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`);
|
|
9166
9367
|
}
|
|
9167
9368
|
const cliLink = cfg.links.find((link) => link.kind === EGO_CLI_KIND);
|
|
9168
9369
|
if (cliLink && cliLink.kind === EGO_CLI_KIND) {
|
|
@@ -9170,13 +9371,13 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9170
9371
|
cliPath: cliLink.cliPath,
|
|
9171
9372
|
bundled: VENDORED_EGO_BIN
|
|
9172
9373
|
}, createSubprocessCliIo(ctx.subprocess));
|
|
9173
|
-
lines.push(resolved.ok ? `cli: ${resolved.path} (${resolved.origin}${attachNow.cliShape ? `, shape ${attachNow.cliShape}` : ""})` : `cli: (missing)
|
|
9374
|
+
lines.push(resolved.ok ? `cli: ${resolved.path} (${resolved.origin}${attachNow.cliShape ? `, shape ${attachNow.cliShape}` : ""})` : `cli: (missing) �?${resolved.message}`);
|
|
9174
9375
|
}
|
|
9175
9376
|
const toolCount = ((EGO_HELP_INDEX["tools"] ?? "").match(/bcdp_/g) ?? []).length;
|
|
9176
9377
|
const legacy = cfg.legacyEgoToolNames === true;
|
|
9177
9378
|
lines.push(`naming: ${toolCount} bcdp_* tools; legacy ego_* aliases ${legacy ? "ON (mutually exclusive with the upstream plugin)" : "OFF (coexists with the upstream plugin)"}`);
|
|
9178
9379
|
const upstream = findUpstreamPluginInstall();
|
|
9179
|
-
if (upstream !== "") lines.push(`conflict: upstream dsh-ego-browser installed at ${upstream}
|
|
9380
|
+
if (upstream !== "") lines.push(`conflict: upstream dsh-ego-browser installed at ${upstream} �?only one plugin should drive the local ego-lite (they would share its task spaces)`);
|
|
9180
9381
|
lines.push(`chromeArgs (effective, next cold start): ${chrArgs.length ? chrArgs.join(" ") : "(none)"}`);
|
|
9181
9382
|
const isWin = process.platform === "win32";
|
|
9182
9383
|
const e = process.env;
|
|
@@ -9184,7 +9385,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9184
9385
|
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`);
|
|
9185
9386
|
lines.push(`state dir: ${stateDir} (exists: ${existsSync(stateDir)})`);
|
|
9186
9387
|
const bjson = `${stateDir}/browser.json`;
|
|
9187
|
-
let browserReport = "browser.json: (none
|
|
9388
|
+
let browserReport = "browser.json: (none �?agent browser not running)";
|
|
9188
9389
|
if (existsSync(bjson)) try {
|
|
9189
9390
|
const { readFile: readFile$1 } = await import("node:fs/promises");
|
|
9190
9391
|
const b = JSON.parse(await readFile$1(bjson, "utf8"));
|
|
@@ -9234,16 +9435,20 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9234
9435
|
reg((() => {
|
|
9235
9436
|
return defineTool({
|
|
9236
9437
|
name: "bcdp_script",
|
|
9237
|
-
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}. Use for a full multi-step browser task as a single script. The task space is selected and a real (non-blank) tab activated for you before your script runs, so page.* works directly.
|
|
9438
|
+
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}. Use for a full multi-step browser task as a single script. 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 to run the body verbatim with no preamble (the retired bcdp_cli behaviour). These scripts expose the vendored SDK (`taskSpaces`, `page.locator()`, global `cdp()`, `fetch.browser|server`) �?NOT the official docs' `taskSpace()` / `page.click()`.",
|
|
9238
9439
|
parameters: {
|
|
9239
9440
|
script: {
|
|
9240
9441
|
type: "string",
|
|
9241
9442
|
required: true,
|
|
9242
|
-
description: "Full JS script body. You may end with console.log(JSON.stringify(payload))
|
|
9443
|
+
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."
|
|
9243
9444
|
},
|
|
9244
9445
|
timeoutMs: {
|
|
9245
9446
|
type: "integer",
|
|
9246
9447
|
description: "Per-run timeout in ms (default plugin grace)."
|
|
9448
|
+
},
|
|
9449
|
+
verbatim: {
|
|
9450
|
+
type: "boolean",
|
|
9451
|
+
description: "Run the body verbatim with NO preamble (no task-space selection, no real-tab activation) — the retired bcdp_cli behaviour. Default false prepends the preamble so page.* works directly. In verbatim mode select the space yourself (`await taskSpaces.useOrCreate(name)`) before touching page.*."
|
|
9247
9452
|
}
|
|
9248
9453
|
},
|
|
9249
9454
|
output: {
|
|
@@ -9274,12 +9479,15 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9274
9479
|
},
|
|
9275
9480
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
9276
9481
|
execute: async (args, exec) => {
|
|
9482
|
+
cfg.spaceTracker.setCurrentSession(callingSessionId(exec));
|
|
9277
9483
|
markEgoToolCall(callingSessionId(exec));
|
|
9278
9484
|
const timeoutMs = typeof args.timeoutMs === "number" && Number.isFinite(args.timeoutMs) && args.timeoutMs > 0 ? args.timeoutMs : void 0;
|
|
9279
9485
|
const start = Date.now();
|
|
9486
|
+
const verbatimMode = bool(args.verbatim, false);
|
|
9280
9487
|
const preamble = (body) => {
|
|
9488
|
+
if (verbatimMode) return body;
|
|
9281
9489
|
if (/taskSpaces\s*\.\s*useOrCreate\s*\(/.test(body)) return body;
|
|
9282
|
-
return `${useSpace(cfg.
|
|
9490
|
+
return `${useSpace(cfg.activeSpace)}${ensureRealTab()}${body}`;
|
|
9283
9491
|
};
|
|
9284
9492
|
const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => preamble(str(args.script, "")), timeoutMs);
|
|
9285
9493
|
const durationMs = Date.now() - start;
|
|
@@ -9287,10 +9495,10 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9287
9495
|
ok: false,
|
|
9288
9496
|
stdout: result.stdout,
|
|
9289
9497
|
stderr: result.stderr,
|
|
9290
|
-
output: mergeCliOutput(result),
|
|
9498
|
+
output: attachSessionHint(mergeCliOutput(result)),
|
|
9291
9499
|
durationMs,
|
|
9292
9500
|
timedOut: false,
|
|
9293
|
-
error: result.error
|
|
9501
|
+
error: attachSessionHint(result.error)
|
|
9294
9502
|
};
|
|
9295
9503
|
const parsed = parseSentinel(mergeCliOutput(result));
|
|
9296
9504
|
return {
|
|
@@ -9335,7 +9543,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9335
9543
|
stepBudget: cfg.jevStepBudget,
|
|
9336
9544
|
wallMs: cfg.jevWallMs
|
|
9337
9545
|
});
|
|
9338
|
-
/** Build the intent from tool args. Hints stay hints
|
|
9546
|
+
/** Build the intent from tool args. Hints stay hints �?never selectors. */
|
|
9339
9547
|
const intentFrom = (args) => {
|
|
9340
9548
|
const hints = str(args.hints, "");
|
|
9341
9549
|
const criteria = str(args.successCriteria, "");
|
|
@@ -9405,6 +9613,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9405
9613
|
},
|
|
9406
9614
|
timeoutMs: 1e4,
|
|
9407
9615
|
execute: async (_args, exec) => {
|
|
9616
|
+
cfg.spaceTracker.setCurrentSession(callingSessionId(exec));
|
|
9408
9617
|
markEgoToolCall(callingSessionId(exec));
|
|
9409
9618
|
const judge = judgeCfg();
|
|
9410
9619
|
const runtime = judgeRuntimeOf();
|
|
@@ -9426,7 +9635,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9426
9635
|
"",
|
|
9427
9636
|
`browser attach : ${attach.wsUrl === "" ? `NOT ATTACHED (status=${attach.status}${attach.code === "" ? "" : `, code=${attach.code}`})` : `${attach.endpoint} (${attach.endpointSource ?? "unknown"})`}`
|
|
9428
9637
|
];
|
|
9429
|
-
if (judge.layaKey === "") lines.push("", "laya has no key, so that hop is SKIPPED
|
|
9638
|
+
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.");
|
|
9430
9639
|
return {
|
|
9431
9640
|
ok: true,
|
|
9432
9641
|
text: lines.join("\n")
|
|
@@ -9504,6 +9713,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9504
9713
|
},
|
|
9505
9714
|
timeoutMs: 6e4,
|
|
9506
9715
|
execute: async (args, exec) => {
|
|
9716
|
+
cfg.spaceTracker.setCurrentSession(callingSessionId(exec));
|
|
9507
9717
|
markEgoToolCall(callingSessionId(exec));
|
|
9508
9718
|
const blocked = attachGate();
|
|
9509
9719
|
if (blocked !== "") return {
|
|
@@ -9576,7 +9786,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9576
9786
|
if (assembland !== null) {
|
|
9577
9787
|
lines.push(`POST : ${assembland.url}`);
|
|
9578
9788
|
lines.push("", "── assembled request body (exactly the three allowed keys) ──", JSON.stringify(assembland.body, null, 2));
|
|
9579
|
-
} else lines.push("", "(no HTTP hop configured
|
|
9789
|
+
} else lines.push("", "(no HTTP hop configured �?only the rule hop is available)");
|
|
9580
9790
|
if (bool(args.dryRun, true)) {
|
|
9581
9791
|
lines.push("", "dryRun: nothing was sent.");
|
|
9582
9792
|
return {
|
|
@@ -9642,6 +9852,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9642
9852
|
},
|
|
9643
9853
|
timeoutMs: 6e4,
|
|
9644
9854
|
execute: async (args, exec) => {
|
|
9855
|
+
cfg.spaceTracker.setCurrentSession(callingSessionId(exec));
|
|
9645
9856
|
markEgoToolCall(callingSessionId(exec));
|
|
9646
9857
|
const blocked = attachGate();
|
|
9647
9858
|
if (blocked !== "") return {
|
|
@@ -9679,13 +9890,13 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9679
9890
|
`budget : ${frame.image === null || frame.image.maxBytes === 0 ? "unbounded" : frame.image.maxBytes + " B"}${frame.image?.overBudget === true ? " *** OVER BUDGET ***" : ""}`,
|
|
9680
9891
|
`candidates : ${frame.dom.nodes.length} of ${frame.dom.total}${frame.dom.truncated ? " (TRUNCATED)" : ""}`
|
|
9681
9892
|
];
|
|
9682
|
-
if (defaultAttachCache.get().engine === "lightpanda") lines.push(`engine : lightpanda (rendering: text
|
|
9893
|
+
if (defaultAttachCache.get().engine === "lightpanda") lines.push(`engine : lightpanda (rendering: text �?screenshot fidelity differs from Chrome)`);
|
|
9683
9894
|
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.");
|
|
9684
9895
|
if (bool(args.showCandidates, true)) {
|
|
9685
9896
|
lines.push("", "── candidates (the judge answers with these numbers) ──");
|
|
9686
9897
|
for (const node of frame.dom.nodes) lines.push(`${node.n}. ${node.role} "${node.name}" [${node.container}]`);
|
|
9687
9898
|
}
|
|
9688
|
-
lines.push("", "note: rects are NOT carried on this path (the AX tree has none)
|
|
9899
|
+
lines.push("", "note: rects are NOT carried on this path (the AX tree has none) �?the executor re-measures before any action.");
|
|
9689
9900
|
return {
|
|
9690
9901
|
ok: true,
|
|
9691
9902
|
text: lines.join("\n")
|
|
@@ -9751,6 +9962,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9751
9962
|
},
|
|
9752
9963
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
9753
9964
|
execute: async (args, exec) => {
|
|
9965
|
+
cfg.spaceTracker.setCurrentSession(callingSessionId(exec));
|
|
9754
9966
|
markEgoToolCall(callingSessionId(exec));
|
|
9755
9967
|
const blocked = attachGate();
|
|
9756
9968
|
if (blocked !== "") return {
|
|
@@ -9848,6 +10060,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9848
10060
|
},
|
|
9849
10061
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
9850
10062
|
execute: async (args, exec) => {
|
|
10063
|
+
cfg.spaceTracker.setCurrentSession(callingSessionId(exec));
|
|
9851
10064
|
markEgoToolCall(callingSessionId(exec));
|
|
9852
10065
|
const blocked = attachGate();
|
|
9853
10066
|
if (blocked !== "") return {
|
|
@@ -9880,7 +10093,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9880
10093
|
const nav = await effects.navigate(url);
|
|
9881
10094
|
if (!nav.ok) return {
|
|
9882
10095
|
ok: false,
|
|
9883
|
-
text: `bcdp_jev_attempt: navigation failed
|
|
10096
|
+
text: `bcdp_jev_attempt: navigation failed �?${nav.error ?? "unknown error"}`
|
|
9884
10097
|
};
|
|
9885
10098
|
const result = await runAttempt({
|
|
9886
10099
|
intent,
|
|
@@ -9892,7 +10105,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9892
10105
|
`reason : ${result.reason}`,
|
|
9893
10106
|
`page : ${result.lastUrl || nav.url}`,
|
|
9894
10107
|
`elapsed : ${Date.now() - started}ms candidates(last round)=${result.candidates}`,
|
|
9895
|
-
`verify via : bcdp_cdp / bcdp_screenshot on targetId=${effects.frames().at(-1)?.target.targetId ?? "unknown"}
|
|
10108
|
+
`verify via : bcdp_cdp / bcdp_screenshot on targetId=${effects.frames().at(-1)?.target.targetId ?? "unknown"} �?the receipt is a report, not a proof`
|
|
9896
10109
|
];
|
|
9897
10110
|
if (effects.lastError() !== "") lines.push(`lastError : ${effects.lastError()}`);
|
|
9898
10111
|
lines.push("", result.actions.length === 0 ? "── actions ── (none)" : "── actions ──");
|
|
@@ -9914,4 +10127,4 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
|
9914
10127
|
}
|
|
9915
10128
|
|
|
9916
10129
|
//#endregion
|
|
9917
|
-
export { Config, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, apply, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, decideCdpAttach, findChromeBinary, findUpstreamPluginInstall, inject, name, parseSentinel, parseStatusFacades, resolveEgoEnv, runWithStaleSpaceRetry, shouldReapBrowser };
|
|
10130
|
+
export { ATTACH_SESSION_HINT, Config, GLOBAL_SESSION_KEY, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, TAB_STUCK_RE, apply, attachSessionHint, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, createSessionSpaceTracker, decideCdpAttach, deriveSlotDefaultName, findChromeBinary, findUpstreamPluginInstall, inject, isTabStuckFailure, name, parseSentinel, parseStatusFacades, resolveEgoEnv, runWithStaleSpaceRetry, runWithTabRevive, shouldReapBrowser };
|