hermes: every bot still on magpie's model follows the model magpie sets (tjhhhh_84378)

Hermes copies the launch profile's model block into a new profile
(hermes_cli/profiles.py _seed_model_config, or --clone's config.yaml) and
never reads the main config again. magpie put its provider into each
profile but left each profile's model alone, so after a model change in
magpie every other bot (profile) still opened on the model magpie had set
when it was made (tjhhhh_84378 on Discord, with the Hermes gateway closed).

Now picking a magpie model for Hermes also moves each other profile whose
model.provider is magpie and whose model.default (or model.model, which
Hermes reads with default unset) is the model magpie had set onto the new
one (hermesFollow). "The model magpie had set" is recorded in stash.json
(hermes:<path>:magpie.default); for a config connected before the record,
it is the connected config's own magpie model. A profile on any other
model, magpie's or its own, was set by its user and is left alone, also
when it is on a model magpie used before. Disconnect forgets the record.
A profile made after the change is seeded from the current config, so it
starts on the new model already. RenameProvider goes through the same
field Set, so a renamed provider moves the following bots too.

Test: TestHermesProfilesFollowMagpieModel (internal/agent): a seeded bot
and a model.model bot follow pro -> flash (no record yet) and, through an
own model on the main config in between, -> max; a bot on magpie's
deepseek/lite and a bot on its own provider stay; a bot its user moved
back to the previous magpie model stays. On the old hermes.go it fails:
  hermes_test.go:613: flash: writer is on magpie/deepseek/pro, want magpie/deepseek/flash

Run:
- gofmt -l internal/agent: clean. go vet ./internal/agent on darwin,
  GOOS=linux -tags nogui and GOOS=windows: ok, at this commit (rebased
  onto origin/main 689cf4142; nothing under internal/agent changed in the
  rebase).
- go test -tags nogui -count=1 -run Hermes ./internal/agent at this
  commit: ok (33.6s). Whole ./internal/agent before the rebase: ok (307s).
- Full suite, go test -tags nogui ./... -timeout 45m -count=1, sandbox
  HOME, at a57d2460b (this change on 88ac42843): every package ok except
  two reds already filed on main, in packages this doesn't touch:
  internal/gui TestRestartHandsTheGatewayOver ("11 of 12 requests during
  the restart answered", #3451) and internal/provider's synctest crash in
  filememo.Forget from TestUnreadLoginsWriteErrorsKeepCredentials (#3632).
- Broken by hand: hermesFollow's call removed, the test goes red at
  hermes_test.go:613 as above.

Not tried: the real hermes binary (under a temp HERMES_HOME it rewrites
the live launcher); its seeding was read in hermes_cli/profiles.py.
This commit is contained in:
yetone
2026-10-26 17:48:30 +08:00
parent a5ce158e54
commit a6c808b688
3 changed files with 131 additions and 2 deletions
+1
View File
@@ -49,6 +49,7 @@ something else shows up as drift.
- Qoder's `providers.magpie` keeps `routing`, the timeouts, `type`, `authType`, `anthropic` and a non-empty `displayName` (`qoderKept`).
- fx keeps `reviewer_model` and a `tool_choice_mode` of `omit`. Its `auth` is magpie's whole, since fx refuses an `env` beside `type: none` (`fxKept`).
- Hermes keeps the `default_model` that `hermes model` writes there, `key_cmd`, the timeouts, `extra_body`, a name and headers beside magpie's (`hermesKept`). This holds in every profile.
- 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:<path>: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).
- 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`).
+47 -2
View File
@@ -20,7 +20,10 @@ package agent
// into every profile's too, so magpie is offered in every bot's picker, not
// the main one's alone (lijiho96940561 on X). A profile's own model and
// provider are left as its user set them, and Disconnect takes the provider
// out of each.
// out of each. A profile still on the model magpie last set in the
// connected config (one Hermes seeded or cloned from it) follows the next
// one magpie sets there (hermesFollow; tjhhhh_84378 on Discord: another
// bot kept the old model).
import (
"errors"
@@ -57,6 +60,9 @@ func hermesIn(at place) *Agent {
return errors.Join(errs...)
}
key := "hermes:" + path + ":"
// setKey holds the model magpie last set in the connected config,
// which the profiles still on it follow
setKey := key + "magpie.default"
getKey := func(k string) string { v, _ := edit.GetYAML(path, k); return v }
onMagpie := func() bool { return getKey("model.provider") == magpieID }
// joined: magpie's provider is in providers, though the model is one of
@@ -108,6 +114,7 @@ func hermesIn(at place) *Agent {
if joined() {
errs = append(errs, edit.DelYAML(path, "providers."+magpieID))
}
forget(setKey)
for _, p := range hermesOthers(at, dir) {
errs = append(errs, hermesUnwireProfile(p))
}
@@ -155,6 +162,12 @@ func hermesIn(at place) *Agent {
return edit.DelYAML(path, "model.default")
}
if ref, ok := strings.CutPrefix(v, magpieID+"/"); ok && isMagpie(ref) {
// the model magpie had set: recorded, or, before the
// record was kept, the one the config is on through magpie
was := stashLoad()[setKey]
if was == "" && onMagpie() {
was = getKey("model.default")
}
if !onMagpie() {
stash(map[string]string{
key + "model.provider": getKey("model.provider"),
@@ -168,7 +181,8 @@ func hermesIn(at place) *Agent {
); err != nil {
return err
}
return spread()
stash(map[string]string{setKey: ref})
return errors.Join(spread(), hermesFollow(at, dir, was, ref))
}
if onMagpie() {
if err := restore(); err != nil {
@@ -255,6 +269,37 @@ func hermesOthers(at place, dir string) []string {
return out
}
// hermesFollow moves every profile but the one at dir that is on magpie's
// model was, the one magpie had set in the connected config, onto ref, the
// one it sets now. Hermes gives a new profile a copy of the launch
// profile's model (_seed_model_config, or --clone's config.yaml) and never
// reads it again, so without this each bot stayed on the model magpie set
// when it was made. A profile on another model, magpie's or its own, was
// set there by its user and is left alone.
func hermesFollow(at place, dir, was, ref string) error {
if was == "" || was == ref {
return nil
}
var errs []error
for _, p := range hermesOthers(at, dir) {
if v, _ := edit.GetYAML(p, "model.provider"); v != magpieID {
continue
}
k := "model.default"
v, _ := edit.GetYAML(p, k)
if v == "" {
// Hermes reads model.model when default is unset
// (_read_config_model)
k = "model.model"
v, _ = edit.GetYAML(p, k)
}
if v == was {
errs = append(errs, edit.SetYAML(p, edit.KV{Path: k, Value: ref}))
}
}
return errors.Join(errs...)
}
// hermesUnwireProfile takes magpie's provider out of a profile's config. A
// profile whose model is on magpie (one cloned from a connected main
// config, or picked in that bot) would be left naming a provider that is
+83
View File
@@ -558,3 +558,86 @@ func TestKeyHoldsTakesAGatewayKey(t *testing.T) {
t.Fatalf("wiringOff: %s", d)
}
}
// A bot Hermes seeded or cloned from the connected config holds a copy of
// the model magpie set there and never reads the main config again: it
// follows the next model magpie sets, while a bot on a model its user
// picked keeps it (tjhhhh_84378 on Discord: another profile still showed
// the old model).
func TestHermesProfilesFollowMagpieModel(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"))
if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash", "max", "lite"}}); err != nil {
t.Fatal(err)
}
root := appdir.HermesHomeIn(home)
write := func(rel, s string) string {
p := filepath.Join(root, rel)
os.MkdirAll(filepath.Dir(p), 0o755)
os.WriteFile(p, []byte(s), 0o644)
return p
}
model := func(p string) (string, string) {
var c struct {
Model struct{ Default, Model, Provider string }
}
b, _ := os.ReadFile(p)
yaml.Unmarshal(b, &c)
return c.Model.Default + c.Model.Model, c.Model.Provider
}
// connected before magpie kept a record of the model it set
write("config.yaml", "model:\n default: deepseek/pro\n provider: magpie\n")
// seeded by `hermes profile create` from that config
seeded := write("profiles/writer/config.yaml", "# writer bot\nmodel:\n default: deepseek/pro\n provider: magpie\n")
// a model its user picked in that bot, magpie's or its own
picked := write("profiles/coder/config.yaml", "model:\n default: deepseek/lite\n provider: magpie\n")
own := write("profiles/chat/config.yaml", "model:\n default: deepseek/pro\n provider: deepseek\n")
// model.model, which Hermes reads with default unset
old := write("profiles/old/config.yaml", "model:\n model: deepseek/pro\n provider: magpie\n")
a := hermes(home)
if err := a.Apply("model", "magpie/deepseek/flash"); err != nil {
t.Fatal(err)
}
check := func(when, p, want, wantProv string) {
t.Helper()
if m, prov := model(p); m != want || prov != wantProv {
b, _ := os.ReadFile(p)
t.Fatalf("%s: %s is on %s/%s, want %s/%s:\n%s", when, filepath.Base(filepath.Dir(p)), prov, m, wantProv, want, b)
}
}
check("flash", seeded, "deepseek/flash", "magpie")
check("flash", old, "deepseek/flash", "magpie")
check("flash", picked, "deepseek/lite", "magpie")
check("flash", own, "deepseek/pro", "deepseek")
if b, _ := os.ReadFile(seeded); !strings.Contains(string(b), "# writer bot") {
t.Fatalf("writer lost its comment:\n%s", b)
}
// the connected config on a model of its own between: the bots on
// magpie's last model still follow the next one magpie sets
if err := a.Apply("model", "moonshotai/kimi-k3"); err != nil {
t.Fatal(err)
}
check("own", seeded, "deepseek/flash", "magpie")
if err := a.Apply("model", "magpie/deepseek/max"); err != nil {
t.Fatal(err)
}
check("max", seeded, "deepseek/max", "magpie")
check("max", old, "deepseek/max", "magpie")
check("max", picked, "deepseek/lite", "magpie")
check("max", own, "deepseek/pro", "deepseek")
// a bot whose user moves it off magpie's model, onto the one magpie
// had before, keeps it
edit.SetYAML(seeded, edit.KV{Path: "model.default", Value: "deepseek/flash"})
if err := a.Apply("model", "magpie/deepseek/pro"); err != nil {
t.Fatal(err)
}
check("pro", seeded, "deepseek/flash", "magpie")
check("pro", old, "deepseek/pro", "magpie")
}