UNPKG

scai

Version:

> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.

41 lines (38 loc) 1.3 kB
// File: src/pipeline/modules/refactorModule.ts import { Config } from '../../config.js'; import { generate } from '../../lib/generate.js'; export const refactorModule = { name: 'refactor', description: 'Break code into small, clean functions', run: async (input) => { const lang = Config.getLanguage(); const code = typeof input.content === 'string' ? input.content : ''; if (!code) { throw new Error('⚠️ No code provided for refactoring.'); } const prompt = ` You are a senior ${lang.toUpperCase()} engineer. Refactor the following code: - Only split up long and complex functions - Preserve original names and semantics - Do NOT insert comments - Output the full, valid ${lang.toUpperCase()} code --- CODE START --- ${code} --- CODE END --- `.trim(); const response = await generate({ query: input.query ?? '', content: prompt, }); if (!response || !response.content) { throw new Error('❌ Model returned empty response for refactoring.'); } const output = { query: input.query ?? '', content: response.content, data: { refactoredCode: response.content }, }; return output; }, };