scai
Version:
> AI-powered CLI tools for smart commit messages, auto generated comments, and readme files — all powered by local models.
66 lines (65 loc) • 2.45 kB
JavaScript
import { Command } from "commander";
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { version } = require('../package.json');
import { checkEnv } from "./commands/EnvCmd.js";
import { checkGit } from "./commands/GitCmd.js";
import { suggestCommitMessage } from "./commands/CommitSuggesterCmd.js";
import { handleRefactor } from "./commands/RefactorCmd.js";
import { updateReadmeIfNeeded } from "./commands/ReadmeCmd.js";
import { generateTests } from "./commands/TestGenCmd.js";
import { bootstrap } from './modelSetup.js';
import { ModelConfig } from './config/ModelConfig.js';
import { summarizeFile } from "./commands/SummaryCmd.js";
// Create the CLI instance
const cmd = new Command('scai')
.version(version)
.option('--model <model>', 'Set the model to use (e.g., codellama:34b)')
.option('--lang <lang>', 'Set the target language (ts, java, rust)');
// Define CLI commands
cmd
.command('init')
.description('Initialize the model and download required models')
.action(async () => {
await bootstrap();
console.log('✅ Model initialization completed!');
});
cmd
.command('sugg')
.description('Suggest a commit message from staged changes')
.option('-c, --commit', 'Automatically commit with suggested message')
.action(suggestCommitMessage);
cmd
.command('comm <file>')
.description('Write comments for the given file')
.option('-a, --apply', 'Apply the refactored version to the original file')
.action((file, options) => handleRefactor(file, options));
cmd
.command('readme')
.description('Update README.md if relevant changes were made')
.action(updateReadmeIfNeeded);
cmd
.command('summ <file>')
.description('Print a summary of the given file to the terminal')
.action((file) => summarizeFile(file));
cmd
.command('git')
.description('Check Git status')
.action(checkGit);
cmd
.command('env')
.description('Check environment variables')
.action(checkEnv);
cmd
.command('gen-tests <file>')
.description('Generate a Jest test file for the specified JS/TS module')
.action((file) => generateTests(file));
// ✅ Now that commands are defined, parse args
cmd.parse(process.argv);
// ✅ Apply global options after parsing
const opts = cmd.opts();
if (opts.model)
ModelConfig.setModel(opts.model);
if (opts.lang)
ModelConfig.setLanguage(opts.lang);