import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; import * as fs from "node:fs"; import * as path from "node:path"; import { parseFeaturesMd, getStats } from "../lib/features-parser.js"; export function registerNextCommand(pi: ExtensionAPI) { pi.registerCommand("hive:next", { description: "Show the next feature to implement", handler: async (_args, ctx) => { const featuresPath = path.join(ctx.cwd, "features.md"); if (!fs.existsSync(featuresPath)) { ctx.ui.notify("features.md not found. Run /hive:spec first.", "warning"); return; } const content = fs.readFileSync(featuresPath, "utf-8"); const features = parseFeaturesMd(content); const stats = getStats(features); if (stats.pending.length === 0) { if (stats.inProgress.length > 0) { ctx.ui.notify(`No ready features. ${stats.inProgress.length} in progress.`, "info"); } else if (stats.done.length === stats.total) { ctx.ui.notify("All features complete! 🎉", "info"); } else { ctx.ui.notify(`${stats.blocked.length} features blocked by dependencies.`, "warning"); } return; } const next = stats.pending[0]; ctx.ui.notify( `Next: Feature ${next.number}: ${next.title}\n\n${next.description}\n\nDependencies: ${next.dependencies}`, "info", ); }, }); }