hermes: each profile picks its own model on the Agents page

dongshanfengdongshizhcn on Discord: "我的 hermes 有多个 profile,但现在
agent 的配置里面,似乎只能配置默认的 profile". magpie gave Hermes one model
picker, for the connected profile's config.yaml. A bot under
<root>/profiles/<name> could only follow it or keep its own model.

Hermes's layout comes from its own source (hermes-agent e5ea5fd9,
hermes_cli/profiles.py and main.py): named profiles live in
<root>/profiles/<name> (PROFILE_ID_RE, a .deleted tombstone, the identity
files), active_profile is the sticky one, "default" is the root, and a
profile's model is model.default/model.model under model.provider. magpie
already found these profiles (hermesProfiles/hermesOthers).

Now each profile other than the connected one has a field,
"profile:<name>" (hermesProfileFields). The opened Hermes row draws them as
Other profiles, one line per profile: its name, the app's model picker, and
`hermes -p <name>`. They are never a square of the row's own, and with one
profile only nothing new shows. Nothing needs setting up:
- a magpie model stashes the profile's own provider and model, then puts
  magpie's provider and the model into that profile only;
- 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, so a profile never loses
  its model;
- a bot picked there is recorded (hermes:<path>:picked) and doesn't follow
  the connected config's next model (hermesFollow);
- a sync keeps magpie's provider current in a bot on magpie while the
  connected config isn't on it.
app.js stays under its budget through the previous commit; no budget was
raised. New string: "Other profiles" (zh, zh-TW, ja, de).

