bugzero 0.0.58 → 0.0.59

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 +6 -1
  2. package/dist/index.js +101 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -226,6 +226,8 @@ Apply this change? [y] yes [n] no [m] no, and leave a note for the AI (Enter
226
226
 
227
227
  The whole proposed fix is shown at once, because a fix that spans several files is applied together or not at all. Answer `y` to apply it. Answer `n` (or just press Enter) to decline: nothing is changed, and the AI is told you declined and asked for a different fix, which uses up one attempt. Answer `m` to decline and type a short note that is sent to the AI, such as "leave the config file alone". `--approve` needs an interactive terminal; without one (in CI, or with piped input) it stops immediately, before running anything. It has no effect with `--dry-run` or `--print-prompt`, which never write.
228
228
 
229
+ **Stuck runs stop early.** After each attempt BugZero compares what is still failing with the best result so far. It counts as progress when there are fewer errors, or when a later step is now the one failing (the build passes and lint fails, or lint passes and the tests fail), even if that step shows more errors. If 2 attempts in a row make no progress, it stops and says why, instead of paying for the remaining attempts. Output BugZero cannot count only stops a run when it is exactly the same as before. Attempts whose patch could not be applied, or that you declined, do not count. Change the limit with `--patience <n>` or `patience` in `.bugzerorc`; `0` turns it off.
230
+
229
231
  <details>
230
232
  <summary><strong>Options for <code>rescue</code></strong></summary>
231
233
 
@@ -234,6 +236,7 @@ The whole proposed fix is shown at once, because a fix that spans several files
234
236
  | `--path <dir>` | `-p` | `.` | Path to the target project |
235
237
  | `--max-attempts <n>` | `-n` | `3` | Maximum AI fix iterations before giving up |
236
238
  | `--timeout <seconds>` | `-t` | none | Stop any build, lint, or test command that runs longer than this many seconds |
239
+ | `--patience <n>` | | `2` | Stop early after this many attempts in a row make no progress. `0` turns it off |
237
240
  | `--dry-run` | | `false` | Analyze only — no files will be written |
238
241
  | `--approve` | | `false` | Show each proposed fix as a diff and ask before writing it. Needs an interactive terminal |
239
242
  | `--print-prompt` | | `false` | Print the exact prompt that would be sent to the AI model, then stop. Nothing is sent and no files are written |
@@ -311,7 +314,8 @@ BugZero reads a `.bugzerorc` JSON file in your target project directory to pick
311
314
  {
312
315
  "model": "deepseek/deepseek-chat",
313
316
  "protect": ["config/prod.json", "migrations/**"],
314
- "allow": [".env.example"]
317
+ "allow": [".env.example"],
318
+ "patience": 2
315
319
  }
316
320
  ```
317
321
 
@@ -320,6 +324,7 @@ BugZero reads a `.bugzerorc` JSON file in your target project directory to pick
320
324
  | `model` | The OpenRouter model to use. Set it with `bugzero vibe`. |
321
325
  | `protect` | Extra files BugZero must never edit, added to the built-in list (see Protected files above). |
322
326
  | `allow` | Files from the built-in list that BugZero may edit and read after all, such as `.env.example`. A `protect` pattern still wins. |
327
+ | `patience` | How many attempts in a row may make no progress before `rescue` stops early. Default 2, `0` turns it off. `--patience` overrides it. |
323
328
 
324
329
  Patterns are relative to the project and ignore case. `*` matches within a folder, `**` matches across folders, `?` matches one character, and a trailing `/` means a folder and everything in it. A pattern with no `/` matches that name at any depth, so `.env.*` also covers `apps/web/.env.local`; a pattern with a `/` is anchored to the project root. All keys are optional.
325
330
 
package/dist/index.js CHANGED
@@ -1425,7 +1425,8 @@ var require_dist4 = __commonJS({
1425
1425
  var ESLINT_ERROR_RE = /^\s+(\d+):(\d+)\s+error\s+(.+)$/gm;
1426
1426
  var JEST_FAIL_RE = /● (.+)/g;
1427
1427
  var JEST_FILE_RE = /FAIL\s+([\w/\\.\-]+)/g;
1428
- function parseErrors(output) {
1428
+ function parseErrors(rawOutput) {
1429
+ const output = rawOutput.replace(/\r\n/g, "\n");
1429
1430
  const errors = [];
1430
1431
  const tsMatches = [...output.matchAll(TS_ERROR_RE)];
1431
1432
  for (const m of tsMatches) {
@@ -2018,6 +2019,21 @@ var require_dist7 = __commonJS({
2018
2019
  reducer: (total, added) => total + added,
2019
2020
  default: () => 0
2020
2021
  }),
2022
+ /** How many attempts in a row may make no progress before the run stops early (0 = never stop early) */
2023
+ patience: (0, import_langgraph.Annotation)({
2024
+ reducer: (_, value) => value,
2025
+ default: () => 0
2026
+ }),
2027
+ /** The best result so far and how many attempts in a row did not beat it (null until there is one to compare to) */
2028
+ progress: (0, import_langgraph.Annotation)({
2029
+ reducer: (_, value) => value,
2030
+ default: () => null
2031
+ }),
2032
+ /** True when the run stopped before max attempts because attempts were not making progress */
2033
+ stoppedForNoProgress: (0, import_langgraph.Annotation)({
2034
+ reducer: (_, value) => value,
2035
+ default: () => false
2036
+ }),
2021
2037
  /** Per-command timeout in milliseconds for validation steps (undefined = no limit) */
2022
2038
  timeoutMs: (0, import_langgraph.Annotation)({
2023
2039
  reducer: (_, value) => value,
@@ -2028,7 +2044,42 @@ var require_dist7 = __commonJS({
2028
2044
  var import_prompts = require_dist6();
2029
2045
  var import_config2 = require_dist();
2030
2046
  var import_patcher3 = require_dist3();
2047
+ var import_analyzers2 = require_dist4();
2031
2048
  var import_analyzers = require_dist4();
2049
+ var STEP_ORDER = { build: 0, lint: 1, test: 2, none: 3 };
2050
+ var ANSI_RE = /\u001b\[[0-9;]*[A-Za-z]/g;
2051
+ function snapshotOf(step, output) {
2052
+ const errors = (0, import_analyzers.parseErrors)(output);
2053
+ const countable = errors.length > 0 && errors[0].type !== "unknown";
2054
+ return {
2055
+ step,
2056
+ errorCount: countable ? errors.length : null,
2057
+ fingerprint: output.replace(ANSI_RE, "").replace(/\r\n/g, "\n").trim()
2058
+ };
2059
+ }
2060
+ function isProgress(best, last, current) {
2061
+ const stepDifference = STEP_ORDER[current.step] - STEP_ORDER[best.step];
2062
+ if (stepDifference !== 0) return stepDifference > 0;
2063
+ if (best.errorCount !== null && current.errorCount !== null) {
2064
+ return current.errorCount < best.errorCount;
2065
+ }
2066
+ return current.fingerprint !== best.fingerprint && current.fingerprint !== last.fingerprint;
2067
+ }
2068
+ function startTracking(initial) {
2069
+ return { best: initial, last: initial, stagnantAttempts: 0 };
2070
+ }
2071
+ function recordAttempt(tracker, current) {
2072
+ if (tracker === null) return startTracking(current);
2073
+ if (isProgress(tracker.best, tracker.last, current)) {
2074
+ return { best: current, last: current, stagnantAttempts: 0 };
2075
+ }
2076
+ return { best: tracker.best, last: current, stagnantAttempts: tracker.stagnantAttempts + 1 };
2077
+ }
2078
+ function describeSnapshot(snapshot) {
2079
+ const where = snapshot.step === "none" ? "" : ` in ${snapshot.step}`;
2080
+ if (snapshot.errorCount === null) return `output it cannot count${where}`;
2081
+ return `${snapshot.errorCount} error${snapshot.errorCount === 1 ? "" : "s"}${where}`;
2082
+ }
2032
2083
  var import_shared4 = require_dist2();
2033
2084
  var provider = new import_ai_provider.OpenRouterProvider();
2034
2085
  function protectionFor(cwd) {
@@ -2141,19 +2192,25 @@ Any other files from that same suggestion were rolled back to keep the change at
2141
2192
  };
2142
2193
  }
2143
2194
  console.log("[BugZero] Re-running validation pipeline to verify fix\u2026");
2144
- const result = await (0, import_analyzers.runValidationPipeline)(state.cwd, { timeoutMs: state.timeoutMs });
2195
+ const result = await (0, import_analyzers2.runValidationPipeline)(state.cwd, { timeoutMs: state.timeoutMs });
2145
2196
  if (result.success) {
2146
2197
  console.log("[BugZero] \u2705 Validation succeeded!");
2147
2198
  } else {
2148
2199
  console.log(`[BugZero] \u274C Validation failed at step "${result.step}". New error output captured.`);
2149
2200
  }
2150
- return {
2151
- success: result.success,
2152
- logs: result.success ? "" : result.output
2153
- };
2201
+ if (result.success) return { success: true, logs: "" };
2202
+ const progress = recordAttempt(state.progress, snapshotOf(result.step, result.output));
2203
+ const stuck = state.patience > 0 && progress.stagnantAttempts >= state.patience && state.attempts < state.maxAttempts;
2204
+ if (stuck) {
2205
+ console.log(
2206
+ `[BugZero] No progress in ${progress.stagnantAttempts} attempt(s) in a row (best so far: ${describeSnapshot(progress.best)}; now: ${describeSnapshot(progress.last)}) \u2014 stopping early instead of using the remaining attempt(s).`
2207
+ );
2208
+ }
2209
+ return { success: false, logs: result.output, progress, stoppedForNoProgress: stuck };
2154
2210
  }
2155
2211
  function shouldRetry(state) {
2156
2212
  if (state.success) return import_langgraph2.END;
2213
+ if (state.stoppedForNoProgress) return import_langgraph2.END;
2157
2214
  if (state.attempts >= state.maxAttempts) {
2158
2215
  console.log(
2159
2216
  `[BugZero] Max attempts (${state.maxAttempts}) reached \u2014 giving up.`
@@ -2164,8 +2221,14 @@ Any other files from that same suggestion were rolled back to keep the change at
2164
2221
  }
2165
2222
  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();
2166
2223
  function runRepairWorkflow(input) {
2224
+ const { initialStep, ...rest } = input;
2167
2225
  return workflow.invoke(
2168
- { ...input, attempts: 0, success: false },
2226
+ {
2227
+ ...rest,
2228
+ attempts: 0,
2229
+ success: false,
2230
+ progress: initialStep ? startTracking(snapshotOf(initialStep, input.logs)) : null
2231
+ },
2169
2232
  { recursionLimit: input.maxAttempts * 3 + 5 }
2170
2233
  );
2171
2234
  }
@@ -2206,12 +2269,14 @@ var require_dist8 = __commonJS({
2206
2269
  var index_exports = {};
2207
2270
  __export(index_exports, {
2208
2271
  DEFAULT_MAX_ATTEMPTS: () => DEFAULT_MAX_ATTEMPTS,
2272
+ DEFAULT_PATIENCE: () => DEFAULT_PATIENCE,
2209
2273
  REPORT_FILENAME: () => REPORT_FILENAME2,
2210
2274
  detectFramework: () => detectFramework2,
2211
2275
  detectPackageManager: () => import_analyzers2.detectPackageManager,
2212
2276
  orchestrate: () => orchestrate2,
2213
2277
  orchestrateAndFix: () => orchestrateAndFix2,
2214
2278
  resolveMaxAttempts: () => resolveMaxAttempts2,
2279
+ resolvePatience: () => resolvePatience2,
2215
2280
  resolveTimeoutMs: () => resolveTimeoutMs2
2216
2281
  });
2217
2282
  module2.exports = __toCommonJS(index_exports);
@@ -2359,6 +2424,7 @@ ${params.rawOutput}
2359
2424
  Re-run without \`--dry-run\` to let BugZero attempt a fix.
2360
2425
  `;
2361
2426
  }
