@bobsworkshop/cli 0.1.0

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 (36) hide show
  1. package/bin/bob.ts +74 -0
  2. package/dist/bin/analyse-auto-AAWSETKY.js +540 -0
  3. package/dist/bin/analyse-auto-FQ62GYPV.js +533 -0
  4. package/dist/bin/analyse-auto-JAD24IQ5.js +511 -0
  5. package/dist/bin/analyse-auto-OBCDWYWX.js +529 -0
  6. package/dist/bin/analyse-auto-R4MZA7SX.js +511 -0
  7. package/dist/bin/analyse-auto-V3SH4MS7.js +524 -0
  8. package/dist/bin/analyse-auto-WQUK5YPO.js +531 -0
  9. package/dist/bin/analyse-auto-WVAY6467.js +280 -0
  10. package/dist/bin/analyse-results-3NSD6MAY.js +363 -0
  11. package/dist/bin/analyse-results-B7LONUXU.js +265 -0
  12. package/dist/bin/analyse-results-E6NBAVDB.js +265 -0
  13. package/dist/bin/analyse-results-FIDS4635.js +9 -0
  14. package/dist/bin/analyse-results-LMGVKAUX.js +342 -0
  15. package/dist/bin/analyse-results-LSMLUEIB.js +338 -0
  16. package/dist/bin/analyse-results-MOCLBCD7.js +326 -0
  17. package/dist/bin/analyse-results-NLAEAOOP.js +10 -0
  18. package/dist/bin/analyse-results-PYQIKWYL.js +9 -0
  19. package/dist/bin/analyse-results-QSOD3KVC.js +8 -0
  20. package/dist/bin/analyse-results-R3MG5H7G.js +329 -0
  21. package/dist/bin/analyse-results-UYZZSBHB.js +9 -0
  22. package/dist/bin/analyse-results-YYGHIK2Q.js +9 -0
  23. package/dist/bin/analysis-tracker-N5VANTLH.js +12 -0
  24. package/dist/bin/bob.js +3006 -0
  25. package/dist/bin/chunk-3RSDDQE2.js +420 -0
  26. package/dist/bin/chunk-6KWC4HDO.js +97 -0
  27. package/dist/bin/chunk-6W7WDF4Q.js +589 -0
  28. package/dist/bin/chunk-7CXM3RLM.js +287 -0
  29. package/dist/bin/chunk-FGYL6SWO.js +465 -0
  30. package/dist/bin/chunk-J4BSKFCW.js +624 -0
  31. package/dist/bin/chunk-KWOQFI6L.js +287 -0
  32. package/dist/bin/chunk-LHWBSCJ4.js +878 -0
  33. package/dist/bin/chunk-OOGLZ2QB.js +322 -0
  34. package/dist/bin/chunk-TEVQLSGD.js +287 -0
  35. package/dist/bin/chunk-VUS7R7SO.js +479 -0
  36. package/package.json +47 -0
