swellai 1.0.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 (130) hide show
  1. package/README.md +711 -0
  2. package/dist/agents/linear-agent.d.ts +32 -0
  3. package/dist/agents/linear-agent.d.ts.map +1 -0
  4. package/dist/agents/linear-agent.js +263 -0
  5. package/dist/agents/linear-agent.js.map +1 -0
  6. package/dist/agents/planning-agent.d.ts +36 -0
  7. package/dist/agents/planning-agent.d.ts.map +1 -0
  8. package/dist/agents/planning-agent.js +248 -0
  9. package/dist/agents/planning-agent.js.map +1 -0
  10. package/dist/cli/index.d.ts +3 -0
  11. package/dist/cli/index.d.ts.map +1 -0
  12. package/dist/cli/index.js +102 -0
  13. package/dist/cli/index.js.map +1 -0
  14. package/dist/cli/install.d.ts +11 -0
  15. package/dist/cli/install.d.ts.map +1 -0
  16. package/dist/cli/install.js +257 -0
  17. package/dist/cli/install.js.map +1 -0
  18. package/dist/cli/manifest.d.ts +27 -0
  19. package/dist/cli/manifest.d.ts.map +1 -0
  20. package/dist/cli/manifest.js +65 -0
  21. package/dist/cli/manifest.js.map +1 -0
  22. package/dist/index.d.ts +17 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +17 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/lib/claude-agent-sdk.d.ts +73 -0
  27. package/dist/lib/claude-agent-sdk.d.ts.map +1 -0
  28. package/dist/lib/claude-agent-sdk.js +114 -0
  29. package/dist/lib/claude-agent-sdk.js.map +1 -0
  30. package/dist/lib/conversation-logger.d.ts +66 -0
  31. package/dist/lib/conversation-logger.d.ts.map +1 -0
  32. package/dist/lib/conversation-logger.js +159 -0
  33. package/dist/lib/conversation-logger.js.map +1 -0
  34. package/dist/lib/opencode.d.ts +68 -0
  35. package/dist/lib/opencode.d.ts.map +1 -0
  36. package/dist/lib/opencode.js +151 -0
  37. package/dist/lib/opencode.js.map +1 -0
  38. package/dist/lib/turso-schema.d.ts +13 -0
  39. package/dist/lib/turso-schema.d.ts.map +1 -0
  40. package/dist/lib/turso-schema.js +69 -0
  41. package/dist/lib/turso-schema.js.map +1 -0
  42. package/dist/lib/turso.d.ts +56 -0
  43. package/dist/lib/turso.d.ts.map +1 -0
  44. package/dist/lib/turso.js +144 -0
  45. package/dist/lib/turso.js.map +1 -0
  46. package/dist/lib/types.d.ts +31 -0
  47. package/dist/lib/types.d.ts.map +1 -0
  48. package/dist/lib/types.js +20 -0
  49. package/dist/lib/types.js.map +1 -0
  50. package/dist/lib/utils.d.ts +34 -0
  51. package/dist/lib/utils.d.ts.map +1 -0
  52. package/dist/lib/utils.js +72 -0
  53. package/dist/lib/utils.js.map +1 -0
  54. package/dist/scripts/build-templates.d.ts +17 -0
  55. package/dist/scripts/build-templates.d.ts.map +1 -0
  56. package/dist/scripts/build-templates.js +132 -0
  57. package/dist/scripts/build-templates.js.map +1 -0
  58. package/dist/scripts/claude-agent-runner.d.ts +28 -0
  59. package/dist/scripts/claude-agent-runner.d.ts.map +1 -0
  60. package/dist/scripts/claude-agent-runner.js +278 -0
  61. package/dist/scripts/claude-agent-runner.js.map +1 -0
  62. package/dist/src/agents/linear-agent.d.ts +32 -0
  63. package/dist/src/agents/linear-agent.d.ts.map +1 -0
  64. package/dist/src/agents/linear-agent.js +285 -0
  65. package/dist/src/agents/linear-agent.js.map +1 -0
  66. package/dist/src/agents/planning-agent.d.ts +36 -0
  67. package/dist/src/agents/planning-agent.d.ts.map +1 -0
  68. package/dist/src/agents/planning-agent.js +248 -0
  69. package/dist/src/agents/planning-agent.js.map +1 -0
  70. package/dist/src/cli/index.d.ts +3 -0
  71. package/dist/src/cli/index.d.ts.map +1 -0
  72. package/dist/src/cli/index.js +102 -0
  73. package/dist/src/cli/index.js.map +1 -0
  74. package/dist/src/cli/install.d.ts +11 -0
  75. package/dist/src/cli/install.d.ts.map +1 -0
  76. package/dist/src/cli/install.js +257 -0
  77. package/dist/src/cli/install.js.map +1 -0
  78. package/dist/src/cli/manifest.d.ts +27 -0
  79. package/dist/src/cli/manifest.d.ts.map +1 -0
  80. package/dist/src/cli/manifest.js +65 -0
  81. package/dist/src/cli/manifest.js.map +1 -0
  82. package/dist/src/index.d.ts +17 -0
  83. package/dist/src/index.d.ts.map +1 -0
  84. package/dist/src/index.js +17 -0
  85. package/dist/src/index.js.map +1 -0
  86. package/dist/src/lib/claude-agent-sdk.d.ts +73 -0
  87. package/dist/src/lib/claude-agent-sdk.d.ts.map +1 -0
  88. package/dist/src/lib/claude-agent-sdk.js +114 -0
  89. package/dist/src/lib/claude-agent-sdk.js.map +1 -0
  90. package/dist/src/lib/conversation-logger.d.ts +66 -0
  91. package/dist/src/lib/conversation-logger.d.ts.map +1 -0
  92. package/dist/src/lib/conversation-logger.js +159 -0
  93. package/dist/src/lib/conversation-logger.js.map +1 -0
  94. package/dist/src/lib/opencode.d.ts +153 -0
  95. package/dist/src/lib/opencode.d.ts.map +1 -0
  96. package/dist/src/lib/opencode.js +153 -0
  97. package/dist/src/lib/opencode.js.map +1 -0
  98. package/dist/src/lib/turso-schema.d.ts +13 -0
  99. package/dist/src/lib/turso-schema.d.ts.map +1 -0
  100. package/dist/src/lib/turso-schema.js +69 -0
  101. package/dist/src/lib/turso-schema.js.map +1 -0
  102. package/dist/src/lib/turso.d.ts +56 -0
  103. package/dist/src/lib/turso.d.ts.map +1 -0
  104. package/dist/src/lib/turso.js +144 -0
  105. package/dist/src/lib/turso.js.map +1 -0
  106. package/dist/src/lib/types.d.ts +31 -0
  107. package/dist/src/lib/types.d.ts.map +1 -0
  108. package/dist/src/lib/types.js +20 -0
  109. package/dist/src/lib/types.js.map +1 -0
  110. package/dist/src/lib/utils.d.ts +34 -0
  111. package/dist/src/lib/utils.d.ts.map +1 -0
  112. package/dist/src/lib/utils.js +72 -0
  113. package/dist/src/lib/utils.js.map +1 -0
  114. package/package.json +63 -0
  115. package/templates/.env.example +51 -0
  116. package/templates/agents/codebase-analyzer.md +121 -0
  117. package/templates/agents/codebase-locator.md +105 -0
  118. package/templates/agents/coding-agent.md +187 -0
  119. package/templates/agents/debug-agent.md +300 -0
  120. package/templates/prompts/consolidate-and-create-linear.md +282 -0
  121. package/templates/prompts/implementation.md +94 -0
  122. package/templates/prompts/plan-generation.md +171 -0
  123. package/templates/prompts/review.md +39 -0
  124. package/templates/prompts/verify.md +80 -0
  125. package/templates/scripts/claude-agent-runner.js +12887 -0
  126. package/templates/scripts/detect-runtime.sh +95 -0
  127. package/templates/scripts/linear-agent.js +1753 -0
  128. package/templates/scripts/planning-agent.js +1738 -0
  129. package/templates/workflows/claude-implement.yml +931 -0
  130. package/templates/workflows/claude-plan.yml +301 -0
