GeezerVison is showing github.com — fix(gui-extensions): parseVersion takes the first line of login-shell output — an SSH/WSL banner is read as the CLI version (both remote-cli copies) · Issue #265 · developing-today-forks/opencode
fix(gui-extensions): parseVersion takes the first line of login-shell output — an SSH/WSL banner is read as the CLI version (both remote-cli copies) #265
Description
Problem
parseVersion reads the remote CLI's version from the first non-empty line of a login shell's output. Any banner, MOTD, or .profile echo printed before the version line is returned as the "version" — so a correctly installed remote CLI is misread on every host whose login shell prints anything.
Both copies of the parser have the identical flaw (the WSL copy's header says "keep the two copies in step"):
packages/gui-extensions/src/ssh/remote-cli.ts:47-60
packages/gui-extensions/src/wsl/remote-cli.ts:26-39
const line = output.split(/\r?\n/).find((line) => line.trim())?.trim()
const marker = line.lastIndexOf(" v")
const version = marker === -1 ? line : line.slice(marker + 2)
Both transports run login shells, so profile/banner output on stdout is expected, not exotic:
- SSH:
packages/gui-extensions/src/ssh/bootstrap.ts:86 runs scripts via sh -l -s
- WSL:
packages/gui-extensions/src/wsl/runtime.ts:224 runs scripts via sh -lc
Reproduction (parser logic run verbatim under node)
| Input |
Returned "version" |
"2.1.0\n" |
"2.1.0" ✅ |
"Welcome to Ubuntu 24.04 LTS\n2.1.0\n" |
"Welcome to Ubuntu 24.04 LTS" ❌ |
"dev tools v3 loaded\nopencode v2.1.0\n" |
"3 loaded" ❌ |
"Last login: Thu Oct 22 00:01:02 2026 from 10.0.0.2\n2.1.0\n" |
the whole login line ❌ |
Impact
- SSH bootstrap (
packages/gui-extensions/src/ssh/bootstrap.ts:106-107): parseVersion(existing) === input.version decides whether a staged CLI is reused. With any banner it is always false, so every connect re-downloads/reinstalls the CLI (or falls into the upload path), and the development-mode staged-beta choice is skewed the same way.
- WSL (
packages/gui-extensions/src/wsl/runtime.ts:347-349): readCliVersion returns the banner text as the installed version to its callers' version comparisons.
- Same first-line pattern, same login shell: WSL
resolveCli (runtime.ts:343) returns firstLine(discoverScript output) as the CLI path, so a banner line becomes the command path there too.
Contrast: the robust patterns already in this codebase
Acceptance criteria
- Both
parseVersion copies (ssh + wsl) ignore non-version lines: scan for a line whose trimmed content matches the accepted version shape already enforced by requireVersion (local or ^[0-9][a-zA-Z0-9.+-]*$, allowing the opencode v… / trailing- v… form the current lastIndexOf(" v") handles), instead of taking the first non-empty line.
- WSL
resolveCli likewise returns the discovered path line rather than the first line of login-shell output (e.g. the line that is an absolute path to an opencode binary).
- New unit tests for both parsers covering: clean output, banner/MOTD line before the version, a banner line containing
" v" (must not yield "3 loaded"), and empty output → null. No test file exists for either remote-cli.ts today, and no test references parseVersion/readCliVersion.
- Clean-output behaviour is unchanged:
"2.1.0" and "opencode v2.1.0" inputs return the same values as before.
Filed by new-issue-creator after verifying on main a7ea147ade (file:line reads, node repro of the exact parser logic, dedup searches for parseVersion / readCliVersion / remote-cli banner returned no issue).
Metadata
Metadata
Development
No branches or pull requestsIssue actions