@@ -0,0 +1,322 @@
1
+ import {
2
+ callCloudFunction,
3
+ callLocalModel,
4
+ proposeAndWriteFile,
5
+ readFileContent
6
+ } from "./chunk-FGYL6SWO.js";
7
+ import {
8
+ markSuggestionById
9
+ } from "./chunk-6KWC4HDO.js";
10
+
11
+ // src/commands/analyse-results.ts
12
+ import chalk from "chalk";
13
+ import inquirer from "inquirer";
14
+ import * as fs from "fs";
15
+ import * as path from "path";
16
+ var RED = chalk.hex("#EF5350");
17
+ var PURPLE = chalk.hex("#AB47BC");
18
+ var BLUE = chalk.hex("#42A5F5");
19
+ var TEAL = chalk.hex("#26A69A");
20
+ var AMBER = chalk.hex("#FFAB00");
21
+ var GRAY = chalk.gray;
22
+ var BORDER = chalk.hex("#455A64");
23
+ var PRIORITY_COLORS = {
24
+ "critical": chalk.bgHex("#B71C1C").white,
25
+ "high": chalk.hex("#FF6D00"),
26
+ "medium": chalk.hex("#FFA726"),
27
+ "low": chalk.hex("#66BB6A")
28
+ };
29
+ var CATEGORY_COLORS = {
30
+ "bugs": RED,
31
+ "features": PURPLE,
32
+ "improvements": BLUE,
33
+ "upgrades": TEAL
34
+ };
35
+ async function showInteractiveResults(config, category, sort, search) {
36
+ let allSuggestions = [];
37
+ if (config.tier === "platform" && config.provider !== "local" && config.loggedIn && config.conversationId) {
38
+ try {
39
+ const result = await callCloudFunction("getCLIAnalysisResults", {
40
+ conversationId: config.conversationId,
41
+ category,
42
+ sort: sort || "priority",
43
+ search: search || null
44
+ });
45
+ allSuggestions = result?.suggestions || [];
46
+ } catch (error) {
47
+ console.log(chalk.red(` \u274C ${error.message}`));
48
+ return;
49
+ }
50
+ } else {
51
+ allSuggestions = loadLocalSuggestions(category);
52
+ }
53
+ if (search) {
54
+ const query = search.toLowerCase();
55
+ allSuggestions = allSuggestions.filter(
56
+ (s) => (s.description || "").toLowerCase().includes(query) || (s.title || "").toLowerCase().includes(query) || (s.filePath || "").toLowerCase().includes(query)
57
+ );
58
+ }
59
+ sortSuggestions(allSuggestions, sort || "priority");
60
+ if (allSuggestions.length === 0) {
61
+ console.log("");
62
+ console.log(chalk.green(" \u2705 No items found. Clean!"));
63
+ console.log("");
64
+ return;
65
+ }
66
+ const color = CATEGORY_COLORS[category] || GRAY;
67
+ let running = true;
68
+ let displaySuggestions = [...allSuggestions];
69
+ let currentSort = sort || "priority";
70
+ while (running) {
71
+ console.log("");
72
+ console.log(color(` \u25C6 ${category.toUpperCase()} (${displaySuggestions.length} items) | Sort: ${currentSort}`));
73
+ console.log(GRAY(" \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\u2500\u2500\u2500\u2500\u2500"));
74
+ console.log("");
75
+ const choices = [];
76
+ choices.push({
77
+ name: chalk.cyan(" \u{1F500} Toggle sort"),
78
+ value: "__sort__",
79
+ short: "Sort"
80
+ });
81
+ choices.push(new inquirer.Separator(GRAY(" \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")));
82
+ for (let idx = 0; idx < displaySuggestions.length; idx++) {
83
+ const item = displaySuggestions[idx];
84
+ const pColor = PRIORITY_COLORS[item.priority?.toLowerCase()] || GRAY;
85
+ const priorityLabel = (item.priority || "MEDIUM").toUpperCase().padEnd(9);
86
+ const filePath = (item.filePath || "unknown").split("/").pop() || "unknown";
87
+ const desc = (item.description || item.title || "No description").slice(0, 42);
88
+ const displayName = `${pColor(priorityLabel)} ${chalk.cyan(filePath.padEnd(18))} ${chalk.white(desc)}`;
89
+ choices.push({
90
+ name: displayName,
91
+ value: idx,
92
+ short: item.title || item.description?.slice(0, 30) || "Item",
93
+ description: `${item.priority} ${item.filePath} ${item.title} ${item.description}`
94
+ });
95
+ }
96
+ choices.push(new inquirer.Separator(GRAY(" \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")));
97
+ choices.push({
98
+ name: chalk.gray(" \u2190 Quit"),
99
+ value: "__quit__",
100
+ short: "Quit"
101
+ });
102
+ const { selected } = await inquirer.prompt([
103
+ {
104
+ type: "search",
105
+ name: "selected",
106
+ message: color(`Search ${category} (type to filter):`),
107
+ source: (input) => {
108
+ if (!input) return choices;
109
+ const query = input.toLowerCase();
110
+ const filtered = choices.filter((c) => {
111
+ if (c.type === "separator") return true;
112
+ if (c.value === "__sort__" || c.value === "__quit__") return true;
113
+ const searchable = c.description?.toLowerCase() || "";
114
+ return searchable.includes(query);
115
+ });
116
+ return filtered;
117
+ },
118
+ pageSize: 12
119
+ }
120
+ ]);
121
+ if (selected === "__quit__") {
122
+ running = false;
123
+ break;
124
+ }
125
+ if (selected === "__sort__") {
126
+ currentSort = currentSort === "priority" ? "file" : "priority";
127
+ sortSuggestions(displaySuggestions, currentSort);
128
+ console.log(chalk.cyan(` Sort changed to: ${currentSort}`));
129
+ continue;
130
+ }
131
+ if (typeof selected === "number") {
132
+ const item = displaySuggestions[selected];
133
+ const action = await showExpandedView(item, category);
134
+ if (action === "implement") {
135
+ await handleImplement(item, config);
136
+ } else if (action === "dismiss") {
137
+ if (item.id) {
138
+ markSuggestionById(item.id, category, "dismissed", {
139
+ reason: "User dismissed from CLI",
140
+ implementedBy: "user"
141
+ });
142
+ }
143
+ displaySuggestions.splice(selected, 1);
144
+ const originalIdx = allSuggestions.findIndex((s) => s.id === item.id);
145
+ if (originalIdx !== -1) allSuggestions.splice(originalIdx, 1);
146
+ console.log(chalk.gray(" \u23ED\uFE0F Dismissed and logged."));
147
+ }
148
+ }
149
+ }
150
+ }
151
+ async function showExpandedView(item, category) {
152
+ const color = CATEGORY_COLORS[category] || GRAY;
153
+ const pColor = PRIORITY_COLORS[item.priority?.toLowerCase()] || GRAY;
154
+ console.log("");
155
+ console.log(color(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
156
+ console.log(color(" \u2551 ") + pColor(`${(item.priority || "MEDIUM").toUpperCase()} ${category.toUpperCase().slice(0, -1)}`));
157
+ console.log(color(" \u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"));
158
+ console.log(color(" \u2551") + chalk.gray(" File: ") + chalk.cyan(item.filePath || "unknown"));
159
+ console.log(color(" \u2551") + chalk.gray(" Priority: ") + pColor((item.priority || "medium").toUpperCase()));
160
+ console.log(color(" \u2551"));
161
+ console.log(color(" \u2551") + chalk.gray(" Title:"));
162
+ console.log(color(" \u2551") + chalk.white.bold(` ${item.title || "No title"}`));
163
+ console.log(color(" \u2551"));
164
+ console.log(color(" \u2551") + chalk.gray(" Description:"));
165
+ const descLines = wrapText(item.description || "No description", 54);
166
+ for (const line of descLines) {
167
+ console.log(color(" \u2551") + chalk.white(` ${line}`));
168
+ }
169
+ if (item.implementation) {
170
+ console.log(color(" \u2551"));
171
+ console.log(color(" \u2551") + chalk.gray(" Implementation:"));
172
+ const implLines = wrapText(item.implementation, 54);
173
+ for (const line of implLines) {
174
+ console.log(color(" \u2551") + chalk.white(` ${line}`));
175
+ }
176
+ }
177
+ console.log(color(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
178
+ console.log("");
179
+ const { action } = await inquirer.prompt([
180
+ {
181
+ type: "select",
182
+ name: "action",
183
+ message: "What do you want to do?",
184
+ choices: [
185
+ { name: chalk.green(" \u{1F527} Implement this fix"), value: "implement" },
186
+ { name: chalk.red(" \u{1F5D1}\uFE0F Dismiss"), value: "dismiss" },
187
+ { name: chalk.gray(" \u2190 Back to list"), value: "back" }
188
+ ]
189
+ }
190
+ ]);
191
+ return action;
192
+ }
193
+ async function handleImplement(item, config) {
194
+ console.log("");
195
+ console.log(chalk.cyan(" \u{1F527} Implementing fix..."));
196
+ console.log("");
197
+ if (config.provider === "local" && config.localEndpoint) {
198
+ const fileContent = readFileContent(item.filePath);
199
+ if (!fileContent) {
200
+ console.log(chalk.red(` \u274C Could not read file: ${item.filePath}`));
201
+ return;
202
+ }
203
+ const prompt = `You are an expert programmer implementing a specific code change.
204
+
205
+ CURRENT FILE: ${item.filePath}
206
+ ${fileContent}
207
+
208
+ CHANGE TO IMPLEMENT:
209
+ Title: ${item.title}
210
+ Description: ${item.description}
211
+ Implementation Instructions: ${item.implementation || "Apply the fix described above."}
212
+
213
+ RULES:
214
+ - Return ONLY the complete updated file content with the change applied.
215
+ - Start the code with: // File: ${item.filePath}
216
+ - PRESERVE all existing code structure. Only change what's needed.
217
+ - Do NOT include any explanation outside the code.`;
218
+ try {
219
+ const messages = [
220
+ { role: "system", content: "You are an expert programmer. Return ONLY the complete updated file. Start with // File: path comment. Preserve existing structure." },
221
+ { role: "user", content: prompt }
222
+ ];
223
+ const response = await callLocalModel(config.localEndpoint, messages);
224
+ const lines = response.split("\n");
225
+ const firstLine = lines[0].trim();
226
+ let newContent;
227
+ if (firstLine.match(/^\/\/\s*(File:)?\s*/)) {
228
+ newContent = lines.slice(1).join("\n").trim();
229
+ } else {
230
+ newContent = response.trim();
231
+ }
232
+ await proposeAndWriteFile({
233
+ filePath: item.filePath,
234
+ content: newContent,
235
+ isNew: false
236
+ });
237
+ if (item.id) {
238
+ const { markSuggestionById: markSuggestionById2 } = await import("./analysis-tracker-N5VANTLH.js");
239
+ markSuggestionById2(item.id, "bugs", "implemented", {
240
+ reason: "User approved implementation from CLI",
241
+ implementedBy: "user"
242
+ });
243
+ }
244
+ } catch (error) {
245
+ console.log(chalk.red(` \u274C Implementation failed: ${error.message}`));
246
+ }
247
+ } else if (config.loggedIn && config.conversationId) {
248
+ try {
249
+ const result = await callCloudFunction("implementSuggestion", {
250
+ conversationId: config.conversationId,
251
+ filePath: item.filePath,
252
+ suggestionId: item.id || "unknown",
253
+ category: "bugs",
254
+ jobId: `cli_impl_${Date.now()}`
255
+ });
256
+ if (result?.success) {
257
+ console.log(chalk.green(` \u2705 ${result.message}`));
258
+ } else {
259
+ console.log(chalk.red(" \u274C Implementation failed on platform."));
260
+ }
261
+ } catch (error) {
262
+ console.log(chalk.red(` \u274C ${error.message}`));
263
+ }
264
+ } else {
265
+ console.log(chalk.red(" \u274C No provider configured for implementation."));
266
+ }
267
+ console.log("");
268
+ }
269
+ function sortSuggestions(suggestions, method) {
270
+ if (method === "file") {
271
+ suggestions.sort((a, b) => (a.filePath || "").localeCompare(b.filePath || ""));
272
+ } else {
273
+ const priorityMap = { "critical": 0, "high": 1, "medium": 2, "low": 3 };
274
+ suggestions.sort((a, b) => {
275
+ const pA = priorityMap[a.priority?.toLowerCase()] ?? 99;
276
+ const pB = priorityMap[b.priority?.toLowerCase()] ?? 99;
277
+ return pA - pB;
278
+ });
279
+ }
280
+ }
281
+ function loadLocalSuggestions(category) {
282
+ const cwd = process.cwd();
283
+ const projectName = path.basename(cwd);
284
+ const homeDir = process.env.HOME || process.env.USERPROFILE || "";
285
+ const analysisPath = path.join(homeDir, ".bob", "projects", projectName, "analysis", "results", "analysis.json");
286
+ if (!fs.existsSync(analysisPath)) return [];
287
+ const allResults = JSON.parse(fs.readFileSync(analysisPath, "utf-8"));
288
+ const suggestions = [];
289
+ for (const [filePath, fileResults] of Object.entries(allResults)) {
290
+ const items = fileResults[category] || [];
291
+ items.forEach((item, idx) => {
292
+ if (!item.status || item.status === "pending") {
293
+ suggestions.push({
294
+ ...item,
295
+ filePath,
296
+ id: `${filePath.replace(/[\/\\]/g, "_")}_${idx}`
297
+ });
298
+ }
299
+ });
300
+ }
301
+ return suggestions;
302
+ }
303
+ function wrapText(text, maxWidth) {
304
+ const words = text.split(" ");
305
+ const lines = [];
306
+ let currentLine = "";
307
+ for (const word of words) {
308
+ if (currentLine.length + word.length + 1 > maxWidth) {
309
+ lines.push(currentLine);
310
+ currentLine = word;
311
+ } else {
312
+ currentLine += (currentLine ? " " : "") + word;
313
+ }
314
+ }
315
+ if (currentLine) lines.push(currentLine);
316
+ return lines;
317
+ }
318
+
319
+ export {
320
+ showInteractiveResults,
321
+ loadLocalSuggestions
322
+ };
@@ -0,0 +1,287 @@
1
+ import {
2
+ callCloudFunction,
3
+ callLocalModel,
4
+ ensureProjectStructure,
5
+ proposeAndWriteFile,
6
+ readFileContent
7
+ } from "./chunk-6W7WDF4Q.js";
8
+
9
+ // src/commands/analyse-results.ts
10
+ import chalk from "chalk";
11
+ import inquirer from "inquirer";
12
+ import * as fs from "fs";
13
+ import * as path from "path";
14
+ var RED = chalk.hex("#EF5350");
15
+ var PURPLE = chalk.hex("#AB47BC");
16
+ var BLUE = chalk.hex("#42A5F5");
17
+ var TEAL = chalk.hex("#26A69A");
18
+ var AMBER = chalk.hex("#FFAB00");
19
+ var GRAY = chalk.gray;
20
+ var BORDER = chalk.hex("#455A64");
21
+ var PRIORITY_COLORS = {
22
+ "critical": chalk.bgHex("#B71C1C").white,
23
+ "high": chalk.hex("#FF6D00"),
24
+ "medium": chalk.hex("#FFA726"),
25
+ "low": chalk.hex("#66BB6A")
26
+ };
27
+ var CATEGORY_COLORS = {
28
+ "bugs": RED,
29
+ "features": PURPLE,
30
+ "improvements": BLUE,
31
+ "upgrades": TEAL
32
+ };
33
+ async function showInteractiveResults(config, category, sort, search) {
34
+ let allSuggestions = [];
35
+ if (config.tier === "platform" && config.provider !== "local" && config.loggedIn && config.conversationId) {
36
+ try {
37
+ const result = await callCloudFunction("getCLIAnalysisResults", {
38
+ conversationId: config.conversationId,
39
+ category,
40
+ sort: sort || "priority",
41
+ search: search || null
42
+ });
43
+ allSuggestions = result?.suggestions || [];
44
+ } catch (error) {
45
+ console.log(chalk.red(` \u274C ${error.message}`));
46
+ return;
47
+ }
48
+ } else {
49
+ allSuggestions = loadLocalSuggestions(category);
50
+ }
51
+ if (search) {
52
+ const query = search.toLowerCase();
53
+ allSuggestions = allSuggestions.filter(
54
+ (s) => (s.description || "").toLowerCase().includes(query) || (s.title || "").toLowerCase().includes(query) || (s.filePath || "").toLowerCase().includes(query)
55
+ );
56
+ }
57
+ sortSuggestions(allSuggestions, sort || "priority");
58
+ if (allSuggestions.length === 0) {
59
+ console.log("");
60
+ console.log(chalk.green(" \u2705 No items found. Clean!"));
61
+ console.log("");
62
+ return;
63
+ }
64
+ const color = CATEGORY_COLORS[category] || GRAY;
65
+ let running = true;
66
+ let displaySuggestions = [...allSuggestions];
67
+ let currentSort = sort || "priority";
68
+ while (running) {
69
+ console.log("");
70
+ console.log(color(` \u25C6 ${category.toUpperCase()} (${displaySuggestions.length} items) | Sort: ${currentSort}`));
71
+ console.log(GRAY(" \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\u2500\u2500\u2500\u2500\u2500"));
72
+ console.log("");
73
+ const choices = displaySuggestions.map((item, idx) => {
74
+ const pColor = PRIORITY_COLORS[item.priority?.toLowerCase()] || GRAY;
75
+ const priorityLabel = (item.priority || "MEDIUM").toUpperCase().padEnd(9);
76
+ const filePath = (item.filePath || "unknown").split("/").pop() || "unknown";
77
+ const desc = (item.description || item.title || "No description").slice(0, 42);
78
+ const displayName = `${pColor(priorityLabel)} ${chalk.cyan(filePath.padEnd(18))} ${chalk.white(desc)}`;
79
+ return {
80
+ name: displayName,
81
+ value: idx,
82
+ short: item.title || item.description?.slice(0, 30) || "Item",
83
+ // Used for search matching
84
+ description: `${item.priority} ${item.filePath} ${item.title} ${item.description}`
85
+ };
86
+ });
87
+ const { selected } = await inquirer.prompt([
88
+ {
89
+ type: "search",
90
+ name: "selected",
91
+ message: color(`Search ${category} (type to filter, arrows to navigate):`),
92
+ source: (input) => {
93
+ if (!input) return [...choices, { name: chalk.cyan(" \u{1F500} Toggle sort"), value: "__sort__", short: "Sort" }, { name: chalk.gray(" \u2190 Quit"), value: "__quit__", short: "Quit" }];
94
+ const query = input.toLowerCase();
95
+ const filtered = choices.filter((c) => {
96
+ const searchable = c.description?.toLowerCase() || "";
97
+ return searchable.includes(query);
98
+ });
99
+ return [...filtered, { name: chalk.gray(" \u2190 Quit"), value: "__quit__", short: "Quit" }];
100
+ },
101
+ pageSize: 12
102
+ }
103
+ ]);
104
+ if (selected === "__quit__") {
105
+ running = false;
106
+ break;
107
+ }
108
+ if (selected === "__sort__") {
109
+ currentSort = currentSort === "priority" ? "file" : "priority";
110
+ sortSuggestions(displaySuggestions, currentSort);
111
+ console.log(chalk.cyan(` Sort changed to: ${currentSort}`));
112
+ continue;
113
+ }
114
+ if (typeof selected === "number") {
115
+ const item = displaySuggestions[selected];
116
+ const action = await showExpandedView(item, category);
117
+ if (action === "implement") {
118
+ await handleImplement(item, config);
119
+ } else if (action === "dismiss") {
120
+ displaySuggestions.splice(selected, 1);
121
+ const originalIdx = allSuggestions.findIndex((s) => s.id === item.id);
122
+ if (originalIdx !== -1) allSuggestions.splice(originalIdx, 1);
123
+ console.log(chalk.gray(" \u23ED\uFE0F Dismissed."));
124
+ }
125
+ }
126
+ }
127
+ }
128
+ async function showExpandedView(item, category) {
129
+ const color = CATEGORY_COLORS[category] || GRAY;
130
+ const pColor = PRIORITY_COLORS[item.priority?.toLowerCase()] || GRAY;
131
+ console.log("");
132
+ console.log(color(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
133
+ console.log(color(" \u2551 ") + pColor(`${(item.priority || "MEDIUM").toUpperCase()} ${category.toUpperCase().slice(0, -1)}`));
134
+ console.log(color(" \u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"));
135
+ console.log(color(" \u2551") + chalk.gray(" File: ") + chalk.cyan(item.filePath || "unknown"));
136
+ console.log(color(" \u2551") + chalk.gray(" Priority: ") + pColor((item.priority || "medium").toUpperCase()));
137
+ console.log(color(" \u2551"));
138
+ console.log(color(" \u2551") + chalk.gray(" Title:"));
139
+ console.log(color(" \u2551") + chalk.white.bold(` ${item.title || "No title"}`));
140
+ console.log(color(" \u2551"));
141
+ console.log(color(" \u2551") + chalk.gray(" Description:"));
142
+ const descLines = wrapText(item.description || "No description", 54);
143
+ for (const line of descLines) {
144
+ console.log(color(" \u2551") + chalk.white(` ${line}`));
145
+ }
146
+ if (item.implementation) {
147
+ console.log(color(" \u2551"));
148
+ console.log(color(" \u2551") + chalk.gray(" Implementation:"));
149
+ const implLines = wrapText(item.implementation, 54);
150
+ for (const line of implLines) {
151
+ console.log(color(" \u2551") + chalk.white(` ${line}`));
152
+ }
153
+ }
154
+ console.log(color(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
155
+ console.log("");
156
+ const { action } = await inquirer.prompt([
157
+ {
158
+ type: "select",
159
+ name: "action",
160
+ message: "What do you want to do?",
161
+ choices: [
162
+ { name: chalk.green(" \u{1F527} Implement this fix"), value: "implement" },
163
+ { name: chalk.red(" \u{1F5D1}\uFE0F Dismiss"), value: "dismiss" },
164
+ { name: chalk.gray(" \u2190 Back to list"), value: "back" }
165
+ ]
166
+ }
167
+ ]);
168
+ return action;
169
+ }
170
+ async function handleImplement(item, config) {
171
+ console.log("");
172
+ console.log(chalk.cyan(" \u{1F527} Implementing fix..."));
173
+ console.log("");
174
+ if (config.provider === "local" && config.localEndpoint) {
175
+ const fileContent = readFileContent(item.filePath);
176
+ if (!fileContent) {
177
+ console.log(chalk.red(` \u274C Could not read file: ${item.filePath}`));
178
+ return;
179
+ }
180
+ const prompt = `You are an expert programmer implementing a specific code change.
181
+
182
+ CURRENT FILE: ${item.filePath}
183
+ ${fileContent}
184
+
185
+ CHANGE TO IMPLEMENT:
186
+ Title: ${item.title}
187
+ Description: ${item.description}
188
+ Implementation Instructions: ${item.implementation || "Apply the fix described above."}
189
+
190
+ RULES:
191
+ - Return ONLY the complete updated file content with the change applied.
192
+ - Start the code with: // File: ${item.filePath}
193
+ - PRESERVE all existing code structure. Only change what's needed.
194
+ - Do NOT include any explanation outside the code.`;
195
+ try {
196
+ const messages = [
197
+ { role: "system", content: "You are an expert programmer. Return ONLY the complete updated file. Start with // File: path comment. Preserve existing structure." },
198
+ { role: "user", content: prompt }
199
+ ];
200
+ const response = await callLocalModel(config.localEndpoint, messages);
201
+ const lines = response.split("\n");
202
+ const firstLine = lines[0].trim();
203
+ let newContent;
204
+ if (firstLine.match(/^\/\/\s*(File:)?\s*/)) {
205
+ newContent = lines.slice(1).join("\n").trim();
206
+ } else {
207
+ newContent = response.trim();
208
+ }
209
+ await proposeAndWriteFile({
210
+ filePath: item.filePath,
211
+ content: newContent,
212
+ isNew: false
213
+ });
214
+ } catch (error) {
215
+ console.log(chalk.red(` \u274C Implementation failed: ${error.message}`));
216
+ }
217
+ } else if (config.loggedIn && config.conversationId) {
218
+ try {
219
+ const result = await callCloudFunction("implementSuggestion", {
220
+ conversationId: config.conversationId,
221
+ filePath: item.filePath,
222
+ suggestionId: item.id || "unknown",
223
+ category: "bugs",
224
+ jobId: `cli_impl_${Date.now()}`
225
+ });
226
+ if (result?.success) {
227
+ console.log(chalk.green(` \u2705 ${result.message}`));
228
+ } else {
229
+ console.log(chalk.red(" \u274C Implementation failed on platform."));
230
+ }
231
+ } catch (error) {
232
+ console.log(chalk.red(` \u274C ${error.message}`));
233
+ }
234
+ } else {
235
+ console.log(chalk.red(" \u274C No provider configured for implementation."));
236
+ }
237
+ console.log("");
238
+ }
239
+ function sortSuggestions(suggestions, method) {
240
+ if (method === "file") {
241
+ suggestions.sort((a, b) => (a.filePath || "").localeCompare(b.filePath || ""));
242
+ } else {
243
+ const priorityMap = { "critical": 0, "high": 1, "medium": 2, "low": 3 };
244
+ suggestions.sort((a, b) => {
245
+ const pA = priorityMap[a.priority?.toLowerCase()] ?? 99;
246
+ const pB = priorityMap[b.priority?.toLowerCase()] ?? 99;
247
+ return pA - pB;
248
+ });
249
+ }
250
+ }
251
+ function loadLocalSuggestions(category) {
252
+ const cwd = process.cwd();
253
+ const { analysisDir } = ensureProjectStructure(cwd);
254
+ const analysisPath = path.join(analysisDir, "results", "analysis.json");
255
+ if (!fs.existsSync(analysisPath)) return [];
256
+ const allResults = JSON.parse(fs.readFileSync(analysisPath, "utf-8"));
257
+ const suggestions = [];
258
+ for (const [filePath, fileResults] of Object.entries(allResults)) {
259
+ const items = fileResults[category] || [];
260
+ suggestions.push(...items.map((item, idx) => ({
261
+ ...item,
262
+ filePath,
263
+ id: `${filePath.replace(/[\/\\]/g, "_")}_${idx}`
264
+ })));
265
+ }
266
+ return suggestions;
267
+ }
268
+ function wrapText(text, maxWidth) {
269
+ const words = text.split(" ");
270
+ const lines = [];
271
+ let currentLine = "";
272
+ for (const word of words) {
273
+ if (currentLine.length + word.length + 1 > maxWidth) {
274
+ lines.push(currentLine);
275
+ currentLine = word;
276
+ } else {
277
+ currentLine += (currentLine ? " " : "") + word;
278
+ }
279
+ }
280
+ if (currentLine) lines.push(currentLine);
281
+ return lines;
282
+ }
283
+
284
+ export {
285
+ showInteractiveResults,
286
+ loadLocalSuggestions
287
+ };