bugzero 0.0.65 → 0.0.66

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 +2 -0
  2. package/dist/index.js +63 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -349,6 +349,8 @@ Patterns are relative to the project and ignore case. `*` matches within a folde
349
349
 
350
350
  `bugzero vibe` creates the file if it is missing and only changes `model`, so your other settings are kept.
351
351
 
352
+ Mistakes are not ignored. If `.bugzerorc` is not valid JSON, or a setting has the wrong type (for example `protect` written as text instead of a list), BugZero stops and says what is wrong before it runs or sends anything. `bugzero undo` is the exception: it warns you and restores your files using the built-in protection rules. Save the file as UTF-8. Keys BugZero does not recognise are ignored, so check their spelling.
353
+
352
354
  ### Your own commands
353
355
 
354
356
  To run something other than your `package.json` scripts, add `commands`:
package/dist/index.js CHANGED
@@ -433,29 +433,61 @@ var require_dist = __commonJS({
433
433
  var import_fs22 = __toESM2(require("fs"));
434
434
  var import_path22 = __toESM2(require("path"));
435
435
  var CONFIG_FILENAME = ".bugzerorc";
436
- function getLocalConfig(cwd = process.cwd()) {
436
+ function configError(configPath, problem) {
437
+ return new Error(`${configPath} ${problem} Fix it, or delete the file to use the default settings.`);
438
+ }
439
+ function readConfigText(configPath) {
440
+ let bytes;
437
441
  try {
438
- const configPath = import_path22.default.resolve(cwd, CONFIG_FILENAME);
439
- if (import_fs22.default.existsSync(configPath)) {
440
- const content = import_fs22.default.readFileSync(configPath, "utf-8");
441
- return JSON.parse(content);
442
+ bytes = import_fs22.default.readFileSync(configPath);
443
+ } catch (error) {
444
+ const { code, message } = error;
445
+ if (code === "ENOENT" || code === "ENOTDIR") return void 0;
446
+ throw configError(configPath, `could not be read (${message}).`);
447
+ }
448
+ const utf16 = bytes[0] === 255 && bytes[1] === 254 || bytes[0] === 254 && bytes[1] === 255;
449
+ if (utf16) throw configError(configPath, "is saved as UTF-16, which BugZero cannot read. Save it as UTF-8.");
450
+ const text = bytes.toString("utf-8");
451
+ return text.charCodeAt(0) === 65279 ? text.slice(1) : text;
452
+ }
453
+ function checkTypes(configPath, config) {
454
+ for (const key of ["protect", "allow"]) {
455
+ const value = config[key];
456
+ if (value !== void 0 && !(Array.isArray(value) && value.every((entry) => typeof entry === "string"))) {
457
+ throw configError(configPath, `has a "${key}" that is not a list of text, such as ["config/prod.json"].`);
442
458
  }
443
- } catch (e) {
444
459
  }
445
- return {};
460
+ if (config.model !== void 0 && typeof config.model !== "string") {
461
+ throw configError(configPath, 'has a "model" that is not text.');
462
+ }
463
+ }
464
+ function getLocalConfig(cwd = process.cwd()) {
465
+ const configPath = import_path22.default.resolve(cwd, CONFIG_FILENAME);
466
+ const text = readConfigText(configPath);
467
+ if (text === void 0 || text.trim() === "") return {};
468
+ let parsed;
469
+ try {
470
+ parsed = JSON.parse(text);
471
+ } catch (error) {
472
+ throw configError(configPath, `is not valid JSON (${error.message}).`);
473
+ }
474
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
475
+ throw configError(configPath, 'must hold a JSON object, such as {"model": "..."}.');
476
+ }
477
+ checkTypes(configPath, parsed);
478
+ return parsed;
446
479
  }
447
480
  function saveLocalConfig(config, cwd = process.cwd()) {
448
481
  const configPath = import_path22.default.resolve(cwd, CONFIG_FILENAME);
449
482
  const merged = { ...getLocalConfig(cwd), ...config };
450
483
  import_fs22.default.writeFileSync(configPath, JSON.stringify(merged, null, 2), "utf-8");
451
484
  }
452
- function stringList(value) {
453
- if (!Array.isArray(value)) return [];
454
- return value.filter((entry) => typeof entry === "string" && entry.trim() !== "");
485
+ function entries(list) {
486
+ return (list ?? []).filter((entry) => entry.trim() !== "");
455
487
  }
456
488
  function getProtectionSettings2(cwd = process.cwd()) {
457
489
  const config = getLocalConfig(cwd);
458
- return { protect: stringList(config.protect), allow: stringList(config.allow) };
490
+ return { protect: entries(config.protect), allow: entries(config.allow) };
459
491
  }
460
492
  function getSelectedModel(cwd = process.cwd()) {
461
493
  const config = getLocalConfig(cwd);
@@ -3960,10 +3992,20 @@ program.command("rescue").description("Detect build failures and automatically a
3960
3992
  program.command("undo").description("Put back the files BugZero changed, from the backups saved next to them").option("-p, --path <dir>", "Path to the target project", ".").option("--dry-run", "Show what would be restored without changing anything", false).option("--force", "Also restore files that were edited after BugZero fixed them (those edits are lost)", false).action((opts) => {
3961
3993
  try {
3962
3994
  const cwd = import_path2.default.resolve(opts.path);
3995
+ let settings;
3996
+ try {
3997
+ settings = (0, import_config.getProtectionSettings)(cwd);
3998
+ } catch (error) {
3999
+ console.warn(
4000
+ `
4001
+ \u26A0\uFE0F [BugZero] ${error.message}
4002
+ Undo is going ahead with the built-in protection rules; your protect and allow lists are not applied.`
4003
+ );
4004
+ }
3963
4005
  const entries = (0, import_patcher2.undoChanges)(cwd, {
3964
4006
  dryRun: opts.dryRun === true,
3965
4007
  force: opts.force === true,
3966
- protection: (0, import_shared3.createProtectedPathRules)((0, import_config.getProtectionSettings)(cwd))
4008
+ protection: (0, import_shared3.createProtectedPathRules)(settings)
3967
4009
  });
3968
4010
  const summary = buildUndoSummary(entries, { dryRun: opts.dryRun === true });
3969
4011
  console.log();
@@ -3985,6 +4027,15 @@ program.command("vibe").description("Select which AI model (brain) to use for re
3985
4027
  const { getLocalConfig, saveLocalConfig } = await Promise.resolve().then(() => __toESM(require_dist()));
3986
4028
  const readline2 = await import("readline");
3987
4029
  const axios = (await import("axios")).default;
4030
+ let currentModel;
4031
+ try {
4032
+ currentModel = getLocalConfig().model || "deepseek/deepseek-chat";
4033
+ } catch (error) {
4034
+ console.error(`
4035
+ \u274C [BugZero] Execution failed: ${error.message}`);
4036
+ process.exitCode = 1;
4037
+ return;
4038
+ }
3988
4039
  console.log(`
3989
4040
  \u{1F9E0} BugZero Brain Selector`);
3990
4041
  console.log(`\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`);
@@ -4017,7 +4068,6 @@ program.command("vibe").description("Select which AI model (brain) to use for re
4017
4068
  { id: "meta-llama/llama-3.3-70b-instruct", name: "Llama 3.3 Instruct" }
4018
4069
  ];
4019
4070
  }
4020
- const currentModel = getLocalConfig().model || "deepseek/deepseek-chat";
4021
4071
  console.log(`
4022
4072
  Current active model: \x1B[36m${currentModel}\x1B[0m
4023
4073
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.65",
3
+ "version": "0.0.66",
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)",