import { BUILTIN_SLASH_COMMANDS } from "../../../../../../packages/coding-agent/src/core/slash-commands.ts"; import { filterWebUiSlashCommands, type SlashCommandEntry } from "../slash/dispatch.ts"; import type { SendCmd } from "../types/context.ts"; export async function listSlashCommands(sendCmd: SendCmd): Promise { const builtinNames = new Set(BUILTIN_SLASH_COMMANDS.map((command) => command.name)); const commands: SlashCommandEntry[] = BUILTIN_SLASH_COMMANDS.map((command) => ({ name: command.name, description: command.description, source: "builtin", })); const response = await sendCmd({ type: "get_commands" }); if (!response.success) throw new Error(response.error || "读取命令失败"); for (const command of response.data?.commands || []) { const name = String(command?.name || ""); if (!name) continue; const source = String(command?.source || ""); if (source === "extension" && builtinNames.has(name)) continue; if (source === "prompt") { commands.push({ name, description: String(command.description || ""), source: "prompt", }); continue; } if (source === "skill") { commands.push({ name, description: String(command.description || ""), source: "skill", }); continue; } if (source === "extension") { commands.push({ name, description: String(command.description || ""), source: "extension", }); } } return filterWebUiSlashCommands(commands).sort((a, b) => a.name.localeCompare(b.name)); }