bugzero 0.0.25 → 0.0.27

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > bugzero@0.0.25 build D:\WD projects\OpsPilot\packages\cli
2
+ > bugzero@0.0.27 build D:\WD projects\OpsPilot\packages\cli
3
3
  > tsup src/index.ts --format cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -7,8 +7,8 @@
7
7
  CLI tsup v8.5.1
8
8
  CLI Target: es2022
9
9
  CJS Build start
10
- CJS dist\index.js 62.76 KB
11
- CJS ⚡️ Build success in 217ms
10
+ CJS dist\index.js 70.06 KB
11
+ CJS ⚡️ Build success in 75ms
12
12
  DTS Build start
13
- DTS ⚡️ Build success in 1999ms
13
+ DTS ⚡️ Build success in 1335ms
14
14
  DTS dist\index.d.ts 20.00 B
package/dist/index.js CHANGED
@@ -386,18 +386,36 @@ var require_dist = __commonJS({
386
386
  });
387
387
  module2.exports = __toCommonJS(index_exports);
388
388
  var import_dotenv = __toESM2(require_main());
389
- import_dotenv.default.config();
390
- var env = {
391
- openRouterKey: process.env.OPENROUTER_API_KEY
392
- };
393
389
  var import_fs = __toESM2(require("fs"));
394
390
  var import_path2 = __toESM2(require("path"));
391
+ function loadEnv() {
392
+ let dir = process.cwd();
393
+ while (true) {
394
+ const envPath = import_path2.default.join(dir, ".env");
395
+ if (import_fs.default.existsSync(envPath)) {
396
+ import_dotenv.default.config({ path: envPath });
397
+ return;
398
+ }
399
+ const parent = import_path2.default.dirname(dir);
400
+ if (parent === dir) {
401
+ break;
402
+ }
403
+ dir = parent;
404
+ }
405
+ import_dotenv.default.config();
406
+ }
407
+ loadEnv();
408
+ var env = {
409
+ openRouterKey: process.env.OPENROUTER_API_KEY || ""
410
+ };
411
+ var import_fs2 = __toESM2(require("fs"));
412
+ var import_path22 = __toESM2(require("path"));
395
413
  var CONFIG_FILENAME = ".bugzerorc";
