agent: the Qoder app counts as Qoder again, found by the status file it writes to ~/.qoder (#2138, xiaozicoder)

xiaozicoder's Windows 11 has the Qoder app and the Qoder CN app
(Qoder-win-x64-user.exe, Qoder-CN-win-x64-user.exe from qoder.com and
qoder.cn) and no qodercli, and since v0.1.1220 magpie's Agents page lists
no Qoder at all. Qoder-win-x64-user.exe is the Qoder app (com.qoder.app,
qoder-app/releases/latest.yml at 0.4.7), not the Qoder IDE. Its app.asar
runs Qoder's CLI as its agent (qodercli 1.1.64's worker runtime, config dir
.qoder / .qoder-cn, QODER_CONFIG_DIR, with BYOK config management), so
~/.qoder/settings.json's providers.magpie reaches it. It writes the
enabledPlugins of its bundled qoder-context plugin to settings.json, which
alone stopped counting in the same change, so the app's Qoder was lost.

The app also writes .qoder-app-status.json (-canary-, -dev- for its other
channels) into ~/.qoder, or ~/.qoder-cn for the China product (the map is
in its app.asar; this Mac's Qoder.app 0.4.3 wrote one). Agent gets sign, one
more sign the agent is here for a dirShared folder, and Qoder's (both
builds) is that file. The JetBrains plugin's folder of #1495 has none, so it
still isn't Qoder.

