diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index d27da74ef..8c1099ca3 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -14,6 +14,7 @@ something else shows up as drift. | --- | --- | --- | | Agent description | `Agent` has an id, name, icon, `Bin` and `Dir` for detection, `Path`, `Fields` and `Native`. It also has optional hooks: `Notice`, `UA`, `ListsModels`, `Sync`, `Unwire`, `Join`/`Joined`, `Routed`, `Follow`, `RenameRefs`, `Check`, `LastUsed`, `Reached`, `Import`/`Added`, `Launch`, `SplitSuffix`, `Spelled` and `ModelAliases`. Each hook's comment says which agents need it. | [`agent.go`](../../internal/agent/agent.go) | | Fields and options | A `Field` has `Get`, `Set` and `Options`. `Set("")` returns the field to the agent's default and takes magpie's wiring out. `Quiet` fields follow another field until set (`Follows`, such as Claude Code's tiers). An `Option` carries the picker's facts: `Direct`, `Via`, `Same`, `Alias`, `Rate` and `Context`. The GUI's and TUI's pickers list `Agent.Picks`: with the agent in settings' `ownModelsHidden` (the switch at the top of its model list, #1642), a field that offers catalog models (`Ref`) leaves out the agent's own (no `Ref`), but for its default and the value it is set to. The CLI still takes an own model by name. | [`agent.go`](../../internal/agent/agent.go), [`route.go`](../../internal/agent/route.go) | +| The agent's own telemetry | `Agent.Telemetry` (`Get`, `Set`) is the agent's documented switch for the usage data it sends its vendor: Codex's `[analytics] enabled = false`, Claude Code's env `DISABLE_TELEMETRY` and `DISABLE_ERROR_REPORTING`, Gemini CLI's and Qwen Code's `privacy.usageStatisticsEnabled = false` (OipsAnthony on X). It is not a `Field`, so profiles never carry it and Unwire leaves it. Off writes only keys the file lacks and records them in the stash (`.telemetry`); a key the user set on refuses Off, naming it, and one they set off stays. On takes out only what magpie wrote and still holds magpie's value. An unreadable file is unknown: the row says so and can't be pressed. Offered for an agent on this computer only, never a WSL distro's (#3896). The GUI row is `telemetryRow` in the agent's Settings; the route is `POST /api/agents/telemetry/{id}`. | [`telemetry.go`](../../internal/agent/telemetry.go), [`api.go`](../../internal/gui/api.go) | | The list of agents | `All` lists every agent magpie knows, then the WSL agents (`wslAgents`). `Clients` lists every agent whose requests the gateway knows by name, which `usage.Agents` reads. One file per agent: `claude.go`, `codex.go`, `opencode` in `agents.go`, and so on. | [`agents.go`](../../internal/agent/agents.go) | | Connect | `ConnectHow` picks the model an agent starts on and reports how. `How` is one of: `kept`, `again`, `joined`, `magpie`, `same`, `alike`, `default` or `first` (#726). With no models to give, it returns `NoModelsError` (code `no_models`). | [`applied.go`](../../internal/agent/applied.go) | | What magpie set | `Apply` sets a field and records it in `applied.json`. `Wired` says whether magpie is in the config. `Drift` reports `unwired`, `replaced`, `unreachable`, `proxied` or `bypassed`. `Reapply` sets the record again. `Keep` accepts the config as it is now, and keeps the agent connected (`applied.Kept`). An agent whose magpie is a provider of its own config (`Spelled`, not `Native`) is connected only when magpie set it up (`setUp`: a record, `Kept`, or a `.connect.was` stash). A provider named magpie the user wrote by hand (`handWired`) is theirs: it isn't `Wired`, has no `Drift`, and neither `SyncCatalog`, `RenameProvider` nor `Disconnect` writes it; connecting in magpie takes it on (JFunfunfun on X, Pi on `magpie/`; `TestPiHandWiredMagpieProviderIsTheirs`, `TestPiConnectedBeforeStaysConnected`, `TestHandWiredMagpieProviderSiblings`). | [`applied.go`](../../internal/agent/applied.go) | diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 16b75480b..23517db96 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -315,6 +315,10 @@ type Agent struct { // is the model's on the command line: magpie claude opus sets the // model, where another field's name alone shows that field. ModelAliases []string + // Telemetry, when set, turns the agent's own telemetry to its vendor + // off in its config (telemetry.go). It is not a field: a profile + // saved before would turn it back on. + Telemetry *Telemetry // detect, when set, says whether the agent is here in place of looking // for its files and binary: a distro's, probed once. detect func() bool diff --git a/internal/agent/claude.go b/internal/agent/claude.go index 3d989fced..da2c1ebf2 100644 --- a/internal/agent/claude.go +++ b/internal/agent/claude.go @@ -2265,6 +2265,7 @@ func claudeIn(at place) *Agent { Bin: "claude", Dir: filepath.Dir(path), Path: path, Fields: fields, ModelAliases: claudeAliases, + Telemetry: claudeTelemetry(at, path), // Claude Code as it was before magpie: its default puts it back as // installed, on Anthropic's endpoint, where this brings back the // endpoint, token and model the user had diff --git a/internal/agent/codex.go b/internal/agent/codex.go index 095f83c2b..c8dac0356 100644 --- a/internal/agent/codex.go +++ b/internal/agent/codex.go @@ -167,6 +167,7 @@ type codexTop struct { Desktop any `toml:"desktop"` Profile any `toml:"profile"` Profiles any `toml:"profiles"` + Analytics any `toml:"analytics"` } // codexTopOf is the config at path as codexTop, decoded again only once the @@ -1854,7 +1855,8 @@ func codexIn(at place) *Agent { a := atomic(&Agent{ ID: "codex", Name: "Codex", Icon: "codex-color", Bin: "codex", Dir: dir, Path: path, - UA: []string{"codex", "acp-extension-codex"}, // The ACP adapter's default client name becomes Codex's originator. + Telemetry: codexTelemetry(at, path), + UA: []string{"codex", "acp-extension-codex"}, // The ACP adapter's default client name becomes Codex's originator. // Codex as it was before magpie: its default puts it back as // installed, OpenAI and its default model, where this brings back // the provider and model the user had diff --git a/internal/agent/gemini.go b/internal/agent/gemini.go index 7d9126330..ba09fd591 100644 --- a/internal/agent/gemini.go +++ b/internal/agent/gemini.go @@ -185,6 +185,7 @@ func geminiIn(at place) *Agent { ID: "gemini", Name: "Gemini CLI", Icon: "geminicli-color", Aliases: []string{"gemini-cli"}, NoNames: true, UA: []string{"geminicli", "gemini-cli"}, Bin: "gemini", Dir: dir, Path: path, + Telemetry: usageStatsTelemetry(at, path, "gemini"), // its model's default forgets what it had before magpie, its // sign-in's default forgets the sign-in: this puts both back Unwire: unroute, diff --git a/internal/agent/qwen.go b/internal/agent/qwen.go index 9aa1b997f..3578b0109 100644 --- a/internal/agent/qwen.go +++ b/internal/agent/qwen.go @@ -318,7 +318,8 @@ func qwenIn(at place) *Agent { // openaiContentGenerator/provider/default.ts buildHeaders) UA: []string{"qwencode"}, Bin: "qwen", Dir: dir, Path: path, - ListOnly: true, + ListOnly: true, + Telemetry: usageStatsTelemetry(at, path, "qwen"), Sync: func() error { for _, c := range qwenCustoms(path) { if c.ours { diff --git a/internal/agent/telemetry.go b/internal/agent/telemetry.go new file mode 100644 index 000000000..4e4c3bd9c --- /dev/null +++ b/internal/agent/telemetry.go @@ -0,0 +1,328 @@ +package agent + +// An agent's own telemetry, off (OipsAnthony on X: "agent 管理页面支持给每个 +// agent 关闭遥测功能"). An agent with a documented switch for the usage data +// it sends its vendor has it in its settings on the Agents page, which +// writes that switch into the agent's own config. Only agents whose key was +// read in their source or binary: +// +// - Codex: [analytics] enabled = false in config.toml. "When false, +// disables OpenAI analytics across Codex product surfaces"; the default +// statsig metrics exporter follows it (AnalyticsConfigToml and +// OtelConfigToml in codex-rs/config/src/types.rs, rust-v0.167.0). +// feedback.enabled is left alone: it takes /feedback away, which only +// sends when the user asks. +// - Claude Code: env DISABLE_TELEMETRY and DISABLE_ERROR_REPORTING in +// settings.json. 2.1.316 takes any value of DISABLE_TELEMETRY as its +// "no-telemetry" level, from any settings tier, and any value of +// DISABLE_ERROR_REPORTING keeps its error reports in. +// CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC would also stop its updates, +// which is no telemetry. +// - Gemini CLI and Qwen Code: privacy.usageStatisticsEnabled = false in +// settings.json (settingsSchema.ts of each, default true). +// +// None is written unless the user turns it off here. Off writes each key +// the file doesn't have and remembers it in the stash; a key the user has +// already written is theirs: one that already turns telemetry off is left +// as it is, and one that keeps it on is never written over (off is +// refused, naming it). On takes out only what magpie wrote, as magpie +// wrote it. Connecting or disconnecting the agent leaves it alone: it is +// about the agent's vendor, not about magpie. +// +// Only an agent on this computer has it: a WSL distro's file isn't read on +// each look, which would start a stopped distro (#3896). + +import ( + "encoding/json" + "errors" + "fmt" + "io/fs" + "strings" + + "github.com/tidwall/jsonc" + + "github.com/yetone/magpie/internal/edit" + "github.com/yetone/magpie/internal/filememo" +) + +// TelemetryState is an agent's telemetry as its config has it. +type TelemetryState struct { + // Off: every key of the switch turns telemetry off + Off bool `json:"off"` + // Own: keys the user wrote that keep it off, which on leaves in + Own []string `json:"own,omitempty"` + // Keys: what the switch writes, as the file spells it + Keys []string `json:"keys"` + // File: the config it writes + File string `json:"file"` + // Error: why the config couldn't be read, when it couldn't (the + // state is then unknown) + Error string `json:"error,omitempty"` +} + +// Telemetry is an agent's switch for its own telemetry. +type Telemetry struct { + Get func() (TelemetryState, error) + Set func(off bool) error +} + +// telemetryKey is one key of a switch: name as the file spells it (a +// dotted path in JSON; "table.key" in TOML), value what magpie writes, off +// whether a value the file has keeps telemetry off. +type telemetryKey struct { + name string + value any + off func(v any) bool +} + +// telemetryFile reads and writes one key of the agent's config. get says +// whether the key is there, and fails on a file that doesn't parse (which +// is unknown, never "not there"). +type telemetryFile struct { + path string + get func(k telemetryKey) (v any, has bool, err error) + set func(k telemetryKey) error + del func(k telemetryKey) error +} + +func isFalse(v any) bool { return v == false } + +// anyValue: an environment variable that is set, to anything but empty +func anyValue(v any) bool { + switch x := v.(type) { + case string: + return x != "" + case nil: + return false + } + return true +} + +// telemetrySwitch is the switch over keys in f; stashKey is where what +// magpie wrote is kept. +func telemetrySwitch(at place, f telemetryFile, stashKey string, keys ...telemetryKey) *Telemetry { + if at.spell != nil || at.cold { + return nil + } + names := make([]string, len(keys)) + for i, k := range keys { + names[i] = k.name + } + wrote := func() map[string]bool { + out := map[string]bool{} + for _, n := range strings.Split(stashShared()[stashKey], ",") { + if n != "" { + out[n] = true + } + } + return out + } + keep := func(m map[string]bool) { + var out []string + for _, n := range names { + if m[n] { + out = append(out, n) + } + } + stash(map[string]string{stashKey: strings.Join(out, ",")}) + } + ours := func(k telemetryKey, v any) bool { + a, _ := json.Marshal(v) + b, _ := json.Marshal(k.value) + return string(a) == string(b) + } + get := func() (TelemetryState, error) { + st := TelemetryState{Off: true, Keys: names, File: at.native(f.path)} + mine := wrote() + for _, k := range keys { + v, has, err := f.get(k) + if err != nil { + return TelemetryState{Keys: names, File: st.File}, err + } + if !has || !k.off(v) { + st.Off = false + continue + } + if !(mine[k.name] && ours(k, v)) { + st.Own = append(st.Own, k.name) + } + } + return st, nil + } + set := func(off bool) error { + mine := wrote() + if off { + // every key read first: one the user set on stops it before + // anything is written + var missing []telemetryKey + for _, k := range keys { + v, has, err := f.get(k) + if err != nil { + return err + } + switch { + case !has: + missing = append(missing, k) + case !k.off(v): + b, _ := json.Marshal(v) + return fmt.Errorf("%s sets %s to %s; magpie leaves a value of yours as it is (change it there)", at.native(f.path), k.name, b) + case !ours(k, v): + delete(mine, k.name) // the user's, as it is now + } + } + for _, k := range missing { + if err := f.set(k); err != nil { + keep(mine) + return err + } + mine[k.name] = true + } + keep(mine) + return nil + } + for _, k := range keys { + if !mine[k.name] { + continue + } + v, has, err := f.get(k) + if err != nil { + return err + } + // changed since: the user's now + if has && ours(k, v) { + if err := f.del(k); err != nil { + keep(mine) + return err + } + } + delete(mine, k.name) + } + keep(mine) + return nil + } + // a change that fails part way puts the file back as it was + write := func(off bool) error { + if err := edit.Atomically(func() error { return set(off) }, f.path); err != nil || off { + return err + } + st, err := get() + if err != nil { + return err + } + if st.Off { + return fmt.Errorf("%s turns it off itself (%s); magpie leaves a value of yours as it is (take it out there)", at.native(f.path), strings.Join(st.Own, ", ")) + } + return nil + } + return &Telemetry{Get: get, Set: write} +} + +// jsonTelemetryFile is a JSON or JSONC config's keys, by dotted path. +func jsonTelemetryFile(path string) telemetryFile { + return telemetryFile{ + path: path, + get: func(k telemetryKey) (any, bool, error) { + // read again only once the file changes: the Agents page asks + // on each poll + doc, err := filememo.ReadNow("telemetry json", path, func(raw []byte) (any, error) { + b := jsonc.ToJSON(edit.TrimBOM(raw)) + if len(strings.TrimSpace(string(b))) == 0 { + return nil, nil + } + var doc any + err := json.Unmarshal(b, &doc) + return doc, err + }) + if errors.Is(err, fs.ErrNotExist) { + return nil, false, nil + } + if err != nil { + return nil, false, fmt.Errorf("%s: %w", path, err) + } + for _, part := range strings.Split(k.name, ".") { + m, ok := doc.(map[string]any) + if !ok { + return nil, false, nil + } + if doc, ok = m[part]; !ok { + return nil, false, nil + } + } + return doc, true, nil + }, + set: func(k telemetryKey) error { return edit.SetJSON(path, edit.KV{Path: k.name, Value: k.value}) }, + del: func(k telemetryKey) error { return edit.DelJSON(path, k.name) }, + } +} + +// codexTelemetry is Codex's: [analytics] enabled = false in config.toml. +func codexTelemetry(at place, path string) *Telemetry { + f := telemetryFile{ + path: path, + get: func(k telemetryKey) (any, bool, error) { + doc, err := codexTopOf(path) + if err != nil { + return nil, false, fmt.Errorf("%s: %w", path, err) + } + table, key, _ := strings.Cut(k.name, ".") + var m map[string]any + switch table { + case "analytics": + if doc.Analytics == nil { + return nil, false, nil + } + var ok bool + if m, ok = doc.Analytics.(map[string]any); !ok { + return nil, false, fmt.Errorf("%s: analytics is not a table", path) + } + } + v, has := m[key] + return v, has, nil + }, + set: func(k telemetryKey) error { + table, key, _ := strings.Cut(k.name, ".") + // written inline or as dotted keys, the table is the user's + // spelling, where a [analytics] of magpie's would define it + // twice + if doc, err := codexTopOf(path); err != nil { + return fmt.Errorf("%s: %w", path, err) + } else if t, err := edit.GetTOMLTable(path, table); err != nil { + return err + } else if t == nil && doc.Analytics != nil { + return fmt.Errorf("%s has %s written in a way magpie doesn't add to; set %s there", at.native(path), table, k.name) + } + return edit.SetTOMLKey(path, table, key, k.value) + }, + del: func(k telemetryKey) error { + table, key, _ := strings.Cut(k.name, ".") + return edit.DelTOMLKey(path, table, key) + }, + } + return telemetrySwitch(at, f, at.key("codex.telemetry"), telemetryKey{name: "analytics.enabled", value: false, off: isFalse}) +} + +// claudeTelemetry is Claude Code's: its telemetry and error reports off in +// settings.json's env. +func claudeTelemetry(at place, path string) *Telemetry { + return telemetrySwitch(at, jsonTelemetryFile(path), at.key("claude.telemetry"), + telemetryKey{name: "env.DISABLE_TELEMETRY", value: "1", off: anyValue}, + telemetryKey{name: "env.DISABLE_ERROR_REPORTING", value: "1", off: anyValue}) +} + +// usageStatsTelemetry is Gemini CLI's and Qwen Code's: their usage +// statistics off in settings.json. +func usageStatsTelemetry(at place, path, id string) *Telemetry { + return telemetrySwitch(at, jsonTelemetryFile(path), at.key(id+".telemetry"), + telemetryKey{name: "privacy.usageStatisticsEnabled", value: false, off: isFalse}) +} + +// ErrNoTelemetry: the agent has no telemetry switch magpie knows. +var ErrNoTelemetry = errors.New("magpie knows no switch for this agent's telemetry") + +// SetTelemetry turns a's own telemetry off, or back to what it was. +func (a *Agent) SetTelemetry(off bool) error { + if a.Telemetry == nil { + return ErrNoTelemetry + } + return a.Telemetry.Set(off) +} diff --git a/internal/agent/telemetry_test.go b/internal/agent/telemetry_test.go new file mode 100644 index 000000000..e548401a4 --- /dev/null +++ b/internal/agent/telemetry_test.go @@ -0,0 +1,322 @@ +package agent + +import ( + "encoding/json" + "os" + "path/filepath" + "reflect" + "strings" + "testing" + + "github.com/yetone/magpie/internal/edit" +) + +// telemetryHome is a sandbox HOME with file (under it) holding body; "" is +// no file. +func telemetryHome(t *testing.T, file, body string) (home, path string) { + t.Helper() + home = t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + t.Setenv("XDG_DATA_HOME", filepath.Join(home, ".local", "share")) + t.Setenv("CODEX_HOME", "") + t.Setenv("CLAUDE_CONFIG_DIR", "") + t.Setenv("QWEN_HOME", "") + path = filepath.Join(home, file) + if body != "" { + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(path, []byte(body), 0o644); err != nil { + t.Fatal(err) + } + } + return home, path +} + +// jsonAt is the value at a dotted path of the JSON file at path, and +// whether it is there. +func jsonAt(t *testing.T, path, key string) (any, bool) { + t.Helper() + var doc any + if err := json.Unmarshal([]byte(readFile(path)), &doc); err != nil { + t.Fatalf("%v:\n%s", err, readFile(path)) + } + for _, part := range strings.Split(key, ".") { + m, ok := doc.(map[string]any) + if !ok { + return nil, false + } + if doc, ok = m[part]; !ok { + return nil, false + } + } + return doc, true +} + +func telemetryOf(t *testing.T, a *Agent) TelemetryState { + t.Helper() + if a.Telemetry == nil { + t.Fatalf("%s has no telemetry switch", a.ID) + } + st, err := a.Telemetry.Get() + if err != nil { + t.Fatal(err) + } + return st +} + +// OipsAnthony on X: Codex's telemetry off from its page. Off writes +// [analytics] enabled = false beside what is there; on takes out only that, +// and the file is as it was. +func TestCodexTelemetrySwitch(t *testing.T) { + const before = `model = "gpt-5.5" + +[features] +multi_agent = true +` + home, path := telemetryHome(t, ".codex/config.toml", before) + a := codex(home) + if st := telemetryOf(t, a); st.Off || len(st.Own) != 0 || !reflect.DeepEqual(st.Keys, []string{"analytics.enabled"}) { + t.Fatalf("before: %+v", st) + } + if err := a.SetTelemetry(true); err != nil { + t.Fatal(err) + } + got := readFile(path) + if !strings.HasPrefix(got, before) || !strings.Contains(got, "[analytics]\nenabled = false\n") { + t.Fatalf("off:\n%s", got) + } + if st := telemetryOf(t, codex(home)); !st.Off || len(st.Own) != 0 { + t.Fatalf("after off: %+v", st) + } + // off again writes nothing new + if err := a.SetTelemetry(true); err != nil || readFile(path) != got { + t.Fatalf("off again: %v\n%s", err, readFile(path)) + } + if err := codex(home).SetTelemetry(false); err != nil { + t.Fatal(err) + } + if readFile(path) != before { + t.Fatalf("on:\n%s", readFile(path)) + } + if st := telemetryOf(t, a); st.Off { + t.Fatalf("after on: %+v", st) + } +} + +// A Codex with no config.toml yet gets one with the table alone, and on +// leaves no table behind. +func TestCodexTelemetryNoConfig(t *testing.T) { + home, path := telemetryHome(t, ".codex/config.toml", "") + a := codex(home) + if err := a.SetTelemetry(true); err != nil { + t.Fatal(err) + } + if got := readFile(path); strings.TrimSpace(got) != "[analytics]\nenabled = false" { + t.Fatalf("off:\n%s", got) + } + if err := a.SetTelemetry(false); err != nil { + t.Fatal(err) + } + if got := readFile(path); strings.Contains(got, "analytics") { + t.Fatalf("on:\n%s", got) + } +} + +// The user's own analytics setting is theirs: on is never written over, +// their own off is left in on "on", and a table written inline isn't +// added to. Nothing in the file moves. +func TestCodexTelemetryLeavesTheUsers(t *testing.T) { + for _, c := range []struct { + name, body string + off bool // the file keeps it off already + }{ + {"on", "[analytics]\nenabled = true # mine\n", false}, + {"inline", "analytics = { }\n", false}, + {"dotted on", "analytics.enabled = true\n", false}, + {"their off", "[analytics]\nenabled = false # mine\n", true}, + } { + t.Run(c.name, func(t *testing.T) { + home, path := telemetryHome(t, ".codex/config.toml", c.body) + a := codex(home) + st := telemetryOf(t, a) + if st.Off != c.off { + t.Fatalf("state: %+v", st) + } + if c.off { + if !reflect.DeepEqual(st.Own, []string{"analytics.enabled"}) { + t.Fatalf("own: %+v", st) + } + if err := a.SetTelemetry(true); err != nil { + t.Fatal(err) + } + // on: theirs stays, and says why it is still off + if err := a.SetTelemetry(false); err == nil || !strings.Contains(err.Error(), "analytics.enabled") { + t.Fatalf("on over the user's off: %v", err) + } + } else if err := a.SetTelemetry(true); err == nil { + t.Fatal("off was written over the user's own value") + } + if readFile(path) != c.body { + t.Fatalf("the user's file changed:\n%s", readFile(path)) + } + }) + } +} + +// A config that doesn't parse is unknown: no state is made up for it and +// nothing is written into it. +func TestTelemetryUnreadableConfig(t *testing.T) { + for _, c := range []struct { + name, file, body string + of func(string) *Agent + }{ + {"codex", ".codex/config.toml", "[analytics\nenabled = ", codex}, + {"claude", ".claude/settings.json", `{"env": {`, claude}, + {"gemini", ".gemini/settings.json", `{"privacy": [`, gemini}, + {"qwen", ".qwen/settings.json", `{"privacy": `, qwen}, + } { + t.Run(c.name, func(t *testing.T) { + home, path := telemetryHome(t, c.file, c.body) + a := c.of(home) + if a.Telemetry == nil { + t.Fatal("no telemetry switch") + } + if _, err := a.Telemetry.Get(); err == nil { + t.Fatal("an unreadable config read as a state") + } + if err := a.SetTelemetry(true); err == nil { + t.Fatal("off written into an unreadable config") + } + if readFile(path) != c.body { + t.Fatalf("written:\n%s", readFile(path)) + } + }) + } +} + +// Claude Code's telemetry and error reports go off in settings.json's env +// beside the user's variables; on takes out only magpie's, and a variable +// the user set keeps its value. +func TestClaudeTelemetrySwitch(t *testing.T) { + home, path := telemetryHome(t, ".claude/settings.json", `{ + "model": "opus", + "env": {"FOO": "1", "DISABLE_TELEMETRY": "true"} +} +`) + a := claude(home) + st := telemetryOf(t, a) + if st.Off || !reflect.DeepEqual(st.Keys, []string{"env.DISABLE_TELEMETRY", "env.DISABLE_ERROR_REPORTING"}) { + t.Fatalf("before: %+v", st) + } + if err := a.SetTelemetry(true); err != nil { + t.Fatal(err) + } + for k, want := range map[string]any{"env.DISABLE_TELEMETRY": "true", "env.DISABLE_ERROR_REPORTING": "1", "env.FOO": "1", "model": "opus"} { + if v, _ := jsonAt(t, path, k); v != want { + t.Fatalf("off: %s = %v:\n%s", k, v, readFile(path)) + } + } + if st := telemetryOf(t, a); !st.Off || !reflect.DeepEqual(st.Own, []string{"env.DISABLE_TELEMETRY"}) { + t.Fatalf("after off: %+v", st) + } + // on: magpie's goes; the user's DISABLE_TELEMETRY stays, and with + // error reports back on, telemetry reads as not all off (no error) + if err := a.SetTelemetry(false); err != nil { + t.Fatal(err) + } + if _, ok := jsonAt(t, path, "env.DISABLE_ERROR_REPORTING"); ok { + t.Fatalf("on kept magpie's:\n%s", readFile(path)) + } + if v, _ := jsonAt(t, path, "env.DISABLE_TELEMETRY"); v != "true" { + t.Fatalf("on took the user's:\n%s", readFile(path)) + } +} + +// A value magpie wrote that the user changed since is theirs: on leaves it. +func TestClaudeTelemetryChangedSince(t *testing.T) { + home, path := telemetryHome(t, ".claude/settings.json", `{"env": {}}`) + a := claude(home) + if err := a.SetTelemetry(true); err != nil { + t.Fatal(err) + } + if err := edit.SetJSON(path, edit.KV{Path: "env.DISABLE_TELEMETRY", Value: "yes"}); err != nil { + t.Fatal(err) + } + if err := a.SetTelemetry(false); err != nil { + t.Fatal(err) + } + if v, _ := jsonAt(t, path, "env.DISABLE_TELEMETRY"); v != "yes" { + t.Fatalf("on took the user's changed value:\n%s", readFile(path)) + } + if _, ok := jsonAt(t, path, "env.DISABLE_ERROR_REPORTING"); ok { + t.Fatalf("on kept magpie's:\n%s", readFile(path)) + } +} + +// Gemini CLI's and Qwen Code's usage statistics go off in settings.json's +// privacy, beside what is there; their own true is never written over. +func TestUsageStatsTelemetrySwitch(t *testing.T) { + for _, c := range []struct { + name, file string + of func(string) *Agent + }{ + {"gemini", ".gemini/settings.json", gemini}, + {"qwen", ".qwen/settings.json", qwen}, + } { + t.Run(c.name, func(t *testing.T) { + home, path := telemetryHome(t, c.file, `{"privacy": {"other": 1}, "ui": {"theme": "x"}}`) + a := c.of(home) + if st := telemetryOf(t, a); st.Off { + t.Fatalf("before: %+v", st) + } + if err := a.SetTelemetry(true); err != nil { + t.Fatal(err) + } + if v, ok := jsonAt(t, path, "privacy.usageStatisticsEnabled"); !ok || v != false { + t.Fatalf("off:\n%s", readFile(path)) + } + if st := telemetryOf(t, a); !st.Off || len(st.Own) != 0 { + t.Fatalf("after off: %+v", st) + } + if err := a.SetTelemetry(false); err != nil { + t.Fatal(err) + } + if _, ok := jsonAt(t, path, "privacy.usageStatisticsEnabled"); ok { + t.Fatalf("on:\n%s", readFile(path)) + } + if v, _ := jsonAt(t, path, "privacy.other"); v != float64(1) { + t.Fatalf("on moved the user's:\n%s", readFile(path)) + } + if v, _ := jsonAt(t, path, "ui.theme"); v != "x" { + t.Fatalf("on moved the user's:\n%s", readFile(path)) + } + + const theirs = `{"privacy": {"usageStatisticsEnabled": true}}` + if err := os.WriteFile(path, []byte(theirs), 0o644); err != nil { + t.Fatal(err) + } + if err := a.SetTelemetry(true); err == nil || readFile(path) != theirs { + t.Fatalf("off over the user's true: %v\n%s", err, readFile(path)) + } + }) + } +} + +// An agent in a WSL distro has no switch: its file isn't read on each +// look (#3896). +func TestTelemetryOnlyHere(t *testing.T) { + home, _ := telemetryHome(t, ".codex/config.toml", "") + at := place{home: home, spell: func(p string) string { return p }} + for _, a := range []*Agent{codexIn(at), claudeIn(at), geminiIn(at), qwenIn(at)} { + if a.Telemetry != nil { + t.Errorf("%s in a distro has a telemetry switch", a.ID) + } + } + if codex(home).Telemetry == nil { + t.Error("this machine's Codex has none") + } +} diff --git a/internal/cli/settings_parity_test.go b/internal/cli/settings_parity_test.go index 2c42d4e34..2de39abb6 100644 --- a/internal/cli/settings_parity_test.go +++ b/internal/cli/settings_parity_test.go @@ -247,6 +247,7 @@ var notYet = map[string]string{ "POST /api/agents/rescan": A, // api.go "POST /api/agents/restart/{id}": A, // api.go "POST /api/agents/stage/{id}": A, // api.go + "POST /api/agents/telemetry/{id}": A, // api.go "POST /api/cli": A, // api.go "POST /api/cli-behind/quiet": W, // api.go "POST /api/gateway/held/reveal": W, // api.go diff --git a/internal/gui/api.go b/internal/gui/api.go index 1de0cfd2f..3d80f5870 100644 --- a/internal/gui/api.go +++ b/internal/gui/api.go @@ -235,6 +235,9 @@ type agentJSON struct { // Isolated: Claude Desktop's Claude Magpie app (#5671), only where it // can be (macOS): whether it is on, and the app Isolated *agent.DesktopIsolated `json:"isolated,omitempty"` + // Telemetry: the agent's own telemetry to its vendor, where magpie + // knows the switch for it (agent/telemetry.go) + Telemetry *agent.TelemetryState `json:"telemetry,omitempty"` // Joined: connected with its own models still in its list (Codex // signed in with ChatGPT, agent.Agent.Join) Joined bool `json:"joined,omitempty"` @@ -1333,6 +1336,24 @@ func Handler(w Windows, gw *gateway.Server) http.Handler { } writeJSON(rw, state()) }) + // an agent's own telemetry off, or back (agent/telemetry.go) + mux.HandleFunc("POST /api/agents/telemetry/{id}", func(rw http.ResponseWriter, r *http.Request) { + var in struct{ Off bool } + if err := json.NewDecoder(r.Body).Decode(&in); err != nil { + fail(rw, err) + return + } + a, err := agent.Find(r.PathValue("id")) + if err != nil { + fail(rw, err) + return + } + if err := a.SetTelemetry(in.Off); err != nil { + fail(rw, err) + return + } + writeJSON(rw, state()) + }) mux.HandleFunc("POST /api/agents/restart/{id}", func(rw http.ResponseWriter, r *http.Request) { a, err := agent.Find(r.PathValue("id")) if err != nil { @@ -2979,6 +3000,13 @@ func state() stateJSON { aj.Isolated = &iso } } + if a.Telemetry != nil { + st, err := a.Telemetry.Get() + if err != nil { + st.Error = err.Error() + } + aj.Telemetry = &st + } if a.Import != nil { aj.Import = a.Import() if a.Added != nil { diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index f8ec0207c..b1e54771c 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -1304,10 +1304,7 @@ const previews = {}; // agent id → its disconnect preview, as last read const anyMagpieModels = () => state.agents.some((a) => connectField(a)?.options.some((o) => o.ref)); -// connectKind: "ok" (a switch), "empty" (a switch for when magpie has -// models), "no" (never), "link" (an app magpie is added to by a link of its -// own: Cindy), "" (the row as it was); an agent whose CLI is gone is -// offered to no one: only its own row keeps the switch while it is wired +// connectKind: "ok", "empty", "no", "link" (Cindy) or "" (the row as it was) function connectKind(a) { if (a.cliMissing) return "no"; if (a.import) return "link"; @@ -1597,10 +1594,7 @@ function connectRow(a, row, who, { fields, extras, fieldBtn, sw, kind }) { } } -// Switch accounts only (the owner on X): a Claude Code or Codex not -// connected says its account, and its menu signs it in to another. The -// panel's (shuizhuyu on X) is drawn from the kept list (?last=1): a fresh -// read takes seconds after a start, so it waits for the menu +// Switch accounts only (the owner on X): a Claude Code or Codex not connected says its account let accountSwitched = null, panelAccts = null; const switchesAccounts = (a) => !a.wired && (a.id === "claude" || a.id === "codex"); @@ -1679,9 +1673,7 @@ function panelSeveral() { return (quotas || []).some((q) => q.user && !q.balance && (seen.has(q.provider) || !seen.add(q.provider))); } -// agentsLead: above the window's list, what 「接入」 does, said once in a -// line; while no agent is connected, as a welcome, with a way to add a -// provider when magpie has no models to give +// agentsLead: above the window's list, what 「接入」 does, said once function agentsLead(list) { let lead = $("#agentsLead"); if (!lead) { @@ -2030,9 +2022,7 @@ function appReopen(bundle) { return go; } -// appOutSaid: why Codex is on magpie while its ChatGPT account is used up, -// and what of the Codex app is off till the reset (the app turns its -// ChatGPT side off with magpie its provider, and greys Send without) +// appOutSaid: why Codex is on magpie while its ChatGPT account is used up function appOutSaid(a) { const o = a.appOut || {}; let s = o.user @@ -2066,9 +2056,7 @@ function appBackRestart() { return go; } -// keepChatGPT: the takeover turned off where it is told (eddie.zhan on -// Discord: browser use said it had no permission), as the sign-in's -// Always ChatGPT, which puts Codex back on its account at once +// keepChatGPT: the takeover turned off where it is told (eddie.zhan on Discord) function keepChatGPT(a) { const go = el("button", "ag-quiet accent", t("Keep on ChatGPT")); go.type = "button"; @@ -2163,18 +2151,14 @@ function connectPanel(a, { fields, fieldBtn }) { later.onclick = () => { staleSeen[a.id] = a.stale; renderAgents(); }; w.append(later); parts.push(w); - // which copy is left, and how it is reopened: a reopen of one kind - // doesn't end another (the Codex app keeps running on macOS when its - // window is closed; an editor's Codex and the CLI's daemon run on) + // which copy is left, and how it is reopened for (const c of a.staleCopies || []) { const how = STALE_HOW[c.kind]; if (!how) continue; const [pre, post] = t(how[0], { agent: a.name, when: ago(c.since), app: c.app || "" }).split("{cmd}"); const l = line(pre, ...(how[1] ? [code(how[1]), post || ""] : [])); l.classList.add("ag-stale-copy"); - // Codex's daemon, which magpie restarts itself while no codex - // session is on it: with one on, here, when the user says (open - // sessions of Codex 0.162 reconnect to the new one) + // Codex's daemon, restarted here when the user says if (c.kind === "daemon" && a.id === "codex") l.append(daemonRestart()); if (c.kind === "app" && a.id === "codex" && c.bundle) l.append(appReopen(c.bundle)); parts.push(l); @@ -2281,10 +2265,7 @@ function connectPanel(a, { fields, fieldBtn }) { // unset; Codex's is the very value its /model picks, so one choice // the model it starts on is on the row; what goes with it here if (fields) { - // each setting named, as the tray panel's opened rows name them. On the - // row a setting nobody has picked is the agent's own logo for want of - // room, which says nothing about which setting it is, and four of them - // laid side by side all read as one + // each setting named, as the tray panel's opened rows name them for (const b of fields.querySelectorAll(":scope > .field")) { const f = a.fields.find((x) => x.key === b.dataset.key); if (f && !b.querySelector(":scope > .k")) b.prepend(el("span", "k", t(f.label))); @@ -2302,6 +2283,7 @@ function connectPanel(a, { fields, fieldBtn }) { const list = el("div", "list prefs ag-prefs"); homeAgentPrefRows(); list.append(...own.map((id) => $("#" + id))); + if (a.telemetry) list.append(telemetryRow(a)); kv(t("Settings"), list); agentCompactIn(list, own, a); if (!prefs) { @@ -2397,10 +2379,7 @@ function changesList(changes, back) { return box; } -// askDisconnect takes magpie out of an agent's config once asked: every -// field magpie set, and its endpoint and key, give way to what the agent -// had before magpie (agent.Disconnect). Picking Default isn't that: it is -// the agent as installed. +// askDisconnect takes magpie out of an agent's config once asked (agent.Disconnect) function askDisconnect(a) { const ed = el("div", "editor disconnect-ask"); const head = el("div", "ehead"); @@ -4157,6 +4136,7 @@ function agentPrefsButton(a) { // what is in it, by the rows' own names homeAgentPrefRows(); const names = agentPrefsOf(a).map((id) => $("#" + id)).filter((r) => !r.hidden).map((r) => r.querySelector(".name").textContent); + if (a.telemetry) names.push(t("Telemetry")); b.append(el("span", "k", t("Settings")), el("span", "v", names.join(" · ")), c); b.title = t("{agent} settings", { agent: a.name }); b.setAttribute("aria-label", b.title); @@ -20953,9 +20933,7 @@ function warmTimes(ats, at) { return Array.isArray(ats) ? ats : at ? [at] : []; } -// nextWarmTime is the time a daily warm-up's + adds after ats: a 5-hour -// window after the last, so the two follow one another, or the first -// hour that isn't taken when that wraps past midnight onto one. +// nextWarmTime: the time a daily warm-up's + adds, 5 hours after the last function nextWarmTime(ats) { const [h, m] = (ats[ats.length - 1] || "06:00").split(":").map(Number); const pad = (n) => String(n).padStart(2, "0"); @@ -21007,9 +20985,7 @@ function renderWarmAt(box, sub, ats, onReset, via, save) { box.append(segs([["off", t("Off")], ["on", t("On")]], ats.length ? "on" : "off", (v) => save(v === "on" ? (ats.length ? ats : ["06:00"]) : []))); } -// Settings › Usage's Codex auto-use rows and how early one expiring is -// used are drawn by autoresetown.js, imported as Settings first draws -// them; then in the same draw, so a redraw leaves a pressed switch in place +// Settings › Usage's Codex auto-use rows, drawn by autoresetown.js function renderAutoResetOwn(s) { if (window.autoResetOwnPaint) return autoResetOwnPaint(s); import("./autoresetown.js").then(() => autoResetOwnPaint(s), statusErr); @@ -21063,9 +21039,7 @@ function renderWarmAtOwn(s) { } } -// renderWarmNow is Warm up now (a Windows user on Discord): the scheduled -// warm-up's request to one account at once, of several the menu's; what it -// came to stays on its line (warmNowSaid). An account's card: quotaWarm. +// renderWarmNow is Warm up now: the scheduled warm-up's request to one account at once const warmNowSaid = {}; function renderWarmNow(agent, users, rowId) { const row = $(rowId), sub = row.querySelector(".sub"), box = row.lastElementChild; @@ -21157,16 +21131,42 @@ function renderAlerts(s, keep) { $("#turnDoneSegs").replaceChildren(segs(turnOpts, String(d), (v) => savePrefs({ ...keep, turnDoneAlert: Number(v) }))); } -// AGENT_PREFS: an agent's own settings, by its id, each a row kept in -// #agentPrefRows and shown in the agent's sheet (openAgentPrefs). They sat -// in Settings, apart from the agents they set (the owner, 10-20); Long -// conversations is Codex's, Claude Code's and Grok Build's (uk.jent), in each one's sheet. +// AGENT_PREFS: an agent's own settings rows, by its id (openAgentPrefs) const AGENT_PREFS = { codex: ["codexAgentsV1Row", "codexSubagentModelRow", "codexServiceTierRow", "fullContextRow", "codexAsyncRow", "codexTitlesRow", "codexDescriptionsRow", "codexPredictionsRow", "codexAutoReviewRow", "codexMemoriesRow"], claude: ["fullContextRow"], grok: ["fullContextRow"], }; -const agentPrefsOf = (a) => gatewayMode ? null : AGENT_PREFS[kindOf(a)]; +// an agent with a telemetry switch (agent/telemetry.go) has a sheet for it +// when it has no other settings +const agentPrefsOf = (a) => gatewayMode ? null : AGENT_PREFS[kindOf(a)] || (a.telemetry ? [] : null); + +// telemetryRow: the agent's own telemetry off in its config (OipsAnthony on X) +function telemetryRow(a) { + const st = a.telemetry; + const row = el("div", "row pref ag-telemetry"); + const who = el("div", "who"); + who.append(el("div", "name", t("Telemetry"))); + who.title = t("Written in {file}: {keys}", { file: st.file, keys: (st.keys || []).join(", ") }); + if (st.error) who.append(el("div", "sub", t("{file} couldn't be read", { file: st.file }))); + else if (st.off && st.own?.length) who.append(el("div", "sub", t("Turned off in your own config too: {keys}", { keys: st.own.join(", ") }))); + const again = () => { + const now = state.agents.find((x) => x.id === a.id); + if (now?.telemetry && row.isConnected) row.replaceWith(telemetryRow(now)); + if (view === "agents") renderAgents(); + }; + const box = segs([["off", t("Off")], ["on", t("On")]], st.off ? "off" : "on", (v) => { + if ((v === "off") === !!st.off) return; + api("agents/telemetry/" + a.id, { off: v === "off" }).then((ns) => { + state = ns; + status(t("Takes effect when {agent} next starts", { agent: a.name }), "ok"); + again(); + }, (e) => { status(t(e.message), "err"); again(); }); + }); + if (st.error) for (const b of box.querySelectorAll("button")) b.disabled = true; + row.append(who, box); + return row; +} const PREFS_GLYPH = "M2.75 4.75h10.5M2.75 11.25h10.5M5.75 3.25v3M10.25 9.75v3"; let agentPrefRowEls = null; // an agent's own Long conversations, under every agent's (agentcompact.js) @@ -21191,6 +21191,7 @@ async function openAgentPrefs(a) { const list = el("div", "list prefs"); for (const id of ids) list.append($("#" + id)); agentCompactIn(list, ids, a); + if (a.telemetry) list.append(telemetryRow(a)); const bar = el("div", "bar"); const done = el("button", "primary", t("Done")); done.type = "button"; @@ -21282,16 +21283,12 @@ function renderAgentPrefs() { renderCodexSubagentModel(); } -// renderAgentPrefLinks: Settings' search still finds the settings an agent's -// sheet holds, each a row saying where it is that opens the sheet; shown -// only while searching (app.css) +// renderAgentPrefLinks: Settings' search finding the settings an agent's sheet holds function renderAgentPrefLinks() { const box = $("#agentPrefLinks"); box.replaceChildren(); homeAgentPrefRows(); - // Long conversations sets the windows the gateway serves, which an agent - // on another computer reads too: with no Codex or Claude Code here to - // hold it (a gateway, magpie in Docker) it stays in Settings (Linka) + // Long conversations stays in Settings with no agent here to hold it (Linka) const loose = $("#fullContextRow"); if (!state.agents.some((a) => agentPrefsOf(a)?.includes(loose.id))) box.before(loose); else if (loose.parentElement === box.parentElement) $("#agentPrefRows").append(loose); diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index cfe635a32..7f27d26e0 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -4637,6 +4637,11 @@ const I18N = { "Open Claude Magpie from Applications": "从「应用程序」打开 Claude Magpie", "Open Claude Magpie from Applications to use Claude Desktop on magpie. Your own Claude Desktop stays signed in with Anthropic.": "从「应用程序」打开 Claude Magpie,即可在 magpie 上使用 Claude Desktop。你自己的 Claude Desktop 保持 Anthropic 登录。", "Quit Claude Magpie if it is open: it no longer runs on magpie.": "如果 Claude Magpie 正在运行,请退出它:它已不再使用 magpie。", + "Telemetry": "遥测", + "Turned off in your own config too: {keys}": "你自己的配置里也关了:{keys}", + "{file} couldn't be read": "无法读取 {file}", + "Written in {file}: {keys}": "写入 {file}:{keys}", + "Takes effect when {agent} next starts": "{agent} 下次启动时生效", "Claude Desktop runs in a folder of its own on macOS only": "只有 macOS 上的 Claude Desktop 能在独立文件夹中运行", "Claude Desktop (Claude.app) isn't installed": "未安装 Claude Desktop(Claude.app)", "Claude Magpie.app is there already and isn't magpie's": "Claude Magpie.app 已存在,且不是 magpie 创建的", @@ -9522,6 +9527,11 @@ const I18N = { "Open Claude Magpie from Applications": "從「應用程式」打開 Claude Magpie", "Open Claude Magpie from Applications to use Claude Desktop on magpie. Your own Claude Desktop stays signed in with Anthropic.": "從「應用程式」打開 Claude Magpie,即可在 magpie 上使用 Claude Desktop。你自己的 Claude Desktop 維持 Anthropic 登入。", "Quit Claude Magpie if it is open: it no longer runs on magpie.": "如果 Claude Magpie 正在執行,請結束它:它已不再使用 magpie。", + "Telemetry": "遙測", + "Turned off in your own config too: {keys}": "你自己的設定裡也關了:{keys}", + "{file} couldn't be read": "無法讀取 {file}", + "Written in {file}: {keys}": "寫入 {file}:{keys}", + "Takes effect when {agent} next starts": "{agent} 下次啟動時生效", "Claude Desktop runs in a folder of its own on macOS only": "只有 macOS 上的 Claude Desktop 能在獨立資料夾中執行", "Claude Desktop (Claude.app) isn't installed": "未安裝 Claude Desktop(Claude.app)", "Claude Magpie.app is there already and isn't magpie's": "Claude Magpie.app 已存在,且不是 magpie 建立的", @@ -14409,6 +14419,11 @@ const I18N = { "Open Claude Magpie from Applications": "「アプリケーション」から Claude Magpie を開いてください", "Open Claude Magpie from Applications to use Claude Desktop on magpie. Your own Claude Desktop stays signed in with Anthropic.": "「アプリケーション」から Claude Magpie を開くと、magpie で Claude Desktop を使えます。ご自身の Claude Desktop は Anthropic にサインインしたままです。", "Quit Claude Magpie if it is open: it no longer runs on magpie.": "Claude Magpie を開いている場合は終了してください。もう magpie では動きません。", + "Telemetry": "テレメトリ", + "Turned off in your own config too: {keys}": "ご自身の設定でもオフです:{keys}", + "{file} couldn't be read": "{file} を読み取れません", + "Written in {file}: {keys}": "{file} に書き込みます:{keys}", + "Takes effect when {agent} next starts": "{agent} の次回起動時に反映されます", "Claude Desktop runs in a folder of its own on macOS only": "Claude Desktop を専用フォルダで動かせるのは macOS のみです", "Claude Desktop (Claude.app) isn't installed": "Claude Desktop(Claude.app)がインストールされていません", "Claude Magpie.app is there already and isn't magpie's": "Claude Magpie.app が既にあり、magpie が作ったものではありません", @@ -19296,6 +19311,11 @@ const I18N = { "Open Claude Magpie from Applications": "Öffne Claude Magpie unter Programme", "Open Claude Magpie from Applications to use Claude Desktop on magpie. Your own Claude Desktop stays signed in with Anthropic.": "Öffne Claude Magpie unter Programme, um Claude Desktop über magpie zu nutzen. Dein eigenes Claude Desktop bleibt bei Anthropic angemeldet.", "Quit Claude Magpie if it is open: it no longer runs on magpie.": "Beende Claude Magpie, falls es offen ist: Es läuft nicht mehr über magpie.", + "Telemetry": "Telemetrie", + "Turned off in your own config too: {keys}": "Auch in deiner eigenen Konfiguration aus: {keys}", + "{file} couldn't be read": "{file} konnte nicht gelesen werden", + "Written in {file}: {keys}": "Wird in {file} geschrieben: {keys}", + "Takes effect when {agent} next starts": "Wirkt beim nächsten Start von {agent}", "Claude Desktop runs in a folder of its own on macOS only": "Claude Desktop läuft nur unter macOS in einem eigenen Ordner", "Claude Desktop (Claude.app) isn't installed": "Claude Desktop (Claude.app) ist nicht installiert", "Claude Magpie.app is there already and isn't magpie's": "Claude Magpie.app gibt es schon, und es ist nicht von magpie", diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go index 4070fa3d4..271f01539 100644 --- a/internal/gui/core_budget_test.go +++ b/internal/gui/core_budget_test.go @@ -16,7 +16,7 @@ import ( // raises them and says why in its commit. const ( appScriptBudget = 1_316_874 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29); 1,313,704 with a window whose WebKit scrolls under wheels it never tells of (macOS 13) remembered once seen, a scroll at rest then waiting 120ms for a second the same way within 80ms before it is put back, kept for a late wheel to give back (waitsBack), and a load landing under the wheel keeping the reader's way (backAfterLoad, issennknight), the window's own scroll guard, with no room added (10-29); back to 1,311,735 with Settings › Models › Web search's rows (renderSearch, renderSearcher, the search APIs' keys) moved out to the search plugin (plugins/search/settings.js), app.js 1,292,527 after it, not lowered further since what is left plus 1.5% is over it (#4133, 10-29); 1,315,316 with the Agents row of a Claude Code or Codex not connected saying the account it is signed in to and switching it to another (Switch accounts only, the owner on X), in place of the failover line's ChatGPT accounts button, the Agents page's, the core's own, its comments cut down, with no room added (10-30); 1,317,705 with a Claude account added from a setup-token (sfss5362 on X): the sign-in's Use a setup-token instead…, its sheet, and its account row's magpie only, the provider editor's account rows, the core's own editor, its comments cut down, with no room added (10-30); back to 1,315,316 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, loaded when one is asked for (signAsk, 10-30); 1,315,479 with the provider editor lining its Advanced up with its fields (the owner: 高级这个折叠按钮为什么在一个前不着村后不着店的位置?) and a refresh on each of its accounts (在这里也要加上手动刷新用量的按钮), the core's own editor, with no room added (10-31); 1,315,603 with About's Log row, the path of the log the app writes and an Open for its folder (rayem1w on X), in app.js, its comment cut to one line, with no room added (10-31); 1,316,781 with a provider's model listed by an id of the user's (zeewell on X), the provider editor's Names & levels Listed as box beside Same as, the core's own editor, with no room added (10-31); 1,316,874 with a package manager's magpie (the AUR's magpie-bin) naming the command that updates it in Settings' Version row and lighting no Update pill (shuhai on Discord), the core's own update row, which the tray panel reads too, its comments cut to one line, with no room added (10-31); Settings › Sync's Kept on this computer row (hayden4608 on Discord) raised it to 1,317,497, which is no bound; the 1,316,874 it had came back once later trims left app.js at 1,308,363 (10-31) - coreScriptBudget = 1_533_802 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,532,830 with waitsBack and backAfterLoad (issennknight, macOS 13), the window's own scroll guard, in app.js, with no room added (10-29); the context map's tile wording (a4e929212) and Cindy's Add magpie (628ac36fc) had taken the core over it, and Web search's rows moved out to plugins/search/settings.js brought it back to 1,530,861 (#4133, 10-29); 1,532,459 with a provider editor's account rows on one line each, First or Make first at its right end and the settings that aren't set under ⋯ (the owner), the core's own editor, in app.js, which stays in its budget with its comments cut down, with no room added (10-29); 1,532,602 with a plugin's README waiting for its bird to land on three lines before it goes in, however soon it came (the owner, 10-30), in plugins.js, with no room added; 1,536,357 with Switch accounts only on the Agents row (the owner on X), in app.js, with no room added (10-30); 1,537,034 with a plugin's README read once shown at once, with no bird, when its page opens again and read again behind it, the last 20 kept (the owner), in plugins.js, with no room added (10-30); 1,539,423 with a Claude account added from a setup-token (sfss5362 on X), in app.js, with no room added (10-30); 1,538,975 with purposes.js written as compact JSON by genpurposes and the MCP tool purpose in it, 448 bytes less in all (ferock on Discord), lowered to it (10-30); 1,536,586 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, lowered by the 2,389 the setup-token raised it (10-30); 1,536,631 with the 45 bytes b62fa332f added to app.js (Send requests unmasked for subscriptions and plugin providers too) without a raise, with no room added (10-31); 1,537,356 with Settings › Models › Replies › Claude Code's interactive mode, a row beside Short Claude system prompt (the owner), in app.js, with no room added (10-31); Long conversations in Codex's row naming the config.toml keys Codex reads before it, with Take it out, and the window magpie tells Codex for the model it runs (zgjfjfl on Discord) raised it to 1,537,669, and it is back under 1,537,356 with the key list and the window's size written by the server (codexKeysText, tokensSize) and the row's words cut, no raise (10-31); 1,538,554 with the same two, with no room added (10-31); 1,538,678 with About's Log row (rayem1w on X), with no room added (10-31); 1,539,856 with a model's Listed as id (zeewell on X), in app.js, with no room added (10-31); Tuned for you's Codex row offering the advice to background compaction (herman_hong on Discord) and a package manager's magpie naming its command (shuhai on Discord) took it to 1,541,798, and the release notes' dialogs (What's new, the update's ask) moved out to whatsnew.js, loaded when one opens, brought it back under 1,539,856, no raise (10-31); 1,540,479 for Settings › Sync's Kept on this computer row (hayden4608 on Discord) was taken back to 1,539,856 once the core weighed 1,533,355, no raise (10-31); 1,532,958 with the context window card's head naming the agent and the model's lab (the owner), in context.js, after the card's part text viewer moved out to ctxtext.js (7,005 bytes), lowered to it (10-31); 1,533,105 with the provider editor's Claude Code runs as row moved above the accounts, its pill and hover card in claudemode.js, and Settings found at the row that draws anew (the owner), in app.js and i18n.js, with no room added (11-01); a Codex account's credits spent only after every other account, key and fallback (gokoshiki on Discord) fit in it with the Codex options' comments in app.js cut down, no raise (11-01); a plugin option's words in the window's language and the filtered-models note (plugins#590, anewuser6937 on Discord) fit in it with three of the provider editor's comments in app.js cut down, no raise (11-01); 1,533,802 with a closed Mac window telling its page it is out of sight (#4293, pipi-1997), in app.js, which every page needs, its comments cut to one line, with no room added (11-01); Warm up on a Codex or Claude account's Usage card (01huadalang on Discord), in plugins/usage/page.js, its one call in app.js paid for by two comments cut, no raise (11-01); Settings' Check in now for one account (xiaowu_95660), its row and press in checkinnow.js, loaded when Settings draws a check-in, its one call in app.js paid for by three check-in comments cut, no raise (11-02); a ChatGPT account's plan end under its row on Providers (danzi002 on Discord), its line in app.js paid for by two account-row comments cut, no raise (11-02); Scroll to top and Scroll to bottom (#1090, emo172), in scrollends.js, imported on the window's first scroll, its one line in app.js paid for by two comments cut, no raise (11-02); a new-api relay's User ID beside the balance token (zxc56823), in app.js, paid for by four comments cut, no raise (11-03); Air's opened rows saying whether Air's own Codex and Claude Agent go through magpie (jumy_18634 on Discord), in app.js, paid for by six Agents-page comments cut, no raise (11-03); a key's spend cap on its row (sparkling_lemur_62868 on Discord), its pill and held line in keyspend.js, loaded when the provider editor draws a key, its one call in app.js, no raise (11-03); Claude Code's status line square beside ultracode (steven_4422 on Discord), in app.js, paid for by foldSame's comment cut, no raise (11-03); Codex's Restart the app when magpie switches its account tick (atom0964 on Discord), in app.js, paid for by five account-row comments cut, no raise (11-03); over it at 1,534,154 (#5139), 1,533,125 at e928b57f0, 677 bytes under it, and 1,525,207 with Settings › Sync's server form (davForm: WebDAV, S3 and GitHub) moved out to syncfiles.js, loaded when it opens, not lowered since what is left plus 1.5% is over it (11-04); a Mac window's page letting go of its layers after 30s out of sight (#5530, Matrix on Discord), in app.js, paid for by four comments cut, no raise (11-06); a plugin's tools hidden from every agent from its Plugins row (chengming0v0 on Discord), in plugins.js, paid for by two comments cut, no raise (11-07); a key's balance typed by hand (tenacious_eagle on Discord), its pill in keybalance.js, loaded by keyspend.js when the provider editor draws a key of a provider that takes one, nothing in app.js, no raise (11-08); a key's provider's model list off (axelburks on Discord), its tick in app.js, paid for by four Models-section comments cut, no raise (11-08); a model's own headers in Model settings (axelburks on Discord), the core's own editor, paid for by sixteen of its comments cut, no raise (11-08); a model asked on System One (axelburks on Discord), in app.js, paid for by three of the editor's comments cut, no raise (11-08); a typed balance's part that expires (tenacious_eagle_96548 on Discord), its days on the Usage page and the panel in app.js (expiresIn), paid for by five balance comments cut, no raise (11-08); a model's context window and max output in its Model settings row (sayagoodbyeplz on Discord), the row's boxes in modellimits.js, loaded when the provider editor draws a model, its one call in app.js paid for by nine comments cut, no raise (11-08); Make first under Smart saying the order only settles ties (CryptoSarom on X, 4436b7d98, 1,080 bytes in app.js) took it to 1,534,166 (#5720), and About's Open-source licenses dialog moved out to notices.js and Sync's Restore and Upload asks to syncfiles.js, each loaded when it opens, brought it back to 1,530,548, no raise (11-09); a subscription's warm-ups, check-ins and resets moved from Settings into its provider's editor (the owner, 11-07), in app.js, paid for by comments cut, no raise (11-09); Settings › Models › Images' Video generation (a custom provider's video model, Discord #feedback), its row in videogen.js, loaded when Settings draws Image generation, its one call in app.js, no raise (11-09); a window's cap at an amount of its unit (9won_25273 on Discord, 40cbdaa7e) took it to 1,535,556 (#5795), and the account-cap rows' comments cut brought it back to 1,533,547, no raise (11-09); Claude Desktop's Claude Magpie switch (#5671, baranwang on X), in app.js, one switch helper shared with the largest-window one and four comments cut, no raise (11-09); a plugin's page sharing a picture it drew (the day card, JungleyYeh on X), its copy and save in pageshare.js, loaded the first time a page shares one, its one call in pluginpages.js paid for by two of its comments cut, no raise (11-09); the quick panel wording unpriced calls as the Usage page does (tenacious_eagle on Discord), in app.js, paid for by four of the panel's comments cut, no raise (11-10); the Codex reset note naming its ChatGPT projects and chats (b3a57b3d8), paid for by appBackSaid's comment cut, no raise (11-10); the daily check-in's time of day (times_ang on X), its row in checkinnow.js, its one call in app.js, went over it at 1,534,281 on a main that had grown under it, and six check-in comments cut brought it back to 1,533,495, no raise (11-10); Codex's service tier row (JackyFill on X), in app.js, paid for by eight Codex-row comments cut, no raise (11-10); the panel's Usage tab putting a vendor's account first from its count (RealZeroP27 on X), its menu in panelfirst.js, loaded when the count is pressed, paid for by the Allowances tab's arranging moved out to panelarrange.js, loaded when Arrange is pressed, no comments cut, no raise (11-10) + coreScriptBudget = 1_533_802 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,532,830 with waitsBack and backAfterLoad (issennknight, macOS 13), the window's own scroll guard, in app.js, with no room added (10-29); the context map's tile wording (a4e929212) and Cindy's Add magpie (628ac36fc) had taken the core over it, and Web search's rows moved out to plugins/search/settings.js brought it back to 1,530,861 (#4133, 10-29); 1,532,459 with a provider editor's account rows on one line each, First or Make first at its right end and the settings that aren't set under ⋯ (the owner), the core's own editor, in app.js, which stays in its budget with its comments cut down, with no room added (10-29); 1,532,602 with a plugin's README waiting for its bird to land on three lines before it goes in, however soon it came (the owner, 10-30), in plugins.js, with no room added; 1,536,357 with Switch accounts only on the Agents row (the owner on X), in app.js, with no room added (10-30); 1,537,034 with a plugin's README read once shown at once, with no bird, when its page opens again and read again behind it, the last 20 kept (the owner), in plugins.js, with no room added (10-30); 1,539,423 with a Claude account added from a setup-token (sfss5362 on X), in app.js, with no room added (10-30); 1,538,975 with purposes.js written as compact JSON by genpurposes and the MCP tool purpose in it, 448 bytes less in all (ferock on Discord), lowered to it (10-30); 1,536,586 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, lowered by the 2,389 the setup-token raised it (10-30); 1,536,631 with the 45 bytes b62fa332f added to app.js (Send requests unmasked for subscriptions and plugin providers too) without a raise, with no room added (10-31); 1,537,356 with Settings › Models › Replies › Claude Code's interactive mode, a row beside Short Claude system prompt (the owner), in app.js, with no room added (10-31); Long conversations in Codex's row naming the config.toml keys Codex reads before it, with Take it out, and the window magpie tells Codex for the model it runs (zgjfjfl on Discord) raised it to 1,537,669, and it is back under 1,537,356 with the key list and the window's size written by the server (codexKeysText, tokensSize) and the row's words cut, no raise (10-31); 1,538,554 with the same two, with no room added (10-31); 1,538,678 with About's Log row (rayem1w on X), with no room added (10-31); 1,539,856 with a model's Listed as id (zeewell on X), in app.js, with no room added (10-31); Tuned for you's Codex row offering the advice to background compaction (herman_hong on Discord) and a package manager's magpie naming its command (shuhai on Discord) took it to 1,541,798, and the release notes' dialogs (What's new, the update's ask) moved out to whatsnew.js, loaded when one opens, brought it back under 1,539,856, no raise (10-31); 1,540,479 for Settings › Sync's Kept on this computer row (hayden4608 on Discord) was taken back to 1,539,856 once the core weighed 1,533,355, no raise (10-31); 1,532,958 with the context window card's head naming the agent and the model's lab (the owner), in context.js, after the card's part text viewer moved out to ctxtext.js (7,005 bytes), lowered to it (10-31); 1,533,105 with the provider editor's Claude Code runs as row moved above the accounts, its pill and hover card in claudemode.js, and Settings found at the row that draws anew (the owner), in app.js and i18n.js, with no room added (11-01); a Codex account's credits spent only after every other account, key and fallback (gokoshiki on Discord) fit in it with the Codex options' comments in app.js cut down, no raise (11-01); a plugin option's words in the window's language and the filtered-models note (plugins#590, anewuser6937 on Discord) fit in it with three of the provider editor's comments in app.js cut down, no raise (11-01); 1,533,802 with a closed Mac window telling its page it is out of sight (#4293, pipi-1997), in app.js, which every page needs, its comments cut to one line, with no room added (11-01); Warm up on a Codex or Claude account's Usage card (01huadalang on Discord), in plugins/usage/page.js, its one call in app.js paid for by two comments cut, no raise (11-01); Settings' Check in now for one account (xiaowu_95660), its row and press in checkinnow.js, loaded when Settings draws a check-in, its one call in app.js paid for by three check-in comments cut, no raise (11-02); a ChatGPT account's plan end under its row on Providers (danzi002 on Discord), its line in app.js paid for by two account-row comments cut, no raise (11-02); Scroll to top and Scroll to bottom (#1090, emo172), in scrollends.js, imported on the window's first scroll, its one line in app.js paid for by two comments cut, no raise (11-02); a new-api relay's User ID beside the balance token (zxc56823), in app.js, paid for by four comments cut, no raise (11-03); Air's opened rows saying whether Air's own Codex and Claude Agent go through magpie (jumy_18634 on Discord), in app.js, paid for by six Agents-page comments cut, no raise (11-03); a key's spend cap on its row (sparkling_lemur_62868 on Discord), its pill and held line in keyspend.js, loaded when the provider editor draws a key, its one call in app.js, no raise (11-03); Claude Code's status line square beside ultracode (steven_4422 on Discord), in app.js, paid for by foldSame's comment cut, no raise (11-03); Codex's Restart the app when magpie switches its account tick (atom0964 on Discord), in app.js, paid for by five account-row comments cut, no raise (11-03); over it at 1,534,154 (#5139), 1,533,125 at e928b57f0, 677 bytes under it, and 1,525,207 with Settings › Sync's server form (davForm: WebDAV, S3 and GitHub) moved out to syncfiles.js, loaded when it opens, not lowered since what is left plus 1.5% is over it (11-04); a Mac window's page letting go of its layers after 30s out of sight (#5530, Matrix on Discord), in app.js, paid for by four comments cut, no raise (11-06); a plugin's tools hidden from every agent from its Plugins row (chengming0v0 on Discord), in plugins.js, paid for by two comments cut, no raise (11-07); a key's balance typed by hand (tenacious_eagle on Discord), its pill in keybalance.js, loaded by keyspend.js when the provider editor draws a key of a provider that takes one, nothing in app.js, no raise (11-08); a key's provider's model list off (axelburks on Discord), its tick in app.js, paid for by four Models-section comments cut, no raise (11-08); a model's own headers in Model settings (axelburks on Discord), the core's own editor, paid for by sixteen of its comments cut, no raise (11-08); a model asked on System One (axelburks on Discord), in app.js, paid for by three of the editor's comments cut, no raise (11-08); a typed balance's part that expires (tenacious_eagle_96548 on Discord), its days on the Usage page and the panel in app.js (expiresIn), paid for by five balance comments cut, no raise (11-08); a model's context window and max output in its Model settings row (sayagoodbyeplz on Discord), the row's boxes in modellimits.js, loaded when the provider editor draws a model, its one call in app.js paid for by nine comments cut, no raise (11-08); Make first under Smart saying the order only settles ties (CryptoSarom on X, 4436b7d98, 1,080 bytes in app.js) took it to 1,534,166 (#5720), and About's Open-source licenses dialog moved out to notices.js and Sync's Restore and Upload asks to syncfiles.js, each loaded when it opens, brought it back to 1,530,548, no raise (11-09); a subscription's warm-ups, check-ins and resets moved from Settings into its provider's editor (the owner, 11-07), in app.js, paid for by comments cut, no raise (11-09); Settings › Models › Images' Video generation (a custom provider's video model, Discord #feedback), its row in videogen.js, loaded when Settings draws Image generation, its one call in app.js, no raise (11-09); a window's cap at an amount of its unit (9won_25273 on Discord, 40cbdaa7e) took it to 1,535,556 (#5795), and the account-cap rows' comments cut brought it back to 1,533,547, no raise (11-09); Claude Desktop's Claude Magpie switch (#5671, baranwang on X), in app.js, one switch helper shared with the largest-window one and four comments cut, no raise (11-09); a plugin's page sharing a picture it drew (the day card, JungleyYeh on X), its copy and save in pageshare.js, loaded the first time a page shares one, its one call in pluginpages.js paid for by two of its comments cut, no raise (11-09); the quick panel wording unpriced calls as the Usage page does (tenacious_eagle on Discord), in app.js, paid for by four of the panel's comments cut, no raise (11-10); the Codex reset note naming its ChatGPT projects and chats (b3a57b3d8), paid for by appBackSaid's comment cut, no raise (11-10); the daily check-in's time of day (times_ang on X), its row in checkinnow.js, its one call in app.js, went over it at 1,534,281 on a main that had grown under it, and six check-in comments cut brought it back to 1,533,495, no raise (11-10); Codex's service tier row (JackyFill on X), in app.js, paid for by eight Codex-row comments cut, no raise (11-10); the panel's Usage tab putting a vendor's account first from its count (RealZeroP27 on X), its menu in panelfirst.js, loaded when the count is pressed, paid for by the Allowances tab's arranging moved out to panelarrange.js, loaded when Arrange is pressed, no comments cut, no raise (11-10); an agent's own telemetry off in its settings (OipsAnthony on X), in app.js, paid for by sixteen Agents-page comments cut, 1,532,840 after, no raise (11-10) ) func TestCoreScriptBudget(t *testing.T) { diff --git a/internal/gui/tests/agent-telemetry.test.cjs b/internal/gui/tests/agent-telemetry.test.cjs new file mode 100644 index 000000000..c1dbe48cb --- /dev/null +++ b/internal/gui/tests/agent-telemetry.test.cjs @@ -0,0 +1,160 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// An agent's own telemetry off from its page (OipsAnthony on X): an agent +// whose state carries telemetry has a Telemetry row in its opened row's +// Settings and in its settings sheet, on until switched. Off posts +// {off: true} and the row follows the state the reply carries; a refusal +// (a value of the user's own) is said and the row goes back. A value of +// the user's own that keeps it off is said under the name. An agent with +// no switch has no row. Every language, wide and narrow, no native select, +// no scroll on click. No backend: 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"); + +function fixture(lang, { own = [], refuse = "" } = {}) { + const settings = { lang, theme: "light" }; + const posts = []; + const tel = { off: own.length > 0, own, keys: ["privacy.usageStatisticsEnabled"], file: "/test/.gemini/settings.json" }; + const state = () => ({ + agents: [ + { + id: "gemini", name: "Gemini CLI", path: "/test/.gemini/settings.json", icon: "geminicli-color", wired: true, + fields: [{ key: "model", label: "model", value: "magpie/glm-5", options: [{ value: "magpie/glm-5", label: "GLM-5", ref: "magpie/glm-5" }] }], + telemetry: { ...tel }, + }, + { + id: "opencode", name: "OpenCode", path: "/test/.config/opencode/opencode.json", icon: "opencode", wired: true, + fields: [{ key: "model", label: "model", value: "magpie/glm-5", options: [{ value: "magpie/glm-5", label: "GLM-5", ref: "magpie/glm-5" }] }], + }, + ], + profiles: [], settings, + }); + async function serve(route) { + const req = route.request(), url = new URL(req.url()); + const json = (data, status = 200) => route.fulfill({ json: data, status }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json(state()); + if (url.pathname === "/api/agents/telemetry/gemini") { + const body = req.postDataJSON(); + posts.push(body); + if (refuse) return json({ error: refuse }, 400); + tel.off = body.off; + return json(state()); + } + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false }); + if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/settings") return json(settings); + if (url.pathname.startsWith("/api/")) return 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)]; + try { await route.fulfill({ body: await fs.readFile(file), contentType }); } + catch { await route.fulfill({ status: 404, body: "" }); } + } + return { serve, posts }; +} + +const W = { + en: { name: "Telemetry", off: "Off", on: "On", ok: "Takes effect when Gemini CLI next starts", own: "Turned off in your own config too: privacy.usageStatisticsEnabled", details: "Details", settings: "Settings" }, + zh: { name: "遥测", off: "关闭", on: "开启", ok: "Gemini CLI 下次启动时生效", own: "你自己的配置里也关了:privacy.usageStatisticsEnabled", details: "详情", settings: "设置" }, + "zh-TW": { name: "遙測", off: "關閉", on: "開啟", ok: "Gemini CLI 下次啟動時生效", own: "你自己的設定裡也關了:privacy.usageStatisticsEnabled", details: "詳情", settings: "設定" }, + ja: { name: "テレメトリ", off: "オフ", on: "オン", ok: "Gemini CLI の次回起動時に反映されます", own: "ご自身の設定でもオフです:privacy.usageStatisticsEnabled", details: "詳細", settings: "設定" }, + de: { name: "Telemetrie", off: "Aus", on: "An", ok: "Wirkt beim nächsten Start von Gemini CLI", own: "Auch in deiner eigenen Konfiguration aus: privacy.usageStatisticsEnabled", details: "Details", settings: "Einstellungen" }, +}; +const gm = '.row.agent[data-id="gemini"]'; +const oc = '.row.agent[data-id="opencode"]'; + +async function open(engine, lang, width, opts, t) { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await browser.newPage({ viewport: { width, height: 700 } }); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + const fx = fixture(lang, opts); + await page.route("**/*", fx.serve); + t.after(() => browser.close()); + await page.goto("http://magpie.test/?view=agents"); + await page.locator(gm).waitFor(); + await page.locator(`${gm} .ag-link`, { hasText: W[lang].details }).click(); + await page.locator(`${gm} .ag-exp .ag-telemetry`).waitFor(); + return { page, fx, errors }; +} + +// until the faked backend has had n posts +async function posted(fx, n) { + for (let i = 0; i < 500 && fx.posts.length < n; i++) await new Promise((r) => setTimeout(r, 10)); +} +const pressed = (page, sel) => page.evaluate((s) => document.querySelector(s)?.querySelector(".opt.on")?.textContent, sel); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of Object.keys(W)) { + for (const width of [1100, 640]) { + test(`${engine} ${lang} ${width}px: Gemini CLI's telemetry off and back`, async (t) => { + const w = W[lang]; + const { page, fx, errors } = await open(engine, lang, width, {}, t); + const row = `${gm} .ag-exp .ag-telemetry`; + assert.equal(await page.locator(`${row} .name`).textContent(), w.name); + assert.equal(await pressed(page, row), w.on, "off before it was switched"); + assert.equal(await page.locator(`${row} .sub`).count(), 0); + const box = await page.locator(row).boundingBox(); + assert.ok(box.x + box.width <= width && box.height > 0, JSON.stringify(box)); + + const y = await page.evaluate(() => scrollY); + await page.locator(`${row} .opt`, { hasText: w.off }).click(); + await page.waitForFunction(([s, off]) => document.querySelector(s)?.querySelector(".opt.on")?.textContent === off, [row, w.off]); + // the reply's state drawn: the status says it + await page.waitForFunction((ok) => document.querySelector("#status")?.textContent === ok, w.ok); + assert.deepEqual(fx.posts, [{ off: true }]); + assert.equal(await pressed(page, row), w.off); + await page.locator(`${row} .opt`, { hasText: w.on }).click(); + await posted(fx, 2); + await page.waitForFunction(([s, on]) => document.querySelector(s)?.querySelector(".opt.on")?.textContent === on, [row, w.on]); + assert.deepEqual(fx.posts, [{ off: true }, { off: false }]); + + assert.equal(await page.evaluate(() => scrollY), y, "a click scrolled the page"); + // the agent with no switch has none + assert.equal(await page.locator(`${oc} .ag-telemetry`).count(), 0); + assert.equal(await page.locator("select").count(), 0, "a native select"); + assert.deepEqual(errors, []); + }); + } + test(`${engine} ${lang}: the user's own off is said`, async (t) => { + const w = W[lang]; + const { page, errors } = await open(engine, lang, 1100, { own: ["privacy.usageStatisticsEnabled"] }, t); + const row = `${gm} .ag-exp .ag-telemetry`; + assert.equal(await pressed(page, row), w.off); + assert.equal(await page.locator(`${row} .sub`).textContent(), w.own); + assert.deepEqual(errors, []); + }); + } + test(`${engine}: a refusal is said and the row goes back`, async (t) => { + const refuse = "/test/.gemini/settings.json sets privacy.usageStatisticsEnabled to true; magpie leaves a value of yours as it is (change it there)"; + const { page, fx, errors } = await open(engine, "en", 1100, { refuse }, t); + const row = `${gm} .ag-exp .ag-telemetry`; + await page.locator(`${row} .opt`, { hasText: "Off" }).click(); + await page.waitForFunction((s) => document.querySelector("#status")?.textContent === s, refuse); + await page.waitForFunction((s) => document.querySelector(s)?.querySelector(".opt.on")?.textContent === "On", row); + assert.deepEqual(fx.posts, [{ off: true }]); + assert.deepEqual(errors, []); + }); + test(`${engine}: the agent's menu opens a sheet with the row`, async (t) => { + const { page, fx, errors } = await open(engine, "en", 1100, {}, t); + await page.evaluate(() => openAgentPrefs(state.agents.find((a) => a.id === "gemini"))); + const row = "#modal .agent-prefs .ag-telemetry"; + await page.locator(row).waitFor(); + assert.equal(await page.locator(`#modal .agent-prefs .ehead b`).textContent(), "Gemini CLI settings"); + await page.locator(`${row} .opt`, { hasText: "Off" }).click(); + await posted(fx, 1); + await page.waitForFunction((s) => document.querySelector(s)?.querySelector(".opt.on")?.textContent === "Off", row); + assert.deepEqual(fx.posts, [{ off: true }]); + assert.deepEqual(errors, []); + }); +}