Repository navigation
fix(acp): probe opencode 2.x for acp --port/--hostname instead of applying the 1.x floor - #909
Merged
xintaofei merged 3 commits intoOct 9, 2026
Conversation
…uessing opencode 2.0 rearchitected `acp`: it starts its own `serve --stdio --port 0` child and declares neither listen flag, so `--port 0 --hostname 127.0.0.1` makes every connection exit 1 with "Unrecognized flag" (its usage lands on stdout — the ACP channel) before `initialize` answers. `release_accepts_listen_flags` read "version >= LISTEN_FLAGS_MIN_VERSION (1.0.43)" as "accepts", and the 2.x line inherited that reading, so the spacering-net#860 floor was carried across the major. Answer only the 1.x line from its version; major 2 and up go to the `acp --help` probe, which reports v2's absent flags and keeps the bare argv (and follows a later 2.x that re-adds them). Verified against opencode 2.0.24: bare `opencode acp` answers `initialize`; `opencode acp --port 0 --hostname 127.0.0.1` exits 1.
Since 2.x goes to the `acp --help` probe, its "no flags" answer reaches the same info line as a pre-1.0.43 build, which called it a build that "predates `acp --port/--hostname`" with "no HTTP server". A 2.x build is neither: it dropped the flags, and its `acp` runs a private `serve --stdio --port 0` child on loopback. The line now says the build does not accept the flags, and the comment covers both kinds of build. `listen_args`'s doc now says only a release version below 2.0 settles the question without asking the binary.
The 2.0.24 help fixture is now the binary's verbatim output, and the 2.x stand-in prints it on stdout, as 2.x does (1.18 uses stderr), answering `--version` with the real `opencode v2.0.24` banner. A new test pins the rest of the 2.x contract: a managed 2.x label also asks `acp --help` without running `--version`, and a 2.x whose help lists both flags gets them. That second half is the only test that reads the help from stdout.
Collaborator
|
codeg work task |
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.
Fixes #906
问题
0.32.3(#860)起,OpenCode 连接启动时会追加
--port 0 --hostname 127.0.0.1。但系统安装的 opencode 2.x 的acp不接受这两个参数——v2 已重构acp(内部自建serve --stdio --port 0,--port/--hostname只在opencode serve上;v2.0.0 ~ v2.0.26 均如此)。v2 CLI 严格解析未知 flag:打印 usage 到 stdout 并 exit 1,而 stdout 正是 ACP 通道,连接在initialize之前就失败:修复
release_accepts_listen_flags不再把 1.x 的版本下限外推到 2.x:major >= 2返回“未知”,交给既有的acp --help实测(v2 实测没有这两个 flag → 保持裸acp启动;未来某个 2.x 重新支持也能自动跟上)。1.x 行为不变,#860 修复的场景不受影响。验证
cargo test --no-default-features --features server-bin --lib acp::opencode_launch:15/15 通过(含新增用例:2.x 版本号 → 不猜测;fake 2.x 二进制 → 实测后裸 argv)opencode acp的initialize握手成功;带--port/--hostnameexit 1注:手动验证(真实二进制)在 macOS (darwin-arm64) 完成;Windows / Linux 依赖 CI 矩阵(ubuntu / macos / windows 的编译与单测)验证 —— 本改动无平台特定代码,行为差异取决于 opencode 版本而非 OS。