refactor_helper
Provides naming suggestions and extraction hints for selected code to improve readability and maintainability.
Instructions
Naming suggestions and extraction hints for selected code.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"action": "<action>",
"code": "<code>"
},
"name": "refactor_helper"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action: suggest_names (better variable/function names), extract_function (suggest function extraction) | |
| code | Yes | Code snippet to process | |
| language | No | Programming language (optional) | |
| style | No | For suggest_names: naming convention (default: auto) | |
| selection | No | For extract_function: specific code portion to extract (optional) |
Implementation Reference
- src/tools/code-assistance.ts:520-576 (handler)The 'refactor_helper' tool is implemented within the 'CodeAssistanceTools' class, specifically using LLM wrappers for 'suggestNames' (lines 520-576) and 'extractFunction' (lines 582-651). Both functions call 'this.llmWrapper.callToolLlm' with the identifier 'refactor_helper'.
/** * Suggest better names for code identifiers */ async suggestNames( code: string, options?: { language?: string; focusIdentifiers?: string[]; style?: 'camelCase' | 'snake_case' | 'PascalCase'; } ): Promise<SuggestNamesResult> { const language = options?.language ?? 'code'; const style = options?.style ?? 'camelCase'; const prompt = `You are an expert at naming things in code. Analyze this ${language} code and suggest better, more descriptive names for variables, functions, and classes. Naming style: ${style} ${options?.focusIdentifiers ? `Focus on these identifiers: ${options.focusIdentifiers.join(', ')}` : 'Analyze all identifiers that could be improved'} Provide your response as JSON: { "suggestions": [ { "original": "Current name", "suggested": ["Better name 1", "Better name 2"], "reasoning": "Why these names are better", "type": "variable|function|class|parameter" } ] }`; try { const responseText = await this.llmWrapper.callToolLlm( 'refactor_helper', [ { role: 'system', content: prompt }, { role: 'user', content: `\`\`\`${language}\n${code}\n\`\`\`` }, ], { type: 'suggest_names', language, style } ); const parsed = this.parseJsonResponse(responseText, { suggestions: [], }); return { success: true, suggestions: parsed.suggestions || [], }; } catch (error) { return { success: false, suggestions: [], error: error instanceof Error ? error.message : 'Unknown error', }; } }