2427
+ var import_config2 = require_dist();
2362
2428
  var DEFAULT_MAX_ATTEMPTS = 3;
2363
2429
  function resolveTimeoutMs2(seconds) {
2364
2430
  if (seconds === void 0) return void 0;
@@ -2374,6 +2440,16 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
2374
2440
  }
2375
2441
  return attempts;
2376
2442
  }
2443
+ var DEFAULT_PATIENCE = 2;
2444
+ function resolvePatience2(flag, configured) {
2445
+ const source = flag !== void 0 ? "--patience" : "patience in .bugzerorc";
2446
+ const value = flag !== void 0 ? flag : configured;
2447
+ if (value === void 0) return DEFAULT_PATIENCE;
2448
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
2449
+ throw new Error(`${source} must be a whole number of 0 or more, where 0 turns it off (received ${JSON.stringify(value) ?? String(value)}).`);
2450
+ }
2451
+ return value;
2452
+ }
2377
2453
  var import_fs22 = __toESM2(require("fs"));
2378
2454
  var import_path22 = __toESM2(require("path"));
2379
2455
  function assertNodeProject(cwd) {
@@ -2383,12 +2459,12 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
2383
2459
  }
2384
2460
  var import_ai_provider = require_dist5();
2385
2461
  var REPORT_FILENAME2 = "bugzero-report.md";
