Repository navigation
fix: ask the OpenCode binary for --standalone instead of reading its version - #13
Open
alcpereira wants to merge 3 commits into
Open
alcpereira wants to merge 3 commits into
alcpereira wants to merge 3 commits into
Conversation
…version
The version probe decided the launch from `--version`, but every dev, beta
and source build of *both* OpenCode generations reports `0.0.0-*` (or
`local`), which the regex never matched, so they all fell back to the v1
launch. Verified against the published `@opencode/cli@beta`:
$ opencode --version
opencode v0.0.0-beta-19507 <- probe: no match -> major 1
$ apex run opencode
Unrecognized flag: --model in command opencode
The whole preview channel hits the exact error PR callstack#12 exists to prevent,
and `0.0.0-*` cannot be classified by version at all: the old `opencode-ai`
package has published over 11k `0.0.0-*` versions too, so "major 0 means
v2" would just move the bug to v1 dev builds.
Probe the capability instead. `--standalone` exists if and only if the
interface is v2, and `--help` says so on all four real binaries, including
the `0.0.0-*` pair no regex can separate: v1 stable, v1 dev, v2 beta and
v2 stable all answer correctly. v1 writes its help to stderr and v2 to
stdout, so both streams are read.
The probe now answers a tri-state: true (OpenCode 2), false (OpenCode 1),
or null (no answer). It never rejects: execFile can throw synchronously (a
.cmd launcher since CVE-2024-27980) and a failed or timed-out --help is no
answer either. On null, `apex run` adds neither --model nor --standalone,
so the assistant still starts on the user's own config, and says so on
stderr rather than guessing a generation and dying on its flag; the init
summary admits the same instead of blindly showing the v1 expansion.
Also scrub OPENCODE_CONFIG_CONTENT in the test fixture: it reached launched
fakes from the developer's shell, the same leak callstack#11 closed for gateway keys.
Docs-only inaccuracies PR callstack#12 merged (the "flags only follow a subcommand"
comment, the `auth list` example) are untouched here and tracked as F6.
The fanout review found no bugs; these are its confirmed findings. - openCodeSupportsStandalone becomes a short async function over promisify(execFile): one try/catch covers the callback's error branch and what execFile throws synchronously (D2). - A failing or timed-out --help that printed --standalone is an answer after all; the captured streams on the error are read instead of thrown away (D1). - launchOptions owns the unknown-probe sentence as `warning` and says "interface", not "version"; commandRun prints it instead of writing its own wording of the same state (D6, D9). - The init summary drops the note when no binary was found: nothing was asked, so nothing is unknown (D5). - runExpansion joins the command tokens instead of repairing a trailing space with trimEnd() (D10). - Tests: the synchronous-throw case uses a path that actually reaches execFile (a NUL byte); the probe asserts a failed --help with and without the flag in its output; the CLI fake sheds the --version plumbing Apex no longer reads and the stderr cases the probe unit test already covers (D3, D8).
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.
Follow-up F1 (medium) from the review of #12 (
/tmp/review/apex-cli-12/FIX-FOLLOWUPS.md): the version probe misclassifies every non-stable OpenCode 2 build.The bug
openCodeMajordecided the launch from--version, but every dev, beta and source build of both OpenCode generations reports0.0.0-*(orlocal), which the regex never matched, so they all fell back to the v1 launch. Verified against the published@opencode/cli@betabinary:That is the entire preview channel hitting the exact error #12 exists to prevent —
paru -S opencode-betais in OpenCode's own install docs. And0.0.0-*cannot be classified by version at all: the oldopencode-aipackage has published 11k+0.0.0-*versions too, so "major 0 → v2" would just move the bug onto v1 dev builds. (The regex widening the fanout review proposed,(?:[-+(]\S*)?, fails the same way:0 < 2→ v1.)The fix
Probe the capability, not the version.
--standaloneexists if and only if the interface is v2, and--helpsays so — verified against all four real binaries, including the ambiguous0.0.0-dev-*pair no regex can separate:--versionopencode-ai@1.18.341.18.34false0.0.0-dev-202610141901false@opencode/cli@betaopencode v0.0.0-beta-19507trueopencode v2.0.29true(227 ms / 38 ms — same order as the old
--versionprobe.) v1 writes its help to stderr and v2 to stdout, so both streams are read.openCodeSupportsStandaloneanswers a tri-state —true(v2),false(v1),null(no answer) — and never rejects:execFilecan throw synchronously (a.cmdlauncher since CVE-2024-27980), and a--help(capped at 5 s) that fails or times out and prints nothing is no answer either. Even a failing--helpthat printed the flag is an answer:execFilehands over the captured streams beside its error, so a wrapper that prints the page and exits 1 still decides the launch. Onnull,apex runadds neither--modelnor--standalone, so the assistant still starts on the user's own config and a warning on stderr says the gateway model was not selected — honest about not knowing beats guessing v1 and dying on a flag. The warning and theinitsummary's note come fromlaunchOptionsitself, so the unknown state is worded once, as an unknown interface.Tests
--versionany more, so the fakeopencodehas no--versionbranch and no version plumbing at all: which generation a build is comes only from what--helpprints.OPENCODE_CONFIG_CONTENTstill fails the launch before the child starts.--helpwith and without the flag in its output, missing binary, directory, a pathexecFilethrows synchronously on (a NUL byte), andnull— never rejects.OPENCODE_CONFIG_CONTENTis now deleted in the test fixture; it leaked from the developer's shell into launched fakes (the same class of leak test: keep the developer's gateway key out of the test environment #11 closed for gateway keys — it fails existing tests on this author's machine without it).--model.67/67
node --testpass;npm run checkclean.Not in this PR
F2 (probe call-site ordering around
--apply, the.cmdguard ininit), F3 (scrubbed probe env), F4, F5 and F6 stay separate per the follow-ups doc. The known-inaccurate comment prose merged by #12 (auth listexample, "flags only follow a subcommand") is deliberately untouched — that is F6.