UNPKG

autoheal

Version:

GPT Test driven development. Automatically fix tests and guide GPT to write and fix code using your tests.

64 lines (63 loc) 2.48 kB
#!/usr/bin/env node var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { Command } from "commander"; import inquirer from "inquirer"; import { run } from "./run.js"; import { renderTitle } from "./render-title.js"; import chalk from "chalk"; import { languageModels } from "./llm-models.js"; const program = new Command(); renderTitle(); program .name("Auto Heal") .description("Heal your source code") .action(() => { const noApiKeyDetected = !process.env.OPENAI_API_KEY; const prompts = [ ...(noApiKeyDetected ? [ { type: "input", name: "apiKey", message: "What is your OpenAI API key?", }, ] : []), { type: "input", name: "testCommand", message: "What is the command to run the tests?", default: "npm test", }, { type: "list", name: "model", message: "Which OpenAI model?", choices: Object.keys(languageModels).map((key) => ({ name: key, value: key, })), }, ]; if (noApiKeyDetected) { console.log(`OpenAI API keys can found here: ${chalk.bold("https://platform.openai.com/account/api-keys")}\n\nYou can automatically provide your API key to autoheal by adding the key to your env with:\n${chalk.dim("export OPENAI_API_KEY=key")}\n`); } else { console.log(`🔑 API key found: ${chalk.dim("env.OPENAI_API_KEY")}\n`); } inquirer.prompt(prompts).then((answers) => __awaiter(void 0, void 0, void 0, function* () { if (answers.apiKey) { process.env.OPENAI_API_KEY = answers.apiKey; } run(answers); })); }); program.parse(process.argv);