@ait-co/devtools 0.1.120 → 0.1.121

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { $ as buildDeepLinkAttachUrl, A as isDebugToolName, B as readServerLock, C as getDiagnostics, D as getSdkCallHistory, E as getOperationalEnvironment, F as listPages, G as logWarn, H as isRelayEnv, I as measureSafeArea, J as pageCrashError, K as classifyToolError, L as takeScreenshot, M as listConsoleMessages, N as listExceptions, O as getToolAvailability, P as listNetworkRequests, Q as tierRejectionError, R as takeSnapshot, S as filterToolsByEnvironment, T as getMockState, U as logError, V as deriveEnvironment, W as logInfo, X as relayDisconnectError, Y as pageMissingError, Z as sdkAbsentError, _ as BOOTSTRAP_TOOL_NAMES, b as callSdk, et as buildLauncherAttachUrl, f as generateAttachToken, g as startTunnelHealthProbe, h as startQuickTunnel, j as isToolAvailableIn, k as isAitToolName, l as prepareAttach, m as printAttachBanner, nt as startParentWatcher, p as makeTunnelStatus, q as mcpError, s as isSandboxPageFresh, t as RELAY_SANDBOX_STALE_PAGE_MS, tt as startMaxAgeWatchdog, u as renderAndMaybeWait, v as DEBUG_TOOL_DEFINITIONS, w as getDomDocument, x as evaluate, y as InMemoryDiagnosticsCollector, z as acquireLock } from "./attach-orchestrator-BJr41GN8.js";
2
+ import { $ as buildDeepLinkAttachUrl, A as isDebugToolName, B as readServerLock, C as getDiagnostics, D as getSdkCallHistory, E as getOperationalEnvironment, F as listPages, G as logWarn, H as isRelayEnv, I as measureSafeArea, J as pageCrashError, K as classifyToolError, L as takeScreenshot, M as listConsoleMessages, N as listExceptions, O as getToolAvailability, P as listNetworkRequests, Q as tierRejectionError, R as takeSnapshot, S as filterToolsByEnvironment, T as getMockState, U as logError, V as deriveEnvironment, W as logInfo, X as relayDisconnectError, Y as pageMissingError, Z as sdkAbsentError, _ as BOOTSTRAP_TOOL_NAMES, b as callSdk, et as buildLauncherAttachUrl, f as generateAttachToken, g as startTunnelHealthProbe, h as startQuickTunnel, j as isToolAvailableIn, k as isAitToolName, l as prepareAttach, m as printAttachBanner, nt as startParentWatcher, p as makeTunnelStatus, q as mcpError, s as isSandboxPageFresh, t as RELAY_SANDBOX_STALE_PAGE_MS, tt as startMaxAgeWatchdog, u as renderAndMaybeWait, v as DEBUG_TOOL_DEFINITIONS, w as getDomDocument, x as evaluate, y as InMemoryDiagnosticsCollector, z as acquireLock } from "./attach-orchestrator-DPMBN06p.js";
3
3
  import { i as generateTotp, n as assertRelayAuthConfigured, r as buildRelayVerifyAuth } from "./totp-0bvlo9Yb.js";
4
- import { n as injectGlobals, t as injectDebugIndicator } from "./cell-BCNQJ_cS.js";
4
+ import { n as injectGlobals, t as injectDebugIndicator } from "./cell-Cj-u6JTG.js";
5
5
  import { n as loadRelaySecretReadOnly } from "./relay-secret-store-CmDDfZMh.js";
6
6
  import { createRequire } from "node:module";
7
7
  import { accessSync, existsSync } from "node:fs";
