diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 7bea1752a..f93fda3cf 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -74,8 +74,8 @@ something else shows up as drift. - Hermes copies the launch profile's model into a new profile (`_seed_model_config`, or `--clone`'s `config.yaml`) and never reads it again. A model picked in magpie moves every other profile still on `magpie` with the model magpie had set (recorded in `stash.json` as `hermes::magpie.default`, or the connected config's model before that record) onto the new one; a profile on any other model was set by its user and stays (`hermesFollow` in [`hermes.go`](../../internal/agent/hermes.go); tjhhhh_84378 on Discord). - The config magpie connects is the profile `hermes` starts in: `HERMES_HOME` when it names a profile, else the one `hermes profile use` made sticky in `/active_profile` (a live profile folder; `hermes model` writes the same one), else `HERMES_HOME` or the default folder (`hermesActive`; `_apply_profile_override` in Hermes's `hermes_cli/main.py`). The root's config is then one more profile. A bot on the model the connected config is on through magpie follows too, besides one on the recorded model (`hermes model` there before the bot was made). - Disconnect moves a profile on magpie onto its own model from when magpie connected it, else the connected config's own model (with that provider's `providers` entry when the profile lacks it, as Hermes's `launch_model_seed` does); with neither, its model goes. What it was on is kept (`hermes::off`), and connecting again puts it back when nothing has changed it, and gives a profile with no model at all magpie's (`hermesBack`). The recorded model stays through Disconnect. Before, Off emptied every such profile and `hermes` there failed at start after Off and On (tjhhhh on Discord, `TestHermesOffAndOnKeepsEveryBotsModel`, `TestHermesStickyProfile`). - - With more than one profile, each profile other than the connected one has a field of its own, `profile:` (`default` for the root), kept in the API but drawn nowhere on the connected row (`hermesProfileFields`; `hermesBot` in app.js hides it): the profile's own row `hermes#`, below, is where its model is picked, so two controls never set one profile (dongshanfengdongshizhcn on Discord; Norethcy on X). A magpie model puts magpie's provider into that profile and stashes its own provider and model first; a model of its own is written as `model.default` and gives back the stashed provider. Default puts back the profile's model from before magpie, or keeps the one it has: Disconnect sends the same empty value. A bot picked there is recorded (`hermes::picked`) and doesn't follow the connected config's next model, and a sync keeps magpie's provider current in a bot on magpie while the connected config isn't (`TestHermesProfileModels`, `hermes-profiles.test.cjs`). - - Each profile other than the connected one is also an agent row of its own, `hermes#` (`hermesProfileAgents`, named `Hermes · `; `default` for the root when a named profile is connected), the way omp's are `omp#`: its one field, `model`, is the same pick as the connected row's `profile:`, and the Library gives it skills and MCP servers apart from the other profiles, since Hermes reads `skills/` and `mcp_servers` from each profile's own home (`targetOf` in `internal/library/targets.go`; Norethcy on X). None is listed while Hermes itself is gone (`CLIMissing`). + - With more than one profile, each profile other than the connected one has a field of its own, `profile:` (`default` for the root), kept in the API but drawn nowhere on the connected row (`hermesProfileFields`; `hermesBot` in app.js hides it): the profile has no row in the Agents list either (below), so Hermes is one entry and a profile's model is whatever it holds or follows from the connected config (dongshanfengdongshizhcn on Discord; geekbb on X). A magpie model puts magpie's provider into that profile and stashes its own provider and model first; a model of its own is written as `model.default` and gives back the stashed provider. Default puts back the profile's model from before magpie, or keeps the one it has: Disconnect sends the same empty value. A bot picked there is recorded (`hermes::picked`) and doesn't follow the connected config's next model, and a sync keeps magpie's provider current in a bot on magpie while the connected config isn't (`TestHermesProfileModels`, `hermes-profiles.test.cjs`). + - Each profile other than the connected one is also an agent of its own, `hermes#`, marked `Nested`: no list or picker shows it (`DetectedIn`, `ClientsIn` leave it out; geekbb on X: one Hermes entry, not a row and a model pick per bot), while `All` and `Find` still reach it for the Library. A model a user set on a profile, here or in Hermes, stays in its config.yaml and is not touched (`TestHermesProfilesAreNotListedAsAgents`). The agent is `hermesProfileAgents`, named `Hermes · `; `default` for the root when a named profile is connected), the way omp's are `omp#`: its one field, `model`, is the same pick as `profile:`, and the Library gives it skills and MCP servers apart from the other profiles, since Hermes reads `skills/` and `mcp_servers` from each profile's own home (`targetOf` in `internal/library/targets.go`; Norethcy on X). None is listed while Hermes itself is gone (`CLIMissing`). - Hermes's `api_key` may be a reference, `${VAR}` or `${env:VAR}`, which Hermes expands from the `.env` beside the config (its own or a profile's) and then the environment. `Check` and a sync read the key it names (`hermesKey`): one that holds (`keyHolds`) stays and isn't drift, and so does one naming a variable magpie can't see (only a shell profile sets it), which is unknown. One naming a key the gateway doesn't take is drift, and a sync keeps the reference and writes magpie's key into that `.env` under the variable, made `0600` when there is none (`hermesKeptKey`; PaulT on Discord, `TestHermesWithAKeyInItsEnvFile`). A value with more than the one reference in it is replaced by magpie's key, as before. - omp's `models.yml` keeps `modelOverrides`, `discovery`, `disableStrictTools`, headers and compat flags (`ompKept`). Its `auth` and `apiKey` are magpie's, or gone. - Kimi Code's `[providers.magpie]` has magpie's three keys set in place, so `custom_headers`, `env` and `default_model` stay (`kimiProvider`). diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 7a856bee9..d0457e9ff 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -153,6 +153,11 @@ type Agent struct { // the name alone (Empryo, Cursor Private Inference). The setting says // so for each one connected, rather than seeming to do nothing. NoNames bool + // Nested: the agent is a part of another one (a Hermes profile, + // hermes#) that the Library gives its own skills and servers. No + // list of agents or model picker shows it (DetectedIn leaves it out); its + // model is a line of the parent's row, and All and Find still reach it. + Nested bool // Sync, for an agent that reads magpie's models from a file of its own // rather than asking the gateway, rewrites that list as the catalog is // now — where magpie wrote one; nothing else changes (see SyncCatalog). @@ -652,7 +657,7 @@ func Detected() []*Agent { return DetectedIn(All()) } func DetectedIn(all []*Agent) []*Agent { var out []*Agent for _, a := range all { - if a.Detected() { + if a.Detected() && !a.Nested { out = append(out, a) } } diff --git a/internal/agent/agents.go b/internal/agent/agents.go index 3cb90f6e3..bdb08fc68 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -211,7 +211,7 @@ func ClientsIn(all []*Agent) []*Agent { var out []*Agent for _, a := range all { // a WSL agent's requests are its Windows twin's by their UA - if a.WSL == "" { + if a.WSL == "" && !a.Nested { out = append(out, a) } } diff --git a/internal/agent/hermes.go b/internal/agent/hermes.go index 717625e69..e390a45f5 100644 --- a/internal/agent/hermes.go +++ b/internal/agent/hermes.go @@ -477,7 +477,7 @@ func hermesProfileAgents(home string) []*Agent { dir := filepath.Dir(p) out = append(out, &Agent{ ID: "hermes#" + name, Name: "Hermes · " + hermesProfileLabel(p, name), Icon: "hermes", - Spelled: prefixed, NoNames: true, + Spelled: prefixed, NoNames: true, Nested: true, Dir: dir, Path: p, Fields: []Field{func() Field { f := hermesProfileField(at, p, "model", "model") diff --git a/internal/agent/hermes_test.go b/internal/agent/hermes_test.go index 1b1291272..6153495a4 100644 --- a/internal/agent/hermes_test.go +++ b/internal/agent/hermes_test.go @@ -1109,3 +1109,53 @@ func TestHermesProfileRowsReadAsNames(t *testing.T) { } } } + +// geekbb on X: Hermes is one entry in the Agents list and the model +// pickers; its profiles (hermes#) are the Library's targets only, so +// no list that DetectedIn or ClientsIn builds shows them, while All and Find +// still reach one by its id. +func TestHermesProfilesAreNotListedAsAgents(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("HERMES_HOME", "") + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + root := appdir.HermesHomeIn(home) + write := func(rel, s string) { + p := filepath.Join(root, rel) + os.MkdirAll(filepath.Dir(p), 0o755) + os.WriteFile(p, []byte(s), 0o644) + } + write("config.yaml", "model:\n default: a/b\n provider: openrouter\n") + write("hermes-agent/run_agent.py", "") + write("profiles/coder/config.yaml", "model:\n default: kimi-k3\n provider: moonshot\n") + all := onMachine(home, filepath.Join(home, ".config")) + if a := FindByID(all, "hermes#coder"); a == nil || !a.Nested { + t.Fatalf("the profile is no agent for the Library: %+v", a) + } + for name, list := range map[string][]*Agent{"DetectedIn": DetectedIn(all), "ClientsIn": ClientsIn(all)} { + var hermes []string + for _, a := range list { + if strings.HasPrefix(a.ID, "hermes") { + hermes = append(hermes, a.ID) + } + } + if name == "DetectedIn" && !slices.Equal(hermes, []string{"hermes"}) || strings.HasPrefix(name, "C") && slices.Contains(hermes, "hermes#coder") { + t.Fatalf("%s lists %v", name, hermes) + } + } + // the profile's own model stays as its user set it + if b, _ := os.ReadFile(filepath.Join(root, "profiles/coder/config.yaml")); !strings.Contains(string(b), "kimi-k3") { + t.Fatalf("profile config: %s", b) + } +} + +func FindByID(all []*Agent, id string) *Agent { + for _, a := range all { + if a.ID == id { + return a + } + } + return nil +} diff --git a/internal/gui/tests/hermes-profile-row.test.cjs b/internal/gui/tests/hermes-profile-row.test.cjs index 26e459d58..cd10760d5 100644 --- a/internal/gui/tests/hermes-profile-row.test.cjs +++ b/internal/gui/tests/hermes-profile-row.test.cjs @@ -1,7 +1,6 @@ // Run with Node's test runner and Playwright on the module path; see README.md. -// Hermes's other profiles are agents of their own (hermes#, Norethcy on -// X) so the Library can give each its skills and MCP servers. The row is -// named for the profile, says it starts on the model picked here as the +// Hermes is one row in the Agents list (geekbb on X); its other profiles +// (hermes#) are the Library's, never rows here. The row says it starts on the model picked here as the // Hermes row does, and the picker posts the encoded id (a raw # would be // the URL's fragment). In every language, in both engines. No backend: the // API is faked here. @@ -23,7 +22,6 @@ const hermes = (id, bots) => ({ const fresh = () => ({ agents: [ { id: "hermes", name: "Hermes Agent", path: "/test/.hermes/config.yaml", icon: "hermes", wired: true, fields: [{ key: "model", label: "model", value: "magpie/v/glm", options: models }] }, - { id: "hermes#coder", name: "Hermes · coder", path: "/test/.hermes/profiles/coder/config.yaml", icon: "hermes", wired: true, fields: [{ key: "model", label: "model", value: "magpie/v/glm", options: models }] }, ], profiles: [], }); @@ -64,7 +62,7 @@ const W = { for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { for (const lang of Object.keys(W)) { - test(`${engine} ${lang}: a Hermes profile is a row of its own`, async (t) => { + test(`${engine} ${lang}: Hermes is one row, its profiles are none`, async (t) => { const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); const page = await browser.newPage({ viewport: { width: 560, height: 800 } }); page.setDefaultTimeout(5000); @@ -74,9 +72,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.route("**/*", server(lang, sets)); t.after(() => browser.close()); await page.goto("http://magpie.test/"); - const row = '.row.agent[data-id="hermes#coder"]'; + const row = '.row.agent[data-id="hermes"]'; await page.locator(row).waitFor(); - assert.ok((await page.locator(row).innerText()).includes("Hermes · coder")); + // geekbb on X: one entry for Hermes; its bots (profiles) are not rows + assert.equal(await page.locator('.row.agent[data-id^="hermes"]').count(), 1); + assert.ok(!(await page.locator("#agents, body").first().innerText()).includes("Hermes · ")); assert.ok((await page.locator(row).innerText()).includes(W[lang]), await page.locator(row).innerText()); assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "the Agents view overflows"); assert.deepEqual(errors, []);