UNPKG

mycoder

Version:

A command line tool using agent that can do arbitrary tasks, including coding tasks

46 lines 1.8 kB
import { loadConfig } from '../settings/config.js'; import { executePrompt } from './$default.js'; /** * Gets custom commands defined in the config file * @returns Array of command modules for custom commands */ export async function getCustomCommands() { const config = await loadConfig(); if (!config.commands) { return []; } return Object.entries(config.commands).map(([name, commandConfig]) => { return { command: `${name} ${(commandConfig.args || []) .map((arg) => (arg.required ? `<${arg.name}>` : `[${arg.name}]`)) .join(' ')}`, describe: commandConfig.description || `Custom command: ${name}`, builder: (yargs) => { // Register args as options (commandConfig.args || []).forEach((arg) => { yargs.option(arg.name, { type: 'string', description: arg.description, default: arg.default, demandOption: arg.required, }); }); return yargs; }, handler: async (argv) => { // Extract args const args = (commandConfig.args || []).reduce((acc, arg) => { acc[arg.name] = argv[arg.name]; return acc; }, {}); // Load config const config = await loadConfig(); // Execute the command const prompt = await commandConfig.execute(args); // Execute the prompt using the default command handler await executePrompt(prompt, config); }, }; }); } //# sourceMappingURL=custom.js.map