bugzero 0.0.45 → 0.0.47

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 +1 -0
  2. package/dist/index.js +126 -49
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -100,6 +100,7 @@ bugzero rescue
100
100
  ### Safety
101
101
 
102
102
  - **Backups on every patch.** Each file BugZero modifies gets a `.opspilot.bak` copy of its original content first.
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.
103
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.
104
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.
105
106
  - **Command timeouts.** `--timeout <seconds>` (available on both `hunt` and `rescue`) stops any build, lint, or test command that runs longer than that. It kills the whole process tree rather than just the shell, so a hung test run cannot linger in the background, and the step is reported as failed along with whatever output it produced. Without it, a command that hangs will hang BugZero too, so it is worth setting in CI.
package/dist/index.js CHANGED
@@ -817,8 +817,94 @@ var require_dist3 = __commonJS({
817
817
  }
818
818
  });
819
819
 
820
- // ../../packages/prompts/dist/index.js
820
+ // ../../packages/shared/dist/index.js
821
821
  var require_dist4 = __commonJS({
822
+ "../../packages/shared/dist/index.js"(exports2, module2) {
823
+ "use strict";
824
+ var __create2 = Object.create;
825
+ var __defProp2 = Object.defineProperty;
826
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
827
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
828
+ var __getProtoOf2 = Object.getPrototypeOf;
829
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
830
+ var __export = (target, all) => {
831
+ for (var name in all)
832
+ __defProp2(target, name, { get: all[name], enumerable: true });
833
+ };
834
+ var __copyProps2 = (to, from, except, desc) => {
835
+ if (from && typeof from === "object" || typeof from === "function") {
836
+ for (let key of __getOwnPropNames2(from))
837
+ if (!__hasOwnProp2.call(to, key) && key !== except)
838
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
839
+ }
840
+ return to;
841
+ };
842
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
843
+ // If the importer is in node compatibility mode or this is not an ESM
844
+ // file that has been converted to a CommonJS file using a Babel-
845
+ // compatible transform (i.e. "__esModule" has not been set), then set
846
+ // "default" to the CommonJS "module.exports" for node compatibility.
847
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
848
+ mod
849
+ ));
850
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
851
+ var index_exports = {};
852
+ __export(index_exports, {
853
+ isInsideDirectory: () => isInsideDirectory,
854
+ isLexicallyInside: () => isLexicallyInside,
855
+ resolveInsideProject: () => resolveInsideProject,
856
+ uniqueFilePaths: () => uniqueFilePaths3
857
+ });
858
+ module2.exports = __toCommonJS(index_exports);
859
+ function uniqueFilePaths3(patches) {
860
+ return [...new Set(patches.map((patch) => patch.filePath))];
861
+ }
862
+ var import_fs2 = __toESM2(require("fs"));
863
+ var import_path2 = __toESM2(require("path"));
864
+ function isLexicallyInside(root, target) {
865
+ const relative = import_path2.default.relative(import_path2.default.resolve(root), import_path2.default.resolve(target));
866
+ const escapes = relative === ".." || relative.startsWith(`..${import_path2.default.sep}`) || import_path2.default.isAbsolute(relative);
867
+ return !escapes;
868
+ }
869
+ function isInsideDirectory(root, target) {
870
+ const absoluteTarget = import_path2.default.resolve(target);
871
+ if (!isLexicallyInside(root, absoluteTarget)) return false;
872
+ try {
873
+ let probe = absoluteTarget;
874
+ while (!import_fs2.default.existsSync(probe)) {
875
+ const parent = import_path2.default.dirname(probe);
876
+ if (parent === probe) return false;
877
+ probe = parent;
878
+ }
879
+ return isLexicallyInside(import_fs2.default.realpathSync.native(root), import_fs2.default.realpathSync.native(probe));
880
+ } catch {
881
+ return false;
882
+ }
883
+ }
884
+ function resolveInsideProject(cwd, filePath) {
885
+ if (typeof filePath !== "string" || filePath.trim() === "") {
886
+ return { ok: false, error: "The file path is empty. Use a path relative to the project root." };
887
+ }
888
+ if (filePath.includes("\0")) {
889
+ return { ok: false, error: "The file path contains a null character." };
890
+ }
891
+ const absolutePath = import_path2.default.resolve(cwd, filePath);
892
+ if (import_path2.default.resolve(cwd) === absolutePath) {
893
+ return { ok: false, error: `"${filePath}" is the project directory itself, not a file.` };
894
+ }
895
+ if (!isInsideDirectory(cwd, absolutePath)) {
896
+ return {
897
+ ok: false,
898
+ error: `"${filePath}" is outside the project directory. Use a path relative to the project root.`
899
+ };
900
+ }
901
+ return { ok: true, absolutePath };
902
+ }
903
+ }
904
+ });
905
+
906
+ // ../../packages/prompts/dist/index.js
907
+ var require_dist5 = __commonJS({
822
908
  "../../packages/prompts/dist/index.js"(exports2, module2) {
823
909
  "use strict";
824
910
  var __create2 = Object.create;
@@ -854,6 +940,7 @@ var require_dist4 = __commonJS({
854
940
  truncateLogs: () => truncateLogs
855
941
  });
856
942
  module2.exports = __toCommonJS(index_exports);
943
+ var import_shared3 = require_dist4();
857
944
  var import_fs2 = __toESM2(require("fs"));
858
945
  var import_path2 = __toESM2(require("path"));
859
946
  var MAX_LOG_CHARS = 2e4;
@@ -919,7 +1006,7 @@ ${tail}`;
919
1006
  for (const candidate of candidates) {
920
1007
  const absPathCandidate = import_path2.default.isAbsolute(candidate) ? candidate : import_path2.default.resolve(cwd, candidate);
921
1008
  const resolved = resolveExistingPathPrefix(absPathCandidate);
922
- if (resolved) {
1009
+ if (resolved && (0, import_shared3.isInsideDirectory)(cwd, resolved)) {
923
1010
  resolvedPaths.add(import_path2.default.resolve(resolved));
924
1011
  }
925
1012
  }
@@ -1065,7 +1152,7 @@ Critical rules:
1065
1152
  });
1066
1153
 
1067
1154
  // ../../packages/patcher/dist/index.js
1068
- var require_dist5 = __commonJS({
1155
+ var require_dist6 = __commonJS({
1069
1156
  "../../packages/patcher/dist/index.js"(exports2, module2) {
1070
1157
  "use strict";
1071
1158
  var __create2 = Object.create;
@@ -1229,8 +1316,8 @@ var require_dist5 = __commonJS({
1229
1316
  return { success: false, error: err.message };
1230
1317
  }
1231
1318
  }
1319
+ var import_shared3 = require_dist4();
1232
1320
  var import_fs22 = __toESM2(require("fs"));
1233
- var import_path22 = __toESM2(require("path"));
1234
1321
  function rollback(originalContent, backupPaths) {
1235
1322
  for (const [absolutePath, content] of originalContent) {
1236
1323
  try {
@@ -1249,11 +1336,23 @@ var require_dist5 = __commonJS({
1249
1336
  if (patches.length === 0) {
1250
1337
  return { success: false, error: "No patches to apply.", applied: [] };
1251
1338
  }
1339
+ const absolutePaths = [];
1340
+ for (const patch of patches) {
1341
+ const resolved = (0, import_shared3.resolveInsideProject)(cwd, patch.filePath);
1342
+ if (!resolved.ok) {
1343
+ return {
1344
+ success: false,
1345
+ error: `Failed to patch "${patch.filePath}": ${resolved.error}`,
1346
+ applied: []
1347
+ };
1348
+ }
1349
+ absolutePaths.push(resolved.absolutePath);
1350
+ }
1252
1351
  const originalContent = /* @__PURE__ */ new Map();
1253
1352
  const backupPaths = /* @__PURE__ */ new Set();
1254
1353
  const applied = [];
1255
- for (const patch of patches) {
1256
- const absolutePath = import_path22.default.resolve(cwd, patch.filePath);
1354
+ for (const [index, patch] of patches.entries()) {
1355
+ const absolutePath = absolutePaths[index];
1257
1356
  if (!originalContent.has(absolutePath)) {
1258
1357
  try {
1259
1358
  originalContent.set(absolutePath, import_fs22.default.readFileSync(absolutePath, "utf-8"));
@@ -1289,7 +1388,7 @@ var require_dist5 = __commonJS({
1289
1388
  });
1290
1389
 
1291
1390
  // ../../packages/agents/dist/index.js
1292
- var require_dist6 = __commonJS({
1391
+ var require_dist7 = __commonJS({
1293
1392
  "../../packages/agents/dist/index.js"(exports2, module2) {
1294
1393
  "use strict";
1295
1394
  var __defProp2 = Object.defineProperty;
@@ -1352,6 +1451,15 @@ var require_dist6 = __commonJS({
1352
1451
  },
1353
1452
  default: () => null
1354
1453
  }),
1454
+ /**
1455
+ * True when the current attempt's patch could not be applied, so there is nothing new to verify.
1456
+ * Every attempt sets it afresh. (This used to be inferred from a warning left in `logs`, which stayed
1457
+ * there after the failure and made every later attempt skip verification too.)
1458
+ */
1459
+ patchFailed: (0, import_langgraph.Annotation)({
1460
+ reducer: (_, value) => value,
1461
+ default: () => false
1462
+ }),
1355
1463
  /** Number of fix attempts made so far */
1356
1464
  attempts: (0, import_langgraph.Annotation)({
1357
1465
  reducer: (_, value) => value,
@@ -1389,8 +1497,8 @@ var require_dist6 = __commonJS({
1389
1497
  })
1390
1498
  });
1391
1499
  var import_ai_provider = require_dist3();
1392
- var import_prompts = require_dist4();
1393
- var import_patcher = require_dist5();
1500
+ var import_prompts = require_dist5();
1501
+ var import_patcher = require_dist6();
1394
1502
  var import_analyzers = require_dist2();
1395
1503
  var provider = new import_ai_provider.OpenRouterProvider();
1396
1504
  async function analyzeNode(state) {
@@ -1430,7 +1538,7 @@ var require_dist6 = __commonJS({
1430
1538
  async function applyFixNode(state) {
1431
1539
  if (!state.fixSuggestion) {
1432
1540
  console.warn("[BugZero] No fix suggestion available \u2014 skipping patch.");
1433
- return {};
1541
+ return { patchFailed: false };
1434
1542
  }
1435
1543
  const { patches, explanation } = state.fixSuggestion;
1436
1544
  const fileList = patches.map((p) => p.filePath).join(", ");
@@ -1446,7 +1554,8 @@ var require_dist6 = __commonJS({
1446
1554
 
1447
1555
  Any other files from that same suggestion were rolled back to keep the change atomic. Please check if the file path(s) are correct relative to the project root and make sure you target the correct file(s) that contain the build error.`;
1448
1556
  return {
1449
- logs: updatedLogs
1557
+ logs: updatedLogs,
1558
+ patchFailed: true
1450
1559
  };
1451
1560
  }
1452
1561
  for (const applied of result.applied) {
@@ -1455,10 +1564,10 @@ Any other files from that same suggestion were rolled back to keep the change at
1455
1564
  console.log(`[BugZero] Note: exact match failed for ${applied.filePath} \u2014 patch applied via ${applied.matchStrategy} matching.`);
1456
1565
  }
1457
1566
  }
1458
- return { appliedFix: state.fixSuggestion };
1567
+ return { appliedFix: state.fixSuggestion, patchFailed: false };
1459
1568
  }
