@sideboard-ai/core 0.1.348 → 0.1.350

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 (84) hide show
  1. package/dist/{abletime-CGFJZB7L.js → abletime-TX7BTTR2.js} +5 -5
  2. package/dist/{abletime-3HRWLQZJ.js → abletime-URSRZW7P.js} +4 -4
  3. package/dist/{abletime-oauth-QNJQLHR4.js → abletime-oauth-QS3WPSCC.js} +3 -3
  4. package/dist/{abletime-oauth-JQDSH5OL.js → abletime-oauth-SL3NMNEC.js} +4 -4
  5. package/dist/{abletime-rest-TANL5TMY.js → abletime-rest-GGQLUO55.js} +3 -3
  6. package/dist/{abletime-rest-UQA2CRZN.js → abletime-rest-JZU6JJCV.js} +4 -4
  7. package/dist/agents/acp-runner.cjs +491 -0
  8. package/dist/agents/acp-runner.d.cts +46 -0
  9. package/dist/agents/acp-runner.d.ts +46 -0
  10. package/dist/agents/acp-runner.js +323 -0
  11. package/dist/agents/cursor-runner.js +3 -3
  12. package/dist/{agents-T4XBZZDA.js → agents-P5QIV24I.js} +38 -8
  13. package/dist/{agents-5MFGVK7C.js → agents-RGAV5OHD.js} +44 -13
  14. package/dist/{app-settings-SNOPJ7P5.js → app-settings-IA7ZZKWQ.js} +2 -2
  15. package/dist/{app-settings-PPIMYJKS.js → app-settings-XILTSD6L.js} +1 -1
  16. package/dist/{chunk-UGUWFONI.js → chunk-2E2HMJDU.js} +1 -1
  17. package/dist/{chunk-OH3BAUMC.js → chunk-2MESZ5XR.js} +273 -84
  18. package/dist/{chunk-RUIHNWRV.js → chunk-37ZBEBP6.js} +6 -6
  19. package/dist/{chunk-Y6VQX2LY.js → chunk-5AHWUJRT.js} +1927 -1718
  20. package/dist/{chunk-7B2OUQON.js → chunk-5TCMXEYL.js} +48 -3
  21. package/dist/{chunk-FDYMVJFU.js → chunk-5WF54R3B.js} +5 -5
  22. package/dist/{chunk-PVCECFJK.js → chunk-7ZD4OK6G.js} +1 -1
  23. package/dist/{chunk-RYPD7XWV.js → chunk-B4EFQTMP.js} +5 -5
  24. package/dist/chunk-BF6INES4.js +144 -0
  25. package/dist/{chunk-IVRWRYTH.js → chunk-BZK62VPT.js} +2 -2
  26. package/dist/{chunk-AJMERXZP.js → chunk-CCWQ65VD.js} +2 -2
  27. package/dist/{chunk-62ALWH3T.js → chunk-DL4OHDBV.js} +3 -3
  28. package/dist/{chunk-6TV6L2DD.js → chunk-EZ2MUWNW.js} +7 -6
  29. package/dist/{chunk-4NXGVJA6.js → chunk-F4RFFE2H.js} +48 -3
  30. package/dist/{chunk-E77SRVVO.js → chunk-FCKTBE26.js} +1 -1
  31. package/dist/{chunk-NTY5WGRD.js → chunk-FQ3JYUKI.js} +2 -2
  32. package/dist/{chunk-CEQ4Z32M.js → chunk-J4EA5SHF.js} +3 -3
  33. package/dist/{chunk-ORO4ENZR.js → chunk-LESWJ7L4.js} +1 -0
  34. package/dist/{chunk-XNGW4OYD.js → chunk-LFSTOECH.js} +7 -6
  35. package/dist/{chunk-OHUAAX3O.js → chunk-M45WGODR.js} +2 -2
  36. package/dist/{chunk-ZJMYCDYQ.js → chunk-MANERA6F.js} +55 -10
  37. package/dist/{chunk-Q4TZA4MN.js → chunk-NDEVAA34.js} +1629 -1486
  38. package/dist/{chunk-OPXEJJBM.js → chunk-PWOFUPYM.js} +1 -0
  39. package/dist/{chunk-UJMCTGV7.js → chunk-PXSWVZIL.js} +2 -2
  40. package/dist/{chunk-MOUAM6ZC.js → chunk-SMSD6U3N.js} +135 -3
  41. package/dist/{chunk-ATS7SYHG.js → chunk-TCEUNSLX.js} +135 -3
  42. package/dist/chunk-TRMPDDVL.js +232 -0
  43. package/dist/{chunk-6WMNIX2U.js → chunk-UFUAIVNV.js} +9 -5
  44. package/dist/{chunk-2HPVGTHF.js → chunk-VHQ6OG3U.js} +2 -2
  45. package/dist/{chunk-WWU4SYZR.js → chunk-VL6F2KRE.js} +5 -1
  46. package/dist/{chunk-WMD77UCY.js → chunk-W5GHFT7E.js} +279 -87
  47. package/dist/{chunk-5FUAOU3G.js → chunk-WB3G2LQO.js} +1 -1
  48. package/dist/{chunk-JCYGQKER.js → chunk-WFX4ZVSZ.js} +1 -1
  49. package/dist/{chunk-F7WP2U5I.js → chunk-WJURGCBR.js} +1 -1
  50. package/dist/{chunk-BIM24I3O.js → chunk-WWBPK7GB.js} +1 -1
  51. package/dist/chunk-YE7Z5WH3.js +142 -0
  52. package/dist/{chunk-5YCKATG6.js → chunk-YVN7L4KG.js} +1 -1
  53. package/dist/{chunk-GAGTEI6B.js → chunk-ZBSEJIOV.js} +56 -11
  54. package/dist/{conductor-LYQKONSA.js → conductor-HVOGBK63.js} +7 -6
  55. package/dist/{conductor-EMGMDNHL.js → conductor-VGCXUUG6.js} +9 -8
  56. package/dist/connected-teams-2YDE2EZ2.js +1 -1
  57. package/dist/{coordinator-prompt-DLY3FS2L.js → coordinator-prompt-DPO7L2JO.js} +5 -5
  58. package/dist/{coordinator-prompt-WALVMGKI.js → coordinator-prompt-E736TJBS.js} +4 -4
  59. package/dist/{global-workspace-UG2A3CEM.js → global-workspace-4RDPAOTT.js} +5 -5
  60. package/dist/{global-workspace-7OQ5O6JT.js → global-workspace-TG2TVLUF.js} +4 -4
  61. package/dist/index.cjs +2881 -1761
  62. package/dist/index.d.cts +140 -877
  63. package/dist/index.d.ts +140 -877
  64. package/dist/index.js +865 -559
  65. package/dist/{linear-PKYJH4WK.js → linear-E3BX5PX5.js} +2 -2
  66. package/dist/{linear-MIJO6DCV.js → linear-WG23LBCX.js} +3 -3
  67. package/dist/{linear-list-JPQ27RXG.js → linear-list-OINZWVV5.js} +1 -1
  68. package/dist/{linear-list-N57PR6JM.js → linear-list-VU47BNUV.js} +1 -1
  69. package/dist/mcp/run-stdio.cjs +2112 -1287
  70. package/dist/mcp/run-stdio.js +318 -230
  71. package/dist/{optional-cli-4GTEDEYJ.js → optional-cli-K6HX2X5O.js} +4 -3
  72. package/dist/{optional-cli-RPJIQBDX.js → optional-cli-SA3EQYML.js} +6 -5
  73. package/dist/{orchestrator-KNOMW5CZ.js → orchestrator-3I2FLEZL.js} +20 -18
  74. package/dist/{orchestrator-4SXTORD2.js → orchestrator-QDHZ56LA.js} +12 -11
  75. package/dist/thread-CJRchYLj.d.cts +856 -0
  76. package/dist/thread-CJRchYLj.d.ts +856 -0
  77. package/dist/{thread-store-R3G5VBII.js → thread-store-4YTOV2HL.js} +3 -3
  78. package/dist/{thread-store-MEUWZDVV.js → thread-store-LME2ICZP.js} +2 -2
  79. package/dist/{workspaces-KWGTP7DI.js → workspaces-4PA24IX6.js} +4 -4
  80. package/dist/{workspaces-35T6FW57.js → workspaces-6TMYV4N2.js} +5 -5
  81. package/dist/{worktree-ROJXGBWS.js → worktree-4ATMCYIE.js} +3 -3
  82. package/dist/{worktree-5P7SCST3.js → worktree-DA6SKIU5.js} +4 -4
  83. package/package.json +3 -3
  84. /package/dist/{chunk-XOEKCE6L.js → chunk-OHXNGBC4.js} +0 -0
