bugzero 0.0.47 → 0.0.48

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 CHANGED
@@ -99,7 +99,7 @@ bugzero rescue
99
99
 
100
100
  ### Safety
101
101
 
102
- - **Backups on every patch.** Each file BugZero modifies gets a `.opspilot.bak` copy of its original content first.
102
+ - **Backups on every patch.** Each file BugZero modifies gets a `.opspilot.bak` copy of its original content first. The backup is written once per run, so it always restores what you had, even if the fix took several attempts. A leftover backup from an earlier run is replaced.
103
103
  - **Project boundary.** BugZero only reads and edits files inside the project you point it at. A patch whose path leaves the project (with `../`, an absolute path elsewhere, or a symlink or junction that points out) is refused before any file changes, and the model is told why. Files outside the project are never added to what is sent to the model, even if an error log mentions them.
104
104
  - **Dry-run mode.** `bugzero rescue --dry-run` runs validation and error analysis, but makes no fix attempts and never modifies your source files (it still writes a report that diagnoses the failures it found). It exits with code 1 if it found failures and 0 if everything already passes, so you can use it as a check in scripts.
105
105
  - **Prompt size limits.** Very long error output and very large source files are shortened before being sent to the model (for logs, the start and end are kept), so a big failure can't exceed the model's context window or waste tokens.
package/dist/index.js CHANGED
@@ -1291,7 +1291,7 @@ var require_dist6 = __commonJS({
1291
1291
  }
1292
1292
  return findWhitespaceNormalizedMatch(content, search) ?? findSimilarityMatch(content, search);
1293
1293
  }
1294
- function applyPatch(absoluteFilePath, search, replace) {
1294
+ function applyPatch(absoluteFilePath, search, replace, options = {}) {
1295
1295
  try {
1296
1296
  if (!import_fs2.default.existsSync(absoluteFilePath)) {
1297
1297
  return {
@@ -1308,7 +1308,9 @@ var require_dist6 = __commonJS({
1308
1308
  };
1309
1309
  }
1310
1310
  const backupPath = absoluteFilePath + ".opspilot.bak";
1311
- import_fs2.default.writeFileSync(backupPath, original, "utf-8");
1311
+ if (options.backup !== false) {
1312
+ import_fs2.default.writeFileSync(backupPath, original, "utf-8");
1313
+ }
1312
1314
  const fixed = original.slice(0, match.start) + replace + original.slice(match.end);
1313
1315
  import_fs2.default.writeFileSync(absoluteFilePath, fixed, "utf-8");
1314
1316
  return { success: true, backupPath, matchStrategy: match.strategy };
@@ -1332,7 +1334,7 @@ var require_dist6 = __commonJS({
1332
1334
  }
1333
1335
  }
1334
1336
  }
1335
- function applyPatches(cwd, patches) {
1337
+ function applyPatches(cwd, patches, options = {}) {
1336
1338
  if (patches.length === 0) {
1337
1339
  return { success: false, error: "No patches to apply.", applied: [] };
1338
1340
  }
@@ -1351,6 +1353,7 @@ var require_dist6 = __commonJS({
1351
1353
  const originalContent = /* @__PURE__ */ new Map();
1352
1354
  const backupPaths = /* @__PURE__ */ new Set();
1353
1355
  const applied = [];
1356
+ const backedUp = new Set(options.alreadyBackedUp ?? []);
1354
1357
  for (const [index, patch] of patches.entries()) {
1355
1358
  const absolutePath = absolutePaths[index];
1356
1359
  if (!originalContent.has(absolutePath)) {
@@ -1365,8 +1368,12 @@ var require_dist6 = __commonJS({
1365
1368
  };
1366
1369
  }
1367
1370
  }
1368
- const result = applyPatch(absolutePath, patch.search, patch.replace);
1369
- if (result.backupPath) backupPaths.add(result.backupPath);
1371
+ const needsBackup = !backedUp.has(absolutePath);
1372
+ const result = applyPatch(absolutePath, patch.search, patch.replace, { backup: needsBackup });
1373
+ if (result.success && needsBackup) {
1374
+ backedUp.add(absolutePath);
1375
+ backupPaths.add(result.backupPath);
1376
+ }
1370
1377
  if (!result.success) {
1371
1378
  rollback(originalContent, backupPaths);
1372
1379
  return {
@@ -1451,6 +1458,15 @@ var require_dist7 = __commonJS({
1451
1458
  },
1452
1459
  default: () => null
1453
1460
  }),
1461
+ /**
1462
+ * Absolute paths of files whose `.opspilot.bak` already holds their original content, across ALL attempts.
1463
+ * Later attempts leave those backups alone; otherwise a second edit would overwrite the backup with
1464
+ * the first attempt's result and the user's original would be lost.
1465
+ */
1466
+ backedUpFiles: (0, import_langgraph.Annotation)({
1467
+ reducer: (previous, added) => [.../* @__PURE__ */ new Set([...previous, ...added])],
1468
+ default: () => []
1469
+ }),
1454
1470
  /**
1455
1471
  * True when the current attempt's patch could not be applied, so there is nothing new to verify.
1456
1472
  * Every attempt sets it afresh. (This used to be inferred from a warning left in `logs`, which stayed
@@ -1544,7 +1560,7 @@ var require_dist7 = __commonJS({
1544
1560
  const fileList = patches.map((p) => p.filePath).join(", ");
1545
1561
  console.log(`[BugZero] Patching ${patches.length} file${patches.length === 1 ? "" : "s"}: ${fileList}`);
1546
1562
  console.log(`[BugZero] Reason: ${explanation}`);
1547
- const result = (0, import_patcher.applyPatches)(state.cwd, patches);
1563
+ const result = (0, import_patcher.applyPatches)(state.cwd, patches, { alreadyBackedUp: state.backedUpFiles });
1548
1564
  if (!result.success) {
1549
1565
  console.error(`[BugZero] Patch failed: ${result.error}`);
1550
1566
  const updatedLogs = `${state.logs}
@@ -1564,7 +1580,11 @@ Any other files from that same suggestion were rolled back to keep the change at
1564
1580
  console.log(`[BugZero] Note: exact match failed for ${applied.filePath} \u2014 patch applied via ${applied.matchStrategy} matching.`);
1565
1581
  }
1566
1582
  }
1567
- return { appliedFix: state.fixSuggestion, patchFailed: false };
1583
+ return {
1584
+ appliedFix: state.fixSuggestion,
1585
+ backedUpFiles: result.applied.map((applied) => applied.absolutePath),
1586
+ patchFailed: false
1587
+ };
1568
1588
  }
1569
1589
  async function verifyNode(state) {
1570
1590
  if (state.patchFailed) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
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)",