Run: TestQoderAppIsQoder (both builds: plugin-only settings.json not
detected; each of the three status files detected; the status file with no
settings.json detected; a folder of that name not) red on the old code
(Qoder CN subtests fail), green now; TestQoderSettingsFromAnIDEPluginIsNotTheCLI
still green; go test ./internal/agent -count=1 -timeout 45m ok (1576s, the
machine at load ~350; a first run hit the default 10m package timeout mid
TestCodexAgentsV1WarnsWhenCodexOwnV2IsOn at 1s, not a hang). gofmt -l
clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows clean. A
nogui build's `magpie ls` in a sandbox HOME (PATH=/usr/bin:/bin) with
~/.qoder holding the plugin-only settings.json and a copy of this Mac's real
.qoder-app-status.json, and ~/.qoder-cn the same with a qoder-cn status,
lists Qoder and Qoder CN.
Not tried: the Qoder app on Windows itself, and whether its agent takes
magpie's provider from settings.json in practice (would need a live
~/.qoder changed).
This commit is contained in:
yetone
2026-10-14 18:21:44 +08:00
parent 6d19988416
commit b75e21be31
4 changed files with 70 additions and 1 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ something else shows up as drift.
- Tuned settings are written only on the user's click, never by Sync or Connect. The value there before is stashed once (`tune.<agent>.<knob>[.<model>]` in `stash.json`), so Undo puts it back, or takes the key out (and a `modelSettings` entry left empty). A value the user changed after the click is theirs: Undo then only forgets the stash. A variable that comes before the setting (`CLAUDE_CODE_AUTO_COMPACT_WINDOW`, `FORCE_PROMPT_CACHING_5M`, `CLAUDE_CODE_PROMPT_CACHE_TTL`, `CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL`, in settings.json's `env` or magpie's own) is shown as `locked` and Apply refuses, since the setting would change nothing. Claude Code compacts at the smaller of the window set and the model's own (its `/autocompact` says "capped to 200k by model"), so advice starts from that, and a model that isn't Claude's has no window here (magpie's own compact wiring serves it). Advice changes a value only when the replay saves 3% or more, and of the windows within 1% of the cheapest takes the largest. Tokens are weighed as billed: cache reads 0.1, 5-minute writes 1.25, hour writes 2, output 5 for Claude; reads 0.1, writes 1, output 8 otherwise.
- 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`). 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`).
- 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`).
- 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
+7
View File
@@ -275,6 +275,10 @@ type Agent struct {
// not one another tool wrote there first: a JetBrains plugin's
// settings.json in Qoder CN's folder (#1495).
pathOwn func() bool
// sign, when set, is one more sign the agent is here, for a folder
// that is dirShared: a file only the agent (or its own app) writes
// there (the Qoder app's status file, #2138).
sign func() bool
}
// Running reports whether a process whose command line matches any pattern
@@ -315,6 +319,9 @@ func (a *Agent) Detected() bool {
if a.Dir != "" && !a.dirShared && agentDir(a.Dir) {
return true
}
if a.sign != nil && a.sign() {
return true
}
if a.Bin != "" && binAt(a.Bin) != "" {
return true
}
+43
View File
@@ -88,3 +88,46 @@ func TestQoderSettingsFromAnIDEPluginIsNotTheCLI(t *testing.T) {
})
}
}
// xiaozicoder's Windows has the Qoder app and the Qoder CN app
// (Qoder-win-x64-user.exe, Qoder-CN-win-x64-user.exe) and no qodercli
// (#2138). The app runs Qoder's CLI as its agent with ~/.qoder (~/.qoder-cn),
// writes .qoder-app-status.json there, and its settings.json may hold only
// the enabledPlugins of its bundled plugin: Qoder is there, and magpie's
// provider reaches it. The JetBrains plugin's folder (#1495) has no status
// file and still isn't Qoder.
func TestQoderAppIsQoder(t *testing.T) {
t.Setenv("PATH", t.TempDir())
t.Setenv("QODER_CONFIG_DIR", "")
t.Setenv("QODERCN_CONFIG_DIR", "")
for _, mk := range []func(string) *Agent{qoder, qoderCN} {
home := t.TempDir()
a := mk(home)
t.Run(a.ID, func(t *testing.T) {
writeAt(t, a.Path, `{"enabledPlugins":{"qoder-context@qoderapp-bundler":true}}`)
if mk(home).Detected() {
t.Fatalf("%s with a plugin's settings.json alone is taken for %s", a.Dir, a.Name)
}
for _, f := range []string{".qoder-app-status.json", ".qoder-app-canary-status.json", ".qoder-app-dev-status.json"} {
st := filepath.Join(a.Dir, f)
writeAt(t, st, `{"logged_in":true,"version":"0.4.7","schema_version":1,"product":"`+a.ID+`","writer":"main"}`)
if !mk(home).Detected() {
t.Errorf("the Qoder app's %s doesn't find %s", f, a.Name)
}
os.Remove(st)
}
// the app's folder before it wrote a settings.json at all
os.Remove(a.Path)
writeAt(t, filepath.Join(a.Dir, ".qoder-app-status.json"), `{}`)
if !mk(home).Detected() {
t.Errorf("the Qoder app's status file with no settings.json doesn't find %s", a.Name)
}
// a folder of that name is not the app's file
os.Remove(filepath.Join(a.Dir, ".qoder-app-status.json"))
os.MkdirAll(filepath.Join(a.Dir, ".qoder-app-status.json"), 0o755)
if mk(home).Detected() {
t.Errorf("a folder named .qoder-app-status.json is taken for %s", a.Name)
}
})
}
}
+19
View File
@@ -124,8 +124,14 @@ func qoderAt(at place, b qoderBuild) *Agent {
// the same folder, and writes a settings.json of enabledPlugins
// alone, with no CLI installed (#1495): neither is a sign of the
// CLI. Its command, or a settings.json with any other key, is.
// The Qoder app (Qoder-win-x64-user.exe, Qoder.app, not the IDE)
// runs the CLI as its agent with the same folder, so magpie's
// provider reaches it too; its settings.json can hold only
// enabledPlugins (its bundled qoder-context plugin), and its status
// file says it is there (#2138).
dirShared: true,
pathOwn: func() bool { return !qoderPluginOnly(path) },
sign: func() bool { return qoderApp(dir) },
Sync: func() error {
ref, ok := cutMagpie(get("model.name"))
if !ok {
@@ -328,6 +334,19 @@ func qoderKeyed(key, agent string) bool {
// what Qoder's builds say after a change (notice.go)
var noticeQoder = newNotice("{agent} reads its settings as a session starts — open sessions keep the model they have; new ones use this.")
// qoderApp reports whether the Qoder app keeps its status in dir: it
// writes .qoder-app-status.json (-canary-, -dev- for its other channels)
// into ~/.qoder, or ~/.qoder-cn for the China build, as it signs in, and
// runs Qoder's CLI as its agent with that folder's settings.
func qoderApp(dir string) bool {
for _, f := range []string{".qoder-app-status.json", ".qoder-app-canary-status.json", ".qoder-app-dev-status.json"} {
if fi, err := os.Stat(filepath.Join(dir, f)); err == nil && fi.Mode().IsRegular() {
return true
}
}
return false
}
// qoderPluginOnly reports whether the settings file at path is the one
// Qoder's JetBrains plugin writes, an object holding enabledPlugins and
// nothing else. A file that can't be read or parsed isn't known to be