@sideboard-ai/core 0.1.261 → 0.1.263

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 (55) hide show
  1. package/dist/{abletime-OQ4PC52L.js → abletime-6AOJI2YZ.js} +4 -4
  2. package/dist/{abletime-CDGINDXG.js → abletime-U75ZGDIX.js} +5 -5
  3. package/dist/{abletime-oauth-KX2TDFTE.js → abletime-oauth-LOAHGG4X.js} +3 -3
  4. package/dist/{abletime-oauth-5A5EOH2A.js → abletime-oauth-TA2YDCYX.js} +4 -4
  5. package/dist/{abletime-rest-UEHOBLXD.js → abletime-rest-CTA5WV26.js} +4 -4
  6. package/dist/{abletime-rest-PUGKYTRR.js → abletime-rest-YZPFM6IY.js} +3 -3
  7. package/dist/agents/claude-runner.cjs +463 -0
  8. package/dist/agents/claude-runner.d.cts +1 -0
  9. package/dist/agents/claude-runner.d.ts +1 -0
  10. package/dist/agents/claude-runner.js +134 -0
  11. package/dist/agents/cursor-runner.cjs +388 -7
  12. package/dist/agents/cursor-runner.js +34 -7
  13. package/dist/{agents-J2P4KNEY.js → agents-3TUMFSMH.js} +10 -9
  14. package/dist/{agents-IKVUGW5H.js → agents-6FWDRVA2.js} +4 -4
  15. package/dist/{app-settings-OM7H64YM.js → app-settings-MVZPM6WW.js} +1 -1
  16. package/dist/{app-settings-VQEUCONM.js → app-settings-RKFFUIFQ.js} +2 -2
  17. package/dist/{chunk-6PFZ6XO7.js → chunk-2QUQH2SZ.js} +81 -6
  18. package/dist/{chunk-VIC6TDYT.js → chunk-36FOBJBF.js} +76 -3
  19. package/dist/{chunk-ABPNIYRS.js → chunk-3H7O27X2.js} +389 -102
  20. package/dist/{chunk-FSZ7YYFQ.js → chunk-4ALDX5IO.js} +5 -3
  21. package/dist/{chunk-5OKJDCBK.js → chunk-5PK53SAP.js} +5 -5
  22. package/dist/{chunk-U3AOJLH3.js → chunk-5ZPT5YAV.js} +8 -6
  23. package/dist/{chunk-YFTO7U2A.js → chunk-6YOXQVJ7.js} +3 -3
  24. package/dist/{chunk-J6ONZP74.js → chunk-6YY7XPPL.js} +5 -5
  25. package/dist/{chunk-WV7KJH2E.js → chunk-A5SAYFJ4.js} +1 -0
  26. package/dist/{chunk-B6XFBNYM.js → chunk-BOMSJUXW.js} +2 -2
  27. package/dist/{chunk-S7VDDJ34.js → chunk-CEOTK5GZ.js} +3 -3
  28. package/dist/{chunk-4F7J6UWD.js → chunk-EK3KVT7I.js} +515 -139
  29. package/dist/{chunk-HHEKVR6C.js → chunk-F5MFNUAA.js} +40 -2
  30. package/dist/{chunk-KVQX62XI.js → chunk-K7B25HO4.js} +3 -3
  31. package/dist/{chunk-JTNY5CK4.js → chunk-L5WGAIL2.js} +46 -46
  32. package/dist/chunk-NYBFYFK7.js +415 -0
  33. package/dist/{chunk-GIZQAOHZ.js → chunk-QX6QUZVD.js} +121 -91
  34. package/dist/{chunk-X2OTZ36G.js → chunk-RKPBIB2U.js} +52 -52
  35. package/dist/{chunk-W5PWGEKS.js → chunk-T3AYRQJZ.js} +107 -77
  36. package/dist/{chunk-D554YCHG.js → chunk-YKYEHDMX.js} +2 -2
  37. package/dist/connected-teams-RU6VATCM.js +1 -1
  38. package/dist/{coordinator-prompt-VQHQ3RIX.js → coordinator-prompt-HZCQZ6C5.js} +6 -6
  39. package/dist/{coordinator-prompt-TU6656OK.js → coordinator-prompt-J7DKHOCH.js} +3 -3
  40. package/dist/{global-workspace-PHF2MOGW.js → global-workspace-6LDUZ2NF.js} +3 -3
  41. package/dist/{global-workspace-47NZVA44.js → global-workspace-TI26K25J.js} +6 -6
  42. package/dist/index.cjs +1712 -721
  43. package/dist/index.d.cts +181 -41
  44. package/dist/index.d.ts +181 -41
  45. package/dist/index.js +693 -285
  46. package/dist/mcp/run-stdio.cjs +10469 -9896
  47. package/dist/mcp/run-stdio.js +193 -168
  48. package/dist/{orchestrator-VLTO5JBR.js → orchestrator-4JSG7BWC.js} +5 -5
  49. package/dist/{orchestrator-OCG4QVA5.js → orchestrator-5YU46YNS.js} +11 -10
  50. package/dist/{workspaces-I7TWFTJM.js → workspaces-QJ3XIPUJ.js} +6 -6
  51. package/dist/{workspaces-2XTDS7N2.js → workspaces-WOQHJFRQ.js} +3 -3
  52. package/dist/{worktree-DDDF3WHV.js → worktree-6U2FA5LO.js} +2 -2
  53. package/dist/{worktree-YASFE65H.js → worktree-KQA4ON2G.js} +5 -5
  54. package/package.json +4 -3
  55. /package/dist/{chunk-LDXSAVWO.js → chunk-GWFVCCJZ.js} +0 -0
@@ -17,11 +17,11 @@ import {
17
17
  toAbleTimeIssueInfo,
18
18
  updateAbleTimeTask,
19
19
  verifyAbleTimeConnection
20
- } from "./chunk-S7VDDJ34.js";
21
- import "./chunk-B6XFBNYM.js";
22
- import "./chunk-5OKJDCBK.js";
20
+ } from "./chunk-CEOTK5GZ.js";
21
+ import "./chunk-BOMSJUXW.js";
22
+ import "./chunk-5PK53SAP.js";
23
23
  import "./chunk-VKQGAWHY.js";
24
- import "./chunk-VIC6TDYT.js";
24
+ import "./chunk-36FOBJBF.js";
25
25
  import "./chunk-NSTQ6QKD.js";
26
26
  import "./chunk-WWUABK6B.js";
27
27
  import "./chunk-FJZWM2ON.js";
@@ -15,16 +15,16 @@ import {
15
15
  toAbleTimeIssueInfo,
16
16
  updateAbleTimeTask,
17
17
  verifyAbleTimeConnection
18
- } from "./chunk-KVQX62XI.js";
19
- import "./chunk-D554YCHG.js";
20
- import "./chunk-J6ONZP74.js";
18
+ } from "./chunk-K7B25HO4.js";
19
+ import "./chunk-YKYEHDMX.js";
20
+ import "./chunk-6YY7XPPL.js";
21
21
  import "./chunk-N7WZ6NIN.js";
22
- import "./chunk-6PFZ6XO7.js";
22
+ import "./chunk-2QUQH2SZ.js";
23
+ import "./chunk-77WWLBCI.js";
23
24
  import "./chunk-4TR3HZFT.js";
24
25
  import "./chunk-WDRMZKVB.js";
25
26
  import "./chunk-3HO2OY5T.js";
26
27
  import "./chunk-JT7R45JB.js";
27
- import "./chunk-77WWLBCI.js";
28
28
  import "./chunk-EHT2DRT4.js";
29
29
  export {
30
30
  ableTimeDependencyTarget,
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  DEFAULT_ABLETIME_HOST,
5
5
  normalizeAbleTimeHost
6
- } from "./chunk-5OKJDCBK.js";
6
+ } from "./chunk-5PK53SAP.js";
7
7
  import {
8
8
  httpFetch
9
9
  } from "./chunk-VKQGAWHY.js";
