From bc10a619857aaec97fb31486f2b20bf8308637ee Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 3 Nov 2026 15:03:24 +0800 Subject: [PATCH] agents: Claude Code's status line, the 5h and 7d use, is a switch on its row (steven_4422) steven_4422 on Discord asked for the 5h and 7d account use in Claude Code. magpie has had `magpie statusline` since #1997 (kensenzhao), but it was found only in docs/reference.md and needed a hand-written settings.json entry naming a `magpie` the app doesn't put on PATH. Claude Code's row now has a "status line" square beside ultracode (the same toggle, now a table, TOGGLES in app.js), and `magpie claude statusline on|off` in the CLI. On writes settings.json's statusLine as {type: command, command: " statusline"}, quoted for a POSIX shell (Git Bash on Windows, forward slashes). The command reads the gateway's kept windows with a 1s timeout and prints nothing when it can't, as before. - A status line of the user's own is never written over: the square isn't offered while one is there, on is refused, and off and Disconnect leave it byte for byte. Ours is a single plain command whose program is magpie/magpie-* and first argument statusline, so a hand-written one from the reference counts and a compound (&&, |, ;, $(...)) is the user's. - An unreadable settings.json is not written over. - Disconnect takes magpie's status line out with the rest. - Quiet: Claude Code reruns a changed statusLine command in its open sessions, so no restart notice. - Not offered for a WSL distro, and a distro's settings.json isn't read for the options (a stopped one would start, #3896). A stopped distro's fields fall back to magpie's models as options, so without a case in wsl.go its square would have listed models (TestWSLClaudeNoStatusLine). Run on mote (go1.26.8, load ~400): - at f33e6d112 (rebased on 3088872e6): go test -count=1 ./internal/agent ./internal/cli ./internal/gui. Red: TestWSLColdPlaceOpensNothing (mine: Options read a distro's settings.json; fixed), TestCoreScriptBudget (5 bytes over after the rebase; a comment trimmed, no raise), TestEveryRouteHasACommandOrIsNamed (#5026, from 0872bc2a0 on main), TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27). go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok. - GUI at f33e6d112: every agent-*, claude-*, i18n*, field* and tweak* file, both engines: 1294 of 1296. agent-stale-copies (webkit ja 980, #1949) and claude-subagent-tag (webkit ja 1100, filed #5040) timed out under load; at d85b4e49b both files and claude-statusline.test.cjs (en, zh, zh-TW, ja, de at 900 and 400 wide) alone: 130 of 130. - at d85b4e49b (the fixes above): go test ./internal/agent ok; TestCoreScriptBudget ok. - rebased on f37742e14 (a key's spend cap took the core to 21 bytes under its budget; this change's 207 bytes are paid for by foldSame's comment cut, no raise), at the pushed head: go test ./internal/agent ok (318s); TestCoreScriptBudget ok (1,533,597 of 1,533,802); claude-statusline, i18n-keys and claude-effort GUI files, both engines: 46 of 46. - gofmt -l clean. Broken by hand, each red then restored: - the user's-own guard off: TestClaudeStatusLineLeavesTheUsers - the Unwire call taken out: TestClaudeStatusLineGoesOnDisconnect - the file wiped before the write: TestClaudeStatusLineUnreadable - the compound check off: TestClaudeStatusCommand - the WSL asleep case off: TestWSLClaudeNoStatusLine - the here check after the read: TestWSLColdPlaceOpensNothing - the statusline entry out of TOGGLES: claude-statusline 15/15 red Not tried: a real Claude Code session showing it (and its hot reload); Windows Git Bash and PowerShell with a real path; the Linux AppImage path; WSL is not offered at all. --- docs/reference.md | 16 +- docs/subsystems/agent-wiring.md | 1 + internal/agent/claude.go | 7 + internal/agent/claude_statusline.go | 184 +++++++++++++++++ internal/agent/claude_statusline_test.go | 191 ++++++++++++++++++ internal/agent/wsl.go | 5 +- internal/cli/statusline_cli.go | 7 +- internal/gui/assets/app.js | 41 ++-- internal/gui/assets/i18n.js | 12 ++ internal/gui/core_budget_test.go | 2 +- internal/gui/tests/claude-statusline.test.cjs | 108 ++++++++++ 11 files changed, 542 insertions(+), 32 deletions(-) create mode 100644 internal/agent/claude_statusline.go create mode 100644 internal/agent/claude_statusline_test.go create mode 100644 internal/gui/tests/claude-statusline.test.cjs diff --git a/docs/reference.md b/docs/reference.md index 99389d9fd..d048458d9 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -2261,11 +2261,17 @@ The accounts that answered through the gateway in the last 30 days are shown, every one when none has; `magpie statusline claude` (a provider, or an account's email, login or name) keeps only those. It works however Claude Code signs in to the gateway, unlike the `anthropic-ratelimit-*` headers, -which Claude Code reads only while signed in to claude.ai. magpie doesn't -write it into Claude Code's settings, where another status line may be; -add it to `~/.claude/settings.json` yourself: -`"statusLine": {"type": "command", "command": "magpie statusline"}`. With -the gateway not running it prints an empty line. +which Claude Code reads only while signed in to claude.ai. The status +line square on Claude Code's row in the Agents page (or `magpie claude +statusline on`) turns it on: it writes `statusLine` in +`~/.claude/settings.json` to run this magpie by its full path +(`"statusLine": {"type": "command", "command": "/Applications/Magpie.app/Contents/MacOS/magpie statusline"}`), +and off, or Disconnect, takes out only a status line that runs +`magpie statusline`. A status line of the user's own (claude-hud, a script) +is never written over: the square isn't shown while one is there, and on is +refused. Claude Code runs a changed status line in its open sessions too, +so nothing needs a restart. It is offered for Claude Code on this computer, +not in a WSL distro. With the gateway not running it prints an empty line. `magpie heap []` is for a report of magpie holding too much memory: a macOS `sample` of the app shows Go's frames as `???`. It asks the running diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 5e524a78f..7fbed2e6e 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -116,6 +116,7 @@ something else shows up as drift. - T3 Code runs a thread on the harness of the provider instance its model is picked under, so magpie writes two instances (karissasel_ on X: only Claude Code could be picked). `magpie` runs Claude Code, as above. `magpie-codex` ("magpie · Codex", `t3CodexJSON` in [`t3code.go`](../../internal/agent/t3code.go)) runs Codex: its `config.launchArgs`, which T3 hands to `codex app-server` and the `-c` pairs of to `codex exec`, are Codex's own overrides, making `magpie` its `model_provider` (the same table `codex.go` writes) and `magpie-codex-models.json`, written beside settings.json from `codexcat`, its `model_catalog_json`. Each value is quoted for T3's `tokenizeCliArgs` (`t3Arg`; `TestT3CodeCodexInstance` reads them back with a port of it). `~/.codex/config.toml` is not written, and a `binaryPath` or `homePath` the user gave T3's own `codex` instance is carried over. The name, on/off and unknown keys are the user's; the launch args and catalog are magpie's, and Check says when the launch args no longer reach the gateway (`t3CodexOff`). An older Claude-only wiring gets the Codex instance on its next Sync once; one the user removed stays removed (`t3code.codex` in the stash) until magpie is turned on for T3 again (`TestT3CodeCodexInstanceAddedOnce`). - Claude Code takes one window (`CLAUDE_CODE_MAX_CONTEXT_TOKENS`, `claudeContextEnv` in [`claude.go`](../../internal/agent/claude.go)) for every model it doesn't know. Claude Code alone on magpie is told its main model's (`claudeWindow`), and a model picked in its `/model` (magpie's `modelPicker`) runs at that one value. Beside a main that is one of Claude's own models (or a group of them), with no tier that isn't, nothing is told, so a model picked there ran at Claude Code's own 200K: a routing group of a 500K GPT and a 1M Claude did (young02036 on Discord). Then (`pickerApart`) the `/model` rows (`pickerRefs`) count as tiers do in the layout below. While Claude Desktop is on magpie too, its Code tab runs Claude Code on the same `~/.claude/settings.json` with every model Desktop lists, so magpie tells it the largest window of those and of Claude Code's own models (its main, tiers and `/model` rows), and holds each model below it to its own with `modelSettings..autoCompactWindow` (`claudePlan` in [`claude_budget.go`](../../internal/agent/claude_budget.go), #2025: the least held a 1M model to 131K). A model handed by a `[1m]` id (Desktop's under `DesktopLongest`, or Claude Code's own) counts by its 1M too, so it still runs at 1M when Claude Code stops taking the id for 1M (the 1M beta turned away once, `CLAUDE_CODE_DISABLE_1M_CONTEXT`); left out, a 1M model beside a 272K GPT was told 272K (dumplings on Discord). Claude Code 2.1.296 matches that key by the id it was handed, lowercased and without `[1m]`; it comes before the top-level `autoCompactWindow`, which serves a model without one. `CLAUDE_CODE_AUTO_COMPACT_WINDOW` would take precedence over both, so in this mode magpie's working window goes in the top-level `autoCompactWindow` instead, and an entry is written only where a model's window or its own threshold differs from what it would run at without one. magpie's entries and top-level value are stashed (`claude.model_budgets`, `claude.compact_default`) and go when Desktop leaves magpie; the user's own entries, top-level value and variables stay, a user's entry past its model's window (or `auto`) holds the largest to that window, and with a `CLAUDE_CODE_AUTO_COMPACT_WINDOW` of the user's the least window is told as before. A Code tab session whose environment host is WSL runs on the distro's Claude Code, which reads `${CLAUDE_CONFIG_DIR:-$HOME/.claude}` there (Desktop 4.29.0's remote probe) and not Windows' file, so each `claude@wsl:` is told the same while Windows' Desktop is on magpie (`desktopOn`), on magpie itself or not; it read 200K for a 500K group before (young02036 on Discord). - Claude Code is told what each of magpie's models can do in `CLAUDE_CODE_MODEL_CAPABILITIES` (`claudeCapsEnv`, `claudeCapabilities` in [`claude.go`](../../internal/agent/claude.go)): `=effort[,xhigh_effort][,max_effort]` for those it is shown, and, while Claude Desktop is on magpie, for Desktop's `mythos-magpie-` ids its Code tab hands it. A Claude model Claude Code knows gets no more than Claude Code gives it (Opus and Sonnet 4.6: no xhigh), and one with no known levels isn't named. A model that reaches max without xhigh (GLM-5.3 at low/high/max, DeepSeek V4 at high/max) is said to have xhigh too: the gateway runs xhigh at max for it (`fitEffort`), and Claude Code 2.1.299 turns Ultracode down without `xhigh_effort` ("Ultracode isn't available on …"), which in Desktop is the Ultracode level and dynamic workflows (leesunrise2364 on Discord; `TestClaudeModelCapabilities`). A value of the user's is left alone. +- Claude Code's status line (`statusline`, [`claude_statusline.go`](../../internal/agent/claude_statusline.go)) is a switch on its row, beside ultracode (steven_4422 on Discord: the 5h and 7d use in Claude Code). On writes settings.json's `statusLine` to run this magpie by its full path (`update.Program()`, forward slashes and quoted for Git Bash on Windows) with `statusline` (#1997, [`statusline_cli.go`](../../internal/cli/statusline_cli.go)), which reads the gateway's kept windows with a 1s timeout and prints nothing when it can't. A status line runs magpie's when its program's base name is `magpie` (or `magpie-…`) and its first argument `statusline` (`claudeStatusOurs`), so one written by hand from the reference counts too. A status line of the user's own (claude-hud, a script) is never written over: Options is empty while one is there, so the square isn't shown, and on is refused; an unreadable settings.json is refused too. Off and Disconnect take out only magpie's. Claude Code watches settings.json and reruns a changed command in its open sessions, so it is Quiet and needs no restart. Only on this computer: a WSL distro, running or stopped (`wslKinds` asleep options), isn't offered it (`TestClaudeStatusLine*`, `TestWSLClaudeNoStatusLine`, `claude-statusline.test.cjs`). - MiniMax Code takes a model ref with one slash in the whole (a SubAgent's `model` must match `^[^/\s]+\/[^/\s]+$`, #1387), and magpie's refs there are `custom_provider:magpie/`. So a model under `custom_provider.magpie` is written with `~` for each slash of its catalog id (`bb-codex~gpt-6.1-sol`, `provider.FlatID`), only when that spelling stands for one served id (`provider.Flattened`); the gateway takes it back. A config an older magpie wrote moves over on the next sync: the user's keys on a model go to its new key, `defaultModel`, `defaultLightModel` and `memory.captureModel`/`consolidationModel` follow (`mcodeRefs`), and the slashed key stays, switched off (`enabled: false`), so a session begun on it still resumes. magpie never edits the user's own `agents//agent.md`. No other agent was found with this limit ([`minimax.go`](../../internal/agent/minimax.go)). - MiniMax Code Desktop (3.1.10, `MiniMax Code.app`, `com.minimax.agent.cn` or `com.minimax.agent`) runs the same runtime on the same `config.yaml`, but its window keeps the model last picked in it (localStorage `mavis:model-selection`) and runs that, not `defaultModel`, while that model is still listed. Its runtime reads `config.yaml` at start-up and doesn't watch it, and it has no local API in a release build, so magpie can't move the pick. With the app installed (`desktopApps`), MiniMax Code's notice says to restart the app and pick a magpie model once in its menu ([`minimax.go`](../../internal/agent/minimax.go)). - Claude Code's `/model` list (`modelPicker` in its settings.json) is magpie's while it is marked in the stash (`claude.model_picker`, `claude@wsl:.model_picker` for a WSL distro) or while every row's description ends "via magpie", as every row magpie writes does (`magpiesPicker` in [`claude.go`](../../internal/agent/claude.go)). magpie keeps its own list up to date on every model set and `Sync`, and removes it when Claude Code is taken off magpie; a list the user wrote is left alone. The fingerprint covers a list whose mark an older magpie's stash lost, which otherwise stayed without every model added since (#2046). The list sets `replaceBuiltInOptions` (only Default and magpie's rows, Claude Code's own lineup hidden) while Show Claude Code's own models is off (`provider.OwnModelsHidden`) and also while Claude Code's list leaves out some of magpie's catalog (`claudeNarrowed`: only the picked models, some taken out, or a visibility of families). Without it Claude Code 2.1.316 still listed its built-in Fable row beside a list narrowed to one routing group, since magpie leaves that tier unset (yyhhyyyyyy on Discord). A user's own `ANTHROPIC_CUSTOM_MODEL_OPTION` (settings env or shell) keeps the lineup, as the flag would hide that row too (`TestClaudePickerNarrowedListReplacesLineup`). diff --git a/internal/agent/claude.go b/internal/agent/claude.go index a8183c71b..dda3f28d0 100644 --- a/internal/agent/claude.go +++ b/internal/agent/claude.go @@ -2171,6 +2171,9 @@ func claudeIn(at place) *Agent { return claudeSignIns() }, }) + // magpie's status line, offered where the user has none (claude_statusline.go) + statusField := claudeStatusField(at, path, func() { stale = "" }) + fields = append(fields, statusField) // a write asks a proxy in front of magpie first (claudeAsk): each // field's Set, Sync and Unwire. Follow writes only once routed, so a // first look there leaves it for the next one, as reads do. @@ -2200,6 +2203,10 @@ func claudeIn(at place) *Agent { for _, k := range claudeOwnEnv { forget(at.key("claude.env." + k)) } + // magpie's status line goes with it; one of the user's own stays + if err := statusField.Set(""); err != nil { + return err + } // magpie's level in the env goes alone: the effortLevel under // it is the user's own, which Claude Code is back on if e := env(claudeEffortEnv); e != "" && appliedOf(self.ID).Fields["effort"] == e { diff --git a/internal/agent/claude_statusline.go b/internal/agent/claude_statusline.go new file mode 100644 index 000000000..c0a2075b2 --- /dev/null +++ b/internal/agent/claude_statusline.go @@ -0,0 +1,184 @@ +package agent + +// Claude Code's status line, magpie's (steven_4422 on Discord: "show 5h +// and 7d account usage in claude code"). `magpie statusline` (#1997) +// prints the session's model and each account's windows as the gateway +// last read them, but only a user who found it in the reference and wrote +// it into settings.json had it. The Agents page offers it as a switch on +// Claude Code's row: on writes settings.json's statusLine to run this +// magpie's binary by its full path (a terminal's `magpie` may be another +// copy, or none: the app from the site puts none on PATH), off takes out +// only a status line that runs `magpie statusline`. A status line of the +// user's own (claude-hud, a script) is never written over: the switch +// isn't offered while one is there, and on is refused. +// +// Claude Code (2.1.316) watches settings.json and runs a changed +// statusLine command in its open sessions too, with the session's JSON on +// stdin, after each change of its messages; so nothing needs a restart. +// Only on this computer: a WSL distro's Claude Code would run a Windows +// binary through interop, which isn't tried. + +import ( + "fmt" + "runtime" + "strings" + + "github.com/yetone/magpie/internal/edit" + "github.com/yetone/magpie/internal/update" +) + +// claudeStatusExe is the magpie a status line written now runs; a var for +// tests. +var claudeStatusExe = func() string { + if exe, err := update.Program(); err == nil && exe != "" { + return exe + } + return "magpie" +} + +// claudeStatusCommand is the statusLine command that runs exe's +// statusline: by a path Claude Code's shell takes as one word (it runs a +// status line through bash, Git Bash on Windows, where a path is written +// with forward slashes). +func claudeStatusCommand(exe, goos string) string { + if goos == "windows" { + exe = strings.ReplaceAll(exe, `\`, "/") + } + if strings.ContainsAny(exe, " \t'\"\\$`!&;|<>()*?[]#~{}") { + exe = "'" + strings.ReplaceAll(exe, "'", `'\''`) + "'" + } + return exe + " statusline" +} + +// claudeStatusOurs says whether a statusLine command runs magpie's +// statusline and nothing else: a magpie binary by any path or quoting, its +// first argument statusline (with or without the accounts to keep). +func claudeStatusOurs(cmd string) bool { + prog, rest, ok := shellWord(strings.TrimLeft(cmd, " \t")) + if !ok || prog == "" { + return false + } + base := strings.ToLower(prog[strings.LastIndexAny(prog, `/\`)+1:]) + base = strings.TrimSuffix(base, ".exe") + if base != "magpie" && !strings.HasPrefix(base, "magpie-") { + return false + } + // every word plain: a status line that runs more (&& a script, | a + // filter) is the user's, and off never takes it out + for i := 0; ; i++ { + rest = strings.TrimLeft(rest, " \t") + if rest == "" { + return i > 0 + } + var w string + if w, rest, ok = shellWord(rest); !ok || i == 0 && w != "statusline" { + return false + } + } +} + +// shellWord reads s's first word as a POSIX shell does ('…', "…" with its +// \ escapes, a bare \), up to unquoted space; ok is false for a quote +// left open or an operator in it. +func shellWord(s string) (word, rest string, ok bool) { + var b strings.Builder + for i := 0; i < len(s); i++ { + switch c := s[i]; c { + case ' ', '\t', '\n': + return b.String(), s[i:], true + case ';', '&', '|', '<', '>', '(', ')', '`', '$': + return "", "", false + case '\'': + end := strings.IndexByte(s[i+1:], '\'') + if end < 0 { + return "", "", false + } + b.WriteString(s[i+1 : i+1+end]) + i += 1 + end + case '"': + for i++; ; i++ { + if i >= len(s) { + return "", "", false + } + if s[i] == '"' { + break + } + if s[i] == '$' || s[i] == '`' { + return "", "", false + } + if s[i] == '\\' && i+1 < len(s) && strings.IndexByte("\"\\$`", s[i+1]) >= 0 { + i++ + } + b.WriteByte(s[i]) + } + case '\\': + if i+1 < len(s) { + i++ + b.WriteByte(s[i]) + } + default: + b.WriteByte(c) + } + } + return b.String(), "", true +} + +// claudeStatusField is the statusline switch of Claude Code's settings.json +// at path; settled is called after each write (no open session needs a +// restart for it). +func claudeStatusField(at place, path string, settled func()) Field { + // mine: settings.json has a status line; ours: it runs magpie's + cur := func() (has, ours bool) { + if _, ok := edit.GetJSONRaw(path, "statusLine"); !ok { + return false, false + } + cmd, _ := edit.GetJSON(path, "statusLine.command") + return true, claudeStatusOurs(cmd) + } + here := at.base == nil + return Field{ + Key: "statusline", Label: "status line", Quiet: true, + Get: func() string { + if _, ours := cur(); ours { + return "on" + } + return "" + }, + Set: func(v string) error { + has, ours := cur() + switch v { + case "", "off": + if !ours { + return nil + } + settled() + return edit.DelJSON(path, "statusLine") + case "on": + if ours { + return nil + } + if has { + return fmt.Errorf("%s has a status line of its own; magpie leaves it as it is (take it out there first, or add `magpie statusline` to the command it runs)", at.native(path)) + } + if !here { + return fmt.Errorf("magpie's status line is for Claude Code on this computer, not in WSL") + } + settled() + return edit.SetJSON(path, edit.KV{Path: "statusLine", Value: map[string]any{ + "type": "command", "command": claudeStatusCommand(claudeStatusExe(), runtime.GOOS), + }}) + } + return fmt.Errorf("status line is on or off, not %q", v) + }, + Options: func(map[string]string) []Option { + // a distro's file isn't read: a stopped one would start (#3896) + if !here { + return nil + } + if has, ours := cur(); has && !ours { + return nil + } + return []Option{{Value: "on", Note: "the 5h and 7d use of the accounts magpie serves, under Claude Code's prompt"}} + }, + } +} diff --git a/internal/agent/claude_statusline_test.go b/internal/agent/claude_statusline_test.go new file mode 100644 index 000000000..365afb471 --- /dev/null +++ b/internal/agent/claude_statusline_test.go @@ -0,0 +1,191 @@ +package agent + +import ( + "os" + "strings" + "testing" + + "github.com/yetone/magpie/internal/edit" +) + +// claudeStatusAt makes the status line written run exe. +func claudeStatusAt(t *testing.T, exe string) { + t.Helper() + old := claudeStatusExe + claudeStatusExe = func() string { return exe } + t.Cleanup(func() { claudeStatusExe = old }) +} + +// steven_4422 on Discord: the 5h and 7d use in Claude Code. The Agents +// page's switch writes settings.json's statusLine to run this magpie's +// statusline by its full path, beside what else is there, and takes it +// out again; nothing else in the file moves. +func TestClaudeStatusLineSwitch(t *testing.T) { + const before = `{ + "model": "opus", + "env": {"FOO": "1"} +} +` + home, path := claudeSettings(t, before) + claudeStatusAt(t, "/Applications/Magpie.app/Contents/MacOS/magpie") + a := claude(home) + f := a.Field("statusline") + if f == nil { + t.Fatal("Claude Code has no statusline field") + } + if f.Get() != "" { + t.Fatalf("off before: %q", f.Get()) + } + if opts := f.Options(nil); len(opts) != 1 || opts[0].Value != "on" { + t.Fatalf("options with no status line: %+v", opts) + } + if err := f.Set("on"); err != nil { + t.Fatal(err) + } + get := func(k string) string { v, _ := edit.GetJSON(path, k); return v } + if get("statusLine.type") != "command" || get("statusLine.command") != "/Applications/Magpie.app/Contents/MacOS/magpie statusline" || + get("model") != "opus" || get("env.FOO") != "1" { + t.Fatalf("on:\n%s", readFile(path)) + } + if f.Get() != "on" { + t.Fatalf("Get after on: %q", f.Get()) + } + // on again writes nothing new + if err := f.Set("on"); err != nil { + t.Fatal(err) + } + if err := f.Set(""); err != nil { + t.Fatal(err) + } + if _, ok := edit.GetJSONRaw(path, "statusLine"); ok || get("model") != "opus" || get("env.FOO") != "1" { + t.Fatalf("off:\n%s", readFile(path)) + } + if err := f.Set("maybe"); err == nil { + t.Fatal("a value neither on nor off was taken") + } +} + +// A status line of the user's own (claude-hud, a script) is never +// written over or taken out: the switch isn't offered, on is refused, off +// and Disconnect leave it byte for byte. +func TestClaudeStatusLineLeavesTheUsers(t *testing.T) { + const theirs = `{ + "statusLine": {"type": "command", "command": "bash -c 'node ~/.claude/plugins/claude-hud/dist/index.js'", "padding": 0} +} +` + home, path := claudeSettings(t, theirs) + claudeStatusAt(t, "/usr/local/bin/magpie") + a := claude(home) + f := a.Field("statusline") + if f.Get() != "" { + t.Fatalf("the user's read as magpie's: %q", f.Get()) + } + if opts := f.Options(nil); opts != nil { + t.Fatalf("offered over the user's own: %+v", opts) + } + if err := f.Set("on"); err == nil || !strings.Contains(err.Error(), "of its own") { + t.Fatalf("on over the user's own: %v", err) + } + if err := f.Set(""); err != nil { + t.Fatal(err) + } + if err := a.Unwire(); err != nil { + t.Fatal(err) + } + if got := readFile(path); got != theirs { + t.Fatalf("the user's status line changed:\n%s", got) + } +} + +// Disconnect takes magpie's status line out with the rest of magpie. +func TestClaudeStatusLineGoesOnDisconnect(t *testing.T) { + home, path := claudeSettings(t, `{"statusLine": {"type": "command", "command": "magpie statusline"}, "model": "opus"}`) + a := claude(home) + if a.Field("statusline").Get() != "on" { + t.Fatal("the reference's hand-written `magpie statusline` isn't read as magpie's") + } + if err := a.Unwire(); err != nil { + t.Fatal(err) + } + if _, ok := edit.GetJSONRaw(path, "statusLine"); ok { + t.Fatalf("magpie's status line left after Disconnect:\n%s", readFile(path)) + } +} + +// settings.json that can't be read is unknown, not "no status line": on +// writes nothing over it. +func TestClaudeStatusLineUnreadable(t *testing.T) { + home, path := claudeSettings(t, `{"model": "opus",,`) + a := claude(home) + if err := a.Field("statusline").Set("on"); err == nil { + t.Fatal("on over a settings.json that can't be read") + } + if b, _ := os.ReadFile(path); string(b) != `{"model": "opus",,` { + t.Fatalf("written over: %s", b) + } +} + +func TestClaudeStatusCommand(t *testing.T) { + for _, c := range []struct{ exe, goos, want string }{ + {"/Applications/Magpie.app/Contents/MacOS/magpie", "darwin", "/Applications/Magpie.app/Contents/MacOS/magpie statusline"}, + {"/home/me/Jo's Apps/Magpie-x86_64.AppImage", "linux", `'/home/me/Jo'\''s Apps/Magpie-x86_64.AppImage' statusline`}, + {`C:\Users\Me Too\AppData\Local\Programs\magpie\magpie.exe`, "windows", `'C:/Users/Me Too/AppData/Local/Programs/magpie/magpie.exe' statusline`}, + {`C:\Users\me\magpie.exe`, "windows", `C:/Users/me/magpie.exe statusline`}, + } { + got := claudeStatusCommand(c.exe, c.goos) + if got != c.want { + t.Errorf("claudeStatusCommand(%q, %s) = %q, want %q", c.exe, c.goos, got, c.want) + } + if !claudeStatusOurs(got) { + t.Errorf("%q, written by magpie, isn't read as magpie's", got) + } + } + for cmd, want := range map[string]bool{ + "magpie statusline": true, + "magpie statusline claude": true, + `"C:/x/magpie.exe" statusline`: true, + "magpie-darwin-arm64 statusline": true, + "magpie": false, + "magpie status": false, + "magpie statuslinex": false, + "notmagpie statusline": false, + "~/.claude/statusline.sh": false, + "bash -c 'magpie statusline'": false, + `'/x/magpie`: false, + "": false, + `/x/my\ apps/magpie statusline`: true, + "magpie statusline; rm -rf ~": false, + "magpie;statusline": false, + "magpie statusline && echo hi": false, + "magpie statusline | tr a b": false, + "$(which magpie) statusline": false, + "'/x/magpie' 'statusline'": true, + } { + if got := claudeStatusOurs(cmd); got != want { + t.Errorf("claudeStatusOurs(%q) = %v, want %v", cmd, got, want) + } + } +} + +// A WSL distro's Claude Code isn't offered magpie's status line, running +// or stopped (a stopped one's fields fall back to magpie's models), and on +// is refused there. +func TestWSLClaudeNoStatusLine(t *testing.T) { + root, _ := claudeDistroHome(t, `{}`) + saveDeepseek(t) + d := distro{Name: "Ubuntu", Root: root, Home: "/home/me", Has: map[string]bool{"dir:.claude": true}, Gateway: "172.20.0.1"} + k := wslKindOf("claude") + cur := map[string]string{"model": "deepseek/pro"} + for name, a := range map[string]*Agent{"running": wslAgent(k, d), "stopped": asleep(wslAgent(k, d), k, d)} { + f := a.Field("statusline") + if f == nil { + t.Fatalf("%s distro: no statusline field", name) + } + if o := f.Options(cur); len(o) != 0 { + t.Errorf("%s distro offers %v", name, o) + } + } + if err := wslAgent(k, d).Field("statusline").Set("on"); err == nil { + t.Error("on taken in a distro") + } +} diff --git a/internal/agent/wsl.go b/internal/agent/wsl.go index 168fbb62c..069828bc8 100644 --- a/internal/agent/wsl.go +++ b/internal/agent/wsl.go @@ -510,8 +510,9 @@ var wslKinds = []wslKind{ return func(cur map[string]string) []Option { return joinedVia(group("Claude Code", claudeOwn(cur["model"], nil, catalog.Provider("anthropic"))), claudeViaShared(false), [2]string{"\x00claude-via", "\x00asleep"}) } - case "effort", "ultracode": - // their own options read only what was last seen + case "effort", "ultracode", "statusline": + // their own options read only what was last seen; magpie's + // status line isn't offered in a distro return nil case "login": // its sign-in, while the model last seen is magpie's diff --git a/internal/cli/statusline_cli.go b/internal/cli/statusline_cli.go index a4afafed7..943d3ebad 100644 --- a/internal/cli/statusline_cli.go +++ b/internal/cli/statusline_cli.go @@ -30,9 +30,10 @@ const statuslineUsage = `usage: magpie statusline […] windows' use ("5h 62% 7d 41%"), * on the one that answered last. Accounts that answered through magpie in the last 30 days are shown, all of them when none has; a provider or an account's email, login or name keeps only those. - Claude Code runs it on every message with the session's JSON on stdin; put it in - ~/.claude/settings.json yourself (magpie doesn't write it, a status line such as - claude-hud may hold it): + Claude Code runs it on every message with the session's JSON on stdin. Turn it on + with the status line square on Claude Code's row in the Agents page (or + magpie claude statusline on), which writes ~/.claude/settings.json's statusLine + unless a status line of your own (claude-hud, a script) is there; or add it yourself: "statusLine": {"type": "command", "command": "magpie statusline"} It asks the gateway on this computer (the port in Settings' Gateway address, or MAGPIE_ADDR), never a vendor, and prints nothing when the gateway isn't running.` diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index b72ab5edd..f8cbe5bbd 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -492,7 +492,7 @@ function renderAgents() { const fields = el("div", "fields"); const wide = (f) => f.label === "model" || f.label === "large" || f.label === "executor" || f.label === "planner"; // a field with nothing to pick and nothing set isn't drawn (#1499) - const none = (f) => (f.key === "effort" || f.key === "ultracode" || f.label === "subagents" || f.label === SUB_EFFORT || f.label === SUB_MODEL || f.label === AUTO_MODE || f.label === MEMORIES || f.label === "sign-in" || f.key === "small" || asideAccount(a, f)) && !f.options.length && !f.value; + const none = (f) => (f.key === "effort" || toggled(f) || f.label === "subagents" || f.label === SUB_EFFORT || f.label === SUB_MODEL || f.label === AUTO_MODE || f.label === MEMORIES || f.label === "sign-in" || f.key === "small" || asideAccount(a, f)) && !f.options.length && !f.value; const shownFields = a.fields.filter((f) => !grouped(a, f) && !none(f) && !codexOwnSub(a, f) && !codexRowed(a, f) && !hermesBot(f)); const tiers = tierMenu(a); if (tiers) shownFields.push(tiers); @@ -2789,9 +2789,9 @@ async function openPluginAgents(e) { let agentsGlide = null; // how the panel's edge moves after the next render let panelOpenAgent = null; // the one agent row the panel has opened -// set up: a model, a provider, a role given one, not an effort or ultracode; +// set up: a model, a provider, a role given one, not an effort or a switch; // one with 「接入」's switch only when connected or drifted (#726). -const tweak = (f) => f.key === "ultracode" || f.key === "effort" || f.key.endsWith("_effort"); +const tweak = (f) => toggled(f) || f.key === "effort" || f.key.endsWith("_effort"); const onMagpie = (a) => !!(a.added || a.wired || a.drift); // one whose only control is its launch command (Cursor Private Inference) // has nothing set to tell by, and stays up while it is there @@ -4002,7 +4002,7 @@ function codexSubSaid(a, f) { const line = f.value ? t(SUB_MODEL_SET) : (lead ? t(SUB_MODEL_UNSET, { model: lead }) : t(SUB_MODEL_UNSET_PLAIN)) + (old ? "\n" + t(SUB_MODEL_OLD, { model: optionFor(a.fields.find((x) => x.label === "subagents"), old)?.label || old }) : ""); return { name, line, old, lead }; } -const extra = (f) => f.key === "tiers" || FOLLOWS_MODEL.includes(f.label) || f.label === "sign-in" || f.key === "ultracode" || f.label === SUB_EFFORT || f.label === SUB_MODEL || f.label === AUTO_MODE || f.label === MEMORIES; +const extra = (f) => f.key === "tiers" || FOLLOWS_MODEL.includes(f.label) || f.label === "sign-in" || toggled(f) || f.label === SUB_EFFORT || f.label === SUB_MODEL || f.label === AUTO_MODE || f.label === MEMORIES; const EXTRA_GLYPH = { subagents: "M4.5 2.75v10.5M4.5 9.25c0-2.2 1.6-3.75 3.9-3.75h3.35M9.9 3.6l1.9 1.9-1.9 1.9", // a feather for omp's smol role, an hourglass for its slow one @@ -4011,6 +4011,7 @@ const EXTRA_GLYPH = { tiers: "M8 2.6 2.75 5.4 8 8.2l5.25-2.8zM2.75 8.1 8 10.9l5.25-2.8M2.75 10.8 8 13.6l5.25-2.8", "sign-in": "M8 2.5a2.75 2.75 0 1 1 0 5.5 2.75 2.75 0 0 1 0-5.5zM3 13.5c.4-2.4 2.4-3.9 5-3.9s4.6 1.5 5 3.9", ultracode: "M3 4.25h4M3 8h2.5M3 11.75h4M9.5 4.25l3.5 3.75-3.5 3.75", + statusline: "M2.75 3.25h10.5v9.5H2.75zM2.75 10h10.5M4.75 11.4h3.5", // the subagents' branch, with effort's rising bars after it [SUB_EFFORT]: "M3.25 2.75v10.5M3.25 9.25c0-2.2 1.6-3.75 3.9-3.75h.6M9.25 13.25v-2M11.5 13.25v-4M13.75 13.25v-6", // the subagents' branch, ending on a pin: their model, set by magpie @@ -4026,7 +4027,7 @@ const EXTRA_GLYPH = { const MEMORIES_DEFAULT = "Codex's own: gpt-5.6-terra/luna, or the session's magpie model"; const SAME_SESSION = "Same as the session"; function extraField(a, f) { - if (f.key === "ultracode") return ultracodeToggle(a, f); + if (toggled(f)) return fieldToggle(a, f); const said = f.label === SUB_MODEL && codexSub(a) ? codexSubSaid(a, f) : null; const set = !!(f.value || f.custom || said?.old); const b = el("button", "field extra" + (set ? " set" : "")); @@ -4680,14 +4681,18 @@ function holdPop(pop, room) { if (!(parseFloat(getComputedStyle(pop).maxHeight) <= room)) pop.style.maxHeight = room + "px"; } -// ultracodeToggle: Claude Code's ultracode as a square that a click turns -// on or off, lit while on; nothing to pick between. What it does, and that -// an open session keeps what it started with, is said as it changes. -function ultracodeToggle(a, f) { +// a Claude Code switch: a square a click turns on or off, lit while on. +const TOGGLES = { + ultracode: { label: "ultracode", note: "Claude plans a workflow for each substantive task", said: "{agent} ultracode → {value}" }, + statusline: { label: "status line", note: "the 5h and 7d use of the accounts magpie serves, under Claude Code's prompt", said: "{agent} status line → {value}" }, +}; +function toggled(f) { return Object.hasOwn(TOGGLES, f.key); } +function fieldToggle(a, f) { + const k = TOGGLES[f.key]; const on = f.value === "on"; const b = el("button", "field extra" + (on ? " set" : "")); - b.append(svg(EXTRA_GLYPH.ultracode, 13, 1.5)); - b.title = t("{label}: {value}", { label: "ultracode", value: t(on ? "on" : "off") }) + "\n" + t("Claude plans a workflow for each substantive task"); + b.append(svg(EXTRA_GLYPH[f.key], 13, 1.5)); + b.title = t("{label}: {value}", { label: t(k.label), value: t(on ? "on" : "off") }) + "\n" + t(k.note); b.setAttribute("aria-label", b.title); b.setAttribute("aria-pressed", String(on)); b.dataset.key = f.key; @@ -4696,8 +4701,7 @@ function ultracodeToggle(a, f) { try { state = await api("set", { agent: a.id, field: f.key, value: on ? "" : "on" }); renderAgents(); - const msg = t("{agent} ultracode → {value}", { agent: a.name, value: t(on ? "off" : "on") }); - saidOk(msg); + saidOk(t(k.said, { agent: a.name, value: t(on ? "off" : "on") })); } catch (e) { statusErr(e); } }; return b; @@ -4717,14 +4721,9 @@ function oneRowPerModel(options, cur) { return options.filter((o) => !gone.has(o)); } -// foldSame: magpie's rows for the very account the agent is signed in to -// itself (Claude Code's Claude subscription, added in magpie too) are the -// agent's own models a second time; they fold into one row that a click -// opens, for the few who want them (failover to more accounts, a fix that -// only magpie's way has). The value set stays a row of its own (#496). The -// row comes after the agent's own rows of its group: the account is listed -// after the providers the user added, and in its place the group was -// headed twice. A query shows every row it finds, for Enter to pick. +// foldSame: magpie's rows for the account the agent is signed in to itself +// fold into one row a click opens, after the agent's own rows of its group; +// the value set keeps its row (#496), and a query shows every row. function foldSame(items) { if (!pick.modelPicker || pick.groupFilter === "favorites" || $("#q").value.trim()) return items; const same = items.filter((o) => o.same && o.value !== pick.field.value); diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 138bf35aa..54b72e590 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -864,6 +864,9 @@ const I18N = { "on": "开启", "Claude plans a workflow for each substantive task": "Claude 会为每个稍大的任务规划 workflow", "{agent} ultracode → {value}": "{agent} ultracode → {value}", + "status line": "状态栏", + "the 5h and 7d use of the accounts magpie serves, under Claude Code's prompt": "Claude Code 输入框下方显示 magpie 所用账号的 5 小时和 7 天用量", + "{agent} status line → {value}": "{agent} 状态栏 → {value}", "an open Claude Code session keeps the effort it started with — restart it to use this.": "已打开的 Claude Code 会话仍用启动时的推理强度,重开后生效。", "an open Claude Code session keeps the ultracode it started with — restart it to use this.": "已打开的 Claude Code 会话仍用启动时的 ultracode 设置,重开后生效。", "magpie's models join Codex's own; Codex stays signed in to ChatGPT, and while the Codex app blocks its account (out of allowance, no credits left) magpie is Codex's provider, so the app still sends": "默认。Codex 保持 ChatGPT 登录,magpie 的模型与 Codex 自带模型并列;当 Codex 应用拦下该账号(额度用尽且没有剩余积分)时,magpie 临时作为 Codex 的供应商,让 Codex 应用仍能发送", @@ -5390,6 +5393,9 @@ const I18N = { "on": "開啟", "Claude plans a workflow for each substantive task": "Claude 會為每個稍大的任務規劃 workflow", "{agent} ultracode → {value}": "{agent} ultracode → {value}", + "status line": "狀態列", + "the 5h and 7d use of the accounts magpie serves, under Claude Code's prompt": "Claude Code 輸入框下方顯示 magpie 所用帳號的 5 小時和 7 天用量", + "{agent} status line → {value}": "{agent} 狀態列 → {value}", "an open Claude Code session keeps the effort it started with — restart it to use this.": "已開啟的 Claude Code 會話仍用啟動時的推理強度,重開後生效。", "an open Claude Code session keeps the ultracode it started with — restart it to use this.": "已開啟的 Claude Code 會話仍用啟動時的 ultracode 設定,重開後生效。", "magpie's models join Codex's own; Codex stays signed in to ChatGPT, and while the Codex app blocks its account (out of allowance, no credits left) magpie is Codex's provider, so the app still sends": "預設。Codex 保持 ChatGPT 登入,magpie 的模型與 Codex 自帶模型並列;當 Codex 應用攔下該帳號(額度用盡且沒有剩餘積分)時,magpie 臨時作為 Codex 的供應商,讓 Codex 應用仍能傳送", @@ -9881,6 +9887,9 @@ const I18N = { "on": "オン", "Claude plans a workflow for each substantive task": "Claude は実質的なタスクごとにワークフローを計画します", "{agent} ultracode → {value}": "{agent} ultracode → {value}", + "status line": "ステータスライン", + "the 5h and 7d use of the accounts magpie serves, under Claude Code's prompt": "Claude Code の入力欄の下に、magpie が使うアカウントの 5 時間と 7 日の使用量を表示します", + "{agent} status line → {value}": "{agent} ステータスライン → {value}", "an open Claude Code session keeps the effort it started with — restart it to use this.": "開いている Claude Code セッションは起動時の推論レベルのままです。反映するには再起動してください。", "an open Claude Code session keeps the ultracode it started with — restart it to use this.": "開いている Claude Code セッションは起動時の ultracode のままです。反映するには再起動してください。", "magpie's models join Codex's own; Codex stays signed in to ChatGPT, and while the Codex app blocks its account (out of allowance, no credits left) magpie is Codex's provider, so the app still sends": "magpie のモデルが Codex 独自のモデルに加わります。Codex は ChatGPT にサインインしたままで、Codex アプリがアカウントを止めている間(使用量を使い切り、クレジットも残っていないとき)は magpie が Codex のプロバイダーになり、Codex アプリは送信を続けられます", @@ -14390,6 +14399,9 @@ const I18N = { "on": "an", "Claude plans a workflow for each substantive task": "Claude plant für jede größere Aufgabe einen Workflow", "{agent} ultracode → {value}": "{agent} ultracode → {value}", + "status line": "Statuszeile", + "the 5h and 7d use of the accounts magpie serves, under Claude Code's prompt": "die 5-Stunden- und 7-Tage-Nutzung der Konten, die magpie nutzt, unter der Eingabe von Claude Code", + "{agent} status line → {value}": "{agent} Statuszeile → {value}", "an open Claude Code session keeps the effort it started with — restart it to use this.": "eine offene Claude-Code-Sitzung behält den Reasoning-Effort vom Start — zum Übernehmen neu starten.", "an open Claude Code session keeps the ultracode it started with — restart it to use this.": "eine offene Claude-Code-Sitzung behält die ultracode-Einstellung vom Start — zum Übernehmen neu starten.", "magpie's models join Codex's own; Codex stays signed in to ChatGPT, and while the Codex app blocks its account (out of allowance, no credits left) magpie is Codex's provider, so the app still sends": "magpie-Modelle kommen zu den eigenen von Codex hinzu; Codex bleibt bei ChatGPT angemeldet, und solange die Codex-App das Konto blockiert (Kontingent aufgebraucht, keine Credits mehr), ist magpie der Anbieter von Codex, damit die Codex-App weiter senden kann", diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go index 249f955d5..d85de2a93 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) + 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) ) func TestCoreScriptBudget(t *testing.T) { diff --git a/internal/gui/tests/claude-statusline.test.cjs b/internal/gui/tests/claude-statusline.test.cjs new file mode 100644 index 000000000..bac7bb9f9 --- /dev/null +++ b/internal/gui/tests/claude-statusline.test.cjs @@ -0,0 +1,108 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Claude Code's status line (steven_4422 on Discord: the 5h and 7d use in +// Claude Code): a square on Claude Code's row, beside ultracode's, that a +// click turns on (posting statusline on) and off again, lit while on, its +// title saying what it shows and the change said in the status, in every +// language. A row whose settings.json has a status line of the user's own +// gets no options from magpie and shows no square. Chromium and WebKit, +// the window and the narrow tray panel. +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"); +const NOTE = "the 5h and 7d use of the accounts magpie serves, under Claude Code's prompt"; +const claude = (id, value, offered) => ({ + id, name: "Claude Code " + id, icon: "claudecode-color", path: "/test/" + id, wired: true, + fields: [ + { key: "model", label: "model", value: "claude-opus-5-5", options: [{ value: "claude-opus-5-5", icon: "claude-color", ref: "claude/claude-opus-5-5" }] }, + { key: "statusline", label: "status line", value, options: offered ? [{ value: "on", note: NOTE }] : [] }, + ], +}); + +function serve(lang, sets) { + let on = false; + const st = () => ({ agents: [claude("mine", on ? "on" : "", true), claude("theirs", "", false)], profiles: [], settings: { lang, theme: "light" } }); + return async (route) => { + const req = route.request(), url = new URL(req.url()); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return route.fulfill({ json: st() }); + if (url.pathname === "/api/set") { + const b = req.postDataJSON(); + sets.push(b); + if (b.field === "statusline") on = b.value === "on"; + return route.fulfill({ json: st() }); + } + if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } }); + if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] }); + if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } }); + if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } }); + if (url.pathname.startsWith("/api/")) return route.fulfill({ 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)]; + await route.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +const words = { + en: { label: "status line", note: "5h and 7d use", said: "status line → on" }, + zh: { label: "状态栏", note: "5 小时和 7 天用量", said: "状态栏 → 开启" }, + "zh-TW": { label: "狀態列", note: "5 小時和 7 天用量", said: "狀態列 → 開啟" }, + ja: { label: "ステータスライン", note: "5 時間と 7 日の使用量", said: "ステータスライン → オン" }, + de: { label: "Statuszeile", note: "7-Tage-Nutzung", said: "Statuszeile → an" }, +}; +const row = (id) => `.row.agent[data-id="${id}"]`; +const square = (id) => `${row(id)} .field[data-key="statusline"]`; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of Object.keys(words)) { + const w = words[lang]; + test(`${engine} ${lang}: Claude Code's status line is a switch`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const errors = []; + t.after(async () => { + if (errors.length) console.log(errors); + await browser.close(); + }); + for (const mode of ["", "panel"]) { + await t.test(mode || "window", async () => { + const sets = []; + const page = await (await browser.newContext({ viewport: { width: mode ? 400 : 900, height: 560 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, sets)); + await page.goto("http://magpie.test/" + (mode ? "?mode=" + mode : "")); + await page.locator(row("mine")).waitFor(); + // one row open at a time: the user's first, then magpie's + for (const id of ["theirs", "mine"]) { + await page.locator(`${row(id)} ${mode ? ".ag-sum" : ".ag-link"}`).click(); + await page.waitForTimeout(mode ? 700 : 200); + if (id === "theirs") assert.equal(await page.locator(square("theirs")).count(), 0, "a square over the user's own status line"); + } + const sq = page.locator(square("mine")).first(); + await sq.waitFor(); + assert.equal(await sq.getAttribute("aria-pressed"), "false"); + const title = await sq.getAttribute("title"); + assert.ok(title.includes(w.label) && title.includes(w.note), `title ${JSON.stringify(title)}`); + const box = await sq.boundingBox(); + assert.ok(box && box.x >= 0 && box.x + box.width <= (mode ? 400 : 900), "the square is off the page"); + await sq.click(); + await page.waitForTimeout(300); + assert.deepEqual(sets, [{ agent: "mine", field: "statusline", value: "on" }]); + assert.ok((await page.locator("#status").textContent()).includes(w.said), await page.locator("#status").textContent()); + const lit = page.locator(square("mine")).first(); + assert.equal(await lit.getAttribute("aria-pressed"), "true"); + assert.match(await lit.getAttribute("class"), /\bset\b/); + await lit.click(); + await page.waitForTimeout(300); + assert.deepEqual(sets[1], { agent: "mine", field: "statusline", value: "" }); + }); + } + assert.deepEqual(errors, []); + }); + } +}