1460
1569
  async function verifyNode(state) {
1461
- if (state.logs.includes("[BugZero System Warning]")) {
1570
+ if (state.patchFailed) {
1462
1571
  console.log("[BugZero] Skipping validation pipeline because the patch failed to apply.");
1463
1572
  return {
1464
1573
  success: false,
@@ -1497,38 +1606,6 @@ Any other files from that same suggestion were rolled back to keep the change at
1497
1606
  }
1498
1607
  });
1499
1608
 
1500
- // ../../packages/shared/dist/index.js
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
1609
  // ../../packages/core/dist/index.js
1533
1610
  var require_dist8 = __commonJS({
1534
1611
  "../../packages/core/dist/index.js"(exports2, module2) {
@@ -1600,8 +1677,8 @@ var require_dist8 = __commonJS({
1600
1677
  return "unknown";
1601
1678
  }
1602
1679
  var import_analyzers = require_dist2();
1603
- var import_agents = require_dist6();
1604
- var import_shared3 = require_dist7();
1680
+ var import_agents = require_dist7();
1681
+ var import_shared3 = require_dist4();
1605
1682
  var import_fs3 = __toESM2(require("fs"));
1606
1683
  var import_path3 = __toESM2(require("path"));
1607
1684
  var import_url = require("url");
@@ -2002,7 +2079,7 @@ var import_path = __toESM(require("path"));
2002
2079
  var import_core = __toESM(require_dist8());
2003
2080
 
2004
2081
  // src/json-output.ts
2005
- var import_shared = __toESM(require_dist7());
2082
+ var import_shared = __toESM(require_dist4());
2006
2083
  function stepStatus(step) {
2007
2084
  if (step.skipped) return "skipped";
2008
2085
  return step.success ? "passed" : "failed";
@@ -2059,7 +2136,7 @@ function buildErrorJson(message) {
2059
2136
  }
2060
2137
 
2061
2138
  // src/summary.ts
2062
- var import_shared2 = __toESM(require_dist7());
2139
+ var import_shared2 = __toESM(require_dist4());
2063
2140
  function tokenLines(result) {
2064
2141
  if (result.promptTokens === void 0 || result.completionTokens === void 0) return [];
2065
2142
  const total = result.promptTokens + result.completionTokens;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
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)",