The owner (11-12): Memory should have its own icon, a brain. The Library's Memory tab had a bookmark, and Memory's own requests (the conversations it reads into memories, made as memdistill.Agent "memory") were drawn in Routing's graph, Usage and Sessions with the generic cube under their raw id, since "memory" was no client. - icons/memory.svg: a brain, 16-grid, stroke 1.4 with round caps and joins, as the sidebar's marks are; drawn as a one-tone mask. - navicons.js: the Library's Memory tab draws the same path. - agent.others: a client "memory", named Memory, with that icon, so /api/state's clients and agent.Looks (Usage, Sessions) name and draw it. It has no User-Agent: its requests are known by their token. - TestEveryClientHasNameAndIcon: memdistill.Agent is among the ids the gateway records, so it must be a client with a real icon. - tests/memory-icon.test.cjs: the sidebar's Memory tab draws the path icons/memory.svg has (and no other tab does), and a request from "memory" in Routing is drawn with the memory mask, not the cube. Chromium and WebKit, en/zh/zh-TW/ja/de, 1100 and 420px (no sidebar at 420px, so there the request only). Run on the tree rebased ontoff8b43711(same five-file diff; the go packages and the four GUI files first ran atfa7e466acand again here: TestEveryClientHasNameAndIcon ok, 42 of 42) (mote; mote was at load ~27 and mica ~43, mote was the less loaded): - go test ./internal/agent ./internal/gui ./internal/memdistill ./internal/usageapi: ok. - node --test memory-icon nav-sub-icons routing-client-icons i18n-keys: 42 of 42 ok, both engines. - go vet: darwin agent+gui; GOOS=linux agent (gui needs cgo for wails on linux); GOOS=windows agent+gui: ok. gofmt -l clean. Broken by hand (origin/mainfa7e466acwith the new tests): - TestEveryClientHasNameAndIcon: "the gateway records requests as memory, which isn't among the clients". - memory-icon.test.cjs with no icons/memory.svg: 2 of 2 red; with the svg but the old bookmark path: 12 of 22 red, every 1100px case. Not tried: the real app on any OS; Codex's own memories model row (MEMORIES in app.js) keeps its notebook, as it is Codex's memories, not Magpie Memory. The Magpie Memory MCP server keeps magpie's favicon, as magpie's other servers do.
87 lines
3.4 KiB
Go
87 lines
3.4 KiB
Go
package gui
|
|
|
|
import (
|
|
"os"
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/agent"
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
"github.com/yetone/magpie/internal/memdistill"
|
|
)
|
|
|
|
// genericIcon are the clients magpie has no logo for yet, drawn with the
|
|
// generic cube on purpose (#4487). Each leaves this list when its real
|
|
// logo, from the app or its vendor, is added.
|
|
var genericIcon = map[string]bool{"ante": true, "pencil": true, "paseo": true, "openpencil": true, "newmax": true, "kirocrew": true, "raft": true}
|
|
|
|
// Every client a request can be recorded as is drawn by its own name and
|
|
// icon in the Routing page's request list, Usage and Sessions, which all
|
|
// look the request's client up in /api/state's clients (agent.Clients):
|
|
// one not there shows its raw id and the cube (jiabubu on Discord:
|
|
// kimi-code-cli and kimi-code-desktop). This holds the table to the ids
|
|
// the gateway records, and each entry's icon to a file app.js's icon()
|
|
// loads: a PNG only when pngIcons names it, else an SVG.
|
|
func TestEveryClientHasNameAndIcon(t *testing.T) {
|
|
js, err := os.ReadFile("assets/app.js")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m := regexp.MustCompile(`const pngIcons = new Set\(\[([^\]]*)\]\)`).FindSubmatch(js)
|
|
if m == nil {
|
|
t.Fatal("app.js's pngIcons isn't found")
|
|
}
|
|
png := map[string]bool{}
|
|
for _, q := range regexp.MustCompile(`"([^"]+)"`).FindAllSubmatch(m[1], -1) {
|
|
png[string(q[1])] = true
|
|
}
|
|
exists := func(f string) bool { _, err := os.Stat("assets/icons/" + f); return err == nil }
|
|
|
|
clients := map[string]bool{}
|
|
for _, a := range agent.Clients() {
|
|
clients[a.ID] = true
|
|
if strings.TrimSpace(a.Name) == "" {
|
|
t.Errorf("%s has no name", a.ID)
|
|
}
|
|
switch {
|
|
case a.Icon == "generic":
|
|
if !genericIcon[a.ID] {
|
|
t.Errorf("%s is drawn with the generic cube: give it its real logo", a.ID)
|
|
}
|
|
case a.Icon == "" || strings.HasPrefix(a.Icon, "file:") || strings.ContainsAny(a.Icon, ":/"):
|
|
t.Errorf("%s's icon %q isn't one of magpie's", a.ID, a.Icon)
|
|
case png[a.Icon]:
|
|
if !exists(a.Icon + ".png") {
|
|
t.Errorf("%s's icon: pngIcons names %s, with no icons/%[2]s.png", a.ID, a.Icon)
|
|
}
|
|
case exists(a.Icon+".svg") && !strings.HasSuffix(a.Icon, "-color"):
|
|
// an SVG without -color is drawn as a mask: one tone, its
|
|
// shape. A logo that is a filled tile (OpenMausBot's black
|
|
// square with a silver cursor) turns into a plain black square.
|
|
b, _ := os.ReadFile("assets/icons/" + a.Icon + ".svg")
|
|
if strings.Contains(string(b), "Gradient") {
|
|
t.Errorf("%s's icon %s has its own colours but isn't named -color, so it is drawn as one-tone mask", a.ID, a.Icon)
|
|
}
|
|
case !exists(a.Icon + ".svg"):
|
|
if exists(a.Icon + ".png") {
|
|
t.Errorf("%s's icon %s is a PNG app.js's pngIcons doesn't name, so it is drawn as the cube", a.ID, a.Icon)
|
|
} else {
|
|
t.Errorf("%s's icon %s has no file in icons/", a.ID, a.Icon)
|
|
}
|
|
}
|
|
}
|
|
for id := range genericIcon {
|
|
if !clients[id] {
|
|
t.Errorf("genericIcon names %s, which is no client", id)
|
|
}
|
|
}
|
|
// the ids the gateway gives a request by more than its User-Agent
|
|
// (gateway.agentOf), and those it names by one: each is a client
|
|
for _, id := range []string{"claude-desktop", gateway.ScienceID, "cursor-local", "codex", "magpie", "kimi", "kimi-code-desktop", memdistill.Agent} {
|
|
if !clients[id] {
|
|
t.Errorf("the gateway records requests as %s, which isn't among the clients", id)
|
|
}
|
|
}
|
|
}
|