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"; import { RUN_PROMPT } from "../lib/prompts.js"; export function registerRunCommand(pi: ExtensionAPI) { pi.registerCommand("hive:run", { description: "Run sequential feature implementation from features.md", 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.total === 0) { ctx.ui.notify("No features found in features.md.", "warning"); return; } if (stats.done.length === stats.total) { ctx.ui.notify("All features are already done! 🎉", "info"); return; } if (stats.pending.length === 0 && stats.inProgress.length === 0) { ctx.ui.notify( `No features ready. ${stats.blocked.length} blocked by dependencies.`, "warning", ); return; } ctx.ui.notify( `Starting Hive Run: ${stats.pending.length} ready, ${stats.blocked.length} blocked, ${stats.done.length}/${stats.total} done`, "info", ); // Inject the run prompt — the LLM takes over from here pi.sendUserMessage(RUN_PROMPT); }, }); }