wani on Discord (#feedback) asked for Zoo Code (zoocode.dev), a fork of Roo Code for VS Code and JetBrains. Route: Zoo Code keeps its provider profiles in VS Code's SecretStorage, which magpie can't write. The one file it reads is the one its zoo-code.autoImportSettingsPath setting names. On every activation (src/utils/autoImportSettings.ts, Zoo Code 3.90.0) it imports that file as Settings → Import does (importSettingsFromPath). magpie writes <User>/globalStorage/zoocodeorganization.zoo-code/settings/magpie-import.json with one profile, "magpie": apiProvider openai on the gateway's /v1 Chat Completions, key magpie-zoo-code, the chosen model, and an openAiCustomModelInfo built from the catalog (contextWindow, else Zoo's own 128000 default; maxTokens only when an output limit is known). It points the setting at that file in the default settings.json and in each VS Code profile's. A value the user set themselves is stashed and restored by Disconnect. The file sits outside magpie's folder so that a sync keeps an address the user moved (kept.away skips magpie's own folder). Requests say "ZooCode/<version>", and usage names them zoo-code. Limits (also in docs/reference.md → Zoo Code): - Zoo reads the file only at start: the notice asks for Developer: Reload Window. - While connected, each start switches Zoo back to the magpie profile. - Disconnect stops the import but can't delete the imported profile from SecretStorage. The user switches away from it or deletes it in Zoo. - VS Code Stable only. JetBrains is not wired. Zoo Code for JetBrains runs the extension in its own extension host, which is handed an empty configuration on every start (RPCManager.startInitialize in Zoo-Code-JetBrains), so the setting never reaches it. Its secrets sit in ~/.zoo-code/secrets.json, an internal store with no lock and no documented format. Neither is a clean route. Tests (internal/agent/zoocode_test.go): - TestZooCode: connect, model switch, a stale key that Check reports and Sync fixes, and disconnect putting the user's own import path back byte for byte with the file removed. - TestZooCodeFresh and TestZooCodeProfiles: VS Code profiles, including one made after connecting. - TestZooCodeDetectAndUA: Roo alone is not detected; ZooCode/3.90.0 maps to zoo-code. Broken by hand (the restore disabled): TestZooCode and TestZooCodeProfiles went red. The generated file was checked with bun against Zoo's own zod schemas (providerSettingsWithIdSchema, isProviderName; zod 4.6.7 from its repo): valid, every field kept, current profile in apiConfigs. Run, set -o pipefail, GOMODCACHE pinned, sandbox HOME: - First full run, with this change onba319a758at 49bec8c4f: - gofmt -l clean. - go vet darwin, GOOS=linux -tags nogui and GOOS=windows: clean. - go test -timeout 45m ./...: 67 packages ok, including gateway 2543s, gui 509s and library 2326s. - internal/agent was red: TestSyncKeepsAnAddressOnAnotherMachine. The import file was then in magpie's folder, which kept.away skips, so a NAS address was lost. The file was moved into Zoo's globalStorage folder. The package also hit the 45m deadline under load (#2544). - After the fix: -run 'ZooCode|TestSyncKeepsAnAddressOnAnotherMachine| TestReverseProxyIsStillMagpie' ./internal/agent was ok in 112.9s. - At 0aa9c53ce: gofmt -l clean, internal/agent vet clean three ways, and go test -timeout 90m ./internal/agent ./internal/library ./internal/gui ok (agent 1912s, library 1299s, gui 420s). - GUI suite in both engines: 283/283 in chromium and 283/283 in webkit (playwright 1.62.0). It covers the 44 files the change can reach: gui-de, gui-ja, gui-zh-tw, i18n-keys, agent-notice-lang, models-add-and-icons, mono-icon-redraw and every agent-*. After rebasing onto origin/main049040283(which changed internal/agent/claude.go): - go vet ./internal/agent clean three ways; linux nogui and windows builds ok. - -run 'ZooCode|Compact|TestSyncKeepsAnAddressOnAnotherMachine|UserAgent|AgentOf' ./internal/agent ok in 35.9s. - The darwin go build of the binary hit a full disk at link (this machine's, 369M free), not a code error. Not tried: real VS Code (not installed on this machine), Windows and Linux.
193 lines
7.4 KiB
Go
193 lines
7.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/tidwall/gjson"
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/usage"
|
|
)
|
|
|
|
// zooCodeHere is Zoo Code in a VS Code User folder under home, the
|
|
// extension installed as the Marketplace installs it.
|
|
func zooCodeHere(t *testing.T, home string) (*Agent, string) {
|
|
t.Helper()
|
|
dir := filepath.Join(home, "vscode", "User")
|
|
exts := filepath.Join(home, ".vscode", "extensions")
|
|
writeFile(t, filepath.Join(exts, "zoocodeorganization.zoo-code-3.90.0", "package.json"), `{"name":"zoo-code","version":"3.90.0"}`)
|
|
return zooCodeAt(dir, exts), dir
|
|
}
|
|
|
|
// switched on, magpie's file is what zoo-code.autoImportSettingsPath names,
|
|
// in the shape Zoo Code's importSettingsFromPath takes, its profile on the
|
|
// gateway with Zoo Code's key; switched off, settings.json is as it was,
|
|
// the user's own import path back, and magpie's file gone
|
|
func TestZooCode(t *testing.T) {
|
|
home := syncHome(t)
|
|
a, _ := zooCodeHere(t, home)
|
|
settings := `{
|
|
// my editor
|
|
"editor.fontSize": 14,
|
|
"zoo-code.autoImportSettingsPath": "~/zoo-team.json",
|
|
}
|
|
`
|
|
writeFile(t, a.Path, settings)
|
|
f := a.Field("model")
|
|
if !a.Detected() || a.Wired() || f.Get() != "" || a.Notice() != "" {
|
|
t.Fatalf("before: %v %v %q", a.Detected(), a.Wired(), f.Get())
|
|
}
|
|
if err := a.Connect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
file := zooCodeImportPath(filepath.Dir(a.Path))
|
|
if f.Get() != "magpie/relay/glm-4.6" || !a.Wired() || a.Check() != "" || a.Notice() == "" {
|
|
t.Fatalf("connected: %q %v %q %q", f.Get(), a.Wired(), a.Check(), a.Notice())
|
|
}
|
|
if v, _ := edit.GetJSON(a.Path, zooImport); v != file {
|
|
t.Fatalf("import path %q, want %q\n%s", v, file, readFile(a.Path))
|
|
}
|
|
for _, keep := range []string{"// my editor", `"editor.fontSize": 14`} {
|
|
if !strings.Contains(readFile(a.Path), keep) {
|
|
t.Fatalf("settings lost %q:\n%s", keep, readFile(a.Path))
|
|
}
|
|
}
|
|
b := readFile(file)
|
|
if !gjson.Valid(b) {
|
|
t.Fatalf("not JSON:\n%s", b)
|
|
}
|
|
// what providerProfilesSchema and the openai provider's schema need:
|
|
// a current profile that is one of apiConfigs, and a modelInfo with
|
|
// contextWindow and supportsPromptCache
|
|
for k, want := range map[string]string{
|
|
"providerProfiles.currentApiConfigName": "magpie",
|
|
"providerProfiles.apiConfigs.magpie.apiProvider": "openai",
|
|
"providerProfiles.apiConfigs.magpie.openAiBaseUrl": gatewayV1(),
|
|
"providerProfiles.apiConfigs.magpie.openAiApiKey": agentKey("zoo-code"),
|
|
"providerProfiles.apiConfigs.magpie.openAiModelId": "relay/glm-4.6",
|
|
"providerProfiles.apiConfigs.magpie.openAiCustomModelInfo.contextWindow": "204800",
|
|
"providerProfiles.apiConfigs.magpie.openAiCustomModelInfo.supportsPromptCache": "false",
|
|
} {
|
|
if got := gjson.Get(b, k).String(); got != want {
|
|
t.Errorf("%s = %q, want %q", k, got, want)
|
|
}
|
|
}
|
|
if gjson.Get(b, "globalSettings").Exists() {
|
|
t.Fatalf("magpie's import sets Zoo Code's own settings:\n%s", b)
|
|
}
|
|
// the catalog gives glm-4.6 no output limit: Zoo Code's own default
|
|
// stands, not a 0 that would cap every reply
|
|
if r := gjson.Get(b, "providerProfiles.apiConfigs.magpie.openAiCustomModelInfo.maxTokens"); r.Exists() {
|
|
t.Fatalf("maxTokens %s with no output limit known", r.Raw)
|
|
}
|
|
|
|
// another model: the file follows, the setting stays magpie's
|
|
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"glm-4.6", "other"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Apply("model", "magpie/relay/other"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if f.Get() != "magpie/relay/other" {
|
|
t.Fatalf("other: %q\n%s", f.Get(), readFile(file))
|
|
}
|
|
|
|
// the key in the file written over: Sync writes it again, as Zoo Code
|
|
// reads the file on each start
|
|
writeFile(t, file, strings.ReplaceAll(readFile(file), agentKey("zoo-code"), "stale"))
|
|
if c := a.Check(); !strings.Contains(c, "magpie-import.json") {
|
|
t.Fatalf("check: %q", c)
|
|
}
|
|
if err := a.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if c := a.Check(); c != "" {
|
|
t.Fatalf("synced, check: %q\n%s", c, readFile(file))
|
|
}
|
|
|
|
if err := a.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if readFile(a.Path) != settings || a.Wired() || f.Get() != "" {
|
|
t.Fatalf("disconnected: %v %q\n%s", a.Wired(), f.Get(), readFile(a.Path))
|
|
}
|
|
if _, err := os.Stat(file); !os.IsNotExist(err) {
|
|
t.Fatalf("magpie's import file left: %v", err)
|
|
}
|
|
}
|
|
|
|
// with no settings.json: made, and emptied of magpie's setting again
|
|
func TestZooCodeFresh(t *testing.T) {
|
|
home := syncHome(t)
|
|
a, _ := zooCodeHere(t, home)
|
|
if err := a.Connect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if a.Field("model").Get() != "magpie/relay/glm-4.6" || a.Check() != "" {
|
|
t.Fatalf("fresh: %q\n%s", a.Field("model").Get(), readFile(a.Path))
|
|
}
|
|
if err := a.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, ok := edit.GetJSON(a.Path, zooImport); ok || a.Wired() {
|
|
t.Fatalf("disconnected: %q\n%s", v, readFile(a.Path))
|
|
}
|
|
}
|
|
|
|
// a VS Code profile reads its own settings.json: the setting goes in each
|
|
// profile's, one made later is given it on Sync, and each is put back
|
|
func TestZooCodeProfiles(t *testing.T) {
|
|
home := syncHome(t)
|
|
a, dir := zooCodeHere(t, home)
|
|
work := filepath.Join(dir, "profiles", "-5f1c2a")
|
|
writeFile(t, filepath.Join(dir, "globalStorage", "storage.json"), `{"userDataProfiles": [{"location": "-5f1c2a", "name": "Work"}]}`)
|
|
workSettings := "{\n\t// work\n\t\"zoo-code.autoImportSettingsPath\": \"/srv/zoo.json\"\n}\n"
|
|
writeFile(t, filepath.Join(work, "settings.json"), workSettings)
|
|
if err := a.Connect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := edit.GetJSON(filepath.Join(work, "settings.json"), zooImport); v != zooCodeImportPath(dir) {
|
|
t.Fatalf("work profile's import path %q", v)
|
|
}
|
|
writeFile(t, filepath.Join(dir, "globalStorage", "storage.json"), `{"userDataProfiles": [{"location": "-5f1c2a", "name": "Work"}, {"location": "new1", "name": "New"}]}`)
|
|
writeFile(t, filepath.Join(dir, "profiles", "new1", "keybindings.json"), "[]\n")
|
|
if err := a.Sync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
newSettings := filepath.Join(dir, "profiles", "new1", "settings.json")
|
|
if v, _ := edit.GetJSON(newSettings, zooImport); v != zooCodeImportPath(dir) {
|
|
t.Fatalf("new profile's import path %q", v)
|
|
}
|
|
if err := a.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if readFile(filepath.Join(work, "settings.json")) != workSettings {
|
|
t.Fatalf("work profile not as it was:\n%s", readFile(filepath.Join(work, "settings.json")))
|
|
}
|
|
if _, ok := edit.GetJSON(newSettings, zooImport); ok {
|
|
t.Fatalf("new profile kept magpie's import path:\n%s", readFile(newSettings))
|
|
}
|
|
}
|
|
|
|
// listed only with the extension installed; its requests name it
|
|
func TestZooCodeDetectAndUA(t *testing.T) {
|
|
home := syncHome(t)
|
|
dir := filepath.Join(home, "vscode", "User")
|
|
writeFile(t, filepath.Join(dir, "settings.json"), "{}\n")
|
|
exts := filepath.Join(home, ".vscode", "extensions")
|
|
writeFile(t, filepath.Join(exts, "rooveterinaryinc.roo-cline-3.30.0", "package.json"), "{}")
|
|
if zooCodeAt(dir, exts).Detected() {
|
|
t.Fatal("detected without Zoo Code installed")
|
|
}
|
|
writeFile(t, filepath.Join(exts, "zoocodeorganization.zoo-code-3.90.0", "package.json"), "{}")
|
|
if !zooCodeAt(dir, exts).Detected() {
|
|
t.Fatal("not detected with Zoo Code installed")
|
|
}
|
|
if got := usage.AgentOf("ZooCode/3.90.0"); got != "zoo-code" {
|
|
t.Fatalf("AgentOf = %q", got)
|
|
}
|
|
}
|