opencode-teammate 0.1.0 → 0.2.0-next.1

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 (52) hide show
  1. package/dist/bin/mate +36 -0
  2. package/dist/plugin.d.ts +222 -0
  3. package/dist/plugin.js +3634 -0
  4. package/package.json +17 -23
  5. package/.bunli/commands.gen.ts +0 -87
  6. package/.github/workflows/ci.yml +0 -31
  7. package/.github/workflows/release.yml +0 -140
  8. package/.oxfmtrc.json +0 -3
  9. package/.oxlintrc.json +0 -4
  10. package/.zed/settings.json +0 -76
  11. package/bunli.config.ts +0 -11
  12. package/bunup.config.ts +0 -31
  13. package/src/adapters/assets/index.ts +0 -1
  14. package/src/adapters/assets/specifications.ts +0 -70
  15. package/src/adapters/beads/agents.ts +0 -105
  16. package/src/adapters/beads/config.ts +0 -17
  17. package/src/adapters/beads/index.ts +0 -4
  18. package/src/adapters/beads/issues.ts +0 -156
  19. package/src/adapters/beads/specifications.ts +0 -55
  20. package/src/adapters/environments/index.ts +0 -43
  21. package/src/adapters/environments/worktrees.ts +0 -78
  22. package/src/adapters/teammates/index.ts +0 -15
  23. package/src/assets/agent/planner.md +0 -196
  24. package/src/assets/command/brainstorm.md +0 -60
  25. package/src/assets/command/specify.md +0 -135
  26. package/src/assets/command/work.md +0 -247
  27. package/src/assets/index.ts +0 -37
  28. package/src/cli/commands/manifest.ts +0 -6
  29. package/src/cli/commands/spec/sync.ts +0 -47
  30. package/src/cli/commands/work.ts +0 -110
  31. package/src/cli/index.ts +0 -11
  32. package/src/plugin.ts +0 -45
  33. package/src/tools/i-am-done.ts +0 -44
  34. package/src/tools/i-am-stuck.ts +0 -49
  35. package/src/tools/index.ts +0 -2
  36. package/src/use-cases/index.ts +0 -5
  37. package/src/use-cases/inject-beads-issue.ts +0 -97
  38. package/src/use-cases/sync-specifications.ts +0 -48
  39. package/src/use-cases/sync-teammates.ts +0 -35
  40. package/src/use-cases/track-specs.ts +0 -91
  41. package/src/use-cases/work-on-issue.ts +0 -110
  42. package/src/utils/chain.ts +0 -60
  43. package/src/utils/frontmatter.spec.ts +0 -491
  44. package/src/utils/frontmatter.ts +0 -317
  45. package/src/utils/opencode.ts +0 -102
  46. package/src/utils/polling.ts +0 -41
  47. package/src/utils/projects.ts +0 -35
  48. package/src/utils/shell/client.spec.ts +0 -106
  49. package/src/utils/shell/client.ts +0 -117
  50. package/src/utils/shell/error.ts +0 -29
  51. package/src/utils/shell/index.ts +0 -2
  52. package/tsconfig.json +0 -9
