import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { listTickets, isInitialized } from "../utils.js"; /** * /docgraph:tickets — Display the Kanban ticket board. */ export function registerDocgraphTicketsCommand(pi: ExtensionAPI): void { pi.registerCommand("docgraph:tickets", { description: "Display the docgraph ticket board", handler: async (_args, ctx) => { if (!isInitialized(ctx)) { ctx.ui.notify( "Docgraph not initialized. Run /docgraph:init or ask the agent to run docgraph_init.", "warning", ); return; } const tickets = listTickets(ctx.cwd); if (tickets.length === 0) { ctx.ui.notify("No tickets yet. Ask the agent to create one!", "info"); return; } // Group by status const groups = new Map(); for (const t of tickets) { const existing = groups.get(t.status); if (existing) existing.push(t); else groups.set(t.status, [t]); } const order = ["backlog", "ready", "in-progress", "review", "done", "blocked"]; const lines: string[] = []; lines.push(`--- Ticket Board (${tickets.length} total) ---`); for (const status of order) { const items = groups.get(status); if (!items || items.length === 0) continue; lines.push(`\n[${status.toUpperCase()}]`); for (const t of items) { lines.push(` T-${t.id} ${t.priority} ${t.title}`); } } ctx.ui.notify(lines.join("\n"), "info"); }, }); } /** * /docgraph:init — Trigger documentation initialization. */ export function registerDocgraphInitCommand(pi: ExtensionAPI): void { pi.registerCommand("docgraph:init", { description: "Initialize docgraph documentation scaffolding", handler: async (_args, ctx) => { if (isInitialized(ctx)) { ctx.ui.notify( "Docgraph already initialized. Use /docgraph:sync to refresh, or ask the agent to re-init with force.", "info", ); return; } ctx.ui.notify( "Docgraph not initialized. Ask the agent to run the docgraph_init tool.", "warning", ); }, }); } /** * /docgraph:sync — Trigger documentation sync with codebase. */ export function registerDocgraphSyncCommand(pi: ExtensionAPI): void { pi.registerCommand("docgraph:sync", { description: "Sync documentation with codebase", handler: async (_args, ctx) => { if (!isInitialized(ctx)) { ctx.ui.notify( "Docgraph not initialized. Run /docgraph:init or ask the agent.", "warning", ); return; } ctx.ui.notify( "Ask the agent to run docgraph_sync to validate and update documentation.", "info", ); }, }); } /** * /docgraph:graph — Display the documentation graph structure. */ export function registerDocgraphGraphCommand(pi: ExtensionAPI): void { pi.registerCommand("docgraph:graph", { description: "Display the documentation graph", handler: async (_args, ctx) => { if (!isInitialized(ctx)) { ctx.ui.notify( "Docgraph not initialized. Run /docgraph:init or ask the agent.", "warning", ); return; } const lines = [ "Documentation Graph:", "", " README.md ─── Human entry point", " └── AGENTS.md ─── AI entry point", " ├── docs/SPEC.md ─── What & Why", " ├── docs/ARCHITECTURE.md ─── How", " ├── docs/API.md ─── Contracts", " ├── docs/DESIGN.md ─── Design system", " ├── docs/ROADMAP.md ─── Vision", " ├── docs/BACKLOG.md ─── Work queue", " └── docs/tickets/ ─── Individual tickets", ]; ctx.ui.notify(lines.join("\n"), "info"); }, }); } /** * Register all docgraph commands. */ export function registerAllCommands(pi: ExtensionAPI): void { registerDocgraphTicketsCommand(pi); registerDocgraphInitCommand(pi); registerDocgraphSyncCommand(pi); registerDocgraphGraphCommand(pi); }