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 ❤️.
59 lines (54 loc) • 2.21 kB
JavaScript
// File: src/pipeline/modules/commitSuggesterModule.ts
import { Config } from '../../config.js';
import { generate } from '../../lib/generate.js';
export const commitSuggesterModule = {
name: 'commitSuggester',
description: 'Suggests conventional commit messages from Git diff',
run: async (input) => {
const model = Config.getModel();
const diffContent = typeof input.content === 'string' ? input.content : '';
const prompt = `
Suggest ALWAYS 3 concise, conventional Git commit messages based on the input code diff.
- Follow the Conventional Commits specification for prefixes (e.g., feat:, fix:, refactor:, docs:, style:, test:, chore:).
- Choose the most appropriate prefix for each message based on the changes in the diff.
- Do NOT repeat the same prefix unless it is clearly the most appropriate.
- Keep each message short, clear, and action-oriented.
Format your response exactly as:
1. <type>: <message>
2. <type>: <message>
3. <type>: <message>
Here is the diff:
${diffContent}
`.trim();
try {
// === INTERACTION #1: generate.ts (via ModuleIO) ===
const genInput = {
query: 'Suggest 3 conventional commit messages',
content: prompt
};
const genOutput = await generate(genInput);
const rawText = typeof genOutput.data === 'string' ? genOutput.data : '';
// === Parse lines ===
const lines = rawText
.split('\n')
.map(line => line.trim())
.filter(line => /^[1-3][.)]\s+/.test(line));
const suggestions = lines.map(line => line.replace(/^[1-3][.)]\s+/, '').replace(/^"(.*)"$/, '$1').trim());
return {
query: input.query,
content: diffContent,
data: genOutput.data,
suggestions
};
}
catch (err) {
console.warn('⚠️ commitSuggesterModule failed:', err);
return {
query: input.query,
content: diffContent,
data: {},
suggestions: []
};
}
}
};