2386
- function failureMessage(maxAttempts, declined, appliedAnything) {
2462
+ function failureMessage(maxAttempts, declined, appliedAnything, stoppedAfter) {
2387
2463
  const plural = declined === 1 ? "fix" : "fixes";
2388
2464
  if (declined > 0 && !appliedAnything) {
2389
2465
  return `You declined ${declined} proposed ${plural}, so nothing was changed.`;
2390
2466
  }
2391
- const base = `Max attempts (${maxAttempts}) reached without a successful build.`;
2467
+ const base = stoppedAfter !== void 0 ? `Stopped early: ${stoppedAfter} attempt${stoppedAfter === 1 ? "" : "s"} in a row made no progress (the errors did not get fewer and no later step was reached), so the remaining attempts were not used. Try a different model with 'bugzero vibe', or use --patience 0 to keep going regardless.` : `Max attempts (${maxAttempts}) reached without a successful build.`;
2392
2468
  return declined > 0 ? `${base} You declined ${declined} proposed ${plural}.` : base;
2393
2469
  }
2394
2470
  function statusLabel(result) {
@@ -2418,6 +2494,7 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
2418
2494
  assertNodeProject(cwd);
2419
2495
  const maxAttempts = resolveMaxAttempts2(options.maxAttempts);
2420
2496
  const timeoutMs = resolveTimeoutMs2(options.timeoutSeconds);
2497
+ const patience = resolvePatience2(options.patience, (0, import_config2.getLocalConfig)(cwd).patience);
2421
2498
  console.log(`[BugZero] Running validation pipeline in: ${cwd}`);
2422
2499
  const pipelineResult = await (0, import_analyzers.runValidationPipeline)(cwd, { timeoutMs });
2423
2500
  if (pipelineResult.success) {
@@ -2468,14 +2545,22 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
2468
2545
  logs: pipelineResult.output,
2469
2546
  maxAttempts,
2470
2547
  timeoutMs,
2471
- approve: options.approve
2548
+ approve: options.approve,
2549
+ patience,
2550
+ initialStep: pipelineResult.step
2472
2551
  });
2473
2552
  const result = {
2474
2553
  success: finalState.success,
2475
2554
  attempts: finalState.attempts,
2476
2555
  finalOutput: finalState.logs || pipelineResult.output,
2477
2556
  appliedFix: finalState.appliedFix ?? void 0,
2478
- error: finalState.success ? void 0 : failureMessage(maxAttempts, finalState.declinedFixes ?? 0, Boolean(finalState.appliedFix)),
2557
+ error: finalState.success ? void 0 : failureMessage(
2558
+ maxAttempts,
2559
+ finalState.declinedFixes ?? 0,
2560
+ Boolean(finalState.appliedFix),
2561
+ finalState.stoppedForNoProgress ? patience : void 0
2562
+ ),
2563
+ stoppedEarly: finalState.stoppedForNoProgress ? "no-progress" : void 0,
2479
2564
  declinedFixes: finalState.declinedFixes ? finalState.declinedFixes : void 0,
2480
2565
  modelUsed: finalState.modelUsed,
2481
2566
  promptTokens: finalState.promptTokens,
@@ -2977,7 +3062,7 @@ ${allPassed ? "\u2705 All checks passed" : "\u274C Issues found \u2014 run 'bugz
2977
3062
  finish(1, json ? buildErrorJson(String(error.message || error)) : void 0);
2978
3063
  }
2979
3064
  });
