adhdev 0.5.58 → 0.5.61
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 +222 -164
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +55 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -19054,11 +19054,35 @@ var require_dist = __commonJS({
|
|
|
19054
19054
|
}
|
|
19055
19055
|
this.autoApproveBusy = true;
|
|
19056
19056
|
try {
|
|
19057
|
-
|
|
19057
|
+
let targetButton = _chatData?.activeModal?.buttons?.[0] || "Run";
|
|
19058
|
+
const buttons = _chatData?.activeModal?.buttons || [];
|
|
19059
|
+
for (const b of buttons) {
|
|
19060
|
+
const lower = String(b).toLowerCase().replace(/[^\w]/g, "");
|
|
19061
|
+
if (/^(run|approve|accept|yes|allow|always|proceed|save)/.test(lower)) {
|
|
19062
|
+
targetButton = b;
|
|
19063
|
+
break;
|
|
19064
|
+
}
|
|
19065
|
+
}
|
|
19066
|
+
const script = scriptFn({ action: "approve", button: targetButton, buttonText: targetButton });
|
|
19058
19067
|
if (!script) return;
|
|
19059
|
-
LOG5.info("IdeInstance", `[IdeInstance:${this.type}] autoApprove: executing resolveAction`);
|
|
19060
|
-
|
|
19068
|
+
LOG5.info("IdeInstance", `[IdeInstance:${this.type}] autoApprove: executing resolveAction for "${targetButton}"`);
|
|
19069
|
+
let rawResult = await cdp.evaluate(script, 1e4);
|
|
19070
|
+
if (typeof rawResult === "string") {
|
|
19071
|
+
try {
|
|
19072
|
+
rawResult = JSON.parse(rawResult);
|
|
19073
|
+
} catch {
|
|
19074
|
+
}
|
|
19075
|
+
}
|
|
19076
|
+
const result = rawResult;
|
|
19061
19077
|
LOG5.info("IdeInstance", `[IdeInstance:${this.type}] autoApprove result: ${JSON.stringify(result)?.slice(0, 200)}`);
|
|
19078
|
+
if (result?.found && result.x != null && result.y != null) {
|
|
19079
|
+
const x = result.x;
|
|
19080
|
+
const y = result.y;
|
|
19081
|
+
const anyCdp = cdp;
|
|
19082
|
+
await anyCdp.send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "left", clickCount: 1 });
|
|
19083
|
+
await anyCdp.send("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "left", clickCount: 1 });
|
|
19084
|
+
LOG5.info("IdeInstance", `[IdeInstance:${this.type}] autoApprove: dispatched mouse event at ${x},${y}`);
|
|
19085
|
+
}
|
|
19062
19086
|
this.pushEvent({
|
|
19063
19087
|
event: "agent:auto_approved",
|
|
19064
19088
|
chatTitle: _chatData?.title || this.provider.name,
|
|
@@ -19070,7 +19094,7 @@ var require_dist = __commonJS({
|
|
|
19070
19094
|
} finally {
|
|
19071
19095
|
setTimeout(() => {
|
|
19072
19096
|
this.autoApproveBusy = false;
|
|
19073
|
-
},
|
|
19097
|
+
}, 1e3);
|
|
19074
19098
|
}
|
|
19075
19099
|
}
|
|
19076
19100
|
};
|
|
@@ -19650,13 +19674,23 @@ var require_dist = __commonJS({
|
|
|
19650
19674
|
if (!text) return { success: false, error: "text required" };
|
|
19651
19675
|
const _log = (msg) => LOG5.debug("Command", `[send_chat] ${msg}`);
|
|
19652
19676
|
const provider = h.getProvider();
|
|
19677
|
+
const _logSendSuccess = (method, targetAgent) => {
|
|
19678
|
+
h.historyWriter.appendNewMessages(
|
|
19679
|
+
targetAgent || provider?.type || h.currentIdeType || "unknown_agent",
|
|
19680
|
+
[{ role: "user", content: text, receivedAt: Date.now() }],
|
|
19681
|
+
void 0,
|
|
19682
|
+
// title
|
|
19683
|
+
args?.instanceId
|
|
19684
|
+
);
|
|
19685
|
+
return { success: true, sent: true, method, targetAgent };
|
|
19686
|
+
};
|
|
19653
19687
|
if (provider?.category === "cli" || provider?.category === "acp") {
|
|
19654
19688
|
const adapter = h.getCliAdapter(provider.type);
|
|
19655
19689
|
if (adapter) {
|
|
19656
19690
|
_log(`${provider.category} adapter: ${adapter.cliType}`);
|
|
19657
19691
|
try {
|
|
19658
19692
|
await adapter.sendMessage(text);
|
|
19659
|
-
return
|
|
19693
|
+
return _logSendSuccess(`${provider.category}-adapter`, adapter.cliType);
|
|
19660
19694
|
} catch (e) {
|
|
19661
19695
|
return { success: false, error: `${provider.category} send failed: ${e.message}` };
|
|
19662
19696
|
}
|
|
@@ -19676,7 +19710,7 @@ var require_dist = __commonJS({
|
|
|
19676
19710
|
}
|
|
19677
19711
|
if (parsed?.sent) {
|
|
19678
19712
|
_log(`Extension script sent OK`);
|
|
19679
|
-
return
|
|
19713
|
+
return _logSendSuccess("extension-script");
|
|
19680
19714
|
}
|
|
19681
19715
|
if (parsed?.needsTypeAndSend) {
|
|
19682
19716
|
_log(`Extension needsTypeAndSend \u2192 AgentStreamManager`);
|
|
@@ -19689,7 +19723,7 @@ var require_dist = __commonJS({
|
|
|
19689
19723
|
const ok = await h.agentStream.sendToAgent(h.getCdp(), provider.type, text, h.currentIdeType);
|
|
19690
19724
|
if (ok) {
|
|
19691
19725
|
_log(`AgentStreamManager sent OK`);
|
|
19692
|
-
return
|
|
19726
|
+
return _logSendSuccess("agent-stream");
|
|
19693
19727
|
}
|
|
19694
19728
|
}
|
|
19695
19729
|
return { success: false, error: `Extension '${provider.type}' send failed` };
|
|
@@ -19716,7 +19750,7 @@ var require_dist = __commonJS({
|
|
|
19716
19750
|
}
|
|
19717
19751
|
if (wvParsed?.sent) {
|
|
19718
19752
|
_log(`webviewSendMessage (priority) OK`);
|
|
19719
|
-
return
|
|
19753
|
+
return _logSendSuccess("webview-script-priority");
|
|
19720
19754
|
}
|
|
19721
19755
|
_log(`webviewSendMessage (priority) did not confirm sent, falling through`);
|
|
19722
19756
|
}
|
|
@@ -19729,7 +19763,7 @@ var require_dist = __commonJS({
|
|
|
19729
19763
|
const sent = await targetCdp.typeAndSend(provider.inputSelector, text);
|
|
19730
19764
|
if (sent) {
|
|
19731
19765
|
_log(`typeAndSend(provider.inputSelector=${provider.inputSelector}) success`);
|
|
19732
|
-
return
|
|
19766
|
+
return _logSendSuccess("typeAndSend-provider");
|
|
19733
19767
|
}
|
|
19734
19768
|
} catch (e) {
|
|
19735
19769
|
_log(`typeAndSend(provider) failed: ${e.message}`);
|
|
@@ -19748,14 +19782,14 @@ var require_dist = __commonJS({
|
|
|
19748
19782
|
}
|
|
19749
19783
|
if (parsed?.sent) {
|
|
19750
19784
|
_log(`sendMessage script OK`);
|
|
19751
|
-
return
|
|
19785
|
+
return _logSendSuccess("script");
|
|
19752
19786
|
}
|
|
19753
19787
|
if (parsed?.needsTypeAndSend && parsed?.selector) {
|
|
19754
19788
|
try {
|
|
19755
19789
|
const sent = await targetCdp.typeAndSend(parsed.selector, text);
|
|
19756
19790
|
if (sent) {
|
|
19757
19791
|
_log(`typeAndSend(script.selector=${parsed.selector}) success`);
|
|
19758
|
-
return
|
|
19792
|
+
return _logSendSuccess("typeAndSend-script");
|
|
19759
19793
|
}
|
|
19760
19794
|
} catch (e) {
|
|
19761
19795
|
_log(`typeAndSend(script.selector) failed: ${e.message}`);
|
|
@@ -19777,7 +19811,7 @@ var require_dist = __commonJS({
|
|
|
19777
19811
|
}
|
|
19778
19812
|
if (wvParsed?.sent) {
|
|
19779
19813
|
_log(`webviewSendMessage OK`);
|
|
19780
|
-
return
|
|
19814
|
+
return _logSendSuccess("webview-script");
|
|
19781
19815
|
}
|
|
19782
19816
|
}
|
|
19783
19817
|
} catch (e) {
|
|
@@ -19790,7 +19824,7 @@ var require_dist = __commonJS({
|
|
|
19790
19824
|
const sent = await targetCdp.typeAndSendAt(x, y, text);
|
|
19791
19825
|
if (sent) {
|
|
19792
19826
|
_log(`typeAndSendAt(${x},${y}) success`);
|
|
19793
|
-
return
|
|
19827
|
+
return _logSendSuccess("typeAndSendAt-script");
|
|
19794
19828
|
}
|
|
19795
19829
|
} catch (e) {
|
|
19796
19830
|
_log(`typeAndSendAt failed: ${e.message}`);
|
|
@@ -21216,6 +21250,8 @@ var require_dist = __commonJS({
|
|
|
21216
21250
|
}
|
|
21217
21251
|
async handleRefreshScripts(_args) {
|
|
21218
21252
|
if (this._ctx.providerLoader) {
|
|
21253
|
+
await this._ctx.providerLoader.fetchLatest().catch(() => {
|
|
21254
|
+
});
|
|
21219
21255
|
this._ctx.providerLoader.reload();
|
|
21220
21256
|
return { success: true };
|
|
21221
21257
|
}
|
|
@@ -23242,13 +23278,12 @@ var require_dist = __commonJS({
|
|
|
23242
23278
|
/Always\s*allow/i,
|
|
23243
23279
|
/\(y\/n\)/i,
|
|
23244
23280
|
/\[Y\/n\]/i,
|
|
23245
|
-
/Run\s
|
|
23246
|
-
|
|
23247
|
-
// Claude Code v2 approval
|
|
23281
|
+
/Run\s+\w+\s+command/i,
|
|
23282
|
+
// "Run bash command" etc — requires surrounding words to avoid false matches
|
|
23248
23283
|
/Yes,?\s*don'?t\s*ask/i,
|
|
23249
23284
|
// "Yes, don't ask again" (Claude Code)
|
|
23250
|
-
/
|
|
23251
|
-
//
|
|
23285
|
+
/\bDeny\b/i
|
|
23286
|
+
// Word-boundary match — avoids "allow & deny" in /permissions menu text
|
|
23252
23287
|
];
|
|
23253
23288
|
function defaultCleanOutput(raw, _lastUserInput) {
|
|
23254
23289
|
return stripAnsi(raw).trim();
|
|
@@ -23277,7 +23312,7 @@ var require_dist = __commonJS({
|
|
|
23277
23312
|
this.timeouts = {
|
|
23278
23313
|
ptyFlush: t.ptyFlush ?? 50,
|
|
23279
23314
|
dialogAccept: t.dialogAccept ?? 300,
|
|
23280
|
-
approvalCooldown: t.approvalCooldown ??
|
|
23315
|
+
approvalCooldown: t.approvalCooldown ?? 3e3,
|
|
23281
23316
|
generatingIdle: t.generatingIdle ?? 6e3,
|
|
23282
23317
|
idleFinish: t.idleFinish ?? 5e3,
|
|
23283
23318
|
maxResponse: t.maxResponse ?? 3e5,
|
|
@@ -30462,7 +30497,7 @@ var init_adhdev_daemon = __esm({
|
|
|
30462
30497
|
fs2 = __toESM(require("fs"));
|
|
30463
30498
|
path2 = __toESM(require("path"));
|
|
30464
30499
|
import_chalk = __toESM(require("chalk"));
|
|
30465
|
-
pkgVersion = "0.5.
|
|
30500
|
+
pkgVersion = "0.5.61";
|
|
30466
30501
|
if (pkgVersion === "unknown") {
|
|
30467
30502
|
try {
|
|
30468
30503
|
const possiblePaths = [
|
|
@@ -31186,6 +31221,124 @@ ${import_chalk2.default.cyan("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u
|
|
|
31186
31221
|
}
|
|
31187
31222
|
});
|
|
31188
31223
|
|
|
31224
|
+
// src/cli/cdp-utils.ts
|
|
31225
|
+
var cdp_utils_exports = {};
|
|
31226
|
+
__export(cdp_utils_exports, {
|
|
31227
|
+
directCdpEval: () => directCdpEval,
|
|
31228
|
+
sendDaemonCommand: () => sendDaemonCommand
|
|
31229
|
+
});
|
|
31230
|
+
async function sendDaemonCommand(cmd, args = {}, port = 19222) {
|
|
31231
|
+
const WebSocket2 = (await import("ws")).default;
|
|
31232
|
+
const { DAEMON_WS_PATH } = await Promise.resolve().then(() => __toESM(require_dist()));
|
|
31233
|
+
return new Promise((resolve, reject) => {
|
|
31234
|
+
const wsUrl = `ws://127.0.0.1:${port}${DAEMON_WS_PATH || "/daemon"}`;
|
|
31235
|
+
const ws = new WebSocket2(wsUrl);
|
|
31236
|
+
const timeout = setTimeout(() => {
|
|
31237
|
+
ws.close();
|
|
31238
|
+
reject(new Error("Timeout: no response from daemon after 15s"));
|
|
31239
|
+
}, 15e3);
|
|
31240
|
+
ws.on("open", () => {
|
|
31241
|
+
ws.send(JSON.stringify({
|
|
31242
|
+
type: "ext:register",
|
|
31243
|
+
payload: {
|
|
31244
|
+
ideType: "cli-debug",
|
|
31245
|
+
ideVersion: "1.0.0",
|
|
31246
|
+
extensionVersion: "1.0.0",
|
|
31247
|
+
instanceId: `cli-debug-${Date.now()}`,
|
|
31248
|
+
machineId: "cli"
|
|
31249
|
+
}
|
|
31250
|
+
}));
|
|
31251
|
+
setTimeout(() => {
|
|
31252
|
+
ws.send(JSON.stringify({
|
|
31253
|
+
type: "ext:command",
|
|
31254
|
+
payload: { command: cmd, args, messageId: `cli-${Date.now()}` }
|
|
31255
|
+
}));
|
|
31256
|
+
}, 200);
|
|
31257
|
+
});
|
|
31258
|
+
ws.on("message", (data) => {
|
|
31259
|
+
try {
|
|
31260
|
+
const msg = JSON.parse(data.toString());
|
|
31261
|
+
if (msg.type === "daemon:command_result" || msg.type === "command_result") {
|
|
31262
|
+
clearTimeout(timeout);
|
|
31263
|
+
ws.close();
|
|
31264
|
+
resolve(msg.payload?.result || msg.payload || msg);
|
|
31265
|
+
}
|
|
31266
|
+
} catch {
|
|
31267
|
+
}
|
|
31268
|
+
});
|
|
31269
|
+
ws.on("error", (e) => {
|
|
31270
|
+
clearTimeout(timeout);
|
|
31271
|
+
reject(new Error(`Cannot connect to daemon at port ${port}: ${e.message}
|
|
31272
|
+
Is 'adhdev daemon' running?`));
|
|
31273
|
+
});
|
|
31274
|
+
ws.on("close", () => {
|
|
31275
|
+
clearTimeout(timeout);
|
|
31276
|
+
});
|
|
31277
|
+
});
|
|
31278
|
+
}
|
|
31279
|
+
async function directCdpEval(expression, port = 9222) {
|
|
31280
|
+
const http = await import("http");
|
|
31281
|
+
const targets = await new Promise((resolve, reject) => {
|
|
31282
|
+
http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
31283
|
+
let data = "";
|
|
31284
|
+
res.on("data", (c) => data += c);
|
|
31285
|
+
res.on("end", () => {
|
|
31286
|
+
try {
|
|
31287
|
+
resolve(JSON.parse(data));
|
|
31288
|
+
} catch {
|
|
31289
|
+
reject(new Error("Invalid JSON"));
|
|
31290
|
+
}
|
|
31291
|
+
});
|
|
31292
|
+
}).on("error", (e) => reject(new Error(`Cannot reach CDP at port ${port}: ${e.message}`)));
|
|
31293
|
+
});
|
|
31294
|
+
const isNonMain = (title) => !title || /extension-output|ADHDev CDP|Debug Console|Output\s*$|Launchpad/i.test(title);
|
|
31295
|
+
const pages = targets.filter((t) => (t.type === "page" || t.type === "Page") && t.webSocketDebuggerUrl);
|
|
31296
|
+
const mainPages = pages.filter((t) => !isNonMain(t.title || ""));
|
|
31297
|
+
const target = (mainPages.length > 0 ? mainPages[0] : pages[0]) || targets[0];
|
|
31298
|
+
if (!target?.webSocketDebuggerUrl) throw new Error("No CDP target found");
|
|
31299
|
+
const WebSocket2 = (await import("ws")).default;
|
|
31300
|
+
return new Promise((resolve, reject) => {
|
|
31301
|
+
const ws = new WebSocket2(target.webSocketDebuggerUrl);
|
|
31302
|
+
const timeout = setTimeout(() => {
|
|
31303
|
+
ws.close();
|
|
31304
|
+
reject(new Error("CDP timeout"));
|
|
31305
|
+
}, 15e3);
|
|
31306
|
+
let id = 1;
|
|
31307
|
+
ws.on("open", () => {
|
|
31308
|
+
const stripped = expression.replace(/\/\*[\s\S]*?\*\//g, "").trimStart();
|
|
31309
|
+
const isAsync = stripped.startsWith("(async");
|
|
31310
|
+
ws.send(JSON.stringify({
|
|
31311
|
+
id: id++,
|
|
31312
|
+
method: "Runtime.evaluate",
|
|
31313
|
+
params: { expression, returnByValue: true, awaitPromise: isAsync }
|
|
31314
|
+
}));
|
|
31315
|
+
});
|
|
31316
|
+
ws.on("message", (data) => {
|
|
31317
|
+
const msg = JSON.parse(data.toString());
|
|
31318
|
+
if (msg.id) {
|
|
31319
|
+
clearTimeout(timeout);
|
|
31320
|
+
ws.close();
|
|
31321
|
+
if (msg.result?.result?.value !== void 0) {
|
|
31322
|
+
resolve(msg.result.result.value);
|
|
31323
|
+
} else if (msg.result?.exceptionDetails) {
|
|
31324
|
+
reject(new Error(msg.result.exceptionDetails.text));
|
|
31325
|
+
} else {
|
|
31326
|
+
resolve(msg.result);
|
|
31327
|
+
}
|
|
31328
|
+
}
|
|
31329
|
+
});
|
|
31330
|
+
ws.on("error", (e) => {
|
|
31331
|
+
clearTimeout(timeout);
|
|
31332
|
+
reject(new Error(`CDP connection failed: ${e.message}`));
|
|
31333
|
+
});
|
|
31334
|
+
});
|
|
31335
|
+
}
|
|
31336
|
+
var init_cdp_utils = __esm({
|
|
31337
|
+
"src/cli/cdp-utils.ts"() {
|
|
31338
|
+
"use strict";
|
|
31339
|
+
}
|
|
31340
|
+
});
|
|
31341
|
+
|
|
31189
31342
|
// src/cli/index.ts
|
|
31190
31343
|
var import_commander = require("commander");
|
|
31191
31344
|
var import_chalk6 = __toESM(require("chalk"));
|
|
@@ -31645,116 +31798,7 @@ function registerDaemonCommands(program2, pkgVersion3) {
|
|
|
31645
31798
|
|
|
31646
31799
|
// src/cli/provider-commands.ts
|
|
31647
31800
|
var import_chalk5 = __toESM(require("chalk"));
|
|
31648
|
-
|
|
31649
|
-
// src/cli/cdp-utils.ts
|
|
31650
|
-
async function sendDaemonCommand(cmd, args = {}, port = 19222) {
|
|
31651
|
-
const WebSocket2 = (await import("ws")).default;
|
|
31652
|
-
const { DAEMON_WS_PATH } = await Promise.resolve().then(() => __toESM(require_dist()));
|
|
31653
|
-
return new Promise((resolve, reject) => {
|
|
31654
|
-
const wsUrl = `ws://127.0.0.1:${port}${DAEMON_WS_PATH || "/daemon"}`;
|
|
31655
|
-
const ws = new WebSocket2(wsUrl);
|
|
31656
|
-
const timeout = setTimeout(() => {
|
|
31657
|
-
ws.close();
|
|
31658
|
-
reject(new Error("Timeout: no response from daemon after 15s"));
|
|
31659
|
-
}, 15e3);
|
|
31660
|
-
ws.on("open", () => {
|
|
31661
|
-
ws.send(JSON.stringify({
|
|
31662
|
-
type: "ext:register",
|
|
31663
|
-
payload: {
|
|
31664
|
-
ideType: "cli-debug",
|
|
31665
|
-
ideVersion: "1.0.0",
|
|
31666
|
-
extensionVersion: "1.0.0",
|
|
31667
|
-
instanceId: `cli-debug-${Date.now()}`,
|
|
31668
|
-
machineId: "cli"
|
|
31669
|
-
}
|
|
31670
|
-
}));
|
|
31671
|
-
setTimeout(() => {
|
|
31672
|
-
ws.send(JSON.stringify({
|
|
31673
|
-
type: "ext:command",
|
|
31674
|
-
payload: { command: cmd, args, messageId: `cli-${Date.now()}` }
|
|
31675
|
-
}));
|
|
31676
|
-
}, 200);
|
|
31677
|
-
});
|
|
31678
|
-
ws.on("message", (data) => {
|
|
31679
|
-
try {
|
|
31680
|
-
const msg = JSON.parse(data.toString());
|
|
31681
|
-
if (msg.type === "daemon:command_result" || msg.type === "command_result") {
|
|
31682
|
-
clearTimeout(timeout);
|
|
31683
|
-
ws.close();
|
|
31684
|
-
resolve(msg.payload?.result || msg.payload || msg);
|
|
31685
|
-
}
|
|
31686
|
-
} catch {
|
|
31687
|
-
}
|
|
31688
|
-
});
|
|
31689
|
-
ws.on("error", (e) => {
|
|
31690
|
-
clearTimeout(timeout);
|
|
31691
|
-
reject(new Error(`Cannot connect to daemon at port ${port}: ${e.message}
|
|
31692
|
-
Is 'adhdev daemon' running?`));
|
|
31693
|
-
});
|
|
31694
|
-
ws.on("close", () => {
|
|
31695
|
-
clearTimeout(timeout);
|
|
31696
|
-
});
|
|
31697
|
-
});
|
|
31698
|
-
}
|
|
31699
|
-
async function directCdpEval(expression, port = 9222) {
|
|
31700
|
-
const http = await import("http");
|
|
31701
|
-
const targets = await new Promise((resolve, reject) => {
|
|
31702
|
-
http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
31703
|
-
let data = "";
|
|
31704
|
-
res.on("data", (c) => data += c);
|
|
31705
|
-
res.on("end", () => {
|
|
31706
|
-
try {
|
|
31707
|
-
resolve(JSON.parse(data));
|
|
31708
|
-
} catch {
|
|
31709
|
-
reject(new Error("Invalid JSON"));
|
|
31710
|
-
}
|
|
31711
|
-
});
|
|
31712
|
-
}).on("error", (e) => reject(new Error(`Cannot reach CDP at port ${port}: ${e.message}`)));
|
|
31713
|
-
});
|
|
31714
|
-
const isNonMain = (title) => !title || /extension-output|ADHDev CDP|Debug Console|Output\s*$|Launchpad/i.test(title);
|
|
31715
|
-
const pages = targets.filter((t) => (t.type === "page" || t.type === "Page") && t.webSocketDebuggerUrl);
|
|
31716
|
-
const mainPages = pages.filter((t) => !isNonMain(t.title || ""));
|
|
31717
|
-
const target = (mainPages.length > 0 ? mainPages[0] : pages[0]) || targets[0];
|
|
31718
|
-
if (!target?.webSocketDebuggerUrl) throw new Error("No CDP target found");
|
|
31719
|
-
const WebSocket2 = (await import("ws")).default;
|
|
31720
|
-
return new Promise((resolve, reject) => {
|
|
31721
|
-
const ws = new WebSocket2(target.webSocketDebuggerUrl);
|
|
31722
|
-
const timeout = setTimeout(() => {
|
|
31723
|
-
ws.close();
|
|
31724
|
-
reject(new Error("CDP timeout"));
|
|
31725
|
-
}, 15e3);
|
|
31726
|
-
let id = 1;
|
|
31727
|
-
ws.on("open", () => {
|
|
31728
|
-
const stripped = expression.replace(/\/\*[\s\S]*?\*\//g, "").trimStart();
|
|
31729
|
-
const isAsync = stripped.startsWith("(async");
|
|
31730
|
-
ws.send(JSON.stringify({
|
|
31731
|
-
id: id++,
|
|
31732
|
-
method: "Runtime.evaluate",
|
|
31733
|
-
params: { expression, returnByValue: true, awaitPromise: isAsync }
|
|
31734
|
-
}));
|
|
31735
|
-
});
|
|
31736
|
-
ws.on("message", (data) => {
|
|
31737
|
-
const msg = JSON.parse(data.toString());
|
|
31738
|
-
if (msg.id) {
|
|
31739
|
-
clearTimeout(timeout);
|
|
31740
|
-
ws.close();
|
|
31741
|
-
if (msg.result?.result?.value !== void 0) {
|
|
31742
|
-
resolve(msg.result.result.value);
|
|
31743
|
-
} else if (msg.result?.exceptionDetails) {
|
|
31744
|
-
reject(new Error(msg.result.exceptionDetails.text));
|
|
31745
|
-
} else {
|
|
31746
|
-
resolve(msg.result);
|
|
31747
|
-
}
|
|
31748
|
-
}
|
|
31749
|
-
});
|
|
31750
|
-
ws.on("error", (e) => {
|
|
31751
|
-
clearTimeout(timeout);
|
|
31752
|
-
reject(new Error(`CDP connection failed: ${e.message}`));
|
|
31753
|
-
});
|
|
31754
|
-
});
|
|
31755
|
-
}
|
|
31756
|
-
|
|
31757
|
-
// src/cli/provider-commands.ts
|
|
31801
|
+
init_cdp_utils();
|
|
31758
31802
|
function registerProviderCommands(program2) {
|
|
31759
31803
|
const provider = program2.command("provider").description("\u{1F50C} Provider management \u2014 list, test, reload providers");
|
|
31760
31804
|
provider.command("list").description("List all loaded providers").option("-j, --json", "Output raw JSON").action(async (options) => {
|
|
@@ -31797,49 +31841,63 @@ function registerProviderCommands(program2) {
|
|
|
31797
31841
|
process.exit(1);
|
|
31798
31842
|
}
|
|
31799
31843
|
});
|
|
31800
|
-
provider.command("reload").description("Hot-reload all providers
|
|
31844
|
+
provider.command("reload").description("Hot-reload all providers from upstream and restart daemon provider state").action(async () => {
|
|
31801
31845
|
try {
|
|
31802
|
-
const
|
|
31803
|
-
const result = await
|
|
31804
|
-
|
|
31805
|
-
|
|
31806
|
-
port: 19280,
|
|
31807
|
-
path: "/api/providers/reload",
|
|
31808
|
-
method: "POST",
|
|
31809
|
-
headers: { "Content-Type": "application/json", "Content-Length": "2" }
|
|
31810
|
-
}, (res) => {
|
|
31811
|
-
let data = "";
|
|
31812
|
-
res.on("data", (c) => data += c);
|
|
31813
|
-
res.on("end", () => {
|
|
31814
|
-
try {
|
|
31815
|
-
resolve(JSON.parse(data));
|
|
31816
|
-
} catch {
|
|
31817
|
-
resolve({ raw: data });
|
|
31818
|
-
}
|
|
31819
|
-
});
|
|
31820
|
-
});
|
|
31821
|
-
req.on("error", () => reject(new Error("DevServer not reachable. Run: adhdev daemon --dev")));
|
|
31822
|
-
req.write("{}");
|
|
31823
|
-
req.end();
|
|
31824
|
-
});
|
|
31825
|
-
if (result.reloaded) {
|
|
31826
|
-
console.log(import_chalk5.default.green(`
|
|
31827
|
-
\u2713 Providers reloaded: ${result.providers?.length || 0} loaded
|
|
31846
|
+
const { sendDaemonCommand: sendDaemonCommand2 } = await Promise.resolve().then(() => (init_cdp_utils(), cdp_utils_exports));
|
|
31847
|
+
const result = await sendDaemonCommand2("refresh_scripts", {});
|
|
31848
|
+
console.log(import_chalk5.default.green(`
|
|
31849
|
+
\u2713 Providers reloaded
|
|
31828
31850
|
`));
|
|
31829
|
-
|
|
31851
|
+
if (result?.providers?.length) {
|
|
31852
|
+
for (const p of result.providers) {
|
|
31830
31853
|
console.log(` ${import_chalk5.default.green("\u2713")} ${p.type} (${p.category}) \u2014 ${p.name}`);
|
|
31831
31854
|
}
|
|
31832
31855
|
console.log();
|
|
31833
|
-
}
|
|
31834
|
-
|
|
31856
|
+
}
|
|
31857
|
+
} catch {
|
|
31858
|
+
try {
|
|
31859
|
+
const http = await import("http");
|
|
31860
|
+
const result = await new Promise((resolve, reject) => {
|
|
31861
|
+
const req = http.request({
|
|
31862
|
+
hostname: "127.0.0.1",
|
|
31863
|
+
port: 19280,
|
|
31864
|
+
path: "/api/providers/reload",
|
|
31865
|
+
method: "POST",
|
|
31866
|
+
headers: { "Content-Type": "application/json", "Content-Length": "2" }
|
|
31867
|
+
}, (res) => {
|
|
31868
|
+
let data = "";
|
|
31869
|
+
res.on("data", (c) => data += c);
|
|
31870
|
+
res.on("end", () => {
|
|
31871
|
+
try {
|
|
31872
|
+
resolve(JSON.parse(data));
|
|
31873
|
+
} catch {
|
|
31874
|
+
resolve({ raw: data });
|
|
31875
|
+
}
|
|
31876
|
+
});
|
|
31877
|
+
});
|
|
31878
|
+
req.on("error", () => reject(new Error("Daemon not reachable. Is adhdev daemon running?")));
|
|
31879
|
+
req.write("{}");
|
|
31880
|
+
req.end();
|
|
31881
|
+
});
|
|
31882
|
+
if (result.reloaded) {
|
|
31883
|
+
console.log(import_chalk5.default.green(`
|
|
31884
|
+
\u2713 Providers reloaded: ${result.providers?.length || 0} loaded
|
|
31885
|
+
`));
|
|
31886
|
+
for (const p of result.providers || []) {
|
|
31887
|
+
console.log(` ${import_chalk5.default.green("\u2713")} ${p.type} (${p.category}) \u2014 ${p.name}`);
|
|
31888
|
+
}
|
|
31889
|
+
console.log();
|
|
31890
|
+
} else {
|
|
31891
|
+
console.log(import_chalk5.default.red(`
|
|
31835
31892
|
\u2717 Reload failed: ${result.error || "unknown"}
|
|
31836
31893
|
`));
|
|
31837
|
-
|
|
31838
|
-
|
|
31839
|
-
|
|
31894
|
+
}
|
|
31895
|
+
} catch (e) {
|
|
31896
|
+
console.error(import_chalk5.default.red(`
|
|
31840
31897
|
\u2717 ${e.message}
|
|
31841
31898
|
`));
|
|
31842
|
-
|
|
31899
|
+
process.exit(1);
|
|
31900
|
+
}
|
|
31843
31901
|
}
|
|
31844
31902
|
});
|
|
31845
31903
|
provider.command("create <type>").description("Scaffold a new provider.js from template").option("-n, --name <name>", "Display name").option("-c, --category <cat>", "Category: ide, extension, cli", "ide").option("--builtin", "Create in builtin directory (default: ~/.adhdev/providers/)").action(async (type, options) => {
|