@@ -17,17 +17,17 @@ import {
17
17
  toAbleTimeIssueInfo,
18
18
  updateAbleTimeTask,
19
19
  verifyAbleTimeConnection
20
- } from "./chunk-RUIHNWRV.js";
20
+ } from "./chunk-37ZBEBP6.js";
21
+ import "./chunk-CCWQ65VD.js";
21
22
  import "./chunk-DBKHL7NC.js";
22
- import "./chunk-AJMERXZP.js";
23
- import "./chunk-FDYMVJFU.js";
23
+ import "./chunk-5WF54R3B.js";
24
24
  import "./chunk-JAT3JFOS.js";
25
25
  import "./chunk-6K64FJDD.js";
26
- import "./chunk-6WMNIX2U.js";
26
+ import "./chunk-UFUAIVNV.js";
27
+ import "./chunk-JT7R45JB.js";
27
28
  import "./chunk-4TR3HZFT.js";
28
29
  import "./chunk-WDRMZKVB.js";
29
30
  import "./chunk-KI45T4DI.js";
30
- import "./chunk-JT7R45JB.js";
31
31
  import "./chunk-H4UEFJRI.js";
32
32
  export {
33
33
  ableTimeDependencyTarget,
@@ -19,13 +19,13 @@ import {
19
19
  toAbleTimeIssueInfo,
20
20
  updateAbleTimeTask,
21
21
  verifyAbleTimeConnection
22
- } from "./chunk-62ALWH3T.js";
23
- import "./chunk-OHUAAX3O.js";
24
- import "./chunk-RYPD7XWV.js";
22
+ } from "./chunk-DL4OHDBV.js";
23
+ import "./chunk-M45WGODR.js";
24
+ import "./chunk-B4EFQTMP.js";
25
25
  import "./chunk-F6GE7V3Q.js";
