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.
Files changed (207) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/package.json +4 -4
  3. package/tsconfig.json +1 -1
  4. package/clients/__tests__/file-time.test.js +0 -216
  5. package/clients/__tests__/file-time.test.ts +0 -276
  6. package/clients/__tests__/format-service.test.js +0 -245
  7. package/clients/__tests__/format-service.test.ts +0 -339
  8. package/clients/__tests__/formatters.test.js +0 -271
  9. package/clients/__tests__/formatters.test.ts +0 -401
  10. package/clients/agent-behavior-client.js +0 -110
  11. package/clients/agent-behavior-client.test.js +0 -94
  12. package/clients/agent-behavior-client.test.ts +0 -116
  13. package/clients/amain-types.js +0 -164
  14. package/clients/architect-client.js +0 -291
  15. package/clients/ast-grep-client.js +0 -253
  16. package/clients/ast-grep-parser.js +0 -84
  17. package/clients/ast-grep-rule-manager.js +0 -89
  18. package/clients/ast-grep-types.js +0 -9
  19. package/clients/auto-loop.js +0 -131
  20. package/clients/biome-client.js +0 -420
  21. package/clients/biome-client.test.js +0 -144
  22. package/clients/biome-client.test.ts +0 -163
  23. package/clients/cache/rule-cache.js +0 -72
  24. package/clients/cache-manager.js +0 -245
  25. package/clients/cache-manager.test.js +0 -197
  26. package/clients/cache-manager.test.ts +0 -299
  27. package/clients/complexity-client.js +0 -675
  28. package/clients/complexity-client.test.js +0 -234
  29. package/clients/complexity-client.test.ts +0 -255
  30. package/clients/config-validator.js +0 -465
  31. package/clients/dependency-checker.js +0 -325
  32. package/clients/dependency-checker.test.js +0 -60
  33. package/clients/dependency-checker.test.ts +0 -71
  34. package/clients/dispatch/__tests__/autofix-integration.test.js +0 -245
  35. package/clients/dispatch/__tests__/autofix-integration.test.ts +0 -300
  36. package/clients/dispatch/__tests__/runner-registration.test.js +0 -234
  37. package/clients/dispatch/__tests__/runner-registration.test.ts +0 -286
  38. package/clients/dispatch/debug.log +0 -1
  39. package/clients/dispatch/dispatcher.edge.test.js +0 -82
  40. package/clients/dispatch/dispatcher.edge.test.ts +0 -100
  41. package/clients/dispatch/dispatcher.format.test.js +0 -46
  42. package/clients/dispatch/dispatcher.format.test.ts +0 -58
  43. package/clients/dispatch/dispatcher.inline.test.js +0 -74
  44. package/clients/dispatch/dispatcher.inline.test.ts +0 -93
  45. package/clients/dispatch/dispatcher.js +0 -381
  46. package/clients/dispatch/dispatcher.test.js +0 -116
  47. package/clients/dispatch/dispatcher.test.ts +0 -149
  48. package/clients/dispatch/integration.js +0 -108
  49. package/clients/dispatch/plan.js +0 -183
  50. package/clients/dispatch/runners/architect.js +0 -83
  51. package/clients/dispatch/runners/architect.test.js +0 -138
  52. package/clients/dispatch/runners/architect.test.ts +0 -162
  53. package/clients/dispatch/runners/ast-grep-napi.js +0 -405
  54. package/clients/dispatch/runners/ast-grep-napi.test.js +0 -107
  55. package/clients/dispatch/runners/ast-grep-napi.test.ts +0 -129
  56. package/clients/dispatch/runners/ast-grep.js +0 -157
  57. package/clients/dispatch/runners/biome.js +0 -55
  58. package/clients/dispatch/runners/config-validation.js +0 -67
  59. package/clients/dispatch/runners/go-vet.js +0 -48
  60. package/clients/dispatch/runners/index.js +0 -47
  61. package/clients/dispatch/runners/lsp.js +0 -102
  62. package/clients/dispatch/runners/oxlint.js +0 -67
  63. package/clients/dispatch/runners/oxlint.test.js +0 -230
  64. package/clients/dispatch/runners/oxlint.test.ts +0 -303
  65. package/clients/dispatch/runners/pyright.js +0 -100
  66. package/clients/dispatch/runners/pyright.test.js +0 -98
  67. package/clients/dispatch/runners/pyright.test.ts +0 -121
  68. package/clients/dispatch/runners/python-slop.js +0 -97
  69. package/clients/dispatch/runners/python-slop.test.js +0 -203
  70. package/clients/dispatch/runners/python-slop.test.ts +0 -298
  71. package/clients/dispatch/runners/ruff.js +0 -48
  72. package/clients/dispatch/runners/rust-clippy.js +0 -102
  73. package/clients/dispatch/runners/scan_codebase.test.js +0 -89
  74. package/clients/dispatch/runners/scan_codebase.test.ts +0 -105
  75. package/clients/dispatch/runners/shellcheck.js +0 -147
  76. package/clients/dispatch/runners/shellcheck.test.js +0 -98
  77. package/clients/dispatch/runners/shellcheck.test.ts +0 -129
  78. package/clients/dispatch/runners/similarity.js +0 -230
  79. package/clients/dispatch/runners/spellcheck.js +0 -106
  80. package/clients/dispatch/runners/spellcheck.test.js +0 -158
  81. package/clients/dispatch/runners/spellcheck.test.ts +0 -214
  82. package/clients/dispatch/runners/tree-sitter.js +0 -246
  83. package/clients/dispatch/runners/ts-lsp.js +0 -125
  84. package/clients/dispatch/runners/ts-slop.js +0 -113
  85. package/clients/dispatch/runners/type-safety.js +0 -142
  86. package/clients/dispatch/runners/utils/diagnostic-parsers.js +0 -134
  87. package/clients/dispatch/runners/utils/runner-helpers.js +0 -115
  88. package/clients/dispatch/runners/utils.js +0 -51
  89. package/clients/dispatch/runners/yaml-rule-parser.js +0 -360
  90. package/clients/dispatch/types.js +0 -16
  91. package/clients/dispatch/utils/format-utils.js +0 -44
  92. package/clients/dogfood.test.js +0 -201
  93. package/clients/dogfood.test.ts +0 -269
  94. package/clients/file-kinds.js +0 -177
  95. package/clients/file-kinds.test.js +0 -169
  96. package/clients/file-kinds.test.ts +0 -210
  97. package/clients/file-time.js +0 -152
  98. package/clients/file-utils.js +0 -40
  99. package/clients/fix-scanners.js +0 -204
  100. package/clients/format-service.js +0 -184
  101. package/clients/formatters.js +0 -488
  102. package/clients/go-client.js +0 -203
  103. package/clients/go-client.test.js +0 -127
  104. package/clients/go-client.test.ts +0 -143
  105. package/clients/installer/index.js +0 -403
  106. package/clients/interviewer-templates.js +0 -75
  107. package/clients/interviewer.js +0 -173
  108. package/clients/jscpd-client.js +0 -196
  109. package/clients/jscpd-client.test.js +0 -127
  110. package/clients/jscpd-client.test.ts +0 -145
  111. package/clients/knip-client.js +0 -239
  112. package/clients/knip-client.test.js +0 -112
  113. package/clients/knip-client.test.ts +0 -128
  114. package/clients/latency-logger.js +0 -40
  115. package/clients/lsp/__tests__/client.test.js +0 -310
  116. package/clients/lsp/__tests__/client.test.ts +0 -412
  117. package/clients/lsp/__tests__/config.test.js +0 -167
  118. package/clients/lsp/__tests__/config.test.ts +0 -217
  119. package/clients/lsp/__tests__/error-recovery.test.js +0 -213
  120. package/clients/lsp/__tests__/error-recovery.test.ts +0 -279
  121. package/clients/lsp/__tests__/integration.test.js +0 -127
  122. package/clients/lsp/__tests__/integration.test.ts +0 -160
  123. package/clients/lsp/__tests__/launch.test.js +0 -313
  124. package/clients/lsp/__tests__/launch.test.ts +0 -394
  125. package/clients/lsp/__tests__/server.test.js +0 -259
  126. package/clients/lsp/__tests__/server.test.ts +0 -332
  127. package/clients/lsp/__tests__/service.test.js +0 -438
  128. package/clients/lsp/__tests__/service.test.ts +0 -530
  129. package/clients/lsp/client.js +0 -350
  130. package/clients/lsp/config.js +0 -112
  131. package/clients/lsp/index.js +0 -318
  132. package/clients/lsp/installer/index.js +0 -391
  133. package/clients/lsp/interactive-install.js +0 -221
  134. package/clients/lsp/language.js +0 -170
  135. package/clients/lsp/launch.js +0 -329
  136. package/clients/lsp/lsp/launch.js +0 -116
  137. package/clients/lsp/lsp/server.js +0 -532
  138. package/clients/lsp/lsp-index.js +0 -10
  139. package/clients/lsp/path-utils.js +0 -5
  140. package/clients/lsp/server.js +0 -725
  141. package/clients/lsp/test-py-spawn/requirements.txt +0 -1
  142. package/clients/lsp/test-py-spawn/test.py +0 -3
  143. package/clients/lsp/test-py-svc/requirements.txt +0 -1
  144. package/clients/lsp/test-py-svc/test.py +0 -3
  145. package/clients/lsp/test-python-project/requirements.txt +0 -1
  146. package/clients/lsp/test-python-project/test.py +0 -5
  147. package/clients/metrics-client.js +0 -107
  148. package/clients/metrics-client.test.js +0 -128
  149. package/clients/metrics-client.test.ts +0 -163
  150. package/clients/metrics-history.js +0 -367
  151. package/clients/path-utils.js +0 -142
  152. package/clients/pipeline.js +0 -272
  153. package/clients/production-readiness.js +0 -522
  154. package/clients/project-index.js +0 -255
  155. package/clients/project-metadata.js +0 -531
  156. package/clients/ruff-client.js +0 -325
  157. package/clients/ruff-client.test.js +0 -132
  158. package/clients/ruff-client.test.ts +0 -153
  159. package/clients/rules-scanner.js +0 -97
  160. package/clients/runner-tracker.js +0 -152
  161. package/clients/rust-client.js +0 -205
  162. package/clients/rust-client.test.js +0 -108
  163. package/clients/rust-client.test.ts +0 -130
  164. package/clients/safe-spawn-async.js +0 -163
  165. package/clients/safe-spawn.js +0 -241
  166. package/clients/sanitize.js +0 -291
  167. package/clients/sanitize.test.js +0 -177
  168. package/clients/sanitize.test.ts +0 -223
  169. package/clients/scan-architectural-debt.js +0 -167
  170. package/clients/scan-utils.js +0 -83
  171. package/clients/secrets-scanner.js +0 -119
  172. package/clients/secrets-scanner.test.js +0 -100
  173. package/clients/secrets-scanner.test.ts +0 -113
  174. package/clients/sg-runner.js +0 -292
  175. package/clients/state-matrix.js +0 -160
  176. package/clients/subprocess-client.js +0 -65
  177. package/clients/symbol-types.js +0 -5
  178. package/clients/test-runner-client.js +0 -523
  179. package/clients/test-runner-client.test.js +0 -192
  180. package/clients/test-runner-client.test.ts +0 -253
  181. package/clients/test-utils.js +0 -27
  182. package/clients/test-utils.ts +0 -36
  183. package/clients/todo-scanner.js +0 -200
  184. package/clients/todo-scanner.test.js +0 -301
  185. package/clients/todo-scanner.test.ts +0 -352
  186. package/clients/tool-availability.js +0 -207
  187. package/clients/tree-sitter-client.js +0 -601
  188. package/clients/tree-sitter-query-loader.js +0 -355
  189. package/clients/tree-sitter-symbol-extractor.js +0 -289
  190. package/clients/ts-service.js +0 -129
  191. package/clients/type-coverage-client.js +0 -127
  192. package/clients/type-coverage-client.test.js +0 -105
  193. package/clients/type-coverage-client.test.ts +0 -125
  194. package/clients/type-safety-client.js +0 -138
  195. package/clients/types.js +0 -11
  196. package/clients/typescript-client.codefix.test.js +0 -157
  197. package/clients/typescript-client.codefix.test.ts +0 -186
  198. package/clients/typescript-client.js +0 -509
  199. package/clients/typescript-client.test.js +0 -105
  200. package/clients/typescript-client.test.ts +0 -126
  201. package/commands/booboo.js +0 -1007
  202. package/commands/fix-from-booboo.js +0 -398
  203. package/commands/fix-simplified.js +0 -618
  204. package/commands/rate.js +0 -281
  205. package/commands/rate.test.js +0 -119
  206. package/commands/rate.test.ts +0 -131
  207. package/commands/refactor.js +0 -130
