feat: support opencode

This commit is contained in:
weishu
2026-01-29 10:34:57 +08:00
parent 66ab96bf38
commit 70b5c22c8f
47 changed files with 2737 additions and 28 deletions
+56
View File
@@ -0,0 +1,56 @@
import chalk from 'chalk'
import { authAndSetupMachineIfNeeded } from '@/ui/auth'
import { initializeToken } from '@/ui/tokenInit'
import { maybeAutoStartServer } from '@/utils/autoStartServer'
import type { CommandDefinition } from './types'
import type { OpencodePermissionMode } from '@hapi/protocol/types'
export const opencodeCommand: CommandDefinition = {
name: 'opencode',
requiresRuntimeAssets: true,
run: async ({ commandArgs }) => {
try {
const options: {
startedBy?: 'runner' | 'terminal'
startingMode?: 'local' | 'remote'
permissionMode?: OpencodePermissionMode
resumeSessionId?: string
} = {}
for (let i = 0; i < commandArgs.length; i++) {
const arg = commandArgs[i]
if (arg === '--started-by') {
options.startedBy = commandArgs[++i] as 'runner' | 'terminal'
} else if (arg === '--hapi-starting-mode') {
const value = commandArgs[++i]
if (value === 'local' || value === 'remote') {
options.startingMode = value
} else {
throw new Error('Invalid --hapi-starting-mode (expected local or remote)')
}
} else if (arg === '--yolo') {
options.permissionMode = 'yolo'
} else if (arg === '--resume') {
const sessionId = commandArgs[++i]
if (!sessionId) {
throw new Error('Missing --resume value')
}
options.resumeSessionId = sessionId
}
}
await initializeToken()
await maybeAutoStartServer()
await authAndSetupMachineIfNeeded()
const { runOpencode } = await import('@/opencode/runOpencode')
await runOpencode(options)
} catch (error) {
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error')
if (process.env.DEBUG) {
console.error(error)
}
process.exit(1)
}
}
}