bugzero 0.0.58 → 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 +11 -1
- package/dist/index.js +212 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -226,6 +226,10 @@ 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
|
+
|
|
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
|
+
|
|
229
233
|
<details>
|
|
230
234
|
<summary><strong>Options for <code>rescue</code></strong></summary>
|
|
231
235
|
|
|
@@ -234,6 +238,8 @@ The whole proposed fix is shown at once, because a fix that spans several files
|
|
|
234
238
|
| `--path <dir>` | `-p` | `.` | Path to the target project |
|
|
235
239
|
| `--max-attempts <n>` | `-n` | `3` | Maximum AI fix iterations before giving up |
|
|
236
240
|
| `--timeout <seconds>` | `-t` | none | Stop any build, lint, or test command that runs longer than this many seconds |
|
|
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 |
|
|
237
243
|
| `--dry-run` | | `false` | Analyze only — no files will be written |
|
|
238
244
|
| `--approve` | | `false` | Show each proposed fix as a diff and ask before writing it. Needs an interactive terminal |
|
|
239
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 |
|
|
@@ -311,7 +317,9 @@ BugZero reads a `.bugzerorc` JSON file in your target project directory to pick
|
|
|
311
317
|
{
|
|
312
318
|
"model": "deepseek/deepseek-chat",
|
|
313
319
|
"protect": ["config/prod.json", "migrations/**"],
|
|
314
|
-
"allow": [".env.example"]
|
|
320
|
+
"allow": [".env.example"],
|
|
321
|
+
"patience": 2,
|
|
322
|
+
"focusTests": true
|
|
315
323
|
}
|
|
316
324
|
```
|
|
317
325
|
|
|
@@ -320,6 +328,8 @@ BugZero reads a `.bugzerorc` JSON file in your target project directory to pick
|
|
|
320
328
|
| `model` | The OpenRouter model to use. Set it with `bugzero vibe`. |
|
|
321
329
|
| `protect` | Extra files BugZero must never edit, added to the built-in list (see Protected files above). |
|
|
322
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. |
|
|
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. |
|
|
323
333
|
|
|
324
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.
|
|
325
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 };
|
|
@@ -1425,7 +1442,8 @@ var require_dist4 = __commonJS({
|
|
|
1425
1442
|
var ESLINT_ERROR_RE = /^\s+(\d+):(\d+)\s+error\s+(.+)$/gm;
|
|
1426
1443
|
var JEST_FAIL_RE = /● (.+)/g;
|
|
1427
1444
|
var JEST_FILE_RE = /FAIL\s+([\w/\\.\-]+)/g;
|
|
1428
|
-
function parseErrors(
|
|
1445
|
+
function parseErrors(rawOutput) {
|
|
1446
|
+
const output = rawOutput.replace(/\r\n/g, "\n");
|
|
1429
1447
|
const errors = [];
|
|
1430
1448
|
const tsMatches = [...output.matchAll(TS_ERROR_RE)];
|
|
1431
1449
|
for (const m of tsMatches) {
|
|
@@ -1496,6 +1514,61 @@ var require_dist4 = __commonJS({
|
|
|
1496
1514
|
}
|
|
1497
1515
|
return { success: true, step: "none", output: "" };
|
|
1498
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
|
+
}
|
|
1499
1572
|
}
|
|
1500
1573
|
});
|
|
1501
1574
|
|
|
@@ -2018,6 +2091,26 @@ var require_dist7 = __commonJS({
|
|
|
2018
2091
|
reducer: (total, added) => total + added,
|
|
2019
2092
|
default: () => 0
|
|
2020
2093
|
}),
|
|
2094
|
+
/** How many attempts in a row may make no progress before the run stops early (0 = never stop early) */
|
|
2095
|
+
patience: (0, import_langgraph.Annotation)({
|
|
2096
|
+
reducer: (_, value) => value,
|
|
2097
|
+
default: () => 0
|
|
2098
|
+
}),
|
|
2099
|
+
/** The best result so far and how many attempts in a row did not beat it (null until there is one to compare to) */
|
|
2100
|
+
progress: (0, import_langgraph.Annotation)({
|
|
2101
|
+
reducer: (_, value) => value,
|
|
2102
|
+
default: () => null
|
|
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
|
+
}),
|
|
2109
|
+
/** True when the run stopped before max attempts because attempts were not making progress */
|
|
2110
|
+
stoppedForNoProgress: (0, import_langgraph.Annotation)({
|
|
2111
|
+
reducer: (_, value) => value,
|
|
2112
|
+
default: () => false
|
|
2113
|
+
}),
|
|
2021
2114
|
/** Per-command timeout in milliseconds for validation steps (undefined = no limit) */
|
|
2022
2115
|
timeoutMs: (0, import_langgraph.Annotation)({
|
|
2023
2116
|
reducer: (_, value) => value,
|
|
@@ -2028,7 +2121,42 @@ var require_dist7 = __commonJS({
|
|
|
2028
2121
|
var import_prompts = require_dist6();
|
|
2029
2122
|
var import_config2 = require_dist();
|
|
2030
2123
|
var import_patcher3 = require_dist3();
|
|
2124
|
+
var import_analyzers2 = require_dist4();
|
|
2031
2125
|
var import_analyzers = require_dist4();
|
|
2126
|
+
var STEP_ORDER = { build: 0, lint: 1, test: 2, none: 3 };
|
|
2127
|
+
var ANSI_RE = /\u001b\[[0-9;]*[A-Za-z]/g;
|
|
2128
|
+
function snapshotOf(step, output) {
|
|
2129
|
+
const errors = (0, import_analyzers.parseErrors)(output);
|
|
2130
|
+
const countable = errors.length > 0 && errors[0].type !== "unknown";
|
|
2131
|
+
return {
|
|
2132
|
+
step,
|
|
2133
|
+
errorCount: countable ? errors.length : null,
|
|
2134
|
+
fingerprint: output.replace(ANSI_RE, "").replace(/\r\n/g, "\n").trim()
|
|
2135
|
+
};
|
|
2136
|
+
}
|
|
2137
|
+
function isProgress(best, last, current) {
|
|
2138
|
+
const stepDifference = STEP_ORDER[current.step] - STEP_ORDER[best.step];
|
|
2139
|
+
if (stepDifference !== 0) return stepDifference > 0;
|
|
2140
|
+
if (best.errorCount !== null && current.errorCount !== null) {
|
|
2141
|
+
return current.errorCount < best.errorCount;
|
|
2142
|
+
}
|
|
2143
|
+
return current.fingerprint !== best.fingerprint && current.fingerprint !== last.fingerprint;
|
|
2144
|
+
}
|
|
2145
|
+
function startTracking(initial) {
|
|
2146
|
+
return { best: initial, last: initial, stagnantAttempts: 0 };
|
|
2147
|
+
}
|
|
2148
|
+
function recordAttempt(tracker, current) {
|
|
2149
|
+
if (tracker === null) return startTracking(current);
|
|
2150
|
+
if (isProgress(tracker.best, tracker.last, current)) {
|
|
2151
|
+
return { best: current, last: current, stagnantAttempts: 0 };
|
|
2152
|
+
}
|
|
2153
|
+
return { best: tracker.best, last: current, stagnantAttempts: tracker.stagnantAttempts + 1 };
|
|
2154
|
+
}
|
|
2155
|
+
function describeSnapshot(snapshot) {
|
|
2156
|
+
const where = snapshot.step === "none" ? "" : ` in ${snapshot.step}`;
|
|
2157
|
+
if (snapshot.errorCount === null) return `output it cannot count${where}`;
|
|
2158
|
+
return `${snapshot.errorCount} error${snapshot.errorCount === 1 ? "" : "s"}${where}`;
|
|
2159
|
+
}
|
|
2032
2160
|
var import_shared4 = require_dist2();
|
|
2033
2161
|
var provider = new import_ai_provider.OpenRouterProvider();
|
|
2034
2162
|
function protectionFor(cwd) {
|
|
@@ -2132,6 +2260,25 @@ Any other files from that same suggestion were rolled back to keep the change at
|
|
|
2132
2260
|
patchFailed: false
|
|
2133
2261
|
};
|
|
2134
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
|
+
}
|
|
2135
2282
|
async function verifyNode(state) {
|
|
2136
2283
|
if (state.patchFailed) {
|
|
2137
2284
|
console.log("[BugZero] Skipping validation pipeline because the patch failed to apply.");
|
|
@@ -2141,19 +2288,25 @@ Any other files from that same suggestion were rolled back to keep the change at
|
|
|
2141
2288
|
};
|
|
2142
2289
|
}
|
|
2143
2290
|
console.log("[BugZero] Re-running validation pipeline to verify fix\u2026");
|
|
2144
|
-
const result = await (
|
|
2291
|
+
const result = await validate(state);
|
|
2145
2292
|
if (result.success) {
|
|
2146
2293
|
console.log("[BugZero] \u2705 Validation succeeded!");
|
|
2147
2294
|
} else {
|
|
2148
2295
|
console.log(`[BugZero] \u274C Validation failed at step "${result.step}". New error output captured.`);
|
|
2149
2296
|
}
|
|
2150
|
-
return {
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2297
|
+
if (result.success) return { success: true, logs: "" };
|
|
2298
|
+
const progress = recordAttempt(state.progress, snapshotOf(result.step, result.output));
|
|
2299
|
+
const stuck = state.patience > 0 && progress.stagnantAttempts >= state.patience && state.attempts < state.maxAttempts;
|
|
2300
|
+
if (stuck) {
|
|
2301
|
+
console.log(
|
|
2302
|
+
`[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).`
|
|
2303
|
+
);
|
|
2304
|
+
}
|
|
2305
|
+
return { success: false, logs: result.output, progress, stoppedForNoProgress: stuck };
|
|
2154
2306
|
}
|
|
2155
2307
|
function shouldRetry(state) {
|
|
2156
2308
|
if (state.success) return import_langgraph2.END;
|
|
2309
|
+
if (state.stoppedForNoProgress) return import_langgraph2.END;
|
|
2157
2310
|
if (state.attempts >= state.maxAttempts) {
|
|
2158
2311
|
console.log(
|
|
2159
2312
|
`[BugZero] Max attempts (${state.maxAttempts}) reached \u2014 giving up.`
|
|
@@ -2164,8 +2317,14 @@ Any other files from that same suggestion were rolled back to keep the change at
|
|
|
2164
2317
|
}
|
|
2165
2318
|
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
2319
|
function runRepairWorkflow(input) {
|
|
2320
|
+
const { initialStep, ...rest } = input;
|
|
2167
2321
|
return workflow.invoke(
|
|
2168
|
-
{
|
|
2322
|
+
{
|
|
2323
|
+
...rest,
|
|
2324
|
+
attempts: 0,
|
|
2325
|
+
success: false,
|
|
2326
|
+
progress: initialStep ? startTracking(snapshotOf(initialStep, input.logs)) : null
|
|
2327
|
+
},
|
|
2169
2328
|
{ recursionLimit: input.maxAttempts * 3 + 5 }
|
|
2170
2329
|
);
|
|
2171
2330
|
}
|
|
@@ -2206,12 +2365,15 @@ var require_dist8 = __commonJS({
|
|
|
2206
2365
|
var index_exports = {};
|
|
2207
2366
|
__export(index_exports, {
|
|
2208
2367
|
DEFAULT_MAX_ATTEMPTS: () => DEFAULT_MAX_ATTEMPTS,
|
|
2368
|
+
DEFAULT_PATIENCE: () => DEFAULT_PATIENCE,
|
|
2209
2369
|
REPORT_FILENAME: () => REPORT_FILENAME2,
|
|
2210
2370
|
detectFramework: () => detectFramework2,
|
|
2211
2371
|
detectPackageManager: () => import_analyzers2.detectPackageManager,
|
|
2212
2372
|
orchestrate: () => orchestrate2,
|
|
2213
2373
|
orchestrateAndFix: () => orchestrateAndFix2,
|
|
2374
|
+
resolveFocusTests: () => resolveFocusTests,
|
|
2214
2375
|
resolveMaxAttempts: () => resolveMaxAttempts2,
|
|
2376
|
+
resolvePatience: () => resolvePatience2,
|
|
2215
2377
|
resolveTimeoutMs: () => resolveTimeoutMs2
|
|
2216
2378
|
});
|
|
2217
2379
|
module2.exports = __toCommonJS(index_exports);
|
|
@@ -2359,6 +2521,7 @@ ${params.rawOutput}
|
|
|
2359
2521
|
Re-run without \`--dry-run\` to let BugZero attempt a fix.
|
|
2360
2522
|
`;
|
|
2361
2523
|
}
|
|
2524
|
+
var import_config2 = require_dist();
|
|
2362
2525
|
var DEFAULT_MAX_ATTEMPTS = 3;
|
|
2363
2526
|
function resolveTimeoutMs2(seconds) {
|
|
2364
2527
|
if (seconds === void 0) return void 0;
|
|
@@ -2374,6 +2537,24 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
|
|
|
2374
2537
|
}
|
|
2375
2538
|
return attempts;
|
|
2376
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
|
+
}
|
|
2548
|
+
var DEFAULT_PATIENCE = 2;
|
|
2549
|
+
function resolvePatience2(flag, configured) {
|
|
2550
|
+
const source = flag !== void 0 ? "--patience" : "patience in .bugzerorc";
|
|
2551
|
+
const value = flag !== void 0 ? flag : configured;
|
|
2552
|
+
if (value === void 0) return DEFAULT_PATIENCE;
|
|
2553
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
2554
|
+
throw new Error(`${source} must be a whole number of 0 or more, where 0 turns it off (received ${JSON.stringify(value) ?? String(value)}).`);
|
|
2555
|
+
}
|
|
2556
|
+
return value;
|
|
2557
|
+
}
|
|
2377
2558
|
var import_fs22 = __toESM2(require("fs"));
|
|
2378
2559
|
var import_path22 = __toESM2(require("path"));
|
|
2379
2560
|
function assertNodeProject(cwd) {
|
|
@@ -2383,12 +2564,12 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
|
|
|
2383
2564
|
}
|
|
2384
2565
|
var import_ai_provider = require_dist5();
|
|
2385
2566
|
var REPORT_FILENAME2 = "bugzero-report.md";
|
|
2386
|
-
function failureMessage(maxAttempts, declined, appliedAnything) {
|
|
2567
|
+
function failureMessage(maxAttempts, declined, appliedAnything, stoppedAfter) {
|
|
2387
2568
|
const plural = declined === 1 ? "fix" : "fixes";
|
|
2388
2569
|
if (declined > 0 && !appliedAnything) {
|
|
2389
2570
|
return `You declined ${declined} proposed ${plural}, so nothing was changed.`;
|
|
2390
2571
|
}
|
|
2391
|
-
const base = `Max attempts (${maxAttempts}) reached without a successful build.`;
|
|
2572
|
+
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
2573
|
return declined > 0 ? `${base} You declined ${declined} proposed ${plural}.` : base;
|
|
2393
2574
|
}
|
|
2394
2575
|
function statusLabel(result) {
|
|
@@ -2418,6 +2599,9 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
|
|
|
2418
2599
|
assertNodeProject(cwd);
|
|
2419
2600
|
const maxAttempts = resolveMaxAttempts2(options.maxAttempts);
|
|
2420
2601
|
const timeoutMs = resolveTimeoutMs2(options.timeoutSeconds);
|
|
2602
|
+
const config = (0, import_config2.getLocalConfig)(cwd);
|
|
2603
|
+
const patience = resolvePatience2(options.patience, config.patience);
|
|
2604
|
+
const focusTests = resolveFocusTests(options.focusTests, config.focusTests);
|
|
2421
2605
|
console.log(`[BugZero] Running validation pipeline in: ${cwd}`);
|
|
2422
2606
|
const pipelineResult = await (0, import_analyzers.runValidationPipeline)(cwd, { timeoutMs });
|
|
2423
2607
|
if (pipelineResult.success) {
|
|
@@ -2468,14 +2652,23 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
|
|
|
2468
2652
|
logs: pipelineResult.output,
|
|
2469
2653
|
maxAttempts,
|
|
2470
2654
|
timeoutMs,
|
|
2471
|
-
approve: options.approve
|
|
2655
|
+
approve: options.approve,
|
|
2656
|
+
patience,
|
|
2657
|
+
focusTests,
|
|
2658
|
+
initialStep: pipelineResult.step
|
|
2472
2659
|
});
|
|
2473
2660
|
const result = {
|
|
2474
2661
|
success: finalState.success,
|
|
2475
2662
|
attempts: finalState.attempts,
|
|
2476
2663
|
finalOutput: finalState.logs || pipelineResult.output,
|
|
2477
2664
|
appliedFix: finalState.appliedFix ?? void 0,
|
|
2478
|
-
error: finalState.success ? void 0 : failureMessage(
|
|
2665
|
+
error: finalState.success ? void 0 : failureMessage(
|
|
2666
|
+
maxAttempts,
|
|
2667
|
+
finalState.declinedFixes ?? 0,
|
|
2668
|
+
Boolean(finalState.appliedFix),
|
|
2669
|
+
finalState.stoppedForNoProgress ? patience : void 0
|
|
2670
|
+
),
|
|
2671
|
+
stoppedEarly: finalState.stoppedForNoProgress ? "no-progress" : void 0,
|
|
2479
2672
|
declinedFixes: finalState.declinedFixes ? finalState.declinedFixes : void 0,
|
|
2480
2673
|
modelUsed: finalState.modelUsed,
|
|
2481
2674
|
promptTokens: finalState.promptTokens,
|
|
@@ -2977,7 +3170,7 @@ ${allPassed ? "\u2705 All checks passed" : "\u274C Issues found \u2014 run 'bugz
|
|
|
2977
3170
|
finish(1, json ? buildErrorJson(String(error.message || error)) : void 0);
|
|
2978
3171
|
}
|
|
2979
3172
|
});
|
|
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) => {
|
|
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) => {
|
|
2981
3174
|
const json = opts.json === true;
|
|
2982
3175
|
const printPrompt = opts.printPrompt === true;
|
|
2983
3176
|
if (json || printPrompt) routeLogsToStderr();
|
|
@@ -2986,6 +3179,9 @@ program.command("rescue").description("Detect build failures and automatically a
|
|
|
2986
3179
|
(0, import_config.loadProjectEnv)(cwd);
|
|
2987
3180
|
const maxAttempts = (0, import_core.resolveMaxAttempts)(Number(opts.maxAttempts));
|
|
2988
3181
|
const timeoutSeconds = parseTimeout(opts.timeout);
|
|
3182
|
+
const patience = opts.patience === void 0 ? void 0 : Number(opts.patience);
|
|
3183
|
+
(0, import_core.resolvePatience)(patience, void 0);
|
|
3184
|
+
const focusTests = opts.focusTests === false ? false : void 0;
|
|
2989
3185
|
const dryRun = opts.dryRun;
|
|
2990
3186
|
let approve;
|
|
2991
3187
|
if (opts.approve === true && !dryRun && !printPrompt) {
|
|
@@ -3005,9 +3201,11 @@ program.command("rescue").description("Detect build failures and automatically a
|
|
|
3005
3201
|
console.log(` Package manager: ${packageManager}`);
|
|
3006
3202
|
console.log(` Max attempts: ${maxAttempts}`);
|
|
3007
3203
|
if (timeoutSeconds !== void 0) console.log(` Timeout: ${timeoutSeconds}s per command`);
|
|
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)`);
|
|
3008
3206
|
if (dryRun) console.log(` Mode: DRY RUN (no files will be modified)`);
|
|
3009
3207
|
console.log();
|
|
3010
|
-
const result = await (0, import_core.orchestrateAndFix)({ cwd, maxAttempts, dryRun, timeoutSeconds, printPrompt, approve });
|
|
3208
|
+
const result = await (0, import_core.orchestrateAndFix)({ cwd, maxAttempts, dryRun, timeoutSeconds, printPrompt, approve, patience, focusTests });
|
|
3011
3209
|
if (result.promptPreview !== void 0) {
|
|
3012
3210
|
if (json) {
|
|
3013
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)",
|