ac4af582301a4e8a29245dbba767eba31334ddf9
10
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
beba9e8a1f |
claude warm-up: the account it started is read again, its old reading keeping its time
koohoko5924 (v0.1.3057): after a warm-up the card said "just updated"
over windows read before it. claudeWarmedNow cleared the kept
reading's time (e.at) and kept its windows, so claudeReadAt gave nil
and readNow stamped them now. Nothing read the account again either:
claudeWindows' next read waits on when /usage last ran (e.tried),
which the warm-up left alone.
claudeWarmedNow now clears e.tried, which makes the next read due as
for an account never read, and keeps e.at, so until that read the card
shows the reading's own time. Codex's warmed hook only drops its cache
(its usage is a fresh API read), so it has no such sibling.
Run (mote, at this tree): go test ./internal/provider -run
'TestClaudeWarmedReadAgain|Warm|Claude' ok; gofmt -l clean.
Broken by hand: on the old claudeWarmedNow TestClaudeWarmedReadAgain is
red ("the kept reading's time is <nil>"); keeping e.at but not clearing
e.tried, red ("warmed, not read again", the 10% reading kept).
Not tried: a real warm-up on a real Claude account.
|
||
|
|
77031d5817 |
claude usage: a /usage panel with no window is no window started, and a failure says why
koohoko5924 (Discord #help, v0.1.3057, macOS): a Claude Enterprise
account with a five-hour window only. A manual refresh took ~5s and
gave the card no window and the error "Claude Code's usage showed no
usage figures: ▐▛███▜▌ … magpie-claude-work…": Claude Code's banner,
not a reason.
Claude Code 2.1.316's Usage tab (gi) draws a window only once
Anthropic's answer has it non-null, and a window is null until the
request that starts it. An idle 5h-only account's panel loads with
the session's cost, maybe the plan's credit bar, and no window. The
helper told that panel's words, joined from the top of the screen, and
the card took them as a failure with the banner first.
- claudetui: a panel that loaded (tabs, Session/Total cost, nothing
loading, refreshing, stale or failed, no gateway Spend limit) with no
"Current session"/"Current week" is told as NoUsageWindow ("No usage
window has started"). The provider reads that as no window started:
no error, the unstarted 5h window as for any account.
- claudetui: the two rate-limit errors gi draws ("Claude is temporarily
limiting requests to the usage page (not your usage limit)…",
"Usage endpoint is rate limited until …") are failures to load, like
"Failed to load usage data": retried once, then told as an error with
the panel's own "Error: …" text, never the banner. A panel with no
window and no error is told from its tabs on, the session's cost
lines left out.
- provider: "(not your usage limit)" no longer reads as an account
refused (claudeDenied, at every place claudeUsageDenied judged a
reading: the CLI parse, codex_switch, quota_last, subscription_usage).
Counts ("Last 7d · 403 requests …") are taken out wherever they sit in
a line before that check, as the panel's words come on one line now.
A no-figures error keeps every line (600 runes), not the first clipped
at 120.
Tests are built from 2.1.316's own strings (ko/gi/hi in the bundled
cli.js), drawn on the helper's 200x50 grid row by row. Guessed: the
exact bytes of a real Enterprise panel (not captured; no such account
here) and the credit bar's layout.
Run (mote, at this tree): go test ./internal/claudetui ./internal/provider
-run 'Usage|Claude|Shim|Quota|Codex' ok; go vet for claudetui, provider,
gateway; GOOS=linux -tags nogui and GOOS=windows go vet; gofmt -l clean.
Broken by hand (each red, then restored):
- the NoUsageWindow case off: TestShimReadsUsageWithNoWindow red in all
three panels (told the panel's words as success);
- the provider's claudeNoWindow branch off: TestClaudeUsageNoWindowStarted
red ("showed no usage figures: No usage window has started");
- claudeDenied back to claudeUsageDenied: TestClaudeUsageWhyKept red
("read as an account refused");
- usageFailed back to "Failed to load usage data" and the whole screen as
the reason: TestShimToldWhyUsageFailed red in all three (the banner as
the reason; the rate-limit panels told as no window), TestUsageNoWindow
red.
Not tried: a real Claude Enterprise account; a real rate-limited panel.
|
||
|
|
3a74cd92e8 |
claude: /usage waits for its figures, and a read without them is unknown
Seagull fries (haioushutiao, Discord #help; magpie 0.1.2704, Claude Code
2.1.316, Windows 11, Claude Pro): the Claude card said 暂时无法获取额度,
"Claude Code's /usage told no allowance: ❯ /usage ─── Settin s Status
Config Usage …". Reproduced with a real Claude Code 2.1.316 under
Windows' pseudo console in a sandbox: /usage's panel is drawn first with
"Loading usage data…" while Claude Code asks Anthropic for the figures
(5s timeout, retried only on a 401), and the helper took 3s of a still
screen as the panel drawn whole. On a slow answer it told the panel's
frame as the result, and parseClaudeUsage called any text with no window
"told no allowance". A failed load ("Error: Failed to load usage data",
"r to retry") went the same way.
claudetui:
- screen.go: a small terminal grid (CUP/CUU..CHA/VPA, EL, ED, ECH, CR/LF
with scrolling, OSC/DCS skipped, an escape or UTF-8 character cut
between reads kept), 200x50 on Windows as the pseudo console is made,
80x24 elsewhere. The pseudo console sends only the cells that changed,
skipping a cell that holds the same letter ("Settin\x1b[1Cs"), so the
stream read split words and kept a redrawn digit beside the old one.
While /usage is read, each look of the screen with a window is kept
(panel), and usageText reads that before the stream.
- command(), built on b4073c06a's wait for the panel (ikunbots; its
usageDrawn and "hadn't drawn" error kept, now also judged on the grid,
since the pseudo console's split "Settin s" never matched its tabs):
"Loading usage data" on screen is waited out (to
commandWait, s.doing "was still loading /usage's figures" for the
deadline message); "Failed to load usage data" gets one "r"; a panel
still with no figure and loading or failed on screen is an
error_during_execution result, "/usage couldn't load the plan's usage:
<screen>".
- the fake draws the panel a frame at a time (fakeFrames), as Claude Code
does: with one write, the pseudo console passed on only the last
frame, which no longer shows the windows. TestShimReadsUsage now passes
on Windows (#4820, the fake's side; a real panel with figures was not
seen on Windows, see below).
provider:
- parseClaudeUsage: a panel with no figure is "Claude Code's /usage
showed no usage figures: …", not "told no allowance" (kept for
claudeUsageDenied's refusals).
- claudeUsageUnknown: Claude Code's "temporarily unavailable" and the
helper's "couldn't load the plan's usage" keep the account's reported
reading (quota_last), as the first did alone before. Other no-figure
text is still shown as an error (TestClaudeHeaderSurvivesUnclassified-
UsageFailure, TestClaudeUsageReadingAloneDoesNotHideUnclassifiedFailure
hold that).
Fixtures are the reporter's case as the pseudo console passed it on for
the real 2.1.316 (a temporary dump of the helper's screen bytes, sandbox config,
proxy that never answers / refuses): testdata/usage-loading-win-2.1.316.bin
and usage-failed-win-2.1.316.bin.
Run at the pushed head:
- mote: go test ./internal/claudetui ./internal/provider ok; go test
-run 'Claude|Usage|TUI' ./internal/gateway ok; GOOS=darwin/linux/
windows go vet ./internal/claudetui ./internal/provider ok; gofmt -l
clean.
- xiaomi-gpu (win-run): go test ./internal/claudetui: all pass except
TestShimFirstMessageWaitsForTools, red on Windows at main (#4810).
- xiaomi-gpu, real Claude Code 2.1.316 (npm), sandbox CLAUDE_CONFIG_DIR
with a fake token, magpie.exe built from this tree, helper run as the
gateway runs it: a proxy that never answers gives is_error "/usage
couldn't load the plan's usage: … Settings Status … Loading usage data…"
after the 20s wait (was a success with the chrome); a refused proxy
shows "Failed to load usage data", "r" is pressed, and the same error
comes back in 6.6s. "Settings" is whole now.
Broken by hand (before the rebase onto b4073c06a; the merged loop is
re-checked below):
- old tui.go: TestShimWaitsForUsageFigures slow, retried and failed again
all red, each telling the reporter's chrome as success.
- the "r" not written: TestShimWaitsForUsageFigures/retried red.
- old parse message: TestClaudeUsageWithoutFiguresIsUnknown red ("told
no allowance"); old quota_last check: its couldn't-load cases red.
- after the rebase, on the merged loop: the "r" not written,
TestShimWaitsForUsageFigures/retried red; the old "anything still 3s"
in place of usageDrawn on the grid, TestShimWaitsPastTheBanner red.
Not tried: a real account (the box has none of the owner's), so a real
2.1.316 panel with figures was never seen through the pseudo console;
whether Claude Code's frames that show the windows reach the pseudo
console's output before it renders the next one is shown only by the
fake. Not taken: asking Anthropic's /api/oauth/usage, which the owner
ruled out (
|
||
|
|
7b6b7492a9 |
claude: an account on overages is read with its windows and switched off (#4532)
Claude Code's /usage line "You are currently using your overages to power your Claude Code usage…" was in claudeUsageDenied, so the whole reading became an error: the card lost its windows, and NextLogin, which stays on an account it can't read, left Claude Code billing overages while other accounts had room (StringKe's audit, item 3). Now the line is no error. The windows under it are read as usual, and a Text row "Extra usage" with Used 100 is added (claudeOveragesWindow), so usedPast/roomLeft count the account spent and the switch moves off it. The row ends when the last used-up window renews (the time Claude Code says it switches back), else at the next reading. Routing skips Text rows, so the gateway's own account choice is unchanged. The GUI says the row "In use" in the reader's language (quotaText; a plugin's text row keeps its display as it came). The overages case is out of TestClaudeUsageFailureDoesNotHideAccountErrors: it was the bug. Run (mote): - TestClaudeUsageOverages, TestClaudeSwitchOffOverages: red on the old claude_usage_cli.go (an error; switched to ""), red with the row's Used set to 0 by hand, green now. - go test -tags nogui ./internal/provider -run 'Claude|Usage|NextLogin|Next|Switch' ok. - GUI: claude-overages (new, 5 languages, chromium + webkit) red 8 of 10 on the old app.js (en passes there), green now; with quota-text-row, quota-name-translated, i18n-keys, usage-no-reading: 40 pass. - go vet darwin/linux/windows; gofmt clean. Not tried: a real account on overages; the text is Claude Code 2.1.316's string table, and the windows under it are what StringKe describes. |
||
|
|
41b5c0f19a |
accounts: Claude Code stays on the account it moved to till that is spent too (hxy920830 on X)
hxy920830 on X wants Claude Code to use one account to 98%, move to the next and use that one to 98%, not jump back the moment the first resets. No setting gave that. NextLogin (#408) signed the agent back in to the first account as soon as it was under 90% again, under every routing. KeepLogin pins one account, In order goes back too, and switch only went back as well. Where the sign-in is what spends the accounts (Claude Code, whose own requests never pass the gateway, and Codex under switch only), the sign-in now stays on the account it moved to until that one is spent or fails, then moves on to the next ticked account with room. It goes back to the first only where the user said the first comes first: routing In order, or KeepLogin. Codex through the gateway keeps going back, because Smart routing sends its requests to the first account (#209) and the sign-in follows it. This is returnsToFirst in codex_switch.go. The return record is still written, so turning In order on later goes back as before. An old record is ignored otherwise, and its "First again" label (logins.go) is hidden. No user setting is overridden: In order and KeepLogin keep their meaning. GUI: the Routing note for Claude Code (and Codex under switch only) now says it stays on the account till that one is 98% used too. The two switch-only tooltips no longer promise going back. New and changed strings are in zh, zh-TW, ja and de. app.js lost a 3-line comment so the core script budget holds without a raise (core 1,531,108 of 1,533,105). Run on mote at 94cd5edde (base |
||
|
|
957aa79aa3 |
provider, gateway: refreshing a saved Claude account's card reads its allowance through Claude Code, without switching to it (#1630, hhh2210)
A saved (not signed-in) Claude account's Usage card read nothing on Refresh: claudeWindows only ever ran /usage for the account Claude Code itself is signed in to, so the button did nothing for the rest. Now the card's own refresh (RefreshUsage for that account, savedRefresh) runs the real Claude Code's /usage with CLAUDE_CONFIG_DIR set to the account's claudeSavedDir (readSavedClaudeUsage). magpie still never calls Anthropic with the token itself, and Claude Code's own account is not switched. The 30-second per-account floor holds, background reads keep the last reading, and asks for every card (the Usage page opened, magpie quota, magpie accounts) start no Claude Code per saved account: they keep the last reading, or the "not read yet: refresh this account's card" note. Claude Code may refresh the account's token in that directory while it runs, spending the old refresh token. So: - inSavedClaudeDir holds a per-account RWMutex (claudeDirRun) for the run, and switchSavedLogin takes it for writing first, so a switch never hands Claude Code a copy the run has just spent; - syncSavedClaude copies a rotated sign-in from the directory back into logins.json right after the run, under savedTokenMu and loginsMu. Two Claude Codes in one directory are kept from refreshing at once by Claude Code's own lock file (2.1.296's refresh lock in its config dir). A saved account's warm-up, which already ran in that directory, now goes through inSavedClaudeDir too. The plumbing (configDir through UsageClaudeVia, readClaudeUsage and the gateway's claudeUsage, and TestClaudeUsageRunsInSavedAccountDirectory) is from hhh2210's patch 043ee7d7, reviewed line by line. Its gate (any explicit read reads every saved account) was narrowed to the card's own refresh, and the lock and sync back are new. Run: go test -tags nogui ./internal/provider ./internal/gateway . (sandbox HOME, fake claude via UsageClaudeVia, no real token), gofmt -l, GOOS=linux and GOOS=windows go vet on the three packages. Broken by hand, each red: saved never read (all three new tests), any ask reads saved (TestRefreshSavedClaudeUsage), switch not held and no sync back (TestSavedClaudeUsageKeepsRotatedSignIn / SavesRotatedSignIn), run in "" instead of the account's directory. Not tried with a real Claude Code binary against a real saved account. Co-authored-by: hhh2210 <hzy2210@gmail.com> |
||
|
|
c7e4f3fe3f | claude: an account's saved sign-in isn't overwritten with the account Claude Code was just switched to (netfishx on X: Pro, Max and Team accounts, "Keep Claude Code signed in to" on; after routing moved once or twice the Usage page showed one account's plan and allowance on another's card) — magpie switching Claude Code (to the kept account, or back to it) writes the new sign-in and profile, and a Claude Code started on the account before then writes that one's profile into ~/.claude.json: the credential was the Team's, the profile the Pro's. rememberLogins paired them, and upsertLogin, matching the Pro's record by the profile, wrote the Team's sign-in and plan into it ("pro@x.com · Team"). The Pro's runs, in its own config directory seeded from that record, then spent the Team account, and their rate_limit_events and plan showed on the Pro's card. upsertLogin now refuses a Claude sign-in another saved account holds (access or refresh token) while the record the profile names doesn't: the account the profile names holding it already, or Claude Code having renewed it, it is saved as before, so a record crossed by an earlier version doesn't hold the owner back (re-adding the crossed account puts its own sign-in back). TestClaudeUsageUnavailableAfterAccountSwitch switched by the profile alone; it now writes the new account's sign-in as a switch does. Not tried with real Claude accounts (one here). claude_crossed_test (switch to Team, the Pro's profile written after, switch back: each record and each saved account's directory keeps its own sign-in and plan; a crossed record doesn't stop the Team's own being saved, renewed or not) fails without the fix on the first case and passes with -race -count=5; go test ./internal/provider/ ./internal/gateway/, go vet, linux(nogui)/windows builds pass. | ||
|
|
d696d8bc40 |
fix: 账号额度的两条读取路径共用同一份读数 (#836)
/api/login/usage 与 /api/usage/quotas 按账号共用 1 分钟内的读数,同一账号的并发请求合并为一次后台读取,不因某个请求先超时而中断。 避免重复请求供应商、两处显示不一致;手动刷新仍会重新读取。 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
34538b0a4b |
Preserve fresh Claude headers and shorten tray cache labels (#548)
* Preserve fresh Claude headers and shorten tray cache labels * Keep local permission errors separate from Claude account refusals |
||
|
|
e0121f71b9 |
Preserve dated Claude usage when allowance is unavailable (#511)
* fix(provider): preserve dated Claude usage after unavailable reads * fix: clarify cached Claude usage and preserve account return |