bugzero 0.0.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.
@@ -0,0 +1,14 @@
1
+
2
+ > bugzero@0.0.1 build D:\WD projects\OpsPilot\packages\cli
3
+ > tsup src/index.ts --format esm --dts
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Target: es2022
9
+ ESM Build start
10
+ ESM dist\index.js 41.55 KB
11
+ ESM ⚡️ Build success in 165ms
12
+ DTS Build start
13
+ DTS ⚡️ Build success in 1740ms
14
+ DTS dist\index.d.ts 20.00 B
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/index.js ADDED
@@ -0,0 +1,1028 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // ../../node_modules/.pnpm/dotenv@17.4.2/node_modules/dotenv/lib/main.js
35
+ var require_main = __commonJS({
36
+ "../../node_modules/.pnpm/dotenv@17.4.2/node_modules/dotenv/lib/main.js"(exports, module) {
37
+ "use strict";
38
+ var fs = __require("fs");
39
+ var path2 = __require("path");
40
+ var os = __require("os");
41
+ var crypto = __require("crypto");
42
+ var TIPS = [
43
+ "\u25C8 encrypted .env [www.dotenvx.com]",
44
+ "\u25C8 secrets for agents [www.dotenvx.com]",
45
+ "\u2301 auth for agents [www.vestauth.com]",
46
+ "\u2318 custom filepath { path: '/custom/path/.env' }",
47
+ "\u2318 enable debugging { debug: true }",
48
+ "\u2318 override existing { override: true }",
49
+ "\u2318 suppress logs { quiet: true }",
50
+ "\u2318 multiple files { path: ['.env.local', '.env'] }"
51
+ ];
52
+ function _getRandomTip() {
53
+ return TIPS[Math.floor(Math.random() * TIPS.length)];
54
+ }
55
+ function parseBoolean(value) {
56
+ if (typeof value === "string") {
57
+ return !["false", "0", "no", "off", ""].includes(value.toLowerCase());
58
+ }
59
+ return Boolean(value);
60
+ }
61
+ function supportsAnsi() {
62
+ return process.stdout.isTTY;
63
+ }
64
+ function dim(text) {
65
+ return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
66
+ }
67
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
68
+ function parse(src) {
69
+ const obj = {};
70
+ let lines = src.toString();
71
+ lines = lines.replace(/\r\n?/mg, "\n");
72
+ let match;
73
+ while ((match = LINE.exec(lines)) != null) {
74
+ const key = match[1];
75
+ let value = match[2] || "";
76
+ value = value.trim();
77
+ const maybeQuote = value[0];
78
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
79
+ if (maybeQuote === '"') {
80
+ value = value.replace(/\\n/g, "\n");
81
+ value = value.replace(/\\r/g, "\r");
82
+ }
83
+ obj[key] = value;
84
+ }
85
+ return obj;
86
+ }
87
+ function _parseVault(options) {
88
+ options = options || {};
89
+ const vaultPath = _vaultPath(options);
90
+ options.path = vaultPath;
91
+ const result = DotenvModule.configDotenv(options);
92
+ if (!result.parsed) {
93
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
94
+ err.code = "MISSING_DATA";
95
+ throw err;
96
+ }
97
+ const keys = _dotenvKey(options).split(",");
98
+ const length = keys.length;
99
+ let decrypted;
100
+ for (let i = 0; i < length; i++) {
101
+ try {
102
+ const key = keys[i].trim();
103
+ const attrs = _instructions(result, key);
104
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
105
+ break;
106
+ } catch (error) {
107
+ if (i + 1 >= length) {
108
+ throw error;
109
+ }
110
+ }
111
+ }
112
+ return DotenvModule.parse(decrypted);
113
+ }
114
+ function _warn(message) {
115
+ console.error(`\u26A0 ${message}`);
116
+ }
117
+ function _debug(message) {
118
+ console.log(`\u2506 ${message}`);
119
+ }
120
+ function _log(message) {
121
+ console.log(`\u25C7 ${message}`);
122
+ }
123
+ function _dotenvKey(options) {
124
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
125
+ return options.DOTENV_KEY;
126
+ }
127
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
128
+ return process.env.DOTENV_KEY;
129
+ }
130
+ return "";
131
+ }
132
+ function _instructions(result, dotenvKey) {
133
+ let uri;
134
+ try {
135
+ uri = new URL(dotenvKey);
136
+ } catch (error) {
137
+ if (error.code === "ERR_INVALID_URL") {
138
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
139
+ err.code = "INVALID_DOTENV_KEY";
140
+ throw err;
141
+ }
142
+ throw error;
143
+ }
144
+ const key = uri.password;
145
+ if (!key) {
146
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
147
+ err.code = "INVALID_DOTENV_KEY";
148
+ throw err;
149
+ }
150
+ const environment = uri.searchParams.get("environment");
151
+ if (!environment) {
152
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
153
+ err.code = "INVALID_DOTENV_KEY";
154
+ throw err;
155
+ }
156
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
157
+ const ciphertext = result.parsed[environmentKey];
158
+ if (!ciphertext) {
159
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
160
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
161
+ throw err;
162
+ }
163
+ return { ciphertext, key };
164
+ }
165
+ function _vaultPath(options) {
166
+ let possibleVaultPath = null;
167
+ if (options && options.path && options.path.length > 0) {
168
+ if (Array.isArray(options.path)) {
169
+ for (const filepath of options.path) {
170
+ if (fs.existsSync(filepath)) {
171
+ possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
172
+ }
173
+ }
174
+ } else {
175
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
176
+ }
177
+ } else {
178
+ possibleVaultPath = path2.resolve(process.cwd(), ".env.vault");
179
+ }
180
+ if (fs.existsSync(possibleVaultPath)) {
181
+ return possibleVaultPath;
182
+ }
183
+ return null;
184
+ }
185
+ function _resolveHome(envPath) {
186
+ return envPath[0] === "~" ? path2.join(os.homedir(), envPath.slice(1)) : envPath;
187
+ }
188
+ function _configVault(options) {
189
+ const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
190
+ const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
191
+ if (debug || !quiet) {
192
+ _log("loading env from encrypted .env.vault");
193
+ }
194
+ const parsed = DotenvModule._parseVault(options);
195
+ let processEnv = process.env;
196
+ if (options && options.processEnv != null) {
197
+ processEnv = options.processEnv;
198
+ }
199
+ DotenvModule.populate(processEnv, parsed, options);
200
+ return { parsed };
201
+ }
202
+ function configDotenv(options) {
203
+ const dotenvPath = path2.resolve(process.cwd(), ".env");
204
+ let encoding = "utf8";
205
+ let processEnv = process.env;
206
+ if (options && options.processEnv != null) {
207
+ processEnv = options.processEnv;
208
+ }
209
+ let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
210
+ let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
211
+ if (options && options.encoding) {
212
+ encoding = options.encoding;
213
+ } else {
214
+ if (debug) {
215
+ _debug("no encoding is specified (UTF-8 is used by default)");
216
+ }
217
+ }
218
+ let optionPaths = [dotenvPath];
219
+ if (options && options.path) {
220
+ if (!Array.isArray(options.path)) {
221
+ optionPaths = [_resolveHome(options.path)];
222
+ } else {
223
+ optionPaths = [];
224
+ for (const filepath of options.path) {
225
+ optionPaths.push(_resolveHome(filepath));
226
+ }
227
+ }
228
+ }
229
+ let lastError;
230
+ const parsedAll = {};
231
+ for (const path3 of optionPaths) {
232
+ try {
233
+ const parsed = DotenvModule.parse(fs.readFileSync(path3, { encoding }));
234
+ DotenvModule.populate(parsedAll, parsed, options);
235
+ } catch (e) {
236
+ if (debug) {
237
+ _debug(`failed to load ${path3} ${e.message}`);
238
+ }
239
+ lastError = e;
240
+ }
241
+ }
242
+ const populated = DotenvModule.populate(processEnv, parsedAll, options);
243
+ debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
244
+ quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
245
+ if (debug || !quiet) {
246
+ const keysCount = Object.keys(populated).length;
247
+ const shortPaths = [];
248
+ for (const filePath of optionPaths) {
249
+ try {
250
+ const relative = path2.relative(process.cwd(), filePath);
251
+ shortPaths.push(relative);
252
+ } catch (e) {
253
+ if (debug) {
254
+ _debug(`failed to load ${filePath} ${e.message}`);
255
+ }
256
+ lastError = e;
257
+ }
258
+ }
259
+ _log(`injected env (${keysCount}) from ${shortPaths.join(",")} ${dim(`// tip: ${_getRandomTip()}`)}`);
260
+ }
261
+ if (lastError) {
262
+ return { parsed: parsedAll, error: lastError };
263
+ } else {
264
+ return { parsed: parsedAll };
265
+ }
266
+ }
267
+ function config(options) {
268
+ if (_dotenvKey(options).length === 0) {
269
+ return DotenvModule.configDotenv(options);
270
+ }
271
+ const vaultPath = _vaultPath(options);
272
+ if (!vaultPath) {
273
+ _warn(`you set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}`);
274
+ return DotenvModule.configDotenv(options);
275
+ }
276
+ return DotenvModule._configVault(options);
277
+ }
278
+ function decrypt(encrypted, keyStr) {
279
+ const key = Buffer.from(keyStr.slice(-64), "hex");
280
+ let ciphertext = Buffer.from(encrypted, "base64");
281
+ const nonce = ciphertext.subarray(0, 12);
282
+ const authTag = ciphertext.subarray(-16);
283
+ ciphertext = ciphertext.subarray(12, -16);
284
+ try {
285
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
286
+ aesgcm.setAuthTag(authTag);
287
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
288
+ } catch (error) {
289
+ const isRange = error instanceof RangeError;
290
+ const invalidKeyLength = error.message === "Invalid key length";
291
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
292
+ if (isRange || invalidKeyLength) {
293
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
294
+ err.code = "INVALID_DOTENV_KEY";
295
+ throw err;
296
+ } else if (decryptionFailed) {
297
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
298
+ err.code = "DECRYPTION_FAILED";
299
+ throw err;
300
+ } else {
301
+ throw error;
302
+ }
303
+ }
304
+ }
305
+ function populate(processEnv, parsed, options = {}) {
306
+ const debug = Boolean(options && options.debug);
307
+ const override = Boolean(options && options.override);
308
+ const populated = {};
309
+ if (typeof parsed !== "object") {
310
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
311
+ err.code = "OBJECT_REQUIRED";
312
+ throw err;
313
+ }
314
+ for (const key of Object.keys(parsed)) {
315
+ if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
316
+ if (override === true) {
317
+ processEnv[key] = parsed[key];
318
+ populated[key] = parsed[key];
319
+ }
320
+ if (debug) {
321
+ if (override === true) {
322
+ _debug(`"${key}" is already defined and WAS overwritten`);
323
+ } else {
324
+ _debug(`"${key}" is already defined and was NOT overwritten`);
325
+ }
326
+ }
327
+ } else {
328
+ processEnv[key] = parsed[key];
329
+ populated[key] = parsed[key];
330
+ }
331
+ }
332
+ return populated;
333
+ }
334
+ var DotenvModule = {
335
+ configDotenv,
336
+ _configVault,
337
+ _parseVault,
338
+ config,
339
+ decrypt,
340
+ parse,
341
+ populate
342
+ };
343
+ module.exports.configDotenv = DotenvModule.configDotenv;
344
+ module.exports._configVault = DotenvModule._configVault;
345
+ module.exports._parseVault = DotenvModule._parseVault;
346
+ module.exports.config = DotenvModule.config;
347
+ module.exports.decrypt = DotenvModule.decrypt;
348
+ module.exports.parse = DotenvModule.parse;
349
+ module.exports.populate = DotenvModule.populate;
350
+ module.exports = DotenvModule;
351
+ }
352
+ });
353
+
354
+ // ../config/dist/index.js
355
+ var require_dist = __commonJS({
356
+ "../config/dist/index.js"(exports, module) {
357
+ "use strict";
358
+ var __create2 = Object.create;
359
+ var __defProp2 = Object.defineProperty;
360
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
361
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
362
+ var __getProtoOf2 = Object.getPrototypeOf;
363
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
364
+ var __export = (target, all) => {
365
+ for (var name in all)
366
+ __defProp2(target, name, { get: all[name], enumerable: true });
367
+ };
368
+ var __copyProps2 = (to, from, except, desc) => {
369
+ if (from && typeof from === "object" || typeof from === "function") {
370
+ for (let key of __getOwnPropNames2(from))
371
+ if (!__hasOwnProp2.call(to, key) && key !== except)
372
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
373
+ }
374
+ return to;
375
+ };
376
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
377
+ // If the importer is in node compatibility mode or this is not an ESM
378
+ // file that has been converted to a CommonJS file using a Babel-
379
+ // compatible transform (i.e. "__esModule" has not been set), then set
380
+ // "default" to the CommonJS "module.exports" for node compatibility.
381
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
382
+ mod
383
+ ));
384
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
385
+ var index_exports = {};
386
+ __export(index_exports, {
387
+ env: () => env
388
+ });
389
+ module.exports = __toCommonJS(index_exports);
390
+ var import_dotenv = __toESM2(require_main());
391
+ import_dotenv.default.config();
392
+ var env = {
393
+ openRouterKey: process.env.OPENROUTER_API_KEY
394
+ };
395
+ }
396
+ });
397
+
398
+ // ../analyzers/dist/index.js
399
+ var require_dist2 = __commonJS({
400
+ "../analyzers/dist/index.js"(exports, module) {
401
+ "use strict";
402
+ var __defProp2 = Object.defineProperty;
403
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
404
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
405
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
406
+ var __export = (target, all) => {
407
+ for (var name in all)
408
+ __defProp2(target, name, { get: all[name], enumerable: true });
409
+ };
410
+ var __copyProps2 = (to, from, except, desc) => {
411
+ if (from && typeof from === "object" || typeof from === "function") {
412
+ for (let key of __getOwnPropNames2(from))
413
+ if (!__hasOwnProp2.call(to, key) && key !== except)
414
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
415
+ }
416
+ return to;
417
+ };
418
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
419
+ var index_exports = {};
420
+ __export(index_exports, {
421
+ parseErrors: () => parseErrors,
422
+ runBuild: () => runBuild,
423
+ runCommand: () => runCommand,
424
+ runLint: () => runLint,
425
+ runTests: () => runTests
426
+ });
427
+ module.exports = __toCommonJS(index_exports);
428
+ async function runCommand(command, cwd) {
429
+ const { execa } = await import("execa");
430
+ try {
431
+ const result = await execa(command, {
432
+ shell: true,
433
+ cwd: cwd ?? process.cwd(),
434
+ all: true
435
+ });
436
+ return {
437
+ success: true,
438
+ output: result.all ?? result.stdout
439
+ };
440
+ } catch (err) {
441
+ return {
442
+ success: false,
443
+ output: err.all ?? err.stderr ?? err.stdout ?? err.message
444
+ };
445
+ }
446
+ }
447
+ var runBuild = (cwd) => runCommand("npm run build", cwd);
448
+ var runLint = (cwd) => runCommand("npm run lint", cwd);
449
+ var runTests = (cwd) => runCommand("npm run test", cwd);
450
+ var TS_ERROR_RE = /^(.+)\((\d+),(\d+)\):\s+error\s+TS\d+:\s+(.+)$/gm;
451
+ var ESLINT_ERROR_RE = /^\s+(\d+):(\d+)\s+error\s+(.+)$/gm;
452
+ var JEST_FAIL_RE = /● (.+)/g;
453
+ var JEST_FILE_RE = /FAIL\s+([\w/\\.\-]+)/g;
454
+ function parseErrors(output) {
455
+ const errors = [];
456
+ const tsMatches = [...output.matchAll(TS_ERROR_RE)];
457
+ for (const m of tsMatches) {
458
+ errors.push({
459
+ type: "typescript",
460
+ file: m[1].trim(),
461
+ line: parseInt(m[2], 10),
462
+ column: parseInt(m[3], 10),
463
+ message: m[4].trim(),
464
+ raw: m[0]
465
+ });
466
+ }
467
+ if (errors.length > 0) return errors;
468
+ const eslintMatches = [...output.matchAll(ESLINT_ERROR_RE)];
469
+ for (const m of eslintMatches) {
470
+ errors.push({
471
+ type: "eslint",
472
+ line: parseInt(m[1], 10),
473
+ column: parseInt(m[2], 10),
474
+ message: m[3].trim(),
475
+ raw: m[0]
476
+ });
477
+ }
478
+ if (errors.length > 0) return errors;
479
+ const jestFiles = [...output.matchAll(JEST_FILE_RE)].map((m) => m[1]);
480
+ const jestFails = [...output.matchAll(JEST_FAIL_RE)];
481
+ for (const m of jestFails) {
482
+ errors.push({
483
+ type: "jest",
484
+ file: jestFiles[0],
485
+ message: m[1].trim(),
486
+ raw: m[0]
487
+ });
488
+ }
489
+ if (errors.length > 0) return errors;
490
+ if (output.trim()) {
491
+ errors.push({
492
+ type: "unknown",
493
+ message: output.slice(0, 500),
494
+ raw: output
495
+ });
496
+ }
497
+ return errors;
498
+ }
499
+ }
500
+ });
501
+
502
+ // ../ai-provider/dist/index.js
503
+ var require_dist3 = __commonJS({
504
+ "../ai-provider/dist/index.js"(exports, module) {
505
+ "use strict";
506
+ var __create2 = Object.create;
507
+ var __defProp2 = Object.defineProperty;
508
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
509
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
510
+ var __getProtoOf2 = Object.getPrototypeOf;
511
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
512
+ var __export = (target, all) => {
513
+ for (var name in all)
514
+ __defProp2(target, name, { get: all[name], enumerable: true });
515
+ };
516
+ var __copyProps2 = (to, from, except, desc) => {
517
+ if (from && typeof from === "object" || typeof from === "function") {
518
+ for (let key of __getOwnPropNames2(from))
519
+ if (!__hasOwnProp2.call(to, key) && key !== except)
520
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
521
+ }
522
+ return to;
523
+ };
524
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
525
+ // If the importer is in node compatibility mode or this is not an ESM
526
+ // file that has been converted to a CommonJS file using a Babel-
527
+ // compatible transform (i.e. "__esModule" has not been set), then set
528
+ // "default" to the CommonJS "module.exports" for node compatibility.
529
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
530
+ mod
531
+ ));
532
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
533
+ var index_exports = {};
534
+ __export(index_exports, {
535
+ OpenRouterProvider: () => OpenRouterProvider
536
+ });
537
+ module.exports = __toCommonJS(index_exports);
538
+ var import_axios = __toESM2(__require("axios"));
539
+ var OpenRouterProvider = class {
540
+ async invoke(prompt) {
541
+ const response = await import_axios.default.post(
542
+ "https://openrouter.ai/api/v1/chat/completions",
543
+ {
544
+ model: "anthropic/claude-sonnet-4",
545
+ messages: [
546
+ {
547
+ role: "user",
548
+ content: prompt
549
+ }
550
+ ]
551
+ },
552
+ {
553
+ headers: {
554
+ Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`,
555
+ "Content-Type": "application/json"
556
+ }
557
+ }
558
+ );
559
+ return response.data.choices[0].message.content;
560
+ }
561
+ };
562
+ }
563
+ });
564
+
565
+ // ../prompts/dist/index.js
566
+ var require_dist4 = __commonJS({
567
+ "../prompts/dist/index.js"(exports, module) {
568
+ "use strict";
569
+ var __defProp2 = Object.defineProperty;
570
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
571
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
572
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
573
+ var __export = (target, all) => {
574
+ for (var name in all)
575
+ __defProp2(target, name, { get: all[name], enumerable: true });
576
+ };
577
+ var __copyProps2 = (to, from, except, desc) => {
578
+ if (from && typeof from === "object" || typeof from === "function") {
579
+ for (let key of __getOwnPropNames2(from))
580
+ if (!__hasOwnProp2.call(to, key) && key !== except)
581
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
582
+ }
583
+ return to;
584
+ };
585
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
586
+ var index_exports = {};
587
+ __export(index_exports, {
588
+ buildAnalysisPrompt: () => buildAnalysisPrompt
589
+ });
590
+ module.exports = __toCommonJS(index_exports);
591
+ function buildAnalysisPrompt(errorOutput, cwd) {
592
+ return `You are an expert software engineer specialising in fixing build, lint, and test failures.
593
+
594
+ A project located at "${cwd}" failed to build. Here is the complete error output:
595
+
596
+ \`\`\`
597
+ ${errorOutput}
598
+ \`\`\`
599
+
600
+ Your task:
601
+ 1. Identify the root cause.
602
+ 2. Locate the exact file and code that needs to change.
603
+ 3. Provide the minimal, precise fix.
604
+
605
+ Reply with ONLY a valid JSON object in this exact shape \u2014 no markdown fences, no extra text:
606
+ {
607
+ "rootCause": "One-sentence explanation of the error",
608
+ "filePath": "relative/path/from/project/root/to/file.ts",
609
+ "search": "exact code that currently exists in the file and must be replaced",
610
+ "replace": "the corrected code that replaces the search string",
611
+ "explanation": "short explanation of what you changed and why"
612
+ }
613
+
614
+ Critical rules:
615
+ - "filePath" must be a relative path from the project root (no leading /).
616
+ - "search" must be an EXACT character-for-character substring of the current file content.
617
+ - "replace" must be syntactically valid code.
618
+ - Do NOT add backticks, markdown, or any text outside the JSON object.`;
619
+ }
620
+ }
621
+ });
622
+
623
+ // ../patcher/dist/index.js
624
+ var require_dist5 = __commonJS({
625
+ "../patcher/dist/index.js"(exports, module) {
626
+ "use strict";
627
+ var __create2 = Object.create;
628
+ var __defProp2 = Object.defineProperty;
629
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
630
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
631
+ var __getProtoOf2 = Object.getPrototypeOf;
632
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
633
+ var __export = (target, all) => {
634
+ for (var name in all)
635
+ __defProp2(target, name, { get: all[name], enumerable: true });
636
+ };
637
+ var __copyProps2 = (to, from, except, desc) => {
638
+ if (from && typeof from === "object" || typeof from === "function") {
639
+ for (let key of __getOwnPropNames2(from))
640
+ if (!__hasOwnProp2.call(to, key) && key !== except)
641
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
642
+ }
643
+ return to;
644
+ };
645
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
646
+ // If the importer is in node compatibility mode or this is not an ESM
647
+ // file that has been converted to a CommonJS file using a Babel-
648
+ // compatible transform (i.e. "__esModule" has not been set), then set
649
+ // "default" to the CommonJS "module.exports" for node compatibility.
650
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
651
+ mod
652
+ ));
653
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
654
+ var index_exports = {};
655
+ __export(index_exports, {
656
+ applyPatch: () => applyPatch
657
+ });
658
+ module.exports = __toCommonJS(index_exports);
659
+ var import_fs = __toESM2(__require("fs"));
660
+ var import_path2 = __toESM2(__require("path"));
661
+ function applyPatch(absoluteFilePath, search, replace) {
662
+ try {
663
+ if (!import_fs.default.existsSync(absoluteFilePath)) {
664
+ return {
665
+ success: false,
666
+ error: `File not found: ${absoluteFilePath}`
667
+ };
668
+ }
669
+ const original = import_fs.default.readFileSync(absoluteFilePath, "utf-8");
670
+ if (!original.includes(search)) {
671
+ return {
672
+ success: false,
673
+ error: `Search string not found in ${import_path2.default.basename(absoluteFilePath)}. The AI's "search" field did not match file content.`
674
+ };
675
+ }
676
+ const backupPath = absoluteFilePath + ".opspilot.bak";
677
+ import_fs.default.writeFileSync(backupPath, original, "utf-8");
678
+ const fixed = original.replace(search, replace);
679
+ import_fs.default.writeFileSync(absoluteFilePath, fixed, "utf-8");
680
+ return { success: true, backupPath };
681
+ } catch (err) {
682
+ return { success: false, error: err.message };
683
+ }
684
+ }
685
+ }
686
+ });
687
+
688
+ // ../agents/dist/index.js
689
+ var require_dist6 = __commonJS({
690
+ "../agents/dist/index.js"(exports, module) {
691
+ "use strict";
692
+ var __create2 = Object.create;
693
+ var __defProp2 = Object.defineProperty;
694
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
695
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
696
+ var __getProtoOf2 = Object.getPrototypeOf;
697
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
698
+ var __export = (target, all) => {
699
+ for (var name in all)
700
+ __defProp2(target, name, { get: all[name], enumerable: true });
701
+ };
702
+ var __copyProps2 = (to, from, except, desc) => {
703
+ if (from && typeof from === "object" || typeof from === "function") {
704
+ for (let key of __getOwnPropNames2(from))
705
+ if (!__hasOwnProp2.call(to, key) && key !== except)
706
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
707
+ }
708
+ return to;
709
+ };
710
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
711
+ // If the importer is in node compatibility mode or this is not an ESM
712
+ // file that has been converted to a CommonJS file using a Babel-
713
+ // compatible transform (i.e. "__esModule" has not been set), then set
714
+ // "default" to the CommonJS "module.exports" for node compatibility.
715
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
716
+ mod
717
+ ));
718
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
719
+ var index_exports = {};
720
+ __export(index_exports, {
721
+ workflow: () => workflow
722
+ });
723
+ module.exports = __toCommonJS(index_exports);
724
+ var import_langgraph2 = __require("@langchain/langgraph");
725
+ var import_path2 = __toESM2(__require("path"));
726
+ var import_langgraph = __require("@langchain/langgraph");
727
+ var GraphState = import_langgraph.Annotation.Root({
728
+ /** Absolute path to the project being fixed */
729
+ cwd: (0, import_langgraph.Annotation)({
730
+ reducer: (_, value) => value,
731
+ default: () => process.cwd()
732
+ }),
733
+ /** Raw error output from the failing command */
734
+ logs: (0, import_langgraph.Annotation)({
735
+ reducer: (_, value) => value,
736
+ default: () => ""
737
+ }),
738
+ /** Full text response from the AI */
739
+ analysis: (0, import_langgraph.Annotation)({
740
+ reducer: (_, value) => value,
741
+ default: () => ""
742
+ }),
743
+ /** Structured fix parsed from the AI response */
744
+ fixSuggestion: (0, import_langgraph.Annotation)({
745
+ reducer: (_, value) => value,
746
+ default: () => null
747
+ }),
748
+ /** Number of fix attempts made so far */
749
+ attempts: (0, import_langgraph.Annotation)({
750
+ reducer: (_, value) => value,
751
+ default: () => 0
752
+ }),
753
+ /** Maximum allowed attempts before giving up */
754
+ maxAttempts: (0, import_langgraph.Annotation)({
755
+ reducer: (_, value) => value,
756
+ default: () => 3
757
+ }),
758
+ /** Whether the last build verification succeeded */
759
+ success: (0, import_langgraph.Annotation)({
760
+ reducer: (_, value) => value,
761
+ default: () => false
762
+ })
763
+ });
764
+ var import_ai_provider = require_dist3();
765
+ var import_prompts = require_dist4();
766
+ var import_patcher = require_dist5();
767
+ var import_analyzers = require_dist2();
768
+ var provider = new import_ai_provider.OpenRouterProvider();
769
+ async function analyzeNode(state) {
770
+ console.log(
771
+ `
772
+ [OpsPilot] Attempt ${state.attempts + 1}/${state.maxAttempts} \u2014 asking AI\u2026`
773
+ );
774
+ const prompt = (0, import_prompts.buildAnalysisPrompt)(state.logs, state.cwd);
775
+ const response = await provider.invoke(prompt);
776
+ let fixSuggestion = null;
777
+ try {
778
+ const cleaned = response.replace(/```json\n?/g, "").replace(/```\n?/g, "").trim();
779
+ const jsonMatch = cleaned.match(/\{[\s\S]*\}/);
780
+ if (jsonMatch) {
781
+ fixSuggestion = JSON.parse(jsonMatch[0]);
782
+ } else {
783
+ console.warn("[OpsPilot] AI response did not contain a valid JSON object.");
784
+ }
785
+ } catch (e) {
786
+ console.error("[OpsPilot] Failed to parse AI response:", e);
787
+ }
788
+ return {
789
+ analysis: response,
790
+ fixSuggestion,
791
+ attempts: state.attempts + 1
792
+ };
793
+ }
794
+ async function applyFixNode(state) {
795
+ if (!state.fixSuggestion) {
796
+ console.warn("[OpsPilot] No fix suggestion available \u2014 skipping patch.");
797
+ return {};
798
+ }
799
+ const { filePath, search, replace, explanation } = state.fixSuggestion;
800
+ const absolutePath = import_path2.default.resolve(state.cwd, filePath);
801
+ console.log(`[OpsPilot] Patching: ${filePath}`);
802
+ console.log(`[OpsPilot] Reason: ${explanation}`);
803
+ const result = (0, import_patcher.applyPatch)(absolutePath, search, replace);
804
+ if (!result.success) {
805
+ console.error(`[OpsPilot] Patch failed: ${result.error}`);
806
+ } else {
807
+ console.log(`[OpsPilot] Backup saved to: ${result.backupPath}`);
808
+ }
809
+ return {};
810
+ }
811
+ async function verifyNode(state) {
812
+ console.log("[OpsPilot] Re-running build to verify fix\u2026");
813
+ const result = await (0, import_analyzers.runBuild)(state.cwd);
814
+ if (result.success) {
815
+ console.log("[OpsPilot] \u2705 Build succeeded!");
816
+ } else {
817
+ console.log("[OpsPilot] \u274C Build still failing. New error output captured.");
818
+ }
819
+ return {
820
+ success: result.success,
821
+ logs: result.success ? "" : result.output
822
+ };
823
+ }
824
+ function shouldRetry(state) {
825
+ if (state.success) return import_langgraph2.END;
826
+ if (state.attempts >= state.maxAttempts) {
827
+ console.log(
828
+ `[OpsPilot] Max attempts (${state.maxAttempts}) reached \u2014 giving up.`
829
+ );
830
+ return import_langgraph2.END;
831
+ }
832
+ return "analyze";
833
+ }
834
+ var workflow = new import_langgraph2.StateGraph(GraphState).addNode("analyze", analyzeNode).addNode("apply_fix", applyFixNode).addNode("verify", verifyNode).addEdge(import_langgraph2.START, "analyze").addEdge("analyze", "apply_fix").addEdge("apply_fix", "verify").addConditionalEdges("verify", shouldRetry).compile();
835
+ }
836
+ });
837
+
838
+ // ../core/dist/index.js
839
+ var require_dist7 = __commonJS({
840
+ "../core/dist/index.js"(exports, module) {
841
+ "use strict";
842
+ var __create2 = Object.create;
843
+ var __defProp2 = Object.defineProperty;
844
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
845
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
846
+ var __getProtoOf2 = Object.getPrototypeOf;
847
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
848
+ var __export = (target, all) => {
849
+ for (var name in all)
850
+ __defProp2(target, name, { get: all[name], enumerable: true });
851
+ };
852
+ var __copyProps2 = (to, from, except, desc) => {
853
+ if (from && typeof from === "object" || typeof from === "function") {
854
+ for (let key of __getOwnPropNames2(from))
855
+ if (!__hasOwnProp2.call(to, key) && key !== except)
856
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
857
+ }
858
+ return to;
859
+ };
860
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
861
+ // If the importer is in node compatibility mode or this is not an ESM
862
+ // file that has been converted to a CommonJS file using a Babel-
863
+ // compatible transform (i.e. "__esModule" has not been set), then set
864
+ // "default" to the CommonJS "module.exports" for node compatibility.
865
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
866
+ mod
867
+ ));
868
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
869
+ var index_exports = {};
870
+ __export(index_exports, {
871
+ detectFramework: () => detectFramework2,
872
+ orchestrate: () => orchestrate2,
873
+ orchestrateAndFix: () => orchestrateAndFix2
874
+ });
875
+ module.exports = __toCommonJS(index_exports);
876
+ var import_fs = __toESM2(__require("fs"));
877
+ var import_path2 = __toESM2(__require("path"));
878
+ function detectFramework2(cwd = process.cwd()) {
879
+ const has = (...files) => files.some((f) => import_fs.default.existsSync(import_path2.default.join(cwd, f)));
880
+ if (has("next.config.js", "next.config.ts", "next.config.mjs")) return "nextjs";
881
+ if (has("nest-cli.json")) return "nestjs";
882
+ if (has("vite.config.ts", "vite.config.js", "vite.config.mts")) return "vite";
883
+ if (has("remix.config.js", "remix.config.ts")) return "remix";
884
+ if (has("astro.config.mjs", "astro.config.ts", "astro.config.js")) return "astro";
885
+ if (has("svelte.config.js", "svelte.config.ts")) return "sveltekit";
886
+ if (has("nuxt.config.ts", "nuxt.config.js")) return "nuxt";
887
+ const pkgPath = import_path2.default.join(cwd, "package.json");
888
+ if (import_fs.default.existsSync(pkgPath)) {
889
+ try {
890
+ const pkg = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf-8"));
891
+ const deps = {
892
+ ...pkg.dependencies ?? {},
893
+ ...pkg.devDependencies ?? {}
894
+ };
895
+ if (deps["react-scripts"]) return "create-react-app";
896
+ if (deps["@angular/core"]) return "angular";
897
+ } catch {
898
+ }
899
+ }
900
+ if (has("tsconfig.json")) return "typescript";
901
+ return "unknown";
902
+ }
903
+ var import_analyzers = require_dist2();
904
+ var import_agents = require_dist6();
905
+ async function orchestrate2(options = {}) {
906
+ const cwd = options.cwd ?? process.cwd();
907
+ const [build, lint, test] = await Promise.all([
908
+ (0, import_analyzers.runBuild)(cwd),
909
+ (0, import_analyzers.runLint)(cwd),
910
+ (0, import_analyzers.runTests)(cwd)
911
+ ]);
912
+ return { build, lint, test };
913
+ }
914
+ async function orchestrateAndFix2(options = {}) {
915
+ const cwd = options.cwd ?? process.cwd();
916
+ const maxAttempts = options.maxAttempts ?? 3;
917
+ console.log(`[OpsPilot] Running build in: ${cwd}`);
918
+ const buildResult = await (0, import_analyzers.runBuild)(cwd);
919
+ if (buildResult.success) {
920
+ console.log("[OpsPilot] Build already passing \u2014 nothing to fix.");
921
+ return { success: true, attempts: 0, finalOutput: buildResult.output };
922
+ }
923
+ const errors = (0, import_analyzers.parseErrors)(buildResult.output);
924
+ console.log(`[OpsPilot] Detected ${errors.length} error(s) (type: ${errors[0]?.type ?? "unknown"})`);
925
+ if (options.dryRun) {
926
+ console.log("[OpsPilot] Dry-run mode \u2014 skipping AI fix.");
927
+ return {
928
+ success: false,
929
+ attempts: 0,
930
+ finalOutput: buildResult.output,
931
+ error: "Dry-run: analysis complete, no files modified."
932
+ };
933
+ }
934
+ const finalState = await import_agents.workflow.invoke({
935
+ cwd,
936
+ logs: buildResult.output,
937
+ maxAttempts,
938
+ attempts: 0,
939
+ success: false
940
+ });
941
+ return {
942
+ success: finalState.success,
943
+ attempts: finalState.attempts,
944
+ finalOutput: finalState.logs || buildResult.output,
945
+ appliedFix: finalState.fixSuggestion ?? void 0,
946
+ error: finalState.success ? void 0 : `Max attempts (${maxAttempts}) reached without a successful build.`
947
+ };
948
+ }
949
+ }
950
+ });
951
+
952
+ // src/index.ts
953
+ var import_config = __toESM(require_dist(), 1);
954
+ var import_core = __toESM(require_dist7(), 1);
955
+ import { Command } from "commander";
956
+ import path from "path";
957
+ var program = new Command();
958
+ program.name("bugzero").description("AI-powered build issue fixer \u2014 detects and repairs build errors automatically").version("0.0.1");
959
+ program.command("analyze").description("Run build, lint, and tests \u2014 report issues without modifying files").option("-p, --path <dir>", "Path to the target project", ".").action(async (opts) => {
960
+ const cwd = path.resolve(opts.path);
961
+ const framework = (0, import_core.detectFramework)(cwd);
962
+ console.log(`
963
+ \u{1F50D} BugZero \u2014 Analyzing project`);
964
+ console.log(` Path: ${cwd}`);
965
+ console.log(` Framework: ${framework}
966
+ `);
967
+ const { build, lint, test } = await (0, import_core.orchestrate)({ cwd });
968
+ console.log("\u2500\u2500 Build \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
969
+ if (build.success) {
970
+ console.log(" \u2705 Passed");
971
+ } else {
972
+ console.log(" \u274C Failed\n");
973
+ console.log(build.output);
974
+ }
975
+ console.log("\n\u2500\u2500 Lint \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
976
+ if (lint.success) {
977
+ console.log(" \u2705 Passed");
978
+ } else {
979
+ console.log(" \u274C Failed\n");
980
+ console.log(lint.output);
981
+ }
982
+ console.log("\n\u2500\u2500 Tests \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
983
+ if (test.success) {
984
+ console.log(" \u2705 Passed");
985
+ } else {
986
+ console.log(" \u274C Failed\n");
987
+ console.log(test.output);
988
+ }
989
+ const allPassed = build.success && lint.success && test.success;
990
+ console.log(`
991
+ ${allPassed ? "\u2705 All checks passed" : "\u274C Issues found \u2014 run 'bugzero fix' to repair"}
992
+ `);
993
+ process.exit(allPassed ? 0 : 1);
994
+ });
995
+ program.command("fix").description("Detect build failures and automatically apply AI-generated fixes").option("-p, --path <dir>", "Path to the target project", ".").option("-n, --max-attempts <number>", "Maximum AI fix attempts", "3").option("--dry-run", "Analyse only \u2014 print what would be fixed without writing files", false).action(async (opts) => {
996
+ const cwd = path.resolve(opts.path);
997
+ const maxAttempts = parseInt(opts.maxAttempts, 10);
998
+ const dryRun = opts.dryRun;
999
+ const framework = (0, import_core.detectFramework)(cwd);
1000
+ console.log(`
1001
+ \u{1F916} BugZero Fix`);
1002
+ console.log(` Path: ${cwd}`);
1003
+ console.log(` Framework: ${framework}`);
1004
+ console.log(` Max attempts: ${maxAttempts}`);
1005
+ if (dryRun) console.log(` Mode: DRY RUN (no files will be modified)`);
1006
+ console.log();
1007
+ const result = await (0, import_core.orchestrateAndFix)({ cwd, maxAttempts, dryRun });
1008
+ console.log("\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
1009
+ if (result.success) {
1010
+ console.log(`\u2705 Build fixed after ${result.attempts} attempt(s)!`);
1011
+ if (result.appliedFix) {
1012
+ console.log(` File: ${result.appliedFix.filePath}`);
1013
+ console.log(` Reason: ${result.appliedFix.explanation}`);
1014
+ console.log(` Root cause: ${result.appliedFix.rootCause}`);
1015
+ }
1016
+ } else {
1017
+ console.log(`\u274C Could not fix build after ${result.attempts} attempt(s).`);
1018
+ if (result.error) console.log(` ${result.error}`);
1019
+ }
1020
+ console.log();
1021
+ process.exit(result.success ? 0 : 1);
1022
+ });
1023
+ program.command("protect").description("[Deprecated] Use 'analyze' instead").action(async () => {
1024
+ console.warn("\u26A0\uFE0F 'protect' is deprecated \u2014 use 'bugzero analyze' instead.\n");
1025
+ const result = await (0, import_core.orchestrate)();
1026
+ console.log(result);
1027
+ });
1028
+ program.parse();
package/dist/index.mjs ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { Command } from "commander";
5
+ import { orchestrate } from "@opspilot/core";
6
+ var program = new Command();
7
+ program.command("protect").action(async () => {
8
+ const result = await orchestrate();
9
+ console.log(result);
10
+ });
11
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "bugzero",
3
+ "version": "0.0.1",
4
+ "bin": {
5
+ "bugzero": "dist/index.js"
6
+ },
7
+ "dependencies": {
8
+ "@langchain/core": "^1.1.48",
9
+ "@langchain/langgraph": "^1.3.2",
10
+ "axios": "^1.16.1",
11
+ "commander": "^15.0.0",
12
+ "execa": "^7.2.0"
13
+ },
14
+ "devDependencies": {
15
+ "@opspilot/agents": "0.0.1",
16
+ "@opspilot/config": "0.0.1",
17
+ "@opspilot/core": "0.0.1"
18
+ },
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "type": "module",
22
+ "scripts": {
23
+ "build": "tsup src/index.ts --format esm --dts"
24
+ }
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ import "@opspilot/config"; // loads .env before anything else
4
+ import { Command } from "commander";
5
+ import path from "path";
6
+ import { orchestrate, orchestrateAndFix, detectFramework } from "@opspilot/core";
7
+
8
+
9
+ const program = new Command();
10
+
11
+ program
12
+ .name("bugzero")
13
+ .description("AI-powered build issue fixer — detects and repairs build errors automatically")
14
+ .version("0.0.1");
15
+
16
+ // ── bugzero analyze ─────────────────────────────────────────────────────────
17
+ program
18
+ .command("analyze")
19
+ .description("Run build, lint, and tests — report issues without modifying files")
20
+ .option("-p, --path <dir>", "Path to the target project", ".")
21
+ .action(async (opts) => {
22
+ const cwd = path.resolve(opts.path);
23
+ const framework = detectFramework(cwd);
24
+
25
+ console.log(`\n🔍 BugZero — Analyzing project`);
26
+ console.log(` Path: ${cwd}`);
27
+ console.log(` Framework: ${framework}\n`);
28
+
29
+ const { build, lint, test } = await orchestrate({ cwd });
30
+
31
+ console.log("── Build ──────────────────────────────────────");
32
+ if (build.success) {
33
+ console.log(" ✅ Passed");
34
+ } else {
35
+ console.log(" ❌ Failed\n");
36
+ console.log(build.output);
37
+ }
38
+
39
+ console.log("\n── Lint ───────────────────────────────────────");
40
+ if (lint.success) {
41
+ console.log(" ✅ Passed");
42
+ } else {
43
+ console.log(" ❌ Failed\n");
44
+ console.log(lint.output);
45
+ }
46
+
47
+ console.log("\n── Tests ──────────────────────────────────────");
48
+ if (test.success) {
49
+ console.log(" ✅ Passed");
50
+ } else {
51
+ console.log(" ❌ Failed\n");
52
+ console.log(test.output);
53
+ }
54
+
55
+ const allPassed = build.success && lint.success && test.success;
56
+ console.log(`\n${allPassed ? "✅ All checks passed" : "❌ Issues found — run 'bugzero fix' to repair"}\n`);
57
+ process.exit(allPassed ? 0 : 1);
58
+ });
59
+
60
+ // ── bugzero fix ─────────────────────────────────────────────────────────────
61
+ program
62
+ .command("fix")
63
+ .description("Detect build failures and automatically apply AI-generated fixes")
64
+ .option("-p, --path <dir>", "Path to the target project", ".")
65
+ .option("-n, --max-attempts <number>", "Maximum AI fix attempts", "3")
66
+ .option("--dry-run", "Analyse only — print what would be fixed without writing files", false)
67
+ .action(async (opts) => {
68
+ const cwd = path.resolve(opts.path);
69
+ const maxAttempts = parseInt(opts.maxAttempts, 10);
70
+ const dryRun: boolean = opts.dryRun;
71
+ const framework = detectFramework(cwd);
72
+
73
+ console.log(`\n🤖 BugZero Fix`);
74
+ console.log(` Path: ${cwd}`);
75
+ console.log(` Framework: ${framework}`);
76
+ console.log(` Max attempts: ${maxAttempts}`);
77
+ if (dryRun) console.log(` Mode: DRY RUN (no files will be modified)`);
78
+ console.log();
79
+
80
+ const result = await orchestrateAndFix({ cwd, maxAttempts, dryRun });
81
+
82
+ console.log("\n──────────────────────────────────────────────");
83
+ if (result.success) {
84
+ console.log(`✅ Build fixed after ${result.attempts} attempt(s)!`);
85
+ if (result.appliedFix) {
86
+ console.log(` File: ${result.appliedFix.filePath}`);
87
+ console.log(` Reason: ${result.appliedFix.explanation}`);
88
+ console.log(` Root cause: ${result.appliedFix.rootCause}`);
89
+ }
90
+ } else {
91
+ console.log(`❌ Could not fix build after ${result.attempts} attempt(s).`);
92
+ if (result.error) console.log(` ${result.error}`);
93
+ }
94
+ console.log();
95
+
96
+ process.exit(result.success ? 0 : 1);
97
+ });
98
+
99
+ // ── bugzero protect (legacy) ────────────────────────────────────────────────
100
+ program
101
+ .command("protect")
102
+ .description("[Deprecated] Use 'analyze' instead")
103
+ .action(async () => {
104
+ console.warn("⚠️ 'protect' is deprecated — use 'bugzero analyze' instead.\n");
105
+ const result = await orchestrate();
106
+ console.log(result);
107
+ });
108
+
109
+ program.parse();
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src"
6
+ },
7
+ "include": ["src"]
8
+ }