bugzero 0.0.46 → 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 +2 -1
- package/dist/index.js +139 -52
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,7 +99,8 @@ 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
|
+
- **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/
|
|
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
|
|
1155
|
+
var require_dist6 = __commonJS({
|
|
1069
1156
|
"../../packages/patcher/dist/index.js"(exports2, module2) {
|
|
1070
1157
|
"use strict";
|
|
1071
1158
|
var __create2 = Object.create;
|
|
@@ -1204,7 +1291,7 @@ var require_dist5 = __commonJS({
|
|
|
1204
1291
|
}
|
|
1205
1292
|
return findWhitespaceNormalizedMatch(content, search) ?? findSimilarityMatch(content, search);
|
|
1206
1293
|
}
|
|
1207
|
-
function applyPatch(absoluteFilePath, search, replace) {
|
|
1294
|
+
function applyPatch(absoluteFilePath, search, replace, options = {}) {
|
|
1208
1295
|
try {
|
|
1209
1296
|
if (!import_fs2.default.existsSync(absoluteFilePath)) {
|
|
1210
1297
|
return {
|
|
@@ -1221,7 +1308,9 @@ var require_dist5 = __commonJS({
|
|
|
1221
1308
|
};
|
|
1222
1309
|
}
|
|
1223
1310
|
const backupPath = absoluteFilePath + ".opspilot.bak";
|
|
1224
|
-
|
|
1311
|
+
if (options.backup !== false) {
|
|
1312
|
+
import_fs2.default.writeFileSync(backupPath, original, "utf-8");
|
|
1313
|
+
}
|
|
1225
1314
|
const fixed = original.slice(0, match.start) + replace + original.slice(match.end);
|
|
1226
1315
|
import_fs2.default.writeFileSync(absoluteFilePath, fixed, "utf-8");
|
|
1227
1316
|
return { success: true, backupPath, matchStrategy: match.strategy };
|
|
@@ -1229,8 +1318,8 @@ var require_dist5 = __commonJS({
|
|
|
1229
1318
|
return { success: false, error: err.message };
|
|
1230
1319
|
}
|
|
1231
1320
|
}
|
|
1321
|
+
var import_shared3 = require_dist4();
|
|
1232
1322
|
var import_fs22 = __toESM2(require("fs"));
|
|
1233
|
-
var import_path22 = __toESM2(require("path"));
|
|
1234
1323
|
function rollback(originalContent, backupPaths) {
|
|
1235
1324
|
for (const [absolutePath, content] of originalContent) {
|
|
1236
1325
|
try {
|
|
@@ -1245,15 +1334,28 @@ var require_dist5 = __commonJS({
|
|
|
1245
1334
|
}
|
|
1246
1335
|
}
|
|
1247
1336
|
}
|
|
1248
|
-
function applyPatches(cwd, patches) {
|
|
1337
|
+
function applyPatches(cwd, patches, options = {}) {
|
|
1249
1338
|
if (patches.length === 0) {
|
|
1250
1339
|
return { success: false, error: "No patches to apply.", applied: [] };
|
|
1251
1340
|
}
|
|
1341
|
+
const absolutePaths = [];
|
|
1342
|
+
for (const patch of patches) {
|
|
1343
|
+
const resolved = (0, import_shared3.resolveInsideProject)(cwd, patch.filePath);
|
|
1344
|
+
if (!resolved.ok) {
|
|
1345
|
+
return {
|
|
1346
|
+
success: false,
|
|
1347
|
+
error: `Failed to patch "${patch.filePath}": ${resolved.error}`,
|
|
1348
|
+
applied: []
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
absolutePaths.push(resolved.absolutePath);
|
|
1352
|
+
}
|
|
1252
1353
|
const originalContent = /* @__PURE__ */ new Map();
|
|
1253
1354
|
const backupPaths = /* @__PURE__ */ new Set();
|
|
1254
1355
|
const applied = [];
|
|
1255
|
-
|
|
1256
|
-
|
|
1356
|
+
const backedUp = new Set(options.alreadyBackedUp ?? []);
|
|
1357
|
+
for (const [index, patch] of patches.entries()) {
|
|
1358
|
+
const absolutePath = absolutePaths[index];
|
|
1257
1359
|
if (!originalContent.has(absolutePath)) {
|
|
1258
1360
|
try {
|
|
1259
1361
|
originalContent.set(absolutePath, import_fs22.default.readFileSync(absolutePath, "utf-8"));
|
|
@@ -1266,8 +1368,12 @@ var require_dist5 = __commonJS({
|
|
|
1266
1368
|
};
|
|
1267
1369
|
}
|
|
1268
1370
|
}
|
|
1269
|
-
const
|
|
1270
|
-
|
|
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
|
+
}
|
|
1271
1377
|
if (!result.success) {
|
|
1272
1378
|
rollback(originalContent, backupPaths);
|
|
1273
1379
|
return {
|
|
@@ -1289,7 +1395,7 @@ var require_dist5 = __commonJS({
|
|
|
1289
1395
|
});
|
|
1290
1396
|
|
|
1291
1397
|
// ../../packages/agents/dist/index.js
|
|
1292
|
-
var
|
|
1398
|
+
var require_dist7 = __commonJS({
|
|
1293
1399
|
"../../packages/agents/dist/index.js"(exports2, module2) {
|
|
1294
1400
|
"use strict";
|
|
1295
1401
|
var __defProp2 = Object.defineProperty;
|
|
@@ -1352,6 +1458,15 @@ var require_dist6 = __commonJS({
|
|
|
1352
1458
|
},
|
|
1353
1459
|
default: () => null
|
|
1354
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
|
+
}),
|
|
1355
1470
|
/**
|
|
1356
1471
|
* True when the current attempt's patch could not be applied, so there is nothing new to verify.
|
|
1357
1472
|
* Every attempt sets it afresh. (This used to be inferred from a warning left in `logs`, which stayed
|
|
@@ -1398,8 +1513,8 @@ var require_dist6 = __commonJS({
|
|
|
1398
1513
|
})
|
|
1399
1514
|
});
|
|
1400
1515
|
var import_ai_provider = require_dist3();
|
|
1401
|
-
var import_prompts =
|
|
1402
|
-
var import_patcher =
|
|
1516
|
+
var import_prompts = require_dist5();
|
|
1517
|
+
var import_patcher = require_dist6();
|
|
1403
1518
|
var import_analyzers = require_dist2();
|
|
1404
1519
|
var provider = new import_ai_provider.OpenRouterProvider();
|
|
1405
1520
|
async function analyzeNode(state) {
|
|
@@ -1445,7 +1560,7 @@ var require_dist6 = __commonJS({
|
|
|
1445
1560
|
const fileList = patches.map((p) => p.filePath).join(", ");
|
|
1446
1561
|
console.log(`[BugZero] Patching ${patches.length} file${patches.length === 1 ? "" : "s"}: ${fileList}`);
|
|
1447
1562
|
console.log(`[BugZero] Reason: ${explanation}`);
|
|
1448
|
-
const result = (0, import_patcher.applyPatches)(state.cwd, patches);
|
|
1563
|
+
const result = (0, import_patcher.applyPatches)(state.cwd, patches, { alreadyBackedUp: state.backedUpFiles });
|
|
1449
1564
|
if (!result.success) {
|
|
1450
1565
|
console.error(`[BugZero] Patch failed: ${result.error}`);
|
|
1451
1566
|
const updatedLogs = `${state.logs}
|
|
@@ -1465,7 +1580,11 @@ Any other files from that same suggestion were rolled back to keep the change at
|
|
|
1465
1580
|
console.log(`[BugZero] Note: exact match failed for ${applied.filePath} \u2014 patch applied via ${applied.matchStrategy} matching.`);
|
|
1466
1581
|
}
|
|
1467
1582
|
}
|
|
1468
|
-
return {
|
|
1583
|
+
return {
|
|
1584
|
+
appliedFix: state.fixSuggestion,
|
|
1585
|
+
backedUpFiles: result.applied.map((applied) => applied.absolutePath),
|
|
1586
|
+
patchFailed: false
|
|
1587
|
+
};
|
|
1469
1588
|
}
|
|
1470
1589
|
async function verifyNode(state) {
|
|
1471
1590
|
if (state.patchFailed) {
|
|
@@ -1507,38 +1626,6 @@ Any other files from that same suggestion were rolled back to keep the change at
|
|
|
1507
1626
|
}
|
|
1508
1627
|
});
|
|
1509
1628
|
|
|
1510
|
-
// ../../packages/shared/dist/index.js
|
|
1511
|
-
var require_dist7 = __commonJS({
|
|
1512
|
-
"../../packages/shared/dist/index.js"(exports2, module2) {
|
|
1513
|
-
"use strict";
|
|
1514
|
-
var __defProp2 = Object.defineProperty;
|
|
1515
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
1516
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
1517
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
1518
|
-
var __export = (target, all) => {
|
|
1519
|
-
for (var name in all)
|
|
1520
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
1521
|
-
};
|
|
1522
|
-
var __copyProps2 = (to, from, except, desc) => {
|
|
1523
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
1524
|
-
for (let key of __getOwnPropNames2(from))
|
|
1525
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
1526
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
1527
|
-
}
|
|
1528
|
-
return to;
|
|
1529
|
-
};
|
|
1530
|
-
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
1531
|
-
var index_exports = {};
|
|
1532
|
-
__export(index_exports, {
|
|
1533
|
-
uniqueFilePaths: () => uniqueFilePaths3
|
|
1534
|
-
});
|
|
1535
|
-
module2.exports = __toCommonJS(index_exports);
|
|
1536
|
-
function uniqueFilePaths3(patches) {
|
|
1537
|
-
return [...new Set(patches.map((patch) => patch.filePath))];
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
});
|
|
1541
|
-
|
|
1542
1629
|
// ../../packages/core/dist/index.js
|
|
1543
1630
|
var require_dist8 = __commonJS({
|
|
1544
1631
|
"../../packages/core/dist/index.js"(exports2, module2) {
|
|
@@ -1610,8 +1697,8 @@ var require_dist8 = __commonJS({
|
|
|
1610
1697
|
return "unknown";
|
|
1611
1698
|
}
|
|
1612
1699
|
var import_analyzers = require_dist2();
|
|
1613
|
-
var import_agents =
|
|
1614
|
-
var import_shared3 =
|
|
1700
|
+
var import_agents = require_dist7();
|
|
1701
|
+
var import_shared3 = require_dist4();
|
|
1615
1702
|
var import_fs3 = __toESM2(require("fs"));
|
|
1616
1703
|
var import_path3 = __toESM2(require("path"));
|
|
1617
1704
|
var import_url = require("url");
|
|
@@ -2012,7 +2099,7 @@ var import_path = __toESM(require("path"));
|
|
|
2012
2099
|
var import_core = __toESM(require_dist8());
|
|
2013
2100
|
|
|
2014
2101
|
// src/json-output.ts
|
|
2015
|
-
var import_shared = __toESM(
|
|
2102
|
+
var import_shared = __toESM(require_dist4());
|
|
2016
2103
|
function stepStatus(step) {
|
|
2017
2104
|
if (step.skipped) return "skipped";
|
|
2018
2105
|
return step.success ? "passed" : "failed";
|
|
@@ -2069,7 +2156,7 @@ function buildErrorJson(message) {
|
|
|
2069
2156
|
}
|
|
2070
2157
|
|
|
2071
2158
|
// src/summary.ts
|
|
2072
|
-
var import_shared2 = __toESM(
|
|
2159
|
+
var import_shared2 = __toESM(require_dist4());
|
|
2073
2160
|
function tokenLines(result) {
|
|
2074
2161
|
if (result.promptTokens === void 0 || result.completionTokens === void 0) return [];
|
|
2075
2162
|
const total = result.promptTokens + result.completionTokens;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bugzero",
|
|
3
|
-
"version": "0.0.
|
|
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)",
|