@kud/ai-conventional-commit-cli 3.2.2 → 3.2.5

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 (50) hide show
  1. package/dist/{chunk-IWJLYYKM.js → chunk-EHJXGWTJ.js} +3 -19
  2. package/dist/{chunk-OLEHSPCO.js → chunk-GVOA4OR7.js} +55 -16
  3. package/dist/index.cjs +1200 -0
  4. package/dist/index.d.cts +1 -0
  5. package/dist/index.js +60 -44
  6. package/dist/{reword-6EWRZ6WZ.js → reword-BKQ7K33J.js} +1 -1
  7. package/dist/{reword-D5YVSCPO.js → reword-QQO7UBGM.js} +3 -1
  8. package/package.json +1 -1
  9. package/dist/chunk-2WRUFO3O.js +0 -689
  10. package/dist/chunk-2X3JJVRR.js +0 -639
  11. package/dist/chunk-7FBRAH4R.js +0 -643
  12. package/dist/chunk-7U4J2ORD.js +0 -614
  13. package/dist/chunk-CC3NIT53.js +0 -650
  14. package/dist/chunk-CLQ6OPLU.js +0 -668
  15. package/dist/chunk-F3BOAVBY.js +0 -122
  16. package/dist/chunk-FYJNHXAR.js +0 -700
  17. package/dist/chunk-H4W6AMGZ.js +0 -549
  18. package/dist/chunk-HJR5M6U7.js +0 -120
  19. package/dist/chunk-HOUMTU6H.js +0 -699
  20. package/dist/chunk-KEEMHNNS.js +0 -628
  21. package/dist/chunk-RHXNXVGI.js +0 -621
  22. package/dist/chunk-SNV4RWS4.js +0 -696
  23. package/dist/chunk-W7OC77AV.js +0 -649
  24. package/dist/chunk-WFXVVHL2.js +0 -645
  25. package/dist/chunk-YIXP5EWA.js +0 -545
  26. package/dist/chunk-YRVQGOVW.js +0 -649
  27. package/dist/chunk-ZLYMV2NJ.js +0 -644
  28. package/dist/config-C3S4LWLD.js +0 -12
  29. package/dist/config-RHGCFLHQ.js +0 -12
  30. package/dist/reword-2ASH5EH5.js +0 -212
  31. package/dist/reword-3MH2DYFS.js +0 -212
  32. package/dist/reword-CZDYMQEV.js +0 -150
  33. package/dist/reword-ESY2TLBT.js +0 -212
  34. package/dist/reword-FE5N4MGV.js +0 -150
  35. package/dist/reword-IN2D2J4H.js +0 -212
  36. package/dist/reword-JRE6KAF7.js +0 -212
  37. package/dist/reword-KIR2DMTO.js +0 -212
  38. package/dist/reword-KUE3IVBE.js +0 -212
  39. package/dist/reword-LIVSGNUN.js +0 -212
  40. package/dist/reword-MCQOCOZ2.js +0 -212
  41. package/dist/reword-NGEKVTD6.js +0 -212
  42. package/dist/reword-PEOUOAT7.js +0 -212
  43. package/dist/reword-Q7MES34W.js +0 -212
  44. package/dist/reword-T44WTP5I.js +0 -212
  45. package/dist/reword-UA3EG7DK.js +0 -212
  46. package/dist/reword-UE5IP5V3.js +0 -212
  47. package/dist/reword-VKG5G6CB.js +0 -212
  48. package/dist/reword-VRH7B6BE.js +0 -205
  49. package/dist/reword-WFCNTOEU.js +0 -203
  50. package/dist/reword-XWYWVQRZ.js +0 -212
@@ -171,18 +171,7 @@ Refine now.`
171
171
 
172
172
  // src/model/provider.ts
173
173
  import { z } from "zod";
174
- import { createServer } from "net";
175
174
  import { createOpencode } from "@opencode-ai/sdk";
176
- function findFreePort() {
177
- return new Promise((resolve, reject) => {
178
- const server = createServer();
179
- server.on("error", reject);
180
- server.listen(0, "127.0.0.1", () => {
181
- const port = server.address().port;
182
- server.close(() => resolve(port));
183
- });
184
- });
185
- }
186
175
  var OpenCodeProvider = class {
187
176
  constructor(model = "github-copilot/gpt-4.1") {
188
177
  this.model = model;
@@ -221,16 +210,11 @@ ${userAggregate}`;
221
210
  const start = Date.now();
222
211
  let server;
