Skip to content

feat(engines): 添加 opencode 引擎支持#279

Open
hahhforest wants to merge 2 commits into
xvirobotics:mainfrom
hahhforest:feat/opencode-engine
Open

feat(engines): 添加 opencode 引擎支持#279
hahhforest wants to merge 2 commits into
xvirobotics:mainfrom
hahhforest:feat/opencode-engine

Conversation

@hahhforest

@hahhforest hahhforest commented May 14, 2026

Copy link
Copy Markdown

概述

基于 #223@yyi407609-droid)的工作,添加 OpenCode 作为第 4 个引擎后端(与 Claude、Kimi、Codex 并列)。

  • OpenCodeExecutor 以子进程方式启动 opencode run --format json,解析 JSONL 输出
  • JSONL 翻译器 将 OpenCode 事件(step_starttexttool_usestep_finisherror)转换为 SDKMessage,由现有的 StreamProcessor 消费
  • 复用 Claude 的 StreamProcessor — 与 Codex/Kimi 引擎一致(无自定义 stream processor)
  • 完整的配置链OpenCodeJsonConfigOpenCodeBotConfigbuildOpenCodeConfig(),已接入所有 *FromJson*FromEnv 函数
  • 全面的测试 — JSONL 翻译器集成测试、CLI 参数构建测试、多步骤执行测试

相比 #223 的改动

根据 @floodsung 的 review 反馈进行了以下修复:

  1. 删除废代码 OpenCodeStreamProcessor — 复用 Claude 的 StreamProcessor
  2. 新增 tool_use 事件翻译(原来被静默丢弃)
  3. 使用 stream_event + content_block_delta 实现实时流式文本
  4. 处理多步骤执行(step_finishreason: "tool-calls" 是中间状态)
  5. 移除有问题的 Windows 路径硬编码 — 改用 PATH 查找 + OPENCODE_EXECUTABLE_PATH
  6. 移除硬编码的私有模型名
  7. 补全完整的 config 反序列化(feat(engines): add opencode engine support #223 中缺失)
  8. OpenCodeBotConfig 中增加 executablecontextWindow 字段
  9. 恢复被误删的 persistentExecutor 配置字段
  10. 移除 StreamProcessorLike 联合类型 — 回归为 StreamProcessor

贡献者说明

本 PR 保留了 @yyi407609-droid 的原始 commit 及其 Author 字段。请使用 regular merge(非 squash),以确保两位贡献者都出现在仓库的 Contributors 列表中。

测试计划

  • npm run build — 编译通过(command-handler.ts 中有 2 个已有的 warning,与本 PR 无关)
  • npm run lint — 0 错误(2 个已有的 warning,与本 PR 无关)
  • npm test — 324 个测试全部通过,包含 3 个新测试文件:
    • tests/opencode-jsonl-translator.test.ts — 完整事件→CardState 集成测试 + 单元测试
    • tests/opencode-build-args.test.ts — CLI 参数构建测试
    • tests/opencode-multi-step.test.ts — 多步骤 tool-calls→stop 流程测试

yyi407609-droid and others added 2 commits May 14, 2026 18:37
Add OpenCodeEngine implementing the Engine interface:
- OpenCodeExecutor spawns opencode CLI with JSONL streaming
- OpenCodeStreamProcessor transforms opencode events into CardState
- OpenCode JSONL translator for event format conversion
- Add 'opencode' to EngineName type and BotConfigBase
- Add OpenCodeBotConfig for model/skipPermissions/extraArgs settings

Original work by @yyi407609-droid from PR xvirobotics#223.
…ics#223

Based on reviewer feedback (floodsung), this commit fixes:

1. Delete dead-code OpenCodeStreamProcessor — reuse Claude's
   StreamProcessor (same pattern as Codex/Kimi engines)
2. Add tool_use event translation — tool calls now appear on
   Feishu cards instead of being silently dropped
3. Use stream_event+content_block_delta for real-time text streaming
   instead of batched assistant messages
4. Handle multi-step execution — step_finish with reason "tool-calls"
   is intermediate, only reason "stop" emits a terminal result
5. Remove broken Windows path hardcoding — use PATH lookup +
   OPENCODE_EXECUTABLE_PATH env var
6. Remove hardcoded private model — model comes from config
7. Add full config deserialization — OpenCodeJsonConfig,
   buildOpenCodeConfig(), EngineJsonFields.opencode, all *FromJson
   and *FromEnv functions wired
8. Add executable and contextWindow to OpenCodeBotConfig
9. Restore persistentExecutor field deleted by original commit
10. Remove StreamProcessorLike union — back to StreamProcessor only
11. Add comprehensive tests: JSONL translator, CLI args, multi-step

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hahhforest hahhforest changed the title feat(engines): add opencode engine support feat(engines): 添加 opencode 引擎支持 May 14, 2026
@mkafw

mkafw commented May 29, 2026

Copy link
Copy Markdown

还剩一个gemini

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants