A user on X asked for OpenMausBot (github.com/milind-soni/OpenMausBot,
read at 516ca75; released 0.1.145). Its bots run on engines from
`instances` in ~/.openmausbot/config.json ($OMB_DATA_DIR,
server/config.ts:713). Without this, a Claude bot reached magpie only
through ~/.claude/settings.json, and its picker listed Claude's static
models alone: OpenMausBot doesn't read the model from env
(readClaudeModelCatalog, claude.ts:296-316).
- openmausbot.go writes `instances.magpie` in the shape of OpenMausBot's
own "Claude endpoint" (newClaudeEndpoint, claude-endpoints.ts:91-139):
- driver claudeAgent, access custom
- config.configDir is <data>/providers/magpie. Given that,
OpenMausBot starts Claude Code with that CLAUDE_CONFIG_DIR and
strips account keys the engine doesn't set (claudeEnvironment,
claude.ts:111-136, 158-179), so the engine owns its routing.
- requireApiKey
- ANTHROPIC_BASE_URL, AUTH_TOKEN, API_KEY and MODEL point at the
gateway
- endpointModels holds magpie's models, kept to the ids
CLAUDE_MODEL_ID accepts. One bad id makes OpenMausBot refuse the
whole engine (claude.ts:636).
- A non-empty `instances` is the whole fleet (config.ts:1173). With
none saved, magpie writes DEFAULT_FLEET (instance-fleets.ts) beside
magpie, stashed as openmausbot.fleet. Off takes the fleet out again
if the user hasn't changed it.
- What stays the user's: the engine's name, a model they picked from
the list, their other env and an inherited `cli`.
- Check reports the base URL drifting away from the gateway.
- OpenMausBot reads config.json once at start (index.ts:780), and an
engine edited in it writes back the fleet it holds
(routes/instances.ts:132, config.ts:997-1012). So Set is refused
while it runs (errOMBRunning), and the notice asks to quit it first,
since Windows can't tell.
- ListOnly, ListsModels, OMB_DATA_DIR in agentenv. The icon is
OpenMausBot's build/icon.svg (Apache-2.0).
- i18n in zh, zh-TW, ja and de. Docs: reference, agent-wiring, both
READMEs.
- Codex bots use ~/.codex (codex.ts:373-386), which the Codex wiring
already covers.
- The agent package's TestMain holds ombRunning false. An OpenMausBot
open on the test machine refused every test that turns magpie on for
each agent: my own sandbox OpenMausBot on mote turned
TestSyncKeepsAnAddressOnAnotherMachine, TestListOnlyAgentsReadConnected
and TestReverseProxyIsStillMagpie red. With a process named
openmausbot running, they now pass. LiveAgent's, OpenPencil's and
NewMax's running checks have the same hole and are left to #5587.
Run (all on mote):
- gofmt -l: clean
- go vet ./... on darwin, GOOS=linux -tags nogui and GOOS=windows: ok
- go build for the same three targets: ok
- go test -tags nogui ./... -timeout 45m at e1453a168 (this change on
origin/main 30ae0e3f9): 88 packages ok, none failed. Rebased after
it onto e932cd258, which changes internal/library and adds one GUI
test only. At the pushed head: go vet of internal/agent and
internal/library, and go test of internal/agent, agentenv and
appdir, all ok.
- GUI: the 71 files this change reaches, in chromium and webkit, every
language they cover: agent-*, agents-*, i18n-*, icon-*, gui-de,
gui-ja, gui-zh-tw, about-notices, deprecation-notice, header-relang,
market-icon-corners. 1145 of 1146 pass. The one red is i18n-keys'
"a plugin's words are its own" for plugins' "Use the library's",
"No session ID" and "View routing", the same on main and filed
(#5332, #5426, #5482). The whole GUI suite was started too and
stopped at 369 ok, 0 failed: at ~5h on mote it runs after this push.
Real OpenMausBot: 0.1.145's arm64 app was run on mote, its own server
(ELECTRON_RUN_AS_NODE, Resources/server/index.js) with HOME and
OMB_DATA_DIR in a sandbox, on a free port, against a config.json
magpie's Set wrote. /api/instances listed 28 engines, among them
`magpie`: access custom, claudeEndpoint at http://127.0.0.1:3425, and
models relay/glm-4.6 and relay/gpt-5.5 in its picker, with the first as
default. It read "unavailable: `claude` CLI not found" only because the
sandbox PATH had no claude. The file was left as magpie wrote it.
Broken by hand:
- The fleet not written: TestOpenMausBotEngine red.
- The model-id filter taken out: TestOpenMausBotEngine and
TestOpenMausBotKeepsTheUsers red ("relay/glm 4.6 (beta)"). Green
before a bad id was added to the fixture, so one was added.
Not tried:
- A bot turn through Claude Code to a gateway. No claude CLI or
account on mote.
- The desktop app's window, Linux and Windows builds.
- An OpenMausBot running while magpie writes. The refusal is
unit-tested only.
169 lines
6.6 KiB
Go
169 lines
6.6 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// listsSandbox is a HOME of its own with one provider of two models.
|
|
func listsSandbox(t *testing.T) (home, cfg string) {
|
|
t.Helper()
|
|
home = t.TempDir()
|
|
cfg = filepath.Join(home, ".config")
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("XDG_CONFIG_HOME", cfg)
|
|
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"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return home, cfg
|
|
}
|
|
|
|
// An agent whose switch puts magpie's models in a picker of its own, with
|
|
// no field of its picking among them, lists only the ones picked for it on
|
|
// the Agents page, as every other agent does: ZCode was given every model,
|
|
// with no way to hide one (#1508, NovaTrailX). ListsModels is what gives
|
|
// its row that list.
|
|
func TestEveryPickerOfMagpiesModelsCanBeNarrowed(t *testing.T) {
|
|
home, cfg := listsSandbox(t)
|
|
var bare, menus []string
|
|
for _, a := range builtins(home, cfg) {
|
|
vals := a.Values()
|
|
refs, magpie := false, false
|
|
for _, f := range a.Fields {
|
|
if f.Options == nil {
|
|
continue
|
|
}
|
|
for _, o := range f.Options(vals) {
|
|
refs = refs || o.Ref != ""
|
|
magpie = magpie || o.Value == magpieID
|
|
}
|
|
}
|
|
switch {
|
|
// Claude Desktop's tier pickers list the catalog once it is
|
|
// connected (desktopTierFields), and the sandbox has no Desktop
|
|
case refs, a.ID == "claude-desktop":
|
|
// Kiro Crew's models are its harness's: the agent it runs (Codex,
|
|
// Claude Code…), whose own row narrows them
|
|
case a.ID == "kirocrew":
|
|
case a.ListsModels:
|
|
menus = append(menus, a.ID)
|
|
case magpie:
|
|
bare = append(bare, a.ID)
|
|
}
|
|
}
|
|
if len(bare) > 0 {
|
|
t.Errorf("magpie's models are put in these agents' pickers with no way to pick which: %v", bare)
|
|
}
|
|
for _, id := range []string{"zcode", "pencil", "openpencil", "openbot", "newmax", "liveagent", "t3code", "openmausbot", "workbuddy", "workbuddy-ai", copilotJBID, CursorLocalID} {
|
|
if !slices.Contains(menus, id) {
|
|
t.Errorf("%s's row has no model list to pick in (ListsModels): %v", id, menus)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The models taken out of ZCode's list on the Agents page are out of both
|
|
// files it reads, config.json and provider_config.json, and come back when
|
|
// they are put back; what the user set by hand stays: their own providers,
|
|
// rules and keys, and their manual rule for a model of magpie's (#1508).
|
|
func TestZCodeListsOnlyThePicked(t *testing.T) {
|
|
home, _ := listsSandbox(t)
|
|
dir := filepath.Join(home, ".zcode", "v2")
|
|
path, rules := filepath.Join(dir, "config.json"), filepath.Join(dir, "provider_config.json")
|
|
os.MkdirAll(dir, 0o755)
|
|
os.WriteFile(path, []byte(`{"provider":{"builtin:bigmodel":{"name":"Bigmodel","kind":"anthropic","enabled":true},"mine":{"name":"Mine","kind":"openai","models":{"m1":{"name":"M1"}}}},"theme":"dark"}`), 0o644)
|
|
os.WriteFile(rules, []byte(`{"schemaVersion":1,"config":{"providerConfigRules":{"providerRules":[{"providerId":"mine","enabled":true,"config":{"personalModelIds":["m1"]}}]},"modelConfigRules":{"providerModelRules":[{"providerId":"mine","modelId":"m1","config":{"properties":{"contextWindow":1000}}}],"manualProviderModelRules":[{"providerId":"magpie","modelId":"deepseek/pro","config":{"enabled":true,"properties":{"contextWindow":4242}}}]}},"ui":{"lang":"zh"}}`), 0o600)
|
|
a := zcode(home)
|
|
if err := a.Field("provider").Set("magpie"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
type configDoc struct {
|
|
Theme string `json:"theme"`
|
|
Provider map[string]map[string]any `json:"provider"`
|
|
}
|
|
readConfig := func() configDoc {
|
|
var c configDoc
|
|
b, _ := os.ReadFile(path)
|
|
if err := json.Unmarshal(b, &c); err != nil {
|
|
t.Fatalf("%v\n%s", err, b)
|
|
}
|
|
if c.Theme != "dark" || c.Provider["builtin:bigmodel"] == nil || c.Provider["mine"]["models"].(map[string]any)["m1"] == nil {
|
|
t.Fatalf("the user's own config went: %s", b)
|
|
}
|
|
return c
|
|
}
|
|
type rulesDoc struct {
|
|
UI map[string]any `json:"ui"`
|
|
Config struct {
|
|
ProviderConfigRules struct {
|
|
ProviderRules []map[string]any `json:"providerRules"`
|
|
} `json:"providerConfigRules"`
|
|
ModelConfigRules struct {
|
|
ProviderModelRules []map[string]any `json:"providerModelRules"`
|
|
ManualProviderModelRules []map[string]any `json:"manualProviderModelRules"`
|
|
} `json:"modelConfigRules"`
|
|
} `json:"config"`
|
|
}
|
|
readRules := func() rulesDoc {
|
|
var d rulesDoc
|
|
b, _ := os.ReadFile(rules)
|
|
if err := json.Unmarshal(b, &d); err != nil {
|
|
t.Fatalf("%v\n%s", err, b)
|
|
}
|
|
pr, mr := d.Config.ProviderConfigRules.ProviderRules, d.Config.ModelConfigRules
|
|
if d.UI["lang"] != "zh" || len(pr) != 2 || pr[0]["providerId"] != "mine" ||
|
|
!slices.ContainsFunc(mr.ProviderModelRules, func(r map[string]any) bool { return r["providerId"] == "mine" && r["modelId"] == "m1" }) ||
|
|
len(mr.ManualProviderModelRules) != 1 || mr.ManualProviderModelRules[0]["modelId"] != "deepseek/pro" {
|
|
t.Fatalf("the user's own rules went: %s", b)
|
|
}
|
|
return d
|
|
}
|
|
listed := func() (config, personal, ruled []string) {
|
|
for id := range readConfig().Provider["magpie"]["models"].(map[string]any) {
|
|
config = append(config, id)
|
|
}
|
|
d := readRules()
|
|
for _, id := range d.Config.ProviderConfigRules.ProviderRules[1]["config"].(map[string]any)["personalModelIds"].([]any) {
|
|
personal = append(personal, id.(string))
|
|
}
|
|
for _, r := range d.Config.ModelConfigRules.ProviderModelRules {
|
|
if r["providerId"] == magpieID {
|
|
ruled = append(ruled, r["modelId"].(string))
|
|
}
|
|
}
|
|
slices.Sort(config)
|
|
slices.Sort(personal)
|
|
return config, personal, ruled
|
|
}
|
|
both := []string{"deepseek/flash", "deepseek/pro"}
|
|
if c, p, _ := listed(); !slices.Equal(c, both) || !slices.Equal(p, both) {
|
|
t.Fatalf("connected: config.json %v, provider_config.json %v", c, p)
|
|
}
|
|
// taken out on the Agents page: gone from both, at the next sync
|
|
if err := provider.SetHiddenModels("zcode", []string{"deepseek/flash"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if c, p, r := listed(); !slices.Equal(c, []string{"deepseek/pro"}) || !slices.Equal(p, []string{"deepseek/pro"}) || len(r) != 0 {
|
|
t.Fatalf("hidden: config.json %v, provider_config.json %v, rules %v", c, p, r)
|
|
}
|
|
// and back
|
|
if err := provider.SetHiddenModels("zcode", nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if c, p, r := listed(); !slices.Equal(c, both) || !slices.Equal(p, both) || !slices.Equal(r, []string{"deepseek/flash"}) {
|
|
t.Fatalf("shown again: config.json %v, provider_config.json %v, rules %v", c, p, r)
|
|
}
|
|
}
|