adhdev 0.5.21 → 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
  }
@@ -30109,7 +30175,7 @@ var init_adhdev_daemon = __esm({
30109
30175
  path2 = __toESM(require("path"));
30110
30176
  crypto2 = __toESM(require("crypto"));
30111
30177
  import_chalk = __toESM(require("chalk"));
30112
- pkgVersion = "0.5.21";
30178
+ pkgVersion = "0.5.23";
30113
30179
  if (pkgVersion === "unknown") {
30114
30180
  try {
30115
30181
  const possiblePaths = [
@@ -30193,7 +30259,18 @@ var init_adhdev_daemon = __esm({
30193
30259
  if (this.ideType === "unknown") this.ideType = ideType;
30194
30260
  },
30195
30261
  onStreamsUpdated: (ideType, streams) => {
30196
- 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
+ }
30197
30274
  }
30198
30275
  });
30199
30276
  const versionArchive = new import_daemon_core4.VersionArchive();
@@ -30366,76 +30443,9 @@ var init_adhdev_daemon = __esm({
30366
30443
  if (this.p2p) this.p2p.handleSignaling(sigType, msg.payload);
30367
30444
  });
30368
30445
  }
30369
- const directCdpCommands = [
30370
- "read_chat",
30371
- "send_chat",
30372
- "list_chats",
30373
- "new_chat",
30374
- "switch_chat",
30375
- "set_mode",
30376
- "change_model",
30377
- "set_thought_level",
30378
- "screenshot",
30379
- "cdp_eval",
30380
- "cdp_screenshot",
30381
- "cdp_command_exec",
30382
- "cdp_batch",
30383
- "cdp_remote_action",
30384
- "cdp_discover_agents",
30385
- "file_read",
30386
- "file_write",
30387
- "file_list",
30388
- "file_list_browse",
30389
- "terminal_exec",
30390
- "refresh_scripts",
30391
- // CLI/daemon-local commands (launch, restart, detect, stop)
30392
- "launch_ide",
30393
- "stop_ide",
30394
- "restart_ide",
30395
- "detect_ides",
30396
- "restart_session",
30397
- "exec_command",
30398
- "launch_cli",
30399
- "stop_cli",
30400
- // Extension-delegated commands (must be registered to receive WS messages)
30401
- "vscode_command_exec",
30402
- "execute_vscode_command",
30403
- "get_open_editors",
30404
- "open_tab",
30405
- "close_tab",
30406
- "open_folder",
30407
- "open_folder_picker",
30408
- "open_recent",
30409
- "get_commands",
30410
- "get_recent_workspaces",
30411
- "get_cli_history",
30412
- "open_panel",
30413
- "open_file",
30414
- "create_terminal",
30415
- "close_terminal",
30416
- // Agent stream commands
30417
- "agent_stream_switch",
30418
- "agent_stream_read",
30419
- "agent_stream_send",
30420
- "agent_stream_resolve",
30421
- "agent_stream_new",
30422
- "agent_stream_list_chats",
30423
- "agent_stream_switch_session",
30424
- "agent_stream_focus",
30425
- // PTY I/O commands (terminal view)
30426
- "pty_input",
30427
- "pty_resize",
30428
- // Extension model/mode control
30429
- "list_extension_models",
30430
- "set_extension_model",
30431
- "list_extension_modes",
30432
- "set_extension_mode"
30433
- ];
30434
- for (const cmdType of directCdpCommands) {
30435
- this.serverConn.on(cmdType, async (msg) => {
30436
- await this.handleCommand(msg, cmdType, msg.payload);
30437
- });
30438
- }
30446
+ this.serverConn.onUnhandled(async (msg) => {
30447
+ await this.handleCommand(msg, msg.type, msg.payload);
30448
+ });
30439
30449
  }
30440
30450
  async handleCommand(msg, cmd, args) {
30441
30451
  import_daemon_core4.LOG.info("Command", `${cmd}${args?._targetInstance ? ` \u2192 ${args._targetType}:${args._targetInstance.split("_")[0]}` : ""}`);
@@ -30552,10 +30562,20 @@ var init_adhdev_daemon = __esm({
30552
30562
  }
30553
30563
  }
30554
30564
  // ─── CDP helpers ─────────────────────────────
30555
- /** 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
+ */
30556
30571
  getCdpFor(ideType) {
30557
30572
  if (!this.components) return null;
30558
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
+ }
30559
30579
  const exact = this.components.cdpManagers.get(key);
30560
30580
  if (exact) return exact;
30561
30581
  for (const [k, m] of this.components.cdpManagers.entries()) {