feat(engines): 添加 opencode 引擎支持#279
Open
hahhforest wants to merge 2 commits into
Open
Conversation
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>
|
还剩一个gemini |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
基于 #223(@yyi407609-droid)的工作,添加 OpenCode 作为第 4 个引擎后端(与 Claude、Kimi、Codex 并列)。
opencode run --format json,解析 JSONL 输出step_start、text、tool_use、step_finish、error)转换为SDKMessage,由现有的StreamProcessor消费StreamProcessor— 与 Codex/Kimi 引擎一致(无自定义 stream processor)OpenCodeJsonConfig、OpenCodeBotConfig、buildOpenCodeConfig(),已接入所有*FromJson和*FromEnv函数相比 #223 的改动
根据 @floodsung 的 review 反馈进行了以下修复:
OpenCodeStreamProcessor— 复用 Claude 的StreamProcessortool_use事件翻译(原来被静默丢弃)stream_event+content_block_delta实现实时流式文本step_finish的reason: "tool-calls"是中间状态)OPENCODE_EXECUTABLE_PATHOpenCodeBotConfig中增加executable和contextWindow字段persistentExecutor配置字段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 流程测试