@@ -12,7 +12,7 @@ import {
12
12
  getAbleTimeHost,
13
13
  loadAppSettings,
14
14
  saveAbleTimeConnection
15
- } from "./chunk-VIC6TDYT.js";
15
+ } from "./chunk-36FOBJBF.js";
16
16
  import "./chunk-NSTQ6QKD.js";
17
17
  import "./chunk-WWUABK6B.js";
18
18
  import "./chunk-FJZWM2ON.js";
@@ -288,7 +288,7 @@ async function startAbleTimeOAuth(opts) {
288
288
  persistAbleTimeTokens(data, { host });
289
289
  const token = data.access_token.trim();
290
290
  try {
291
- const { getAbleTimeOrientation } = await import("./abletime-OQ4PC52L.js");
291
+ const { getAbleTimeOrientation } = await import("./abletime-6AOJI2YZ.js");
292
292
  const orientation = await getAbleTimeOrientation({ token, host });
293
293
  return saveAbleTimeConnection({
294
294
  accessToken: token,
@@ -20,15 +20,15 @@ import {
20
20
  parseAbleTimeOAuthCallbackUrl,
21
21
  resolveAbleTimeOAuthHost,
22
22
  startAbleTimeOAuth
23
- } from "./chunk-YFTO7U2A.js";
24
- import "./chunk-J6ONZP74.js";
23
+ } from "./chunk-6YOXQVJ7.js";
24
+ import "./chunk-6YY7XPPL.js";
25
25
  import "./chunk-N7WZ6NIN.js";
26
- import "./chunk-6PFZ6XO7.js";
26
+ import "./chunk-2QUQH2SZ.js";
27
+ import "./chunk-77WWLBCI.js";
27
28
  import "./chunk-4TR3HZFT.js";
28
29
  import "./chunk-WDRMZKVB.js";
29
30
  import "./chunk-3HO2OY5T.js";
30
31
  import "./chunk-JT7R45JB.js";
31
- import "./chunk-77WWLBCI.js";
32
32
  import "./chunk-EHT2DRT4.js";
33
33
  export {
34
34
  ABLETIME_OAUTH_CALLBACK_PATH,
@@ -5,15 +5,15 @@ import {
5
5
  callAbleTimeRestTool,
6
6
  looksLikeAbleTimeUlid,
7
7
  textFromAbleTimeDoc
8
- } from "./chunk-D554YCHG.js";
9
- import "./chunk-J6ONZP74.js";
8
+ } from "./chunk-YKYEHDMX.js";
9
+ import "./chunk-6YY7XPPL.js";
10
10
  import "./chunk-N7WZ6NIN.js";
11
- import "./chunk-6PFZ6XO7.js";
11
+ import "./chunk-2QUQH2SZ.js";
12
+ import "./chunk-77WWLBCI.js";
12
13
  import "./chunk-4TR3HZFT.js";
13
14
  import "./chunk-WDRMZKVB.js";
14
15
  import "./chunk-3HO2OY5T.js";
15
16
  import "./chunk-JT7R45JB.js";
16
- import "./chunk-77WWLBCI.js";
17
17
  import "./chunk-EHT2DRT4.js";
18
18
  export {
19
19
  ABLETIME_REST_PREFIX,
@@ -7,10 +7,10 @@ import {
7
7
  callAbleTimeRestTool,
8
8
  looksLikeAbleTimeUlid,
9
9
  textFromAbleTimeDoc
10
- } from "./chunk-B6XFBNYM.js";
11
- import "./chunk-5OKJDCBK.js";
10
+ } from "./chunk-BOMSJUXW.js";
11
+ import "./chunk-5PK53SAP.js";
12
12
  import "./chunk-VKQGAWHY.js";
13
- import "./chunk-VIC6TDYT.js";
13
+ import "./chunk-36FOBJBF.js";
14
14
  import "./chunk-NSTQ6QKD.js";
15
15
  import "./chunk-WWUABK6B.js";
16
16
  import "./chunk-FJZWM2ON.js";
@@ -0,0 +1,463 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/agents/claude-runner.ts
27
+ var import_node_readline2 = require("readline");
28
+
29
+ // src/agent-rpc/protocol.ts
30
+ var AGENT_RPC_PROTOCOL_VERSION = 1;
31
+ var AGENT_RPC_TOKEN_QUERY = "authToken";
32
+ var AGENT_RPC_CLAUDE_SDK_SERVER = "sideboard_rpc";
33
+ function isJsonRpcNotification(value) {
34
+ if (!value || typeof value !== "object") return false;
35
+ const rec = value;
36
+ if (rec.jsonrpc !== "2.0") return false;
37
+ if (typeof rec.method !== "string" || !rec.method.trim()) return false;
38
+ if ("id" in rec && rec.id !== void 0) return false;
39
+ if ("error" in rec || "result" in rec) return false;
40
+ return true;
41
+ }
42
+ function parseRpcFrame(raw) {
43
+ try {
44
+ return JSON.parse(raw);
45
+ } catch {
46
+ return void 0;
47
+ }
48
+ }
49
+
50
+ // src/hook/nested-electron-env.ts
51
+ var NESTED_ELECTRON_ENV_PREFIXES = ["ELECTRON_", "CHROME_"];
52
+ function isNestedElectronEnvKey(key) {
53
+ return NESTED_ELECTRON_ENV_PREFIXES.some((prefix) => key.startsWith(prefix));
54
+ }
55
+ function dropNestedElectronEnvFromProcess(env = process.env) {
56
+ for (const key of Object.keys(env)) {
57
+ if (isNestedElectronEnvKey(key)) delete env[key];
58
+ }
59
+ }
60
+ var STRIP_NESTED_ELECTRON_THEN_EXEC = [
61
+ "vars=`printenv | awk -F= '/^(ELECTRON_|CHROME_)/{print $1}'`",
62
+ '[ -n "$vars" ] && unset $vars',
63
+ "export ELECTRON_RUN_AS_NODE=1",
64
+ 'exec "$@"'
65
+ ].join("; ");
66
+
67
+ // src/agents/claude-sdk-tools.ts
68
+ var import_zod = require("zod");
69
+
70
+ // src/agent-rpc/client.ts
71
+ var import_ws = require("ws");
72
+
73
+ // src/agent-rpc/metadata.ts
74
+ var import_node_fs6 = require("fs");
75
+ var import_node_path7 = require("path");
76
+
77
+ // src/store/paths.ts
78
+ var import_node_path5 = require("path");
79
+ var import_node_os2 = require("os");
80
+ var import_node_path6 = require("path");
81
+ var import_node_fs5 = require("fs");
82
+
83
+ // src/hook/settings.ts
84
+ var import_node_fs4 = require("fs");
85
+ var import_node_os = require("os");
86
+ var import_node_path4 = require("path");
87
+ var import_smol_toml = require("smol-toml");
88
+
89
+ // src/hook/convention-setup.ts
90
+ var import_node_fs = require("fs");
91
+ var import_node_path = require("path");
92
+
93
+ // src/hook/cursor-worktrees.ts
94
+ var import_node_fs2 = require("fs");
95
+ var import_node_path2 = require("path");
96
+ var import_execa = require("execa");
97
+ var import_node_readline = require("readline");
98
+
99
+ // src/hook/dev-preview.ts
100
+ var import_node_fs3 = require("fs");
101
+ var import_node_path3 = require("path");
102
+
103
+ // src/store/paths.ts
104
+ function appDataDir() {
105
+ const override = process.env.SIDEBOARD_APP_DATA?.trim();
106
+ const base = override ? override : process.platform === "darwin" ? (0, import_node_path6.join)((0, import_node_os2.homedir)(), "Library", "Application Support", "sideboard") : process.platform === "win32" ? (0, import_node_path6.join)(process.env.APPDATA ?? (0, import_node_path6.join)((0, import_node_os2.homedir)(), "AppData", "Roaming"), "sideboard") : (0, import_node_path6.join)((0, import_node_os2.homedir)(), ".local", "share", "sideboard");
107
+ (0, import_node_fs5.mkdirSync)(base, { recursive: true });
108
+ return base;
109
+ }
110
+
111
+ // src/agent-rpc/metadata.ts
112
+ function agentRuntimeMetadataPath() {
113
+ return (0, import_node_path7.join)(appDataDir(), "agent-runtime.json");
114
+ }
115
+ function readAgentRuntimeMetadata() {
116
+ try {
117
+ const raw = JSON.parse((0, import_node_fs6.readFileSync)(agentRuntimeMetadataPath(), "utf8"));
118
+ if (!raw || typeof raw !== "object") return null;
119
+ const rec = raw;
120
+ if (typeof rec.runtimeId !== "string" || !rec.runtimeId.trim()) return null;
121
+ if (typeof rec.authToken !== "string" || !rec.authToken.trim()) return null;
122
+ const pid = Number(rec.pid);
123
+ if (!Number.isInteger(pid) || pid <= 0) return null;
124
+ const transports = Array.isArray(rec.transports) ? rec.transports : [];
125
+ const ws = transports.filter((t) => {
126
+ if (!t || typeof t !== "object") return false;
127
+ const row = t;
128
+ return row.kind === "websocket" && typeof row.url === "string" && Boolean(row.url.trim());
129
+ });
130
+ return {
131
+ runtimeId: rec.runtimeId.trim(),
132
+ pid,
133
+ protocolVersion: Number(rec.protocolVersion) || AGENT_RPC_PROTOCOL_VERSION,
134
+ authToken: rec.authToken,
135
+ startedAt: Number(rec.startedAt) || 0,
136
+ transports: ws
137
+ };
138
+ } catch {
139
+ return null;
140
+ }
141
+ }
142
+ function websocketUrlFromMetadata(meta) {
143
+ const url = meta?.transports.find((t) => t.kind === "websocket")?.url?.trim();
144
+ return url || null;
145
+ }
146
+ function agentRpcConnectFromMetadata(meta = readAgentRuntimeMetadata()) {
147
+ if (!agentRuntimeLooksLive(meta)) return null;
148
+ const url = websocketUrlFromMetadata(meta);
149
+ const authToken = meta?.authToken;
150
+ if (!url || !authToken) return null;
151
+ return { url, authToken };
152
+ }
153
+ function pidAlive(pid) {
154
+ try {
155
+ process.kill(pid, 0);
156
+ return true;
157
+ } catch {
158
+ return false;
159
+ }
160
+ }
161
+ function agentRuntimeLooksLive(meta = readAgentRuntimeMetadata()) {
162
+ if (!meta) return false;
163
+ return pidAlive(meta.pid);
164
+ }
165
+
166
+ // src/agent-rpc/client.ts
167
+ var AgentRpcClient = class {
168
+ ws = null;
169
+ pending = /* @__PURE__ */ new Map();
170
+ nextId = 1;
171
+ url;
172
+ authToken;
173
+ notifyListeners = /* @__PURE__ */ new Set();
174
+ constructor(opts = {}) {
175
+ const connect = opts.url && opts.authToken ? { url: opts.url, authToken: opts.authToken } : agentRpcConnectFromMetadata();
176
+ if (!connect) throw new Error("Agent RPC runtime is not running (no live agent-runtime.json)");
177
+ this.url = connect.url;
178
+ this.authToken = connect.authToken;
179
+ }
180
+ onNotify(fn) {
181
+ this.notifyListeners.add(fn);
182
+ return () => this.notifyListeners.delete(fn);
183
+ }
184
+ async call(method, params) {
185
+ const ws = await this.ensureSocket();
186
+ const id = this.nextId;
187
+ this.nextId += 1;
188
+ const key = String(id);
189
+ const payload = {
190
+ jsonrpc: "2.0",
191
+ id,
192
+ method,
193
+ params,
194
+ authToken: this.authToken
195
+ };
196
+ return new Promise((resolve, reject) => {
197
+ this.pending.set(key, { resolve, reject });
198
+ try {
199
+ ws.send(JSON.stringify(payload));
200
+ } catch (err) {
201
+ this.pending.delete(key);
202
+ reject(err instanceof Error ? err : new Error(String(err)));
203
+ }
204
+ });
205
+ }
206
+ socketUrl() {
207
+ const url = new URL(this.url);
208
+ url.searchParams.set(AGENT_RPC_TOKEN_QUERY, this.authToken);
209
+ return url.toString();
210
+ }
211
+ async ensureSocket() {
212
+ if (this.ws && this.ws.readyState === import_ws.WebSocket.OPEN) return this.ws;
213
+ const ws = new import_ws.WebSocket(this.socketUrl());
214
+ this.ws = ws;
215
+ ws.on("message", (data) => this.onFrame(data.toString()));
216
+ ws.on("error", (err) => this.drop(ws, err));
217
+ ws.on("close", () => this.drop(ws, new Error("Agent RPC socket closed")));
218
+ ws.on("unexpected-response", (_req, res) => {
219
+ res.resume();
220
+ this.drop(
221
+ ws,
222
+ new Error(
223
+ res.statusCode === 401 ? "Unauthorized" : `Unexpected server response: ${res.statusCode}`
224
+ )
225
+ );
226
+ });
227
+ await new Promise((resolve, reject) => {
228
+ const fail = (err) => {
229
+ const message = err.message.includes("401") ? "Unauthorized" : err.message;
230
+ reject(message === err.message ? err : new Error(message));
231
+ };
232
+ ws.once("unexpected-response", (_req, res) => {
233
+ fail(
234
+ new Error(
235
+ res.statusCode === 401 ? "Unauthorized" : `Unexpected server response: ${res.statusCode}`
236
+ )
237
+ );
238
+ });
239
+ ws.once("error", fail);
240
+ ws.once("open", () => {
241
+ ws.off("error", fail);
242
+ resolve();
243
+ });
244
+ });
245
+ return ws;
246
+ }
247
+ drop(ws, err) {
248
+ if (this.ws === ws) this.ws = null;
249
+ if (this.pending.size === 0) return;
250
+ this.failAll(err);
251
+ }
252
+ onFrame(raw) {
253
+ const parsed = parseRpcFrame(raw);
254
+ if (parsed === void 0) return;
255
+ if (isJsonRpcNotification(parsed)) {
256
+ for (const fn of this.notifyListeners) fn(parsed);
257
+ return;
258
+ }
259
+ if (!parsed || typeof parsed !== "object") return;
260
+ const rec = parsed;
261
+ if (rec.id === void 0 || rec.id === null) return;
262
+ const key = String(rec.id);
263
+ const waiter = this.pending.get(key);
264
+ if (!waiter) return;
265
+ this.pending.delete(key);
266
+ if (rec.error && typeof rec.error === "object") {
267
+ const err = rec.error;
268
+ waiter.reject(new Error(err.message || "Agent RPC error"));
269
+ return;
270
+ }
271
+ waiter.resolve(rec.result);
272
+ }
273
+ failAll(err) {
274
+ for (const waiter of this.pending.values()) waiter.reject(err);
275
+ this.pending.clear();
276
+ }
277
+ close() {
278
+ const ws = this.ws;
279
+ this.ws = null;
280
+ this.failAll(new Error("Agent RPC client closed"));
281
+ if (ws) {
282
+ try {
283
+ ws.close();
284
+ } catch {
285
+ }
286
+ }
287
+ }
288
+ };
289
+
290
+ // src/agent-rpc/pilot-tools.ts
291
+ var PILOT_TOOL_DESCRIPTIONS = {
292
+ present_artifact: "Show a document or live log in Sideboard\u2019s side column. For html/svg/markdown/react, pass the FULL document and do not also fence that same body in chat. For type=log, pass only NEW lines (same artifact_id appends). Prefer type=log for long-running job output \u2014 do not resend HTML. type=react is a single default-export component (JSX/TSX); only react/react-dom imports.",
293
+ wait_for_job: "Wait until a detached long job (tests, pack, deploy, connector CLI) finishes. This call stays open for up to ~2 minutes. stillRunning true means the runtime hit the max hold; call wait_for_job again immediately. If the job is hanging, producing no useful output, or doing the wrong thing, call stop_job instead. Do not end the turn or tell the user you will let them know later.",
294
+ stop_job: "Stop a detached job you started with detached-job.cjs when it is hanging, producing no useful output, buffering forever, or doing the wrong thing (wrong project, infinite watch, huge dump). Do not stop a pack/test/deploy that is clearly making progress."
295
+ };
296
+ function jsonToolResult(value) {
297
+ return JSON.stringify(value);
298
+ }
299
+ function jsonToolError(err) {
300
+ const message = err instanceof Error ? err.message : String(err);
301
+ return jsonToolResult({ ok: false, error: message });
302
+ }
303
+ function createPilotRpcExecutors(opts) {
304
+ const client = new AgentRpcClient(opts.rpc);
305
+ let waitToolCallId;
306
+ if (opts.onProgress) {
307
+ const onProgress = opts.onProgress;
308
+ client.onNotify((msg) => {
309
+ if (msg.method === "runtime.progress") onProgress(msg.params, waitToolCallId);
310
+ });
311
+ }
312
+ const call = async (method, args) => {
313
+ try {
314
+ return jsonToolResult(await client.call(method, args));
315
+ } catch (err) {
316
+ return jsonToolError(err);
317
+ }
318
+ };
319
+ const callJob = (method, args) => call(method, { ...args, cwd: opts.cwd });
320
+ return {
321
+ present_artifact: (args) => call("ui.presentArtifact", args),
322
+ wait_for_job: async (args, context) => {
323
+ const prev = waitToolCallId;
324
+ waitToolCallId = typeof context?.toolCallId === "string" ? context.toolCallId : void 0;
325
+ try {
326
+ return await callJob("job.wait", args);
327
+ } finally {
328
+ waitToolCallId = prev;
329
+ }
330
+ },
331
+ stop_job: (args) => callJob("job.stop", args),
332
+ wait_for_turn: async (args, context) => {
333
+ const prev = waitToolCallId;
334
+ waitToolCallId = typeof context?.toolCallId === "string" ? context.toolCallId : void 0;
335
+ try {
336
+ return await call("turn.wait", args);
337
+ } finally {
338
+ waitToolCallId = prev;
339
+ }
340
+ },
341
+ close: () => client.close()
342
+ };
343
+ }
344
+
345
+ // src/agents/claude-sdk-tools.ts
346
+ function textResult(text) {
347
+ return { content: [{ type: "text", text }] };
348
+ }
349
+ function createClaudePilotSdkServer(createSdkMcpServer, tool, opts) {
350
+ const exec = createPilotRpcExecutors(opts);
351
+ const server = createSdkMcpServer({
352
+ name: AGENT_RPC_CLAUDE_SDK_SERVER,
353
+ version: "1.0.0",
354
+ timeout: 18e4,
355
+ tools: [
356
+ tool(
357
+ "present_artifact",
358
+ PILOT_TOOL_DESCRIPTIONS.present_artifact,
359
+ {
360
+ title: import_zod.z.string(),
361
+ type: import_zod.z.enum(["html", "svg", "markdown", "react", "log"]),
362
+ content: import_zod.z.string(),
363
+ artifact_id: import_zod.z.string().optional(),
364
+ status: import_zod.z.enum(["running", "ok", "failed", "idle"]).optional(),
365
+ phase: import_zod.z.string().optional(),
366
+ mode: import_zod.z.enum(["append", "replace"]).optional()
367
+ },
368
+ async (args) => textResult(await exec.present_artifact(args))
369
+ ),
370
+ tool(
371
+ "wait_for_job",
372
+ PILOT_TOOL_DESCRIPTIONS.wait_for_job,
373
+ { id: import_zod.z.string() },
374
+ async (args) => textResult(await exec.wait_for_job(args))
375
+ ),
376
+ tool(
377
+ "stop_job",
378
+ PILOT_TOOL_DESCRIPTIONS.stop_job,
379
+ { id: import_zod.z.string(), reason: import_zod.z.string().optional() },
380
+ async (args) => textResult(await exec.stop_job(args))
381
+ )
382
+ ]
383
+ });
384
+ return { server, exec };
385
+ }
386
+
387
+ // src/agents/claude-runner.ts
388
+ dropNestedElectronEnvFromProcess();
389
+ function emit(value) {
390
+ process.stdout.write(`${JSON.stringify(value)}
391
+ `);
392
+ }
393
+ async function readStdin() {
394
+ const rl = (0, import_node_readline2.createInterface)({ input: process.stdin, crlfDelay: Infinity });
395
+ const chunks = [];
396
+ for await (const line of rl) chunks.push(line);
397
+ return chunks.join("\n").trim();
398
+ }
399
+ async function main() {
400
+ const raw = await readStdin();
401
+ if (!raw) {
402
+ emit({ type: "stderr", data: "claude-runner: empty stdin" });
403
+ process.exitCode = 1;
404
+ return;
405
+ }
406
+ const req = JSON.parse(raw);
407
+ if (!req.prompt || !req.cwd || !req.agentRpc || !req.claudePath) {
408
+ emit({ type: "stderr", data: "claude-runner: prompt, cwd, claudePath, and agentRpc are required" });
409
+ process.exitCode = 1;
410
+ return;
411
+ }
412
+ let sdk;
413
+ try {
414
+ sdk = await import("@anthropic-ai/claude-agent-sdk");
415
+ } catch (err) {
416
+ const message = err instanceof Error ? err.message : String(err);
417
+ emit({
418
+ type: "stderr",
419
+ data: `claude-runner: @anthropic-ai/claude-agent-sdk is required (${message})`
420
+ });
421
+ process.exitCode = 1;
422
+ return;
423
+ }
424
+ const { server, exec } = createClaudePilotSdkServer(
425
+ sdk.createSdkMcpServer,
426
+ sdk.tool,
427
+ { cwd: req.cwd, rpc: req.agentRpc }
428
+ );
429
+ const mcpServers = {
430
+ [AGENT_RPC_CLAUDE_SDK_SERVER]: server
431
+ };
432
+ for (const [name, spec] of Object.entries(req.mcpServers ?? {})) {
433
+ mcpServers[name] = spec;
434
+ }
435
+ try {
436
+ const options = {
437
+ cwd: req.cwd,
438
+ pathToClaudeCodeExecutable: req.claudePath,
439
+ permissionMode: req.permissionMode,
440
+ allowedTools: req.allowedTools,
441
+ mcpServers,
442
+ includePartialMessages: true
443
+ };
444
+ if (req.sessionId) options.resume = req.sessionId;
445
+ if (req.model) options.model = req.model;
446
+ if (req.systemPrompt) options.appendSystemPrompt = req.systemPrompt;
447
+ if (req.effort) options.effort = req.effort;
448
+ if (req.chrome) options.chrome = true;
449
+ options.settingSources = [];
450
+ for await (const message of sdk.query({ prompt: req.prompt, options })) {
451
+ emit(message);
452
+ }
453
+ } finally {
454
+ exec.close();
455
+ }
456
+ }
457
+ main().catch((err) => {
458
+ emit({
459
+ type: "stderr",
460
+ data: err instanceof Error ? err.message : String(err)
461
+ });
462
+ process.exitCode = 1;
463
+ });
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node