agent: on Windows Claude Code and Codex are never taken for uninstalled by their folder, so neither shows "CLI not found" with its settings hidden (#1482, edussss)
edussss (Windows 11) on 10-15: "昨天早上的版本还能找到,今天早上更新后又找不到了". Their screenshot shows both Claude Code and Codex marked "CLI not found", with no model or effort pickers. v0.1.1231 listed both. Cause:d0fcb8bcd(#2177, in v0.1.1238). It made cliHeld declare a shared folder (~/.claude, ~/.codex, ~/.cline) a leftover when neither the CLI nor a known reader is here. The known readers are editor extensions under ~/.<editor>/extensions, Claude.app, Claude Desktop, JetBrains and Zed. Before that commit a shared folder was never gone. The list was checked on a Mac only. On Windows, other programs read these folders too: a Store app, an editor run portable or with --extensions-dir, or a CLI on a PATH that only a shell profile sets (fnm). The Agents page, the TUI, `magpie ls`, Install another agent and the Library targets (all through CLIMissing) treated both of the reporter's agents as uninstalled. Fix: on Windows, cliHeld says "can't tell" for a shared folder whose CLI isn't found. A shared folder is then never gone, as before v0.1.1238, and as OpenCode and Goose already are off a Mac. A found CLI still holds it. Agents whose folder only their CLI keeps (dsh, Hermes) are still gone on Windows. The Windows-only branches in that path became unreachable and are dropped: desktopdir.Installed in the claude case, and the Windows dirs of jetBrainsHere and zedAgentsHere. goneOS lets a test judge for Windows on any host. docs/subsystems/agent-wiring.md says so. What was run: - Windows box (Windows 11 x64), sandbox USERPROFILE/APPDATA/LOCALAPPDATA holding only ~\.claude\settings.json and ~\.codex\config.toml, PATH C:\Windows\system32 (the registry PATH has the box's real ~\.local\bin\claude.exe; there is no codex on the box): - `magpie ls` at v0.1.1231 lists Codex "gpt-5 · effort". - At origin/main69d7ee33ait lists "Codex CLI not found". That is the regression. - With this fix it lists "Codex gpt-5 · effort" again. - At main, a fake openai.chatgpt extension in ~\.vscode or ~\.cursor also kept Codex listed. So the extension check works on Windows, and the reporter's reader is something cliHeld doesn't list. - agent.test.exe -test.run TestCLIMissing on the Windows box: all four pass (TestCLIMissing, Hermes, SharedFolders, SharedFoldersWindows). - Broken by hand: with the Windows branch disabled, TestCLIMissingSharedFoldersWindows goes red for claude, codex and cline. Each is taken for gone and offered again as missing. - gofmt -l clean. go vet -tags nogui passes for GOOS darwin, linux and windows. - set -o pipefail; go test -p 4 -timeout 40m ./... on macOS at base69d7ee33aplus this change: all 55 packages ok, exit 0 (internal/agent, cli, gui, library and tui among them). Not tried: the reporter's own setup. Their screenshot doesn't say what reads their folders. The reply on #1482 asks for `where.exe claude`, the install method and the magpie version.
This commit is contained in:
@@ -95,7 +95,7 @@ something else shows up as drift.
|
||||
- A plugin's agent writes each key in place (JSON, YAML or env), the user's comments and other keys kept. An object or array `connect` returns is taken as its JSON text (`agentplug.keys`), so it is written in the order the plugin gave it, not sorted as a Go map would be: Kilo lists its effort variants in key order (#1890, `TestPluggedKeepsPluginOrder`). What each key held before the first write is stashed under `plugin:<id>:<path>`, typed, and its own model or Disconnect puts every key back and takes out the ones that weren't there; the file is never written whole. A `connect` that throws or takes over a second writes nothing and says why. Its gateway key is `magpie-<id>` (`agentKeyAt`), and usage names its requests by that key or by its `ua` words (`usage.PluginAgents`). Its `agent.library` (instructions, `mcp` with `mcpFormat`, skills) gives it the Library's three as well, written by `internal/library` as any agent's are ([library](library.md)); a `mcpFormat` outside `agentplug.MCPFormats`, or an `mcp` without one, keeps the plugin from loading.
|
||||
- StepCode config root resolves to the parent of an absolute `STEP_CODING_AGENT_DIR` (agent resources directory differs from config root; relative values ignored), or `STEPCODE_CONFIG_DIR` under home when native, defaulting to `~/.stepcode` ([`stepcode.go`](../../internal/agent/stepcode.go)). Project configs override global configs in StepCode, but magpie manages global configuration only (`config.toml` and `models.json`). Detection is strictly directory-only via `agentDir`, avoiding collision with Smallstep's bare `step` command on `PATH`. Wiring performs an atomic two-file edit (`models.json` provider block and `config.toml` top-level defaults/scope) backed by `stash.json`. Custom fields within `providers.magpie` are preserved during sync, and the original provider block is restored on disconnect. A renamed provider's `magpie/<old>/` entries in `enabledModels` follow it, a glob or a thinking level included, and the scope remembered for disconnect follows too; the user's other entries stay. Disconnect restores original defaults, preserves user native changes and custom scope edits, and removes newly created files only when empty.
|
||||
- An agent is detected by its config file, its folder, or its command on magpie's PATH (`Detected`). That PATH is the login shell's plus the folders users' tools go in (`proc.UserPath`: `~/.local/bin`, npm's prefixes, the Node nvm's default alias resolves to (the highest installed when it names none), bun, Homebrew, ...), so a CLI a terminal doesn't find can still be found and listed: an npm install under a Node the terminal no longer uses. `/api/agents/cli` then gives where it is (`path`) and `offPath` when the login shell's PATH (`proc.LoginPath`) lacks its folder, and the Agents row says "Not on your terminal's PATH", its tip naming the file (悠悠哥 on Discord: Codex 0.162.1 listed with no codex on PATH and no `~/.codex`). An unknown login PATH says nothing. A folder another tool writes too doesn't count (`dirShared`): Pi's for omp, `~/.copilot` for the Copilot CLI, which GitHub Copilot's JetBrains and VS Code plugins also write, and Qoder's and Qoder CN's, which Qoder's JetBrains plugin fills. A config file another tool writes first counts only when `pathOwn` says it is the agent's: Qoder's `settings.json` holding `enabledPlugins` alone is the plugin's (`qoderPluginOnly`; #1495, `TestCopilotFolderFromAnIDEPluginIsNotTheCLI`, `TestQoderSettingsFromAnIDEPluginIsNotTheCLI`). The Qoder app (the desktop app, which runs Qoder's CLI as its agent with the same folder) is found by the `.qoder-app-status.json` it writes there (`sign`, `qoderApp`; #2138, `TestQoderAppIsQoder`), as its `settings.json` can be its bundled plugin's `enabledPlugins` alone. Only the GUI and `daemon install` widen the PATH so; `magpie serve`, `web`, `tui` and the CLI keep the one they were started with, so an agent's CLI (`cliBin`, which its version and `omp`'s max effort are read from) is looked for in those folders (`proc.FindTool`) on every system when it isn't on the PATH, not only on Windows (whqtian on Discord: omp under `~/.bun/bin` on Ubuntu read as no version and offered xhigh in place of max; `TestOmpVersionOffPath`).
|
||||
- Detection goes by an agent's folder, which an uninstall leaves behind, so an agent found by that alone is shown as gone (`CLIMissing`; #843, #2177, #2173): its CLI is on no PATH and in none of `proc.FindTool`'s folders nor where its own installer puts it (`~/.claude/local`, `~/.codex/packages/standalone`, `~/.opencode/bin`, Hermes' `hermes-agent` checkout), and nothing else that reads the folder is here (`cliHeld`): its desktop app (`HasApp`), an editor's extension (`~/.<editor>/extensions/<id>-*`: `anthropic.claude-code`, `openai.chatgpt`, `saoudrizwan.claude-dev`), Claude.app or Claude Desktop on Windows, OpenCode.app and Goose.app on a Mac, a JetBrains IDE's settings (its AI Assistant's agents and Cline's plugin) or Zed's `external_agents` (its Claude Code and Codex adapters). Where magpie can't tell (OpenCode and Goose off a Mac, Gemini, an agent detected its own way or by a command name other tools share, one with no install command but `cliOnly`'s Hermes), it is never gone. A gone row in the GUI shows "CLI not found" and none of its settings, nor Apply again; while connected it keeps its switch and Disconnect, and it folds under Not set up once not. Get started never offers it (`connectKind` is "no"). The TUI leaves it out and `magpie ls` says "CLI not found" (`TestCLIMissing*`, `agent-cli-missing.test.cjs`, `getting-started.test.cjs`).
|
||||
- Detection goes by an agent's folder, which an uninstall leaves behind, so an agent found by that alone is shown as gone (`CLIMissing`; #843, #2177, #2173): its CLI is on no PATH and in none of `proc.FindTool`'s folders nor where its own installer puts it (`~/.claude/local`, `~/.codex/packages/standalone`, `~/.opencode/bin`, Hermes' `hermes-agent` checkout), and nothing else that reads the folder is here (`cliHeld`): its desktop app (`HasApp`), an editor's extension (`~/.<editor>/extensions/<id>-*`: `anthropic.claude-code`, `openai.chatgpt`, `saoudrizwan.claude-dev`), Claude.app, OpenCode.app and Goose.app on a Mac, a JetBrains IDE's settings (its AI Assistant's agents and Cline's plugin) or Zed's `external_agents` (its Claude Code and Codex adapters). Where magpie can't tell (every shared folder, `cliShared`, on Windows, whose readers can be a Store app, a portable editor or a PATH only a shell profile sets, #1482; OpenCode and Goose off a Mac, Gemini, an agent detected its own way or by a command name other tools share, one with no install command but `cliOnly`'s Hermes), it is never gone. A gone row in the GUI shows "CLI not found" and none of its settings, nor Apply again; while connected it keeps its switch and Disconnect, and it folds under Not set up once not. Get started never offers it (`connectKind` is "no"). The TUI leaves it out and `magpie ls` says "CLI not found" (`TestCLIMissing*`, `agent-cli-missing.test.cjs`, `getting-started.test.cjs`).
|
||||
- Tests never touch the real machine. `TestMain` uses `testenv`, which points HOME, USERPROFILE, the XDG folders and APPDATA into a temporary folder, clears `agentenv.Vars` and puts failing stand-ins for keychain tools and agent CLIs on PATH. Agent-specific side effects (Aside, the Zed keychain, Codex's usage check) are also stubbed in `TestMain`.
|
||||
|
||||
## Verification
|
||||
|
||||
+15
-15
@@ -6,8 +6,6 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/desktopdir"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -26,6 +24,10 @@ import (
|
||||
// and links ~/.local/bin/hermes to it.
|
||||
var cliOnly = map[string]bool{"hermes": true}
|
||||
|
||||
// goneOS is the system cliHeld judges for; a var so a test on a Mac can
|
||||
// judge for Windows.
|
||||
var goneOS = runtime.GOOS
|
||||
|
||||
// cliHeld reports whether something here is the agent, or reads its
|
||||
// folder as the agent does, so the folder is no leftover; known is false
|
||||
// when magpie can't tell, which never counts as gone.
|
||||
@@ -71,13 +73,22 @@ func (a *Agent) cliHeld() (held, known bool) {
|
||||
if !cliShared[a.ID] {
|
||||
return false, true
|
||||
}
|
||||
// On Windows the programs that read a shared folder can't all be
|
||||
// told: a Store app, an editor run portable or with its extensions
|
||||
// moved off ~\.vscode, a CLI on a PATH only a shell profile sets (fnm).
|
||||
// Taking ~\.claude and ~\.codex for leftovers there hid both agents'
|
||||
// settings, "CLI not found", from a user whose Claude Code and Codex
|
||||
// v0.1.1231 listed (#1482, edussss). There a shared folder whose CLI
|
||||
// isn't found is never taken for gone.
|
||||
if goneOS == "windows" {
|
||||
return false, false
|
||||
}
|
||||
// the others that keep a shared folder: editors' extensions, desktop
|
||||
// apps, and the IDEs and editors whose agents bring their own copy of
|
||||
// the program
|
||||
switch a.ID {
|
||||
case "claude":
|
||||
if extensionHere(home, "anthropic.claude-code") || appHere("Claude.app") ||
|
||||
desktopdir.Installed(desktopdir.OS, home, appdir.Getenv) {
|
||||
if extensionHere(home, "anthropic.claude-code") || appHere("Claude.app") {
|
||||
return true, true
|
||||
}
|
||||
return false, !jetBrainsHere(home) && !zedAgentsHere(home)
|
||||
@@ -159,11 +170,6 @@ func jetBrainsHere(home string) bool {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
dirs = []string{filepath.Join(home, "Library", "Application Support", "JetBrains")}
|
||||
case "windows":
|
||||
if d := appdir.Getenv("APPDATA"); d != "" {
|
||||
dirs = append(dirs, filepath.Join(d, "JetBrains"))
|
||||
}
|
||||
dirs = append(dirs, filepath.Join(home, "AppData", "Roaming", "JetBrains"))
|
||||
default:
|
||||
dirs = []string{filepath.Join(home, ".config", "JetBrains"), filepath.Join(home, ".local", "share", "JetBrains")}
|
||||
}
|
||||
@@ -183,12 +189,6 @@ func zedAgentsHere(home string) bool {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
d = filepath.Join(home, "Library", "Application Support", "Zed")
|
||||
case "windows":
|
||||
local := appdir.Getenv("LOCALAPPDATA")
|
||||
if local == "" {
|
||||
local = filepath.Join(home, "AppData", "Local")
|
||||
}
|
||||
d = filepath.Join(local, "Zed")
|
||||
default:
|
||||
d = filepath.Join(home, ".local", "share", "zed")
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ func TestCLIMissing(t *testing.T) {
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("PATH", t.TempDir())
|
||||
judgeOffWindows(t)
|
||||
// no desktop app either, whatever this machine has installed
|
||||
was := appFolders
|
||||
appFolders = func() []string { return nil }
|
||||
@@ -150,6 +151,7 @@ type goneCase struct {
|
||||
}
|
||||
|
||||
func TestCLIMissingSharedFolders(t *testing.T) {
|
||||
judgeOffWindows(t)
|
||||
cases := []goneCase{
|
||||
{"claude", ".claude", nil, true},
|
||||
{"claude", ".claude", func(t *testing.T, home, _ string) {
|
||||
@@ -220,24 +222,80 @@ func TestCLIMissingSharedFolders(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// judgeOffWindows has cliHeld judge as on Linux when the tests run on
|
||||
// Windows, where a shared folder is never gone (#1482): the cases above
|
||||
// are about the systems where its readers can be told.
|
||||
func judgeOffWindows(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
judgeFor(t, "linux")
|
||||
}
|
||||
}
|
||||
|
||||
func judgeFor(t *testing.T, goos string) {
|
||||
t.Helper()
|
||||
was := goneOS
|
||||
goneOS = goos
|
||||
t.Cleanup(func() { goneOS = was })
|
||||
}
|
||||
|
||||
// #1482 (edussss, Windows 11): from v0.1.1238 Claude Code and Codex both
|
||||
// showed "CLI not found", their settings hidden, though v0.1.1231 listed
|
||||
// them and the user runs them. On Windows what reads ~\.claude and
|
||||
// ~\.codex can't all be told (a Store app, a portable editor, a PATH only
|
||||
// a shell profile sets), so a shared folder is never gone there. An agent
|
||||
// whose folder is only its CLI's still is.
|
||||
func TestCLIMissingSharedFoldersWindows(t *testing.T) {
|
||||
judgeFor(t, "windows")
|
||||
for _, c := range []struct{ id, folder string }{{"claude", ".claude"}, {"codex", ".codex"}, {"cline", ".cline"}} {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
|
||||
t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local"))
|
||||
t.Setenv("PATH", t.TempDir())
|
||||
noApps(t)
|
||||
dir := filepath.Join(home, c.folder)
|
||||
writeT(t, filepath.Join(dir, "settings.json"), "{}")
|
||||
a := &Agent{ID: c.id, Name: c.id, Bin: "magpie-test-gone-" + c.id, Dir: dir, Path: filepath.Join(dir, "settings.json")}
|
||||
if !a.Detected() {
|
||||
t.Fatalf("%s: its folder not detected", c.id)
|
||||
}
|
||||
if a.CLIMissing() {
|
||||
t.Errorf("%s: its folder alone taken for gone on Windows", c.id)
|
||||
}
|
||||
for _, x := range installsOf([]*Agent{a}, "windows", true) {
|
||||
if x.Missing {
|
||||
t.Errorf("%s offered again as gone: %+v", c.id, x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// an agent whose folder only its CLI keeps is still gone without it
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("PATH", t.TempDir())
|
||||
noApps(t)
|
||||
hdir := filepath.Join(home, ".hermes")
|
||||
writeT(t, filepath.Join(hdir, "config.yaml"), "custom_providers: []\n")
|
||||
h := &Agent{ID: "hermes", Name: "Hermes Agent", Bin: "magpie-test-gone-hermes", Dir: hdir, Path: filepath.Join(hdir, "config.yaml")}
|
||||
if !h.CLIMissing() {
|
||||
t.Fatal("hermes by its config.yaml alone not gone when judged for Windows")
|
||||
}
|
||||
}
|
||||
|
||||
// jetBrainsDirFor and zedAgentsDirFor are where jetBrainsHere and
|
||||
// zedAgentsHere look on this system.
|
||||
func jetBrainsDirFor(home string) string {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
if runtime.GOOS == "darwin" {
|
||||
return filepath.Join(home, "Library", "Application Support", "JetBrains")
|
||||
case "windows":
|
||||
return filepath.Join(home, "AppData", "Roaming", "JetBrains")
|
||||
}
|
||||
return filepath.Join(home, ".config", "JetBrains")
|
||||
}
|
||||
|
||||
func zedAgentsDirFor(home string) string {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
if runtime.GOOS == "darwin" {
|
||||
return filepath.Join(home, "Library", "Application Support", "Zed", "external_agents")
|
||||
case "windows":
|
||||
return filepath.Join(home, "AppData", "Local", "Zed", "external_agents")
|
||||
}
|
||||
return filepath.Join(home, ".local", "share", "zed", "external_agents")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user