bugzero 0.0.50 → 0.0.52

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 +94 -46
  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) {
@@ -1720,10 +1741,76 @@ var require_dist8 = __commonJS({
1720
1741
  }
1721
1742
  var import_analyzers = require_dist2();
1722
1743
  var import_agents = require_dist7();
1723
- var import_shared3 = require_dist4();
1744
+ var import_shared22 = require_dist4();
1724
1745
  var import_fs3 = __toESM2(require("fs"));
1725
1746
  var import_path3 = __toESM2(require("path"));
1726
1747
  var import_url = require("url");
1748
+ var import_prompts = require_dist5();
1749
+ var import_shared3 = require_dist4();
1750
+ var MAX_REPORT_LOG_CHARS = 2e4;
1751
+ function capReportLogs(logs, maxChars = MAX_REPORT_LOG_CHARS) {
1752
+ return (0, import_prompts.truncateLogs)(logs, maxChars);
1753
+ }
1754
+ function buildHuntDiagnosisPrompt(checks) {
1755
+ const sections = [
1756
+ { label: "BUILD FAILURE", check: checks.build },
1757
+ { label: "LINT FAILURE", check: checks.lint },
1758
+ { label: "TEST FAILURE", check: checks.test }
1759
+ ].filter((section) => !section.check.success);
1760
+ const share = Math.floor(MAX_REPORT_LOG_CHARS / Math.max(sections.length, 1));
1761
+ const logs = sections.map((section) => `[${section.label}]
1762
+ ${capReportLogs(section.check.output ?? "", share)}
1763
+
1764
+ `).join("");
1765
+ return `You are an expert software engineer assistant. Below is the error output from a project's build, lint, and test checks.
1766
+ Please analyze the errors and generate a professional, beautifully formatted Markdown report summarizing:
1767
+ 1. **Diagnosis:** Clear explanation of what failed and why.
1768
+ 2. **Root Cause:** The underlying issue in the code/config.
1769
+ 3. **Action Plan:** Step-by-step instructions on what files need to be modified and what exact changes to make.
1770
+
1771
+ Failed Checks Logs:
1772
+ ${logs}
1773
+
1774
+ Generate the Markdown report directly. Do not wrap it in markdown block fences (\`\`\`markdown ... \`\`\`). Just write the markdown text directly.`;
1775
+ }
1776
+ function formatPatchesForPrompt(appliedFix) {
1777
+ return appliedFix.patches.map(
1778
+ (p, i) => `File ${i + 1}: ${p.filePath}
1779
+ - Search code:
1780
+ ${p.search}
1781
+ - Replace code:
1782
+ ${p.replace}`
1783
+ ).join("\n\n");
1784
+ }
1785
+ function buildRescueSuccessPrompt(params) {
1786
+ const { cwd, attempts, appliedFix } = params;
1787
+ const patchedFiles = (0, import_shared3.uniqueFilePaths)(appliedFix.patches).join(", ");
1788
+ return `You are an expert software engineer assistant. An automated AI agent successfully resolved a build/lint/test failure in a project located at "${cwd}" after ${attempts} attempts by applying a patch to: ${patchedFiles}.
1789
+ Here is the patch details:
1790
+ - Root Cause: ${appliedFix.rootCause}
1791
+ - Explanation: ${appliedFix.explanation}
1792
+ ${formatPatchesForPrompt(appliedFix)}
1793
+
1794
+ Please generate a professional, beautifully formatted Markdown report summarizing:
1795
+ 1. **Repair Summary:** Celebrate the success and explain the fix.
1796
+ 2. **Details of the Solution:** Walk the developer through what was changed and why.
1797
+ 3. **Verification:** Explain how it was verified (build, lint, tests passed).
1798
+
1799
+ Generate the Markdown report directly. Do not wrap it in markdown block fences (\`\`\`markdown ... \`\`\`). Just write the markdown text directly.`;
1800
+ }
1801
+ function buildRescueFailurePrompt(params) {
1802
+ const { cwd, attempts, rawOutput } = params;
1803
+ return `You are an expert software engineer assistant. An automated AI agent tried to repair build/lint/test errors in a project located at "${cwd}", but could not resolve them after ${attempts} attempts.
1804
+ Below is the unresolved error logs.
1805
+ Please analyze these logs and generate a professional, beautifully formatted Markdown report summarizing:
1806
+ 1. **Analysis of Unresolved Errors:** Explain why the AI fixes might have failed or what is still unresolved.
1807
+ 2. **Manual Action Plan:** Provide detailed, step-by-step instructions for the developer on how to fix this manually.
1808
+
1809
+ Unresolved Error Logs:
1810
+ ${capReportLogs(rawOutput ?? "")}
1811
+
1812
+ Generate the Markdown report directly. Do not wrap it in markdown block fences (\`\`\`markdown ... \`\`\`). Just write the markdown text directly.`;
1813
+ }
1727
1814
  function buildDryRunPrompt(cwd, rawOutput) {
1728
1815
  return `You are an expert software engineer assistant. BugZero ran in dry-run mode on the project located at "${cwd}": it ran the project's build/lint/test checks and found failures, but it intentionally attempted NO fixes and modified NO files.
1729
1816
  Below is the error output.
@@ -1733,7 +1820,7 @@ Please analyze these logs and generate a professional, beautifully formatted Mar
1733
1820
  3. **Suggested Fix:** Step-by-step instructions on what files need to be modified and what exact changes to make.
1734
1821
 
1735
1822
  Error Logs:
1736
- ${rawOutput}
1823
+ ${capReportLogs(rawOutput)}
1737
1824
 
1738
1825
  Generate the Markdown report directly. Do not wrap it in markdown block fences (\`\`\`markdown ... \`\`\`). Just write the markdown text directly.`;
1739
1826
  }
@@ -1880,15 +1967,6 @@ Re-run without \`--dry-run\` to let BugZero attempt a fix.
1880
1967
  });
1881
1968
  return result;
1882
1969
  }
1883
- function formatPatchesForPrompt(appliedFix) {
1884
- return appliedFix.patches.map(
1885
- (p, i) => `File ${i + 1}: ${p.filePath}
1886
- - Search code:
1887
- ${p.search}
1888
- - Replace code:
1889
- ${p.replace}`
1890
- ).join("\n\n");
1891
- }
1892
1970
  function formatPatchesMarkdown(appliedFix) {
1893
1971
  return appliedFix.patches.map(
1894
1972
  (p) => `**File:** \`${p.filePath}\`
@@ -1924,16 +2002,7 @@ ${test.output}
1924
2002
 
1925
2003
  `;
1926
2004
  console.log("[BugZero] Calling AI to diagnose errors and write report...");
1927
- const prompt = `You are an expert software engineer assistant. Below is the error output from a project's build, lint, and test checks.
1928
- Please analyze the errors and generate a professional, beautifully formatted Markdown report summarizing:
1929
- 1. **Diagnosis:** Clear explanation of what failed and why.
1930
- 2. **Root Cause:** The underlying issue in the code/config.
1931
- 3. **Action Plan:** Step-by-step instructions on what files need to be modified and what exact changes to make.
1932
-
1933
- Failed Checks Logs:
1934
- ${logs}
1935
-
1936
- Generate the Markdown report directly. Do not wrap it in markdown block fences (\`\`\`markdown ... \`\`\`). Just write the markdown text directly.`;
2005
+ const prompt = buildHuntDiagnosisPrompt({ build, lint, test });
1937
2006
  try {
1938
2007
  const result = await provider.invoke(prompt, { cwd });
1939
2008
  content = result.content;
@@ -2007,19 +2076,7 @@ Your project already passes its build, lint, and tests, so BugZero made no chang
2007
2076
  }
2008
2077
  } else if (success && appliedFix) {
2009
2078
  console.log("[BugZero] Calling AI to write solution summary report...");
2010
- const patchedFiles = (0, import_shared3.uniqueFilePaths)(appliedFix.patches).join(", ");
2011
- const prompt = `You are an expert software engineer assistant. An automated AI agent successfully resolved a build/lint/test failure in a project located at "${cwd}" after ${attempts} attempts by applying a patch to: ${patchedFiles}.
2012
- Here is the patch details:
2013
- - Root Cause: ${appliedFix.rootCause}
2014
- - Explanation: ${appliedFix.explanation}
2015
- ${formatPatchesForPrompt(appliedFix)}
2016
-
2017
- Please generate a professional, beautifully formatted Markdown report summarizing:
2018
- 1. **Repair Summary:** Celebrate the success and explain the fix.
2019
- 2. **Details of the Solution:** Walk the developer through what was changed and why.
2020
- 3. **Verification:** Explain how it was verified (build, lint, tests passed).
2021
-
2022
- Generate the Markdown report directly. Do not wrap it in markdown block fences (\`\`\`markdown ... \`\`\`). Just write the markdown text directly.`;
2079
+ const prompt = buildRescueSuccessPrompt({ cwd, attempts, appliedFix });
2023
2080
  try {
2024
2081
  const result = await provider.invoke(prompt, { cwd });
2025
2082
  content = result.content;
@@ -2045,7 +2102,7 @@ Generate the Markdown report directly. Do not wrap it in markdown block fences (
2045
2102
  - **Token Usage:** ${promptTokens !== void 0 && completionTokens !== void 0 ? `Prompt: **${promptTokens}** | Completion: **${completionTokens}** | Total: **${promptTokens + completionTokens}**` : "*N/A*"}
2046
2103
 
2047
2104
  ## \u{1F6E0}\uFE0F Applied Solution
2048
- - **Target File(s):** ${(0, import_shared3.uniqueFilePaths)(appliedFix.patches).map((file) => `\`${file}\``).join(", ")}
2105
+ - **Target File(s):** ${(0, import_shared22.uniqueFilePaths)(appliedFix.patches).map((file) => `\`${file}\``).join(", ")}
2049
2106
  - **Root Cause:** ${appliedFix.rootCause}
2050
2107
  - **Explanation:** ${appliedFix.explanation}
2051
2108
 
@@ -2055,16 +2112,7 @@ ${formatPatchesMarkdown(appliedFix)}
2055
2112
  }
2056
2113
  } else {
2057
2114
  console.log("[BugZero] Calling AI to analyze unresolved errors and write report...");
2058
- const prompt = `You are an expert software engineer assistant. An automated AI agent tried to repair build/lint/test errors in a project located at "${cwd}", but could not resolve them after ${attempts} attempts.
2059
- Below is the unresolved error logs.
2060
- Please analyze these logs and generate a professional, beautifully formatted Markdown report summarizing:
2061
- 1. **Analysis of Unresolved Errors:** Explain why the AI fixes might have failed or what is still unresolved.
2062
- 2. **Manual Action Plan:** Provide detailed, step-by-step instructions for the developer on how to fix this manually.
2063
-
2064
- Unresolved Error Logs:
2065
- ${rawOutput}
2066
-
2067
- Generate the Markdown report directly. Do not wrap it in markdown block fences (\`\`\`markdown ... \`\`\`). Just write the markdown text directly.`;
2115
+ const prompt = buildRescueFailurePrompt({ cwd, attempts, rawOutput });
2068
2116
  try {
2069
2117
  const result = await provider.invoke(prompt, { cwd });
2070
2118
  content = result.content;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.50",
3
+ "version": "0.0.52",
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)",