import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; import { qPrompt } from "../lib/prompts.js"; export function registerQCommand(pi: ExtensionAPI) { pi.registerCommand("hive:q", { description: "Ask questions about the project (read-only, no code generation)", handler: async (args, ctx) => { const question = args?.trim(); if (!question) { ctx.ui.notify("Usage: /hive:q \n\nExample: /hive:q What endpoints does the API have?", "info"); return; } // Restrict to read-only tools for safety const allTools = pi.getAllTools().map((t) => t.name); const readOnlyTools = allTools.filter((t) => ["read", "bash", "grep", "find", "ls"].includes(t), ); const previousTools = pi.getActiveTools(); pi.setActiveTools(readOnlyTools); // Restore tools after the agent finishes const cleanup = () => { pi.setActiveTools(previousTools); }; pi.on("agent_end", async () => { cleanup(); }); // Send the exploration prompt pi.sendUserMessage(qPrompt(question)); }, }); }