bugzero 0.0.59 → 0.0.60
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.
- package/README.md +6 -1
- package/dist/index.js +115 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -228,6 +228,8 @@ The whole proposed fix is shown at once, because a fix that spans several files
|
|
|
228
228
|
|
|
229
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
230
|
|
|
231
|
+
**Failing tests are re-run on their own first.** While tests are what is failing, BugZero re-runs only the test files that failed after each attempt, which is much quicker than the whole pipeline on a big project. Once those files pass it runs the full build, lint and tests, so a fix is never called done on a partial check. This works for projects whose `test` script runs Jest or Vitest as one plain command (for example `vitest run` or `jest --ci`); for any other script, or when no failing test file can be found in the output, the full pipeline runs as before. Turn it off with `--no-focus-tests` or `"focusTests": false` in `.bugzerorc`.
|
|
232
|
+
|
|
231
233
|
<details>
|
|
232
234
|
<summary><strong>Options for <code>rescue</code></strong></summary>
|
|
233
235
|
|
|
@@ -237,6 +239,7 @@ The whole proposed fix is shown at once, because a fix that spans several files
|
|
|
237
239
|
| `--max-attempts <n>` | `-n` | `3` | Maximum AI fix iterations before giving up |
|
|
238
240
|
| `--timeout <seconds>` | `-t` | none | Stop any build, lint, or test command that runs longer than this many seconds |
|
|
239
241
|
| `--patience <n>` | | `2` | Stop early after this many attempts in a row make no progress. `0` turns it off |
|
|
242
|
+
| `--no-focus-tests` | | off | Always run the full build, lint and tests, instead of re-running only the failing test files between attempts |
|
|
240
243
|
| `--dry-run` | | `false` | Analyze only — no files will be written |
|
|
241
244
|
| `--approve` | | `false` | Show each proposed fix as a diff and ask before writing it. Needs an interactive terminal |
|
|
242
245
|
| `--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 |
|
|
@@ -315,7 +318,8 @@ BugZero reads a `.bugzerorc` JSON file in your target project directory to pick
|
|
|
315
318
|
"model": "deepseek/deepseek-chat",
|
|
316
319
|
"protect": ["config/prod.json", "migrations/**"],
|
|
317
320
|
"allow": [".env.example"],
|
|
318
|
-
"patience": 2
|
|
321
|
+
"patience": 2,
|
|
322
|
+
"focusTests": true
|
|
319
323
|
}
|
|
320
324
|
```
|
|
321
325
|
|
|
@@ -325,6 +329,7 @@ BugZero reads a `.bugzerorc` JSON file in your target project directory to pick
|
|
|
325
329
|
| `protect` | Extra files BugZero must never edit, added to the built-in list (see Protected files above). |
|
|
326
330
|
| `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
331
|
| `patience` | How many attempts in a row may make no progress before `rescue` stops early. Default 2, `0` turns it off. `--patience` overrides it. |
|
|
332
|
+
| `focusTests` | Set to `false` to always run the full pipeline, instead of re-running only the failing test files between attempts. Default `true`. `--no-focus-tests` overrides it. |
|
|
328
333
|
|
|
329
334
|
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.
|
|
330
335
|
|
package/dist/index.js
CHANGED
|
@@ -1295,15 +1295,21 @@ var require_dist4 = __commonJS({
|
|
|
1295
1295
|
var index_exports = {};
|
|
1296
1296
|
__export(index_exports, {
|
|
1297
1297
|
detectPackageManager: () => detectPackageManager3,
|
|
1298
|
+
detectTestRunner: () => detectTestRunner,
|
|
1299
|
+
findFailingTestFiles: () => findFailingTestFiles,
|
|
1298
1300
|
getRunScriptCommand: () => getRunScriptCommand,
|
|
1299
1301
|
parseErrors: () => parseErrors,
|
|
1302
|
+
planFocusedTests: () => planFocusedTests,
|
|
1303
|
+
readScriptText: () => readScriptText,
|
|
1300
1304
|
readScripts: () => readScripts,
|
|
1301
1305
|
runBuild: () => runBuild,
|
|
1302
1306
|
runCommand: () => runCommand,
|
|
1307
|
+
runFocusedTests: () => runFocusedTests,
|
|
1303
1308
|
runLint: () => runLint,
|
|
1304
1309
|
runScript: () => runScript,
|
|
1305
1310
|
runTests: () => runTests,
|
|
1306
|
-
runValidationPipeline: () => runValidationPipeline
|
|
1311
|
+
runValidationPipeline: () => runValidationPipeline,
|
|
1312
|
+
usableFocusedResult: () => usableFocusedResult
|
|
1307
1313
|
});
|
|
1308
1314
|
module2.exports = __toCommonJS(index_exports);
|
|
1309
1315
|
var import_fs2 = __toESM2(require("fs"));
|
|
@@ -1412,6 +1418,17 @@ var require_dist4 = __commonJS({
|
|
|
1412
1418
|
return [];
|
|
1413
1419
|
}
|
|
1414
1420
|
}
|
|
1421
|
+
function readScriptText(cwd, name) {
|
|
1422
|
+
try {
|
|
1423
|
+
const pkgPath = import_path3.default.join(cwd, "package.json");
|
|
1424
|
+
if (!import_fs2.default.existsSync(pkgPath)) return void 0;
|
|
1425
|
+
const pkg = JSON.parse(import_fs2.default.readFileSync(pkgPath, "utf-8"));
|
|
1426
|
+
const text = pkg?.scripts?.[name];
|
|
1427
|
+
return typeof text === "string" ? text : void 0;
|
|
1428
|
+
} catch {
|
|
1429
|
+
return void 0;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1415
1432
|
async function runScript(script, cwd, options) {
|
|
1416
1433
|
if (!readScripts(cwd).includes(script)) {
|
|
1417
1434
|
return { success: true, output: "", skipped: true };
|
|
@@ -1497,6 +1514,61 @@ var require_dist4 = __commonJS({
|
|
|
1497
1514
|
}
|
|
1498
1515
|
return { success: true, step: "none", output: "" };
|
|
1499
1516
|
}
|
|
1517
|
+
var import_fs32 = __toESM2(require("fs"));
|
|
1518
|
+
var import_shared4 = require_dist2();
|
|
1519
|
+
var MAX_FOCUSED_FILES = 10;
|
|
1520
|
+
var ANSI_RE = /\u001b\[[0-9;]*[A-Za-z]/g;
|
|
1521
|
+
var FAIL_LINE_RE = /^[ \t]*FAIL[ \t]+(?:\|[^|\n]*\|[ \t]+)?(\S+)/gm;
|
|
1522
|
+
var TEST_FILE_RE = /\.(test|spec)\.[cm]?[jt]sx?$|(^|\/)__tests__\//;
|
|
1523
|
+
var SAFE_PATH_RE = /^[A-Za-z0-9_@.+/-]+$/;
|
|
1524
|
+
function detectTestRunner(script) {
|
|
1525
|
+
if (typeof script !== "string" || script.trim() === "") return null;
|
|
1526
|
+
if (/[&|;<>`$()]/.test(script)) return null;
|
|
1527
|
+
const names = /* @__PURE__ */ new Set();
|
|
1528
|
+
for (const token of script.trim().split(/\s+/)) {
|
|
1529
|
+
const name = token.split(/[\\/]/).pop();
|
|
1530
|
+
if (name === "vitest" || name === "jest") names.add(name);
|
|
1531
|
+
}
|
|
1532
|
+
return names.size === 1 ? [...names][0] : null;
|
|
1533
|
+
}
|
|
1534
|
+
function findFailingTestFiles(cwd, output) {
|
|
1535
|
+
const text = output.replace(ANSI_RE, "").replace(/\r\n/g, "\n");
|
|
1536
|
+
const files = [];
|
|
1537
|
+
for (const match of text.matchAll(FAIL_LINE_RE)) {
|
|
1538
|
+
const candidate = match[1].replace(/\\/g, "/").replace(/^\.\//, "");
|
|
1539
|
+
if (files.includes(candidate)) continue;
|
|
1540
|
+
if (!SAFE_PATH_RE.test(candidate) || candidate.startsWith("-") || candidate.split("/").includes("..")) continue;
|
|
1541
|
+
if (!TEST_FILE_RE.test(candidate)) continue;
|
|
1542
|
+
const resolved = (0, import_shared4.resolveInsideProject)(cwd, candidate);
|
|
1543
|
+
if (!resolved.ok) continue;
|
|
1544
|
+
try {
|
|
1545
|
+
if (!import_fs32.default.statSync(resolved.absolutePath).isFile()) continue;
|
|
1546
|
+
} catch {
|
|
1547
|
+
continue;
|
|
1548
|
+
}
|
|
1549
|
+
files.push(candidate);
|
|
1550
|
+
}
|
|
1551
|
+
return files.length > MAX_FOCUSED_FILES ? [] : files;
|
|
1552
|
+
}
|
|
1553
|
+
function focusedCommand(manager, files) {
|
|
1554
|
+
const args = files.map((file) => `"${file}"`).join(" ");
|
|
1555
|
+
return manager === "npm" ? `npm run test -- ${args}` : `${manager} run test ${args}`;
|
|
1556
|
+
}
|
|
1557
|
+
function planFocusedTests(cwd, output) {
|
|
1558
|
+
const runner = detectTestRunner(readScriptText(cwd, "test"));
|
|
1559
|
+
if (runner === null) return null;
|
|
1560
|
+
const files = findFailingTestFiles(cwd, output);
|
|
1561
|
+
if (files.length === 0) return null;
|
|
1562
|
+
return { runner, files, command: focusedCommand(detectPackageManager3(cwd), files) };
|
|
1563
|
+
}
|
|
1564
|
+
function runFocusedTests(plan, cwd, options) {
|
|
1565
|
+
return runCommand(plan.command, cwd, options);
|
|
1566
|
+
}
|
|
1567
|
+
function usableFocusedResult(cwd, result) {
|
|
1568
|
+
if (result.success) return false;
|
|
1569
|
+
if (result.timedOut) return true;
|
|
1570
|
+
return findFailingTestFiles(cwd, result.output).length > 0;
|
|
1571
|
+
}
|
|
1500
1572
|
}
|
|
1501
1573
|
});
|
|
1502
1574
|
|
|
@@ -2029,6 +2101,11 @@ var require_dist7 = __commonJS({
|
|
|
2029
2101
|
reducer: (_, value) => value,
|
|
2030
2102
|
default: () => null
|
|
2031
2103
|
}),
|
|
2104
|
+
/** Whether, while tests are what is failing, verification may re-run only the failing test files first */
|
|
2105
|
+
focusTests: (0, import_langgraph.Annotation)({
|
|
2106
|
+
reducer: (_, value) => value,
|
|
2107
|
+
default: () => true
|
|
2108
|
+
}),
|
|
2032
2109
|
/** True when the run stopped before max attempts because attempts were not making progress */
|
|
2033
2110
|
stoppedForNoProgress: (0, import_langgraph.Annotation)({
|
|
2034
2111
|
reducer: (_, value) => value,
|
|
@@ -2183,6 +2260,25 @@ Any other files from that same suggestion were rolled back to keep the change at
|
|
|
2183
2260
|
patchFailed: false
|
|
2184
2261
|
};
|
|
2185
2262
|
}
|
|
2263
|
+
async function validate(state) {
|
|
2264
|
+
const options = { timeoutMs: state.timeoutMs };
|
|
2265
|
+
if (state.focusTests !== false && state.progress?.last.step === "test") {
|
|
2266
|
+
const plan = (0, import_analyzers2.planFocusedTests)(state.cwd, state.logs);
|
|
2267
|
+
if (plan) {
|
|
2268
|
+
console.log(
|
|
2269
|
+
`[BugZero] Re-running only the failing test file${plan.files.length === 1 ? "" : "s"}: ${plan.files.join(", ")} (the full pipeline runs once they pass)\u2026`
|
|
2270
|
+
);
|
|
2271
|
+
const focused = await (0, import_analyzers2.runFocusedTests)(plan, state.cwd, options);
|
|
2272
|
+
if ((0, import_analyzers2.usableFocusedResult)(state.cwd, focused)) {
|
|
2273
|
+
return { success: false, step: "test", output: focused.output };
|
|
2274
|
+
}
|
|
2275
|
+
console.log(
|
|
2276
|
+
focused.success ? "[BugZero] Those tests pass now \u2014 running the full pipeline to confirm\u2026" : "[BugZero] The focused run did not report any failing test file, so it is not trusted \u2014 running the full pipeline instead\u2026"
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
return (0, import_analyzers2.runValidationPipeline)(state.cwd, options);
|
|
2281
|
+
}
|
|
2186
2282
|
async function verifyNode(state) {
|
|
2187
2283
|
if (state.patchFailed) {
|
|
2188
2284
|
console.log("[BugZero] Skipping validation pipeline because the patch failed to apply.");
|
|
@@ -2192,7 +2288,7 @@ Any other files from that same suggestion were rolled back to keep the change at
|
|
|
2192
2288
|
};
|
|
2193
2289
|
}
|
|
2194
2290
|
console.log("[BugZero] Re-running validation pipeline to verify fix\u2026");
|
|
2195
|
-
const result = await (
|
|
2291
|
+
const result = await validate(state);
|
|
2196
2292
|
if (result.success) {
|
|
2197
2293
|
console.log("[BugZero] \u2705 Validation succeeded!");
|
|
2198
2294
|
} else {
|
|
@@ -2275,6 +2371,7 @@ var require_dist8 = __commonJS({
|
|
|
2275
2371
|
detectPackageManager: () => import_analyzers2.detectPackageManager,
|
|
2276
2372
|
orchestrate: () => orchestrate2,
|
|
2277
2373
|
orchestrateAndFix: () => orchestrateAndFix2,
|
|
2374
|
+
resolveFocusTests: () => resolveFocusTests,
|
|
2278
2375
|
resolveMaxAttempts: () => resolveMaxAttempts2,
|
|
2279
2376
|
resolvePatience: () => resolvePatience2,
|
|
2280
2377
|
resolveTimeoutMs: () => resolveTimeoutMs2
|
|
@@ -2440,6 +2537,14 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
|
|
|
2440
2537
|
}
|
|
2441
2538
|
return attempts;
|
|
2442
2539
|
}
|
|
2540
|
+
function resolveFocusTests(flag, configured) {
|
|
2541
|
+
if (flag !== void 0) return flag;
|
|
2542
|
+
if (configured === void 0) return true;
|
|
2543
|
+
if (typeof configured !== "boolean") {
|
|
2544
|
+
throw new Error(`focusTests in .bugzerorc must be true or false (received ${JSON.stringify(configured)}).`);
|
|
2545
|
+
}
|
|
2546
|
+
return configured;
|
|
2547
|
+
}
|
|
2443
2548
|
var DEFAULT_PATIENCE = 2;
|
|
2444
2549
|
function resolvePatience2(flag, configured) {
|
|
2445
2550
|
const source = flag !== void 0 ? "--patience" : "patience in .bugzerorc";
|
|
@@ -2494,7 +2599,9 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
|
|
|
2494
2599
|
assertNodeProject(cwd);
|
|
2495
2600
|
const maxAttempts = resolveMaxAttempts2(options.maxAttempts);
|
|
2496
2601
|
const timeoutMs = resolveTimeoutMs2(options.timeoutSeconds);
|
|
2497
|
-
const
|
|
2602
|
+
const config = (0, import_config2.getLocalConfig)(cwd);
|
|
2603
|
+
const patience = resolvePatience2(options.patience, config.patience);
|
|
2604
|
+
const focusTests = resolveFocusTests(options.focusTests, config.focusTests);
|
|
2498
2605
|
console.log(`[BugZero] Running validation pipeline in: ${cwd}`);
|
|
2499
2606
|
const pipelineResult = await (0, import_analyzers.runValidationPipeline)(cwd, { timeoutMs });
|
|
2500
2607
|
if (pipelineResult.success) {
|
|
@@ -2547,6 +2654,7 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
|
|
|
2547
2654
|
timeoutMs,
|
|
2548
2655
|
approve: options.approve,
|
|
2549
2656
|
patience,
|
|
2657
|
+
focusTests,
|
|
2550
2658
|
initialStep: pipelineResult.step
|
|
2551
2659
|
});
|
|
2552
2660
|
const result = {
|
|
@@ -3062,7 +3170,7 @@ ${allPassed ? "\u2705 All checks passed" : "\u274C Issues found \u2014 run 'bugz
|
|
|
3062
3170
|
finish(1, json ? buildErrorJson(String(error.message || error)) : void 0);
|
|
3063
3171
|
}
|
|
3064
3172
|
});
|
|
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) => {
|
|
3173
|
+
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("--no-focus-tests", "Always run the full build, lint and tests, instead of re-running only the failing test files between attempts").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) => {
|
|
3066
3174
|
const json = opts.json === true;
|
|
3067
3175
|
const printPrompt = opts.printPrompt === true;
|
|
3068
3176
|
if (json || printPrompt) routeLogsToStderr();
|
|
@@ -3073,6 +3181,7 @@ program.command("rescue").description("Detect build failures and automatically a
|
|
|
3073
3181
|
const timeoutSeconds = parseTimeout(opts.timeout);
|
|
3074
3182
|
const patience = opts.patience === void 0 ? void 0 : Number(opts.patience);
|
|
3075
3183
|
(0, import_core.resolvePatience)(patience, void 0);
|
|
3184
|
+
const focusTests = opts.focusTests === false ? false : void 0;
|
|
3076
3185
|
const dryRun = opts.dryRun;
|
|
3077
3186
|
let approve;
|
|
3078
3187
|
if (opts.approve === true && !dryRun && !printPrompt) {
|
|
@@ -3093,9 +3202,10 @@ program.command("rescue").description("Detect build failures and automatically a
|
|
|
3093
3202
|
console.log(` Max attempts: ${maxAttempts}`);
|
|
3094
3203
|
if (timeoutSeconds !== void 0) console.log(` Timeout: ${timeoutSeconds}s per command`);
|
|
3095
3204
|
if (patience !== void 0) console.log(` Patience: ${patience === 0 ? "off" : `${patience} attempt(s) without progress`}`);
|
|
3205
|
+
if (focusTests === false) console.log(` Focus tests: off (the full pipeline runs every time)`);
|
|
3096
3206
|
if (dryRun) console.log(` Mode: DRY RUN (no files will be modified)`);
|
|
3097
3207
|
console.log();
|
|
3098
|
-
const result = await (0, import_core.orchestrateAndFix)({ cwd, maxAttempts, dryRun, timeoutSeconds, printPrompt, approve, patience });
|
|
3208
|
+
const result = await (0, import_core.orchestrateAndFix)({ cwd, maxAttempts, dryRun, timeoutSeconds, printPrompt, approve, patience, focusTests });
|
|
3099
3209
|
if (result.promptPreview !== void 0) {
|
|
3100
3210
|
if (json) {
|
|
3101
3211
|
finish(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bugzero",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
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)",
|