()
| 8 | import { callAI } from "../core/ai"; |
| 9 | |
| 10 | export async function suggestCommand() { |
| 11 | if (!(await isInitialized())) { |
| 12 | console.log(chalk.red("✗ DevContext not initialized. Run `devctx init` first.")); |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | try { |
| 17 | const branch = await getCurrentBranch(); |
| 18 | const entries = await loadBranchContext(branch); |
| 19 | const [filesChanged, recentCommits] = await Promise.all([ |
| 20 | getChangedFiles(), |
| 21 | getRecentCommits(10), |
| 22 | ]); |
| 23 | |
| 24 | if (entries.length === 0 && filesChanged.length === 0) { |
| 25 | console.log(chalk.yellow("⚠ No context or changes found. Nothing to analyze.")); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | console.log(chalk.gray(" Analyzing codebase and context...")); |
| 30 | |
| 31 | const latest = entries[entries.length - 1]; |
| 32 | const contextSummary = latest |
| 33 | ? `Current task: ${latest.task} |
| 34 | Current state: ${latest.currentState} |
| 35 | Previous approaches: ${latest.approaches.join(", ") || "none"} |
| 36 | Previous decisions: ${latest.decisions.join(", ") || "none"} |
| 37 | Known blockers: ${latest.blockers?.join(", ") || "none"} |
| 38 | Previous next steps: ${latest.nextSteps.join(", ") || "none"}` |
| 39 | : "No previous context available."; |
| 40 | |
| 41 | const prompt = `You are a senior developer mentor. Based on the following project context, suggest concrete next steps. |
| 42 | |
| 43 | Branch: ${branch} |
| 44 | |
| 45 | ${contextSummary} |
| 46 | |
| 47 | Recent commits: |
| 48 | ${recentCommits.map((c) => `- ${c}`).join("\n")} |
| 49 | |
| 50 | Currently changed files: ${filesChanged.join(", ") || "none"} |
| 51 | |
| 52 | Provide 3-5 specific, actionable next steps. For each step, briefly explain WHY it's important. Format as a numbered list.`; |
| 53 | |
| 54 | const result = await callAI([ |
| 55 | { |
| 56 | role: "system", |
| 57 | content: "You are a helpful senior developer. Be concise and actionable.", |
| 58 | }, |
| 59 | { role: "user", content: prompt }, |
| 60 | ]); |
| 61 | |
| 62 | if (result.error) { |
| 63 | console.log(chalk.red(`✗ ${result.error}`)); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | console.log(chalk.bold.cyan("\n💡 Suggested Next Steps\n")); |
nothing calls this directly
no test coverage detected