396
414
  function getLocalConfig(cwd = process.cwd()) {
397
415
  try {
398
- const configPath = import_path2.default.resolve(cwd, CONFIG_FILENAME);
399
- if (import_fs.default.existsSync(configPath)) {
400
- const content = import_fs.default.readFileSync(configPath, "utf-8");
416
+ const configPath = import_path22.default.resolve(cwd, CONFIG_FILENAME);
417
+ if (import_fs2.default.existsSync(configPath)) {
418
+ const content = import_fs2.default.readFileSync(configPath, "utf-8");
401
419
  return JSON.parse(content);
402
420
  }
403
421
  } catch (e) {
@@ -405,8 +423,8 @@ var require_dist = __commonJS({
405
423
  return {};
406
424
  }
407
425
  function saveLocalConfig(config, cwd = process.cwd()) {
408
- const configPath = import_path2.default.resolve(cwd, CONFIG_FILENAME);
409
- import_fs.default.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
426
+ const configPath = import_path22.default.resolve(cwd, CONFIG_FILENAME);
427
+ import_fs2.default.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
410
428
  }
411
429
  function getSelectedModel(cwd = process.cwd()) {
412
430
  const config = getLocalConfig(cwd);
@@ -621,6 +639,18 @@ var require_dist3 = __commonJS({
621
639
  var OpenRouterProvider = class {
622
640
  async invoke(prompt, options) {
623
641
  const model = resolveModel(options?.cwd);
642
+ const apiKey = process.env.OPENROUTER_API_KEY;
643
+ if (!apiKey) {
644
+ console.error(`
645
+ \u274C [BugZero] Error: OPENROUTER_API_KEY environment variable is not set.`);
646
+ console.error(`\u{1F449} Please configure it using one of the following methods:`);
647
+ console.error(` - On macOS/Linux: export OPENROUTER_API_KEY="your_openrouter_api_key_here"`);
648
+ console.error(` - On Windows (PowerShell): $env:OPENROUTER_API_KEY="your_openrouter_api_key_here"`);
649
+ console.error(` - Or add it to a .env file at the root of the project you are fixing:`);
650
+ console.error(` OPENROUTER_API_KEY=your_openrouter_api_key_here
651
+ `);
652
+ throw new Error("Missing OPENROUTER_API_KEY environment variable.");
653
+ }
624
654
  try {
625
655
  const response = await import_axios.default.post(
626
656
  "https://openrouter.ai/api/v1/chat/completions",
@@ -683,9 +713,11 @@ var require_dist3 = __commonJS({
683
713
  var require_dist4 = __commonJS({
684
714
  "../prompts/dist/index.js"(exports2, module2) {
685
715
  "use strict";
716
+ var __create2 = Object.create;
686
717
  var __defProp2 = Object.defineProperty;
687
718
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
688
719
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
720
+ var __getProtoOf2 = Object.getPrototypeOf;
689
721
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
690
722
  var __export = (target, all) => {
691
723
  for (var name in all)
@@ -699,12 +731,155 @@ var require_dist4 = __commonJS({
699
731
  }
700
732
  return to;
701
733
  };
734
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
735
+ // If the importer is in node compatibility mode or this is not an ESM
736
+ // file that has been converted to a CommonJS file using a Babel-
737
+ // compatible transform (i.e. "__esModule" has not been set), then set
738
+ // "default" to the CommonJS "module.exports" for node compatibility.
739
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
740
+ mod
741
+ ));
702
742
  var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
703
743
  var index_exports = {};
704
744
  __export(index_exports, {
705
745
  buildAnalysisPrompt: () => buildAnalysisPrompt
706
746
  });
707
747
  module2.exports = __toCommonJS(index_exports);
748
+ var import_fs = __toESM2(require("fs"));
749
+ var import_path2 = __toESM2(require("path"));
750
+ function resolveExistingPathPrefix(candidate) {
751
+ let current = candidate.replace(/(?::\d+)+$/, "").replace(/['"()\[\]`]+$/, "").trim();
752
+ while (current.length > 0) {
753
+ try {
754
+ if (import_fs.default.existsSync(current)) {
755
+ return current;
756
+ }
757
+ } catch {
758
+ }
759
+ const lastSpace = current.lastIndexOf(" ");
760
+ if (lastSpace === -1) {
761
+ const lastSlash = Math.max(current.lastIndexOf("/"), current.lastIndexOf("\\"));
762
+ if (lastSlash === -1) {
763
+ break;
764
+ }
765
+ current = current.slice(0, lastSlash).trim();
766
+ } else {
767
+ current = current.slice(0, lastSpace).trim();
768
+ }
769
+ }
770
+ return null;
771
+ }
772
+ function getContextFiles(logs, cwd) {
773
+ const candidates = /* @__PURE__ */ new Set();
774
+ const quotedRegex = /['"`]([^'"`\n]+)['"`]/g;
775
+ let match;
776
+ while ((match = quotedRegex.exec(logs)) !== null) {
777
+ const p = match[1].trim();
778
+ if (p.includes("/") || p.includes("\\") || p === "." || p.startsWith(".")) {
779
+ candidates.add(p);
780
+ }
781
+ }
782
+ const winAbsRegex = /([a-zA-Z]:\\[^*?"<>|\n\r]+)/g;
783
+ while ((match = winAbsRegex.exec(logs)) !== null) {
784
+ candidates.add(match[1].trim());
785
+ }
786
+ const unixAbsRegex = /(\/[^*?"<>|\n\r\t]+)/g;
787
+ while ((match = unixAbsRegex.exec(logs)) !== null) {
788
+ candidates.add(match[1].trim());
789
+ }
790
+ const fallbackRegex = /(?:[a-zA-Z]:)?[a-zA-Z0-9_\-\/\\.]+\.(?:tsx?|jsx?|json|css|html|js|jsx)/g;
791
+ const fallbackMatches = logs.match(fallbackRegex) || [];
792
+ for (const m of fallbackMatches) {
793
+ candidates.add(m.trim());
794
+ }
795
+ const resolvedPaths = /* @__PURE__ */ new Set();
796
+ for (const candidate of candidates) {
797
+ const absPathCandidate = import_path2.default.isAbsolute(candidate) ? candidate : import_path2.default.resolve(cwd, candidate);
798
+ const resolved = resolveExistingPathPrefix(absPathCandidate);
799
+ if (resolved) {
800
+ resolvedPaths.add(import_path2.default.resolve(resolved));
801
+ }
802
+ }
803
+ if (resolvedPaths.size === 0) return "";
804
+ let context = "\n\n### \u{1F4C1} Codebase Context:\n";
805
+ const processedFiles = /* @__PURE__ */ new Set();
806
+ const addFileToContext = (filePath) => {
807
+ const relPath = import_path2.default.relative(cwd, filePath);
808
+ if (relPath.includes("node_modules") || relPath.startsWith("build") || relPath.startsWith("dist") || relPath.startsWith(".git")) {
809
+ return;
810
+ }
811
+ if (processedFiles.has(filePath)) return;
812
+ processedFiles.add(filePath);
813
+ try {
814
+ const content = import_fs.default.readFileSync(filePath, "utf-8");
815
+ context += `
816
+ --- File: ${relPath} ---
817
+ \`\`\`
818
+ ${content}
819
+ \`\`\`
820
+ `;
821
+ } catch {
822
+ }
823
+ };
824
+ for (const absPath of resolvedPaths) {
825
+ try {
826
+ const stats = import_fs.default.statSync(absPath);
827
+ if (stats.isFile()) {
828
+ addFileToContext(absPath);
829
+ const parentDir = import_path2.default.dirname(absPath);
830
+ const filesInDir = import_fs.default.readdirSync(parentDir);
831
+ const relParentDir = import_path2.default.relative(cwd, parentDir) || ".";
832
+ context += `
833
+ --- Directory files in "${relParentDir}": ---
834
+ `;
835
+ for (const file of filesInDir) {
836
+ try {
837
+ const fileStats = import_fs.default.statSync(import_path2.default.join(parentDir, file));
838
+ const marker = fileStats.isDirectory() ? "/" : "";
839
+ context += `- ${file}${marker}
840
+ `;
841
+ } catch {
842
+ context += `- ${file}
843
+ `;
844
+ }
845
+ }
846
+ } else if (stats.isDirectory()) {
847
+ const relParentDir = import_path2.default.relative(cwd, absPath) || ".";
848
+ if (relParentDir !== ".") {
849
+ const filesInDir = import_fs.default.readdirSync(absPath);
850
+ context += `
851
+ --- Directory files in "${relParentDir}": ---
852
+ `;
853
+ for (const file of filesInDir) {
854
+ try {
855
+ const fileStats = import_fs.default.statSync(import_path2.default.join(absPath, file));
856
+ const marker = fileStats.isDirectory() ? "/" : "";
857
+ context += `- ${file}${marker}
858
+ `;
859
+ } catch {
860
+ context += `- ${file}
861
+ `;
862
+ }
863
+ }
864
+ if (filesInDir.length <= 15) {
865
+ for (const file of filesInDir) {
866
+ const filePathFull = import_path2.default.join(absPath, file);
867
+ const fileExt = import_path2.default.extname(file).toLowerCase();
868
+ try {
869
+ if (import_fs.default.statSync(filePathFull).isFile() && [".js", ".jsx", ".ts", ".tsx", ".json", ".css"].includes(fileExt)) {
870
+ addFileToContext(filePathFull);
871
+ }
872
+ } catch {
873
+ }
874
+ }
875
+ }
876
+ }
877
+ }
878
+ } catch {
879
+ }
880
+ }
881
+ return context;
882
+ }
708
883
  function buildAnalysisPrompt(errorOutput, cwd) {
709
884
  const warningMarker = "\u26A0\uFE0F [BugZero System Warning]";
710
885
  let compilerLogs = errorOutput;
@@ -721,18 +896,19 @@ ${w}`).join("\n\n")}
721
896
 
722
897
  **CRITICAL RULE:** Do NOT suggest modifying or creating the files listed under "Previous Failed Attempts" if they failed with a "File not found" or "Search string not found" error. You must inspect the compiler error logs below to find the actual file that exists and contains the error.`;
723
898
  }
899
+ const contextSection = getContextFiles(compilerLogs, cwd);
724
900
  return `You are an expert software engineer specialising in fixing build, lint, and test failures.
725
901
 
726
902
  A project located at "${cwd}" failed to build. Here is the complete error output:
727
903
 
728
904
  \`\`\`
729
905
  ${compilerLogs}
730
- \`\`\`${historySection}
906
+ \`\`\`${historySection}${contextSection}
731
907
 
732
908
  Your task:
733
- 1. Identify the root cause.
734
- 2. Locate the exact file and code that needs to change.
735
- 3. Provide the minimal, precise fix.
909
+ 1. Root Cause: Identify the root cause of the build failure.
910
+ 2. Codebase Context: Read the provided file contents and directory listings under "\u{1F4C1} Codebase Context" to locate the correct files, imports, and file paths. Do not guess filenames or contents that are not in the context.
911
+ 3. Patch: Provide the minimal, precise fix.
736
912
 
737
913
  Reply with ONLY a valid JSON object in this exact shape \u2014 no markdown fences, no extra text:
738
914
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "bin": {
5
5
  "bugzero": "dist/index.js"
6
6
  },