adhdev 0.5.21 → 0.5.24

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);
@@ -20780,6 +20834,10 @@ var require_dist = __commonJS({
20780
20834
  /** Extract ideType from _targetInstance or explicit ideType */
20781
20835
  extractIdeType(args) {
20782
20836
  if (args?.ideType) {
20837
+ const mappedKey = this._ctx.instanceIdMap?.get(args.ideType);
20838
+ if (mappedKey) {
20839
+ return mappedKey;
20840
+ }
20783
20841
  if (this._ctx.cdpManagers.has(args.ideType)) {
20784
20842
  return args.ideType;
20785
20843
  }
@@ -25098,7 +25156,7 @@ ${installInfo}`
25098
25156
  results.push(agent.lastState);
25099
25157
  } else {
25100
25158
  try {
25101
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25159
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25102
25160
  const state = await agent.adapter.readChat(evaluate);
25103
25161
  agent.lastState = state;
25104
25162
  agent.lastError = null;
@@ -25136,7 +25194,7 @@ ${installInfo}`
25136
25194
  const agent = this.managed.get(agentType);
25137
25195
  if (!agent) return false;
25138
25196
  try {
25139
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25197
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25140
25198
  await agent.adapter.sendMessage(evaluate, text);
25141
25199
  return true;
25142
25200
  } catch (e) {
@@ -25149,7 +25207,7 @@ ${installInfo}`
25149
25207
  const agent = this.managed.get(agentType);
25150
25208
  if (!agent) return false;
25151
25209
  try {
25152
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25210
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25153
25211
  return await agent.adapter.resolveAction(evaluate, action);
25154
25212
  } catch (e) {
25155
25213
  this.logFn(`[AgentStream] resolveAction(${agentType}) error: ${e.message}`);
@@ -25161,7 +25219,7 @@ ${installInfo}`
25161
25219
  const agent = this.managed.get(agentType);
25162
25220
  if (!agent) return false;
25163
25221
  try {
25164
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25222
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25165
25223
  await agent.adapter.newSession(evaluate);
25166
25224
  return true;
25167
25225
  } catch (e) {
@@ -25179,7 +25237,7 @@ ${installInfo}`
25179
25237
  }
25180
25238
  if (!agent || typeof agent.adapter.listChats !== "function") return [];
25181
25239
  try {
25182
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25240
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25183
25241
  return await agent.adapter.listChats(evaluate);
25184
25242
  } catch (e) {
25185
25243
  this.logFn(`[AgentStream] listChats(${agentType}) error: ${e.message}`);
@@ -25196,7 +25254,7 @@ ${installInfo}`
25196
25254
  }
25197
25255
  if (!agent || typeof agent.adapter.switchSession !== "function") return false;
25198
25256
  try {
25199
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25257
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25200
25258
  return await agent.adapter.switchSession(evaluate, sessionId);
25201
25259
  } catch (e) {
25202
25260
  this.logFn(`[AgentStream] switchSession(${agentType}) error: ${e.message}`);
@@ -25207,7 +25265,7 @@ ${installInfo}`
25207
25265
  const agent = this.managed.get(agentType);
25208
25266
  if (!agent || typeof agent.adapter.focusEditor !== "function") return false;
25209
25267
  try {
25210
- const evaluate = (expr, timeout) => cdp.evaluateInSession(agent.sessionId, expr, timeout);
25268
+ const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
25211
25269
  await agent.adapter.focusEditor(evaluate);
25212
25270
  return true;
25213
25271
  } catch (e) {
@@ -28879,6 +28937,8 @@ var init_server_connection = __esm({
28879
28937
  pongTimeout = null;
28880
28938
  messageHandlers = /* @__PURE__ */ new Map();
28881
28939
  stateChangeCallbacks = [];
28940
+ /** Fallback handler for message types without specific on() registration */
28941
+ unhandledHandler = null;
28882
28942
  userPlan = "free";
28883
28943
  iceServers = null;
28884
28944
  planLimits = null;
@@ -28944,6 +29004,14 @@ var init_server_connection = __esm({
28944
29004
  }
28945
29005
  this.messageHandlers.get(type).push(handler);
28946
29006
  }
29007
+ /**
29008
+ * Register a fallback handler for unregistered message types.
29009
+ * Used for command routing — all server→daemon commands that aren't
29010
+ * explicitly registered (via on()) are forwarded to this handler.
29011
+ */
29012
+ onUnhandled(handler) {
29013
+ this.unhandledHandler = handler;
29014
+ }
28947
29015
  onStateChange(callback) {
28948
29016
  this.stateChangeCallbacks.push(callback);
28949
29017
  }
@@ -29011,6 +29079,8 @@ var init_server_connection = __esm({
29011
29079
  const handlers = this.messageHandlers.get(message.type);
29012
29080
  if (handlers) {
29013
29081
  handlers.forEach((h) => h(message));
29082
+ } else if (this.unhandledHandler && message.type !== "auth_ok") {
29083
+ this.unhandledHandler(message);
29014
29084
  } else if (message.type !== "auth_ok") {
29015
29085
  import_daemon_core.LOG.info("Server", `[ServerConn] Unhandled message type: ${message.type}`);
29016
29086
  }
@@ -29728,16 +29798,16 @@ ${e?.stack || ""}`);
29728
29798
  }
29729
29799
  }
29730
29800
  async handleInputEvent(peerId, msg) {
29731
- const { id, action, params } = msg;
29801
+ const { id, action, params, instanceId } = msg;
29732
29802
  if (!this.inputHandler) {
29733
29803
  this.sendToPeer(peerId, { id, type: "response", success: false, error: "No input handler" });
29734
29804
  return;
29735
29805
  }
29736
29806
  try {
29737
29807
  const peer = this.peers.get(peerId);
29738
- const ideType = peer?.screenshotIdeType;
29808
+ const ideType = instanceId || peer?.screenshotIdeType;
29739
29809
  if (!ideType) {
29740
- log(`[Input] WARNING: No screenshotIdeType for peer ${peerId} \u2014 input may route to wrong IDE`);
29810
+ log(`[Input] WARNING: No instanceId or screenshotIdeType for peer ${peerId}`);
29741
29811
  }
29742
29812
  const result = await this.inputHandler({ action, params, ideType });
29743
29813
  this.sendToPeer(peerId, { id, type: "response", success: true, result });
@@ -30109,7 +30179,7 @@ var init_adhdev_daemon = __esm({
30109
30179
  path2 = __toESM(require("path"));
30110
30180
  crypto2 = __toESM(require("crypto"));
30111
30181
  import_chalk = __toESM(require("chalk"));
30112
- pkgVersion = "0.5.21";
30182
+ pkgVersion = "0.5.24";
30113
30183
  if (pkgVersion === "unknown") {
30114
30184
  try {
30115
30185
  const possiblePaths = [
@@ -30193,7 +30263,18 @@ var init_adhdev_daemon = __esm({
30193
30263
  if (this.ideType === "unknown") this.ideType = ideType;
30194
30264
  },
30195
30265
  onStreamsUpdated: (ideType, streams) => {
30196
- this.statusReporter?.updateAgentStreams(ideType, streams);
30266
+ const ideInstance = this.components?.instanceManager?.getInstance(`ide:${ideType}`);
30267
+ if (ideInstance?.onEvent) {
30268
+ for (const stream of streams) {
30269
+ ideInstance.onEvent("stream_update", {
30270
+ extensionType: stream.agentType,
30271
+ streams: [stream],
30272
+ messages: stream.messages || [],
30273
+ status: stream.status || "idle",
30274
+ activeModal: stream.activeModal || null
30275
+ });
30276
+ }
30277
+ }
30197
30278
  }
30198
30279
  });
30199
30280
  const versionArchive = new import_daemon_core4.VersionArchive();
@@ -30366,76 +30447,9 @@ var init_adhdev_daemon = __esm({
30366
30447
  if (this.p2p) this.p2p.handleSignaling(sigType, msg.payload);
30367
30448
  });
30368
30449
  }
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
- }
30450
+ this.serverConn.onUnhandled(async (msg) => {
30451
+ await this.handleCommand(msg, msg.type, msg.payload);
30452
+ });
30439
30453
  }
30440
30454
  async handleCommand(msg, cmd, args) {
30441
30455
  import_daemon_core4.LOG.info("Command", `${cmd}${args?._targetInstance ? ` \u2192 ${args._targetType}:${args._targetInstance.split("_")[0]}` : ""}`);
@@ -30552,10 +30566,20 @@ var init_adhdev_daemon = __esm({
30552
30566
  }
30553
30567
  }
30554
30568
  // ─── CDP helpers ─────────────────────────────
30555
- /** Return CDP manager for specific IDE (exact match first, then prefix match for multi-window keys) */
30569
+ /** Return CDP manager for specific IDE.
30570
+ * Lookup order:
30571
+ * 1. instanceIdMap (UUID → managerKey) — for multi-window UUID instance IDs
30572
+ * 2. Exact match on cdpManagers (key = "cursor", "antigravity")
30573
+ * 3. Prefix match (multi-window: "antigravity_WorkspaceName")
30574
+ */
30556
30575
  getCdpFor(ideType) {
30557
30576
  if (!this.components) return null;
30558
30577
  const key = ideType.toLowerCase();
30578
+ const mappedKey = this.components.instanceIdMap.get(ideType) || this.components.instanceIdMap.get(key);
30579
+ if (mappedKey) {
30580
+ const mapped = this.components.cdpManagers.get(mappedKey);
30581
+ if (mapped?.isConnected) return mapped;
30582
+ }
30559
30583
  const exact = this.components.cdpManagers.get(key);
30560
30584
  if (exact) return exact;
30561
30585
  for (const [k, m] of this.components.cdpManagers.entries()) {
@@ -31152,6 +31176,38 @@ function registerSetupCommands(program2, providerLoader) {
31152
31176
  console.log(import_chalk3.default.gray(" Run `adhdev setup` to reconfigure.\n"));
31153
31177
  }
31154
31178
  });
31179
+ program2.command("logout").description("Log out from ADHDev (clear auth credentials, keep config)").option("-f, --force", "Skip confirmation prompt").action(async (options) => {
31180
+ const { loadConfig: loadConfig3, saveConfig: saveConfig2 } = await Promise.resolve().then(() => __toESM(require_dist()));
31181
+ if (!options.force) {
31182
+ const inquirer2 = await import("inquirer");
31183
+ const { confirm } = await inquirer2.default.prompt([
31184
+ {
31185
+ type: "confirm",
31186
+ name: "confirm",
31187
+ message: "Log out from ADHDev? This will clear your auth token and disconnect the daemon.",
31188
+ default: false
31189
+ }
31190
+ ]);
31191
+ if (!confirm) return;
31192
+ }
31193
+ try {
31194
+ const { isDaemonRunning: isDaemonRunning2, stopDaemon: stopDaemon2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
31195
+ if (isDaemonRunning2()) {
31196
+ console.log(import_chalk3.default.gray(" Stopping daemon..."));
31197
+ stopDaemon2();
31198
+ }
31199
+ } catch {
31200
+ }
31201
+ const config2 = loadConfig3();
31202
+ config2.apiToken = null;
31203
+ config2.connectionToken = null;
31204
+ config2.userEmail = null;
31205
+ config2.userName = null;
31206
+ saveConfig2(config2);
31207
+ console.log(import_chalk3.default.green("\n\u2713 Logged out successfully."));
31208
+ console.log(import_chalk3.default.gray(" Auth credentials cleared. IDE and workspace settings preserved."));
31209
+ console.log(import_chalk3.default.gray(" Run `adhdev setup` to log in again.\n"));
31210
+ });
31155
31211
  }
31156
31212
 
31157
31213
  // src/cli/daemon-commands.ts