bugzero 0.0.50 → 0.0.51

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 (2) hide show
  1. package/dist/index.js +22 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1313,6 +1313,26 @@ var require_dist6 = __commonJS({
1313
1313
  }
1314
1314
  return findWhitespaceNormalizedMatch(content, search) ?? findSimilarityMatch(content, search);
1315
1315
  }
1316
+ var CRLF = "\r\n";
1317
+ var LF = "\n";
1318
+ function countEndings(text) {
1319
+ const crlf = text.split(CRLF).length - 1;
1320
+ const lf = text.split(LF).length - 1 - crlf;
1321
+ return { crlf, lf };
1322
+ }
1323
+ function detectLineEnding(text, start, end) {
1324
+ const inside = countEndings(text.slice(start, end));
1325
+ if (inside.crlf !== inside.lf) return inside.crlf > inside.lf ? CRLF : LF;
1326
+ const nextBreak = text.indexOf(LF, end);
1327
+ if (nextBreak !== -1) return text[nextBreak - 1] === "\r" ? CRLF : LF;
1328
+ const previousBreak = start > 0 ? text.lastIndexOf(LF, start - 1) : -1;
1329
+ if (previousBreak !== -1) return text[previousBreak - 1] === "\r" ? CRLF : LF;
1330
+ const whole = countEndings(text);
1331
+ return whole.crlf > whole.lf ? CRLF : LF;
1332
+ }
1333
+ function withLineEnding(text, ending) {
1334
+ return text.replace(/\r\n|\n/g, ending);
1335
+ }
1316
1336
  function applyPatch(absoluteFilePath, search, replace, options = {}) {
1317
1337
  try {
1318
1338
  if (!import_fs2.default.existsSync(absoluteFilePath)) {
@@ -1333,7 +1353,8 @@ var require_dist6 = __commonJS({
1333
1353
  if (options.backup !== false) {
1334
1354
  import_fs2.default.writeFileSync(backupPath, original, "utf-8");
1335
1355
  }
1336
- const fixed = original.slice(0, match.start) + replace + original.slice(match.end);
1356
+ const replacement = withLineEnding(replace, detectLineEnding(original, match.start, match.end));
1357
+ const fixed = original.slice(0, match.start) + replacement + original.slice(match.end);
1337
1358
  import_fs2.default.writeFileSync(absoluteFilePath, fixed, "utf-8");
1338
1359
  return { success: true, backupPath, matchStrategy: match.strategy };
1339
1360
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.50",
3
+ "version": "0.0.51",
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)",