diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 779bb8721..8f6f637fb 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -96,7 +96,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::`, 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-` (`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//` 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 (`~/./extensions/-*`: `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`). +- 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 (`~/./extensions/-*`: `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, and there too one a desktop app of the agent's reads, `desktopApps`: DeepSeek Harness Desktop installs to any folder and puts its `dsh.cmd` in one the user picks, #2300, #2304; 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 diff --git a/internal/agent/gone.go b/internal/agent/gone.go index 583517a81..703d548f7 100644 --- a/internal/agent/gone.go +++ b/internal/agent/gone.go @@ -70,19 +70,24 @@ func (a *Agent) cliHeld() (held, known bool) { return true, true } } - 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" { + // isn't found is never taken for gone. A folder an agent's desktop app + // reads is one too: DeepSeek Harness Desktop installs to any folder + // and puts its dsh.cmd in one the user picks, and taking ~\.dsh for a + // leftover hid dsh's settings from v0.1.1239 (#2300, yangkai2; #2304, + // wlj521: 未找到 CLI, no model to pick). + _, hasApp := desktopApps[a.ID] + if goneOS == "windows" && (cliShared[a.ID] || hasApp) { return false, false } + if !cliShared[a.ID] { + return false, true + } // 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 diff --git a/internal/agent/install_missing_test.go b/internal/agent/install_missing_test.go index b65cea741..3e5c7cf5f 100644 --- a/internal/agent/install_missing_test.go +++ b/internal/agent/install_missing_test.go @@ -284,6 +284,43 @@ func TestCLIMissingSharedFoldersWindows(t *testing.T) { } } +// #2300 (yangkai2, Windows) and #2304 (wlj521): from v0.1.1239 DeepSeek +// Harness showed 未找到 CLI with no model to pick. ~\.dsh is read by +// DeepSeek Harness Desktop too, which installs to any folder and puts +// its dsh.cmd in one the user picks, so on Windows a ~\.dsh whose dsh +// isn't found where magpie looks is never taken for a leftover. Judged +// for a Mac, the same folder is still gone (#843). +func TestCLIMissingDshWindows(t *testing.T) { + 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, ".dsh") + // the desktop app's profile, as it leaves it after its first start + writeT(t, filepath.Join(dir, "profiles", "desktop", "cordis.patch.yml"), dshDesktopPatch) + writeT(t, filepath.Join(dir, "profiles", "desktop", "package.json"), "{}\n") + dsh := &Agent{ID: "dsh", Name: "DeepSeek Harness", Bin: "magpie-test-gone-dsh", Dir: dir, Path: filepath.Join(dir, "profiles", "desktop", "cordis.patch.yml")} + if !dsh.Detected() { + t.Fatal("~\\.dsh not detected") + } + judgeFor(t, "windows") + if dsh.CLIMissing() { + t.Fatal("dsh taken for uninstalled on Windows, its settings hidden") + } + for _, x := range installsOf([]*Agent{dsh}, "windows", true) { + if x.Missing { + t.Fatalf("dsh offered again as gone on Windows: %+v", x) + } + } + judgeFor(t, "darwin") + if !dsh.CLIMissing() { + t.Fatal("~/.dsh with no dsh and no app not gone when judged for a Mac") + } +} + // jetBrainsDirFor and zedAgentsDirFor are where jetBrainsHere and // zedAgentsHere look on this system. func jetBrainsDirFor(home string) string {