"Can support Shelley?" Shelley is boldsoftware/shelley (Apache-2.0, Go,
`shelley serve`). It keeps models and profiles in its SQLite database,
not in a config file, so magpie talks to a running Shelley through the
same API its own Models and Profiles pages use, on the Unix socket it
opens for its CLI ($SHELLEY_SOCKET, else shelley.sock / shelley-N.sock in
$XDG_CONFIG_HOME/shelley or ~/.config/shelley; read from its source).
- Connect: each magpie model is a custom model (POST /api/custom-models,
provider_type openai, endpoint = the gateway's /v1, Shelley's own
gateway key, model_name = the catalog id, reasoning/images/max_tokens
from the catalog). Picking one makes it the default profile's model
(PUT /api/profiles/{name} with the whole profile, as the API requires)
and clears a thinking level the model can't take.
- The user's own values: the profile's model and thinking level are
stashed once and put back on Disconnect (to the server's default if
that model is gone); only the custom models magpie made (ids stashed)
are deleted, so a model the user pointed at the gateway by hand stays.
- Sync re-points magpie's models when the gateway port moves; Check names
a model left on an old address. Shelley not running is an error on a
pick and nothing on Sync/Check; turned off while Shelley is uninstalled,
the takeout is stashed and done when Shelley answers again (Alma's way).
- A notice: new conversations start on the pick, an open one keeps its
model. i18n for zh, zh-TW, ja, de.
- Icon: Shelley's own S mark from its assets, one tone. README (en, zh),
site index, docs/reference.md, docs/integrating.md, site integrate
pages (en, zh), docs/subsystems/agent-wiring.md.
- Library: listed as "not looked at (#5897)" like the other new agents.
- Shelley has no Windows build, so there is no Windows or WSL wiring.
Run (mote refused SSH for the whole session, kex reset, so runs went to
the Linux VM and the Windows box):
- Real binary: shelley v0.1718.926152762 linux_amd64 (sha256 66cb5acb…
checked) in a sandbox HOME/XDG_CONFIG_HOME/-db on the Linux VM, with a
throwaway test driving it against a fake OpenAI upstream at
MAGPIE_ADDR: connect made custom model glm-4-6-… and the default
profile's model; POST /api/conversations/new sent two
/v1/chat/completions with model=relay/glm-4.6, auth magpie-shelley,
UA Shelley/58d5f200; disconnect left the profile as before and no
custom models. Check "" and Drift nil while connected.
- Linux (wsl-run, nogui): go vet ./internal/agent ./internal/agentenv
./internal/library; go test ./internal/agent ./internal/agentenv
./internal/library ./internal/profile ./internal/sessions: ok except
TestGrokInstalled (#3548, red on base too) and, before its fix here,
TestEveryAgentInLibrary. internal/cli times out there in
TestEveryAgentFieldNameWritesNothing (43m, the #5234 class).
- Windows (win-run): go vet ./internal/agent ./internal/agentenv;
GOOS=darwin and GOOS=linux -tags nogui vet; the Shelley, applied,
rewire, disconnect, mark and kept tests: red only in
TestAppliedOfParsesAnUnchangedFileOnce (#5950),
TestAsideOfflineDisconnectRestoresWithoutDaemon (#5951) and the #4786
allocation tests, all red on base d4b4a188e too. internal/cli
TestHelpOnEveryCommandDoesNothing, TestEveryAgentFieldNameWritesNothing
and internal/library TestEvery*: ok.
- GUI (node --test, chromium + webkit) i18n-keys, i18n-en-no-cjk,
agent-notice-lang, gui-de, gui-ja, gui-zh-tw, icon-one-tone, icon-tile,
routing-client-icons, usage-agent-filter-icons, agent-connect,
agent-models, agent-layout, on the Windows box at the rebased head:
110 tests, 107 pass. Red: gui-ja "ja has every zh string" ({model}
twice, #5943) and icon-one-tone webkit voyage-color (#5962), both red
at origin/main a1ba92ad8 too.
- At the rebased head 2a9c7b715 (on origin/main a1ba92ad8), Linux:
vet of agent, agentenv, library ok; go test agent, agentenv, library,
profile ok except TestGrokInstalled (#3548). Pushed on ca7a39291,
which changes only internal/gateway (MiniMax drawing); not rerun.
- gofmt -l clean.
Broken by hand: not restoring the profile's model on Disconnect turns
TestShelley and TestShelleyThinkingLevel red; not deleting magpie's
custom models turns TestShelley and TestShelleyKeepsHandWired red.
Not tried: a real model upstream (the upstream was a fake), macOS (mote
unreachable; the darwin build was vetted only), the GUI against a real
Shelley, Shelley's web UI after the switch.
155 lines
5.0 KiB
Go
155 lines
5.0 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
)
|
|
|
|
// commentable says whether an agent reads path as TOML, YAML or dotenv,
|
|
// where a line can carry a comment. JSON can't, and gets none.
|
|
func commentable(path string) bool {
|
|
switch strings.ToLower(filepath.Ext(path)) {
|
|
case ".toml", ".yaml", ".yml", ".env":
|
|
return true
|
|
}
|
|
return filepath.Base(path) == ".env"
|
|
}
|
|
|
|
// rewrittenEachSync are the agents whose config every sync writes again
|
|
// unchanged, notes or none (#3870)
|
|
var rewrittenEachSync = map[string]bool{"kimi": true, "grok": true, "atomcode": true}
|
|
|
|
func modTimes(home string) map[string]time.Time {
|
|
m := map[string]time.Time{}
|
|
filepath.WalkDir(home, func(p string, e os.DirEntry, err error) error {
|
|
if err == nil && !e.IsDir() {
|
|
if fi, err := e.Info(); err == nil {
|
|
rel, _ := filepath.Rel(home, p)
|
|
m[rel] = fi.ModTime()
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
return m
|
|
}
|
|
|
|
// Every agent magpie writes into a TOML, YAML or dotenv config gets a
|
|
// comment line over each line that points at the gateway, saying magpie
|
|
// wrote it and how to undo it: Jevik_AI on X deleted magpie's folders by hand and
|
|
// was left with a Codex config naming a gateway that no longer ran, and
|
|
// nothing in it naming magpie. Disconnect takes each note with its line.
|
|
func TestMarkedLinesEveryAgent(t *testing.T) {
|
|
home, _ := codexHome(t, "", "")
|
|
edit.Mark = lineNote
|
|
t.Cleanup(func() { edit.Mark = nil })
|
|
managed := claudeManaged
|
|
claudeManaged = func() string { return filepath.Join(home, "managed-settings.json") }
|
|
t.Cleanup(func() { claudeManaged = managed })
|
|
startAlma(t)
|
|
startShelley(t)
|
|
host := strings.TrimPrefix(gateway.URL(), "http://")
|
|
var marked []string
|
|
for _, a := range All() {
|
|
if a.Launch != nil || a.Native != nil || a.WSL != "" || len(a.Fields) == 0 {
|
|
continue
|
|
}
|
|
t.Run(a.ID, func(t *testing.T) {
|
|
if _, err := a.ConnectHow(); err != nil {
|
|
t.Skip("can't be connected here:", err)
|
|
}
|
|
if !a.Wired() {
|
|
t.Skip("not wired by Connect here")
|
|
}
|
|
// a note is read back as written: a sync doesn't write the
|
|
// file again and again, as one that compared a line with the
|
|
// one it would write did (dsh's routes)
|
|
SyncCatalog()
|
|
dshWiredOnce()
|
|
synced, when := agentFiles(t, home), modTimes(home)
|
|
SyncCatalog()
|
|
dshWiredOnce()
|
|
later := modTimes(home)
|
|
for p, b := range agentFiles(t, home) {
|
|
if synced[p] != b {
|
|
t.Errorf("a second sync changed %s:\n--- first\n%s\n--- second\n%s", p, synced[p], b)
|
|
} else if commentable(p) && !when[p].Equal(later[p]) && !rewrittenEachSync[a.ID] {
|
|
t.Errorf("a second sync wrote %s again", p)
|
|
}
|
|
}
|
|
for p, b := range agentFiles(t, home) {
|
|
if !commentable(p) {
|
|
continue
|
|
}
|
|
lines := strings.Split(b, "\n")
|
|
for i, l := range lines {
|
|
if strings.Contains(l, "# "+edit.MarkTag) {
|
|
marked = append(marked, a.ID)
|
|
// a line of its own: Grok App reads the rest of
|
|
// a line as its value
|
|
if !edit.IsNote(l) {
|
|
t.Errorf("%s: a note beside a value: %q", p, l)
|
|
}
|
|
}
|
|
above := i > 0 && edit.IsNote(lines[i-1])
|
|
// a scalar on its own line; an inline table or a list
|
|
// can't carry a note of its own
|
|
if !strings.Contains(l, host) || edit.IsNote(l) || above || strings.HasPrefix(strings.TrimSpace(l), "- ") || strings.Contains(l, "= {") || strings.Contains(l, "= [") {
|
|
continue
|
|
}
|
|
t.Errorf("%s: a line on the gateway without a note: %q", p, l)
|
|
}
|
|
}
|
|
if err := a.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for p, b := range agentFiles(t, home) {
|
|
for _, l := range strings.Split(b, "\n") {
|
|
if strings.Contains(l, "# "+edit.MarkTag) && !strings.Contains(l, "Codex threads started on magpie") {
|
|
t.Errorf("%s: a note outlived Disconnect: %q", p, l)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
if !slices.Contains(marked, "codex") {
|
|
t.Fatal("Codex's config.toml got no note")
|
|
}
|
|
}
|
|
|
|
// Codex's own keys that name magpie get a note on how to undo them by
|
|
// hand, not only the base URL.
|
|
func TestCodexMarkedLines(t *testing.T) {
|
|
codexHome(t, "", "model = \"gpt-5.5\"\n")
|
|
edit.Mark = lineNote
|
|
t.Cleanup(func() { edit.Mark = nil })
|
|
a, _ := Find("codex")
|
|
if _, err := a.ConnectHow(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, _ := os.ReadFile(a.Path)
|
|
got := string(b)
|
|
for _, want := range []string{
|
|
"# magpie: Codex on magpie's local gateway; Disconnect in magpie or `magpie uninstall` undoes it, or delete this line and the model line\nmodel_provider = \"magpie\"\n",
|
|
"# magpie: magpie's model list for Codex; " + undo + ", or delete this line\nmodel_catalog_json = ",
|
|
"# magpie: for Codex threads started on magpie; unused while model_provider doesn't name magpie\nbase_url = \"" + gateway.URL() + "/v1\"\n",
|
|
} {
|
|
if !strings.Contains(got, want) {
|
|
t.Errorf("missing %q in:\n%s", want, got)
|
|
}
|
|
}
|
|
if err := a.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, _ = os.ReadFile(a.Path)
|
|
if !strings.HasPrefix(string(b), "model = \"gpt-5.5\"\n") {
|
|
t.Fatalf("after Disconnect:\n%s", b)
|
|
}
|
|
}
|