adhdev 0.6.57 → 0.6.59
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 +381 -209
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +341 -169
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -536,15 +536,15 @@ var init_ide_detector = __esm({
|
|
|
536
536
|
|
|
537
537
|
// ../daemon-core/src/detection/cli-detector.ts
|
|
538
538
|
function execAsync(cmd, timeoutMs = 5e3) {
|
|
539
|
-
return new Promise((
|
|
539
|
+
return new Promise((resolve7) => {
|
|
540
540
|
const child = (0, import_child_process2.exec)(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
|
|
541
541
|
if (err || !stdout?.trim()) {
|
|
542
|
-
|
|
542
|
+
resolve7(null);
|
|
543
543
|
} else {
|
|
544
|
-
|
|
544
|
+
resolve7(stdout.trim());
|
|
545
545
|
}
|
|
546
546
|
});
|
|
547
|
-
child.on("error", () =>
|
|
547
|
+
child.on("error", () => resolve7(null));
|
|
548
548
|
});
|
|
549
549
|
}
|
|
550
550
|
async function detectCLIs(providerLoader) {
|
|
@@ -926,7 +926,7 @@ var init_manager = __esm({
|
|
|
926
926
|
* Returns multiple entries if multiple IDE windows are open on same port
|
|
927
927
|
*/
|
|
928
928
|
static listAllTargets(port) {
|
|
929
|
-
return new Promise((
|
|
929
|
+
return new Promise((resolve7) => {
|
|
930
930
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
931
931
|
let data = "";
|
|
932
932
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -942,16 +942,16 @@ var init_manager = __esm({
|
|
|
942
942
|
(t) => !isNonMain(t.title || "") && t.url?.includes("workbench.html") && !t.url?.includes("agent")
|
|
943
943
|
);
|
|
944
944
|
const fallbackPages = pages.filter((t) => !isNonMain(t.title || ""));
|
|
945
|
-
|
|
945
|
+
resolve7(mainPages.length > 0 ? mainPages : fallbackPages);
|
|
946
946
|
} catch {
|
|
947
|
-
|
|
947
|
+
resolve7([]);
|
|
948
948
|
}
|
|
949
949
|
});
|
|
950
950
|
});
|
|
951
|
-
req.on("error", () =>
|
|
951
|
+
req.on("error", () => resolve7([]));
|
|
952
952
|
req.setTimeout(2e3, () => {
|
|
953
953
|
req.destroy();
|
|
954
|
-
|
|
954
|
+
resolve7([]);
|
|
955
955
|
});
|
|
956
956
|
});
|
|
957
957
|
}
|
|
@@ -991,7 +991,7 @@ var init_manager = __esm({
|
|
|
991
991
|
}
|
|
992
992
|
}
|
|
993
993
|
findTargetOnPort(port) {
|
|
994
|
-
return new Promise((
|
|
994
|
+
return new Promise((resolve7) => {
|
|
995
995
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
996
996
|
let data = "";
|
|
997
997
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -1002,7 +1002,7 @@ var init_manager = __esm({
|
|
|
1002
1002
|
(t) => (t.type === "page" || t.type === "browser" || t.type === "Page") && t.webSocketDebuggerUrl
|
|
1003
1003
|
);
|
|
1004
1004
|
if (pages.length === 0) {
|
|
1005
|
-
|
|
1005
|
+
resolve7(targets.find((t) => t.webSocketDebuggerUrl) || null);
|
|
1006
1006
|
return;
|
|
1007
1007
|
}
|
|
1008
1008
|
const mainPages = pages.filter((t) => !this.isNonMainTitle(t.title || ""));
|
|
@@ -1012,24 +1012,24 @@ var init_manager = __esm({
|
|
|
1012
1012
|
const specific = list.find((t) => t.id === this._targetId);
|
|
1013
1013
|
if (specific) {
|
|
1014
1014
|
this._pageTitle = specific.title || "";
|
|
1015
|
-
|
|
1015
|
+
resolve7(specific);
|
|
1016
1016
|
} else {
|
|
1017
1017
|
this.log(`[CDP] Target ${this._targetId} not found in page list`);
|
|
1018
|
-
|
|
1018
|
+
resolve7(null);
|
|
1019
1019
|
}
|
|
1020
1020
|
return;
|
|
1021
1021
|
}
|
|
1022
1022
|
this._pageTitle = list[0]?.title || "";
|
|
1023
|
-
|
|
1023
|
+
resolve7(list[0]);
|
|
1024
1024
|
} catch {
|
|
1025
|
-
|
|
1025
|
+
resolve7(null);
|
|
1026
1026
|
}
|
|
1027
1027
|
});
|
|
1028
1028
|
});
|
|
1029
|
-
req.on("error", () =>
|
|
1029
|
+
req.on("error", () => resolve7(null));
|
|
1030
1030
|
req.setTimeout(2e3, () => {
|
|
1031
1031
|
req.destroy();
|
|
1032
|
-
|
|
1032
|
+
resolve7(null);
|
|
1033
1033
|
});
|
|
1034
1034
|
});
|
|
1035
1035
|
}
|
|
@@ -1040,7 +1040,7 @@ var init_manager = __esm({
|
|
|
1040
1040
|
this.extensionProviders = providers;
|
|
1041
1041
|
}
|
|
1042
1042
|
connectToTarget(wsUrl) {
|
|
1043
|
-
return new Promise((
|
|
1043
|
+
return new Promise((resolve7) => {
|
|
1044
1044
|
this.ws = new import_ws.default(wsUrl);
|
|
1045
1045
|
this.ws.on("open", async () => {
|
|
1046
1046
|
this._connected = true;
|
|
@@ -1050,17 +1050,17 @@ var init_manager = __esm({
|
|
|
1050
1050
|
}
|
|
1051
1051
|
this.connectBrowserWs().catch(() => {
|
|
1052
1052
|
});
|
|
1053
|
-
|
|
1053
|
+
resolve7(true);
|
|
1054
1054
|
});
|
|
1055
1055
|
this.ws.on("message", (data) => {
|
|
1056
1056
|
try {
|
|
1057
1057
|
const msg = JSON.parse(data.toString());
|
|
1058
1058
|
if (msg.id && this.pending.has(msg.id)) {
|
|
1059
|
-
const { resolve:
|
|
1059
|
+
const { resolve: resolve8, reject } = this.pending.get(msg.id);
|
|
1060
1060
|
this.pending.delete(msg.id);
|
|
1061
1061
|
this.failureCount = 0;
|
|
1062
1062
|
if (msg.error) reject(new Error(msg.error.message));
|
|
1063
|
-
else
|
|
1063
|
+
else resolve8(msg.result);
|
|
1064
1064
|
} else if (msg.method === "Runtime.executionContextCreated") {
|
|
1065
1065
|
this.contexts.add(msg.params.context.id);
|
|
1066
1066
|
} else if (msg.method === "Runtime.executionContextDestroyed") {
|
|
@@ -1083,7 +1083,7 @@ var init_manager = __esm({
|
|
|
1083
1083
|
this.ws.on("error", (err) => {
|
|
1084
1084
|
this.log(`[CDP] WebSocket error: ${err.message}`);
|
|
1085
1085
|
this._connected = false;
|
|
1086
|
-
|
|
1086
|
+
resolve7(false);
|
|
1087
1087
|
});
|
|
1088
1088
|
});
|
|
1089
1089
|
}
|
|
@@ -1097,7 +1097,7 @@ var init_manager = __esm({
|
|
|
1097
1097
|
return;
|
|
1098
1098
|
}
|
|
1099
1099
|
this.log(`[CDP] Connecting browser WS for target discovery...`);
|
|
1100
|
-
await new Promise((
|
|
1100
|
+
await new Promise((resolve7, reject) => {
|
|
1101
1101
|
this.browserWs = new import_ws.default(browserWsUrl);
|
|
1102
1102
|
this.browserWs.on("open", async () => {
|
|
1103
1103
|
this._browserConnected = true;
|
|
@@ -1107,16 +1107,16 @@ var init_manager = __esm({
|
|
|
1107
1107
|
} catch (e) {
|
|
1108
1108
|
this.log(`[CDP] setDiscoverTargets failed: ${e.message}`);
|
|
1109
1109
|
}
|
|
1110
|
-
|
|
1110
|
+
resolve7();
|
|
1111
1111
|
});
|
|
1112
1112
|
this.browserWs.on("message", (data) => {
|
|
1113
1113
|
try {
|
|
1114
1114
|
const msg = JSON.parse(data.toString());
|
|
1115
1115
|
if (msg.id && this.browserPending.has(msg.id)) {
|
|
1116
|
-
const { resolve:
|
|
1116
|
+
const { resolve: resolve8, reject: reject2 } = this.browserPending.get(msg.id);
|
|
1117
1117
|
this.browserPending.delete(msg.id);
|
|
1118
1118
|
if (msg.error) reject2(new Error(msg.error.message));
|
|
1119
|
-
else
|
|
1119
|
+
else resolve8(msg.result);
|
|
1120
1120
|
}
|
|
1121
1121
|
} catch {
|
|
1122
1122
|
}
|
|
@@ -1136,31 +1136,31 @@ var init_manager = __esm({
|
|
|
1136
1136
|
}
|
|
1137
1137
|
}
|
|
1138
1138
|
getBrowserWsUrl() {
|
|
1139
|
-
return new Promise((
|
|
1139
|
+
return new Promise((resolve7) => {
|
|
1140
1140
|
const req = http.get(`http://127.0.0.1:${this.port}/json/version`, (res) => {
|
|
1141
1141
|
let data = "";
|
|
1142
1142
|
res.on("data", (chunk) => data += chunk.toString());
|
|
1143
1143
|
res.on("end", () => {
|
|
1144
1144
|
try {
|
|
1145
1145
|
const info = JSON.parse(data);
|
|
1146
|
-
|
|
1146
|
+
resolve7(info.webSocketDebuggerUrl || null);
|
|
1147
1147
|
} catch {
|
|
1148
|
-
|
|
1148
|
+
resolve7(null);
|
|
1149
1149
|
}
|
|
1150
1150
|
});
|
|
1151
1151
|
});
|
|
1152
|
-
req.on("error", () =>
|
|
1152
|
+
req.on("error", () => resolve7(null));
|
|
1153
1153
|
req.setTimeout(3e3, () => {
|
|
1154
1154
|
req.destroy();
|
|
1155
|
-
|
|
1155
|
+
resolve7(null);
|
|
1156
1156
|
});
|
|
1157
1157
|
});
|
|
1158
1158
|
}
|
|
1159
1159
|
sendBrowser(method, params = {}, timeoutMs = 15e3) {
|
|
1160
|
-
return new Promise((
|
|
1160
|
+
return new Promise((resolve7, reject) => {
|
|
1161
1161
|
if (!this.browserWs || !this._browserConnected) return reject(new Error("Browser WS not connected"));
|
|
1162
1162
|
const id = this.browserMsgId++;
|
|
1163
|
-
this.browserPending.set(id, { resolve:
|
|
1163
|
+
this.browserPending.set(id, { resolve: resolve7, reject });
|
|
1164
1164
|
this.browserWs.send(JSON.stringify({ id, method, params }));
|
|
1165
1165
|
setTimeout(() => {
|
|
1166
1166
|
if (this.browserPending.has(id)) {
|
|
@@ -1200,11 +1200,11 @@ var init_manager = __esm({
|
|
|
1200
1200
|
}
|
|
1201
1201
|
// ─── CDP Protocol ────────────────────────────────────────
|
|
1202
1202
|
sendInternal(method, params = {}, timeoutMs = 15e3) {
|
|
1203
|
-
return new Promise((
|
|
1203
|
+
return new Promise((resolve7, reject) => {
|
|
1204
1204
|
if (!this.ws || !this._connected) return reject(new Error("CDP not connected"));
|
|
1205
1205
|
if (this.ws.readyState !== import_ws.default.OPEN) return reject(new Error("WebSocket not open"));
|
|
1206
1206
|
const id = this.msgId++;
|
|
1207
|
-
this.pending.set(id, { resolve:
|
|
1207
|
+
this.pending.set(id, { resolve: resolve7, reject });
|
|
1208
1208
|
this.ws.send(JSON.stringify({ id, method, params }));
|
|
1209
1209
|
setTimeout(() => {
|
|
1210
1210
|
if (this.pending.has(id)) {
|
|
@@ -1453,7 +1453,7 @@ var init_manager = __esm({
|
|
|
1453
1453
|
const browserWs = this.browserWs;
|
|
1454
1454
|
let msgId = this.browserMsgId;
|
|
1455
1455
|
const sendWs = (method, params = {}, sessionId) => {
|
|
1456
|
-
return new Promise((
|
|
1456
|
+
return new Promise((resolve7, reject) => {
|
|
1457
1457
|
const mid = msgId++;
|
|
1458
1458
|
this.browserMsgId = msgId;
|
|
1459
1459
|
const handler = (raw) => {
|
|
@@ -1462,7 +1462,7 @@ var init_manager = __esm({
|
|
|
1462
1462
|
if (msg.id === mid) {
|
|
1463
1463
|
browserWs.removeListener("message", handler);
|
|
1464
1464
|
if (msg.error) reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
1465
|
-
else
|
|
1465
|
+
else resolve7(msg.result);
|
|
1466
1466
|
}
|
|
1467
1467
|
} catch {
|
|
1468
1468
|
}
|
|
@@ -1644,14 +1644,14 @@ var init_manager = __esm({
|
|
|
1644
1644
|
if (!ws2 || ws2.readyState !== import_ws.default.OPEN) {
|
|
1645
1645
|
throw new Error("CDP not connected");
|
|
1646
1646
|
}
|
|
1647
|
-
return new Promise((
|
|
1647
|
+
return new Promise((resolve7, reject) => {
|
|
1648
1648
|
const id = getNextId();
|
|
1649
1649
|
pendingMap.set(id, {
|
|
1650
1650
|
resolve: (result) => {
|
|
1651
1651
|
if (result?.result?.subtype === "error") {
|
|
1652
1652
|
reject(new Error(result.result.description));
|
|
1653
1653
|
} else {
|
|
1654
|
-
|
|
1654
|
+
resolve7(result?.result?.value);
|
|
1655
1655
|
}
|
|
1656
1656
|
},
|
|
1657
1657
|
reject
|
|
@@ -1683,10 +1683,10 @@ var init_manager = __esm({
|
|
|
1683
1683
|
throw new Error("CDP not connected");
|
|
1684
1684
|
}
|
|
1685
1685
|
const sendViaSession = (method, params = {}) => {
|
|
1686
|
-
return new Promise((
|
|
1686
|
+
return new Promise((resolve7, reject) => {
|
|
1687
1687
|
const pendingMap = this._browserConnected ? this.browserPending : this.pending;
|
|
1688
1688
|
const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
|
|
1689
|
-
pendingMap.set(id, { resolve:
|
|
1689
|
+
pendingMap.set(id, { resolve: resolve7, reject });
|
|
1690
1690
|
ws2.send(JSON.stringify({ id, sessionId, method, params }));
|
|
1691
1691
|
setTimeout(() => {
|
|
1692
1692
|
if (pendingMap.has(id)) {
|
|
@@ -2386,6 +2386,8 @@ var init_chat_history = __esm({
|
|
|
2386
2386
|
lastSeenCounts = /* @__PURE__ */ new Map();
|
|
2387
2387
|
/** Last seen message hash per agent (deduplication) */
|
|
2388
2388
|
lastSeenHashes = /* @__PURE__ */ new Map();
|
|
2389
|
+
/** Last seen append-only terminal transcript per agent */
|
|
2390
|
+
lastSeenTerminal = /* @__PURE__ */ new Map();
|
|
2389
2391
|
rotated = false;
|
|
2390
2392
|
/**
|
|
2391
2393
|
* Append new messages to history
|
|
@@ -2443,10 +2445,51 @@ var init_chat_history = __esm({
|
|
|
2443
2445
|
} catch {
|
|
2444
2446
|
}
|
|
2445
2447
|
}
|
|
2448
|
+
appendTerminalHistory(agentType, terminalHistory, sessionTitle, instanceId) {
|
|
2449
|
+
const next = String(terminalHistory || "");
|
|
2450
|
+
if (!next.trim()) return;
|
|
2451
|
+
try {
|
|
2452
|
+
const dedupKey = instanceId ? `${agentType}:${instanceId}:terminal` : `${agentType}:terminal`;
|
|
2453
|
+
const prev = this.lastSeenTerminal.get(dedupKey) || "";
|
|
2454
|
+
if (prev === next) return;
|
|
2455
|
+
let delta = "";
|
|
2456
|
+
if (!prev) {
|
|
2457
|
+
delta = next;
|
|
2458
|
+
} else if (next.startsWith(prev)) {
|
|
2459
|
+
delta = next.slice(prev.length);
|
|
2460
|
+
} else if (prev.includes(next)) {
|
|
2461
|
+
this.lastSeenTerminal.set(dedupKey, next);
|
|
2462
|
+
return;
|
|
2463
|
+
} else {
|
|
2464
|
+
delta = `
|
|
2465
|
+
|
|
2466
|
+
[terminal snapshot reset ${(/* @__PURE__ */ new Date()).toISOString()} | ${sessionTitle || agentType}]
|
|
2467
|
+
${next}`;
|
|
2468
|
+
}
|
|
2469
|
+
if (!delta) {
|
|
2470
|
+
this.lastSeenTerminal.set(dedupKey, next);
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
const dir = path4.join(HISTORY_DIR, this.sanitize(agentType));
|
|
2474
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
2475
|
+
const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
2476
|
+
const filePrefix = instanceId ? `${this.sanitize(instanceId)}_` : "";
|
|
2477
|
+
const filePath = path4.join(dir, `${filePrefix}${date5}.terminal.log`);
|
|
2478
|
+
fs3.appendFileSync(filePath, delta, "utf-8");
|
|
2479
|
+
this.lastSeenTerminal.set(dedupKey, next);
|
|
2480
|
+
if (!this.rotated) {
|
|
2481
|
+
this.rotated = true;
|
|
2482
|
+
this.rotateOldFiles().catch(() => {
|
|
2483
|
+
});
|
|
2484
|
+
}
|
|
2485
|
+
} catch {
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2446
2488
|
/** Called when agent session is explicitly changed */
|
|
2447
2489
|
onSessionChange(agentType) {
|
|
2448
2490
|
this.lastSeenHashes.delete(agentType);
|
|
2449
2491
|
this.lastSeenCounts.delete(agentType);
|
|
2492
|
+
this.lastSeenTerminal.delete(`${agentType}:terminal`);
|
|
2450
2493
|
}
|
|
2451
2494
|
/** Delete history files older than 30 days */
|
|
2452
2495
|
async rotateOldFiles() {
|
|
@@ -2456,7 +2499,7 @@ var init_chat_history = __esm({
|
|
|
2456
2499
|
const agentDirs = fs3.readdirSync(HISTORY_DIR, { withFileTypes: true }).filter((d) => d.isDirectory());
|
|
2457
2500
|
for (const dir of agentDirs) {
|
|
2458
2501
|
const dirPath = path4.join(HISTORY_DIR, dir.name);
|
|
2459
|
-
const files = fs3.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl"));
|
|
2502
|
+
const files = fs3.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl") || f.endsWith(".terminal.log"));
|
|
2460
2503
|
for (const file2 of files) {
|
|
2461
2504
|
const filePath = path4.join(dirPath, file2);
|
|
2462
2505
|
const stat = fs3.statSync(filePath);
|
|
@@ -3364,7 +3407,13 @@ async function handleReadChat(h, args) {
|
|
|
3364
3407
|
_log(`${provider.category} adapter: ${adapter.cliType}`);
|
|
3365
3408
|
const status = adapter.getStatus?.();
|
|
3366
3409
|
if (status) {
|
|
3367
|
-
return {
|
|
3410
|
+
return {
|
|
3411
|
+
success: true,
|
|
3412
|
+
messages: status.messages || [],
|
|
3413
|
+
status: status.status,
|
|
3414
|
+
activeModal: status.activeModal,
|
|
3415
|
+
terminalHistory: status.terminalHistory || ""
|
|
3416
|
+
};
|
|
3368
3417
|
}
|
|
3369
3418
|
}
|
|
3370
3419
|
return { success: false, error: `${provider.category} adapter not found` };
|
|
@@ -5134,7 +5183,7 @@ var init_handler = __esm({
|
|
|
5134
5183
|
try {
|
|
5135
5184
|
const http3 = await import("http");
|
|
5136
5185
|
const postData = JSON.stringify(body);
|
|
5137
|
-
const result = await new Promise((
|
|
5186
|
+
const result = await new Promise((resolve7, reject) => {
|
|
5138
5187
|
const req = http3.request({
|
|
5139
5188
|
hostname: "127.0.0.1",
|
|
5140
5189
|
port: 19280,
|
|
@@ -5146,9 +5195,9 @@ var init_handler = __esm({
|
|
|
5146
5195
|
res.on("data", (chunk) => data += chunk);
|
|
5147
5196
|
res.on("end", () => {
|
|
5148
5197
|
try {
|
|
5149
|
-
|
|
5198
|
+
resolve7(JSON.parse(data));
|
|
5150
5199
|
} catch {
|
|
5151
|
-
|
|
5200
|
+
resolve7({ raw: data });
|
|
5152
5201
|
}
|
|
5153
5202
|
});
|
|
5154
5203
|
});
|
|
@@ -5166,15 +5215,15 @@ var init_handler = __esm({
|
|
|
5166
5215
|
if (!providerType) return { success: false, error: "providerType required" };
|
|
5167
5216
|
try {
|
|
5168
5217
|
const http3 = await import("http");
|
|
5169
|
-
const result = await new Promise((
|
|
5218
|
+
const result = await new Promise((resolve7, reject) => {
|
|
5170
5219
|
http3.get(`http://127.0.0.1:19280/api/providers/${providerType}/${endpoint}`, (res) => {
|
|
5171
5220
|
let data = "";
|
|
5172
5221
|
res.on("data", (chunk) => data += chunk);
|
|
5173
5222
|
res.on("end", () => {
|
|
5174
5223
|
try {
|
|
5175
|
-
|
|
5224
|
+
resolve7(JSON.parse(data));
|
|
5176
5225
|
} catch {
|
|
5177
|
-
|
|
5226
|
+
resolve7({ raw: data });
|
|
5178
5227
|
}
|
|
5179
5228
|
});
|
|
5180
5229
|
}).on("error", reject);
|
|
@@ -5188,7 +5237,7 @@ var init_handler = __esm({
|
|
|
5188
5237
|
try {
|
|
5189
5238
|
const http3 = await import("http");
|
|
5190
5239
|
const postData = JSON.stringify(args || {});
|
|
5191
|
-
const result = await new Promise((
|
|
5240
|
+
const result = await new Promise((resolve7, reject) => {
|
|
5192
5241
|
const req = http3.request({
|
|
5193
5242
|
hostname: "127.0.0.1",
|
|
5194
5243
|
port: 19280,
|
|
@@ -5200,9 +5249,9 @@ var init_handler = __esm({
|
|
|
5200
5249
|
res.on("data", (chunk) => data += chunk);
|
|
5201
5250
|
res.on("end", () => {
|
|
5202
5251
|
try {
|
|
5203
|
-
|
|
5252
|
+
resolve7(JSON.parse(data));
|
|
5204
5253
|
} catch {
|
|
5205
|
-
|
|
5254
|
+
resolve7({ raw: data });
|
|
5206
5255
|
}
|
|
5207
5256
|
});
|
|
5208
5257
|
});
|
|
@@ -5249,9 +5298,7 @@ var init_provider_loader = __esm({
|
|
|
5249
5298
|
if (options?.builtinDir) {
|
|
5250
5299
|
this.builtinDirs = Array.isArray(options.builtinDir) ? options.builtinDir : [options.builtinDir];
|
|
5251
5300
|
} else {
|
|
5252
|
-
|
|
5253
|
-
const devDir = path6.resolve(__dirname, "../../providers/_builtin");
|
|
5254
|
-
this.builtinDirs = [fs5.existsSync(devDir) ? devDir : bundledDir];
|
|
5301
|
+
this.builtinDirs = [];
|
|
5255
5302
|
}
|
|
5256
5303
|
this.userDir = options?.userDir || path6.join(os7.homedir(), ".adhdev", "providers");
|
|
5257
5304
|
this.upstreamDir = path6.join(this.userDir, ".upstream");
|
|
@@ -5773,7 +5820,7 @@ var init_provider_loader = __esm({
|
|
|
5773
5820
|
return { updated: false };
|
|
5774
5821
|
}
|
|
5775
5822
|
try {
|
|
5776
|
-
const etag = await new Promise((
|
|
5823
|
+
const etag = await new Promise((resolve7, reject) => {
|
|
5777
5824
|
const options = {
|
|
5778
5825
|
method: "HEAD",
|
|
5779
5826
|
hostname: "github.com",
|
|
@@ -5791,7 +5838,7 @@ var init_provider_loader = __esm({
|
|
|
5791
5838
|
headers: { "User-Agent": "adhdev-launcher" },
|
|
5792
5839
|
timeout: 1e4
|
|
5793
5840
|
}, (res2) => {
|
|
5794
|
-
|
|
5841
|
+
resolve7(res2.headers.etag || res2.headers["last-modified"] || "");
|
|
5795
5842
|
});
|
|
5796
5843
|
req2.on("error", reject);
|
|
5797
5844
|
req2.on("timeout", () => {
|
|
@@ -5800,7 +5847,7 @@ var init_provider_loader = __esm({
|
|
|
5800
5847
|
});
|
|
5801
5848
|
req2.end();
|
|
5802
5849
|
} else {
|
|
5803
|
-
|
|
5850
|
+
resolve7(res.headers.etag || res.headers["last-modified"] || "");
|
|
5804
5851
|
}
|
|
5805
5852
|
});
|
|
5806
5853
|
req.on("error", reject);
|
|
@@ -5864,7 +5911,7 @@ var init_provider_loader = __esm({
|
|
|
5864
5911
|
downloadFile(url2, destPath) {
|
|
5865
5912
|
const https = require("https");
|
|
5866
5913
|
const http3 = require("http");
|
|
5867
|
-
return new Promise((
|
|
5914
|
+
return new Promise((resolve7, reject) => {
|
|
5868
5915
|
const doRequest = (reqUrl, redirectCount = 0) => {
|
|
5869
5916
|
if (redirectCount > 5) {
|
|
5870
5917
|
reject(new Error("Too many redirects"));
|
|
@@ -5884,7 +5931,7 @@ var init_provider_loader = __esm({
|
|
|
5884
5931
|
res.pipe(ws2);
|
|
5885
5932
|
ws2.on("finish", () => {
|
|
5886
5933
|
ws2.close();
|
|
5887
|
-
|
|
5934
|
+
resolve7();
|
|
5888
5935
|
});
|
|
5889
5936
|
ws2.on("error", reject);
|
|
5890
5937
|
});
|
|
@@ -6250,17 +6297,17 @@ async function findFreePort(ports) {
|
|
|
6250
6297
|
throw new Error("No free port found");
|
|
6251
6298
|
}
|
|
6252
6299
|
function checkPortFree(port) {
|
|
6253
|
-
return new Promise((
|
|
6300
|
+
return new Promise((resolve7) => {
|
|
6254
6301
|
const server = net.createServer();
|
|
6255
6302
|
server.unref();
|
|
6256
|
-
server.on("error", () =>
|
|
6303
|
+
server.on("error", () => resolve7(false));
|
|
6257
6304
|
server.listen(port, "127.0.0.1", () => {
|
|
6258
|
-
server.close(() =>
|
|
6305
|
+
server.close(() => resolve7(true));
|
|
6259
6306
|
});
|
|
6260
6307
|
});
|
|
6261
6308
|
}
|
|
6262
6309
|
async function isCdpActive(port) {
|
|
6263
|
-
return new Promise((
|
|
6310
|
+
return new Promise((resolve7) => {
|
|
6264
6311
|
const req = require("http").get(`http://127.0.0.1:${port}/json/version`, {
|
|
6265
6312
|
timeout: 2e3
|
|
6266
6313
|
}, (res) => {
|
|
@@ -6269,16 +6316,16 @@ async function isCdpActive(port) {
|
|
|
6269
6316
|
res.on("end", () => {
|
|
6270
6317
|
try {
|
|
6271
6318
|
const info = JSON.parse(data);
|
|
6272
|
-
|
|
6319
|
+
resolve7(!!info["WebKit-Version"] || !!info["Browser"]);
|
|
6273
6320
|
} catch {
|
|
6274
|
-
|
|
6321
|
+
resolve7(false);
|
|
6275
6322
|
}
|
|
6276
6323
|
});
|
|
6277
6324
|
});
|
|
6278
|
-
req.on("error", () =>
|
|
6325
|
+
req.on("error", () => resolve7(false));
|
|
6279
6326
|
req.on("timeout", () => {
|
|
6280
6327
|
req.destroy();
|
|
6281
|
-
|
|
6328
|
+
resolve7(false);
|
|
6282
6329
|
});
|
|
6283
6330
|
});
|
|
6284
6331
|
}
|
|
@@ -16512,6 +16559,36 @@ function promptLikelyVisible(screenText, promptSnippet) {
|
|
|
16512
16559
|
).length;
|
|
16513
16560
|
return matched >= required2;
|
|
16514
16561
|
}
|
|
16562
|
+
function splitHistoryLines(text) {
|
|
16563
|
+
return String(text || "").split("\n").map((line) => line.replace(/\s+$/, ""));
|
|
16564
|
+
}
|
|
16565
|
+
function normalizeHistoryLine(line) {
|
|
16566
|
+
return String(line || "").replace(/\s+/g, " ").trim();
|
|
16567
|
+
}
|
|
16568
|
+
function mergeTerminalHistory(existing, snapshot) {
|
|
16569
|
+
const next = String(snapshot || "").trim();
|
|
16570
|
+
if (!next) return existing;
|
|
16571
|
+
const prev = String(existing || "").trim();
|
|
16572
|
+
if (!prev) return next;
|
|
16573
|
+
if (prev === next || prev.endsWith(next)) return prev;
|
|
16574
|
+
const prevLines = splitHistoryLines(prev);
|
|
16575
|
+
const nextLines = splitHistoryLines(next);
|
|
16576
|
+
const prevNorm = prevLines.map(normalizeHistoryLine);
|
|
16577
|
+
const nextNorm = nextLines.map(normalizeHistoryLine);
|
|
16578
|
+
const maxOverlap = Math.min(prevLines.length, nextLines.length);
|
|
16579
|
+
for (let overlap = maxOverlap; overlap >= 1; overlap -= 1) {
|
|
16580
|
+
const prevTail = prevNorm.slice(prevNorm.length - overlap);
|
|
16581
|
+
const nextHead = nextNorm.slice(0, overlap);
|
|
16582
|
+
if (prevTail.every((line, index) => line === nextHead[index])) {
|
|
16583
|
+
return [...prevLines, ...nextLines.slice(overlap)].join("\n").trim();
|
|
16584
|
+
}
|
|
16585
|
+
}
|
|
16586
|
+
const compactPrev = prevNorm.join("\n");
|
|
16587
|
+
const compactNext = nextNorm.join("\n");
|
|
16588
|
+
if (compactPrev.includes(compactNext)) return prev;
|
|
16589
|
+
return `${prev}
|
|
16590
|
+
${next}`.trim();
|
|
16591
|
+
}
|
|
16515
16592
|
function parsePatternEntry(x) {
|
|
16516
16593
|
if (x instanceof RegExp) return x;
|
|
16517
16594
|
if (x && typeof x === "object" && typeof x.source === "string") {
|
|
@@ -16588,6 +16665,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
16588
16665
|
this.approvalKeys = rawKeys && typeof rawKeys === "object" ? rawKeys : {};
|
|
16589
16666
|
this.sendDelayMs = typeof provider.sendDelayMs === "number" ? Math.max(0, provider.sendDelayMs) : 0;
|
|
16590
16667
|
this.sendKey = typeof provider.sendKey === "string" && provider.sendKey.length > 0 ? provider.sendKey : "\r";
|
|
16668
|
+
this.submitStrategy = provider.submitStrategy === "immediate" ? "immediate" : "wait_for_echo";
|
|
16591
16669
|
this.cliScripts = provider.scripts || {};
|
|
16592
16670
|
const scriptNames = Object.keys(this.cliScripts).filter((k) => typeof this.cliScripts[k] === "function");
|
|
16593
16671
|
if (scriptNames.length > 0) {
|
|
@@ -16602,6 +16680,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
16602
16680
|
provider;
|
|
16603
16681
|
ptyProcess = null;
|
|
16604
16682
|
messages = [];
|
|
16683
|
+
committedMessages = [];
|
|
16605
16684
|
structuredMessages = [];
|
|
16606
16685
|
currentStatus = "starting";
|
|
16607
16686
|
onStatusChange = null;
|
|
@@ -16648,8 +16727,35 @@ var init_provider_cli_adapter = __esm({
|
|
|
16648
16727
|
accumulatedRawBuffer = "";
|
|
16649
16728
|
/** Current visible terminal screen snapshot */
|
|
16650
16729
|
terminalScreen = new TerminalScreen(40, 120);
|
|
16730
|
+
/** Rolling append-only terminal transcript built from screen snapshots */
|
|
16731
|
+
terminalHistory = "";
|
|
16651
16732
|
/** Max accumulated buffer size (last 50KB) */
|
|
16652
16733
|
static MAX_ACCUMULATED_BUFFER = 5e4;
|
|
16734
|
+
currentTurnScope = null;
|
|
16735
|
+
syncMessageViews() {
|
|
16736
|
+
this.messages = [...this.committedMessages];
|
|
16737
|
+
this.structuredMessages = [...this.committedMessages];
|
|
16738
|
+
}
|
|
16739
|
+
sliceFromOffset(text, start) {
|
|
16740
|
+
if (!text) return "";
|
|
16741
|
+
if (!Number.isFinite(start) || start <= 0) return text;
|
|
16742
|
+
if (start >= text.length) return "";
|
|
16743
|
+
return text.slice(start);
|
|
16744
|
+
}
|
|
16745
|
+
buildParseInput(baseMessages, partialResponse, scope) {
|
|
16746
|
+
const buffer = scope ? this.sliceFromOffset(this.terminalHistory, scope.terminalHistoryStart) || this.sliceFromOffset(this.accumulatedBuffer, scope.bufferStart) || this.accumulatedBuffer : this.accumulatedBuffer;
|
|
16747
|
+
const rawBuffer = scope ? this.sliceFromOffset(this.accumulatedRawBuffer, scope.rawBufferStart) || this.accumulatedRawBuffer : this.accumulatedRawBuffer;
|
|
16748
|
+
const terminalHistory = scope ? this.sliceFromOffset(this.terminalHistory, scope.terminalHistoryStart) || this.terminalHistory : this.terminalHistory;
|
|
16749
|
+
return {
|
|
16750
|
+
buffer,
|
|
16751
|
+
rawBuffer,
|
|
16752
|
+
recentBuffer: buffer.slice(-1e3) || this.recentOutputBuffer,
|
|
16753
|
+
screenText: this.terminalScreen.getText(),
|
|
16754
|
+
terminalHistory,
|
|
16755
|
+
messages: [...baseMessages],
|
|
16756
|
+
partialResponse
|
|
16757
|
+
};
|
|
16758
|
+
}
|
|
16653
16759
|
setStatus(status, trigger) {
|
|
16654
16760
|
const prev = this.currentStatus;
|
|
16655
16761
|
if (prev === status) return;
|
|
@@ -16664,6 +16770,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
16664
16770
|
approvalKeys;
|
|
16665
16771
|
sendDelayMs;
|
|
16666
16772
|
sendKey;
|
|
16773
|
+
submitStrategy;
|
|
16667
16774
|
/** Inject CLI scripts after construction (e.g. when resolved by ProviderLoader) */
|
|
16668
16775
|
setCliScripts(scripts) {
|
|
16669
16776
|
this.cliScripts = scripts;
|
|
@@ -16759,6 +16866,8 @@ var init_provider_cli_adapter = __esm({
|
|
|
16759
16866
|
this.startupParseGate = true;
|
|
16760
16867
|
this.startupBuffer = "";
|
|
16761
16868
|
this.terminalScreen.reset(40, 120);
|
|
16869
|
+
this.terminalHistory = "";
|
|
16870
|
+
this.currentTurnScope = null;
|
|
16762
16871
|
this.ready = false;
|
|
16763
16872
|
this.setStatus("idle", "pty_ready");
|
|
16764
16873
|
this.onStatusChange?.();
|
|
@@ -16770,6 +16879,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
16770
16879
|
this.ptyProcess?.write("\x1B[1;1R");
|
|
16771
16880
|
}
|
|
16772
16881
|
this.terminalScreen.write(rawData);
|
|
16882
|
+
this.terminalHistory = mergeTerminalHistory(this.terminalHistory, this.terminalScreen.getText());
|
|
16773
16883
|
const cleanData = stripAnsi(rawData);
|
|
16774
16884
|
if (this.isWaitingForResponse && cleanData) {
|
|
16775
16885
|
this.responseBuffer = (this.responseBuffer + cleanData).slice(-8e3);
|
|
@@ -16914,6 +17024,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
16914
17024
|
finishResponse() {
|
|
16915
17025
|
if (this.submitPendingUntil > Date.now()) return;
|
|
16916
17026
|
if (this.responseSettleIgnoreUntil > Date.now()) return;
|
|
17027
|
+
this.commitCurrentTranscript();
|
|
16917
17028
|
if (this.responseTimeout) {
|
|
16918
17029
|
clearTimeout(this.responseTimeout);
|
|
16919
17030
|
this.responseTimeout = null;
|
|
@@ -16935,10 +17046,58 @@ var init_provider_cli_adapter = __esm({
|
|
|
16935
17046
|
this.responseSettleIgnoreUntil = 0;
|
|
16936
17047
|
this.submitRetryUsed = false;
|
|
16937
17048
|
this.submitRetryPromptSnippet = "";
|
|
17049
|
+
this.currentTurnScope = null;
|
|
16938
17050
|
this.activeModal = null;
|
|
16939
17051
|
this.setStatus("idle", "response_finished");
|
|
16940
17052
|
this.onStatusChange?.();
|
|
16941
17053
|
}
|
|
17054
|
+
commitCurrentTranscript() {
|
|
17055
|
+
const baseMessages = [...this.committedMessages];
|
|
17056
|
+
const parsed = this.parseCurrentTranscript(baseMessages, "", this.currentTurnScope);
|
|
17057
|
+
if (parsed && Array.isArray(parsed.messages) && parsed.messages.length > 0) {
|
|
17058
|
+
const parsedMessages = parsed.messages.filter((m) => m && (m.role === "user" || m.role === "assistant")).map((m) => ({
|
|
17059
|
+
role: m.role,
|
|
17060
|
+
content: typeof m.content === "string" ? m.content : String(m.content || ""),
|
|
17061
|
+
timestamp: m.timestamp
|
|
17062
|
+
}));
|
|
17063
|
+
const latestAssistant = [...parsedMessages].reverse().find((m) => m.role === "assistant" && m.content.trim());
|
|
17064
|
+
if (latestAssistant) {
|
|
17065
|
+
LOG.info("CLI", `[${this.cliType}] commitCurrentTranscript parsed assistant len=${latestAssistant.content.length} scopePrompt=${JSON.stringify(this.currentTurnScope?.prompt || "").slice(0, 120)}`);
|
|
17066
|
+
const nextMessages = [...baseMessages];
|
|
17067
|
+
const last2 = nextMessages[nextMessages.length - 1];
|
|
17068
|
+
if (last2?.role === "assistant") {
|
|
17069
|
+
last2.content = latestAssistant.content;
|
|
17070
|
+
last2.timestamp = latestAssistant.timestamp || last2.timestamp;
|
|
17071
|
+
} else if (last2?.role === "user") {
|
|
17072
|
+
nextMessages.push({
|
|
17073
|
+
role: "assistant",
|
|
17074
|
+
content: latestAssistant.content,
|
|
17075
|
+
timestamp: latestAssistant.timestamp || Date.now()
|
|
17076
|
+
});
|
|
17077
|
+
} else {
|
|
17078
|
+
nextMessages.push({
|
|
17079
|
+
role: "assistant",
|
|
17080
|
+
content: latestAssistant.content,
|
|
17081
|
+
timestamp: latestAssistant.timestamp || Date.now()
|
|
17082
|
+
});
|
|
17083
|
+
}
|
|
17084
|
+
this.committedMessages = nextMessages;
|
|
17085
|
+
this.syncMessageViews();
|
|
17086
|
+
return;
|
|
17087
|
+
}
|
|
17088
|
+
}
|
|
17089
|
+
const fallback = String(this.responseBuffer || "").trim();
|
|
17090
|
+
LOG.info("CLI", `[${this.cliType}] commitCurrentTranscript fallback len=${fallback.length} scopePrompt=${JSON.stringify(this.currentTurnScope?.prompt || "").slice(0, 120)}`);
|
|
17091
|
+
if (!fallback) return;
|
|
17092
|
+
const last = baseMessages[baseMessages.length - 1];
|
|
17093
|
+
if (last?.role === "assistant") {
|
|
17094
|
+
last.content = fallback;
|
|
17095
|
+
} else {
|
|
17096
|
+
baseMessages.push({ role: "assistant", content: fallback, timestamp: Date.now() });
|
|
17097
|
+
}
|
|
17098
|
+
this.committedMessages = baseMessages;
|
|
17099
|
+
this.syncMessageViews();
|
|
17100
|
+
}
|
|
16942
17101
|
// ─── Script Execution ──────────────────────────
|
|
16943
17102
|
runDetectStatus(text) {
|
|
16944
17103
|
if (!this.cliScripts?.detectStatus) return null;
|
|
@@ -16968,24 +17127,12 @@ var init_provider_cli_adapter = __esm({
|
|
|
16968
17127
|
}
|
|
16969
17128
|
// ─── Public API (CliAdapter) ───────────────────
|
|
16970
17129
|
getStatus() {
|
|
16971
|
-
const scriptResult = this.getScriptParsedStatus();
|
|
16972
|
-
if (scriptResult) {
|
|
16973
|
-
return {
|
|
16974
|
-
status: this.currentStatus,
|
|
16975
|
-
messages: (scriptResult.messages || []).map((m) => ({
|
|
16976
|
-
role: m.role,
|
|
16977
|
-
content: m.content,
|
|
16978
|
-
timestamp: m.timestamp
|
|
16979
|
-
})),
|
|
16980
|
-
workingDir: this.workingDir,
|
|
16981
|
-
activeModal: this.activeModal
|
|
16982
|
-
};
|
|
16983
|
-
}
|
|
16984
17130
|
return {
|
|
16985
17131
|
status: this.currentStatus,
|
|
16986
|
-
messages: [...this.
|
|
17132
|
+
messages: [...this.committedMessages],
|
|
16987
17133
|
workingDir: this.workingDir,
|
|
16988
|
-
activeModal: this.activeModal
|
|
17134
|
+
activeModal: this.activeModal,
|
|
17135
|
+
terminalHistory: this.terminalHistory
|
|
16989
17136
|
};
|
|
16990
17137
|
}
|
|
16991
17138
|
/**
|
|
@@ -16993,31 +17140,32 @@ var init_provider_cli_adapter = __esm({
|
|
|
16993
17140
|
* Called by command handler / dashboard for rich content rendering.
|
|
16994
17141
|
*/
|
|
16995
17142
|
getScriptParsedStatus() {
|
|
17143
|
+
const messages = [...this.committedMessages];
|
|
17144
|
+
return {
|
|
17145
|
+
id: "cli_session",
|
|
17146
|
+
status: this.currentStatus,
|
|
17147
|
+
title: this.cliName,
|
|
17148
|
+
terminalHistory: this.terminalHistory,
|
|
17149
|
+
messages: messages.slice(-50).map((message, index) => ({
|
|
17150
|
+
id: `msg_${index}`,
|
|
17151
|
+
role: message.role,
|
|
17152
|
+
content: message.content,
|
|
17153
|
+
timestamp: message.timestamp,
|
|
17154
|
+
index,
|
|
17155
|
+
kind: "standard"
|
|
17156
|
+
})),
|
|
17157
|
+
activeModal: this.activeModal
|
|
17158
|
+
};
|
|
17159
|
+
}
|
|
17160
|
+
parseCurrentTranscript(baseMessages, partialResponse, scope) {
|
|
16996
17161
|
if (!this.cliScripts?.parseOutput) return null;
|
|
16997
17162
|
try {
|
|
16998
|
-
const input =
|
|
16999
|
-
|
|
17000
|
-
rawBuffer: this.accumulatedRawBuffer,
|
|
17001
|
-
recentBuffer: this.recentOutputBuffer,
|
|
17002
|
-
screenText: this.terminalScreen.getText(),
|
|
17003
|
-
messages: [...this.structuredMessages.length > 0 ? this.structuredMessages : this.messages],
|
|
17004
|
-
partialResponse: this.responseBuffer
|
|
17005
|
-
};
|
|
17006
|
-
const result = this.cliScripts.parseOutput(input);
|
|
17007
|
-
if (result && typeof result === "object") {
|
|
17008
|
-
if (Array.isArray(result.messages)) {
|
|
17009
|
-
this.structuredMessages = result.messages.map((m) => ({
|
|
17010
|
-
role: m.role,
|
|
17011
|
-
content: m.content,
|
|
17012
|
-
timestamp: m.timestamp
|
|
17013
|
-
}));
|
|
17014
|
-
}
|
|
17015
|
-
return result;
|
|
17016
|
-
}
|
|
17163
|
+
const input = this.buildParseInput(baseMessages, partialResponse, scope);
|
|
17164
|
+
return this.cliScripts.parseOutput(input);
|
|
17017
17165
|
} catch (e) {
|
|
17018
17166
|
LOG.warn("CLI", `[${this.cliType}] parseOutput error: ${e.message}`);
|
|
17167
|
+
return null;
|
|
17019
17168
|
}
|
|
17020
|
-
return null;
|
|
17021
17169
|
}
|
|
17022
17170
|
/** Whether this adapter has CLI scripts loaded */
|
|
17023
17171
|
hasCliScripts() {
|
|
@@ -17052,15 +17200,23 @@ ${data.message || ""}`.trim();
|
|
|
17052
17200
|
if (this.startupParseGate) {
|
|
17053
17201
|
const deadline = Date.now() + 1e4;
|
|
17054
17202
|
while (this.startupParseGate && Date.now() < deadline) {
|
|
17055
|
-
await new Promise((
|
|
17203
|
+
await new Promise((resolve7) => setTimeout(resolve7, 50));
|
|
17056
17204
|
}
|
|
17057
17205
|
}
|
|
17058
17206
|
if (!this.ready) throw new Error(`${this.cliName} not ready (status: ${this.currentStatus})`);
|
|
17059
17207
|
if (this.isWaitingForResponse) return;
|
|
17060
|
-
this.
|
|
17061
|
-
this.
|
|
17208
|
+
this.committedMessages.push({ role: "user", content: text, timestamp: Date.now() });
|
|
17209
|
+
this.syncMessageViews();
|
|
17062
17210
|
this.isWaitingForResponse = true;
|
|
17063
17211
|
this.responseBuffer = "";
|
|
17212
|
+
this.currentTurnScope = {
|
|
17213
|
+
prompt: text,
|
|
17214
|
+
startedAt: Date.now(),
|
|
17215
|
+
bufferStart: this.accumulatedBuffer.length,
|
|
17216
|
+
rawBufferStart: this.accumulatedRawBuffer.length,
|
|
17217
|
+
terminalHistoryStart: this.terminalHistory.length
|
|
17218
|
+
};
|
|
17219
|
+
LOG.info("CLI", `[${this.cliType}] sendMessage turn scope buffer=${this.currentTurnScope.bufferStart} raw=${this.currentTurnScope.rawBufferStart} terminal=${this.currentTurnScope.terminalHistoryStart} prompt=${JSON.stringify(text).slice(0, 120)}`);
|
|
17064
17220
|
this.submitRetryUsed = false;
|
|
17065
17221
|
this.submitRetryPromptSnippet = extractPromptRetrySnippet(text);
|
|
17066
17222
|
const normalizedPromptSnippet = normalizePromptText(this.submitRetryPromptSnippet);
|
|
@@ -17080,10 +17236,12 @@ ${data.message || ""}`.trim();
|
|
|
17080
17236
|
this.responseSettleIgnoreUntil = Date.now() + submitDelayMs + this.timeouts.outputSettle + 250;
|
|
17081
17237
|
this.setStatus("generating", "sendMessage");
|
|
17082
17238
|
this.onStatusChange?.();
|
|
17083
|
-
|
|
17084
|
-
this.
|
|
17085
|
-
|
|
17086
|
-
|
|
17239
|
+
const startResponseTimeout = () => {
|
|
17240
|
+
if (this.responseTimeout) clearTimeout(this.responseTimeout);
|
|
17241
|
+
this.responseTimeout = setTimeout(() => {
|
|
17242
|
+
if (this.isWaitingForResponse) this.finishResponse();
|
|
17243
|
+
}, this.timeouts.maxResponse);
|
|
17244
|
+
};
|
|
17087
17245
|
const submit = () => {
|
|
17088
17246
|
if (!this.ptyProcess) return;
|
|
17089
17247
|
this.submitPendingUntil = 0;
|
|
@@ -17106,10 +17264,30 @@ ${data.message || ""}`.trim();
|
|
|
17106
17264
|
this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
|
|
17107
17265
|
};
|
|
17108
17266
|
this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
|
|
17109
|
-
|
|
17110
|
-
if (this.isWaitingForResponse) this.finishResponse();
|
|
17111
|
-
}, this.timeouts.maxResponse);
|
|
17267
|
+
startResponseTimeout();
|
|
17112
17268
|
};
|
|
17269
|
+
if (this.submitStrategy === "immediate") {
|
|
17270
|
+
this.submitPendingUntil = 0;
|
|
17271
|
+
this.ptyProcess.write(text + this.sendKey);
|
|
17272
|
+
this.submitRetryTimer = setTimeout(() => {
|
|
17273
|
+
this.submitRetryTimer = null;
|
|
17274
|
+
if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
|
|
17275
|
+
if (this.currentStatus !== "generating") return;
|
|
17276
|
+
if ((this.responseBuffer || "").trim()) return;
|
|
17277
|
+
const screenText = this.terminalScreen.getText();
|
|
17278
|
+
if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
|
|
17279
|
+
LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
|
|
17280
|
+
this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
|
|
17281
|
+
this.ptyProcess.write(this.sendKey);
|
|
17282
|
+
this.submitRetryUsed = true;
|
|
17283
|
+
}, retryDelayMs);
|
|
17284
|
+
startResponseTimeout();
|
|
17285
|
+
return;
|
|
17286
|
+
}
|
|
17287
|
+
if (submitDelayMs > 0) {
|
|
17288
|
+
this.submitPendingUntil = Date.now() + submitDelayMs;
|
|
17289
|
+
}
|
|
17290
|
+
this.ptyProcess.write(text);
|
|
17113
17291
|
const submitStartedAt = Date.now();
|
|
17114
17292
|
let lastNormalizedScreen = "";
|
|
17115
17293
|
let lastScreenChangeAt = submitStartedAt;
|
|
@@ -17176,10 +17354,12 @@ ${data.message || ""}`.trim();
|
|
|
17176
17354
|
}
|
|
17177
17355
|
}
|
|
17178
17356
|
clearHistory() {
|
|
17179
|
-
this.
|
|
17180
|
-
this.
|
|
17357
|
+
this.committedMessages = [];
|
|
17358
|
+
this.syncMessageViews();
|
|
17181
17359
|
this.accumulatedBuffer = "";
|
|
17182
17360
|
this.accumulatedRawBuffer = "";
|
|
17361
|
+
this.terminalHistory = "";
|
|
17362
|
+
this.currentTurnScope = null;
|
|
17183
17363
|
this.submitRetryUsed = false;
|
|
17184
17364
|
this.submitRetryPromptSnippet = "";
|
|
17185
17365
|
this.terminalScreen.reset();
|
|
@@ -17233,9 +17413,12 @@ ${data.message || ""}`.trim();
|
|
|
17233
17413
|
spawnAt: this.spawnAt,
|
|
17234
17414
|
workingDir: this.workingDir,
|
|
17235
17415
|
messages: this.messages.slice(-20),
|
|
17416
|
+
committedMessages: this.committedMessages.slice(-20),
|
|
17236
17417
|
structuredMessages: this.structuredMessages.slice(-20),
|
|
17237
|
-
messageCount: this.
|
|
17418
|
+
messageCount: this.committedMessages.length,
|
|
17238
17419
|
screenText: this.terminalScreen.getText().slice(-4e3),
|
|
17420
|
+
terminalHistory: this.terminalHistory.slice(-8e3),
|
|
17421
|
+
currentTurnScope: this.currentTurnScope,
|
|
17239
17422
|
startupBuffer: this.startupBuffer.slice(-4e3),
|
|
17240
17423
|
recentOutputBuffer: this.recentOutputBuffer.slice(-500),
|
|
17241
17424
|
settledBuffer: this.settledBuffer.slice(-500),
|
|
@@ -17248,6 +17431,7 @@ ${data.message || ""}`.trim();
|
|
|
17248
17431
|
lastApprovalResolvedAt: this.lastApprovalResolvedAt,
|
|
17249
17432
|
sendDelayMs: this.sendDelayMs,
|
|
17250
17433
|
sendKey: this.sendKey,
|
|
17434
|
+
submitStrategy: this.submitStrategy,
|
|
17251
17435
|
submitPendingUntil: this.submitPendingUntil,
|
|
17252
17436
|
responseSettleIgnoreUntil: this.responseSettleIgnoreUntil,
|
|
17253
17437
|
resizeSuppressUntil: this.resizeSuppressUntil,
|
|
@@ -17320,31 +17504,12 @@ var init_cli_provider_instance = __esm({
|
|
|
17320
17504
|
async onTick() {
|
|
17321
17505
|
}
|
|
17322
17506
|
getState() {
|
|
17323
|
-
const
|
|
17324
|
-
const parsedStatus = this.adapter.getScriptParsedStatus();
|
|
17325
|
-
const adapterStatus = parsedStatus ? {
|
|
17326
|
-
...rawStatus,
|
|
17327
|
-
messages: parsedStatus.messages || rawStatus.messages,
|
|
17328
|
-
activeModal: parsedStatus.activeModal || rawStatus.activeModal
|
|
17329
|
-
} : rawStatus;
|
|
17507
|
+
const adapterStatus = this.adapter.getStatus();
|
|
17330
17508
|
const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
|
|
17331
17509
|
const recentMessages = adapterStatus.messages.slice(-50).map((m) => {
|
|
17332
17510
|
const content = typeof m.content === "string" && m.content.length > 8e3 ? m.content.slice(0, 8e3) + "\n... (truncated)" : m.content;
|
|
17333
17511
|
return { ...m, content };
|
|
17334
17512
|
});
|
|
17335
|
-
const partial2 = this.adapter.getPartialResponse();
|
|
17336
|
-
const shouldAppendRawPartial = !parsedStatus;
|
|
17337
|
-
if (shouldAppendRawPartial && adapterStatus.status === "generating" && partial2) {
|
|
17338
|
-
const cleaned = partial2.trim();
|
|
17339
|
-
if (cleaned && cleaned !== "(generating...)") {
|
|
17340
|
-
recentMessages.push({
|
|
17341
|
-
role: "assistant",
|
|
17342
|
-
content: (cleaned.length > 8e3 ? cleaned.slice(0, 8e3) + "..." : cleaned) + "...",
|
|
17343
|
-
timestamp: Date.now(),
|
|
17344
|
-
meta: { streaming: true }
|
|
17345
|
-
});
|
|
17346
|
-
}
|
|
17347
|
-
}
|
|
17348
17513
|
if (recentMessages.length > 0) {
|
|
17349
17514
|
const dirName2 = this.workingDir.split("/").filter(Boolean).pop() || "session";
|
|
17350
17515
|
this.historyWriter.appendNewMessages(
|
|
@@ -17354,6 +17519,14 @@ var init_cli_provider_instance = __esm({
|
|
|
17354
17519
|
this.instanceId
|
|
17355
17520
|
);
|
|
17356
17521
|
}
|
|
17522
|
+
if (adapterStatus.terminalHistory?.trim()) {
|
|
17523
|
+
this.historyWriter.appendTerminalHistory(
|
|
17524
|
+
this.type,
|
|
17525
|
+
adapterStatus.terminalHistory,
|
|
17526
|
+
`${this.provider.name} \xB7 ${dirName}`,
|
|
17527
|
+
this.instanceId
|
|
17528
|
+
);
|
|
17529
|
+
}
|
|
17357
17530
|
return {
|
|
17358
17531
|
type: this.type,
|
|
17359
17532
|
name: this.provider.name,
|
|
@@ -17366,6 +17539,7 @@ var init_cli_provider_instance = __esm({
|
|
|
17366
17539
|
status: adapterStatus.status,
|
|
17367
17540
|
messages: recentMessages,
|
|
17368
17541
|
activeModal: adapterStatus.activeModal,
|
|
17542
|
+
terminalHistory: adapterStatus.terminalHistory,
|
|
17369
17543
|
inputContent: ""
|
|
17370
17544
|
},
|
|
17371
17545
|
workspace: this.workingDir,
|
|
@@ -33569,8 +33743,8 @@ var init_acp = __esm({
|
|
|
33569
33743
|
this.#requestHandler = requestHandler;
|
|
33570
33744
|
this.#notificationHandler = notificationHandler;
|
|
33571
33745
|
this.#stream = stream;
|
|
33572
|
-
this.#closedPromise = new Promise((
|
|
33573
|
-
this.#abortController.signal.addEventListener("abort", () =>
|
|
33746
|
+
this.#closedPromise = new Promise((resolve7) => {
|
|
33747
|
+
this.#abortController.signal.addEventListener("abort", () => resolve7());
|
|
33574
33748
|
});
|
|
33575
33749
|
this.#receive();
|
|
33576
33750
|
}
|
|
@@ -33719,8 +33893,8 @@ var init_acp = __esm({
|
|
|
33719
33893
|
}
|
|
33720
33894
|
async sendRequest(method, params) {
|
|
33721
33895
|
const id = this.#nextRequestId++;
|
|
33722
|
-
const responsePromise = new Promise((
|
|
33723
|
-
this.#pendingResponses.set(id, { resolve:
|
|
33896
|
+
const responsePromise = new Promise((resolve7, reject) => {
|
|
33897
|
+
this.#pendingResponses.set(id, { resolve: resolve7, reject });
|
|
33724
33898
|
});
|
|
33725
33899
|
await this.#sendMessage({ jsonrpc: "2.0", id, method, params });
|
|
33726
33900
|
return responsePromise;
|
|
@@ -34252,13 +34426,13 @@ var init_acp_provider_instance = __esm({
|
|
|
34252
34426
|
}
|
|
34253
34427
|
this.currentStatus = "waiting_approval";
|
|
34254
34428
|
this.detectStatusTransition();
|
|
34255
|
-
const approved = await new Promise((
|
|
34256
|
-
this.permissionResolvers.push(
|
|
34429
|
+
const approved = await new Promise((resolve7) => {
|
|
34430
|
+
this.permissionResolvers.push(resolve7);
|
|
34257
34431
|
setTimeout(() => {
|
|
34258
|
-
const idx = this.permissionResolvers.indexOf(
|
|
34432
|
+
const idx = this.permissionResolvers.indexOf(resolve7);
|
|
34259
34433
|
if (idx >= 0) {
|
|
34260
34434
|
this.permissionResolvers.splice(idx, 1);
|
|
34261
|
-
|
|
34435
|
+
resolve7(false);
|
|
34262
34436
|
}
|
|
34263
34437
|
}, 3e5);
|
|
34264
34438
|
});
|
|
@@ -35849,7 +36023,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
35849
36023
|
binary: null,
|
|
35850
36024
|
detectedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
35851
36025
|
};
|
|
35852
|
-
const
|
|
36026
|
+
const verCmdConfig = provider.versionCommand;
|
|
36027
|
+
const versionCommand = typeof verCmdConfig === "object" && verCmdConfig !== null ? verCmdConfig[currentOs] : verCmdConfig;
|
|
35853
36028
|
if (provider.category === "ide") {
|
|
35854
36029
|
const osPaths = provider.paths?.[currentOs] || [];
|
|
35855
36030
|
const appPath = checkPathExists2(osPaths);
|
|
@@ -36428,15 +36603,15 @@ var init_dev_server = __esm({
|
|
|
36428
36603
|
this.json(res, 500, { error: e.message });
|
|
36429
36604
|
}
|
|
36430
36605
|
});
|
|
36431
|
-
return new Promise((
|
|
36606
|
+
return new Promise((resolve7, reject) => {
|
|
36432
36607
|
this.server.listen(port, "127.0.0.1", () => {
|
|
36433
36608
|
this.log(`Dev server listening on http://127.0.0.1:${port}`);
|
|
36434
|
-
|
|
36609
|
+
resolve7();
|
|
36435
36610
|
});
|
|
36436
36611
|
this.server.on("error", (e) => {
|
|
36437
36612
|
if (e.code === "EADDRINUSE") {
|
|
36438
36613
|
this.log(`Port ${port} in use, skipping dev server`);
|
|
36439
|
-
|
|
36614
|
+
resolve7();
|
|
36440
36615
|
} else {
|
|
36441
36616
|
reject(e);
|
|
36442
36617
|
}
|
|
@@ -36519,20 +36694,20 @@ var init_dev_server = __esm({
|
|
|
36519
36694
|
child.stderr?.on("data", (d) => {
|
|
36520
36695
|
stderr += d.toString().slice(0, 2e3);
|
|
36521
36696
|
});
|
|
36522
|
-
await new Promise((
|
|
36697
|
+
await new Promise((resolve7) => {
|
|
36523
36698
|
const timer = setTimeout(() => {
|
|
36524
36699
|
child.kill();
|
|
36525
|
-
|
|
36700
|
+
resolve7();
|
|
36526
36701
|
}, 3e3);
|
|
36527
36702
|
child.on("exit", () => {
|
|
36528
36703
|
clearTimeout(timer);
|
|
36529
|
-
|
|
36704
|
+
resolve7();
|
|
36530
36705
|
});
|
|
36531
36706
|
child.stdout?.once("data", () => {
|
|
36532
36707
|
setTimeout(() => {
|
|
36533
36708
|
child.kill();
|
|
36534
36709
|
clearTimeout(timer);
|
|
36535
|
-
|
|
36710
|
+
resolve7();
|
|
36536
36711
|
}, 500);
|
|
36537
36712
|
});
|
|
36538
36713
|
});
|
|
@@ -37276,14 +37451,14 @@ var init_dev_server = __esm({
|
|
|
37276
37451
|
child.stderr?.on("data", (d) => {
|
|
37277
37452
|
stderr += d.toString();
|
|
37278
37453
|
});
|
|
37279
|
-
await new Promise((
|
|
37454
|
+
await new Promise((resolve7) => {
|
|
37280
37455
|
const timer = setTimeout(() => {
|
|
37281
37456
|
child.kill();
|
|
37282
|
-
|
|
37457
|
+
resolve7();
|
|
37283
37458
|
}, timeout);
|
|
37284
37459
|
child.on("exit", () => {
|
|
37285
37460
|
clearTimeout(timer);
|
|
37286
|
-
|
|
37461
|
+
resolve7();
|
|
37287
37462
|
});
|
|
37288
37463
|
});
|
|
37289
37464
|
const elapsed = Date.now() - start;
|
|
@@ -37334,11 +37509,7 @@ var init_dev_server = __esm({
|
|
|
37334
37509
|
return;
|
|
37335
37510
|
}
|
|
37336
37511
|
let targetDir;
|
|
37337
|
-
|
|
37338
|
-
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
37339
|
-
} else {
|
|
37340
|
-
targetDir = this.providerLoader.getBuiltinProviderDir(category, type);
|
|
37341
|
-
}
|
|
37512
|
+
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
37342
37513
|
const jsonPath = path12.join(targetDir, "provider.json");
|
|
37343
37514
|
if (fs10.existsSync(jsonPath)) {
|
|
37344
37515
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
@@ -38136,8 +38307,7 @@ var init_dev_server = __esm({
|
|
|
38136
38307
|
}
|
|
38137
38308
|
loadAutoImplReferenceScripts(category, referenceType) {
|
|
38138
38309
|
if (!referenceType) return {};
|
|
38139
|
-
const
|
|
38140
|
-
const refDir = path12.join(builtinDir, category, referenceType);
|
|
38310
|
+
const refDir = this.providerLoader.getUpstreamProviderDir(category, referenceType);
|
|
38141
38311
|
if (!fs10.existsSync(refDir)) return {};
|
|
38142
38312
|
const referenceScripts = {};
|
|
38143
38313
|
const scriptsDir = path12.join(refDir, "scripts");
|
|
@@ -38376,7 +38546,7 @@ var init_dev_server = __esm({
|
|
|
38376
38546
|
}
|
|
38377
38547
|
if (model) args.push("--model", model);
|
|
38378
38548
|
const escapedArgs = args.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
|
38379
|
-
const metaPrompt = `Read the file at ${promptFile} and follow ALL instructions
|
|
38549
|
+
const metaPrompt = `Read the file at ${promptFile} and follow ALL instructions strictly. DO NOT spend time exploring the filesystem or other providers. You have full authority to implement ALL required script files and independently test them against 127.0.0.1:19280 via CDP CURL. Upon complete validation of ALL assigned files, print exactly "_PIPELINE_COMPLETE_SIGNAL_" to gracefully close the pipeline. DO NOT WAIT FOR APPROVAL, execute completely autonomously.`;
|
|
38380
38550
|
shellCmd = `${command} ${escapedArgs} "${metaPrompt}"`;
|
|
38381
38551
|
} else {
|
|
38382
38552
|
const escapedArgs = baseArgs.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
|
@@ -38639,6 +38809,8 @@ var init_dev_server = __esm({
|
|
|
38639
38809
|
lines.push("5. Do NOT modify `scripts.js` router \u2014 only edit individual `*.js` files");
|
|
38640
38810
|
lines.push("6. All scripts run in the browser (CDP evaluate) \u2014 use DOM APIs only");
|
|
38641
38811
|
lines.push('7. **Cross-Platform Compatibility**: If you use ARIA labels that contain keyboard shortcuts (e.g., `Cascade (\u2318L)`), you MUST use substring matches (`aria-label*="Cascade"`) or handle both macOS (`\u2318`, `Cmd`) and Windows (`Ctrl`) so the script does not break on other operating systems.');
|
|
38812
|
+
lines.push("8. **CRITICAL: DO NOT explore the filesystem or read other providers.** The reference implementation pattern is already provided below. Do not run `find`, `rg`, or `cat` on upstream providers. Doing so wastes context tokens and will crash the agent session. Focus entirely on modifying the target files.");
|
|
38813
|
+
lines.push("9. Do NOT delete any files. Implement the logic by replacing the empty stubs.");
|
|
38642
38814
|
lines.push("");
|
|
38643
38815
|
lines.push("## Required Return Format");
|
|
38644
38816
|
lines.push("| Function | Return JSON |");
|
|
@@ -38988,14 +39160,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
38988
39160
|
res.end(JSON.stringify(data, null, 2));
|
|
38989
39161
|
}
|
|
38990
39162
|
async readBody(req) {
|
|
38991
|
-
return new Promise((
|
|
39163
|
+
return new Promise((resolve7) => {
|
|
38992
39164
|
let body = "";
|
|
38993
39165
|
req.on("data", (chunk) => body += chunk);
|
|
38994
39166
|
req.on("end", () => {
|
|
38995
39167
|
try {
|
|
38996
|
-
|
|
39168
|
+
resolve7(JSON.parse(body));
|
|
38997
39169
|
} catch {
|
|
38998
|
-
|
|
39170
|
+
resolve7({});
|
|
38999
39171
|
}
|
|
39000
39172
|
});
|
|
39001
39173
|
});
|
|
@@ -39300,10 +39472,10 @@ async function installExtension(ide, extension) {
|
|
|
39300
39472
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
39301
39473
|
const fs13 = await import("fs");
|
|
39302
39474
|
fs13.writeFileSync(vsixPath, buffer);
|
|
39303
|
-
return new Promise((
|
|
39475
|
+
return new Promise((resolve7) => {
|
|
39304
39476
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
39305
39477
|
(0, import_child_process8.exec)(cmd, { timeout: 6e4 }, (error48, _stdout, stderr) => {
|
|
39306
|
-
|
|
39478
|
+
resolve7({
|
|
39307
39479
|
extensionId: extension.id,
|
|
39308
39480
|
marketplaceId: extension.marketplaceId,
|
|
39309
39481
|
success: !error48,
|
|
@@ -39316,11 +39488,11 @@ async function installExtension(ide, extension) {
|
|
|
39316
39488
|
} catch (e) {
|
|
39317
39489
|
}
|
|
39318
39490
|
}
|
|
39319
|
-
return new Promise((
|
|
39491
|
+
return new Promise((resolve7) => {
|
|
39320
39492
|
const cmd = `"${ide.cliCommand}" --install-extension ${extension.marketplaceId} --force`;
|
|
39321
39493
|
(0, import_child_process8.exec)(cmd, { timeout: 6e4 }, (error48, stdout, stderr) => {
|
|
39322
39494
|
if (error48) {
|
|
39323
|
-
|
|
39495
|
+
resolve7({
|
|
39324
39496
|
extensionId: extension.id,
|
|
39325
39497
|
marketplaceId: extension.marketplaceId,
|
|
39326
39498
|
success: false,
|
|
@@ -39328,7 +39500,7 @@ async function installExtension(ide, extension) {
|
|
|
39328
39500
|
error: stderr || error48.message
|
|
39329
39501
|
});
|
|
39330
39502
|
} else {
|
|
39331
|
-
|
|
39503
|
+
resolve7({
|
|
39332
39504
|
extensionId: extension.id,
|
|
39333
39505
|
marketplaceId: extension.marketplaceId,
|
|
39334
39506
|
success: true,
|
|
@@ -40164,13 +40336,13 @@ ${e?.stack || ""}`);
|
|
|
40164
40336
|
} catch {
|
|
40165
40337
|
}
|
|
40166
40338
|
const http3 = esmRequire("https");
|
|
40167
|
-
const data = await new Promise((
|
|
40339
|
+
const data = await new Promise((resolve7, reject) => {
|
|
40168
40340
|
const req = http3.get(`${serverUrl}/api/v1/turn/credentials`, {
|
|
40169
40341
|
headers: { "Authorization": `Bearer ${token}` }
|
|
40170
40342
|
}, (res) => {
|
|
40171
40343
|
let d = "";
|
|
40172
40344
|
res.on("data", (c) => d += c);
|
|
40173
|
-
res.on("end", () =>
|
|
40345
|
+
res.on("end", () => resolve7(d));
|
|
40174
40346
|
});
|
|
40175
40347
|
req.on("error", reject);
|
|
40176
40348
|
req.setTimeout(5e3, () => {
|
|
@@ -41026,7 +41198,7 @@ var init_adhdev_daemon = __esm({
|
|
|
41026
41198
|
fs12 = __toESM(require("fs"));
|
|
41027
41199
|
path14 = __toESM(require("path"));
|
|
41028
41200
|
import_chalk2 = __toESM(require("chalk"));
|
|
41029
|
-
pkgVersion = "0.6.
|
|
41201
|
+
pkgVersion = "0.6.59";
|
|
41030
41202
|
if (pkgVersion === "unknown") {
|
|
41031
41203
|
try {
|
|
41032
41204
|
const possiblePaths = [
|
|
@@ -41825,7 +41997,7 @@ __export(cdp_utils_exports, {
|
|
|
41825
41997
|
async function sendDaemonCommand(cmd, args = {}, port = 19222) {
|
|
41826
41998
|
const WebSocket3 = (await import("ws")).default;
|
|
41827
41999
|
const { DAEMON_WS_PATH: DAEMON_WS_PATH2 } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
41828
|
-
return new Promise((
|
|
42000
|
+
return new Promise((resolve7, reject) => {
|
|
41829
42001
|
const wsUrl = `ws://127.0.0.1:${port}${DAEMON_WS_PATH2 || "/daemon"}`;
|
|
41830
42002
|
const ws2 = new WebSocket3(wsUrl);
|
|
41831
42003
|
const timeout = setTimeout(() => {
|
|
@@ -41856,7 +42028,7 @@ async function sendDaemonCommand(cmd, args = {}, port = 19222) {
|
|
|
41856
42028
|
if (msg.type === "daemon:command_result" || msg.type === "command_result") {
|
|
41857
42029
|
clearTimeout(timeout);
|
|
41858
42030
|
ws2.close();
|
|
41859
|
-
|
|
42031
|
+
resolve7(msg.payload?.result || msg.payload || msg);
|
|
41860
42032
|
}
|
|
41861
42033
|
} catch {
|
|
41862
42034
|
}
|
|
@@ -41873,13 +42045,13 @@ Is 'adhdev daemon' running?`));
|
|
|
41873
42045
|
}
|
|
41874
42046
|
async function directCdpEval(expression, port = 9222) {
|
|
41875
42047
|
const http3 = await import("http");
|
|
41876
|
-
const targets = await new Promise((
|
|
42048
|
+
const targets = await new Promise((resolve7, reject) => {
|
|
41877
42049
|
http3.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
41878
42050
|
let data = "";
|
|
41879
42051
|
res.on("data", (c) => data += c);
|
|
41880
42052
|
res.on("end", () => {
|
|
41881
42053
|
try {
|
|
41882
|
-
|
|
42054
|
+
resolve7(JSON.parse(data));
|
|
41883
42055
|
} catch {
|
|
41884
42056
|
reject(new Error("Invalid JSON"));
|
|
41885
42057
|
}
|
|
@@ -41892,7 +42064,7 @@ async function directCdpEval(expression, port = 9222) {
|
|
|
41892
42064
|
const target = (mainPages.length > 0 ? mainPages[0] : pages[0]) || targets[0];
|
|
41893
42065
|
if (!target?.webSocketDebuggerUrl) throw new Error("No CDP target found");
|
|
41894
42066
|
const WebSocket3 = (await import("ws")).default;
|
|
41895
|
-
return new Promise((
|
|
42067
|
+
return new Promise((resolve7, reject) => {
|
|
41896
42068
|
const ws2 = new WebSocket3(target.webSocketDebuggerUrl);
|
|
41897
42069
|
const timeout = setTimeout(() => {
|
|
41898
42070
|
ws2.close();
|
|
@@ -41914,11 +42086,11 @@ async function directCdpEval(expression, port = 9222) {
|
|
|
41914
42086
|
clearTimeout(timeout);
|
|
41915
42087
|
ws2.close();
|
|
41916
42088
|
if (msg.result?.result?.value !== void 0) {
|
|
41917
|
-
|
|
42089
|
+
resolve7(msg.result.result.value);
|
|
41918
42090
|
} else if (msg.result?.exceptionDetails) {
|
|
41919
42091
|
reject(new Error(msg.result.exceptionDetails.text));
|
|
41920
42092
|
} else {
|
|
41921
|
-
|
|
42093
|
+
resolve7(msg.result);
|
|
41922
42094
|
}
|
|
41923
42095
|
}
|
|
41924
42096
|
});
|
|
@@ -42525,7 +42697,7 @@ function registerProviderCommands(program2) {
|
|
|
42525
42697
|
} catch {
|
|
42526
42698
|
try {
|
|
42527
42699
|
const http3 = await import("http");
|
|
42528
|
-
const result = await new Promise((
|
|
42700
|
+
const result = await new Promise((resolve7, reject) => {
|
|
42529
42701
|
const req = http3.request({
|
|
42530
42702
|
hostname: "127.0.0.1",
|
|
42531
42703
|
port: 19280,
|
|
@@ -42537,9 +42709,9 @@ function registerProviderCommands(program2) {
|
|
|
42537
42709
|
res.on("data", (c) => data += c);
|
|
42538
42710
|
res.on("end", () => {
|
|
42539
42711
|
try {
|
|
42540
|
-
|
|
42712
|
+
resolve7(JSON.parse(data));
|
|
42541
42713
|
} catch {
|
|
42542
|
-
|
|
42714
|
+
resolve7({ raw: data });
|
|
42543
42715
|
}
|
|
42544
42716
|
});
|
|
42545
42717
|
});
|
|
@@ -42642,12 +42814,12 @@ function registerProviderCommands(program2) {
|
|
|
42642
42814
|
console.log(import_chalk6.default.yellow("Invalid port number."));
|
|
42643
42815
|
continue;
|
|
42644
42816
|
}
|
|
42645
|
-
const isFree = await new Promise((
|
|
42817
|
+
const isFree = await new Promise((resolve7) => {
|
|
42646
42818
|
const server = net2.createServer();
|
|
42647
42819
|
server.unref();
|
|
42648
|
-
server.on("error", () =>
|
|
42820
|
+
server.on("error", () => resolve7(false));
|
|
42649
42821
|
server.listen(port, "127.0.0.1", () => {
|
|
42650
|
-
server.close(() =>
|
|
42822
|
+
server.close(() => resolve7(true));
|
|
42651
42823
|
});
|
|
42652
42824
|
});
|
|
42653
42825
|
if (!isFree) {
|
|
@@ -42662,7 +42834,7 @@ function registerProviderCommands(program2) {
|
|
|
42662
42834
|
rl.close();
|
|
42663
42835
|
const location = options.builtin ? "builtin" : "user";
|
|
42664
42836
|
const http3 = await import("http");
|
|
42665
|
-
const result = await new Promise((
|
|
42837
|
+
const result = await new Promise((resolve7, reject) => {
|
|
42666
42838
|
const postData = JSON.stringify({ type, name, category, location, cdpPorts, osPaths, processNames });
|
|
42667
42839
|
const req = http3.request({
|
|
42668
42840
|
hostname: "127.0.0.1",
|
|
@@ -42675,9 +42847,9 @@ function registerProviderCommands(program2) {
|
|
|
42675
42847
|
res.on("data", (c) => data += c);
|
|
42676
42848
|
res.on("end", () => {
|
|
42677
42849
|
try {
|
|
42678
|
-
|
|
42850
|
+
resolve7(JSON.parse(data));
|
|
42679
42851
|
} catch {
|
|
42680
|
-
|
|
42852
|
+
resolve7({ raw: data });
|
|
42681
42853
|
}
|
|
42682
42854
|
});
|
|
42683
42855
|
});
|
|
@@ -42913,7 +43085,7 @@ function registerProviderCommands(program2) {
|
|
|
42913
43085
|
...userComment ? { comment: userComment } : {},
|
|
42914
43086
|
reference
|
|
42915
43087
|
});
|
|
42916
|
-
const startResult = await new Promise((
|
|
43088
|
+
const startResult = await new Promise((resolve7, reject) => {
|
|
42917
43089
|
const req = http3.request({
|
|
42918
43090
|
hostname: "127.0.0.1",
|
|
42919
43091
|
port: 19280,
|
|
@@ -42925,9 +43097,9 @@ function registerProviderCommands(program2) {
|
|
|
42925
43097
|
res.on("data", (c) => data += c);
|
|
42926
43098
|
res.on("end", () => {
|
|
42927
43099
|
try {
|
|
42928
|
-
|
|
43100
|
+
resolve7(JSON.parse(data));
|
|
42929
43101
|
} catch {
|
|
42930
|
-
|
|
43102
|
+
resolve7({ raw: data });
|
|
42931
43103
|
}
|
|
42932
43104
|
});
|
|
42933
43105
|
});
|
|
@@ -42957,7 +43129,7 @@ function registerProviderCommands(program2) {
|
|
|
42957
43129
|
fsMock.writeFileSync(logFile2, `=== Auto-Impl Started ===
|
|
42958
43130
|
`);
|
|
42959
43131
|
console.log(import_chalk6.default.gray(` Agent logs: ${logFile2}`));
|
|
42960
|
-
await new Promise((
|
|
43132
|
+
await new Promise((resolve7, reject) => {
|
|
42961
43133
|
http3.get(`http://127.0.0.1:19280${startResult.sseUrl}`, (res) => {
|
|
42962
43134
|
let buffer = "";
|
|
42963
43135
|
res.on("data", (chunk) => {
|
|
@@ -42994,7 +43166,7 @@ function registerProviderCommands(program2) {
|
|
|
42994
43166
|
if (currentData.success === false) {
|
|
42995
43167
|
reject(new Error(`Agent failed to implement scripts properly (exit: ${currentData.exitCode})`));
|
|
42996
43168
|
} else {
|
|
42997
|
-
|
|
43169
|
+
resolve7();
|
|
42998
43170
|
}
|
|
42999
43171
|
} else if (currentEvent === "error") {
|
|
43000
43172
|
fsMock.appendFileSync(logFile2, `
|
|
@@ -43005,7 +43177,7 @@ function registerProviderCommands(program2) {
|
|
|
43005
43177
|
}
|
|
43006
43178
|
}
|
|
43007
43179
|
});
|
|
43008
|
-
res.on("end",
|
|
43180
|
+
res.on("end", resolve7);
|
|
43009
43181
|
}).on("error", reject);
|
|
43010
43182
|
});
|
|
43011
43183
|
console.log(import_chalk6.default.green(`
|
|
@@ -43064,7 +43236,7 @@ function registerProviderCommands(program2) {
|
|
|
43064
43236
|
ideType: type,
|
|
43065
43237
|
params: options.param ? { text: options.param, sessionId: options.param, buttonText: options.param } : {}
|
|
43066
43238
|
});
|
|
43067
|
-
const result = await new Promise((
|
|
43239
|
+
const result = await new Promise((resolve7, reject) => {
|
|
43068
43240
|
const req = http3.request({
|
|
43069
43241
|
hostname: "127.0.0.1",
|
|
43070
43242
|
port: 19280,
|
|
@@ -43076,9 +43248,9 @@ function registerProviderCommands(program2) {
|
|
|
43076
43248
|
res.on("data", (c) => data += c);
|
|
43077
43249
|
res.on("end", () => {
|
|
43078
43250
|
try {
|
|
43079
|
-
|
|
43251
|
+
resolve7(JSON.parse(data));
|
|
43080
43252
|
} catch {
|
|
43081
|
-
|
|
43253
|
+
resolve7({ raw: data });
|
|
43082
43254
|
}
|
|
43083
43255
|
});
|
|
43084
43256
|
});
|
|
@@ -43114,15 +43286,15 @@ function registerProviderCommands(program2) {
|
|
|
43114
43286
|
provider.command("source <type>").description("View source code of a provider").action(async (type) => {
|
|
43115
43287
|
try {
|
|
43116
43288
|
const http3 = await import("http");
|
|
43117
|
-
const result = await new Promise((
|
|
43289
|
+
const result = await new Promise((resolve7, reject) => {
|
|
43118
43290
|
http3.get(`http://127.0.0.1:19280/api/providers/${type}/source`, (res) => {
|
|
43119
43291
|
let data = "";
|
|
43120
43292
|
res.on("data", (c) => data += c);
|
|
43121
43293
|
res.on("end", () => {
|
|
43122
43294
|
try {
|
|
43123
|
-
|
|
43295
|
+
resolve7(JSON.parse(data));
|
|
43124
43296
|
} catch {
|
|
43125
|
-
|
|
43297
|
+
resolve7({ raw: data });
|
|
43126
43298
|
}
|
|
43127
43299
|
});
|
|
43128
43300
|
}).on("error", () => {
|
|
@@ -43171,7 +43343,7 @@ function registerProviderCommands(program2) {
|
|
|
43171
43343
|
try {
|
|
43172
43344
|
const http3 = await import("http");
|
|
43173
43345
|
const postData = JSON.stringify({ script: "readChat", params: {} });
|
|
43174
|
-
const result = await new Promise((
|
|
43346
|
+
const result = await new Promise((resolve7, reject) => {
|
|
43175
43347
|
const req = http3.request({
|
|
43176
43348
|
hostname: "127.0.0.1",
|
|
43177
43349
|
port: 19280,
|
|
@@ -43183,9 +43355,9 @@ function registerProviderCommands(program2) {
|
|
|
43183
43355
|
res2.on("data", (c) => data += c);
|
|
43184
43356
|
res2.on("end", () => {
|
|
43185
43357
|
try {
|
|
43186
|
-
|
|
43358
|
+
resolve7(JSON.parse(data));
|
|
43187
43359
|
} catch {
|
|
43188
|
-
|
|
43360
|
+
resolve7({ raw: data });
|
|
43189
43361
|
}
|
|
43190
43362
|
});
|
|
43191
43363
|
});
|
|
@@ -43426,13 +43598,13 @@ function registerCdpCommands(program2) {
|
|
|
43426
43598
|
cdp.command("screenshot").description("Capture IDE screenshot").option("-p, --port <port>", "CDP port", "9222").option("-o, --output <file>", "Output file path", "/tmp/cdp_screenshot.jpg").action(async (options) => {
|
|
43427
43599
|
try {
|
|
43428
43600
|
const http3 = await import("http");
|
|
43429
|
-
const targets = await new Promise((
|
|
43601
|
+
const targets = await new Promise((resolve7, reject) => {
|
|
43430
43602
|
http3.get(`http://127.0.0.1:${options.port}/json`, (res) => {
|
|
43431
43603
|
let data = "";
|
|
43432
43604
|
res.on("data", (c) => data += c);
|
|
43433
43605
|
res.on("end", () => {
|
|
43434
43606
|
try {
|
|
43435
|
-
|
|
43607
|
+
resolve7(JSON.parse(data));
|
|
43436
43608
|
} catch {
|
|
43437
43609
|
reject(new Error("Invalid JSON"));
|
|
43438
43610
|
}
|
|
@@ -43446,7 +43618,7 @@ function registerCdpCommands(program2) {
|
|
|
43446
43618
|
if (!target?.webSocketDebuggerUrl) throw new Error("No CDP target");
|
|
43447
43619
|
const WebSocket3 = (await import("ws")).default;
|
|
43448
43620
|
const ws2 = new WebSocket3(target.webSocketDebuggerUrl);
|
|
43449
|
-
await new Promise((
|
|
43621
|
+
await new Promise((resolve7, reject) => {
|
|
43450
43622
|
ws2.on("open", () => {
|
|
43451
43623
|
ws2.send(JSON.stringify({ id: 1, method: "Page.captureScreenshot", params: { format: "jpeg", quality: 50 } }));
|
|
43452
43624
|
});
|
|
@@ -43459,7 +43631,7 @@ function registerCdpCommands(program2) {
|
|
|
43459
43631
|
\u2713 Screenshot saved to ${options.output}
|
|
43460
43632
|
`));
|
|
43461
43633
|
ws2.close();
|
|
43462
|
-
|
|
43634
|
+
resolve7();
|
|
43463
43635
|
}
|
|
43464
43636
|
});
|
|
43465
43637
|
ws2.on("error", (e) => reject(e));
|