import chalk from 'chalk'; import axios from 'axios'; import ora from 'ora'; interface RoadmapStep { id: string; title: string; step_number: number; description: string; status: string; role: string; } export async function suggestNextMove(projectId: string, apiKey: string, apiUrl: string) { // Silent spinner just to fetch data quickly // const spinner = ora('Analyzing mission parameters...').start(); try { // We use the roadmap chunks endpoint or a dedicated query // For CLI efficiency, let's query raw chunks via a unified endpoint if possible // Or assume we have a direct endpoint. // Let's use the standard `list_roadmap_tasks` equivalent logic via REST API if available. // Assuming /api/v1/roadmap/next exists or similar. // If not, we query pending tasks. const response = await axios.get(`${apiUrl}/api/v1/roadmap/chunks`, { params: { project_id: projectId, status: 'PENDING', limit: 1, order: 'step_number.asc' }, headers: { Authorization: `Bearer ${apiKey}` } }); if (!response.data.success) { return; // Fail silently, feature relies on API being ready } const tasks = response.data.data.chunks || []; if (tasks.length === 0) return; const nextTask = tasks[0] as RoadmapStep; // Visual Presentation console.log(''); console.log(chalk.bold('🎯 TACTICAL INTELLIGENCE')); console.log(chalk.dim('────────────────────────────────────────')); console.log(`${chalk.bold('Active Phase:')} Implementation`); console.log(`${chalk.bold('Next Mission:')} ${chalk.cyan(nextTask.title)}`); if (nextTask.role) { console.log(`${chalk.bold('Required Role:')} ${chalk.magenta(nextTask.role)}`); } console.log(''); console.log(chalk.yellow('SUGGESTED NEXT MOVE:')); console.log(chalk.white(`> rigstate work start ${nextTask.id} `) + chalk.dim('(Start this task)')); console.log(chalk.white(`> rigstate chat "How do I solve T-${nextTask.step_number}?" `) + chalk.dim('(Ask Architect)')); console.log(chalk.dim('────────────────────────────────────────')); console.log(''); } catch (e) { // Ignore errors in suggestion engine to not break the flow } }