package/dist/plugin.js ADDED
@@ -0,0 +1,3634 @@
1
+ // @bun
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true,
8
+ configurable: true,
9
+ set: (newValue) => all[name] = () => newValue
10
+ });
11
+ };
12
+
13
+ // src/assets/index.ts
14
+ var {Glob, $ } = globalThis.Bun;
15
+ import * as path from "path";
16
+
17
+ // node_modules/radashi/dist/radashi.js
18
+ function first(array, defaultValue) {
19
+ return (array == null ? undefined : array.length) > 0 ? array[0] : defaultValue;
20
+ }
21
+ function objectify(array, getKey, getValue = (item) => item) {
22
+ return array.reduce((acc, item, i) => {
23
+ acc[getKey(item, i)] = getValue(item, i);
24
+ return acc;
25
+ }, {});
26
+ }
27
+ function sift(array) {
28
+ return (array == null ? undefined : array.filter((x) => !!x)) ?? [];
29
+ }
30
+ async function all(input) {
31
+ const errors = [];
32
+ const onError = (err) => {
33
+ errors.push(err);
34
+ };
35
+ let output;
36
+ if (isArray(input)) {
37
+ output = await Promise.all(input.map((value) => Promise.resolve(value).catch(onError)));
38
+ } else {
39
+ output = { ...input };
40
+ await Promise.all(Object.keys(output).map(async (key) => {
41
+ output[key] = await Promise.resolve(output[key]).catch(onError);
42
+ }));
43
+ }
44
+ if (errors.length > 0) {
45
+ throw new AggregateErrorOrPolyfill(errors);
46
+ }
47
+ return output;
48
+ }
49
+ async function toResult(promise) {
50
+ try {
51
+ const result = await promise;
52
+ return [undefined, result];
53
+ } catch (error) {
54
+ if (isError(error)) {
55
+ return [error, undefined];
56
+ }
57
+ throw error;
58
+ }
59
+ }
60
+ function tryit(func) {
61
+ return (...args) => {
62
+ try {
63
+ const result = func(...args);
64
+ return isPromise(result) ? result.then((value) => [undefined, value], (err) => [err, undefined]) : [undefined, result];
65
+ } catch (err) {
66
+ return [err, undefined];
67
+ }
68
+ };
69
+ }
70
+ function withResolvers() {
71
+ let resolve;
72
+ let reject;
73
+ const promise = new Promise((res, rej) => {
74
+ resolve = res;
75
+ reject = rej;
76
+ });
77
+ return { resolve, reject, promise };
78
+ }
79
+ function noop() {}
80
+ function listify(obj, toItem) {
81
+ if (!obj) {
82
+ return [];
83
+ }
84
+ const entries = Object.entries(obj);
85
+ if (entries.length === 0) {
86
+ return [];
87
+ }
88
+ return entries.reduce((acc, entry) => {
89
+ acc.push(toItem(entry[0], entry[1]));
90
+ return acc;
91
+ }, []);
92
+ }
93
+ function shake(obj, filter = (value) => value === undefined) {
94
+ if (!obj) {
95
+ return {};
96
+ }
97
+ return Object.keys(obj).reduce((acc, key) => {
98
+ if (!filter(obj[key])) {
99
+ acc[key] = obj[key];
100
+ }
101
+ return acc;
102
+ }, {});
103
+ }
104
+ var AggregateErrorOrPolyfill = /* @__PURE__ */ (() => globalThis.AggregateError ?? class AggregateError extends Error {
105
+ constructor(errors = []) {
106
+ var _a, _b;
107
+ super();
108
+ const name = ((_a = errors.find((e) => e.name)) == null ? undefined : _a.name) ?? "";
109
+ this.name = `AggregateError(${name}...)`;
110
+ this.message = `AggregateError with ${errors.length} errors`;
111
+ this.stack = ((_b = errors.find((e) => e.stack)) == null ? undefined : _b.stack) ?? this.stack;
112
+ this.errors = errors;
113
+ }
114
+ })();
115
+ var SemaphorePermit = class {
116
+ constructor(semaphore, request, weight) {
117
+ this.semaphore = semaphore;
118
+ this.request = request;
119
+ this.weight = weight;
120
+ }
121
+ release() {
122
+ this.semaphore.release(this);
123
+ this.release = noop;
124
+ }
125
+ };
126
+ var Semaphore = class {
127
+ constructor(maxCapacity) {
128
+ this.maxCapacity = maxCapacity;
129
+ this.queue = [];
130
+ if (maxCapacity <= 0) {
131
+ throw new Error("maxCapacity must be > 0");
132
+ }
133
+ this.capacity = maxCapacity;
134
+ }
135
+ get queueLength() {
136
+ return this.queue.length;
137
+ }
138
+ async acquire({
139
+ signal,
140
+ weight = 1
141
+ } = {}) {
142
+ if (weight <= 0) {
143
+ throw new Error("weight must be > 0");
144
+ }
145
+ if (weight > this.maxCapacity) {
146
+ throw new Error("weight must be \u2264 maxCapacity");
147
+ }
148
+ const request = withResolvers();
149
+ const permit = new SemaphorePermit(this, request, weight);
150
+ if (signal) {
151
+ const abort = () => {
152
+ const index = this.queue.indexOf(permit);
153
+ if (index >= 0) {
154
+ this.queue.splice(index, 1);
155
+ request.reject(signal.reason);
156
+ }
157
+ };
158
+ signal.addEventListener("abort", abort);
159
+ const cleanup = () => {
160
+ signal.removeEventListener("abort", abort);
161
+ };
162
+ request.promise.then(cleanup, cleanup);
163
+ }
164
+ if (this.capacity < weight) {
165
+ this.queue.push(permit);
166
+ await request.promise;
167
+ } else {
168
+ this.capacity -= weight;
169
+ }
170
+ return permit;
171
+ }
172
+ reject(error) {
173
+ this.acquire = () => Promise.reject(error);
174
+ this.queue.forEach((permit) => permit.request.reject(error));
175
+ this.queue = [];
176
+ }
177
+ release(permit) {
178
+ this.capacity += permit.weight;
179
+ const nextPermit = this.queue[0];
180
+ if (nextPermit && this.capacity >= nextPermit.weight) {
181
+ this.capacity -= nextPermit.weight;
182
+ this.queue.shift();
183
+ nextPermit.request.resolve();
184
+ }
185
+ }
186
+ };
187
+ function dedent(text, ...values) {
188
+ var _a;
189
+ if (isArray(text)) {
190
+ if (values.length > 0) {
191
+ return dedent(text.reduce((acc, input, i) => {
192
+ var _a2;
193
+ let value = String(values[i] ?? "");
194
+ const indent2 = value.includes(`
195
+ `) && ((_a2 = input.match(/[ \t]*(?=[^\n]*$)/)) == null ? undefined : _a2[0]);
196
+ if (indent2) {
197
+ value = value.replace(/\n(?=[^\n]*?\S)/g, `
198
+ ` + indent2);
199
+ }
200
+ return acc + input + value;
201
+ }, ""));
202
+ }
203
+ text = text[0];
204
+ }
205
+ const indent = values[0] ?? ((_a = text.match(/^[ \t]*(?=\S)/m)) == null ? undefined : _a[0]);
206
+ const output = indent ? text.replace(new RegExp(`^${indent}`, "gm"), "") : text;
207
+ return output.replace(/^[ \t]*\n|\n[ \t]*$/g, "");
208
+ }
209
+ function assert(condition, message) {
210
+ if (!condition) {
211
+ throw message instanceof Error ? message : new Error(message ?? "Assertion failed");
212
+ }
213
+ }
214
+ var isArray = /* @__PURE__ */ (() => Array.isArray)();
215
+ function isBoolean(value) {
216
+ return typeof value === "boolean";
217
+ }
218
+ function isDate(value) {
219
+ return isTagged(value, "[object Date]");
220
+ }
221
+ function isEmpty(value) {
222
+ if (typeof value !== "object" || value === null) {
223
+ return !value || value === true;
224
+ }
225
+ if (isDate(value)) {
226
+ return Number.isNaN(value.getTime());
227
+ }
228
+ const length = value.length;
229
+ if (isNumber(length)) {
230
+ return length === 0;
231
+ }
232
+ const size = value.size;
233
+ if (isNumber(size)) {
234
+ return size === 0;
235
+ }
236
+ const keys2 = Object.keys(value).length;
237
+ return keys2 === 0;
238
+ }
239
+ function isError(value) {
240
+ return isTagged(value, "[object Error]");
241
+ }
242
+ function isFunction(value) {
243
+ return typeof value === "function";
244
+ }
245
+ function isNumber(value) {
246
+ return typeof value === "number" && !Number.isNaN(value);
247
+ }
248
+ function isObject(value) {
249
+ return isTagged(value, "[object Object]");
250
+ }
251
+ function isPromise(value) {
252
+ return !!value && isFunction(value.then);
253
+ }
254
+ function isTagged(value, tag) {
255
+ return Object.prototype.toString.call(value) === tag;
256
+ }
257
+
258
+ // src/assets/index.ts
259
+ var MARKDOWNS = new Glob("**/*.md");
260
+ async function install(destination) {
261
+ const $$ = $.cwd(destination);
262
+ await $$`mkdir -p .opencode/command && mkdir -p .opencode/agent`;
263
+ const assets = await all(objectify(Array.from(MARKDOWNS.scanSync({ cwd: import.meta.dir })), (fileName) => fileName, async (fileName) => {
264
+ const parsed = path.parse(fileName);
265
+ const output = path.format({
266
+ ...parsed,
267
+ base: `mate.${parsed.base}`,
268
+ name: `mate.${parsed.name}`
269
+ });
270
+ const [error] = await toResult($$`cp ${import.meta.dir}/${fileName} ${destination}/.opencode/${output}`.quiet());
271
+ if (error)
272
+ ;
273
+ return error === undefined;
274
+ }));
275
+ return assets;
276
+ }
277
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/core/serverSentEvents.gen.js
278
+ var createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
279
+ let lastEventId;
280
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
281
+ const createStream = async function* () {
282
+ let retryDelay = sseDefaultRetryDelay ?? 3000;
283
+ let attempt = 0;
284
+ const signal = options.signal ?? new AbortController().signal;
285
+ while (true) {
286
+ if (signal.aborted)
287
+ break;
288
+ attempt++;
289
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
290
+ if (lastEventId !== undefined) {
291
+ headers.set("Last-Event-ID", lastEventId);
292
+ }
293
+ try {
294
+ const requestInit = {
295
+ redirect: "follow",
296
+ ...options,
297
+ body: options.serializedBody,
298
+ headers,
299
+ signal
300
+ };
301
+ let request = new Request(url, requestInit);
302
+ if (onRequest) {
303
+ request = await onRequest(url, requestInit);
304
+ }
305
+ const _fetch = options.fetch ?? globalThis.fetch;
306
+ const response = await _fetch(request);
307
+ if (!response.ok)
308
+ throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
309
+ if (!response.body)
310
+ throw new Error("No body in SSE response");
311
+ const reader = response.body.pipeThrough(new TextDecoderStream).getReader();
312
+ let buffer = "";
313
+ const abortHandler = () => {
314
+ try {
315
+ reader.cancel();
316
+ } catch {}
317
+ };
318
+ signal.addEventListener("abort", abortHandler);
319
+ try {
320
+ while (true) {
321
+ const { done, value } = await reader.read();
322
+ if (done)
323
+ break;
324
+ buffer += value;
325
+ buffer = buffer.replace(/\r\n/g, `
326
+ `).replace(/\r/g, `
327
+ `);
328
+ const chunks = buffer.split(`
329
+
330
+ `);
331
+ buffer = chunks.pop() ?? "";
332
+ for (const chunk of chunks) {
333
+ const lines = chunk.split(`
334
+ `);
335
+ const dataLines = [];
336
+ let eventName;
337
+ for (const line of lines) {
338
+ if (line.startsWith("data:")) {
339
+ dataLines.push(line.replace(/^data:\s*/, ""));
340
+ } else if (line.startsWith("event:")) {
341
+ eventName = line.replace(/^event:\s*/, "");
342
+ } else if (line.startsWith("id:")) {
343
+ lastEventId = line.replace(/^id:\s*/, "");
344
+ } else if (line.startsWith("retry:")) {
345
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
346
+ if (!Number.isNaN(parsed)) {
347
+ retryDelay = parsed;
348
+ }
349
+ }
350
+ }
351
+ let data;
352
+ let parsedJson = false;
353
+ if (dataLines.length) {
354
+ const rawData = dataLines.join(`
355
+ `);
356
+ try {
357
+ data = JSON.parse(rawData);
358
+ parsedJson = true;
359
+ } catch {
360
+ data = rawData;
361
+ }
362
+ }
363
+ if (parsedJson) {
364
+ if (responseValidator) {
365
+ await responseValidator(data);
366
+ }
367
+ if (responseTransformer) {
368
+ data = await responseTransformer(data);
369
+ }
370
+ }
371
+ onSseEvent?.({
372
+ data,
373
+ event: eventName,
374
+ id: lastEventId,
375
+ retry: retryDelay
376
+ });
377
+ if (dataLines.length) {
378
+ yield data;
379
+ }
380
+ }
381
+ }
382
+ } finally {
383
+ signal.removeEventListener("abort", abortHandler);
384
+ reader.releaseLock();
385
+ }
386
+ break;
387
+ } catch (error) {
388
+ onSseError?.(error);
389
+ if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) {
390
+ break;
391
+ }
392
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
393
+ await sleep(backoff);
394
+ }
395
+ }
396
+ };
397
+ const stream = createStream();
398
+ return { stream };
399
+ };
400
+
401
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/core/pathSerializer.gen.js
402
+ var separatorArrayExplode = (style) => {
403
+ switch (style) {
404
+ case "label":
405
+ return ".";
406
+ case "matrix":
407
+ return ";";
408
+ case "simple":
409
+ return ",";
410
+ default:
411
+ return "&";
412
+ }
413
+ };
414
+ var separatorArrayNoExplode = (style) => {
415
+ switch (style) {
416
+ case "form":
417
+ return ",";
418
+ case "pipeDelimited":
419
+ return "|";
420
+ case "spaceDelimited":
421
+ return "%20";
422
+ default:
423
+ return ",";
424
+ }
425
+ };
426
+ var separatorObjectExplode = (style) => {
427
+ switch (style) {
428
+ case "label":
429
+ return ".";
430
+ case "matrix":
431
+ return ";";
432
+ case "simple":
433
+ return ",";
434
+ default:
435
+ return "&";
436
+ }
437
+ };
438
+ var serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
439
+ if (!explode) {
440
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
441
+ switch (style) {
442
+ case "label":
443
+ return `.${joinedValues2}`;
444
+ case "matrix":
445
+ return `;${name}=${joinedValues2}`;
446
+ case "simple":
447
+ return joinedValues2;
448
+ default:
449
+ return `${name}=${joinedValues2}`;
450
+ }
451
+ }
452
+ const separator = separatorArrayExplode(style);
453
+ const joinedValues = value.map((v) => {
454
+ if (style === "label" || style === "simple") {
455
+ return allowReserved ? v : encodeURIComponent(v);
456
+ }
457
+ return serializePrimitiveParam({
458
+ allowReserved,
459
+ name,
460
+ value: v
461
+ });
462
+ }).join(separator);
463
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
464
+ };
465
+ var serializePrimitiveParam = ({ allowReserved, name, value }) => {
466
+ if (value === undefined || value === null) {
467
+ return "";
468
+ }
469
+ if (typeof value === "object") {
470
+ throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");
471
+ }
472
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
473
+ };
474
+ var serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
475
+ if (value instanceof Date) {
476
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
477
+ }
478
+ if (style !== "deepObject" && !explode) {
479
+ let values = [];
480
+ Object.entries(value).forEach(([key, v]) => {
481
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
482
+ });
483
+ const joinedValues2 = values.join(",");
484
+ switch (style) {
485
+ case "form":
486
+ return `${name}=${joinedValues2}`;
487
+ case "label":
488
+ return `.${joinedValues2}`;
489
+ case "matrix":
490
+ return `;${name}=${joinedValues2}`;
491
+ default:
492
+ return joinedValues2;
493
+ }
494
+ }
495
+ const separator = separatorObjectExplode(style);
496
+ const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
497
+ allowReserved,
498
+ name: style === "deepObject" ? `${name}[${key}]` : key,
499
+ value: v
500
+ })).join(separator);
501
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
502
+ };
503
+
504
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/core/utils.gen.js
505
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
506
+ var defaultPathSerializer = ({ path: path2, url: _url }) => {
507
+ let url = _url;
508
+ const matches = _url.match(PATH_PARAM_RE);
509
+ if (matches) {
510
+ for (const match of matches) {
511
+ let explode = false;
512
+ let name = match.substring(1, match.length - 1);
513
+ let style = "simple";
514
+ if (name.endsWith("*")) {
515
+ explode = true;
516
+ name = name.substring(0, name.length - 1);
517
+ }
518
+ if (name.startsWith(".")) {
519
+ name = name.substring(1);
520
+ style = "label";
521
+ } else if (name.startsWith(";")) {
522
+ name = name.substring(1);
523
+ style = "matrix";
524
+ }
525
+ const value = path2[name];
526
+ if (value === undefined || value === null) {
527
+ continue;
528
+ }
529
+ if (Array.isArray(value)) {
530
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
531
+ continue;
532
+ }
533
+ if (typeof value === "object") {
534
+ url = url.replace(match, serializeObjectParam({
535
+ explode,
536
+ name,
537
+ style,
538
+ value,
539
+ valueOnly: true
540
+ }));
541
+ continue;
542
+ }
543
+ if (style === "matrix") {
544
+ url = url.replace(match, `;${serializePrimitiveParam({
545
+ name,
546
+ value
547
+ })}`);
548
+ continue;
549
+ }
550
+ const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
551
+ url = url.replace(match, replaceValue);
552
+ }
553
+ }
554
+ return url;
555
+ };
556
+ var getUrl = ({ baseUrl, path: path2, query, querySerializer, url: _url }) => {
557
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
558
+ let url = (baseUrl ?? "") + pathUrl;
559
+ if (path2) {
560
+ url = defaultPathSerializer({ path: path2, url });
561
+ }
562
+ let search = query ? querySerializer(query) : "";
563
+ if (search.startsWith("?")) {
564
+ search = search.substring(1);
565
+ }
566
+ if (search) {
567
+ url += `?${search}`;
568
+ }
569
+ return url;
570
+ };
571
+ function getValidRequestBody(options) {
572
+ const hasBody = options.body !== undefined;
573
+ const isSerializedBody = hasBody && options.bodySerializer;
574
+ if (isSerializedBody) {
575
+ if ("serializedBody" in options) {
576
+ const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== "";
577
+ return hasSerializedBody ? options.serializedBody : null;
578
+ }
579
+ return options.body !== "" ? options.body : null;
580
+ }
581
+ if (hasBody) {
582
+ return options.body;
583
+ }
584
+ return;
585
+ }
586
+
587
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/core/auth.gen.js
588
+ var getAuthToken = async (auth, callback) => {
589
+ const token = typeof callback === "function" ? await callback(auth) : callback;
590
+ if (!token) {
591
+ return;
592
+ }
593
+ if (auth.scheme === "bearer") {
594
+ return `Bearer ${token}`;
595
+ }
596
+ if (auth.scheme === "basic") {
597
+ return `Basic ${btoa(token)}`;
598
+ }
599
+ return token;
600
+ };
601
+
602
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/core/bodySerializer.gen.js
603
+ var jsonBodySerializer = {
604
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
605
+ };
606
+
607
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/client/utils.gen.js
608
+ var createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
609
+ const querySerializer = (queryParams) => {
610
+ const search = [];
611
+ if (queryParams && typeof queryParams === "object") {
612
+ for (const name in queryParams) {
613
+ const value = queryParams[name];
614
+ if (value === undefined || value === null) {
615
+ continue;
616
+ }
617
+ const options = parameters[name] || args;
618
+ if (Array.isArray(value)) {
619
+ const serializedArray = serializeArrayParam({
620
+ allowReserved: options.allowReserved,
621
+ explode: true,
622
+ name,
623
+ style: "form",
624
+ value,
625
+ ...options.array
626
+ });
627
+ if (serializedArray)
628
+ search.push(serializedArray);
629
+ } else if (typeof value === "object") {
630
+ const serializedObject = serializeObjectParam({
631
+ allowReserved: options.allowReserved,
632
+ explode: true,
633
+ name,
634
+ style: "deepObject",
635
+ value,
636
+ ...options.object
637
+ });
638
+ if (serializedObject)
639
+ search.push(serializedObject);
640
+ } else {
641
+ const serializedPrimitive = serializePrimitiveParam({
642
+ allowReserved: options.allowReserved,
643
+ name,
644
+ value
645
+ });
646
+ if (serializedPrimitive)
647
+ search.push(serializedPrimitive);
648
+ }
649
+ }
650
+ }
651
+ return search.join("&");
652
+ };
653
+ return querySerializer;
654
+ };
655
+ var getParseAs = (contentType) => {
656
+ if (!contentType) {
657
+ return "stream";
658
+ }
659
+ const cleanContent = contentType.split(";")[0]?.trim();
660
+ if (!cleanContent) {
661
+ return;
662
+ }
663
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
664
+ return "json";
665
+ }
666
+ if (cleanContent === "multipart/form-data") {
667
+ return "formData";
668
+ }
669
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
670
+ return "blob";
671
+ }
672
+ if (cleanContent.startsWith("text/")) {
673
+ return "text";
674
+ }
675
+ return;
676
+ };
677
+ var checkForExistence = (options, name) => {
678
+ if (!name) {
679
+ return false;
680
+ }
681
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
682
+ return true;
683
+ }
684
+ return false;
685
+ };
686
+ var setAuthParams = async ({ security, ...options }) => {
687
+ for (const auth of security) {
688
+ if (checkForExistence(options, auth.name)) {
689
+ continue;
690
+ }
691
+ const token = await getAuthToken(auth, options.auth);
692
+ if (!token) {
693
+ continue;
694
+ }
695
+ const name = auth.name ?? "Authorization";
696
+ switch (auth.in) {
697
+ case "query":
698
+ if (!options.query) {
699
+ options.query = {};
700
+ }
701
+ options.query[name] = token;
702
+ break;
703
+ case "cookie":
704
+ options.headers.append("Cookie", `${name}=${token}`);
705
+ break;
706
+ case "header":
707
+ default:
708
+ options.headers.set(name, token);
709
+ break;
710
+ }
711
+ }
712
+ };
713
+ var buildUrl = (options) => getUrl({
714
+ baseUrl: options.baseUrl,
715
+ path: options.path,
716
+ query: options.query,
717
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
718
+ url: options.url
719
+ });
720
+ var mergeConfigs = (a, b) => {
721
+ const config = { ...a, ...b };
722
+ if (config.baseUrl?.endsWith("/")) {
723
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
724
+ }
725
+ config.headers = mergeHeaders(a.headers, b.headers);
726
+ return config;
727
+ };
728
+ var headersEntries = (headers) => {
729
+ const entries = [];
730
+ headers.forEach((value, key) => {
731
+ entries.push([key, value]);
732
+ });
733
+ return entries;
734
+ };
735
+ var mergeHeaders = (...headers) => {
736
+ const mergedHeaders = new Headers;
737
+ for (const header of headers) {
738
+ if (!header) {
739
+ continue;
740
+ }
741
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
742
+ for (const [key, value] of iterator) {
743
+ if (value === null) {
744
+ mergedHeaders.delete(key);
745
+ } else if (Array.isArray(value)) {
746
+ for (const v of value) {
747
+ mergedHeaders.append(key, v);
748
+ }
749
+ } else if (value !== undefined) {
750
+ mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
751
+ }
752
+ }
753
+ }
754
+ return mergedHeaders;
755
+ };
756
+
757
+ class Interceptors {
758
+ fns = [];
759
+ clear() {
760
+ this.fns = [];
761
+ }
762
+ eject(id) {
763
+ const index = this.getInterceptorIndex(id);
764
+ if (this.fns[index]) {
765
+ this.fns[index] = null;
766
+ }
767
+ }
768
+ exists(id) {
769
+ const index = this.getInterceptorIndex(id);
770
+ return Boolean(this.fns[index]);
771
+ }
772
+ getInterceptorIndex(id) {
773
+ if (typeof id === "number") {
774
+ return this.fns[id] ? id : -1;
775
+ }
776
+ return this.fns.indexOf(id);
777
+ }
778
+ update(id, fn) {
779
+ const index = this.getInterceptorIndex(id);
780
+ if (this.fns[index]) {
781
+ this.fns[index] = fn;
782
+ return id;
783
+ }
784
+ return false;
785
+ }
786
+ use(fn) {
787
+ this.fns.push(fn);
788
+ return this.fns.length - 1;
789
+ }
790
+ }
791
+ var createInterceptors = () => ({
792
+ error: new Interceptors,
793
+ request: new Interceptors,
794
+ response: new Interceptors
795
+ });
796
+ var defaultQuerySerializer = createQuerySerializer({
797
+ allowReserved: false,
798
+ array: {
799
+ explode: true,
800
+ style: "form"
801
+ },
802
+ object: {
803
+ explode: true,
804
+ style: "deepObject"
805
+ }
806
+ });
807
+ var defaultHeaders = {
808
+ "Content-Type": "application/json"
809
+ };
810
+ var createConfig = (override = {}) => ({
811
+ ...jsonBodySerializer,
812
+ headers: defaultHeaders,
813
+ parseAs: "auto",
814
+ querySerializer: defaultQuerySerializer,
815
+ ...override
816
+ });
817
+
818
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/client/client.gen.js
819
+ var createClient = (config = {}) => {
820
+ let _config = mergeConfigs(createConfig(), config);
821
+ const getConfig = () => ({ ..._config });
822
+ const setConfig = (config2) => {
823
+ _config = mergeConfigs(_config, config2);
824
+ return getConfig();
825
+ };
826
+ const interceptors = createInterceptors();
827
+ const beforeRequest = async (options) => {
828
+ const opts = {
829
+ ..._config,
830
+ ...options,
831
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
832
+ headers: mergeHeaders(_config.headers, options.headers),
833
+ serializedBody: undefined
834
+ };
835
+ if (opts.security) {
836
+ await setAuthParams({
837
+ ...opts,
838
+ security: opts.security
839
+ });
840
+ }
841
+ if (opts.requestValidator) {
842
+ await opts.requestValidator(opts);
843
+ }
844
+ if (opts.body !== undefined && opts.bodySerializer) {
845
+ opts.serializedBody = opts.bodySerializer(opts.body);
846
+ }
847
+ if (opts.body === undefined || opts.serializedBody === "") {
848
+ opts.headers.delete("Content-Type");
849
+ }
850
+ const url = buildUrl(opts);
851
+ return { opts, url };
852
+ };
853
+ const request = async (options) => {
854
+ const { opts, url } = await beforeRequest(options);
855
+ const requestInit = {
856
+ redirect: "follow",
857
+ ...opts,
858
+ body: getValidRequestBody(opts)
859
+ };
860
+ let request2 = new Request(url, requestInit);
861
+ for (const fn of interceptors.request.fns) {
862
+ if (fn) {
863
+ request2 = await fn(request2, opts);
864
+ }
865
+ }
866
+ const _fetch = opts.fetch;
867
+ let response;
868
+ try {
869
+ response = await _fetch(request2);
870
+ } catch (error2) {
871
+ let finalError2 = error2;
872
+ for (const fn of interceptors.error.fns) {
873
+ if (fn) {
874
+ finalError2 = await fn(error2, undefined, request2, opts);
875
+ }
876
+ }
877
+ finalError2 = finalError2 || {};
878
+ if (opts.throwOnError) {
879
+ throw finalError2;
880
+ }
881
+ return opts.responseStyle === "data" ? undefined : {
882
+ error: finalError2,
883
+ request: request2,
884
+ response: undefined
885
+ };
886
+ }
887
+ for (const fn of interceptors.response.fns) {
888
+ if (fn) {
889
+ response = await fn(response, request2, opts);
890
+ }
891
+ }
892
+ const result = {
893
+ request: request2,
894
+ response
895
+ };
896
+ if (response.ok) {
897
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
898
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
899
+ let emptyData;
900
+ switch (parseAs) {
901
+ case "arrayBuffer":
902
+ case "blob":
903
+ case "text":
904
+ emptyData = await response[parseAs]();
905
+ break;
906
+ case "formData":
907
+ emptyData = new FormData;
908
+ break;
909
+ case "stream":
910
+ emptyData = response.body;
911
+ break;
912
+ case "json":
913
+ default:
914
+ emptyData = {};
915
+ break;
916
+ }
917
+ return opts.responseStyle === "data" ? emptyData : {
918
+ data: emptyData,
919
+ ...result
920
+ };
921
+ }
922
+ let data;
923
+ switch (parseAs) {
924
+ case "arrayBuffer":
925
+ case "blob":
926
+ case "formData":
927
+ case "text":
928
+ data = await response[parseAs]();
929
+ break;
930
+ case "json": {
931
+ const text = await response.text();
932
+ data = text ? JSON.parse(text) : {};
933
+ break;
934
+ }
935
+ case "stream":
936
+ return opts.responseStyle === "data" ? response.body : {
937
+ data: response.body,
938
+ ...result
939
+ };
940
+ }
941
+ if (parseAs === "json") {
942
+ if (opts.responseValidator) {
943
+ await opts.responseValidator(data);
944
+ }
945
+ if (opts.responseTransformer) {
946
+ data = await opts.responseTransformer(data);
947
+ }
948
+ }
949
+ return opts.responseStyle === "data" ? data : {
950
+ data,
951
+ ...result
952
+ };
953
+ }
954
+ const textError = await response.text();
955
+ let jsonError;
956
+ try {
957
+ jsonError = JSON.parse(textError);
958
+ } catch {}
959
+ const error = jsonError ?? textError;
960
+ let finalError = error;
961
+ for (const fn of interceptors.error.fns) {
962
+ if (fn) {
963
+ finalError = await fn(error, response, request2, opts);
964
+ }
965
+ }
966
+ finalError = finalError || {};
967
+ if (opts.throwOnError) {
968
+ throw finalError;
969
+ }
970
+ return opts.responseStyle === "data" ? undefined : {
971
+ error: finalError,
972
+ ...result
973
+ };
974
+ };
975
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
976
+ const makeSseFn = (method) => async (options) => {
977
+ const { opts, url } = await beforeRequest(options);
978
+ return createSseClient({
979
+ ...opts,
980
+ body: opts.body,
981
+ headers: opts.headers,
982
+ method,
983
+ onRequest: async (url2, init) => {
984
+ let request2 = new Request(url2, init);
985
+ for (const fn of interceptors.request.fns) {
986
+ if (fn) {
987
+ request2 = await fn(request2, opts);
988
+ }
989
+ }
990
+ return request2;
991
+ },
992
+ serializedBody: getValidRequestBody(opts),
993
+ url
994
+ });
995
+ };
996
+ return {
997
+ buildUrl,
998
+ connect: makeMethodFn("CONNECT"),
999
+ delete: makeMethodFn("DELETE"),
1000
+ get: makeMethodFn("GET"),
1001
+ getConfig,
1002
+ head: makeMethodFn("HEAD"),
1003
+ interceptors,
1004
+ options: makeMethodFn("OPTIONS"),
1005
+ patch: makeMethodFn("PATCH"),
1006
+ post: makeMethodFn("POST"),
1007
+ put: makeMethodFn("PUT"),
1008
+ request,
1009
+ setConfig,
1010
+ sse: {
1011
+ connect: makeSseFn("CONNECT"),
1012
+ delete: makeSseFn("DELETE"),
1013
+ get: makeSseFn("GET"),
1014
+ head: makeSseFn("HEAD"),
1015
+ options: makeSseFn("OPTIONS"),
1016
+ patch: makeSseFn("PATCH"),
1017
+ post: makeSseFn("POST"),
1018
+ put: makeSseFn("PUT"),
1019
+ trace: makeSseFn("TRACE")
1020
+ },
1021
+ trace: makeMethodFn("TRACE")
1022
+ };
1023
+ };
1024
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/core/params.gen.js
1025
+ var extraPrefixesMap = {
1026
+ $body_: "body",
1027
+ $headers_: "headers",
1028
+ $path_: "path",
1029
+ $query_: "query"
1030
+ };
1031
+ var extraPrefixes = Object.entries(extraPrefixesMap);
1032
+ var buildKeyMap = (fields, map) => {
1033
+ if (!map) {
1034
+ map = new Map;
1035
+ }
1036
+ for (const config of fields) {
1037
+ if ("in" in config) {
1038
+ if (config.key) {
1039
+ map.set(config.key, {
1040
+ in: config.in,
1041
+ map: config.map
1042
+ });
1043
+ }
1044
+ } else if ("key" in config) {
1045
+ map.set(config.key, {
1046
+ map: config.map
1047
+ });
1048
+ } else if (config.args) {
1049
+ buildKeyMap(config.args, map);
1050
+ }
1051
+ }
1052
+ return map;
1053
+ };
1054
+ var stripEmptySlots = (params) => {
1055
+ for (const [slot, value] of Object.entries(params)) {
1056
+ if (value && typeof value === "object" && !Object.keys(value).length) {
1057
+ delete params[slot];
1058
+ }
1059
+ }
1060
+ };
1061
+ var buildClientParams = (args, fields) => {
1062
+ const params = {
1063
+ body: {},
1064
+ headers: {},
1065
+ path: {},
1066
+ query: {}
1067
+ };
1068
+ const map = buildKeyMap(fields);
1069
+ let config;
1070
+ for (const [index, arg] of args.entries()) {
1071
+ if (fields[index]) {
1072
+ config = fields[index];
1073
+ }
1074
+ if (!config) {
1075
+ continue;
1076
+ }
1077
+ if ("in" in config) {
1078
+ if (config.key) {
1079
+ const field = map.get(config.key);
1080
+ const name = field.map || config.key;
1081
+ if (field.in) {
1082
+ params[field.in][name] = arg;
1083
+ }
1084
+ } else {
1085
+ params.body = arg;
1086
+ }
1087
+ } else {
1088
+ for (const [key, value] of Object.entries(arg ?? {})) {
1089
+ const field = map.get(key);
1090
+ if (field) {
1091
+ if (field.in) {
1092
+ const name = field.map || key;
1093
+ params[field.in][name] = value;
1094
+ } else {
1095
+ params[field.map] = value;
1096
+ }
1097
+ } else {
1098
+ const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
1099
+ if (extra) {
1100
+ const [prefix, slot] = extra;
1101
+ params[slot][key.slice(prefix.length)] = value;
1102
+ } else if ("allowExtra" in config && config.allowExtra) {
1103
+ for (const [slot, allowed] of Object.entries(config.allowExtra)) {
1104
+ if (allowed) {
1105
+ params[slot][key] = value;
1106
+ break;
1107
+ }
1108
+ }
1109
+ }
1110
+ }
1111
+ }
1112
+ }
1113
+ }
1114
+ stripEmptySlots(params);
1115
+ return params;
1116
+ };
1117
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/client.gen.js
1118
+ var client = createClient(createConfig({ baseUrl: "http://localhost:4096" }));
1119
+
1120
+ // node_modules/@opencode-ai/sdk/dist/v2/gen/sdk.gen.js
1121
+ class HeyApiClient {
1122
+ client;
1123
+ constructor(args) {
1124
+ this.client = args?.client ?? client;
1125
+ }
1126
+ }
1127
+
1128
+ class HeyApiRegistry {
1129
+ defaultKey = "default";
1130
+ instances = new Map;
1131
+ get(key) {
1132
+ const instance = this.instances.get(key ?? this.defaultKey);
1133
+ if (!instance) {
1134
+ throw new Error(`No SDK client found. Create one with "new OpencodeClient()" to fix this error.`);
1135
+ }
1136
+ return instance;
1137
+ }
1138
+ set(value, key) {
1139
+ this.instances.set(key ?? this.defaultKey, value);
1140
+ }
1141
+ }
1142
+
1143
+ class Config extends HeyApiClient {
1144
+ get(options) {
1145
+ return (options?.client ?? this.client).get({
1146
+ url: "/global/config",
1147
+ ...options
1148
+ });
1149
+ }
1150
+ update(parameters, options) {
1151
+ const params = buildClientParams([parameters], [{ args: [{ key: "config", map: "body" }] }]);
1152
+ return (options?.client ?? this.client).patch({
1153
+ url: "/global/config",
1154
+ ...options,
1155
+ ...params,
1156
+ headers: {
1157
+ "Content-Type": "application/json",
1158
+ ...options?.headers,
1159
+ ...params.headers
1160
+ }
1161
+ });
1162
+ }
1163
+ }
1164
+
1165
+ class Global extends HeyApiClient {
1166
+ health(options) {
1167
+ return (options?.client ?? this.client).get({
1168
+ url: "/global/health",
1169
+ ...options
1170
+ });
1171
+ }
1172
+ event(options) {
1173
+ return (options?.client ?? this.client).sse.get({
1174
+ url: "/global/event",
1175
+ ...options
1176
+ });
1177
+ }
1178
+ dispose(options) {
1179
+ return (options?.client ?? this.client).post({
1180
+ url: "/global/dispose",
1181
+ ...options
1182
+ });
1183
+ }
1184
+ _config;
1185
+ get config() {
1186
+ return this._config ??= new Config({ client: this.client });
1187
+ }
1188
+ }
1189
+
1190
+ class Auth extends HeyApiClient {
1191
+ remove(parameters, options) {
1192
+ const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "providerID" }] }]);
1193
+ return (options?.client ?? this.client).delete({
1194
+ url: "/auth/{providerID}",
1195
+ ...options,
1196
+ ...params
1197
+ });
1198
+ }
1199
+ set(parameters, options) {
1200
+ const params = buildClientParams([parameters], [
1201
+ {
1202
+ args: [
1203
+ { in: "path", key: "providerID" },
1204
+ { key: "auth", map: "body" }
1205
+ ]
1206
+ }
1207
+ ]);
1208
+ return (options?.client ?? this.client).put({
1209
+ url: "/auth/{providerID}",
1210
+ ...options,
1211
+ ...params,
1212
+ headers: {
1213
+ "Content-Type": "application/json",
1214
+ ...options?.headers,
1215
+ ...params.headers
1216
+ }
1217
+ });
1218
+ }
1219
+ }
1220
+
1221
+ class Project extends HeyApiClient {
1222
+ list(parameters, options) {
1223
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
1224
+ return (options?.client ?? this.client).get({
1225
+ url: "/project",
1226
+ ...options,
1227
+ ...params
1228
+ });
1229
+ }
1230
+ current(parameters, options) {
1231
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
1232
+ return (options?.client ?? this.client).get({
1233
+ url: "/project/current",
1234
+ ...options,
1235
+ ...params
1236
+ });
1237
+ }
1238
+ update(parameters, options) {
1239
+ const params = buildClientParams([parameters], [
1240
+ {
1241
+ args: [
1242
+ { in: "path", key: "projectID" },
1243
+ { in: "query", key: "directory" },
1244
+ { in: "body", key: "name" },
1245
+ { in: "body", key: "icon" },
1246
+ { in: "body", key: "commands" }
1247
+ ]
1248
+ }
1249
+ ]);
1250
+ return (options?.client ?? this.client).patch({
1251
+ url: "/project/{projectID}",
1252
+ ...options,
1253
+ ...params,
1254
+ headers: {
1255
+ "Content-Type": "application/json",
1256
+ ...options?.headers,
1257
+ ...params.headers
1258
+ }
1259
+ });
1260
+ }
1261
+ }
1262
+
1263
+ class Pty extends HeyApiClient {
1264
+ list(parameters, options) {
1265
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
1266
+ return (options?.client ?? this.client).get({
1267
+ url: "/pty",
1268
+ ...options,
1269
+ ...params
1270
+ });
1271
+ }
1272
+ create(parameters, options) {
1273
+ const params = buildClientParams([parameters], [
1274
+ {
1275
+ args: [
1276
+ { in: "query", key: "directory" },
1277
+ { in: "body", key: "command" },
1278
+ { in: "body", key: "args" },
1279
+ { in: "body", key: "cwd" },
1280
+ { in: "body", key: "title" },
1281
+ { in: "body", key: "env" }
1282
+ ]
1283
+ }
1284
+ ]);
1285
+ return (options?.client ?? this.client).post({
1286
+ url: "/pty",
1287
+ ...options,
1288
+ ...params,
1289
+ headers: {
1290
+ "Content-Type": "application/json",
1291
+ ...options?.headers,
1292
+ ...params.headers
1293
+ }
1294
+ });
1295
+ }
1296
+ remove(parameters, options) {
1297
+ const params = buildClientParams([parameters], [
1298
+ {
1299
+ args: [
1300
+ { in: "path", key: "ptyID" },
1301
+ { in: "query", key: "directory" }
1302
+ ]
1303
+ }
1304
+ ]);
1305
+ return (options?.client ?? this.client).delete({
1306
+ url: "/pty/{ptyID}",
1307
+ ...options,
1308
+ ...params
1309
+ });
1310
+ }
1311
+ get(parameters, options) {
1312
+ const params = buildClientParams([parameters], [
1313
+ {
1314
+ args: [
1315
+ { in: "path", key: "ptyID" },
1316
+ { in: "query", key: "directory" }
1317
+ ]
1318
+ }
1319
+ ]);
1320
+ return (options?.client ?? this.client).get({
1321
+ url: "/pty/{ptyID}",
1322
+ ...options,
1323
+ ...params
1324
+ });
1325
+ }
1326
+ update(parameters, options) {
1327
+ const params = buildClientParams([parameters], [
1328
+ {
1329
+ args: [
1330
+ { in: "path", key: "ptyID" },
1331
+ { in: "query", key: "directory" },
1332
+ { in: "body", key: "title" },
1333
+ { in: "body", key: "size" }
1334
+ ]
1335
+ }
1336
+ ]);
1337
+ return (options?.client ?? this.client).put({
1338
+ url: "/pty/{ptyID}",
1339
+ ...options,
1340
+ ...params,
1341
+ headers: {
1342
+ "Content-Type": "application/json",
1343
+ ...options?.headers,
1344
+ ...params.headers
1345
+ }
1346
+ });
1347
+ }
1348
+ connect(parameters, options) {
1349
+ const params = buildClientParams([parameters], [
1350
+ {
1351
+ args: [
1352
+ { in: "path", key: "ptyID" },
1353
+ { in: "query", key: "directory" }
1354
+ ]
1355
+ }
1356
+ ]);
1357
+ return (options?.client ?? this.client).get({
1358
+ url: "/pty/{ptyID}/connect",
1359
+ ...options,
1360
+ ...params
1361
+ });
1362
+ }
1363
+ }
1364
+
1365
+ class Config2 extends HeyApiClient {
1366
+ get(parameters, options) {
1367
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
1368
+ return (options?.client ?? this.client).get({
1369
+ url: "/config",
1370
+ ...options,
1371
+ ...params
1372
+ });
1373
+ }
1374
+ update(parameters, options) {
1375
+ const params = buildClientParams([parameters], [
1376
+ {
1377
+ args: [
1378
+ { in: "query", key: "directory" },
1379
+ { key: "config", map: "body" }
1380
+ ]
1381
+ }
1382
+ ]);
1383
+ return (options?.client ?? this.client).patch({
1384
+ url: "/config",
1385
+ ...options,
1386
+ ...params,
1387
+ headers: {
1388
+ "Content-Type": "application/json",
1389
+ ...options?.headers,
1390
+ ...params.headers
1391
+ }
1392
+ });
1393
+ }
1394
+ providers(parameters, options) {
1395
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
1396
+ return (options?.client ?? this.client).get({
1397
+ url: "/config/providers",
1398
+ ...options,
1399
+ ...params
1400
+ });
1401
+ }
1402
+ }
1403
+
1404
+ class Tool extends HeyApiClient {
1405
+ ids(parameters, options) {
1406
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
1407
+ return (options?.client ?? this.client).get({
1408
+ url: "/experimental/tool/ids",
1409
+ ...options,
1410
+ ...params
1411
+ });
1412
+ }
1413
+ list(parameters, options) {
1414
+ const params = buildClientParams([parameters], [
1415
+ {
1416
+ args: [
1417
+ { in: "query", key: "directory" },
1418
+ { in: "query", key: "provider" },
1419
+ { in: "query", key: "model" }
1420
+ ]
1421
+ }
1422
+ ]);
1423
+ return (options?.client ?? this.client).get({
1424
+ url: "/experimental/tool",
1425
+ ...options,
1426
+ ...params
1427
+ });
1428
+ }
1429
+ }
1430
+
1431
+ class Worktree extends HeyApiClient {
1432
+ remove(parameters, options) {
1433
+ const params = buildClientParams([parameters], [
1434
+ {
1435
+ args: [
1436
+ { in: "query", key: "directory" },
1437
+ { key: "worktreeRemoveInput", map: "body" }
1438
+ ]
1439
+ }
1440
+ ]);
1441
+ return (options?.client ?? this.client).delete({
1442
+ url: "/experimental/worktree",
1443
+ ...options,
1444
+ ...params,
1445
+ headers: {
1446
+ "Content-Type": "application/json",
1447
+ ...options?.headers,
1448
+ ...params.headers
1449
+ }
1450
+ });
1451
+ }
1452
+ list(parameters, options) {
1453
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
1454
+ return (options?.client ?? this.client).get({
1455
+ url: "/experimental/worktree",
1456
+ ...options,
1457
+ ...params
1458
+ });
1459
+ }
1460
+ create(parameters, options) {
1461
+ const params = buildClientParams([parameters], [
1462
+ {
1463
+ args: [
1464
+ { in: "query", key: "directory" },
1465
+ { key: "worktreeCreateInput", map: "body" }
1466
+ ]
1467
+ }
1468
+ ]);
1469
+ return (options?.client ?? this.client).post({
1470
+ url: "/experimental/worktree",
1471
+ ...options,
1472
+ ...params,
1473
+ headers: {
1474
+ "Content-Type": "application/json",
1475
+ ...options?.headers,
1476
+ ...params.headers
1477
+ }
1478
+ });
1479
+ }
1480
+ reset(parameters, options) {
1481
+ const params = buildClientParams([parameters], [
1482
+ {
1483
+ args: [
1484
+ { in: "query", key: "directory" },
1485
+ { key: "worktreeResetInput", map: "body" }
1486
+ ]
1487
+ }
1488
+ ]);
1489
+ return (options?.client ?? this.client).post({
1490
+ url: "/experimental/worktree/reset",
1491
+ ...options,
1492
+ ...params,
1493
+ headers: {
1494
+ "Content-Type": "application/json",
1495
+ ...options?.headers,
1496
+ ...params.headers
1497
+ }
1498
+ });
1499
+ }
1500
+ }
1501
+
1502
+ class Resource extends HeyApiClient {
1503
+ list(parameters, options) {
1504
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
1505
+ return (options?.client ?? this.client).get({
1506
+ url: "/experimental/resource",
1507
+ ...options,
1508
+ ...params
1509
+ });
1510
+ }
1511
+ }
1512
+
1513
+ class Experimental extends HeyApiClient {
1514
+ _resource;
1515
+ get resource() {
1516
+ return this._resource ??= new Resource({ client: this.client });
1517
+ }
1518
+ }
1519
+
1520
+ class Session extends HeyApiClient {
1521
+ list(parameters, options) {
1522
+ const params = buildClientParams([parameters], [
1523
+ {
1524
+ args: [
1525
+ { in: "query", key: "directory" },
1526
+ { in: "query", key: "roots" },
1527
+ { in: "query", key: "start" },
1528
+ { in: "query", key: "search" },
1529
+ { in: "query", key: "limit" }
1530
+ ]
1531
+ }
1532
+ ]);
1533
+ return (options?.client ?? this.client).get({
1534
+ url: "/session",
1535
+ ...options,
1536
+ ...params
1537
+ });
1538
+ }
1539
+ create(parameters, options) {
1540
+ const params = buildClientParams([parameters], [
1541
+ {
1542
+ args: [
1543
+ { in: "query", key: "directory" },
1544
+ { in: "body", key: "parentID" },
1545
+ { in: "body", key: "title" },
1546
+ { in: "body", key: "permission" }
1547
+ ]
1548
+ }
1549
+ ]);
1550
+ return (options?.client ?? this.client).post({
1551
+ url: "/session",
1552
+ ...options,
1553
+ ...params,
1554
+ headers: {
1555
+ "Content-Type": "application/json",
1556
+ ...options?.headers,
1557
+ ...params.headers
1558
+ }
1559
+ });
1560
+ }
1561
+ status(parameters, options) {
1562
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
1563
+ return (options?.client ?? this.client).get({
1564
+ url: "/session/status",
1565
+ ...options,
1566
+ ...params
1567
+ });
1568
+ }
1569
+ delete(parameters, options) {
1570
+ const params = buildClientParams([parameters], [
1571
+ {
1572
+ args: [
1573
+ { in: "path", key: "sessionID" },
1574
+ { in: "query", key: "directory" }
1575
+ ]
1576
+ }
1577
+ ]);
1578
+ return (options?.client ?? this.client).delete({
1579
+ url: "/session/{sessionID}",
1580
+ ...options,
1581
+ ...params
1582
+ });
1583
+ }
1584
+ get(parameters, options) {
1585
+ const params = buildClientParams([parameters], [
1586
+ {
1587
+ args: [
1588
+ { in: "path", key: "sessionID" },
1589
+ { in: "query", key: "directory" }
1590
+ ]
1591
+ }
1592
+ ]);
1593
+ return (options?.client ?? this.client).get({
1594
+ url: "/session/{sessionID}",
1595
+ ...options,
1596
+ ...params
1597
+ });
1598
+ }
1599
+ update(parameters, options) {
1600
+ const params = buildClientParams([parameters], [
1601
+ {
1602
+ args: [
1603
+ { in: "path", key: "sessionID" },
1604
+ { in: "query", key: "directory" },
1605
+ { in: "body", key: "title" },
1606
+ { in: "body", key: "time" }
1607
+ ]
1608
+ }
1609
+ ]);
1610
+ return (options?.client ?? this.client).patch({
1611
+ url: "/session/{sessionID}",
1612
+ ...options,
1613
+ ...params,
1614
+ headers: {
1615
+ "Content-Type": "application/json",
1616
+ ...options?.headers,
1617
+ ...params.headers
1618
+ }
1619
+ });
1620
+ }
1621
+ children(parameters, options) {
1622
+ const params = buildClientParams([parameters], [
1623
+ {
1624
+ args: [
1625
+ { in: "path", key: "sessionID" },
1626
+ { in: "query", key: "directory" }
1627
+ ]
1628
+ }
1629
+ ]);
1630
+ return (options?.client ?? this.client).get({
1631
+ url: "/session/{sessionID}/children",
1632
+ ...options,
1633
+ ...params
1634
+ });
1635
+ }
1636
+ todo(parameters, options) {
1637
+ const params = buildClientParams([parameters], [
1638
+ {
1639
+ args: [
1640
+ { in: "path", key: "sessionID" },
1641
+ { in: "query", key: "directory" }
1642
+ ]
1643
+ }
1644
+ ]);
1645
+ return (options?.client ?? this.client).get({
1646
+ url: "/session/{sessionID}/todo",
1647
+ ...options,
1648
+ ...params
1649
+ });
1650
+ }
1651
+ init(parameters, options) {
1652
+ const params = buildClientParams([parameters], [
1653
+ {
1654
+ args: [
1655
+ { in: "path", key: "sessionID" },
1656
+ { in: "query", key: "directory" },
1657
+ { in: "body", key: "modelID" },
1658
+ { in: "body", key: "providerID" },
1659
+ { in: "body", key: "messageID" }
1660
+ ]
1661
+ }
1662
+ ]);
1663
+ return (options?.client ?? this.client).post({
1664
+ url: "/session/{sessionID}/init",
1665
+ ...options,
1666
+ ...params,
1667
+ headers: {
1668
+ "Content-Type": "application/json",
1669
+ ...options?.headers,
1670
+ ...params.headers
1671
+ }
1672
+ });
1673
+ }
1674
+ fork(parameters, options) {
1675
+ const params = buildClientParams([parameters], [
1676
+ {
1677
+ args: [
1678
+ { in: "path", key: "sessionID" },
1679
+ { in: "query", key: "directory" },
1680
+ { in: "body", key: "messageID" }
1681
+ ]
1682
+ }
1683
+ ]);
1684
+ return (options?.client ?? this.client).post({
1685
+ url: "/session/{sessionID}/fork",
1686
+ ...options,
1687
+ ...params,
1688
+ headers: {
1689
+ "Content-Type": "application/json",
1690
+ ...options?.headers,
1691
+ ...params.headers
1692
+ }
1693
+ });
1694
+ }
1695
+ abort(parameters, options) {
1696
+ const params = buildClientParams([parameters], [
1697
+ {
1698
+ args: [
1699
+ { in: "path", key: "sessionID" },
1700
+ { in: "query", key: "directory" }
1701
+ ]
1702
+ }
1703
+ ]);
1704
+ return (options?.client ?? this.client).post({
1705
+ url: "/session/{sessionID}/abort",
1706
+ ...options,
1707
+ ...params
1708
+ });
1709
+ }
1710
+ unshare(parameters, options) {
1711
+ const params = buildClientParams([parameters], [
1712
+ {
1713
+ args: [
1714
+ { in: "path", key: "sessionID" },
1715
+ { in: "query", key: "directory" }
1716
+ ]
1717
+ }
1718
+ ]);
1719
+ return (options?.client ?? this.client).delete({
1720
+ url: "/session/{sessionID}/share",
1721
+ ...options,
1722
+ ...params
1723
+ });
1724
+ }
1725
+ share(parameters, options) {
1726
+ const params = buildClientParams([parameters], [
1727
+ {
1728
+ args: [
1729
+ { in: "path", key: "sessionID" },
1730
+ { in: "query", key: "directory" }
1731
+ ]
1732
+ }
1733
+ ]);
1734
+ return (options?.client ?? this.client).post({
1735
+ url: "/session/{sessionID}/share",
1736
+ ...options,
1737
+ ...params
1738
+ });
1739
+ }
1740
+ diff(parameters, options) {
1741
+ const params = buildClientParams([parameters], [
1742
+ {
1743
+ args: [
1744
+ { in: "path", key: "sessionID" },
1745
+ { in: "query", key: "directory" },
1746
+ { in: "query", key: "messageID" }
1747
+ ]
1748
+ }
1749
+ ]);
1750
+ return (options?.client ?? this.client).get({
1751
+ url: "/session/{sessionID}/diff",
1752
+ ...options,
1753
+ ...params
1754
+ });
1755
+ }
1756
+ summarize(parameters, options) {
1757
+ const params = buildClientParams([parameters], [
1758
+ {
1759
+ args: [
1760
+ { in: "path", key: "sessionID" },
1761
+ { in: "query", key: "directory" },
1762
+ { in: "body", key: "providerID" },
1763
+ { in: "body", key: "modelID" },
1764
+ { in: "body", key: "auto" }
1765
+ ]
1766
+ }
1767
+ ]);
1768
+ return (options?.client ?? this.client).post({
1769
+ url: "/session/{sessionID}/summarize",
1770
+ ...options,
1771
+ ...params,
1772
+ headers: {
1773
+ "Content-Type": "application/json",
1774
+ ...options?.headers,
1775
+ ...params.headers
1776
+ }
1777
+ });
1778
+ }
1779
+ messages(parameters, options) {
1780
+ const params = buildClientParams([parameters], [
1781
+ {
1782
+ args: [
1783
+ { in: "path", key: "sessionID" },
1784
+ { in: "query", key: "directory" },
1785
+ { in: "query", key: "limit" }
1786
+ ]
1787
+ }
1788
+ ]);
1789
+ return (options?.client ?? this.client).get({
1790
+ url: "/session/{sessionID}/message",
1791
+ ...options,
1792
+ ...params
1793
+ });
1794
+ }
1795
+ prompt(parameters, options) {
1796
+ const params = buildClientParams([parameters], [
1797
+ {
1798
+ args: [
1799
+ { in: "path", key: "sessionID" },
1800
+ { in: "query", key: "directory" },
1801
+ { in: "body", key: "messageID" },
1802
+ { in: "body", key: "model" },
1803
+ { in: "body", key: "agent" },
1804
+ { in: "body", key: "noReply" },
1805
+ { in: "body", key: "tools" },
1806
+ { in: "body", key: "system" },
1807
+ { in: "body", key: "variant" },
1808
+ { in: "body", key: "parts" }
1809
+ ]
1810
+ }
1811
+ ]);
1812
+ return (options?.client ?? this.client).post({
1813
+ url: "/session/{sessionID}/message",
1814
+ ...options,
1815
+ ...params,
1816
+ headers: {
1817
+ "Content-Type": "application/json",
1818
+ ...options?.headers,
1819
+ ...params.headers
1820
+ }
1821
+ });
1822
+ }
1823
+ message(parameters, options) {
1824
+ const params = buildClientParams([parameters], [
1825
+ {
1826
+ args: [
1827
+ { in: "path", key: "sessionID" },
1828
+ { in: "path", key: "messageID" },
1829
+ { in: "query", key: "directory" }
1830
+ ]
1831
+ }
1832
+ ]);
1833
+ return (options?.client ?? this.client).get({
1834
+ url: "/session/{sessionID}/message/{messageID}",
1835
+ ...options,
1836
+ ...params
1837
+ });
1838
+ }
1839
+ promptAsync(parameters, options) {
1840
+ const params = buildClientParams([parameters], [
1841
+ {
1842
+ args: [
1843
+ { in: "path", key: "sessionID" },
1844
+ { in: "query", key: "directory" },
1845
+ { in: "body", key: "messageID" },
1846
+ { in: "body", key: "model" },
1847
+ { in: "body", key: "agent" },
1848
+ { in: "body", key: "noReply" },
1849
+ { in: "body", key: "tools" },
1850
+ { in: "body", key: "system" },
1851
+ { in: "body", key: "variant" },
1852
+ { in: "body", key: "parts" }
1853
+ ]
1854
+ }
1855
+ ]);
1856
+ return (options?.client ?? this.client).post({
1857
+ url: "/session/{sessionID}/prompt_async",
1858
+ ...options,
1859
+ ...params,
1860
+ headers: {
1861
+ "Content-Type": "application/json",
1862
+ ...options?.headers,
1863
+ ...params.headers
1864
+ }
1865
+ });
1866
+ }
1867
+ command(parameters, options) {
1868
+ const params = buildClientParams([parameters], [
1869
+ {
1870
+ args: [
1871
+ { in: "path", key: "sessionID" },
1872
+ { in: "query", key: "directory" },
1873
+ { in: "body", key: "messageID" },
1874
+ { in: "body", key: "agent" },
1875
+ { in: "body", key: "model" },
1876
+ { in: "body", key: "arguments" },
1877
+ { in: "body", key: "command" },
1878
+ { in: "body", key: "variant" },
1879
+ { in: "body", key: "parts" }
1880
+ ]
1881
+ }
1882
+ ]);
1883
+ return (options?.client ?? this.client).post({
1884
+ url: "/session/{sessionID}/command",
1885
+ ...options,
1886
+ ...params,
1887
+ headers: {
1888
+ "Content-Type": "application/json",
1889
+ ...options?.headers,
1890
+ ...params.headers
1891
+ }
1892
+ });
1893
+ }
1894
+ shell(parameters, options) {
1895
+ const params = buildClientParams([parameters], [
1896
+ {
1897
+ args: [
1898
+ { in: "path", key: "sessionID" },
1899
+ { in: "query", key: "directory" },
1900
+ { in: "body", key: "agent" },
1901
+ { in: "body", key: "model" },
1902
+ { in: "body", key: "command" }
1903
+ ]
1904
+ }
1905
+ ]);
1906
+ return (options?.client ?? this.client).post({
1907
+ url: "/session/{sessionID}/shell",
1908
+ ...options,
1909
+ ...params,
1910
+ headers: {
1911
+ "Content-Type": "application/json",
1912
+ ...options?.headers,
1913
+ ...params.headers
1914
+ }
1915
+ });
1916
+ }
1917
+ revert(parameters, options) {
1918
+ const params = buildClientParams([parameters], [
1919
+ {
1920
+ args: [
1921
+ { in: "path", key: "sessionID" },
1922
+ { in: "query", key: "directory" },
1923
+ { in: "body", key: "messageID" },
1924
+ { in: "body", key: "partID" }
1925
+ ]
1926
+ }
1927
+ ]);
1928
+ return (options?.client ?? this.client).post({
1929
+ url: "/session/{sessionID}/revert",
1930
+ ...options,
1931
+ ...params,
1932
+ headers: {
1933
+ "Content-Type": "application/json",
1934
+ ...options?.headers,
1935
+ ...params.headers
1936
+ }
1937
+ });
1938
+ }
1939
+ unrevert(parameters, options) {
1940
+ const params = buildClientParams([parameters], [
1941
+ {
1942
+ args: [
1943
+ { in: "path", key: "sessionID" },
1944
+ { in: "query", key: "directory" }
1945
+ ]
1946
+ }
1947
+ ]);
1948
+ return (options?.client ?? this.client).post({
1949
+ url: "/session/{sessionID}/unrevert",
1950
+ ...options,
1951
+ ...params
1952
+ });
1953
+ }
1954
+ }
1955
+
1956
+ class Part extends HeyApiClient {
1957
+ delete(parameters, options) {
1958
+ const params = buildClientParams([parameters], [
1959
+ {
1960
+ args: [
1961
+ { in: "path", key: "sessionID" },
1962
+ { in: "path", key: "messageID" },
1963
+ { in: "path", key: "partID" },
1964
+ { in: "query", key: "directory" }
1965
+ ]
1966
+ }
1967
+ ]);
1968
+ return (options?.client ?? this.client).delete({
1969
+ url: "/session/{sessionID}/message/{messageID}/part/{partID}",
1970
+ ...options,
1971
+ ...params
1972
+ });
1973
+ }
1974
+ update(parameters, options) {
1975
+ const params = buildClientParams([parameters], [
1976
+ {
1977
+ args: [
1978
+ { in: "path", key: "sessionID" },
1979
+ { in: "path", key: "messageID" },
1980
+ { in: "path", key: "partID" },
1981
+ { in: "query", key: "directory" },
1982
+ { key: "part", map: "body" }
1983
+ ]
1984
+ }
1985
+ ]);
1986
+ return (options?.client ?? this.client).patch({
1987
+ url: "/session/{sessionID}/message/{messageID}/part/{partID}",
1988
+ ...options,
1989
+ ...params,
1990
+ headers: {
1991
+ "Content-Type": "application/json",
1992
+ ...options?.headers,
1993
+ ...params.headers
1994
+ }
1995
+ });
1996
+ }
1997
+ }
1998
+
1999
+ class Permission extends HeyApiClient {
2000
+ respond(parameters, options) {
2001
+ const params = buildClientParams([parameters], [
2002
+ {
2003
+ args: [
2004
+ { in: "path", key: "sessionID" },
2005
+ { in: "path", key: "permissionID" },
2006
+ { in: "query", key: "directory" },
2007
+ { in: "body", key: "response" }
2008
+ ]
2009
+ }
2010
+ ]);
2011
+ return (options?.client ?? this.client).post({
2012
+ url: "/session/{sessionID}/permissions/{permissionID}",
2013
+ ...options,
2014
+ ...params,
2015
+ headers: {
2016
+ "Content-Type": "application/json",
2017
+ ...options?.headers,
2018
+ ...params.headers
2019
+ }
2020
+ });
2021
+ }
2022
+ reply(parameters, options) {
2023
+ const params = buildClientParams([parameters], [
2024
+ {
2025
+ args: [
2026
+ { in: "path", key: "requestID" },
2027
+ { in: "query", key: "directory" },
2028
+ { in: "body", key: "reply" },
2029
+ { in: "body", key: "message" }
2030
+ ]
2031
+ }
2032
+ ]);
2033
+ return (options?.client ?? this.client).post({
2034
+ url: "/permission/{requestID}/reply",
2035
+ ...options,
2036
+ ...params,
2037
+ headers: {
2038
+ "Content-Type": "application/json",
2039
+ ...options?.headers,
2040
+ ...params.headers
2041
+ }
2042
+ });
2043
+ }
2044
+ list(parameters, options) {
2045
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2046
+ return (options?.client ?? this.client).get({
2047
+ url: "/permission",
2048
+ ...options,
2049
+ ...params
2050
+ });
2051
+ }
2052
+ }
2053
+
2054
+ class Question extends HeyApiClient {
2055
+ list(parameters, options) {
2056
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2057
+ return (options?.client ?? this.client).get({
2058
+ url: "/question",
2059
+ ...options,
2060
+ ...params
2061
+ });
2062
+ }
2063
+ reply(parameters, options) {
2064
+ const params = buildClientParams([parameters], [
2065
+ {
2066
+ args: [
2067
+ { in: "path", key: "requestID" },
2068
+ { in: "query", key: "directory" },
2069
+ { in: "body", key: "answers" }
2070
+ ]
2071
+ }
2072
+ ]);
2073
+ return (options?.client ?? this.client).post({
2074
+ url: "/question/{requestID}/reply",
2075
+ ...options,
2076
+ ...params,
2077
+ headers: {
2078
+ "Content-Type": "application/json",
2079
+ ...options?.headers,
2080
+ ...params.headers
2081
+ }
2082
+ });
2083
+ }
2084
+ reject(parameters, options) {
2085
+ const params = buildClientParams([parameters], [
2086
+ {
2087
+ args: [
2088
+ { in: "path", key: "requestID" },
2089
+ { in: "query", key: "directory" }
2090
+ ]
2091
+ }
2092
+ ]);
2093
+ return (options?.client ?? this.client).post({
2094
+ url: "/question/{requestID}/reject",
2095
+ ...options,
2096
+ ...params
2097
+ });
2098
+ }
2099
+ }
2100
+
2101
+ class Oauth extends HeyApiClient {
2102
+ authorize(parameters, options) {
2103
+ const params = buildClientParams([parameters], [
2104
+ {
2105
+ args: [
2106
+ { in: "path", key: "providerID" },
2107
+ { in: "query", key: "directory" },
2108
+ { in: "body", key: "method" }
2109
+ ]
2110
+ }
2111
+ ]);
2112
+ return (options?.client ?? this.client).post({
2113
+ url: "/provider/{providerID}/oauth/authorize",
2114
+ ...options,
2115
+ ...params,
2116
+ headers: {
2117
+ "Content-Type": "application/json",
2118
+ ...options?.headers,
2119
+ ...params.headers
2120
+ }
2121
+ });
2122
+ }
2123
+ callback(parameters, options) {
2124
+ const params = buildClientParams([parameters], [
2125
+ {
2126
+ args: [
2127
+ { in: "path", key: "providerID" },
2128
+ { in: "query", key: "directory" },
2129
+ { in: "body", key: "method" },
2130
+ { in: "body", key: "code" }
2131
+ ]
2132
+ }
2133
+ ]);
2134
+ return (options?.client ?? this.client).post({
2135
+ url: "/provider/{providerID}/oauth/callback",
2136
+ ...options,
2137
+ ...params,
2138
+ headers: {
2139
+ "Content-Type": "application/json",
2140
+ ...options?.headers,
2141
+ ...params.headers
2142
+ }
2143
+ });
2144
+ }
2145
+ }
2146
+
2147
+ class Provider extends HeyApiClient {
2148
+ list(parameters, options) {
2149
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2150
+ return (options?.client ?? this.client).get({
2151
+ url: "/provider",
2152
+ ...options,
2153
+ ...params
2154
+ });
2155
+ }
2156
+ auth(parameters, options) {
2157
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2158
+ return (options?.client ?? this.client).get({
2159
+ url: "/provider/auth",
2160
+ ...options,
2161
+ ...params
2162
+ });
2163
+ }
2164
+ _oauth;
2165
+ get oauth() {
2166
+ return this._oauth ??= new Oauth({ client: this.client });
2167
+ }
2168
+ }
2169
+
2170
+ class Find extends HeyApiClient {
2171
+ text(parameters, options) {
2172
+ const params = buildClientParams([parameters], [
2173
+ {
2174
+ args: [
2175
+ { in: "query", key: "directory" },
2176
+ { in: "query", key: "pattern" }
2177
+ ]
2178
+ }
2179
+ ]);
2180
+ return (options?.client ?? this.client).get({
2181
+ url: "/find",
2182
+ ...options,
2183
+ ...params
2184
+ });
2185
+ }
2186
+ files(parameters, options) {
2187
+ const params = buildClientParams([parameters], [
2188
+ {
2189
+ args: [
2190
+ { in: "query", key: "directory" },
2191
+ { in: "query", key: "query" },
2192
+ { in: "query", key: "dirs" },
2193
+ { in: "query", key: "type" },
2194
+ { in: "query", key: "limit" }
2195
+ ]
2196
+ }
2197
+ ]);
2198
+ return (options?.client ?? this.client).get({
2199
+ url: "/find/file",
2200
+ ...options,
2201
+ ...params
2202
+ });
2203
+ }
2204
+ symbols(parameters, options) {
2205
+ const params = buildClientParams([parameters], [
2206
+ {
2207
+ args: [
2208
+ { in: "query", key: "directory" },
2209
+ { in: "query", key: "query" }
2210
+ ]
2211
+ }
2212
+ ]);
2213
+ return (options?.client ?? this.client).get({
2214
+ url: "/find/symbol",
2215
+ ...options,
2216
+ ...params
2217
+ });
2218
+ }
2219
+ }
2220
+
2221
+ class File extends HeyApiClient {
2222
+ list(parameters, options) {
2223
+ const params = buildClientParams([parameters], [
2224
+ {
2225
+ args: [
2226
+ { in: "query", key: "directory" },
2227
+ { in: "query", key: "path" }
2228
+ ]
2229
+ }
2230
+ ]);
2231
+ return (options?.client ?? this.client).get({
2232
+ url: "/file",
2233
+ ...options,
2234
+ ...params
2235
+ });
2236
+ }
2237
+ read(parameters, options) {
2238
+ const params = buildClientParams([parameters], [
2239
+ {
2240
+ args: [
2241
+ { in: "query", key: "directory" },
2242
+ { in: "query", key: "path" }
2243
+ ]
2244
+ }
2245
+ ]);
2246
+ return (options?.client ?? this.client).get({
2247
+ url: "/file/content",
2248
+ ...options,
2249
+ ...params
2250
+ });
2251
+ }
2252
+ status(parameters, options) {
2253
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2254
+ return (options?.client ?? this.client).get({
2255
+ url: "/file/status",
2256
+ ...options,
2257
+ ...params
2258
+ });
2259
+ }
2260
+ }
2261
+
2262
+ class Auth2 extends HeyApiClient {
2263
+ remove(parameters, options) {
2264
+ const params = buildClientParams([parameters], [
2265
+ {
2266
+ args: [
2267
+ { in: "path", key: "name" },
2268
+ { in: "query", key: "directory" }
2269
+ ]
2270
+ }
2271
+ ]);
2272
+ return (options?.client ?? this.client).delete({
2273
+ url: "/mcp/{name}/auth",
2274
+ ...options,
2275
+ ...params
2276
+ });
2277
+ }
2278
+ start(parameters, options) {
2279
+ const params = buildClientParams([parameters], [
2280
+ {
2281
+ args: [
2282
+ { in: "path", key: "name" },
2283
+ { in: "query", key: "directory" }
2284
+ ]
2285
+ }
2286
+ ]);
2287
+ return (options?.client ?? this.client).post({
2288
+ url: "/mcp/{name}/auth",
2289
+ ...options,
2290
+ ...params
2291
+ });
2292
+ }
2293
+ callback(parameters, options) {
2294
+ const params = buildClientParams([parameters], [
2295
+ {
2296
+ args: [
2297
+ { in: "path", key: "name" },
2298
+ { in: "query", key: "directory" },
2299
+ { in: "body", key: "code" }
2300
+ ]
2301
+ }
2302
+ ]);
2303
+ return (options?.client ?? this.client).post({
2304
+ url: "/mcp/{name}/auth/callback",
2305
+ ...options,
2306
+ ...params,
2307
+ headers: {
2308
+ "Content-Type": "application/json",
2309
+ ...options?.headers,
2310
+ ...params.headers
2311
+ }
2312
+ });
2313
+ }
2314
+ authenticate(parameters, options) {
2315
+ const params = buildClientParams([parameters], [
2316
+ {
2317
+ args: [
2318
+ { in: "path", key: "name" },
2319
+ { in: "query", key: "directory" }
2320
+ ]
2321
+ }
2322
+ ]);
2323
+ return (options?.client ?? this.client).post({
2324
+ url: "/mcp/{name}/auth/authenticate",
2325
+ ...options,
2326
+ ...params
2327
+ });
2328
+ }
2329
+ }
2330
+
2331
+ class Mcp extends HeyApiClient {
2332
+ status(parameters, options) {
2333
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2334
+ return (options?.client ?? this.client).get({
2335
+ url: "/mcp",
2336
+ ...options,
2337
+ ...params
2338
+ });
2339
+ }
2340
+ add(parameters, options) {
2341
+ const params = buildClientParams([parameters], [
2342
+ {
2343
+ args: [
2344
+ { in: "query", key: "directory" },
2345
+ { in: "body", key: "name" },
2346
+ { in: "body", key: "config" }
2347
+ ]
2348
+ }
2349
+ ]);
2350
+ return (options?.client ?? this.client).post({
2351
+ url: "/mcp",
2352
+ ...options,
2353
+ ...params,
2354
+ headers: {
2355
+ "Content-Type": "application/json",
2356
+ ...options?.headers,
2357
+ ...params.headers
2358
+ }
2359
+ });
2360
+ }
2361
+ connect(parameters, options) {
2362
+ const params = buildClientParams([parameters], [
2363
+ {
2364
+ args: [
2365
+ { in: "path", key: "name" },
2366
+ { in: "query", key: "directory" }
2367
+ ]
2368
+ }
2369
+ ]);
2370
+ return (options?.client ?? this.client).post({
2371
+ url: "/mcp/{name}/connect",
2372
+ ...options,
2373
+ ...params
2374
+ });
2375
+ }
2376
+ disconnect(parameters, options) {
2377
+ const params = buildClientParams([parameters], [
2378
+ {
2379
+ args: [
2380
+ { in: "path", key: "name" },
2381
+ { in: "query", key: "directory" }
2382
+ ]
2383
+ }
2384
+ ]);
2385
+ return (options?.client ?? this.client).post({
2386
+ url: "/mcp/{name}/disconnect",
2387
+ ...options,
2388
+ ...params
2389
+ });
2390
+ }
2391
+ _auth;
2392
+ get auth() {
2393
+ return this._auth ??= new Auth2({ client: this.client });
2394
+ }
2395
+ }
2396
+
2397
+ class Control extends HeyApiClient {
2398
+ next(parameters, options) {
2399
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2400
+ return (options?.client ?? this.client).get({
2401
+ url: "/tui/control/next",
2402
+ ...options,
2403
+ ...params
2404
+ });
2405
+ }
2406
+ response(parameters, options) {
2407
+ const params = buildClientParams([parameters], [
2408
+ {
2409
+ args: [
2410
+ { in: "query", key: "directory" },
2411
+ { key: "body", map: "body" }
2412
+ ]
2413
+ }
2414
+ ]);
2415
+ return (options?.client ?? this.client).post({
2416
+ url: "/tui/control/response",
2417
+ ...options,
2418
+ ...params,
2419
+ headers: {
2420
+ "Content-Type": "application/json",
2421
+ ...options?.headers,
2422
+ ...params.headers
2423
+ }
2424
+ });
2425
+ }
2426
+ }
2427
+
2428
+ class Tui extends HeyApiClient {
2429
+ appendPrompt(parameters, options) {
2430
+ const params = buildClientParams([parameters], [
2431
+ {
2432
+ args: [
2433
+ { in: "query", key: "directory" },
2434
+ { in: "body", key: "text" }
2435
+ ]
2436
+ }
2437
+ ]);
2438
+ return (options?.client ?? this.client).post({
2439
+ url: "/tui/append-prompt",
2440
+ ...options,
2441
+ ...params,
2442
+ headers: {
2443
+ "Content-Type": "application/json",
2444
+ ...options?.headers,
2445
+ ...params.headers
2446
+ }
2447
+ });
2448
+ }
2449
+ openHelp(parameters, options) {
2450
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2451
+ return (options?.client ?? this.client).post({
2452
+ url: "/tui/open-help",
2453
+ ...options,
2454
+ ...params
2455
+ });
2456
+ }
2457
+ openSessions(parameters, options) {
2458
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2459
+ return (options?.client ?? this.client).post({
2460
+ url: "/tui/open-sessions",
2461
+ ...options,
2462
+ ...params
2463
+ });
2464
+ }
2465
+ openThemes(parameters, options) {
2466
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2467
+ return (options?.client ?? this.client).post({
2468
+ url: "/tui/open-themes",
2469
+ ...options,
2470
+ ...params
2471
+ });
2472
+ }
2473
+ openModels(parameters, options) {
2474
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2475
+ return (options?.client ?? this.client).post({
2476
+ url: "/tui/open-models",
2477
+ ...options,
2478
+ ...params
2479
+ });
2480
+ }
2481
+ submitPrompt(parameters, options) {
2482
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2483
+ return (options?.client ?? this.client).post({
2484
+ url: "/tui/submit-prompt",
2485
+ ...options,
2486
+ ...params
2487
+ });
2488
+ }
2489
+ clearPrompt(parameters, options) {
2490
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2491
+ return (options?.client ?? this.client).post({
2492
+ url: "/tui/clear-prompt",
2493
+ ...options,
2494
+ ...params
2495
+ });
2496
+ }
2497
+ executeCommand(parameters, options) {
2498
+ const params = buildClientParams([parameters], [
2499
+ {
2500
+ args: [
2501
+ { in: "query", key: "directory" },
2502
+ { in: "body", key: "command" }
2503
+ ]
2504
+ }
2505
+ ]);
2506
+ return (options?.client ?? this.client).post({
2507
+ url: "/tui/execute-command",
2508
+ ...options,
2509
+ ...params,
2510
+ headers: {
2511
+ "Content-Type": "application/json",
2512
+ ...options?.headers,
2513
+ ...params.headers
2514
+ }
2515
+ });
2516
+ }
2517
+ showToast(parameters, options) {
2518
+ const params = buildClientParams([parameters], [
2519
+ {
2520
+ args: [
2521
+ { in: "query", key: "directory" },
2522
+ { in: "body", key: "title" },
2523
+ { in: "body", key: "message" },
2524
+ { in: "body", key: "variant" },
2525
+ { in: "body", key: "duration" }
2526
+ ]
2527
+ }
2528
+ ]);
2529
+ return (options?.client ?? this.client).post({
2530
+ url: "/tui/show-toast",
2531
+ ...options,
2532
+ ...params,
2533
+ headers: {
2534
+ "Content-Type": "application/json",
2535
+ ...options?.headers,
2536
+ ...params.headers
2537
+ }
2538
+ });
2539
+ }
2540
+ publish(parameters, options) {
2541
+ const params = buildClientParams([parameters], [
2542
+ {
2543
+ args: [
2544
+ { in: "query", key: "directory" },
2545
+ { key: "body", map: "body" }
2546
+ ]
2547
+ }
2548
+ ]);
2549
+ return (options?.client ?? this.client).post({
2550
+ url: "/tui/publish",
2551
+ ...options,
2552
+ ...params,
2553
+ headers: {
2554
+ "Content-Type": "application/json",
2555
+ ...options?.headers,
2556
+ ...params.headers
2557
+ }
2558
+ });
2559
+ }
2560
+ selectSession(parameters, options) {
2561
+ const params = buildClientParams([parameters], [
2562
+ {
2563
+ args: [
2564
+ { in: "query", key: "directory" },
2565
+ { in: "body", key: "sessionID" }
2566
+ ]
2567
+ }
2568
+ ]);
2569
+ return (options?.client ?? this.client).post({
2570
+ url: "/tui/select-session",
2571
+ ...options,
2572
+ ...params,
2573
+ headers: {
2574
+ "Content-Type": "application/json",
2575
+ ...options?.headers,
2576
+ ...params.headers
2577
+ }
2578
+ });
2579
+ }
2580
+ _control;
2581
+ get control() {
2582
+ return this._control ??= new Control({ client: this.client });
2583
+ }
2584
+ }
2585
+
2586
+ class Instance extends HeyApiClient {
2587
+ dispose(parameters, options) {
2588
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2589
+ return (options?.client ?? this.client).post({
2590
+ url: "/instance/dispose",
2591
+ ...options,
2592
+ ...params
2593
+ });
2594
+ }
2595
+ }
2596
+
2597
+ class Path extends HeyApiClient {
2598
+ get(parameters, options) {
2599
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2600
+ return (options?.client ?? this.client).get({
2601
+ url: "/path",
2602
+ ...options,
2603
+ ...params
2604
+ });
2605
+ }
2606
+ }
2607
+
2608
+ class Vcs extends HeyApiClient {
2609
+ get(parameters, options) {
2610
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2611
+ return (options?.client ?? this.client).get({
2612
+ url: "/vcs",
2613
+ ...options,
2614
+ ...params
2615
+ });
2616
+ }
2617
+ }
2618
+
2619
+ class Command extends HeyApiClient {
2620
+ list(parameters, options) {
2621
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2622
+ return (options?.client ?? this.client).get({
2623
+ url: "/command",
2624
+ ...options,
2625
+ ...params
2626
+ });
2627
+ }
2628
+ }
2629
+
2630
+ class App extends HeyApiClient {
2631
+ log(parameters, options) {
2632
+ const params = buildClientParams([parameters], [
2633
+ {
2634
+ args: [
2635
+ { in: "query", key: "directory" },
2636
+ { in: "body", key: "service" },
2637
+ { in: "body", key: "level" },
2638
+ { in: "body", key: "message" },
2639
+ { in: "body", key: "extra" }
2640
+ ]
2641
+ }
2642
+ ]);
2643
+ return (options?.client ?? this.client).post({
2644
+ url: "/log",
2645
+ ...options,
2646
+ ...params,
2647
+ headers: {
2648
+ "Content-Type": "application/json",
2649
+ ...options?.headers,
2650
+ ...params.headers
2651
+ }
2652
+ });
2653
+ }
2654
+ agents(parameters, options) {
2655
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2656
+ return (options?.client ?? this.client).get({
2657
+ url: "/agent",
2658
+ ...options,
2659
+ ...params
2660
+ });
2661
+ }
2662
+ skills(parameters, options) {
2663
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2664
+ return (options?.client ?? this.client).get({
2665
+ url: "/skill",
2666
+ ...options,
2667
+ ...params
2668
+ });
2669
+ }
2670
+ }
2671
+
2672
+ class Lsp extends HeyApiClient {
2673
+ status(parameters, options) {
2674
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2675
+ return (options?.client ?? this.client).get({
2676
+ url: "/lsp",
2677
+ ...options,
2678
+ ...params
2679
+ });
2680
+ }
2681
+ }
2682
+
2683
+ class Formatter extends HeyApiClient {
2684
+ status(parameters, options) {
2685
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2686
+ return (options?.client ?? this.client).get({
2687
+ url: "/formatter",
2688
+ ...options,
2689
+ ...params
2690
+ });
2691
+ }
2692
+ }
2693
+
2694
+ class Event extends HeyApiClient {
2695
+ subscribe(parameters, options) {
2696
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }]);
2697
+ return (options?.client ?? this.client).sse.get({
2698
+ url: "/event",
2699
+ ...options,
2700
+ ...params
2701
+ });
2702
+ }
2703
+ }
2704
+
2705
+ class OpencodeClient extends HeyApiClient {
2706
+ static __registry = new HeyApiRegistry;
2707
+ constructor(args) {
2708
+ super(args);
2709
+ OpencodeClient.__registry.set(this, args?.key);
2710
+ }
2711
+ _global;
2712
+ get global() {
2713
+ return this._global ??= new Global({ client: this.client });
2714
+ }
2715
+ _auth;
2716
+ get auth() {
2717
+ return this._auth ??= new Auth({ client: this.client });
2718
+ }
2719
+ _project;
2720
+ get project() {
2721
+ return this._project ??= new Project({ client: this.client });
2722
+ }
2723
+ _pty;
2724
+ get pty() {
2725
+ return this._pty ??= new Pty({ client: this.client });
2726
+ }
2727
+ _config;
2728
+ get config() {
2729
+ return this._config ??= new Config2({ client: this.client });
2730
+ }
2731
+ _tool;
2732
+ get tool() {
2733
+ return this._tool ??= new Tool({ client: this.client });
2734
+ }
2735
+ _worktree;
2736
+ get worktree() {
2737
+ return this._worktree ??= new Worktree({ client: this.client });
2738
+ }
2739
+ _experimental;
2740
+ get experimental() {
2741
+ return this._experimental ??= new Experimental({ client: this.client });
2742
+ }
2743
+ _session;
2744
+ get session() {
2745
+ return this._session ??= new Session({ client: this.client });
2746
+ }
2747
+ _part;
2748
+ get part() {
2749
+ return this._part ??= new Part({ client: this.client });
2750
+ }
2751
+ _permission;
2752
+ get permission() {
2753
+ return this._permission ??= new Permission({ client: this.client });
2754
+ }
2755
+ _question;
2756
+ get question() {
2757
+ return this._question ??= new Question({ client: this.client });
2758
+ }
2759
+ _provider;
2760
+ get provider() {
2761
+ return this._provider ??= new Provider({ client: this.client });
2762
+ }
2763
+ _find;
2764
+ get find() {
2765
+ return this._find ??= new Find({ client: this.client });
2766
+ }
2767
+ _file;
2768
+ get file() {
2769
+ return this._file ??= new File({ client: this.client });
2770
+ }
2771
+ _mcp;
2772
+ get mcp() {
2773
+ return this._mcp ??= new Mcp({ client: this.client });
2774
+ }
2775
+ _tui;
2776
+ get tui() {
2777
+ return this._tui ??= new Tui({ client: this.client });
2778
+ }
2779
+ _instance;
2780
+ get instance() {
2781
+ return this._instance ??= new Instance({ client: this.client });
2782
+ }
2783
+ _path;
2784
+ get path() {
2785
+ return this._path ??= new Path({ client: this.client });
2786
+ }
2787
+ _vcs;
2788
+ get vcs() {
2789
+ return this._vcs ??= new Vcs({ client: this.client });
2790
+ }
2791
+ _command;
2792
+ get command() {
2793
+ return this._command ??= new Command({ client: this.client });
2794
+ }
2795
+ _app;
2796
+ get app() {
2797
+ return this._app ??= new App({ client: this.client });
2798
+ }
2799
+ _lsp;
2800
+ get lsp() {
2801
+ return this._lsp ??= new Lsp({ client: this.client });
2802
+ }
2803
+ _formatter;
2804
+ get formatter() {
2805
+ return this._formatter ??= new Formatter({ client: this.client });
2806
+ }
2807
+ _event;
2808
+ get event() {
2809
+ return this._event ??= new Event({ client: this.client });
2810
+ }
2811
+ }
2812
+
2813
+ // node_modules/@opencode-ai/sdk/dist/v2/client.js
2814
+ function createOpencodeClient(config) {
2815
+ if (!config?.fetch) {
2816
+ const customFetch = (req) => {
2817
+ req.timeout = false;
2818
+ return fetch(req);
2819
+ };
2820
+ config = {
2821
+ ...config,
2822
+ fetch: customFetch
2823
+ };
2824
+ }
2825
+ if (config?.directory) {
2826
+ const isNonASCII = /[^\x00-\x7F]/.test(config.directory);
2827
+ const encodedDirectory = isNonASCII ? encodeURIComponent(config.directory) : config.directory;
2828
+ config.headers = {
2829
+ ...config.headers,
2830
+ "x-opencode-directory": encodedDirectory
2831
+ };
2832
+ }
2833
+ const client2 = createClient(config);
2834
+ return new OpencodeClient({ client: client2 });
2835
+ }
2836
+
2837
+ // src/utils/opencode.ts
2838
+ var STORE = Bun.file(`${Bun.env.HOME}/Library/Application Support/ai.opencode.desktop/store.json`);
2839
+ var context = {
2840
+ client: Bun.env.OPENCODE_CLIENT ?? "unknown",
2841
+ password: Bun.env.OPENCODE_SERVER_PASSWORD,
2842
+ username: Bun.env.OPENCODE_SERVER_USERNAME
2843
+ };
2844
+ async function register(options) {
2845
+ if (context.client === "desktop") {
2846
+ const server = await getServer();
2847
+ const config = {
2848
+ username: context.username,
2849
+ password: context.password,
2850
+ seenAt: new Date,
2851
+ directory: options.directory,
2852
+ project: options.project,
2853
+ ...server
2854
+ };
2855
+ await Bun.write(STORE, JSON.stringify(config));
2856
+ return createOpencodeClient(createOpencodeClientConfigFromServerConfig(config));
2857
+ }
2858
+ return createOpencodeClient({
2859
+ directory: options.directory
2860
+ });
2861
+ }
2862
+ function createOpencodeClientConfigFromServerConfig(server) {
2863
+ return {
2864
+ baseUrl: `http://${server.hostname}:${server.port}`,
2865
+ headers: {
2866
+ Authorization: `Basic ${btoa(`${server.username}:${server.password}`)}`
2867
+ }
2868
+ };
2869
+ }
2870
+ async function getServer() {
2871
+ const process2 = await Bun.$`ps ax -o pid=,command= | grep "opencode-cli " | grep "serve" | grep -v grep`.nothrow().text();
2872
+ const pid = process2.match(/^(\d+)\s+/)?.[1];
2873
+ const hostname = process2.match(/--hostname\s+([\S]+)/)?.[1];
2874
+ const port = process2.match(/--port\s+(\d+)/)?.[1];
2875
+ return {
2876
+ pid: pid ? parseInt(pid, 10) : undefined,
2877
+ hostname,
2878
+ port: port ? parseInt(port, 10) : undefined
2879
+ };
2880
+ }
2881
+
2882
+ // src/utils/chain.ts
2883
+ async function chain(options, ...fns) {
2884
+ const { stopOnFatal = true } = options;
2885
+ for (const fn of fns) {
2886
+ await fn().catch((error) => {
2887
+ if (error instanceof ChainError) {
2888
+ if (error.severity === "BEGNIGN")
2889
+ return;
2890
+ if (error.severity === "WARNING")
2891
+ ;
2892
+ if (error.severity === "ERROR")
2893
+ ;
2894
+ if (error.severity === "FATAL") {
2895
+ if (stopOnFatal)
2896
+ throw error;
2897
+ }
2898
+ } else
2899
+ throw error;
2900
+ });
2901
+ }
2902
+ }
2903
+ function createBegnign(message, options) {
2904
+ return new ChainError(message, { severity: "BEGNIGN", ...options });
2905
+ }
2906
+ function createError(message, options) {
2907
+ return new ChainError(message, { severity: "ERROR", ...options });
2908
+ }
2909
+
2910
+ class ChainError extends Error {
2911
+ severity;
2912
+ stop;
2913
+ constructor(message, options) {
2914
+ super(message, { cause: options?.cause });
2915
+ this.severity = options?.severity ?? "BEGNIGN";
2916
+ this.stop = options?.stop ?? false;
2917
+ }
2918
+ }
2919
+
2920
+ // src/adapters/assets/specifications.ts
2921
+ import { z } from "zod";
2922
+ var MARKDOWN = new Bun.Glob("**/*.md");
2923
+ var Frontmatter = z.object({
2924
+ issue: z.string().optional()
2925
+ });
2926
+ // src/adapters/beads/agents.ts
2927
+ var exports_agents = {};
2928
+ __export(exports_agents, {
2929
+ use: () => use3,
2930
+ stuck: () => stuck,
2931
+ state: () => state,
2932
+ done: () => done
2933
+ });
2934
+
2935
+ // src/utils/shell/client.ts
2936
+ var exports_client = {};
2937
+ __export(exports_client, {
2938
+ use: () => use,
2939
+ create: () => create
2940
+ });
2941
+
2942
+ // src/utils/shell/error.ts
2943
+ class ShellError extends Error {
2944
+ output;
2945
+ constructor(output, options) {
2946
+ const stdout = output.stdout.toString().trim() || undefined;
2947
+ const stderr = output.stderr.toString().trim() || undefined;
2948
+ const message = stderr ?? stdout ?? "Unknown shell error";
2949
+ super(message, { cause: options.cause });
2950
+ this.output = output;
2951
+ }
2952
+ }
2953
+
2954
+ class InvalidExitCodeError extends Error {
2955
+ exitCode;
2956
+ constructor(output) {
2957
+ const exitCode = output.exitCode;
2958
+ super(`Exited with code '${exitCode}'`);
2959
+ this.exitCode = exitCode;
2960
+ }
2961
+ }
2962
+
2963
+ // src/utils/shell/client.ts
2964
+ function use(input) {
2965
+ if (input instanceof Bun.$.Shell)
2966
+ return create(input);
2967
+ if (SHELL_CLIENT in input)
2968
+ return input;
2969
+ throw new Error("Invalid client input");
2970
+ }
2971
+ function create(_$) {
2972
+ let shell = _$;
2973
+ const makeExec = (strings, ...expressions) => {
2974
+ let injected = 0;
2975
+ const parts = [...strings];
2976
+ const extended = expressions.flatMap((expr, i) => {
2977
+ if (!isObject(expr))
2978
+ return [expr];
2979
+ const options = listify(shake(expr), (key, value) => {
2980
+ if (isBoolean(value))
2981
+ return `--${key}`;
2982
+ if (isArray(value))
2983
+ return `--${key}=${sift(value).join(",")}`;
2984
+ return `--${key}='${String(value)}'`;
2985
+ });
2986
+ if (isEmpty(options))
2987
+ return [""];
2988
+ const separators = options.length - 1;
2989
+ parts.splice(i + 1 + injected, 0, ...Array(separators).fill(" "));
2990
+ injected += separators;
2991
+ return options;
2992
+ });
2993
+ const template = Object.assign(parts, {
2994
+ raw: [...parts]
2995
+ });
2996
+ const promise = shell(template, ...extended);
2997
+ return createPromise(promise);
2998
+ };
2999
+ const client2 = Object.assign(makeExec, {
3000
+ [SHELL_CLIENT]: true,
3001
+ cwd(path2) {
3002
+ shell = shell.cwd(path2);
3003
+ return client2;
3004
+ },
3005
+ env(vars) {
3006
+ shell = shell.env(vars);
3007
+ return client2;
3008
+ }
3009
+ });
3010
+ return client2;
3011
+ }
3012
+ var SHELL_CLIENT = Symbol("shell_client");
3013
+ function createPromise(shell) {
3014
+ return {
3015
+ json: async (options) => {
3016
+ const output = await shell.quiet(options?.quiet).nothrow();
3017
+ const [notJson, result] = await tryit(() => output.json())();
3018
+ if (result)
3019
+ return result;
3020
+ throw new ShellError(output, { cause: notJson });
3021
+ },
3022
+ text: async (options) => {
3023
+ const output = await shell.quiet(options?.quiet).nothrow();
3024
+ const out = output.stdout.toString().trim() || undefined;
3025
+ if (output.exitCode !== 0)
3026
+ return [new ShellError(output, { cause: new InvalidExitCodeError(output) }), out];
3027
+ return [undefined, out];
3028
+ }
3029
+ };
3030
+ }
3031
+ // src/adapters/beads/issues.ts
3032
+ var exports_issues = {};
3033
+ __export(exports_issues, {
3034
+ use: () => use2,
3035
+ update: () => update,
3036
+ show: () => show,
3037
+ list: () => list,
3038
+ find: () => find,
3039
+ close: () => close,
3040
+ claim: () => claim
3041
+ });
3042
+ var list = Object.assign(async (client2, options = {}) => {
3043
+ if (isEmpty(options.ids))
3044
+ return [];
3045
+ const $2 = exports_client.use(client2);
3046
+ const issues = await $2`bd list ${options} --json`.json();
3047
+ return issues;
3048
+ }, {
3049
+ ready: async (client2, options = {}) => {
3050
+ const $2 = exports_client.use(client2);
3051
+ const issues = await $2`bd ready ${options} --json`.json();
3052
+ return issues;
3053
+ }
3054
+ });
3055
+ async function use2(client2, input, options) {
3056
+ if ("status" in input && !options?.force)
3057
+ return input;
3058
+ return first(await list(client2, {
3059
+ ...options,
3060
+ ids: [input.id]
3061
+ }));
3062
+ }
3063
+ async function update(client2, input, options = {}) {
3064
+ const $2 = exports_client.use(client2);
3065
+ const issues = await $2`bd update ${input.id} ${options} --json`.json();
3066
+ const [issue] = issues;
3067
+ assert(issue, `Issue '${input.id}' not found`);
3068
+ return issue;
3069
+ }
3070
+ async function claim(client2, input, options = {}) {
3071
+ const $2 = exports_client.use(client2);
3072
+ const issues = await $2`bd update ${input.id} ${options} --claim --json`.json();
3073
+ const [issue] = issues;
3074
+ assert(issue, `Issue '${input.id}' not found`);
3075
+ return issue;
3076
+ }
3077
+ async function close(client2, input, options = {}) {
3078
+ const $2 = exports_client.use(client2);
3079
+ const issues = await $2`bd close ${input.id} ${options} --json`.json();
3080
+ const [issue] = issues;
3081
+ assert(issue, `Issue '${input.id}' not found`);
3082
+ return issue;
3083
+ }
3084
+ async function show(client2, input) {
3085
+ const $2 = exports_client.use(client2);
3086
+ return $2`bd show ${input.id}`.text();
3087
+ }
3088
+ var find;
3089
+ ((find) => {
3090
+ async function byExternalRef(client2, ref, options) {
3091
+ const _issues = await list(client2, options);
3092
+ return _issues.find((data) => data.external_ref === ref);
3093
+ }
3094
+ find.byExternalRef = byExternalRef;
3095
+ })(find ||= {});
3096
+
3097
+ // src/adapters/beads/agents.ts
3098
+ async function stuck(client2, slug, options) {
3099
+ const agent = await state(client2, slug, "stuck");
3100
+ await update(client2, { id: agent.agent }, {
3101
+ "add-label": createContextLabels(options.context),
3102
+ description: options.reason
3103
+ });
3104
+ return agent;
3105
+ }
3106
+ async function done(client2, slug, options = {}) {
3107
+ const agent = await state(client2, slug, "done");
3108
+ await update(client2, { id: agent.agent }, {
3109
+ "add-label": createContextLabels(options.context),
3110
+ description: ""
3111
+ });
3112
+ return agent;
3113
+ }
3114
+ async function state(client2, slug, state2) {
3115
+ const $2 = exports_client.use(client2);
3116
+ const agent = await $2`bd agent state gram-${slug} ${state2} --json`.json();
3117
+ return agent;
3118
+ }
3119
+ async function use3(client2, input) {
3120
+ const $2 = exports_client.use(client2);
3121
+ const id = "slug" in input ? `gram-${input.slug}` : input.id;
3122
+ const agent = await $2`bd agent show ${id} --json`.json();
3123
+ return agent;
3124
+ }
3125
+ function createContextLabels(context2) {
3126
+ if (!context2)
3127
+ return;
3128
+ const labels = sift(listify(context2, (key, value) => value && `${key}:${value}`));
3129
+ return isEmpty(labels) ? undefined : labels;
3130
+ }
3131
+ // src/adapters/beads/specifications.ts
3132
+ var find2;
3133
+ ((find) => {
3134
+ function byExternalRef(client2, ref) {
3135
+ return find.byExternalRef(client2, ref, { type: "epic" });
3136
+ }
3137
+ find.byExternalRef = byExternalRef;
3138
+ })(find2 ||= {});
3139
+ // src/adapters/beads/config.ts
3140
+ var exports_config = {};
3141
+ __export(exports_config, {
3142
+ issuePrefix: () => issuePrefix,
3143
+ get: () => get
3144
+ });
3145
+ async function issuePrefix(client2) {
3146
+ return get(client2, { key: "issue_prefix" });
3147
+ }
3148
+ async function get(client2, input) {
3149
+ const $2 = exports_client.use(client2);
3150
+ return await $2`bd config get ${input.key} --json`.json();
3151
+ }
3152
+ // node_modules/@bunli/utils/dist/index.js
3153
+ var colorCodes = {
3154
+ black: 30,
3155
+ red: 31,
3156
+ green: 32,
3157
+ yellow: 33,
3158
+ blue: 34,
3159
+ magenta: 35,
3160
+ cyan: 36,
3161
+ white: 37,
3162
+ gray: 90,
3163
+ brightRed: 91,
3164
+ brightGreen: 92,
3165
+ brightYellow: 93,
3166
+ brightBlue: 94,
3167
+ brightMagenta: 95,
3168
+ brightCyan: 96,
3169
+ brightWhite: 97,
3170
+ bgRed: 41,
3171
+ bgGreen: 42,
3172
+ bgYellow: 43,
3173
+ bgBlue: 44,
3174
+ bgMagenta: 45,
3175
+ bgCyan: 46,
3176
+ bgWhite: 47,
3177
+ bold: 1,
3178
+ dim: 2,
3179
+ italic: 3,
3180
+ underline: 4,
3181
+ strikethrough: 9,
3182
+ reset: 0
3183
+ };
3184
+ function createColorFunction(code) {
3185
+ return (text) => {
3186
+ if (!process.stdout.isTTY || process.env.NO_COLOR) {
3187
+ return text;
3188
+ }
3189
+ return `\x1B[${code}m${text}\x1B[0m`;
3190
+ };
3191
+ }
3192
+ function stripAnsi(text) {
3193
+ return text.replace(/\x1b\[[0-9;]*m/g, "");
3194
+ }
3195
+ var colors = {
3196
+ black: createColorFunction(colorCodes.black),
3197
+ red: createColorFunction(colorCodes.red),
3198
+ green: createColorFunction(colorCodes.green),
3199
+ yellow: createColorFunction(colorCodes.yellow),
3200
+ blue: createColorFunction(colorCodes.blue),
3201
+ magenta: createColorFunction(colorCodes.magenta),
3202
+ cyan: createColorFunction(colorCodes.cyan),
3203
+ white: createColorFunction(colorCodes.white),
3204
+ gray: createColorFunction(colorCodes.gray),
3205
+ brightRed: createColorFunction(colorCodes.brightRed),
3206
+ brightGreen: createColorFunction(colorCodes.brightGreen),
3207
+ brightYellow: createColorFunction(colorCodes.brightYellow),
3208
+ brightBlue: createColorFunction(colorCodes.brightBlue),
3209
+ brightMagenta: createColorFunction(colorCodes.brightMagenta),
3210
+ brightCyan: createColorFunction(colorCodes.brightCyan),
3211
+ brightWhite: createColorFunction(colorCodes.brightWhite),
3212
+ bgRed: createColorFunction(colorCodes.bgRed),
3213
+ bgGreen: createColorFunction(colorCodes.bgGreen),
3214
+ bgYellow: createColorFunction(colorCodes.bgYellow),
3215
+ bgBlue: createColorFunction(colorCodes.bgBlue),
3216
+ bgMagenta: createColorFunction(colorCodes.bgMagenta),
3217
+ bgCyan: createColorFunction(colorCodes.bgCyan),
3218
+ bgWhite: createColorFunction(colorCodes.bgWhite),
3219
+ bold: createColorFunction(colorCodes.bold),
3220
+ dim: createColorFunction(colorCodes.dim),
3221
+ italic: createColorFunction(colorCodes.italic),
3222
+ underline: createColorFunction(colorCodes.underline),
3223
+ strikethrough: createColorFunction(colorCodes.strikethrough),
3224
+ reset: createColorFunction(colorCodes.reset),
3225
+ strip: stripAnsi
3226
+ };
3227
+ var ESC = "\x1B";
3228
+ var CSI = `${ESC}[`;
3229
+ var CLEAR_LINE = `${CSI}2K`;
3230
+ var CURSOR_START = `${CSI}G`;
3231
+ var CURSOR_HIDE = `${CSI}?25l`;
3232
+ var CURSOR_SHOW = `${CSI}?25h`;
3233
+ async function readline(prompt) {
3234
+ process.stdout.write(prompt);
3235
+ for await (const line of console) {
3236
+ return line;
3237
+ }
3238
+ return "";
3239
+ }
3240
+ async function prompt(message, options = {}) {
3241
+ const defaultHint = options.default ? ` (${options.default})` : "";
3242
+ const promptText = `${message}${defaultHint} `;
3243
+ while (true) {
3244
+ const input = await readline(promptText);
3245
+ const value = input.trim() || options.default || "";
3246
+ if (options.schema) {
3247
+ const result = await options.schema["~standard"].validate(value);
3248
+ if (result.issues) {
3249
+ for (const issue of result.issues) {}
3250
+ continue;
3251
+ }
3252
+ return result.value;
3253
+ }
3254
+ if (options.validate) {
3255
+ const result = options.validate(value);
3256
+ if (result === true) {
3257
+ return value;
3258
+ } else if (typeof result === "string") {
3259
+ continue;
3260
+ } else {
3261
+ continue;
3262
+ }
3263
+ }
3264
+ return value;
3265
+ }
3266
+ }
3267
+ async function confirm(message, options = {}) {
3268
+ const defaultHint = options.default === true ? "Y/n" : options.default === false ? "y/N" : "y/n";
3269
+ const promptText = `${message} (${defaultHint}) `;
3270
+ while (true) {
3271
+ const input = await readline(promptText);
3272
+ const value = input.trim().toLowerCase();
3273
+ if (!value && options.default !== undefined) {
3274
+ return options.default;
3275
+ }
3276
+ if (value === "y" || value === "yes") {
3277
+ return true;
3278
+ }
3279
+ if (value === "n" || value === "no") {
3280
+ return false;
3281
+ }
3282
+ }
3283
+ }
3284
+ async function select(message, options) {
3285
+ const { options: choices, default: defaultValue } = options;
3286
+ let selectedIndex = defaultValue ? choices.findIndex((opt) => opt.value === defaultValue) : 0;
3287
+ if (selectedIndex === -1)
3288
+ selectedIndex = 0;
3289
+ process.stdout.write(CURSOR_HIDE);
3290
+ drawOptions(choices, selectedIndex);
3291
+ return new Promise((resolve) => {
3292
+ process.stdin.setRawMode(true);
3293
+ process.stdin.resume();
3294
+ const cleanup = () => {
3295
+ process.stdin.setRawMode(false);
3296
+ process.stdin.pause();
3297
+ process.stdout.write(CURSOR_SHOW);
3298
+ };
3299
+ process.stdin.on("data", (data) => {
3300
+ const key = data.toString();
3301
+ if (key === "\x1B[A") {
3302
+ selectedIndex = Math.max(0, selectedIndex - 1);
3303
+ drawOptions(choices, selectedIndex);
3304
+ } else if (key === "\x1B[B") {
3305
+ selectedIndex = Math.min(choices.length - 1, selectedIndex + 1);
3306
+ drawOptions(choices, selectedIndex);
3307
+ } else if (key === "\r" || key === `
3308
+ `) {
3309
+ cleanup();
3310
+ for (let i = 0;i < choices.length; i++) {
3311
+ process.stdout.write(`${CSI}1A${CLEAR_LINE}`);
3312
+ }
3313
+ const selected = choices[selectedIndex];
3314
+ if (selected) {
3315
+ resolve(selected.value);
3316
+ }
3317
+ } else if (key === "\x03" || key === "\x1B") {
3318
+ cleanup();
3319
+ process.exit(0);
3320
+ }
3321
+ });
3322
+ });
3323
+ }
3324
+ function drawOptions(options, selectedIndex) {
3325
+ for (let i = 0;i < options.length; i++) {
3326
+ process.stdout.write(`${CSI}1A`);
3327
+ }
3328
+ options.forEach((option, index) => {
3329
+ process.stdout.write(CLEAR_LINE + CURSOR_START);
3330
+ const prefix = index === selectedIndex ? "\u276F " : " ";
3331
+ const hint = option.hint ? ` (${option.hint})` : "";
3332
+ });
3333
+ }
3334
+ async function password(message, options = {}) {
3335
+ process.stdout.write(message + " ");
3336
+ return new Promise((resolve) => {
3337
+ let input = "";
3338
+ process.stdin.setRawMode(true);
3339
+ process.stdin.resume();
3340
+ const cleanup = () => {
3341
+ process.stdin.setRawMode(false);
3342
+ process.stdin.pause();
3343
+ };
3344
+ process.stdin.on("data", async (data) => {
3345
+ const key = data.toString();
3346
+ if (key === "\r" || key === `
3347
+ `) {
3348
+ cleanup();
3349
+ if (options.schema) {
3350
+ const result = await options.schema["~standard"].validate(input);
3351
+ if (result.issues) {
3352
+ for (const issue of result.issues) {}
3353
+ password(message, options).then(resolve);
3354
+ return;
3355
+ }
3356
+ resolve(result.value);
3357
+ } else if (options.validate) {
3358
+ const result = options.validate(input);
3359
+ if (result === true) {
3360
+ resolve(input);
3361
+ } else {
3362
+ const errorMsg = typeof result === "string" ? result : "Invalid input";
3363
+ password(message, options).then(resolve);
3364
+ }
3365
+ } else {
3366
+ resolve(input);
3367
+ }
3368
+ } else if (key === "\x03") {
3369
+ cleanup();
3370
+ process.exit(0);
3371
+ } else if (key === "\x7F" || key === "\b") {
3372
+ if (input.length > 0) {
3373
+ input = input.slice(0, -1);
3374
+ process.stdout.write("\b \b");
3375
+ }
3376
+ } else if (key.length === 1 && key >= " ") {
3377
+ input += key;
3378
+ process.stdout.write("*");
3379
+ }
3380
+ });
3381
+ });
3382
+ }
3383
+ var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
3384
+ var CLEAR_LINE2 = "\x1B[2K";
3385
+ var CURSOR_START2 = "\x1B[G";
3386
+ function createSpinner(options) {
3387
+ const config = typeof options === "string" ? { text: options } : options || {};
3388
+ let isSpinning = false;
3389
+ let frameIndex = 0;
3390
+ let intervalId = null;
3391
+ let currentText = config.text || "";
3392
+ const render = (symbol, text) => {
3393
+ process.stdout.write(`${CLEAR_LINE2}${CURSOR_START2}${symbol} ${text}`);
3394
+ };
3395
+ const spinner = {
3396
+ start(text) {
3397
+ if (isSpinning)
3398
+ return;
3399
+ isSpinning = true;
3400
+ if (text !== undefined) {
3401
+ currentText = text;
3402
+ }
3403
+ process.stdout.write("\x1B[?25l");
3404
+ intervalId = setInterval(() => {
3405
+ const frame = SPINNER_FRAMES[frameIndex];
3406
+ render(frame, currentText);
3407
+ frameIndex = (frameIndex + 1) % SPINNER_FRAMES.length;
3408
+ }, 80);
3409
+ },
3410
+ stop(text) {
3411
+ if (!isSpinning)
3412
+ return;
3413
+ isSpinning = false;
3414
+ if (intervalId) {
3415
+ clearInterval(intervalId);
3416
+ intervalId = null;
3417
+ }
3418
+ process.stdout.write(CLEAR_LINE2 + CURSOR_START2);
3419
+ process.stdout.write("\x1B[?25h");
3420
+ if (text) {}
3421
+ },
3422
+ succeed(text) {
3423
+ this.stop();
3424
+ },
3425
+ fail(text) {
3426
+ this.stop();
3427
+ },
3428
+ warn(text) {
3429
+ this.stop();
3430
+ },
3431
+ info(text) {
3432
+ this.stop();
3433
+ },
3434
+ update(text) {
3435
+ currentText = text;
3436
+ if (isSpinning) {
3437
+ render(SPINNER_FRAMES[frameIndex], currentText);
3438
+ }
3439
+ }
3440
+ };
3441
+ process.on("exit", () => spinner.stop());
3442
+ process.on("SIGINT", () => {
3443
+ spinner.stop();
3444
+ process.exit(0);
3445
+ });
3446
+ return spinner;
3447
+ }
3448
+ var utils = {
3449
+ prompt: Object.assign(prompt, {
3450
+ confirm,
3451
+ select,
3452
+ password,
3453
+ text: (message, options) => prompt(message, options),
3454
+ multiselect: async (message, options) => {
3455
+ const { options: choices } = options;
3456
+ const selected = [];
3457
+ for (const choice of choices) {
3458
+ const ok = await confirm(`Select ${choice.label}?`, { default: false });
3459
+ if (ok)
3460
+ selected.push(choice.value);
3461
+ }
3462
+ return selected;
3463
+ }
3464
+ }),
3465
+ spinner: createSpinner,
3466
+ colors
3467
+ };
3468
+ var prompt2 = Object.assign(prompt, {
3469
+ confirm,
3470
+ select,
3471
+ password,
3472
+ text: (message, options) => prompt(message, options),
3473
+ multiselect: async (message, options) => {
3474
+ const { options: choices } = options;
3475
+ const selected = [];
3476
+ for (const choice of choices) {
3477
+ const ok = await confirm(`Select ${choice.label}?`, { default: false });
3478
+ if (ok)
3479
+ selected.push(choice.value);
3480
+ }
3481
+ return selected;
3482
+ }
3483
+ });
3484
+
3485
+ // src/adapters/environments/worktrees.ts
3486
+ var semaphore = new Semaphore(1);
3487
+ // src/use-cases/inject-beads-issue.ts
3488
+ var WHITE_LISTED_COMMANDS = new Set(["work", "fake_work"]);
3489
+ async function injectBeadsIssue(options) {
3490
+ const { input } = options;
3491
+ assert(!WHITE_LISTED_COMMANDS.has(input.command), createBegnign(`Command '${input.command}' is not withe-listed`));
3492
+ const $2 = Bun.$.cwd(options.directory);
3493
+ const log = createLog(input.command);
3494
+ const issueId = first(input.arguments.split(" "));
3495
+ assert(issueId, createBegnign(`Issue ID not found`));
3496
+ const prefix = await exports_config.issuePrefix($2);
3497
+ assert(issueId.startsWith(prefix.value), createBegnign(`Issue ID: ${issueId}, expected to start with '${prefix.value}' prefix`));
3498
+ const alreadyInjected = options.output.parts.some((part) => part.type === "text" && part.metadata?.["injected_beads_issue_id"] === issueId);
3499
+ assert(alreadyInjected, createBegnign(`Injection for '${issueId}' already exists, skipped.`));
3500
+ const [error, injection] = await exports_issues.show($2, { id: issueId });
3501
+ assert(error === undefined, createError(`Failed to inject issue ${issueId}: ${error}`));
3502
+ assert(injection, createError(`Nothing to inject for issue '${issueId}'`));
3503
+ const partToInject = createInjectionPart(issueId, injection);
3504
+ const shouldReplaceOnExistingMessage = options.input.arguments.trim() === issueId;
3505
+ if (shouldReplaceOnExistingMessage) {
3506
+ const partToEdit = options.output.parts.find((part) => part.type === "text" && part.text.includes(issueId));
3507
+ if (partToEdit && partToEdit.type === "text") {
3508
+ partToEdit.text = partToEdit.text.replace(issueId, partToInject.text);
3509
+ partToEdit.metadata = Object.assign({}, partToEdit.metadata, partToInject.metadata);
3510
+ log(`Message updated with issue '${issueId}' injection`);
3511
+ return;
3512
+ }
3513
+ }
3514
+ options.output.parts.push(partToInject);
3515
+ log(`Message part added with issue '${issueId}' injection`);
3516
+ }
3517
+ function createInjectionPart(issueId, content) {
3518
+ return {
3519
+ type: "text",
3520
+ text: dedent`
3521
+ <issue>
3522
+ ${content}
3523
+ </issue>
3524
+ `,
3525
+ metadata: {
3526
+ injected_beads_issue_id: issueId
3527
+ }
3528
+ };
3529
+ }
3530
+ function createLog(command) {
3531
+ return (message) => {};
3532
+ }
3533
+ // node_modules/@opencode-ai/plugin/dist/tool.js
3534
+ import { z as z2 } from "zod";
3535
+ function tool(input) {
3536
+ return input;
3537
+ }
3538
+ tool.schema = z2;
3539
+ // src/tools/i-am-stuck.ts
3540
+ var createIAmStuck = (client2) => tool({
3541
+ description: dedent`
3542
+ Inform your manager that you are stuck and cannot proceed with the task. The manager will then jump in to help you out.
3543
+ Use this tool when:
3544
+ - You need human intervention to proceed with the task.
3545
+ - You face an issue that you cannot resolve on your own.
3546
+ `,
3547
+ args: {
3548
+ reason: tool.schema.string().describe("Describe why you are stuck and what kind of help you need.")
3549
+ },
3550
+ execute: async (args, ctx) => {
3551
+ const session = await client2.session.get({
3552
+ sessionID: ctx.sessionID,
3553
+ directory: ctx.directory
3554
+ });
3555
+ assert(session.data, `Failed to fetch session: ${JSON.stringify(session.error)}`);
3556
+ const message = await client2.session.message({
3557
+ sessionID: ctx.sessionID,
3558
+ messageID: ctx.messageID,
3559
+ directory: ctx.directory
3560
+ });
3561
+ assert(message.data, `Failed to fetch session message: ${JSON.stringify(session.error)}`);
3562
+ const { info } = message.data;
3563
+ await exports_agents.stuck(Bun.$.cwd(session.data.directory), session.data.slug, {
3564
+ reason: args.reason,
3565
+ context: {
3566
+ agent: ctx.agent,
3567
+ model: info.role === "user" ? info.model.modelID : info.modelID,
3568
+ provider: info.role === "user" ? info.model.providerID : info.providerID
3569
+ }
3570
+ });
3571
+ return dedent`
3572
+ Your manager has been notified. Please wait for him to jump in and help you out.
3573
+ `;
3574
+ }
3575
+ });
3576
+ // src/tools/i-am-done.ts
3577
+ var createIAmDone = (client2) => tool({
3578
+ description: dedent`
3579
+ Inform your manager that you are done with the task. The manager will then review your work and handle the rest.
3580
+ Use this tool when:
3581
+ - All acceptance criteria are met and you have completed the task.
3582
+ - Right before returning
3583
+ `,
3584
+ args: {},
3585
+ execute: async (_args, ctx) => {
3586
+ const session = await client2.session.get({
3587
+ sessionID: ctx.sessionID,
3588
+ directory: ctx.directory
3589
+ });
3590
+ assert(session.data, `Failed to fetch session: ${JSON.stringify(session.error)}`);
3591
+ const message = await client2.session.message({
3592
+ sessionID: ctx.sessionID,
3593
+ messageID: ctx.messageID,
3594
+ directory: ctx.directory
3595
+ });
3596
+ assert(message.data, `Failed to fetch session message: ${JSON.stringify(session.error)}`);
3597
+ const { info } = message.data;
3598
+ await exports_agents.done(Bun.$.cwd(session.data.directory), session.data.slug, {
3599
+ context: {
3600
+ agent: ctx.agent,
3601
+ model: info.role === "user" ? info.model.modelID : info.modelID,
3602
+ provider: info.role === "user" ? info.model.providerID : info.providerID
3603
+ }
3604
+ });
3605
+ return dedent`
3606
+ You are marked as done. Your manager will review your work and come back to you if needed.
3607
+ `;
3608
+ }
3609
+ });
3610
+ // src/plugin.ts
3611
+ var TeammatePlugin = async (options) => {
3612
+ const { directory } = options;
3613
+ const client2 = await register(options);
3614
+ await install(directory);
3615
+ return {
3616
+ "command.execute.before": async (input, output) => {
3617
+ await chain({ stopOnFatal: true }, () => injectBeadsIssue({
3618
+ client: client2,
3619
+ directory,
3620
+ input,
3621
+ output
3622
+ }));
3623
+ },
3624
+ tool: {
3625
+ i_am_stuck: createIAmStuck(client2),
3626
+ i_am_done: createIAmDone(client2)
3627
+ }
3628
+ };
3629
+ };
3630
+ var plugin_default = TeammatePlugin;
3631
+ export {
3632
+ plugin_default as default,
3633
+ TeammatePlugin
3634
+ };