adhdev 0.5.38 → 0.5.41
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 +89 -62
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +89 -62
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20664,7 +20664,13 @@ var require_dist = __commonJS({
|
|
|
20664
20664
|
return { success: false, error: `Script '${actualScriptName}' not available for ${agentType}` };
|
|
20665
20665
|
}
|
|
20666
20666
|
const scriptFn = provider.scripts[actualScriptName];
|
|
20667
|
-
const
|
|
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);
|
|
20668
20674
|
if (!scriptCode) return { success: false, error: `Script '${actualScriptName}' returned null` };
|
|
20669
20675
|
const cdpKey = provider.category === "ide" ? h.currentIdeType || agentType : h.currentIdeType || ideType;
|
|
20670
20676
|
LOG5.info("Command", `[ExtScript] provider=${provider.type} category=${provider.category} cdpKey=${cdpKey}`);
|
|
@@ -20681,10 +20687,31 @@ var require_dist = __commonJS({
|
|
|
20681
20687
|
break;
|
|
20682
20688
|
}
|
|
20683
20689
|
}
|
|
20684
|
-
|
|
20685
|
-
|
|
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);
|
|
20686
20714
|
}
|
|
20687
|
-
result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
|
|
20688
20715
|
} else if (hasWebviewScript && cdp.evaluateInWebviewFrame) {
|
|
20689
20716
|
const matchText = provider.webviewMatchText;
|
|
20690
20717
|
const matchFn = matchText ? (body) => body.includes(matchText) : void 0;
|
|
@@ -26503,14 +26530,29 @@ async (params) => {
|
|
|
26503
26530
|
return;
|
|
26504
26531
|
}
|
|
26505
26532
|
this.log(`Exec script length: ${scriptCode.length}, first 50 chars: ${scriptCode.slice(0, 50)}...`);
|
|
26506
|
-
const isWebviewScript =
|
|
26533
|
+
const isWebviewScript = scriptName.toLowerCase().includes("webview");
|
|
26507
26534
|
let raw;
|
|
26508
|
-
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) {
|
|
26509
26554
|
const matchText = provider.webviewMatchText;
|
|
26510
26555
|
const matchFn = matchText ? (body2) => body2.includes(matchText) : void 0;
|
|
26511
|
-
if (!cdp.evaluateInWebviewFrame) {
|
|
26512
|
-
throw new Error(`CDP manager does not support evaluateInWebviewFrame`);
|
|
26513
|
-
}
|
|
26514
26556
|
raw = await cdp.evaluateInWebviewFrame(scriptCode, matchFn);
|
|
26515
26557
|
} else {
|
|
26516
26558
|
raw = await cdp.evaluate(scriptCode, 3e4);
|
|
@@ -29497,7 +29539,7 @@ ${e?.stack || ""}`);
|
|
|
29497
29539
|
}
|
|
29498
29540
|
get isConnected() {
|
|
29499
29541
|
for (const peer of this.peers.values()) {
|
|
29500
|
-
if (peer.state === "connected" && peer.
|
|
29542
|
+
if (peer.state === "connected" && peer.dataChannel) return true;
|
|
29501
29543
|
}
|
|
29502
29544
|
return false;
|
|
29503
29545
|
}
|
|
@@ -29617,9 +29659,9 @@ ${e?.stack || ""}`);
|
|
|
29617
29659
|
if (oldestPeer) {
|
|
29618
29660
|
log(`P2P limit reached (${connectedCount}/${limits.maxP2PConnections}). Evicting oldest peer ${oldestPeer.id.slice(0, 12)}\u2026`);
|
|
29619
29661
|
const evictedPeer = this.peers.get(oldestPeer.id);
|
|
29620
|
-
if (evictedPeer?.
|
|
29662
|
+
if (evictedPeer?.dataChannel?.isOpen()) {
|
|
29621
29663
|
try {
|
|
29622
|
-
evictedPeer.
|
|
29664
|
+
evictedPeer.dataChannel.sendMessage(JSON.stringify({
|
|
29623
29665
|
type: "p2p_evicted",
|
|
29624
29666
|
reason: "P2P_LIMIT_REACHED",
|
|
29625
29667
|
maxconnections: limits.maxP2PConnections
|
|
@@ -29686,8 +29728,7 @@ ${e?.stack || ""}`);
|
|
|
29686
29728
|
const entry = {
|
|
29687
29729
|
peerId: pid,
|
|
29688
29730
|
pc,
|
|
29689
|
-
|
|
29690
|
-
commandChannel: null,
|
|
29731
|
+
dataChannel: null,
|
|
29691
29732
|
state: "connecting",
|
|
29692
29733
|
screenshotActive: false,
|
|
29693
29734
|
connectedAt: Date.now(),
|
|
@@ -29750,41 +29791,31 @@ ${e?.stack || ""}`);
|
|
|
29750
29791
|
}
|
|
29751
29792
|
}
|
|
29752
29793
|
});
|
|
29753
|
-
const
|
|
29754
|
-
|
|
29755
|
-
|
|
29794
|
+
const dataCh = pc.createDataChannel("data");
|
|
29795
|
+
entry.dataChannel = dataCh;
|
|
29796
|
+
dataCh.onOpen(() => {
|
|
29797
|
+
log(`Data channel OPEN for peer ${pid}`);
|
|
29756
29798
|
const peer = this.peers.get(pid);
|
|
29757
29799
|
if (peer) {
|
|
29758
|
-
peer.screenshotChannel = screenshotCh;
|
|
29759
29800
|
peer.state = "connected";
|
|
29760
29801
|
this.notifyStateChange();
|
|
29761
29802
|
if (peer.screenshotActive) {
|
|
29762
29803
|
log(`Screenshots auto-starting for peer ${pid} (was waiting for channel open)`);
|
|
29763
29804
|
}
|
|
29764
29805
|
}
|
|
29806
|
+
setTimeout(() => this.sendPtyScrollback(pid), 100);
|
|
29765
29807
|
});
|
|
29766
|
-
|
|
29767
|
-
log(`
|
|
29808
|
+
dataCh.onClosed(() => {
|
|
29809
|
+
log(`Data channel CLOSED for peer ${pid}`);
|
|
29768
29810
|
const peer = this.peers.get(pid);
|
|
29769
|
-
if (peer?.
|
|
29770
|
-
peer.
|
|
29811
|
+
if (peer?.dataChannel === dataCh) {
|
|
29812
|
+
peer.dataChannel = null;
|
|
29771
29813
|
peer.state = "failed";
|
|
29772
29814
|
this.notifyStateChange();
|
|
29773
29815
|
}
|
|
29774
29816
|
});
|
|
29775
|
-
|
|
29776
|
-
|
|
29777
|
-
entry.commandChannel = filesCh;
|
|
29778
|
-
filesCh.onOpen(() => {
|
|
29779
|
-
log(`Command channel OPEN for peer ${pid}`);
|
|
29780
|
-
setTimeout(() => this.sendPtyScrollback(pid), 100);
|
|
29781
|
-
});
|
|
29782
|
-
filesCh.onClosed(() => {
|
|
29783
|
-
const peer = this.peers.get(pid);
|
|
29784
|
-
if (peer?.commandChannel === filesCh) peer.commandChannel = null;
|
|
29785
|
-
});
|
|
29786
|
-
filesCh.onError((err) => log(`Command channel error: ${err}`));
|
|
29787
|
-
filesCh.onMessage((msg) => this.handleCommandMessage(pid, msg));
|
|
29817
|
+
dataCh.onError((err) => log(`Data channel error: ${err}`));
|
|
29818
|
+
dataCh.onMessage((msg) => this.handleCommandMessage(pid, msg));
|
|
29788
29819
|
} catch (e) {
|
|
29789
29820
|
log(`connection failed for peer ${pid}: ${e?.message}`);
|
|
29790
29821
|
const peer = this.peers.get(pid);
|
|
@@ -29805,9 +29836,9 @@ ${e?.stack || ""}`);
|
|
|
29805
29836
|
}
|
|
29806
29837
|
if (parsed.type === "ping") {
|
|
29807
29838
|
const peer = this.peers.get(peerId);
|
|
29808
|
-
if (peer?.
|
|
29839
|
+
if (peer?.dataChannel?.isOpen()) {
|
|
29809
29840
|
try {
|
|
29810
|
-
peer.
|
|
29841
|
+
peer.dataChannel.sendMessage(JSON.stringify({ type: "pong", ts: Date.now() }));
|
|
29811
29842
|
} catch {
|
|
29812
29843
|
}
|
|
29813
29844
|
}
|
|
@@ -29828,7 +29859,7 @@ ${e?.stack || ""}`);
|
|
|
29828
29859
|
peer.screenshotActive = true;
|
|
29829
29860
|
peer.screenshotIdeType = parsed.ideType;
|
|
29830
29861
|
peer.needsFirstFrame = true;
|
|
29831
|
-
log(`screenshot_start: peer=${peerId}, ideType=${parsed.ideType}, channelOpen=${!!peer.
|
|
29862
|
+
log(`screenshot_start: peer=${peerId}, ideType=${parsed.ideType}, channelOpen=${!!peer.dataChannel}, state=${peer.state}`);
|
|
29832
29863
|
} else {
|
|
29833
29864
|
log(`screenshot_start: peer ${peerId} NOT FOUND in peers map!`);
|
|
29834
29865
|
}
|
|
@@ -29882,9 +29913,9 @@ ${e?.stack || ""}`);
|
|
|
29882
29913
|
});
|
|
29883
29914
|
let sentAny = false;
|
|
29884
29915
|
for (const peer of this.peers.values()) {
|
|
29885
|
-
if (peer.state !== "connected" || !peer.
|
|
29916
|
+
if (peer.state !== "connected" || !peer.dataChannel) continue;
|
|
29886
29917
|
try {
|
|
29887
|
-
peer.
|
|
29918
|
+
peer.dataChannel.sendMessage(payload);
|
|
29888
29919
|
sentAny = true;
|
|
29889
29920
|
} catch {
|
|
29890
29921
|
}
|
|
@@ -29900,9 +29931,9 @@ ${e?.stack || ""}`);
|
|
|
29900
29931
|
});
|
|
29901
29932
|
let sentAny = false;
|
|
29902
29933
|
for (const peer of this.peers.values()) {
|
|
29903
|
-
if (peer.state !== "connected" || !peer.
|
|
29934
|
+
if (peer.state !== "connected" || !peer.dataChannel) continue;
|
|
29904
29935
|
try {
|
|
29905
|
-
peer.
|
|
29936
|
+
peer.dataChannel.sendMessage(payload);
|
|
29906
29937
|
sentAny = true;
|
|
29907
29938
|
} catch {
|
|
29908
29939
|
}
|
|
@@ -29920,9 +29951,9 @@ ${e?.stack || ""}`);
|
|
|
29920
29951
|
const msg = JSON.stringify({ type: "pty_output", cliType, data });
|
|
29921
29952
|
let sentAny = false;
|
|
29922
29953
|
for (const peer of this.peers.values()) {
|
|
29923
|
-
if (peer.state !== "connected" || !peer.
|
|
29954
|
+
if (peer.state !== "connected" || !peer.dataChannel) continue;
|
|
29924
29955
|
try {
|
|
29925
|
-
peer.
|
|
29956
|
+
peer.dataChannel.sendMessage(msg);
|
|
29926
29957
|
sentAny = true;
|
|
29927
29958
|
} catch {
|
|
29928
29959
|
}
|
|
@@ -29932,11 +29963,11 @@ ${e?.stack || ""}`);
|
|
|
29932
29963
|
/** Send scrollback on peer connect */
|
|
29933
29964
|
sendPtyScrollback(peerId) {
|
|
29934
29965
|
const peer = this.peers.get(peerId);
|
|
29935
|
-
if (!peer?.
|
|
29966
|
+
if (!peer?.dataChannel) return;
|
|
29936
29967
|
for (const [cliType, buffer] of this.ptyScrollback) {
|
|
29937
29968
|
if (!buffer) continue;
|
|
29938
29969
|
try {
|
|
29939
|
-
peer.
|
|
29970
|
+
peer.dataChannel.sendMessage(JSON.stringify({
|
|
29940
29971
|
type: "pty_output",
|
|
29941
29972
|
cliType,
|
|
29942
29973
|
data: buffer,
|
|
@@ -29958,17 +29989,17 @@ ${e?.stack || ""}`);
|
|
|
29958
29989
|
const CHUNK_SIZE = 6e4;
|
|
29959
29990
|
for (const [pid, peer] of this.peers.entries()) {
|
|
29960
29991
|
if (debugOnce) {
|
|
29961
|
-
logDebug(`sendScreenshot peer=${pid}: state=${peer.state},
|
|
29992
|
+
logDebug(`sendScreenshot peer=${pid}: state=${peer.state}, hasCh=${!!peer.dataChannel}, ssActive=${peer.screenshotActive}, chOpen=${peer.dataChannel?.isOpen?.() ?? "N/A"}, bufSize=${buffer.length}`);
|
|
29962
29993
|
}
|
|
29963
|
-
if (peer.state !== "connected" || !peer.
|
|
29994
|
+
if (peer.state !== "connected" || !peer.dataChannel || !peer.screenshotActive) continue;
|
|
29964
29995
|
try {
|
|
29965
|
-
if (!peer.
|
|
29996
|
+
if (!peer.dataChannel.isOpen()) continue;
|
|
29966
29997
|
const header = Buffer.alloc(4);
|
|
29967
29998
|
header.writeUInt32BE(buffer.length, 0);
|
|
29968
|
-
peer.
|
|
29999
|
+
peer.dataChannel.sendMessageBinary(header);
|
|
29969
30000
|
for (let offset = 0; offset < buffer.length; offset += CHUNK_SIZE) {
|
|
29970
30001
|
const chunk = buffer.subarray(offset, Math.min(offset + CHUNK_SIZE, buffer.length));
|
|
29971
|
-
peer.
|
|
30002
|
+
peer.dataChannel.sendMessageBinary(chunk);
|
|
29972
30003
|
}
|
|
29973
30004
|
sentAny = true;
|
|
29974
30005
|
if (peer.needsFirstFrame) {
|
|
@@ -30045,9 +30076,9 @@ ${e?.stack || ""}`);
|
|
|
30045
30076
|
}
|
|
30046
30077
|
sendToPeer(peerId, data) {
|
|
30047
30078
|
const peer = this.peers.get(peerId);
|
|
30048
|
-
if (!peer?.
|
|
30079
|
+
if (!peer?.dataChannel) return;
|
|
30049
30080
|
try {
|
|
30050
|
-
peer.
|
|
30081
|
+
peer.dataChannel.sendMessage(JSON.stringify(data));
|
|
30051
30082
|
} catch {
|
|
30052
30083
|
}
|
|
30053
30084
|
}
|
|
@@ -30133,12 +30164,8 @@ ${e?.stack || ""}`);
|
|
|
30133
30164
|
if (peer.failedCleanupTimer) clearTimeout(peer.failedCleanupTimer);
|
|
30134
30165
|
if (peer.heartbeatTimer) clearInterval(peer.heartbeatTimer);
|
|
30135
30166
|
if (peer.connectionTimeout) clearTimeout(peer.connectionTimeout);
|
|
30136
|
-
if (peer.
|
|
30137
|
-
peer.
|
|
30138
|
-
} catch {
|
|
30139
|
-
}
|
|
30140
|
-
if (peer.commandChannel) try {
|
|
30141
|
-
peer.commandChannel.close();
|
|
30167
|
+
if (peer.dataChannel) try {
|
|
30168
|
+
peer.dataChannel.close();
|
|
30142
30169
|
} catch {
|
|
30143
30170
|
}
|
|
30144
30171
|
if (peer.pc) try {
|
|
@@ -30168,8 +30195,8 @@ ${e?.stack || ""}`);
|
|
|
30168
30195
|
return;
|
|
30169
30196
|
}
|
|
30170
30197
|
try {
|
|
30171
|
-
if (p.
|
|
30172
|
-
p.
|
|
30198
|
+
if (p.dataChannel?.isOpen()) {
|
|
30199
|
+
p.dataChannel.sendMessage(JSON.stringify({ type: "ping", ts: Date.now() }));
|
|
30173
30200
|
}
|
|
30174
30201
|
} catch {
|
|
30175
30202
|
}
|
|
@@ -30401,7 +30428,7 @@ var init_adhdev_daemon = __esm({
|
|
|
30401
30428
|
fs2 = __toESM(require("fs"));
|
|
30402
30429
|
path2 = __toESM(require("path"));
|
|
30403
30430
|
import_chalk = __toESM(require("chalk"));
|
|
30404
|
-
pkgVersion = "0.5.
|
|
30431
|
+
pkgVersion = "0.5.41";
|
|
30405
30432
|
if (pkgVersion === "unknown") {
|
|
30406
30433
|
try {
|
|
30407
30434
|
const possiblePaths = [
|