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.
This commit is contained in:
Chris Scott committed 2026-10-02 09:53:57 -04:00
1 parent 7cac8baade
commit 7e93eb4c34
35 files changed
+2291 -767

No files matched your search

+28 -107
View File
@@ -1,11 +1,11 @@
import { useState, useCallback } from 'react'
import { useNavigate } from 'react-router-dom'
import { compactSession, runCommand } from '@/api/opencode'
import { useCallback } from 'react'
import { runCommand } from '@/api/opencode'
import type { PromptAgentInput, PromptFileInput, PromptSkillInput } from '@/api/opencode'
import { useCreateSession, useSyncSessionSelection } from '@/hooks/useOpenCode'
import { useSyncSessionSelection } from '@/hooks/useOpenCode'
import { showToast } from '@/lib/toast'
import type { CommandInfo, ModelRef } from '@opencode-manager/shared/opencode'
import { useSessionStatus } from '@/stores/sessionStatusStore'
import { isBuiltinCommand, type CommandActions } from '@/lib/builtinCommands'
interface CommandSubmission {
text: string
@@ -18,129 +18,50 @@ interface CommandHandlerProps {
sessionID: string
directory?: string
model?: ModelRef
onShowSessionsDialog?: () => void
onShowModelsDialog?: () => void
onShowHelpDialog?: () => void
onToggleDetails?: () => boolean
onExportSession?: () => void
onUndo?: () => void | Promise<void>
onRedo?: () => void | Promise<void>
currentAgent?: string
actions: CommandActions
}
export function useCommandHandler({
sessionID,
directory,
model,
onShowSessionsDialog,
onShowModelsDialog,
onShowHelpDialog,
onToggleDetails,
onExportSession,
onUndo,
onRedo,
currentAgent
currentAgent,
actions,
}: CommandHandlerProps) {
const navigate = useNavigate()
const createSession = useCreateSession(directory)
const syncSelection = useSyncSessionSelection(directory)
const setSessionStatus = useSessionStatus((state) => state.setStatus)
const [loading, setLoading] = useState(false)
const executeCommand = useCallback(async (command: CommandInfo, submission: CommandSubmission = { text: '' }): Promise<boolean> => {
setLoading(true)
if (isBuiltinCommand(command)) {
try {
await actions[command.action](submission.text)
return !command.keepsPrompt
} catch (error) {
showToast.error(`Command failed: ${error instanceof Error ? error.message : 'Unknown error'}`)
return false
}
}
try {
switch (command.name) {
case 'sessions':
case 'resume':
case 'continue':
onShowSessionsDialog?.()
return true
case 'models':
onShowModelsDialog?.()
return true
case 'help':
onShowHelpDialog?.()
return true
case 'new':
case 'clear': {
try {
const newSession = await createSession.mutateAsync({
agent: undefined
})
if (newSession?.id) {
const currentPath = window.location.pathname
const repoMatch = currentPath.match(/\/repos\/(\d+)\/sessions\//)
if (repoMatch) {
const repoId = repoMatch[1]
const newPath = `/repos/${repoId}/sessions/${newSession.id}`
navigate(newPath)
} else {
navigate(`/session/${newSession.id}`)
}
}
} catch (error) {
showToast.error(`Failed to create new session: ${error instanceof Error ? error.message : 'Unknown error'}`)
}
return true
}
case 'details':
if (onToggleDetails) {
const expanded = onToggleDetails()
showToast.success(expanded ? 'Tool details expanded' : 'Tool details collapsed')
}
return true
case 'export':
onExportSession?.()
return true
case 'compact': {
showToast.loading('Compacting session...', { id: `compact-${sessionID}` })
setSessionStatus(sessionID, { type: 'compact' })
await compactSession(sessionID)
return true
}
case 'undo':
await onUndo?.()
return false
case 'redo':
await onRedo?.()
return false
default: {
await syncSelection({ sessionID, model, agent: currentAgent })
await runCommand({
sessionID,
name: command.name,
text: submission.text,
...(submission.files ? { files: submission.files } : {}),
...(submission.agents ? { agents: submission.agents } : {}),
...(submission.skills ? { skills: submission.skills } : {}),
})
return true
}
}
await syncSelection({ sessionID, model, agent: currentAgent })
await runCommand({
sessionID,
name: command.name,
text: submission.text,
...(submission.files ? { files: submission.files } : {}),
...(submission.agents ? { agents: submission.agents } : {}),
...(submission.skills ? { skills: submission.skills } : {}),
})
return true
} catch (error) {
showToast.error(`Command failed: ${error instanceof Error ? error.message : 'Unknown error'}`)
setSessionStatus(sessionID, { type: 'idle' })
return false
} finally {
setLoading(false)
}
}, [sessionID, model, onShowSessionsDialog, onShowModelsDialog, onShowHelpDialog, onToggleDetails, onExportSession, onUndo, onRedo, createSession, navigate, syncSelection, currentAgent, setSessionStatus])
}, [actions, sessionID, model, syncSelection, currentAgent, setSessionStatus])
return {
executeCommand,
loading
executeCommand
}
}