find_the_most_critical_design_issue
Analyze Java files to identify and prioritize the most critical design flaw requiring immediate refactoring, focusing on improving maintainability, readability, loose coupling, and cohesion.
Instructions
Analyze one Java file. Find the most serious design flaw. It must need immediate refactoring. Ignore cosmetic or minor issues. Fix the one problem that will best improve code quality. Code quality means maintainability, readability, loose coupling, and high cohesion. Point out the problem and where it is in the file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/tools.ts:24-31 (handler)The tool handler function that destructures the input path, safely executes aibolit(path), and returns it wrapped in the expected content format for MCP.async ({ path }) => { return ({ content: [{ text: await safe(() => aibolit(path)), type: 'text' }] }); }
- src/tools.ts:23-23 (schema)Zod input schema requiring a 'path' string parameter.{ path: z.string() },
- src/tools.ts:10-32 (registration)Registers the MCP tool 'find_the_most_critical_design_issue' with server.tool, including description prompt, schema, and handler.server.tool( 'find_the_most_critical_design_issue', to_gpt( ` Analyze one Java file. Find the most serious design flaw. It must need immediate refactoring. Ignore cosmetic or minor issues. Fix the one problem that will best improve code quality. Code quality means maintainability, readability, loose coupling, and high cohesion. Point out the problem and where it is in the file. ` ), { path: z.string() }, async ({ path }) => { return ({ content: [{ text: await safe(() => aibolit(path)), type: 'text' }] }); } );
- src/aibolit.ts:30-64 (helper)Core helper function 'aibolit' that checks Aibolit version, runs the CLI on the Java file, parses warnings, selects the top-priority design issue by score, and formats the result.export const aibolit = async function(path: string): Promise<string> { check_version(); if (!fs.existsSync(path)) { return `File does not exist: ${path}`; } const warns = execSync( ` /bin/bash -c "set -o pipefail; (python3 -m aibolit check --full --filenames ${path} || true)" ` ).toString(); const lines = warns.trim().split('\n').filter(line => line.trim()); const parsed = lines.map(line => { const match = line.match(/^.+?\[(\d+)\]:\s(.+?)\s\(P\d+:\s(\d+(?:\.\d+)?)\)$/); if (match) { return { line: parseFloat(match[1]), name: match[2].trim(), value: parseFloat(match[3]) }; } return null; }).filter(item => item !== null) as { line: number, name: string; value: number }[]; const sorted = parsed.sort((a, b) => b.value - a.value); const top = sorted[0]; if (!top) { return 'Your code is perfect'; } return to_gpt( ` The most important design issue in this Java file (${path}) is on the line no.${top.line}: "${top.name}". It needs immediate refactoring if you want to increase code maintainability. ` ); }