UNPKG

scai

Version:

> AI-powered CLI tool for commit messages **and** pull request reviews — using local models.

75 lines (64 loc) 2.55 kB
import { Config } from '../../config.js'; import { generate } from '../../lib/generate.js'; import { detectFileType } from '../../fileRules/detectFileType.js'; export const addCommentsModule = { name: 'comments', description: 'Adds meaningful comments to any file type (code, config, or data)', async run(input) { const model = Config.getModel(); const fileType = detectFileType(input.filepath || ''); // Map file types to valid comment syntax const commentMap = { javascript: '//', typescript: '//', java: '//', rust: '//', c: '//', cpp: '//', csharp: '//', go: '//', swift: '//', kotlin: '//', scala: '//', python: '#', ruby: '#', php: '//', shell: '#', bash: '#', config: '#', yaml: '#', markdown: '<!-- -->', html: '<!-- -->', xml: '<!-- -->', json: '/* */', sql: '--', csv: '#', tsv: '#', text: '#', }; const commentSyntax = commentMap[fileType] || '//'; const prompt = ` You are a senior engineer reviewing a ${fileType} file. Please: 1. Add a concise summary comment above each function describing its purpose. - Do NOT write trivial summaries like "..." or empty comments. - Do NOT overwrite or remove any existing comments. 2. Add clear, helpful inline comments to explain non-obvious logic inside functions. - Preserve all existing comments as-is. 3. Use "${commentSyntax}" as the comment syntax appropriate for ${fileType}. 4. Preserve all original formatting, whitespace, and code exactly. 5. You may only be shown parts of a file. Add comments as instructed. Rules: - Return the full original chunk of code with added comments only. - Do NOT remove, change, or overwrite any existing code or comments. - Summaries should be brief but meaningful. - Inline comments should clarify complex or tricky parts only. - Do NOT add any “chunk” start/end markers, numbering, or metadata to the output. Code to comments is below this line: ${input.content} `.trim(); const response = await generate({ content: prompt }, model); const contentToReturn = (response.content && response.content !== 'NO UPDATE') ? response.content : input.content; return { content: contentToReturn }; }, };