mstro-app 0.4.44 → 0.4.45
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/dist/server/services/websocket/handler.js +1 -1
- package/dist/server/services/websocket/handler.js.map +1 -1
- package/dist/server/services/websocket/quality-complexity.d.ts +1 -1
- package/dist/server/services/websocket/quality-complexity.d.ts.map +1 -1
- package/dist/server/services/websocket/quality-complexity.js +88 -59
- package/dist/server/services/websocket/quality-complexity.js.map +1 -1
- package/dist/server/services/websocket/quality-handlers.d.ts.map +1 -1
- package/dist/server/services/websocket/quality-handlers.js +4 -21
- package/dist/server/services/websocket/quality-handlers.js.map +1 -1
- package/dist/server/services/websocket/quality-linting.d.ts.map +1 -1
- package/dist/server/services/websocket/quality-linting.js +71 -50
- package/dist/server/services/websocket/quality-linting.js.map +1 -1
- package/dist/server/services/websocket/quality-persistence.d.ts +1 -1
- package/dist/server/services/websocket/quality-persistence.d.ts.map +1 -1
- package/dist/server/services/websocket/quality-service.d.ts +0 -4
- package/dist/server/services/websocket/quality-service.d.ts.map +1 -1
- package/dist/server/services/websocket/quality-service.js +40 -34
- package/dist/server/services/websocket/quality-service.js.map +1 -1
- package/dist/server/services/websocket/quality-tools.d.ts +13 -0
- package/dist/server/services/websocket/quality-tools.d.ts.map +1 -1
- package/dist/server/services/websocket/quality-tools.js +32 -0
- package/dist/server/services/websocket/quality-tools.js.map +1 -1
- package/dist/server/services/websocket/types.d.ts +2 -2
- package/dist/server/services/websocket/types.d.ts.map +1 -1
- package/dist/server/services/websocket/types.js +2 -2
- package/dist/server/services/websocket/types.js.map +1 -1
- package/package.json +1 -1
- package/server/services/websocket/handler.ts +1 -1
- package/server/services/websocket/quality-complexity.ts +87 -51
- package/server/services/websocket/quality-handlers.ts +4 -18
- package/server/services/websocket/quality-linting.ts +74 -47
- package/server/services/websocket/quality-persistence.ts +1 -1
- package/server/services/websocket/quality-service.ts +44 -39
- package/server/services/websocket/quality-tools.ts +33 -0
- package/server/services/websocket/types.ts +2 -2
- package/dist/server/services/websocket/quality-fix-agent.d.ts +0 -16
- package/dist/server/services/websocket/quality-fix-agent.d.ts.map +0 -1
- package/dist/server/services/websocket/quality-fix-agent.js +0 -181
- package/dist/server/services/websocket/quality-fix-agent.js.map +0 -1
- package/server/services/websocket/quality-fix-agent.ts +0 -216
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
// Licensed under the MIT License. See LICENSE file for details.
|
|
3
3
|
|
|
4
4
|
import { extname, relative } from 'node:path';
|
|
5
|
-
import { runCommand, type SourceFile } from './quality-tools.js';
|
|
5
|
+
import { chunkFileList, filesByExt, runCommand, type SourceFile } from './quality-tools.js';
|
|
6
6
|
import { biomeDiagToFinding, type Ecosystem, FUNCTION_LENGTH_THRESHOLD, isBiomeComplexityDiagnostic, isEslintComplexityRule, type QualityFinding } from './quality-types.js';
|
|
7
7
|
|
|
8
|
+
const NODE_COMPLEXITY_EXTS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
9
|
+
const PY_COMPLEXITY_EXTS = ['.py', '.pyi'];
|
|
10
|
+
|
|
8
11
|
// ============================================================================
|
|
9
12
|
// Function Length Analysis
|
|
10
13
|
// ============================================================================
|
|
@@ -160,43 +163,62 @@ function computeComplexityScore(findings: QualityFinding[]): number {
|
|
|
160
163
|
return Math.max(0, 100 - penalty);
|
|
161
164
|
}
|
|
162
165
|
|
|
163
|
-
async function complexityFromBiome(dirPath: string): Promise<QualityFinding[] | null> {
|
|
164
|
-
const
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
166
|
+
async function complexityFromBiome(dirPath: string, files: SourceFile[]): Promise<QualityFinding[] | null> {
|
|
167
|
+
const targets = filesByExt(files, NODE_COMPLEXITY_EXTS);
|
|
168
|
+
if (targets.length === 0) return [];
|
|
169
|
+
|
|
170
|
+
const findings: QualityFinding[] = [];
|
|
171
|
+
for (const chunk of chunkFileList(targets)) {
|
|
172
|
+
const result = await runCommand('npx', ['@biomejs/biome', 'lint', '--reporter=json', ...chunk], dirPath);
|
|
173
|
+
if (result.exitCode > 1) return null;
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
const parsed = JSON.parse(result.stdout);
|
|
177
|
+
if (!parsed.diagnostics) continue;
|
|
178
|
+
for (const d of parsed.diagnostics) {
|
|
179
|
+
if (isBiomeComplexityDiagnostic(d)) findings.push(biomeDiagToFinding(d, 'complexity'));
|
|
180
|
+
}
|
|
181
|
+
} catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return findings;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function eslintFileToComplexityFindings(
|
|
189
|
+
file: { filePath: string; messages?: Array<Record<string, unknown>> },
|
|
190
|
+
dirPath: string,
|
|
191
|
+
): QualityFinding[] {
|
|
192
|
+
const out: QualityFinding[] = [];
|
|
193
|
+
for (const msg of file.messages || []) {
|
|
194
|
+
if (!isEslintComplexityRule(msg.ruleId as string)) continue;
|
|
195
|
+
out.push({
|
|
196
|
+
severity: msg.severity === 2 ? 'high' : 'medium',
|
|
197
|
+
category: 'complexity',
|
|
198
|
+
file: relative(dirPath, file.filePath),
|
|
199
|
+
line: (msg.line as number) ?? null,
|
|
200
|
+
title: (msg.ruleId as string) || 'complexity',
|
|
201
|
+
description: msg.message as string,
|
|
202
|
+
});
|
|
175
203
|
}
|
|
204
|
+
return out;
|
|
176
205
|
}
|
|
177
206
|
|
|
178
|
-
async function complexityFromEslint(dirPath: string): Promise<QualityFinding[] | null> {
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
207
|
+
async function complexityFromEslint(dirPath: string, files: SourceFile[]): Promise<QualityFinding[] | null> {
|
|
208
|
+
const targets = filesByExt(files, NODE_COMPLEXITY_EXTS);
|
|
209
|
+
if (targets.length === 0) return [];
|
|
181
210
|
|
|
182
211
|
const findings: QualityFinding[] = [];
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
line: msg.line ?? null,
|
|
193
|
-
title: msg.ruleId || 'complexity',
|
|
194
|
-
description: msg.message,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
212
|
+
for (const chunk of chunkFileList(targets)) {
|
|
213
|
+
const result = await runCommand('npx', ['eslint', '--format=json', ...chunk], dirPath);
|
|
214
|
+
if (result.exitCode > 1 && !result.stdout.trim().startsWith('[')) return null;
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
const parsed = JSON.parse(result.stdout);
|
|
218
|
+
for (const file of parsed) findings.push(...eslintFileToComplexityFindings(file, dirPath));
|
|
219
|
+
} catch {
|
|
220
|
+
return null;
|
|
197
221
|
}
|
|
198
|
-
} catch {
|
|
199
|
-
return null;
|
|
200
222
|
}
|
|
201
223
|
|
|
202
224
|
return findings;
|
|
@@ -215,28 +237,40 @@ function radonFuncToFinding(filePath: string, func: Record<string, unknown>): Qu
|
|
|
215
237
|
};
|
|
216
238
|
}
|
|
217
239
|
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
240
|
+
function radonPayloadToFindings(payload: Record<string, Array<Record<string, unknown>>>): QualityFinding[] {
|
|
241
|
+
const out: QualityFinding[] = [];
|
|
242
|
+
for (const [filePath, functions] of Object.entries(payload)) {
|
|
243
|
+
for (const func of functions) {
|
|
244
|
+
const finding = radonFuncToFinding(filePath, func);
|
|
245
|
+
if (finding) out.push(finding);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function complexityFromRadon(dirPath: string, files: SourceFile[]): Promise<QualityFinding[] | null> {
|
|
252
|
+
const targets = filesByExt(files, PY_COMPLEXITY_EXTS);
|
|
253
|
+
if (targets.length === 0) return [];
|
|
254
|
+
|
|
255
|
+
const findings: QualityFinding[] = [];
|
|
256
|
+
for (const chunk of chunkFileList(targets)) {
|
|
257
|
+
const result = await runCommand('radon', ['cc', '--json', ...chunk], dirPath);
|
|
258
|
+
if (result.exitCode !== 0 && !result.stdout.trim().startsWith('{')) return null;
|
|
259
|
+
|
|
260
|
+
try {
|
|
261
|
+
const parsed = JSON.parse(result.stdout) as Record<string, Array<Record<string, unknown>>>;
|
|
262
|
+
findings.push(...radonPayloadToFindings(parsed));
|
|
263
|
+
} catch {
|
|
264
|
+
return null;
|
|
230
265
|
}
|
|
231
|
-
return findings;
|
|
232
|
-
} catch {
|
|
233
|
-
return null;
|
|
234
266
|
}
|
|
267
|
+
return findings;
|
|
235
268
|
}
|
|
236
269
|
|
|
237
270
|
async function analyzeNodeComplexity(
|
|
238
271
|
dirPath: string,
|
|
239
272
|
installed: Set<string> | null,
|
|
273
|
+
files: SourceFile[],
|
|
240
274
|
): Promise<QualityFinding[] | null> {
|
|
241
275
|
const hasCapableTool = !installed || installed.has('biome') || installed.has('eslint');
|
|
242
276
|
if (!hasCapableTool) return null;
|
|
@@ -245,24 +279,26 @@ async function analyzeNodeComplexity(
|
|
|
245
279
|
// This fixes monorepo scenarios where biome.json is in a subdirectory.
|
|
246
280
|
const hasBiome = !installed || installed.has('biome');
|
|
247
281
|
if (hasBiome) {
|
|
248
|
-
const findings = await complexityFromBiome(dirPath);
|
|
282
|
+
const findings = await complexityFromBiome(dirPath, files);
|
|
249
283
|
if (findings) return findings;
|
|
250
284
|
}
|
|
251
|
-
return complexityFromEslint(dirPath);
|
|
285
|
+
return complexityFromEslint(dirPath, files);
|
|
252
286
|
}
|
|
253
287
|
|
|
254
288
|
async function analyzePythonComplexity(
|
|
255
289
|
dirPath: string,
|
|
256
290
|
installed: Set<string> | null,
|
|
291
|
+
files: SourceFile[],
|
|
257
292
|
): Promise<QualityFinding[] | null> {
|
|
258
293
|
const hasRadon = !installed || installed.has('radon');
|
|
259
294
|
if (!hasRadon) return null;
|
|
260
|
-
return complexityFromRadon(dirPath);
|
|
295
|
+
return complexityFromRadon(dirPath, files);
|
|
261
296
|
}
|
|
262
297
|
|
|
263
298
|
export async function analyzeComplexity(
|
|
264
299
|
dirPath: string,
|
|
265
300
|
ecosystems: Ecosystem[],
|
|
301
|
+
files: SourceFile[],
|
|
266
302
|
installedToolNames?: string[],
|
|
267
303
|
): Promise<{ score: number; findings: QualityFinding[]; issueCount: number; available: boolean }> {
|
|
268
304
|
const allFindings: QualityFinding[] = [];
|
|
@@ -272,7 +308,7 @@ export async function analyzeComplexity(
|
|
|
272
308
|
for (const ecosystem of ecosystems) {
|
|
273
309
|
const analyze = ecosystem === 'node' ? analyzeNodeComplexity : ecosystem === 'python' ? analyzePythonComplexity : null;
|
|
274
310
|
if (!analyze) continue;
|
|
275
|
-
const findings = await analyze(dirPath, installed);
|
|
311
|
+
const findings = await analyze(dirPath, installed, files);
|
|
276
312
|
if (findings) {
|
|
277
313
|
canAnalyze = true;
|
|
278
314
|
allFindings.push(...findings);
|
|
@@ -2,19 +2,18 @@
|
|
|
2
2
|
// Licensed under the MIT License. See LICENSE file for details.
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Quality Handlers — WebSocket message router for quality scanning
|
|
6
|
-
* code review
|
|
5
|
+
* Quality Handlers — WebSocket message router for quality scanning
|
|
6
|
+
* and code review operations. Fixes are handled via chat tabs from the
|
|
7
|
+
* web client (see web/src/components/views/QualityView/qualityUtils.ts)
|
|
8
|
+
* so there is no server-side fix message anymore.
|
|
7
9
|
*
|
|
8
10
|
* Agent logic lives in focused modules:
|
|
9
11
|
* - quality-review-agent.ts — AI code review prompt, parsing, handler
|
|
10
|
-
* - quality-fix-agent.ts — AI fix prompt, progress tracking, handler
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import { join, resolve } from 'node:path';
|
|
14
15
|
import { validatePathWithinWorkingDir } from '../pathUtils.js';
|
|
15
16
|
import type { HandlerContext } from './handler-context.js';
|
|
16
|
-
import type { FindingForFix } from './quality-fix-agent.js';
|
|
17
|
-
import { handleFixIssues } from './quality-fix-agent.js';
|
|
18
17
|
import { QualityPersistence } from './quality-persistence.js';
|
|
19
18
|
import { handleCodeReview } from './quality-review-agent.js';
|
|
20
19
|
import { detectTools, installTools, runQualityScan } from './quality-service.js';
|
|
@@ -92,17 +91,6 @@ export function handleQualityMessage(
|
|
|
92
91
|
handleCodeReview(ctx, ws, reportPath, dirPath, workingDir, activeReviews, getPersistence)
|
|
93
92
|
.finally(() => persistence.clearActiveOperation(reportPath));
|
|
94
93
|
},
|
|
95
|
-
qualityFixIssues: () => {
|
|
96
|
-
const { resolved: dirPath, error } = resolveAndValidatePath(workingDir, msg.data?.path, isSandboxed);
|
|
97
|
-
if (error) { sendPathError(msg.data?.path || '.', error); return; }
|
|
98
|
-
const reportPath = msg.data?.path || '.';
|
|
99
|
-
const section: string | undefined = msg.data?.section;
|
|
100
|
-
const findings: FindingForFix[] = msg.data?.findings || [];
|
|
101
|
-
const persistence = getPersistence(workingDir);
|
|
102
|
-
persistence.setActiveOperation(reportPath, 'fixing');
|
|
103
|
-
handleFixIssues(ctx, ws, reportPath, dirPath, workingDir, section, findings, getPersistence)
|
|
104
|
-
.finally(() => persistence.clearActiveOperation(reportPath));
|
|
105
|
-
},
|
|
106
94
|
qualityLoadState: () => handleLoadState(ctx, ws, workingDir),
|
|
107
95
|
qualityClearPending: () => {
|
|
108
96
|
const persistence = getPersistence(workingDir);
|
|
@@ -145,8 +133,6 @@ async function handleLoadState(
|
|
|
145
133
|
ctx.send(ws, { type: 'qualityScanResults', data: pending.data });
|
|
146
134
|
} else if (pending.type === 'codeReview') {
|
|
147
135
|
ctx.send(ws, { type: 'qualityCodeReview', data: pending.data });
|
|
148
|
-
} else if (pending.type === 'fixComplete') {
|
|
149
|
-
ctx.send(ws, { type: 'qualityFixComplete', data: pending.data });
|
|
150
136
|
}
|
|
151
137
|
}
|
|
152
138
|
persistence.clearPendingResults();
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
// Licensed under the MIT License. See LICENSE file for details.
|
|
3
3
|
|
|
4
4
|
import { relative } from 'node:path';
|
|
5
|
-
import { runCommand, type SourceFile } from './quality-tools.js';
|
|
5
|
+
import { chunkFileList, filesByExt, runCommand, type SourceFile } from './quality-tools.js';
|
|
6
6
|
import { biomeDiagToFinding, type Ecosystem, isBiomeComplexityDiagnostic, isEslintComplexityRule, type QualityFinding } from './quality-types.js';
|
|
7
7
|
|
|
8
|
+
const NODE_LINT_EXTS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
9
|
+
const PY_LINT_EXTS = ['.py', '.pyi'];
|
|
10
|
+
|
|
8
11
|
interface LintAccumulator {
|
|
9
12
|
errors: number;
|
|
10
13
|
warnings: number;
|
|
@@ -31,17 +34,22 @@ function parseBiomeDiagnostics(stdout: string, acc: LintAccumulator): void {
|
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
async function lintWithBiome(dirPath: string, acc: LintAccumulator): Promise<void> {
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
+
async function lintWithBiome(dirPath: string, acc: LintAccumulator, files: SourceFile[]): Promise<void> {
|
|
38
|
+
const targets = filesByExt(files, NODE_LINT_EXTS);
|
|
39
|
+
if (targets.length === 0) return;
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
acc.
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
for (const chunk of chunkFileList(targets)) {
|
|
42
|
+
const result = await runCommand('npx', ['@biomejs/biome', 'lint', '--reporter=json', ...chunk], dirPath);
|
|
43
|
+
if (result.exitCode > 1) return;
|
|
44
|
+
|
|
45
|
+
acc.ran = true;
|
|
46
|
+
try {
|
|
47
|
+
parseBiomeDiagnostics(result.stdout, acc);
|
|
48
|
+
} catch {
|
|
49
|
+
acc.errors += (result.stdout.match(/error/gi) || []).length;
|
|
50
|
+
acc.warnings += (result.stdout.match(/warning/gi) || []).length;
|
|
51
|
+
acc.ran = acc.errors > 0 || acc.warnings > 0 || result.exitCode === 0;
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
55
|
|
|
@@ -64,58 +72,77 @@ function processEslintMessage(
|
|
|
64
72
|
});
|
|
65
73
|
}
|
|
66
74
|
|
|
67
|
-
async function lintWithEslint(dirPath: string, acc: LintAccumulator): Promise<void> {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
async function lintWithEslint(dirPath: string, acc: LintAccumulator, files: SourceFile[]): Promise<void> {
|
|
76
|
+
const targets = filesByExt(files, NODE_LINT_EXTS);
|
|
77
|
+
if (targets.length === 0) return;
|
|
78
|
+
|
|
79
|
+
for (const chunk of chunkFileList(targets)) {
|
|
80
|
+
const result = await runCommand('npx', ['eslint', '--format=json', ...chunk], dirPath);
|
|
81
|
+
acc.ran = true;
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(result.stdout);
|
|
84
|
+
for (const file of parsed) {
|
|
85
|
+
for (const msg of file.messages || []) {
|
|
86
|
+
processEslintMessage(msg, file.filePath, dirPath, acc);
|
|
87
|
+
}
|
|
75
88
|
}
|
|
89
|
+
} catch {
|
|
90
|
+
acc.errors += (result.stderr.match(/error/gi) || []).length;
|
|
91
|
+
acc.warnings += (result.stderr.match(/warning/gi) || []).length;
|
|
76
92
|
}
|
|
77
|
-
} catch {
|
|
78
|
-
acc.errors += (result.stderr.match(/error/gi) || []).length;
|
|
79
|
-
acc.warnings += (result.stderr.match(/warning/gi) || []).length;
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
95
|
|
|
83
|
-
async function lintNode(
|
|
96
|
+
async function lintNode(
|
|
97
|
+
dirPath: string,
|
|
98
|
+
acc: LintAccumulator,
|
|
99
|
+
installed: Set<string> | null,
|
|
100
|
+
files: SourceFile[],
|
|
101
|
+
): Promise<void> {
|
|
84
102
|
// Use installed tools list to decide which linter to run, not config file presence.
|
|
85
103
|
// This fixes monorepo scenarios where the config is in a subdirectory.
|
|
86
104
|
const hasBiome = !installed || installed.has('biome');
|
|
87
105
|
const hasEslint = !installed || installed.has('eslint');
|
|
88
106
|
|
|
89
107
|
if (hasBiome) {
|
|
90
|
-
await lintWithBiome(dirPath, acc);
|
|
108
|
+
await lintWithBiome(dirPath, acc, files);
|
|
91
109
|
if (acc.ran) return;
|
|
92
110
|
}
|
|
93
111
|
if (hasEslint) {
|
|
94
|
-
await lintWithEslint(dirPath, acc);
|
|
112
|
+
await lintWithEslint(dirPath, acc, files);
|
|
95
113
|
}
|
|
96
114
|
}
|
|
97
115
|
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
116
|
+
function processRuffItem(item: Record<string, unknown>, dirPath: string, acc: LintAccumulator): void {
|
|
117
|
+
const code = item.code as string | undefined;
|
|
118
|
+
const sev = code?.startsWith('E') ? 'high' : 'medium';
|
|
119
|
+
if (sev === 'high') acc.errors++;
|
|
120
|
+
else acc.warnings++;
|
|
121
|
+
const location = item.location as Record<string, unknown> | undefined;
|
|
122
|
+
acc.findings.push({
|
|
123
|
+
severity: sev,
|
|
124
|
+
category: 'lint',
|
|
125
|
+
file: item.filename ? relative(dirPath, item.filename as string) : '',
|
|
126
|
+
line: (location?.row as number) ?? null,
|
|
127
|
+
title: code || 'Lint issue',
|
|
128
|
+
description: (item.message as string) || '',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
101
131
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
} catch { /* ignore */ }
|
|
132
|
+
async function lintPython(dirPath: string, acc: LintAccumulator, files: SourceFile[]): Promise<void> {
|
|
133
|
+
const targets = filesByExt(files, PY_LINT_EXTS);
|
|
134
|
+
if (targets.length === 0) return;
|
|
135
|
+
|
|
136
|
+
for (const chunk of chunkFileList(targets)) {
|
|
137
|
+
const result = await runCommand('ruff', ['check', '--output-format=json', ...chunk], dirPath);
|
|
138
|
+
if (result.exitCode !== 0 && !result.stdout.trim().startsWith('[')) continue;
|
|
139
|
+
|
|
140
|
+
acc.ran = true;
|
|
141
|
+
try {
|
|
142
|
+
const parsed = JSON.parse(result.stdout);
|
|
143
|
+
for (const item of parsed) processRuffItem(item, dirPath, acc);
|
|
144
|
+
} catch { /* ignore */ }
|
|
145
|
+
}
|
|
119
146
|
}
|
|
120
147
|
|
|
121
148
|
function processClippyMessage(msg: Record<string, unknown>, acc: LintAccumulator): void {
|
|
@@ -174,8 +201,8 @@ export async function analyzeLinting(
|
|
|
174
201
|
const acc = newLintAccumulator();
|
|
175
202
|
const installed = installedToolNames ? new Set(installedToolNames) : null;
|
|
176
203
|
|
|
177
|
-
if (ecosystems.includes('node')) await lintNode(dirPath, acc, installed);
|
|
178
|
-
if (ecosystems.includes('python')) await lintPython(dirPath, acc);
|
|
204
|
+
if (ecosystems.includes('node')) await lintNode(dirPath, acc, installed, files);
|
|
205
|
+
if (ecosystems.includes('python')) await lintPython(dirPath, acc, files);
|
|
179
206
|
if (ecosystems.includes('rust')) await lintRust(dirPath, acc);
|
|
180
207
|
|
|
181
208
|
if (!acc.ran) {
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
import { extname } from 'node:path';
|
|
5
5
|
import { analyzeComplexity, analyzeFunctionLength } from './quality-complexity.js';
|
|
6
6
|
import { analyzeLinting } from './quality-linting.js';
|
|
7
|
-
import { collectSourceFiles, detectEcosystem, runCommand, type SourceFile } from './quality-tools.js';
|
|
7
|
+
import { chunkFileList, collectSourceFiles, detectEcosystem, filesByExt, runCommand, type SourceFile } from './quality-tools.js';
|
|
8
8
|
import { type CategoryPenalty, type CategoryScore, type Ecosystem, FILE_LENGTH_THRESHOLD, hasInstalledToolInCategory, type QualityFinding, type QualityResults, type ScanProgress, type ScoreBreakdown, TOTAL_STEPS } from './quality-types.js';
|
|
9
9
|
|
|
10
|
+
const NODE_FMT_EXTS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
11
|
+
const PY_FMT_EXTS = ['.py', '.pyi'];
|
|
12
|
+
|
|
10
13
|
export { detectEcosystem, detectTools, installTools } from './quality-tools.js';
|
|
11
14
|
// Re-export public API for backward compatibility
|
|
12
15
|
export type { CategoryPenalty, CategoryScore, QualityFinding, QualityResults, QualityTool, ScanProgress, ScoreBreakdown } from './quality-types.js';
|
|
@@ -27,34 +30,51 @@ function newFmtAccumulator(): FmtAccumulator {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
async function fmtNode(dirPath: string, files: SourceFile[], acc: FmtAccumulator): Promise<void> {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (const
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
const targets = filesByExt(files, NODE_FMT_EXTS);
|
|
34
|
+
if (targets.length === 0) return;
|
|
35
|
+
|
|
36
|
+
acc.totalFiles += targets.length;
|
|
37
|
+
const unformattedSet = new Set<string>();
|
|
38
|
+
|
|
39
|
+
for (const chunk of chunkFileList(targets)) {
|
|
40
|
+
const result = await runCommand('npx', ['prettier', '--check', ...chunk], dirPath);
|
|
41
|
+
acc.ran = true;
|
|
42
|
+
for (const line of result.stdout.split('\n')) {
|
|
43
|
+
if (!line.trim() || line.startsWith('Checking')) continue;
|
|
44
|
+
const rel = line.startsWith('/') ? line.replace(`${dirPath}/`, '') : line;
|
|
45
|
+
unformattedSet.add(rel.trim());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
acc.passingFiles += Math.max(0, targets.length - unformattedSet.size);
|
|
50
|
+
for (const rel of unformattedSet) {
|
|
39
51
|
acc.findings.push({ severity: 'low', category: 'format', file: rel, line: null, title: 'File not formatted', description: 'Does not match Prettier formatting rules.' });
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
|
|
43
55
|
async function fmtPython(dirPath: string, files: SourceFile[], acc: FmtAccumulator): Promise<void> {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
acc.totalFiles +=
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
const targets = filesByExt(files, PY_FMT_EXTS);
|
|
57
|
+
if (targets.length === 0) return;
|
|
58
|
+
|
|
59
|
+
acc.totalFiles += targets.length;
|
|
60
|
+
let reformatCount = 0;
|
|
61
|
+
const findings: typeof acc.findings = [];
|
|
62
|
+
|
|
63
|
+
for (const chunk of chunkFileList(targets)) {
|
|
64
|
+
const result = await runCommand('black', ['--check', '--quiet', ...chunk], dirPath);
|
|
65
|
+
acc.ran = true;
|
|
66
|
+
if (result.exitCode === 0) continue;
|
|
67
|
+
|
|
68
|
+
const reformatLines = result.stderr.split('\n').filter((l) => l.includes('would reformat'));
|
|
69
|
+
reformatCount += reformatLines.length;
|
|
70
|
+
for (const line of reformatLines) {
|
|
71
|
+
const match = line.match(/would reformat (.+)/);
|
|
72
|
+
if (match) findings.push({ severity: 'low', category: 'format', file: match[1].trim(), line: null, title: 'File not formatted', description: 'Does not match Black formatting rules.' });
|
|
73
|
+
}
|
|
57
74
|
}
|
|
75
|
+
|
|
76
|
+
acc.passingFiles += Math.max(0, targets.length - reformatCount);
|
|
77
|
+
acc.findings.push(...findings);
|
|
58
78
|
}
|
|
59
79
|
|
|
60
80
|
async function fmtRust(dirPath: string, files: SourceFile[], acc: FmtAccumulator): Promise<void> {
|
|
@@ -223,21 +243,6 @@ export function computeFormulaScore(
|
|
|
223
243
|
};
|
|
224
244
|
}
|
|
225
245
|
|
|
226
|
-
/** @deprecated — use computeFormulaScore instead */
|
|
227
|
-
export function computeAiReviewScore(
|
|
228
|
-
findings: Array<{ severity: string }>,
|
|
229
|
-
totalLines: number,
|
|
230
|
-
): number {
|
|
231
|
-
if (findings.length === 0) return 100;
|
|
232
|
-
const effectiveKloc = Math.max(totalLines / 1000, 1.0);
|
|
233
|
-
const totalPenalty = findings.reduce(
|
|
234
|
-
(sum, f) => sum + (SEVERITY_WEIGHT[f.severity] ?? 2.0),
|
|
235
|
-
0,
|
|
236
|
-
);
|
|
237
|
-
const penaltyDensity = totalPenalty / effectiveKloc;
|
|
238
|
-
return Math.round(100 * Math.exp(-0.10 * penaltyDensity));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
246
|
// ============================================================================
|
|
242
247
|
// Main Scan
|
|
243
248
|
// ============================================================================
|
|
@@ -278,7 +283,7 @@ export async function runQualityScan(
|
|
|
278
283
|
|
|
279
284
|
// Step 4: Analyze complexity (using real tools: Biome, ESLint, radon)
|
|
280
285
|
progress('Analyzing complexity', 4);
|
|
281
|
-
const complexityResult = await analyzeComplexity(dirPath, ecosystems, installedToolNames);
|
|
286
|
+
const complexityResult = await analyzeComplexity(dirPath, ecosystems, files, installedToolNames);
|
|
282
287
|
|
|
283
288
|
// Step 5: Check file lengths
|
|
284
289
|
progress('Checking file lengths', 5);
|
|
@@ -239,6 +239,39 @@ export async function collectSourceFiles(dirPath: string, rootPath: string): Pro
|
|
|
239
239
|
return files;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
+
// ============================================================================
|
|
243
|
+
// File List Helpers
|
|
244
|
+
// ============================================================================
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Filter a SourceFile list by extension and return relative paths.
|
|
248
|
+
* Used to pass an explicit, git-ignored-filtered file list to external tools
|
|
249
|
+
* (prettier, biome, eslint, ...) so they don't walk ignored directories like
|
|
250
|
+
* web/dist or nested build outputs in monorepos.
|
|
251
|
+
*/
|
|
252
|
+
export function filesByExt(files: SourceFile[], exts: string[]): string[] {
|
|
253
|
+
const set = new Set(exts.map((e) => e.toLowerCase()));
|
|
254
|
+
const out: string[] = [];
|
|
255
|
+
for (const f of files) {
|
|
256
|
+
if (set.has(extname(f.path).toLowerCase())) out.push(f.relativePath);
|
|
257
|
+
}
|
|
258
|
+
return out;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Split a file list into chunks so a single command invocation doesn't
|
|
263
|
+
* blow past ARG_MAX. macOS ARG_MAX is ~256KB; 400 paths at ~200 chars each
|
|
264
|
+
* leaves plenty of headroom.
|
|
265
|
+
*/
|
|
266
|
+
export function chunkFileList(paths: string[], size = 400): string[][] {
|
|
267
|
+
if (paths.length === 0) return [];
|
|
268
|
+
const chunks: string[][] = [];
|
|
269
|
+
for (let i = 0; i < paths.length; i += size) {
|
|
270
|
+
chunks.push(paths.slice(i, i + size));
|
|
271
|
+
}
|
|
272
|
+
return chunks;
|
|
273
|
+
}
|
|
274
|
+
|
|
242
275
|
// ============================================================================
|
|
243
276
|
// Command Runner
|
|
244
277
|
// ============================================================================
|
|
@@ -42,7 +42,7 @@ const SessionSyncMessages = ['getActiveTabs', 'createTab', 'reorderTabs', 'syncT
|
|
|
42
42
|
|
|
43
43
|
const SettingsMessages = ['getSettings', 'updateSettings'] as const;
|
|
44
44
|
|
|
45
|
-
const QualityMessages = ['qualityDetectTools', 'qualityScan', 'qualityInstallTools', 'qualityCodeReview', '
|
|
45
|
+
const QualityMessages = ['qualityDetectTools', 'qualityScan', 'qualityInstallTools', 'qualityCodeReview', 'qualityLoadState', 'qualitySaveDirectories'] as const;
|
|
46
46
|
|
|
47
47
|
const FileUploadMessages = ['fileUploadStart', 'fileUploadChunk', 'fileUploadComplete', 'fileUploadCancel'] as const;
|
|
48
48
|
|
|
@@ -105,7 +105,7 @@ const SessionSyncResponseMessages = ['activeTabs', 'tabCreated', 'tabRemoved', '
|
|
|
105
105
|
|
|
106
106
|
const SettingsResponseMessages = ['settings', 'settingsUpdated'] as const;
|
|
107
107
|
|
|
108
|
-
const QualityResponseMessages = ['qualityToolsDetected', 'qualityScanProgress', 'qualityScanResults', 'qualityInstallProgress', 'qualityInstallComplete', 'qualityCodeReview', 'qualityCodeReviewProgress', 'qualityPostSession', '
|
|
108
|
+
const QualityResponseMessages = ['qualityToolsDetected', 'qualityScanProgress', 'qualityScanResults', 'qualityInstallProgress', 'qualityInstallComplete', 'qualityCodeReview', 'qualityCodeReviewProgress', 'qualityPostSession', 'qualityError', 'qualityStateLoaded'] as const;
|
|
109
109
|
|
|
110
110
|
const FileUploadResponseMessages = ['fileUploadAck', 'fileUploadReady', 'fileUploadError'] as const;
|
|
111
111
|
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ToolUseEvent } from '../../cli/headless/types.js';
|
|
2
|
-
import type { HandlerContext } from './handler-context.js';
|
|
3
|
-
import type { QualityPersistence } from './quality-persistence.js';
|
|
4
|
-
import type { WSContext } from './types.js';
|
|
5
|
-
export interface FindingForFix {
|
|
6
|
-
severity: string;
|
|
7
|
-
category: string;
|
|
8
|
-
file: string;
|
|
9
|
-
line: number | null;
|
|
10
|
-
title: string;
|
|
11
|
-
description: string;
|
|
12
|
-
suggestion?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare function createToolProgressCallback(ctx: HandlerContext, ws: WSContext, reportPath: string): (event: ToolUseEvent) => void;
|
|
15
|
-
export declare function handleFixIssues(ctx: HandlerContext, ws: WSContext, reportPath: string, dirPath: string, workingDir: string, section: string | undefined, findings: FindingForFix[], getPersistence: (dir: string) => QualityPersistence): Promise<void>;
|
|
16
|
-
//# sourceMappingURL=quality-fix-agent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quality-fix-agent.d.ts","sourceRoot":"","sources":["../../../../server/services/websocket/quality-fix-agent.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAI5C,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAYD,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,IAEvF,OAAO,YAAY,UAmB5B;AAiDD,wBAAsB,eAAe,CACnC,GAAG,EAAE,cAAc,EACnB,EAAE,EAAE,SAAS,EACb,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,QAAQ,EAAE,aAAa,EAAE,EACzB,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,kBAAkB,GAClD,OAAO,CAAC,IAAI,CAAC,CAiGf"}
|