dsh-browser-cdp 1.7.1-rc.3 → 1.7.1-rc.5

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 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.7.1-rc.3",
5
+ "version": "1.7.1-rc.5",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/client.js CHANGED
@@ -103,7 +103,7 @@ function buildCliRow(input) {
103
103
  id: newLinkId(),
104
104
  label: trimmed(input.label) || cliPath || EGO_CLI_LABEL,
105
105
  cliPath,
106
- useSdkPath: false,
106
+ useSdkPath: true,
107
107
  enabled: true,
108
108
  note: "",
109
109
  probeStatus: "unknown",
@@ -2318,21 +2318,7 @@ function FamLinks(props) {
2318
2318
  }
2319
2319
  writeLinks(updateRow(links, row.id, { endpoint: v }));
2320
2320
  }
2321
- }), isCli ? h("label", { style: {
2322
- display: "flex",
2323
- alignItems: "center",
2324
- gap: "4px",
2325
- fontSize: "11px",
2326
- color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.7))",
2327
- flex: "0 0 auto"
2328
- } }, h(FamSwitch, {
2329
- checked: row.useSdkPath === true,
2330
- writable,
2331
- title: wt("linksCliSdk"),
2332
- onToggle: function(next) {
2333
- writeLinks(updateRow(links, row.id, { useSdkPath: next }));
2334
- }
2335
- }), wt("linksCliSdk")) : null, !isCli && !isLp ? h("button", {
2321
+ }), !isCli && !isLp ? h("button", {
2336
2322
  type: "button",
2337
2323
  disabled: !writable || probingId === row.id,
2338
2324
  style: btnStyle,
package/lib/index.js CHANGED
@@ -1255,7 +1255,7 @@ function coerceLink(raw) {
1255
1255
  kind: EGO_CLI_KIND,
1256
1256
  label: label === "" ? EGO_CLI_LABEL : label,
1257
1257
  cliPath,
1258
- ...rec.useSdkPath === void 0 ? {} : { useSdkPath: Boolean(rec.useSdkPath) }
1258
+ useSdkPath: true
1259
1259
  };
1260
1260
  }
1261
1261
  if (rec.kind === LP_KIND) {
@@ -1335,13 +1335,40 @@ function findLink(links, id) {
1335
1335
  return links.find((link) => link.id === id) ?? null;
1336
1336
  }
1337
1337
  /**
1338
- * The link that currently owns the tools. A disabled entry never wins even if
1339
- * it is still pointed at by `activeTargetId` — its id may be reactivated later
1340
- * without being removed from the sequence.
1338
+ * The link that owns routing RIGHT NOW — re-derived on every links event
1339
+ * (enable/activation toggle, reorder, add, remove).
1340
+ *
1341
+ * Activation wins while it is usable. The moment an event leaves
1342
+ * `activeTargetId` pointing at a disabled or missing entry, the FIRST enabled
1343
+ * link in sequence order takes over — the sequence order IS the priority
1344
+ * order. An EMPTY activation stays "nothing activated" (explicit off) instead
1345
+ * of silently adopting a link the user never activated.
1341
1346
  */
1342
- function activeLink(links, activeTargetId) {
1343
- const link = findLink(links, activeTargetId);
1344
- return link && link.enabled ? link : null;
1347
+ function resolveEffectiveLink(links, activeTargetId) {
1348
+ if (activeTargetId === "") return null;
1349
+ const activated = findLink(links, activeTargetId);
1350
+ if (activated && activated.enabled) return {
1351
+ link: activated,
1352
+ reason: "activated"
1353
+ };
1354
+ const fallback = links.find((link) => link.enabled);
1355
+ if (!fallback) return null;
1356
+ return {
1357
+ link: fallback,
1358
+ reason: "priority-fallback",
1359
+ demotedId: activeTargetId
1360
+ };
1361
+ }
1362
+ /**
1363
+ * True when an attach cache row describes THIS link (same id, and for a cdp
1364
+ * link the same endpoint string). After a links event the async refresh may
1365
+ * still be probing the new owner; a cache row describing the PREVIOUS owner
1366
+ * must not leak its linkKind/cliPath/wsUrl into the new channel's decisions —
1367
+ * that leak is how a deactivated ego-cli kept driving every bcdp_* call.
1368
+ */
1369
+ function attachMatchesLink(attach, link) {
1370
+ if (attach.targetId !== link.id) return false;
1371
+ return link.kind !== "cdp" || attach.endpoint === link.endpoint;
1345
1372
  }
1346
1373
  /**
1347
1374
  * Resolve one endpoint to a browser websocket URL.
@@ -1606,12 +1633,15 @@ async function refreshAttach(input) {
1606
1633
  const now = input.now ?? (() => Date.now());
1607
1634
  const previous = cache.get();
1608
1635
  const suggested = {
1609
- ...previous,
1636
+ ...emptyAttachState(),
1610
1637
  mode: input.mode,
1611
1638
  status: input.mode === "local" ? "local" : "idle",
1612
- wsUrl: input.mode === "local" ? "" : previous.wsUrl,
1613
- code: "",
1614
- message: ""
1639
+ linkKind: void 0,
1640
+ cliPath: void 0,
1641
+ cliShape: void 0,
1642
+ sdkPath: "",
1643
+ endpointSource: void 0,
1644
+ engine: void 0
1615
1645
  };
1616
1646
  if (input.mode === "local") {
1617
1647
  suggested.targetId = "";
@@ -1658,7 +1688,7 @@ async function refreshAttach(input) {
1658
1688
  }
1659
1689
  return cache.patch(suggested);
1660
1690
  }
1661
- const target = activeLink(input.targets, input.activeTargetId);
1691
+ const target = resolveEffectiveLink(input.targets, input.activeTargetId)?.link ?? null;
1662
1692
  if (!target) return cache.patch({
1663
1693
  ...suggested,
1664
1694
  status: "no-active",
@@ -1666,7 +1696,7 @@ async function refreshAttach(input) {
1666
1696
  endpoint: "",
1667
1697
  wsUrl: "",
1668
1698
  code: input.remoteEnabled === false ? "remote-disabled" : "no-active-target",
1669
- message: input.remoteEnabled === false ? "remote CDP is disabled by the remoteEnabled switch; the target sequence is preserved and can be re-enabled at any time" : "no activated target in the sequence",
1699
+ message: input.remoteEnabled === false ? "remote CDP is disabled by the remoteEnabled switch; the target sequence is preserved and can be re-enabled at any time" : input.activeTargetId === "" ? "no activated target in the sequence" : "the activated entry is disabled or gone and no enabled link can take over; enable a link, activate one, or set cdpMode=local",
1670
1700
  resolvedAt: now()
1671
1701
  });
1672
1702
  if (input.remoteEnabled === false && target.kind !== EGO_CLI_KIND && target.kind !== LP_KIND) return cache.patch({
@@ -1702,6 +1732,7 @@ async function refreshAttach(input) {
1702
1732
  status: "ready",
1703
1733
  wsUrl: outcome.wsUrl,
1704
1734
  engine: outcome.engine,
1735
+ endpointSource: "remote",
1705
1736
  code: "",
1706
1737
  message: "",
1707
1738
  latencyMs: outcome.latencyMs,
@@ -2677,7 +2708,7 @@ const Config$1 = z.object({
2677
2708
  id: z.string(),
2678
2709
  label: z.string(),
2679
2710
  cliPath: z.string(),
2680
- useSdkPath: z.boolean(),
2711
+ useSdkPath: z.boolean().description("Deprecated: ALWAYS treated as true since v1.7.1-rc.5 — the native ego CLI has no taskSpaces facade, so without the bundled harness every call fails. Kept in the row shape so old profiles still validate; a stored false is healed on read."),
2681
2712
  enabled: z.boolean(),
2682
2713
  note: z.string(),
2683
2714
  probeStatus: z.union([
@@ -2717,8 +2748,8 @@ const Config$1 = z.object({
2717
2748
  "unknown"
2718
2749
  ])
2719
2750
  })
2720
- ])).description("Ordered connection sequence: CDP endpoints and (at most one) local ego CLI link. Only the ACTIVATED and enabled entry receives every bcdp_* call. Order IS the priority order.").volatile(),
2721
- activeTargetId: z.string().description("Id of the activated entry in links. Empty = nothing activated.").volatile(),
2751
+ ])).description("Ordered connection sequence: CDP endpoints and (at most one) local ego CLI link. The ACTIVATED entry receives every bcdp_* call; if the activation points at a disabled or removed entry, the FIRST enabled link in this order takes over (logged and shown by bcdp_doctor). Order IS the priority order.").volatile(),
2752
+ activeTargetId: z.string().description("Id of the activated entry in links. Empty = nothing activated (no silent adoption). A disabled/removed entry here falls back to the first enabled link in order.").volatile(),
2722
2753
  cdpMode: cdpMode.description("auto = use the activated target and never start a local browser silently; remote = only ever connect to the activated target; local = always use local browser control.").volatile(),
2723
2754
  cdpProbeTimeoutMs: z.number().min(200).max(3e4).step(100).description("Timeout for one CDP endpoint probe (http endpoints answer /json/version)."),
2724
2755
  cursorHud: z.boolean().description("Draw the agent cursor HUD into screenshots."),
@@ -7421,21 +7452,37 @@ function resolveEgoEnv(cfg, { platform = process.platform, baseEnv = process.env
7421
7452
  return env;
7422
7453
  }
7423
7454
  /**
7455
+ * The channel that owns routing right now: `resolveEffectiveLink` over the
7456
+ * CURRENT config (activation first, sequence order as the visible fallback),
7457
+ * plus the attach cache SCOPED to that link. After any links event
7458
+ * (enable/activation toggle, reorder, add, remove) the async refresh may still
7459
+ * be probing; a cache row describing the PREVIOUS owner must not leak its
7460
+ * linkKind/cliPath/wsUrl into the new channel's spawn decisions.
7461
+ */
7462
+ function effectiveChannel(cfg) {
7463
+ const effective = resolveEffectiveLink(cfg.links ?? [], cfg.activeTargetId ?? "");
7464
+ const live = defaultAttachCache.get();
7465
+ return {
7466
+ effective,
7467
+ attach: effective && attachMatchesLink(live, effective.link) ? live : emptyAttachState()
7468
+ };
7469
+ }
7470
+ /**
7424
7471
  * Read the attach decision for the CURRENTLY configured mode/activation.
7425
- * Pure over (cfg, cache) �?the decision table itself lives in cdp-targets.ts.
7472
+ * Pure over (cfg, cache) — the decision table itself lives in cdp-targets.ts.
7426
7473
  */
7427
7474
  function decideCdpAttach(cfg) {
7428
- const attach = defaultAttachCache.get();
7475
+ const { effective, attach } = effectiveChannel(cfg);
7429
7476
  return decideAttach({
7430
7477
  mode: cfg?.cdpMode ?? "auto",
7431
- hasActive: attach.status !== "no-active" && attach.targetId !== "",
7478
+ hasActive: effective !== null,
7432
7479
  status: attach.status,
7433
7480
  wsUrl: attach.wsUrl,
7434
7481
  code: attach.code,
7435
7482
  message: attach.message,
7436
7483
  allowLocalFallback: Boolean(cfg?.allowLocalFallback),
7437
- remoteDisabled: attach.code === "remote-disabled",
7438
- ...attach.linkKind ? { linkKind: attach.linkKind } : {},
7484
+ remoteDisabled: cfg?.remoteEnabled === false,
7485
+ ...effective ? { linkKind: effective.link.kind } : {},
7439
7486
  localLauncherReady: true
7440
7487
  });
7441
7488
  }
@@ -7527,7 +7574,7 @@ async function openAgentWindow(ctx, cfg) {
7527
7574
  ok: false,
7528
7575
  error: gate
7529
7576
  };
7530
- if (defaultAttachCache.get().linkKind === EGO_CLI_KIND) {
7577
+ if (effectiveChannel(cfg).effective?.link.kind === EGO_CLI_KIND) {
7531
7578
  ctx.logger?.info?.("dsh-browser-cdp: ego-cli: browser already visible, skipping --open");
7532
7579
  return { ok: true };
7533
7580
  }
@@ -7759,7 +7806,7 @@ function buildEgoToolArgv(prefix, attach, runtimeArgs) {
7759
7806
  async function runEgoScript(subprocess, script, exec, cfg, graceOverrideMs) {
7760
7807
  let handle;
7761
7808
  try {
7762
- const attach = defaultAttachCache.get();
7809
+ const { attach } = effectiveChannel(cfg);
7763
7810
  handle = subprocess.spawn({
7764
7811
  argv: buildEgoToolArgv(cfg.egoArgvPrefix, attach, cfg.runtimeArgs ?? ""),
7765
7812
  cwd: process.cwd(),
@@ -8083,8 +8130,8 @@ function apply(ctx, config = {}) {
8083
8130
  return sanitizeLinks(raw.links ?? raw.cdpTargets).droppedEgoCli;
8084
8131
  },
8085
8132
  get egoArgvPrefix() {
8086
- const attach = defaultAttachCache.get();
8087
- if (attach.linkKind === EGO_CLI_KIND && attach.cliPath) return spawnArgvFor(attach.cliShape === "node" ? "node" : "direct", attach.cliPath, []);
8133
+ const { effective, attach } = effectiveChannel(this);
8134
+ if (effective?.link.kind === EGO_CLI_KIND && attach.cliPath) return spawnArgvFor(attach.cliShape === "node" ? "node" : "direct", attach.cliPath, []);
8088
8135
  return [process.execPath, this.egoBin];
8089
8136
  },
8090
8137
  get activeTargetId() {
@@ -8299,6 +8346,8 @@ function apply(ctx, config = {}) {
8299
8346
  let pending = false;
8300
8347
  /** Last ws handed to the worker; a differ means the browser was relaunched. */
8301
8348
  let lastAttachWs = null;
8349
+ /** Last channel owner (id|reason); a differ is logged so takeovers are visible. */
8350
+ let lastOwnerKey = null;
8302
8351
  /** True when this pass actually moved the resolved endpoint. */
8303
8352
  let changed = false;
8304
8353
  const run = async () => {
@@ -8310,6 +8359,12 @@ function apply(ctx, config = {}) {
8310
8359
  changed = false;
8311
8360
  try {
8312
8361
  const resolved = resolveConfig(bridge.source());
8362
+ const owner = resolveEffectiveLink(resolved.links, resolved.activeTargetId);
8363
+ const ownerKey = owner ? `${owner.link.id}|${owner.reason}` : "none";
8364
+ if (ownerKey !== lastOwnerKey) {
8365
+ lastOwnerKey = ownerKey;
8366
+ ctx.logger?.info?.(owner ? `dsh-browser-cdp: channel owner: ${owner.link.label} [${owner.link.id}] (${owner.reason}${owner.demotedId ? `, over ${owner.demotedId}` : ""})` : "dsh-browser-cdp: channel owner: none (no enabled link owns routing)");
8367
+ }
8313
8368
  const attach = await refreshAttach({
8314
8369
  targets: resolved.links,
8315
8370
  activeTargetId: resolved.activeTargetId,
@@ -8394,7 +8449,7 @@ function apply(ctx, config = {}) {
8394
8449
  const last = getLastEgoActivity();
8395
8450
  if (!shouldReapBrowser(Date.now(), last, cfg.idleTimeoutMin)) return;
8396
8451
  if (last <= reapedFor) return;
8397
- if (defaultAttachCache.get().linkKind === EGO_CLI_KIND) {
8452
+ if (effectiveChannel(cfg).effective?.link.kind === EGO_CLI_KIND) {
8398
8453
  reapedFor = last;
8399
8454
  ctx.logger?.info?.("dsh-browser-cdp: idle reaper skipped: ego-cli owns the user's browser (never --stop it)");
8400
8455
  return;
@@ -8441,7 +8496,7 @@ function apply(ctx, config = {}) {
8441
8496
  }, "dsh-browser-cdp: idle reaper");
8442
8497
  ctx.effect?.(() => {
8443
8498
  try {
8444
- if (defaultAttachCache.get().linkKind === EGO_CLI_KIND) {
8499
+ if (effectiveChannel(cfg).effective?.link.kind === EGO_CLI_KIND) {
8445
8500
  ctx.logger?.info?.("dsh-browser-cdp: teardown skipped --stop: ego-cli owns the user's browser");
8446
8501
  return;
8447
8502
  }
@@ -8503,7 +8558,7 @@ function registerEgoStatus(ctx, cfg, reg, tiers) {
8503
8558
  tiers.pulse(callingSessionId(exec));
8504
8559
  return withEgoLock(async () => {
8505
8560
  try {
8506
- const attach = defaultAttachCache.get();
8561
+ const { attach } = effectiveChannel(cfg);
8507
8562
  const handle = ctx.subprocess.spawn({
8508
8563
  argv: buildEgoToolArgv(cfg.egoArgvPrefix, attach, cfg.runtimeArgs ?? ""),
8509
8564
  cwd: process.cwd(),
@@ -9549,6 +9604,8 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9549
9604
  const chrArgs = filterArgs(cfg.chromeArgs ?? "", CHROME_BLOCKED);
9550
9605
  lines.push(`runtimeArgs (effective): ${cliArgs.length ? cliArgs.join(" ") : "(none)"}`);
9551
9606
  const attachNow = defaultAttachCache.get();
9607
+ const channel = effectiveChannel(cfg);
9608
+ lines.push(`channel: ${channel.effective ? `${channel.effective.link.label} [${channel.effective.link.id}] (${channel.effective.reason}${channel.effective.demotedId ? `, over ${channel.effective.demotedId}` : ""})` : "(none — activate a link or enable one)"}`);
9552
9609
  lines.push(`remote CDP: ${cfg.remoteEnabled === false ? "DISABLED by switch (sequence preserved)" : "enabled"}`);
9553
9610
  lines.push(`attach: ${attachNow.status}${attachNow.endpointSource ? ` (source: ${attachNow.endpointSource})` : ""}${attachNow.endpoint ? ` @ ${attachNow.endpoint}` : ""}`);
9554
9611
  if (attachNow.engine !== void 0) lines.push(`engine: ${attachNow.engine}`);
@@ -9763,7 +9820,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9763
9820
  * must say so rather than failing later with a confusing worker error.
9764
9821
  */
9765
9822
  const effectsOf = (judge, onFrame) => {
9766
- const attach = defaultAttachCache.get();
9823
+ const { attach } = effectiveChannel(cfg);
9767
9824
  return makeJudgeEffects({
9768
9825
  subprocess: ctx.subprocess,
9769
9826
  workerPath: RENDER_WORKER_BIN,
@@ -9782,7 +9839,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9782
9839
  };
9783
9840
  /** The browser must be attached before any frame exists. Shared by 3 tools. */
9784
9841
  const attachGate = () => {
9785
- const attach = defaultAttachCache.get();
9842
+ const { attach } = effectiveChannel(cfg);
9786
9843
  if (attach.wsUrl === "") return `no live browser: the activated link has no CDP endpoint yet. Run bcdp_status (or bcdp_doctor) to attach, then retry. (attach status=${attach.status}${attach.code === "" ? "" : `, code=${attach.code}`})`;
9787
9844
  return "";
9788
9845
  };
@@ -9813,7 +9870,7 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
9813
9870
  markEgoToolCall(callingSessionId(exec));
9814
9871
  const judge = judgeCfg();
9815
9872
  const runtime = judgeRuntimeOf();
9816
- const attach = defaultAttachCache.get();
9873
+ const { attach } = effectiveChannel(cfg);
9817
9874
  const lines = [
9818
9875
  "judgement chain (priority order):",
9819
9876
  ...describeJudge(runtime),
@@ -10323,4 +10380,4 @@ function registerHelpAndDoctor(ctx, cfg, reg, tiers) {
10323
10380
  }
10324
10381
 
10325
10382
  //#endregion
10326
- export { ATTACH_SESSION_HINT, CDP_CONNECT_FAIL_RE, 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 };
10383
+ export { ATTACH_SESSION_HINT, CDP_CONNECT_FAIL_RE, Config, GLOBAL_SESSION_KEY, STATUS_FACADE_SCRIPT, STATUS_FACADE_SENTINEL, TAB_STUCK_RE, apply, attachSessionHint, buildEgoToolArgv, cdpAttachError, createActiveSpaceTracker, createSessionSpaceTracker, decideCdpAttach, deriveSlotDefaultName, effectiveChannel, 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.7.1-rc.3",
3
+ "version": "1.7.1-rc.5",
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",
@@ -104,6 +104,6 @@
104
104
  },
105
105
  "publishConfig": {
106
106
  "registry": "https://registry.npmjs.org",
107
- "tag": "dsh-1.1.0"
107
+ "tag": "dsh-0.2.1-rc.3"
108
108
  }
109
109
  }