223
212
  try {
224
- if (debug) console.error("[ai-cc][provider] starting opencode server");
225
- const port = await findFreePort();
226
- const opencode = await createOpencode({ signal: ac.signal, port });
213
+ const opencode = await createOpencode({ signal: ac.signal });
227
214
  server = opencode.server;
228
- const client = opencode.client;
215
+ const { client } = opencode;
229
216
  const session = await client.session.create({ body: { title: "aicc" } });
230
- if (!session.data) {
231
- const errMsg = session.error?.message ?? JSON.stringify(session.error) ?? "unknown";
232
- throw new Error(`Failed to create opencode session: ${errMsg}`);
233
- }
217
+ if (!session.data) throw new Error("Failed to create opencode session");
234
218
  const result = await client.session.prompt({
235
219
  path: { id: session.data.id },
236
220
  body: {
@@ -201,7 +201,8 @@ import { createServer } from "net";
201
201
  import { mkdirSync, writeFileSync } from "fs";
202
202
  import { join } from "path";
203
203
  import { tmpdir } from "os";
204
- import { createOpencode } from "@opencode-ai/sdk/v2";
204
+ import { spawn } from "child_process";
205
+ import { createOpencodeClient } from "@opencode-ai/sdk/v2";
205
206
  import chalk2 from "chalk";
206
207
  var pTag = chalk2.dim("[ai-cc]") + chalk2.cyan("[provider]");
207
208
  var pdbg = (msg, pairs = {}) => {
@@ -267,18 +268,60 @@ var OpenCodeProvider = class {
267
268
  const isolatedDir = join(tmpdir(), `aicc-${process.pid}`, "opencode");
268
269
  mkdirSync(isolatedDir, { recursive: true });
269
270
  writeFileSync(join(isolatedDir, "config.json"), '{"mcp":{}}');
271
+ const port = await findFreePort();
270
272
  const originalXDG = process.env.XDG_CONFIG_HOME;
271
273
  process.env.XDG_CONFIG_HOME = join(tmpdir(), `aicc-${process.pid}`);
272
- let opencode;
273
- try {
274
- const port = await findFreePort();
275
- opencode = await createOpencode({ signal: this.ac.signal, port });
276
- } finally {
277
- if (originalXDG === void 0) delete process.env.XDG_CONFIG_HOME;
278
- else process.env.XDG_CONFIG_HOME = originalXDG;
279
- }
280
- const { server, client } = opencode;
281
- this.syncClose = () => server?.close();
274
+ const proc = spawn("opencode", ["serve", `--hostname=127.0.0.1`, `--port=${port}`], {
275
+ env: { ...process.env, OPENCODE_CONFIG_CONTENT: JSON.stringify({ mcp: {} }) }
276
+ });
277
+ const killProc = () => {
278
+ try {
279
+ process.kill(proc.pid, "SIGTERM");
280
+ } catch {
281
+ }
282
+ };
283
+ this.syncClose = killProc;
284
+ if (originalXDG === void 0) delete process.env.XDG_CONFIG_HOME;
285
+ else process.env.XDG_CONFIG_HOME = originalXDG;
286
+ const url = await new Promise((resolve, reject) => {
287
+ const id = setTimeout(
288
+ () => reject(new Error(`Timeout waiting for opencode server after 10s`)),
289
+ 1e4
290
+ );
291
+ let output = "";
292
+ proc.stdout?.on("data", (chunk) => {
293
+ output += chunk.toString();
294
+ for (const line of output.split("\n")) {
295
+ if (!line.startsWith("opencode server listening")) continue;
296
+ const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
297
+ if (!match) {
298
+ reject(new Error(`Failed to parse server url: ${line}`));
299
+ return;
300
+ }
301
+ clearTimeout(id);
302
+ resolve(match[1]);
303
+ return;
304
+ }
305
+ });
306
+ proc.stderr?.on("data", (chunk) => {
307
+ output += chunk.toString();
308
+ });
309
+ proc.on("exit", (code) => {
310
+ clearTimeout(id);
311
+ reject(new Error(`Server exited with code ${code}
312
+ ${output}`));
313
+ });
314
+ proc.on("error", (err) => {
315
+ clearTimeout(id);
316
+ reject(err);
317
+ });
318
+ this.ac.signal.addEventListener("abort", () => {
319
+ clearTimeout(id);
320
+ killProc();
321
+ reject(new Error("Aborted"));
322
+ });
323
+ });
324
+ const client = createOpencodeClient({ baseUrl: url });
282
325
  if (this.debug) {
283
326
  const mcpStatusResult = await client.mcp.status();
284
327
  pdbg("mcp status", { status: JSON.stringify(mcpStatusResult.data) });
@@ -289,7 +332,7 @@ var OpenCodeProvider = class {
289
332
  throw new Error(`Failed to create opencode session: ${errMsg}`);
290
333
  }
291
334
  if (this.debug) pdbg("session created", { id: sessionResult.data.id });
292
- return { client, server, sessionID: sessionResult.data.id };
335
+ return { client, server: { url, close: killProc }, sessionID: sessionResult.data.id };
293
336
  }
294
337
  async chat(messages, _opts) {
295
338
  const mockMode = process.env.AICC_DEBUG_PROVIDER === "mock";
@@ -316,10 +359,8 @@ ${userAggregate}`;
316
359
  const providerID = slashIdx !== -1 ? this.model.slice(0, slashIdx) : this.model;
317
360
  const modelID = slashIdx !== -1 ? this.model.slice(slashIdx + 1) : this.model;
318
361
  const start = Date.now();
319
- let server;
320
362
  try {
321
363
  const ctx = await (this.warmPromise ?? this._startServer());
322
- server = ctx.server;
323
364
  if (this.debug) {
324
365
  pdbg("sending prompt", { model: this.model, promptChars: fullPrompt.length });
325
366
  }
@@ -355,8 +396,6 @@ ${userAggregate}`;
355
396
  }
356
397
  if (this.debug) pdbg(chalk2.red("call failed"), { error: e.message });
357
398
  throw new Error(e.message || "opencode SDK call failed");
358
- } finally {
359
- server?.close();
360
399
  }
361
400
  }
362
401
  };