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

@@ -9,16 +9,13 @@ import { useUIState } from '@/stores/uiStateStore'
import { useQuery } from '@tanstack/react-query'
import { getRepo } from '@/api/repos'
import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
import { OPENCODE_API_ENDPOINT } from '@/config'
import { SideDrawer, SideDrawerContent } from '@/components/ui/side-drawer'
import { FileBrowserSheet } from '@/components/file-browser/FileBrowserSheet'
import { buildMoreItems } from './moreDrawerItems'
import { useSwipeBack } from '@/hooks/useMobile'
import { getRepoDisplayName } from '@/lib/utils'
import { getPathWithReturnTo, isAssistantPath } from '@/lib/navigation'
import type { components } from '@/api/opencode-types'
type CommandType = components['schemas']['Command']
import type { CommandInfo } from '@opencode-manager/shared/opencode'
interface MoreDrawerProps {
isOpen: boolean
@@ -40,7 +37,7 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
const isSessionDetail = /^\/repos\/\d+\/sessions\/[^/]+$/.test(location.pathname)
const isAssistantRoute = isAssistantPath(location.pathname)
const isAssistantSession = isSessionDetail && searchParams.get('assistant') === '1'
const { filterCommands } = useCommands(isSessionDetail ? OPENCODE_API_ENDPOINT : null)
const { filterCommands } = useCommands({ enabled: isSessionDetail })
const activePromptFileBasePath = useUIState((state) => state.activePromptFileBasePath)
const selectPromptCommand = useUIState((state) => state.selectPromptCommand)
const selectPromptFile = useUIState((state) => state.selectPromptFile)
@@ -95,7 +92,7 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
}
}
const handleCommandClick = (command: CommandType) => {
const handleCommandClick = (command: CommandInfo) => {
selectPromptCommand(command)
onClose()
}
@@ -2,7 +2,7 @@ import { render, screen, fireEvent } from '@testing-library/react'
import { describe, it, expect, vi } from 'vitest'
import { MemoryRouter } from 'react-router-dom'
import { NotificationsSheet } from './NotificationsSheet'
import { usePermissions, useQuestions } from '@/contexts/EventContext'
import { usePermissions, useForms } from '@/contexts/EventContext'
vi.mock('@/contexts/EventContext')
@@ -19,17 +19,15 @@ describe('NotificationsSheet', () => {
current: null,
respond: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useQuestions).mockReturnValue({
vi.mocked(useForms).mockReturnValue({
pendingCount: 0,
navigateToCurrent: vi.fn(),
current: null,
reply: vi.fn(),
reject: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
const handleClose = vi.fn()
@@ -48,28 +46,21 @@ describe('NotificationsSheet', () => {
current: {
id: 'perm-1',
sessionID: 'session-1',
permission: 'write',
patterns: ['/test/pattern'],
action: 'shell',
resources: ['/test/pattern'],
metadata: {},
always: [],
tool: {
messageID: 'msg-1',
callID: 'call-1',
},
},
respond: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useQuestions).mockReturnValue({
vi.mocked(useForms).mockReturnValue({
pendingCount: 0,
navigateToCurrent: vi.fn(),
current: null,
reply: vi.fn(),
reject: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
const handleClose = vi.fn()
@@ -78,10 +69,11 @@ describe('NotificationsSheet', () => {
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
expect(screen.getByText('Pending permissions')).toBeInTheDocument()
expect(screen.getByText('Run Command')).toBeInTheDocument()
expect(screen.getByText('+1 more')).toBeInTheDocument()
})
it('renders question section with pending count', () => {
it('renders form section with pending count', () => {
vi.mocked(usePermissions).mockReturnValue({
pendingCount: 0,
setShowDialog: vi.fn(),
@@ -89,29 +81,20 @@ describe('NotificationsSheet', () => {
current: null,
respond: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useQuestions).mockReturnValue({
vi.mocked(useForms).mockReturnValue({
pendingCount: 1,
navigateToCurrent: vi.fn(),
current: {
id: 'q-1',
id: 'form-1',
sessionID: 'session-1',
questions: [{
question: 'Test question',
options: [],
}],
metadata: {},
tool: {
messageID: 'msg-1',
callID: 'call-1',
},
title: 'Test question',
fields: [{ key: 'q0', type: 'string', options: [] }],
},
reply: vi.fn(),
reject: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
const handleClose = vi.fn()
@@ -119,7 +102,7 @@ describe('NotificationsSheet', () => {
<NotificationsSheet isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
expect(screen.getByText('Pending questions')).toBeInTheDocument()
expect(screen.getByText('Pending forms')).toBeInTheDocument()
expect(screen.getByText('Test question')).toBeInTheDocument()
})
@@ -134,28 +117,21 @@ describe('NotificationsSheet', () => {
current: {
id: 'perm-1',
sessionID: 'session-1',
permission: 'write',
patterns: ['/test/pattern'],
action: 'shell',
resources: ['/test/pattern'],
metadata: {},
always: [],
tool: {
messageID: 'msg-1',
callID: 'call-1',
},
},
respond: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useQuestions).mockReturnValue({
vi.mocked(useForms).mockReturnValue({
pendingCount: 0,
navigateToCurrent: vi.fn(),
current: null,
reply: vi.fn(),
reject: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
render(
@@ -168,8 +144,8 @@ describe('NotificationsSheet', () => {
expect(handleClose).toHaveBeenCalled()
})
it('calls navigateToCurrent and onClose when question is clicked', () => {
const navigateToQuestionMock = vi.fn()
it('calls navigateToCurrent and onClose when form is clicked', () => {
const navigateToFormMock = vi.fn()
const handleClose = vi.fn()
vi.mocked(usePermissions).mockReturnValue({
pendingCount: 0,
@@ -178,29 +154,20 @@ describe('NotificationsSheet', () => {
current: null,
respond: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useQuestions).mockReturnValue({
vi.mocked(useForms).mockReturnValue({
pendingCount: 1,
navigateToCurrent: navigateToQuestionMock,
navigateToCurrent: navigateToFormMock,
current: {
id: 'q-1',
id: 'form-1',
sessionID: 'session-1',
questions: [{
question: 'Test question',
options: [],
}],
metadata: {},
tool: {
messageID: 'msg-1',
callID: 'call-1',
},
title: 'Test question',
fields: [{ key: 'q0', type: 'string', options: [] }],
},
reply: vi.fn(),
reject: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
getForCallID: vi.fn(),
hasForSession: vi.fn(),
})
render(
@@ -208,7 +175,7 @@ describe('NotificationsSheet', () => {
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
fireEvent.click(screen.getByText('Test question'))
expect(navigateToQuestionMock).toHaveBeenCalled()
expect(navigateToFormMock).toHaveBeenCalled()
expect(handleClose).toHaveBeenCalled()
})
})
@@ -1,6 +1,6 @@
import { BottomSheet, BottomSheetHeader, BottomSheetContent } from '@/components/ui/bottom-sheet'
import { usePermissions, useQuestions } from '@/contexts/EventContext'
import { getQuestionText } from '@opencode-manager/shared/notifications'
import { usePermissions, useForms } from '@/contexts/EventContext'
import { getFormText, getPermissionDetail, getPermissionLabel } from '@opencode-manager/shared/notifications'
import { Bell, HelpCircle } from 'lucide-react'
interface NotificationsSheetProps {
@@ -16,10 +16,10 @@ export function NotificationsSheet({ isOpen, onClose }: NotificationsSheetProps)
navigateToCurrent: navigateToPermission,
} = usePermissions()
const {
current: currentQuestion,
pendingCount: questionCount,
navigateToCurrent: navigateToQuestion,
} = useQuestions()
current: currentForm,
pendingCount: formCount,
navigateToCurrent: navigateToForm,
} = useForms()
const handlePermissionClick = () => {
navigateToPermission()
@@ -27,8 +27,8 @@ export function NotificationsSheet({ isOpen, onClose }: NotificationsSheetProps)
onClose()
}
const handleQuestionClick = () => {
navigateToQuestion()
const handleFormClick = () => {
navigateToForm()
onClose()
}
@@ -53,11 +53,11 @@ export function NotificationsSheet({ isOpen, onClose }: NotificationsSheetProps)
onClick={handlePermissionClick}
className="flex flex-col items-start gap-1 p-3 rounded-lg border border-border hover:bg-accent transition-colors text-left w-full"
>
<span className="font-medium text-foreground capitalize">
{currentPermission.permission.replace(/_/g, ' ')}
<span className="font-medium text-foreground">
{getPermissionLabel(currentPermission.action)}
</span>
<span className="text-xs text-muted-foreground truncate w-full">
{currentPermission.patterns?.[0] || 'View details'}
{getPermissionDetail(currentPermission).primary || 'View details'}
</span>
</button>
)}
@@ -73,31 +73,31 @@ export function NotificationsSheet({ isOpen, onClose }: NotificationsSheetProps)
<div>
<div className="flex items-center gap-2 mb-3">
<HelpCircle className="w-5 h-5 text-blue-500" />
<h3 className="font-semibold text-foreground">Pending questions</h3>
<h3 className="font-semibold text-foreground">Pending forms</h3>
</div>
{questionCount === 0 ? (
{formCount === 0 ? (
<div className="text-muted-foreground text-sm py-4">
You're all caught up
</div>
) : (
<div className="flex flex-col gap-2">
{currentQuestion && (
{currentForm && (
<button
type="button"
onClick={handleQuestionClick}
onClick={handleFormClick}
className="flex flex-col items-start gap-1 p-3 rounded-lg border border-border hover:bg-accent transition-colors text-left w-full"
>
<span className="font-medium text-foreground">
{getQuestionText(currentQuestion) || 'Question'}
{getFormText(currentForm) || 'Form'}
</span>
<span className="text-xs text-muted-foreground truncate w-full">
Tap to view
</span>
</button>
)}
{questionCount > 1 && (
{formCount > 1 && (
<div className="text-xs text-muted-foreground px-3">
+{questionCount - 1} more
+{formCount - 1} more
</div>
)}
</div>
@@ -35,19 +35,17 @@ describe('buildMoreItems', () => {
it('returns session-specific items for /repos/:id/sessions/:sid', () => {
const items = buildMoreItems('/repos/42/sessions/abc')
expect(items).toHaveLength(10)
expect(items).toHaveLength(9)
expect(items[0].key).toBe('home')
expect(items[1].key).toBe('files')
expect(items[2].key).toBe('mcp')
expect(items[3].key).toBe('skills')
expect(items[4].key).toBe('lsp')
expect(items[4].dialog).toBe('lsp')
expect(items[5].key).toBe('reset-permissions')
expect(items[6].key).toBe('schedules')
expect(items[6].to).toBe('/repos/42/schedules')
expect(items[7].key).toBe('source-control')
expect(items[8].key).toBe('settings')
expect(items[9].key).toBe('logout')
expect(items[4].key).toBe('reset-permissions')
expect(items[5].key).toBe('schedules')
expect(items[5].to).toBe('/repos/42/schedules')
expect(items[6].key).toBe('source-control')
expect(items[7].key).toBe('settings')
expect(items[8].key).toBe('logout')
})
it('returns assistant workspace items for /repos/:id/assistant', () => {
@@ -1,5 +1,5 @@
import type { LucideIcon } from 'lucide-react'
import { Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, Code2, Settings, LogOut, Plus, Bot, Folder, Clock, SquarePlus, Home } from 'lucide-react'
import { Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, Settings, LogOut, Plus, Bot, Folder, Clock, SquarePlus, Home } from 'lucide-react'
import { getAssistantPath, isAssistantPath } from '@/lib/navigation'
import type { SidebarActionKey } from '@/hooks/useSidebarAction'
@@ -78,7 +78,6 @@ function buildRouteNavModel(pathname: string): NavModel {
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
{ key: 'mcp', label: 'MCP', icon: Plug, dialog: 'mcp' },
{ key: 'skills', label: 'Skills', icon: Sparkles, dialog: 'skills' },
{ key: 'lsp', label: 'LSP', icon: Code2, dialog: 'lsp' },
{ key: 'reset-permissions', label: 'Reset Permissions', icon: ShieldOff, dialog: 'resetPermissions', danger: true },
{ key: 'schedules', label: 'Schedules', icon: CalendarClock, to: `/repos/${sessionDetailMatch[1]}/schedules` },
{ key: 'source-control', label: 'Source Control', icon: GitCommitHorizontal, dialog: 'sourceControl' },