import { z } from 'zod'; import type { ToolDef } from '../types.js'; import { callBoocontext } from '../../boocontext_client.js'; export const GetCodeHealthInput = z.object({ directory: z.string().optional().describe('Directory to analyze (defaults to project root)'), file: z.string().optional().describe('Optional: specific file to analyze'), }); export type GetCodeHealthInputT = z.infer; const DESCRIPTION = 'Code health analysis. Returns A–F grades per file across 7 dimensions ' + '(cohesion, coupling, complexity, documentation, duplication, unit size, test coverage). ' + 'Includes project health summary and refactoring candidates.'; /** * Standalone execute function — calls the boocontext MCP server's * boocontext_health tool and returns the raw report text. * * Structured for direct test access: accepts input + projectPath, * no side effects beyond the MCP call. */ export async function executeGetCodeHealth( input: GetCodeHealthInputT, projectPath: string, ): Promise { const args: Record = {}; if (input.directory) args['directory'] = input.directory; if (input.file) args['file'] = input.file; const resp = await callBoocontext({ toolName: 'boocontext_health', args }); return resp.result; } export const getCodeHealth: ToolDef = { name: 'get_code_health', description: DESCRIPTION, inputSchema: GetCodeHealthInput, jsonSchema: { type: 'function', function: { name: 'get_code_health', description: DESCRIPTION, parameters: { type: 'object', properties: { directory: { type: 'string', description: 'Directory to analyze (defaults to project root)', }, file: { type: 'string', description: 'Optional: specific file to analyze', }, }, additionalProperties: false, }, }, }, async execute(input, projectRoot) { return executeGetCodeHealth(input, projectRoot); }, };