adhdev 0.5.20 → 0.5.23

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/dist/cli/index.js CHANGED
@@ -17958,6 +17958,60 @@ var require_dist = __commonJS({
17958
17958
  }, timeoutMs);
17959
17959
  });
17960
17960
  }
17961
+ /**
17962
+ * Evaluate inside the child frame of an attached session.
17963
+ * Extension webviews have a nested iframe structure:
17964
+ * outer (vscode-webview://) → inner (extension React app)
17965
+ * This method navigates into the inner frame using CDP Page.getFrameTree.
17966
+ * Falls back to evaluateInSession if no child frame is found.
17967
+ */
17968
+ async evaluateInSessionFrame(sessionId, expression, timeoutMs = 15e3) {
17969
+ const ws = this._browserConnected ? this.browserWs : this.ws;
17970
+ if (!ws || ws.readyState !== import_ws2.default.OPEN) {
17971
+ throw new Error("CDP not connected");
17972
+ }
17973
+ const sendViaSession = (method, params = {}) => {
17974
+ return new Promise((resolve7, reject) => {
17975
+ const pendingMap = this._browserConnected ? this.browserPending : this.pending;
17976
+ const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
17977
+ pendingMap.set(id, { resolve: resolve7, reject });
17978
+ ws.send(JSON.stringify({ id, sessionId, method, params }));
17979
+ setTimeout(() => {
17980
+ if (pendingMap.has(id)) {
17981
+ pendingMap.delete(id);
17982
+ reject(new Error(`CDP session timeout: ${method}`));
17983
+ }
17984
+ }, timeoutMs);
17985
+ });
17986
+ };
17987
+ try {
17988
+ const { frameTree } = await sendViaSession("Page.getFrameTree");
17989
+ const childFrame = frameTree?.childFrames?.[0]?.frame;
17990
+ if (!childFrame) {
17991
+ return this.evaluateInSession(sessionId, expression, timeoutMs);
17992
+ }
17993
+ const { executionContextId } = await sendViaSession("Page.createIsolatedWorld", {
17994
+ frameId: childFrame.id,
17995
+ worldName: "adhdev-agent-eval",
17996
+ grantUniveralAccess: true
17997
+ });
17998
+ const result = await sendViaSession("Runtime.evaluate", {
17999
+ expression,
18000
+ returnByValue: true,
18001
+ awaitPromise: true,
18002
+ contextId: executionContextId
18003
+ });
18004
+ if (result?.result?.subtype === "error") {
18005
+ throw new Error(result.result.description);
18006
+ }
18007
+ return result?.result?.value;
18008
+ } catch (e) {
18009
+ if (e.message?.includes("getFrameTree")) {
18010
+ return this.evaluateInSession(sessionId, expression, timeoutMs);
18011
+ }
18012
+ throw e;
18013
+ }
18014
+ }
17961
18015
  async detachAgent(sessionId) {
17962
18016
  try {
17963
18017
  const sendFn = this._browserConnected ? this.sendBrowser.bind(this) : this.sendInternal.bind(this);
@@ -18102,7 +18156,7 @@ var require_dist = __commonJS({
18102
18156
  }
18103
18157
  let result;
18104
18158
  if (sessionId) {
18105
- result = await this.getCdp().evaluateInSession(sessionId, expression);
18159
+ result = await this.getCdp().evaluateInSessionFrame(sessionId, expression);
18106
18160
  } else {
18107
18161
  result = await this.getCdp().evaluate(expression, 3e4);
18108
18162
  }
@@ -18163,7 +18217,7 @@ var require_dist = __commonJS({
18163
18217
  try {
18164
18218
  let raw;
18165
18219
  if (sessionId) {
18166
- raw = await this.getCdp().evaluateInSession(sessionId, expression);
18220
+ raw = await this.getCdp().evaluateInSessionFrame(sessionId, expression);
18167
18221
  } else {
18168
18222
  raw = await this.getCdp().evaluate(expression, 15e3);
18169
18223
  }
@@ -18298,7 +18352,7 @@ var require_dist = __commonJS({
18298
18352
  try {
18299
18353
  let raw;
18300
18354
  if (sessionId) {
18301
- raw = await this.getCdp().evaluateInSession(sessionId, expression);
18355
+ raw = await this.getCdp().evaluateInSessionFrame(sessionId, expression);
18302
18356
  } else {
18303
18357
  raw = await this.getCdp().evaluate(expression, 3e4);
18304
18358
  }
@@ -20520,7 +20574,7 @@ var require_dist = __commonJS({
20520
20574
  if (!targetSessionId) {
20521
20575
  return { success: false, error: `No active session found for ${agentType}` };
20522
20576
  }
20523
- result = await cdp.evaluateInSession(targetSessionId, scriptCode);
20577
+ result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
20524
20578
  } else if (hasWebviewScript && cdp.evaluateInWebviewFrame) {
20525
20579
  const matchText = provider.webviewMatchText;
20526
20580
  const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
@@ -20754,7 +20808,7 @@ var require_dist = __commonJS({
20754
20808
  sessionId = this.getExtensionSessionId(provider);
20755
20809
  }
20756
20810
  if (!sessionId) return null;
20757
- const result2 = await cdp.evaluateInSession(sessionId, script, timeout);
20811
+ const result2 = await cdp.evaluateInSessionFrame(sessionId, script, timeout);
20758
20812
  return { result: result2, category: "extension" };
20759
20813
  }
20760
20814
  const result = await cdp.evaluate(script, timeout);
@@ -25098,7 +25152,7 @@ ${installInfo}`
25098
25152
  results.push(agent.lastState);
25099
25153
  } else {
25100
25154
  try {
25101
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25155
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25102
25156
  const state = await agent.adapter.readChat(evaluate);
25103
25157
  agent.lastState = state;
25104
25158
  agent.lastError = null;
@@ -25136,7 +25190,7 @@ ${installInfo}`
25136
25190
  const agent = this.managed.get(agentType);
25137
25191
  if (!agent) return false;
25138
25192
  try {
25139
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25193
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25140
25194
  await agent.adapter.sendMessage(evaluate, text);
25141
25195
  return true;
25142
25196
  } catch (e) {
@@ -25149,7 +25203,7 @@ ${installInfo}`
25149
25203
  const agent = this.managed.get(agentType);
25150
25204
  if (!agent) return false;
25151
25205
  try {
25152
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25206
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25153
25207
  return await agent.adapter.resolveAction(evaluate, action);
25154
25208
  } catch (e) {
25155
25209
  this.logFn(`[AgentStream] resolveAction(${agentType}) error: ${e.message}`);
@@ -25161,7 +25215,7 @@ ${installInfo}`
25161
25215
  const agent = this.managed.get(agentType);
25162
25216
  if (!agent) return false;
25163
25217
  try {
25164
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25218
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25165
25219
  await agent.adapter.newSession(evaluate);
25166
25220
  return true;
25167
25221
  } catch (e) {
@@ -25179,7 +25233,7 @@ ${installInfo}`
25179
25233
  }
25180
25234
  if (!agent || typeof agent.adapter.listChats !== "function") return [];
25181
25235
  try {
25182
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25236
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25183
25237
  return await agent.adapter.listChats(evaluate);
25184
25238
  } catch (e) {
25185
25239
  this.logFn(`[AgentStream] listChats(${agentType}) error: ${e.message}`);
@@ -25196,7 +25250,7 @@ ${installInfo}`
25196
25250
  }
25197
25251
  if (!agent || typeof agent.adapter.switchSession !== "function") return false;
25198
25252
  try {
25199
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25253
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25200
25254
  return await agent.adapter.switchSession(evaluate, sessionId);
25201
25255
  } catch (e) {
25202
25256
  this.logFn(`[AgentStream] switchSession(${agentType}) error: ${e.message}`);
@@ -25207,7 +25261,7 @@ ${installInfo}`
25207
25261
  const agent = this.managed.get(agentType);
25208
25262
  if (!agent || typeof agent.adapter.focusEditor !== "function") return false;
25209
25263
  try {
25210
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25264
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25211
25265
  await agent.adapter.focusEditor(evaluate);
25212
25266
  return true;
25213
25267
  } catch (e) {
@@ -28879,6 +28933,8 @@ var init_server_connection = __esm({
28879
28933
  pongTimeout = null;
28880
28934
  messageHandlers = /* @__PURE__ */ new Map();
28881
28935
  stateChangeCallbacks = [];
28936
+ /** Fallback handler for message types without specific on() registration */
28937
+ unhandledHandler = null;
28882
28938
  userPlan = "free";
28883
28939
  iceServers = null;
28884
28940
  planLimits = null;
@@ -28944,6 +29000,14 @@ var init_server_connection = __esm({
28944
29000
  }
28945
29001
  this.messageHandlers.get(type).push(handler);
28946
29002
  }
29003
+ /**
29004
+ * Register a fallback handler for unregistered message types.
29005
+ * Used for command routing — all server→daemon commands that aren't
29006
+ * explicitly registered (via on()) are forwarded to this handler.
29007
+ */
29008
+ onUnhandled(handler) {
29009
+ this.unhandledHandler = handler;
29010
+ }
28947
29011
  onStateChange(callback) {
28948
29012
  this.stateChangeCallbacks.push(callback);
28949
29013
  }
@@ -29011,6 +29075,8 @@ var init_server_connection = __esm({
29011
29075
  const handlers = this.messageHandlers.get(message.type);
29012
29076
  if (handlers) {
29013
29077
  handlers.forEach((h) => h(message));
29078
+ } else if (this.unhandledHandler && message.type !== "auth_ok") {
29079
+ this.unhandledHandler(message);
29014
29080
  } else if (message.type !== "auth_ok") {
29015
29081
  import_daemon_core.LOG.info("Server", `[ServerConn] Unhandled message type: ${message.type}`);
29016
29082
  }
@@ -29028,6 +29094,28 @@ var init_server_connection = __esm({
29028
29094
  this.setState("disconnected");
29029
29095
  return;
29030
29096
  }
29097
+ if (code === 4012) {
29098
+ import_daemon_core.LOG.info("Server", `[ServerConn] \u26A0 Force disconnected by user from dashboard.`);
29099
+ import_daemon_core.LOG.info("Server", `[ServerConn] Run 'adhdev daemon' to reconnect.`);
29100
+ this.setState("disconnected");
29101
+ return;
29102
+ }
29103
+ if (code === 4013) {
29104
+ import_daemon_core.LOG.info("Server", `[ServerConn] \u26A0 Connection token was revoked.`);
29105
+ import_daemon_core.LOG.info("Server", `[ServerConn] Run 'adhdev setup' to re-authenticate.`);
29106
+ this.setState("disconnected");
29107
+ try {
29108
+ const path3 = require("path");
29109
+ const fs3 = require("fs");
29110
+ const configPath = path3.join(process.env.HOME || process.env.USERPROFILE || "", ".adhdev", "config.json");
29111
+ if (fs3.existsSync(configPath)) {
29112
+ fs3.unlinkSync(configPath);
29113
+ import_daemon_core.LOG.info("Server", `[ServerConn] Config file removed. Re-run 'adhdev setup'.`);
29114
+ }
29115
+ } catch {
29116
+ }
29117
+ return;
29118
+ }
29031
29119
  if (code !== 1e3 && this.reconnectAttempts < 50) {
29032
29120
  this.setState("disconnected");
29033
29121
  this.scheduleReconnect();
@@ -29513,11 +29601,15 @@ ${e?.stack || ""}`);
29513
29601
  if (parsed.type === "pong") return;
29514
29602
  if (parsed.type === "screenshot_start") {
29515
29603
  const peer = this.peers.get(peerId);
29604
+ if (!parsed.ideType) {
29605
+ log(`screenshot_start: REJECTED \u2014 no ideType from peer ${peerId}`);
29606
+ return;
29607
+ }
29516
29608
  if (peer) {
29517
29609
  peer.screenshotActive = true;
29518
- peer.screenshotIdeType = parsed.ideType || void 0;
29610
+ peer.screenshotIdeType = parsed.ideType;
29519
29611
  peer.needsFirstFrame = true;
29520
- log(`screenshot_start: peer=${peerId}, ideType=${parsed.ideType || "any"}, channelOpen=${!!peer.screenshotChannel}, state=${peer.state}`);
29612
+ log(`screenshot_start: peer=${peerId}, ideType=${parsed.ideType}, channelOpen=${!!peer.screenshotChannel}, state=${peer.state}`);
29521
29613
  } else {
29522
29614
  log(`screenshot_start: peer ${peerId} NOT FOUND in peers map!`);
29523
29615
  }
@@ -29931,7 +30023,11 @@ var init_screenshot_controller = __esm({
29931
30023
  if (!this.deps.isRunning()) return;
29932
30024
  const active = this.deps.isScreenshotActive();
29933
30025
  const ssIdeType = this.deps.getScreenshotIdeType();
29934
- const cdp = this.deps.getCdp(ssIdeType);
30026
+ if (active && !ssIdeType) {
30027
+ this.timer = setTimeout(() => this.tick(), 500);
30028
+ return;
30029
+ }
30030
+ const cdp = ssIdeType ? this.deps.getCdp(ssIdeType) : null;
29935
30031
  const isRelay = this.deps.isUsingRelay();
29936
30032
  const profile = isRelay ? this.profileRelay : this.profileDirect;
29937
30033
  this.checkBudgetReset();
@@ -30079,7 +30175,7 @@ var init_adhdev_daemon = __esm({
30079
30175
  path2 = __toESM(require("path"));
30080
30176
  crypto2 = __toESM(require("crypto"));
30081
30177
  import_chalk = __toESM(require("chalk"));
30082
- pkgVersion = "0.5.20";
30178
+ pkgVersion = "0.5.23";
30083
30179
  if (pkgVersion === "unknown") {
30084
30180
  try {
30085
30181
  const possiblePaths = [
@@ -30163,7 +30259,18 @@ var init_adhdev_daemon = __esm({
30163
30259
  if (this.ideType === "unknown") this.ideType = ideType;
30164
30260
  },
30165
30261
  onStreamsUpdated: (ideType, streams) => {
30166
- this.statusReporter?.updateAgentStreams(ideType, streams);
30262
+ const ideInstance = this.components?.instanceManager?.getInstance(`ide:${ideType}`);
30263
+ if (ideInstance?.onEvent) {
30264
+ for (const stream of streams) {
30265
+ ideInstance.onEvent("stream_update", {
30266
+ extensionType: stream.agentType,
30267
+ streams: [stream],
30268
+ messages: stream.messages || [],
30269
+ status: stream.status || "idle",
30270
+ activeModal: stream.activeModal || null
30271
+ });
30272
+ }
30273
+ }
30167
30274
  }
30168
30275
  });
30169
30276
  const versionArchive = new import_daemon_core4.VersionArchive();
@@ -30336,76 +30443,9 @@ var init_adhdev_daemon = __esm({
30336
30443
  if (this.p2p) this.p2p.handleSignaling(sigType, msg.payload);
30337
30444
  });
30338
30445
  }
30339
- const directCdpCommands = [
30340
- "read_chat",
30341
- "send_chat",
30342
- "list_chats",
30343
- "new_chat",
30344
- "switch_chat",
30345
- "set_mode",
30346
- "change_model",
30347
- "set_thought_level",
30348
- "screenshot",
30349
- "cdp_eval",
30350
- "cdp_screenshot",
30351
- "cdp_command_exec",
30352
- "cdp_batch",
30353
- "cdp_remote_action",
30354
- "cdp_discover_agents",
30355
- "file_read",
30356
- "file_write",
30357
- "file_list",
30358
- "file_list_browse",
30359
- "terminal_exec",
30360
- "refresh_scripts",
30361
- // CLI/daemon-local commands (launch, restart, detect, stop)
30362
- "launch_ide",
30363
- "stop_ide",
30364
- "restart_ide",
30365
- "detect_ides",
30366
- "restart_session",
30367
- "exec_command",
30368
- "launch_cli",
30369
- "stop_cli",
30370
- // Extension-delegated commands (must be registered to receive WS messages)
30371
- "vscode_command_exec",
30372
- "execute_vscode_command",
30373
- "get_open_editors",
30374
- "open_tab",
30375
- "close_tab",
30376
- "open_folder",
30377
- "open_folder_picker",
30378
- "open_recent",
30379
- "get_commands",
30380
- "get_recent_workspaces",
30381
- "get_cli_history",
30382
- "open_panel",
30383
- "open_file",
30384
- "create_terminal",
30385
- "close_terminal",
30386
- // Agent stream commands
30387
- "agent_stream_switch",
30388
- "agent_stream_read",
30389
- "agent_stream_send",
30390
- "agent_stream_resolve",
30391
- "agent_stream_new",
30392
- "agent_stream_list_chats",
30393
- "agent_stream_switch_session",
30394
- "agent_stream_focus",
30395
- // PTY I/O commands (terminal view)
30396
- "pty_input",
30397
- "pty_resize",
30398
- // Extension model/mode control
30399
- "list_extension_models",
30400
- "set_extension_model",
30401
- "list_extension_modes",
30402
- "set_extension_mode"
30403
- ];
30404
- for (const cmdType of directCdpCommands) {
30405
- this.serverConn.on(cmdType, async (msg) => {
30406
- await this.handleCommand(msg, cmdType, msg.payload);
30407
- });
30408
- }
30446
+ this.serverConn.onUnhandled(async (msg) => {
30447
+ await this.handleCommand(msg, msg.type, msg.payload);
30448
+ });
30409
30449
  }
30410
30450
  async handleCommand(msg, cmd, args) {
30411
30451
  import_daemon_core4.LOG.info("Command", `${cmd}${args?._targetInstance ? ` \u2192 ${args._targetType}:${args._targetInstance.split("_")[0]}` : ""}`);
@@ -30522,10 +30562,20 @@ var init_adhdev_daemon = __esm({
30522
30562
  }
30523
30563
  }
30524
30564
  // ─── CDP helpers ─────────────────────────────
30525
- /** Return CDP manager for specific IDE (exact match first, then prefix match for multi-window keys) */
30565
+ /** Return CDP manager for specific IDE.
30566
+ * Lookup order:
30567
+ * 1. instanceIdMap (UUID → managerKey) — for multi-window UUID instance IDs
30568
+ * 2. Exact match on cdpManagers (key = "cursor", "antigravity")
30569
+ * 3. Prefix match (multi-window: "antigravity_WorkspaceName")
30570
+ */
30526
30571
  getCdpFor(ideType) {
30527
30572
  if (!this.components) return null;
30528
30573
  const key = ideType.toLowerCase();
30574
+ const mappedKey = this.components.instanceIdMap.get(ideType) || this.components.instanceIdMap.get(key);
30575
+ if (mappedKey) {
30576
+ const mapped = this.components.cdpManagers.get(mappedKey);
30577
+ if (mapped?.isConnected) return mapped;
30578
+ }
30529
30579
  const exact = this.components.cdpManagers.get(key);
30530
30580
  if (exact) return exact;
30531
30581
  for (const [k, m] of this.components.cdpManagers.entries()) {