Commit Graph
17 Commits
Author SHA1 Message Date
yetone 3a7d0314a9 usage: a window's Pace as a number on its card, and in the menu bar when asked (fflake33)
fflake33 on Discord asked for the pace as a figure, "+12%" or "−8%"
against an even pace through the window, on the Usage cards and in the
menu bar.

- provider: QuotaWindow.Pace(readAt, now) is the share used (0-100) less
  the share of the window gone by, from Bounds (reset less span; a
  month's window a calendar month); none for an unlimited window, one
  whose span or reset isn't known, or outside it. WithWindowStarts sets
  startsAt on copies of the cards for the GUI (the caches' cards are
  left alone); /api/usage/quotas and its refresh send it.
- Usage page: "Pace +20%" on the reset line after the wait (quotaPace,
  paceLine), its sign turned with the meter in Left mode, amber while
  more is used than an even pace would have, what it means in its
  tooltip. Past cycles and windows with no known start show none.
- Menu bar: Settings > Menu bar pace (settings.TrayPace, off by default;
  hidden on Windows, whose tray shows no text) puts " +12%" beside each
  figure ("42% −14%", at most 10 runes, trayRowMax) and "pace −14%" in
  the tooltip. KeepOwn keeps it device-local like the other tray
  settings; the Settings save keeps it (prefsKeep).
- Strings in en, zh, zh-TW, ja, de. gui-shell.md says it.

Run:
- go test -tags nogui ./internal/provider ./internal/gui ./internal/settings
  ./internal/usage: ok; ./internal/davsync: ok (now covers TrayPace;
  red with TrayPace taken out of KeepOwn). go test ./internal/gui -run
  Tray (darwin, with the tray image tests): ok.
- New TestWindowPace, TestWithWindowStarts (input not mutated),
  TestTrayUsagePace (off unchanged, used and left, rows, tooltip).
- quota-pace.test.cjs, chromium and webkit: 4 pass; cards in en, zh,
  zh-TW, ja, de at 1100 and 420px, used and left, amber, tooltips, no
  sideways scroll, a click moves nothing; the Settings row in all five
  at both widths, On posts trayPace, a currency save keeps it, no
  scroll; hidden with no card and on Windows, shown on Linux. Red with
  paceLine not called, with trayPace out of prefsKeep, and with the
  Left-mode sign not turned.
- gui-de, gui-ja, gui-zh-tw, i18n-keys: 12 pass; tray-bird 6, quota-holds
  2, quota-read-at 4 pass.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows clean.
Not tried: the real menu bar on a Mac or Linux tray.
2026-10-14 13:02:48 +08:00
yetone db0af71864 gui: the menu bar can show today's or the last 7 days' tokens and cost (#1984)
Settings → Usage → "In the menu bar" lists two more rows after the
subscriptions: "Tokens and cost today" and "Tokens and cost, last 7 days",
ticked and saved as a card is (ids "usage:today", "usage:7d" in
trayUsages; provider ids are [a-z0-9-], so the prefix can't collide). They
show beside the allowances or alone.

- trayusage.go: a total is a card built from usage.SummarizeTop(p, 0)'s
  Totals (the Usage page's own cached numbers, Input+Output as its
  tokensOf counts them): tokens over cost, in the currency Settings picks,
  "+" when some requests had no known price. On the Mac it is a Plain cell
  (no vendor logo; the bird beside it says whose it is); on Windows/Linux
  the tray's text label and tooltip ("Today in magpie / 1.2M tokens (912K
  in · 318K out) / ≈$3.40+ / 152 requests…"). Quotas aren't fetched when
  only totals are picked.
- Clicked, a total opens the Usage page's Overview at its period
  (quotaView → ?view=usage&tab=usage&period=…, read and dropped from the
  URL) or the panel's Usage tab at that period (panelUseFocus).
- Only today and 7d: the Usage page has no 3-day window, and a menu-bar
  number nobody can open in magpie at the same span would disagree with it.
- The pill names a lone total, and counts a mix as "{n} shown" rather than
  calling it subscriptions. Strings in en/zh/zh-TW/ja/de.
- docs/reference.md and gui-shell.md say so.

Run:
- go test -tags nogui ./internal/gui/ (sandbox HOME): ok. The new
  TestTrayTotals/BesideCards/TrayCount went red with each piece broken by
  hand (no Plain, no text branch, no quotaView branch, 3d accepted).
- tray-totals.test.cjs (new) plus tray-usages, tray-inuse,
  proto-menu-overflow (updated for the two rows), i18n-keys, panel-usage,
  allowance-open-read, tray-cell-click: 46/46 in Chromium and WebKit, five
  languages, 1100 and 420 wide. tray-totals fails 5/5 against the old
  app.js.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- The Mac cell image rendered and looked at (bird, "1.2M" over "$3.40").

Not tried: a real macOS menu bar, nor a Windows or Linux tray; the tray
tooltip is English, as the existing tray tooltips are.
2026-10-13 18:15:18 +08:00
yetone cd93bbec0e provider, gui: a signed-in account can be given a name of the user's own, and a GLM seat's account card keeps the key plan's name and no longer flickers back to two cards (#1515, aindijrncom)
The same GLM Coding Plan team seat was added twice: as a key provider the
user had named, and as a ZCode plugin account. The Usage page kept only the
account's card, which read "31****36@qq.com" or just "ZCode", and whenever
either read failed ("BigModel API keys: not JSON") or a window had no reset
yet, the key's card came back beside it.

Seat (the flicker): the old check returned "different" on any error. It
now returns same, different or unknown (seatMatch). A match is remembered in
seats.json beside quotas.json; while the remembered account is signed in an
unknown check keeps the key card hidden, windows that disagree forget it,
and a signed-out account brings the key card back (seatCards, used by
quotas, Allotted and CachedCards). A failed read is "unknown", never "not
the same".

Names: providers.json gains accountNames (by the account in lower case,
like accountCaps), set by provider.SetAccountName. They are magpie's own
and never written into the vendor's or a plugin's sign-in. Built-in and
plugin accounts both take one; key providers are refused. Each card carries
Alias (the user's name, else the seat) and Seat (the key provider's name,
and the key's when it has several).
- GUI: the editor's account row shows the name with the address beside
  it, or the address with "≡ <key plan>"; a click or Enter renames it in
  place (posted once to provider/accountname; Escape leaves it, empty
  clears it). The name stays selectable text: dragging across it renames
  nothing.
  The Usage page's cards and the tray panel name the account the same way.
  Hide accounts hides the name too. Strings in zh, zh-TW, ja, de.
- The tray tooltip says "ZCode · <name>".
- CLI: `magpie accounts alias <agent> <email> [<name>|--clear]`.
  `magpie accounts` and `magpie quota` show the name; quota also matches
  on it.
- /v1/magpie/quotas carries alias and seat.

Run:
- account_seats_test TestSeatKeptThroughAFailedRead fails on the old code
  ("a failed read brought the key's card back") and passes now.
  TestAccountNameOfAPluginAccount uses the fake plugin and checks that
  plugin-auth.json and logins.json are byte-for-byte unchanged.
  TestAccountsAlias checks that Codex's auth.json is unchanged.
  TestTrayNamesTheAccountByItsAlias.
- account-alias.test.cjs: Chromium and WebKit; en, zh, zh-TW, ja, de;
  900 and 360px; 20/20 pass. It covers no scroll on a click, keyboard,
  selectable text, no select, no stripe, no sideways scroll and masking.
  With the post-once guard removed it goes red. account-arrange (text
  selection) passes in both engines.
- Sandbox HOME, built binary, vendors behind a dead proxy:
  - `magpie accounts alias codex Me@Example.com 某某·GLM高级版`, then
    `magpie accounts` and `magpie quota` showed the name.
  - An unknown account was refused.
  - `magpie web` on spare ports: POST /api/provider/accountname saved
    "Team seat" (whitespace folded), and an unknown account got an error.
  - Gateway /v1/magpie/quotas and /api/usage/quotas carried the alias.
  - auth.json's sha was unchanged throughout.
- go test -tags nogui ./... (temp HOME, load ~200): all ok except
  TestSetAnswersWhileDevinAndProvidersHang (15.5s under load), which
  passes alone 3/3 at ~250ms.
- gofmt -l; GOOS=linux and GOOS=windows go vet on internal/provider,
  internal/gui and the root package.
- The whole GUI suite in Chromium and WebKit, each failed file rerun
  alone. These are red on the parent commit 472b36cec as well:
  mobile-web (9), usage-heatmap (11), old-webkit (Safari 15 :has and
  :focus-visible rules), usage-alert on WebKit (2), and routing-proxy,
  which flakes 2 of 3 runs on the base. Every other file passes alone.
Not run: a real GLM key plus a real ZCode account. The seat match against
real BigModel/ZCode answers is covered only by the fake-upstream tests.
2026-10-11 03:42:35 +08:00
yetone bc2496dca8 gui, provider: the menu bar's "Account in use" moves as soon as another account answers, and a plugin's shows the one that answered last (#1516, ikxlpz)
f5c062677 made the menu bar's account-in-use card ("codex|*") follow the
account that answered through the gateway within the last hour. Two gaps
were left:

- The tray read its cards again only every few minutes, so after the
  gateway moved to another account, or the user switched, the menu bar
  kept the old account's numbers until the next tick. NoteServed now calls
  OnServedMoved when a provider's answers move to another account or key
  (and on the first one this process sees), and SwitchLogin calls it after
  a switch; the tray loop is woken by it, as by OnSubscriptionUsage.
- A plugin's accounts (moved Kiro, Devin, ...) are no sign-in InUseLogin
  knows, so with nothing served in the last hour the first card was shown
  even when the gateway had last gone to another. trayInUseCard now takes,
  after InUseLogin, the one that answered last at any age, before the first.

Run: TestTrayInUsePluginFollowsLastServed fails without the fallback
("plugin: ... User:k1@x.y"); TestServedMovedWakesTheMenuBar fails with
the hook's firing removed ("the first answer told nobody", "b@ answering
after a@ told nobody"); both pass now, with TestTrayInUse and
TestTrayInUseFollowsWhoAnswered. go test -tags nogui ./... (-timeout 40m)
passes; gofmt -l, go vet (gui with and without nogui), GOOS=linux and
GOOS=windows go vet -tags nogui on gui, provider, autostart pass. No GUI asset changed.
Not tried with the real menu bar and two real accounts.
2026-10-11 01:20:18 +08:00
yetone f5c0626770 tray, usage: the menu bar's account in use is the one that answered last, and the Usage page's cards are told when each did (okingkee on X)
okingkee on X: three Codex accounts, the menu bar set to follow the account
in use. A used its allowance up and the gateway went on to B, but the menu
bar stayed on A; changing the first account moved it, the gateway moving
on did not. trayInUseCard asked InUseLogin, which reckons from the account
the agent is signed in to, and that lags the gateway (and under Smart it
picks any account).

- provider: SubscriptionQuota gains lastServedAt, set by Quotas
  (cardsServed) from served.json the way /v1/magpie/quotas already was,
  on this computer's own cards only and on copies, the caches untouched.
  withServed's matching moved into servedBy.at, shared by both.
  This also makes the Usage page and tray panel's "show the account that
  answered last in full" (ae6b4c93) work: it read q.lastServedAt, which the
  window's API never sent, so it always showed the first.
- tray: a "<provider>|*" card takes the provider's account that answered
  within the last hour (trayServedFresh), else InUseLogin's as before.

Run:
- TestTrayInUseFollowsWhoAnswered (A at 100% answered 40 min ago, B 1 min
  ago → B; both stale → InUseLogin's A; one account → it) fails with the
  served pick disabled and passes; TestCardsLastServed (subscription by
  user, balance with no user, a remote card left alone, inputs unwritten)
  passes; TestTrayInUse and TestQuotasLastServed unchanged and pass.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... pass.
- go test ./... passes except internal/gateway, which hit the 10m default
  timeout under this machine's load; run alone with -timeout 20m it passes
  (726s). No JS changed, so no GUI test run.
2026-10-10 22:45:01 +08:00
yetone bd45fa452a gui: Linux tray quotas reach the bar's tooltip (atie on Discord: on Omarchy, hovering magpie's tray icon showed no quota with 设置 › 用量 › 菜单栏显示额度 on, after opening the panel and restarting) — Wails v3.0.0-beta.24's Linux SetTooltip is a "TBD" no-op: the StatusNotifierItem's ToolTip stayed the {title: "magpie"} it was made with and no NewToolTip was ever sent, so every bar showed "magpie" (Omarchy's bar shows tooltipTitle before Title, waybar ToolTip before Title too, and waybar reads ToolTip again only on NewToolTip). magpie now sets the ToolTip itself after Wails' SetTooltip: through the prop.Properties Wails exported (reached by reflection, so the (sa(iiay)ss) type it was made with is kept and PropertiesChanged goes out), then sends org.kde.StatusNotifierItem.NewToolTip from the same session-bus connection. The quotas go in the title, the part both Omarchy's bar and waybar show; waybar reads it as Pango markup, so &, < and > become look-alikes (sniTip) rather than losing the whole tooltip. Until the tray is up (or should a Wails update move the field) the loop tries again next time. TestSNITipIsSafeMarkup covers the markup. In the omarchy VM (Omarchy 4, Quickshell bar), built there with -tags "production gtk3", in a sandbox HOME with the VM's DeepSeek and Kimi balance keys: the released magpie's item kept ToolTip "magpie" (Title "¥79.15 | $8.83"); this build's ToolTip is (sa(iiay)ss) "DeepSeek · ¥79.15\n\nKimi · $8.83", dbus-monitor shows PropertiesChanged then NewToolTip from the item's connection, and hovering its icon in Omarchy's bar shows both balances. Waybar itself wasn't run (the VM's Omarchy 4 has none); what it does is from its source (sni/item.cpp). go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but TestProvidersAnswerWhileListsComeIn and TestClaudeSignedOut, timing tests that pass alone. 2026-10-03 20:57:39 +08:00
lizhuo ebcd5281c2 gui: open matching allowance cards from macOS menu-bar quotas (#662)
* gui: navigate menu-bar quota cells to allowance cards

* gui: fix quota navigation in lightweight and folded views

Route quota hits through the existing status-item monitor rather than relying on local monitor ordering. Recreate released panels through panelWin, and expand hidden accounts before focusing them. Keep panel headers non-draggable and cancel pending navigation after five seconds or purposeful scrolling.

Add a native AppKit subprocess regression that fails with the former nil-panel dereference and verifies runtime-queued focus, closing, and recreation. Extend browser checks for folded accounts, expiry, cancellation, and panel drag state.
2026-10-03 19:01:13 +08:00
yetone 37809ac722 usage: WorkBuddy's credits are said beside their share — on the Routing page, the Usage page and the menu bar, used or left as the share is (#659)
Moody-Sin: the Routing page showed a WorkBuddy account as "已用 71%" only, which for a plan counted in credits says little. A quota window now carries its own count when the vendor counts in amounts — amount of limit, in unit (QuotaWindow, QuotaSpan for quota --json and /v1/magpie/quotas, and the routing trace's Weighed, from the window its share is of: Allowance.Count). WorkBuddy's built-in fills it from the resource summary, and @magpie-community/opencode-workbuddy-auth 0.1.8 tells it from auth.usage (amount / limit / unit, passed through host.js); the workbuddy mover's min is 0.1.8. The Routing page's stage and its list of what each account did, the Usage page's meter, the menu bar's tooltip and the TUI say "3,550 / 5,000 credits · 71% used", or "1,450 / 5,000 credits · 29% left" with Left on (积分 in Chinese); a window counted in shares alone reads as before.

quota-credits.test.cjs (WebKit, en/zh, used/left, Routing and Usage pages) fails on the old assets and passes; TestQuotaWindowCount, TestAllowanceCount, TestTraceTellsTheCount, TestPluginUsage (the count through the host) and TestWorkBuddyAccounts cover the Go side. Tried with the real WorkBuddy and WorkBuddy AI accounts in a sandbox magpie: moved onto the local plugin, /api/usage/quotas gives 33.29 / 3900 and 13.47 / 2250 credits and the Usage page reads "33.29 / 3,900 积分 · 已用 0.9%", "3,866.71 / 3,900 积分 · 剩余 99.1%" after a click on the count; not moved, the built-in gives the same for WorkBuddy. The Routing page with two real accounts of one provider wasn't tried (one account each). go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-03 16:45:48 +08:00
Fanbuz 5ebb053ce1 fix: 统一额度相关的中英文界面文案 (#493) 2026-10-02 09:37:00 +08:00
yetone 044f61f50f usage: a custom balance's card says when it was read, shows each of its amounts on a line of its own and a percent as a meter (#420 by emo172: 余额卡片显示读取时间、百分比进度条) — a balance read from a provider's own Balance URL showed one line, "Balance $2.00 · Today $2.50 · Used 90%", and nothing said how old it was. magpie now hands the card the amounts the user's expression names, each with its label, and a "%" one's share; the Usage page shows each on a line of its own, the user's label quiet and the first amount the larger, "Balance" only where no label was given, and a percent as the quota meter, amber from 90%. Every card that was read says so, "Updated 3 minutes ago" (3分钟前更新), and one standing in for a reading that failed just now says "As of … — couldn't be read just now" (截至 …,暂时无法获取最新用量), allowance cards too. The menu bar panel's Balances show the same amounts and meter and an amber "As of" (截至), and the tray's tooltip adds "as of …, couldn't be read just now". One amount alone reads as it did, and the balance line, the CLI and the expression syntax are unchanged. No balance URL, path or site is added: /api/usage/token and unlimited_quota are one kind of relay's and stay the user's to write. TestBalanceParts, TestTrayUsageText and balance-parts.test.cjs fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; balance-parts, click-scroll, old-webkit, quota-families, panel-usage, tray-usages, balance-fix, usage-refresh, currency, claude-usage-asked pass. 2026-10-01 19:44:44 +08:00
yetone a91385c175 gui: the menu bar's usage can go without its logos (Jevin on Discord: 为什么托盘的额度显示要带小图标啊 反而丑了一些) — on the Mac each card in the menu bar was a small logo before its stacked percentages, with no way to drop it. Settings has a Menu bar logos On/Off row under Menu bar refresh (shown on a Mac with a card picked), On by default as before; Off draws each card as its percentages alone, a faint hairline between one card and the next, and the bar is redrawn at once. TestTrayPlain, TestTrayImagePlain and tray-logos.test.cjs (Chromium, WebKit, en/zh) fail without the change; tray-usages.test.cjs clicks Currency where it is, as Playwright otherwise scrolled to it under the footer now the row sits above it. go vet, go build (darwin GUI), go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; click-scroll, old-webkit, tray-usages, tray-inuse, settings-groups, usage-alert, update-hide, currency pass. 2026-10-01 12:26:05 +08:00
yetone 52c8e838d2 providers, sign-in, tray, plugins: four of StringKe's reports on Discord — (1) Removing a provider left its editor open and listed, and a second Remove said there was no such provider: the removal had been made, but moving the agents off its models failed on one agent whose config couldn't be written, and Reseat returned that as the change's error; now such an agent is a move with its error ("still on X, not moved: …", a warning in the panel, a line in the CLI and TUI), the others are moved, and the panel, told a delete failed, re-reads the list and closes the editor when the provider is gone. (2) The sign-in waiting sheet shows the sign-in link itself, selected whole on a click, with a copy button, for a browser other than the one that opens. (3) A subscription with several accounts offers "Account in use" among the menu bar's usages, following the account the gateway goes to first. (4) The Antigravity plugin's sign-in never started: magpie called every plugin's authorize with an inputs object, the way OpenCode's CLI does, and opencode-antigravity-auth then asked its Project ID on the terminal — magpie's stdin — until the minute ran out; inputs now go only to a method with prompts, as OpenCode's TUI passes them (checked against the real package under Bun in a sandbox: the Google sign-in URL comes back at once). TestReseatUnmovable, TestTrayInUse, TestInUseOf, TestAuthorizeNoPrompts, provider-remove.test.cjs, signin-link.test.cjs and tray-inuse.test.cjs fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; click-scroll, old-webkit, tray-usages, plugin-signin, signin-callback, factory-sub pass. 2026-09-30 20:45:23 +08:00
yetone ef4edf8c58 tray: the menu bar shows several subscriptions' usage side by side (KevinXC on Discord) — Settings → Usage in the menu bar picked one card; its menu now ticks any number (kept open while ticking, saved once when it closes, Off unticks all, a ticked card that has gone stays listed to untick) and the pill says "3 subscriptions". settings.TrayUsages keeps them in order; a file with only the older trayUsage shows that one, and trayUsage is still written as the first for an older magpie. On the Mac the bird and a cell per card are drawn as one image by AppKit on the status item's button: the card's logo (a black glyph tinted in the menu bar's text colour, a coloured one as it is, the name's letter in a ring when there is none) and its two windows stacked, "42%" over "18%", in the bar's colour light or dark and sharp at any scale; the bird's flap goes through it. Arc flags run into numbers (Codex's logo) are spaced out for AppKit's SVG reader. A row longer than 10 characters (a plan's balance read from its page) is cut with an ellipsis in the bar and whole in the tooltip. Windows and Linux show the cards as text, " | " between them. TestTrayUsageCells, TestSVGArcFlags, TestTrayImage (darwin, renders 0-3 cards light and dark at 2x), TestTrayUsagesMigrate and tray-usages.test.cjs (Chromium, WebKit, en/zh) are new. go vet, go build (darwin GUI), go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./..., go test ./internal/gui pass; tray-usages, settings-groups, panel-*, click-scroll, old-webkit pass. Not seen in a live menu bar. 2026-09-30 19:45:44 +08:00
bcb9db9356 fix(gui): 用量文字与提示显示最多一位小数 (#287)
* feat(gui): 订阅用量百分比保留两位小数

Co-authored-by: Codex <codex@openai.com>

* feat(gui): 支持配置订阅用量小数位

Co-authored-by: Codex <codex@openai.com>

* fix(gui): 默认用量百分比保持整数显示

Co-authored-by: Codex <codex@openai.com>

* fix(gui): 整数用量保留原有圆环尺寸

Co-authored-by: Codex <codex@openai.com>

* fix(gui): 按原布局显示用量小数

菜单栏与圆环维持整数;仅在用量文字和提示中为非整数比例显示一位小数。移除小数位配置及相关布局调整。

Co-authored-by: Codex <codex@openai.com>

---------

Co-authored-by: louis.ning <louis.ning@nio.com>
Co-authored-by: Codex <codex@openai.com>
2026-09-30 16:37:23 +08:00
yetone e31a6a15b0 usage: the menu bar's usage is refreshed as often as asked — every 1, 3, 5, 10 or 30 minutes, 3 as before — and reads as used or left as the Usage page does; that choice is a setting now rather than the browser's, so the page, the panel and the menu bar agree, and Settings has it too; a browser's choice from before is carried over once (#122) 2026-09-28 09:27:49 +08:00
yetone a7dd920e8a tray: the terminal-only build builds again — the menu bar's usage watcher, which needs the tray, is in a file of its own left out of nogui builds; 9cbcb68 had it beside the card's text, which every build has 2026-09-27 19:33:03 +08:00
yetone 9cbcb681dd tray: a subscription's use can sit beside the icon in the menu bar — Settings → Usage in the menu bar picks one of the Usage page's cards, and its windows' use shows there ("42% · 18%", the shortest window first; a key's balance as it reads), with each window and when it starts again in the tooltip, brought up to date every few minutes from the page's own caches, so the vendors are asked no more often. Windows' tray has no room for text and shows the tooltip only. Asked for on Discord 2026-09-27 19:10:27 +08:00