Share slash command definitions

This commit is contained in:
weishu
2026-05-21 10:36:25 +08:00
parent d6f97065c1
commit 2e1e2d39db
10 changed files with 91 additions and 148 deletions
+1
View File
@@ -9,6 +9,7 @@
".": "./src/index.ts",
"./apiTypes": "./src/apiTypes.ts",
"./messages": "./src/messages.ts",
"./slashCommands": "./src/slashCommands.ts",
"./buildInfo": "./src/buildInfo.ts",
"./modes": "./src/modes.ts",
"./schemas": "./src/schemas.ts",
+14
View File
@@ -93,3 +93,17 @@ export type OpencodeModelsResponse = {
}
export type ListOpencodeModelsResponse = OpencodeModelsResponse
export type SlashCommand = {
name: string
description?: string
source: 'builtin' | 'user' | 'plugin' | 'project'
content?: string
pluginName?: string
}
export type SlashCommandsResponse = {
success: boolean
commands?: SlashCommand[]
error?: string
}
+1
View File
@@ -7,6 +7,7 @@ export * from './modes'
export * from './resume'
export * from './socket'
export * from './sessionSummary'
export * from './slashCommands'
export * from './utils'
export * from './version'
export type * from './types'
+55
View File
@@ -0,0 +1,55 @@
import type { SlashCommand } from './apiTypes'
export const BUILTIN_SLASH_COMMANDS = {
claude: [
{ name: 'clear', description: 'Clear conversation history and free up context', source: 'builtin' },
{ name: 'compact', description: 'Clear conversation history but keep a summary in context', source: 'builtin' },
{ name: 'context', description: 'Visualize current context usage as a colored grid', source: 'builtin' },
{ name: 'cost', description: 'Show the total cost and duration of the current session', source: 'builtin' },
{ name: 'doctor', description: 'Diagnose and verify your Claude Code installation and settings', source: 'builtin' },
{ name: 'plan', description: 'View or open the current session plan', source: 'builtin' },
{ name: 'stats', description: 'Show your Claude Code usage statistics and activity', source: 'builtin' },
{ name: 'status', description: 'Show Claude Code status including version, model, account, and API connectivity', source: 'builtin' },
],
codex: [
{ name: 'clear', description: 'Clear current Codex thread context', source: 'builtin' },
{ name: 'compact', description: 'Compact current Codex thread context', source: 'builtin' },
{ name: 'goal', description: 'Set, view, pause, resume, or clear a persistent Codex goal', source: 'builtin' },
{ name: 'help', description: 'Show supported HAPI Codex slash commands', source: 'builtin' },
{ name: 'plan', description: 'Enable plan mode; use /plan off to return to default', source: 'builtin' },
{ name: 'default', description: 'Return Codex collaboration mode to default', source: 'builtin' },
{ name: 'execute', description: 'Return Codex collaboration mode to default', source: 'builtin' },
{ name: 'status', description: 'Show current Codex session config', source: 'builtin' },
{ name: 'model', description: 'Show or set Codex model, e.g. /model gpt-5.5', source: 'builtin' },
{ name: 'reasoning', description: 'Show or set reasoning effort', source: 'builtin' },
{ name: 'effort', description: 'Alias for /reasoning', source: 'builtin' },
{ name: 'permissions', description: 'Show or set permission mode', source: 'builtin' },
{ name: 'permission', description: 'Alias for /permissions', source: 'builtin' },
],
gemini: [
{ name: 'about', description: 'Show version info', source: 'builtin' },
{ name: 'clear', description: 'Clear the screen and conversation history', source: 'builtin' },
{ name: 'compress', description: 'Compress the context by replacing it with a summary', source: 'builtin' },
{ name: 'stats', description: 'Check session stats', source: 'builtin' },
],
opencode: [],
cursor: [],
} as const satisfies Record<string, readonly SlashCommand[]>
export function getBuiltinSlashCommands(agent: string): SlashCommand[] {
const commands = BUILTIN_SLASH_COMMANDS[agent as keyof typeof BUILTIN_SLASH_COMMANDS]
?? BUILTIN_SLASH_COMMANDS.claude
return commands.map((command) => ({ ...command }))
}
export function mergeSlashCommands(commands: readonly SlashCommand[]): SlashCommand[] {
const commandMap = new Map<string, SlashCommand>()
for (const command of commands) {
const key = command.name.toLowerCase()
if (commandMap.has(key)) {
commandMap.delete(key)
}
commandMap.set(key, command)
}
return Array.from(commandMap.values())
}