lyj1115 on X asked for the current account's quota, or the relay key's
balance, under Codex's chat box, off by default. Codex's TUI draws its
footer from a status line provider from 0.171.0-alpha.12 on: a stdio
MCP server whose tool advertises a statusline entrypoint, picked in
[tui] status_line_provider behind [features] tui_extensions_statusline.
Codex reads it about once a second with the thread's id. Nothing is put
into the prompt or the model's reply.
- `magpie statusline --codex` is that server. Each read asks the local
gateway for the thread's latest route and the kept quotas (no vendor
read). It answers `→ provider/model` and that provider's account that
answered last, with its windows or a key's balance. A gateway that is
down gives a null tree, never an error, because an error stops Codex's
reads. The tool's name and words name neither magpie nor a vendor,
since the tool is listed to the model.
- A status line square on Codex's row (`magpie codex statusline on`)
writes the flag, [mcp_servers.quota_line] (this magpie by full path,
args statusline --codex, env_vars = ["MAGPIE_ADDR"]) and the
provider. Every write is read back, and the file is restored on a
mismatch. Off and Disconnect take out only magpie's keys, and the flag
only when the stash says magpie wrote it.
- Nothing of the user's is written over. A provider of their own, a
quota_line of theirs, the flag turned off or an unreadable file keeps
the square away and refuses on.
- The switch is offered only when a Codex CLI here is 0.171.0-alpha.12
or newer (0.170.0 reads the keys and draws nothing), and only on this
computer, not in a WSL distro.
- In the GUI, the status line square's title takes the note of its
field's on option, which Claude Code's field already sent with the
same words TOGGLES kept, so Codex's says its own words in en, zh,
zh-TW, ja and de. TOGGLES' copy of Claude's note went, and app.js
stays under its budget (30 bytes of room) without a raise.
The Codex desktop app has no such footer. cockpit-tools reaches it
through a debug port, and magpie doesn't.
Run (WSL magpie-desktop, since mote's load was over 18):
- go vet -tags nogui ./...; GOOS=windows go vet of agent, cli, provider
and gui; gofmt -l clean.
- go test -tags nogui of ./internal/cli and ./internal/provider: ok.
- ./internal/agent -run "CodexStatus|Statusline|StatusLine|TestCodex|
TestWSLCodex": ok.
- ./internal/gui -run "CoreScript|Budget|I18n|Keys" and node --test of
codex-statusline, claude-statusline and i18n-keys (both engines, every
language, window and panel), with vet (and GOOS=linux and windows
vet) of agent, cli, provider and gui, on mote at the rebased head
(on 1bd1a08a3): all ok, 64 of 64 GUI cases.
Broken by hand:
- free() reduced to `readable`: TestCodexStatusLineLeavesTheUsers is red
on their provider, their server and flag off.
- The field not appended: TestCodexStatusLineSwitch is red ("no
statusline field").
- The first build checked `at.base == nil` after codexIn had set base.
Every agent test went red, which is how that bug was found.
Real Codex, in a sandbox HOME on WSL with a fake gateway:
- 0.171.0-alpha.13, with `magpie codex statusline on` writing config.toml,
draws `→ relay/glm-5 relay $4.20` under the prompt, and the server is
read about once a second.
- Without env_vars, Codex starts the server without MAGPIE_ADDR: nothing
was asked and nothing was drawn. That is why env_vars is written.
- On a second time leaves the file byte for byte. Off brings it back to
what it was, apart from Codex's own NUX counter.
- 0.170.0 lists quota_line from the same file and runs fine.
Not tried: macOS and Windows Codex; a real gateway with real accounts
(the server was fed through MAGPIE_ADDR); whether an open Codex session
picks the footer up without a restart.
Full suite: run after push.
118 lines
4.7 KiB
Go
118 lines
4.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/json"
|
|
"io"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// codexRead is a resources/read as Codex's TUI sends it (statusline.d.ts:
|
|
// the thread's state in params._meta), cut to the fields around the one
|
|
// read.
|
|
const codexRead = `{"jsonrpc":"2.0","id":3,"method":"resources/read","params":{"uri":"ui://quota-line/footer","_meta":{"com.openai/codex-statusline-state":{"thread":{"id":"6f1d2c3a-9b8e-4a7f-8c1d-2e3f4a5b6c7d"},"model":{"name":"gpt-5.5"},"account":{"rate_limits":null}}}}}`
|
|
|
|
// mcpTalk sends lines to a codexStatus and returns its replies by id.
|
|
func mcpTalk(t *testing.T, c *codexStatus, lines ...string) map[string]map[string]any {
|
|
t.Helper()
|
|
pr, pw := io.Pipe()
|
|
go func() {
|
|
c.serve(strings.NewReader(strings.Join(lines, "\n")+"\n"), pw)
|
|
pw.Close()
|
|
}()
|
|
out := map[string]map[string]any{}
|
|
sc := bufio.NewScanner(pr)
|
|
for sc.Scan() {
|
|
var m map[string]any
|
|
if err := json.Unmarshal(sc.Bytes(), &m); err != nil {
|
|
t.Fatalf("%v: %s", err, sc.Text())
|
|
}
|
|
id, _ := json.Marshal(m["id"])
|
|
out[string(id)] = m
|
|
}
|
|
return out
|
|
}
|
|
|
|
// lyj1115 on X: Codex's footer shows the model the thread went to and
|
|
// that account's windows, from what the gateway kept (never a vendor
|
|
// read); a tool Codex's statusline picker takes (its entrypoint), whose
|
|
// words name neither magpie nor a vendor, since the model is told them.
|
|
func TestCodexStatuslineServer(t *testing.T) {
|
|
now := time.Now()
|
|
s := statuslineGateway(t, now)
|
|
c := newCodexStatus(s.URL)
|
|
got := mcpTalk(t, c,
|
|
`{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"codex-mcp-client","version":"0.171.0"}}}`,
|
|
`{"jsonrpc":"2.0","method":"notifications/initialized"}`,
|
|
`{"jsonrpc":"2.0","id":2,"method":"tools/list"}`,
|
|
codexRead,
|
|
`{"jsonrpc":"2.0","id":4,"method":"resources/read","params":{"uri":"ui://quota-line/footer","_meta":{"com.openai/codex-statusline-state":{"thread":{"id":"another"}}}}}`,
|
|
`{"jsonrpc":"2.0","id":5,"method":"nope"}`,
|
|
)
|
|
if len(got) != 5 {
|
|
t.Fatalf("replies: %v", got)
|
|
}
|
|
if res, _ := got["1"]["result"].(map[string]any); res["protocolVersion"] != "2025-06-18" {
|
|
t.Fatalf("initialize: %v", got["1"])
|
|
}
|
|
tools, _ := got["2"]["result"].(map[string]any)["tools"].([]any)
|
|
tool, _ := tools[0].(map[string]any)
|
|
b, _ := json.Marshal(tool)
|
|
if tool["name"] != "statusline" || !strings.Contains(string(b), `"entrypoints":[{"resourceUri":"ui://quota-line/footer","type":"statusline"}]`) {
|
|
t.Fatalf("tool: %s", b)
|
|
}
|
|
if low := strings.ToLower(string(b)); strings.Contains(low, "magpie") || strings.Contains(low, "codex") || strings.Contains(low, "openai\"") {
|
|
t.Fatalf("the tool the model is told of names magpie or a vendor: %s", b)
|
|
}
|
|
tree := func(id string) string {
|
|
res, _ := got[id]["result"].(map[string]any)
|
|
cs, _ := res["contents"].([]any)
|
|
c, _ := cs[0].(map[string]any)
|
|
if c["mimeType"] != "application/json" {
|
|
t.Fatalf("read %s: %v", id, got[id])
|
|
}
|
|
return c["text"].(string)
|
|
}
|
|
// the thread's route is claude's: its account that answered last
|
|
if want := `{"children":[{"children":["→ claude/claude-opus-5-5"],"props":{"color":"status-model"},"type":"text"},{"children":["claude a@example.com 5h 62% 7d 41%"],"props":{"color":"status-limit"},"type":"text"}],"props":{"gap":2,"wrap":"wrap"},"type":"row"}`; tree("3") != want {
|
|
t.Fatalf("read:\n got %s\nwant %s", tree("3"), want)
|
|
}
|
|
// a thread the gateway has no route for: the account that answered last
|
|
if !strings.Contains(tree("4"), `"claude a@example.com 5h 62% 7d 41%"`) || strings.Contains(tree("4"), "→") {
|
|
t.Fatalf("read with no route: %s", tree("4"))
|
|
}
|
|
if got["5"]["error"] == nil {
|
|
t.Fatalf("unknown method answered: %v", got["5"])
|
|
}
|
|
}
|
|
|
|
// A relay key's balance is the account's line; a gateway that doesn't
|
|
// answer clears the footer (null) and never errors, which would stop
|
|
// Codex's reads.
|
|
func TestCodexStatuslineBalanceAndDown(t *testing.T) {
|
|
now := time.Now()
|
|
c := newCodexStatus(statuslineGateway(t, now).URL)
|
|
if got := c.cells(""); len(got) != 1 || got[0] != "claude a@example.com 5h 62% 7d 41%" {
|
|
t.Fatalf("no thread: %q", got)
|
|
}
|
|
down := newCodexStatus("http://127.0.0.1:1")
|
|
got := mcpTalk(t, down, codexRead)
|
|
res, _ := got["3"]["result"].(map[string]any)
|
|
cs, _ := res["contents"].([]any)
|
|
if len(cs) != 1 || cs[0].(map[string]any)["text"] != "null" {
|
|
t.Fatalf("gateway down: %v", got["3"])
|
|
}
|
|
}
|
|
|
|
// statusline --codex takes nothing else, and a flag it doesn't know is
|
|
// refused, never read as an account.
|
|
func TestStatuslineFlags(t *testing.T) {
|
|
for _, args := range [][]string{{"statusline", "--codex", "x"}, {"statusline", "--nope"}, {"statusline", "--help"}} {
|
|
if err := statuslineCmd(args); err == nil || !strings.Contains(err.Error(), "usage") {
|
|
t.Fatalf("%q: %v", args, err)
|
|
}
|
|
}
|
|
}
|