bugzero 0.0.29 → 0.0.31

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.28 build D:\WD projects\OpsPilot\packages\cli
2
+ > bugzero@0.0.31 build /home/runner/work/Bugzero/Bugzero/apps/bugzero
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 70.42 KB
11
- CJS ⚡️ Build success in 68ms
10
+ CJS dist/index.js 74.91 KB
11
+ CJS ⚡️ Build success in 34ms
12
12
  DTS Build start
13
- DTS ⚡️ Build success in 1321ms
14
- DTS dist\index.d.ts 20.00 B
13
+ DTS ⚡️ Build success in 1100ms
14
+ DTS dist/index.d.ts 20.00 B
package/README.md CHANGED
@@ -74,6 +74,7 @@ bugzero rescue
74
74
  | Multi-model support | DeepSeek, Claude, GPT-4o, Gemini, Llama via OpenRouter |
75
75
  | Framework detection | Automatically identifies your project's tooling setup |
76
76
  | Safe file patching | Every modified file receives a `.opspilot.bak` backup |
77
+ | Fuzzy patch matching | Falls back from exact match to whitespace-normalized and similarity-scored matching when the AI's snippet doesn't match the file verbatim |
77
78
  | Error type parsing | Parses TypeScript, ESLint, and Jest error formats |
78
79
  | Dry-run mode | Analyze and report without writing any files |
79
80
  | Local model config | Save preferred model to `.bugzerorc` per project |
package/dist/index.js CHANGED
@@ -346,9 +346,9 @@ var require_main = __commonJS({
346
346
  }
347
347
  });
348
348
 
