|
| 1 | +/** |
| 2 | + * Server slash-command route metadata. |
| 3 | + * |
| 4 | + * Summary: |
| 5 | + * Maps supported DeepCode runtime slash commands to HTTP route metadata for the |
| 6 | + * local server. This module is intentionally independent from the CLI slash |
| 7 | + * command table so server behavior does not depend on terminal UI code. |
| 8 | + * |
| 9 | + * Exports: |
| 10 | + * - buildHeadlessCommandRoutes(): HeadlessCommandRoute[] |
| 11 | + * - findHeadlessCommandRoute(pathname: string): HeadlessCommandRoute | null |
| 12 | + */ |
| 13 | +export type HeadlessCommandRoute = { |
| 14 | + name: string; |
| 15 | + label: string; |
| 16 | + description: string; |
| 17 | + method: "GET" | "POST"; |
| 18 | + path: string; |
| 19 | + aliases: string[]; |
| 20 | + implemented: boolean; |
| 21 | +}; |
| 22 | + |
| 23 | +type RuntimeCommand = { |
| 24 | + name: string; |
| 25 | + label: string; |
| 26 | + description: string; |
| 27 | +}; |
| 28 | + |
| 29 | +const RUNTIME_COMMANDS: RuntimeCommand[] = [ |
| 30 | + { name: "skills", label: "/skills", description: "List available skills" }, |
| 31 | + { name: "model", label: "/model", description: "Select model, thinking mode and effort control" }, |
| 32 | + { name: "new", label: "/new", description: "Start a fresh conversation" }, |
| 33 | + { name: "init", label: "/init", description: "Initialize an AGENTS.md file with instructions for LLM" }, |
| 34 | + { name: "resume", label: "/resume", description: "Pick a previous conversation to continue" }, |
| 35 | + { name: "continue", label: "/continue", description: "Continue the active conversation or pick one to resume" }, |
| 36 | + { name: "undo", label: "/undo", description: "Restore code and/or conversation to a previous point" }, |
| 37 | + { name: "mcp", label: "/mcp", description: "Show MCP server status and available tools" }, |
| 38 | + { name: "raw", label: "/raw", description: "CLI display mode command; no backend raw display state is exposed" }, |
| 39 | + { name: "exit", label: "/exit", description: "Quit Deep Code server" }, |
| 40 | +]; |
| 41 | + |
| 42 | +const READ_ONLY_COMMANDS = new Set(["skills", "resume", "mcp", "model"]); |
| 43 | +const IMPLEMENTED_COMMANDS = new Set(["skills", "new", "init", "resume", "continue", "undo", "mcp", "model", "exit"]); |
| 44 | + |
| 45 | +function commandMethod(command: RuntimeCommand): "GET" | "POST" { |
| 46 | + return READ_ONLY_COMMANDS.has(command.name) ? "GET" : "POST"; |
| 47 | +} |
| 48 | + |
| 49 | +function commandAliases(command: RuntimeCommand): string[] { |
| 50 | + if (command.name === "model") { |
| 51 | + return ["/model"]; |
| 52 | + } |
| 53 | + return [`/${command.name}`, `/api/${command.name}`]; |
| 54 | +} |
| 55 | + |
| 56 | +export function buildHeadlessCommandRoutes(): HeadlessCommandRoute[] { |
| 57 | + return RUNTIME_COMMANDS.map((command) => ({ |
| 58 | + name: command.name, |
| 59 | + label: command.label, |
| 60 | + description: command.description, |
| 61 | + method: commandMethod(command), |
| 62 | + path: `/${command.name}`, |
| 63 | + aliases: commandAliases(command), |
| 64 | + implemented: IMPLEMENTED_COMMANDS.has(command.name), |
| 65 | + })); |
| 66 | +} |
| 67 | + |
| 68 | +export function findHeadlessCommandRoute(pathname: string): HeadlessCommandRoute | null { |
| 69 | + const normalized = pathname.replace(/\/+$/u, "") || "/"; |
| 70 | + return buildHeadlessCommandRoutes().find((route) => route.aliases.includes(normalized)) ?? null; |
| 71 | +} |
0 commit comments