feat(opencode): migrate OpenCode Manager to OpenCode 2 (#359)

* feat(opencode): migrate OpenCode Manager to OpenCode 2

Port the backend lifecycle, generated plugins, event aggregation,
schedules, worktrees, provider credentials, MCP, config handling, the
frontend chat model, and the ocm CLI to OpenCode 2.

Adopt @opencode/client 2.0.15 as the single typed V2 API contract,
require OpenCode 2.0.0 or newer (pinned 2.0.15), and delete every
V1-only code path.

* refactor(opencode): reload config in place and drop v1 compatibility shims

Route config/skill/AGENTS.md changes through the OpenCode location reload
API instead of a full server restart, stop auto-resuming interrupted
sessions, remove the restart coordinator and v1 MCP/version shims, and pin
support to OpenCode >=2.0.15 <3.0.0. Adds integration-ready retries,
service-mode launch, ocm-cli repo proxy, and new frontend form/MCP helpers.

* refactor(opencode): consolidate v2 migration helpers and harden install, proxy, and session flows

- extract shared semver and model-ref utilities, reuse across version checks
- share the OpenCode release download script across Docker, entrypoint, dev setup
- unify install/upgrade failure recovery and guard externally managed OPENCODE_BIN
- scope the repo proxy location rewrite and surface ocm proxy errors
- rework frontend session projection, permission lookup, and cache invalidation

* fix(schedules): reject unavailable agents before creating a session

* feat(opencode): add ocm install, schedule agent fallback, and session move guards
This commit is contained in:
Chris Scott authored and GitHub committed 2026-09-26 13:16:45 -04:00
1 parent 6c2ebd764b
commit dacde879d6
383 files changed
+29905 -46566

No files matched your search

+35 -159
View File
@@ -1,189 +1,65 @@
import { useQuery } from '@tanstack/react-query'
import { createOpenCodeClient } from '@/api/opencode'
import type { components } from '@/api/opencode-types'
import { listCommands } from '@/api/opencode'
import type { CommandInfo } from '@opencode-manager/shared/opencode'
type CommandType = components['schemas']['Command']
function sortCommandsByName(commands: CommandType[]): CommandType[] {
function sortCommandsByName(commands: CommandInfo[]): CommandInfo[] {
return [...commands].sort((a, b) => a.name.localeCompare(b.name))
}
function rankCommandMatch(command: CommandType, searchTerm: string): number {
function rankCommandMatch(command: CommandInfo, searchTerm: string): number {
const name = command.name.toLowerCase()
if (name === searchTerm) return 0
if (name.startsWith(searchTerm)) return 1
return 2
}
// Built-in OpenCode commands
const BUILTIN_COMMANDS: CommandType[] = [
{
name: 'help',
description: 'Show the help dialog',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'init',
description: 'Create or update AGENTS.md file',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'new',
description: 'Start a new session',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'clear',
description: 'Start a new session (alias for /new)',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'sessions',
description: 'List and switch between sessions',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'resume',
description: 'List and switch between sessions (alias for /sessions)',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'continue',
description: 'List and switch between sessions (alias for /sessions)',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'models',
description: 'List available models',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'themes',
description: 'List available themes',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'share',
description: 'Share current session',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'unshare',
description: 'Unshare current session',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'export',
description: 'Export current conversation to Markdown',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'compact',
description: 'Compact the current session',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'summarize',
description: 'Compact the current session (alias for /compact)',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'undo',
description: 'Undo last message in the conversation',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'redo',
description: 'Redo a previously undone message',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'details',
description: 'Toggle tool execution details',
template: '',
agent: '',
model: '',
hints: []
},
{
name: 'editor',
description: 'Open external editor for composing messages',
template: '',
agent: '',
model: '',
hints: []
}
const BUILTIN_COMMANDS: CommandInfo[] = [
{ name: 'help', description: 'Show the help dialog' },
{ name: 'init', description: 'Create or update AGENTS.md file' },
{ name: 'new', description: 'Start a new session' },
{ name: 'clear', description: 'Start a new session (alias for /new)' },
{ name: 'sessions', description: 'List and switch between sessions' },
{ name: 'resume', description: 'List and switch between sessions (alias for /sessions)' },
{ name: 'continue', description: 'List and switch between sessions (alias for /sessions)' },
{ name: 'models', description: 'List available models' },
{ name: 'themes', description: 'List available themes' },
{ name: 'share', description: 'Share current session' },
{ name: 'unshare', description: 'Unshare current session' },
{ name: 'export', description: 'Export current conversation to Markdown' },
{ name: 'compact', description: 'Compact the current session' },
{ name: 'undo', description: 'Undo last message in the conversation' },
{ name: 'redo', description: 'Redo a previously undone message' },
{ name: 'details', description: 'Toggle tool execution details' },
{ name: 'editor', description: 'Open external editor for composing messages' },
]
const SORTED_BUILTIN_COMMANDS = sortCommandsByName(BUILTIN_COMMANDS)
export function useCommands(opcodeUrl: string | null) {
interface UseCommandsOptions {
directory?: string
enabled?: boolean
}
export function useCommands(options: UseCommandsOptions = {}) {
const { directory, enabled = true } = options
const { data: commands, isLoading: loading, error } = useQuery({
queryKey: ['opencode', 'commands', opcodeUrl],
queryKey: ['opencode', 'commands', directory ?? null],
queryFn: async () => {
const client = createOpenCodeClient(opcodeUrl!)
const commandList = await client.listCommands()
const allCommands = [...BUILTIN_COMMANDS, ...commandList]
const loaded = await listCommands(directory)
const allCommands = [...BUILTIN_COMMANDS, ...loaded]
const uniqueCommands = allCommands.filter((command, index, self) =>
index === self.findIndex((c) => c.name === command.name)
)
return sortCommandsByName(uniqueCommands)
},
enabled: !!opcodeUrl,
enabled,
initialData: SORTED_BUILTIN_COMMANDS,
})
const filterCommands = (query: string) => {
if (!query.trim()) return commands
const searchTerm = query.toLowerCase()
return commands
.filter(command => command.name.toLowerCase().includes(searchTerm))