dsh-browser-cdp 1.5.0 → 1.6.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 CHANGED
@@ -274,12 +274,21 @@ wait / space / escape 三族已按 `op` 合并,旧工具名**移除**(不保
274
274
 
275
275
  > 取舍提醒:窄工具(一个动作一个工具)是模型写对参数、少重试的护栏。1.5.0 只合并了 **wait / space / escape** 三族同源冗余(41 → 34,省 1,869 字符 schema):五个 wait 共用同一 preamble 与 timeout 语义、三个 space 本就是同一个 op 工具的碎片、cli/script 是同一 heredoc 运行时。代价是这三族的旧工具名不再存在(见上方迁移表);交互原子(click/fill/key…)**不合并**,因为它们是模型写对参数的护栏。
276
276
 
277
- ## 任务空间命名与并发隔离(1.4.1)
277
+ ## 任务空间命名与并发隔离(1.6.0)
278
278
 
279
- - **默认空间名统一为 `default`**:代码常量 `DEFAULT_SPACE='default'`、`bcdp_space` 的 `op=open` 描述、`Config.defaultSpace` 三者一致。持久化 Profile 模式(默认)下**始终复用这一个具名槽**——登录态、tab、stream 跨会话保留;不要因为"当前在做任务 X"就另开编号空间(`#4`/`#5`),那会丢持久化。
280
- - **`defaultSpace` 可配(A)**:`Config.defaultSpace` 是 volatile 标量,留空折叠为 `'default'`,热更新不重注册。注意区分两个概念:配置值 `cfg.defaultSpace`(schema 里那个)和运行时的**当前会话活值** `cfg.activeSpace`(命令实际用的 `useSpace(...)` 入参);前者是设置,后者随会话切换。
279
+ > **默认就是会话隔离**:不传 `space` 的调用落在**本会话自己的**任务空间 `dsh-agent-<会话id前8位>`,两个会话永远不会共用或抢占同一个浏览上下文。**只有显式写 `space: 'default'`(或 `bcdp_space op=open name='default'`)才会用那个跨会话共享的具名槽。**
280
+
281
+ | 你怎么写 | 落到哪个空间 |
282
+ |---|---|
283
+ | 省略 `space`(默认,`defaultSpace` 未设 = `:auto`) | `dsh-agent-<会话id前8位>`,每会话独立 |
284
+ | `space: 'default'` / `op=open name='default'` | 共享具名槽 `default`(此后该会话固定用它) |
285
+ | `defaultSpace: 'default'`(配置项改成具名) | 所有会话默认都用 `default`(退回旧行为,全局生效) |
286
+ | 无 session 的调用(`__global__`) | `default`,保证向后兼容 |
287
+
288
+ - **`defaultSpace`(A)**:volatile 标量,**留空/缺失折叠为 `:auto`**(1.6.0 起,此前折叠为 `default`),热更新不重注册。注意区分两个概念:配置值 `cfg.defaultSpace`(schema 里那个,可以是 `:auto` 或具名)与运行时**当前会话活值** `cfg.activeSpace`(命令实际用的 `useSpace(...)` 入参);前者是设置,后者随会话与显式选择切换。
289
+ - **`:auto` 派生(C)**:`:auto` 在**两种模式**下都派生 `dsh-agent-<sid8>` —— 空间**命名**与 `isolateSpaces`(那个只管 Profile 落盘还是内存沙箱)是两条独立的轴。会话 id 会先剥掉 `session-` 前缀再取 8 位:真实 DSH id 形如 `session-52adc205-…`,直接 `slice(0,8)` 会得到 `session-`,让**所有会话撞成同一个空间**——这正是隔离失效的经典坑,已用 `sessionSpaceToken()` 修掉并有回归测试。
281
290
  - **会话级隔离(B)**:活动空间追踪器按 `sessionId` 键控成一张槽位表(`Map<string,Slot>`,无 session 的调用落 `__global__` 槽保持向后兼容)。每个 `bcdp_*` 调用一进来就 `setCurrentSession(callingSessionId(exec))`,所以**并发多会话各开各的空间互不漂移**——A 会话重启空间不波及 B。
282
- - **`:auto` 哨兵(C)**:沙箱模式(`isolateSpaces:true`)下默认名派生为 `dsh-agent-<sessionId 前 8 位>`,给每个会话一个独立命名空间;持久模式下 `:auto` 折叠为具名单槽 `default`。`resolveConfig` 把 `:auto` 原样保留,由追踪器据 sessionId + 模式决定真正落点。
291
+ - **不要再手动建编号空间**:不需要 `#4`/`#5` 这类手工命名,隔离已经由会话派生自动完成;需要共享就走显式 `default`。
283
292
 
284
293
  ### 跨调用稳定定位(D1)
285
294
 
package/dsh-plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
3
3
  "id": "dsh-browser-cdp",
4
4
  "name": "dsh-browser-cdp",
5
- "version": "1.5.0",
5
+ "version": "1.6.0",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/index.js CHANGED
@@ -2620,7 +2620,7 @@ const encoder = z.union([
2620
2620
  ]);
2621
2621
  const Config$1 = z.object({
2622
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(),
2623
+ defaultSpace: z.string().description("Task space used when an bcdp_* call omits `space`. Default `:auto` = derive a per-session space `dsh-agent-<sessionId8>`, so concurrent sessions never share or hijack each other's browsing context. Set a fixed name (e.g. `default`) to reuse ONE shared slot across sessions — pass `space: \"default\"` on a single call for the same effect. Note this only names spaces; whether the browser profile itself persists is controlled by isolateSpaces.").volatile(),
2624
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(),
2625
2625
  chromePath: z.string().description("Path to Chrome/Chromium. Empty = auto-detect.").volatile(),
2626
2626
  captureBackend: backend.description("Capture backend: auto, cdp, or ffmpeg.").volatile(),
@@ -2967,7 +2967,7 @@ function resolveConfig(config = {}) {
2967
2967
  runtimeArgs: typeof config.runtimeArgs === "string" ? config.runtimeArgs : typeof config.egoCliArgs === "string" ? config.egoCliArgs : "",
2968
2968
  chromeArgs: typeof config.chromeArgs === "string" ? config.chromeArgs : "",
2969
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",
2970
+ defaultSpace: typeof config.defaultSpace === "string" && config.defaultSpace.trim() !== "" ? config.defaultSpace.trim() : AUTO_SPACE_SENTINEL,
2971
2971
  idleTimeoutMin: finiteIn(config.idleTimeoutMin, 0, 1440) ? config.idleTimeoutMin : 0,
2972
2972
  links: sanitizeLinks(config.links ?? config.cdpTargets).links.map(normalizeProbeState),
2973
2973
  activeTargetId: typeof config.activeTargetId === "string" ? config.activeTargetId : "",
@@ -7159,20 +7159,52 @@ function createActiveSpaceTracker(defaultSpace = DEFAULT_SPACE) {
7159
7159
  }
7160
7160
  const GLOBAL_SESSION_KEY = "__global__";
7161
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.
7162
+ * C — resolve the fallback slot name for a session.
7163
+ *
7164
+ * v1.6.0 — SESSION ISOLATION IS THE DEFAULT. `defaultSpace` ships as `:auto`,
7165
+ * so a call that omits `space` lands in a per-session task space
7166
+ * `dsh-agent-<sid8>` instead of the shared `default` slot. The sentinel is
7167
+ * honoured regardless of `isolateSpaces`, because space NAMING and PROFILE
7168
+ * persistence are two different axes: `isolateSpaces` only decides whether the
7169
+ * browser profile lives on disk or in an in-memory sandbox.
7170
+ *
7171
+ * A caller that deliberately wants the shared slot sets `defaultSpace` to a
7172
+ * named value (e.g. `default`) or passes `space: 'default'` on a call — the
7173
+ * tracker then pins that session to it. Calls carrying NO session id always
7174
+ * fall back to the named shared slot so pre-existing behaviour keeps working.
7175
+ * Any other configured value passes through verbatim.
7166
7176
  * @internal exported for tests
7167
7177
  */
7168
7178
  function deriveSlotDefaultName(rc, sessionKey) {
7169
7179
  const name$1 = rc.defaultSpace;
7170
7180
  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);
7181
+ if (sessionKey === GLOBAL_SESSION_KEY) return DEFAULT_SPACE;
7182
+ return AUTO_SPACE_PREFIX + sessionSpaceToken(sessionKey);
7173
7183
  }
7174
7184
  return name$1;
7175
7185
  }
7186
+ /**
7187
+ * A stable, space-name-safe 8-char token for a DSH session id.
7188
+ *
7189
+ * DSH session ids look like `session-52adc205-3251-…`, so the old
7190
+ * `slice(0, 8)` yielded the literal `session-` for EVERY session — silently
7191
+ * collapsing all sessions into one space, i.e. exactly the failure this
7192
+ * feature exists to prevent. The known prefix is stripped and
7193
+ * hyphens kept, other non-alphanumerics dropped, then sliced to 8; a short id
7194
+ * is used as-is (still unique), and only a degenerate/empty id falls back to a
7195
+ * deterministic FNV-1a hash so the name is never empty.
7196
+ * @internal exported for tests
7197
+ */
7198
+ function sessionSpaceToken(sessionId) {
7199
+ const bare = sessionId.replace(/^session-/, "").replace(/[^A-Za-z0-9-]/g, "");
7200
+ if (bare.length > 0) return bare.slice(0, 8);
7201
+ let h = 2166136261;
7202
+ for (let i = 0; i < sessionId.length; i += 1) {
7203
+ h ^= sessionId.charCodeAt(i);
7204
+ h = Math.imul(h, 16777619) >>> 0;
7205
+ }
7206
+ return h.toString(16).padStart(8, "0").slice(0, 8);
7207
+ }
7176
7208
  function createSessionSpaceTracker(defaultNameFor = () => DEFAULT_SPACE) {
7177
7209
  const slots = /* @__PURE__ */ new Map();
7178
7210
  let sessionKey = GLOBAL_SESSION_KEY;
@@ -8531,7 +8563,7 @@ function registerActionTools(ctx, cfg, reg) {
8531
8563
  };
8532
8564
  reg(t({
8533
8565
  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.",
8566
+ description: "Task space: op=open (or reuse) | close | list | handoff | takeover. Omitting `space` targets THIS session's own space (dsh-agent-<sessionId8>), so concurrent sessions never share or hijack each other's browsing context — this is the default and needs no setup. To reuse ONE shared slot across sessions, pass `space: 'default'` (or op=open with name='default') deliberately; do NOT create numbered spaces like #4/#5. The browser profile (logins) persists on disk across restarts unless isolateSpaces is on; if a page needs login, prompt the user to log in manually. handoff yields control to the human (stop driving until they hand back); takeover resumes agent control.",
8535
8567
  parameters: {
8536
8568
  op: {
8537
8569
  type: "string",
@@ -8540,7 +8572,7 @@ function registerActionTools(ctx, cfg, reg) {
8540
8572
  },
8541
8573
  name: {
8542
8574
  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."
8575
+ description: "op=open/close: task-space name. Omit to use this session's own space (dsh-agent-<sessionId8>); pass 'default' only when you deliberately want the ONE shared slot. op=handoff/takeover: default = this session's space."
8544
8576
  },
8545
8577
  keep: {
8546
8578
  type: "boolean",
@@ -10127,4 +10159,4 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
10127
10159
  }
10128
10160
 
10129
10161
  //#endregion
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 };
10162
+ 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, sessionSpaceToken, shouldReapBrowser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "dsh-browser-cdp: DSH browser plugin — attach to a running Chrome/Edge over CDP (no bundled browser needed); structured browser-automation tools (30+ bcdp_*) that drive the vendored ego runtime through ctx.subprocess, plus a realtime watch panel (live SSE screencast + direct mouse interaction + download capture + human-verification notice). Web shell: floating watch panel without dsh-better-sidebar, sidebar tab with it. Headless/TUI hosts: tools-only. [DSH 0.1.7-rc.1 ~ 0.2.1-rc.1 line (exact rc enumeration): declarative settings via Config .volatile() fields; for DSH 0.1.2-rc.1 ~ 0.1.5-rc.3 use the 0.17.x line]",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",