From 43d8a5633fcfc23ccc706eca2cf10eb1b23af316 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 13 Oct 2026 14:48:17 +0800 Subject: [PATCH] =?UTF-8?q?library:=20Library=20=E2=86=92=20Instructions?= =?UTF-8?q?=20lists=20Qoder,=20Command=20Code,=20CodeBuddy=20Code=20and=20?= =?UTF-8?q?Reasonix,=20each=20at=20the=20file=20its=20source=20reads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rest of the audit after wongxy's Qwen Code report (cefdbfd4e): four more agents magpie wires read a user-wide instructions file in their own folder, and the Library gave them none. - Qoder (and Qoder CN): AGENTS.md in its folder, renamed by its settings' context.fileName as Qwen Code's is, so qwenContextFile becomes contextFile(settings, default) for both (discoverMemoryPaths, @qoder-ai/qodercli 1.1.69's bundle). - Command Code: ~/.commandcode/AGENTS.md (getUserMemoryPath, command-code 1.81.0's dist/cli.mjs). - CodeBuddy Code: CODEBUDDY.md in its folder ($CODEBUDDY_CONFIG_DIR, else ~/.codebuddy), else CODEBUDDY.mdc there, so a user's own .mdc is written into rather than hidden (MemoryLoader.loadUserMemories, @tencent-ai/codebuddy-code 2.164.0). - Reasonix: REASONIX.md, its own of the three it reads, in its state folder: $REASONIX_STATE_HOME, else [storage] state in its config.toml (~ and variables expanded), else its home (DocumentNames, MemoryUserDir, Roots.Dir and readStorageDirs, esengine/DeepSeek-Reasonix d460758e). Run: TestSiblingInstructionsMore (new) checks each target, the write with the user's text kept and Qoder's settings untouched, Qoder's context.fileName, and Reasonix's [storage] state and variable. Broken by hand six ways (Qoder's rename ignored, no Command Code line, CodeBuddy always CODEBUDDY.md, [storage] state ignored, REASONIX_STATE_HOME ignored, ~ not expanded): each FAIL. go test -tags nogui ./internal/library, gofmt -l, go vet darwin, linux (-tags nogui) and windows. Not tried with the real binaries; the Qoder, Command Code and CodeBuddy paths were read from their npm bundles, not from a run. --- internal/library/agent_skills_test.go | 60 +++++++++++++++++++++++++++ internal/library/targets.go | 55 ++++++++++++++++++++---- 2 files changed, 108 insertions(+), 7 deletions(-) diff --git a/internal/library/agent_skills_test.go b/internal/library/agent_skills_test.go index 6f99430ef..7cc69c08f 100644 --- a/internal/library/agent_skills_test.go +++ b/internal/library/agent_skills_test.go @@ -6,6 +6,8 @@ import ( "slices" "strings" "testing" + + "github.com/yetone/magpie/internal/agent" ) // Every agent on the Agents page that reads skills has a place for them in @@ -279,6 +281,64 @@ func TestSiblingInstructions(t *testing.T) { } } +// Qoder, Command Code, CodeBuddy Code and Reasonix read a user-wide +// instructions file in their own folders too: Qoder's renamed by its +// settings' context.fileName, CodeBuddy's the first of its two names there +// is, Reasonix's in its state folder wherever that is moved. +func TestSiblingInstructionsMore(t *testing.T) { + h := sandbox(t) + write(t, filepath.Join(h, ".qoder", "settings.json"), "{}") + write(t, filepath.Join(h, ".commandcode", "settings.json"), "{}") + write(t, filepath.Join(h, ".codebuddy", "settings.json"), "{}") + write(t, filepath.Join(h, ".codebuddy", "CODEBUDDY.mdc"), "# Mine\n") + want := map[string]string{ + "qoder": filepath.Join(h, ".qoder", "AGENTS.md"), + "commandcode": filepath.Join(h, ".commandcode", "AGENTS.md"), + "codebuddy": filepath.Join(h, ".codebuddy", "CODEBUDDY.mdc"), + } + for id, inst := range want { + if tg := targetByID(id); tg == nil || tg.Instructions != inst { + t.Fatalf("%s's instructions: %+v, want %s", id, tg, inst) + } + } + shared := "Use tabs." + ok(t)(SaveInstructions(InstructionsChange{Shared: &shared, Agents: []string{"qoder", "commandcode", "codebuddy"}})) + for id, inst := range want { + pre := "" + if id == "codebuddy" { + pre = "# Mine\n\n" + } + if s := read(t, inst); s != pre+blockBegin+"\nUse tabs.\n"+blockEnd+"\n" { + t.Fatalf("%s's %s:\n%s", id, filepath.Base(inst), s) + } + } + if cfg := read(t, filepath.Join(h, ".qoder", "settings.json")); cfg != "{}" { + t.Fatalf("instructions rewrote Qoder's settings: %s", cfg) + } + + // Qoder's context.fileName; Reasonix's [storage] state, then its variable + write(t, filepath.Join(h, ".qoder", "settings.json"), `{"context": {"fileName": ["QODER.md", "AGENTS.md"]}}`) + if tg := targetByID("qoder"); tg == nil || tg.Instructions != filepath.Join(h, ".qoder", "QODER.md") { + t.Fatalf("Qoder with context.fileName: %+v", tg) + } + // Reasonix Studio is found by its app alone, so its target is asked + // of the agent as magpie makes it + rx := filepath.Join(h, ".reasonix") + reasonix := &agent.Agent{ID: "reasonix", Dir: rx, Path: filepath.Join(rx, "config.toml")} + if tg := targetOf(reasonix); tg == nil || tg.Instructions != filepath.Join(rx, "REASONIX.md") { + t.Fatalf("Reasonix's instructions: %+v", tg) + } + write(t, reasonix.Path, "[storage]\nstate = \"~/rx-state\"\n") + if tg := targetOf(reasonix); tg.Instructions != filepath.Join(h, "rx-state", "REASONIX.md") { + t.Fatalf("Reasonix with [storage] state: %+v", tg) + } + st := filepath.Join(h, "rx-env-state") + t.Setenv("REASONIX_STATE_HOME", st) + if tg := targetOf(reasonix); tg.Instructions != filepath.Join(st, "REASONIX.md") { + t.Fatalf("Reasonix under REASONIX_STATE_HOME: %+v", tg) + } +} + // Grok App's independent home (Use on a custom provider) reads AGENTS.md // and skills beside agent-home/config.toml, not Grok Build's ~/.grok. func TestGrokAppInstructions(t *testing.T) { diff --git a/internal/library/targets.go b/internal/library/targets.go index f1397a0c7..c262a2341 100644 --- a/internal/library/targets.go +++ b/internal/library/targets.go @@ -14,6 +14,7 @@ import ( "github.com/yetone/magpie/internal/agentplug" "github.com/yetone/magpie/internal/appdir" "github.com/yetone/magpie/internal/desktopdir" + "github.com/yetone/magpie/internal/edit" "github.com/yetone/magpie/internal/plugin" ) @@ -288,6 +289,10 @@ func targetOf(a *agent.Agent) *Target { // (docs.qoder.com/cli/mcp-reference), beside magpie's provider t.MCP = &mcpFile{Path: a.Path, Format: fmtOmp} t.Skills = filepath.Join(a.Dir, "skills") + // and AGENTS.md in its folder before every conversation, which its + // settings' context.fileName renames as Qwen Code's does + // (discoverMemoryPaths, @qoder-ai/qodercli 1.1.69's bundle) + t.Instructions = filepath.Join(a.Dir, contextFile(a.Path, "AGENTS.md")) case "cline": // Cline's CLI reads its MCP servers from settings/ // cline_mcp_settings.json beside providers.json, or @@ -302,6 +307,9 @@ func targetOf(a *agent.Agent) *Target { // Command Code reads ~/.commandcode/mcp.json (getUserMcpConfigPath) t.MCP = &mcpFile{Path: filepath.Join(a.Dir, "mcp.json"), Format: fmtCommandCode} t.Skills = filepath.Join(a.Dir, "skills") + // and ~/.commandcode/AGENTS.md before every conversation + // (getUserMemoryPath, command-code 1.81.0's dist/cli.mjs) + t.Instructions = filepath.Join(a.Dir, "AGENTS.md") case "workbuddy", "workbuddy-ai": // WorkBuddy's own servers are mcp.json in its folder (WorkBuddy // AI's, ~/.workbuddy-ai, for the international build) @@ -326,6 +334,9 @@ func targetOf(a *agent.Agent) *Target { // are in skills/ in its folder (getHomeSkillsDir) (#1266). t.MCP = &mcpFile{Path: codebuddyMCP(a.Dir), Format: fmtClaude} t.Skills = filepath.Join(a.Dir, "skills") + // Its user-wide instructions are CODEBUDDY.md in its folder, else + // CODEBUDDY.mdc there (MemoryLoader.loadUserMemories, 2.164.0) + t.Instructions = firstThere(a.Dir, "CODEBUDDY.md", "CODEBUDDY.mdc") case "hanako", "fx": // a skills folder in the agent's own: Hanako's $HANA_HOME, fx's // ~/.fx — each said by its docs or source. No MCP servers: @@ -382,7 +393,14 @@ func targetOf(a *agent.Agent) *Target { // storage.ts, getMemoryFilePaths in memory/memoryDiscovery.ts, // getCurrentMemoryFilename in utils/memory-constants.ts, // QwenLM/qwen-code c5098a27) - t.Instructions = filepath.Join(a.Dir, qwenContextFile(a.Path)) + t.Instructions = filepath.Join(a.Dir, contextFile(a.Path, "QWEN.md")) + case "reasonix": + // Reasonix reads every one there is of REASONIX.md, AGENTS.md and + // CLAUDE.md in its state folder; REASONIX.md is its own + // (DocumentNames in internal/state/instruction/resolver.go, + // MemoryUserDir in internal/contract/config/paths.go, esengine/ + // DeepSeek-Reasonix d460758e) + t.Instructions = filepath.Join(reasonixState(a), "REASONIX.md") case "zed": // Zed reads its MCP servers from context_servers in the settings.json // magpie sets its model in (~/.config/zed, $XDG_CONFIG_HOME/zed, @@ -427,11 +445,12 @@ func firstThere(dir string, names ...string) string { return filepath.Join(dir, names[0]) } -// qwenContextFile is the name of the file Qwen Code reads its user-wide -// instructions from: the first of its settings' context.fileName, a name -// or a list of them, else QWEN.md (packages/cli/src/config/config.ts sets -// it with setMemoryFilename, which trims each name and skips an empty one). -func qwenContextFile(settings string) string { +// contextFile is the name of the file Qwen Code, or Qoder, reads its +// user-wide instructions from: the first of its settings' context.fileName, +// a name or a list of them, else def (Qwen's packages/cli/src/config/ +// config.ts sets it with setMemoryFilename, which trims each name and skips +// an empty one). +func contextFile(settings, def string) string { raw, _ := os.ReadFile(settings) v := gjson.GetBytes(jsonc.ToJSON(raw), "context.fileName") names := []gjson.Result{v} @@ -443,7 +462,29 @@ func qwenContextFile(settings string) string { return name } } - return "QWEN.md" + return def +} + +// reasonixState is Reasonix's state folder: $REASONIX_STATE_HOME, else +// [storage] state in its config.toml, else its home (Roots.Dir in +// internal/contract/config/storage_roots.go, readStorageDirs in +// storage_config.go). +func reasonixState(a *agent.Agent) string { + d := appdir.Getenv("REASONIX_STATE_HOME") + if strings.TrimSpace(d) == "" { + st, _ := edit.GetTOMLTable(a.Path, "storage") + d = st["state"] + } + if d = strings.TrimSpace(os.ExpandEnv(d)); d == "" { + return a.Dir + } + if d == "~" || strings.HasPrefix(d, "~/") || strings.HasPrefix(d, `~\`) { + d = filepath.Join(home(), strings.TrimLeft(d[1:], `/\`)) + } + if abs, err := filepath.Abs(d); err == nil { + d = abs + } + return d } // pluginMCP is each MCP format an agent plugin may name