349
- // ../config/dist/index.js
349
+ // ../../packages/config/dist/index.js
350
350
  var require_dist = __commonJS({
351
- "../config/dist/index.js"(exports2, module2) {
351
+ "../../packages/config/dist/index.js"(exports2, module2) {
352
352
  "use strict";
353
353
  var __create2 = Object.create;
354
354
  var __defProp2 = Object.defineProperty;
@@ -433,9 +433,9 @@ var require_dist = __commonJS({
433
433
  }
434
434
  });
435
435
 
436
- // ../analyzers/dist/index.js
436
+ // ../../packages/analyzers/dist/index.js
437
437
  var require_dist2 = __commonJS({
438
- "../analyzers/dist/index.js"(exports2, module2) {
438
+ "../../packages/analyzers/dist/index.js"(exports2, module2) {
439
439
  "use strict";
440
440
  var __create2 = Object.create;
441
441
  var __defProp2 = Object.defineProperty;
@@ -586,9 +586,9 @@ var require_dist2 = __commonJS({
586
586
  }
587
587
  });
588
588
 
589
- // ../ai-provider/dist/index.js
589
+ // ../../packages/ai-provider/dist/index.js
590
590
  var require_dist3 = __commonJS({
591
- "../ai-provider/dist/index.js"(exports2, module2) {
591
+ "../../packages/ai-provider/dist/index.js"(exports2, module2) {
592
592
  "use strict";
593
593
  var __create2 = Object.create;
594
594
  var __defProp2 = Object.defineProperty;
@@ -709,9 +709,9 @@ var require_dist3 = __commonJS({
709
709
  }
710
710
  });
711
711
 
712
- // ../prompts/dist/index.js
712
+ // ../../packages/prompts/dist/index.js
713
713
  var require_dist4 = __commonJS({
714
- "../prompts/dist/index.js"(exports2, module2) {
714
+ "../../packages/prompts/dist/index.js"(exports2, module2) {
715
715
  "use strict";
716
716
  var __create2 = Object.create;
717
717
  var __defProp2 = Object.defineProperty;
@@ -928,9 +928,9 @@ Critical rules:
928
928
  }
929
929
  });
930
930
 
931
- // ../patcher/dist/index.js
931
+ // ../../packages/patcher/dist/index.js
932
932
  var require_dist5 = __commonJS({
933
- "../patcher/dist/index.js"(exports2, module2) {
933
+ "../../packages/patcher/dist/index.js"(exports2, module2) {
934
934
  "use strict";
935
935
  var __create2 = Object.create;
936
936
  var __defProp2 = Object.defineProperty;
@@ -961,11 +961,112 @@ var require_dist5 = __commonJS({
961
961
  var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
962
962
  var index_exports = {};
963
963
  __export(index_exports, {
964
- applyPatch: () => applyPatch
964
+ applyPatch: () => applyPatch,
965
+ findMatch: () => findMatch,
966
+ lineSimilarity: () => lineSimilarity
965
967
  });
966
968
  module2.exports = __toCommonJS(index_exports);
967
969
  var import_fs = __toESM2(require("fs"));
968
970
  var import_path2 = __toESM2(require("path"));
971
+ var SIMILARITY_THRESHOLD = 0.85;
972
+ var AMBIGUITY_MARGIN = 0.05;
973
+ var MAX_LINES_FOR_SIMILARITY_PASS = 2e4;
974
+ function splitLinesWithOffsets(text) {
975
+ const lines = [];
976
+ let start = 0;
977
+ for (let i = 0; i < text.length; i++) {
978
+ if (text[i] === "\n") {
979
+ let end = i;
980
+ if (end > start && text[end - 1] === "\r") end -= 1;
981
+ lines.push({ text: text.slice(start, end), start, end });
982
+ start = i + 1;
983
+ }
984
+ }
985
+ lines.push({ text: text.slice(start), start, end: text.length });
986
+ return lines;
987
+ }
988
+ function normalizeLine(line) {
989
+ return line.trim().replace(/\s+/g, " ");
990
+ }
991
+ function levenshtein(a, b) {
992
+ const m = a.length;
993
+ const n = b.length;
994
+ if (m === 0) return n;
995
+ if (n === 0) return m;
996
+ const dp = new Array(n + 1);
997
+ for (let j = 0; j <= n; j++) dp[j] = j;
998
+ for (let i = 1; i <= m; i++) {
999
+ let prev = dp[0];
1000
+ dp[0] = i;
1001
+ for (let j = 1; j <= n; j++) {
1002
+ const temp = dp[j];
1003
+ dp[j] = a[i - 1] === b[j - 1] ? prev : 1 + Math.min(prev, dp[j], dp[j - 1]);
1004
+ prev = temp;
1005
+ }
1006
+ }
1007
+ return dp[n];
1008
+ }
1009
+ function lineSimilarity(a, b) {
1010
+ const maxLen = Math.max(a.length, b.length);
1011
+ if (maxLen === 0) return 1;
1012
+ return 1 - levenshtein(a, b) / maxLen;
1013
+ }
1014
+ function findWhitespaceNormalizedMatch(content, search) {
1015
+ const searchLines = search.split(/\r\n|\n/).map(normalizeLine);
1016
+ const contentLines = splitLinesWithOffsets(content);
1017
+ if (searchLines.length === 0 || searchLines.length > contentLines.length) return null;
1018
+ const normalizedContentLines = contentLines.map((l) => normalizeLine(l.text));
1019
+ for (let i = 0; i + searchLines.length <= contentLines.length; i++) {
1020
+ let matches = true;
1021
+ for (let j = 0; j < searchLines.length; j++) {
1022
+ if (normalizedContentLines[i + j] !== searchLines[j]) {
1023
+ matches = false;
1024
+ break;
1025
+ }
1026
+ }
1027
+ if (matches) {
1028
+ const firstLine = contentLines[i];
1029
+ const lastLine = contentLines[i + searchLines.length - 1];
1030
+ return { start: firstLine.start, end: lastLine.end, strategy: "whitespace", score: 1 };
1031
+ }
1032
+ }
1033
+ return null;
1034
+ }
1035
+ function findSimilarityMatch(content, search) {
1036
+ const searchLines = search.split(/\r\n|\n/);
1037
+ const contentLines = splitLinesWithOffsets(content);
1038
+ if (searchLines.length === 0 || searchLines.length > contentLines.length) return null;
1039
+ if (contentLines.length > MAX_LINES_FOR_SIMILARITY_PASS) return null;
1040
+ let bestIndex = -1;
1041
+ let bestScore = -1;
1042
+ let secondBestScore = -1;
1043
+ for (let i = 0; i + searchLines.length <= contentLines.length; i++) {
1044
+ let total = 0;
1045
+ for (let j = 0; j < searchLines.length; j++) {
1046
+ total += lineSimilarity(searchLines[j], contentLines[i + j].text);
1047
+ }
1048
+ const avgScore = total / searchLines.length;
1049
+ if (avgScore > bestScore) {
1050
+ secondBestScore = bestScore;
1051
+ bestScore = avgScore;
1052
+ bestIndex = i;
1053
+ } else if (avgScore > secondBestScore) {
1054
+ secondBestScore = avgScore;
1055
+ }
1056
+ }
1057
+ if (bestIndex === -1 || bestScore < SIMILARITY_THRESHOLD) return null;
1058
+ if (secondBestScore >= 0 && bestScore - secondBestScore < AMBIGUITY_MARGIN) return null;
1059
+ const firstLine = contentLines[bestIndex];
1060
+ const lastLine = contentLines[bestIndex + searchLines.length - 1];
1061
+ return { start: firstLine.start, end: lastLine.end, strategy: "similarity", score: bestScore };
1062
+ }
1063
+ function findMatch(content, search) {
1064
+ const exactIndex = content.indexOf(search);
1065
+ if (exactIndex !== -1) {
1066
+ return { start: exactIndex, end: exactIndex + search.length, strategy: "exact", score: 1 };
1067
+ }
1068
+ return findWhitespaceNormalizedMatch(content, search) ?? findSimilarityMatch(content, search);
1069
+ }
969
1070
  function applyPatch(absoluteFilePath, search, replace) {
970
1071
  try {
971
1072
  if (!import_fs.default.existsSync(absoluteFilePath)) {
@@ -975,17 +1076,18 @@ var require_dist5 = __commonJS({
975
1076
  };
976
1077
  }
977
1078
  const original = import_fs.default.readFileSync(absoluteFilePath, "utf-8");
978
- if (!original.includes(search)) {
1079
+ const match = findMatch(original, search);
1080
+ if (!match) {
979
1081
  return {
980
1082
  success: false,
981
- error: `Search string not found in ${import_path2.default.basename(absoluteFilePath)}. The AI's "search" field did not match file content.`
1083
+ error: `Search string not found in ${import_path2.default.basename(absoluteFilePath)} (tried exact, whitespace-normalized, and fuzzy matching). The AI's "search" field did not match file content.`
982
1084
  };
983
1085
  }
984
1086
  const backupPath = absoluteFilePath + ".opspilot.bak";
985
1087
  import_fs.default.writeFileSync(backupPath, original, "utf-8");
986
- const fixed = original.replace(search, replace);
1088
+ const fixed = original.slice(0, match.start) + replace + original.slice(match.end);
987
1089
  import_fs.default.writeFileSync(absoluteFilePath, fixed, "utf-8");
988
- return { success: true, backupPath };
1090
+ return { success: true, backupPath, matchStrategy: match.strategy };
989
1091
  } catch (err) {
990
1092
  return { success: false, error: err.message };
991
1093
  }
@@ -993,9 +1095,9 @@ var require_dist5 = __commonJS({
993
1095
  }
994
1096
  });
995
1097
 
996
- // ../agents/dist/index.js
1098
+ // ../../packages/agents/dist/index.js
997
1099
  var require_dist6 = __commonJS({
998
- "../agents/dist/index.js"(exports2, module2) {
1100
+ "../../packages/agents/dist/index.js"(exports2, module2) {
999
1101
  "use strict";
1000
1102
  var __create2 = Object.create;
1001
1103
  var __defProp2 = Object.defineProperty;
@@ -1141,6 +1243,9 @@ Please check if the file path is correct relative to the project root and make s
1141
1243
  };
1142
1244
  } else {
1143
1245
  console.log(`[BugZero] Backup saved to: ${result.backupPath}`);
1246
+ if (result.matchStrategy && result.matchStrategy !== "exact") {
1247
+ console.log(`[BugZero] Note: exact match failed \u2014 patch applied via ${result.matchStrategy} matching.`);
1248
+ }
1144
1249
  }
1145
1250
  return {};
1146
1251
  }
@@ -1178,9 +1283,9 @@ Please check if the file path is correct relative to the project root and make s
1178
1283
  }
1179
1284
  });
1180
1285
 
1181
- // ../core/dist/index.js
1286
+ // ../../packages/core/dist/index.js
1182
1287
  var require_dist7 = __commonJS({
1183
- "../core/dist/index.js"(exports2, module2) {
1288
+ "../../packages/core/dist/index.js"(exports2, module2) {
1184
1289
  "use strict";
1185
1290
  var __create2 = Object.create;
1186
1291
  var __defProp2 = Object.defineProperty;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "description": "An autonomous, AI-powered CLI tool for automatic build error detection and repair.",
5
5
  "license": "MIT",
6
6
  "bin": {
package/tsconfig.json CHANGED
@@ -1,8 +1,8 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "src"
6
- },
7
- "include": ["src"]
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src"
6
+ },
7
+ "include": ["src"]
8
8
  }
@@ -1,426 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined") return require.apply(this, arguments);
11
- throw Error('Dynamic require of "' + x + '" is not supported');
12
- });
13
- var __commonJS = (cb, mod) => function __require2() {
14
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
32
-
33
- // ../../node_modules/.pnpm/dotenv@17.4.2/node_modules/dotenv/lib/main.js
34
- var require_main = __commonJS({
35
- "../../node_modules/.pnpm/dotenv@17.4.2/node_modules/dotenv/lib/main.js"(exports, module) {
36
- "use strict";
37
- var fs = __require("fs");
38
- var path = __require("path");
39
- var os = __require("os");
40
- var crypto = __require("crypto");
41
- var TIPS = [
42
- "\u25C8 encrypted .env [www.dotenvx.com]",
43
- "\u25C8 secrets for agents [www.dotenvx.com]",
44
- "\u2301 auth for agents [www.vestauth.com]",
45
- "\u2318 custom filepath { path: '/custom/path/.env' }",
46
- "\u2318 enable debugging { debug: true }",
47
- "\u2318 override existing { override: true }",
48
- "\u2318 suppress logs { quiet: true }",
49
- "\u2318 multiple files { path: ['.env.local', '.env'] }"
50
- ];
51
- function _getRandomTip() {
52
- return TIPS[Math.floor(Math.random() * TIPS.length)];
53
- }
54
- function parseBoolean(value) {
55
- if (typeof value === "string") {
56
- return !["false", "0", "no", "off", ""].includes(value.toLowerCase());
57
- }
58
- return Boolean(value);
59
- }
60
- function supportsAnsi() {
61
- return process.stdout.isTTY;
62
- }
63
- function dim(text) {
64
- return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
65
- }
66
- var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
67
- function parse(src) {
68
- const obj = {};
69
- let lines = src.toString();
70
- lines = lines.replace(/\r\n?/mg, "\n");
71
- let match;
72
- while ((match = LINE.exec(lines)) != null) {
73
- const key = match[1];
74
- let value = match[2] || "";
75
- value = value.trim();
76
- const maybeQuote = value[0];
77
- value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
78
- if (maybeQuote === '"') {
79
- value = value.replace(/\\n/g, "\n");
80
- value = value.replace(/\\r/g, "\r");
81
- }
82
- obj[key] = value;
83
- }
84
- return obj;
85
- }
86
- function _parseVault(options) {
87
- options = options || {};
88
- const vaultPath = _vaultPath(options);
89
- options.path = vaultPath;
90
- const result = DotenvModule.configDotenv(options);
91
- if (!result.parsed) {
92
- const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
93
- err.code = "MISSING_DATA";
94
- throw err;
95
- }
96
- const keys = _dotenvKey(options).split(",");
97
- const length = keys.length;
98
- let decrypted;
99
- for (let i = 0; i < length; i++) {
100
- try {
101
- const key = keys[i].trim();
102
- const attrs = _instructions(result, key);
103
- decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
104
- break;
105
- } catch (error) {
106
- if (i + 1 >= length) {
107
- throw error;
108
- }
109
- }
110
- }
111
- return DotenvModule.parse(decrypted);
112
- }
113
- function _warn(message) {
114
- console.error(`\u26A0 ${message}`);
115
- }
116
- function _debug(message) {
117
- console.log(`\u2506 ${message}`);
118
- }
119
- function _log(message) {
120
- console.log(`\u25C7 ${message}`);
121
- }
122
- function _dotenvKey(options) {
123
- if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
124
- return options.DOTENV_KEY;
125
- }
126
- if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
127
- return process.env.DOTENV_KEY;
128
- }
129
- return "";
130
- }
131
- function _instructions(result, dotenvKey) {
132
- let uri;
133
- try {
134
- uri = new URL(dotenvKey);
135
- } catch (error) {
136
- if (error.code === "ERR_INVALID_URL") {
137
- const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
138
- err.code = "INVALID_DOTENV_KEY";
139
- throw err;
140
- }
141
- throw error;
142
- }
143
- const key = uri.password;
144
- if (!key) {
145
- const err = new Error("INVALID_DOTENV_KEY: Missing key part");
146
- err.code = "INVALID_DOTENV_KEY";
147
- throw err;
148
- }
149
- const environment = uri.searchParams.get("environment");
150
- if (!environment) {
151
- const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
152
- err.code = "INVALID_DOTENV_KEY";
153
- throw err;
154
- }
155
- const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
156
- const ciphertext = result.parsed[environmentKey];
157
- if (!ciphertext) {
158
- const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
159
- err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
160
- throw err;
161
- }
162
- return { ciphertext, key };
163
- }
164
- function _vaultPath(options) {
165
- let possibleVaultPath = null;
166
- if (options && options.path && options.path.length > 0) {
167
- if (Array.isArray(options.path)) {
168
- for (const filepath of options.path) {
169
- if (fs.existsSync(filepath)) {
170
- possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
171
- }
172
- }
173
- } else {
174
- possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
175
- }
176
- } else {
177
- possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
178
- }
179
- if (fs.existsSync(possibleVaultPath)) {
180
- return possibleVaultPath;
181
- }
182
- return null;
183
- }
184
- function _resolveHome(envPath) {
185
- return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
186
- }
187
- function _configVault(options) {
188
- const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
189
- const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
190
- if (debug || !quiet) {
191
- _log("loading env from encrypted .env.vault");
192
- }
193
- const parsed = DotenvModule._parseVault(options);
194
- let processEnv = process.env;
195
- if (options && options.processEnv != null) {
196
- processEnv = options.processEnv;
197
- }
198
- DotenvModule.populate(processEnv, parsed, options);
199
- return { parsed };
200
- }
201
- function configDotenv(options) {
202
- const dotenvPath = path.resolve(process.cwd(), ".env");
203
- let encoding = "utf8";
204
- let processEnv = process.env;
205
- if (options && options.processEnv != null) {
206
- processEnv = options.processEnv;
207
- }
208
- let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
209
- let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
210
- if (options && options.encoding) {
211
- encoding = options.encoding;
212
- } else {
213
- if (debug) {
214
- _debug("no encoding is specified (UTF-8 is used by default)");
215
- }
216
- }
217
- let optionPaths = [dotenvPath];
218
- if (options && options.path) {
219
- if (!Array.isArray(options.path)) {
220
- optionPaths = [_resolveHome(options.path)];
221
- } else {
222
- optionPaths = [];
223
- for (const filepath of options.path) {
224
- optionPaths.push(_resolveHome(filepath));
225
- }
226
- }
227
- }
228
- let lastError;
229
- const parsedAll = {};
230
- for (const path2 of optionPaths) {
231
- try {
232
- const parsed = DotenvModule.parse(fs.readFileSync(path2, { encoding }));
233
- DotenvModule.populate(parsedAll, parsed, options);
234
- } catch (e) {
235
- if (debug) {
236
- _debug(`failed to load ${path2} ${e.message}`);
237
- }
238
- lastError = e;
239
- }
240
- }
241
- const populated = DotenvModule.populate(processEnv, parsedAll, options);
242
- debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
243
- quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
244
- if (debug || !quiet) {
245
- const keysCount = Object.keys(populated).length;
246
- const shortPaths = [];
247
- for (const filePath of optionPaths) {
248
- try {
249
- const relative = path.relative(process.cwd(), filePath);
250
- shortPaths.push(relative);
251
- } catch (e) {
252
- if (debug) {
253
- _debug(`failed to load ${filePath} ${e.message}`);
254
- }
255
- lastError = e;
256
- }
257
- }
258
- _log(`injected env (${keysCount}) from ${shortPaths.join(",")} ${dim(`// tip: ${_getRandomTip()}`)}`);
259
- }
260
- if (lastError) {
261
- return { parsed: parsedAll, error: lastError };
262
- } else {
263
- return { parsed: parsedAll };
264
- }
265
- }
266
- function config(options) {
267
- if (_dotenvKey(options).length === 0) {
268
- return DotenvModule.configDotenv(options);
269
- }
270
- const vaultPath = _vaultPath(options);
271
- if (!vaultPath) {
272
- _warn(`you set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}`);
273
- return DotenvModule.configDotenv(options);
274
- }
275
- return DotenvModule._configVault(options);
276
- }
277
- function decrypt(encrypted, keyStr) {
278
- const key = Buffer.from(keyStr.slice(-64), "hex");
279
- let ciphertext = Buffer.from(encrypted, "base64");
280
- const nonce = ciphertext.subarray(0, 12);
281
- const authTag = ciphertext.subarray(-16);
282
- ciphertext = ciphertext.subarray(12, -16);
283
- try {
284
- const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
285
- aesgcm.setAuthTag(authTag);
286
- return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
287
- } catch (error) {
288
- const isRange = error instanceof RangeError;
289
- const invalidKeyLength = error.message === "Invalid key length";
290
- const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
291
- if (isRange || invalidKeyLength) {
292
- const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
293
- err.code = "INVALID_DOTENV_KEY";
294
- throw err;
295
- } else if (decryptionFailed) {
296
- const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
297
- err.code = "DECRYPTION_FAILED";
298
- throw err;
299
- } else {
300
- throw error;
301
- }
302
- }
303
- }
304
- function populate(processEnv, parsed, options = {}) {
305
- const debug = Boolean(options && options.debug);
306
- const override = Boolean(options && options.override);
307
- const populated = {};
308
- if (typeof parsed !== "object") {
309
- const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
310
- err.code = "OBJECT_REQUIRED";
311
- throw err;
312
- }
313
- for (const key of Object.keys(parsed)) {
314
- if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
315
- if (override === true) {
316
- processEnv[key] = parsed[key];
317
- populated[key] = parsed[key];
318
- }
319
- if (debug) {
320
- if (override === true) {
321
- _debug(`"${key}" is already defined and WAS overwritten`);
322
- } else {
323
- _debug(`"${key}" is already defined and was NOT overwritten`);
324
- }
325
- }
326
- } else {
327
- processEnv[key] = parsed[key];
328
- populated[key] = parsed[key];
329
- }
330
- }
331
- return populated;
332
- }
333
- var DotenvModule = {
334
- configDotenv,
335
- _configVault,
336
- _parseVault,
337
- config,
338
- decrypt,
339
- parse,
340
- populate
341
- };
342
- module.exports.configDotenv = DotenvModule.configDotenv;
343
- module.exports._configVault = DotenvModule._configVault;
344
- module.exports._parseVault = DotenvModule._parseVault;
345
- module.exports.config = DotenvModule.config;
346
- module.exports.decrypt = DotenvModule.decrypt;
347
- module.exports.parse = DotenvModule.parse;
348
- module.exports.populate = DotenvModule.populate;
349
- module.exports = DotenvModule;
350
- }
351
- });
352
-
353
- // ../config/dist/index.js
354
- var require_dist = __commonJS({
355
- "../config/dist/index.js"(exports, module) {
356
- var __create2 = Object.create;
357
- var __defProp2 = Object.defineProperty;
358
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
359
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
360
- var __getProtoOf2 = Object.getPrototypeOf;
361
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
362
- var __export = (target, all) => {
363
- for (var name in all)
364
- __defProp2(target, name, { get: all[name], enumerable: true });
365
- };
366
- var __copyProps2 = (to, from, except, desc) => {
367
- if (from && typeof from === "object" || typeof from === "function") {
368
- for (let key of __getOwnPropNames2(from))
369
- if (!__hasOwnProp2.call(to, key) && key !== except)
370
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
371
- }
372
- return to;
373
- };
374
- var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
375
- // If the importer is in node compatibility mode or this is not an ESM
376
- // file that has been converted to a CommonJS file using a Babel-
377
- // compatible transform (i.e. "__esModule" has not been set), then set
378
- // "default" to the CommonJS "module.exports" for node compatibility.
379
- isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
380
- mod
381
- ));
382
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
383
- var index_exports = {};
384
- __export(index_exports, {
385
- env: () => env,
386
- getLocalConfig: () => getLocalConfig,
387
- getSelectedModel: () => getSelectedModel,
388
- saveLocalConfig: () => saveLocalConfig
389
- });
390
- module.exports = __toCommonJS(index_exports);
391
- var import_dotenv = __toESM2(require_main());
392
- import_dotenv.default.config();
393
- var env = {
394
- openRouterKey: process.env.OPENROUTER_API_KEY
395
- };
396
- var import_fs = __toESM2(__require("fs"));
397
- var import_path = __toESM2(__require("path"));
398
- var CONFIG_FILENAME = ".bugzerorc";
399
- function getLocalConfig(cwd = process.cwd()) {
400
- try {
401
- const configPath = import_path.default.resolve(cwd, CONFIG_FILENAME);
402
- if (import_fs.default.existsSync(configPath)) {
403
- const content = import_fs.default.readFileSync(configPath, "utf-8");
404
- return JSON.parse(content);
405
- }
406
- } catch (e) {
407
- }
408
- return {};
409
- }
410
- function saveLocalConfig(config, cwd = process.cwd()) {
411
- const configPath = import_path.default.resolve(cwd, CONFIG_FILENAME);
412
- import_fs.default.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
413
- }
414
- function getSelectedModel(cwd = process.cwd()) {
415
- const config = getLocalConfig(cwd);
416
- return config.model || "deepseek/deepseek-chat";
417
- }
418
- }
419
- });
420
-
421
- export {
422
- __require,
423
- __commonJS,
424
- __toESM,
425
- require_dist
426
- };
@@ -1,4 +0,0 @@
1
- import {
2
- require_dist
3
- } from "./chunk-4ANZDGVD.js";
4
- export default require_dist();
package/dist/index.d.mts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/index.mjs DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/index.ts
4
- import { Command } from "commander";
5
- import { orchestrate } from "@opspilot/core";
6
- var program = new Command();
7
- program.command("protect").action(async () => {
8
- const result = await orchestrate();
9
- console.log(result);
10
- });
11
- program.parse();