bugzero 0.0.67 → 0.0.68

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 +11 -1
  2. package/dist/index.js +112 -27
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -111,7 +111,7 @@ bugzero rescue
111
111
  - **Framework detection.** Identifies Next.js, NestJS, Vite, Remix, Astro, SvelteKit, Nuxt, Angular, Create React App, or a plain TypeScript project from its config files and dependencies, and shows the result in the run banner.
112
112
  - **Package manager detection.** Runs build, lint, and test with the tool your project actually uses — npm, pnpm, yarn, or bun. It checks the `packageManager` field in `package.json` first, then `pnpm-workspace.yaml` or a lockfile, and falls back to npm.
113
113
  - **Script-aware validation.** Only runs the build, lint, and test scripts your `package.json` actually defines. A missing script is reported as skipped rather than failed, so a project without a `lint` script no longer shows a false lint failure. You can also give any step [your own command](#your-own-commands). Pointing `--path` at a directory with no `package.json` stops immediately with a clear error, unless `.bugzerorc` gives it [a command to run](#your-own-commands).
114
- - **Error parsing.** Recognizes TypeScript compiler errors (file, line, column, message), ESLint errors, and Jest failures to classify what broke and how many errors were found. Output in any other format is still passed to the model as raw logs.
114
+ - **Error parsing.** Recognizes TypeScript compiler errors (file, line, column, message), ESLint errors, Jest failures and pytest failures to classify what broke and how many errors were found. Output in any other format is still passed to the model as raw logs.
115
115
 
116
116
  ### Integrations and output
117
117
 
@@ -373,6 +373,16 @@ To run something other than your `package.json` scripts, add `commands`:
373
373
 
374
374
  These commands run on your machine exactly as written, so, as with `package.json` scripts, only run BugZero on projects you trust.
375
375
 
376
+ ### Python projects
377
+
378
+ A folder with a `pyproject.toml`, `setup.py`, `setup.cfg`, `requirements.txt` (or `requirements-dev.txt` and the like), `Pipfile`, `pytest.ini` or `tox.ini` and no `package.json` is a Python project. BugZero shows it as `python`, and with no settings at all it runs your tests with `python -m pytest`, as long as the project clearly uses pytest (a `pytest.ini`, a `conftest.py`, a pytest section in its config, or pytest in its requirements) and pytest can really be run.
379
+
380
+ - The Python used is the project's own `.venv` or `venv` folder if it has one, otherwise `python3` (on Windows, `python`, then `py`).
381
+ - Nothing else is run by default. For a build or lint step, add `commands`, for example `{"commands": {"build": "mypy .", "lint": "ruff check ."}}`. A `test` command of your own replaces the default, and `"test": false` turns it off.
382
+ - If pytest is set up but cannot be run (it is not installed), BugZero stops and says so, rather than asking the model to fix a missing install.
383
+ - A folder that also has a `package.json` is treated as a Node.js project, as before.
384
+ - pytest output is understood: each failed test, and each file that could not be imported, counts as one error. That lets BugZero stop early when attempts are not getting anywhere. Re-running only the failing test files between attempts is still for Jest and Vitest.
385
+
376
386
  ---
377
387
 
378
388
  ## Reports
package/dist/index.js CHANGED
@@ -1385,11 +1385,14 @@ var require_dist4 = __commonJS({
1385
1385
  var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
1386
1386
  var index_exports = {};
1387
1387
  __export(index_exports, {
1388
+ defaultPythonCommands: () => defaultPythonCommands,
1388
1389
  detectPackageManager: () => detectPackageManager2,
1389
1390
  detectTestRunner: () => detectTestRunner,
1390
1391
  findFailingTestFiles: () => findFailingTestFiles,
1392
+ findPython: () => findPython,
1391
1393
  getRunScriptCommand: () => getRunScriptCommand,
1392
1394
  hasPackageJson: () => hasPackageJson,
1395
+ isPythonProject: () => isPythonProject,
1393
1396
  parseErrors: () => parseErrors,
1394
1397
  planFocusedTests: () => planFocusedTests,
1395
1398
  readScriptText: () => readScriptText,
@@ -1402,7 +1405,8 @@ var require_dist4 = __commonJS({
1402
1405
  runStep: () => runStep,
1403
1406
  runTests: () => runTests,
1404
1407
  runValidationPipeline: () => runValidationPipeline,
1405
- usableFocusedResult: () => usableFocusedResult
1408
+ usableFocusedResult: () => usableFocusedResult,
1409
+ usesPytest: () => usesPytest
1406
1410
  });
1407
1411
  module2.exports = __toCommonJS(index_exports);
1408
1412
  var import_fs2 = __toESM2(require("fs"));
@@ -1547,6 +1551,8 @@ var require_dist4 = __commonJS({
1547
1551
  var ESLINT_ERROR_RE = /^\s+(\d+):(\d+)\s+error\s+(.+)$/gm;
1548
1552
  var JEST_FAIL_RE = /● (.+)/g;
1549
1553
  var JEST_FILE_RE = /FAIL\s+([\w/\\.\-]+)/g;
1554
+ var PYTEST_LINE_RE = /^(?:FAILED|ERROR)[ \t]+(\S+?\.py)(?:::(.+?))?(?:[ \t]+-[ \t]+(.*))?$/gm;
1555
+ var ANSI_RE = /\u001b\[[0-9;]*[A-Za-z]/g;
1550
1556
  function parseErrors(rawOutput) {
1551
1557
  const output = rawOutput.replace(/\r\n/g, "\n");
1552
1558
  const errors = [];
@@ -1584,6 +1590,16 @@ var require_dist4 = __commonJS({
1584
1590
  });
1585
1591
  }
1586
1592
  if (errors.length > 0) return errors;
1593
+ for (const m of output.replace(ANSI_RE, "").matchAll(PYTEST_LINE_RE)) {
1594
+ const [raw, file, test, reason] = m;
1595
+ errors.push({
1596
+ type: "pytest",
1597
+ file,
1598
+ message: `${test ?? file}${reason ? ` - ${reason.trim()}` : ""}`,
1599
+ raw
1600
+ });
1601
+ }
1602
+ if (errors.length > 0) return errors;
1587
1603
  if (output.trim()) {
1588
1604
  errors.push({
1589
1605
  type: "unknown",
@@ -1634,7 +1650,7 @@ var require_dist4 = __commonJS({
1634
1650
  var import_fs32 = __toESM2(require("fs"));
1635
1651
  var import_shared4 = require_dist2();
1636
1652
  var MAX_FOCUSED_FILES = 10;
1637
- var ANSI_RE = /\u001b\[[0-9;]*[A-Za-z]/g;
1653
+ var ANSI_RE2 = /\u001b\[[0-9;]*[A-Za-z]/g;
1638
1654
  var FAIL_LINE_RE = /^[ \t]*FAIL[ \t]+(?:\|[^|\n]*\|[ \t]+)?(\S+)/gm;
1639
1655
  var TEST_FILE_RE = /\.(test|spec)\.[cm]?[jt]sx?$|(^|\/)__tests__\//;
1640
1656
  var SAFE_PATH_RE = /^[A-Za-z0-9_@.+/-]+$/;
@@ -1649,7 +1665,7 @@ var require_dist4 = __commonJS({
1649
1665
  return names.size === 1 ? [...names][0] : null;
1650
1666
  }
1651
1667
  function findFailingTestFiles(cwd, output) {
1652
- const text = output.replace(ANSI_RE, "").replace(/\r\n/g, "\n");
1668
+ const text = output.replace(ANSI_RE2, "").replace(/\r\n/g, "\n");
1653
1669
  const files = [];
1654
1670
  for (const match of text.matchAll(FAIL_LINE_RE)) {
1655
1671
  const candidate = match[1].replace(/\\/g, "/").replace(/^\.\//, "");
@@ -1688,6 +1704,60 @@ var require_dist4 = __commonJS({
1688
1704
  if (result.timedOut) return true;
1689
1705
  return findFailingTestFiles(cwd, result.output).length > 0;
1690
1706
  }
1707
+ var import_child_process2 = require("child_process");
1708
+ var import_fs4 = __toESM2(require("fs"));
1709
+ var import_path42 = __toESM2(require("path"));
1710
+ var MARKER_FILES = ["pyproject.toml", "setup.py", "setup.cfg", "Pipfile", "pytest.ini", "tox.ini"];
1711
+ function requirementsFiles(cwd) {
1712
+ try {
1713
+ return import_fs4.default.readdirSync(cwd).filter((name) => /^requirements([-_.].+)?\.txt$/i.test(name));
1714
+ } catch {
1715
+ return [];
1716
+ }
1717
+ }
1718
+ function isPythonProject(cwd = process.cwd()) {
1719
+ return MARKER_FILES.some((file) => import_fs4.default.existsSync(import_path42.default.join(cwd, file))) || requirementsFiles(cwd).length > 0;
1720
+ }
1721
+ function readText(file) {
1722
+ try {
1723
+ return import_fs4.default.readFileSync(file, "utf-8");
1724
+ } catch {
1725
+ return "";
1726
+ }
1727
+ }
1728
+ function usesPytest(cwd = process.cwd()) {
1729
+ const exists = (file) => import_fs4.default.existsSync(import_path42.default.join(cwd, file));
1730
+ if (exists("pytest.ini") || exists("conftest.py") || exists("tests/conftest.py") || exists("test/conftest.py")) return true;
1731
+ const pyproject = readText(import_path42.default.join(cwd, "pyproject.toml"));
1732
+ if (/\[tool\.pytest/.test(pyproject) || /["']pytest(?![\w.-])/.test(pyproject) || /^\s*pytest\s*=/m.test(pyproject)) return true;
1733
+ if (/^\[(?:tool:)?pytest\]/m.test(readText(import_path42.default.join(cwd, "setup.cfg")))) return true;
1734
+ if (/^\[(?:tool:)?pytest\]/m.test(readText(import_path42.default.join(cwd, "tox.ini")))) return true;
1735
+ if (/^\s*pytest\s*=/m.test(readText(import_path42.default.join(cwd, "Pipfile")))) return true;
1736
+ return requirementsFiles(cwd).some((name) => /^\s*pytest(?![\w.-])/im.test(readText(import_path42.default.join(cwd, name))));
1737
+ }
1738
+ function runsPytest(python, cwd) {
1739
+ const program2 = /[\\/]/.test(python) ? import_path42.default.resolve(cwd, python) : python;
1740
+ return (0, import_child_process2.spawnSync)(program2, ["-m", "pytest", "--version"], { cwd, stdio: "ignore", timeout: 2e4 }).status === 0;
1741
+ }
1742
+ function runsPython(command) {
1743
+ const result = (0, import_child_process2.spawnSync)(command, ["--version"], { stdio: "ignore", timeout: 5e3 });
1744
+ return result.status === 0;
1745
+ }
1746
+ function findPython(cwd, options = {}) {
1747
+ const platform = options.platform ?? process.platform;
1748
+ const works = options.works ?? runsPython;
1749
+ for (const folder of [".venv", "venv"]) {
1750
+ const interpreter = platform === "win32" ? import_path42.default.join(folder, "Scripts", "python.exe") : import_path42.default.join(folder, "bin", "python");
1751
+ if (import_fs4.default.existsSync(import_path42.default.join(cwd, interpreter))) return interpreter;
1752
+ }
1753
+ return (platform === "win32" ? ["python", "py"] : ["python3", "python"]).find((command) => works(command));
1754
+ }
1755
+ function defaultPythonCommands(cwd, options = {}) {
1756
+ if (hasPackageJson(cwd) || !isPythonProject(cwd) || !usesPytest(cwd)) return void 0;
1757
+ const python = findPython(cwd, options);
1758
+ if (python === void 0 || !(options.pytestWorks ?? runsPytest)(python, cwd)) return void 0;
1759
+ return { test: `${python} -m pytest` };
1760
+ }
1691
1761
  }
1692
1762
  });
1693
1763
 
@@ -2967,7 +3037,7 @@ var require_dist8 = __commonJS({
2967
3037
  DEFAULT_PATIENCE: () => DEFAULT_PATIENCE,
2968
3038
  REPORT_FILENAME: () => REPORT_FILENAME2,
2969
3039
  detectFramework: () => detectFramework2,
2970
- detectPackageManager: () => import_analyzers3.detectPackageManager,
3040
+ detectPackageManager: () => import_analyzers4.detectPackageManager,
2971
3041
  orchestrate: () => orchestrate2,
2972
3042
  orchestrateAndFix: () => orchestrateAndFix2,
2973
3043
  projectPackageManager: () => projectPackageManager2,
@@ -2982,6 +3052,7 @@ var require_dist8 = __commonJS({
2982
3052
  module2.exports = __toCommonJS(index_exports);
2983
3053
  var import_fs2 = __toESM2(require("fs"));
2984
3054
  var import_path3 = __toESM2(require("path"));
3055
+ var import_analyzers = require_dist4();
2985
3056
  function detectFramework2(cwd = process.cwd()) {
2986
3057
  const has = (...files) => files.some((f) => import_fs2.default.existsSync(import_path3.default.join(cwd, f)));
2987
3058
  if (has("next.config.js", "next.config.ts", "next.config.mjs")) return "nextjs";
@@ -3005,9 +3076,10 @@ var require_dist8 = __commonJS({
3005
3076
  }
3006
3077
  }
3007
3078
  if (has("tsconfig.json")) return "typescript";
3079
+ if (!has("package.json") && (0, import_analyzers.isPythonProject)(cwd)) return "python";
3008
3080
  return "unknown";
3009
3081
  }
3010
- var import_analyzers2 = require_dist4();
3082
+ var import_analyzers3 = require_dist4();
3011
3083
  var import_agents = require_dist7();
3012
3084
  var import_shared22 = require_dist2();
3013
3085
  var import_fs3 = __toESM2(require("fs"));
@@ -3208,19 +3280,23 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
3208
3280
  }
3209
3281
  return commands;
3210
3282
  }
3211
- var import_analyzers = require_dist4();
3283
+ var import_analyzers2 = require_dist4();
3212
3284
  var import_fs22 = __toESM2(require("fs"));
3213
3285
  var import_path22 = __toESM2(require("path"));
3214
3286
  var hasPackageJson = (cwd) => import_fs22.default.existsSync(import_path22.default.join(cwd, "package.json"));
3215
3287
  function assertProject(cwd, commands = {}) {
3216
3288
  if (hasPackageJson(cwd)) return;
3217
3289
  if (Object.values(commands).some((command) => typeof command === "string")) return;
3290
+ if ((0, import_analyzers2.isPythonProject)(cwd)) {
3291
+ const why = (0, import_analyzers2.usesPytest)(cwd) ? "BugZero found pytest set up but could not run it (is it installed? A .venv or venv folder in the project is used when there is one). Install it, or" : "BugZero found no test setup it knows (pytest). To tell it how to check the project,";
3292
+ throw new Error(`No package.json found in ${cwd}. This looks like a Python project. ${why} set "commands" in .bugzerorc (see the README).`);
3293
+ }
3218
3294
  throw new Error(
3219
3295
  `No package.json found in ${cwd}. Point --path at a Node.js project, or, to check a project of another kind, set "commands" in .bugzerorc (see the README).`
3220
3296
  );
3221
3297
  }
3222
3298
  function projectPackageManager2(cwd) {
3223
- return hasPackageJson(cwd) ? (0, import_analyzers.detectPackageManager)(cwd) : "none";
3299
+ return hasPackageJson(cwd) ? (0, import_analyzers2.detectPackageManager)(cwd) : "none";
3224
3300
  }
3225
3301
  var import_ai_provider = require_dist5();
3226
3302
  var REPORT_FILENAME2 = "bugzero-report.md";
@@ -3236,14 +3312,22 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
3236
3312
  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.`;
3237
3313
  return declined > 0 ? `${base} You declined ${declined} proposed ${plural}.` : base;
3238
3314
  }
3239
- function projectCommands(configured) {
3240
- const commands = resolveCommands(configured);
3241
- return Object.keys(commands).length === 0 ? void 0 : commands;
3242
- }
3243
- function announceCommands(commands) {
3244
- if (commands === void 0) return;
3245
- const listed = ["build", "lint", "test"].filter((step) => commands[step] !== void 0).map((step) => `${step}: ${commands[step] === false ? "off" : commands[step]}`);
3246
- console.log(`[BugZero] Commands from .bugzerorc: ${listed.join(" | ")}`);
3315
+ function projectCommands(cwd, configured) {
3316
+ const own = resolveCommands(configured);
3317
+ const defaults = own.test === void 0 ? (0, import_analyzers3.defaultPythonCommands)(cwd) ?? {} : {};
3318
+ const all = { ...defaults, ...own };
3319
+ return { commands: Object.keys(all).length === 0 ? void 0 : all, own, defaults };
3320
+ }
3321
+ function announceCommands({ own, defaults }) {
3322
+ const steps = ["build", "lint", "test"];
3323
+ const listed = steps.filter((step) => own[step] !== void 0).map((step) => `${step}: ${own[step] === false ? "off" : own[step]}`);
3324
+ if (listed.length > 0) console.log(`[BugZero] Commands from .bugzerorc: ${listed.join(" | ")}`);
3325
+ for (const step of steps) {
3326
+ if (own[step] !== void 0 || defaults[step] === void 0) continue;
3327
+ console.log(
3328
+ `[BugZero] Python project: running ${step === "test" ? "tests" : step} with ${defaults[step]} (a default; set "commands" in .bugzerorc to change it).`
3329
+ );
3330
+ }
3247
3331
  }
3248
3332
  function statusLabel(result) {
3249
3333
  if (result.disabled) return "\u23ED\uFE0F Skipped (turned off in .bugzerorc)";
@@ -3254,14 +3338,14 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
3254
3338
  async function orchestrate2(options = {}) {
3255
3339
  const cwd = options.cwd ?? process.cwd();
3256
3340
  const timeoutMs = resolveTimeoutMs2(options.timeoutSeconds);
3257
- const commands = projectCommands((0, import_config2.getLocalConfig)(cwd).commands);
3258
- assertProject(cwd, commands);
3259
- announceCommands(commands);
3260
- const stepOptions = { timeoutMs, commands };
3341
+ const project = projectCommands(cwd, (0, import_config2.getLocalConfig)(cwd).commands);
3342
+ assertProject(cwd, project.commands);
3343
+ announceCommands(project);
3344
+ const stepOptions = { timeoutMs, commands: project.commands };
3261
3345
  const [build, lint, test] = await Promise.all([
3262
- (0, import_analyzers2.runBuild)(cwd, stepOptions),
3263
- (0, import_analyzers2.runLint)(cwd, stepOptions),
3264
- (0, import_analyzers2.runTests)(cwd, stepOptions)
3346
+ (0, import_analyzers3.runBuild)(cwd, stepOptions),
3347
+ (0, import_analyzers3.runLint)(cwd, stepOptions),
3348
+ (0, import_analyzers3.runTests)(cwd, stepOptions)
3265
3349
  ]);
3266
3350
  await writeReport(cwd, "hunt", {
3267
3351
  success: build.success && lint.success && test.success,
@@ -3282,9 +3366,10 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
3282
3366
  const maxTokens = resolveMaxTokens2(options.maxTokens, config.maxTokens);
3283
3367
  const tools = resolveTools(options.tools, config.tools);
3284
3368
  const maxToolRequests = resolveMaxToolRequests2(options.maxToolRequests, config.maxToolRequests);
3285
- const commands = projectCommands(config.commands);
3369
+ const project = projectCommands(cwd, config.commands);
3370
+ const commands = project.commands;
3286
3371
  assertProject(cwd, commands);
3287
- announceCommands(commands);
3372
+ announceCommands(project);
3288
3373
  const announceTools = () => {
3289
3374
  if (tools) {
3290
3375
  console.log(
@@ -3295,7 +3380,7 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
3295
3380
  }
3296
3381
  };
3297
3382
  console.log(`[BugZero] Running validation pipeline in: ${cwd}`);
3298
- const pipelineResult = await (0, import_analyzers2.runValidationPipeline)(cwd, { timeoutMs, commands });
3383
+ const pipelineResult = await (0, import_analyzers3.runValidationPipeline)(cwd, { timeoutMs, commands });
3299
3384
  if (pipelineResult.success) {
3300
3385
  console.log("[BugZero] Validation already passing \u2014 nothing to fix.");
3301
3386
  if (options.printPrompt) {
@@ -3311,7 +3396,7 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
3311
3396
  });
3312
3397
  return { success: true, attempts: 0, finalOutput: "" };
3313
3398
  }
3314
- const errors = (0, import_analyzers2.parseErrors)(pipelineResult.output);
3399
+ const errors = (0, import_analyzers3.parseErrors)(pipelineResult.output);
3315
3400
  console.log(`[BugZero] Detected ${errors.length} error(s) (type: ${errors[0]?.type ?? "unknown"})`);
3316
3401
  if (options.printPrompt) {
3317
3402
  console.log("[BugZero] --print-prompt: showing the first prompt without sending it.");
@@ -3636,7 +3721,7 @@ ${rawOutput}
3636
3721
  }
3637
3722
  return spend;
3638
3723
  }
3639
- var import_analyzers3 = require_dist4();
3724
+ var import_analyzers4 = require_dist4();
3640
3725
  }
3641
3726
  });
3642
3727
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.67",
3
+ "version": "0.0.68",
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)",