adhdev 0.5.37 → 0.5.40

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/index.js CHANGED
@@ -18479,6 +18479,8 @@ var require_dist = __commonJS({
18479
18479
  agentStreams = [];
18480
18480
  messages = [];
18481
18481
  activeModal = null;
18482
+ currentModel = "";
18483
+ currentMode = "";
18482
18484
  lastAgentStatus = "idle";
18483
18485
  generatingStartedAt = 0;
18484
18486
  monitor;
@@ -18518,6 +18520,8 @@ var require_dist = __commonJS({
18518
18520
  activeModal: this.activeModal,
18519
18521
  inputContent: ""
18520
18522
  } : null,
18523
+ currentModel: this.currentModel || void 0,
18524
+ currentPlan: this.currentMode || void 0,
18521
18525
  agentStreams: this.agentStreams,
18522
18526
  instanceId: this.instanceId,
18523
18527
  lastUpdated: Date.now(),
@@ -18530,6 +18534,8 @@ var require_dist = __commonJS({
18530
18534
  if (data?.streams) this.agentStreams = data.streams;
18531
18535
  if (data?.messages) this.messages = data.messages;
18532
18536
  if (data?.activeModal !== void 0) this.activeModal = data.activeModal;
18537
+ if (data?.model) this.currentModel = data.model;
18538
+ if (data?.mode) this.currentMode = data.mode;
18533
18539
  if (data?.status) {
18534
18540
  const newStatus = data.status;
18535
18541
  this.detectTransition(newStatus, data);
@@ -20658,7 +20664,13 @@ var require_dist = __commonJS({
20658
20664
  return { success: false, error: `Script '${actualScriptName}' not available for ${agentType}` };
20659
20665
  }
20660
20666
  const scriptFn = provider.scripts[actualScriptName];
20661
- const scriptCode = scriptFn(args);
20667
+ const normalizedArgs = { ...args };
20668
+ for (const key of ["mode", "model", "message", "action", "button", "text", "sessionId"]) {
20669
+ if (key in normalizedArgs && !(key.toUpperCase() in normalizedArgs)) {
20670
+ normalizedArgs[key.toUpperCase()] = normalizedArgs[key];
20671
+ }
20672
+ }
20673
+ const scriptCode = scriptFn(normalizedArgs);
20662
20674
  if (!scriptCode) return { success: false, error: `Script '${actualScriptName}' returned null` };
20663
20675
  const cdpKey = provider.category === "ide" ? h.currentIdeType || agentType : h.currentIdeType || ideType;
20664
20676
  LOG5.info("Command", `[ExtScript] provider=${provider.type} category=${provider.category} cdpKey=${cdpKey}`);
@@ -20675,10 +20687,31 @@ var require_dist = __commonJS({
20675
20687
  break;
20676
20688
  }
20677
20689
  }
20678
- if (!targetSessionId) {
20679
- return { success: false, error: `No active session found for ${agentType}` };
20690
+ const IDE_LEVEL_SCRIPTS = ["listModes", "setMode", "listModels", "setModel"];
20691
+ if (IDE_LEVEL_SCRIPTS.includes(scriptName)) {
20692
+ if (targetSessionId) {
20693
+ try {
20694
+ result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
20695
+ const parsed = typeof result === "string" ? JSON.parse(result) : result;
20696
+ const notFound = parsed?.error?.includes("not found") || parsed?.error?.includes("no root");
20697
+ if (notFound) {
20698
+ LOG5.info("Command", `[ExtScript] ${scriptName} not found in session frame \u2192 trying IDE main page`);
20699
+ result = await cdp.evaluate(scriptCode, 3e4);
20700
+ }
20701
+ } catch {
20702
+ LOG5.info("Command", `[ExtScript] ${scriptName} session frame failed \u2192 trying IDE main page`);
20703
+ result = await cdp.evaluate(scriptCode, 3e4);
20704
+ }
20705
+ } else {
20706
+ LOG5.info("Command", `[ExtScript] ${scriptName} no session \u2192 trying IDE main page`);
20707
+ result = await cdp.evaluate(scriptCode, 3e4);
20708
+ }
20709
+ } else {
20710
+ if (!targetSessionId) {
20711
+ return { success: false, error: `No active session found for ${agentType}` };
20712
+ }
20713
+ result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
20680
20714
  }
20681
- result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
20682
20715
  } else if (hasWebviewScript && cdp.evaluateInWebviewFrame) {
20683
20716
  const matchText = provider.webviewMatchText;
20684
20717
  const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
@@ -25161,6 +25194,7 @@ ${installInfo}`
25161
25194
  messages: data.messages || [],
25162
25195
  inputContent: data.inputContent || "",
25163
25196
  model: data.model,
25197
+ mode: data.mode,
25164
25198
  activeModal: data.activeModal
25165
25199
  };
25166
25200
  if (state.messages.length > 0) {
@@ -26496,14 +26530,29 @@ async (params) => {
26496
26530
  return;
26497
26531
  }
26498
26532
  this.log(`Exec script length: ${scriptCode.length}, first 50 chars: ${scriptCode.slice(0, 50)}...`);
26499
- const isWebviewScript = provider.category === "extension" || scriptName.toLowerCase().includes("webview");
26533
+ const isWebviewScript = scriptName.toLowerCase().includes("webview");
26500
26534
  let raw;
26501
- if (isWebviewScript) {
26535
+ if (provider.category === "extension" && !isWebviewScript) {
26536
+ const sessions = cdp.getAgentSessions();
26537
+ let sessionId = null;
26538
+ for (const [sid, target] of sessions) {
26539
+ if (target.agentType === type) {
26540
+ sessionId = sid;
26541
+ break;
26542
+ }
26543
+ }
26544
+ if (sessionId) {
26545
+ raw = await cdp.evaluateInSessionFrame(sessionId, scriptCode);
26546
+ } else if (cdp.evaluateInWebviewFrame) {
26547
+ const matchText = provider.webviewMatchText;
26548
+ const matchFn = matchText ? (body2) => body2.includes(matchText) : void 0;
26549
+ raw = await cdp.evaluateInWebviewFrame(scriptCode, matchFn);
26550
+ } else {
26551
+ raw = await cdp.evaluate(scriptCode, 3e4);
26552
+ }
26553
+ } else if (isWebviewScript && cdp.evaluateInWebviewFrame) {
26502
26554
  const matchText = provider.webviewMatchText;
26503
26555
  const matchFn = matchText ? (body2) => body2.includes(matchText) : void 0;
26504
- if (!cdp.evaluateInWebviewFrame) {
26505
- throw new Error(`CDP manager does not support evaluateInWebviewFrame`);
26506
- }
26507
26556
  raw = await cdp.evaluateInWebviewFrame(scriptCode, matchFn);
26508
26557
  } else {
26509
26558
  raw = await cdp.evaluate(scriptCode, 3e4);
@@ -29490,7 +29539,7 @@ ${e?.stack || ""}`);
29490
29539
  }
29491
29540
  get isConnected() {
29492
29541
  for (const peer of this.peers.values()) {
29493
- if (peer.state === "connected" && peer.screenshotChannel) return true;
29542
+ if (peer.state === "connected" && peer.dataChannel) return true;
29494
29543
  }
29495
29544
  return false;
29496
29545
  }
@@ -29610,9 +29659,9 @@ ${e?.stack || ""}`);
29610
29659
  if (oldestPeer) {
29611
29660
  log(`P2P limit reached (${connectedCount}/${limits.maxP2PConnections}). Evicting oldest peer ${oldestPeer.id.slice(0, 12)}\u2026`);
29612
29661
  const evictedPeer = this.peers.get(oldestPeer.id);
29613
- if (evictedPeer?.commandChannel?.isOpen()) {
29662
+ if (evictedPeer?.dataChannel?.isOpen()) {
29614
29663
  try {
29615
- evictedPeer.commandChannel.sendMessage(JSON.stringify({
29664
+ evictedPeer.dataChannel.sendMessage(JSON.stringify({
29616
29665
  type: "p2p_evicted",
29617
29666
  reason: "P2P_LIMIT_REACHED",
29618
29667
  maxconnections: limits.maxP2PConnections
@@ -29679,8 +29728,7 @@ ${e?.stack || ""}`);
29679
29728
  const entry = {
29680
29729
  peerId: pid,
29681
29730
  pc,
29682
- screenshotChannel: null,
29683
- commandChannel: null,
29731
+ dataChannel: null,
29684
29732
  state: "connecting",
29685
29733
  screenshotActive: false,
29686
29734
  connectedAt: Date.now(),
@@ -29743,41 +29791,31 @@ ${e?.stack || ""}`);
29743
29791
  }
29744
29792
  }
29745
29793
  });
29746
- const screenshotCh = pc.createDataChannel("screenshots");
29747
- screenshotCh.onOpen(() => {
29748
- log(`Screenshots channel OPEN for peer ${pid}`);
29794
+ const dataCh = pc.createDataChannel("data");
29795
+ entry.dataChannel = dataCh;
29796
+ dataCh.onOpen(() => {
29797
+ log(`Data channel OPEN for peer ${pid}`);
29749
29798
  const peer = this.peers.get(pid);
29750
29799
  if (peer) {
29751
- peer.screenshotChannel = screenshotCh;
29752
29800
  peer.state = "connected";
29753
29801
  this.notifyStateChange();
29754
29802
  if (peer.screenshotActive) {
29755
29803
  log(`Screenshots auto-starting for peer ${pid} (was waiting for channel open)`);
29756
29804
  }
29757
29805
  }
29806
+ setTimeout(() => this.sendPtyScrollback(pid), 100);
29758
29807
  });
29759
- screenshotCh.onClosed(() => {
29760
- log(`Screenshots channel CLOSED for peer ${pid}`);
29808
+ dataCh.onClosed(() => {
29809
+ log(`Data channel CLOSED for peer ${pid}`);
29761
29810
  const peer = this.peers.get(pid);
29762
- if (peer?.screenshotChannel === screenshotCh) {
29763
- peer.screenshotChannel = null;
29811
+ if (peer?.dataChannel === dataCh) {
29812
+ peer.dataChannel = null;
29764
29813
  peer.state = "failed";
29765
29814
  this.notifyStateChange();
29766
29815
  }
29767
29816
  });
29768
- screenshotCh.onError((err) => log(`Screenshots error: ${err}`));
29769
- const filesCh = pc.createDataChannel("commands");
29770
- entry.commandChannel = filesCh;
29771
- filesCh.onOpen(() => {
29772
- log(`Command channel OPEN for peer ${pid}`);
29773
- setTimeout(() => this.sendPtyScrollback(pid), 100);
29774
- });
29775
- filesCh.onClosed(() => {
29776
- const peer = this.peers.get(pid);
29777
- if (peer?.commandChannel === filesCh) peer.commandChannel = null;
29778
- });
29779
- filesCh.onError((err) => log(`Command channel error: ${err}`));
29780
- filesCh.onMessage((msg) => this.handleCommandMessage(pid, msg));
29817
+ dataCh.onError((err) => log(`Data channel error: ${err}`));
29818
+ dataCh.onMessage((msg) => this.handleCommandMessage(pid, msg));
29781
29819
  } catch (e) {
29782
29820
  log(`connection failed for peer ${pid}: ${e?.message}`);
29783
29821
  const peer = this.peers.get(pid);
@@ -29798,9 +29836,9 @@ ${e?.stack || ""}`);
29798
29836
  }
29799
29837
  if (parsed.type === "ping") {
29800
29838
  const peer = this.peers.get(peerId);
29801
- if (peer?.commandChannel?.isOpen()) {
29839
+ if (peer?.dataChannel?.isOpen()) {
29802
29840
  try {
29803
- peer.commandChannel.sendMessage(JSON.stringify({ type: "pong", ts: Date.now() }));
29841
+ peer.dataChannel.sendMessage(JSON.stringify({ type: "pong", ts: Date.now() }));
29804
29842
  } catch {
29805
29843
  }
29806
29844
  }
@@ -29821,7 +29859,7 @@ ${e?.stack || ""}`);
29821
29859
  peer.screenshotActive = true;
29822
29860
  peer.screenshotIdeType = parsed.ideType;
29823
29861
  peer.needsFirstFrame = true;
29824
- log(`screenshot_start: peer=${peerId}, ideType=${parsed.ideType}, channelOpen=${!!peer.screenshotChannel}, state=${peer.state}`);
29862
+ log(`screenshot_start: peer=${peerId}, ideType=${parsed.ideType}, channelOpen=${!!peer.dataChannel}, state=${peer.state}`);
29825
29863
  } else {
29826
29864
  log(`screenshot_start: peer ${peerId} NOT FOUND in peers map!`);
29827
29865
  }
@@ -29875,9 +29913,9 @@ ${e?.stack || ""}`);
29875
29913
  });
29876
29914
  let sentAny = false;
29877
29915
  for (const peer of this.peers.values()) {
29878
- if (peer.state !== "connected" || !peer.commandChannel) continue;
29916
+ if (peer.state !== "connected" || !peer.dataChannel) continue;
29879
29917
  try {
29880
- peer.commandChannel.sendMessage(payload);
29918
+ peer.dataChannel.sendMessage(payload);
29881
29919
  sentAny = true;
29882
29920
  } catch {
29883
29921
  }
@@ -29893,9 +29931,9 @@ ${e?.stack || ""}`);
29893
29931
  });
29894
29932
  let sentAny = false;
29895
29933
  for (const peer of this.peers.values()) {
29896
- if (peer.state !== "connected" || !peer.commandChannel) continue;
29934
+ if (peer.state !== "connected" || !peer.dataChannel) continue;
29897
29935
  try {
29898
- peer.commandChannel.sendMessage(payload);
29936
+ peer.dataChannel.sendMessage(payload);
29899
29937
  sentAny = true;
29900
29938
  } catch {
29901
29939
  }
@@ -29913,9 +29951,9 @@ ${e?.stack || ""}`);
29913
29951
  const msg = JSON.stringify({ type: "pty_output", cliType, data });
29914
29952
  let sentAny = false;
29915
29953
  for (const peer of this.peers.values()) {
29916
- if (peer.state !== "connected" || !peer.commandChannel) continue;
29954
+ if (peer.state !== "connected" || !peer.dataChannel) continue;
29917
29955
  try {
29918
- peer.commandChannel.sendMessage(msg);
29956
+ peer.dataChannel.sendMessage(msg);
29919
29957
  sentAny = true;
29920
29958
  } catch {
29921
29959
  }
@@ -29925,11 +29963,11 @@ ${e?.stack || ""}`);
29925
29963
  /** Send scrollback on peer connect */
29926
29964
  sendPtyScrollback(peerId) {
29927
29965
  const peer = this.peers.get(peerId);
29928
- if (!peer?.commandChannel) return;
29966
+ if (!peer?.dataChannel) return;
29929
29967
  for (const [cliType, buffer] of this.ptyScrollback) {
29930
29968
  if (!buffer) continue;
29931
29969
  try {
29932
- peer.commandChannel.sendMessage(JSON.stringify({
29970
+ peer.dataChannel.sendMessage(JSON.stringify({
29933
29971
  type: "pty_output",
29934
29972
  cliType,
29935
29973
  data: buffer,
@@ -29951,17 +29989,17 @@ ${e?.stack || ""}`);
29951
29989
  const CHUNK_SIZE = 6e4;
29952
29990
  for (const [pid, peer] of this.peers.entries()) {
29953
29991
  if (debugOnce) {
29954
- logDebug(`sendScreenshot peer=${pid}: state=${peer.state}, hasSsCh=${!!peer.screenshotChannel}, ssActive=${peer.screenshotActive}, chOpen=${peer.screenshotChannel?.isOpen?.() ?? "N/A"}, bufSize=${buffer.length}`);
29992
+ logDebug(`sendScreenshot peer=${pid}: state=${peer.state}, hasCh=${!!peer.dataChannel}, ssActive=${peer.screenshotActive}, chOpen=${peer.dataChannel?.isOpen?.() ?? "N/A"}, bufSize=${buffer.length}`);
29955
29993
  }
29956
- if (peer.state !== "connected" || !peer.screenshotChannel || !peer.screenshotActive) continue;
29994
+ if (peer.state !== "connected" || !peer.dataChannel || !peer.screenshotActive) continue;
29957
29995
  try {
29958
- if (!peer.screenshotChannel.isOpen()) continue;
29996
+ if (!peer.dataChannel.isOpen()) continue;
29959
29997
  const header = Buffer.alloc(4);
29960
29998
  header.writeUInt32BE(buffer.length, 0);
29961
- peer.screenshotChannel.sendMessageBinary(header);
29999
+ peer.dataChannel.sendMessageBinary(header);
29962
30000
  for (let offset = 0; offset < buffer.length; offset += CHUNK_SIZE) {
29963
30001
  const chunk = buffer.subarray(offset, Math.min(offset + CHUNK_SIZE, buffer.length));
29964
- peer.screenshotChannel.sendMessageBinary(chunk);
30002
+ peer.dataChannel.sendMessageBinary(chunk);
29965
30003
  }
29966
30004
  sentAny = true;
29967
30005
  if (peer.needsFirstFrame) {
@@ -30038,9 +30076,9 @@ ${e?.stack || ""}`);
30038
30076
  }
30039
30077
  sendToPeer(peerId, data) {
30040
30078
  const peer = this.peers.get(peerId);
30041
- if (!peer?.commandChannel) return;
30079
+ if (!peer?.dataChannel) return;
30042
30080
  try {
30043
- peer.commandChannel.sendMessage(JSON.stringify(data));
30081
+ peer.dataChannel.sendMessage(JSON.stringify(data));
30044
30082
  } catch {
30045
30083
  }
30046
30084
  }
@@ -30126,12 +30164,8 @@ ${e?.stack || ""}`);
30126
30164
  if (peer.failedCleanupTimer) clearTimeout(peer.failedCleanupTimer);
30127
30165
  if (peer.heartbeatTimer) clearInterval(peer.heartbeatTimer);
30128
30166
  if (peer.connectionTimeout) clearTimeout(peer.connectionTimeout);
30129
- if (peer.screenshotChannel) try {
30130
- peer.screenshotChannel.close();
30131
- } catch {
30132
- }
30133
- if (peer.commandChannel) try {
30134
- peer.commandChannel.close();
30167
+ if (peer.dataChannel) try {
30168
+ peer.dataChannel.close();
30135
30169
  } catch {
30136
30170
  }
30137
30171
  if (peer.pc) try {
@@ -30161,8 +30195,8 @@ ${e?.stack || ""}`);
30161
30195
  return;
30162
30196
  }
30163
30197
  try {
30164
- if (p.commandChannel?.isOpen()) {
30165
- p.commandChannel.sendMessage(JSON.stringify({ type: "ping", ts: Date.now() }));
30198
+ if (p.dataChannel?.isOpen()) {
30199
+ p.dataChannel.sendMessage(JSON.stringify({ type: "ping", ts: Date.now() }));
30166
30200
  }
30167
30201
  } catch {
30168
30202
  }
@@ -30394,7 +30428,7 @@ var init_adhdev_daemon = __esm({
30394
30428
  fs2 = __toESM(require("fs"));
30395
30429
  path2 = __toESM(require("path"));
30396
30430
  import_chalk = __toESM(require("chalk"));
30397
- pkgVersion = "0.5.37";
30431
+ pkgVersion = "0.5.40";
30398
30432
  if (pkgVersion === "unknown") {
30399
30433
  try {
30400
30434
  const possiblePaths = [
@@ -30486,7 +30520,9 @@ var init_adhdev_daemon = __esm({
30486
30520
  streams: [stream],
30487
30521
  messages: stream.messages || [],
30488
30522
  status: stream.status || "idle",
30489
- activeModal: stream.activeModal || null
30523
+ activeModal: stream.activeModal || null,
30524
+ model: stream.model || void 0,
30525
+ mode: stream.mode || void 0
30490
30526
  });
30491
30527
  }
30492
30528
  }