26
26
  import "./chunk-N2WW62LF.js";
27
27
  import "./chunk-2GPQZZLY.js";
28
- import "./chunk-WWU4SYZR.js";
28
+ import "./chunk-VL6F2KRE.js";
29
29
  import "./chunk-NSTQ6QKD.js";
30
30
  import "./chunk-WWUABK6B.js";
31
31
  import "./chunk-FJZWM2ON.js";
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  DEFAULT_ABLETIME_HOST,
5
5
  normalizeAbleTimeHost
6
- } from "./chunk-RYPD7XWV.js";
6
+ } from "./chunk-B4EFQTMP.js";
7
7
  import {
8
8
  httpFetch
9
9
  } from "./chunk-2GPQZZLY.js";
@@ -12,7 +12,7 @@ import {
12
12
  getAbleTimeHost,
13
13
  loadAppSettings,
14
14
  saveAbleTimeConnection
15
- } from "./chunk-WWU4SYZR.js";
15
+ } from "./chunk-VL6F2KRE.js";
16
16
  import "./chunk-NSTQ6QKD.js";
17
17
  import "./chunk-WWUABK6B.js";
18
18
  import "./chunk-FJZWM2ON.js";
@@ -287,7 +287,7 @@ async function startAbleTimeOAuth(opts) {
287
287
  persistAbleTimeTokens(data, { host });
288
288
  const token = data.access_token.trim();
289
289
  try {
290
- const { getAbleTimeOrientation } = await import("./abletime-3HRWLQZJ.js");
290
+ const { getAbleTimeOrientation } = await import("./abletime-URSRZW7P.js");
291
291
  const orientation = await getAbleTimeOrientation({ token, host });
292
292
  return saveAbleTimeConnection({
293
293
  accessToken: token,
@@ -20,14 +20,14 @@ import {
20
20
  parseAbleTimeOAuthCallbackUrl,
21
21
  resolveAbleTimeOAuthHost,
22
22
  startAbleTimeOAuth
23
- } from "./chunk-CEQ4Z32M.js";
24
- import "./chunk-FDYMVJFU.js";
23
+ } from "./chunk-J4EA5SHF.js";
24
+ import "./chunk-5WF54R3B.js";
25
25
  import "./chunk-JAT3JFOS.js";
26
- import "./chunk-6WMNIX2U.js";
26
+ import "./chunk-UFUAIVNV.js";
27
+ import "./chunk-JT7R45JB.js";
27
28
  import "./chunk-4TR3HZFT.js";
28
29
  import "./chunk-WDRMZKVB.js";
29
30
  import "./chunk-KI45T4DI.js";
30
- import "./chunk-JT7R45JB.js";
31
31
  import "./chunk-H4UEFJRI.js";
32
32
  export {
33
33
  ABLETIME_OAUTH_CALLBACK_PATH,
@@ -7,10 +7,10 @@ import {
7
7
  callAbleTimeRestTool,
8
8
  looksLikeAbleTimeUlid,
9
9
  textFromAbleTimeDoc
10
- } from "./chunk-OHUAAX3O.js";
11
- import "./chunk-RYPD7XWV.js";
10
+ } from "./chunk-M45WGODR.js";
11
+ import "./chunk-B4EFQTMP.js";
12
12
  import "./chunk-2GPQZZLY.js";
13
- import "./chunk-WWU4SYZR.js";
13
+ import "./chunk-VL6F2KRE.js";
14
14
  import "./chunk-NSTQ6QKD.js";
15
15
  import "./chunk-WWUABK6B.js";
16
16
  import "./chunk-FJZWM2ON.js";
@@ -5,14 +5,14 @@ import {
5
5
  callAbleTimeRestTool,
6
6
  looksLikeAbleTimeUlid,
7
7
  textFromAbleTimeDoc
8
- } from "./chunk-AJMERXZP.js";
9
- import "./chunk-FDYMVJFU.js";
8
+ } from "./chunk-CCWQ65VD.js";
9
+ import "./chunk-5WF54R3B.js";
10
10
  import "./chunk-JAT3JFOS.js";
11
- import "./chunk-6WMNIX2U.js";
11
+ import "./chunk-UFUAIVNV.js";
12
+ import "./chunk-JT7R45JB.js";
12
13
  import "./chunk-4TR3HZFT.js";
13
14
  import "./chunk-WDRMZKVB.js";
14
15
  import "./chunk-KI45T4DI.js";
15
- import "./chunk-JT7R45JB.js";
16
16
  import "./chunk-H4UEFJRI.js";
17
17
  export {
18
18
  ABLETIME_REST_PREFIX,
@@ -0,0 +1,491 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/agents/acp-runner.ts
22
+ var acp_runner_exports = {};
23
+ __export(acp_runner_exports, {
24
+ runAcpTurn: () => runAcpTurn
25
+ });
26
+ module.exports = __toCommonJS(acp_runner_exports);
27
+ var import_node_child_process = require("child_process");
28
+ var import_node_readline = require("readline");
29
+ var import_node_path = require("path");
30
+
31
+ // src/agents/acp-protocol.ts
32
+ var ACP_PROTOCOL_VERSION = 1;
33
+ var ACP_REPLAY_CHAR_BUDGET = 16e3;
34
+ var PLAN_READ_TOOL_KINDS = /* @__PURE__ */ new Set(["read", "search", "think"]);
35
+ function acpSessionOpenPlan(input) {
36
+ if (input.loadSession && input.sessionId?.trim()) return "load";
37
+ return "new";
38
+ }
39
+ function buildAcpReplayPrompt(prior, prompt) {
40
+ if (prior.length === 0) return prompt;
41
+ const lines = prior.map((turn) => {
42
+ const who = turn.role === "user" ? "User" : turn.role === "agent" ? "Assistant" : "Note";
43
+ return `${who}:
44
+ ${turn.text}`;
45
+ });
46
+ let body = lines.join("\n\n");
47
+ if (body.length > ACP_REPLAY_CHAR_BUDGET) {
48
+ body = `\u2026(earlier turns omitted)
49
+
50
+ ${body.slice(body.length - ACP_REPLAY_CHAR_BUDGET)}`;
51
+ }
52
+ return [
53
+ "Previous conversation (this harness cannot load a saved session, so Sideboard replayed the transcript):",
54
+ body,
55
+ "Current request:",
56
+ prompt
57
+ ].join("\n\n");
58
+ }
59
+ function selectAcpPermissionOption(options, mode, toolKind) {
60
+ const allowAlways = options.find((option) => option.kind === "allow_always");
61
+ const allowOnce = options.find((option) => option.kind === "allow_once");
62
+ const rejectOnce = options.find((option) => option.kind === "reject_once");
63
+ const rejectAlways = options.find((option) => option.kind === "reject_always");
64
+ if (mode === "plan") {
65
+ if (toolKind && PLAN_READ_TOOL_KINDS.has(toolKind)) {
66
+ const allow2 = allowOnce ?? allowAlways;
67
+ if (allow2) return { outcome: "selected", optionId: allow2.optionId };
68
+ }
69
+ const reject2 = rejectOnce ?? rejectAlways;
70
+ if (reject2) return { outcome: "selected", optionId: reject2.optionId };
71
+ return { outcome: "cancelled" };
72
+ }
73
+ if (mode === "full") {
74
+ const allow2 = allowAlways ?? allowOnce;
75
+ if (allow2) return { outcome: "selected", optionId: allow2.optionId };
76
+ }
77
+ const allow = allowOnce ?? allowAlways;
78
+ if (allow) return { outcome: "selected", optionId: allow.optionId };
79
+ const reject = rejectOnce ?? rejectAlways;
80
+ if (reject) return { outcome: "selected", optionId: reject.optionId };
81
+ return { outcome: "cancelled" };
82
+ }
83
+ function clip(text, max = 8e3) {
84
+ if (text.length <= max) return text;
85
+ return `${text.slice(0, max)}
86
+ \u2026(${text.length - max} more characters)`;
87
+ }
88
+ function blockToText(block) {
89
+ if (!block || typeof block !== "object") return "";
90
+ const record = block;
91
+ if (record.type === "text" && typeof record.text === "string") return record.text;
92
+ if (typeof record.path === "string" && (record.type === "diff" || record.type === "resource")) {
93
+ return record.path;
94
+ }
95
+ return "";
96
+ }
97
+ function acpContentToText(content) {
98
+ if (typeof content === "string") return content;
99
+ const blocks = Array.isArray(content) ? content : content ? [content] : [];
100
+ return blocks.map(blockToText).filter(Boolean).join("\n");
101
+ }
102
+ function asRecord(value) {
103
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
104
+ return value;
105
+ }
106
+ function num(value) {
107
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
108
+ }
109
+ function acpUsageFromUnknown(value) {
110
+ const record = asRecord(value);
111
+ if (!record) return null;
112
+ const input = num(record.inputTokens ?? record.input_tokens);
113
+ const output = num(record.outputTokens ?? record.output_tokens);
114
+ if (input == null && output == null) return null;
115
+ const cacheRead = num(record.cacheReadTokens ?? record.cachedReadTokens ?? record.cached_read_tokens);
116
+ const cacheWrite = num(
117
+ record.cacheWriteTokens ?? record.cachedWriteTokens ?? record.cached_write_tokens
118
+ );
119
+ return {
120
+ inputTokens: input ?? 0,
121
+ outputTokens: output ?? 0,
122
+ ...cacheRead != null ? { cacheReadTokens: cacheRead } : {},
123
+ ...cacheWrite != null ? { cacheWriteTokens: cacheWrite } : {}
124
+ };
125
+ }
126
+ function toolInput(raw) {
127
+ const record = asRecord(raw);
128
+ return record ?? void 0;
129
+ }
130
+ function sessionUpdateToEvents(params) {
131
+ const root = asRecord(params);
132
+ const update = asRecord(root?.update) ?? root;
133
+ if (!update) return [];
134
+ const kind = typeof update.sessionUpdate === "string" ? update.sessionUpdate : "";
135
+ if (kind === "user_message_chunk") return [];
136
+ if (kind === "agent_message_chunk") {
137
+ const text = acpContentToText(update.content);
138
+ return text ? [{ type: "stdout", data: text }] : [];
139
+ }
140
+ if (kind === "agent_thought_chunk") {
141
+ const text = acpContentToText(update.content);
142
+ return text ? [{ type: "thinking", data: text }] : [];
143
+ }
144
+ if (kind === "plan") {
145
+ const entries = Array.isArray(update.entries) ? update.entries : [];
146
+ const text = entries.map((entry) => {
147
+ const record = asRecord(entry);
148
+ return typeof record?.content === "string" ? record.content : "";
149
+ }).filter(Boolean).join("\n");
150
+ return text ? [{ type: "thinking", data: text }] : [];
151
+ }
152
+ if (kind === "tool_call" || kind === "tool_call_update") {
153
+ const id = typeof update.toolCallId === "string" ? update.toolCallId : "";
154
+ if (!id) return [];
155
+ const name = typeof update.title === "string" && update.title || typeof update.kind === "string" && update.kind || "tool";
156
+ const status = typeof update.status === "string" ? update.status : "";
157
+ const content = clip(acpContentToText(update.content ?? update.rawOutput));
158
+ const events = [];
159
+ if (kind === "tool_call") {
160
+ events.push({
161
+ type: "tool_use",
162
+ id,
163
+ name,
164
+ ...toolInput(update.rawInput) ? { input: toolInput(update.rawInput) } : {}
165
+ });
166
+ }
167
+ if (status === "completed" || status === "failed" || kind === "tool_call_update" && content) {
168
+ events.push({
169
+ type: "tool_result",
170
+ id,
171
+ ...content ? { content } : {},
172
+ isError: status === "failed",
173
+ partial: status !== "completed" && status !== "failed"
174
+ });
175
+ }
176
+ return events;
177
+ }
178
+ return [];
179
+ }
180
+
181
+ // src/agents/acp-runner.ts
182
+ function emitLine(emit, event) {
183
+ emit(event);
184
+ }
185
+ function permissionMode(req) {
186
+ if (req.planMode) return "plan";
187
+ if (req.autonomy === "full") return "full";
188
+ return "default";
189
+ }
190
+ function asRecord2(value) {
191
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
192
+ return value;
193
+ }
194
+ var AcpConnection = class {
195
+ constructor(stdin, stdout, onRequest, onNotification) {
196
+ this.stdin = stdin;
197
+ this.onRequest = onRequest;
198
+ this.onNotification = onNotification;
199
+ stdout.setEncoding("utf8");
200
+ stdout.on("data", (chunk) => this.ingest(chunk));
201
+ stdout.on("end", () => {
202
+ this.failAll(new Error("ACP harness closed stdout"));
203
+ });
204
+ }
205
+ stdin;
206
+ onRequest;
207
+ onNotification;
208
+ nextId = 1;
209
+ pending = /* @__PURE__ */ new Map();
210
+ buffer = "";
211
+ ingest(chunk) {
212
+ this.buffer += chunk;
213
+ while (true) {
214
+ const nl = this.buffer.indexOf("\n");
215
+ if (nl < 0) break;
216
+ const line = this.buffer.slice(0, nl).replace(/\r$/, "").trim();
217
+ this.buffer = this.buffer.slice(nl + 1);
218
+ if (!line) continue;
219
+ let msg;
220
+ try {
221
+ msg = JSON.parse(line);
222
+ } catch {
223
+ continue;
224
+ }
225
+ void this.dispatch(msg);
226
+ }
227
+ }
228
+ async dispatch(msg) {
229
+ if (msg.method && (msg.id === void 0 || msg.id === null)) {
230
+ this.onNotification(msg.method, msg.params);
231
+ return;
232
+ }
233
+ if (msg.method && msg.id != null) {
234
+ try {
235
+ const result = await this.onRequest(msg.method, msg.params);
236
+ this.send({ jsonrpc: "2.0", id: msg.id, result });
237
+ } catch (err) {
238
+ const message = err instanceof Error ? err.message : String(err);
239
+ this.send({
240
+ jsonrpc: "2.0",
241
+ id: msg.id,
242
+ error: { code: -32603, message }
243
+ });
244
+ }
245
+ return;
246
+ }
247
+ if (msg.id == null) return;
248
+ const pending = this.pending.get(String(msg.id));
249
+ if (!pending) return;
250
+ this.pending.delete(String(msg.id));
251
+ if (msg.error) {
252
+ const data = asRecord2(msg.error.data);
253
+ const code = typeof data?.code === "string" ? data.code : "";
254
+ const message = msg.error.message || code || "ACP request failed";
255
+ pending.reject(new Error(code ? `${message} (${code})` : message));
256
+ return;
257
+ }
258
+ pending.resolve(msg.result);
259
+ }
260
+ request(method, params) {
261
+ const id = this.nextId++;
262
+ const promise = new Promise((resolve2, reject) => {
263
+ this.pending.set(String(id), { resolve: resolve2, reject });
264
+ });
265
+ this.send({ jsonrpc: "2.0", id, method, params });
266
+ return promise;
267
+ }
268
+ notify(method, params) {
269
+ this.send({ jsonrpc: "2.0", method, params });
270
+ }
271
+ send(value) {
272
+ this.stdin.write(`${JSON.stringify(value)}
273
+ `);
274
+ }
275
+ failAll(error) {
276
+ for (const pending of this.pending.values()) pending.reject(error);
277
+ this.pending.clear();
278
+ }
279
+ };
280
+ function permissionOptions(value) {
281
+ if (!Array.isArray(value)) return [];
282
+ const options = [];
283
+ for (const entry of value) {
284
+ const record = asRecord2(entry);
285
+ if (!record || typeof record.optionId !== "string" || typeof record.kind !== "string") continue;
286
+ options.push({
287
+ optionId: record.optionId,
288
+ kind: record.kind,
289
+ ...typeof record.name === "string" ? { name: record.name } : {}
290
+ });
291
+ }
292
+ return options;
293
+ }
294
+ async function readStdinJson() {
295
+ const rl = (0, import_node_readline.createInterface)({ input: process.stdin, crlfDelay: Infinity });
296
+ const chunks = [];
297
+ for await (const line of rl) chunks.push(line);
298
+ const raw = chunks.join("\n").trim();
299
+ if (!raw) throw new Error("acp-runner: empty stdin (expected JSON AcpTurnRequest)");
300
+ return JSON.parse(raw);
301
+ }
302
+ function exitWhenDone(child) {
303
+ return new Promise((resolveExit) => {
304
+ if (child.exitCode != null) {
305
+ resolveExit(child.exitCode);
306
+ return;
307
+ }
308
+ child.once("exit", (code) => resolveExit(code));
309
+ });
310
+ }
311
+ async function runAcpTurn(req, emit) {
312
+ if (!req.prompt?.trim()) {
313
+ emitLine(emit, { type: "stderr", data: "acp-runner: prompt is required" });
314
+ return 1;
315
+ }
316
+ if (!req.cwd?.trim() || !req.command?.trim()) {
317
+ emitLine(emit, { type: "stderr", data: "acp-runner: cwd and command are required" });
318
+ return 1;
319
+ }
320
+ const cwd = (0, import_node_path.resolve)(req.cwd);
321
+ const child = (0, import_node_child_process.spawn)(req.command, req.args ?? [], {
322
+ cwd,
323
+ env: { ...process.env, ...req.env },
324
+ stdio: ["pipe", "pipe", "pipe"]
325
+ });
326
+ child.stderr.setEncoding("utf8");
327
+ let stderrBuf = "";
328
+ child.stderr.on("data", (chunk) => {
329
+ stderrBuf += chunk;
330
+ while (stderrBuf.includes("\n")) {
331
+ const nl = stderrBuf.indexOf("\n");
332
+ const line = stderrBuf.slice(0, nl).replace(/\r$/, "");
333
+ stderrBuf = stderrBuf.slice(nl + 1);
334
+ if (line.trim()) emitLine(emit, { type: "stderr", data: line });
335
+ }
336
+ });
337
+ let suppressUpdates = false;
338
+ let sessionId = req.sessionId?.trim() || null;
339
+ const mode = permissionMode(req);
340
+ const mcpServers = req.mcpServers ?? [];
341
+ const conn = new AcpConnection(
342
+ child.stdin,
343
+ child.stdout,
344
+ async (method, params) => {
345
+ if (method === "session/request_permission") {
346
+ const record = asRecord2(params);
347
+ const tool = asRecord2(record?.toolCall);
348
+ const toolKind = typeof tool?.kind === "string" ? tool.kind : null;
349
+ const selected = selectAcpPermissionOption(permissionOptions(record?.options), mode, toolKind);
350
+ return { outcome: selected };
351
+ }
352
+ throw new Error(`ACP client method not implemented: ${method}`);
353
+ },
354
+ (method, params) => {
355
+ if (method !== "session/update" || suppressUpdates) return;
356
+ for (const event of sessionUpdateToEvents(params)) emitLine(emit, event);
357
+ }
358
+ );
359
+ let stopWatching = false;
360
+ const earlyFailure = new Promise((resolveExit) => {
361
+ child.once("error", (err) => {
362
+ if (stopWatching) return;
363
+ stopWatching = true;
364
+ emitLine(emit, { type: "stderr", data: err.message });
365
+ resolveExit(1);
366
+ });
367
+ child.once("exit", (code2) => {
368
+ if (stopWatching) return;
369
+ stopWatching = true;
370
+ emitLine(emit, {
371
+ type: "stderr",
372
+ data: `ACP harness exited (${code2 ?? "null"}) before the turn finished`
373
+ });
374
+ resolveExit(1);
375
+ });
376
+ });
377
+ const turn = (async () => {
378
+ const init = asRecord2(
379
+ await conn.request("initialize", {
380
+ protocolVersion: ACP_PROTOCOL_VERSION,
381
+ clientCapabilities: {
382
+ fs: { readTextFile: false, writeTextFile: false },
383
+ terminal: false
384
+ },
385
+ clientInfo: { name: "sideboard", version: "0" }
386
+ })
387
+ );
388
+ const capabilities = asRecord2(init?.agentCapabilities);
389
+ const loadSession = capabilities?.loadSession === true;
390
+ let loaded = false;
391
+ if (acpSessionOpenPlan({ loadSession, sessionId }) === "load" && sessionId) {
392
+ suppressUpdates = true;
393
+ try {
394
+ await conn.request("session/load", { sessionId, cwd, mcpServers });
395
+ loaded = true;
396
+ emitLine(emit, { type: "session_id", data: sessionId });
397
+ } catch (err) {
398
+ const message = err instanceof Error ? err.message : String(err);
399
+ emitLine(emit, {
400
+ type: "stderr",
401
+ data: `ACP session/load failed (${message}). Starting a new session and replaying the transcript.`
402
+ });
403
+ sessionId = null;
404
+ } finally {
405
+ suppressUpdates = false;
406
+ }
407
+ }
408
+ if (!loaded) {
409
+ const created = asRecord2(await conn.request("session/new", { cwd, mcpServers }));
410
+ const createdId = typeof created?.sessionId === "string" ? created.sessionId.trim() : "";
411
+ if (!createdId) throw new Error("ACP session/new did not return a sessionId");
412
+ sessionId = createdId;
413
+ emitLine(emit, { type: "session_id", data: createdId });
414
+ }
415
+ const text = loaded ? req.resumePrompt || req.prompt : buildAcpReplayPrompt(req.transcript ?? [], req.prompt);
416
+ const result = asRecord2(
417
+ await conn.request("session/prompt", {
418
+ sessionId,
419
+ prompt: [{ type: "text", text }]
420
+ })
421
+ );
422
+ const usage = acpUsageFromUnknown(result?.usage);
423
+ if (usage) emitLine(emit, { type: "usage", data: usage, scope: "turn" });
424
+ const stop = typeof result?.stopReason === "string" ? result.stopReason : "end_turn";
425
+ if (stop === "refusal" || stop === "cancelled") {
426
+ emitLine(emit, { type: "stderr", data: `ACP turn stopped: ${stop}` });
427
+ return 2;
428
+ }
429
+ if (stop !== "end_turn") {
430
+ emitLine(emit, { type: "stderr", data: `ACP stop reason: ${stop}` });
431
+ }
432
+ return 0;
433
+ })();
434
+ const settled = turn.then(
435
+ (value) => ({ ok: true, value }),
436
+ (err) => ({ ok: false, err })
437
+ );
438
+ const raced = await Promise.race([
439
+ settled.then((result) => {
440
+ stopWatching = true;
441
+ return result;
442
+ }),
443
+ earlyFailure.then((value) => ({ ok: true, value, early: true }))
444
+ ]);
445
+ const code = "early" in raced ? raced.value : raced.ok ? raced.value : 1;
446
+ if (!("early" in raced) && !raced.ok) {
447
+ const message = raced.err instanceof Error ? raced.err.message : String(raced.err);
448
+ emitLine(emit, { type: "stderr", data: message });
449
+ }
450
+ stopWatching = true;
451
+ if (code !== 0 && sessionId) {
452
+ try {
453
+ conn.notify("session/cancel", { sessionId });
454
+ } catch {
455
+ }
456
+ }
457
+ child.stdin.end();
458
+ const finished = exitWhenDone(child);
459
+ const timed = await Promise.race([
460
+ finished,
461
+ new Promise((resolveExit) => {
462
+ setTimeout(() => resolveExit(null), 3e3);
463
+ })
464
+ ]);
465
+ if (timed == null) child.kill("SIGTERM");
466
+ return code;
467
+ }
468
+ function isDirectRun() {
469
+ const argv1 = process.argv[1] ?? "";
470
+ const base = argv1.split(/[/\\]/).pop() ?? "";
471
+ return base === "acp-runner.ts" || base === "acp-runner.js" || base === "acp-runner.cjs";
472
+ }
473
+ if (isDirectRun()) {
474
+ readStdinJson().then(
475
+ (req) => runAcpTurn(req, (event) => {
476
+ process.stdout.write(`${JSON.stringify(event)}
477
+ `);
478
+ })
479
+ ).then((code) => {
480
+ process.exitCode = code;
481
+ }).catch((err) => {
482
+ const message = err instanceof Error ? err.message : String(err);
483
+ process.stdout.write(`${JSON.stringify({ type: "stderr", data: message })}
484
+ `);
485
+ process.exitCode = 1;
486
+ });
487
+ }
488
+ // Annotate the CommonJS export names for ESM import in node:
489
+ 0 && (module.exports = {
490
+ runAcpTurn
491
+ });
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ import { A as AcpHarnessId, a as AgentEvent } from '../thread-CJRchYLj.cjs';
3
+
4
+ /**
5
+ * Agent Client Protocol (JSON-RPC over stdio) helpers shared by the runner
6
+ * and tests. No process spawn here.
7
+ *
8
+ * Session resume: a harness is resumed only when `initialize` reports
9
+ * `loadSession`. Otherwise each turn is a new session and Sideboard replays
10
+ * the prior transcript into the prompt. The harness process does not stay
11
+ * alive between turns.
12
+ */
13
+
14
+ type AcpMcpServer = {
15
+ name: string;
16
+ command: string;
17
+ args: string[];
18
+ env: Array<{
19
+ name: string;
20
+ value: string;
21
+ }>;
22
+ };
23
+ type AcpTranscriptTurn = {
24
+ role: 'user' | 'agent' | 'summary';
25
+ text: string;
26
+ };
27
+
28
+ type AcpTurnRequest = {
29
+ prompt: string;
30
+ /** Prompt without the cached prefix. Used only after a successful session/load. */
31
+ resumePrompt: string;
32
+ transcript?: AcpTranscriptTurn[];
33
+ cwd: string;
34
+ sessionId?: string | null;
35
+ harness: AcpHarnessId;
36
+ command: string;
37
+ args: string[];
38
+ mcpServers?: AcpMcpServer[];
39
+ planMode?: boolean;
40
+ autonomy?: 'default' | 'full';
41
+ /** Extra env for the harness (tests). Inherited env is always passed through. */
42
+ env?: Record<string, string>;
43
+ };
44
+ declare function runAcpTurn(req: AcpTurnRequest, emit: (event: AgentEvent) => void): Promise<number>;
45
+
46
+ export { type AcpTurnRequest, runAcpTurn };