Files
opencode-manager/frontend/src/lib/builtinCommands.ts
T
Chris Scott 7e93eb4c34 feat(commands): align built-in slash commands with OpenCode v2
Replace the split built-in command name list and switch with one typed
registry, so a registered command without a handler is a compile error.
Remove the broken themes/share/unshare/editor entries and the hardcoded
init; server and custom commands now win on a name clash and built-ins
dispatch by registry identity.

Add /copy, /btw, /rename, /fork (message picker), /timeline, /model,
/agent, /variants, /mcp, /skills, /settings and /connect. Open the model
picker through state so /model and the select-model shortcut work while a
response is running, load full session history in the fork picker, and
keep attachments when a built-in command is submitted.

Extract shared clipboard and primary-agent helpers, reuse CopyButton in
the manager token settings, and update the Quick Start and chat docs.
2026-10-02 09:53:57 -04:00

68 lines
3.3 KiB
TypeScript

import type { CommandInfo } from '@opencode-manager/shared/opencode'
export const BUILTIN_COMMAND_ACTIONS = [
'showSessions',
'showModels',
'newSession',
'toggleDetails',
'exportSession',
'copyTranscript',
'compact',
'askSideQuestion',
'renameSession',
'forkSession',
'jumpToMessage',
'undo',
'redo',
'cycleAgent',
'cycleVariant',
'showMcp',
'showSkills',
'showSettings',
'connectProvider',
] as const
type BuiltinCommandAction = (typeof BUILTIN_COMMAND_ACTIONS)[number]
type CommandActionHandler = (argument: string) => void | Promise<void>
export type CommandActions = Record<BuiltinCommandAction, CommandActionHandler>
export type PageCommandActions = Omit<CommandActions, 'cycleAgent' | 'cycleVariant'>
interface BuiltinCommand extends CommandInfo {
action: BuiltinCommandAction
keepsPrompt?: boolean
}
export const BUILTIN_COMMANDS: readonly BuiltinCommand[] = [
{ name: 'help', description: 'Show the help dialog', action: 'showSettings' },
{ name: 'new', description: 'Start a new session', action: 'newSession' },
{ name: 'clear', description: 'Start a new session (alias for /new)', action: 'newSession' },
{ name: 'sessions', description: 'List and switch between sessions', action: 'showSessions' },
{ name: 'resume', description: 'List and switch between sessions (alias for /sessions)', action: 'showSessions' },
{ name: 'continue', description: 'List and switch between sessions (alias for /sessions)', action: 'showSessions' },
{ name: 'models', description: 'List available models', action: 'showModels' },
{ name: 'model', description: 'Choose a model', action: 'showModels' },
{ name: 'agent', description: 'Switch to the next primary agent', action: 'cycleAgent' },
{ name: 'variants', description: 'Cycle the model reasoning variant', action: 'cycleVariant' },
{ name: 'export', description: 'Export current conversation to Markdown', action: 'exportSession' },
{ name: 'copy', description: 'Copy the session transcript to the clipboard', action: 'copyTranscript' },
{ name: 'compact', description: 'Compact the current session', action: 'compact' },
{ name: 'btw', description: 'Ask a side question without adding it to the conversation', action: 'askSideQuestion' },
{ name: 'rename', description: 'Rename the session, or regenerate its title when no title is given', action: 'renameSession' },
{ name: 'fork', description: 'Fork the session from a chosen message', action: 'forkSession' },
{ name: 'timeline', description: 'Jump to a message in the conversation', action: 'jumpToMessage' },
{ name: 'undo', description: 'Undo last message in the conversation', action: 'undo', keepsPrompt: true },
{ name: 'redo', description: 'Redo a previously undone message', action: 'redo', keepsPrompt: true },
{ name: 'details', description: 'Toggle tool execution details', action: 'toggleDetails' },
{ name: 'mcp', description: 'Manage MCP servers', action: 'showMcp' },
{ name: 'skills', description: 'Load a skill', action: 'showSkills' },
{ name: 'settings', description: 'Open settings', action: 'showSettings' },
{ name: 'connect', description: 'Connect a provider', action: 'connectProvider' },
]
export function isBuiltinCommand(command: CommandInfo): command is BuiltinCommand {
return 'action' in command
}