@@ -175,8 +175,8 @@ function createRelayConnectionFactory(opts) {
175
175
  let family;
176
176
  return {
177
177
  async open() {
178
- const { prepareAttach, renderAndMaybeWait } = await import("./attach-orchestrator-BbCfcfT0.js");
179
- const { injectDebugIndicator, injectGlobals } = await import("./cell-CJcDstzr.js");
178
+ const { prepareAttach, renderAndMaybeWait } = await import("./attach-orchestrator-BTsEHXfq.js");
179
+ const { injectDebugIndicator, injectGlobals } = await import("./cell-Bca_k5ne.js");
180
180
  const { loadRelaySecretReadOnly } = await import("./relay-secret-store-BlFEhqwb.js");
181
181
  const { bootRelayFamily, buildRelayVerifyAuth } = await Promise.resolve().then(() => debug_server_exports);
182
182
  await loadRelaySecretReadOnly({ projectRoot });
@@ -4238,7 +4238,7 @@ function createDebugServer(deps) {
4238
4238
  };
4239
4239
  const server = new Server({
4240
4240
  name: "ait-debug",
4241
- version: "0.1.120"
4241
+ version: "0.1.121"
4242
4242
  }, { capabilities: { tools: { listChanged: true } } });
4243
4243
  server.setRequestHandler(ListToolsRequestSchema, () => {
4244
4244
  const conn = router.active;
@@ -4644,15 +4644,23 @@ function errorResult(err, name, isLocal = false) {
4644
4644
  * `connection.listTargets()` and sends a `notifications/tools/list_changed`
4645
4645
  * notification on the given server.
4646
4646
  *
4647
- * The watcher polls every `intervalMs` (default 1 000 ms). It fires
4648
- * `server.sendToolListChanged()` + `onAttach()` whenever the sorted target-id
4649
- * signature changes AND the new target set is non-empty. This covers:
4647
+ * The watcher polls every `intervalMs` (default 1 000 ms). On each tick it
4648
+ * calls `connection.refreshTargets?.()` first (fix #705-B) so that silent
4649
+ * disconnects (no CDP event, phone backgrounded / tunnel quiet) are picked up
4650
+ * before the signature is read. If `refreshTargets` throws — e.g. a transient
4651
+ * relay error — the tick is skipped entirely to avoid a spurious detach signal.
4652
+ *
4653
+ * After the refresh, it fires `server.sendToolListChanged()` + `onAttach()`
4654
+ * whenever the sorted target-id signature changes AND the new target set is
4655
+ * non-empty. This covers:
4650
4656
  * - 0→N first attach
4651
4657
  * - 1→1 target replacement (same count, different id — e.g. rescan)
4652
4658
  * - N→M any change where the result is still non-empty
4653
4659
  *
4654
- * Full detach (→ empty) updates the stored signature but does NOT fire the
4655
- * callback`onAttach` semantics are about a live target being present.
4660
+ * Full detach (→ empty) fires `onDetach()` (fix #705-A) on the exact
4661
+ * non-empty→empty edge i.e. only when the previous signature was non-empty.
4662
+ * This lets callers push an immediate "disconnected" SSE update to the
4663
+ * dashboard without waiting for the next periodic interval.
4656
4664
  *
4657
4665
  * The interval is **never cleared automatically** — it keeps running until
4658
4666
  * `stop()` is called during shutdown. This ensures that a target replacement
@@ -4660,15 +4668,15 @@ function errorResult(err, name, isLocal = false) {
4660
4668
  *
4661
4669
  * `onAttach` is called on every non-empty signature change (or immediately when
4662
4670
  * already attached). Use this to trigger side-effects such as pushing a fresh
4663
- * SSE state to open dashboard tabs (issue #509). The callback is optional;
4664
- * omitting it preserves the previous behaviour exactly.
4671
+ * SSE state to open dashboard tabs (issue #509). Both callbacks are optional;
4672
+ * omitting them preserves the previous behaviour exactly.
4665
4673
  *
4666
4674
  * SECRET-HANDLING: target `id`/`title`/`url` are not written to any log here.
4667
4675
  * Only an attach-detected stderr line is emitted (no target details).
4668
4676
  *
4669
4677
  * @returns `stop` — call this during shutdown to clear the interval.
4670
4678
  */
4671
- function startAttachWatcher(connection, server, intervalMs = 1e3, onAttach) {
4679
+ function startAttachWatcher(connection, server, intervalMs = 1e3, onAttach, onDetach) {
4672
4680
  /** Sorted, comma-joined target-id string — '' means no targets attached. */
4673
4681
  function signature() {
4674
4682
  return connection.listTargets().map((t) => t.id).sort().join(",");
@@ -4678,15 +4686,23 @@ function startAttachWatcher(connection, server, intervalMs = 1e3, onAttach) {
4678
4686
  server.sendToolListChanged();
4679
4687
  onAttach?.();
4680
4688
  }
4681
- const handle = setInterval(() => {
4689
+ /** Compare current vs last signature and fire the appropriate callback. */
4690
+ function tick() {
4682
4691
  const current = signature();
4683
4692
  if (current !== lastSignature) {
4693
+ const wasNonEmpty = lastSignature !== "";
4684
4694
  lastSignature = current;
4685
4695
  if (current !== "") {
4686
4696
  server.sendToolListChanged();
4687
4697
  onAttach?.();
4688
- }
4698
+ } else if (wasNonEmpty) onDetach?.();
4689
4699
  }
4700
+ }
4701
+ const handle = setInterval(() => {
4702
+ if (connection.refreshTargets) connection.refreshTargets().then(() => {
4703
+ tick();
4704
+ }, (_err) => {});
4705
+ else tick();
4690
4706
  }, intervalMs);
4691
4707
  return { stop() {
4692
4708
  clearInterval(handle);
@@ -5073,6 +5089,8 @@ var DualConnectionRouter = class {
5073
5089
  env
5074
5090
  });
5075
5091
  }
5092
+ }, () => {
5093
+ this.deps.onPageDetach?.();
5076
5094
  });
5077
5095
  }
5078
5096
  /**
@@ -5174,6 +5192,7 @@ async function runDebugServer(options = {}) {
5174
5192
  diagnosticsCollector,
5175
5193
  devtoolsOpener,
5176
5194
  onPageAttach: () => qrServer?.notifyStateChange(),
5195
+ onPageDetach: () => qrServer?.notifyStateChange(),
5177
5196
  getInspectorStableUrl: () => qrServer?.inspectorStableUrl ?? null,
5178
5197
  readSandboxRelayUrl: (pr) => readMobileRelayBaseUrl(process.env, pr).catch(() => null)
5179
5198
  });
@@ -5388,6 +5407,7 @@ async function runLocalDebugServer(options = {}) {
5388
5407
  diagnosticsCollector,
5389
5408
  devtoolsOpener,
5390
5409
  onPageAttach: () => qrServer?.notifyStateChange(),
5410
+ onPageDetach: () => qrServer?.notifyStateChange(),
5391
5411
  getInspectorStableUrl: () => qrServer?.inspectorStableUrl ?? null,
5392
5412
  readSandboxRelayUrl: (pr) => readMobileRelayBaseUrl(process.env, pr).catch(() => null)
5393
5413
  });
@@ -5584,6 +5604,7 @@ async function runMobileDebugServer(options = {}) {
5584
5604
  diagnosticsCollector,
5585
5605
  devtoolsOpener,
5586
5606
  onPageAttach: () => qrServer?.notifyStateChange(),
5607
+ onPageDetach: () => qrServer?.notifyStateChange(),
5587
5608
  getInspectorStableUrl: () => qrServer?.inspectorStableUrl ?? null,
5588
5609
  readSandboxRelayUrl: (pr) => readMobileRelayBaseUrl(process.env, pr ?? options.projectRoot ?? process.cwd()).catch(() => null)
5589
5610
  });
@@ -5734,4 +5755,4 @@ async function runMobileDebugServer(options = {}) {
5734
5755
  //#endregion
5735
5756
  export { wrapEnvelope as a, runMobileDebugServer as i, runDebugServer as n, runLocalDebugServer as r, debug_server_exports as t };
5736
5757
 
5737
- //# sourceMappingURL=debug-server-DNqP-T9V.js.map
5758
+ //# sourceMappingURL=debug-server-m9lIC9YW.js.map