saint carol, on Windows with OpenCode's desktop app: opening magpie,
often right after an update, brings up OpenCode. af0cd09c9 covered only a
Mac's app bundles.
OpenCode's desktop app installs per user, to
%LOCALAPPDATA%\Programs\ai.opencode.desktop\OpenCode.exe (electron-builder
NSIS; @opencodedesktop before), with its CLI at
resources\opencode-cli.exe. The installer puts nothing on PATH, and
"Install CLI" is Mac-only. With that folder on PATH, `opencode` finds
OpenCode.exe, since Windows looks names up without case and PATHEXT adds
.exe. magpie's `opencode --version` at each start and after a CLI update
(proc.Version, library openCodeVersion, cliupdate runCheck) then started
the Electron app. Nothing else in magpie starts OpenCode on Windows: no
App Paths lookup, no opencode:// link, and scoop's opencode-desktop gives
a shortcut, not a shim.
ProbeContext now also refuses (cmd.Err, nothing started) a program whose
PE header names the GUI subsystem (guiExe: e_lfanew, PE signature,
optional header Subsystem == 2). Console programs run as before: CLIs,
bun's, npm's and WinGet's shims, opencode-cli.exe. Anything that isn't a
PE, or whose header can't be read, also runs as before. On the Windows
box, every program magpie probes that is installed there is console
(claude.exe, codex.exe, git.exe). The GUI ones on PATH are system32
tools, git-gui, gitk and Codex's codex-command-runner, which no probe
asks.
Tests:
- TestGuiPE: GUI PE32 and PE32+ headers are a window's program; console,
a bad magic, a cut-short header, a script and empty bytes are not.
- TestProbeNeverOpensAWindowsApp (Windows): the install's layout is made
from copies of the test binary, which notes that it ran (TestMain's
MAGPIE_PROC_RAN). OpenCode.exe is patched to the GUI subsystem as
Electron's is. With the folder on PATH, `opencode` resolves to
OpenCode.exe and isn't run, and Version is "". opencode-cli.exe still
answers 2.2.5.
Broken by hand on xiaomi-gpu: with guiExe out of ProbeContext,
TestProbeNeverOpensAWindowsApp goes red ("OpenCode.exe was run and said
2.2.5").
Run at 4b407bb79 plus this change (go test -count=1 -timeout 45m):
- mote (macOS): internal/proc, library, agent, provider, wslrun ok;
GOOS=windows go vet ./... ok, GOOS=linux go vet -tags nogui ./... ok;
gofmt -l empty.
- xiaomi-gpu (Windows, win-run): internal/proc ok. internal/library red
on TestGoneAgentListedToTakeOut and TestCheckMixedServerEachSide, the
same at 4b407bb79 without this change, both listed in #4115.
- magpie-desktop (Linux, wsl-run): internal/proc ok.
Not tried: the real OpenCode desktop app on Windows (not installed on the
test box; the layout is from OpenCode's electron-builder config and NSIS
include), the reporter's PATH, and a .cmd or .ps1 the user wrote that
starts OpenCode.exe (still run).
saint carol on Discord: opening magpie, often right after an update,
brings up OpenCode, which they never asked for.
magpie asks `opencode --version` at every start and after a CLI update
(proc.Version for the agents' CLI info, library/rtk.go openCodeVersion,
agent/cliupdate.go runCheck), all through proc.ProbeContext. When the
`opencode` on PATH is OpenCode.app's own program (a link to
OpenCode.app/Contents/MacOS/OpenCode, or the bundle's MacOS folder on
PATH, where a case-insensitive disk finds OpenCode as opencode), running
it with any arguments opens the app's window. A GUI app never answers
--version, and a timeout isn't cached, so it happened again at each
start. Nothing else in magpie opens OpenCode: no `open -a`, no
opencode:// URL, and the Sessions menu's Open/Terminal actions are a
user's click.
ProbeContext now refuses (cmd.Err, nothing started) a program that is
the main executable of an outermost .app bundle, after links: the
CFBundleExecutable of an XML Info.plist, or the program named as the
bundle when the plist can't be read (binary, as Kiro CLI.app's is). Every
probe goes through it: version, auth status, Grok's agentProbe. A
bundle's other programs still run (OpenCode's opencode-cli, Kiro CLI's
kiro-cli beside kiro_cli_desktop), and so does a bundle inside another
app's: ChatGPT.app's codex is CodexCLI.app's main executable (plist
checked on this Mac, ChatGPT 26.1027).
Tests (internal/proc/appmain_test.go, not on Windows): a fake
OpenCode.app whose programs record that they ran.
- TestProbeNeverOpensAnApp: a link to OpenCode is not run, Version is "",
`opencode` found in the bundle's folder by PATH is refused, the
bundled opencode-cli still answers.
- TestProbeUnreadPlistByName: no plist / a binary one: OpenCode is not
run, opencode-cli is.
- TestProbeRunsANestedAppsCLI: CodexCLI.app's codex inside ChatGPT.app,
with that app's plist keys, answers.
- TestAppMainOnlyBundles: paths that only look like a bundle.
Broken by hand: with the guard off, TestProbeNeverOpensAnApp and
TestProbeUnreadPlistByName go red (OpenCode ran); with the nested check
off, TestProbeRunsANestedAppsCLI and TestAppMainOnlyBundles go red.
Run on mote at a8d6a861a plus this change (go test -count=1 -timeout 45m):
internal/proc, library, wslrun, agent, provider ok. internal/cli red on
TestEveryRouteHasACommandOrIsNamed (POST /api/usage/checkin-account has
no command), which is #4826 from e87140242 and not touched here.
GOOS=windows go vet ./... ok; GOOS=linux go vet -tags nogui ./... ok
(wails' Linux GUI doesn't cross-vet from a Mac); gofmt -l empty.
Not tried: the real OpenCode desktop app (the cause is read from its
bundle layout and magpie's code, not reproduced), the reporter's PATH or
link, and a shell wrapper that execs the GUI program (still run).