package/commands/rate.js DELETED
@@ -1,281 +0,0 @@
1
- /**
2
- * /lens-rate command
3
- *
4
- * Provides a visual scoring breakdown of code quality across multiple dimensions.
5
- * Uses existing scan data to calculate scores.
6
- */
7
- import * as nodeFs from "node:fs";
8
- import * as path from "node:path";
9
- import { safeSpawn } from "../clients/safe-spawn.js";
10
- import { EXCLUDED_DIRS, isTestFile } from "../clients/file-utils.js";
11
- import { getSourceFiles } from "../clients/scan-utils.js";
12
- /**
13
- * Run all scans and calculate scores
14
- */
15
- export async function gatherScores(targetPath, clients) {
16
- const isTsProject = nodeFs.existsSync(path.join(targetPath, "tsconfig.json"));
17
- const files = getSourceFiles(targetPath, isTsProject);
18
- const categories = [];
19
- // ─── Type Safety ───
20
- let typeCoverageScore = 100;
21
- const typeIssues = [];
22
- if (clients.typeCoverage.isAvailable()) {
23
- const result = clients.typeCoverage.scan(targetPath);
24
- if (result.success) {
25
- typeCoverageScore = result.percentage;
26
- if (result.percentage < 90) {
27
- typeIssues.push(`${result.total - result.typed} untyped identifiers`);
28
- }
29
- }
30
- }
31
- categories.push({
32
- name: "Type Safety",
33
- score: Math.round(typeCoverageScore),
34
- icon: "šŸ”·",
35
- issues: typeIssues,
36
- });
37
- // ─── Complexity ───
38
- let complexityScore = 100;
39
- const complexityIssues = [];
40
- let totalScore = 0;
41
- let fileCount = 0;
42
- let worstFile = "";
43
- let worstScore = 100;
44
- for (const file of files.slice(0, 50)) {
45
- if (clients.complexity.isSupportedFile(file)) {
46
- const metrics = clients.complexity.analyzeFile(file);
47
- if (metrics) {
48
- totalScore += metrics.maintainabilityIndex;
49
- fileCount++;
50
- if (metrics.maintainabilityIndex < worstScore) {
51
- worstScore = metrics.maintainabilityIndex;
52
- worstFile = path.basename(file);
53
- }
54
- }
55
- }
56
- }
57
- if (fileCount > 0) {
58
- complexityScore = totalScore / fileCount;
59
- if (complexityScore < 70) {
60
- complexityIssues.push(`High complexity: ${worstFile}`);
61
- }
62
- }
63
- categories.push({
64
- name: "Complexity",
65
- score: Math.round(complexityScore),
66
- icon: "🧩",
67
- issues: complexityIssues,
68
- });
69
- // ─── Security ───
70
- let securityScore = 100;
71
- const securityIssues = [];
72
- let secretsFound = 0;
73
- // Check for secrets in source files (skip test files)
74
- const secretPatterns = [
75
- { name: "API Key (sk-)", pattern: /sk-[a-zA-Z0-9]{20,}/ },
76
- { name: "GitHub Token", pattern: /ghp_[a-zA-Z0-9]{36}/ },
77
- { name: "AWS Key", pattern: /AKIA[A-Z0-9]{16}/ },
78
- { name: "Anthropic Key", pattern: /sk-ant-[a-zA-Z0-9]{20,}/ },
79
- { name: "OpenAI Key", pattern: /sk-proj-[a-zA-Z0-9]{20,}/ },
80
- {
81
- name: "Private Key",
82
- pattern: /-----BEGIN (?:RSA |EC |DSA )?PRIVATE KEY-----/,
83
- },
84
- ];
85
- for (const file of files.slice(0, 100)) {
86
- // Skip test files
87
- if (isTestFile(file))
88
- continue;
89
- try {
90
- const content = nodeFs.readFileSync(file, "utf-8");
91
- for (const line of content.split("\n")) {
92
- if (line.trim().startsWith("//") || line.trim().startsWith("#"))
93
- continue;
94
- for (const { name, pattern } of secretPatterns) {
95
- if (pattern.test(line)) {
96
- secretsFound++;
97
- if (securityIssues.length < 3) {
98
- securityIssues.push(`${name} in ${path.basename(file)}`);
99
- }
100
- }
101
- }
102
- }
103
- }
104
- catch (err) {
105
- // Skip unreadable files
106
- void err;
107
- }
108
- }
109
- securityScore = Math.max(0, 100 - secretsFound * 15);
110
- categories.push({
111
- name: "Security",
112
- score: securityScore,
113
- icon: "šŸ”’",
114
- issues: securityIssues,
115
- });
116
- // ─── Architecture ───
117
- let archScore = 100;
118
- const archIssues = [];
119
- clients.architect.loadConfig(targetPath);
120
- if (clients.architect.hasConfig()) {
121
- let archViolations = 0;
122
- const scanDir = (dir) => {
123
- for (const entry of nodeFs.readdirSync(dir, { withFileTypes: true })) {
124
- const full = path.join(dir, entry.name);
125
- if (entry.isDirectory()) {
126
- if (EXCLUDED_DIRS.includes(entry.name))
127
- continue;
128
- scanDir(full);
129
- }
130
- else if (/\.(ts|tsx|js|jsx|py|go|rs)$/.test(entry.name)) {
131
- const relPath = path.relative(targetPath, full).replace(/\\/g, "/");
132
- const content = nodeFs.readFileSync(full, "utf-8");
133
- const violations = clients.architect.checkFile(relPath, content);
134
- archViolations += violations.length;
135
- if (violations.length > 0 && archIssues.length < 3) {
136
- archIssues.push(`${violations.length} in ${path.basename(full)}`);
137
- }
138
- const sizeV = clients.architect.checkFileSize(relPath, content.split("\n").length);
139
- if (sizeV)
140
- archViolations++;
141
- }
142
- }
143
- };
144
- scanDir(targetPath);
145
- archScore = Math.max(0, 100 - archViolations * 10);
146
- }
147
- categories.push({
148
- name: "Architecture",
149
- score: archScore,
150
- icon: "šŸ—ļø",
151
- issues: archIssues,
152
- });
153
- // ─── Dead Code ───
154
- let deadCodeScore = 100;
155
- const deadCodeIssues = [];
156
- if (clients.knip.isAvailable()) {
157
- const result = clients.knip.analyze(targetPath);
158
- if (result.success) {
159
- const unusedExports = result.unusedExports.length;
160
- const unusedFiles = result.unusedFiles.length;
161
- const total = unusedExports + unusedFiles;
162
- deadCodeScore = Math.max(0, 100 - total * 3);
163
- if (unusedExports > 0) {
164
- deadCodeIssues.push(`${unusedExports} unused export(s)`);
165
- }
166
- if (unusedFiles > 0) {
167
- deadCodeIssues.push(`${unusedFiles} unused file(s)`);
168
- }
169
- }
170
- }
171
- categories.push({
172
- name: "Dead Code",
173
- score: deadCodeScore,
174
- icon: "šŸ—‘ļø",
175
- issues: deadCodeIssues,
176
- });
177
- // ─── Tests ───
178
- let testScore = 100;
179
- const testIssues = [];
180
- // Quick test run
181
- try {
182
- const testResult = safeSpawn("npx", ["vitest", "run", "--reporter=basic"], {
183
- timeout: 60000,
184
- cwd: targetPath,
185
- });
186
- if (testResult.status !== 0) {
187
- const output = (testResult.stdout || "") + (testResult.stderr || "");
188
- if (output.includes("failed")) {
189
- // Count failing tests
190
- const failMatch = output.match(/(\d+) failed/);
191
- testScore = 50;
192
- testIssues.push(failMatch ? `${failMatch[1]} test(s) failing` : "Some tests failing");
193
- }
194
- else {
195
- testScore = 70;
196
- testIssues.push("Tests timed out or errored");
197
- }
198
- }
199
- }
200
- catch {
201
- testScore = 70;
202
- testIssues.push("Could not run tests");
203
- }
204
- categories.push({
205
- name: "Tests",
206
- score: testScore,
207
- icon: "āœ…",
208
- issues: testIssues,
209
- });
210
- // ─── Calculate Overall ───
211
- const overall = Math.round(categories.reduce((sum, c) => sum + c.score, 0) / categories.length);
212
- return { overall, categories };
213
- }
214
- /**
215
- * Format score as a bar
216
- */
217
- function scoreBar(score, width = 10) {
218
- const filled = Math.round((score / 100) * width);
219
- const empty = width - filled;
220
- const color = score >= 80 ? "🟩" : score >= 60 ? "🟨" : "🟄";
221
- return color.repeat(filled) + "⬜".repeat(empty);
222
- }
223
- /**
224
- * Get grade from score
225
- */
226
- function getGrade(score) {
227
- if (score >= 90)
228
- return "A";
229
- if (score >= 80)
230
- return "B";
231
- if (score >= 70)
232
- return "C";
233
- if (score >= 60)
234
- return "D";
235
- return "F";
236
- }
237
- /**
238
- * Format rate result for terminal
239
- */
240
- export function formatRateResult(result) {
241
- const lines = [];
242
- lines.push("ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”");
243
- const gradeText = ` (${getGrade(result.overall)})`;
244
- const scoreText = `šŸ“Š CODE QUALITY SCORE: ${result.overall}/100${gradeText}`;
245
- const padding = Math.max(0, 55 - scoreText.length);
246
- lines.push(`│ ${scoreText}${" ".repeat(padding)}│`);
247
- lines.push("ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤");
248
- for (const cat of result.categories) {
249
- const name = cat.name.padEnd(14);
250
- const bar = scoreBar(cat.score);
251
- const score = String(cat.score).padStart(3);
252
- lines.push(`│ ${cat.icon} ${name} ${bar} ${score} │`);
253
- }
254
- lines.push("ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜");
255
- // Show issues if any
256
- const allIssues = result.categories
257
- .filter((c) => c.issues.length > 0)
258
- .flatMap((c) => c.issues.map((i) => `${c.icon} ${c.name}: ${i}`));
259
- if (allIssues.length > 0) {
260
- lines.push("");
261
- lines.push("Issues to address:");
262
- for (const issue of allIssues.slice(0, 5)) {
263
- lines.push(` • ${issue}`);
264
- }
265
- if (allIssues.length > 5) {
266
- lines.push(` ... and ${allIssues.length - 5} more`);
267
- }
268
- lines.push("");
269
- lines.push("šŸ’” Run /lens-booboo for full details");
270
- }
271
- return lines.join("\n");
272
- }
273
- /**
274
- * Handle /lens-rate command
275
- */
276
- export async function handleRate(args, ctx, clients) {
277
- const targetPath = args.trim() || ctx.cwd || process.cwd();
278
- ctx.ui.notify("šŸ“Š Calculating code quality scores...", "info");
279
- const result = await gatherScores(targetPath, clients);
280
- return formatRateResult(result);
281
- }
@@ -1,119 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { formatRateResult } from "./rate.js";
3
- // Test the formatting functions directly with mock data
4
- describe("formatRateResult", () => {
5
- it("should format a visual score breakdown", () => {
6
- const result = {
7
- overall: 75,
8
- categories: [
9
- { name: "Type Safety", score: 85, icon: "šŸ”·", issues: [] },
10
- { name: "Complexity", score: 70, icon: "🧩", issues: [] },
11
- { name: "Security", score: 100, icon: "šŸ”’", issues: [] },
12
- { name: "Architecture", score: 85, icon: "šŸ—ļø", issues: [] },
13
- { name: "Dead Code", score: 100, icon: "šŸ—‘ļø", issues: [] },
14
- { name: "Tests", score: 100, icon: "āœ…", issues: [] },
15
- ],
16
- };
17
- const output = formatRateResult(result);
18
- expect(output).toContain("CODE QUALITY SCORE");
19
- expect(output).toContain("75/100");
20
- expect(output).toContain("Type Safety");
21
- expect(output).toContain("Security");
22
- expect(output).toContain("Tests");
23
- });
24
- it("should show correct grade for A", () => {
25
- const result = {
26
- overall: 95,
27
- categories: Array(6).fill({
28
- name: "Test",
29
- score: 95,
30
- icon: "āœ…",
31
- issues: [],
32
- }),
33
- };
34
- const output = formatRateResult(result);
35
- expect(output).toContain("A");
36
- });
37
- it("should show correct grade for B", () => {
38
- const result = {
39
- overall: 85,
40
- categories: Array(6).fill({
41
- name: "Test",
42
- score: 85,
43
- icon: "āœ…",
44
- issues: [],
45
- }),
46
- };
47
- const output = formatRateResult(result);
48
- expect(output).toContain("B");
49
- });
50
- it("should show correct grade for C", () => {
51
- const result = {
52
- overall: 75,
53
- categories: Array(6).fill({
54
- name: "Test",
55
- score: 75,
56
- icon: "āœ…",
57
- issues: [],
58
- }),
59
- };
60
- const output = formatRateResult(result);
61
- expect(output).toContain("C");
62
- });
63
- it("should show issues section when there are problems", () => {
64
- const result = {
65
- overall: 50,
66
- categories: [
67
- {
68
- name: "Type Safety",
69
- score: 50,
70
- icon: "šŸ”·",
71
- issues: ["50 untyped identifiers"],
72
- },
73
- {
74
- name: "Complexity",
75
- score: 50,
76
- icon: "🧩",
77
- issues: ["High complexity: foo.ts"],
78
- },
79
- { name: "Security", score: 100, icon: "šŸ”’", issues: [] },
80
- { name: "Architecture", score: 100, icon: "šŸ—ļø", issues: [] },
81
- { name: "Dead Code", score: 100, icon: "šŸ—‘ļø", issues: [] },
82
- { name: "Tests", score: 100, icon: "āœ…", issues: [] },
83
- ],
84
- };
85
- const output = formatRateResult(result);
86
- expect(output).toContain("Issues to address");
87
- expect(output).toContain("Type Safety");
88
- expect(output).toContain("/lens-booboo");
89
- });
90
- it("should not show issues section when clean", () => {
91
- const result = {
92
- overall: 100,
93
- categories: Array(6).fill({
94
- name: "Test",
95
- score: 100,
96
- icon: "āœ…",
97
- issues: [],
98
- }),
99
- };
100
- const output = formatRateResult(result);
101
- expect(output).not.toContain("Issues to address");
102
- });
103
- it("should use colored bars based on score", () => {
104
- const resultHigh = {
105
- overall: 90,
106
- categories: [{ name: "Test", score: 85, icon: "āœ…", issues: [] }],
107
- };
108
- const resultLow = {
109
- overall: 50,
110
- categories: [{ name: "Test", score: 50, icon: "āœ…", issues: [] }],
111
- };
112
- const outputHigh = formatRateResult(resultHigh);
113
- const outputLow = formatRateResult(resultLow);
114
- // High score should have green squares
115
- expect(outputHigh).toContain("🟩");
116
- // Low score should have red squares
117
- expect(outputLow).toContain("🟄");
118
- });
119
- });
@@ -1,131 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { formatRateResult } from "./rate.js";
3
-
4
- // Test the formatting functions directly with mock data
5
-
6
- describe("formatRateResult", () => {
7
- it("should format a visual score breakdown", () => {
8
- const result = {
9
- overall: 75,
10
- categories: [
11
- { name: "Type Safety", score: 85, icon: "šŸ”·", issues: [] },
12
- { name: "Complexity", score: 70, icon: "🧩", issues: [] },
13
- { name: "Security", score: 100, icon: "šŸ”’", issues: [] },
14
- { name: "Architecture", score: 85, icon: "šŸ—ļø", issues: [] },
15
- { name: "Dead Code", score: 100, icon: "šŸ—‘ļø", issues: [] },
16
- { name: "Tests", score: 100, icon: "āœ…", issues: [] },
17
- ],
18
- };
19
-
20
- const output = formatRateResult(result);
21
-
22
- expect(output).toContain("CODE QUALITY SCORE");
23
- expect(output).toContain("75/100");
24
- expect(output).toContain("Type Safety");
25
- expect(output).toContain("Security");
26
- expect(output).toContain("Tests");
27
- });
28
-
29
- it("should show correct grade for A", () => {
30
- const result = {
31
- overall: 95,
32
- categories: Array(6).fill({
33
- name: "Test",
34
- score: 95,
35
- icon: "āœ…",
36
- issues: [],
37
- }),
38
- };
39
- const output = formatRateResult(result);
40
- expect(output).toContain("A");
41
- });
42
-
43
- it("should show correct grade for B", () => {
44
- const result = {
45
- overall: 85,
46
- categories: Array(6).fill({
47
- name: "Test",
48
- score: 85,
49
- icon: "āœ…",
50
- issues: [],
51
- }),
52
- };
53
- const output = formatRateResult(result);
54
- expect(output).toContain("B");
55
- });
56
-
57
- it("should show correct grade for C", () => {
58
- const result = {
59
- overall: 75,
60
- categories: Array(6).fill({
61
- name: "Test",
62
- score: 75,
63
- icon: "āœ…",
64
- issues: [],
65
- }),
66
- };
67
- const output = formatRateResult(result);
68
- expect(output).toContain("C");
69
- });
70
-
71
- it("should show issues section when there are problems", () => {
72
- const result = {
73
- overall: 50,
74
- categories: [
75
- {
76
- name: "Type Safety",
77
- score: 50,
78
- icon: "šŸ”·",
79
- issues: ["50 untyped identifiers"],
80
- },
81
- {
82
- name: "Complexity",
83
- score: 50,
84
- icon: "🧩",
85
- issues: ["High complexity: foo.ts"],
86
- },
87
- { name: "Security", score: 100, icon: "šŸ”’", issues: [] },
88
- { name: "Architecture", score: 100, icon: "šŸ—ļø", issues: [] },
89
- { name: "Dead Code", score: 100, icon: "šŸ—‘ļø", issues: [] },
90
- { name: "Tests", score: 100, icon: "āœ…", issues: [] },
91
- ],
92
- };
93
- const output = formatRateResult(result);
94
- expect(output).toContain("Issues to address");
95
- expect(output).toContain("Type Safety");
96
- expect(output).toContain("/lens-booboo");
97
- });
98
-
99
- it("should not show issues section when clean", () => {
100
- const result = {
101
- overall: 100,
102
- categories: Array(6).fill({
103
- name: "Test",
104
- score: 100,
105
- icon: "āœ…",
106
- issues: [],
107
- }),
108
- };
109
- const output = formatRateResult(result);
110
- expect(output).not.toContain("Issues to address");
111
- });
112
-
113
- it("should use colored bars based on score", () => {
114
- const resultHigh = {
115
- overall: 90,
116
- categories: [{ name: "Test", score: 85, icon: "āœ…", issues: [] }],
117
- };
118
- const resultLow = {
119
- overall: 50,
120
- categories: [{ name: "Test", score: 50, icon: "āœ…", issues: [] }],
121
- };
122
-
123
- const outputHigh = formatRateResult(resultHigh);
124
- const outputLow = formatRateResult(resultLow);
125
-
126
- // High score should have green squares
127
- expect(outputHigh).toContain("🟩");
128
- // Low score should have red squares
129
- expect(outputLow).toContain("🟄");
130
- });
131
- });
@@ -1,130 +0,0 @@
1
- import * as nodeFs from "node:fs";
2
- import * as path from "node:path";
3
- import { createAutoLoop } from "../clients/auto-loop.js";
4
- import { scanArchitectViolations, scanComplexityMetrics, scanSkipViolations, scoreFiles, } from "../clients/scan-architectural-debt.js";
5
- // Auto-loop singleton for refactor command (initialized at module load)
6
- let refactorLoop = null;
7
- export function initRefactorLoop(pi) {
8
- if (!refactorLoop) {
9
- refactorLoop = createAutoLoop(pi, {
10
- name: "refactor",
11
- maxIterations: 5,
12
- command: "/lens-booboo-refactor --loop",
13
- exitPatterns: [
14
- /āœ… No architectural debt found/,
15
- /No more files to refactor/,
16
- ],
17
- completionPatterns: [/āœ… No architectural debt found/],
18
- continuePrompt: "Continue to next worst offender with /lens-booboo-refactor --loop",
19
- });
20
- // refactor auto-loop initialized silently
21
- }
22
- return refactorLoop;
23
- }
24
- function getRefactorLoop(pi) {
25
- if (!refactorLoop) {
26
- return initRefactorLoop(pi);
27
- }
28
- return refactorLoop;
29
- }
30
- export async function handleRefactor(args, ctx, clients, pi, skipRules, ruleActions) {
31
- const loopMode = args.includes("--loop");
32
- const cleanArgs = args.replace("--loop", "").trim();
33
- const targetPath = cleanArgs || ctx.cwd || process.cwd();
34
- // Initialize auto-loop if --loop flag
35
- const loop = getRefactorLoop(pi);
36
- if (loopMode && !loop.getState().active) {
37
- loop.start(ctx);
38
- }
39
- ctx.ui.notify("šŸ—ļø Scanning for architectural debt...", "info");
40
- const configPath = path.join(process.cwd(), "rules", "ast-grep-rules", ".sgconfig.yml");
41
- const isTsProject = nodeFs.existsSync(path.join(targetPath, "tsconfig.json"));
42
- const skipByFile = scanSkipViolations(clients.astGrep, configPath, targetPath, isTsProject, skipRules, ruleActions);
43
- const metricsByFile = scanComplexityMetrics(clients.complexity, targetPath, isTsProject);
44
- const architectViolations = clients.architect.hasConfig()
45
- ? scanArchitectViolations(clients.architect, targetPath)
46
- : new Map();
47
- const scored = scoreFiles(skipByFile, metricsByFile, architectViolations);
48
- if (scored.length === 0) {
49
- ctx.ui.notify("āœ… No architectural debt found — codebase is clean.", "info");
50
- return;
51
- }
52
- // --- Write ranked list to TSV for agent reference ---
53
- const reportDir = path.join(process.cwd(), ".pi-lens", "reports");
54
- nodeFs.mkdirSync(reportDir, { recursive: true });
55
- const reportPath = path.join(reportDir, "refactor-ranked.tsv");
56
- const tsvRows = [
57
- "rank\tfile\tscore\tmi\tcognitive\tnesting\tviolations",
58
- ];
59
- scored.slice(0, 50).forEach((f, i) => {
60
- const m = metricsByFile.get(f.file);
61
- const skipCount = skipByFile.get(f.file)?.length ?? 0;
62
- const archCount = architectViolations?.get(f.file)?.length ?? 0;
63
- const totalViolations = skipCount + archCount;
64
- const relPath = path.relative(targetPath, f.file).replace(/\\/g, "/");
65
- tsvRows.push(`${i + 1}\t${relPath}\t${f.score}\t${m?.mi.toFixed(1) ?? "-"}\t${m?.cognitive ?? "-"}\t${m?.nesting ?? "-"}\t${totalViolations}`);
66
- });
67
- nodeFs.writeFileSync(reportPath, tsvRows.join("\n"), "utf-8");
68
- // --- Current worst offender ---
69
- const { file: worstFile, score } = scored[0];
70
- const relFile = path.relative(targetPath, worstFile).replace(/\\/g, "/");
71
- const issues = skipByFile.get(worstFile) ?? [];
72
- const metrics = metricsByFile.get(worstFile);
73
- const archIssues = architectViolations.get(worstFile) ?? [];
74
- const ruleGroups = new Map();
75
- for (const i of issues)
76
- ruleGroups.set(i.rule, (ruleGroups.get(i.rule) ?? 0) + 1);
77
- const issuesSummary = [...ruleGroups.entries()]
78
- .map(([r, n]) => `- \`${r}\` (Ɨ${n})${ruleActions[r] ? ` — ${ruleActions[r].note}` : ""}`)
79
- .join("\n");
80
- const archSummary = archIssues.length > 0 ? archIssues.map((m) => `- ${m}`).join("\n") : "None";
81
- const metricsSummary = metrics
82
- ? `MI: ${metrics.mi.toFixed(1)}, Cognitive: ${metrics.cognitive}, Nesting: ${metrics.nesting}`
83
- : "";
84
- // First violation line for quick reference
85
- const firstViolationLine = issues.length > 0 ? issues[0].line : null;
86
- // --- Full ranked list in terminal (agent won't read TSV) ---
87
- const topFiles = scored
88
- .slice(0, 15)
89
- .map((f, i) => {
90
- const name = path.relative(targetPath, f.file).replace(/\\/g, "/");
91
- const m = metricsByFile.get(f.file);
92
- const mi = m ? `MI:${m.mi.toFixed(0)}` : "";
93
- return ` ${i + 1}. ${name} (${f.score} pts${mi ? `, ${mi}` : ""})`;
94
- })
95
- .join("\n");
96
- ctx.ui.notify(`šŸ—ļø Worst: ${relFile} (score: ${score}) — ${scored.length} files with debt`, "info");
97
- console.log(`\nšŸ“Š Ranked by debt score:\n${topFiles}${scored.length > 15 ? `\n ... and ${scored.length - 15} more` : ""}\n`);
98
- // --- Steer message for agent ---
99
- const steer = [
100
- `šŸ—ļø BOOBOO REFACTOR — worst offender identified`,
101
- "",
102
- `**File**: \`${relFile}\` (debt score: ${score})`,
103
- "",
104
- metrics ? `**Complexity**: ${metricsSummary}` : "",
105
- "",
106
- issues.length > 0 ? `**Violations**:\n${issuesSummary}` : "",
107
- archIssues.length > 0
108
- ? `**Architectural rules violated**:\n${archSummary}`
109
- : "",
110
- firstViolationLine ? `First violation at line ${firstViolationLine}` : "",
111
- "",
112
- `šŸ“„ Read \`${relFile}\` when ready to implement`,
113
- "",
114
- "**Your job**:",
115
- "1. Analyze this code — what's the most impactful refactoring for this file?",
116
- "2. Build 3-5 refactoring options. For each, explain *why* it helps and *what* you'd change. Mark one as recommended.",
117
- "3. For each option, estimate the impact: linesReduced (number), miProjection (e.g. '3.5 → 8'), cognitiveProjection (e.g. '1533 → 1400').",
118
- "4. Include an option to skip to the next worst offender.",
119
- "5. Call the `interviewer` tool with:",
120
- " - `question`: what you're asking the user",
121
- " - `options`: array of { value, label, context, recommended, impact: { linesReduced, miProjection, cognitiveProjection } }",
122
- "6. The user picks an option or types a free-text response in the browser form.",
123
- "7. Implement the refactoring. After changes, run `git diff HEAD~1` to capture what was changed.",
124
- "8. Run a complexity scan on the changed file(s) to compute the metrics delta (before vs after MI, cognitive).",
125
- "9. Call the `interviewer` tool AGAIN with confirmationMode=true. The plan should contain: what was changed (summary + diff lines), how metrics evolved, and a free-chat option for refinements.",
126
- "10. If the user describes changes: make further edits, re-run the scan, call interviewer again with an updated report. Repeat until satisfied.",
127
- "11. CRITICAL: Once the user is satisfied with the current file, you MUST re-scan the project (or re-run /lens-booboo-refactor) and immediately start the process for the NEXT worst offender. Do not stop until all architectural debt is resolved.",
128
- ].join("\n");
129
- pi.sendUserMessage(steer, { deliverAs: "steer" });
130
- }