bugzero 0.0.12 → 0.0.16

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.12 build D:\WD projects\OpsPilot\packages\cli
2
+ > bugzero@0.0.16 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 49.97 KB
11
- CJS ⚡️ Build success in 105ms
10
+ CJS dist\index.js 56.82 KB
11
+ CJS ⚡️ Build success in 170ms
12
12
  DTS Build start
13
- DTS ⚡️ Build success in 1226ms
13
+ DTS ⚡️ Build success in 1192ms
14
14
  DTS dist\index.d.ts 20.00 B
package/README.md CHANGED
@@ -77,6 +77,7 @@ bugzero rescue
77
77
  | Error type parsing | Parses TypeScript, ESLint, and Jest error formats |
78
78
  | Dry-run mode | Analyze and report without writing any files |
79
79
  | Local model config | Save preferred model to `.bugzerorc` per project |
80
+ | Markdown Reports | Automatically generates a detailed `bugzero-report.md` listing error logs, model name, token usage, and search/replace code diffs |
80
81
 
81
82
  ---
82
83
 
@@ -165,6 +166,17 @@ This file is created automatically when you run `bugzero vibe`.
165
166
 
166
167
  ---
167
168
 
169
+ ## Reports
170
+
171
+ Every time you run `bugzero hunt` or `bugzero rescue`, a detailed Markdown report is automatically generated at `bugzero-report.md` in the target project directory. This report includes:
172
+ - **Pipeline Summary:** Clear status checklist of your project's Build, Lint, and Test suites.
173
+ - **Detailed Error Outputs:** Full error logs from any failing checks.
174
+ - **AI Brain Details:** The exact OpenRouter model used.
175
+ - **Token Usage:** Accumulated prompt and completion tokens used for the run.
176
+ - **Applied Fixes (for rescue):** The root cause, explanation, and before/after search-replace code diffs of any patches applied.
177
+
178
+ ---
179
+
168
180
  ## Development Setup
169
181
 
170
182
  Clone the repository and install dependencies. This project uses a pnpm monorepo managed by Turborepo.
