UNPKG

scai

Version:

> AI-powered CLI tools for smart commit messages, auto generated comments, and readme files — all powered by local models.

43 lines (38 loc) 1.32 kB
import { ModelConfig } from '../../config/ModelConfig.js'; export const summaryModule = { name: 'summary', description: 'Prints a summary of changes to the terminal', async run({ code }) { const model = ModelConfig.getModel(); const lang = ModelConfig.getLanguage(); const prompt = ` You are a senior ${lang.toUpperCase()} engineer. Analyze the code below and return a concise summary of its functionality or structure. Only return the summary in this format: // Summary of code: // - [Bullet 1] // - [Bullet 2] // - etc. Return the original code after the summary. --- CODE START --- ${code} --- CODE END --- `.trim(); const res = await fetch('http://localhost:11434/api/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ model, prompt, stream: false }) }); const data = await res.json(); const summary = data.response?.trim(); if (summary) { console.log('\n📝 Code Summary:\n'); console.log(summary); } else { console.warn('⚠️ No summary generated.'); } // Return unchanged input so it’s pipe-safe, if reused in pipelines return { code }; } };