scai
Version:
> AI-powered CLI tool for commit messages **and** pull request reviews — using local models.
29 lines (25 loc) • 1.08 kB
JavaScript
import { Config } from '../../config.js';
import { generate } from '../../lib/generate.js';
export const addCommentsModule = {
name: 'addComments',
description: 'Adds meaningful // comments to each block of code',
async run(input) {
const model = Config.getModel();
const lang = Config.getLanguage();
const prompt = `
You are a senior ${lang.toUpperCase()} engineer reviewing source code.
Your task is to add clear and insightful single-line comments to the code.
⚠️ VERY IMPORTANT RULES:
- You MUST return the ENTIRE original code.
- You MUST NOT remove, replace, reformat, or alter ANY code.
- Only add single-line // comments to complex or non-obvious parts of the code.
- Do NOT wrap the code in markdown or code blocks.
- The code should be valid ${lang.toUpperCase()} after your changes.
--- CODE START ---
${input.content}
--- CODE END ---
`.trim();
const response = await generate({ content: prompt }, model);
return { content: response.content === 'NO UPDATE' ? '' : response.content };
},
};