import { Command } from 'commander'; import chalk from 'chalk'; import ora from 'ora'; import axios from 'axios'; import inquirer from 'inquirer'; import { getApiKey, getApiUrl, getProjectId } from '../utils/config.js'; export function createIdeaCommand(): Command { return new Command('idea') .description('Capture a new idea or feature request') .argument('[title]', 'Quick title of the idea') .option('-d, --desc ', 'Detailed description') .option('-t, --tag ', 'Comma separated tags (e.g. ui,auth)') .action(async (title, options) => { try { const apiKey = getApiKey(); const apiUrl = getApiUrl(); const projectId = getProjectId(); if (!projectId) { console.error(chalk.red('Project context missing. Run rigstate link.')); process.exit(1); } // Interactive Inputs if missing let ideaTitle = title; let ideaDesc = options.desc; let tags = options.tag ? options.tag.split(',') : []; if (!ideaTitle) { const ans = await inquirer.prompt([{ type: 'input', name: 'title', message: 'Idea Title:' }]); ideaTitle = ans.title; } if (!ideaDesc) { const ans = await inquirer.prompt([{ type: 'input', name: 'desc', message: 'Description (Optional):' }]); ideaDesc = ans.desc; } if (tags.length === 0) { // Maybe ask for tags? Or just let it be empty } const spinner = ora('Securing idea in the Lab...').start(); // Submit to API const response = await axios.post( `${apiUrl}/api/v1/ideas`, { project_id: projectId, title: ideaTitle, description: ideaDesc, tags }, { headers: { Authorization: `Bearer ${apiKey}` } } ); if (response.data.success) { spinner.succeed(chalk.green('Idea Captured! 💡')); console.log(chalk.dim(`ID: ${response.data.data?.id || 'Saved'}`)); } else { throw new Error(response.data.error); } } catch (e: any) { const errorDetail = e.response?.data?.error || e.message; console.error(chalk.red(`\nFailed to capture idea: ${errorDetail}`)); } }); }