dsh-browser-cdp 0.18.21 → 1.2.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.md +27 -0
- package/bin/cdp-cast-worker.mjs +16 -0
- package/dsh-plugin.json +190 -148
- package/lib/client.js +532 -45
- package/lib/index.js +544 -43
- package/package.json +27 -15
package/lib/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { f as stopLocalBrowser, l as launchLocalBrowser } from "./launcher-BadIUjAx.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
3
4
|
import { constants, createReadStream, createWriteStream, existsSync, readdirSync } from "node:fs";
|
|
4
5
|
import { homedir, tmpdir } from "node:os";
|
|
@@ -1771,9 +1772,23 @@ let lastEgoActivity = 0;
|
|
|
1771
1772
|
function getLastEgoActivity() {
|
|
1772
1773
|
return lastEgoActivity;
|
|
1773
1774
|
}
|
|
1775
|
+
const activityListeners = /* @__PURE__ */ new Set();
|
|
1776
|
+
/**
|
|
1777
|
+
* Subscribe to "one bcdp_* call just landed".
|
|
1778
|
+
* @returns the unsubscribe function.
|
|
1779
|
+
*/
|
|
1780
|
+
function onEgoActivity(cb) {
|
|
1781
|
+
activityListeners.add(cb);
|
|
1782
|
+
return () => {
|
|
1783
|
+
activityListeners.delete(cb);
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1774
1786
|
function markEgoToolCall(sessionId) {
|
|
1775
1787
|
toolCallCount += 1;
|
|
1776
1788
|
lastEgoActivity = Date.now();
|
|
1789
|
+
for (const cb of [...activityListeners]) try {
|
|
1790
|
+
cb();
|
|
1791
|
+
} catch {}
|
|
1777
1792
|
const payload = sessionId === void 0 || sessionId === "" ? { count: toolCallCount } : {
|
|
1778
1793
|
count: toolCallCount,
|
|
1779
1794
|
sessionId
|
|
@@ -2536,6 +2551,7 @@ const cdpMode = z.union([
|
|
|
2536
2551
|
"local",
|
|
2537
2552
|
"remote"
|
|
2538
2553
|
]);
|
|
2554
|
+
const toolInjection = z.union(["lazy", "always"]);
|
|
2539
2555
|
const encoder = z.union([
|
|
2540
2556
|
"auto",
|
|
2541
2557
|
"software",
|
|
@@ -2640,6 +2656,10 @@ const Config$1 = z.object({
|
|
|
2640
2656
|
cursorName: z.string().description("Name label shown in the cursor HUD."),
|
|
2641
2657
|
allowLocalFallback: z.boolean().description("auto mode may fall back to launching a local browser when the activated target is unreachable. Off by default: the fallback must be explicit.").volatile(),
|
|
2642
2658
|
legacyEgoToolNames: z.boolean().description("ALSO register the tools under their old ego_* names for scripts written before the bcdp_* rename. Off by default; mutually exclusive with installing the upstream ego-browser plugin (same tool names)."),
|
|
2659
|
+
toolInjection: toolInjection.default("lazy").description("lazy = keep only the core tier resident and inject the rest after the first bcdp_* activity (the idle reaper seals them back); always = register every allowed tool at mount (the historical behaviour).").volatile(),
|
|
2660
|
+
toolBrowse: z.boolean().default(true).description("Basic browsing tier (14 tools: click / fill / key / hover / scroll / select / check / screenshot / page_info / read_element / js / wait / wait_for_selector / space_close). Off = sealed: removed from the model tool list.").volatile(),
|
|
2661
|
+
toolExtended: z.boolean().default(true).description("Extended tier (13 tools: drag / upload / download / dialog / raw CDP / http / cli / script / captcha / auth_flush / login_import / wait_for_url / wait_for_response). Off = sealed even after browser activity.").volatile(),
|
|
2662
|
+
toolJudge: z.boolean().default(true).description("Judgement tier (5 bcdp_jev_* tools). On still requires a JEV or Laya key: without one they can only answer \"not configured\", so they stay sealed anyway.").volatile(),
|
|
2643
2663
|
localHeadless: z.boolean().description("Run the locally launched browser headless."),
|
|
2644
2664
|
remoteEnabled: z.boolean().description("Master switch for REMOTE attach. Off = the configured target sequence is preserved but inert (nothing probes or connects remotely); flip back on any time. Does not affect cdpMode=local.").volatile(),
|
|
2645
2665
|
localUserDataDir: z.string().description("Profile dir for the locally launched browser. Empty = managed dir; never point at your daily Chrome profile."),
|
|
@@ -2831,6 +2851,13 @@ function judgeSettingsOf(config) {
|
|
|
2831
2851
|
wallMs: config.jevWallMs
|
|
2832
2852
|
};
|
|
2833
2853
|
}
|
|
2854
|
+
/**
|
|
2855
|
+
* 分级开关的默认极性 = 开放。只有显式的假值才是封印:`undefined`(用户从没碰
|
|
2856
|
+
* 过表单)与手改 YAML 写出的 `'false'` / `0` 都得认,否则一个空字段就会把
|
|
2857
|
+
* 14 个工具静默封掉。prime-memory 的 `v.toolRoom !== false` 同式,只是这里把
|
|
2858
|
+
* 手改形状一并接住。
|
|
2859
|
+
*/
|
|
2860
|
+
const tierOpenByDefault = (value) => !(value === false || value === "false" || value === 0);
|
|
2834
2861
|
function resolveConfig(config = {}) {
|
|
2835
2862
|
config = derefVolatileConfig(config);
|
|
2836
2863
|
const legacyFps = finiteIn(config.castFpsCap, 0, 60) ? config.castFpsCap === 0 ? 20 : Math.max(5, Math.min(30, config.castFpsCap)) : 20;
|
|
@@ -2895,6 +2922,10 @@ function resolveConfig(config = {}) {
|
|
|
2895
2922
|
cursorName: typeof config.cursorName === "string" && config.cursorName.trim() !== "" ? config.cursorName : "DeepSeek",
|
|
2896
2923
|
allowLocalFallback: config.allowLocalFallback === void 0 ? false : Boolean(config.allowLocalFallback),
|
|
2897
2924
|
legacyEgoToolNames: Boolean(config.legacyEgoToolNames),
|
|
2925
|
+
toolInjection: oneOf(config.toolInjection, ["lazy", "always"], "lazy"),
|
|
2926
|
+
toolBrowse: tierOpenByDefault(config.toolBrowse),
|
|
2927
|
+
toolExtended: tierOpenByDefault(config.toolExtended),
|
|
2928
|
+
toolJudge: tierOpenByDefault(config.toolJudge),
|
|
2898
2929
|
localHeadless: config.localHeadless === void 0 ? false : Boolean(config.localHeadless),
|
|
2899
2930
|
localUserDataDir: typeof config.localUserDataDir === "string" ? config.localUserDataDir : "",
|
|
2900
2931
|
lightpandaArgs: trimmed(config.lightpandaArgs),
|
|
@@ -3140,7 +3171,7 @@ function envelopeError(code, message) {
|
|
|
3140
3171
|
* add/change a tool, remember to sync an entry here or bcdp_help won't find it.
|
|
3141
3172
|
*/
|
|
3142
3173
|
const EGO_HELP_INDEX = {
|
|
3143
|
-
overview: "CDP 浏览器代理:结构化浏览器工具。导航/交互/观察/表单/网络/等待/键鼠皆有专项工具,另提供 bcdp_help(本索引)、bcdp_doctor(体检)、bcdp_cli/bcdp_script(自由脚本逃生舱)。连接与激活见 topic=links。分类见: tools / navigate / observe / input / keyboard-mouse / form / wait / network / login / script / doctor / lightpanda。用 `topic` 查询,或直接给工具名。",
|
|
3174
|
+
overview: "CDP 浏览器代理:结构化浏览器工具。导航/交互/观察/表单/网络/等待/键鼠皆有专项工具,另提供 bcdp_help(本索引)、bcdp_doctor(体检)、bcdp_cli/bcdp_script(自由脚本逃生舱)。连接与激活见 topic=links。分类见: tools / navigate / observe / input / keyboard-mouse / form / wait / network / login / script / doctor / lightpanda / injection。用 `topic` 查询,或直接给工具名。",
|
|
3144
3175
|
tools: "工具清单: bcdp_status, bcdp_space_open, bcdp_space_close, bcdp_snapshot, bcdp_navigate, bcdp_click(+double), bcdp_fill, bcdp_js, bcdp_cdp, bcdp_screenshot(+selector), bcdp_page_info, bcdp_wait, bcdp_wait_for_selector, bcdp_wait_for_url, bcdp_wait_for_response, bcdp_key(+text/type), 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_cli, bcdp_script, bcdp_jev_status, bcdp_jev_frame, bcdp_jev_attempt, bcdp_jev_ask, bcdp_jev_run。",
|
|
3145
3176
|
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 连接。",
|
|
3146
3177
|
navigate: "bcdp_navigate: 打开URL或切tab(同任务复用当前tab)。bcdp_wait_for_url: 等跳转(登录/分页)。",
|
|
@@ -3154,7 +3185,8 @@ const EGO_HELP_INDEX = {
|
|
|
3154
3185
|
captcha: "bcdp_captcha: 检测页面人机验证(CAPTCHA)并返回{detected,kind}; 检测到请让用户去 ego 浏览器完成; bcdp_page_info 也附带 humanCheck。",
|
|
3155
3186
|
login: "bcdp_auth_flush: 把登录cookie落盘到ego profile; 观察窗登录引导条+『已登录,保存』按钮触发同一动作。bcdp_login_import: 从系统浏览器(Chrome/Edge/Brave)按域名导入登录cookie(source/domains/dryRun; 先dryRun看可导入项; ego浏览器须已在运行)。",
|
|
3156
3187
|
script: "bcdp_cli / bcdp_script: 原样运行任意内置运行时 heredoc 脚本(page/browser/taskSpaces/site/fetch/cdp预载)。bcdp_script额外返回 duration/timedOut。",
|
|
3157
|
-
doctor: "bcdp_doctor:
|
|
3188
|
+
doctor: "bcdp_doctor: 体检环境(浏览器候选、vendored runtime、状态目录、CDP端口、任务空间、引擎与降级清单);首行附工具注入面快照。",
|
|
3189
|
+
injection: "工具分级注入(不是工具,是出现时机):38 个 bcdp_* 分四级——core(status/doctor/help/space_open/navigate/snapshot,常驻不可封印)/ browse(基础操作)/ extended(拖拽上传下载对话框裸CDP脚本登录搬运)/ judge(bcdp_jev_*)。设置旋钮(全 volatile,一级一个开关):toolInjection = lazy(默认,只常驻 core,首次 bcdp_* 调用后铺开)/ always(挂载即全量,历史行为);toolBrowse / toolExtended / toolJudge 三把开关——开 = 开放注册,关 = 该级从工具列表移除(core 级不给开关,封了就没解锁入口);judge 级即使开了仍需配 JEV/Laya Key。封印 = 从工具列表里反注册,不是执行期报错;lazy 下闲置回收会把扩展面收回。**若某个 bcdp_* 工具不在你的工具列表里**:它被分级封印了——先跑 bcdp_status 或 bcdp_doctor(两者也算浏览器活动,会把面铺开),或让用户在设置页「工具封印」里打开对应档位的开关;别猜测不存在的工具名。",
|
|
3158
3190
|
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)",
|
|
3159
3191
|
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 未开放注册)。"
|
|
3160
3192
|
};
|
|
@@ -3226,6 +3258,384 @@ function installEgoBrowserSettings(ctx, config) {
|
|
|
3226
3258
|
}
|
|
3227
3259
|
};
|
|
3228
3260
|
}
|
|
3261
|
+
function installSettingsAuto(ctx, config) {
|
|
3262
|
+
const legacySettings = ctx.settings;
|
|
3263
|
+
const legacyModule = (() => {
|
|
3264
|
+
try {
|
|
3265
|
+
return createRequire(import.meta.url)("@deepseek-ai/dsh-settings");
|
|
3266
|
+
} catch {
|
|
3267
|
+
return;
|
|
3268
|
+
}
|
|
3269
|
+
})();
|
|
3270
|
+
if (typeof legacyModule?.installSettingsSection === "function" && typeof legacyModule?.settingsNamespace === "function") {
|
|
3271
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3272
|
+
let current = derefVolatileConfig(config);
|
|
3273
|
+
const notify = () => {
|
|
3274
|
+
for (const listener of [...listeners]) listener();
|
|
3275
|
+
};
|
|
3276
|
+
const ns = legacyModule.settingsNamespace("dsh-browser-cdp");
|
|
3277
|
+
legacyModule.installSettingsSection(ctx, ns, Config$1, current, {
|
|
3278
|
+
setSource: (source) => {
|
|
3279
|
+
current = derefVolatileConfig((typeof source === "function" ? source() : source) ?? {});
|
|
3280
|
+
},
|
|
3281
|
+
onChange: () => {
|
|
3282
|
+
notify();
|
|
3283
|
+
}
|
|
3284
|
+
});
|
|
3285
|
+
return {
|
|
3286
|
+
source: () => current,
|
|
3287
|
+
onChange: (cb) => {
|
|
3288
|
+
listeners.add(cb);
|
|
3289
|
+
return () => {
|
|
3290
|
+
listeners.delete(cb);
|
|
3291
|
+
};
|
|
3292
|
+
}
|
|
3293
|
+
};
|
|
3294
|
+
}
|
|
3295
|
+
if (legacySettings && typeof legacySettings.installSection === "function") {
|
|
3296
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3297
|
+
let current = derefVolatileConfig(config);
|
|
3298
|
+
const notify = () => {
|
|
3299
|
+
for (const listener of [...listeners]) listener();
|
|
3300
|
+
};
|
|
3301
|
+
legacySettings.installSection(ctx, "dsh-browser-cdp", Config$1, current, {
|
|
3302
|
+
setSource: (source) => {
|
|
3303
|
+
current = derefVolatileConfig((typeof source === "function" ? source() : source) ?? {});
|
|
3304
|
+
},
|
|
3305
|
+
onChange: () => {
|
|
3306
|
+
notify();
|
|
3307
|
+
}
|
|
3308
|
+
});
|
|
3309
|
+
return {
|
|
3310
|
+
source: () => current,
|
|
3311
|
+
onChange: (cb) => {
|
|
3312
|
+
listeners.add(cb);
|
|
3313
|
+
return () => {
|
|
3314
|
+
listeners.delete(cb);
|
|
3315
|
+
};
|
|
3316
|
+
}
|
|
3317
|
+
};
|
|
3318
|
+
}
|
|
3319
|
+
return installEgoBrowserSettings(ctx, config);
|
|
3320
|
+
}
|
|
3321
|
+
const SETTINGS_BRIDGE_NS = "dsh-browser-cdp";
|
|
3322
|
+
function bridgeSendJson(res, code, body) {
|
|
3323
|
+
res.writeHead(code, {
|
|
3324
|
+
"content-type": "application/json; charset=utf-8",
|
|
3325
|
+
"cache-control": "no-cache"
|
|
3326
|
+
});
|
|
3327
|
+
res.end(JSON.stringify(body));
|
|
3328
|
+
}
|
|
3329
|
+
function bridgeReadJson(req) {
|
|
3330
|
+
return new Promise((resolve$1, reject) => {
|
|
3331
|
+
const chunks = [];
|
|
3332
|
+
let size = 0;
|
|
3333
|
+
req.on("data", (chunk) => {
|
|
3334
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
3335
|
+
size += buf.length;
|
|
3336
|
+
if (size > 256 * 1024) {
|
|
3337
|
+
reject(/* @__PURE__ */ new Error("bridge body too large"));
|
|
3338
|
+
if (typeof req.resume === "function") req.resume();
|
|
3339
|
+
return;
|
|
3340
|
+
}
|
|
3341
|
+
chunks.push(buf);
|
|
3342
|
+
});
|
|
3343
|
+
req.on("end", () => {
|
|
3344
|
+
const raw = Buffer.concat(chunks).toString("utf8");
|
|
3345
|
+
if (raw === "") {
|
|
3346
|
+
resolve$1({});
|
|
3347
|
+
return;
|
|
3348
|
+
}
|
|
3349
|
+
try {
|
|
3350
|
+
resolve$1(JSON.parse(raw));
|
|
3351
|
+
} catch (e) {
|
|
3352
|
+
reject(e instanceof Error ? e : new Error(String(e)));
|
|
3353
|
+
}
|
|
3354
|
+
});
|
|
3355
|
+
req.on("error", reject);
|
|
3356
|
+
});
|
|
3357
|
+
}
|
|
3358
|
+
function bridgeDescribeNs(svc, ns) {
|
|
3359
|
+
return svc.describe({ redactSecrets: true }).find((d) => d.ns === ns);
|
|
3360
|
+
}
|
|
3361
|
+
/**
|
|
3362
|
+
* 注册 /api/dsh-browser-cdp/settings/{describe,mutate} 两端点(kind:'exact')。
|
|
3363
|
+
* 宿主 settings 服务经惰性 ctx.get 取(cordis get 永不 throw;服务未解析时
|
|
3364
|
+
* describe 回 settings-unavailable,client 桥按瞬态重试)。webServer 缺席的
|
|
3365
|
+
* 宿主(TUI/headless)整段 no-op。
|
|
3366
|
+
*/
|
|
3367
|
+
function registerSettingsBridge(wctx, ctx) {
|
|
3368
|
+
const ws = wctx;
|
|
3369
|
+
if (!ws || typeof ws.register !== "function") return;
|
|
3370
|
+
const c = ctx;
|
|
3371
|
+
const getSettingsSvc = () => {
|
|
3372
|
+
try {
|
|
3373
|
+
return typeof c?.get === "function" ? c.get("settings") : void 0;
|
|
3374
|
+
} catch {
|
|
3375
|
+
return;
|
|
3376
|
+
}
|
|
3377
|
+
};
|
|
3378
|
+
ws.register({
|
|
3379
|
+
kind: "exact",
|
|
3380
|
+
path: `/api/${SETTINGS_BRIDGE_NS}/settings/describe`,
|
|
3381
|
+
handler: (req, res) => {
|
|
3382
|
+
if (req.method !== "POST") {
|
|
3383
|
+
bridgeSendJson(res, 405, {
|
|
3384
|
+
ok: false,
|
|
3385
|
+
code: "method-not-allowed"
|
|
3386
|
+
});
|
|
3387
|
+
return;
|
|
3388
|
+
}
|
|
3389
|
+
const svc = getSettingsSvc();
|
|
3390
|
+
if (!svc || typeof svc.describe !== "function") {
|
|
3391
|
+
bridgeSendJson(res, 200, {
|
|
3392
|
+
ok: false,
|
|
3393
|
+
code: "settings-unavailable",
|
|
3394
|
+
message: "settings service not resolved yet"
|
|
3395
|
+
});
|
|
3396
|
+
return;
|
|
3397
|
+
}
|
|
3398
|
+
try {
|
|
3399
|
+
const descriptor = bridgeDescribeNs(svc, SETTINGS_BRIDGE_NS);
|
|
3400
|
+
if (descriptor === void 0) {
|
|
3401
|
+
bridgeSendJson(res, 200, {
|
|
3402
|
+
ok: false,
|
|
3403
|
+
code: "ns-not-registered",
|
|
3404
|
+
message: `settings namespace "${SETTINGS_BRIDGE_NS}" is not registered`
|
|
3405
|
+
});
|
|
3406
|
+
return;
|
|
3407
|
+
}
|
|
3408
|
+
bridgeSendJson(res, 200, {
|
|
3409
|
+
ok: true,
|
|
3410
|
+
value: {
|
|
3411
|
+
descriptor,
|
|
3412
|
+
writable: svc.writable !== false
|
|
3413
|
+
}
|
|
3414
|
+
});
|
|
3415
|
+
} catch (e) {
|
|
3416
|
+
bridgeSendJson(res, 200, {
|
|
3417
|
+
ok: false,
|
|
3418
|
+
code: "internal",
|
|
3419
|
+
message: e instanceof Error ? e.message : String(e)
|
|
3420
|
+
});
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
});
|
|
3424
|
+
ws.register({
|
|
3425
|
+
kind: "exact",
|
|
3426
|
+
path: `/api/${SETTINGS_BRIDGE_NS}/settings/mutate`,
|
|
3427
|
+
handler: (req, res) => {
|
|
3428
|
+
if (req.method !== "POST") {
|
|
3429
|
+
bridgeSendJson(res, 405, {
|
|
3430
|
+
ok: false,
|
|
3431
|
+
code: "method-not-allowed"
|
|
3432
|
+
});
|
|
3433
|
+
return;
|
|
3434
|
+
}
|
|
3435
|
+
const svc = getSettingsSvc();
|
|
3436
|
+
if (!svc || typeof svc.mutate !== "function") {
|
|
3437
|
+
bridgeSendJson(res, 200, {
|
|
3438
|
+
ok: false,
|
|
3439
|
+
code: "settings-unavailable",
|
|
3440
|
+
message: "settings service mutate not available"
|
|
3441
|
+
});
|
|
3442
|
+
return;
|
|
3443
|
+
}
|
|
3444
|
+
bridgeReadJson(req).then((body) => {
|
|
3445
|
+
const ops = body?.ops;
|
|
3446
|
+
if (!(Array.isArray(ops) && ops.every((op) => op !== null && typeof op === "object" && (op.op === "set" || op.op === "unset")))) {
|
|
3447
|
+
bridgeSendJson(res, 200, {
|
|
3448
|
+
ok: false,
|
|
3449
|
+
code: "settings-rejected",
|
|
3450
|
+
message: "malformed bridge mutate ops"
|
|
3451
|
+
});
|
|
3452
|
+
return;
|
|
3453
|
+
}
|
|
3454
|
+
const expectedRevision = typeof body.expectedRevision === "number" ? body.expectedRevision : void 0;
|
|
3455
|
+
Promise.resolve(svc.mutate(SETTINGS_BRIDGE_NS, ops, expectedRevision)).then(() => {
|
|
3456
|
+
const descriptor = bridgeDescribeNs(svc, SETTINGS_BRIDGE_NS);
|
|
3457
|
+
if (descriptor === void 0) {
|
|
3458
|
+
bridgeSendJson(res, 200, {
|
|
3459
|
+
ok: false,
|
|
3460
|
+
code: "internal",
|
|
3461
|
+
message: `namespace "${SETTINGS_BRIDGE_NS}" disposed after mutate`
|
|
3462
|
+
});
|
|
3463
|
+
return;
|
|
3464
|
+
}
|
|
3465
|
+
bridgeSendJson(res, 200, {
|
|
3466
|
+
ok: true,
|
|
3467
|
+
value: { descriptor }
|
|
3468
|
+
});
|
|
3469
|
+
}).catch((e) => {
|
|
3470
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
3471
|
+
bridgeSendJson(res, 200, e instanceof Error && /conflict|revision/i.test(msg) ? {
|
|
3472
|
+
ok: false,
|
|
3473
|
+
code: "settings-conflict",
|
|
3474
|
+
message: msg
|
|
3475
|
+
} : {
|
|
3476
|
+
ok: false,
|
|
3477
|
+
code: "internal",
|
|
3478
|
+
message: msg
|
|
3479
|
+
});
|
|
3480
|
+
});
|
|
3481
|
+
}).catch((e) => {
|
|
3482
|
+
bridgeSendJson(res, 200, {
|
|
3483
|
+
ok: false,
|
|
3484
|
+
code: "bad-request",
|
|
3485
|
+
message: e instanceof Error ? e.message : String(e)
|
|
3486
|
+
});
|
|
3487
|
+
});
|
|
3488
|
+
}
|
|
3489
|
+
});
|
|
3490
|
+
}
|
|
3491
|
+
|
|
3492
|
+
//#endregion
|
|
3493
|
+
//#region src/toolTiers.ts
|
|
3494
|
+
const CORE = [
|
|
3495
|
+
"bcdp_status",
|
|
3496
|
+
"bcdp_doctor",
|
|
3497
|
+
"bcdp_help",
|
|
3498
|
+
"bcdp_space_open",
|
|
3499
|
+
"bcdp_navigate",
|
|
3500
|
+
"bcdp_snapshot"
|
|
3501
|
+
];
|
|
3502
|
+
const BROWSE = [
|
|
3503
|
+
"bcdp_space_close",
|
|
3504
|
+
"bcdp_click",
|
|
3505
|
+
"bcdp_fill",
|
|
3506
|
+
"bcdp_key",
|
|
3507
|
+
"bcdp_hover",
|
|
3508
|
+
"bcdp_scroll",
|
|
3509
|
+
"bcdp_select",
|
|
3510
|
+
"bcdp_check",
|
|
3511
|
+
"bcdp_screenshot",
|
|
3512
|
+
"bcdp_page_info",
|
|
3513
|
+
"bcdp_read_element",
|
|
3514
|
+
"bcdp_js",
|
|
3515
|
+
"bcdp_wait",
|
|
3516
|
+
"bcdp_wait_for_selector"
|
|
3517
|
+
];
|
|
3518
|
+
const EXTENDED = [
|
|
3519
|
+
"bcdp_drag",
|
|
3520
|
+
"bcdp_upload",
|
|
3521
|
+
"bcdp_download",
|
|
3522
|
+
"bcdp_dialog",
|
|
3523
|
+
"bcdp_cdp",
|
|
3524
|
+
"bcdp_http",
|
|
3525
|
+
"bcdp_cli",
|
|
3526
|
+
"bcdp_script",
|
|
3527
|
+
"bcdp_captcha",
|
|
3528
|
+
"bcdp_auth_flush",
|
|
3529
|
+
"bcdp_login_import",
|
|
3530
|
+
"bcdp_wait_for_url",
|
|
3531
|
+
"bcdp_wait_for_response"
|
|
3532
|
+
];
|
|
3533
|
+
const JUDGE = [
|
|
3534
|
+
"bcdp_jev_status",
|
|
3535
|
+
"bcdp_jev_ask",
|
|
3536
|
+
"bcdp_jev_frame",
|
|
3537
|
+
"bcdp_jev_run",
|
|
3538
|
+
"bcdp_jev_attempt"
|
|
3539
|
+
];
|
|
3540
|
+
/** 工具名 → 分级。`ego_*` 旧名(legacyEgoToolNames 别名)与 bcdp_* 同名同组。 */
|
|
3541
|
+
const TIER_OF_TOOL = new Map([
|
|
3542
|
+
["core", CORE],
|
|
3543
|
+
["browse", BROWSE],
|
|
3544
|
+
["extended", EXTENDED],
|
|
3545
|
+
["judge", JUDGE]
|
|
3546
|
+
].flatMap(([tier, names]) => names.map((n) => [n, tier])));
|
|
3547
|
+
/** 去掉 `bcdp_`/`ego_` 前缀后的裸名,便于策略表保持前缀无关。 */
|
|
3548
|
+
const bareToolName = (name$1) => name$1.replace(/^(?:bcdp|ego)_/, "");
|
|
3549
|
+
/**
|
|
3550
|
+
* 工具所属分级。未登记的名字落到 `extended`(最严的一档:宁可等活动解锁,
|
|
3551
|
+
* 也不让新工具悄悄回到常驻面);调用方应当在启动时打一条 warn,见
|
|
3552
|
+
* `unknownTieredTools`。分级表漂移由 `tests/tool-tiers.test.ts` 的覆盖率断言
|
|
3553
|
+
* 兜住,这里只是运行期兜底。
|
|
3554
|
+
*/
|
|
3555
|
+
function tierOfTool(name$1) {
|
|
3556
|
+
const bare = bareToolName(name$1);
|
|
3557
|
+
for (const [known, tier] of TIER_OF_TOOL) if (bareToolName(known) === bare) return tier;
|
|
3558
|
+
return "extended";
|
|
3559
|
+
}
|
|
3560
|
+
/** 名单里所有查不到分级登记的工具名(启动自检 / 测试用)。 */
|
|
3561
|
+
const unknownTieredTools = (names) => names.filter((n) => ![...TIER_OF_TOOL.keys()].some((k) => bareToolName(k) === bareToolName(n)));
|
|
3562
|
+
/**
|
|
3563
|
+
* 评审链是否「已配置」:至少有一个可用的 key。`layaUrl` 有默认值(sidecar
|
|
3564
|
+
* 本机 8000),所以 URL 非空说明不了任何事——只有 key 才是配置证据。
|
|
3565
|
+
* 两个 hop 独立可达,任一有 key 就算配置(见 config.ts 的 jev/laya 分离说明)。
|
|
3566
|
+
*/
|
|
3567
|
+
const judgeConfigured = (c) => (c.jevKey ?? "").trim() !== "" || (c.layaKey ?? "").trim() !== "";
|
|
3568
|
+
/** 某级开关的当前极性;`core` 恒开放。 */
|
|
3569
|
+
const tierOpen = (tier, p) => {
|
|
3570
|
+
switch (tier) {
|
|
3571
|
+
case "browse": return p.toolBrowse;
|
|
3572
|
+
case "extended": return p.toolExtended;
|
|
3573
|
+
case "judge": return p.toolJudge;
|
|
3574
|
+
default: return true;
|
|
3575
|
+
}
|
|
3576
|
+
};
|
|
3577
|
+
/**
|
|
3578
|
+
* 该分级此刻是否允许注册。
|
|
3579
|
+
*
|
|
3580
|
+
* 三条独立闸,任一不过即封印:
|
|
3581
|
+
* ① 本级开关(一级一个,ON = 开放);
|
|
3582
|
+
* ② 评审级额外要求已配 Key(没 Key 的 `bcdp_jev_*` 只能回「未配置」);
|
|
3583
|
+
* ③ 注入模式:`lazy` 下非 core 级要等活动,`always` 下不设时机闸。
|
|
3584
|
+
*/
|
|
3585
|
+
function tierAllowed(tier, p) {
|
|
3586
|
+
if (!tierOpen(tier, p)) return false;
|
|
3587
|
+
if (tier === "judge" && !p.judgeConfigured) return false;
|
|
3588
|
+
if (tier === "core") return true;
|
|
3589
|
+
return p.injection === "always" || p.active;
|
|
3590
|
+
}
|
|
3591
|
+
/** 某工具此刻是否允许注册(名字 → 分级 → 策略)。 */
|
|
3592
|
+
const toolAllowed = (name$1, p) => tierAllowed(tierOfTool(name$1), p);
|
|
3593
|
+
function createTierInjector(o) {
|
|
3594
|
+
const label = o.label ?? "dsh-browser-cdp";
|
|
3595
|
+
/** 全部已登记工具,插入序。 */
|
|
3596
|
+
const all = /* @__PURE__ */ new Map();
|
|
3597
|
+
/** 此刻注册在宿主上的工具 → disposer。 */
|
|
3598
|
+
const live = /* @__PURE__ */ new Map();
|
|
3599
|
+
/** 无名字的工具(不该出现,兜底直注不误伤既有行为)。 */
|
|
3600
|
+
let anon = 0;
|
|
3601
|
+
const reapply = () => {
|
|
3602
|
+
const p = o.policy();
|
|
3603
|
+
const added = [];
|
|
3604
|
+
const removed = [];
|
|
3605
|
+
for (const [name$1, tool] of all) {
|
|
3606
|
+
const allowed = toolAllowed(name$1, p);
|
|
3607
|
+
if (allowed && !live.has(name$1)) {
|
|
3608
|
+
live.set(name$1, o.register(tool));
|
|
3609
|
+
added.push(name$1);
|
|
3610
|
+
} else if (!allowed && live.has(name$1)) {
|
|
3611
|
+
live.get(name$1)?.();
|
|
3612
|
+
live.delete(name$1);
|
|
3613
|
+
removed.push(name$1);
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3616
|
+
if (added.length > 0) o.logger?.info?.(`${label}: 工具注入 +${added.length} (${added.join(" ")})`);
|
|
3617
|
+
if (removed.length > 0) o.logger?.warn?.(`${label}: 工具封印 -${removed.length} (${removed.join(" ")})`);
|
|
3618
|
+
};
|
|
3619
|
+
return {
|
|
3620
|
+
offer(tool) {
|
|
3621
|
+
const name$1 = typeof tool?.name === "string" ? tool.name : "";
|
|
3622
|
+
if (name$1 === "") {
|
|
3623
|
+
anon += 1;
|
|
3624
|
+
live.set(`#anon${anon}`, o.register(tool));
|
|
3625
|
+
return;
|
|
3626
|
+
}
|
|
3627
|
+
all.set(name$1, tool);
|
|
3628
|
+
reapply();
|
|
3629
|
+
},
|
|
3630
|
+
reapply,
|
|
3631
|
+
surface() {
|
|
3632
|
+
return {
|
|
3633
|
+
live: [...live.keys()],
|
|
3634
|
+
sealed: [...all.keys()].filter((n) => !live.has(n))
|
|
3635
|
+
};
|
|
3636
|
+
}
|
|
3637
|
+
};
|
|
3638
|
+
}
|
|
3229
3639
|
|
|
3230
3640
|
//#endregion
|
|
3231
3641
|
//#region src/ffmpeg-manifest.ts
|
|
@@ -6593,7 +7003,11 @@ const messageOf = (error) => error instanceof Error ? error.message : String(err
|
|
|
6593
7003
|
//#endregion
|
|
6594
7004
|
//#region src/index.ts
|
|
6595
7005
|
const name = "dsh-browser-cdp";
|
|
6596
|
-
const inject = [
|
|
7006
|
+
const inject = [
|
|
7007
|
+
"tools",
|
|
7008
|
+
"subprocess",
|
|
7009
|
+
"settings"
|
|
7010
|
+
];
|
|
6597
7011
|
const Config = Config$1;
|
|
6598
7012
|
/** Vendored ego-linux CLI shipped inside this plugin (runtime/ego-linux/bin/). */
|
|
6599
7013
|
const VENDORED_EGO_BIN = fileURLToPath(new URL("../runtime/ego-linux/bin/ego-browser.mjs", import.meta.url));
|
|
@@ -7082,7 +7496,7 @@ function defineEgoTool(ctx, cfg, opts) {
|
|
|
7082
7496
|
});
|
|
7083
7497
|
}
|
|
7084
7498
|
function apply(ctx, config = {}) {
|
|
7085
|
-
const bridge =
|
|
7499
|
+
const bridge = installSettingsAuto(ctx, config);
|
|
7086
7500
|
const ffmpegManager = getSharedFfmpegInstallationManager();
|
|
7087
7501
|
const initialFfmpegConfig = resolveConfig(bridge.source());
|
|
7088
7502
|
ffmpegManager.check({
|
|
@@ -7150,6 +7564,18 @@ function apply(ctx, config = {}) {
|
|
|
7150
7564
|
get idleTimeoutMin() {
|
|
7151
7565
|
return resolveConfig(bridge.source()).idleTimeoutMin;
|
|
7152
7566
|
},
|
|
7567
|
+
get toolInjection() {
|
|
7568
|
+
return resolveConfig(bridge.source()).toolInjection;
|
|
7569
|
+
},
|
|
7570
|
+
get toolBrowse() {
|
|
7571
|
+
return resolveConfig(bridge.source()).toolBrowse;
|
|
7572
|
+
},
|
|
7573
|
+
get toolExtended() {
|
|
7574
|
+
return resolveConfig(bridge.source()).toolExtended;
|
|
7575
|
+
},
|
|
7576
|
+
get toolJudge() {
|
|
7577
|
+
return resolveConfig(bridge.source()).toolJudge;
|
|
7578
|
+
},
|
|
7153
7579
|
get links() {
|
|
7154
7580
|
return resolveConfig(bridge.source()).links;
|
|
7155
7581
|
},
|
|
@@ -7238,27 +7664,83 @@ function apply(ctx, config = {}) {
|
|
|
7238
7664
|
return judgeSettingsOf(resolveConfig(bridge.source())).wallMs;
|
|
7239
7665
|
}
|
|
7240
7666
|
};
|
|
7667
|
+
let browserActive = false;
|
|
7668
|
+
const tiers = createTierInjector({
|
|
7669
|
+
register: (tool) => {
|
|
7670
|
+
const dispose = ctx.tools.register(tool);
|
|
7671
|
+
ctx.effect?.(() => dispose);
|
|
7672
|
+
return dispose;
|
|
7673
|
+
},
|
|
7674
|
+
policy: () => ({
|
|
7675
|
+
injection: cfg.toolInjection,
|
|
7676
|
+
toolBrowse: cfg.toolBrowse,
|
|
7677
|
+
toolExtended: cfg.toolExtended,
|
|
7678
|
+
toolJudge: cfg.toolJudge,
|
|
7679
|
+
judgeConfigured: judgeConfigured({
|
|
7680
|
+
jevKey: cfg.jevKey,
|
|
7681
|
+
layaKey: cfg.layaKey
|
|
7682
|
+
}),
|
|
7683
|
+
active: browserActive
|
|
7684
|
+
}),
|
|
7685
|
+
logger: ctx.logger
|
|
7686
|
+
});
|
|
7687
|
+
/** 活动信号:只翻一次牌,重复调用零成本。 */
|
|
7688
|
+
const pulseActivity = () => {
|
|
7689
|
+
if (browserActive) return;
|
|
7690
|
+
browserActive = true;
|
|
7691
|
+
tiers.reapply();
|
|
7692
|
+
};
|
|
7693
|
+
{
|
|
7694
|
+
const offActivity = onEgoActivity(pulseActivity);
|
|
7695
|
+
ctx.effect?.(() => offActivity);
|
|
7696
|
+
}
|
|
7697
|
+
/**
|
|
7698
|
+
* 闲置回收后把注入面收回 core 级(lazy 模式专属):浏览器已经停了,模型
|
|
7699
|
+
* 面上留着 30 多个驱动它的工具只是白付。下一次活动会重新铺开。
|
|
7700
|
+
*/
|
|
7701
|
+
const sealAfterReap = () => {
|
|
7702
|
+
if (cfg.toolInjection !== "lazy" || !browserActive) return;
|
|
7703
|
+
browserActive = false;
|
|
7704
|
+
tiers.reapply();
|
|
7705
|
+
};
|
|
7706
|
+
/**
|
|
7707
|
+
* 常驻级工具看到的分级视图:`pulse` = 把本次调用当成一次浏览器活动;
|
|
7708
|
+
* `surface` = 当前注入面(doctor 直接打出来,开关状态得看得见)。
|
|
7709
|
+
*/
|
|
7710
|
+
const tierView = {
|
|
7711
|
+
pulse: pulseActivity,
|
|
7712
|
+
active: () => browserActive,
|
|
7713
|
+
surface: () => tiers.surface()
|
|
7714
|
+
};
|
|
7241
7715
|
const reg = (tool) => {
|
|
7242
|
-
|
|
7243
|
-
ctx.effect?.(() => dispose);
|
|
7716
|
+
tiers.offer(tool);
|
|
7244
7717
|
if (cfg.legacyEgoToolNames && typeof tool.name === "string" && tool.name.startsWith("bcdp_")) {
|
|
7245
7718
|
const alias = {
|
|
7246
7719
|
...tool,
|
|
7247
7720
|
name: "ego_" + tool.name.slice(5)
|
|
7248
7721
|
};
|
|
7249
7722
|
try {
|
|
7250
|
-
|
|
7251
|
-
ctx.effect?.(() => disposeAlias);
|
|
7723
|
+
tiers.offer(alias);
|
|
7252
7724
|
} catch (error) {
|
|
7253
7725
|
ctx.logger?.warn?.(`dsh-browser-cdp: legacy alias ${alias.name} not registered: ${error.message}`);
|
|
7254
7726
|
}
|
|
7255
7727
|
}
|
|
7256
7728
|
};
|
|
7257
|
-
registerEgoStatus(ctx, cfg, reg);
|
|
7729
|
+
registerEgoStatus(ctx, cfg, reg, tierView);
|
|
7258
7730
|
registerAuthFlush(ctx, cfg, reg);
|
|
7259
7731
|
registerLoginImport(ctx, cfg, reg);
|
|
7260
7732
|
registerActionTools(ctx, cfg, reg);
|
|
7261
|
-
registerHelpAndDoctor(ctx, cfg, reg);
|
|
7733
|
+
registerHelpAndDoctor(ctx, cfg, reg, tierView);
|
|
7734
|
+
{
|
|
7735
|
+
const s = tiers.surface();
|
|
7736
|
+
const unlisted = unknownTieredTools([...s.live, ...s.sealed]);
|
|
7737
|
+
if (unlisted.length > 0) ctx.logger?.warn?.(`dsh-browser-cdp: tools missing from the tier table (defaulted to extended): ${unlisted.join(" ")}`);
|
|
7738
|
+
ctx.logger?.info?.(`dsh-browser-cdp: tool surface ${s.live.length}/${s.live.length + s.sealed.length} (injection=${cfg.toolInjection}, switches browse=${cfg.toolBrowse ? "open" : "sealed"} extended=${cfg.toolExtended ? "open" : "sealed"} judge=${cfg.toolJudge ? "open" : "sealed"}, judgeConfigured=${judgeConfigured({
|
|
7739
|
+
jevKey: cfg.jevKey,
|
|
7740
|
+
layaKey: cfg.layaKey
|
|
7741
|
+
})})`);
|
|
7742
|
+
}
|
|
7743
|
+
bridge.onChange(() => tiers.reapply());
|
|
7262
7744
|
const triggerCdpRefresh = (() => {
|
|
7263
7745
|
let inFlight = false;
|
|
7264
7746
|
let pending = false;
|
|
@@ -7333,6 +7815,11 @@ function apply(ctx, config = {}) {
|
|
|
7333
7815
|
} catch (err) {
|
|
7334
7816
|
ctx.logger?.warn?.(`dsh-browser-cdp: capability gateway init failed: ${err?.message ?? err}`);
|
|
7335
7817
|
}
|
|
7818
|
+
try {
|
|
7819
|
+
registerSettingsBridge(wctx, ctx);
|
|
7820
|
+
} catch (err) {
|
|
7821
|
+
ctx.logger?.warn?.(`dsh-browser-cdp: settings bridge init failed: ${err?.message ?? err}`);
|
|
7822
|
+
}
|
|
7336
7823
|
});
|
|
7337
7824
|
ctx.effect?.(() => {
|
|
7338
7825
|
if (cfg.idleTimeoutMin <= 0) return;
|
|
@@ -7377,6 +7864,7 @@ function apply(ctx, config = {}) {
|
|
|
7377
7864
|
},
|
|
7378
7865
|
graceMs: 8e3
|
|
7379
7866
|
}).done.catch(() => null);
|
|
7867
|
+
sealAfterReap();
|
|
7380
7868
|
} catch {}
|
|
7381
7869
|
})();
|
|
7382
7870
|
}, 6e4);
|
|
@@ -7404,7 +7892,7 @@ function apply(ctx, config = {}) {
|
|
|
7404
7892
|
ctx.logger?.info?.(`dsh-browser-cdp: mounted (egoBin=${cfg.egoBin}, defaultSpace=${cfg.defaultSpace})`);
|
|
7405
7893
|
}
|
|
7406
7894
|
/** `bcdp_status` probes CLI availability by running the real `--status` path. */
|
|
7407
|
-
function registerEgoStatus(ctx, cfg, reg) {
|
|
7895
|
+
function registerEgoStatus(ctx, cfg, reg, tiers) {
|
|
7408
7896
|
reg(defineTool({
|
|
7409
7897
|
name: "bcdp_status",
|
|
7410
7898
|
description: "Check whether the ego-browser CLI is usable (runs `ego-browser --status`). Use this first when other bcdp_* tools report \"CLI not found\".",
|
|
@@ -7429,37 +7917,40 @@ function registerEgoStatus(ctx, cfg, reg) {
|
|
|
7429
7917
|
render: renderText
|
|
7430
7918
|
},
|
|
7431
7919
|
timeoutMs: 25e3,
|
|
7432
|
-
execute: async () =>
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
|
|
7461
|
-
|
|
7462
|
-
|
|
7920
|
+
execute: async () => {
|
|
7921
|
+
tiers.pulse();
|
|
7922
|
+
return withEgoLock(async () => {
|
|
7923
|
+
try {
|
|
7924
|
+
const handle = ctx.subprocess.spawn({
|
|
7925
|
+
argv: [...cfg.egoArgvPrefix, "--status"],
|
|
7926
|
+
cwd: process.cwd(),
|
|
7927
|
+
env: resolveEgoEnv(cfg),
|
|
7928
|
+
stdio: {
|
|
7929
|
+
stdin: { data: "" },
|
|
7930
|
+
stdout: { maxBytes: 4096 },
|
|
7931
|
+
stderr: { maxBytes: 4096 }
|
|
7932
|
+
},
|
|
7933
|
+
graceMs: 25e3
|
|
7934
|
+
});
|
|
7935
|
+
const outcome = await handle.done;
|
|
7936
|
+
const out = readAll(handle.collected.stdout).trim();
|
|
7937
|
+
return {
|
|
7938
|
+
ok: true,
|
|
7939
|
+
available: outcome.exitCode === 0 && out !== "",
|
|
7940
|
+
path: cfg.egoBin,
|
|
7941
|
+
exitCode: outcome.exitCode
|
|
7942
|
+
};
|
|
7943
|
+
} catch (err) {
|
|
7944
|
+
return {
|
|
7945
|
+
ok: true,
|
|
7946
|
+
available: false,
|
|
7947
|
+
path: "",
|
|
7948
|
+
exitCode: null,
|
|
7949
|
+
error: describeSpawnFailure(err)
|
|
7950
|
+
};
|
|
7951
|
+
}
|
|
7952
|
+
});
|
|
7953
|
+
},
|
|
7463
7954
|
presentCall: () => ({
|
|
7464
7955
|
card: "generic",
|
|
7465
7956
|
title: "bcdp_status",
|
|
@@ -8269,7 +8760,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
8269
8760
|
})());
|
|
8270
8761
|
}
|
|
8271
8762
|
/** Register bcdp_help / bcdp_doctor / bcdp_script. */
|
|
8272
|
-
function registerHelpAndDoctor(ctx, cfg, reg) {
|
|
8763
|
+
function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
|
|
8273
8764
|
reg(defineTool({
|
|
8274
8765
|
name: "bcdp_captcha",
|
|
8275
8766
|
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.",
|
|
@@ -8355,6 +8846,7 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
|
|
|
8355
8846
|
},
|
|
8356
8847
|
timeoutMs: 1e4,
|
|
8357
8848
|
execute: async (args) => {
|
|
8849
|
+
tiers.pulse();
|
|
8358
8850
|
const q = str(args.topic, "").trim().toLowerCase();
|
|
8359
8851
|
const key = Object.prototype.hasOwnProperty.call(EGO_HELP_INDEX, q) ? q : "";
|
|
8360
8852
|
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;
|
|
@@ -8394,7 +8886,16 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
|
|
|
8394
8886
|
},
|
|
8395
8887
|
timeoutMs: 25e3,
|
|
8396
8888
|
execute: async () => {
|
|
8889
|
+
tiers.pulse();
|
|
8397
8890
|
const lines = [];
|
|
8891
|
+
{
|
|
8892
|
+
const s = tiers.surface();
|
|
8893
|
+
const key = judgeConfigured({
|
|
8894
|
+
jevKey: cfg.jevKey,
|
|
8895
|
+
layaKey: cfg.layaKey
|
|
8896
|
+
});
|
|
8897
|
+
lines.push(`tool injection: mode=${cfg.toolInjection} browse=${cfg.toolBrowse ? "open" : "sealed"} extended=${cfg.toolExtended ? "open" : "sealed"} judge=${cfg.toolJudge ? "open" : "sealed"} judgeKey=${key ? "set" : "none"} active=${tiers.active() ? "yes" : "no"} → live ${s.live.length} / sealed ${s.sealed.length}`);
|
|
8898
|
+
}
|
|
8398
8899
|
lines.push(`egoBin: ${cfg.egoBin}`);
|
|
8399
8900
|
try {
|
|
8400
8901
|
lines.push(`egoBin exists: ${existsSync(cfg.egoBin)}`);
|