Commit Graph
36 Commits
Author SHA1 Message Date
yetone 73ce9765f1 proc: EndProbes returns once a killed probe's whole group is gone, so an exit right after can't leave a missed child running (#1278)
JJ-Lin's fault injection on #1278: when the first signal to a probe's
group missed a process being forked, group.kill went on signalling it
from a goroutine nobody waited for, and the probe counted as ended as
soon as the first signal went out. EndProbes returned in ~0.2ms; magpie
then exiting (or Exec'ing the new version) ended that goroutine, and the
missed child lived on with PPID 1.

group.kill now returns a channel closed once none of the group is left
(or killFor has passed). A probe's Cancel marks its kill as begun and
counts the probe ended only when that channel closes. EndProbes waits up
to endWait for each kill to begin (a probe that already answered has
none, as before) and then for the group to be empty, bounded by killFor
plus a second. Every exit path goes through EndProbes: the GUI's
OnShutdown, the CLI's return and signal handler, and update.Reexec.

Windows: the job's TerminateJobObject takes no new process once it is
ending, and a probe is killed alone with TerminateProcess, so there was
no background loop to outlive; kill returns a closed channel there. The
known Windows gap that a shim's children aren't in a job for probes is
unchanged.

Run:
- TestEndProbesThenExitLeavesNothing (new) re-runs the test binary as a
  magpie whose group signals miss for 300ms, which calls EndProbes and
  os.Exit(0) at once. On the old code it fails 3/3 on darwin: "what the
  probe started (pid N) outlived magpie's exit after EndProbes".
- darwin: go test -race ./internal/proc ok; -race -count=10 of the
  probe/EndProbes tests ok.
- linux (docker golang:1.26.8 --init, GOTOOLCHAIN=local): -race -count=5
  of the probe/tree tests ok. Without --init the container's PID 1
  reaps nothing and every group test fails on zombies, on old code too.
- Windows box: new TestEndProbesWindows (ping probe ended, EndProbes
  ~0ms) passes 3/3; the rest of the package passes except
  TestNoCommandBypassesProc, which walks ../.. and found other
  checkouts in C:\Users\yeton since the binary ran outside a tree.
- gofmt -l, go vet (darwin), GOOS=linux vet -tags nogui, GOOS=windows vet.
2026-10-13 05:21:03 +08:00
yetone 7d0c68b187 proc: the mise-hangs test gives up on its fake mise once it has written its pid, not after 300ms a loaded machine passes first (#1838)
What: the context an ask of mise runs under comes from miseAsk (a var;
production keeps miseWait = 5s, now a const). The "hangs" case of
TestFindToolKeepsWrapperWhenMiseDoesntSay cancels it once the fake mise
has written its pid (polled, with a minute's cap), then checks that
FindTool returns the wrapper within 30s of that (the fake sleeps 60s) and
that the fake's process is gone. The other wrapper tests give an
answering fake a minute instead of the production 5s.

Why: the test set miseWait to 300ms; at load average ~20 the fake's shell
hadn't written its pid by then, was killed, and the test said "mise
wasn't asked" though FindTool had asked. Under the same load the "fails"
case took 4.5s of the 5s budget here, so the answering fakes got room too.

Run (go1.26.8, sandbox HOME, private GOCACHE, load avg ~20):
- repro on old code: a 0.5s sleep injected before the fake writes its pid
  -> hangs FAIL "mise wasn't asked".
- new code with a 2s sleep injected: pass (hangs 2.2s). Removed after.
- break check: miseWhich ignoring the context -> FAIL "FindTool returned
  1m0s after mise was given up on". Restored: pass.
- gofmt -l clean; go vet ./... darwin, linux -tags nogui, windows: clean.
- go test -tags nogui ./internal/proc: ok; -race -count=5 -run
  'TestFindTool|TestParseMiseWrapper': ok.
Not run: the full go test ./...; Linux CI's run of this test.
2026-10-12 23:56:20 +08:00
yetone 8bfe33f1f4 agent, proc: where each command is on PATH is looked up once while its folders are unchanged, so a Windows page doesn't stat PATH per agent and per session (#1771)
oxyuan profiled every page's first load on Windows at seconds (4-7s), and
Sessions, Usage → Sessions and Context at 26-45s: 96-98% of the samples
were os.Stat under exec.LookPath and proc.FindTool. A failed lookup stats
every PATHEXT candidate in every PATH folder (111ms there), and the pages
asked once per known agent (Detected → binAt) and once per Pi session
(sessions.carries → ompThere) on every request.

proc.Look (new, look.go) is exec.LookPath with its answers kept. The
proc.LookPath that 1bf722e28 added (exec.LookPath, then Unwrap of a mise
wrapper script) is now Look then Unwrap, and FindTool keeps its PATH
answer the same way before Unwrap. Unwrap keeps its own answer by the
script's size and time, and on Windows it returns at once. The PATH
answers are keyed on PATH and PATHEXT,
and dropped when a looked-in folder's modification time changes (an
install or removal), checked at most every 2s, every time in a test binary
testenv isolated. proc.Forget drops them all and agent.Rescan (the Agents
page's refresh) calls it. Every exec.LookPath that a page or the gateway
reaches now goes through one of them. The sites 1bf722e28 made unwrap keep
LookPath: agent (agent, air, nativemodels) and provider (codex models,
cursor, devin, kiro). The rest keep exec.LookPath's answer as it was,
through Look: agent (agents, cliupdate, the shim, gemini, install,
reasonix, vscode, zed), sessions/carry and library/rtk. Those left
on exec.LookPath run once per user action (update's pkexec, the
secret-tool read, installers, rtk upgrade) or in tests.

Run:
- look_test.go: asks once while folders are unchanged, sees an install and
  a removal, a changed PATH and Forget, concurrent lookups under -race. The
  first goes red with LookPath calling exec.LookPath directly.
- On the Windows box (yeton@10.0.0.132, amd64 probe, sandbox USERPROFILE):
  Detected with 4 agents 252ms → 7ms per call after the first, 297x
  LookPath(omp) 879ms → 1.1ms; drift over Detected 274ms → 42ms; Titles
  for 6 sessions 23ms → 4ms. The first call is the same (it looks).
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., sandboxed go test ./... at the rebased head.
Not run: the reporter's own machine (47 PATH folders, 59 agents).
2026-10-12 22:55:22 +08:00
yetone e4134d1fb7 agent: Codex's proxy is worked out from the login shell's NO_PROXY and HTTP_PROXY and macOS' HTTP entry alone, as its reqwest reads them, so "Codex 经代理连 magpie" no longer shows while Codex goes direct (liu_dyj on X)
liu_dyj: with the VPN on, magpie said Codex reached magpie through a
proxy that didn't pass its requests on; versions before f156d9046 had
no such check, which is why upgrading brought it.

Cause: codexProxyFor didn't read the proxy the way Codex does.
- It read magpie's own environment. Codex in a terminal has the login
  shell's, and the ChatGPT app's Codex too (ChatGPT.app 26.1007 runs
  $SHELL -ilc at start and Object.assign()s its env into process.env).
  magpie opened from the Dock has neither, so a NO_PROXY=127.0.0.1 in
  .zshrc, which keeps Codex direct, wasn't seen, and magpie probed the
  system proxy and warned.
- For the system proxy it took netproxy's one URL (HTTPS over HTTP over
  SOCKS). hyper-util 0.1.20's Matcher::from_system, which reqwest
  0.12.28 uses for Codex, takes only macOS' HTTP entry for an http://
  URL; with only the HTTPS or SOCKS entry set (ShadowsocksX-NG's global
  mode is SOCKS only) Codex goes direct and magpie warned. On Windows
  it takes ProxyServer as one address, which a per-protocol list
  ("http=..;https=..") isn't (http's Authority::parse refuses two
  colons), so Codex goes direct there too.
- With respect_system_proxy on macOS, CFNetwork's SOCKS entry is
  UnsupportedProxyScheme, and Codex falls back to HTTP_PROXY/ALL_PROXY
  with NO_PROXY (codex-rs outbound_proxy.rs resolve_env_proxy_route);
  magpie used the SOCKS URL.
- The probe spoke real SOCKS5 to a socks5:// proxy. Codex's reqwest is
  built without SOCKS (no tokio-socks in codex-rs Cargo.lock) and sends
  an absolute-URI HTTP request to it, so the probe now does the same:
  it passes a Clash mixed port as Codex does and fails a SOCKS-only
  port as Codex does.

So netproxy.Proxy carries the HTTP and SOCKS entries alone beside URL
(parseScutil, parseWindows), proc asks the login shell for the
*_PROXY variables with agentenv.Vars in the same probe and only reads
them (proc.LoginEnv; never set in magpie's env, whose requests use
netproxy), and codexProxyFor uses both. Failover's gate
(codexProxyOK) and the drift share codexProxyFor and proxyProbe, so
both follow. The pill's How to fix now names the shell profile for
NO_PROXY. Clash/mihomo rule mode with a 127.0.0.0/8 DIRECT rule never
warned and still doesn't; global mode or a rule set without it still
warns, rightly (real codex 502s there). TUN mode sets no proxy and
never warned.

Run:
- real codex-cli 0.162.1 in a sandbox HOME/CODEX_HOME against a fake
  gateway and mihomo v1.19.32 (rule, no-LAN-rule, global ports):
  direct, rule, and ALL_PROXY=socks5:// on the rule port reach the
  gateway; no-LAN-rule and global 502; global with NO_PROXY=127.0.0.1
  reaches it. The Go probe agrees on every one.
- go test -tags nogui ./internal/agent, ./internal/netproxy,
  ./internal/proc; gofmt -l; GOOS=linux and GOOS=windows go vet
  -tags nogui on the three packages.
- Broke each part by hand: sys.URL back in codexProxyFor (Windows per
  protocol, macOS HTTPS/SOCKS alone red), the probe's socks->http
  (TestRealProxyProbe red), codexEnv without the login shell
  (TestCodexEnvTakesLoginShell red), the respect-path SOCKS fallback
  (three respect cases red), setUnset of every shell var and the probe
  without ProxyVars (TestLoginEnvProxyVarsNotSet red).

Not tried: the macOS system proxy cases with real Codex (changing the
system's proxy settings is off limits here; read from hyper-util,
reqwest and codex-rs sources), the Windows per-protocol ProxyServer
with real Codex (from the http crate's source; no Windows run), and
the reporter's own app and mode, which are asked on X.
2026-10-12 22:33:50 +08:00
yetone 1bf722e289 proc, provider, agent: a claude (or other agent CLI) that is a mise wrapper script is run as the program mise names, and a Claude sign-in that gets no link says which program it ran (deluxe on Discord)
deluxe (Omarchy Linux, magpie started from the desktop) never saw the
Claude sign-in link. ~/.local/bin/claude was a script ending
`exec mise x "claude" -- "claude" "$@"`; without the shell's mise
environment, `mise x` looks claude up on PATH, finds the same script
(~/.local/bin is before mise's shims) and it runs itself for ever.

What changed:
- proc.Unwrap / proc.LookPath (internal/proc/wrapper.go): a small #!
  script whose line is `[exec] mise|rtx x|exec [opts] [tool] -- <name>`
  is resolved with `mise which <name>` (then `mise which --tool <tool>
  <name>`), run as a probe (process group killed) with a 5s timeout,
  magpie's environment and the home folder as cwd. The answer must be an
  executable file that isn't the wrapper or another wrapper; otherwise,
  or with no mise, the old path is kept. Answers are cached per file
  (path, mtime, size); a failed ask is retried after a minute.
  Windows is unchanged.
- proc.FindTool (claude via claudecode.Find: the sign-in, the gateway's
  Claude subscription, `magpie claude-code`) unwraps what it finds.
- The siblings that looked an agent CLI up with exec.LookPath use
  proc.LookPath: agent.binAt (detection, CLI version/update), codex,
  kiro-cli, devin, cursor-agent, Air's opencode, nativemodels' npm
  package lookup.
- The Claude sign-in already gave up after linkWait (30s) with "claude
  auth login gave no link to open". It now adds the last line the CLI
  printed, or, when it printed nothing, the program it ran and to run
  `<path> auth login` in a terminal to see what it does.

asdf shims (`exec asdf exec "claude" "$@"`) are left alone: asdf exec
resolves the real program itself and doesn't recurse.

Verified (macOS, sandbox HOME, Go caches pinned):
- New tests: internal/proc/wrapper_test.go (wrapper -> mise's program;
  no mise -> wrapper; mise fails / names the wrapper / names a folder /
  hangs -> wrapper, and the hung mise's pid is gone; deluxe's own fixed
  script, a node launcher, a wrapper of another command, a commented
  line -> unchanged and mise never asked; parse cases; --tool retry),
  internal/provider/signin_claude_wrapper_test.go (the full Claude
  sign-in through the wrapper with a fake mise that really recurses:
  link shown, account added; with no `mise which`, the sign-in fails in
  linkWait naming the wrapper).
- Break checks: with find.go put back, TestFindToolUnwrapsMiseWrapper and
  TestFindToolAsksWithWrappersTool FAIL (FindTool = the wrapper), and
  TestClaudeSignInThroughMiseWrapper FAILs with "claude auth login gave
  no link to open: .../local-bin/claude printed nothing in 5s". With the
  old error string, TestClaudeSignInWrapperThatNeverStarts FAILs.
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; GOOS=linux go build -tags nogui;
  GOOS=windows go build.
- go test -tags nogui ./...: every package ok except internal/agent and
  internal/gateway, which hit the default 10m timeout with the machine
  at load ~45 (different tests each run, none in the new code). Those
  two were rerun with -timeout 40m; origin/main 217d2f8f2's
  internal/agent alone took 2094s under the same load.
- Rebased on 9964535ad, -timeout 40m: internal/agent ok (1689s),
  internal/proc ok, internal/provider ok (681s), internal/claudecode ok;
  internal/gateway FAIL in one test, TestCodexHeardWithinItsIdleTimeout
  (3.78s against its 3s wall-clock bound, body right, no retry taken).
  Alone with -count=5 it passes 5 of 5. Filed as #1800; unrelated to
  binary lookup.

Not verified: no real mise or the reporter's Omarchy machine; the fake
mise stands in for mise's which/x. The wrapper fixture is the line the
reporter quoted, not their whole file.
2026-10-12 19:52:37 +08:00
yetone e2b3eb7406 agent: an npm -g agent under mise's Node says its version and updates with that Node's npm, not "can't tell how it was installed" (flp on Discord)
On Windows with Node managed by mise, the Agents page read "无法判断安装方式"
for an agent installed with npm install -g. howInstalled decided from the
binary's path, and a mise shim leads nowhere near node_modules: on a Mac
or Linux it is a symlink to the mise binary; on Windows a copy of
mise-shim.exe (exe mode, the default), a .cmd plus a bash script running
`mise x --` (file), or a hard or symbolic link to mise.exe.

A shim is now recognised (a link to mise, or a file in mise's shims
folder: parent "mise", a .mode file, or MISE_DATA_DIR/shims) and mise is
asked which program it runs, `mise which <cmd>` from the home folder; how
it was installed is read from that program. On Windows mise names npm's
extensionless sh script, so the .cmd beside it is used. The update runs
that Node version's own npm with --prefix, then `mise reshim`: on Windows
npm install -g makes no shim for a new command (seen on the box), mise's
Unix npm wrapper reshims itself, so it is harmless there.

Siblings:
- asdf shims (scripts with "# asdf-plugin:" and `exec asdf exec`) are
  asked with `asdf which` the same way; asdf-nodejs's npm reshims itself
  and asdf has no Windows build.
- proc.UserBinDirs on Windows also looks in mise's shims folder
  (MISE_DATA_DIR, else XDG_DATA_HOME\mise, which mise follows on Windows,
  else %LOCALAPPDATA%\mise) for an agent PATH doesn't reach.
- Install side: npmIn accepts npm.exe beside node as well as npm.cmd.
- WSL agents get no update path (CLI skips them) and wsl.go's probe
  already lists mise/asdf shims: unchanged.
- MISE_DATA_DIR and ASDF_DIR join agentenv.Vars, so a test sandbox
  clears them (TestFolderVarsAreListed).

Fixtures are real bytes: internal/agent/testdata/mise-windows from mise
2026.10.7 on the Windows box (file-mode snow.cmd and snow, .mode files,
npm's snow.cmd/snow in the Node folder); the Mac layout and the asdf
shim's text from mise 2026.10.7 and asdf 0.20.2 release binaries in a
sandbox home.

Run:
- flp's own layout (where.exe claude: installs\node\24.20.0\claude,
  claude.cmd, shims\claude.exe; mise which claude names the extensionless
  script): TestMiseShimWindowsFiveAgents covers claude, pi, codex,
  opencode and codebuddy through shims\<cmd>.exe; run on the Windows box,
  red with the fix removed by hand, green restored.
- go test -tags nogui ./internal/agent ./internal/proc -run
  'Shim|HowInstalled|UpdateCLI|NpmIn|InstalledVersion'; with installedAt
  skipping the shim by hand TestMiseShimIsNodesNpm,
  TestUpdateCLIThroughMiseShim and TestAsdfShimIsNodesNpm go red, green
  again restored.
- Real mise on the Mac (sandbox home, mise 2026.10.7, node 22.23.3,
  snow-ai): detection through the real shim and `mise which`, and a real
  update 0.9.1 -> 0.9.2 through UpdateCLI.
- Real mise on Windows (the box, sandbox USERPROFILE/LOCALAPPDATA, mise
  2026.10.7, node 22.23.3, snow-ai): the Windows test binary's unit tests
  (TestMiseShimWindows, TestHowInstalledWindowsShim, TestNpmIn) pass;
  a temporary test through the real shim in exe, file and hardlink modes
  found npm.cmd --prefix <node>, version 0.9.2; after npm install -g
  snow-ai@0.9.1 a real UpdateCLI took it to 0.9.2 and reshimmed; snow.exe
  ran 0.9.2. Symlink mode was not tried (needs developer mode); it is
  the link-to-mise case the Mac covers. flp's own machine was not tried.
- go test -tags nogui -timeout 40m ./...; gofmt -l; GOOS=linux and
  GOOS=windows go vet -tags nogui ./...
2026-10-11 12:45:31 +08:00
ggbdpqandfactory-droid[bot] c409693806 proc: a test's own signalGroup put back no longer races the kill loop still reading it (#1568, ggbdpq)
What changed:
- group.kill's retry loop outlives its caller: it keeps signalling a
  process group every 5ms for up to 10s after the caller (a probe's
  cmd.Cancel on exec's watchCtx goroutine) has gone. It read the package
  var signalGroup on every pass, so a test that swaps the var for its own
  and puts the old one back when it ends (TestProbeKillEndsWhatTheSignal-
  Missed's cleanup) raced the loop's reads: go test -race ./internal/proc/
  went red with "WARNING: DATA RACE" (write at probe_test.go:151, read at
  tree_other.go:43), 5 of 5 runs.
- kill now takes the kill function once at its entry and the loop uses
  that copy. In production nothing changes (the var is never written);
  a test's swap is seen by every kill started after it, and a loop under
  way finishes with the function it was started with, which is the one
  that must answer whether the group is empty.

Run:
- go test -race -tags nogui -count=1 -run TestProbeKillEndsWhatTheSignalMissed
  ./internal/proc/: FAIL with DATA RACE without the change (1 warning,
  5 of 5 runs), ok with it, and -race -count=20 ok.
- go test -race -tags nogui -count=1 and -count=1 ./internal/proc/ ok.
  Nothing else in the tree reads or writes signalGroup (grep).

Review: on main (3f5702421) go test -race -count=5 -run
TestProbeKillEndsWhatTheSignalMissed ./internal/proc reported 4 DATA RACE
warnings: the cleanup's write (probe_test.go:151) and the next run's swap
(probe_test.go:141) against the loop's read (tree_other.go:43), and one
run failed. With the change -race -count=30 is ok and the whole package
is ok under -race.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-10-11 12:00:41 +08:00
yetone 6b8dc4cdd8 proc, agent: magpie finds an agent CLI under the Node nvm's default names, not the folder whose name sorts last (v9 after v22)
proc.UserPath added "the newest-looking" nvm Node to magpie's PATH, the
last folder of ~/.nvm/versions/node/*/bin in string order. That isn't
the Node a terminal gets, and string order puts v9.11.2 after v22.12.0
and v22.3.0 after v22.12.0. So magpie could find, run and update a
codex/claude/gemini under a Node the user's terminal doesn't use (found
while answering 悠悠哥 on Discord, 9f407cafa). UserBinDirs (FindTool,
the Codex executable, nodeHere) took every version in reverse name
order, with the same flaw.

Now (internal/proc/nodever_other.go) the nvm folder is $NVM_DIR or
~/.nvm, and its default is resolved as nvm.sh does on load (nvm_auto
use -> nvm_resolve_local_alias default, read from nvm v0.40.3's
source): alias/default and each alias it names in turn (lts/* ->
lts/jod -> v22.x, lts/-N as nvm_normalize_lts counts it, user aliases),
a cycle being none; node/stable the highest installed; a partial
version (22, v20, 22.3) the highest installed it starts; an exact one
when its bin/node is installed. UserPath adds that one; with no usable
default (unset, not installed, cycle, iojs/unstable) the highest
version by number; with "system" none of nvm's, since the terminal then
runs the system Node. UserBinDirs lists the default first, then the
rest highest first.

Siblings:
- mise's installs and fnm's node-versions (UserBinDirs only) were in
  reverse name order too: now by number, fnm's aliases/default first
  (and $FNM_DIR looked in). mise's active Node is reached through its
  shims, which come earlier.
- volta, asdf and mise shims, and n (one copy in /usr/local/bin), pick
  the version themselves: no change.
- Windows (path_windows.go) lists no per-version folder: nvm-windows'
  current Node is its NVM_SYMLINK on the registry PATH. No change.
- The WSL probe's wslbin (internal/agent/wsl.go) globbed
  "$HOME"/.nvm/versions/node/*/bin, first in name order (v18 before the
  default v22). It now asks nvm itself (nvm.sh sourced by bash with
  --no-use, nvm_version default), then the rest highest first.
- NVM_DIR and FNM_DIR join agentenv.Vars: test sandboxes clear them, and
  UserPath takes them from the login shell like the agents' variables.

Run: TestUserPathNvmDefault (15 real nvm layouts: v9 vs v22, lts/*,
lts/iron, lts/-1, 22, v20, exact v9, node, stable, a user alias, a
default not installed, lts/* naming a line not installed, a cycle,
system direct and through an alias), TestFindToolNvmDefaultFirst,
TestUserPathNvmDir, TestUserBinDirsFnmMise, TestWSLProbeNvmDefault.
With the old path_other.go 14 of the 15 nvm cases go red (v9.11.2
picked; the exact-v9 default passes), as do the other three; with the
default ignored by hand 9 go red; with the old probe line all 3 WSL
cases go red. Cross-checked nvmDefault against
nvm v0.40.3's own nvm_version default on 19 alias layouts: same version
each time (nvm says N/A where magpie falls back, and N/A for system
with no system node). The new probe run with the real nvm.sh under
/bin/sh and /bin/dash resolved lts/*, lts/iron and 18 right. go test
./internal/proc ./internal/agent ./internal/agentenv ./internal/provider
./internal/testenv; full go test -tags nogui ./...; gofmt -l; go vet,
GOOS=linux and GOOS=windows go vet -tags nogui on the touched packages.
All under a temp HOME; no real ~/.nvm read.
2026-10-11 06:41:06 +08:00
yetone 81cf081f04 proc: a test that empties PATH means a machine without the tool, not one with Homebrew's (#1525, BUKOWSKIREAL)
TestFindTakesTheMachinesOwnFirst, TestClaudeSubscriptionRunsTheDownloadedClaudeCode
and TestClaudeSubscriptionWithoutClaudeCodeSaysHowToGetIt set PATH to an
empty folder to stand for a machine with no Claude Code, but
proc.FindTool falls back to proc.UserBinDirs, which lists the machine's
own /opt/homebrew/bin and /usr/local/bin. A Mac with
/opt/homebrew/bin/claude made Find() return it instead of the download.

proc.SystemDirs now gives every path of the machine's own that discovery
looks in. Outside tests it gives them as they are. In a test binary
testenv isolated (MAGPIE_TEST_SANDBOX set), each one is under the test's
home, at <home>/system/<path>, so the tests decide what is installed
there. The same leak was in the sibling finders, which now go through
it too:
- proc.UserBinDirs (Homebrew, /usr/local/bin), used by FindTool, the
  agents' install check (proc.FindTool(a.Bin) in internal/agent) and codexExecutable;
- FindTool's and nodeHere's Windows fallback to the registry PATH and
  %ProgramFiles%\nodejs;
- KiroExecutable, CursorExecutable and DevinExecutable's /usr/local/bin,
  /opt/homebrew/bin and /Applications/Kiro CLI.app paths.
Production discovery doesn't change.

Not changed: update's and rtk's choice of a PATH folder to link into
(they only take a folder already on PATH, which the test sets) and
FindShell (a test that runs a shell needs the real one).

Reproduced on this Mac, which has /opt/homebrew/bin/gemini, npm, node and
opencode but no claude there: under testenv with PATH emptied,
FindTool("gemini") gave /opt/homebrew/bin/gemini. The new
TestSystemDirsLieInTheTestsHome checks that no tool is found with an
empty PATH, and that a claude put at SystemDirs("/opt/homebrew/bin") in
the test's home is still found. Making SystemDirs return its paths
unchanged turns it red (gemini, npm, node and opencode found on the
host).

Run: go test -tags nogui -count=1 ./internal/proc ./internal/claudecode
./internal/provider ./internal/agent . (all ok); the three tests from
the issue -run by name in ./internal/claudecode ./internal/gateway (pass);
gofmt -l; GOOS=linux and GOOS=windows go vet -tags nogui on the touched
packages.
2026-10-11 00:52:57 +08:00
yetone cc8eb5a742 proc: the login shell's PATH comes when its profile starts tmux or zellij in an interactive shell, or is slow to come up in one (John on Discord)
John on Discord: agents on fish's PATH weren't found, fish being the login
shell (set with chsh). With SHELL=fish and a plain config.fish the probe
already worked (9bad1144's checks), so the difference is in the profile.
Reproduced with real fish 4.9.3 under the probe (ProbeContext, -ilc, no
terminal), a config.fish adding a folder with fish_add_path, plus:
  fish_greeting set              PATH comes
  read -P under is-interactive   PATH comes
  exec tmux under is-interactive no answer: tmux replaces fish
  exec /bin/cat likewise         no answer
  sleep 6 (a slow profile)       no answer after the 5s limit
With no answer magpie got no PATH at all from the login shell.

askShell now asks again as a login shell only (-lc) when the interactive
login shell (-ilc) gives no answer, timed out or not, with the same 5s
limit. fish reads config.fish then too, zsh .zprofile, bash
.bash_profile. MAGPIE_SHELL_PROBE=1 is in the probe's environment both
times, so a profile can skip its auto-start for magpie.

Not the cause, checked: a desktop app and a LaunchAgent get SHELL from
the user record (every launchd job here has SHELL); askShell runs the
absolute $SHELL as it is (/opt/homebrew/bin/fish). A SHELL left from
before chsh until logout is covered by 9bad1144 asking an installed,
set-up fish beside it. The TUI/CLI take the terminal's own PATH.

Tests: TestAskShellProfileExecsOrHangs (fake shells that exec cat or
sleep when interactive) and TestAskShellRealFishAutostart (real fish,
skipped without it) fail on the old askShell:
  slow: PATH = "", vars false: the login shell wasn't asked again
  tmux: PATH = "", want ".../fb" in it
and with the variable taken out: "exec: MAGPIE_SHELL_PROBE didn't reach
the profile". Run: internal/proc and internal/update tests pass (with
fish 4.9.3 on PATH); gofmt -l clean; go vet and GOOS=linux,
GOOS=windows go vet on internal/proc clean.
Real use: sandbox magpie (go build -tags dev, own HOME, ports
3486/3487, PATH=/usr/bin:/bin:/usr/sbin:/sbin, SHELL=<real fish>,
config.fish with fish_add_path to a folder holding a fake claude and
`if status is-interactive; and not set -q TMUX; exec /bin/cat; end`):
origin/main finds no claude in /api/agents/cli or /api/state; this
build finds it (2.1.99, the fake's).
2026-10-10 21:54:38 +08:00
yetone 9bad11449b proc, update: an agent installed in a folder only fish's config adds is found when the terminal opens fish but the login shell is zsh or bash (John on Discord)
John on Discord: 二进制文件没有从用户环境变量找到,我终端环境使用的fish. The desktop
app gets launchd's PATH and asks the login shell ($SHELL) for its own.
fish isn't a POSIX shell, so many keep zsh or bash as the login shell and
have the terminal open fish (its profile setting, or exec fish from
.zshrc). magpie then asked only zsh, and a claude or codex in a folder
config.fish adds (fish_add_path, set -gx PATH) wasn't seen.

The suspected cause, fish joining "$PATH" with spaces, isn't it: PATH is a
path variable in fish and is joined with ':' in double quotes. Checked with
real fish 4.9.3 (macOS), 3.6 and 4.0.2 (Debian, Docker) under -ilc with
the probe's printf and \0: PATH whole, the variables in place. With
SHELL=fish the old code already found the agent.

- shellEnv asks fish and nushell too, in parallel with the login shell,
  when they are installed and their config folder exists (each makes it
  on its first run) and they aren't the login shell. Their PATH folders
  come after the login shell's; a variable of agentenv.Vars the login
  shell leaves empty is taken from them.
- proc.FindShell finds a shell in the system's, Homebrew's, MacPorts',
  Nix's, ~/.local/bin and cargo's folders, then /etc/shells, then PATH.
  Settings > Command line (update.installedShells) uses it too, so a fish
  from MacPorts or Nix is listed there as well.
- The shellProbe comment now says why fish's "$PATH" is right.

Tests: TestShellEnvAsksFishBesideLoginShell (a fake fish answering with
the bytes real fish 4.9.3 printed) and TestShellEnvRealFish (real fish,
skipped where it isn't installed) fail on the old shellEnv:
  PATH = "/from/zsh:/usr/bin:/bin", want the login shell's first and
  fish's folder after
  PATH = "/usr/bin:/bin", want fish's ".../fish bin" in it
TestShellEnvLeavesUnusedFish and TestShellEnvFishLogin cover fish with no
config and fish as the login shell.

Run: internal/proc shell tests on macOS with the downloaded fish 4.9.3 and
on Linux (golang:1.26.8 + Debian fish 4.0.2) all pass; go test ./...
under a temp HOME: all pass except gateway (10m timeout under load; the
failing TestClaudeUnloadableSessionStartsAnew passes alone) and gui
TestOTelPreferencesAPI (TempDir cleanup race, passes alone -count=3),
neither touching this code; gofmt -l clean; go vet and GOOS=linux,
GOOS=windows go vet on internal/proc and internal/update clean.
Real use: a sandbox magpie (go build -tags dev, own HOME, ports
3486/3487, launchd-like PATH=/usr/bin:/bin:/usr/sbin:/sbin, SHELL=/bin/zsh
with no .zshrc, fish at ~/.local/bin/fish, a fake claude only in a folder
config.fish adds with fish_add_path): the old build reports no claude in
/api/agents/cli and /api/state; this one finds it (version 2.1.99 of the
fake). With SHELL=fish both builds find it.
2026-10-10 21:42:00 +08:00
yetone b934d64a4e tests: TestNoCommandBypassesProc leaves out internal/testenv, which only tests import and which can't import proc (its tests import testenv); main was red since 2da8fbe4's testenv.Bun ran bun with os/exec 2026-10-10 10:51:48 +08:00
yetone 98236edd77 agent: Codex installed by install.ps1 on Windows shows its newest version and offers codex update, and its version is read again after each update (xiaoxiaofeixz on Discord: 不会自动检测最新的版本)
Codex's install.ps1 puts %LOCALAPPDATA%\Programs\OpenAI\Codex\bin on PATH.
That folder is a junction to ~\.codex\packages\standalone\current\bin, and
current is a junction to releases\<version>-<target>, retargeted by each
update. filepath.EvalSymlinks leaves junctions alone since Go 1.23, so
magpie saw the binary only as ...\Programs\OpenAI\Codex\bin\codex.exe:

- howInstalled didn't find .codex/packages/standalone in its path, so the
  Agents page showed the version with no newest version and no update.
- installedVersion's stamp was that unchanged path plus size and mtime.
  npm's archive, which install.ps1's legacy layout copies from, gives every
  version's codex.exe the same 1985 mtime. So a new release was asked again
  only if its size happened to differ, else after the 24h memo.

proc.RealPath is now the path Windows opens (GetFinalPathNameByHandle),
junctions followed, and filepath.EvalSymlinks elsewhere. cliupdate's
howInstalled and installedVersion and proc.Version use it.

TestCodexInstallPs1Junctions (Windows) builds install.ps1's layout with
mklink /J, two releases whose codex.exe have the same bytes and mtime. It
checks that codex is recognized as self-updated (codex update) and that
retargeting current makes the version asked again. On the Windows box
(10.0.0.132, sandboxed USERPROFILE/APPDATA/LOCALAPPDATA) it fails on the old
code (howInstalled nil; "0.161.0" after the update) and passes on the new.
The rest of the agent package fails on Windows with the same 17 tests
before and after (TestFolderVarsAreListed, TestAside*, TestVSCodium, ...),
which CI never runs there. `codex update` on Windows is in codex.exe 0.162.0
(win32-x64): it runs install.ps1. The layout was read from
https://chatgpt.com/codex/install.ps1.

Not tried with a real install.ps1 install (it rewrites the user's PATH in
the registry). go test -tags nogui ./internal/agent ./internal/proc
./internal/provider ./internal/library (macOS), gofmt, and go vet for
GOOS=linux and windows pass.
2026-10-09 13:44:50 +08:00
yetone 1831ac4b63 proc: a CLI probe or agent run that is killed leaves nothing of itself running on Mac and Linux, even a launcher that keeps calling itself: its process group is signalled until it is empty, not once (#1278, JJ-Lin)
An old ~/.local/bin/cursor-agent that runs `cursor agent`, which (Cursor's
own bin/cursor) first runs ~/.local/bin/cursor-agent --min-version=... status,
calls itself without end. magpie asks cursor-agent who is signed in (about,
10s timeout) and kills the probe's session on the timeout with one SIGKILL
to the group. On macOS that one signal can miss a process being forked as it
goes out; the miss lives on, in the same group, adopted by init, and keeps
calling itself until the user can start no process (JJ-Lin: ~4800 bash
processes in one chain whose root's parent is PID 1). group.kill now sends
SIGKILL to the group again every 5ms, behind the caller, until the group is
gone (ESRCH) or 10s pass. The group keeps its id while any of it lives, so
nothing else is signalled. It covers ProbeContext's timeout and EndProbes,
and StartTree's Kill and sweep.

Verified:
- red without the change: TestProbeKillEndsWhatTheSignalMissed (the first
  group signal is made to miss, as the race does) fails with
  "what the probe started (pid 95576) outlived a kill that missed it once";
  passes with it (-count=5).
- reproduced the leak with the real Cursor 3.12.6 launcher script
  (/Applications/Cursor.app/.../bin/cursor, read only) and JJ-Lin's 87-byte
  wrapper in a sandbox HOME, under ulimit -u: ProbeContext(cursor-agent about)
  with a 10s timeout peaked at 311-700 processes; before the change 1 of 3
  runs left a chain behind (root ppid 1, same pgid, args
  "agent --min-version=2025.10.01 status"), after it 0 of 6. A fake
  launcher (60 parallel self-calling chains, killed at 500ms) left survivors
  4 of 30 runs before, 0 of 30 after.
- the same through provider.askCursorStatus with the real launcher, 5 runs:
  no cursor process left after each.
- go test -tags nogui ./internal/proc/ in a sandbox HOME; go vet -tags nogui
  of proc for darwin, linux and windows.
2026-10-08 18:18:15 +08:00
yetone 9fcd332b6c proc: a .cmd or .bat is run through cmd.exe with each argument quoted for it, so npm.cmd under C:\Program Files\nodejs (nvm-windows) no longer runs "C:\Program" when magpie updates Claude Code (wztlink1013 on Discord)
Windows starts a batch file as `cmd.exe /c <line>`, and Go builds that
line for a program's parser: with more than two quotes cmd.exe drops the
first and last, so `"C:\Program Files\nodejs\npm.cmd" install -g --prefix
"C:\Program Files\nodejs" …` ran C:\Program. An argument with & or | was
also left unquoted and split into a second command. Every command magpie
runs is made by proc.Command/CommandContext, so the fix is there:
cmd.exe /d /e:ON /v:OFF /s /c "<script> <args>", each argument quoted as
Rust's std does for batch files (doubled ", % broken up).

TestBatchFileInFolderWithSpace (windows) runs npm.cmd, a .bat and npm via
PATH under "Program Files" with the reporter's arguments plus & | % ^ and
trailing-\ cases, through a script that hands %* to a real program. On the
old code it fails on the Windows box with "'…\Program' 不是内部或外部命令".
On the Windows box (Windows 11, zh-CN) magpie's own updater
(howInstalled + runUpdate) on a real npm install of Claude Code 2.0.50
under "…\Program Files\nodejs": old code failed with the reporter's error,
new code updated it to 2.1.293.
2026-10-08 15:04:24 +08:00
forever c2020e0bb3 proc tests: TestAskShellOwnSession reads magpie's session with x/sys/unix, so the package's tests build on Linux (#1219)
bbf99143's test called syscall.Getsid, which Go's syscall package has on
macOS and the BSDs but not on Linux: go vet ./... (and every test run) on
Linux stopped at "undefined: syscall.Getsid", so the ubuntu Test job failed
at Vet on main and on every PR. golang.org/x/sys/unix, already required,
has Getsid on every Unix.

Verified: GOOS=linux, darwin, freebsd and android go vet ./internal/proc;
go test -run TestAskShellOwnSession ./internal/proc on macOS. Linux is run
by this PR's ubuntu job; there is no Linux machine here.
2026-10-08 04:44:10 +08:00
yetone bbf9914307 proc: the login shell magpie asks for its PATH runs in a session of its own, so it can't take the terminal from magpie (DD on Discord: magpie web → zsh: suspended (tty input))
askShell ran `$SHELL -ilc` (and ReadCLI's zsh, bash and fish, for Settings › Command line; LoginPath for Library › RTK) in magpie's own session and process group. An interactive zsh puts itself in the terminal's foreground, so while it ran, magpie's group was in the background of the terminal it was started from: Ctrl-C no longer reached `magpie web`, and anything left in magpie's group that touched the terminal — the bash asked beside it, whose profile runs in magpie's group without job control, or another child — had the kernel send SIGTTIN to the whole group, stopping magpie ("zsh: suspended (tty input)"). Run with `&`, the user's own shell then got EIO reading the terminal and exited. A timeout also killed only the shell, leaving what its profile started holding the terminal.

The shell is now a probe (ProbeContext): it leads a session with no controlling terminal, and its timeout and EndProbes end its whole group. It still answers with its PATH and variables.

TestAskShellOwnSession (a fake shell answering with its process group; a real zsh still gives a PATH) fails without the change: "the login shell ran in magpie's process group …". Reproduced on a pty under an interactive zsh -f, temp HOME, MAGPIE_ADDR 127.0.0.1:47811, magpie web on 47812, ~/.zshrc `sleep 2`, ~/.bash_profile reading /dev/tty, GET /api/cli: the old build prints "zsh: suspended (tty input)  magpie web" in the foreground and "[1] + suspended (tty input)" with `&` (then "zsh: error on TTY read"); with a plain profile it loses the foreground (ps S+ → S). The fixed build stays S+ / running in both, and /api/cli still says zsh and bash are known. go vet -tags nogui ./..., GOOS=linux go build -tags nogui, GOOS=windows go build, and go test -tags nogui of internal/proc, internal/update, internal/library and internal/gui under a temp HOME pass; -race -count=10 of the new test passes. Not tried with DD's own profile, or on Linux.
2026-10-08 03:45:32 +08:00
yetone 06420a7121 tests: a fake program is a file macOS has already let run (testenv.Program), so a fake's first start no longer eats a test's wait under load
macOS checks a newly written executable before its first exec: 0.27s
alone, 2-5s while other new programs start (a go test ./... starting its
test binaries). The same file again takes 0.009s, and the pass is kept
across a rename and an in-place rewrite. 108852b4 worked round this for one
test with /bin/sh -c; the class was every test that writes a `#!/bin/sh`
fake and times its answer.

testenv.Program(t, path, script) replaces os.WriteFile(path, script, 0o755)
for fakes. On macOS it renames a file that has run once from a pool to path
and writes the script into it in place; at the test's cleanup the file goes
back to the pool (only a path the test created; a stand-in it wrote over
stays). Fakes still end with their tests: nothing about how they are
started or waited on changed. Run (and gateway's TestMain) remove the pool
at the end. TestMain's PATH stand-ins are run once in the background
(testenv.StandIns). Other systems write the file as before.

Converted every `#!/bin/sh` fake written by tests under internal/ (agent,
gateway, gui, library, plugin, proc, provider, update). Windows, binary
and node/bun fakes are unchanged.

Under the same load (3 loops each starting 8 freshly written scripts at a
time), 4 rounds each, before (108852b4 / origin/main) vs after:
- provider TestSavedButSignedOutClaudeServed: 4/4 fail (8.01s) -> 4/4 pass
- provider TestClaudeSignInOverStaleCredentials: 4/4 fail (5.00s) -> 4/4 pass
- provider TestDevinSignedInOnlyInMagpie: 3/4 fail ("CLI's own []") -> 4/4 pass
- gateway TestClaudeRunEndsWhenTheClientLeaves: 4/4 fail -> 4/4 pass
  (and 3/3 fail -> 3/3 pass at a third of that load)
- gateway TestClientGoneRecordedAsCanceled: 4/4 fail -> 4/4 pass
- gui TestProvidersAnswerWhileListsComeIn ("cursor found false" at 3.03s):
  4/4 fail -> 4/4 pass. The same class, not bfe8bcaf's test order.
- proc TestUserPath (login shell's PATH never came, 7.01s): 4/4 fail ->
  4/4 pass
Unloaded, every touched package passes; no pool directory or process is
left after a run.
2026-10-07 03:00:47 +08:00
TryWorld 3cc017cd11 proc: IsMagpie knows the name an update leaves a running exe under (#963)
An update moves the running exe aside to exe.old, and when that name is still
held to exe.old-2, -3 (internal/update/update.go, oldName; two of the Windows
install tests assert .old-2 is where the running exe ended up). IsMagpie stripped
".old" and then ".exe", in that order, which unwraps exe.old but not exe.old-2:
".old" is not a suffix of "magpie.exe.old-2", so nothing came off and the name
matched neither magpie nor dial.

So the Gateway card's "Quit magpie and take over" refused to end the user's own
magpie: quitMagpieOnPort takes the "not-magpie" reason and the window says
"which isn't magpie, so magpie leaves it alone", with no way to end it from
there. startHere reads the same function, so it also misreports a magpie that
took the port back as something else.

The tail is now recognised as the count an update appends. Another program's
own name is still left alone: ".old-2" without a number is not ours, and
"magpie.old-backup" is not an update's.

Unchanged: every name IsMagpie already accepted, and the rule that only magpie's
own programs are ended — nothing else is ever touched.

TestIsMagpie's four new paths fail without the change (magpie.exe.old-2,
magpie.exe.old-3, magpie.old-2, dial.old-4 all read as not magpie) and pass
with it; the two negatives are checked in the same table. go vet ./... and the
builds for darwin, GOOS=linux and GOOS=windows pass, and internal/proc passes
-race -count=20.
2026-10-06 11:28:04 +08:00
yetone 0ef7066915 gui, proc: a magpie in a container holding the gateway's port is said as a container's to stop, Settings can move this magpie's gateway past it, and the take-over button is bordered in dark mode (leslie_luo on Discord)
An old magpie (v0.1.552) running in OrbStack held 3425, forwarded on the
Mac by OrbStack Helper. The Gateway card's take-over named OrbStack Helper
as a program that isn't magpie and said to move the gateway to another
port in Settings, and Settings refused the move because another magpie
served the gateway, so there was no way out. proc.IsForwarder tells the
programs that hold a port for a container or a VM (OrbStack, Docker
Desktop, docker-proxy, vpnkit, gvproxy, Lima, WSL's relay); the take-over
then answers reason container, said as the magpie inside it to stop (docker
ps, docker stop, or OrbStack / Docker Desktop) or this magpie's port to
move. setPort refuses only when a magpie program of this user's listens on
the port (magpieOnPort): one in a container, or one this user can't see,
is left on its port and this magpie serves on the new one, the agents it
connected moved with it. The take-over/restart button is text action, a
bordered button, as a plain text button read as words on the dark card.

TestGatewayHeldByAContainer runs a copy of the test binary named OrbStack
Helper answering as magpie on a port of the test's own: the take-over says
container and leaves it running, and setPort moves the gateway to a new
port where it answers as this one's; a copy named magpie still has its
port set there. TestIsForwarder covers the names. gateway-takeover.test.cjs
checks the container message in English and Chinese and the button's
border in dark mode. Both fail without the change. go vet, go build
(GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp
HOME pass.
2026-10-05 22:20:45 +08:00
yetone d6daa40ce3 update, gui: Settings › About › Command line says what magpie runs in a new terminal and adds it (PAMI on Discord) — the app downloaded from the site, and every Windows one, left terminals without the magpie command, and nothing in the GUI said whether it was there. A Command line row now asks each shell installed (zsh, bash, fish and the login shell; PowerShell and cmd on Windows) for its PATH and says, with a dot each, whether its magpie runs this app, another copy (with that copy's version, read from its .app's Info.plist or Homebrew Cellar folder, never by running it), or none. Add to PATH links this app's program (Homebrew's opt link, the AppImage) into the folder on the default shell's PATH whose magpie runs first, else ~/.local/bin or the like when on PATH, replacing another copy there as install.sh's ln -sf does; on Windows it puts the app's folder first in HKCU\Environment Path and broadcasts WM_SETTINGCHANGE. A shell whose PATH lacks that folder gets its own button naming its profile (~/.zshrc, ~/.bash_profile on the Mac or ~/.bashrc, fish's config.fish), which links into ~/.local/bin and adds that folder with one marked line, once; no profile is written otherwise. A translocated or disk-image app is told to move first and gets no button. It says new terminals take the change (on Windows: new PowerShell/cmd windows, restart Windows Terminal). GET/POST /api/cli; en/zh/ja/de. TestCLIOnPath (temp HOME, stubbed shells: link, fish profile once, a shadowing copy replaced, no folder → zsh's profile kept and appended, an unknown shell refused, plist version, translocated refused) and TestPathFirst are new; cli-path.test.cjs (WebKit, en and zh: per-shell dots, Add posts {} and turns green, fish's button posts fish alone, Windows lists PowerShell and cmd, translocated gets no button, no scroll, no select, no left border, translations) fails without the change; cli-behind and update-auto pass. Not tried on a real Windows machine. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass (TestOTelWholeWaterfallFallback and TestDevinSignedInOnlyInMagpie failed once each under load and pass alone). 2026-10-05 17:49:20 +08:00
yetone 2c801b6f9a gui, proc: the Gateway card quits an older magpie serving the gateway and takes it over, or restarts the gateway (leslie_luo on Discord) — the card said an older magpie served the gateway and to quit it, with no way to tell which process that was. With an older magpie on the port it now has "Quit magpie {v} and take over": the process listening on the gateway's port is found (lsof on a Mac, /proc on Linux, Get-NetTCPConnection on Windows), its program path checked to be magpie's (magpie, magpie-*, dial, .exe/.old), asked to quit (SIGTERM, then SIGKILL after 5 s; TerminateProcess on Windows) and this magpie serves the gateway at once instead of within 15 s. Otherwise the card has "Restart gateway" ("Start gateway" when none runs); a magpie of this version or newer gets no button. Anything else on the port is never ended: a program that isn't magpie, one of another user or an administrator, one that won't quit, or a magpie a LaunchAgent/systemd unit/scheduled task starts again is said under the button with its path and pid, in en/zh/ja/de. TestGatewayFixQuitsOnlyAMagpie (copies of the test binary on a port of its own: one named other-server answering as magpie is left running, one named magpie is quit and the gateway is served here, then restarted) and gateway-takeover.test.cjs (WebKit and Chromium, en and zh, no scroll, no left border) fail without the change; TestListeningOn/TestIsMagpie pass on macOS and in a Linux container. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. 2026-10-05 15:05:31 +08:00
yetone 4183f516bf agent, provider: a CLI whose --version fails isn't run again until it changes, and an npm CLI's version is read from its package (#864) — macOS put up 「已阻止恶意软件:未打开 "codex"」 each time magpie's window opened: the codex magpie finds was asked its version every ten minutes (the model list's client version) and again with the Agents page (a failure retried after ten minutes), and macOS stops a program XProtect flags with that alert on every start. proc.Version is the one way both ask now: an npm CLI (…/node_modules/@openai/codex/bin/codex.js) has its package.json's version read and isn't run at all; any other is run with --version, and a run that ran and said nothing, or couldn't start, isn't made again until the binary's path, size or mtime changes (a reinstall); one cut off by the timeout is. A CLI that answered is asked as before. TestCodexVersionNotRerun (a codex that exits 137 run once over three ten-minute refreshes; an npm codex's version read, not run) fails on the old code (run 3 times); TestVersionRunsOnce. TestUpdateCLI and the agent and provider tests pass. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but for TestClientGoneRecordedAsCanceled, which passes alone (-count=3). 2026-10-05 13:24:01 +08:00
yetone 72c6b85b0d provider: Claude Code installed off magpie's PATH is found on Windows too, so its sign-in no longer says to install it (EZN7L2C3, #839) — claudeExecutable looked on PATH, then at ~/.local/bin/claude, /usr/local/bin/claude and /opt/homebrew/bin/claude; on Windows the installer's binary is ~/.local/bin/claude.exe, and a magpie started before Claude Code was installed hasn't its folder on PATH, so the Claude sign-in said "install Claude Code first" while the Agents page, which reads ~/.claude, listed it. proc.FindTool now finds a CLI as a terminal would: on PATH, in the folders users' tools go in (UserBinDirs: npm's, ~/.local/bin, bun's, volta's, pnpm's, …) as name.exe, name.cmd or name on Windows, then on the PATH the registry has now; the sign-in and the gateway's Claude runs both use it. TestClaudeFoundInLocalBin fails on the old code on Windows (built for windows/amd64 and run on the Windows 11 test box: claude ""), passes there and here; TestToolIn. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-05 07:42:57 +08:00
tobitege 21702d01ff Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars

Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows.

* Makefile: know magpie's folder by its go.mod, so paths with spaces work

The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs.

* i18n: German for the strings main added since, with a parity test

75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system.

* appdir: ignore relative folder variables when reading, keep them for children

CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder.

* Sandbox the tests main added since

internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE.

* agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose

omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over.

* i18n: German for the Library's multi-select and System One's decision API

The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes.

* appdir: tidy the import into magpie's group; say what Go makes of /c/x

The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x.
2026-10-04 23:30:56 +08:00
ylornandylorn 1aef0f3f2d proc: the login-shell probe asks nushell through /bin/sh, and a value the shell printed instead of expanding counts as unset (#738: with nushell as the login shell, shellEnv's printf '…' "$PATH" "$CLAUDE_CONFIG_DIR" … came back as the text "$PATH", "$CLAUDE_CONFIG_DIR", … — a double-quoted string is literal in nushell — and setUnset exported every one of agentenv.Vars with its own name as the value; Claude sign-in then failed with "mkdir $CLAUDE_CONFIG_DIR: read-only file system" (putClaudeLogin's MkdirAll of that relative name under the GUI's cwd /), and the account lapsed minutes later as "Claude Code is no longer signed in", its sign-in looked for under that folder; Codex, Pi, omp and the rest were pointed at "$CODEX_HOME", "$PI_CODING_AGENT_DIR", "$OMP_PROFILE" the same way, in the GUI alone, which is the one caller of UserPath) — shellProbe builds the command: for a shell named nu it is ^/bin/sh -c '<the same printf>' (nushell has no POSIX quoting to ask with and its PATH is a list, while a child of it gets the environment as any child does, PATH joined back into one string, and sh expands the references; the outer string in nushell's single quotes where a backslash is a backslash, the format in sh's double quotes where \0 reaches printf), any other shell keeps the printf it had; and parseShellEnv takes a value that is the variable's own reference ("$CODEX_HOME", or "$PATH" for PATH) for unset, so a login shell with other quoting than POSIX leaves a variable alone rather than setting it to its name. TestShellEnvNushell runs the probe through a nushell on the machine (skipped where there is none) and checks the command's shape anyway; TestParseShellEnvUnexpanded feeds the unexpanded answer. Verified against nushell 0.116.0: PATH comes back, CODEX_HOME from the environment reaches sh, unset variables are "". (#739)
Co-authored-by: ylorn <ylorn@icloud.com>
2026-10-04 11:13:50 +08:00
yetone a27bd9ec96 proc: the desktop app takes the agents' folder variables from the login shell, as it does PATH (atie on Discord: PI_CODING_AGENT_DIR set in the shell, magpie still wrote Pi's config to ~/.pi/agent/models.json) — magpie reads PI_CODING_AGENT_DIR, CODEX_HOME, CLAUDE_CONFIG_DIR and the rest with os.Getenv, but an app opened from the Finder, the Dock or the login item gets launchd's environment, with nothing a shell profile exports, so every agent was wired into its default folder in the home. proc.UserPath already asked the login shell for its PATH (sh -ilc printf with markers); the same single call now prints PATH and every variable in agentenv.Vars between the markers, parted by NULs, and each one magpie's environment doesn't have and the shell gives a non-empty value is set with os.Setenv; one magpie was started with is kept. These are read as soon as the app starts (the library is synced into the agents at once, the backend wires them), so UserPath now waits for the shell's answer up to 2 s instead of not at all; a slower profile still doesn't hold the window up longer, and what it says later is still taken. LoginPath uses the same call. Windows is unchanged (an app gets the user's environment from the registry there). Only the GUI's runGUI/runPanel call UserPath; no test but proc's own does. TestUserPathTakesAgentVars (a fake $SHELL whose profile exports PI_CODING_AGENT_DIR with a space, CODEX_HOME and an empty GROK_HOME) fails on the old code (nothing taken) and passes: Pi's folder is set by the time UserPath returns, magpie's own CODEX_HOME is kept, the empty and absent ones stay unset. Tried with a built binary calling proc.UserPath under env -i (launchd's PATH, a temp HOME): with /bin/zsh, .zshrc's PI_CODING_AGENT_DIR="$HOME/my pi" and CLAUDE_CONFIG_DIR came through, CODEX_HOME=/kept stayed, .zprofile's PATH folder was added, in 19 ms; with /bin/bash, .bash_profile's value came through. go vet, builds (darwin, GOOS=linux -tags nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but TestClaudeSignedOut, TestClaudeAccountNamedAsItsLogin, TestClaudeIdentityServedWhileAsked and TestDevinSignedInOnlyInMagpie, timing tests on fake CLIs (5 s waits) that pass when the package is rerun; none of them reaches UserPath. 2026-10-03 22:34:36 +08:00
yetone 9848a9062a library: RTK says when rtk isn't on the PATH the agents get, and puts it there when asked (#601, Moody-Sin: magpie好像没有正确安装RTK — Pi said "RTK disabled: rtk binary not found in PATH" while the Library showed RTK working) — rtk's hooks run it by name (Pi's extension probes rtk --version and turns itself off when that fails; Claude Code's and Codex's are rtk hook …; the commands they rewrite to are rtk git status and so on), but magpie looked for rtk in more places than an agent's PATH: ~/.local/bin and ~/.cargo/bin, which the app adds to its own PATH whether the user's shell has them or not (rtk's own install.sh puts it in ~/.local/bin and only warns when that isn't on PATH), and WinGet\Links on Windows, which winget doesn't always link into. So rtk was "installed", the agents were switched on with it by its whole path, and none of them could run it. Now the PATH a terminal opened now has is read — the login shell's (proc.LoginPath, the one UserPath already asks for, kept a minute) or on Windows the registry's (moved from provider's registryPath) — and when rtk isn't in it the RTK card says so, with what Put RTK on PATH will do, and each agent that has rtk is tagged Not on PATH (不在 PATH 中). Put RTK on PATH (magpie library rtk path) links rtk into the first of ~/.local/bin, ~/bin, /opt/homebrew/bin, /usr/local/bin, linuxbrew's bin, ~/.cargo/bin that is on that PATH and writable, or on Windows adds rtk's own folder to the user's PATH in the registry (a link needs Developer Mode, and a copy is left behind when winget upgrades rtk; winget's package folder doesn't change across upgrades) and tells Explorer; with no such folder it says which folder to add to PATH in the shell profile — shell profiles are never edited. rtk is also found in winget's package folder (WinGet\Packages\rtk-ai.rtk_*), and rtk's script upgrades a linked rtk where the link points, not over the link. TestRTKOffPath and library-rtk-path.test.cjs (en, zh) fail without the change. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build and vet, go test -tags nogui -count=1 ./... under a temp HOME pass but the known TestFXInState flake. The Windows registry path is built, not run on Windows. 2026-10-03 02:38:17 +08:00
AronnaxandClaude Opus 5.5 ec4ee5a3a4 fix(proc): end what a CLI probe started, on its timeout and when magpie exits (#414)
* fix(proc): end what a CLI probe started, on its timeout and when magpie exits

The probes that ask an agent's CLI something (claude auth status,
cursor-agent about/models/status, the --version checks) ran through
proc.CommandContext, which on its timeout kills only the command itself.
A CLI that is a script (a version manager's wrapper, a shim) left what it
had started running, adopted by init; and a probe still asking when magpie
exited (a one-shot command, an update, a restart) was left whole, with
nothing to end it. With Omarchy's mise wrappers stuck in their exec loop
(omacom/omarchy#7234) that was five processes holding about half a core
each for up to six hours.

proc.ProbeContext gives such a probe a session of its own on Unix, as
StartTree does, and its context ending kills the whole group. Probes still
running are listed, and proc.EndProbes kills them when magpie exits (after
run in main) or puts a new version in its place (update.Reexec). On
Windows a probe is killed alone, as before, a job being joined only once
the command has started.

TestProbeTimeoutEndsWhatItStarted and TestEndProbes fail without the
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(proc): end probes on a terminal's signals and on a Mac's quit

Review of the first change: a probe leading its own session no longer
gets the Ctrl+C, hang-up or SIGTERM sent to magpie's terminal or service,
and magpie ending on the signal never reached EndProbes, so the probe was
left to init where before it died with magpie. main now catches SIGINT,
SIGTERM and SIGHUP, ends the probes and exits as the signal would have
(128+n). A signal magpie was started ignoring (nohup, a background job)
stays ignored. The account sign-in and plugin commands, which end
themselves on Ctrl+C, go through interruptContext and are left to do so.

On a Mac the desktop app's quit ([NSApp terminate:], also the restart to
update) exits without returning to main, so OnShutdown ends the probes.

TestProbeTimeoutEndsWhatItStarted ended its probe on a 500ms timeout,
which on a Mac could come before the script had written its child's pid
(6 of 10 runs failed in review). It now ends the context once that pid is
read, the same Cancel path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: let the app and the TUI quit on a signal their own way

Review of the signal handling: endProbesOnSignal exited ahead of Wails
and bubbletea, which quit on SIGINT and SIGTERM themselves. `magpie tray`
exited 143 without OnShutdown (no downloaded update installed, and
sessions.Saved skipped in main), and `magpie tui` left the terminal on its
alternate screen with the cursor hidden. The app's and the TUI's entry
points now hand the signals back (ownSignals): the app's OnShutdown ends
the probes, and the TUI comes back to main, which ends them too. A
one-shot command keeps the handler.

TestOwnSignalsHandsThemBack fails without the change (magpie exited 143
before the command could quit its own way); TestSignalExits keeps the
one-shot behavior.

childPid waited 3s for a script just written to start its child, which a
busy Mac can exceed (2 of 3 full runs failed in review). It waits 30s now
and, should the probe end first, says the probe's error rather than "the
script started nothing".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep SIGHUP for the app and the TUI, and die of the signal

ownSignals handed SIGHUP back along with SIGINT and SIGTERM, but neither
Wails nor bubbletea handles it: the terminal closing under the TUI or an
app started from a shell ended magpie on the spot, and its probes, in a
session of their own, out of the hang-up's reach, kept running (before
this PR they were in the terminal's group and ended with it). SIGHUP now
stays with endProbesOnSignal. A tray under a pty whose terminal closes
left 2 processes before, none now.

The handler asked whether a command was ending itself on Ctrl+C only
after EndProbes, which can take up to a second; a sign-in done in the
meantime got magpie ended in the middle of its own cleanup. It is asked
first.

It exited 128+n, which a shell takes for a child that handled the signal:
a loop running magpie went on to the next run on Ctrl+C. It now dies of
the signal (handling reset, the signal sent again); Windows, which can't
send one, still exits with the code.

agentProbe and agentCommand share withProxy; the Windows probeGroup
comment no longer says EndProbes ends what a shim started.

TestOwnSignalsKeepsHangUp and TestInterruptWhileEndingProbes fail without
the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: hand signals to the TUI and the app only once they listen

Review: runTUI handed SIGINT and SIGTERM back before tui.Run, whose
newModel asks agents' CLIs (claude auth status, up to 5s) before
bubbletea listens for signals. Ctrl+C, SIGTERM or SIGINT while it loaded
ended magpie by Go's default and left the probe and its child running.
tui.Run now takes ready, called once the model is made, and runTUI passes
ownSignals.

The app had the same window: runGUI handed them back before gui.Run,
which starts the backend (probes included) before Wails' Run starts
listening. ownSignals is now gui.Started, called on ApplicationStarted,
which Wails emits after its signal handler is set up. A tray sent SIGTERM
0.05s after starting, a probe under way, left 2 processes before and
none now; one sent it once started still quits through OnShutdown
(exit 0).

TestTUIKeepsSignalsWhileLoading fails without the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 00:42:48 +08:00
yetone 0361189f9e test: every package's tests pass on Windows, and none writes outside its sandbox (the user: 把 Windows 上那几个失败的测试修掉) — on a Windows box the suite failed in most packages, and the root package hung for 25 minutes. Tests set HOME, which os.UserHomeDir ignores on Windows (it reads USERPROFILE), so they read and wrote the runner's own home; each now sets USERPROFILE beside HOME, and Devin's, Goose's, Crush's and Claude Desktop's tests set APPDATA/LOCALAPPDATA, where those keep their files there. said() read the command's output only once it returned, and a pipe holds a few KB on Windows, so magpie model --help blocked forever; it reads while the command writes. Unix permission bits (the gateway key store's 0600 too), exec bits and symlinks Windows lacks are checked only off Windows; TOML strings hold Windows paths as literal strings, JSON as marshalled ones; a URL's path is compared as one. The provider and usage packages run in a home of their own (TestMain, as the gateway's already does), since a CLI's identity kept by a refresh still going when its test ended landed in the runner's ~/.config/magpie — and on a Mac in the user's own. Two product fixes came out of it: imagemcp took a file:///C:/… root or image for the path /C:/…, which doesn't exist on Windows, and now makes a Windows path of it (a host for a UNC share); and session discovery could keep a new Cowork session hidden on Linux, where a folder's mtime is a kernel tick and its size doesn't change, so an entry added within the tick of the last listing left both as they were — a listing made within 2s of its folder's last change is read again, as git does for racy files. TestFilePath and TestRacyDirectoryListedAgain fail without the change. On Windows 11 every package passes (32 of 32) and a run of each package in a fresh home leaves nothing in home, APPDATA or LOCALAPPDATA; on Linux (WSL) and macOS go test -tags nogui ./... passes. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build pass. 2026-10-01 23:15:07 +08:00
yetone dd12c75bff codex: a turn relayed through Codex accounts says it is the Codex client it came from, or newer, so a model Codex CLI reaches on its own is no longer refused through magpie (Discord, lantern2077 / TuskerManshu: gpt-6.1-sol through a routing group answered 400 "The 'gpt-6.1-sol' model is not supported when using Codex with a ChatGPT account" while Codex CLI alone could use it) — the ChatGPT backend serves a model only to a client new enough for it. Re-signing a pool turn, codexSign set User-Agent codex_cli_rs/<codexVersion()>, the newest of a constant 0.154.0, ~/.codex/models_cache.json's client_version (written by the Codex before the last update) and codex --version when codex was on PATH, ~/.local/bin or Homebrew's — nvm, mise, fnm, npm prefixes, pnpm and Volta were out of reach, above all in magpie serve — while the client's own version header was relayed: one turn saying two versions, the older in the User-Agent. Now codexSign writes one version in both, never older than the relayed one; the gateway notes the newest version a Codex client (originator or codex… User-Agent) has come with (SawCodexClient) and codexVersion, also asked by the accounts' model lists, takes it; the fallback is 0.159.0; the models cache is read from CODEX_HOME when set; codexExecutable also looks in proc.UserBinDirs() (every Node of nvm, mise and fnm, ~/.npmrc's prefix, pnpm, bun, Volta; %APPDATA%\npm and the like on Windows; codex.cmd/.exe there). Tested with TestCodexPoolSaysTheClientsVersion against a fake backend refusing gpt-6.1-sol below 0.161.0: Codex CLI 0.161.0 through the pool failed on main with codex_cli_rs/0.154.0 and passes; TestCodexVersionSeen (Claude Code's User-Agent ignored, CLI and Desktop versions read, never lowered, the model list asked with it), TestCodexVersion with CODEX_HOME, TestCodexExecutableOffPath (nvm, mise, an .npmrc prefix with PATH /usr/bin:/bin). go vet ./internal/..., go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass. Not tried against the real backend: the version gating is read from the error and the models cache, not seen on the wire. 2026-09-30 10:06:15 +08:00
yetone 03dbde12d0 accounts: after a Codex switch, magpie says when Codex's background service is still on the account before, and restarts it when asked (vincentzhang on Discord) — Codex CLI can keep an app-server running (codex app-server --managed-daemon) that reads the sign-in once, when it starts, so sessions opened after a switch still ran on the account before. When a switch changes the account while such a daemon runs, Codex's account list shows that it is still signed in as the one before, with Later and Restart; Restart runs codex app-server daemon restart for the Codex home magpie signs in through, which ends the Codex sessions on it, so magpie never does it unasked. magpie accounts switch codex prints the same hint and the command. The notice goes when the daemon restarts or stops, or Codex is switched back. Only a codex program's app-server with --managed-daemon counts: the ChatGPT app's codex and other apps' app-servers don't. Tested with a fake codex and a fake daemon in a sandbox magpie web; the real codex 0.155 has the restart command 2026-09-29 11:59:57 +08:00
yetone 8ad73e8bfc accounts: a slow or hanging agent CLI no longer holds the providers page (#123) — its timeout now ends the call (a CLI that is a script running node left node holding the output, and the call waited for it however long, the 10s timeouts notwithstanding: a CLI's pipes are closed 2s after); a CLI never answered before is waited for 3s, once, then served as nobody signed in until its answer comes behind; and a CLI saying nobody is signed in is kept like any answer, where before it wasn't and every start waited for it again. Tried with cursor-agent and devin hanging 20s and the network black-holed: the first providers call went from 40.6s to 6s on a first start, and to 13ms on the next 2026-09-28 11:20:14 +08:00
yetone b5340c7033 grok, cursor: a run ends with its caller — one whose client left mid-reply (Esc, /clear, Claude Code quit) is stopped at once instead of answering no one, one waiting on tool results that never come is let go after 5 minutes, not 30, and a stop kills what the CLI started too (its own session on Mac and Linux, a job on Windows). A tool that runs longer still gets its answer, from a run told the whole conversation. Runs are stopped with the gateway 2026-09-27 17:42:01 +08:00
yetone bbd7e0475d desktop app: opened from the Finder, the Dock or a login item, magpie takes up the PATH a terminal of the user's has — launchd gives it /usr/bin:/bin and nothing a shell profile adds, so a claude installed under a custom npm prefix (~/.npm-global/bin), or through nvm, bun, volta or asdf, wasn't found and its subscription couldn't be used; the folders those tools use are added at once, and the login shell's own PATH in the background 2026-09-25 17:27:34 +08:00
yetone e8b3be572c windows: the desktop app no longer opens a console window for every command it runs (#54) — it is linked as a GUI program and has no console, so each console CLI it started (devin auth status and models list, devin acp for every Devin turn, claude, codex, cursor-agent and grok probes and runs, grok login) was given a new console by Windows, and a Windows Terminal window with it, some every few seconds while the app sat idle. Every command magpie runs is now made through internal/proc, which starts it with CREATE_NO_WINDOW when magpie has no console of its own: the child gets a console without a window, and its output, which magpie always pipes back, arrives as before. A magpie run in a terminal (magpie serve, the TUI, the desktop app started from one with a command) has one, and its children share it as they did, so Ctrl+C there still reaches them. The relaunch after an update keeps its DETACHED_PROCESS, added to rather than replacing the flags it was made with, and a test fails on any command made with os/exec directly, so a new one can't bring the windows back 2026-09-25 14:04:44 +08:00