feat: 添加对 OpenCode 的支持,更新 CLI 工具配置和会话发现逻辑

This commit is contained in:
catlog22
2026-01-08 10:47:07 +08:00
parent d2d6cce5f4
commit 55fa170b4e
7 changed files with 223 additions and 104 deletions

View File

@@ -290,6 +290,32 @@ export function buildCommand(params: {
}
break;
case 'opencode':
// OpenCode: opencode run "prompt" for non-interactive mode
// https://opencode.ai/docs/cli/
args.push('run');
// Native resume: opencode run --continue or --session <id>
if (nativeResume?.enabled) {
if (nativeResume.isLatest) {
args.push('--continue');
} else if (nativeResume.sessionId) {
args.push('--session', nativeResume.sessionId);
}
}
// Model: --model <provider/model> (e.g., anthropic/claude-sonnet-4-20250514)
if (model) {
args.push('--model', model);
}
// Write mode: Use full-auto permission via environment or default permissive mode
// OpenCode uses OPENCODE_PERMISSION env var for permission control
// For now, we rely on project-level configuration
// Output format for parsing
args.push('--format', 'default');
// Prompt is passed as positional argument after 'run'
// Use stdin for prompt to avoid shell escaping issues
useStdin = true;
break;
default:
errorLog('BUILD_CMD', `Unknown CLI tool: ${tool}`);
throw new Error(`Unknown CLI tool: ${tool}`);