pi-lens 3.6.2 → 3.6.4
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.
- package/CHANGELOG.md +10 -2
- package/package.json +4 -4
- package/tsconfig.json +1 -1
- package/clients/__tests__/file-time.test.js +0 -216
- package/clients/__tests__/file-time.test.ts +0 -276
- package/clients/__tests__/format-service.test.js +0 -245
- package/clients/__tests__/format-service.test.ts +0 -339
- package/clients/__tests__/formatters.test.js +0 -271
- package/clients/__tests__/formatters.test.ts +0 -401
- package/clients/agent-behavior-client.js +0 -110
- package/clients/agent-behavior-client.test.js +0 -94
- package/clients/agent-behavior-client.test.ts +0 -116
- package/clients/amain-types.js +0 -164
- package/clients/architect-client.js +0 -291
- package/clients/ast-grep-client.js +0 -253
- package/clients/ast-grep-parser.js +0 -84
- package/clients/ast-grep-rule-manager.js +0 -89
- package/clients/ast-grep-types.js +0 -9
- package/clients/auto-loop.js +0 -131
- package/clients/biome-client.js +0 -420
- package/clients/biome-client.test.js +0 -144
- package/clients/biome-client.test.ts +0 -163
- package/clients/cache/rule-cache.js +0 -72
- package/clients/cache-manager.js +0 -245
- package/clients/cache-manager.test.js +0 -197
- package/clients/cache-manager.test.ts +0 -299
- package/clients/complexity-client.js +0 -675
- package/clients/complexity-client.test.js +0 -234
- package/clients/complexity-client.test.ts +0 -255
- package/clients/config-validator.js +0 -465
- package/clients/dependency-checker.js +0 -325
- package/clients/dependency-checker.test.js +0 -60
- package/clients/dependency-checker.test.ts +0 -71
- package/clients/dispatch/__tests__/autofix-integration.test.js +0 -245
- package/clients/dispatch/__tests__/autofix-integration.test.ts +0 -300
- package/clients/dispatch/__tests__/runner-registration.test.js +0 -234
- package/clients/dispatch/__tests__/runner-registration.test.ts +0 -286
- package/clients/dispatch/debug.log +0 -1
- package/clients/dispatch/dispatcher.edge.test.js +0 -82
- package/clients/dispatch/dispatcher.edge.test.ts +0 -100
- package/clients/dispatch/dispatcher.format.test.js +0 -46
- package/clients/dispatch/dispatcher.format.test.ts +0 -58
- package/clients/dispatch/dispatcher.inline.test.js +0 -74
- package/clients/dispatch/dispatcher.inline.test.ts +0 -93
- package/clients/dispatch/dispatcher.js +0 -381
- package/clients/dispatch/dispatcher.test.js +0 -116
- package/clients/dispatch/dispatcher.test.ts +0 -149
- package/clients/dispatch/integration.js +0 -108
- package/clients/dispatch/plan.js +0 -183
- package/clients/dispatch/runners/architect.js +0 -83
- package/clients/dispatch/runners/architect.test.js +0 -138
- package/clients/dispatch/runners/architect.test.ts +0 -162
- package/clients/dispatch/runners/ast-grep-napi.js +0 -405
- package/clients/dispatch/runners/ast-grep-napi.test.js +0 -107
- package/clients/dispatch/runners/ast-grep-napi.test.ts +0 -129
- package/clients/dispatch/runners/ast-grep.js +0 -157
- package/clients/dispatch/runners/biome.js +0 -55
- package/clients/dispatch/runners/config-validation.js +0 -67
- package/clients/dispatch/runners/go-vet.js +0 -48
- package/clients/dispatch/runners/index.js +0 -47
- package/clients/dispatch/runners/lsp.js +0 -102
- package/clients/dispatch/runners/oxlint.js +0 -67
- package/clients/dispatch/runners/oxlint.test.js +0 -230
- package/clients/dispatch/runners/oxlint.test.ts +0 -303
- package/clients/dispatch/runners/pyright.js +0 -100
- package/clients/dispatch/runners/pyright.test.js +0 -98
- package/clients/dispatch/runners/pyright.test.ts +0 -121
- package/clients/dispatch/runners/python-slop.js +0 -97
- package/clients/dispatch/runners/python-slop.test.js +0 -203
- package/clients/dispatch/runners/python-slop.test.ts +0 -298
- package/clients/dispatch/runners/ruff.js +0 -48
- package/clients/dispatch/runners/rust-clippy.js +0 -102
- package/clients/dispatch/runners/scan_codebase.test.js +0 -89
- package/clients/dispatch/runners/scan_codebase.test.ts +0 -105
- package/clients/dispatch/runners/shellcheck.js +0 -147
- package/clients/dispatch/runners/shellcheck.test.js +0 -98
- package/clients/dispatch/runners/shellcheck.test.ts +0 -129
- package/clients/dispatch/runners/similarity.js +0 -230
- package/clients/dispatch/runners/spellcheck.js +0 -106
- package/clients/dispatch/runners/spellcheck.test.js +0 -158
- package/clients/dispatch/runners/spellcheck.test.ts +0 -214
- package/clients/dispatch/runners/tree-sitter.js +0 -246
- package/clients/dispatch/runners/ts-lsp.js +0 -125
- package/clients/dispatch/runners/ts-slop.js +0 -113
- package/clients/dispatch/runners/type-safety.js +0 -142
- package/clients/dispatch/runners/utils/diagnostic-parsers.js +0 -134
- package/clients/dispatch/runners/utils/runner-helpers.js +0 -115
- package/clients/dispatch/runners/utils.js +0 -51
- package/clients/dispatch/runners/yaml-rule-parser.js +0 -360
- package/clients/dispatch/types.js +0 -16
- package/clients/dispatch/utils/format-utils.js +0 -44
- package/clients/dogfood.test.js +0 -201
- package/clients/dogfood.test.ts +0 -269
- package/clients/file-kinds.js +0 -177
- package/clients/file-kinds.test.js +0 -169
- package/clients/file-kinds.test.ts +0 -210
- package/clients/file-time.js +0 -152
- package/clients/file-utils.js +0 -40
- package/clients/fix-scanners.js +0 -204
- package/clients/format-service.js +0 -184
- package/clients/formatters.js +0 -488
- package/clients/go-client.js +0 -203
- package/clients/go-client.test.js +0 -127
- package/clients/go-client.test.ts +0 -143
- package/clients/installer/index.js +0 -403
- package/clients/interviewer-templates.js +0 -75
- package/clients/interviewer.js +0 -173
- package/clients/jscpd-client.js +0 -196
- package/clients/jscpd-client.test.js +0 -127
- package/clients/jscpd-client.test.ts +0 -145
- package/clients/knip-client.js +0 -239
- package/clients/knip-client.test.js +0 -112
- package/clients/knip-client.test.ts +0 -128
- package/clients/latency-logger.js +0 -40
- package/clients/lsp/__tests__/client.test.js +0 -310
- package/clients/lsp/__tests__/client.test.ts +0 -412
- package/clients/lsp/__tests__/config.test.js +0 -167
- package/clients/lsp/__tests__/config.test.ts +0 -217
- package/clients/lsp/__tests__/error-recovery.test.js +0 -213
- package/clients/lsp/__tests__/error-recovery.test.ts +0 -279
- package/clients/lsp/__tests__/integration.test.js +0 -127
- package/clients/lsp/__tests__/integration.test.ts +0 -160
- package/clients/lsp/__tests__/launch.test.js +0 -313
- package/clients/lsp/__tests__/launch.test.ts +0 -394
- package/clients/lsp/__tests__/server.test.js +0 -259
- package/clients/lsp/__tests__/server.test.ts +0 -332
- package/clients/lsp/__tests__/service.test.js +0 -438
- package/clients/lsp/__tests__/service.test.ts +0 -530
- package/clients/lsp/client.js +0 -350
- package/clients/lsp/config.js +0 -112
- package/clients/lsp/index.js +0 -318
- package/clients/lsp/installer/index.js +0 -391
- package/clients/lsp/interactive-install.js +0 -221
- package/clients/lsp/language.js +0 -170
- package/clients/lsp/launch.js +0 -329
- package/clients/lsp/lsp/launch.js +0 -116
- package/clients/lsp/lsp/server.js +0 -532
- package/clients/lsp/lsp-index.js +0 -10
- package/clients/lsp/path-utils.js +0 -5
- package/clients/lsp/server.js +0 -725
- package/clients/lsp/test-py-spawn/requirements.txt +0 -1
- package/clients/lsp/test-py-spawn/test.py +0 -3
- package/clients/lsp/test-py-svc/requirements.txt +0 -1
- package/clients/lsp/test-py-svc/test.py +0 -3
- package/clients/lsp/test-python-project/requirements.txt +0 -1
- package/clients/lsp/test-python-project/test.py +0 -5
- package/clients/metrics-client.js +0 -107
- package/clients/metrics-client.test.js +0 -128
- package/clients/metrics-client.test.ts +0 -163
- package/clients/metrics-history.js +0 -367
- package/clients/path-utils.js +0 -142
- package/clients/pipeline.js +0 -272
- package/clients/production-readiness.js +0 -522
- package/clients/project-index.js +0 -255
- package/clients/project-metadata.js +0 -531
- package/clients/ruff-client.js +0 -325
- package/clients/ruff-client.test.js +0 -132
- package/clients/ruff-client.test.ts +0 -153
- package/clients/rules-scanner.js +0 -97
- package/clients/runner-tracker.js +0 -152
- package/clients/rust-client.js +0 -205
- package/clients/rust-client.test.js +0 -108
- package/clients/rust-client.test.ts +0 -130
- package/clients/safe-spawn-async.js +0 -163
- package/clients/safe-spawn.js +0 -241
- package/clients/sanitize.js +0 -291
- package/clients/sanitize.test.js +0 -177
- package/clients/sanitize.test.ts +0 -223
- package/clients/scan-architectural-debt.js +0 -167
- package/clients/scan-utils.js +0 -83
- package/clients/secrets-scanner.js +0 -119
- package/clients/secrets-scanner.test.js +0 -100
- package/clients/secrets-scanner.test.ts +0 -113
- package/clients/sg-runner.js +0 -292
- package/clients/state-matrix.js +0 -160
- package/clients/subprocess-client.js +0 -65
- package/clients/symbol-types.js +0 -5
- package/clients/test-runner-client.js +0 -523
- package/clients/test-runner-client.test.js +0 -192
- package/clients/test-runner-client.test.ts +0 -253
- package/clients/test-utils.js +0 -27
- package/clients/test-utils.ts +0 -36
- package/clients/todo-scanner.js +0 -200
- package/clients/todo-scanner.test.js +0 -301
- package/clients/todo-scanner.test.ts +0 -352
- package/clients/tool-availability.js +0 -207
- package/clients/tree-sitter-client.js +0 -601
- package/clients/tree-sitter-query-loader.js +0 -355
- package/clients/tree-sitter-symbol-extractor.js +0 -289
- package/clients/ts-service.js +0 -129
- package/clients/type-coverage-client.js +0 -127
- package/clients/type-coverage-client.test.js +0 -105
- package/clients/type-coverage-client.test.ts +0 -125
- package/clients/type-safety-client.js +0 -138
- package/clients/types.js +0 -11
- package/clients/typescript-client.codefix.test.js +0 -157
- package/clients/typescript-client.codefix.test.ts +0 -186
- package/clients/typescript-client.js +0 -509
- package/clients/typescript-client.test.js +0 -105
- package/clients/typescript-client.test.ts +0 -126
- package/commands/booboo.js +0 -1007
- package/commands/fix-from-booboo.js +0 -398
- package/commands/fix-simplified.js +0 -618
- package/commands/rate.js +0 -281
- package/commands/rate.test.js +0 -119
- package/commands/rate.test.ts +0 -131
- package/commands/refactor.js +0 -130
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* /lens-booboo-fix command - Sequential fixing from booboo results
|
|
3
|
-
*
|
|
4
|
-
* Reads the latest /lens-booboo review and applies automated fixes
|
|
5
|
-
* for the issues found. Works sequentially through fixable issues.
|
|
6
|
-
*/
|
|
7
|
-
import * as nodeFs from "node:fs";
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
import { getSourceFiles } from "../clients/scan-utils.js";
|
|
10
|
-
import { isTestFile } from "../clients/file-utils.js";
|
|
11
|
-
export async function handleFixFromBooboo(args, ctx, clients, pi) {
|
|
12
|
-
const targetPath = args.trim() || ctx.cwd || process.cwd();
|
|
13
|
-
// Find latest booboo review
|
|
14
|
-
const reviewDir = path.join(targetPath, ".pi-lens", "reviews");
|
|
15
|
-
let latestReview = null;
|
|
16
|
-
// Check if reviews directory exists
|
|
17
|
-
if (!nodeFs.existsSync(reviewDir)) {
|
|
18
|
-
ctx.ui.notify("❌ No /lens-booboo review found (no .pi-lens/reviews directory). Run `/lens-booboo` first.", "error");
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
let jsonFiles = [];
|
|
22
|
-
let detailedReport = "";
|
|
23
|
-
let reportRelPath = ""; // Will hold relative path to markdown report
|
|
24
|
-
try {
|
|
25
|
-
const files = nodeFs.readdirSync(reviewDir);
|
|
26
|
-
jsonFiles = files
|
|
27
|
-
.filter((f) => f.startsWith("booboo-") && f.endsWith(".json"))
|
|
28
|
-
.sort()
|
|
29
|
-
.reverse();
|
|
30
|
-
if (jsonFiles.length === 0) {
|
|
31
|
-
ctx.ui.notify("❌ No /lens-booboo review found. Run `/lens-booboo` first to scan for issues.", "error");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const latestReviewPath = path.join(reviewDir, jsonFiles[0]);
|
|
35
|
-
const fileContent = nodeFs.readFileSync(latestReviewPath, "utf-8");
|
|
36
|
-
latestReview = JSON.parse(fileContent);
|
|
37
|
-
// Load detailed markdown report for specific findings
|
|
38
|
-
const mdFile = jsonFiles[0].replace(".json", ".md");
|
|
39
|
-
const mdPath = path.join(reviewDir, mdFile);
|
|
40
|
-
reportRelPath = path.relative(targetPath, mdPath).replace(/\\/g, "/");
|
|
41
|
-
try {
|
|
42
|
-
detailedReport = nodeFs.readFileSync(mdPath, "utf-8");
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// Ignore - we'll work without details
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
console.error("[fix-from-booboo] Error reading review:", err);
|
|
50
|
-
ctx.ui.notify(`❌ Error reading booboo review: ${err instanceof Error ? err.message : String(err)}`, "error");
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (!latestReview) {
|
|
54
|
-
ctx.ui.notify("❌ Failed to parse booboo review. Run `/lens-booboo` again.", "error");
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
// Check if meta exists
|
|
58
|
-
if (!latestReview.meta) {
|
|
59
|
-
ctx.ui.notify("❌ Invalid booboo review format (missing meta). Run `/lens-booboo` again.", "error");
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// Use meta properties directly (summary object doesn't exist in JSON)
|
|
63
|
-
const totalIssues = latestReview.meta.totalIssues ?? 0;
|
|
64
|
-
const fixableCount = latestReview.meta.fixableCount ?? 0;
|
|
65
|
-
const refactorNeeded = latestReview.meta.refactorNeeded ?? 0;
|
|
66
|
-
const timestamp = latestReview.meta.timestamp ?? "unknown";
|
|
67
|
-
const runners = latestReview.meta.runners ?? [];
|
|
68
|
-
ctx.ui.notify(`🔧 Fixing from review: ${timestamp} (${fixableCount} fixable issues)`, "info");
|
|
69
|
-
const results = [];
|
|
70
|
-
let fixedCount = 0;
|
|
71
|
-
const isTsProject = nodeFs.existsSync(path.join(targetPath, "tsconfig.json"));
|
|
72
|
-
// Get source files with SAME exclusions as booboo uses
|
|
73
|
-
// 1. Start with scan-utils getSourceFiles (excludes EXCLUDED_DIRS)
|
|
74
|
-
// 2. Filter out test files (matches booboo's shouldIncludeFile)
|
|
75
|
-
// 3. Filter out compiled .js in TS projects (same as booboo)
|
|
76
|
-
const sourceFiles = getSourceFiles(targetPath, isTsProject).filter(file => {
|
|
77
|
-
// Match booboo's shouldIncludeFile: exclude test files
|
|
78
|
-
if (isTestFile(file))
|
|
79
|
-
return false;
|
|
80
|
-
// Match booboo's TS project compiled JS exclusion
|
|
81
|
-
if (isTsProject && file.endsWith(".js") && nodeFs.existsSync(file.replace(/\.js$/, ".ts"))) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
return true;
|
|
85
|
-
});
|
|
86
|
-
ctx.ui.notify(`🔧 Found ${sourceFiles.length} source file(s) to check (tests/excluded dirs skipped)`, "info");
|
|
87
|
-
// 1. Biome auto-fixes for TS/JS files - run once on all files for efficiency
|
|
88
|
-
if (clients.biome.isAvailable()) {
|
|
89
|
-
const biomeFiles = sourceFiles.filter(f => clients.biome.isSupportedFile(f));
|
|
90
|
-
if (biomeFiles.length > 0) {
|
|
91
|
-
ctx.ui.notify(`🔧 Running Biome on ${biomeFiles.length} file(s)...`, "info");
|
|
92
|
-
const biomeResult = clients.biome.fixFiles(biomeFiles);
|
|
93
|
-
if (biomeResult.success && biomeResult.fixed > 0) {
|
|
94
|
-
fixedCount += biomeResult.fixed;
|
|
95
|
-
results.push(`✅ Biome: Fixed ${biomeResult.fixed} issue(s) in ${biomeFiles.length} file(s)`);
|
|
96
|
-
}
|
|
97
|
-
else if (biomeResult.success) {
|
|
98
|
-
results.push(`✅ Biome: No issues found in ${biomeFiles.length} file(s)`);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
results.push(`⚠️ Biome: ${biomeResult.error || "Failed to run"}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// 2. Ruff auto-fixes for Python files - run once on all files for efficiency
|
|
106
|
-
if (clients.ruff.isAvailable()) {
|
|
107
|
-
const pythonFiles = sourceFiles.filter(f => f.endsWith(".py"));
|
|
108
|
-
if (pythonFiles.length > 0) {
|
|
109
|
-
ctx.ui.notify(`🔧 Running Ruff on ${pythonFiles.length} Python file(s)...`, "info");
|
|
110
|
-
const ruffResult = clients.ruff.fixFiles(pythonFiles);
|
|
111
|
-
if (ruffResult.success && ruffResult.fixed > 0) {
|
|
112
|
-
fixedCount += ruffResult.fixed;
|
|
113
|
-
results.push(`✅ Ruff: Fixed ${ruffResult.fixed} issue(s) in ${pythonFiles.length} file(s)`);
|
|
114
|
-
}
|
|
115
|
-
else if (ruffResult.success) {
|
|
116
|
-
results.push(`✅ Ruff: No issues found in ${pythonFiles.length} file(s)`);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
results.push(`⚠️ Ruff: ${ruffResult.error || "Failed to run"}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// 3. Categorize findings for agent dispatch
|
|
124
|
-
const agentTasks = [];
|
|
125
|
-
const deferredToRefactor = [];
|
|
126
|
-
const informational = [];
|
|
127
|
-
// Parse detailed report sections to build specific tasks
|
|
128
|
-
const reportSections = parseReportSections(detailedReport);
|
|
129
|
-
// Check for issues from booboo review runners and dispatch appropriately
|
|
130
|
-
for (const runner of runners) {
|
|
131
|
-
if (runner.findings === 0)
|
|
132
|
-
continue;
|
|
133
|
-
switch (runner.name) {
|
|
134
|
-
case "ast-grep (design smells)": {
|
|
135
|
-
// AST-grep issues can often be fixed immediately by agent
|
|
136
|
-
const section = reportSections["ast-grep"];
|
|
137
|
-
if (section) {
|
|
138
|
-
const files = extractFilesFromSection(section);
|
|
139
|
-
agentTasks.push({
|
|
140
|
-
type: "ast-grep",
|
|
141
|
-
priority: 1,
|
|
142
|
-
prompt: `**AST Structural Issues** (${runner.findings} found)\n\nFix design smell issues in:\n${files.map(f => `- ${f}`).join("\n")}\n\nReview the /lens-booboo report for specific rule violations and apply fixes. Focus on: extracting nested logic, reducing parameter lists, converting callbacks to async/await, and removing redundant code.`,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
case "ast-grep (similar functions)": {
|
|
148
|
-
// Similar functions need major refactoring - defer
|
|
149
|
-
deferredToRefactor.push(`${runner.findings} groups of similar functions - use "/lens-booboo-refactor --mode=extract-helpers"`);
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
case "semantic similarity (Amain)": {
|
|
153
|
-
// Semantic duplicates need major refactoring - defer
|
|
154
|
-
deferredToRefactor.push(`${runner.findings} semantic duplicate pairs - use "/lens-booboo-refactor --mode=consolidate"`);
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
case "complexity metrics": {
|
|
158
|
-
// High complexity can sometimes be reduced immediately
|
|
159
|
-
const section = reportSections["Complexity Metrics"];
|
|
160
|
-
if (section) {
|
|
161
|
-
const highCogFiles = extractComplexityFiles(section);
|
|
162
|
-
if (highCogFiles.length > 0) {
|
|
163
|
-
agentTasks.push({
|
|
164
|
-
type: "complexity",
|
|
165
|
-
priority: 2,
|
|
166
|
-
prompt: `**Complexity Reduction** (${highCogFiles.length} high-complexity files)\n\nReduce cognitive complexity in:\n${highCogFiles.slice(0, 5).map(f => `- ${f.file} (cognitive: ${f.cognitive})`).join("\n")}${highCogFiles.length > 5 ? `\n- ... and ${highCogFiles.length - 5} more` : ""}\n\nApply these techniques:\n1. Extract nested logic into named functions\n2. Use early returns to reduce nesting\n3. Replace nested if/else with switch or lookup tables\n4. Simplify boolean expressions\n\nRun "/lens-booboo-refactor --mode=reduce-complexity" for major cases.`,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
case "duplicate code (jscpd)": {
|
|
173
|
-
// Duplicates need extraction - defer to refactor
|
|
174
|
-
deferredToRefactor.push(`${runner.findings} duplicate code blocks - use "/lens-booboo-refactor --mode=extract-helpers"`);
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
case "dead code (Knip)": {
|
|
178
|
-
// Dead code can be removed immediately
|
|
179
|
-
const section = reportSections["Dead Code"];
|
|
180
|
-
if (section) {
|
|
181
|
-
const deadItems = extractDeadCodeItems(section);
|
|
182
|
-
if (deadItems.length > 0) {
|
|
183
|
-
agentTasks.push({
|
|
184
|
-
type: "dead-code",
|
|
185
|
-
priority: 1, // High priority - safe to remove
|
|
186
|
-
prompt: `**Dead Code Removal** (${runner.findings} items)\n\nRemove unused code:\n${deadItems.slice(0, 10).map(i => `- [${i.type}] ${i.name} in ${i.file || "unknown"}`).join("\n")}${deadItems.length > 10 ? `\n- ... and ${deadItems.length - 10} more` : ""}\n\nCheck each item is truly unused (not dynamically imported or called via reflection), then safely remove.`,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
case "type coverage": {
|
|
193
|
-
// Type coverage issues - agent can add types
|
|
194
|
-
const section = reportSections["Type Coverage"];
|
|
195
|
-
if (section) {
|
|
196
|
-
const untypedFiles = extractUntypedFiles(section);
|
|
197
|
-
if (untypedFiles.length > 0) {
|
|
198
|
-
agentTasks.push({
|
|
199
|
-
type: "types",
|
|
200
|
-
priority: 3,
|
|
201
|
-
prompt: `**Add Type Annotations** (${untypedFiles.length} files with untyped identifiers)\n\nAdd explicit types to improve type coverage in:\n${untypedFiles.slice(0, 5).map(f => `- ${f.file} (${f.count} untyped)`).join("\n")}${untypedFiles.length > 5 ? `\n- ... and ${untypedFiles.length - 5} more` : ""}\n\nFocus on:\n1. Function parameters and return types\n2. Variable declarations with 'any'\n3. Object literal types\n4. Event handler signatures`,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
case "circular deps (Madge)": {
|
|
208
|
-
// Circular deps need architectural refactoring - defer
|
|
209
|
-
deferredToRefactor.push(`${runner.findings} circular dependency chains - use "/lens-booboo-refactor --mode=break-circular"`);
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
case "architectural rules": {
|
|
213
|
-
// Some architectural issues can be fixed immediately
|
|
214
|
-
const section = reportSections["Architectural Rules"];
|
|
215
|
-
if (section) {
|
|
216
|
-
const archIssues = extractArchitecturalIssues(section);
|
|
217
|
-
if (archIssues.length > 0) {
|
|
218
|
-
agentTasks.push({
|
|
219
|
-
type: "architectural",
|
|
220
|
-
priority: 2,
|
|
221
|
-
prompt: `**Fix Architectural Violations** (${runner.findings} violations)\n\nFix these architectural issues:\n${archIssues.slice(0, 10).map(i => `- ${i.file}: ${i.message}`).join("\n")}${archIssues.length > 10 ? `\n- ... and ${archIssues.length - 10} more` : ""}\n\nFocus on:\n1. Replace 'any' types with proper types or 'unknown'\n2. Fix absolute paths to use path.join()\n3. Extract deeply nested functions\n4. Reduce long parameter lists with options objects`,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
case "TODO scanner": {
|
|
228
|
-
informational.push(`${runner.findings} TODOs/annotations - informational only`);
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
// Build summary report
|
|
234
|
-
const outputParts = [
|
|
235
|
-
`🔧 /lens-booboo-fix from ${timestamp}`,
|
|
236
|
-
`Found ${totalIssues} total issues, ${fixableCount} fixable`,
|
|
237
|
-
"",
|
|
238
|
-
"=== Automatic Fixes (Biome/Ruff) ===",
|
|
239
|
-
...(results.length > 0 ? results : ["ℹ️ No automatic fixes applied"]),
|
|
240
|
-
"",
|
|
241
|
-
];
|
|
242
|
-
// Add agent tasks
|
|
243
|
-
if (agentTasks.length > 0) {
|
|
244
|
-
outputParts.push(`=== Agent Work Queue (${agentTasks.length} task groups) ===`);
|
|
245
|
-
agentTasks.sort((a, b) => a.priority - b.priority);
|
|
246
|
-
for (const task of agentTasks) {
|
|
247
|
-
outputParts.push(`\n🎯 **${task.type.toUpperCase()}** (Priority: ${task.priority})`);
|
|
248
|
-
}
|
|
249
|
-
outputParts.push("");
|
|
250
|
-
}
|
|
251
|
-
// Add deferred items
|
|
252
|
-
if (deferredToRefactor.length > 0) {
|
|
253
|
-
outputParts.push("=== Deferred to /lens-booboo-refactor ===");
|
|
254
|
-
for (const item of deferredToRefactor) {
|
|
255
|
-
outputParts.push(`⏭️ ${item}`);
|
|
256
|
-
}
|
|
257
|
-
outputParts.push("");
|
|
258
|
-
}
|
|
259
|
-
// Add informational
|
|
260
|
-
if (informational.length > 0) {
|
|
261
|
-
outputParts.push("=== Informational ===");
|
|
262
|
-
for (const item of informational) {
|
|
263
|
-
outputParts.push(`ℹ️ ${item}`);
|
|
264
|
-
}
|
|
265
|
-
outputParts.push("");
|
|
266
|
-
}
|
|
267
|
-
// Add completion status
|
|
268
|
-
if (fixedCount > 0) {
|
|
269
|
-
outputParts.push(`✅ Fixed ${fixedCount} issue(s) automatically with Biome/Ruff`);
|
|
270
|
-
outputParts.push("");
|
|
271
|
-
}
|
|
272
|
-
outputParts.push("Next steps:");
|
|
273
|
-
if (agentTasks.length > 0) {
|
|
274
|
-
outputParts.push("- Agent will work through the tasks above (priority order)");
|
|
275
|
-
}
|
|
276
|
-
if (deferredToRefactor.length > 0) {
|
|
277
|
-
outputParts.push('- Run "/lens-booboo-refactor" for major structural changes');
|
|
278
|
-
}
|
|
279
|
-
outputParts.push('- Run "/lens-booboo" again to verify fixes');
|
|
280
|
-
const message = outputParts.join("\n");
|
|
281
|
-
// Always show summary to user in UI first
|
|
282
|
-
ctx.ui.notify(message, "info");
|
|
283
|
-
// If there are agent tasks, also send a compact prompt to the agent
|
|
284
|
-
if (agentTasks.length > 0) {
|
|
285
|
-
// Sort by priority
|
|
286
|
-
agentTasks.sort((a, b) => a.priority - b.priority);
|
|
287
|
-
// Compact task list - just type and brief description
|
|
288
|
-
const compactTasks = agentTasks.map((t, i) => {
|
|
289
|
-
const briefDesc = t.type === "complexity" ? "reduce cognitive complexity" :
|
|
290
|
-
t.type === "architectural" ? "fix architectural violations" :
|
|
291
|
-
t.type === "dead-code" ? "remove unused code" :
|
|
292
|
-
t.type === "types" ? "add type annotations" :
|
|
293
|
-
t.type === "ast-grep" ? "fix design smells" : "fix issues";
|
|
294
|
-
return `${i + 1}. [P${t.priority}] ${t.type}: ${briefDesc}`;
|
|
295
|
-
}).join("\n");
|
|
296
|
-
// Context-optimized prompt (~500 chars vs 4000+ before)
|
|
297
|
-
const agentPrompt = `🔧 /lens-booboo-fix: ${totalIssues} issues, ${fixableCount} fixable
|
|
298
|
-
|
|
299
|
-
Auto-fixes: ${fixedCount > 0 ? `${fixedCount} issues fixed` : "none applied"}
|
|
300
|
-
|
|
301
|
-
${agentTasks.length} tasks queued (priority order):
|
|
302
|
-
${compactTasks}
|
|
303
|
-
|
|
304
|
-
${deferredToRefactor.length > 0 ? `\nDeferred (${deferredToRefactor.length}): Use /lens-booboo-refactor for major structural changes\n` : ""}
|
|
305
|
-
📄 Read ${reportRelPath} for detailed findings and file locations.
|
|
306
|
-
|
|
307
|
-
Work through tasks in priority order (P1 highest). Read specific sections of the report as needed.`;
|
|
308
|
-
try {
|
|
309
|
-
if (ctx.isIdle()) {
|
|
310
|
-
pi.sendUserMessage(agentPrompt);
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
pi.sendUserMessage(agentPrompt, { deliverAs: "steer" });
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
catch (err) {
|
|
317
|
-
console.error("[fix-from-booboo] sendUserMessage failed:", err);
|
|
318
|
-
// Error already logged, UI already notified with summary
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function parseReportSections(report) {
|
|
323
|
-
const sections = {};
|
|
324
|
-
if (!report)
|
|
325
|
-
return sections;
|
|
326
|
-
// Split on ## headers
|
|
327
|
-
const parts = report.split(/^## /m);
|
|
328
|
-
for (const part of parts) {
|
|
329
|
-
if (!part.trim())
|
|
330
|
-
continue;
|
|
331
|
-
const lines = part.split("\n");
|
|
332
|
-
const title = lines[0].trim();
|
|
333
|
-
const content = lines.slice(1).join("\n");
|
|
334
|
-
sections[title] = content;
|
|
335
|
-
}
|
|
336
|
-
return sections;
|
|
337
|
-
}
|
|
338
|
-
function extractFilesFromSection(section) {
|
|
339
|
-
const files = [];
|
|
340
|
-
// Match file paths in table rows
|
|
341
|
-
const regex = /\|\s*([^|\n]+\.ts|[^|\n]+\.js|[^|\n]+\.tsx|[^|\n]+\.jsx)\s*\|/g;
|
|
342
|
-
let match;
|
|
343
|
-
while ((match = regex.exec(section)) !== null) {
|
|
344
|
-
const file = match[1].trim();
|
|
345
|
-
if (!files.includes(file))
|
|
346
|
-
files.push(file);
|
|
347
|
-
}
|
|
348
|
-
return files.slice(0, 10); // Limit to first 10
|
|
349
|
-
}
|
|
350
|
-
function extractComplexityFiles(section) {
|
|
351
|
-
const files = [];
|
|
352
|
-
// Match complexity table rows: | file | cognitive |
|
|
353
|
-
const lines = section.split("\n");
|
|
354
|
-
for (const line of lines) {
|
|
355
|
-
const match = line.match(/\|\s*([^|]+\.ts|[^|]+\.js)\s*\|\s*(\d+)\s*\|/);
|
|
356
|
-
if (match) {
|
|
357
|
-
files.push({ file: match[1].trim(), cognitive: parseInt(match[2]) });
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
// Match report threshold: Very High Cognitive Complexity (> 30)
|
|
361
|
-
return files.filter(f => f.cognitive > 30).sort((a, b) => b.cognitive - a.cognitive);
|
|
362
|
-
}
|
|
363
|
-
function extractDeadCodeItems(section) {
|
|
364
|
-
const items = [];
|
|
365
|
-
// Match dead code table rows: | type | name | file |
|
|
366
|
-
const lines = section.split("\n");
|
|
367
|
-
for (const line of lines) {
|
|
368
|
-
const match = line.match(/\|\s*(\w+)\s*\|\s*([^|]+)\s*\|\s*([^|]*)\s*\|/);
|
|
369
|
-
if (match) {
|
|
370
|
-
items.push({ type: match[1].trim(), name: match[2].trim(), file: match[3]?.trim() || undefined });
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
return items;
|
|
374
|
-
}
|
|
375
|
-
function extractUntypedFiles(section) {
|
|
376
|
-
const files = [];
|
|
377
|
-
// Match file count table rows: | file | count |
|
|
378
|
-
const lines = section.split("\n");
|
|
379
|
-
for (const line of lines) {
|
|
380
|
-
const match = line.match(/\|\s*([^|]+\.ts|[^|]+\.js)\s*\|\s*(\d+)\s*\|/);
|
|
381
|
-
if (match) {
|
|
382
|
-
files.push({ file: match[1].trim(), count: parseInt(match[2]) });
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return files;
|
|
386
|
-
}
|
|
387
|
-
function extractArchitecturalIssues(section) {
|
|
388
|
-
const issues = [];
|
|
389
|
-
// Match bullet points: - **file**: message
|
|
390
|
-
const lines = section.split("\n");
|
|
391
|
-
for (const line of lines) {
|
|
392
|
-
const match = line.match(/-\s*\*\*([^*]+)\*\*:\s*(.+)/);
|
|
393
|
-
if (match) {
|
|
394
|
-
issues.push({ file: match[1].trim(), message: match[2].trim() });
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return issues;
|
|
398
|
-
}
|