Skip to content

Commit

Permalink
feat: add ask and edit commands
Browse files Browse the repository at this point in the history
  • Loading branch information
markwylde committed Aug 30, 2024
1 parent 5ab5c52 commit 6c0970c
Show file tree
Hide file tree
Showing 6 changed files with 642 additions and 25 deletions.
34 changes: 15 additions & 19 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import fs from 'node:fs';
import path from 'node:path';
import minimist from 'minimist';
import inquirer from 'inquirer';
import chalk from 'chalk';

import listTypesAndFunctions from '../src/listTypesAndFunctions';
import listFiles from '../src/listFiles';
import { queryModel, listModels } from '../src/ai';
import editFiles from '../src/editFiles';
import selectModel from '../src/selectModel';

const argv = minimist(process.argv.slice(2));

Expand All @@ -20,6 +21,7 @@ Commands:
ls Show a recursive directory tree of all files
types List all types and function signatures for TypeScript and JavaScript files
ask Ask a question to an AI model
edit Apply AI-powered edits to files in the current directory
help Show this help message
Options:
Expand All @@ -30,33 +32,18 @@ Examples:
aitk cat ./src
aitk ls ./src ./tests
aitk types ./src
aitk edit "Refactor the main function to use async/await"
`;

async function selectModel(models: string[]): Promise<string> {
const { model } = await inquirer.prompt([
{
type: 'list',
name: 'model',
message: 'Select a model:',
choices: models,
},
]);
return model;
}

async function main() {
if (argv.help || argv._.includes('help') || argv._.length === 0) {
console.log(helpMessage);
return;
}

const command = argv._[0];
const directories = argv._.slice(1);

if (directories.length === 0 && command !== 'ask') {
directories.push(process.cwd());
}

const args = argv._.slice(1);
let directories = [];
let output = '';

switch (command) {
Expand Down Expand Up @@ -97,6 +84,15 @@ async function main() {
});
console.log();
break;
case 'edit':
if (args.length === 0) {
console.error('Please provide an edit instruction after the "edit" command.');
return;
}
const editInstruction = args.join(' ');
const currentDirectory = process.cwd();
await editFiles([currentDirectory], editInstruction);
break;
case 'types':
directories.forEach(directory => {
if (!fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) {
Expand Down
Loading

0 comments on commit 6c0970c

Please sign in to comment.