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: "<this magpie's full path> 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 on3088872e6): 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, from0872bc2a0on 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 onf37742e14(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.
This commit is contained in:
+11
-5
@@ -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 [<file>]` 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
|
||||
|
||||
@@ -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.<id>.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:<distro>` 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)): `<model>=effort[,xhigh_effort][,max_effort]` for those it is shown, and, while Claude Desktop is on magpie, for Desktop's `mythos-magpie-<number>` 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/<model>`. 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/<name>/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:<distro>.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`).
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"}}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -30,9 +30,10 @@ const statuslineUsage = `usage: magpie statusline [<provider|account>…]
|
||||
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.`
|
||||
|
||||
+20
-21
@@ -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);
|
||||
|
||||
@@ -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",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user