@aiderdesk/aiderdesk 0.72.0 → 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.
Files changed (74) hide show
  1. package/out/cli.js +982 -13
  2. package/out/renderer/assets/{AgentSettings-CEw1Tgyu.js → AgentSettings-B8NFKgLb.js} +2 -2
  3. package/out/renderer/assets/{InfoIcon-B6bij_VJ.js → InfoIcon-DhMP8XnB.js} +1 -1
  4. package/out/renderer/assets/{Onboarding-C2CtQOko.js → Onboarding-CmlEw4fh.js} +4 -4
  5. package/out/renderer/assets/{ProviderHeader-BCrdzdGT.js → ProviderHeader-DMNcKpGs.js} +83 -275
  6. package/out/renderer/assets/{SettingsPage-CNCsKRS7.js → SettingsPage-CmOR4wA1.js} +7 -7
  7. package/out/renderer/assets/{UsageDashboard-DtZ8GTj6.js → UsageDashboard-BGAWd1b2.js} +3 -3
  8. package/out/renderer/assets/{arc-DnyT8oZ2.js → arc-Jg3VSYdu.js} +1 -1
  9. package/out/renderer/assets/{architectureDiagram-3BPJPVTR-Dus_2n--.js → architectureDiagram-3BPJPVTR-BhT1Ad0h.js} +3 -3
  10. package/out/renderer/assets/{blockDiagram-GPEHLZMM-A3REgcbw.js → blockDiagram-GPEHLZMM-BZuMX6U_.js} +4 -4
  11. package/out/renderer/assets/{c4Diagram-AAUBKEIU-DksErR7z.js → c4Diagram-AAUBKEIU-QL7T5rpZ.js} +2 -2
  12. package/out/renderer/assets/{channel-DkjNDJNa.js → channel-K2W31OE5.js} +1 -1
  13. package/out/renderer/assets/{chunk-2J33WTMH-CrUC6pnQ.js → chunk-2J33WTMH-LumY2cbE.js} +1 -1
  14. package/out/renderer/assets/{chunk-4BX2VUAB-BulXGa1B.js → chunk-4BX2VUAB-GLhRzKG1.js} +1 -1
  15. package/out/renderer/assets/{chunk-55IACEB6-pQjPbAe9.js → chunk-55IACEB6-B3B3AcnH.js} +1 -1
  16. package/out/renderer/assets/{chunk-727SXJPM-BcqphFMh.js → chunk-727SXJPM-DMyZUEKf.js} +5 -5
  17. package/out/renderer/assets/{chunk-AQP2D5EJ-DCREtqoW.js → chunk-AQP2D5EJ-CQsD5TCd.js} +3 -3
  18. package/out/renderer/assets/{chunk-FMBD7UC4-LFUgit2t.js → chunk-FMBD7UC4-x4SmU5Oe.js} +1 -1
  19. package/out/renderer/assets/{chunk-ND2GUHAM-Bkunzp-9.js → chunk-ND2GUHAM-pT6s9nFT.js} +1 -1
  20. package/out/renderer/assets/{chunk-QZHKN3VN-foWYS4_y.js → chunk-QZHKN3VN-Cv8umQxL.js} +1 -1
  21. package/out/renderer/assets/{classDiagram-4FO5ZUOK-CVbKiC6R.js → classDiagram-4FO5ZUOK-DmOcXaER.js} +6 -6
  22. package/out/renderer/assets/{classDiagram-v2-Q7XG4LA2-CVbKiC6R.js → classDiagram-v2-Q7XG4LA2-DmOcXaER.js} +6 -6
  23. package/out/renderer/assets/{cose-bilkent-S5V4N54A-Bw7reEuM.js → cose-bilkent-S5V4N54A-Bi6ESdxa.js} +1 -1
  24. package/out/renderer/assets/{dagre-BM42HDAG-oGURKg82.js → dagre-BM42HDAG-BK2slT53.js} +3 -3
  25. package/out/renderer/assets/{diagram-2AECGRRQ-kaoJ1YpU.js → diagram-2AECGRRQ-DkgLH6e2.js} +3 -3
  26. package/out/renderer/assets/{diagram-5GNKFQAL-EvoHkNwk.js → diagram-5GNKFQAL-BwAieVd0.js} +4 -4
  27. package/out/renderer/assets/{diagram-KO2AKTUF-D5N5hwBV.js → diagram-KO2AKTUF-D6Km_LB9.js} +3 -3
  28. package/out/renderer/assets/{diagram-LMA3HP47-kKi9mSGe.js → diagram-LMA3HP47-BhWSHEeO.js} +3 -3
  29. package/out/renderer/assets/{diagram-OG6HWLK6-BWJ9L5AP.js → diagram-OG6HWLK6-zoN4RvNr.js} +4 -4
  30. package/out/renderer/assets/{erDiagram-TEJ5UH35-d1W9ONuu.js → erDiagram-TEJ5UH35-DooZS_mc.js} +4 -4
  31. package/out/renderer/assets/{flowDiagram-I6XJVG4X-u5Xk-TTj.js → flowDiagram-I6XJVG4X-CmZPvaDJ.js} +6 -6
  32. package/out/renderer/assets/{ganttDiagram-6RSMTGT7-DiheBMSM.js → ganttDiagram-6RSMTGT7-Bx6OJzRM.js} +3 -3
  33. package/out/renderer/assets/{gitGraphDiagram-PVQCEYII-B7hUlCNM.js → gitGraphDiagram-PVQCEYII-BPUT8Ht7.js} +4 -4
  34. package/out/renderer/assets/{graph-D7JlCUW0.js → graph-CwC0h_b8.js} +1 -1
  35. package/out/renderer/assets/{index-DJwDiyPe.css → index-B3o44aT2.css} +0 -24
  36. package/out/renderer/assets/{index-3OKQF96N.js → index-BSFaA4XQ.js} +1 -1
  37. package/out/renderer/assets/{index-gnQtDa4r.js → index-BrZFlbuf.js} +1 -1
  38. package/out/renderer/assets/{index-biM8l5ZN.js → index-CI0IUNzz.js} +9458 -1795
  39. package/out/renderer/assets/{index-BgXUknVd.js → index-CXq4cCbe.js} +5 -4
  40. package/out/renderer/assets/{index-D8P2TG70.js → index-ChKmR4QP.js} +1 -1
  41. package/out/renderer/assets/{index-DcFrLBMu.js → index-DOOlJc12.js} +1 -1
  42. package/out/renderer/assets/{index-DOl0MdBC.js → index-DqiktxfT.js} +1 -1
  43. package/out/renderer/assets/{index-ClS76F34.js → index-Ds5GQdTm.js} +1 -1
  44. package/out/renderer/assets/{index-CzGef_M5.js → index-PGLvyST0.js} +1 -1
  45. package/out/renderer/assets/{index-Duwg55fn.js → index-xI0MsLE8.js} +1 -1
  46. package/out/renderer/assets/{infoDiagram-5YYISTIA-BNOwcP8d.js → infoDiagram-5YYISTIA-C77gIx1a.js} +2 -2
  47. package/out/renderer/assets/{ishikawaDiagram-YF4QCWOH-DZGvMXcI.js → ishikawaDiagram-YF4QCWOH-DZ8xk7_N.js} +1 -1
  48. package/out/renderer/assets/{journeyDiagram-JHISSGLW-BF-SCAHN.js → journeyDiagram-JHISSGLW-BLPdv_c5.js} +4 -4
  49. package/out/renderer/assets/{jsx-dev-runtime-BZnUoQef.js → jsx-dev-runtime-1M6DZ35g.js} +1 -1
  50. package/out/renderer/assets/{kanban-definition-UN3LZRKU-Cp9SfO9v.js → kanban-definition-UN3LZRKU-CMHVN7c3.js} +2 -2
  51. package/out/renderer/assets/{layout-BxWwRUTm.js → layout-BJqshyQm.js} +2 -2
  52. package/out/renderer/assets/{linear-Cpdxqlgb.js → linear-CbEhS1qE.js} +1 -1
  53. package/out/renderer/assets/{mindmap-definition-RKZ34NQL-BtGsJF8k.js → mindmap-definition-RKZ34NQL-C8Cz7pQU.js} +3 -3
  54. package/out/renderer/assets/{pieDiagram-4H26LBE5-choZS41J.js → pieDiagram-4H26LBE5-Bx5tSw6i.js} +4 -4
  55. package/out/renderer/assets/{quadrantDiagram-W4KKPZXB-CSEwIgFD.js → quadrantDiagram-W4KKPZXB-CX6DcDEk.js} +2 -2
  56. package/out/renderer/assets/{requirementDiagram-4Y6WPE33-sCdLoMf0.js → requirementDiagram-4Y6WPE33-qBp8nKy9.js} +3 -3
  57. package/out/renderer/assets/{sankeyDiagram-5OEKKPKP-DunA5v4o.js → sankeyDiagram-5OEKKPKP-B5zYIsBo.js} +1 -1
  58. package/out/renderer/assets/{sequenceDiagram-3UESZ5HK-Cwz8rZA1.js → sequenceDiagram-3UESZ5HK-C57DtTdH.js} +3 -3
  59. package/out/renderer/assets/{stateDiagram-AJRCARHV-VCMhb3e-.js → stateDiagram-AJRCARHV-CGRyr6CG.js} +6 -6
  60. package/out/renderer/assets/{stateDiagram-v2-BHNVJYJU-B9OcfdsH.js → stateDiagram-v2-BHNVJYJU-3hvBe5lv.js} +4 -4
  61. package/out/renderer/assets/{time-CtsiuOCL.js → time-B3bXse3U.js} +1 -1
  62. package/out/renderer/assets/{timeline-definition-PNZ67QCA-B36Hc_gQ.js → timeline-definition-PNZ67QCA-Dpq0iPd0.js} +2 -2
  63. package/out/renderer/assets/{vennDiagram-CIIHVFJN-Dt2oWHz0.js → vennDiagram-CIIHVFJN-_jSNuVb5.js} +1 -1
  64. package/out/renderer/assets/{wardley-L42UT6IY-DkWaUY9X.js → wardley-L42UT6IY-DixmVaQZ.js} +1 -1
  65. package/out/renderer/assets/{wardleyDiagram-YWT4CUSO-BHFM3JNH.js → wardleyDiagram-YWT4CUSO-DMK4zc32.js} +3 -3
  66. package/out/renderer/assets/{xychartDiagram-2RQKCTM6-2wqqMVJ7.js → xychartDiagram-2RQKCTM6-DKPuWmAF.js} +2 -2
  67. package/out/renderer/index.html +2 -2
  68. package/out/resources/skills/extension-creator/SKILL.md +5 -5
  69. package/out/resources/skills/extension-creator/references/in-repo-flow.md +4 -4
  70. package/out/resources/skills/extension-creator/references/install-targets.md +2 -2
  71. package/out/resources/skills/extension-creator/references/project-global-flow.md +1 -1
  72. package/out/runner.js +115 -58
  73. package/package.json +3 -2
  74. package/scripts/generate-package.mjs +1 -0
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";
@@ -1049,14 +1068,14 @@ class RunStreamView {
1049
1068
  return visible;
1050
1069
  }