@@ -0,0 +1,1738 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/agents/planning-agent.ts
4
+ import { readFile } from "fs/promises";
5
+ import { join } from "path";
6
+
7
+ // src/lib/types.ts
8
+ var DEFAULT_MODELS = {
9
+ anthropic: "claude-opus-4-5",
10
+ openai: "gpt-5.2-pro",
11
+ google: "gemini-2.5-flash"
12
+ };
13
+ var API_KEY_ENV_VARS = {
14
+ anthropic: ["ANTHROPIC_API_KEY", "CLAUDE_CODE_OAUTH_TOKEN"],
15
+ openai: ["OPENAI_API_KEY"],
16
+ google: ["GOOGLE_GENERATIVE_AI_API_KEY"]
17
+ };
18
+
19
+ // src/lib/utils.ts
20
+ function extractTextFromParts(parts) {
21
+ if (!Array.isArray(parts))
22
+ return "";
23
+ return parts.filter((part) => part.type === "text").map((part) => part.text || "").join(`
24
+ `);
25
+ }
26
+ function getApiKey(provider) {
27
+ const envVars = API_KEY_ENV_VARS[provider];
28
+ for (const envVar of envVars) {
29
+ const apiKey = process.env[envVar];
30
+ if (apiKey) {
31
+ return apiKey;
32
+ }
33
+ }
34
+ const errorMsg = [
35
+ `Error: No API key found for provider "${provider}"`,
36
+ `Required environment variables (at least one):`,
37
+ ...envVars.map((envVar) => ` - ${envVar}`)
38
+ ].join(`
39
+ `);
40
+ throw new Error(errorMsg);
41
+ }
42
+ function validateProvider(provider) {
43
+ const validProviders = ["anthropic", "openai", "google"];
44
+ if (!validProviders.includes(provider)) {
45
+ throw new Error(`Error: Unsupported provider "${provider}". ` + `Supported providers: ${validProviders.join(", ")}`);
46
+ }
47
+ }
48
+ // node_modules/@opencode-ai/sdk/dist/gen/core/serverSentEvents.gen.js
49
+ var createSseClient = ({ onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
50
+ let lastEventId;
51
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
52
+ const createStream = async function* () {
53
+ let retryDelay = sseDefaultRetryDelay ?? 3000;
54
+ let attempt = 0;
55
+ const signal = options.signal ?? new AbortController().signal;
56
+ while (true) {
57
+ if (signal.aborted)
58
+ break;
59
+ attempt++;
60
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
61
+ if (lastEventId !== undefined) {
62
+ headers.set("Last-Event-ID", lastEventId);
63
+ }
64
+ try {
65
+ const response = await fetch(url, { ...options, headers, signal });
66
+ if (!response.ok)
67
+ throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
68
+ if (!response.body)
69
+ throw new Error("No body in SSE response");
70
+ const reader = response.body.pipeThrough(new TextDecoderStream).getReader();
71
+ let buffer = "";
72
+ const abortHandler = () => {
73
+ try {
74
+ reader.cancel();
75
+ } catch {}
76
+ };
77
+ signal.addEventListener("abort", abortHandler);
78
+ try {
79
+ while (true) {
80
+ const { done, value } = await reader.read();
81
+ if (done)
82
+ break;
83
+ buffer += value;
84
+ const chunks = buffer.split(`
85
+
86
+ `);
87
+ buffer = chunks.pop() ?? "";
88
+ for (const chunk of chunks) {
89
+ const lines = chunk.split(`
90
+ `);
91
+ const dataLines = [];
92
+ let eventName;
93
+ for (const line of lines) {
94
+ if (line.startsWith("data:")) {
95
+ dataLines.push(line.replace(/^data:\s*/, ""));
96
+ } else if (line.startsWith("event:")) {
97
+ eventName = line.replace(/^event:\s*/, "");
98
+ } else if (line.startsWith("id:")) {
99
+ lastEventId = line.replace(/^id:\s*/, "");
100
+ } else if (line.startsWith("retry:")) {
101
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
102
+ if (!Number.isNaN(parsed)) {
103
+ retryDelay = parsed;
104
+ }
105
+ }
106
+ }
107
+ let data;
108
+ let parsedJson = false;
109
+ if (dataLines.length) {
110
+ const rawData = dataLines.join(`
111
+ `);
112
+ try {
113
+ data = JSON.parse(rawData);
114
+ parsedJson = true;
115
+ } catch {
116
+ data = rawData;
117
+ }
118
+ }
119
+ if (parsedJson) {
120
+ if (responseValidator) {
121
+ await responseValidator(data);
122
+ }
123
+ if (responseTransformer) {
124
+ data = await responseTransformer(data);
125
+ }
126
+ }
127
+ onSseEvent?.({
128
+ data,
129
+ event: eventName,
130
+ id: lastEventId,
131
+ retry: retryDelay
132
+ });
133
+ if (dataLines.length) {
134
+ yield data;
135
+ }
136
+ }
137
+ }
138
+ } finally {
139
+ signal.removeEventListener("abort", abortHandler);
140
+ reader.releaseLock();
141
+ }
142
+ break;
143
+ } catch (error) {
144
+ onSseError?.(error);
145
+ if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) {
146
+ break;
147
+ }
148
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
149
+ await sleep(backoff);
150
+ }
151
+ }
152
+ };
153
+ const stream = createStream();
154
+ return { stream };
155
+ };
156
+
157
+ // node_modules/@opencode-ai/sdk/dist/gen/core/auth.gen.js
158
+ var getAuthToken = async (auth, callback) => {
159
+ const token = typeof callback === "function" ? await callback(auth) : callback;
160
+ if (!token) {
161
+ return;
162
+ }
163
+ if (auth.scheme === "bearer") {
164
+ return `Bearer ${token}`;
165
+ }
166
+ if (auth.scheme === "basic") {
167
+ return `Basic ${btoa(token)}`;
168
+ }
169
+ return token;
170
+ };
171
+
172
+ // node_modules/@opencode-ai/sdk/dist/gen/core/bodySerializer.gen.js
173
+ var jsonBodySerializer = {
174
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
175
+ };
176
+
177
+ // node_modules/@opencode-ai/sdk/dist/gen/core/pathSerializer.gen.js
178
+ var separatorArrayExplode = (style) => {
179
+ switch (style) {
180
+ case "label":
181
+ return ".";
182
+ case "matrix":
183
+ return ";";
184
+ case "simple":
185
+ return ",";
186
+ default:
187
+ return "&";
188
+ }
189
+ };
190
+ var separatorArrayNoExplode = (style) => {
191
+ switch (style) {
192
+ case "form":
193
+ return ",";
194
+ case "pipeDelimited":
195
+ return "|";
196
+ case "spaceDelimited":
197
+ return "%20";
198
+ default:
199
+ return ",";
200
+ }
201
+ };
202
+ var separatorObjectExplode = (style) => {
203
+ switch (style) {
204
+ case "label":
205
+ return ".";
206
+ case "matrix":
207
+ return ";";
208
+ case "simple":
209
+ return ",";
210
+ default:
211
+ return "&";
212
+ }
213
+ };
214
+ var serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
215
+ if (!explode) {
216
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
217
+ switch (style) {
218
+ case "label":
219
+ return `.${joinedValues2}`;
220
+ case "matrix":
221
+ return `;${name}=${joinedValues2}`;
222
+ case "simple":
223
+ return joinedValues2;
224
+ default:
225
+ return `${name}=${joinedValues2}`;
226
+ }
227
+ }
228
+ const separator = separatorArrayExplode(style);
229
+ const joinedValues = value.map((v) => {
230
+ if (style === "label" || style === "simple") {
231
+ return allowReserved ? v : encodeURIComponent(v);
232
+ }
233
+ return serializePrimitiveParam({
234
+ allowReserved,
235
+ name,
236
+ value: v
237
+ });
238
+ }).join(separator);
239
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
240
+ };
241
+ var serializePrimitiveParam = ({ allowReserved, name, value }) => {
242
+ if (value === undefined || value === null) {
243
+ return "";
244
+ }
245
+ if (typeof value === "object") {
246
+ throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
247
+ }
248
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
249
+ };
250
+ var serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
251
+ if (value instanceof Date) {
252
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
253
+ }
254
+ if (style !== "deepObject" && !explode) {
255
+ let values = [];
256
+ Object.entries(value).forEach(([key, v]) => {
257
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
258
+ });
259
+ const joinedValues2 = values.join(",");
260
+ switch (style) {
261
+ case "form":
262
+ return `${name}=${joinedValues2}`;
263
+ case "label":
264
+ return `.${joinedValues2}`;
265
+ case "matrix":
266
+ return `;${name}=${joinedValues2}`;
267
+ default:
268
+ return joinedValues2;
269
+ }
270
+ }
271
+ const separator = separatorObjectExplode(style);
272
+ const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
273
+ allowReserved,
274
+ name: style === "deepObject" ? `${name}[${key}]` : key,
275
+ value: v
276
+ })).join(separator);
277
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
278
+ };
279
+
280
+ // node_modules/@opencode-ai/sdk/dist/gen/core/utils.gen.js
281
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
282
+ var defaultPathSerializer = ({ path, url: _url }) => {
283
+ let url = _url;
284
+ const matches = _url.match(PATH_PARAM_RE);
285
+ if (matches) {
286
+ for (const match of matches) {
287
+ let explode = false;
288
+ let name = match.substring(1, match.length - 1);
289
+ let style = "simple";
290
+ if (name.endsWith("*")) {
291
+ explode = true;
292
+ name = name.substring(0, name.length - 1);
293
+ }
294
+ if (name.startsWith(".")) {
295
+ name = name.substring(1);
296
+ style = "label";
297
+ } else if (name.startsWith(";")) {
298
+ name = name.substring(1);
299
+ style = "matrix";
300
+ }
301
+ const value = path[name];
302
+ if (value === undefined || value === null) {
303
+ continue;
304
+ }
305
+ if (Array.isArray(value)) {
306
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
307
+ continue;
308
+ }
309
+ if (typeof value === "object") {
310
+ url = url.replace(match, serializeObjectParam({
311
+ explode,
312
+ name,
313
+ style,
314
+ value,
315
+ valueOnly: true
316
+ }));
317
+ continue;
318
+ }
319
+ if (style === "matrix") {
320
+ url = url.replace(match, `;${serializePrimitiveParam({
321
+ name,
322
+ value
323
+ })}`);
324
+ continue;
325
+ }
326
+ const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
327
+ url = url.replace(match, replaceValue);
328
+ }
329
+ }
330
+ return url;
331
+ };
332
+ var getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
333
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
334
+ let url = (baseUrl ?? "") + pathUrl;
335
+ if (path) {
336
+ url = defaultPathSerializer({ path, url });
337
+ }
338
+ let search = query ? querySerializer(query) : "";
339
+ if (search.startsWith("?")) {
340
+ search = search.substring(1);
341
+ }
342
+ if (search) {
343
+ url += `?${search}`;
344
+ }
345
+ return url;
346
+ };
347
+
348
+ // node_modules/@opencode-ai/sdk/dist/gen/client/utils.gen.js
349
+ var createQuerySerializer = ({ allowReserved, array, object } = {}) => {
350
+ const querySerializer = (queryParams) => {
351
+ const search = [];
352
+ if (queryParams && typeof queryParams === "object") {
353
+ for (const name in queryParams) {
354
+ const value = queryParams[name];
355
+ if (value === undefined || value === null) {
356
+ continue;
357
+ }
358
+ if (Array.isArray(value)) {
359
+ const serializedArray = serializeArrayParam({
360
+ allowReserved,
361
+ explode: true,
362
+ name,
363
+ style: "form",
364
+ value,
365
+ ...array
366
+ });
367
+ if (serializedArray)
368
+ search.push(serializedArray);
369
+ } else if (typeof value === "object") {
370
+ const serializedObject = serializeObjectParam({
371
+ allowReserved,
372
+ explode: true,
373
+ name,
374
+ style: "deepObject",
375
+ value,
376
+ ...object
377
+ });
378
+ if (serializedObject)
379
+ search.push(serializedObject);
380
+ } else {
381
+ const serializedPrimitive = serializePrimitiveParam({
382
+ allowReserved,
383
+ name,
384
+ value
385
+ });
386
+ if (serializedPrimitive)
387
+ search.push(serializedPrimitive);
388
+ }
389
+ }
390
+ }
391
+ return search.join("&");
392
+ };
393
+ return querySerializer;
394
+ };
395
+ var getParseAs = (contentType) => {
396
+ if (!contentType) {
397
+ return "stream";
398
+ }
399
+ const cleanContent = contentType.split(";")[0]?.trim();
400
+ if (!cleanContent) {
401
+ return;
402
+ }
403
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
404
+ return "json";
405
+ }
406
+ if (cleanContent === "multipart/form-data") {
407
+ return "formData";
408
+ }
409
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
410
+ return "blob";
411
+ }
412
+ if (cleanContent.startsWith("text/")) {
413
+ return "text";
414
+ }
415
+ return;
416
+ };
417
+ var checkForExistence = (options, name) => {
418
+ if (!name) {
419
+ return false;
420
+ }
421
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
422
+ return true;
423
+ }
424
+ return false;
425
+ };
426
+ var setAuthParams = async ({ security, ...options }) => {
427
+ for (const auth of security) {
428
+ if (checkForExistence(options, auth.name)) {
429
+ continue;
430
+ }
431
+ const token = await getAuthToken(auth, options.auth);
432
+ if (!token) {
433
+ continue;
434
+ }
435
+ const name = auth.name ?? "Authorization";
436
+ switch (auth.in) {
437
+ case "query":
438
+ if (!options.query) {
439
+ options.query = {};
440
+ }
441
+ options.query[name] = token;
442
+ break;
443
+ case "cookie":
444
+ options.headers.append("Cookie", `${name}=${token}`);
445
+ break;
446
+ case "header":
447
+ default:
448
+ options.headers.set(name, token);
449
+ break;
450
+ }
451
+ }
452
+ };
453
+ var buildUrl = (options) => getUrl({
454
+ baseUrl: options.baseUrl,
455
+ path: options.path,
456
+ query: options.query,
457
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
458
+ url: options.url
459
+ });
460
+ var mergeConfigs = (a, b) => {
461
+ const config = { ...a, ...b };
462
+ if (config.baseUrl?.endsWith("/")) {
463
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
464
+ }
465
+ config.headers = mergeHeaders(a.headers, b.headers);
466
+ return config;
467
+ };
468
+ var mergeHeaders = (...headers) => {
469
+ const mergedHeaders = new Headers;
470
+ for (const header of headers) {
471
+ if (!header || typeof header !== "object") {
472
+ continue;
473
+ }
474
+ const iterator = header instanceof Headers ? header.entries() : Object.entries(header);
475
+ for (const [key, value] of iterator) {
476
+ if (value === null) {
477
+ mergedHeaders.delete(key);
478
+ } else if (Array.isArray(value)) {
479
+ for (const v of value) {
480
+ mergedHeaders.append(key, v);
481
+ }
482
+ } else if (value !== undefined) {
483
+ mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
484
+ }
485
+ }
486
+ }
487
+ return mergedHeaders;
488
+ };
489
+
490
+ class Interceptors {
491
+ _fns;
492
+ constructor() {
493
+ this._fns = [];
494
+ }
495
+ clear() {
496
+ this._fns = [];
497
+ }
498
+ getInterceptorIndex(id) {
499
+ if (typeof id === "number") {
500
+ return this._fns[id] ? id : -1;
501
+ } else {
502
+ return this._fns.indexOf(id);
503
+ }
504
+ }
505
+ exists(id) {
506
+ const index = this.getInterceptorIndex(id);
507
+ return !!this._fns[index];
508
+ }
509
+ eject(id) {
510
+ const index = this.getInterceptorIndex(id);
511
+ if (this._fns[index]) {
512
+ this._fns[index] = null;
513
+ }
514
+ }
515
+ update(id, fn) {
516
+ const index = this.getInterceptorIndex(id);
517
+ if (this._fns[index]) {
518
+ this._fns[index] = fn;
519
+ return id;
520
+ } else {
521
+ return false;
522
+ }
523
+ }
524
+ use(fn) {
525
+ this._fns = [...this._fns, fn];
526
+ return this._fns.length - 1;
527
+ }
528
+ }
529
+ var createInterceptors = () => ({
530
+ error: new Interceptors,
531
+ request: new Interceptors,
532
+ response: new Interceptors
533
+ });
534
+ var defaultQuerySerializer = createQuerySerializer({
535
+ allowReserved: false,
536
+ array: {
537
+ explode: true,
538
+ style: "form"
539
+ },
540
+ object: {
541
+ explode: true,
542
+ style: "deepObject"
543
+ }
544
+ });
545
+ var defaultHeaders = {
546
+ "Content-Type": "application/json"
547
+ };
548
+ var createConfig = (override = {}) => ({
549
+ ...jsonBodySerializer,
550
+ headers: defaultHeaders,
551
+ parseAs: "auto",
552
+ querySerializer: defaultQuerySerializer,
553
+ ...override
554
+ });
555
+
556
+ // node_modules/@opencode-ai/sdk/dist/gen/client/client.gen.js
557
+ var createClient = (config = {}) => {
558
+ let _config = mergeConfigs(createConfig(), config);
559
+ const getConfig = () => ({ ..._config });
560
+ const setConfig = (config2) => {
561
+ _config = mergeConfigs(_config, config2);
562
+ return getConfig();
563
+ };
564
+ const interceptors = createInterceptors();
565
+ const beforeRequest = async (options) => {
566
+ const opts = {
567
+ ..._config,
568
+ ...options,
569
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
570
+ headers: mergeHeaders(_config.headers, options.headers),
571
+ serializedBody: undefined
572
+ };
573
+ if (opts.security) {
574
+ await setAuthParams({
575
+ ...opts,
576
+ security: opts.security
577
+ });
578
+ }
579
+ if (opts.requestValidator) {
580
+ await opts.requestValidator(opts);
581
+ }
582
+ if (opts.body && opts.bodySerializer) {
583
+ opts.serializedBody = opts.bodySerializer(opts.body);
584
+ }
585
+ if (opts.serializedBody === undefined || opts.serializedBody === "") {
586
+ opts.headers.delete("Content-Type");
587
+ }
588
+ const url = buildUrl(opts);
589
+ return { opts, url };
590
+ };
591
+ const request = async (options) => {
592
+ const { opts, url } = await beforeRequest(options);
593
+ const requestInit = {
594
+ redirect: "follow",
595
+ ...opts,
596
+ body: opts.serializedBody
597
+ };
598
+ let request2 = new Request(url, requestInit);
599
+ for (const fn of interceptors.request._fns) {
600
+ if (fn) {
601
+ request2 = await fn(request2, opts);
602
+ }
603
+ }
604
+ const _fetch = opts.fetch;
605
+ let response = await _fetch(request2);
606
+ for (const fn of interceptors.response._fns) {
607
+ if (fn) {
608
+ response = await fn(response, request2, opts);
609
+ }
610
+ }
611
+ const result = {
612
+ request: request2,
613
+ response
614
+ };
615
+ if (response.ok) {
616
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
617
+ return opts.responseStyle === "data" ? {} : {
618
+ data: {},
619
+ ...result
620
+ };
621
+ }
622
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
623
+ let data;
624
+ switch (parseAs) {
625
+ case "arrayBuffer":
626
+ case "blob":
627
+ case "formData":
628
+ case "json":
629
+ case "text":
630
+ data = await response[parseAs]();
631
+ break;
632
+ case "stream":
633
+ return opts.responseStyle === "data" ? response.body : {
634
+ data: response.body,
635
+ ...result
636
+ };
637
+ }
638
+ if (parseAs === "json") {
639
+ if (opts.responseValidator) {
640
+ await opts.responseValidator(data);
641
+ }
642
+ if (opts.responseTransformer) {
643
+ data = await opts.responseTransformer(data);
644
+ }
645
+ }
646
+ return opts.responseStyle === "data" ? data : {
647
+ data,
648
+ ...result
649
+ };
650
+ }
651
+ const textError = await response.text();
652
+ let jsonError;
653
+ try {
654
+ jsonError = JSON.parse(textError);
655
+ } catch {}
656
+ const error = jsonError ?? textError;
657
+ let finalError = error;
658
+ for (const fn of interceptors.error._fns) {
659
+ if (fn) {
660
+ finalError = await fn(error, response, request2, opts);
661
+ }
662
+ }
663
+ finalError = finalError || {};
664
+ if (opts.throwOnError) {
665
+ throw finalError;
666
+ }
667
+ return opts.responseStyle === "data" ? undefined : {
668
+ error: finalError,
669
+ ...result
670
+ };
671
+ };
672
+ const makeMethod = (method) => {
673
+ const fn = (options) => request({ ...options, method });
674
+ fn.sse = async (options) => {
675
+ const { opts, url } = await beforeRequest(options);
676
+ return createSseClient({
677
+ ...opts,
678
+ body: opts.body,
679
+ headers: opts.headers,
680
+ method,
681
+ url
682
+ });
683
+ };
684
+ return fn;
685
+ };
686
+ return {
687
+ buildUrl,
688
+ connect: makeMethod("CONNECT"),
689
+ delete: makeMethod("DELETE"),
690
+ get: makeMethod("GET"),
691
+ getConfig,
692
+ head: makeMethod("HEAD"),
693
+ interceptors,
694
+ options: makeMethod("OPTIONS"),
695
+ patch: makeMethod("PATCH"),
696
+ post: makeMethod("POST"),
697
+ put: makeMethod("PUT"),
698
+ request,
699
+ setConfig,
700
+ trace: makeMethod("TRACE")
701
+ };
702
+ };
703
+ // node_modules/@opencode-ai/sdk/dist/gen/core/params.gen.js
704
+ var extraPrefixesMap = {
705
+ $body_: "body",
706
+ $headers_: "headers",
707
+ $path_: "path",
708
+ $query_: "query"
709
+ };
710
+ var extraPrefixes = Object.entries(extraPrefixesMap);
711
+ // node_modules/@opencode-ai/sdk/dist/gen/client.gen.js
712
+ var client = createClient(createConfig({
713
+ baseUrl: "http://localhost:4096"
714
+ }));
715
+
716
+ // node_modules/@opencode-ai/sdk/dist/gen/sdk.gen.js
717
+ class _HeyApiClient {
718
+ _client = client;
719
+ constructor(args) {
720
+ if (args?.client) {
721
+ this._client = args.client;
722
+ }
723
+ }
724
+ }
725
+
726
+ class Global extends _HeyApiClient {
727
+ event(options) {
728
+ return (options?.client ?? this._client).get.sse({
729
+ url: "/global/event",
730
+ ...options
731
+ });
732
+ }
733
+ }
734
+
735
+ class Project extends _HeyApiClient {
736
+ list(options) {
737
+ return (options?.client ?? this._client).get({
738
+ url: "/project",
739
+ ...options
740
+ });
741
+ }
742
+ current(options) {
743
+ return (options?.client ?? this._client).get({
744
+ url: "/project/current",
745
+ ...options
746
+ });
747
+ }
748
+ }
749
+
750
+ class Pty extends _HeyApiClient {
751
+ list(options) {
752
+ return (options?.client ?? this._client).get({
753
+ url: "/pty",
754
+ ...options
755
+ });
756
+ }
757
+ create(options) {
758
+ return (options?.client ?? this._client).post({
759
+ url: "/pty",
760
+ ...options,
761
+ headers: {
762
+ "Content-Type": "application/json",
763
+ ...options?.headers
764
+ }
765
+ });
766
+ }
767
+ remove(options) {
768
+ return (options.client ?? this._client).delete({
769
+ url: "/pty/{id}",
770
+ ...options
771
+ });
772
+ }
773
+ get(options) {
774
+ return (options.client ?? this._client).get({
775
+ url: "/pty/{id}",
776
+ ...options
777
+ });
778
+ }
779
+ update(options) {
780
+ return (options.client ?? this._client).put({
781
+ url: "/pty/{id}",
782
+ ...options,
783
+ headers: {
784
+ "Content-Type": "application/json",
785
+ ...options.headers
786
+ }
787
+ });
788
+ }
789
+ connect(options) {
790
+ return (options.client ?? this._client).get({
791
+ url: "/pty/{id}/connect",
792
+ ...options
793
+ });
794
+ }
795
+ }
796
+
797
+ class Config extends _HeyApiClient {
798
+ get(options) {
799
+ return (options?.client ?? this._client).get({
800
+ url: "/config",
801
+ ...options
802
+ });
803
+ }
804
+ update(options) {
805
+ return (options?.client ?? this._client).patch({
806
+ url: "/config",
807
+ ...options,
808
+ headers: {
809
+ "Content-Type": "application/json",
810
+ ...options?.headers
811
+ }
812
+ });
813
+ }
814
+ providers(options) {
815
+ return (options?.client ?? this._client).get({
816
+ url: "/config/providers",
817
+ ...options
818
+ });
819
+ }
820
+ }
821
+
822
+ class Tool extends _HeyApiClient {
823
+ ids(options) {
824
+ return (options?.client ?? this._client).get({
825
+ url: "/experimental/tool/ids",
826
+ ...options
827
+ });
828
+ }
829
+ list(options) {
830
+ return (options.client ?? this._client).get({
831
+ url: "/experimental/tool",
832
+ ...options
833
+ });
834
+ }
835
+ }
836
+
837
+ class Instance extends _HeyApiClient {
838
+ dispose(options) {
839
+ return (options?.client ?? this._client).post({
840
+ url: "/instance/dispose",
841
+ ...options
842
+ });
843
+ }
844
+ }
845
+
846
+ class Path extends _HeyApiClient {
847
+ get(options) {
848
+ return (options?.client ?? this._client).get({
849
+ url: "/path",
850
+ ...options
851
+ });
852
+ }
853
+ }
854
+
855
+ class Vcs extends _HeyApiClient {
856
+ get(options) {
857
+ return (options?.client ?? this._client).get({
858
+ url: "/vcs",
859
+ ...options
860
+ });
861
+ }
862
+ }
863
+
864
+ class Session extends _HeyApiClient {
865
+ list(options) {
866
+ return (options?.client ?? this._client).get({
867
+ url: "/session",
868
+ ...options
869
+ });
870
+ }
871
+ create(options) {
872
+ return (options?.client ?? this._client).post({
873
+ url: "/session",
874
+ ...options,
875
+ headers: {
876
+ "Content-Type": "application/json",
877
+ ...options?.headers
878
+ }
879
+ });
880
+ }
881
+ status(options) {
882
+ return (options?.client ?? this._client).get({
883
+ url: "/session/status",
884
+ ...options
885
+ });
886
+ }
887
+ delete(options) {
888
+ return (options.client ?? this._client).delete({
889
+ url: "/session/{id}",
890
+ ...options
891
+ });
892
+ }
893
+ get(options) {
894
+ return (options.client ?? this._client).get({
895
+ url: "/session/{id}",
896
+ ...options
897
+ });
898
+ }
899
+ update(options) {
900
+ return (options.client ?? this._client).patch({
901
+ url: "/session/{id}",
902
+ ...options,
903
+ headers: {
904
+ "Content-Type": "application/json",
905
+ ...options.headers
906
+ }
907
+ });
908
+ }
909
+ children(options) {
910
+ return (options.client ?? this._client).get({
911
+ url: "/session/{id}/children",
912
+ ...options
913
+ });
914
+ }
915
+ todo(options) {
916
+ return (options.client ?? this._client).get({
917
+ url: "/session/{id}/todo",
918
+ ...options
919
+ });
920
+ }
921
+ init(options) {
922
+ return (options.client ?? this._client).post({
923
+ url: "/session/{id}/init",
924
+ ...options,
925
+ headers: {
926
+ "Content-Type": "application/json",
927
+ ...options.headers
928
+ }
929
+ });
930
+ }
931
+ fork(options) {
932
+ return (options.client ?? this._client).post({
933
+ url: "/session/{id}/fork",
934
+ ...options,
935
+ headers: {
936
+ "Content-Type": "application/json",
937
+ ...options.headers
938
+ }
939
+ });
940
+ }
941
+ abort(options) {
942
+ return (options.client ?? this._client).post({
943
+ url: "/session/{id}/abort",
944
+ ...options
945
+ });
946
+ }
947
+ unshare(options) {
948
+ return (options.client ?? this._client).delete({
949
+ url: "/session/{id}/share",
950
+ ...options
951
+ });
952
+ }
953
+ share(options) {
954
+ return (options.client ?? this._client).post({
955
+ url: "/session/{id}/share",
956
+ ...options
957
+ });
958
+ }
959
+ diff(options) {
960
+ return (options.client ?? this._client).get({
961
+ url: "/session/{id}/diff",
962
+ ...options
963
+ });
964
+ }
965
+ summarize(options) {
966
+ return (options.client ?? this._client).post({
967
+ url: "/session/{id}/summarize",
968
+ ...options,
969
+ headers: {
970
+ "Content-Type": "application/json",
971
+ ...options.headers
972
+ }
973
+ });
974
+ }
975
+ messages(options) {
976
+ return (options.client ?? this._client).get({
977
+ url: "/session/{id}/message",
978
+ ...options
979
+ });
980
+ }
981
+ prompt(options) {
982
+ return (options.client ?? this._client).post({
983
+ url: "/session/{id}/message",
984
+ ...options,
985
+ headers: {
986
+ "Content-Type": "application/json",
987
+ ...options.headers
988
+ }
989
+ });
990
+ }
991
+ message(options) {
992
+ return (options.client ?? this._client).get({
993
+ url: "/session/{id}/message/{messageID}",
994
+ ...options
995
+ });
996
+ }
997
+ promptAsync(options) {
998
+ return (options.client ?? this._client).post({
999
+ url: "/session/{id}/prompt_async",
1000
+ ...options,
1001
+ headers: {
1002
+ "Content-Type": "application/json",
1003
+ ...options.headers
1004
+ }
1005
+ });
1006
+ }
1007
+ command(options) {
1008
+ return (options.client ?? this._client).post({
1009
+ url: "/session/{id}/command",
1010
+ ...options,
1011
+ headers: {
1012
+ "Content-Type": "application/json",
1013
+ ...options.headers
1014
+ }
1015
+ });
1016
+ }
1017
+ shell(options) {
1018
+ return (options.client ?? this._client).post({
1019
+ url: "/session/{id}/shell",
1020
+ ...options,
1021
+ headers: {
1022
+ "Content-Type": "application/json",
1023
+ ...options.headers
1024
+ }
1025
+ });
1026
+ }
1027
+ revert(options) {
1028
+ return (options.client ?? this._client).post({
1029
+ url: "/session/{id}/revert",
1030
+ ...options,
1031
+ headers: {
1032
+ "Content-Type": "application/json",
1033
+ ...options.headers
1034
+ }
1035
+ });
1036
+ }
1037
+ unrevert(options) {
1038
+ return (options.client ?? this._client).post({
1039
+ url: "/session/{id}/unrevert",
1040
+ ...options
1041
+ });
1042
+ }
1043
+ }
1044
+
1045
+ class Command extends _HeyApiClient {
1046
+ list(options) {
1047
+ return (options?.client ?? this._client).get({
1048
+ url: "/command",
1049
+ ...options
1050
+ });
1051
+ }
1052
+ }
1053
+
1054
+ class Oauth extends _HeyApiClient {
1055
+ authorize(options) {
1056
+ return (options.client ?? this._client).post({
1057
+ url: "/provider/{id}/oauth/authorize",
1058
+ ...options,
1059
+ headers: {
1060
+ "Content-Type": "application/json",
1061
+ ...options.headers
1062
+ }
1063
+ });
1064
+ }
1065
+ callback(options) {
1066
+ return (options.client ?? this._client).post({
1067
+ url: "/provider/{id}/oauth/callback",
1068
+ ...options,
1069
+ headers: {
1070
+ "Content-Type": "application/json",
1071
+ ...options.headers
1072
+ }
1073
+ });
1074
+ }
1075
+ }
1076
+
1077
+ class Provider2 extends _HeyApiClient {
1078
+ list(options) {
1079
+ return (options?.client ?? this._client).get({
1080
+ url: "/provider",
1081
+ ...options
1082
+ });
1083
+ }
1084
+ auth(options) {
1085
+ return (options?.client ?? this._client).get({
1086
+ url: "/provider/auth",
1087
+ ...options
1088
+ });
1089
+ }
1090
+ oauth = new Oauth({ client: this._client });
1091
+ }
1092
+
1093
+ class Find extends _HeyApiClient {
1094
+ text(options) {
1095
+ return (options.client ?? this._client).get({
1096
+ url: "/find",
1097
+ ...options
1098
+ });
1099
+ }
1100
+ files(options) {
1101
+ return (options.client ?? this._client).get({
1102
+ url: "/find/file",
1103
+ ...options
1104
+ });
1105
+ }
1106
+ symbols(options) {
1107
+ return (options.client ?? this._client).get({
1108
+ url: "/find/symbol",
1109
+ ...options
1110
+ });
1111
+ }
1112
+ }
1113
+
1114
+ class File extends _HeyApiClient {
1115
+ list(options) {
1116
+ return (options.client ?? this._client).get({
1117
+ url: "/file",
1118
+ ...options
1119
+ });
1120
+ }
1121
+ read(options) {
1122
+ return (options.client ?? this._client).get({
1123
+ url: "/file/content",
1124
+ ...options
1125
+ });
1126
+ }
1127
+ status(options) {
1128
+ return (options?.client ?? this._client).get({
1129
+ url: "/file/status",
1130
+ ...options
1131
+ });
1132
+ }
1133
+ }
1134
+
1135
+ class App extends _HeyApiClient {
1136
+ log(options) {
1137
+ return (options?.client ?? this._client).post({
1138
+ url: "/log",
1139
+ ...options,
1140
+ headers: {
1141
+ "Content-Type": "application/json",
1142
+ ...options?.headers
1143
+ }
1144
+ });
1145
+ }
1146
+ agents(options) {
1147
+ return (options?.client ?? this._client).get({
1148
+ url: "/agent",
1149
+ ...options
1150
+ });
1151
+ }
1152
+ }
1153
+
1154
+ class Auth extends _HeyApiClient {
1155
+ remove(options) {
1156
+ return (options.client ?? this._client).delete({
1157
+ url: "/mcp/{name}/auth",
1158
+ ...options
1159
+ });
1160
+ }
1161
+ start(options) {
1162
+ return (options.client ?? this._client).post({
1163
+ url: "/mcp/{name}/auth",
1164
+ ...options
1165
+ });
1166
+ }
1167
+ callback(options) {
1168
+ return (options.client ?? this._client).post({
1169
+ url: "/mcp/{name}/auth/callback",
1170
+ ...options,
1171
+ headers: {
1172
+ "Content-Type": "application/json",
1173
+ ...options.headers
1174
+ }
1175
+ });
1176
+ }
1177
+ authenticate(options) {
1178
+ return (options.client ?? this._client).post({
1179
+ url: "/mcp/{name}/auth/authenticate",
1180
+ ...options
1181
+ });
1182
+ }
1183
+ set(options) {
1184
+ return (options.client ?? this._client).put({
1185
+ url: "/auth/{id}",
1186
+ ...options,
1187
+ headers: {
1188
+ "Content-Type": "application/json",
1189
+ ...options.headers
1190
+ }
1191
+ });
1192
+ }
1193
+ }
1194
+
1195
+ class Mcp extends _HeyApiClient {
1196
+ status(options) {
1197
+ return (options?.client ?? this._client).get({
1198
+ url: "/mcp",
1199
+ ...options
1200
+ });
1201
+ }
1202
+ add(options) {
1203
+ return (options?.client ?? this._client).post({
1204
+ url: "/mcp",
1205
+ ...options,
1206
+ headers: {
1207
+ "Content-Type": "application/json",
1208
+ ...options?.headers
1209
+ }
1210
+ });
1211
+ }
1212
+ connect(options) {
1213
+ return (options.client ?? this._client).post({
1214
+ url: "/mcp/{name}/connect",
1215
+ ...options
1216
+ });
1217
+ }
1218
+ disconnect(options) {
1219
+ return (options.client ?? this._client).post({
1220
+ url: "/mcp/{name}/disconnect",
1221
+ ...options
1222
+ });
1223
+ }
1224
+ auth = new Auth({ client: this._client });
1225
+ }
1226
+
1227
+ class Lsp extends _HeyApiClient {
1228
+ status(options) {
1229
+ return (options?.client ?? this._client).get({
1230
+ url: "/lsp",
1231
+ ...options
1232
+ });
1233
+ }
1234
+ }
1235
+
1236
+ class Formatter extends _HeyApiClient {
1237
+ status(options) {
1238
+ return (options?.client ?? this._client).get({
1239
+ url: "/formatter",
1240
+ ...options
1241
+ });
1242
+ }
1243
+ }
1244
+
1245
+ class Control extends _HeyApiClient {
1246
+ next(options) {
1247
+ return (options?.client ?? this._client).get({
1248
+ url: "/tui/control/next",
1249
+ ...options
1250
+ });
1251
+ }
1252
+ response(options) {
1253
+ return (options?.client ?? this._client).post({
1254
+ url: "/tui/control/response",
1255
+ ...options,
1256
+ headers: {
1257
+ "Content-Type": "application/json",
1258
+ ...options?.headers
1259
+ }
1260
+ });
1261
+ }
1262
+ }
1263
+
1264
+ class Tui extends _HeyApiClient {
1265
+ appendPrompt(options) {
1266
+ return (options?.client ?? this._client).post({
1267
+ url: "/tui/append-prompt",
1268
+ ...options,
1269
+ headers: {
1270
+ "Content-Type": "application/json",
1271
+ ...options?.headers
1272
+ }
1273
+ });
1274
+ }
1275
+ openHelp(options) {
1276
+ return (options?.client ?? this._client).post({
1277
+ url: "/tui/open-help",
1278
+ ...options
1279
+ });
1280
+ }
1281
+ openSessions(options) {
1282
+ return (options?.client ?? this._client).post({
1283
+ url: "/tui/open-sessions",
1284
+ ...options
1285
+ });
1286
+ }
1287
+ openThemes(options) {
1288
+ return (options?.client ?? this._client).post({
1289
+ url: "/tui/open-themes",
1290
+ ...options
1291
+ });
1292
+ }
1293
+ openModels(options) {
1294
+ return (options?.client ?? this._client).post({
1295
+ url: "/tui/open-models",
1296
+ ...options
1297
+ });
1298
+ }
1299
+ submitPrompt(options) {
1300
+ return (options?.client ?? this._client).post({
1301
+ url: "/tui/submit-prompt",
1302
+ ...options
1303
+ });
1304
+ }
1305
+ clearPrompt(options) {
1306
+ return (options?.client ?? this._client).post({
1307
+ url: "/tui/clear-prompt",
1308
+ ...options
1309
+ });
1310
+ }
1311
+ executeCommand(options) {
1312
+ return (options?.client ?? this._client).post({
1313
+ url: "/tui/execute-command",
1314
+ ...options,
1315
+ headers: {
1316
+ "Content-Type": "application/json",
1317
+ ...options?.headers
1318
+ }
1319
+ });
1320
+ }
1321
+ showToast(options) {
1322
+ return (options?.client ?? this._client).post({
1323
+ url: "/tui/show-toast",
1324
+ ...options,
1325
+ headers: {
1326
+ "Content-Type": "application/json",
1327
+ ...options?.headers
1328
+ }
1329
+ });
1330
+ }
1331
+ publish(options) {
1332
+ return (options?.client ?? this._client).post({
1333
+ url: "/tui/publish",
1334
+ ...options,
1335
+ headers: {
1336
+ "Content-Type": "application/json",
1337
+ ...options?.headers
1338
+ }
1339
+ });
1340
+ }
1341
+ control = new Control({ client: this._client });
1342
+ }
1343
+
1344
+ class Event extends _HeyApiClient {
1345
+ subscribe(options) {
1346
+ return (options?.client ?? this._client).get.sse({
1347
+ url: "/event",
1348
+ ...options
1349
+ });
1350
+ }
1351
+ }
1352
+
1353
+ class OpencodeClient extends _HeyApiClient {
1354
+ postSessionIdPermissionsPermissionId(options) {
1355
+ return (options.client ?? this._client).post({
1356
+ url: "/session/{id}/permissions/{permissionID}",
1357
+ ...options,
1358
+ headers: {
1359
+ "Content-Type": "application/json",
1360
+ ...options.headers
1361
+ }
1362
+ });
1363
+ }
1364
+ global = new Global({ client: this._client });
1365
+ project = new Project({ client: this._client });
1366
+ pty = new Pty({ client: this._client });
1367
+ config = new Config({ client: this._client });
1368
+ tool = new Tool({ client: this._client });
1369
+ instance = new Instance({ client: this._client });
1370
+ path = new Path({ client: this._client });
1371
+ vcs = new Vcs({ client: this._client });
1372
+ session = new Session({ client: this._client });
1373
+ command = new Command({ client: this._client });
1374
+ provider = new Provider2({ client: this._client });
1375
+ find = new Find({ client: this._client });
1376
+ file = new File({ client: this._client });
1377
+ app = new App({ client: this._client });
1378
+ mcp = new Mcp({ client: this._client });
1379
+ lsp = new Lsp({ client: this._client });
1380
+ formatter = new Formatter({ client: this._client });
1381
+ tui = new Tui({ client: this._client });
1382
+ auth = new Auth({ client: this._client });
1383
+ event = new Event({ client: this._client });
1384
+ }
1385
+
1386
+ // node_modules/@opencode-ai/sdk/dist/client.js
1387
+ function createOpencodeClient(config) {
1388
+ if (!config?.fetch) {
1389
+ const customFetch = (req) => {
1390
+ req.timeout = false;
1391
+ return fetch(req);
1392
+ };
1393
+ config = {
1394
+ ...config,
1395
+ fetch: customFetch
1396
+ };
1397
+ }
1398
+ if (config?.directory) {
1399
+ config.headers = {
1400
+ ...config.headers,
1401
+ "x-opencode-directory": config.directory
1402
+ };
1403
+ }
1404
+ const client2 = createClient(config);
1405
+ return new OpencodeClient({ client: client2 });
1406
+ }
1407
+ // node_modules/@opencode-ai/sdk/dist/server.js
1408
+ import { spawn } from "node:child_process";
1409
+ async function createOpencodeServer(options) {
1410
+ options = Object.assign({
1411
+ hostname: "127.0.0.1",
1412
+ port: 4096,
1413
+ timeout: 5000
1414
+ }, options ?? {});
1415
+ const proc = spawn(`opencode`, [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`], {
1416
+ signal: options.signal,
1417
+ env: {
1418
+ ...process.env,
1419
+ OPENCODE_CONFIG_CONTENT: JSON.stringify(options.config ?? {})
1420
+ }
1421
+ });
1422
+ const url = await new Promise((resolve, reject) => {
1423
+ const id = setTimeout(() => {
1424
+ reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
1425
+ }, options.timeout);
1426
+ let output = "";
1427
+ proc.stdout?.on("data", (chunk) => {
1428
+ output += chunk.toString();
1429
+ const lines = output.split(`
1430
+ `);
1431
+ for (const line of lines) {
1432
+ if (line.startsWith("opencode server listening")) {
1433
+ const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
1434
+ if (!match) {
1435
+ throw new Error(`Failed to parse server url from output: ${line}`);
1436
+ }
1437
+ clearTimeout(id);
1438
+ resolve(match[1]);
1439
+ return;
1440
+ }
1441
+ }
1442
+ });
1443
+ proc.stderr?.on("data", (chunk) => {
1444
+ output += chunk.toString();
1445
+ });
1446
+ proc.on("exit", (code) => {
1447
+ clearTimeout(id);
1448
+ let msg = `Server exited with code ${code}`;
1449
+ if (output.trim()) {
1450
+ msg += `
1451
+ Server output: ${output}`;
1452
+ }
1453
+ reject(new Error(msg));
1454
+ });
1455
+ proc.on("error", (error) => {
1456
+ clearTimeout(id);
1457
+ reject(error);
1458
+ });
1459
+ if (options.signal) {
1460
+ options.signal.addEventListener("abort", () => {
1461
+ clearTimeout(id);
1462
+ reject(new Error("Aborted"));
1463
+ });
1464
+ }
1465
+ });
1466
+ return {
1467
+ url,
1468
+ close() {
1469
+ proc.kill();
1470
+ }
1471
+ };
1472
+ }
1473
+ // node_modules/@opencode-ai/sdk/dist/index.js
1474
+ async function createOpencode(options) {
1475
+ const server2 = await createOpencodeServer({
1476
+ ...options
1477
+ });
1478
+ const client3 = createOpencodeClient({
1479
+ baseUrl: server2.url
1480
+ });
1481
+ return {
1482
+ client: client3,
1483
+ server: server2
1484
+ };
1485
+ }
1486
+
1487
+ // src/lib/opencode.ts
1488
+ async function createOpencodeServer2(options) {
1489
+ const {
1490
+ provider,
1491
+ apiKey,
1492
+ model,
1493
+ agentName,
1494
+ agentDescription,
1495
+ agentPrompt,
1496
+ agentTools = {},
1497
+ agentPermissions = {},
1498
+ maxSteps = 30,
1499
+ linearApiKey
1500
+ } = options;
1501
+ const opcodeConfig = {
1502
+ provider: {
1503
+ [provider]: {
1504
+ options: {
1505
+ apiKey,
1506
+ timeout: false
1507
+ }
1508
+ }
1509
+ },
1510
+ ...linearApiKey && {
1511
+ mcp: {
1512
+ linear: {
1513
+ type: "remote",
1514
+ url: "https://mcp.linear.app/mcp",
1515
+ headers: {
1516
+ Authorization: `Bearer ${linearApiKey}`
1517
+ }
1518
+ }
1519
+ }
1520
+ },
1521
+ agent: {
1522
+ [agentName]: {
1523
+ description: agentDescription,
1524
+ mode: "subagent",
1525
+ model,
1526
+ prompt: agentPrompt,
1527
+ tools: agentTools,
1528
+ maxSteps,
1529
+ permission: agentPermissions
1530
+ }
1531
+ }
1532
+ };
1533
+ console.error("Starting OpenCode server...");
1534
+ const { client: client3, server: server2 } = await createOpencode({
1535
+ hostname: "127.0.0.1",
1536
+ port: 0,
1537
+ config: opcodeConfig
1538
+ });
1539
+ console.error(`✓ OpenCode server started at ${server2.url}`);
1540
+ return { client: client3, server: server2 };
1541
+ }
1542
+ function setupEventMonitoring(client3) {
1543
+ console.error("Setting up event monitoring...");
1544
+ (async () => {
1545
+ try {
1546
+ const events = await client3.event.subscribe();
1547
+ for await (const event of events.stream) {
1548
+ if (event.type === "message.part.updated") {
1549
+ const part = event.properties.part;
1550
+ if (part.type === "tool") {
1551
+ const status = part.state.status;
1552
+ const toolName = part.tool;
1553
+ if (status === "running") {
1554
+ const input = JSON.stringify(part.state.input || {}, null, 2);
1555
+ console.error(`
1556
+ [TOOL] ${toolName} - RUNNING`);
1557
+ console.error(` Input: ${input}`);
1558
+ } else if (status === "completed") {
1559
+ const output = part.state.output?.slice(0, 200) || "(no output)";
1560
+ const duration = part.state.time?.end && part.state.time?.start ? `${((part.state.time.end - part.state.time.start) / 1000).toFixed(2)}s` : "unknown";
1561
+ console.error(`
1562
+ [TOOL] ${toolName} - COMPLETED (${duration})`);
1563
+ console.error(` Output preview: ${output}${part.state.output && part.state.output.length > 200 ? "..." : ""}`);
1564
+ } else if (status === "error") {
1565
+ console.error(`
1566
+ [TOOL] ${toolName} - ERROR`);
1567
+ console.error(` Error: ${part.state.error}`);
1568
+ }
1569
+ }
1570
+ }
1571
+ if (event.type === "session.status") {
1572
+ const status = event.properties.status;
1573
+ if (String(status) === "idle") {
1574
+ console.error(`
1575
+ [STATUS] Session idle`);
1576
+ } else if (String(status) === "busy") {
1577
+ console.error(`
1578
+ [STATUS] Session busy (processing)`);
1579
+ } else if (typeof status === "object" && "attempt" in status) {
1580
+ console.error(`
1581
+ [STATUS] Session retrying (attempt ${status.attempt})`);
1582
+ if ("message" in status)
1583
+ console.error(` Reason: ${status.message}`);
1584
+ if ("next" in status)
1585
+ console.error(` Next retry in: ${status.next}ms`);
1586
+ }
1587
+ }
1588
+ if (event.type === "session.error") {
1589
+ const error = event.properties.error;
1590
+ console.error(`
1591
+ [ERROR] Session error:`, error);
1592
+ }
1593
+ }
1594
+ } catch (err) {
1595
+ console.error("Event monitoring subscription error:", err);
1596
+ }
1597
+ })();
1598
+ }
1599
+
1600
+ // src/agents/planning-agent.ts
1601
+ var AGENT_NAME = "planning-agent";
1602
+ var PROMPT_FILE = join(process.cwd(), ".github", "claude-parallel", "prompts", "plan-generation.md");
1603
+ async function main() {
1604
+ const args = process.argv.slice(2);
1605
+ if (args.length < 1) {
1606
+ console.error("Usage: planning-agent.ts <feature-description>");
1607
+ console.error("");
1608
+ console.error("Examples:");
1609
+ console.error(" # Use default (Anthropic Claude)");
1610
+ console.error(' ANTHROPIC_API_KEY=xxx planning-agent.ts "Add user authentication"');
1611
+ console.error("");
1612
+ console.error(" # Use OpenAI GPT-4");
1613
+ console.error(' PROVIDER=openai OPENAI_API_KEY=xxx planning-agent.ts "Add user authentication"');
1614
+ console.error("");
1615
+ console.error(" # Use Google Gemini");
1616
+ console.error(' PROVIDER=google GOOGLE_GENERATIVE_AI_API_KEY=xxx planning-agent.ts "Add user authentication"');
1617
+ console.error("");
1618
+ console.error("Environment variables:");
1619
+ console.error(" PROVIDER - anthropic (default), openai, or google");
1620
+ console.error(" MODEL - Override default model for the provider");
1621
+ process.exit(1);
1622
+ }
1623
+ const featureDescription = args.join(" ");
1624
+ const providerEnv = (process.env.PROVIDER || "anthropic").toLowerCase();
1625
+ validateProvider(providerEnv);
1626
+ const provider = providerEnv;
1627
+ const apiKey = getApiKey(provider);
1628
+ const model = process.env.MODEL || DEFAULT_MODELS[provider];
1629
+ console.error(`
1630
+ ${"=".repeat(60)}`);
1631
+ console.error(`Planning Agent`);
1632
+ console.error(`${"=".repeat(60)}`);
1633
+ console.error(`Provider: ${provider}`);
1634
+ console.error(`Model: ${model}`);
1635
+ console.error(`Feature: ${featureDescription}`);
1636
+ console.error("");
1637
+ let prompt;
1638
+ try {
1639
+ prompt = await readFile(PROMPT_FILE, "utf-8");
1640
+ console.error(`✓ Loaded prompt from ${PROMPT_FILE}`);
1641
+ } catch (error) {
1642
+ console.error(`✗ Failed to read prompt file: ${PROMPT_FILE}`);
1643
+ console.error("Please create a plan-generation.md file in the prompts directory");
1644
+ process.exit(1);
1645
+ }
1646
+ const { client: client3, server: server2 } = await createOpencodeServer2({
1647
+ provider,
1648
+ apiKey,
1649
+ model,
1650
+ agentName: AGENT_NAME,
1651
+ agentDescription: "Generate a comprehensive implementation plan for a given feature",
1652
+ agentPrompt: prompt,
1653
+ agentTools: {
1654
+ write: false,
1655
+ edit: false,
1656
+ bash: false,
1657
+ read: true,
1658
+ list: true,
1659
+ glob: true,
1660
+ grep: true,
1661
+ webfetch: true
1662
+ },
1663
+ agentPermissions: {
1664
+ edit: "deny",
1665
+ bash: "deny",
1666
+ webfetch: "allow"
1667
+ },
1668
+ maxSteps: 30
1669
+ });
1670
+ setupEventMonitoring(client3);
1671
+ try {
1672
+ console.error(`Creating session...`);
1673
+ const sessionResponse = await client3.session.create({
1674
+ body: { title: `Plan generation: ${featureDescription}` }
1675
+ });
1676
+ if (!sessionResponse.data) {
1677
+ throw new Error("Failed to create session: no data in response");
1678
+ }
1679
+ const session = sessionResponse.data;
1680
+ console.error(`✓ Session created: ${session.id}`);
1681
+ console.error(`Generating plan with ${AGENT_NAME}...`);
1682
+ console.error(`This may take a few moments while the AI generates the plan...`);
1683
+ const promptResponse = await client3.session.prompt({
1684
+ path: { id: session.id },
1685
+ body: {
1686
+ model: {
1687
+ providerID: provider,
1688
+ modelID: model
1689
+ },
1690
+ agent: AGENT_NAME,
1691
+ parts: [{ type: "text", text: featureDescription }]
1692
+ }
1693
+ });
1694
+ if (!promptResponse.data) {
1695
+ throw new Error("Failed to get response: no data in response");
1696
+ }
1697
+ const responseInfo = promptResponse.data.info;
1698
+ if (responseInfo?.error) {
1699
+ const err = responseInfo.error;
1700
+ const errorName = err.name;
1701
+ const errorData = "data" in err ? err.data : {};
1702
+ const errorMessage = "message" in errorData ? errorData.message : JSON.stringify(errorData);
1703
+ throw new Error(`Provider error: ${errorName}: ${errorMessage}`);
1704
+ }
1705
+ const planText = extractTextFromParts(promptResponse.data.parts);
1706
+ if (planText.length === 0) {
1707
+ throw new Error("Empty response from planning agent");
1708
+ }
1709
+ console.error("");
1710
+ console.error(`${"=".repeat(60)}`);
1711
+ console.error(`SUCCESS!`);
1712
+ console.error(`${"=".repeat(60)}`);
1713
+ console.error(`Generated plan: ${planText.length} characters`);
1714
+ console.error(`Session ID: ${session.id}`);
1715
+ console.error("");
1716
+ console.log(planText);
1717
+ process.exit(0);
1718
+ } catch (error) {
1719
+ const errorMessage = error instanceof Error ? error.message : String(error);
1720
+ console.error("");
1721
+ console.error(`${"=".repeat(60)}`);
1722
+ console.error("ERROR!");
1723
+ console.error(`${"=".repeat(60)}`);
1724
+ console.error(`Error: ${errorMessage}`);
1725
+ if (error instanceof Error && error.stack) {
1726
+ console.error("Stack trace:", error.stack);
1727
+ }
1728
+ console.error("");
1729
+ process.exit(1);
1730
+ } finally {
1731
+ console.error("Shutting down OpenCode server...");
1732
+ server2.close();
1733
+ }
1734
+ }
1735
+ main().catch((error) => {
1736
+ console.error("FATAL ERROR:", error);
1737
+ process.exit(1);
1738
+ });