@shgroup/dsh-serenity-hooks 1.138.3 → 1.139.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/dsh.plugin.json +1 -1
- package/lib/index.js +111 -112
- package/package.json +1 -1
package/dsh.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-serenity-hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.139.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"description": "宁静号 ACC harness(Native Cordis 插件):给 DSH 装一个「AI 工作区」——13 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin/browser_slot;另两个 im-bridge/diagram 按条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/IM 桥/认知轨迹唤醒注册表 + 浏览器槽位管理(≤20 个独立 profile 的 Chrome 槽位,带占用归属与异常时向所属会话反向注入提醒)。轨迹声明 = 轨迹目录下的 trajectory.json(约束面 + 旧标识 uid + CRO 机器绑定 cro.host;旧名 trajectory-constraint.json / skiff.json 仍在读取族里);轨迹提示词 = 轨迹目录下的 PROMPT.md(一条轨迹「是谁、按什么章程工作」,所有轨迹通用,追加在容器层与质量层之后,不替换它们)。适配 DSH 0.1.7-rc.1 / 0.2.0-rc.1 / 0.2.1-rc.1(三档,deepseek-ai/deepseek-harness)。",
|
|
6
6
|
"engines": {
|
package/lib/index.js
CHANGED
|
@@ -6594,15 +6594,15 @@ function createCognitiveTrajectoryTool(ctx) {
|
|
|
6594
6594
|
});
|
|
6595
6595
|
return [
|
|
6596
6596
|
message,
|
|
6597
|
-
`✓
|
|
6598
|
-
`
|
|
6597
|
+
`✓ Auto-activated (it had **no binding** before): ${active.dir} — subsequent work writes back to that trajectory's SESSION.md.`,
|
|
6598
|
+
` (Rule: no binding before create ⇒ activate; with a binding we only create, never take over — see below.)`
|
|
6599
6599
|
].join("\n");
|
|
6600
6600
|
}
|
|
6601
6601
|
return [
|
|
6602
6602
|
message,
|
|
6603
|
-
`⚠
|
|
6604
|
-
`
|
|
6605
|
-
`
|
|
6603
|
+
`⚠ This trajectory was NOT activated — currently bound to ${priorBound}; the existing binding wins (we do not take over the one you are using).`,
|
|
6604
|
+
` To activate it (and open a session under its name): use cognitive_trajectory send-now to send a message to ${result.dirName} —`,
|
|
6605
|
+
` if the target has no live dsh session, one is created and bound, with the usage prompt and your message injected together.`
|
|
6606
6606
|
].join("\n");
|
|
6607
6607
|
}
|
|
6608
6608
|
case "use": {
|
|
@@ -6740,7 +6740,7 @@ function createCognitiveTrajectoryTool(ctx) {
|
|
|
6740
6740
|
code: parseTrajectoryCode(entry.dirName),
|
|
6741
6741
|
uid: cur,
|
|
6742
6742
|
retired: true,
|
|
6743
|
-
note: cur === null ?
|
|
6743
|
+
note: cur === null ? `No legacy UID set ⇒ identify it by code (${parseTrajectoryCode(entry.dirName) ?? "no code"}).UID writing is retired; for a handle you can name, start a new trajectory with create --id.` : `Legacy UID = ${cur} (file ${UID_FILENAME}, read-only compat) — still usable to name this trajectory.⚠️ Writing it is retired: give new trajectories a code via create --id.`
|
|
6744
6744
|
};
|
|
6745
6745
|
}
|
|
6746
6746
|
case "send-later": {
|
|
@@ -18236,10 +18236,10 @@ function deriveSlotState(lease, proc, now, policy = DEFAULT_POLICY) {
|
|
|
18236
18236
|
reasons: ["进程已退出"]
|
|
18237
18237
|
};
|
|
18238
18238
|
const idle = now - lease.lastActionAt;
|
|
18239
|
-
if (!(lease.holdUntil > now) && idle > policy.idleMs) reasons.push(
|
|
18240
|
-
if (now - lease.leasedAt > policy.leaseMaxMs) reasons.push(
|
|
18241
|
-
if (proc && proc.cpuPct >= policy.cpuPct) reasons.push(`CPU ${proc.cpuPct.toFixed(0)}%
|
|
18242
|
-
if (proc && proc.rssMb >= policy.rssMb) reasons.push(
|
|
18239
|
+
if (!(lease.holdUntil > now) && idle > policy.idleMs) reasons.push(`idle ${Math.round(idle / 6e4)}m`);
|
|
18240
|
+
if (now - lease.leasedAt > policy.leaseMaxMs) reasons.push(`held over ${Math.round(policy.leaseMaxMs / 6e4)}m cap`);
|
|
18241
|
+
if (proc && proc.cpuPct >= policy.cpuPct) reasons.push(`CPU ${proc.cpuPct.toFixed(0)}% over threshold`);
|
|
18242
|
+
if (proc && proc.rssMb >= policy.rssMb) reasons.push(`rss ${proc.rssMb.toFixed(0)}MB over threshold`);
|
|
18243
18243
|
return reasons.length > 0 ? {
|
|
18244
18244
|
state: "stale",
|
|
18245
18245
|
reasons
|
|
@@ -18271,10 +18271,10 @@ function shouldNudge(lease, state, now, policy) {
|
|
|
18271
18271
|
* 而它真正该做的是 `release`。⇒ 每条文本都把**具体动作**写明。
|
|
18272
18272
|
*/
|
|
18273
18273
|
function nudgeText(slot, state, reasons, policy) {
|
|
18274
|
-
const head = `[
|
|
18275
|
-
const rel = `
|
|
18276
|
-
if (state === "orphaned") return `${head}\n
|
|
18277
|
-
return `${head}\n
|
|
18274
|
+
const head = `[slot-watchman] slot ${slotLabel(slot)} (port ${slotPort(slot)}) needs your action.`;
|
|
18275
|
+
const rel = ` You hold it — **release as soon as you are done**: \`browser_slot release ${slotLabel(slot)}\``;
|
|
18276
|
+
if (state === "orphaned") return `${head}\n What: the Chrome process for this slot is gone.\n ⚠️ If you still need it, further calls will fail — it will NOT recover by itself.\n ⇒ Do this: \`browser_slot release ${slotLabel(slot)}\` to hand it back, then \`acquire\` a fresh slot.\n${rel}`;
|
|
18277
|
+
return `${head}\n What: ${reasons.length > 0 ? reasons.join("; ") : "abnormal state"}\n${` Thresholds (which line you crossed): idle ${Math.round(policy.idleMs / 6e4)}m / CPU ${policy.cpuPct}% / rss ${policy.rssMb}MB / held cap ${Math.round(policy.leaseMaxMs / 6e4)}m.`}\n Why you: **you** leased this slot; only you know whether it is still needed.\n ⇒ Still using it: perform any action below the idle threshold, or release and re-acquire (resets the timer).\n ⇒ Done with it: if you no longer need it, just release — that is the cheapest step.\n${rel}`;
|
|
18278
18278
|
}
|
|
18279
18279
|
/**
|
|
18280
18280
|
* 🔴 **强关判定(纯函数,owner 2026-11-24 令)**。
|
|
@@ -18318,7 +18318,7 @@ function shouldForceReap(lease, proc, now, policy = DEFAULT_POLICY) {
|
|
|
18318
18318
|
* ⛔ 不写"你的槽位异常了" —— 那是无法行动的话。
|
|
18319
18319
|
*/
|
|
18320
18320
|
function forceReapText(slot, idleMin, nudges, policy = DEFAULT_POLICY) {
|
|
18321
|
-
return `[
|
|
18321
|
+
return `[slot-watchman] slot ${slotLabel(slot)} was **force-reclaimed** (idle ${idleMin}m, nudged ${nudges}x before).\n · Your browser is closed. **The profile dir is kept** ⇒ login sessions survive; re-acquire without re-login.\n · If this was a false kill (long download, slow query), hold it next time:\n \`browser_slot hold --slot ${slotLabel(slot)} --reason "<what you are doing>" --holdFor <minutes>\`\n · To continue: just \`acquire\` again.\n Why me: the idle threshold is ${Math.round(policy.idleKillMs / 6e4)}m — a browser actually doing work does not go silent that long.`;
|
|
18322
18322
|
}
|
|
18323
18323
|
/**
|
|
18324
18324
|
* 选一个空槽。⛔ 不做"最久未用优先"这类聪明事 —— 20 个槽位装得下,选择规则越简单越可预测。
|
|
@@ -21626,7 +21626,7 @@ async function acquireSlot(input) {
|
|
|
21626
21626
|
slot: existing.slot,
|
|
21627
21627
|
state: "leased",
|
|
21628
21628
|
reused: true,
|
|
21629
|
-
detail:
|
|
21629
|
+
detail: `You already hold slot ${slotLabel(existing.slot)} (port ${slotPort(existing.slot)}); reusing it.\n ⛔ Do not lease a second one — two slots per session is exactly the shape of the incident (leased and forgotten).\n` + launched.detail
|
|
21630
21630
|
};
|
|
21631
21631
|
}
|
|
21632
21632
|
const picked = withLedger((lg) => {
|
|
@@ -21662,14 +21662,14 @@ async function acquireSlot(input) {
|
|
|
21662
21662
|
slot: 0,
|
|
21663
21663
|
state: "free",
|
|
21664
21664
|
reused: false,
|
|
21665
|
-
detail: "20
|
|
21665
|
+
detail: "All 20 slots are taken, ⛔ refusing to lease another.\n ⇒ See who holds them: `browser_slot list`; hand one back with `release <slot>`.\n ⚠️ A full house is usually not \"high demand\" but **someone forgot to release** — look at the largest idleMin row."
|
|
21666
21666
|
};
|
|
21667
21667
|
if (picked < 0) return {
|
|
21668
21668
|
ok: false,
|
|
21669
21669
|
slot: -picked,
|
|
21670
21670
|
state: "leased",
|
|
21671
21671
|
reused: false,
|
|
21672
|
-
detail:
|
|
21672
|
+
detail: `Slot ${slotLabel(-picked)} is taken (⛔ not preempting). Use \`browser_slot list\` to see the owner, or omit --slot to let the system pick.`
|
|
21673
21673
|
};
|
|
21674
21674
|
const n = picked;
|
|
21675
21675
|
const launched = ensureRunning(input.root, n, 0);
|
|
@@ -21681,7 +21681,6 @@ async function acquireSlot(input) {
|
|
|
21681
21681
|
result: null
|
|
21682
21682
|
};
|
|
21683
21683
|
});
|
|
21684
|
-
const r = SLOT_RESOLUTION(n);
|
|
21685
21684
|
if (!launched.ok) {
|
|
21686
21685
|
withLedger((lg) => {
|
|
21687
21686
|
delete lg.leases[String(n)];
|
|
@@ -21705,7 +21704,7 @@ async function acquireSlot(input) {
|
|
|
21705
21704
|
slot: n,
|
|
21706
21705
|
state: "leased",
|
|
21707
21706
|
reused: false,
|
|
21708
|
-
detail:
|
|
21707
|
+
detail: `${launched.detail}\n🔴 **You must hand it back**: \`browser_slot release ${slotLabel(n)}\`\n If you forget, the watchman will nudge you once it sits idle — by then you may have moved on.`
|
|
21709
21708
|
};
|
|
21710
21709
|
}
|
|
21711
21710
|
/** 启动退避:连续失败按指数推迟(G9)。返回 0 = 可以尝试,>0 = 还需等待的毫秒 */
|
|
@@ -21748,18 +21747,18 @@ function ensureRunning(root, n, pidHint) {
|
|
|
21748
21747
|
if (live.length > 0) return {
|
|
21749
21748
|
ok: true,
|
|
21750
21749
|
pid: live[0],
|
|
21751
|
-
detail:
|
|
21750
|
+
detail: `Slot ${slotLabel(n)} already running (pid ${live[0]})`
|
|
21752
21751
|
};
|
|
21753
21752
|
if (pidHint > 0 && existsSync(`/proc/${pidHint}`)) return {
|
|
21754
21753
|
ok: true,
|
|
21755
21754
|
pid: pidHint,
|
|
21756
|
-
detail:
|
|
21755
|
+
detail: `Slot ${slotLabel(n)} already running (pid ${pidHint})`
|
|
21757
21756
|
};
|
|
21758
21757
|
const wait = backoffWaitMs(root, n, Date.now());
|
|
21759
21758
|
if (wait > 0) return {
|
|
21760
21759
|
ok: false,
|
|
21761
21760
|
pid: 0,
|
|
21762
|
-
detail:
|
|
21761
|
+
detail: `Slot ${slotLabel(n)} is in **launch backoff** (${Math.ceil(wait / 1e3)}s left).\n 🔴 Cause: this slot failed to start repeatedly. ⇒ Retrying pays a full re-check again (seconds) and **is indistinguishable in the readings**.\n ⇒ Find the root cause first: \`browser_slot doctor\` for pidDrift and log paths; or use another slot.`
|
|
21763
21762
|
};
|
|
21764
21763
|
const launched = launchSlot(n);
|
|
21765
21764
|
if (!launched.ok) {
|
|
@@ -21767,7 +21766,7 @@ function ensureRunning(root, n, pidHint) {
|
|
|
21767
21766
|
return {
|
|
21768
21767
|
ok: false,
|
|
21769
21768
|
pid: 0,
|
|
21770
|
-
detail: `${launched.detail}\n ⇒
|
|
21769
|
+
detail: `${launched.detail}\n ⇒ One launch failure recorded; next attempt allowed in ${Math.ceil(w / 1e3)}s.`
|
|
21771
21770
|
};
|
|
21772
21771
|
}
|
|
21773
21772
|
clearLaunchFailure(root, n);
|
|
@@ -21810,12 +21809,12 @@ function releaseSlot(root, sessionId, target) {
|
|
|
21810
21809
|
const lease = readLedger().leases[String(target)];
|
|
21811
21810
|
if (!lease) return {
|
|
21812
21811
|
ok: true,
|
|
21813
|
-
detail:
|
|
21812
|
+
detail: `Slot ${slotLabel(target)} was already free (nothing to release).`,
|
|
21814
21813
|
released: false
|
|
21815
21814
|
};
|
|
21816
21815
|
if (sessionId && lease.sessionId && lease.sessionId !== sessionId) return {
|
|
21817
21816
|
ok: false,
|
|
21818
|
-
detail:
|
|
21817
|
+
detail: `Slot ${slotLabel(target)} is not yours (owner: ${lease.trajectory || lease.sessionId || "unknown"}).\n ⛔ Not releasing on someone else's behalf — they may be using it. If you are sure it is abandoned, use \`browser_slot reap <slot>\` (watchman action, records a reason).`,
|
|
21819
21818
|
released: false
|
|
21820
21819
|
};
|
|
21821
21820
|
const destroyed = destroySlot(target, lease.pid);
|
|
@@ -21830,7 +21829,7 @@ function releaseSlot(root, sessionId, target) {
|
|
|
21830
21829
|
sampleCache.delete(target);
|
|
21831
21830
|
return {
|
|
21832
21831
|
ok: true,
|
|
21833
|
-
detail:
|
|
21832
|
+
detail: `Released slot ${slotLabel(target)}. ${destroyed.detail}`,
|
|
21834
21833
|
released: true
|
|
21835
21834
|
};
|
|
21836
21835
|
}
|
|
@@ -21884,7 +21883,7 @@ function reapSlot(root, target, reason) {
|
|
|
21884
21883
|
sampleCache.delete(target);
|
|
21885
21884
|
return {
|
|
21886
21885
|
ok: true,
|
|
21887
|
-
detail:
|
|
21886
|
+
detail: `Reclaimed slot ${slotLabel(target)} (reason: ${reason}). ${destroyed.detail}`
|
|
21888
21887
|
};
|
|
21889
21888
|
}
|
|
21890
21889
|
/**
|
|
@@ -21914,7 +21913,7 @@ async function forceReapIdleSlots(root, inject, policy = policyFromEnv()) {
|
|
|
21914
21913
|
scanned += 1;
|
|
21915
21914
|
const verdict = shouldForceReap(lease, readProcFor(root, lease.slot, now, lease.pid), now, policy);
|
|
21916
21915
|
if (!verdict) continue;
|
|
21917
|
-
const res = reapSlot(root, lease.slot,
|
|
21916
|
+
const res = reapSlot(root, lease.slot, `idle ${verdict.idleMin}m (nudged ${verdict.nudges}x)`);
|
|
21918
21917
|
recordRecentKill(lease.slot, lease.trajectory, verdict.idleMin, verdict.nudges, res.ok);
|
|
21919
21918
|
const target = lease.trajectory || lease.sessionId;
|
|
21920
21919
|
let delivered = false;
|
|
@@ -21928,7 +21927,7 @@ async function forceReapIdleSlots(root, inject, policy = policyFromEnv()) {
|
|
|
21928
21927
|
} catch (err) {
|
|
21929
21928
|
deliverDetail = String(err?.message ?? err);
|
|
21930
21929
|
}
|
|
21931
|
-
} else deliverDetail = "
|
|
21930
|
+
} else deliverDetail = "This slot has no owning trajectory (sessionId and trajectory both empty) ⇒ cannot notify; the kill is still recorded in the ledger";
|
|
21932
21931
|
out.push({
|
|
21933
21932
|
slot: lease.slot,
|
|
21934
21933
|
trajectory: lease.trajectory,
|
|
@@ -21962,20 +21961,20 @@ async function forceReapIdleSlots(root, inject, policy = policyFromEnv()) {
|
|
|
21962
21961
|
function holdSlot(root, sessionId, target, minutes, reason) {
|
|
21963
21962
|
if (!Number.isFinite(minutes) || minutes <= 0) return {
|
|
21964
21963
|
ok: false,
|
|
21965
|
-
detail: `hold
|
|
21964
|
+
detail: `hold needs a positive number of minutes (got ${minutes})`
|
|
21966
21965
|
};
|
|
21967
21966
|
if (minutes > 240) return {
|
|
21968
21967
|
ok: false,
|
|
21969
|
-
detail: `hold
|
|
21968
|
+
detail: `hold is capped at 240 minutes per call (got ${minutes}).\n ⛔ Never a permanent exemption — that would defeat idle reclaim. Renew before it expires if you need longer.`
|
|
21970
21969
|
};
|
|
21971
21970
|
const lease = readLedger().leases[String(target)];
|
|
21972
21971
|
if (!lease) return {
|
|
21973
21972
|
ok: false,
|
|
21974
|
-
detail:
|
|
21973
|
+
detail: `Slot ${slotLabel(target)} is not leased (nothing to hold).`
|
|
21975
21974
|
};
|
|
21976
21975
|
if (sessionId && lease.sessionId && lease.sessionId !== sessionId) return {
|
|
21977
21976
|
ok: false,
|
|
21978
|
-
detail:
|
|
21977
|
+
detail: `Slot ${slotLabel(target)} is not yours; ⛔ cannot hold on someone else's behalf.`
|
|
21979
21978
|
};
|
|
21980
21979
|
const until = Date.now() + minutes * 6e4;
|
|
21981
21980
|
withLedger((lg) => {
|
|
@@ -21988,7 +21987,7 @@ function holdSlot(root, sessionId, target, minutes, reason) {
|
|
|
21988
21987
|
});
|
|
21989
21988
|
return {
|
|
21990
21989
|
ok: true,
|
|
21991
|
-
detail:
|
|
21990
|
+
detail: `Held slot ${slotLabel(target)} until ${new Date(until).toLocaleTimeString("en-GB")} (${minutes} min).\n · Idle is NOT judged while held, but process liveness / CPU / rss still are.\n · Reason: ${reason || "(none given)"}\n · If still idle when it expires, the normal nudge→force-reclaim flow resumes.`
|
|
21992
21991
|
};
|
|
21993
21992
|
}
|
|
21994
21993
|
/**
|
|
@@ -22035,7 +22034,7 @@ async function nudgeStaleSlots(root, inject, policy = policyFromEnv()) {
|
|
|
22035
22034
|
state,
|
|
22036
22035
|
trajectory: "",
|
|
22037
22036
|
delivered: false,
|
|
22038
|
-
detail: "
|
|
22037
|
+
detail: "This slot has no owning trajectory (sessionId and trajectory both empty) ⇒ cannot inject; needs manual handling"
|
|
22039
22038
|
});
|
|
22040
22039
|
continue;
|
|
22041
22040
|
}
|
|
@@ -22122,8 +22121,8 @@ function doctorSlots(root, policy = policyFromEnv()) {
|
|
|
22122
22121
|
*/
|
|
22123
22122
|
function assertSlotOwned(root, slot, sessionId) {
|
|
22124
22123
|
const lease = readLedger().leases[String(slot)];
|
|
22125
|
-
if (!lease) throw new Error(
|
|
22126
|
-
if (sessionId === "" || lease.sessionId !== sessionId) throw new Error(
|
|
22124
|
+
if (!lease) throw new Error(`Slot ${slotLabel(slot)} is not leased right now ⇒ \`browser_slot acquire\` one first.\n ⛔ Not auto-leasing for you: lease-and-forget is exactly the shape of the 2026-11-09 36-hour power incident.`);
|
|
22125
|
+
if (sessionId === "" || lease.sessionId !== sessionId) throw new Error(`Slot ${slotLabel(slot)} is not yours (owner ${lease.sessionId || "(none)"}) ⇒ refusing the operation.\n ⇒ Find your own with \`browser_slot list\`; to open a new one use \`browser_slot acquire\`.\n ⚠️ A hard refusal is deliberate: allowing it would make "who drives whose browser" unanswerable.`);
|
|
22127
22126
|
}
|
|
22128
22127
|
/** 把页面上一次成功的操作推进 lastActionAt(这就是"长期不动作"判据的来源) */
|
|
22129
22128
|
function pageTouched(root, slot) {
|
|
@@ -22142,14 +22141,14 @@ function pageTouched(root, slot) {
|
|
|
22142
22141
|
* @returns 解析好的 targetId(**唯一**),或抛出可读错误(0 命中 / 多命中都把候选列全)
|
|
22143
22142
|
*/
|
|
22144
22143
|
async function resolveTarget(root, slot, sessionId, opts) {
|
|
22145
|
-
if (!opts.target && !opts.match) throw new Error("⛔
|
|
22144
|
+
if (!opts.target && !opts.match) throw new Error("⛔ needs --target=<targetId> or --match=<URL or title substring>.\n ⇒ Run `browser_slot targets --slot b1` to see what is there, or just pass --match=example.com");
|
|
22146
22145
|
if (opts.target) return opts.target;
|
|
22147
22146
|
const list = await slotTargets(root, slot, sessionId);
|
|
22148
22147
|
const res = pickTarget(list, { match: opts.match });
|
|
22149
22148
|
if (res.ok) return res.target.id;
|
|
22150
22149
|
const pages = list.filter((t) => t.type === "page");
|
|
22151
|
-
if (res.reason === "not-found") throw new Error(`⛔
|
|
22152
|
-
throw new Error(`⛔
|
|
22150
|
+
if (res.reason === "not-found") throw new Error(`⛔ No page matches "${opts.match}" (matches url or title, case-insensitive).\n ⇒ ${pages.length} page(s) currently:\n${renderHits(pages)}`);
|
|
22151
|
+
throw new Error(`⛔ "${opts.match}" matched ${res.hits.length} pages — refusing to pick one for you (a wrong pick yields an image that looks right but belongs to someone else).\n ⇒ Use a longer substring, or name one with --target=<id>:\n${renderHits(res.hits)}`);
|
|
22153
22152
|
}
|
|
22154
22153
|
/**
|
|
22155
22154
|
* 语义化点击:`--text` 子串或 `--xy` 坐标。
|
|
@@ -22162,11 +22161,11 @@ async function resolveTarget(root, slot, sessionId, opts) {
|
|
|
22162
22161
|
*/
|
|
22163
22162
|
async function slotClick(root, slot, sessionId, targetId, opts) {
|
|
22164
22163
|
assertSlotOwned(root, slot, sessionId);
|
|
22165
|
-
if (!opts.text && !opts.xy) throw new Error("⛔
|
|
22164
|
+
if (!opts.text && !opts.xy) throw new Error("⛔ needs --text=<visible label> or coordinates (run targets first for a targetId)");
|
|
22166
22165
|
if (opts.xy) {
|
|
22167
22166
|
const hit = judgeHit(await hitTestAt(slot, targetId, opts.xy.x, opts.xy.y), opts.ref !== void 0 ? { backendNodeId: opts.ref } : void 0);
|
|
22168
|
-
if (hit.kind === "offscreen" || hit.kind === "blank") throw new Error(`⛔
|
|
22169
|
-
if (hit.kind === "blocked") throw new Error(`⛔
|
|
22167
|
+
if (hit.kind === "offscreen" || hit.kind === "blank") throw new Error(`⛔ Not clicking: ${renderHit(hit)}\n ⇒ coords ${opts.xy.x},${opts.xy.y}. Get a ref via \`ax\` first (more reliable), or \`scroll\` the target into the viewport.`);
|
|
22168
|
+
if (hit.kind === "blocked") throw new Error(`⛔ Not clicking: ${renderHit(hit)}\n ⇒ When something covers it, the click runs ANOTHER element's handler (and a receipt saying "clicked" would never reveal it).\n ⇒ Fix: use \`ax\` to see what that layer is (overlay / sticky header / mask) and close it; or name the target with \`--ref\`.`);
|
|
22170
22169
|
const r = await clickAt(slot, targetId, opts.xy.x, opts.xy.y);
|
|
22171
22170
|
pageTouched(root, slot);
|
|
22172
22171
|
return {
|
|
@@ -22192,12 +22191,12 @@ async function slotClick(root, slot, sessionId, targetId, opts) {
|
|
|
22192
22191
|
const res = pickClickable(list, { text: opts.text });
|
|
22193
22192
|
if (!res.ok) {
|
|
22194
22193
|
const visible = list.filter((e) => e.w > 0 && e.h > 0);
|
|
22195
|
-
if (res.reason === "ambiguous") throw new Error(`⛔
|
|
22196
|
-
if (res.reason === "not-clickable") throw new Error(`⛔
|
|
22197
|
-
throw new Error(`⛔
|
|
22194
|
+
if (res.reason === "ambiguous") throw new Error(`⛔ "${opts.text}" matched ${res.hits.length} clickable elements — refusing to pick (a wrong click has already happened and will not undo itself).\n ⇒ Use a longer label, or name it with --xy=<x,y>:\n${renderClickables(res.hits)}`);
|
|
22195
|
+
if (res.reason === "not-clickable") throw new Error(`⛔ "${opts.text}" was found, but ${res.why}.\n ⇒ This is not a "try clicking anyway" situation: a dead click and no click read the same.\n${renderClickables(res.hits)}`);
|
|
22196
|
+
throw new Error(`⛔ No clickable element on the page matches "${opts.text}" (matches rendered visible text, incl. value/aria-label/title).\n ⇒ ${visible.length} visible clickable element(s) right now:\n${renderClickables(visible)}`);
|
|
22198
22197
|
}
|
|
22199
22198
|
const hit = judgeHit(await hitTestAt(slot, targetId, res.el.x, res.el.y));
|
|
22200
|
-
if (hit.kind === "offscreen" || hit.kind === "blank") throw new Error(`⛔
|
|
22199
|
+
if (hit.kind === "offscreen" || hit.kind === "blank") throw new Error(`⛔ Not clicking "${opts.text}": ${renderHit(hit)}\n ⇒ "Found" and "can be clicked" are two different things: visible and clickable in the DOM does not mean this click lands on it.`);
|
|
22201
22200
|
const clicked = await clickAt(slot, targetId, res.el.x, res.el.y);
|
|
22202
22201
|
pageTouched(root, slot);
|
|
22203
22202
|
return {
|
|
@@ -22279,9 +22278,9 @@ async function slotClose(root, slot, sessionId, targetId, all = false) {
|
|
|
22279
22278
|
*/
|
|
22280
22279
|
function needBackendId(args) {
|
|
22281
22280
|
const ref = typeof args.ref === "string" ? args.ref : "";
|
|
22282
|
-
if (!ref) throw new Error("⛔
|
|
22281
|
+
if (!ref) throw new Error("⛔ needs --ref=<eNNN> (run `browser_slot ax` to get a ref first).\n ⇒ A ref comes from an accessibility-tree snapshot; ⛔ it is not a DOM selector or CSS path.");
|
|
22283
22282
|
const id = refToBackendId(ref);
|
|
22284
|
-
if (id === null) throw new Error(`⛔ --ref
|
|
22283
|
+
if (id === null) throw new Error(`⛔ malformed --ref: ${JSON.stringify(ref)} (expected e12345, as printed by \`ax\`).\n ⛔ CSS selectors / text are not accepted — those need guessing, and a wrong guess drives another element with no signal.`);
|
|
22285
22284
|
return id;
|
|
22286
22285
|
}
|
|
22287
22286
|
/** AX 快照 */
|
|
@@ -22299,7 +22298,7 @@ async function slotAx(root, slot, sessionId, targetId, limit = 200) {
|
|
|
22299
22298
|
async function slotPress(root, slot, sessionId, targetId, keyDesc, times = 1) {
|
|
22300
22299
|
assertSlotOwned(root, slot, sessionId);
|
|
22301
22300
|
const stroke = parseKeyStroke(keyDesc);
|
|
22302
|
-
if (!stroke) throw new Error(`⛔
|
|
22301
|
+
if (!stroke) throw new Error(`⛔ Cannot parse key: ${JSON.stringify(keyDesc)}.\n ⇒ Accepted forms: Enter / Escape / Tab / ArrowUp|Down|Left|Right / Home / End / PageUp / PageDown / Space / Backspace / Delete; join modifiers with + (Control+A / Meta+Shift+Enter); single chars limited to a-z 0-9.\n ⇒ To type free text into a field use type (goes through Input.insertText, no key guessing): --text=<text>`);
|
|
22303
22302
|
const sent = await pressKey(slot, targetId, stroke, times);
|
|
22304
22303
|
pageTouched(root, slot);
|
|
22305
22304
|
return {
|
|
@@ -22360,7 +22359,7 @@ async function slotScroll(root, slot, sessionId, targetId, opts) {
|
|
|
22360
22359
|
async function slotWait(root, slot, sessionId, targetId, raw, timeoutMs) {
|
|
22361
22360
|
assertSlotOwned(root, slot, sessionId);
|
|
22362
22361
|
const spec = parseWaitSpec(raw);
|
|
22363
|
-
if (!spec) throw new Error(`⛔
|
|
22362
|
+
if (!spec) throw new Error(`⛔ Cannot parse wait condition: ${JSON.stringify(raw)}.\n ⇒ Accepted forms (prefix required; a bare value is ambiguous and may wait for something that never comes):\n selector:<CSS> text:<substring> url:<substring> gone:<CSS> js:<expression>`);
|
|
22364
22363
|
const r = await waitForInPage(slot, targetId, spec.expression, timeoutMs);
|
|
22365
22364
|
pageTouched(root, slot);
|
|
22366
22365
|
if (!r.ok) throw new Error(explainWaitTimeout(spec, r.waitedMs, r.last));
|
|
@@ -22388,9 +22387,9 @@ function resolveUploadPath(cccRoot, relOrAbs) {
|
|
|
22388
22387
|
try {
|
|
22389
22388
|
st = statSync(abs);
|
|
22390
22389
|
} catch {
|
|
22391
|
-
throw new Error(`⛔
|
|
22390
|
+
throw new Error(`⛔ File does not exist: ${relOrAbs} (resolved to ${abs}).\n ⚠️ This refusal is necessary: DOM.setFileInputFiles SILENTLY SUCCEEDS on a missing path, the form field stays empty, and the page looks exactly like "uploading".`);
|
|
22392
22391
|
}
|
|
22393
|
-
if (!st.isFile()) throw new Error(`⛔
|
|
22392
|
+
if (!st.isFile()) throw new Error(`⛔ Not a regular file (directory/device/symlink): ${relOrAbs}`);
|
|
22394
22393
|
return abs;
|
|
22395
22394
|
}
|
|
22396
22395
|
async function slotUpload(root, slot, sessionId, targetId, backendNodeId, absPaths) {
|
|
@@ -22448,7 +22447,7 @@ async function slotExt(root, slot, sessionId, name, args) {
|
|
|
22448
22447
|
return {
|
|
22449
22448
|
ok: false,
|
|
22450
22449
|
code: "ext-not-found",
|
|
22451
|
-
error:
|
|
22450
|
+
error: `No extension named "${name}".\n` + (known.length > 0 ? ` ⇒ Extensions in this CCC: ${known.join(", ")}` : ` ⇒ This CCC has no extensions yet (no .ts files under <CCC root>/${EXT_DIR_REL}/).\n To add one: stdin gets {slot,port,cccRoot,args}; the last stdout line returns {"ok":true,"result":…}`)
|
|
22452
22451
|
};
|
|
22453
22452
|
}
|
|
22454
22453
|
const res = await runExtension(entry, buildExtPayload({
|
|
@@ -22907,9 +22906,9 @@ function trajectoryNameFromCwd(root, cwd) {
|
|
|
22907
22906
|
*/
|
|
22908
22907
|
function row(v) {
|
|
22909
22908
|
const g = STATE_GLYPH[v.state] ?? "?";
|
|
22910
|
-
const who = v.state === "free" ? "" : ` ${v.trajectory || v.sessionId || "(
|
|
22911
|
-
const res = v.sampled ? `cpu${v.cpuPct}%
|
|
22912
|
-
const extra = v.state === "free" ? "" : `
|
|
22909
|
+
const who = v.state === "free" ? "" : ` ${v.trajectory || v.sessionId || "(unowned)"}`;
|
|
22910
|
+
const res = v.sampled ? `cpu${v.cpuPct}% rss${v.rssMb}M` : "cpu— rss—(not sampled on this platform)";
|
|
22911
|
+
const extra = v.state === "free" ? "" : ` held${v.heldMin}m idle${v.idleMin}m ${res}`;
|
|
22913
22912
|
const why = v.reasons.length > 0 ? `\n ↳ ${v.reasons.join(";")}` : "";
|
|
22914
22913
|
return ` ${g} ${v.label.padEnd(3)} :${v.port} ${v.resolution.padEnd(9)} ${v.state.padEnd(8)}${who}${extra}${why}`;
|
|
22915
22914
|
}
|
|
@@ -22922,7 +22921,7 @@ function row(v) {
|
|
|
22922
22921
|
*/
|
|
22923
22922
|
function needSlot(args) {
|
|
22924
22923
|
const n = normalizeSlotId(String(args.slot ?? ""));
|
|
22925
|
-
if (n === 0) throw new Error(`⛔
|
|
22924
|
+
if (n === 0) throw new Error(`⛔ needs --slot <b1..b20> (got ${JSON.stringify(args.slot)}).\n ⇒ Page actions must name the slot: run \`browser_slot list\` to see which one you hold.`);
|
|
22926
22925
|
return n;
|
|
22927
22926
|
}
|
|
22928
22927
|
/**
|
|
@@ -22934,7 +22933,7 @@ function needSlot(args) {
|
|
|
22934
22933
|
async function needTarget(root, n, sessionId, args) {
|
|
22935
22934
|
const target = str(args.target);
|
|
22936
22935
|
const match = str(args.match);
|
|
22937
|
-
if (!target && !match) throw new Error("⛔
|
|
22936
|
+
if (!target && !match) throw new Error("⛔ needs --target=<targetId> or --match=<URL/title substring> (run targets first).\n ⇒ --match is a substring match: it acts only on a unique hit; multiple hits are rejected with all candidates listed.");
|
|
22938
22937
|
return resolveTarget(root, n, sessionId, {
|
|
22939
22938
|
target,
|
|
22940
22939
|
match
|
|
@@ -22999,7 +22998,7 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
22999
22998
|
trajectory,
|
|
23000
22999
|
want: typeof args.slot === "string" ? normalizeSlotId(args.slot) : 0
|
|
23001
23000
|
});
|
|
23002
|
-
if (!res.ok) return `⛔
|
|
23001
|
+
if (!res.ok) return `⛔ acquire failed.\n${res.detail}`;
|
|
23003
23002
|
if (args.wait === true) {
|
|
23004
23003
|
const ready = await waitSlotReady(root, res.slot);
|
|
23005
23004
|
return `${res.detail}\n${ready.ok ? "✓ " + ready.detail : "⚠️ " + ready.detail}`;
|
|
@@ -23008,27 +23007,27 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
23008
23007
|
}
|
|
23009
23008
|
case "release": {
|
|
23010
23009
|
const n = normalizeSlotId(String(args.slot ?? ""));
|
|
23011
|
-
if (n === 0) return "⛔
|
|
23010
|
+
if (n === 0) return "⛔ release needs --slot <b1..b20>";
|
|
23012
23011
|
const r = releaseSlot(root, sessionId, n);
|
|
23013
23012
|
return r.detail + (r.released && r.ok ? domainSkillPrompt(root) : "");
|
|
23014
23013
|
}
|
|
23015
23014
|
case "reap": {
|
|
23016
23015
|
const n = normalizeSlotId(String(args.slot ?? ""));
|
|
23017
|
-
if (n === 0) return "⛔
|
|
23016
|
+
if (n === 0) return "⛔ reap needs --slot <b1..b20>";
|
|
23018
23017
|
return reapSlot(root, n, typeof args.reason === "string" && args.reason ? args.reason : "manual reaping").detail;
|
|
23019
23018
|
}
|
|
23020
23019
|
case "hold": {
|
|
23021
23020
|
const n = normalizeSlotId(String(args.slot ?? ""));
|
|
23022
|
-
if (n === 0) return "⛔
|
|
23021
|
+
if (n === 0) return "⛔ hold needs --slot <b1..b20>";
|
|
23023
23022
|
const mins = num(args.holdFor);
|
|
23024
|
-
if (mins === void 0) return "⛔
|
|
23023
|
+
if (mins === void 0) return "⛔ hold needs --holdFor=<minutes> (e.g. --holdFor 60). No permanent hold — that would defeat idle reclaim.";
|
|
23025
23024
|
const r = holdSlot(root, sessionId, n, mins, typeof args.reason === "string" ? args.reason : "");
|
|
23026
23025
|
return r.ok ? r.detail : `⛔ ${r.detail}`;
|
|
23027
23026
|
}
|
|
23028
23027
|
case "status": {
|
|
23029
23028
|
const n = normalizeSlotId(String(args.slot ?? ""));
|
|
23030
23029
|
const v = n > 0 ? slotStatus(root, n) : null;
|
|
23031
|
-
if (!v) return `⛔
|
|
23030
|
+
if (!v) return `⛔ invalid slot (1..20)`;
|
|
23032
23031
|
return row(v).trimStart();
|
|
23033
23032
|
}
|
|
23034
23033
|
case "list":
|
|
@@ -23037,24 +23036,24 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
23037
23036
|
const occupied = views.filter((v) => v.state !== "free");
|
|
23038
23037
|
const bad = views.filter((v) => v.state === "stale" || v.state === "orphaned");
|
|
23039
23038
|
const lines = [];
|
|
23040
|
-
lines.push(
|
|
23041
|
-
lines.push(" ·
|
|
23042
|
-
if (occupied.length === 0) lines.push("
|
|
23039
|
+
lines.push(`slots ${views.length} (busy ${occupied.length}, free ${views.length - occupied.length}, bad ${bad.length})` + (ledgerAgeMin > 0 ? ` ledger ${ledgerAgeMin}m old` : ""));
|
|
23040
|
+
lines.push(" · free ✓ leased ! stale(act) ✗ orphaned");
|
|
23041
|
+
if (occupied.length === 0) lines.push(" (all free)");
|
|
23043
23042
|
else for (const v of occupied) lines.push(row(v));
|
|
23044
23043
|
if (bad.length > 0) {
|
|
23045
23044
|
lines.push("");
|
|
23046
|
-
lines.push("🔴
|
|
23045
|
+
lines.push("🔴 The watchman notifies the OWNING session; if the owner is gone, reap it:");
|
|
23047
23046
|
for (const v of bad) lines.push(` browser_slot reap --slot ${v.label}`);
|
|
23048
23047
|
}
|
|
23049
23048
|
lines.push("");
|
|
23050
|
-
lines.push("
|
|
23049
|
+
lines.push("usage: acquire (auto-picks, or --slot) · release (always when done) · status --slot b1");
|
|
23051
23050
|
const visits = Object.entries(readVisits(root).domains).sort((a, b) => b[1].opens - a[1].opens || b[1].lastAt - a[1].lastAt);
|
|
23052
23051
|
if (visits.length > 0) {
|
|
23053
23052
|
const missing = visits.filter(([h]) => !hasDomainSkill(root, h)).length;
|
|
23054
23053
|
lines.push("");
|
|
23055
|
-
lines.push(
|
|
23056
|
-
for (const [h, v] of visits.slice(0, 5)) lines.push(` ${hasDomainSkill(root, h) ? "✓" : "·"} ${h.padEnd(28)} ${v.opens}
|
|
23057
|
-
if (visits.length > 5) lines.push(`
|
|
23054
|
+
lines.push(`domains ${visits.length}${missing > 0 ? ` (${missing} without notes)` : " (all documented)"}:`);
|
|
23055
|
+
for (const [h, v] of visits.slice(0, 5)) lines.push(` ${hasDomainSkill(root, h) ? "✓" : "·"} ${h.padEnd(28)} ${v.opens}x`);
|
|
23056
|
+
if (visits.length > 5) lines.push(` …${visits.length - 5} more (BROWSER/_index.json)`);
|
|
23058
23057
|
}
|
|
23059
23058
|
return lines.join("\n");
|
|
23060
23059
|
}
|
|
@@ -23062,13 +23061,13 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
23062
23061
|
case "targets": {
|
|
23063
23062
|
const n = needSlot(args);
|
|
23064
23063
|
const list = await slotTargets(root, n, sessionId);
|
|
23065
|
-
if (list.length === 0) return
|
|
23066
|
-
return `[browser_slot] ${list.length}
|
|
23064
|
+
if (list.length === 0) return `no targets on ${slotLabel(n)} (port ${slotPort(n)})`;
|
|
23065
|
+
return `[browser_slot] ${list.length} target(s) on ${slotLabel(n)} (port ${slotPort(n)})\n` + list.map((t) => ` ${t.type.padEnd(10)} ${t.id} ${t.title.slice(0, 40)} ${t.url.slice(0, 90)}`).join("\n");
|
|
23067
23066
|
}
|
|
23068
23067
|
case "open": {
|
|
23069
23068
|
const n = needSlot(args);
|
|
23070
23069
|
const url = str(args.url);
|
|
23071
|
-
if (!url) return "⛔
|
|
23070
|
+
if (!url) return "⛔ needs --url=<address>";
|
|
23072
23071
|
return `[browser_slot] targetId=${await slotOpen(root, n, sessionId, url)}` + domainSkillTail(root, url, sessionId, n);
|
|
23073
23072
|
}
|
|
23074
23073
|
case "goto": {
|
|
@@ -23078,9 +23077,9 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
23078
23077
|
const match = str(args.match);
|
|
23079
23078
|
const missing = [];
|
|
23080
23079
|
if (n === 0) missing.push("--slot <b1..b20>");
|
|
23081
|
-
if (!target && !match) missing.push("--target <targetId>
|
|
23082
|
-
if (!url) missing.push("--url
|
|
23083
|
-
if (missing.length > 0) return `⛔ goto
|
|
23080
|
+
if (!target && !match) missing.push("--target <targetId> or --match <URL/title substring> (run targets first)");
|
|
23081
|
+
if (!url) missing.push("--url <destination>");
|
|
23082
|
+
if (missing.length > 0) return `⛔ goto missing ${missing.length} arg(s), all listed at once:\n` + missing.map((m) => ` · ${m}`).join("\n") + `\n ⚠️ goto differs from open: open needs only --slot + --url; goto also needs WHICH tab to navigate.`;
|
|
23084
23083
|
const slotN = n;
|
|
23085
23084
|
const destUrl = url;
|
|
23086
23085
|
const tgt = target ?? await needTarget(root, slotN, sessionId, args);
|
|
@@ -23091,7 +23090,7 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
23091
23090
|
const n = needSlot(args);
|
|
23092
23091
|
const js = str(args.js);
|
|
23093
23092
|
const target = await needTarget(root, n, sessionId, args);
|
|
23094
|
-
if (!js) return "⛔
|
|
23093
|
+
if (!js) return "⛔ needs --js=<expression> (e.g. document.title)";
|
|
23095
23094
|
const v = await slotEval(root, n, sessionId, target, js, num(args.timeout));
|
|
23096
23095
|
return typeof v === "string" ? v : JSON.stringify(v, null, 2);
|
|
23097
23096
|
}
|
|
@@ -23110,59 +23109,59 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
23110
23109
|
}
|
|
23111
23110
|
case "reload": {
|
|
23112
23111
|
const n = needSlot(args);
|
|
23113
|
-
return `[browser_slot] reload
|
|
23112
|
+
return `[browser_slot] reload done (readyState=${await slotReload(root, n, sessionId, await needTarget(root, n, sessionId, args), str(args.script)) || "?"})`;
|
|
23114
23113
|
}
|
|
23115
23114
|
case "click": {
|
|
23116
23115
|
const n = needSlot(args);
|
|
23117
23116
|
const target = await needTarget(root, n, sessionId, args);
|
|
23118
23117
|
const text = str(args.text);
|
|
23119
23118
|
const xy = parseXY(args.xy);
|
|
23120
|
-
if (!text && !xy) return `⛔
|
|
23119
|
+
if (!text && !xy) return `⛔ needs --text=<visible label> or coordinates (all three forms accepted):\n${xyFormHint("xy")}\n e.g. --text=Sign in`;
|
|
23121
23120
|
const refRaw = str(args.ref);
|
|
23122
23121
|
const refId = refRaw === void 0 ? void 0 : refToBackendId(refRaw) ?? void 0;
|
|
23123
|
-
if (refRaw !== void 0 && refId === void 0) return `⛔ --ref
|
|
23122
|
+
if (refRaw !== void 0 && refId === void 0) return `⛔ malformed --ref: ${JSON.stringify(refRaw)} (want eNNN from \`ax\`)`;
|
|
23124
23123
|
const { picked, dialogs, hit } = await slotClick(root, n, sessionId, target, {
|
|
23125
23124
|
text,
|
|
23126
23125
|
xy,
|
|
23127
23126
|
ref: refId
|
|
23128
23127
|
});
|
|
23129
|
-
const base = `[browser_slot] clicked ${xy ? `@${xy.x},${xy.y}` : `<${picked.tag}> "${picked.text.slice(0, 60)}" @${picked.x},${picked.y}`}
|
|
23128
|
+
const base = `[browser_slot] clicked ${xy ? `@${xy.x},${xy.y}` : `<${picked.tag}> "${picked.text.slice(0, 60)}" @${picked.x},${picked.y}`}|hit: ${renderHit(hit)}`;
|
|
23130
23129
|
if (dialogs.length === 0) return base;
|
|
23131
|
-
return `${base}\n${dialogs.map((d) => ` ⚠️
|
|
23130
|
+
return `${base}\n${dialogs.map((d) => ` ⚠️ auto-handled dialog ${d.type || "(unknown)"}: ${JSON.stringify(d.message.slice(0, 100))} ⇒ ${d.accepted ? "accepted" : "dismissed"}`).join("\n")}\n (default = dismiss; use dialog --accept to confirm — OK often means delete/pay/publish)`;
|
|
23132
23131
|
}
|
|
23133
23132
|
case "ax": {
|
|
23134
23133
|
const n = needSlot(args);
|
|
23135
23134
|
const target = await needTarget(root, n, sessionId, args);
|
|
23136
23135
|
const { lines, total } = await slotAx(root, n, sessionId, target, num(args.limit) ?? 200);
|
|
23137
|
-
if (lines.length === 0) return `[browser_slot] ax
|
|
23138
|
-
return `[browser_slot] ax
|
|
23136
|
+
if (lines.length === 0) return `[browser_slot] ax — no interactive elements in the a11y tree (target=${target}).\n ⇒ maybe not rendered yet (wait first), or the page is genuinely static text (use text).`;
|
|
23137
|
+
return `[browser_slot] ax — ${lines.length} interactive element(s) (of ${total}; ref stays stable across snapshots)\n${renderAx(lines, total)}`;
|
|
23139
23138
|
}
|
|
23140
23139
|
case "press": {
|
|
23141
23140
|
const n = needSlot(args);
|
|
23142
23141
|
const target = await needTarget(root, n, sessionId, args);
|
|
23143
23142
|
const k = str(args.key);
|
|
23144
|
-
if (!k) return "⛔
|
|
23143
|
+
if (!k) return "⛔ needs --key=<key> (e.g. Enter / Escape / Control+A / Meta+Shift+Enter)";
|
|
23145
23144
|
const { stroke, sent } = await slotPress(root, n, sessionId, target, k, num(args.times) ?? 1);
|
|
23146
|
-
return `[browser_slot] press ${stroke.key}
|
|
23145
|
+
return `[browser_slot] press ${stroke.key} (code=${stroke.code}, modifiers=${stroke.modifiers}) × ${sent}\n ⚠️ This only reports keys SENT, ⛔ not that the UI responded — re-read with ax / eval.`;
|
|
23147
23146
|
}
|
|
23148
23147
|
case "type": {
|
|
23149
23148
|
const n = needSlot(args);
|
|
23150
23149
|
const target = await needTarget(root, n, sessionId, args);
|
|
23151
23150
|
const text = typeof args.text === "string" ? args.text : void 0;
|
|
23152
|
-
if (text === void 0 || text === "") return "⛔
|
|
23151
|
+
if (text === void 0 || text === "") return "⛔ needs --text=<exact text> (acts on current focus; use fill to set a value)";
|
|
23153
23152
|
await slotType(root, n, sessionId, target, text);
|
|
23154
|
-
return `[browser_slot] type ${JSON.stringify(text.slice(0, 40))}
|
|
23153
|
+
return `[browser_slot] type ${JSON.stringify(text.slice(0, 40))} (inserted ${[...text].length} chars; ⛔ no change event — blur triggers it)`;
|
|
23155
23154
|
}
|
|
23156
23155
|
case "fill": {
|
|
23157
23156
|
const n = needSlot(args);
|
|
23158
23157
|
const target = await needTarget(root, n, sessionId, args);
|
|
23159
23158
|
const id = needBackendId(args);
|
|
23160
23159
|
const value = typeof args.value === "string" ? args.value : void 0;
|
|
23161
|
-
if (value === void 0) return "⛔
|
|
23160
|
+
if (value === void 0) return "⛔ needs --value=<value> (empty string allowed: --value=)";
|
|
23162
23161
|
const r = await slotFill(root, n, sessionId, target, id, value);
|
|
23163
|
-
if (!r.ok) return `⛔ fill
|
|
23162
|
+
if (!r.ok) return `⛔ fill failed (<${r.tag || "?"}>): ${r.why ?? "unknown reason"}`;
|
|
23164
23163
|
const same = r.readBack === value;
|
|
23165
|
-
return `[browser_slot] fill <${r.tag}>
|
|
23164
|
+
return `[browser_slot] fill <${r.tag}> read-back=${JSON.stringify(r.readBack.slice(0, 80))}` + (same ? " ✓ matches the value given" : " ⚠️ does NOT match — the control may reformat or reject it");
|
|
23166
23165
|
}
|
|
23167
23166
|
case "scroll": {
|
|
23168
23167
|
const n = needSlot(args);
|
|
@@ -23171,55 +23170,55 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
23171
23170
|
const xy = parseXY(args.xy);
|
|
23172
23171
|
const toRaw = str(args.to);
|
|
23173
23172
|
const to = toRaw === "top" || toRaw === "bottom" ? toRaw : void 0;
|
|
23174
|
-
if (!refStr && !xy && !to) return "⛔
|
|
23173
|
+
if (!refStr && !xy && !to) return "⛔ needs one of --ref=<eNNN> / --xy=<x,y> / --to=<top|bottom>";
|
|
23175
23174
|
const { scrolledY, via, why } = await slotScroll(root, n, sessionId, target, {
|
|
23176
23175
|
ref: refStr ? needBackendId(args) : void 0,
|
|
23177
23176
|
xy,
|
|
23178
23177
|
to,
|
|
23179
23178
|
deltaY: num(args.delta)
|
|
23180
23179
|
});
|
|
23181
|
-
const viaLine = via === "wheel" ? "
|
|
23182
|
-
return `[browser_slot] scroll → scrollY
|
|
23180
|
+
const viaLine = via === "wheel" ? "(real wheel event)" : `(⚠️ fell back to JS scroll — ${why ?? ""}; NO wheel event was emitted, so wheel-triggered lazy loading will not start)`;
|
|
23181
|
+
return `[browser_slot] scroll → scrollY ${scrolledY > 0 ? "+" : ""}${scrolledY}px ${viaLine}`;
|
|
23183
23182
|
}
|
|
23184
23183
|
case "wait": {
|
|
23185
23184
|
const n = needSlot(args);
|
|
23186
23185
|
const target = await needTarget(root, n, sessionId, args);
|
|
23187
23186
|
const forRaw = str(args.for);
|
|
23188
|
-
if (!forRaw) return "⛔
|
|
23187
|
+
if (!forRaw) return "⛔ needs --for=<selector:…|text:…|url:…|gone:…|js:…> (prefix required)";
|
|
23189
23188
|
const { spec, waitedMs } = await slotWait(root, n, sessionId, target, forRaw, num(args.timeout) ?? 15e3);
|
|
23190
|
-
return `[browser_slot] wait ${spec.kind}
|
|
23189
|
+
return `[browser_slot] wait ${spec.kind} satisfied (waited ${waitedMs}ms)`;
|
|
23191
23190
|
}
|
|
23192
23191
|
case "drag": {
|
|
23193
23192
|
const n = needSlot(args);
|
|
23194
23193
|
const target = await needTarget(root, n, sessionId, args);
|
|
23195
23194
|
const from = parseXY(args.from);
|
|
23196
23195
|
const to = parseXY(args.to);
|
|
23197
|
-
if (!from || !to) return `⛔
|
|
23196
|
+
if (!from || !to) return `⛔ needs --from and --to (all three coordinate forms accepted):\n${xyFormHint("from")}${xyFormHint("to")}\n get a ref via ax, then measure coords with scroll/eval`;
|
|
23198
23197
|
const steps = num(args.steps) ?? 12;
|
|
23199
23198
|
await slotDrag(root, n, sessionId, target, from, to, steps);
|
|
23200
|
-
return `[browser_slot] drag ${from.x},${from.y} → ${to.x},${to.y}
|
|
23199
|
+
return `[browser_slot] drag ${from.x},${from.y} → ${to.x},${to.y} (${steps} steps; ⛔ this does not report success)`;
|
|
23201
23200
|
}
|
|
23202
23201
|
case "upload": {
|
|
23203
23202
|
const n = needSlot(args);
|
|
23204
23203
|
const target = await needTarget(root, n, sessionId, args);
|
|
23205
23204
|
const id = needBackendId(args);
|
|
23206
23205
|
const list = Array.isArray(args.file) ? args.file : typeof args.file === "string" ? [args.file] : [];
|
|
23207
|
-
if (list.length === 0) return "⛔
|
|
23206
|
+
if (list.length === 0) return "⛔ needs --file=<path inside CCC> (repeatable; paths outside the CCC root are refused)";
|
|
23208
23207
|
const abs = list.filter((x) => typeof x === "string" && x !== "").map((f) => resolveUploadPath(root, f));
|
|
23209
|
-
if (abs.length === 0) return "⛔ --file
|
|
23208
|
+
if (abs.length === 0) return "⛔ no usable path in --file";
|
|
23210
23209
|
const r = await slotUpload(root, n, sessionId, target, id, abs);
|
|
23211
|
-
return `[browser_slot] upload ${r.files.length}
|
|
23210
|
+
return `[browser_slot] upload ${r.files.length} file(s) → ref ${str(args.ref) ?? ""}\n ${r.files.map((f) => f.replace(root + "/", "")).join("\n ")}`;
|
|
23212
23211
|
}
|
|
23213
23212
|
case "downloads": {
|
|
23214
23213
|
const n = needSlot(args);
|
|
23215
23214
|
const { dir, files } = await slotDownloads(root, n, sessionId, await needTarget(root, n, sessionId, args));
|
|
23216
|
-
return `[browser_slot]
|
|
23215
|
+
return `[browser_slot] download capture dir: ${dir}\n${files.length === 0 ? "(directory is empty)" : files.map((f) => ` ${f.name} ${Math.round(f.bytes / 1024)} KB`).join("\n")}\n ⇒ trigger a download with click (links with download attr are refused) or eval; then call downloads again to see new files.\n ⚠️ The dir is never auto-cleaned — cleaning it destroys evidence.`;
|
|
23217
23216
|
}
|
|
23218
23217
|
case "dialog": {
|
|
23219
23218
|
const n = needSlot(args);
|
|
23220
23219
|
const r = await slotDialog(root, n, sessionId, await needTarget(root, n, sessionId, args), args.accept === true, str(args.prompt));
|
|
23221
|
-
if (!r.hadDialog) return "[browser_slot] dialog
|
|
23222
|
-
return `[browser_slot] dialog ${r.type || "(
|
|
23220
|
+
if (!r.hadDialog) return "[browser_slot] dialog — no dialog open right now (normal, not an error)";
|
|
23221
|
+
return `[browser_slot] dialog ${r.type || "(unknown)"}: ${JSON.stringify(r.message.slice(0, 120))}\n ${r.accepted ? "✓ accepted (OK)" : "✓ dismissed (Cancel)"}`;
|
|
23223
23222
|
}
|
|
23224
23223
|
case "close": {
|
|
23225
23224
|
const n = needSlot(args);
|
|
@@ -23228,15 +23227,15 @@ async function run(ctx, root, sessionId, trajectory, action, args) {
|
|
|
23228
23227
|
}
|
|
23229
23228
|
case "ext-list": {
|
|
23230
23229
|
const exts = slotExtList(root);
|
|
23231
|
-
if (exts.length === 0) return
|
|
23232
|
-
return
|
|
23230
|
+
if (exts.length === 0) return `No browser extensions in this CCC yet.\n To add one: drop a .ts file under <CCC root>/${EXT_DIR_REL}/ — the filename is the extension name.\n Contract: stdin gets {slot,port,cccRoot,args}; stdout's LAST non-empty line must be {"ok":true,"result":…}.\n ⚠️ ACC only spawns, ⛔ never imports — your syntax error cannot take down the host.`;
|
|
23231
|
+
return `browser extensions in this CCC: ${exts.length} (<CCC root>/${EXT_DIR_REL}/):\n` + exts.map((e) => ` · ${e.name}`).join("\n") + `\n\ncall: browser_slot ext --slot b1 --name <name> [--earg key=value … (repeatable)]`;
|
|
23233
23232
|
}
|
|
23234
23233
|
case "ext": {
|
|
23235
23234
|
const n = needSlot(args);
|
|
23236
23235
|
const name = str(args.name);
|
|
23237
|
-
if (!name) return "⛔
|
|
23236
|
+
if (!name) return "⛔ needs --name=<extension> (run ext-list first)";
|
|
23238
23237
|
const res = await slotExt(root, n, sessionId, name, extArgs(args));
|
|
23239
|
-
if (!res.ok) return `⛔
|
|
23238
|
+
if (!res.ok) return `⛔ extension "${name}" failed (${res.code ?? "unknown"}):\n${res.error ?? ""}`;
|
|
23240
23239
|
return typeof res.result === "string" ? res.result : JSON.stringify(res.result ?? null, null, 2);
|
|
23241
23240
|
}
|
|
23242
23241
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shgroup/dsh-serenity-hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.139.0",
|
|
4
4
|
"description": "宁静号 ACC harness(Native Cordis 插件)——给 DeepSeek Harness 装一个「AI 工作区」:13 个工具(container_fs/cognitive_trajectory/dashboard/container_git/msm/praxis/ontology/serenity-skill-creator/localstore/container_admin/browser_slot;另两个 im-bridge/diagram 按条件出现)+ 机械约束(安全模式/工作区围墙/密钥守卫/对外输出守卫)+ 认知轨迹日志与原地重建 + 网页登录入口/IM 桥/认知轨迹唤醒注册表 + 浏览器槽位管理(≤20 个独立 profile 的 Chrome 槽位,带占用归属与异常时向所属会话反向注入提醒)。轨迹声明 = 轨迹目录下的 trajectory.json(约束面 + 旧标识 uid + CRO 机器绑定 cro.host;旧名 trajectory-constraint.json / skiff.json 仍在读取族里);轨迹提示词 = 轨迹目录下的 PROMPT.md(一条轨迹「是谁、按什么章程工作」,所有轨迹通用,追加在容器层与质量层之后,不替换它们)。适配 DSH 0.1.7-rc.1 / 0.2.0-rc.1 / 0.2.1-rc.1(三档)。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|