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

+16 -160
View File
@@ -1,132 +1,29 @@
import { memo } from 'react'
import type { components } from '@/api/opencode-types'
import { Volume2, VolumeX, Loader2 } from 'lucide-react'
import type { SessionMessageAssistant } from '@opencode-manager/shared/opencode'
import { TextPart } from './TextPart'
import { PatchPart } from './PatchPart'
import { ToolCallPart } from './ToolCallPart'
import { RetryPart } from './RetryPart'
import { useTTS } from '@/hooks/useTTS'
import { useMobile } from '@/hooks/useMobile'
import { useSettings } from '@/hooks/useSettings'
import { CopyButton } from '@/components/ui/copy-button'
type RetryPartType = components['schemas']['RetryPart']
type Part = components['schemas']['Part']
type AssistantContentPart = SessionMessageAssistant['content'][number]
interface MessagePartProps {
part: Part
role?: string
allParts?: Part[]
partIndex?: number
part: AssistantContentPart
messageID?: string
onFileClick?: (filePath: string, lineNumber?: number) => void
onChildSessionClick?: (sessionId: string) => void
messageTextContent?: string
}
function getCopyableContent(part: Part, allParts?: Part[]): string {
switch (part.type) {
case 'text':
return part.text || ''
case 'patch':
return `Patch: ${part.hash}\nFiles: ${part.files.join(', ')}`
case 'tool':
if (part.state.status === 'completed' && part.state.input) {
return JSON.stringify(part.state.input, null, 2)
} else if (part.state.status === 'running' && part.state.input) {
return JSON.stringify(part.state.input, null, 2)
}
return `Tool: ${part.tool} (${part.state.status})`
case 'reasoning':
return part.text || ''
case 'snapshot':
return part.snapshot || ''
case 'agent':
return `Agent: ${part.name}`
case 'subtask':
return `${part.agent}: ${part.description}\n\n${part.prompt}`.trim()
case 'step-finish':
if (allParts) {
return allParts
.filter(p => p.type === 'text')
.map(p => p.text || '')
.join('\n\n')
.trim()
}
return ''
case 'file':
return part.filename || part.url || 'File'
default:
return ''
}
}
interface TTSButtonProps {
messageId: string
content: string
className?: string
}
function TTSButton({ messageId, content, className = "" }: TTSButtonProps) {
const { speakMessage, stop, isEnabled, isPlaying, isLoading, activeMessageId } = useTTS()
if (!isEnabled || !content.trim()) {
return null
}
const isThisPlaying = (isPlaying || isLoading) && activeMessageId === messageId
const handleClick = () => {
if (isThisPlaying) {
stop()
} else {
speakMessage(messageId, content)
}
}
return (
<button
onClick={handleClick}
className={`p-1.5 rounded ${isThisPlaying ? 'bg-red-500/20 text-red-500 hover:bg-red-500/30' : 'bg-card hover:bg-card-hover text-muted-foreground hover:text-foreground'} ${className}`}
title={isThisPlaying ? "Stop playback" : "Read aloud"}
disabled={isLoading && !isThisPlaying}
>
{isLoading && isThisPlaying ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : isThisPlaying ? (
<VolumeX className="w-4 h-4" />
) : (
<Volume2 className="w-4 h-4" />
)}
</button>
)
}
export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick, onChildSessionClick, messageTextContent }: MessagePartProps) {
export const MessagePart = memo(function MessagePart({ part, messageID, onFileClick, onChildSessionClick }: MessagePartProps) {
const { preferences } = useSettings()
const simpleChatMode = preferences?.simpleChatMode ?? false
const showReasoning = preferences?.showReasoning ?? false
const copyableContent = getCopyableContent(part, allParts)
const isMobile = useMobile()
switch (part.type) {
case 'text':
if (part.synthetic) return null
if (role === 'user' && allParts && partIndex !== undefined) {
const nextPart = allParts[partIndex + 1]
if (nextPart && nextPart.type === 'file') {
return null
}
}
return <TextPart part={part} />
case 'patch':
if (simpleChatMode) return null
return <PatchPart part={part} onFileClick={onFileClick} />
case 'tool':
if (simpleChatMode && part.tool !== 'task') return null
return <ToolCallPart part={part} onFileClick={onFileClick} onChildSessionClick={onChildSessionClick} />
return <TextPart text={part.text} />
case 'reasoning':
if (simpleChatMode || !showReasoning) return null
if (!part.text.trim()) return null
return (
<details className="border border-border rounded-lg my-2">
<summary className="px-4 py-2 bg-muted hover:bg-accent cursor-pointer text-sm font-medium">
@@ -137,57 +34,16 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
</div>
</details>
)
case 'snapshot':
if (simpleChatMode) return null
case 'tool':
if (simpleChatMode && part.name !== 'subagent') return null
return (
<div className="border border-border rounded-lg p-4 my-2 bg-card">
<div className="text-xs text-muted-foreground font-mono">Snapshot: {part.snapshot}</div>
</div>
<ToolCallPart
part={part}
messageID={messageID}
onFileClick={onFileClick}
onChildSessionClick={onChildSessionClick}
/>
)
case 'agent':
if (simpleChatMode) return null
return (
<div className="border border-border rounded-lg p-4 my-2 bg-card">
<div className="text-sm font-medium text-blue-600 dark:text-blue-400">Agent: {part.name}</div>
</div>
)
case 'step-finish':
if (simpleChatMode) return null
{
const isFree = part.cost === 0
const totalTokens = part.tokens.input + part.tokens.output + (part.tokens.cache?.read || 0)
const costText = isMobile && isFree ? null : <span>${part.cost.toFixed(4)} • {totalTokens} tokens</span>
return (
<div className="text-xs text-muted-foreground my-1 flex items-center gap-2">
{costText}
<CopyButton content={copyableContent} title="Copy step complete" />
{messageTextContent && part.messageID && <TTSButton messageId={part.messageID} content={messageTextContent} />}
</div>
)
}
case 'file':
return (
<span className="inline-flex items-center gap-1 px-2 py-1 rounded bg-muted border border-border text-sm text-foreground">
<span className="text-blue-600 dark:text-blue-400">@</span>
<span className="font-medium">{part.filename || 'File'}</span>
</span>
)
case 'retry':
return <RetryPart part={part as RetryPartType} />
case 'subtask': {
const label = part.description || part.prompt || 'Sub-agent task'
return (
<div className="my-1 w-full rounded-lg border border-blue-500/20 bg-blue-500/5 px-3 py-1.5 text-left text-xs text-muted-foreground shadow-sm shadow-blue-500/5">
<div className="flex items-center gap-2 min-w-0">
<span className="truncate">{label}</span>
<span className="ml-auto shrink-0 text-[11px] text-muted-foreground">sub-agent</span>
</div>
</div>
)
}
case 'step-start':
case 'compaction':
return null
default:
return null
}