package/dist/index.js CHANGED
@@ -643,7 +643,11 @@ var require_dist3 = __commonJS({
643
643
  if (response.data?.error) {
644
644
  throw new Error(response.data.error.message || JSON.stringify(response.data.error));
645
645
  }
646
- return response.data.choices[0].message.content;
646
+ return {
647
+ content: response.data.choices[0].message.content,
648
+ model,
649
+ usage: response.data.usage
650
+ };
647
651
  } catch (error) {
648
652
  let msg = error.message;
649
653
  if (error.response?.data?.error?.message) {
@@ -692,13 +696,28 @@ var require_dist4 = __commonJS({
692
696
  });
693
697
  module2.exports = __toCommonJS(index_exports);
694
698
  function buildAnalysisPrompt(errorOutput, cwd) {
699
+ const warningMarker = "\u26A0\uFE0F [BugZero System Warning]";
700
+ let compilerLogs = errorOutput;
701
+ let historySection = "";
702
+ if (errorOutput.includes(warningMarker)) {
703
+ const parts = errorOutput.split(warningMarker);
704
+ compilerLogs = parts[0].trim();
705
+ const warnings = parts.slice(1).map((w) => w.trim());
706
+ historySection = `
707
+
708
+ ### \u26A0\uFE0F Previous Failed Attempts:
709
+ ${warnings.map((w, idx) => `Failed Attempt ${idx + 1}:
710
+ ${w}`).join("\n\n")}
711
+
712
+ **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.`;
713
+ }
695
714
  return `You are an expert software engineer specialising in fixing build, lint, and test failures.
696
715
 
697
716
  A project located at "${cwd}" failed to build. Here is the complete error output:
698
717
 
699
718
  \`\`\`
700
- ${errorOutput}
701
- \`\`\`
719
+ ${compilerLogs}
720
+ \`\`\`${historySection}
702
721
 
703
722
  Your task:
704
723
  1. Identify the root cause.
@@ -862,6 +881,21 @@ var require_dist6 = __commonJS({
862
881
  success: (0, import_langgraph.Annotation)({
863
882
  reducer: (_, value) => value,
864
883
  default: () => false
884
+ }),
885
+ /** Model used for the repair */
886
+ modelUsed: (0, import_langgraph.Annotation)({
887
+ reducer: (_, value) => value,
888
+ default: () => ""
889
+ }),
890
+ /** Total prompt tokens used */
891
+ promptTokens: (0, import_langgraph.Annotation)({
892
+ reducer: (old, value) => old + value,
893
+ default: () => 0
894
+ }),
895
+ /** Total completion tokens used */
896
+ completionTokens: (0, import_langgraph.Annotation)({
897
+ reducer: (old, value) => old + value,
898
+ default: () => 0
865
899
  })
866
900
  });
867
901
  var import_ai_provider = require_dist3();
@@ -875,7 +909,8 @@ var require_dist6 = __commonJS({
875
909
  [BugZero] Attempt ${state.attempts + 1}/${state.maxAttempts} \u2014 asking AI\u2026`
876
910
  );
877
911
  const prompt = (0, import_prompts.buildAnalysisPrompt)(state.logs, state.cwd);
878
- const response = await provider.invoke(prompt, { cwd: state.cwd });
912
+ const result = await provider.invoke(prompt, { cwd: state.cwd });
913
+ const response = result.content;
879
914
  let fixSuggestion = null;
880
915
  try {
881
916
  const cleaned = response.replace(/```json\n?/g, "").replace(/```\n?/g, "").trim();
@@ -891,7 +926,10 @@ var require_dist6 = __commonJS({
891
926
  return {
892
927
  analysis: response,
893
928
  fixSuggestion,
894
- attempts: state.attempts + 1
929
+ attempts: state.attempts + 1,
930
+ modelUsed: result.model,
931
+ promptTokens: result.usage?.prompt_tokens ?? 0,
932
+ completionTokens: result.usage?.completion_tokens ?? 0
895
933
  };
896
934
  }
897
935
  async function applyFixNode(state) {
@@ -1021,6 +1059,8 @@ var require_dist7 = __commonJS({
1021
1059
  }
1022
1060
  var import_analyzers = require_dist2();
1023
1061
  var import_agents = require_dist6();
1062
+ var import_fs2 = __toESM2(require("fs"));
1063
+ var import_path22 = __toESM2(require("path"));
1024
1064
  async function orchestrate2(options = {}) {
1025
1065
  const cwd = options.cwd ?? process.cwd();
1026
1066
  const [build, lint, test] = await Promise.all([
@@ -1028,6 +1068,12 @@ var require_dist7 = __commonJS({
1028
1068
  (0, import_analyzers.runLint)(cwd),
1029
1069
  (0, import_analyzers.runTests)(cwd)
1030
1070
  ]);
1071
+ writeReport(cwd, "hunt", {
1072
+ success: build.success && lint.success && test.success,
1073
+ build,
1074
+ lint,
1075
+ test
1076
+ });
1031
1077
  return { build, lint, test };
1032
1078
  }
1033
1079
  async function orchestrateAndFix2(options = {}) {
@@ -1037,12 +1083,25 @@ var require_dist7 = __commonJS({
1037
1083
  const pipelineResult = await (0, import_analyzers.runValidationPipeline)(cwd);
1038
1084
  if (pipelineResult.success) {
1039
1085
  console.log("[BugZero] Validation already passing \u2014 nothing to fix.");
1086
+ writeReport(cwd, "rescue", {
1087
+ success: true,
1088
+ attempts: 0,
1089
+ maxAttempts,
1090
+ rawOutput: ""
1091
+ });
1040
1092
  return { success: true, attempts: 0, finalOutput: "" };
1041
1093
  }
1042
1094
  const errors = (0, import_analyzers.parseErrors)(pipelineResult.output);
1043
1095
  console.log(`[BugZero] Detected ${errors.length} error(s) (type: ${errors[0]?.type ?? "unknown"})`);
1044
1096
  if (options.dryRun) {
1045
1097
  console.log("[BugZero] Dry-run mode \u2014 skipping AI fix.");
1098
+ writeReport(cwd, "rescue", {
1099
+ success: false,
1100
+ attempts: 0,
1101
+ maxAttempts,
1102
+ error: "Dry-run: analysis complete, no files modified.",
1103
+ rawOutput: pipelineResult.output
1104
+ });
1046
1105
  return {
1047
1106
  success: false,
1048
1107
  attempts: 0,
@@ -1057,13 +1116,128 @@ var require_dist7 = __commonJS({
1057
1116
  attempts: 0,
1058
1117
  success: false
1059
1118
  });
1060
- return {
1119
+ const result = {
1061
1120
  success: finalState.success,
1062
1121
  attempts: finalState.attempts,
1063
1122
  finalOutput: finalState.logs || pipelineResult.output,
1064
1123
  appliedFix: finalState.fixSuggestion ?? void 0,
1065
- error: finalState.success ? void 0 : `Max attempts (${maxAttempts}) reached without a successful build.`
1124
+ error: finalState.success ? void 0 : `Max attempts (${maxAttempts}) reached without a successful build.`,
1125
+ modelUsed: finalState.modelUsed,
1126
+ promptTokens: finalState.promptTokens,
1127
+ completionTokens: finalState.completionTokens
1066
1128
  };
1129
+ writeReport(cwd, "rescue", {
1130
+ success: result.success,
1131
+ attempts: result.attempts,
1132
+ maxAttempts,
1133
+ appliedFix: result.appliedFix,
1134
+ error: result.error,
1135
+ rawOutput: result.finalOutput,
1136
+ modelUsed: result.modelUsed,
1137
+ promptTokens: result.promptTokens,
1138
+ completionTokens: result.completionTokens
1139
+ });
1140
+ return result;
1141
+ }
1142
+ function writeReport(cwd, type, data) {
1143
+ const reportPath = import_path22.default.join(cwd, "bugzero-report.md");
1144
+ let content = "";
1145
+ if (type === "hunt") {
1146
+ const { build, lint, test } = data;
1147
+ content = `# \u{1F50D} BugZero Hunt Report
1148
+
1149
+ **Date:** ${(/* @__PURE__ */ new Date()).toLocaleString()}
1150
+ **Project Path:** \`${cwd}\`
1151
+ **Framework:** \`${detectFramework2(cwd)}\`
1152
+
1153
+ ## \u{1F4CA} Status Summary
1154
+ - **Build:** ${build.success ? "\u2705 Passed" : "\u274C Failed"}
1155
+ - **Lint:** ${lint.success ? "\u2705 Passed" : "\u274C Failed"}
1156
+ - **Test:** ${test.success ? "\u2705 Passed" : "\u274C Failed"}
1157
+
1158
+ `;
1159
+ if (!build.success || !lint.success || !test.success) {
1160
+ content += `## \u274C Failed Checks & Error Output
1161
+
1162
+ `;
1163
+ if (!build.success) {
1164
+ content += `### \u{1F7E5} Build Failure
1165
+ \`\`\`text
1166
+ ${build.output}
1167
+ \`\`\`
1168
+
1169
+ `;
1170
+ }
1171
+ if (!lint.success) {
1172
+ content += `### \u{1F7E8} Lint Failure
1173
+ \`\`\`text
1174
+ ${lint.output}
1175
+ \`\`\`
1176
+
1177
+ `;
1178
+ }
1179
+ if (!test.success) {
1180
+ content += `### \u{1F7E6} Test Failure
1181
+ \`\`\`text
1182
+ ${test.output}
1183
+ \`\`\`
1184
+
1185
+ `;
1186
+ }
1187
+ content += `\u{1F4A1} *Run \`bugzero rescue\` to automatically fix these issues.*`;
1188
+ } else {
1189
+ content += `\u{1F389} **All checks passed! Your project is in perfect shape.**`;
1190
+ }
1191
+ } else {
1192
+ const { success, attempts, maxAttempts, appliedFix, error, rawOutput, modelUsed, promptTokens, completionTokens } = data;
1193
+ content = `# \u{1F916} BugZero Rescue Report
1194
+
1195
+ **Date:** ${(/* @__PURE__ */ new Date()).toLocaleString()}
1196
+ **Project Path:** \`${cwd}\`
1197
+ **Framework:** \`${detectFramework2(cwd)}\`
1198
+
1199
+ ## \u{1F4CA} Repair Summary
1200
+ - **Status:** ${success ? "\u2705 Fixed successfully!" : "\u274C Could not repair automatically"}
1201
+ - **Attempts:** ${attempts} / ${maxAttempts}
1202
+ - **AI Brain (Model):** \`${modelUsed || "unknown"}\`
1203
+ - **Token Usage:** ${promptTokens !== void 0 && completionTokens !== void 0 ? `Prompt: **${promptTokens}** | Completion: **${completionTokens}** | Total: **${promptTokens + completionTokens}**` : "*N/A*"}
1204
+
1205
+ `;
1206
+ if (success && appliedFix) {
1207
+ content += `## \u{1F6E0}\uFE0F Applied Solution
1208
+ - **Target File:** \`${appliedFix.filePath}\`
1209
+ - **Root Cause:** ${appliedFix.rootCause}
1210
+ - **Explanation:** ${appliedFix.explanation}
1211
+
1212
+ ### \u{1F4DD} Code Changes
1213
+ **Search (Before):**
1214
+ \`\`\`typescript
1215
+ ${appliedFix.search}
1216
+ \`\`\`
1217
+
1218
+ **Replace (After):**
1219
+ \`\`\`typescript
1220
+ ${appliedFix.replace}
1221
+ \`\`\`
1222
+ `;
1223
+ } else {
1224
+ content += `## \u274C Failed to Repair
1225
+ **Reason:** ${error || "Max attempts reached without finding a solution."}
1226
+
1227
+ ### \u{1F7E5} Unresolved Errors & Logs
1228
+ \`\`\`text
1229
+ ${rawOutput}
1230
+ \`\`\`
1231
+ `;
1232
+ }
1233
+ }
1234
+ try {
1235
+ import_fs2.default.writeFileSync(reportPath, content, "utf-8");
1236
+ console.log(`
1237
+ \u{1F4DD} Generated report at: bugzero-report.md`);
1238
+ } catch (e) {
1239
+ console.error(`\u26A0\uFE0F Failed to write report file: ${e.message}`);
1240
+ }
1067
1241
  }
1068
1242
  }
1069
1243
  });
@@ -1127,6 +1301,10 @@ program.command("rescue").description("Detect build failures and automatically a
1127
1301
  console.log("\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
1128
1302
  if (result.success) {
1129
1303
  console.log(`\u2705 Build fixed after ${result.attempts} attempt(s)!`);
1304
+ console.log(` Model: ${result.modelUsed || "unknown"}`);
1305
+ if (result.promptTokens !== void 0 && result.completionTokens !== void 0) {
1306
+ console.log(` Tokens: Prompt: ${result.promptTokens} | Completion: ${result.completionTokens} | Total: ${result.promptTokens + result.completionTokens}`);
1307
+ }
1130
1308
  if (result.appliedFix) {
1131
1309
  console.log(` File: ${result.appliedFix.filePath}`);
1132
1310
  console.log(` Reason: ${result.appliedFix.explanation}`);
@@ -1134,7 +1312,16 @@ program.command("rescue").description("Detect build failures and automatically a
1134
1312
  }
1135
1313
  } else {
1136
1314
  console.log(`\u274C Could not fix build after ${result.attempts} attempt(s).`);
1315
+ console.log(` Model: ${result.modelUsed || "unknown"}`);
1316
+ if (result.promptTokens !== void 0 && result.completionTokens !== void 0) {
1317
+ console.log(` Tokens: Prompt: ${result.promptTokens} | Completion: ${result.completionTokens} | Total: ${result.promptTokens + result.completionTokens}`);
1318
+ }
1137
1319
  if (result.error) console.log(` ${result.error}`);
1320
+ console.log(`
1321
+ \u2500\u2500 Unresolved Error Output \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`);
1322
+ console.log(result.finalOutput);
1323
+ console.log(`\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
1324
+ `);
1138
1325
  }
1139
1326
  console.log();
1140
1327
  process.exit(result.success ? 0 : 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugzero",
3
- "version": "0.0.12",
3
+ "version": "0.0.16",
4
4
  "bin": {
5
5
  "bugzero": "dist/index.js"
6
6
  },
package/src/index.ts CHANGED
@@ -82,6 +82,10 @@ program
82
82
  console.log("\n──────────────────────────────────────────────");
83
83
  if (result.success) {
84
84
  console.log(`✅ Build fixed after ${result.attempts} attempt(s)!`);
85
+ console.log(` Model: ${result.modelUsed || "unknown"}`);
86
+ if (result.promptTokens !== undefined && result.completionTokens !== undefined) {
87
+ console.log(` Tokens: Prompt: ${result.promptTokens} | Completion: ${result.completionTokens} | Total: ${result.promptTokens + result.completionTokens}`);
88
+ }
85
89
  if (result.appliedFix) {
86
90
  console.log(` File: ${result.appliedFix.filePath}`);
87
91
  console.log(` Reason: ${result.appliedFix.explanation}`);
@@ -89,7 +93,14 @@ program
89
93
  }
90
94
  } else {
91
95
  console.log(`❌ Could not fix build after ${result.attempts} attempt(s).`);
96
+ console.log(` Model: ${result.modelUsed || "unknown"}`);
97
+ if (result.promptTokens !== undefined && result.completionTokens !== undefined) {
98
+ console.log(` Tokens: Prompt: ${result.promptTokens} | Completion: ${result.completionTokens} | Total: ${result.promptTokens + result.completionTokens}`);
99
+ }
92
100
  if (result.error) console.log(` ${result.error}`);
101
+ console.log(`\n── Unresolved Error Output ────────────────────────`);
102
+ console.log(result.finalOutput);
103
+ console.log(`───────────────────────────────────────────────────\n`);
93
104
  }
94
105
  console.log();
95
106