2980
- 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("--approve", "Show each proposed fix as a diff and ask before writing it (needs an interactive terminal)").option("--print-prompt", "Print the exact prompt that would be sent to the AI model, then stop (nothing is sent, no files are written)").option("--json", JSON_DESCRIPTION).action(async (opts) => {
3065
+ 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("--patience <n>", "Stop early after this many attempts in a row make no progress (default 2, 0 turns it off)").option("--dry-run", "Analyse only \u2014 print what would be fixed without writing files", false).option("--approve", "Show each proposed fix as a diff and ask before writing it (needs an interactive terminal)").option("--print-prompt", "Print the exact prompt that would be sent to the AI model, then stop (nothing is sent, no files are written)").option("--json", JSON_DESCRIPTION).action(async (opts) => {
2981
3066
  const json = opts.json === true;
2982
3067
  const printPrompt = opts.printPrompt === true;
2983
3068
  if (json || printPrompt) routeLogsToStderr();
@@ -2986,6 +3071,8 @@ program.command("rescue").description("Detect build failures and automatically a
2986
3071
  (0, import_config.loadProjectEnv)(cwd);
2987
3072
  const maxAttempts = (0, import_core.resolveMaxAttempts)(Number(opts.maxAttempts));
2988
3073
  const timeoutSeconds = parseTimeout(opts.timeout);
3074
+ const patience = opts.patience === void 0 ? void 0 : Number(opts.patience);
3075
+ (0, import_core.resolvePatience)(patience, void 0);
2989
3076
  const dryRun = opts.dryRun;
2990
3077
  let approve;
2991
3078
  if (opts.approve === true && !dryRun && !printPrompt) {
@@ -3005,9 +3092,10 @@ program.command("rescue").description("Detect build failures and automatically a
3005
3092
  console.log(` Package manager: ${packageManager}`);
3006
3093
  console.log(` Max attempts: ${maxAttempts}`);
3007
3094
  if (timeoutSeconds !== void 0) console.log(` Timeout: ${timeoutSeconds}s per command`);
3095
+ if (patience !== void 0) console.log(` Patience: ${patience === 0 ? "off" : `${patience} attempt(s) without progress`}`);
3008
3096
  if (dryRun) console.log(` Mode: DRY RUN (no files will be modified)`);
3009
3097
  console.log();
3010
- const result = await (0, import_core.orchestrateAndFix)({ cwd, maxAttempts, dryRun, timeoutSeconds, printPrompt, approve });
3098
+ const result = await (0, import_core.orchestrateAndFix)({ cwd, maxAttempts, dryRun, timeoutSeconds, printPrompt, approve, patience });
3011
3099
  if (result.promptPreview !== void 0) {
3012
3100
  if (json) {
3013
3101
  finish(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
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)",