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

@@ -0,0 +1,101 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { MemoryRouter } from 'react-router-dom'
import type { PermissionRequest, SessionMessageAssistantTool } from '@opencode-manager/shared/opencode'
import { ToolCallPart } from './ToolCallPart'
const mocks = vi.hoisted(() => ({
useSettings: vi.fn(),
useToolCallPermission: vi.fn(),
}))
vi.mock('@/hooks/useSettings', () => ({
useSettings: mocks.useSettings,
}))
vi.mock('@/contexts/EventContext', () => ({
useToolCallPermission: mocks.useToolCallPermission,
}))
const renderWithProviders = (ui: React.ReactElement) => {
const queryClient = new QueryClient()
return render(
<QueryClientProvider client={queryClient}>
<MemoryRouter>{ui}</MemoryRouter>
</QueryClientProvider>,
)
}
const runningShell = (): SessionMessageAssistantTool => ({
type: 'tool',
id: 'call_1',
name: 'shell',
time: { created: 1, ran: 2 },
state: { status: 'running', input: { command: 'git status' }, metadata: {} },
})
const permissionFor = (source: PermissionRequest['source']): PermissionRequest => ({
id: 'permission_1',
sessionID: 'ses_1',
action: 'shell',
resources: ['git status'],
source,
})
describe('ToolCallPart permission indicator', () => {
beforeEach(() => {
vi.clearAllMocks()
mocks.useSettings.mockReturnValue({
preferences: { expandToolCalls: true },
isLoading: false,
updateSettings: vi.fn(),
isUpdating: false,
})
mocks.useToolCallPermission.mockReturnValue(null)
})
it('shows the waiting permission state for a matching tool call', () => {
mocks.useToolCallPermission.mockReturnValue(
permissionFor({ type: 'tool', messageID: 'msg_1', id: 'call_1' }),
)
renderWithProviders(<ToolCallPart part={runningShell()} messageID="msg_1" />)
expect(mocks.useToolCallPermission).toHaveBeenCalledWith('call_1', 'msg_1')
expect(screen.getByText('awaiting permission')).toBeInTheDocument()
expect(screen.getByText('Waiting for permission...')).toBeInTheDocument()
})
it('does not show the waiting permission state without a pending permission', () => {
renderWithProviders(<ToolCallPart part={runningShell()} messageID="msg_1" />)
expect(screen.queryByText('awaiting permission')).not.toBeInTheDocument()
expect(screen.queryByText('Waiting for permission...')).not.toBeInTheDocument()
expect(screen.getByText('running')).toBeInTheDocument()
})
it('ignores a permission whose source belongs to another tool call or message', () => {
mocks.useToolCallPermission.mockReturnValue(null)
renderWithProviders(<ToolCallPart part={runningShell()} messageID="msg_1" />)
expect(mocks.useToolCallPermission).toHaveBeenCalledWith('call_1', 'msg_1')
expect(screen.queryByText('awaiting permission')).not.toBeInTheDocument()
})
it('does not show the waiting permission state while the tool call is still streaming', () => {
mocks.useToolCallPermission.mockReturnValue(
permissionFor({ type: 'tool', messageID: 'msg_1', id: 'call_1' }),
)
renderWithProviders(
<ToolCallPart
part={{ ...runningShell(), state: { status: 'streaming', input: '' } }}
messageID="msg_1"
/>,
)
expect(screen.queryByText('awaiting permission')).not.toBeInTheDocument()
})
})