@aiderdesk/aiderdesk 0.71.2-dev → 0.73.0
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/out/cli.js +1069 -16
- package/out/renderer/assets/{AgentSettings-CGvSAJzP.js → AgentSettings-B8NFKgLb.js} +133 -125
- package/out/renderer/assets/{InfoIcon-CWchJVTd.js → InfoIcon-DhMP8XnB.js} +1 -1
- package/out/renderer/assets/{Onboarding-DJOy0-Od.js → Onboarding-CmlEw4fh.js} +4 -4
- package/out/renderer/assets/{ProviderHeader-BeAt2P8D.js → ProviderHeader-DMNcKpGs.js} +519 -492
- package/out/renderer/assets/{SettingsPage-iA6BPLfI.js → SettingsPage-CmOR4wA1.js} +651 -269
- package/out/renderer/assets/{UsageDashboard-Byo1Se6j.js → UsageDashboard-BGAWd1b2.js} +3 -3
- package/out/renderer/assets/{arc-DMKtKWVp.js → arc-Jg3VSYdu.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-3BPJPVTR-B6q0Xxlt.js → architectureDiagram-3BPJPVTR-BhT1Ad0h.js} +3 -3
- package/out/renderer/assets/{blockDiagram-GPEHLZMM-CwUkQOmu.js → blockDiagram-GPEHLZMM-BZuMX6U_.js} +4 -4
- package/out/renderer/assets/{c4Diagram-AAUBKEIU-jfNF8o54.js → c4Diagram-AAUBKEIU-QL7T5rpZ.js} +2 -2
- package/out/renderer/assets/{channel-CGSP36Ng.js → channel-K2W31OE5.js} +1 -1
- package/out/renderer/assets/{chunk-2J33WTMH-m9o4-rdE.js → chunk-2J33WTMH-LumY2cbE.js} +1 -1
- package/out/renderer/assets/{chunk-4BX2VUAB-sBI0mD9g.js → chunk-4BX2VUAB-GLhRzKG1.js} +1 -1
- package/out/renderer/assets/{chunk-55IACEB6-Bi-yVgmi.js → chunk-55IACEB6-B3B3AcnH.js} +1 -1
- package/out/renderer/assets/{chunk-727SXJPM-DeJ6FAqm.js → chunk-727SXJPM-DMyZUEKf.js} +5 -5
- package/out/renderer/assets/{chunk-AQP2D5EJ-RYpGSg2J.js → chunk-AQP2D5EJ-CQsD5TCd.js} +3 -3
- package/out/renderer/assets/{chunk-FMBD7UC4-DhXJts_9.js → chunk-FMBD7UC4-x4SmU5Oe.js} +1 -1
- package/out/renderer/assets/{chunk-ND2GUHAM-BmWa3jDz.js → chunk-ND2GUHAM-pT6s9nFT.js} +1 -1
- package/out/renderer/assets/{chunk-QZHKN3VN-BDCZFGDN.js → chunk-QZHKN3VN-Cv8umQxL.js} +1 -1
- package/out/renderer/assets/{classDiagram-4FO5ZUOK-B5meZIas.js → classDiagram-4FO5ZUOK-DmOcXaER.js} +6 -6
- package/out/renderer/assets/{classDiagram-v2-Q7XG4LA2-B5meZIas.js → classDiagram-v2-Q7XG4LA2-DmOcXaER.js} +6 -6
- package/out/renderer/assets/{cose-bilkent-S5V4N54A-nN2TmyEI.js → cose-bilkent-S5V4N54A-Bi6ESdxa.js} +1 -1
- package/out/renderer/assets/{dagre-BM42HDAG-CKF8Re4C.js → dagre-BM42HDAG-BK2slT53.js} +3 -3
- package/out/renderer/assets/{diagram-2AECGRRQ-BEz7N4-p.js → diagram-2AECGRRQ-DkgLH6e2.js} +3 -3
- package/out/renderer/assets/{diagram-5GNKFQAL-DzixbxEI.js → diagram-5GNKFQAL-BwAieVd0.js} +4 -4
- package/out/renderer/assets/{diagram-KO2AKTUF-DrU3hJT-.js → diagram-KO2AKTUF-D6Km_LB9.js} +3 -3
- package/out/renderer/assets/{diagram-LMA3HP47-DeV3p8aR.js → diagram-LMA3HP47-BhWSHEeO.js} +3 -3
- package/out/renderer/assets/{diagram-OG6HWLK6-DqkXt2nH.js → diagram-OG6HWLK6-zoN4RvNr.js} +4 -4
- package/out/renderer/assets/{erDiagram-TEJ5UH35-BQPyNf4w.js → erDiagram-TEJ5UH35-DooZS_mc.js} +4 -4
- package/out/renderer/assets/{flowDiagram-I6XJVG4X-D2v6iQ98.js → flowDiagram-I6XJVG4X-CmZPvaDJ.js} +6 -6
- package/out/renderer/assets/{ganttDiagram-6RSMTGT7-CkYOeW7M.js → ganttDiagram-6RSMTGT7-Bx6OJzRM.js} +3 -3
- package/out/renderer/assets/{gitGraphDiagram-PVQCEYII-g-Uk6P-N.js → gitGraphDiagram-PVQCEYII-BPUT8Ht7.js} +4 -4
- package/out/renderer/assets/{graph-CV504Ptb.js → graph-CwC0h_b8.js} +1 -1
- package/out/renderer/assets/{index-D4QsfuBU.css → index-B3o44aT2.css} +8 -24
- package/out/renderer/assets/{index-U06SYLCN.js → index-BSFaA4XQ.js} +1 -1
- package/out/renderer/assets/{index-BijIcXFX.js → index-BrZFlbuf.js} +1 -1
- package/out/renderer/assets/{index-MWcT9iVP.js → index-CI0IUNzz.js} +12451 -3381
- package/out/renderer/assets/{index-3BRmjDVt.js → index-CXq4cCbe.js} +131 -31
- package/out/renderer/assets/{index-BRRWavZT.js → index-ChKmR4QP.js} +1 -1
- package/out/renderer/assets/{index-DWl6Lclq.js → index-DOOlJc12.js} +1 -1
- package/out/renderer/assets/{index-Bup9YtMB.js → index-DqiktxfT.js} +1 -1
- package/out/renderer/assets/{index-BKAL4gqM.js → index-Ds5GQdTm.js} +1 -1
- package/out/renderer/assets/{index-BBiLtvNT.js → index-PGLvyST0.js} +1 -1
- package/out/renderer/assets/{index-McGZ6Dx1.js → index-xI0MsLE8.js} +1 -1
- package/out/renderer/assets/{infoDiagram-5YYISTIA-D7CDIKx-.js → infoDiagram-5YYISTIA-C77gIx1a.js} +2 -2
- package/out/renderer/assets/{ishikawaDiagram-YF4QCWOH-Dy5lIJM3.js → ishikawaDiagram-YF4QCWOH-DZ8xk7_N.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-JHISSGLW-s4XQg-Ha.js → journeyDiagram-JHISSGLW-BLPdv_c5.js} +4 -4
- package/out/renderer/assets/{jsx-dev-runtime-D9-9kVso.js → jsx-dev-runtime-1M6DZ35g.js} +1 -1
- package/out/renderer/assets/{kanban-definition-UN3LZRKU-BCWYozJY.js → kanban-definition-UN3LZRKU-CMHVN7c3.js} +2 -2
- package/out/renderer/assets/{layout-DnWGEu0W.js → layout-BJqshyQm.js} +2 -2
- package/out/renderer/assets/{linear-BP7dS-hv.js → linear-CbEhS1qE.js} +1 -1
- package/out/renderer/assets/{mindmap-definition-RKZ34NQL-DpF4KI3g.js → mindmap-definition-RKZ34NQL-C8Cz7pQU.js} +3 -3
- package/out/renderer/assets/{pieDiagram-4H26LBE5-B6ZbPky5.js → pieDiagram-4H26LBE5-Bx5tSw6i.js} +4 -4
- package/out/renderer/assets/{quadrantDiagram-W4KKPZXB-QcDi1tPp.js → quadrantDiagram-W4KKPZXB-CX6DcDEk.js} +2 -2
- package/out/renderer/assets/{requirementDiagram-4Y6WPE33-B1JR969o.js → requirementDiagram-4Y6WPE33-qBp8nKy9.js} +3 -3
- package/out/renderer/assets/{sankeyDiagram-5OEKKPKP-BJ5rhw2A.js → sankeyDiagram-5OEKKPKP-B5zYIsBo.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-3UESZ5HK-AdtAIm4D.js → sequenceDiagram-3UESZ5HK-C57DtTdH.js} +3 -3
- package/out/renderer/assets/{stateDiagram-AJRCARHV--GQXQ4Qf.js → stateDiagram-AJRCARHV-CGRyr6CG.js} +6 -6
- package/out/renderer/assets/{stateDiagram-v2-BHNVJYJU-CQAnRm7m.js → stateDiagram-v2-BHNVJYJU-3hvBe5lv.js} +4 -4
- package/out/renderer/assets/{time-BUK5ZzpA.js → time-B3bXse3U.js} +1 -1
- package/out/renderer/assets/{timeline-definition-PNZ67QCA-CRru39WZ.js → timeline-definition-PNZ67QCA-Dpq0iPd0.js} +2 -2
- package/out/renderer/assets/{vennDiagram-CIIHVFJN-KF7qF8WR.js → vennDiagram-CIIHVFJN-_jSNuVb5.js} +1 -1
- package/out/renderer/assets/{wardley-L42UT6IY-D3pQt3SZ.js → wardley-L42UT6IY-DixmVaQZ.js} +1 -1
- package/out/renderer/assets/{wardleyDiagram-YWT4CUSO-D3zxlHug.js → wardleyDiagram-YWT4CUSO-DMK4zc32.js} +3 -3
- package/out/renderer/assets/{xychartDiagram-2RQKCTM6-B_0-TgYJ.js → xychartDiagram-2RQKCTM6-DKPuWmAF.js} +2 -2
- package/out/renderer/index.html +2 -2
- package/out/resources/connector/connector.py +6 -1
- package/out/resources/skills/extension-creator/SKILL.md +5 -5
- package/out/resources/skills/extension-creator/references/in-repo-flow.md +4 -4
- package/out/resources/skills/extension-creator/references/install-targets.md +2 -2
- package/out/resources/skills/extension-creator/references/project-global-flow.md +1 -1
- package/out/runner.js +881 -385
- package/package.json +16 -19
- package/scripts/download-probe.mjs +9 -2
- package/scripts/generate-package.mjs +1 -1
- package/out/renderer/assets/gemini-cli-BKI4k4GP.png +0 -0
- package/patches/ai-sdk-provider-gemini-cli+1.5.1.patch +0 -373
package/out/cli.js
CHANGED
|
@@ -5,6 +5,25 @@ const commander = require("commander");
|
|
|
5
5
|
const child_process = require("child_process");
|
|
6
6
|
const piTui = require("@earendil-works/pi-tui");
|
|
7
7
|
const http = require("http");
|
|
8
|
+
const node_stream = require("node:stream");
|
|
9
|
+
const acp = require("@agentclientprotocol/sdk");
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
12
|
+
if (e) {
|
|
13
|
+
for (const k in e) {
|
|
14
|
+
if (k !== "default") {
|
|
15
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: () => e[k]
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
const acp__namespace = /* @__PURE__ */ _interopNamespaceDefault(acp);
|
|
8
27
|
const READY_PATTERN = /AiderDesk Runner is ready and running on port (\d+)/;
|
|
9
28
|
const DEFAULT_PORT = 24337;
|
|
10
29
|
const DEFAULT_HOST = "localhost";
|
|
@@ -13,6 +32,10 @@ const pkgRoot = path.resolve(path.dirname(__filename), "..");
|
|
|
13
32
|
const resourcesDir = path.resolve(pkgRoot, "out", "resources");
|
|
14
33
|
const rendererDir = path.resolve(pkgRoot, "out", "renderer");
|
|
15
34
|
const runnerPath = path.resolve(pkgRoot, "out", "runner.js");
|
|
35
|
+
const probePlatformDir = process.platform === "win32" ? "win" : process.platform === "darwin" ? "macos" : "linux";
|
|
36
|
+
const probeExeName = process.platform === "win32" ? "probe.exe" : "probe";
|
|
37
|
+
const probeBinaryPath = path.join(resourcesDir, probePlatformDir, probeExeName);
|
|
38
|
+
const probeScriptPath = path.resolve(pkgRoot, "scripts", "download-probe.mjs");
|
|
16
39
|
function getPortFromEnv() {
|
|
17
40
|
const envPort = process.env.AIDER_DESK_PORT;
|
|
18
41
|
if (envPort) {
|
|
@@ -44,6 +67,61 @@ const c = {
|
|
|
44
67
|
boldWhite: (s) => `\x1B[1m\x1B[37m${s}\x1B[0m`,
|
|
45
68
|
bgCyanBlack: (s) => `\x1B[30m\x1B[46m${s}\x1B[0m`
|
|
46
69
|
};
|
|
70
|
+
function isProbeBinaryPresent() {
|
|
71
|
+
return fs.existsSync(probeBinaryPath);
|
|
72
|
+
}
|
|
73
|
+
function announce(line, sink, isError = false) {
|
|
74
|
+
if (sink) {
|
|
75
|
+
sink(line, isError);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const color = isError ? "\x1B[31m" : "\x1B[33m";
|
|
79
|
+
process.stderr.write(`${color}${line}\x1B[0m
|
|
80
|
+
`);
|
|
81
|
+
}
|
|
82
|
+
function ensureProbeBinary(onOutput) {
|
|
83
|
+
if (isProbeBinaryPresent()) return true;
|
|
84
|
+
const usePipe = typeof onOutput === "function";
|
|
85
|
+
announce(`Probe binary not found at ${probeBinaryPath}. Attempting to download...`, onOutput);
|
|
86
|
+
let result;
|
|
87
|
+
try {
|
|
88
|
+
result = child_process.spawnSync(process.execPath, [probeScriptPath, "--current-platform-only"], {
|
|
89
|
+
cwd: pkgRoot,
|
|
90
|
+
env: { ...process.env, RESOURCES_DIR: resourcesDir },
|
|
91
|
+
stdio: usePipe ? "pipe" : "inherit",
|
|
92
|
+
encoding: usePipe ? "utf8" : void 0
|
|
93
|
+
});
|
|
94
|
+
} catch (err) {
|
|
95
|
+
announce(`Failed to launch probe download script: ${err.message}`, onOutput, true);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (result.error) {
|
|
99
|
+
announce(`Failed to download probe binary: ${result.error.message}`, onOutput, true);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (usePipe) {
|
|
103
|
+
const stderr = result.stderr ?? "";
|
|
104
|
+
for (const rawLine of stderr.split("\n")) {
|
|
105
|
+
const line = rawLine.trim();
|
|
106
|
+
if (line) announce(line, onOutput, true);
|
|
107
|
+
}
|
|
108
|
+
const stdout = result.stdout ?? "";
|
|
109
|
+
for (const rawLine of stdout.split("\n")) {
|
|
110
|
+
const line = rawLine.trim();
|
|
111
|
+
if (line) announce(line, onOutput);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (typeof result.status === "number" && result.status !== 0) {
|
|
115
|
+
announce(`Probe download script exited with code ${result.status}.`, onOutput, true);
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (!isProbeBinaryPresent()) {
|
|
119
|
+
announce(`Probe binary still not found at ${probeBinaryPath} after download attempt.`, onOutput, true);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
announce("Probe binary downloaded successfully.", onOutput);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
47
125
|
function getRunnerEnv(port) {
|
|
48
126
|
const env = {
|
|
49
127
|
...process.env,
|
|
@@ -58,14 +136,25 @@ function getRunnerEnv(port) {
|
|
|
58
136
|
}
|
|
59
137
|
return env;
|
|
60
138
|
}
|
|
61
|
-
function spawnRunnerProcess(port, stdio) {
|
|
139
|
+
function spawnRunnerProcess(port, stdio, onEnsureProbeOutput) {
|
|
140
|
+
if (!ensureProbeBinary(onEnsureProbeOutput)) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
"Probe binary is missing and could not be downloaded. Semantic search will not be available. Re-run the probe download manually: RESOURCES_DIR=./out/resources node scripts/download-probe.mjs --current-platform-only"
|
|
143
|
+
);
|
|
144
|
+
}
|
|
62
145
|
return child_process.spawn(process.execPath, [runnerPath], {
|
|
63
146
|
env: getRunnerEnv(port),
|
|
64
147
|
stdio
|
|
65
148
|
});
|
|
66
149
|
}
|
|
67
150
|
function spawnRunner(port, stdio) {
|
|
68
|
-
|
|
151
|
+
let child;
|
|
152
|
+
try {
|
|
153
|
+
child = spawnRunnerProcess(port, stdio);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
console.error(`Failed to start: ${err.message}`);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
69
158
|
const forwardSignal = (signal) => {
|
|
70
159
|
child.kill(signal);
|
|
71
160
|
};
|
|
@@ -151,7 +240,21 @@ class AiderDeskCli {
|
|
|
151
240
|
this.logBuffer.clear();
|
|
152
241
|
this.selectedMenuIndex = 0;
|
|
153
242
|
this.invalidate();
|
|
154
|
-
|
|
243
|
+
try {
|
|
244
|
+
this.childProcess = spawnRunnerProcess(
|
|
245
|
+
this.configuredPort,
|
|
246
|
+
["pipe", "pipe", "pipe"],
|
|
247
|
+
(line, isError) => {
|
|
248
|
+
this.logBuffer.push(isError ? c.red(line) : c.cyan(line));
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
} catch (err) {
|
|
252
|
+
this.logBuffer.push(c.red(`Failed to start: ${err.message}`));
|
|
253
|
+
this.state = "idle";
|
|
254
|
+
this.invalidate();
|
|
255
|
+
this.tui.requestRender();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
155
258
|
const handleOutput = (data) => {
|
|
156
259
|
const text = data.toString();
|
|
157
260
|
const lines = text.split("\n").filter((l) => l.trim());
|
|
@@ -965,14 +1068,14 @@ class RunStreamView {
|
|
|
965
1068
|
return visible;
|
|
966
1069
|
}
|
|
967
1070
|
}
|
|
968
|
-
const parseEventData = (raw) => {
|
|
1071
|
+
const parseEventData$1 = (raw) => {
|
|
969
1072
|
try {
|
|
970
1073
|
return JSON.parse(raw);
|
|
971
1074
|
} catch {
|
|
972
1075
|
return void 0;
|
|
973
1076
|
}
|
|
974
1077
|
};
|
|
975
|
-
const createDeferred = () => {
|
|
1078
|
+
const createDeferred$1 = () => {
|
|
976
1079
|
let resolve;
|
|
977
1080
|
let reject;
|
|
978
1081
|
const promise = new Promise((res, rej) => {
|
|
@@ -1006,7 +1109,7 @@ const readStdin = async () => {
|
|
|
1006
1109
|
}
|
|
1007
1110
|
return Buffer.concat(chunks).toString("utf-8").trim();
|
|
1008
1111
|
};
|
|
1009
|
-
const fetchJSON = async (host, port, path2, method, body) => {
|
|
1112
|
+
const fetchJSON$1 = async (host, port, path2, method, body) => {
|
|
1010
1113
|
return new Promise((resolve, reject) => {
|
|
1011
1114
|
const options = {
|
|
1012
1115
|
hostname: host,
|
|
@@ -1040,7 +1143,7 @@ const fetchJSON = async (host, port, path2, method, body) => {
|
|
|
1040
1143
|
req.end();
|
|
1041
1144
|
});
|
|
1042
1145
|
};
|
|
1043
|
-
const callInterrupt = (host, port, projectDir, taskId) => {
|
|
1146
|
+
const callInterrupt$1 = (host, port, projectDir, taskId) => {
|
|
1044
1147
|
if (!taskId) return Promise.resolve();
|
|
1045
1148
|
const body = JSON.stringify({ projectDir, taskId });
|
|
1046
1149
|
return new Promise((resolve) => {
|
|
@@ -1069,7 +1172,7 @@ const callInterrupt = (host, port, projectDir, taskId) => {
|
|
|
1069
1172
|
req.end();
|
|
1070
1173
|
});
|
|
1071
1174
|
};
|
|
1072
|
-
const requestSSEStream = (host, port, body) => {
|
|
1175
|
+
const requestSSEStream$1 = (host, port, body) => {
|
|
1073
1176
|
return new Promise((resolve, reject) => {
|
|
1074
1177
|
const options = {
|
|
1075
1178
|
hostname: host,
|
|
@@ -1104,7 +1207,7 @@ const requestSSEStream = (host, port, body) => {
|
|
|
1104
1207
|
req.end();
|
|
1105
1208
|
});
|
|
1106
1209
|
};
|
|
1107
|
-
const parseSSEEvents = (stream) => {
|
|
1210
|
+
const parseSSEEvents$1 = (stream) => {
|
|
1108
1211
|
const events = [];
|
|
1109
1212
|
let resolve = null;
|
|
1110
1213
|
const push = (event) => {
|
|
@@ -1142,7 +1245,7 @@ const parseSSEEvents = (stream) => {
|
|
|
1142
1245
|
return {
|
|
1143
1246
|
async next() {
|
|
1144
1247
|
while (events.length === 0) {
|
|
1145
|
-
const d = createDeferred();
|
|
1248
|
+
const d = createDeferred$1();
|
|
1146
1249
|
resolve = d.resolve;
|
|
1147
1250
|
await d.promise;
|
|
1148
1251
|
}
|
|
@@ -1175,7 +1278,7 @@ ${stdinContent}` : stdinContent;
|
|
|
1175
1278
|
process.exit(1);
|
|
1176
1279
|
}
|
|
1177
1280
|
try {
|
|
1178
|
-
const health = await fetchJSON(host, port, "/api/health", "GET");
|
|
1281
|
+
const health = await fetchJSON$1(host, port, "/api/health", "GET");
|
|
1179
1282
|
if (health.status !== 200 || health.data.status !== "ok") {
|
|
1180
1283
|
process.stderr.write("Error: AiderDesk server is not healthy.\n");
|
|
1181
1284
|
process.exit(1);
|
|
@@ -1199,9 +1302,9 @@ ${stdinContent}` : stdinContent;
|
|
|
1199
1302
|
}
|
|
1200
1303
|
const body = JSON.stringify(requestBody);
|
|
1201
1304
|
let reqClosed = false;
|
|
1202
|
-
const sseResponse = await requestSSEStream(host, port, body);
|
|
1305
|
+
const sseResponse = await requestSSEStream$1(host, port, body);
|
|
1203
1306
|
const taskId = sseResponse.taskId;
|
|
1204
|
-
const eventStream = parseSSEEvents(sseResponse.stream);
|
|
1307
|
+
const eventStream = parseSSEEvents$1(sseResponse.stream);
|
|
1205
1308
|
let interrupted = false;
|
|
1206
1309
|
const handleInterrupt = (tui) => {
|
|
1207
1310
|
if (interrupted) {
|
|
@@ -1215,7 +1318,7 @@ ${stdinContent}` : stdinContent;
|
|
|
1215
1318
|
if (!reqClosed) {
|
|
1216
1319
|
sseResponse.stream.destroy();
|
|
1217
1320
|
}
|
|
1218
|
-
void callInterrupt(host, port, projectDir, taskId).then(() => process.exit(130));
|
|
1321
|
+
void callInterrupt$1(host, port, projectDir, taskId).then(() => process.exit(130));
|
|
1219
1322
|
setTimeout(() => process.exit(130), 2e3);
|
|
1220
1323
|
};
|
|
1221
1324
|
process.on("SIGINT", () => handleInterrupt());
|
|
@@ -1248,7 +1351,7 @@ ${stdinContent}` : stdinContent;
|
|
|
1248
1351
|
`);
|
|
1249
1352
|
}
|
|
1250
1353
|
for await (const event of eventStream) {
|
|
1251
|
-
const eventData = parseEventData(event.data);
|
|
1354
|
+
const eventData = parseEventData$1(event.data);
|
|
1252
1355
|
if (!eventData) continue;
|
|
1253
1356
|
switch (event.type) {
|
|
1254
1357
|
case "response-chunk": {
|
|
@@ -1394,7 +1497,7 @@ const runInteractiveStream = async (args) => {
|
|
|
1394
1497
|
let success = false;
|
|
1395
1498
|
try {
|
|
1396
1499
|
for await (const event of args.eventStream) {
|
|
1397
|
-
const eventData = parseEventData(event.data);
|
|
1500
|
+
const eventData = parseEventData$1(event.data);
|
|
1398
1501
|
if (!eventData) continue;
|
|
1399
1502
|
switch (event.type) {
|
|
1400
1503
|
case "response-chunk": {
|
|
@@ -1468,6 +1571,955 @@ function registerRunCommand(program2) {
|
|
|
1468
1571
|
runPrompt(messages, opts);
|
|
1469
1572
|
});
|
|
1470
1573
|
}
|
|
1574
|
+
function getVersion$1() {
|
|
1575
|
+
try {
|
|
1576
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(pkgRoot, "package.json"), "utf8"));
|
|
1577
|
+
return pkg.version ?? "0.0.0";
|
|
1578
|
+
} catch {
|
|
1579
|
+
return "0.0.0";
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
function createDeferred() {
|
|
1583
|
+
let resolve;
|
|
1584
|
+
let reject;
|
|
1585
|
+
const promise = new Promise((res, rej) => {
|
|
1586
|
+
resolve = res;
|
|
1587
|
+
reject = rej;
|
|
1588
|
+
});
|
|
1589
|
+
return { promise, resolve, reject };
|
|
1590
|
+
}
|
|
1591
|
+
function fetchJSON(host, port, path2, method, body) {
|
|
1592
|
+
return new Promise((resolve, reject) => {
|
|
1593
|
+
const options = {
|
|
1594
|
+
hostname: host,
|
|
1595
|
+
port,
|
|
1596
|
+
path: path2,
|
|
1597
|
+
method,
|
|
1598
|
+
headers: body ? { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) } : void 0
|
|
1599
|
+
};
|
|
1600
|
+
const req = http.request(options, (res) => {
|
|
1601
|
+
const chunks = [];
|
|
1602
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
1603
|
+
res.on("end", () => {
|
|
1604
|
+
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
1605
|
+
try {
|
|
1606
|
+
const data = JSON.parse(raw);
|
|
1607
|
+
resolve({ status: res.statusCode ?? 500, data });
|
|
1608
|
+
} catch {
|
|
1609
|
+
resolve({ status: res.statusCode ?? 500, data: raw });
|
|
1610
|
+
}
|
|
1611
|
+
});
|
|
1612
|
+
});
|
|
1613
|
+
req.on("error", reject);
|
|
1614
|
+
req.setTimeout(1e4, () => {
|
|
1615
|
+
req.destroy(new Error("Request timed out"));
|
|
1616
|
+
});
|
|
1617
|
+
if (body) {
|
|
1618
|
+
req.write(body);
|
|
1619
|
+
}
|
|
1620
|
+
req.end();
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
function callInterrupt(host, port, projectDir, taskId) {
|
|
1624
|
+
const body = JSON.stringify({ projectDir, taskId });
|
|
1625
|
+
return fetchJSON(host, port, "/api/project/interrupt", "POST", body).then(() => void 0);
|
|
1626
|
+
}
|
|
1627
|
+
function requestSSEStream(host, port, body) {
|
|
1628
|
+
return new Promise((resolve, reject) => {
|
|
1629
|
+
const options = {
|
|
1630
|
+
hostname: host,
|
|
1631
|
+
port,
|
|
1632
|
+
path: "/api/run-prompt",
|
|
1633
|
+
method: "POST",
|
|
1634
|
+
headers: {
|
|
1635
|
+
"Content-Type": "application/json",
|
|
1636
|
+
Accept: "text/event-stream",
|
|
1637
|
+
"Cache-Control": "no-cache",
|
|
1638
|
+
"Content-Length": Buffer.byteLength(body)
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1641
|
+
const req = http.request(options, (res) => {
|
|
1642
|
+
if (res.statusCode !== 200) {
|
|
1643
|
+
const chunks = [];
|
|
1644
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
1645
|
+
res.on("end", () => {
|
|
1646
|
+
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
1647
|
+
reject(new Error(`Server returned ${res.statusCode}: ${raw}`));
|
|
1648
|
+
});
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
const taskId = res.headers["x-task-id"] ?? "";
|
|
1652
|
+
resolve({ stream: res, taskId });
|
|
1653
|
+
});
|
|
1654
|
+
req.on("error", reject);
|
|
1655
|
+
req.setTimeout(6e5, () => {
|
|
1656
|
+
req.destroy(new Error("Request timed out"));
|
|
1657
|
+
});
|
|
1658
|
+
req.write(body);
|
|
1659
|
+
req.end();
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
function parseSSEEvents(stream) {
|
|
1663
|
+
const events = [];
|
|
1664
|
+
let resolveNext = null;
|
|
1665
|
+
let streamEnded = false;
|
|
1666
|
+
let streamError = null;
|
|
1667
|
+
let buffer = "";
|
|
1668
|
+
let currentEventType = "";
|
|
1669
|
+
let currentDataLines = [];
|
|
1670
|
+
const flushEvent = () => {
|
|
1671
|
+
if (currentDataLines.length > 0) {
|
|
1672
|
+
events.push({
|
|
1673
|
+
type: currentEventType || "message",
|
|
1674
|
+
data: currentDataLines.join("\n")
|
|
1675
|
+
});
|
|
1676
|
+
currentEventType = "";
|
|
1677
|
+
currentDataLines = [];
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
stream.on("data", (chunk) => {
|
|
1681
|
+
buffer += chunk.toString("utf-8");
|
|
1682
|
+
const lines = buffer.split("\n");
|
|
1683
|
+
buffer = lines.pop() ?? "";
|
|
1684
|
+
for (const line of lines) {
|
|
1685
|
+
if (line.startsWith(":")) {
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
if (line.trim() === "") {
|
|
1689
|
+
flushEvent();
|
|
1690
|
+
continue;
|
|
1691
|
+
}
|
|
1692
|
+
if (line.startsWith("event:")) {
|
|
1693
|
+
currentEventType = line.slice(6).trim();
|
|
1694
|
+
} else if (line.startsWith("data:")) {
|
|
1695
|
+
currentDataLines.push(line.slice(5).trimStart());
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
if (resolveNext) {
|
|
1699
|
+
resolveNext();
|
|
1700
|
+
resolveNext = null;
|
|
1701
|
+
}
|
|
1702
|
+
});
|
|
1703
|
+
stream.on("close", () => {
|
|
1704
|
+
streamEnded = true;
|
|
1705
|
+
flushEvent();
|
|
1706
|
+
if (resolveNext) {
|
|
1707
|
+
resolveNext();
|
|
1708
|
+
resolveNext = null;
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
stream.on("error", (err) => {
|
|
1712
|
+
streamError = err;
|
|
1713
|
+
streamEnded = true;
|
|
1714
|
+
if (resolveNext) {
|
|
1715
|
+
resolveNext();
|
|
1716
|
+
resolveNext = null;
|
|
1717
|
+
}
|
|
1718
|
+
});
|
|
1719
|
+
return {
|
|
1720
|
+
[Symbol.asyncIterator]() {
|
|
1721
|
+
return {
|
|
1722
|
+
async next() {
|
|
1723
|
+
while (events.length === 0) {
|
|
1724
|
+
if (streamEnded) {
|
|
1725
|
+
if (streamError) {
|
|
1726
|
+
throw streamError;
|
|
1727
|
+
}
|
|
1728
|
+
return { value: void 0, done: true };
|
|
1729
|
+
}
|
|
1730
|
+
const d = createDeferred();
|
|
1731
|
+
resolveNext = d.resolve;
|
|
1732
|
+
await d.promise;
|
|
1733
|
+
resolveNext = null;
|
|
1734
|
+
}
|
|
1735
|
+
const event = events.shift();
|
|
1736
|
+
return { value: event, done: false };
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
function parseEventData(raw) {
|
|
1743
|
+
try {
|
|
1744
|
+
return JSON.parse(raw);
|
|
1745
|
+
} catch {
|
|
1746
|
+
return void 0;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
const TOOL_KIND_MAP = {
|
|
1750
|
+
read: "read",
|
|
1751
|
+
list: "read",
|
|
1752
|
+
view: "read",
|
|
1753
|
+
get: "read",
|
|
1754
|
+
edit: "edit",
|
|
1755
|
+
write: "edit",
|
|
1756
|
+
create: "edit",
|
|
1757
|
+
modify: "edit",
|
|
1758
|
+
store: "edit",
|
|
1759
|
+
update: "edit",
|
|
1760
|
+
delete: "delete",
|
|
1761
|
+
remove: "delete",
|
|
1762
|
+
move: "move",
|
|
1763
|
+
rename: "move",
|
|
1764
|
+
search: "search",
|
|
1765
|
+
find: "search",
|
|
1766
|
+
grep: "search",
|
|
1767
|
+
glob: "search",
|
|
1768
|
+
retrieve: "search",
|
|
1769
|
+
exec: "execute",
|
|
1770
|
+
run: "execute",
|
|
1771
|
+
command: "execute",
|
|
1772
|
+
bash: "execute",
|
|
1773
|
+
think: "think",
|
|
1774
|
+
plan: "think",
|
|
1775
|
+
fetch: "fetch",
|
|
1776
|
+
download: "fetch"
|
|
1777
|
+
};
|
|
1778
|
+
function inferToolKind(toolName) {
|
|
1779
|
+
const name = toolName.toLowerCase();
|
|
1780
|
+
for (const [pattern, kind] of Object.entries(TOOL_KIND_MAP)) {
|
|
1781
|
+
if (name.includes(pattern)) {
|
|
1782
|
+
return kind;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
return "other";
|
|
1786
|
+
}
|
|
1787
|
+
function parseToolArgs(args) {
|
|
1788
|
+
if (args && typeof args === "object") {
|
|
1789
|
+
return args;
|
|
1790
|
+
}
|
|
1791
|
+
if (typeof args === "string") {
|
|
1792
|
+
try {
|
|
1793
|
+
return JSON.parse(args);
|
|
1794
|
+
} catch {
|
|
1795
|
+
return {};
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
return {};
|
|
1799
|
+
}
|
|
1800
|
+
function extractFilePath(toolName, args) {
|
|
1801
|
+
if (args.filePath) {
|
|
1802
|
+
return String(args.filePath);
|
|
1803
|
+
}
|
|
1804
|
+
if (args.path) {
|
|
1805
|
+
return String(args.path);
|
|
1806
|
+
}
|
|
1807
|
+
if (toolName === "bash" && args.command) {
|
|
1808
|
+
return void 0;
|
|
1809
|
+
}
|
|
1810
|
+
return void 0;
|
|
1811
|
+
}
|
|
1812
|
+
function formatToolInputAsText(toolName, args) {
|
|
1813
|
+
const parts = [];
|
|
1814
|
+
if (args.filePath) {
|
|
1815
|
+
parts.push(`File: ${args.filePath}`);
|
|
1816
|
+
}
|
|
1817
|
+
if (args.url) {
|
|
1818
|
+
parts.push(`URL: ${args.url}`);
|
|
1819
|
+
}
|
|
1820
|
+
if (args.query) {
|
|
1821
|
+
parts.push(`Query: ${args.query}`);
|
|
1822
|
+
}
|
|
1823
|
+
if (args.pattern) {
|
|
1824
|
+
parts.push(`Pattern: ${args.pattern}`);
|
|
1825
|
+
}
|
|
1826
|
+
if (args.filePattern) {
|
|
1827
|
+
parts.push(`Files: ${args.filePattern}`);
|
|
1828
|
+
}
|
|
1829
|
+
if (args.searchTerm) {
|
|
1830
|
+
parts.push(`Search: ${args.searchTerm}`);
|
|
1831
|
+
}
|
|
1832
|
+
if (args.command) {
|
|
1833
|
+
parts.push(`Command: ${args.command}`);
|
|
1834
|
+
}
|
|
1835
|
+
if (args.type) {
|
|
1836
|
+
parts.push(`Type: ${args.type}`);
|
|
1837
|
+
}
|
|
1838
|
+
if (args.limit !== void 0) {
|
|
1839
|
+
parts.push(`Limit: ${args.limit}`);
|
|
1840
|
+
}
|
|
1841
|
+
const knownKeys = /* @__PURE__ */ new Set([
|
|
1842
|
+
"filePath",
|
|
1843
|
+
"path",
|
|
1844
|
+
"url",
|
|
1845
|
+
"query",
|
|
1846
|
+
"pattern",
|
|
1847
|
+
"filePattern",
|
|
1848
|
+
"searchTerm",
|
|
1849
|
+
"command",
|
|
1850
|
+
"type",
|
|
1851
|
+
"limit",
|
|
1852
|
+
"searchTerm",
|
|
1853
|
+
"replacementText",
|
|
1854
|
+
"content",
|
|
1855
|
+
"mode",
|
|
1856
|
+
"isRegex",
|
|
1857
|
+
"replaceAll",
|
|
1858
|
+
"withLines",
|
|
1859
|
+
"lineOffset",
|
|
1860
|
+
"lineLimit",
|
|
1861
|
+
"caseSensitive",
|
|
1862
|
+
"maxResults",
|
|
1863
|
+
"cwd",
|
|
1864
|
+
"ignore",
|
|
1865
|
+
"allowTests",
|
|
1866
|
+
"exact",
|
|
1867
|
+
"timeout",
|
|
1868
|
+
"language",
|
|
1869
|
+
"id"
|
|
1870
|
+
]);
|
|
1871
|
+
for (const [key, value] of Object.entries(args)) {
|
|
1872
|
+
if (!knownKeys.has(key) && value !== void 0) {
|
|
1873
|
+
const valStr = typeof value === "string" && value.length > 200 ? value.slice(0, 200) + "..." : String(value);
|
|
1874
|
+
parts.push(`${key}: ${valStr}`);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
return parts.join("\n");
|
|
1878
|
+
}
|
|
1879
|
+
function formatToolTitle(toolName, args) {
|
|
1880
|
+
const truncate = (s, max) => s.length > max ? s.slice(0, max) + "..." : s;
|
|
1881
|
+
switch (toolName) {
|
|
1882
|
+
case "grep":
|
|
1883
|
+
return args.searchTerm ? `Grep: "${truncate(args.searchTerm, 60)}"${args.filePattern ? ` in ${args.filePattern}` : ""}` : "Grep";
|
|
1884
|
+
case "glob":
|
|
1885
|
+
return args.pattern ? `Glob: ${truncate(args.pattern, 80)}` : "Glob";
|
|
1886
|
+
case "semantic_search":
|
|
1887
|
+
return args.query ? `Semantic Search: ${truncate(args.query, 80)}` : "Semantic Search";
|
|
1888
|
+
case "bash":
|
|
1889
|
+
return args.command ? `Bash: ${truncate(args.command, 80)}` : "Bash";
|
|
1890
|
+
case "file_read":
|
|
1891
|
+
return args.filePath ? `Read: ${args.filePath}` : "Read File";
|
|
1892
|
+
case "file_edit":
|
|
1893
|
+
return args.filePath ? `Edit: ${args.filePath}` : "Edit File";
|
|
1894
|
+
case "file_write":
|
|
1895
|
+
return args.filePath ? `Write: ${args.filePath}` : "Write File";
|
|
1896
|
+
case "fetch":
|
|
1897
|
+
return args.url ? `Fetch: ${truncate(args.url, 80)}` : "Fetch";
|
|
1898
|
+
default:
|
|
1899
|
+
return toolName.charAt(0).toUpperCase() + toolName.slice(1);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
function parseToolResponse(response) {
|
|
1903
|
+
if (!response) {
|
|
1904
|
+
return void 0;
|
|
1905
|
+
}
|
|
1906
|
+
try {
|
|
1907
|
+
return JSON.parse(response);
|
|
1908
|
+
} catch {
|
|
1909
|
+
return response;
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
function isToolFailed(toolName, responseData) {
|
|
1913
|
+
if (typeof responseData === "string") {
|
|
1914
|
+
return responseData.toLowerCase().startsWith("error") || responseData.toLowerCase().includes("failed") || responseData.toLowerCase().includes("denied") || responseData.toLowerCase().includes("cancelled");
|
|
1915
|
+
}
|
|
1916
|
+
return false;
|
|
1917
|
+
}
|
|
1918
|
+
function buildToolCallContentArray(toolName, args, responseData) {
|
|
1919
|
+
const content = [];
|
|
1920
|
+
if (toolName === "file_edit" && args.filePath && args.searchTerm !== void 0 && args.replacementText !== void 0) {
|
|
1921
|
+
content.push({
|
|
1922
|
+
type: "diff",
|
|
1923
|
+
path: args.filePath,
|
|
1924
|
+
oldText: args.searchTerm,
|
|
1925
|
+
newText: args.replacementText
|
|
1926
|
+
});
|
|
1927
|
+
if (typeof responseData === "string" && responseData.includes("Successfully")) {
|
|
1928
|
+
content.push({
|
|
1929
|
+
type: "content",
|
|
1930
|
+
content: { type: "text", text: responseData }
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
return content;
|
|
1934
|
+
}
|
|
1935
|
+
if (toolName === "file_write" && args.filePath) {
|
|
1936
|
+
content.push({
|
|
1937
|
+
type: "diff",
|
|
1938
|
+
path: args.filePath,
|
|
1939
|
+
oldText: null,
|
|
1940
|
+
newText: args.content ?? ""
|
|
1941
|
+
});
|
|
1942
|
+
if (typeof responseData === "string" && responseData.includes("Successfully")) {
|
|
1943
|
+
content.push({
|
|
1944
|
+
type: "content",
|
|
1945
|
+
content: { type: "text", text: responseData }
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
return content;
|
|
1949
|
+
}
|
|
1950
|
+
if (toolName === "file_read" && typeof responseData === "string") {
|
|
1951
|
+
content.push({
|
|
1952
|
+
type: "content",
|
|
1953
|
+
content: { type: "text", text: responseData }
|
|
1954
|
+
});
|
|
1955
|
+
return content;
|
|
1956
|
+
}
|
|
1957
|
+
if (toolName === "bash" && typeof responseData === "string") {
|
|
1958
|
+
content.push({
|
|
1959
|
+
type: "terminal",
|
|
1960
|
+
terminalId: args._terminalId ?? "default"
|
|
1961
|
+
});
|
|
1962
|
+
content.push({
|
|
1963
|
+
type: "content",
|
|
1964
|
+
content: { type: "text", text: responseData }
|
|
1965
|
+
});
|
|
1966
|
+
return content;
|
|
1967
|
+
}
|
|
1968
|
+
if (toolName === "grep") {
|
|
1969
|
+
const text = typeof responseData === "string" && responseData ? responseData : typeof responseData === "string" && responseData === "" ? "No matches found." : JSON.stringify(responseData, null, 2);
|
|
1970
|
+
content.push({
|
|
1971
|
+
type: "content",
|
|
1972
|
+
content: { type: "text", text }
|
|
1973
|
+
});
|
|
1974
|
+
return content;
|
|
1975
|
+
}
|
|
1976
|
+
if (toolName === "glob") {
|
|
1977
|
+
let text;
|
|
1978
|
+
if (Array.isArray(responseData)) {
|
|
1979
|
+
if (responseData.length === 0) {
|
|
1980
|
+
text = "No files found.";
|
|
1981
|
+
} else {
|
|
1982
|
+
text = `Found ${responseData.length} ${responseData.length === 1 ? "file" : "files"}:
|
|
1983
|
+
` + responseData.map((item) => typeof item === "string" ? item : JSON.stringify(item)).join("\n");
|
|
1984
|
+
}
|
|
1985
|
+
} else if (typeof responseData === "string" && responseData) {
|
|
1986
|
+
text = responseData;
|
|
1987
|
+
} else if (typeof responseData === "object" && responseData !== null) {
|
|
1988
|
+
text = JSON.stringify(responseData, null, 2);
|
|
1989
|
+
} else {
|
|
1990
|
+
text = "No files found.";
|
|
1991
|
+
}
|
|
1992
|
+
content.push({
|
|
1993
|
+
type: "content",
|
|
1994
|
+
content: { type: "text", text }
|
|
1995
|
+
});
|
|
1996
|
+
return content;
|
|
1997
|
+
}
|
|
1998
|
+
if (toolName === "semantic_search") {
|
|
1999
|
+
let text;
|
|
2000
|
+
if (typeof responseData === "string" && responseData) {
|
|
2001
|
+
text = responseData;
|
|
2002
|
+
} else if (typeof responseData === "object" && responseData !== null) {
|
|
2003
|
+
text = JSON.stringify(responseData, null, 2);
|
|
2004
|
+
} else {
|
|
2005
|
+
text = "No results found.";
|
|
2006
|
+
}
|
|
2007
|
+
content.push({
|
|
2008
|
+
type: "content",
|
|
2009
|
+
content: { type: "text", text }
|
|
2010
|
+
});
|
|
2011
|
+
return content;
|
|
2012
|
+
}
|
|
2013
|
+
if (Array.isArray(responseData)) {
|
|
2014
|
+
const text = responseData.map((item) => typeof item === "string" ? item : JSON.stringify(item, null, 2)).join("\n");
|
|
2015
|
+
if (text) {
|
|
2016
|
+
content.push({
|
|
2017
|
+
type: "content",
|
|
2018
|
+
content: { type: "text", text }
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
return content;
|
|
2022
|
+
}
|
|
2023
|
+
if (typeof responseData === "object" && responseData !== null) {
|
|
2024
|
+
content.push({
|
|
2025
|
+
type: "content",
|
|
2026
|
+
content: { type: "text", text: JSON.stringify(responseData, null, 2) }
|
|
2027
|
+
});
|
|
2028
|
+
return content;
|
|
2029
|
+
}
|
|
2030
|
+
if (typeof responseData === "string" && responseData) {
|
|
2031
|
+
content.push({
|
|
2032
|
+
type: "content",
|
|
2033
|
+
content: { type: "text", text: responseData }
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
return content;
|
|
2037
|
+
}
|
|
2038
|
+
function contentBlocksToPrompt(blocks) {
|
|
2039
|
+
const parts = [];
|
|
2040
|
+
const images = [];
|
|
2041
|
+
for (const block of blocks) {
|
|
2042
|
+
switch (block.type) {
|
|
2043
|
+
case "text":
|
|
2044
|
+
parts.push(block.text);
|
|
2045
|
+
break;
|
|
2046
|
+
case "image":
|
|
2047
|
+
if (block.data) {
|
|
2048
|
+
images.push(block.data);
|
|
2049
|
+
}
|
|
2050
|
+
break;
|
|
2051
|
+
case "resource": {
|
|
2052
|
+
const resource = block.resource;
|
|
2053
|
+
if (resource && "text" in resource && resource.text) {
|
|
2054
|
+
parts.push(resource.text);
|
|
2055
|
+
}
|
|
2056
|
+
break;
|
|
2057
|
+
}
|
|
2058
|
+
case "resource_link":
|
|
2059
|
+
parts.push(`@${block.name || block.uri}`);
|
|
2060
|
+
break;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
return { prompt: parts.join("\n\n"), images };
|
|
2064
|
+
}
|
|
2065
|
+
function generateSessionId() {
|
|
2066
|
+
return `acp-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
2067
|
+
}
|
|
2068
|
+
const BUILT_IN_MODES = [
|
|
2069
|
+
{ id: "agent", name: "Agent", description: "Agent mode with full tool access" },
|
|
2070
|
+
{ id: "code", name: "Code", description: "Code mode using Aider for edits" },
|
|
2071
|
+
{ id: "ask", name: "Ask", description: "Ask questions without making changes" },
|
|
2072
|
+
{ id: "architect", name: "Architect", description: "Design and plan without implementation" },
|
|
2073
|
+
{ id: "context", name: "Context", description: "Add context files to the conversation" }
|
|
2074
|
+
];
|
|
2075
|
+
const AIDER_MODES = ["code", "ask", "architect", "context"];
|
|
2076
|
+
const AUTONOMY_MODES = [
|
|
2077
|
+
{ id: "manual", name: "Manual", description: "Requires approval for every tool and plan" },
|
|
2078
|
+
{ id: "guided", name: "Guided", description: "Auto-approves tools, waits for plan approval" },
|
|
2079
|
+
{ id: "autonomous", name: "Autonomous", description: "Runs without interruption" }
|
|
2080
|
+
];
|
|
2081
|
+
const DEFAULT_MODE = "agent";
|
|
2082
|
+
const DEFAULT_AUTONOMY_MODE = "guided";
|
|
2083
|
+
function isAgentProfileVisible(mode) {
|
|
2084
|
+
return !AIDER_MODES.includes(mode);
|
|
2085
|
+
}
|
|
2086
|
+
async function fetchAgentProfiles(host, port) {
|
|
2087
|
+
try {
|
|
2088
|
+
const response = await fetchJSON(host, port, "/api/agent-profiles", "GET");
|
|
2089
|
+
if (response.status !== 200) return [];
|
|
2090
|
+
const profiles = response.data;
|
|
2091
|
+
if (!Array.isArray(profiles)) return [];
|
|
2092
|
+
return profiles.map((p) => ({ id: p.id, name: p.name }));
|
|
2093
|
+
} catch {
|
|
2094
|
+
return [];
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
async function fetchDefaultAgentProfileId(host, port, projectDir) {
|
|
2098
|
+
try {
|
|
2099
|
+
const response = await fetchJSON(host, port, `/api/project/settings?projectDir=${encodeURIComponent(projectDir)}`, "GET");
|
|
2100
|
+
if (response.status !== 200) return void 0;
|
|
2101
|
+
const settings = response.data;
|
|
2102
|
+
return settings?.agentProfileId;
|
|
2103
|
+
} catch {
|
|
2104
|
+
return void 0;
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
function resolveDefaultProfileId(profiles, projectDefault, persisted) {
|
|
2108
|
+
if (projectDefault && profiles.some((p) => p.id === projectDefault)) {
|
|
2109
|
+
return projectDefault;
|
|
2110
|
+
}
|
|
2111
|
+
if (persisted && profiles.some((p) => p.id === persisted)) {
|
|
2112
|
+
return persisted;
|
|
2113
|
+
}
|
|
2114
|
+
const defaultProfile = profiles.find((p) => p.id === "default");
|
|
2115
|
+
if (defaultProfile) {
|
|
2116
|
+
return defaultProfile.id;
|
|
2117
|
+
}
|
|
2118
|
+
return profiles[0]?.id;
|
|
2119
|
+
}
|
|
2120
|
+
async function fetchCustomModes(host, port, projectDir) {
|
|
2121
|
+
try {
|
|
2122
|
+
const response = await fetchJSON(host, port, `/api/project/custom-modes?projectDir=${encodeURIComponent(projectDir)}`, "GET");
|
|
2123
|
+
if (response.status !== 200) return [];
|
|
2124
|
+
const modes = response.data;
|
|
2125
|
+
if (!Array.isArray(modes)) return [];
|
|
2126
|
+
return modes.map((m) => ({ id: m.name, name: m.label, description: m.description }));
|
|
2127
|
+
} catch {
|
|
2128
|
+
return [];
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
function getAllModes(customModes) {
|
|
2132
|
+
return [...BUILT_IN_MODES, ...customModes];
|
|
2133
|
+
}
|
|
2134
|
+
function buildModeState(allModes, currentMode) {
|
|
2135
|
+
return {
|
|
2136
|
+
currentModeId: currentMode,
|
|
2137
|
+
availableModes: allModes.map((m) => ({
|
|
2138
|
+
id: m.id,
|
|
2139
|
+
name: m.name,
|
|
2140
|
+
...m.description ? { description: m.description } : {}
|
|
2141
|
+
}))
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
2144
|
+
function buildConfigOptions(allModes, agentProfiles, currentMode, currentProfileId, currentAutonomy) {
|
|
2145
|
+
const options = [
|
|
2146
|
+
{
|
|
2147
|
+
type: "select",
|
|
2148
|
+
id: "chat_mode",
|
|
2149
|
+
name: "Mode",
|
|
2150
|
+
category: "mode",
|
|
2151
|
+
currentValue: currentMode,
|
|
2152
|
+
options: allModes.map((m) => ({
|
|
2153
|
+
value: m.id,
|
|
2154
|
+
name: m.name,
|
|
2155
|
+
...m.description ? { description: m.description } : {}
|
|
2156
|
+
}))
|
|
2157
|
+
}
|
|
2158
|
+
];
|
|
2159
|
+
if (isAgentProfileVisible(currentMode)) {
|
|
2160
|
+
const profileOptions = agentProfiles.length > 0 ? agentProfiles : [{ id: "default", name: "Default" }];
|
|
2161
|
+
options.push({
|
|
2162
|
+
type: "select",
|
|
2163
|
+
id: "agent_profile",
|
|
2164
|
+
name: "Agent Profile",
|
|
2165
|
+
category: "_agent_profile",
|
|
2166
|
+
currentValue: currentProfileId ?? profileOptions[0].id,
|
|
2167
|
+
options: profileOptions.map((p) => ({
|
|
2168
|
+
value: p.id,
|
|
2169
|
+
name: p.name
|
|
2170
|
+
}))
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
2173
|
+
options.push({
|
|
2174
|
+
type: "select",
|
|
2175
|
+
id: "autonomy_mode",
|
|
2176
|
+
name: "Autonomy",
|
|
2177
|
+
category: "_autonomy_mode",
|
|
2178
|
+
currentValue: currentAutonomy,
|
|
2179
|
+
options: AUTONOMY_MODES.map((m) => ({
|
|
2180
|
+
value: m.id,
|
|
2181
|
+
name: m.name,
|
|
2182
|
+
...m.description ? { description: m.description } : {}
|
|
2183
|
+
}))
|
|
2184
|
+
});
|
|
2185
|
+
return options;
|
|
2186
|
+
}
|
|
2187
|
+
class AcpAgent {
|
|
2188
|
+
constructor(host, port) {
|
|
2189
|
+
this.host = host;
|
|
2190
|
+
this.port = port;
|
|
2191
|
+
this.sessions = /* @__PURE__ */ new Map();
|
|
2192
|
+
}
|
|
2193
|
+
async initialize(_params) {
|
|
2194
|
+
return {
|
|
2195
|
+
protocolVersion: acp__namespace.PROTOCOL_VERSION,
|
|
2196
|
+
agentCapabilities: {
|
|
2197
|
+
loadSession: false,
|
|
2198
|
+
promptCapabilities: { image: true, embeddedContext: true }
|
|
2199
|
+
},
|
|
2200
|
+
agentInfo: {
|
|
2201
|
+
name: "aiderdesk",
|
|
2202
|
+
title: "AiderDesk",
|
|
2203
|
+
version: getVersion$1()
|
|
2204
|
+
},
|
|
2205
|
+
authMethods: []
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
async authenticate(_params) {
|
|
2209
|
+
return {};
|
|
2210
|
+
}
|
|
2211
|
+
async newSession(params) {
|
|
2212
|
+
const sessionId = generateSessionId();
|
|
2213
|
+
const cwd = params.cwd ?? "";
|
|
2214
|
+
const [agentProfiles, customModes, projectDefaultProfileId] = await Promise.all([
|
|
2215
|
+
fetchAgentProfiles(this.host, this.port),
|
|
2216
|
+
fetchCustomModes(this.host, this.port, cwd),
|
|
2217
|
+
fetchDefaultAgentProfileId(this.host, this.port, cwd)
|
|
2218
|
+
]);
|
|
2219
|
+
const allModes = getAllModes(customModes);
|
|
2220
|
+
const defaultProfileId = resolveDefaultProfileId(agentProfiles, projectDefaultProfileId, this.lastAgentProfileId);
|
|
2221
|
+
this.sessions.set(sessionId, {
|
|
2222
|
+
cwd,
|
|
2223
|
+
mode: DEFAULT_MODE,
|
|
2224
|
+
agentProfileId: defaultProfileId,
|
|
2225
|
+
autonomyMode: DEFAULT_AUTONOMY_MODE,
|
|
2226
|
+
allModes,
|
|
2227
|
+
agentProfiles
|
|
2228
|
+
});
|
|
2229
|
+
const configOptions = buildConfigOptions(
|
|
2230
|
+
allModes,
|
|
2231
|
+
agentProfiles,
|
|
2232
|
+
DEFAULT_MODE,
|
|
2233
|
+
defaultProfileId,
|
|
2234
|
+
DEFAULT_AUTONOMY_MODE
|
|
2235
|
+
);
|
|
2236
|
+
return {
|
|
2237
|
+
sessionId,
|
|
2238
|
+
configOptions,
|
|
2239
|
+
modes: buildModeState(allModes, DEFAULT_MODE)
|
|
2240
|
+
};
|
|
2241
|
+
}
|
|
2242
|
+
async setConfigOption(params) {
|
|
2243
|
+
const session = this.sessions.get(params.sessionId);
|
|
2244
|
+
if (!session) {
|
|
2245
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
2246
|
+
}
|
|
2247
|
+
const value = String(params.value);
|
|
2248
|
+
switch (params.configId) {
|
|
2249
|
+
case "chat_mode":
|
|
2250
|
+
session.mode = value;
|
|
2251
|
+
break;
|
|
2252
|
+
case "agent_profile":
|
|
2253
|
+
session.agentProfileId = value;
|
|
2254
|
+
this.lastAgentProfileId = value;
|
|
2255
|
+
break;
|
|
2256
|
+
case "autonomy_mode":
|
|
2257
|
+
session.autonomyMode = value;
|
|
2258
|
+
break;
|
|
2259
|
+
}
|
|
2260
|
+
const configOptions = buildConfigOptions(
|
|
2261
|
+
session.allModes,
|
|
2262
|
+
session.agentProfiles,
|
|
2263
|
+
session.mode,
|
|
2264
|
+
session.agentProfileId,
|
|
2265
|
+
session.autonomyMode
|
|
2266
|
+
);
|
|
2267
|
+
return { configOptions };
|
|
2268
|
+
}
|
|
2269
|
+
async prompt(params, cx) {
|
|
2270
|
+
const session = this.sessions.get(params.sessionId);
|
|
2271
|
+
if (!session) {
|
|
2272
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
2273
|
+
}
|
|
2274
|
+
const abortController = new AbortController();
|
|
2275
|
+
session.abortController = abortController;
|
|
2276
|
+
try {
|
|
2277
|
+
const { prompt: promptText, images } = contentBlocksToPrompt(params.prompt);
|
|
2278
|
+
if (!promptText && images.length === 0) {
|
|
2279
|
+
return { stopReason: "end_turn" };
|
|
2280
|
+
}
|
|
2281
|
+
const requestBody = {
|
|
2282
|
+
prompt: promptText,
|
|
2283
|
+
projectDir: session.cwd,
|
|
2284
|
+
mode: session.mode,
|
|
2285
|
+
autonomyMode: session.autonomyMode
|
|
2286
|
+
};
|
|
2287
|
+
if (session.taskId) {
|
|
2288
|
+
requestBody.taskId = session.taskId;
|
|
2289
|
+
}
|
|
2290
|
+
if (session.agentProfileId && isAgentProfileVisible(session.mode)) {
|
|
2291
|
+
requestBody.agentProfileId = session.agentProfileId;
|
|
2292
|
+
}
|
|
2293
|
+
if (images.length > 0) {
|
|
2294
|
+
requestBody.images = images;
|
|
2295
|
+
}
|
|
2296
|
+
const sseResponse = await requestSSEStream(this.host, this.port, JSON.stringify(requestBody));
|
|
2297
|
+
if (sseResponse.taskId && !session.taskId) {
|
|
2298
|
+
session.taskId = sseResponse.taskId;
|
|
2299
|
+
}
|
|
2300
|
+
session.sseStream = sseResponse.stream;
|
|
2301
|
+
const eventStream = parseSSEEvents(sseResponse.stream);
|
|
2302
|
+
let streamedReasoning = "";
|
|
2303
|
+
for await (const event of eventStream) {
|
|
2304
|
+
if (abortController.signal.aborted) {
|
|
2305
|
+
break;
|
|
2306
|
+
}
|
|
2307
|
+
const eventData = parseEventData(event.data);
|
|
2308
|
+
if (!eventData) {
|
|
2309
|
+
continue;
|
|
2310
|
+
}
|
|
2311
|
+
switch (event.type) {
|
|
2312
|
+
case "response-chunk": {
|
|
2313
|
+
if (eventData.reasoning) {
|
|
2314
|
+
streamedReasoning += eventData.reasoning;
|
|
2315
|
+
await cx.notify(acp__namespace.methods.client.session.update, {
|
|
2316
|
+
sessionId: params.sessionId,
|
|
2317
|
+
update: {
|
|
2318
|
+
sessionUpdate: "agent_thought_chunk",
|
|
2319
|
+
...eventData.messageId ? { messageId: eventData.messageId } : {},
|
|
2320
|
+
content: { type: "text", text: eventData.reasoning }
|
|
2321
|
+
}
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2324
|
+
if (eventData.chunk) {
|
|
2325
|
+
await cx.notify(acp__namespace.methods.client.session.update, {
|
|
2326
|
+
sessionId: params.sessionId,
|
|
2327
|
+
update: {
|
|
2328
|
+
sessionUpdate: "agent_message_chunk",
|
|
2329
|
+
...eventData.messageId ? { messageId: eventData.messageId } : {},
|
|
2330
|
+
content: { type: "text", text: eventData.chunk }
|
|
2331
|
+
}
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
break;
|
|
2335
|
+
}
|
|
2336
|
+
case "response-completed": {
|
|
2337
|
+
if (eventData.reasoning) {
|
|
2338
|
+
const remaining = eventData.reasoning.startsWith(streamedReasoning) ? eventData.reasoning.slice(streamedReasoning.length) : eventData.reasoning;
|
|
2339
|
+
if (remaining) {
|
|
2340
|
+
await cx.notify(acp__namespace.methods.client.session.update, {
|
|
2341
|
+
sessionId: params.sessionId,
|
|
2342
|
+
update: {
|
|
2343
|
+
sessionUpdate: "agent_thought_chunk",
|
|
2344
|
+
...eventData.messageId ? { messageId: eventData.messageId } : {},
|
|
2345
|
+
content: { type: "text", text: remaining }
|
|
2346
|
+
}
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
streamedReasoning = eventData.reasoning;
|
|
2350
|
+
}
|
|
2351
|
+
if (eventData.usageReport) {
|
|
2352
|
+
const usage = eventData.usageReport;
|
|
2353
|
+
await cx.notify(acp__namespace.methods.client.session.update, {
|
|
2354
|
+
sessionId: params.sessionId,
|
|
2355
|
+
update: {
|
|
2356
|
+
sessionUpdate: "usage_update",
|
|
2357
|
+
used: (usage.sentTokens ?? 0) + (usage.receivedTokens ?? 0) + (usage.cacheReadTokens ?? 0),
|
|
2358
|
+
size: 0,
|
|
2359
|
+
...usage.agentTotalCost !== void 0 ? { cost: { amount: usage.agentTotalCost, currency: "USD" } } : {}
|
|
2360
|
+
}
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
break;
|
|
2364
|
+
}
|
|
2365
|
+
case "tool": {
|
|
2366
|
+
const toolId = eventData.id || "";
|
|
2367
|
+
if (!eventData.finished) {
|
|
2368
|
+
const args = parseToolArgs(eventData.args);
|
|
2369
|
+
const filePath = extractFilePath(eventData.toolName ?? "", args);
|
|
2370
|
+
const inputText = formatToolInputAsText(eventData.toolName ?? "", args);
|
|
2371
|
+
const title = formatToolTitle(eventData.toolName ?? "", args);
|
|
2372
|
+
await cx.notify(acp__namespace.methods.client.session.update, {
|
|
2373
|
+
sessionId: params.sessionId,
|
|
2374
|
+
update: {
|
|
2375
|
+
sessionUpdate: "tool_call",
|
|
2376
|
+
toolCallId: toolId,
|
|
2377
|
+
title,
|
|
2378
|
+
kind: inferToolKind(eventData.toolName ?? ""),
|
|
2379
|
+
status: "in_progress",
|
|
2380
|
+
...eventData.args ? { rawInput: eventData.args } : {},
|
|
2381
|
+
...filePath ? { locations: [{ path: filePath }] } : {},
|
|
2382
|
+
...inputText ? {
|
|
2383
|
+
content: [{ type: "content", content: { type: "text", text: inputText } }]
|
|
2384
|
+
} : {}
|
|
2385
|
+
}
|
|
2386
|
+
});
|
|
2387
|
+
} else {
|
|
2388
|
+
const args = parseToolArgs(eventData.args);
|
|
2389
|
+
const responseData = parseToolResponse(eventData.response ?? "");
|
|
2390
|
+
const failed = isToolFailed(eventData.toolName ?? "", responseData);
|
|
2391
|
+
const contentArray = buildToolCallContentArray(eventData.toolName ?? "", args, responseData);
|
|
2392
|
+
const inputText = formatToolInputAsText(eventData.toolName ?? "", args);
|
|
2393
|
+
const fullContent = [];
|
|
2394
|
+
if (inputText) {
|
|
2395
|
+
fullContent.push({
|
|
2396
|
+
type: "content",
|
|
2397
|
+
content: { type: "text", text: inputText }
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
fullContent.push(...contentArray);
|
|
2401
|
+
await cx.notify(acp__namespace.methods.client.session.update, {
|
|
2402
|
+
sessionId: params.sessionId,
|
|
2403
|
+
update: {
|
|
2404
|
+
sessionUpdate: "tool_call_update",
|
|
2405
|
+
toolCallId: toolId,
|
|
2406
|
+
status: failed ? "failed" : "completed",
|
|
2407
|
+
...fullContent.length > 0 ? { content: fullContent } : {}
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
}
|
|
2411
|
+
break;
|
|
2412
|
+
}
|
|
2413
|
+
case "log": {
|
|
2414
|
+
if (eventData.message && eventData.level !== "loading") {
|
|
2415
|
+
await cx.notify(acp__namespace.methods.client.session.update, {
|
|
2416
|
+
sessionId: params.sessionId,
|
|
2417
|
+
update: {
|
|
2418
|
+
sessionUpdate: "agent_thought_chunk",
|
|
2419
|
+
content: { type: "text", text: eventData.message }
|
|
2420
|
+
}
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
break;
|
|
2424
|
+
}
|
|
2425
|
+
case "task-updated":
|
|
2426
|
+
case "task-created": {
|
|
2427
|
+
if (eventData.name) {
|
|
2428
|
+
await cx.notify(acp__namespace.methods.client.session.update, {
|
|
2429
|
+
sessionId: params.sessionId,
|
|
2430
|
+
update: {
|
|
2431
|
+
sessionUpdate: "session_info_update",
|
|
2432
|
+
title: eventData.name,
|
|
2433
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2434
|
+
}
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
2437
|
+
break;
|
|
2438
|
+
}
|
|
2439
|
+
case "user-message": {
|
|
2440
|
+
if (eventData.messageId) {
|
|
2441
|
+
await cx.notify(acp__namespace.methods.client.session.update, {
|
|
2442
|
+
sessionId: params.sessionId,
|
|
2443
|
+
update: {
|
|
2444
|
+
sessionUpdate: "user_message_chunk",
|
|
2445
|
+
messageId: eventData.messageId,
|
|
2446
|
+
content: { type: "text", text: promptText }
|
|
2447
|
+
}
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2450
|
+
break;
|
|
2451
|
+
}
|
|
2452
|
+
case "stream-end": {
|
|
2453
|
+
return { stopReason: "end_turn" };
|
|
2454
|
+
}
|
|
2455
|
+
case "error": {
|
|
2456
|
+
process.stderr.write(`Server error: ${eventData.error || "Unknown error"}
|
|
2457
|
+
`);
|
|
2458
|
+
return { stopReason: "end_turn" };
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
if (abortController.signal.aborted) {
|
|
2463
|
+
return { stopReason: "cancelled" };
|
|
2464
|
+
}
|
|
2465
|
+
return { stopReason: "end_turn" };
|
|
2466
|
+
} catch (err) {
|
|
2467
|
+
if (abortController.signal.aborted) {
|
|
2468
|
+
return { stopReason: "cancelled" };
|
|
2469
|
+
}
|
|
2470
|
+
throw err;
|
|
2471
|
+
} finally {
|
|
2472
|
+
session.abortController = void 0;
|
|
2473
|
+
session.sseStream = void 0;
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
async cancel(params) {
|
|
2477
|
+
const session = this.sessions.get(params.sessionId);
|
|
2478
|
+
if (!session) {
|
|
2479
|
+
return;
|
|
2480
|
+
}
|
|
2481
|
+
session.abortController?.abort();
|
|
2482
|
+
if (session.sseStream) {
|
|
2483
|
+
try {
|
|
2484
|
+
session.sseStream.destroy();
|
|
2485
|
+
} catch {
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
if (session.taskId) {
|
|
2489
|
+
try {
|
|
2490
|
+
await callInterrupt(this.host, this.port, session.cwd, session.taskId);
|
|
2491
|
+
} catch {
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
async function startAcpAgent(host, port) {
|
|
2497
|
+
try {
|
|
2498
|
+
const health = await fetchJSON(host, port, "/api/health", "GET");
|
|
2499
|
+
const healthData = health.data;
|
|
2500
|
+
if (health.status !== 200 || healthData.status !== "ok") {
|
|
2501
|
+
process.stderr.write("Error: AiderDesk server is not healthy.\n");
|
|
2502
|
+
process.exit(1);
|
|
2503
|
+
}
|
|
2504
|
+
} catch {
|
|
2505
|
+
process.stderr.write(`Error: AiderDesk server is not running on ${host}:${port}. Start it first with 'aiderdesk' or 'aiderdesk start'.
|
|
2506
|
+
`);
|
|
2507
|
+
process.exit(1);
|
|
2508
|
+
}
|
|
2509
|
+
const agentInstance = new AcpAgent(host, port);
|
|
2510
|
+
const input = node_stream.Writable.toWeb(process.stdout);
|
|
2511
|
+
const output = node_stream.Readable.toWeb(process.stdin);
|
|
2512
|
+
const stream = acp__namespace.ndJsonStream(input, output);
|
|
2513
|
+
const connection = acp__namespace.agent({ name: "aiderdesk", title: "AiderDesk", version: getVersion$1() }).onRequest("initialize", (ctx) => agentInstance.initialize(ctx.params)).onRequest("authenticate", (ctx) => agentInstance.authenticate(ctx.params)).onRequest("session/new", (ctx) => agentInstance.newSession(ctx.params)).onRequest("session/set_config_option", (ctx) => agentInstance.setConfigOption(ctx.params)).onRequest("session/prompt", (ctx) => agentInstance.prompt(ctx.params, ctx.client)).onNotification("session/cancel", (ctx) => agentInstance.cancel(ctx.params)).connect(stream);
|
|
2514
|
+
await connection.closed;
|
|
2515
|
+
}
|
|
2516
|
+
function registerAcpCommand(program2) {
|
|
2517
|
+
program2.command("acp").description("Run as an ACP agent (Agent Client Protocol) over stdio").option("-p, --port <port>", `port to listen on (default: ${DEFAULT_PORT}, env: AIDER_DESK_PORT)`, parseInt).option("--host <host>", `server host (default: ${DEFAULT_HOST})`).action((opts) => {
|
|
2518
|
+
const port = resolvePort(opts.port);
|
|
2519
|
+
const host = opts.host || DEFAULT_HOST;
|
|
2520
|
+
void startAcpAgent(host, port);
|
|
2521
|
+
});
|
|
2522
|
+
}
|
|
1471
2523
|
function getVersion() {
|
|
1472
2524
|
try {
|
|
1473
2525
|
const pkg = JSON.parse(fs.readFileSync(path.join(pkgRoot, "package.json"), "utf8"));
|
|
@@ -1481,4 +2533,5 @@ program.name("aiderdesk").description("AiderDesk - AI-Powered Development Platfo
|
|
|
1481
2533
|
registerStartCommand(program);
|
|
1482
2534
|
registerTuiCommand(program);
|
|
1483
2535
|
registerRunCommand(program);
|
|
2536
|
+
registerAcpCommand(program);
|
|
1484
2537
|
program.parse();
|