Run:
- go test ./internal/agent ./internal/gui ./internal/profile ./internal/tui
  ./internal/cli (-count=1). gui, profile and cli are ok. Two reds were already
  filed: TestFolderVarsAreListed (CARGO_HOME, fixed on main by 3116b8f58,
  which this is rebased on) and TestTUIFetchesSubscriptionModels/agent
  (#3919). Neither touches Hermes.
- TestHermes* ok after the rebase. gofmt -l is clean. go vet and GOOS=windows
  go vet pass on agent, gui and profile. GOOS=linux go vet passes on agent and
  profile; gui needs cgo for wails and doesn't cross-vet from macOS.
- GUI: new hermes-profiles.test.cjs (en, zh, zh-TW, ja, de; 1100px and 560px;
  chromium and webkit; 20/20) plus i18n-keys, claude-auto-mode,
  claude-subagents-pick, claude-subagent-effort-row, tier-effort,
  click-scroll, every agent-*.test.cjs, and the previous commit's Settings
  files: 899 of 900. The one red is the known #3897.

Broken by hand:
- origin/main's hermes.go fails TestHermesProfileModels ("pickers []").
- Without the picked guard in hermesFollow, coder followed main to
  deepseek/max.
- With Default deleting model.default, writer lost gpt-5.5.
- With the sync of bots on magpie turned off, writer's provider lacked a new
  model.
- origin/main's app.js fails hermes-profiles.test.cjs 10 of 10 in chromium.

Not tried: a real Hermes. By rule it isn't run under a sandbox
HERMES_HOME, since that rewrites the live ~/.hermes launcher. The layout was
read from Hermes's source, and the configs were written as its
_seed_model_config does. profile.yaml's display_name is not used; the line
shows the folder name, which is what `hermes -p` takes.
This commit is contained in:
yetone
2026-10-28 00:17:40 +08:00
parent 931d887829
commit 34d38ed669
7 changed files with 413 additions and 7 deletions
+1
View File
@@ -53,6 +53,7 @@ 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:<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).
- 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 `<root>/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:<path>: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:<name>` (`default` for the root), drawn as a line of the opened row's Other profiles with `hermes -p <name>` beside it, never as a square of the row's (`hermesProfileFields`; `hermesBot` in app.js; dongshanfengdongshizhcn on Discord). 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:<path>: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`).
- 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`).
+109 -4
View File
@@ -26,6 +26,9 @@ package agent
// bot kept the old model). The config magpie connects is the profile
// `hermes` starts in (hermesActive), and Disconnect leaves each bot on a
// model it can start with, which connecting again puts back (hermesBack).
// With more than one profile, each other one has a model picker of its own
// on the Agents page (hermesProfileFields; dongshanfengdongshizhcn on
// Discord), and a bot picked there no longer follows the connected one.
import (
"encoding/json"
@@ -94,15 +97,26 @@ func hermesIn(at place) *Agent {
}
return edit.SetYAML(path, kvs...)
}
return &Agent{
a := &Agent{
ID: "hermes", Name: "Hermes Agent", Icon: "hermes", Aliases: []string{"hermes-agent"}, Spelled: prefixed, NoNames: true,
UA: []string{"hermes-agent"},
Bin: "hermes", Dir: dir, Path: path,
Sync: func() error {
if err := syncYAML(path, "providers."+magpieID, func() any { return hermesProvider(path) }); err != nil || !joined() {
if err := syncYAML(path, "providers."+magpieID, func() any { return hermesProvider(path) }); err != nil {
return err
}
return spread()
if joined() {
return spread()
}
// a bot put on magpie by its own picker keeps magpie's
// provider current while the connected config isn't
var errs []error
for _, p := range hermesOthers(at, dir) {
if edit.GetYAMLMap(p, "providers."+magpieID) != nil {
errs = append(errs, syncYAML(p, "providers."+magpieID, func() any { return hermesProvider(p) }))
}
}
return errors.Join(errs...)
},
Notice: func() string {
if Running(`(^|/)hermes( |$)`) {
@@ -226,6 +240,94 @@ func hermesIn(at place) *Agent {
},
}},
}
a.Fields = append(a.Fields, hermesProfileFields(at, dir, hermesProvider)...)
return a
}
// hermesProfileKey begins the key of a profile's model field
// (hermesProfileFields): "profile:<name>"
const hermesProfileKey = "profile:"
// hermesProfileFields is a model picker for each of Hermes's profiles
// besides the one magpie connects (dongshanfengdongshizhcn on Discord: only
// the default profile's model could be set). Each is named as `hermes -p
// <name>` names it, "default" for the root's own, and reads and writes that
// profile's config.yaml alone. A magpie model puts the profile on magpie's
// provider, its own model kept for Disconnect and for an own pick to put
// back (the stash hermesUnwireProfile reads); the pick is recorded, so the
// profile stays on it when the connected config's model changes
// (hermesFollow). Unset puts back the model it had before magpie, and a
// profile nobody picks for here keeps what it has.
func hermesProfileFields(at place, dir string, provider func(string) any) []Field {
root := filepath.Clean(hermesRoot(at))
var out []Field
for _, p := range hermesOthers(at, dir) {
name := "default"
if d := filepath.Clean(filepath.Dir(p)); d != root {
name = filepath.Base(d)
}
k := "hermes:" + p + ":"
out = append(out, Field{
Key: hermesProfileKey + name, Label: name, Quiet: true,
Get: func() string {
m := hermesModelOf(p)
if m.Default != "" && m.Provider == magpieID {
return magpieID + "/" + m.Default
}
return m.Default
},
Set: func(v string) error {
cur := hermesModelOf(p)
if ref, ok := strings.CutPrefix(v, magpieID+"/"); ok && isMagpie(ref) {
if cur.Provider != magpieID {
stash(map[string]string{k + "model.provider": cur.Provider, k + "model.default": cur.Default})
}
if err := edit.SetYAML(p,
edit.KV{Path: "providers." + magpieID, Value: provider(p)},
edit.KV{Path: "model.provider", Value: magpieID},
edit.KV{Path: "model.default", Value: ref},
); err != nil {
return err
}
stash(map[string]string{k + "picked": ref})
return nil
}
forget(k + "picked")
if cur.Provider == magpieID {
// back to the provider and model it had before magpie
var del []string
var kvs []edit.KV
for _, f := range []string{"model.provider", "model.default"} {
if was := unstash(k + f); was != "" {
kvs = append(kvs, edit.KV{Path: f, Value: was})
} else {
del = append(del, f)
}
}
if len(del) > 0 {
if err := edit.DelYAML(p, del...); err != nil {
return err
}
}
if len(kvs) > 0 {
if err := edit.SetYAML(p, kvs...); err != nil {
return err
}
}
}
// unset: the profile keeps its own model, which Hermes
// needs to start there
if v == "" {
return nil
}
return edit.SetYAML(p, edit.KV{Path: "model.default", Value: v})
},
Options: func(cur map[string]string) []Option {
return append(ownOptions("", cur[hermesProfileKey+name]), viaMagpie("hermes", magpieID+"/")...)
},
})
}
return out
}
// hermesProfileID is the name a Hermes profile may have
@@ -348,6 +450,7 @@ func hermesFollow(at place, dir, was, now, ref string) error {
return nil
}
var errs []error
picked := stashLoad()
for _, p := range hermesOthers(at, dir) {
if v, _ := edit.GetYAML(p, "model.provider"); v != magpieID {
continue
@@ -360,7 +463,9 @@ func hermesFollow(at place, dir, was, now, ref string) error {
k = "model.model"
v, _ = edit.GetYAML(p, k)
}
if from(v) {
// one picked for this profile on the Agents page is the user's
// (hermesProfileFields)
if from(v) && picked["hermes:"+p+":picked"] != v {
errs = append(errs, edit.SetYAML(p, edit.KV{Path: k, Value: ref}))
}
}
+164
View File
@@ -838,3 +838,167 @@ func TestHermesStickyProfile(t *testing.T) {
t.Fatalf("coder after Off: %+v", m)
}
}
// Each of Hermes's other profiles has a model picker of its own
// (dongshanfengdongshizhcn on Discord: only the default profile's model
// could be set): it writes that profile's config alone, a magpie model
// stays when the connected config's model changes, an own model puts back
// the provider the profile had, and a profile nobody picks for keeps what
// it has. With the root's profile only, there is no such picker.
func TestHermesProfileModels(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"}}); 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, Provider string }
}
b, _ := os.ReadFile(p)
yaml.Unmarshal(b, &c)
return c.Model.Default, c.Model.Provider
}
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, p, prov, m, wantProv, want, b)
}
}
main := write("config.yaml", "model:\n default: anthropic/claude-opus-5\n provider: openrouter\n")
profileKeys := func(a *Agent) []string {
var ks []string
for _, f := range a.Fields {
if strings.HasPrefix(f.Key, "profile:") {
ks = append(ks, f.Key)
}
}
return ks
}
if ks := profileKeys(hermes(home)); len(ks) != 0 {
t.Fatalf("one profile only, yet pickers %v", ks)
}
coder := write("profiles/coder/config.yaml", "# coder bot\nmodel:\n default: kimi-k3\n provider: moonshot\nproviders:\n mine:\n base_url: https://x\n")
writer := write("profiles/writer/config.yaml", "model:\n default: gpt-5.5\n provider: openai\n")
write("profiles/old/config.yaml", "model:\n default: x\n")
write("profiles/.deleted/old", "")
a := hermes(home)
if ks := profileKeys(a); !slices.Equal(ks, []string{"profile:coder", "profile:writer"}) {
t.Fatalf("pickers %v", ks)
}
if f := a.Field("profile:coder"); f == nil || f.Label != "coder" || f.Get() != "kimi-k3" {
t.Fatalf("coder's picker: %+v", f)
}
if err := a.Connect(); err != nil {
t.Fatal(err)
}
if err := a.Apply("model", "magpie/deepseek/pro"); err != nil {
t.Fatal(err)
}
// picked here: that profile alone, on magpie
if err := a.Apply("profile:coder", "magpie/deepseek/flash"); err != nil {
t.Fatal(err)
}
check("coder on flash", coder, "deepseek/flash", "magpie")
check("coder on flash", main, "deepseek/pro", "magpie")
check("coder on flash", writer, "gpt-5.5", "openai")
if b, _ := os.ReadFile(coder); !strings.Contains(string(b), "# coder bot") || !strings.Contains(string(b), "mine:") {
t.Fatalf("coder lost its own settings:\n%s", b)
}
if v := hermes(home).Field("profile:coder").Get(); v != "magpie/deepseek/flash" {
t.Fatalf("coder reads %q", v)
}
// picked the model the connected config is on: it stays when that one
// changes, as it was picked for this profile
if err := a.Apply("profile:coder", "magpie/deepseek/pro"); err != nil {
t.Fatal(err)
}
if err := a.Apply("model", "magpie/deepseek/max"); err != nil {
t.Fatal(err)
}
check("main on max", coder, "deepseek/pro", "magpie")
check("main on max", writer, "gpt-5.5", "openai")
// a model of its own: the provider it had before magpie comes back
if err := a.Apply("profile:coder", "kimi-k3.5"); err != nil {
t.Fatal(err)
}
check("coder on its own", coder, "kimi-k3.5", "moonshot")
// Default on a profile on magpie: the model it had before magpie;
// on one of its own model, it keeps it
if err := a.Apply("profile:writer", "magpie/deepseek/flash"); err != nil {
t.Fatal(err)
}
if err := a.Apply("profile:writer", ""); err != nil {
t.Fatal(err)
}
check("writer on default", writer, "gpt-5.5", "openai")
if err := a.Apply("profile:coder", ""); err != nil {
t.Fatal(err)
}
check("coder on default", coder, "kimi-k3.5", "moonshot")
// on magpie again, then Off and On: back on its own model, then on
// the one picked for it
if err := a.Apply("profile:writer", "magpie/deepseek/flash"); err != nil {
t.Fatal(err)
}
if err := a.Disconnect(); err != nil {
t.Fatal(err)
}
check("after disconnect", writer, "gpt-5.5", "openai")
check("after disconnect", coder, "kimi-k3.5", "moonshot")
if err := hermes(home).Connect(); err != nil {
t.Fatal(err)
}
check("connected again", writer, "deepseek/flash", "magpie")
check("connected again", coder, "kimi-k3.5", "moonshot")
if err := hermes(home).Disconnect(); err != nil {
t.Fatal(err)
}
// a bot put on magpie while the connected config isn't keeps magpie's
// provider current: a model added since reaches its list at a sync
a = hermes(home)
if err := a.Apply("profile:writer", "magpie/deepseek/flash"); err != nil {
t.Fatal(err)
}
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)
}
if err := a.Sync(); err != nil {
t.Fatal(err)
}
if b, _ := os.ReadFile(writer); !strings.Contains(string(b), "deepseek/lite") {
t.Fatalf("writer's provider after a sync:\n%s", b)
}
// with a sticky profile, the root's config is the profile "default"
write("active_profile", "coder\n")
a = hermes(home)
if ks := profileKeys(a); !slices.Equal(ks, []string{"profile:default", "profile:writer"}) {
t.Fatalf("sticky coder: pickers %v", ks)
}
if err := a.Apply("profile:default", "openrouter/x-model"); err != nil {
t.Fatal(err)
}
if m, _ := model(main); m != "openrouter/x-model" {
b, _ := os.ReadFile(main)
t.Fatalf("default profile:\n%s", b)
}
}
+1 -1
View File
@@ -4233,7 +4233,7 @@ body.window .row + .row.agent.conn > .who { min-height: 41px; } /* the line abov
.ag-stale-copy .ag-quiet { height: 20px; margin-left: 4px; padding: 0 6px; vertical-align: middle; }
.ag-stale-copy .ag-quiet.busy { opacity: .6; cursor: progress; }
.ag-hint { font-size: 12px; color: var(--muted); }
.ag-tier { width: 70px; flex: none; font-size: 12px; color: var(--fg-2); }
.ag-tier { width: 70px; flex: none; font-size: 12px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-vl .field.ag-pick { width: 220px; justify-content: flex-start; }
.ag-vl .field.ag-eff { flex: none; }
/* the subagents' effort, while they are on Claude Code's pick: Default, dimmed, as a macOS control that can't be used yet */
+7 -2
View File
@@ -448,7 +448,7 @@ function renderAgents() {
// user's own)
// nor Aside's account with one account only (#1499)
const none = (f) => (f.key === "effort" || f.key === "ultracode" || f.label === "subagents" || f.label === SUB_EFFORT || f.label === SUB_MODEL || f.label === AUTO_MODE || f.label === MEMORIES || f.label === "sign-in" || f.key === "small" || asideAccount(a, f)) && !f.options.length && !f.value;
const shownFields = a.fields.filter((f) => !grouped(a, f) && !none(f) && !codexOwnSub(a, f) && !codexRowed(a, f));
const shownFields = a.fields.filter((f) => !grouped(a, f) && !none(f) && !codexOwnSub(a, f) && !codexRowed(a, f) && !hermesBot(f));
const tiers = tierMenu(a);
if (tiers) shownFields.push(tiers);
const sorted = shownFields.sort((x, y) => wide(y) - wide(x) || extra(x) - extra(y));
@@ -2002,6 +2002,9 @@ function connectPanel(a, { fields, fieldBtn }) {
} else if (menuFromList(a)) {
kv(t("In {agent}", { agent: a.name }), line(t("{agent}'s model menu lists the models picked here; switch among them there. It reads the list as it starts: quit and reopen it after a change.", { agent: a.name })));
}
// Hermes' other profiles, each on its own model
const bots = a.fields.filter(hermesBot);
if (bots.length) kv(t("Other profiles"), ...bots.map((f) => line(el("span", "ag-tier", f.label), fieldBtn(f, "ag-pick"), el("span", "ag-hint", "hermes -p " + f.label))));
// Claude Code's tiers, each with the /model that picks it
if (a.id === "claude") {
const tiers = a.fields.filter((f) => TIERS.includes(f.label) && f.options.length);
@@ -3840,6 +3843,7 @@ const claudePicks = (a, f) => leadPicks(a, f) && a.id === "claude";
const codexSub = (a) => a.id.split("@wsl:")[0] === "codex" && a.fields.some((f) => f.label === SUB_MODEL && (f.options.length || f.value));
const codexOwnSub = (a, f) => f.label === "subagents" && codexSub(a);
// named rows in Codex's settings: no square too (the owner, 10-25)
const hermesBot = (f) => f.key.startsWith("profile:");
const codexRowed = (a, f) => a.id === "codex" && !gatewayMode && (f.label === SUB_MODEL || f.label === MEMORIES);
const SAME_AS_LEAD = "Same as the lead";
const SUB_MODEL_UNSET = "Each subagent runs on the lead's model ({model}), or on another the lead picks for it. Pick a model here to put every subagent on it.";
@@ -4877,6 +4881,7 @@ function openPicker(agent, field, anchor, ev, only) {
: field.label === AUTO_MODE ? "the model {agent} picks for its auto mode classifier"
: ompAgent(agent) && OMP_OWN_PICK.includes(field.label) ? OMP_UNSET[field.label]
: asideAccount(agent, field) ? "the account active in {agent}"
: hermesBot(field) ? "put back what {agent} had before magpie"
: "what {agent} ships with";
options.unshift({ value: "", label: t("Default"), note: t(note, { agent: agent.name, field: t(field.label) }), icon: agent.icon, reset: true });
}
@@ -4886,7 +4891,7 @@ function openPicker(agent, field, anchor, ev, only) {
const at = options.findIndex((o) => !o.reset);
options.splice(at < 0 ? options.length : at, 0, { value: "\0disconnect", label: t("Disconnect from magpie"), note: t("put back what {agent} had before magpie", { agent: agent.name }), svg: UNPLUG, reset: true, run: () => askDisconnect(agent) });
}
const modelPicker = ["model", "small", "large", MEMORIES, SUB_MODEL, AUTO_MODE, "executor", "planner", ...ROLE_MODELS].includes(field.label) && !only;
const modelPicker = (["model", "small", "large", MEMORIES, SUB_MODEL, AUTO_MODE, "executor", "planner", ...ROLE_MODELS].includes(field.label) || hermesBot(field)) && !only;
pick = { agent, field, options, groups, anchor, cursor: 0, free: !only && !field.menu, modelPicker, effortPicker, groupFilter: "all" };
anchor.classList.add("open");
const pop = $("#pop");
+4
View File
@@ -590,6 +590,7 @@ const I18N = {
"Connected · {n} models in {agent}'s {cmd}": "已接入 · {agent} 的 {cmd} 里有 {n} 个模型",
"Collapse": "收起",
"Tiers": "档位",
"Other profiles": "其他 profile",
"Details": "详情",
"Can't connect": "不能接入",
"New sessions take it; switch the tiers in {cmd}.": "新开的会话生效,在 {cmd} 里切换档位。",
@@ -4622,6 +4623,7 @@ const I18N = {
"Connected · {n} models in {agent}'s {cmd}": "已接入 · {agent} 的 {cmd} 裡有 {n} 個模型",
"Collapse": "收起",
"Tiers": "檔位",
"Other profiles": "其他 profile",
"Details": "詳情",
"Can't connect": "不能接入",
"New sessions take it; switch the tiers in {cmd}.": "新開的會話生效,在 {cmd} 裡切換檔位。",
@@ -8620,6 +8622,7 @@ const I18N = {
"Connected · {n} models in {agent}'s {cmd}": "接続済み · {agent} の {cmd} に {n} モデル",
"Collapse": "折りたたむ",
"Tiers": "階層",
"Other profiles": "ほかのプロファイル",
"Details": "詳細",
"Can't connect": "接続できません",
"New sessions take it; switch the tiers in {cmd}.": "新しいセッションから反映されます。階層は {cmd} で切り替えます。",
@@ -12635,6 +12638,7 @@ const I18N = {
"Connected · {n} models in {agent}'s {cmd}": "Verbunden · {n} Modelle in {cmd} von {agent}",
"Collapse": "Einklappen",
"Tiers": "Stufen",
"Other profiles": "Weitere Profile",
"Details": "Details",
"Can't connect": "Verbinden nicht möglich",
"New sessions take it; switch the tiers in {cmd}.": "Gilt für neue Sitzungen; Stufen in {cmd} wechseln.",
+127
View File
@@ -0,0 +1,127 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Hermes keeps more than one profile (hermes -p <name>), each with its own
// config.yaml, and magpie's Hermes row picked the model of one of them only
// (dongshanfengdongshizhcn on Discord). Each other profile comes as a field
// keyed "profile:<name>": connected, the opened row has an Other profiles
// section with one line per profile (its name, its model picker, the
// command that runs it), and no square of the row's own. A click opens the
// app's model picker with Default first, noted as putting back what the
// profile had before magpie; a model picked is posted for that profile
// alone. With one profile only there is no section. No click scrolls the
// page. In every language, at a normal and a narrow width, in both engines.
// No backend: the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const models = [{ value: "magpie/v/glm", label: "GLM", ref: "v/glm" }, { value: "magpie/v/flash", label: "Flash", ref: "v/flash" }];
const hermes = (id, bots) => ({
id, name: "Hermes", path: "/test/.hermes/config.yaml", icon: "hermes", wired: true,
fields: [
{ key: "model", label: "model", value: "magpie/v/glm", options: models },
...bots.map((b) => ({ key: "profile:" + b, label: b, value: b === "coder" ? "kimi-k3.5" : "magpie/v/glm", quiet: true, options: [{ value: "kimi-k3.5" }, ...models] })),
],
});
const fresh = () => ({ agents: [hermes("hermes", ["a-profile-with-a-long-name", "coder"]), hermes("hermes-one", [])], profiles: [] });
function server(lang, sets) {
let cur = fresh();
return async (route) => {
const req = route.request(), url = new URL(req.url());
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } });
if (url.pathname === "/api/set") {
const body = req.postDataJSON();
sets.push(body);
cur = JSON.parse(JSON.stringify(cur));
cur.agents.find((a) => a.id === body.agent).fields.find((f) => f.key === body.field).value = body.value;
return route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } });
}
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/agents/cli") return route.fulfill({ json: { agents: {}, pending: false } });
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} });
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
// the words as i18n.js has them
const W = {
en: { head: "Other profiles", def: "Default", note: "put back what Hermes had before magpie" },
zh: { head: "其他 profile", def: "默认", note: "还原 Hermes 接入 magpie 之前的设置" },
"zh-TW": { head: "其他 profile", def: "預設", note: "還原 Hermes 接入 magpie 之前的設定" },
ja: { head: "ほかのプロファイル", def: "デフォルト", note: "Hermes を magpie 接続前の設定に戻す" },
de: { head: "Weitere Profile", def: "Standard", note: "Stand von Hermes vor magpie wiederherstellen" },
};
const row = '.row.agent[data-id="hermes"]';
const one = '.row.agent[data-id="hermes-one"]';
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(W)) {
for (const width of [1100, 560]) {
test(`${engine} ${lang} ${width}px: each Hermes profile picks its own model`, async (t) => {
const w = W[lang];
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await browser.newPage({ viewport: { width, height: 800 } });
page.setDefaultTimeout(5000);
const errors = [], sets = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, sets));
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-hermes-profiles.png`) });
}
await browser.close();
});
await page.goto("http://magpie.test/");
await page.locator(row).waitFor();
// no profile picker in the row itself
assert.equal(await page.locator(`${row} > * .field[data-key^="profile:"]`).count(), 0);
// one profile only: no section
await page.locator(`${one} .ag-link`).click();
await page.locator(`${one} .ag-exp`).waitFor();
assert.equal(await page.locator(`${one} .ag-exp`).innerText().then((s) => s.includes(w.head)), false);
assert.equal(await page.locator(`${one} .field[data-key^="profile:"]`).count(), 0);
await page.locator(`${row} .ag-link`).click();
await page.locator(`${row} .ag-exp`).waitFor();
assert.ok((await page.locator(`${row} .ag-exp`).innerText()).includes(w.head));
const keys = await page.locator(`${row} .ag-exp .field.ag-pick[data-key^="profile:"]`).evaluateAll((es) => es.map((e) => e.dataset.key));
assert.deepEqual(keys, ["profile:a-profile-with-a-long-name", "profile:coder"]);
const pick = page.locator(`${row} .ag-exp .field.ag-pick[data-key="profile:coder"]`);
const line = pick.locator("xpath=..");
assert.equal(await line.locator(".ag-tier").textContent(), "coder");
assert.equal(await line.locator(".ag-hint").textContent(), "hermes -p coder");
assert.equal(await pick.locator(".v").textContent(), "kimi-k3.5");
// a long name is cut short, not pushing its picker out
const long = page.locator(`${row} .ag-exp .field.ag-pick[data-key="profile:a-profile-with-a-long-name"]`).locator("xpath=..").locator(".ag-tier");
assert.ok(await long.evaluate((e) => e.scrollWidth > e.clientWidth && getComputedStyle(e).textOverflow === "ellipsis"));
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "the Agents view overflows");
// the app's model picker, Default first, noted as putting back the profile's own
const y = await page.evaluate(() => scrollY);
await pick.click();
await page.locator("#pop:not([hidden]) #list li").first().waitFor();
assert.equal(await page.evaluate(() => scrollY), y, "the click scrolled the page");
assert.equal(await page.locator("#pop").evaluate((e) => e.classList.contains("model-picker")), true);
const first = await page.locator("#pop #list li").first().innerText();
assert.ok(first.includes(w.def) && first.includes(w.note), first);
await page.locator("#pop #list li", { hasText: "Flash" }).first().click();
await page.waitForFunction(() => document.querySelector('.row.agent[data-id="hermes"] .ag-exp .field[data-key="profile:coder"] .v')?.textContent === "Flash");
assert.deepEqual(sets, [{ agent: "hermes", field: "profile:coder", value: "magpie/v/flash" }]);
assert.deepEqual(errors, []);
});
}
}
}