1051
1070
  }
1052
- const parseEventData = (raw) => {
1071
+ const parseEventData$1 = (raw) => {
1053
1072
  try {
1054
1073
  return JSON.parse(raw);
1055
1074
  } catch {
1056
1075
  return void 0;
1057
1076
  }
1058
1077
  };
1059
- const createDeferred = () => {
1078
+ const createDeferred$1 = () => {
1060
1079
  let resolve;
1061
1080
  let reject;
1062
1081
  const promise = new Promise((res, rej) => {
@@ -1090,7 +1109,7 @@ const readStdin = async () => {
1090
1109
  }
1091
1110
  return Buffer.concat(chunks).toString("utf-8").trim();
1092
1111
  };
1093
- const fetchJSON = async (host, port, path2, method, body) => {
1112
+ const fetchJSON$1 = async (host, port, path2, method, body) => {
1094
1113
  return new Promise((resolve, reject) => {
1095
1114
  const options = {
1096
1115
  hostname: host,
@@ -1124,7 +1143,7 @@ const fetchJSON = async (host, port, path2, method, body) => {
1124
1143
  req.end();
1125
1144
  });
1126
1145
  };
1127
- const callInterrupt = (host, port, projectDir, taskId) => {
1146
+ const callInterrupt$1 = (host, port, projectDir, taskId) => {
1128
1147
  if (!taskId) return Promise.resolve();
1129
1148
  const body = JSON.stringify({ projectDir, taskId });
1130
1149
  return new Promise((resolve) => {
@@ -1153,7 +1172,7 @@ const callInterrupt = (host, port, projectDir, taskId) => {
1153
1172
  req.end();
1154
1173
  });
1155
1174
  };
1156
- const requestSSEStream = (host, port, body) => {
1175
+ const requestSSEStream$1 = (host, port, body) => {
1157
1176
  return new Promise((resolve, reject) => {
1158
1177
  const options = {
1159
1178
  hostname: host,
@@ -1188,7 +1207,7 @@ const requestSSEStream = (host, port, body) => {
1188
1207
  req.end();
1189
1208
  });
1190
1209
  };
1191
- const parseSSEEvents = (stream) => {
1210
+ const parseSSEEvents$1 = (stream) => {
1192
1211
  const events = [];
1193
1212
  let resolve = null;
1194
1213
  const push = (event) => {
@@ -1226,7 +1245,7 @@ const parseSSEEvents = (stream) => {
1226
1245
  return {
1227
1246
  async next() {
1228
1247
  while (events.length === 0) {
1229
- const d = createDeferred();
1248
+ const d = createDeferred$1();
1230
1249
  resolve = d.resolve;
1231
1250
  await d.promise;
1232
1251
  }
@@ -1259,7 +1278,7 @@ ${stdinContent}` : stdinContent;
1259
1278
  process.exit(1);
1260
1279
  }
1261
1280
  try {
1262
- const health = await fetchJSON(host, port, "/api/health", "GET");
1281
+ const health = await fetchJSON$1(host, port, "/api/health", "GET");
1263
1282
  if (health.status !== 200 || health.data.status !== "ok") {
1264
1283
  process.stderr.write("Error: AiderDesk server is not healthy.\n");
1265
1284
  process.exit(1);
@@ -1283,9 +1302,9 @@ ${stdinContent}` : stdinContent;
1283
1302
  }
1284
1303
  const body = JSON.stringify(requestBody);
1285
1304
  let reqClosed = false;
1286
- const sseResponse = await requestSSEStream(host, port, body);
1305
+ const sseResponse = await requestSSEStream$1(host, port, body);
1287
1306
  const taskId = sseResponse.taskId;
1288
- const eventStream = parseSSEEvents(sseResponse.stream);
1307
+ const eventStream = parseSSEEvents$1(sseResponse.stream);
1289
1308
  let interrupted = false;
1290
1309
  const handleInterrupt = (tui) => {
1291
1310
  if (interrupted) {
@@ -1299,7 +1318,7 @@ ${stdinContent}` : stdinContent;
1299
1318
  if (!reqClosed) {
1300
1319
  sseResponse.stream.destroy();
1301
1320
  }
1302
- void callInterrupt(host, port, projectDir, taskId).then(() => process.exit(130));
1321
+ void callInterrupt$1(host, port, projectDir, taskId).then(() => process.exit(130));
1303
1322
  setTimeout(() => process.exit(130), 2e3);
1304
1323
  };
1305
1324
  process.on("SIGINT", () => handleInterrupt());
@@ -1332,7 +1351,7 @@ ${stdinContent}` : stdinContent;
1332
1351
  `);
1333
1352
  }
1334
1353
  for await (const event of eventStream) {
1335
- const eventData = parseEventData(event.data);
1354
+ const eventData = parseEventData$1(event.data);
1336
1355
  if (!eventData) continue;
1337
1356
  switch (event.type) {
1338
1357
  case "response-chunk": {
@@ -1478,7 +1497,7 @@ const runInteractiveStream = async (args) => {
1478
1497
  let success = false;
1479
1498
  try {
1480
1499
  for await (const event of args.eventStream) {
1481
- const eventData = parseEventData(event.data);
1500
+ const eventData = parseEventData$1(event.data);
1482
1501
  if (!eventData) continue;
1483
1502
  switch (event.type) {
1484
1503
  case "response-chunk": {
@@ -1552,6 +1571,955 @@ function registerRunCommand(program2) {
1552
1571
  runPrompt(messages, opts);
1553
1572
  });
1554
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
+ }
1555
2523
  function getVersion() {
1556
2524
  try {
1557
2525
  const pkg = JSON.parse(fs.readFileSync(path.join(pkgRoot, "package.json"), "utf8"));
@@ -1565,4 +2533,5 @@ program.name("aiderdesk").description("AiderDesk - AI-Powered Development Platfo
1565
2533
  registerStartCommand(program);
1566
2534
  registerTuiCommand(program);
1567
2535
  registerRunCommand(program);
2536
+ registerAcpCommand(program);
1568
2537
  program.parse();