bugzero 0.0.43 → 0.0.45

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 (3) hide show
  1. package/README.md +16 -1
  2. package/dist/index.js +155 -16
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -114,6 +114,7 @@ bugzero rescue
114
114
  ### Integrations and output
115
115
 
116
116
  - **Markdown reports.** Every `hunt` and `rescue` run writes `bugzero-report.md` to the target project: a pass/fail summary of build, lint, and tests, the full error logs, the model used, token usage, and before/after diffs for every file patched. The terminal prints a clickable link straight to it.
117
+ - **JSON output.** Add `--json` to `hunt` or `rescue` to print the result as a single JSON document on stdout, with all human-readable logs moved to stderr and the exit code unchanged (0 on success, 1 otherwise), so scripts and CI can parse it. See [Scripting and CI](#scripting-and-ci).
117
118
  - **GitHub Action mode.** Run the same repair loop in CI. Instead of patching a local checkout, the Action commits every changed file in one atomic commit through the GitHub API and opens a pull request — see [GitHub Action Mode](#github-action-mode) below.
118
119
 
119
120
  ---
@@ -191,7 +192,7 @@ OPENROUTER_API_KEY=your_openrouter_api_key_here
191
192
  ## Commands
192
193
 
193
194
  ### `bugzero hunt`
194
- Run build, lint, and test checks. Reports all failures without modifying any files. Accepts `--timeout <seconds>`, like `rescue`.
195
+ Run build, lint, and test checks. Reports all failures without modifying any files. Accepts `--timeout <seconds>` and `--json`, like `rescue`.
195
196
 
196
197
  ```bash
197
198
  bugzero hunt --path /path/to/your/project
@@ -213,6 +214,7 @@ bugzero rescue --path /path/to/your/project
213
214
  | `--max-attempts <n>` | `-n` | `3` | Maximum AI fix iterations before giving up |
214
215
  | `--timeout <seconds>` | `-t` | none | Stop any build, lint, or test command that runs longer than this many seconds |
215
216
  | `--dry-run` | | `false` | Analyze only — no files will be written |
217
+ | `--json` | | `false` | Print the result as one JSON document on stdout (logs go to stderr) |
216
218
 
217
219
  </details>
218
220
 
@@ -236,6 +238,19 @@ bugzero vibe
236
238
 
237
239
  ---
238
240
 
241
+ ## Scripting and CI
242
+
243
+ `hunt` and `rescue` accept `--json`. Stdout then contains exactly one JSON document and every human-readable log line goes to stderr, so the output is safe to pipe. Exit codes don't change: `0` when everything passes or is fixed, `1` otherwise.
244
+
245
+ ```bash
246
+ bugzero hunt --json | jq '.steps'
247
+ bugzero rescue --json --dry-run | jq -r '.outcome'
248
+ ```
249
+
250
+ `hunt` reports each step (`build`, `lint`, `test`) as `passed`, `failed`, or `skipped`; failed steps include the command's output and whether it timed out. `rescue` reports an `outcome` of `already-passing`, `fixed`, `failed`, or `dry-run`, along with the model, token usage, and the files and root cause of any fix. Both include the path to the generated report. If a run can't start at all (for example, because of an invalid option), stdout is `{ "success": false, "error": "..." }`.
251
+
252
+ ---
253
+
239
254
  ## Configuration
240
255
 
241
256
  BugZero reads a `.bugzerorc` JSON file in your target project directory to pick up model preferences:
package/dist/index.js CHANGED
@@ -393,7 +393,7 @@ var require_dist = __commonJS({
393
393
  while (true) {
394
394
  const envPath = import_path2.default.join(dir, ".env");
395
395
  if (import_fs2.default.existsSync(envPath)) {
396
- import_dotenv.default.config({ path: envPath });
396
+ import_dotenv.default.config({ path: envPath, quiet: true });
397
397
  return;
398
398
  }
399
399
  const parent = import_path2.default.dirname(dir);
@@ -402,7 +402,7 @@ var require_dist = __commonJS({
402
402
  }
403
403
  dir = parent;
404
404
  }
405
- import_dotenv.default.config();
405
+ import_dotenv.default.config({ quiet: true });
406
406
  }
407
407
  loadEnv();
408
408
  var env = {
@@ -1338,6 +1338,20 @@ var require_dist6 = __commonJS({
1338
1338
  reducer: (_, value) => value,
1339
1339
  default: () => null
1340
1340
  }),
1341
+ /**
1342
+ * Everything that has actually been written to disk so far, across ALL attempts.
1343
+ * `fixSuggestion` is replaced on every attempt, so it can't answer "what changed?" —
1344
+ * earlier attempts' edits stay on disk even after a later attempt proposes something new.
1345
+ * Patches accumulate in order; rootCause and explanation come from the latest applied attempt.
1346
+ */
1347
+ appliedFix: (0, import_langgraph.Annotation)({
1348
+ reducer: (previous, applied) => applied === null ? previous : {
1349
+ rootCause: applied.rootCause,
1350
+ explanation: applied.explanation,
1351
+ patches: [...previous?.patches ?? [], ...applied.patches]
1352
+ },
1353
+ default: () => null
1354
+ }),
1341
1355
  /** Number of fix attempts made so far */
1342
1356
  attempts: (0, import_langgraph.Annotation)({
1343
1357
  reducer: (_, value) => value,
@@ -1441,7 +1455,7 @@ Any other files from that same suggestion were rolled back to keep the change at
1441
1455
  console.log(`[BugZero] Note: exact match failed for ${applied.filePath} \u2014 patch applied via ${applied.matchStrategy} matching.`);
1442
1456
  }
1443
1457
  }
1444
- return {};
1458
+ return { appliedFix: state.fixSuggestion };
1445
1459
  }
1446
1460
  async function verifyNode(state) {
1447
1461
  if (state.logs.includes("[BugZero System Warning]")) {
@@ -1483,8 +1497,40 @@ Any other files from that same suggestion were rolled back to keep the change at
1483
1497
  }
1484
1498
  });
1485
1499
 
1486
- // ../../packages/core/dist/index.js
1500
+ // ../../packages/shared/dist/index.js
1487
1501
  var require_dist7 = __commonJS({
1502
+ "../../packages/shared/dist/index.js"(exports2, module2) {
1503
+ "use strict";
1504
+ var __defProp2 = Object.defineProperty;
1505
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
1506
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
1507
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
1508
+ var __export = (target, all) => {
1509
+ for (var name in all)
1510
+ __defProp2(target, name, { get: all[name], enumerable: true });
1511
+ };
1512
+ var __copyProps2 = (to, from, except, desc) => {
1513
+ if (from && typeof from === "object" || typeof from === "function") {
1514
+ for (let key of __getOwnPropNames2(from))
1515
+ if (!__hasOwnProp2.call(to, key) && key !== except)
1516
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
1517
+ }
1518
+ return to;
1519
+ };
1520
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
1521
+ var index_exports = {};
1522
+ __export(index_exports, {
1523
+ uniqueFilePaths: () => uniqueFilePaths3
1524
+ });
1525
+ module2.exports = __toCommonJS(index_exports);
1526
+ function uniqueFilePaths3(patches) {
1527
+ return [...new Set(patches.map((patch) => patch.filePath))];
1528
+ }
1529
+ }
1530
+ });
1531
+
1532
+ // ../../packages/core/dist/index.js
1533
+ var require_dist8 = __commonJS({
1488
1534
  "../../packages/core/dist/index.js"(exports2, module2) {
1489
1535
  "use strict";
1490
1536
  var __create2 = Object.create;
@@ -1517,6 +1563,7 @@ var require_dist7 = __commonJS({
1517
1563
  var index_exports = {};
1518
1564
  __export(index_exports, {
1519
1565
  DEFAULT_MAX_ATTEMPTS: () => DEFAULT_MAX_ATTEMPTS,
1566
+ REPORT_FILENAME: () => REPORT_FILENAME2,
1520
1567
  detectFramework: () => detectFramework2,
1521
1568
  detectPackageManager: () => import_analyzers2.detectPackageManager,
1522
1569
  orchestrate: () => orchestrate2,
@@ -1554,6 +1601,7 @@ var require_dist7 = __commonJS({
1554
1601
  }
1555
1602
  var import_analyzers = require_dist2();
1556
1603
  var import_agents = require_dist6();
1604
+ var import_shared3 = require_dist7();
1557
1605
  var import_fs3 = __toESM2(require("fs"));
1558
1606
  var import_path3 = __toESM2(require("path"));
1559
1607
  var import_url = require("url");
@@ -1625,6 +1673,7 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
1625
1673
  }
1626
1674
  }
1627
1675
  var import_ai_provider = require_dist3();
1676
+ var REPORT_FILENAME2 = "bugzero-report.md";
1628
1677
  function statusLabel(result) {
1629
1678
  if (result.skipped) return "\u23ED\uFE0F Skipped (no script defined)";
1630
1679
  return result.success ? "\u2705 Passed" : "\u274C Failed";
@@ -1692,7 +1741,7 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
1692
1741
  success: finalState.success,
1693
1742
  attempts: finalState.attempts,
1694
1743
  finalOutput: finalState.logs || pipelineResult.output,
1695
- appliedFix: finalState.fixSuggestion ?? void 0,
1744
+ appliedFix: finalState.appliedFix ?? void 0,
1696
1745
  error: finalState.success ? void 0 : `Max attempts (${maxAttempts}) reached without a successful build.`,
1697
1746
  modelUsed: finalState.modelUsed,
1698
1747
  promptTokens: finalState.promptTokens,
@@ -1826,7 +1875,7 @@ ${logs}
1826
1875
  }
1827
1876
  } else if (success && appliedFix) {
1828
1877
  console.log("[BugZero] Calling AI to write solution summary report...");
1829
- const patchedFiles = appliedFix.patches.map((p) => p.filePath).join(", ");
1878
+ const patchedFiles = (0, import_shared3.uniqueFilePaths)(appliedFix.patches).join(", ");
1830
1879
  const prompt = `You are an expert software engineer assistant. An automated AI agent successfully resolved a build/lint/test failure in a project located at "${cwd}" after ${attempts} attempts by applying a patch to: ${patchedFiles}.
1831
1880
  Here is the patch details:
1832
1881
  - Root Cause: ${appliedFix.rootCause}
@@ -1864,7 +1913,7 @@ Generate the Markdown report directly. Do not wrap it in markdown block fences (
1864
1913
  - **Token Usage:** ${promptTokens !== void 0 && completionTokens !== void 0 ? `Prompt: **${promptTokens}** | Completion: **${completionTokens}** | Total: **${promptTokens + completionTokens}**` : "*N/A*"}
1865
1914
 
1866
1915
  ## \u{1F6E0}\uFE0F Applied Solution
1867
- - **Target File(s):** ${appliedFix.patches.map((p) => `\`${p.filePath}\``).join(", ")}
1916
+ - **Target File(s):** ${(0, import_shared3.uniqueFilePaths)(appliedFix.patches).map((file) => `\`${file}\``).join(", ")}
1868
1917
  - **Root Cause:** ${appliedFix.rootCause}
1869
1918
  - **Explanation:** ${appliedFix.explanation}
1870
1919
 
@@ -1923,7 +1972,7 @@ ${rawOutput}
1923
1972
 
1924
1973
  ---
1925
1974
  *Report generated by **BugZero** on ${(/* @__PURE__ */ new Date()).toLocaleString()}*`;
1926
- const reportPath = import_path3.default.resolve(cwd, "bugzero-report.md");
1975
+ const reportPath = import_path3.default.resolve(cwd, REPORT_FILENAME2);
1927
1976
  try {
1928
1977
  import_fs3.default.writeFileSync(reportPath, content, "utf-8");
1929
1978
  const clickableUrl = (0, import_url.pathToFileURL)(reportPath).toString();
@@ -1950,9 +1999,67 @@ var import_config = __toESM(require_dist());
1950
1999
  var import_commander = require("commander");
1951
2000
  var import_fs = __toESM(require("fs"));
1952
2001
  var import_path = __toESM(require("path"));
1953
- var import_core = __toESM(require_dist7());
2002
+ var import_core = __toESM(require_dist8());
2003
+
2004
+ // src/json-output.ts
2005
+ var import_shared = __toESM(require_dist7());
2006
+ function stepStatus(step) {
2007
+ if (step.skipped) return "skipped";
2008
+ return step.success ? "passed" : "failed";
2009
+ }
2010
+ function stepJson(step) {
2011
+ const status = stepStatus(step);
2012
+ if (status !== "failed") return { status };
2013
+ return { status, timedOut: step.timedOut === true, output: step.output ?? "" };
2014
+ }
2015
+ function buildHuntJson(info, steps) {
2016
+ return {
2017
+ command: "hunt",
2018
+ success: steps.build.success && steps.lint.success && steps.test.success,
2019
+ path: info.path,
2020
+ framework: info.framework,
2021
+ packageManager: info.packageManager,
2022
+ steps: { build: stepJson(steps.build), lint: stepJson(steps.lint), test: stepJson(steps.test) },
2023
+ reportPath: info.reportPath
2024
+ };
2025
+ }
2026
+ function buildRescueJson(result, info) {
2027
+ let outcome;
2028
+ if (result.success && result.attempts === 0) outcome = "already-passing";
2029
+ else if (result.success) outcome = "fixed";
2030
+ else if (info.dryRun) outcome = "dry-run";
2031
+ else outcome = "failed";
2032
+ const tokens = result.promptTokens !== void 0 && result.completionTokens !== void 0 ? {
2033
+ prompt: result.promptTokens,
2034
+ completion: result.completionTokens,
2035
+ total: result.promptTokens + result.completionTokens
2036
+ } : null;
2037
+ return {
2038
+ command: "rescue",
2039
+ outcome,
2040
+ success: result.success,
2041
+ dryRun: info.dryRun,
2042
+ path: info.path,
2043
+ framework: info.framework,
2044
+ packageManager: info.packageManager,
2045
+ attempts: result.attempts,
2046
+ model: result.modelUsed || null,
2047
+ tokens,
2048
+ fix: result.appliedFix ? {
2049
+ rootCause: result.appliedFix.rootCause,
2050
+ explanation: result.appliedFix.explanation,
2051
+ files: (0, import_shared.uniqueFilePaths)(result.appliedFix.patches)
2052
+ } : null,
2053
+ error: result.error ?? null,
2054
+ reportPath: info.reportPath
2055
+ };
2056
+ }
2057
+ function buildErrorJson(message) {
2058
+ return { success: false, error: message };
2059
+ }
1954
2060
 
1955
2061
  // src/summary.ts
2062
+ var import_shared2 = __toESM(require_dist7());
1956
2063
  function tokenLines(result) {
1957
2064
  if (result.promptTokens === void 0 || result.completionTokens === void 0) return [];
1958
2065
  const total = result.promptTokens + result.completionTokens;
@@ -1973,8 +2080,9 @@ function buildRescueSummary(result, options) {
1973
2080
  ];
1974
2081
  if (result.appliedFix) {
1975
2082
  const { patches, explanation, rootCause } = result.appliedFix;
2083
+ const files = (0, import_shared2.uniqueFilePaths)(patches);
1976
2084
  lines2.push(
1977
- ` File${patches.length === 1 ? "" : "s"}: ${patches.map((p) => p.filePath).join(", ")}`,
2085
+ ` File${files.length === 1 ? "" : "s"}: ${files.join(", ")}`,
1978
2086
  ` Reason: ${explanation}`,
1979
2087
  ` Root cause: ${rootCause}`
1980
2088
  );
@@ -2011,9 +2119,23 @@ function parseTimeout(raw) {
2011
2119
  (0, import_core.resolveTimeoutMs)(seconds);
2012
2120
  return seconds;
2013
2121
  }
2122
+ var JSON_DESCRIPTION = "Print the result as one JSON document on stdout (human-readable logs go to stderr)";
2123
+ function routeLogsToStderr() {
2124
+ const toStderr = (...args) => console.error(...args);
2125
+ console.log = toStderr;
2126
+ console.info = toStderr;
2127
+ console.debug = toStderr;
2128
+ }
2129
+ function finish(exitCode, json) {
2130
+ if (json === void 0) process.exit(exitCode);
2131
+ process.stdout.write(`${JSON.stringify(json, null, 2)}
2132
+ `, () => process.exit(exitCode));
2133
+ }
2014
2134
  var program = new import_commander.Command();
2015
2135
  program.name("bugzero").description("AI-powered build issue fixer \u2014 detects and repairs build errors automatically").version(version);
2016
- program.command("hunt").description("Run build, lint, and tests \u2014 report issues without modifying files").option("-p, --path <dir>", "Path to the target project", ".").option("-t, --timeout <seconds>", TIMEOUT_DESCRIPTION).action(async (opts) => {
2136
+ program.command("hunt").description("Run build, lint, and tests \u2014 report issues without modifying files").option("-p, --path <dir>", "Path to the target project", ".").option("-t, --timeout <seconds>", TIMEOUT_DESCRIPTION).option("--json", JSON_DESCRIPTION).action(async (opts) => {
2137
+ const json = opts.json === true;
2138
+ if (json) routeLogsToStderr();
2017
2139
  try {
2018
2140
  const cwd = import_path.default.resolve(opts.path);
2019
2141
  const timeoutSeconds = parseTimeout(opts.timeout);
@@ -2037,14 +2159,22 @@ program.command("hunt").description("Run build, lint, and tests \u2014 report is
2037
2159
  console.log(`
2038
2160
  ${allPassed ? "\u2705 All checks passed" : "\u274C Issues found \u2014 run 'bugzero rescue' to repair"}
2039
2161
  `);
2040
- process.exit(allPassed ? 0 : 1);
2162
+ finish(
2163
+ allPassed ? 0 : 1,
2164
+ json ? buildHuntJson(
2165
+ { path: cwd, framework, packageManager, reportPath: import_path.default.resolve(cwd, import_core.REPORT_FILENAME) },
2166
+ { build, lint, test }
2167
+ ) : void 0
2168
+ );
2041
2169
  } catch (error) {
2042
2170
  console.error(`
2043
2171
  \u274C [BugZero] Execution failed: ${error.message || error}`);
2044
- process.exit(1);
2172
+ finish(1, json ? buildErrorJson(String(error.message || error)) : void 0);
2045
2173
  }
2046
2174
  });
2047
- program.command("rescue").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("-t, --timeout <seconds>", TIMEOUT_DESCRIPTION).option("--dry-run", "Analyse only \u2014 print what would be fixed without writing files", false).action(async (opts) => {
2175
+ program.command("rescue").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("-t, --timeout <seconds>", TIMEOUT_DESCRIPTION).option("--dry-run", "Analyse only \u2014 print what would be fixed without writing files", false).option("--json", JSON_DESCRIPTION).action(async (opts) => {
2176
+ const json = opts.json === true;
2177
+ if (json) routeLogsToStderr();
2048
2178
  try {
2049
2179
  const cwd = import_path.default.resolve(opts.path);
2050
2180
  const maxAttempts = (0, import_core.resolveMaxAttempts)(Number(opts.maxAttempts));
@@ -2066,11 +2196,20 @@ program.command("rescue").description("Detect build failures and automatically a
2066
2196
  const summary = buildRescueSummary(result, { dryRun });
2067
2197
  for (const line of summary.lines) console.log(line);
2068
2198
  console.log();
2069
- process.exit(summary.exitCode);
2199
+ finish(
2200
+ summary.exitCode,
2201
+ json ? buildRescueJson(result, {
2202
+ path: cwd,
2203
+ framework,
2204
+ packageManager,
2205
+ dryRun,
2206
+ reportPath: import_path.default.resolve(cwd, import_core.REPORT_FILENAME)
2207
+ }) : void 0
2208
+ );
2070
2209
  } catch (error) {
2071
2210
  console.error(`
2072
2211
  \u274C [BugZero] Execution failed: ${error.message || error}`);
2073
- process.exit(1);
2212
+ finish(1, json ? buildErrorJson(String(error.message || error)) : void 0);
2074
2213
  }
2075
2214
  });
2076
2215
  program.command("protect").description("[Deprecated] Use 'hunt' instead").action(async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.43",
3
+ "version": "0.0.45",
4
4
  "description": "Autonomous AI-powered CLI and GitHub Action that detects build, lint, and test failures, generates multi-file patches, applies them atomically with fuzzy matching, and re-verifies until your project is green.",
5
5
  "license": "MIT",
6
6
  "author": "Saksham Agarwal (https://github.com/Saksham1800t)",
@@ -54,7 +54,8 @@
54
54
  "devDependencies": {
55
55
  "@opspilot/agents": "workspace:*",
56
56
  "@opspilot/config": "workspace:*",
57
- "@opspilot/core": "workspace:*"
57
+ "@opspilot/core": "workspace:*",
58
+ "@opspilot/shared": "workspace:*"
58
59
  },
59
60
  "main": "./dist/index.js",
60
61
  "types": "./dist/index.d.ts",