Commit Graph
11 Commits
Author SHA1 Message Date
yetone 0b4cda048c gui: the tray panel shrinks back to a short tab, gliding there
The tray panel was held at its tallest tab's height (#124): fit()
measured every tab and asked for the largest. Once Routing or Usage had
been opened, Agents sat over empty room under its rows until the panel
was let go (refeccd on Discord, macOS). fit() now lays every tab out
the same way and asks for the height of the tab showing (Agents when
none is set), so the panel shrinks as well as grows. #124's complaint
was the panel jumping bigger on a tab switch, so a tab picked glides
the edge there instead (TAB_GLIDE: 240ms on app.css's --ease-out, as
.nav-hl; a jump under reduced motion). Content fits inside a tab
(rows unrolling, Allowances landing) are unchanged.

Siblings: the Go side already shrinks on every OS. FitPanel takes the
height asked, panelFrame clamps it to panelMin/panelMax/the screen, and
glidePanel animates the Mac's frame with its top under the menu bar and
steps Windows/Linux by the tray icon. All three take their height from
this one fit(), so nothing there changed. The web host has no panel.

panel-fit-tabs.test.cjs gets "the tray panel shrinks back to a short
tab": two agents and Routing's eight requests, Agents -> Routing ->
Agents, with reduced motion and without. Agents' height is asked
again, and the tab's fit carries ms=240 and the ease (none under
reduced motion). Its Routing-skeleton check now picks the Routing tab
first, as that is the tab whose height it is about. panel-usage's
assertion is now the showing tab's height, not the tallest.

Run on mote (mote-run). At this commit, rebased on d32a7a70c: gofmt -l
internal/gui nothing; go test -tags nogui ./internal/gui ok (sandbox
HOME); panel-fit-tabs, panel-usage, panel-fit-order, panel-fold 40/40.
Earlier, at the same change on c7c05dcf2:
- new test on origin/main's app.js: 10 of 10 red, Chromium and WebKit
  x en/zh/zh-TW/ja/de: "reduce: Routing asked no taller a panel than
  two agents: 163 629" (the short tab asked the tallest's 629)
- with the change: panel-fit-tabs + panel-usage 24/24 ok (both
  engines, five languages); again at the rebased head with i18n-keys:
  27/28, the one red is i18n-keys' "a plugin's words are its own",
  filed as #5332, #5426, #5482
- the 46 GUI files that read /api/window/fit (at d32a7a70c, before
  the rebase; the change is the same): 1182/1186. Reds, none in the
  panel: images-codex-one (Settings window; red alone on origin/main
  d32a7a70c too, #4618, commented) and view-open-wheel's "wheels
  unheard, usage, en, 1000px" in WebKit (window only, no panel page,
  where fit() returns at once; #4132)
- gofmt -l internal/gui: nothing; go vet, GOOS=linux go vet -tags
  nogui, GOOS=windows go vet ./internal/gui: ok
- go test -tags nogui ./internal/gui (sandbox HOME, pinned caches): ok
  (before trimming, TestCoreScriptBudget was 346 bytes over; the
  comments were cut, the budget not raised)

Not tried: the real app's panel on the Mac, Windows or Linux (no
desktop session driven); the whole GUI suite (mote's suite.lock queue
was full); go test ./... .

Reported-by: refeccd (Discord)
2026-11-08 03:41:23 +08:00
yetone ce21ea8566 usage, routing: counts are said short (K/M, 万/亿), the exact number on hover (skyhuang1994)
skyhuang1994 on Discord: long token and request counts on Usage and
Routing are hard to read at a glance. They now go through fmtN (K/M/B,
in Chinese 万/亿), with the exact grouped number (ledNum) as the title,
so hovering shows it. A count that fmtN already writes in full gets no
title.

- Usage (plugins/usage/page.js): the Requests table's input, output and
  cache cells (output keeps its reasoning line, cache write its TTLs
  under the exact number), the Requests block, retried, the sources
  tile and the ledger's sum line. sameRead moves here from app.js,
  beside loadSessions, its only reader.
- app.js: the Tokens and Requests blocks (blk takes a title), the
  ledger's call count, the rank's values and "{n} requests".
- Routing (plugins/routing/client.js): the day menu's note, the "more
  days" name, the day rows and the stats.
Core scripts: 22 bytes smaller than their base (1533979 at this head;
TestCoreScriptBudget stays red on #5139 as on main, not worse).

Tests: usage-compact-counts.test.cjs is new (Usage and Routing, every
language, chromium and webkit, 420 and 1100px). panel-usage's rank
value expects "900K" with title "900,000"; ledger-cache-unknown's
counted cells expect fmtN text with ledNum as the title.

Run (mote-run):
- at ded9e4a62 (on c03dee7e3): TestCoreScriptBudget 1533979 (red, #5139),
  usage-compact-counts, ledger-cache-unknown, panel-usage, i18n-keys:
  50/50.
- at c533a569d (on 69eb93e0a): 136 GUI files (usage-*, ledger-*,
  panel-usage, i18n-keys, routing day/stats files) 1868/1917. The reds,
  rest-try-now (#5035, #2564), usage-agents-hide (#2276), usage-fold
  (#3415), usage-ledger (#5048), ledger-swipe (#5223), usage-computers
  (#5224), are red the same or worse on origin/main 0a5dc40ab in a
  4-file run under the same load; c533a569d's 4-file run had a subset.
- at 56fff616a (on d5d48f4f9): 206 GUI files; besides the above,
  tray-cell-click (#5215) red the same on origin/main 009076a2a.
Broken by hand: page.js, client.js and app.js put back to main's ->
usage-compact-counts and ledger-cache-unknown 0 pass / 42 fail;
restored.
Not tried: the real app with real usage data, the Linux WebKitGTK app,
Windows.
2026-11-04 18:44:11 +08:00
yetone ce8b67de37 gui tests: a page's first load gets a minute, not a click's 5s (#4470)
claude-switch-only set page.setDefaultTimeout(5000) and then called
page.goto with no timeout of its own, so Playwright held the first load
of app.js, i18n.js and the plugins to the 5s bar meant for clicks. On a
busy box (a whole-suite run at load 130-160) that load took longer and
goto timed out. The same pattern is in 988 GUI test files (1174 pages):
every one of them now also sets setDefaultNavigationTimeout(60000) on
the same page, right after its default, so goto, reload and waitForURL
wait on the load itself with room, while clicks and waits keep their
short bar. group-from-model-add's own 20s navigation bar is raised to the
same minute. claude-switch-only also gives its first provider row (drawn
from the page's first reads) a minute before clicking it.

nav-timeout.test.cjs (no browser) reads every GUI test file and names
each page given a default under a minute without a navigation timeout of
at least a minute, so a new file can't bring the pattern back.

What was run (WSL magpie-desktop, Playwright 1.62.0, load 70-260 from
other sessions):
- node --check on every file in internal/gui/tests: all parse.
- nav-timeout.test.cjs against origin/main's test files: red (names the
  1174 pages); against this tree: its only reds were my own probe copies
  of the old files, since removed.
- By hand: claude-switch-only with app.js served 7s late (a busy box's
  first load), --test-name-pattern "1100 en": origin/main's file 4 of 4
  red with "page.goto: Timeout 5000ms exceeded"; this file 4 of 4 green.
- claude-switch-only.test.cjs, both engines, en/zh/ja/de, 1100 and 420:
  32 of 32. group-from-model-add, usage-access-key-card and i18n-keys:
  green. agent-plugin-agents: Chromium green; WebKit's de 420 subtest red
  on a 5s waitForFunction at line 115 (a wait after load, not the
  navigation), at load ~230.

Not tried: the whole GUI suite (about 1000 files; the change is one
mechanical line per page), Windows or mote (mote's browsers, #4125).
2026-10-31 02:09:18 +08:00
yetone 2a8a177466 gui: the tray panel fits its tallest tab whole, and Routing's first open holds its height
CyberCaius (Discord, Windows): the tray panel jitters or shows a
scrollbar, and today's call count is slow on the first open.

- fit() measured the sections alone, so the view's padding, the gap
  under the tabs and what sits around a section were left out: 10px
  short on Routing, 31px with 8 agents. It now lays out every section
  at once (no data-ptab for the measure), sums each tab's sections by
  their margin box, skips what is display:none, and adds what lies
  outside the view. It never shows one tab after another: hiding the
  open tab ends its running transitions (panel-fold's unroll,
  tray-cell-click's refresh).
- Routing's placeholder was three short bars, and the panel grew when
  the trace landed. It is now a hidden copy of the stage and six
  request rows, so it is as tall as what comes.
- Today's line (usage?period=today) is asked for when the page is
  built, not after the first trace.

Test: internal/gui/tests/panel-fit-tabs.test.cjs, chromium and webkit
x en, zh, zh-TW, ja, de. 8 and 2 agents: no tab overflows the fitted
panel. Trace held: today's 42 shows before it, the fit is the same
after it, Routing doesn't overflow. Scrolled by wheel in a 220px
panel: fit(40); fit() leaves scrollTop where it was, with no scroll
events.

Run at tree 53ae48f72 (on origin/main 3b5a2f612): go test -tags nogui
-timeout 45m ./internal/usage ./internal/gui ok (TestCoreScriptBudget
included, no budget raised; app.js 1,317,465 of 1,317,486). GUI files
panel*, tray*, i18n-keys, routing-sessions (27 files, chromium and
webkit): 336 pass, 0 fail. gofmt clean. Earlier, at 7571ebc93: full
GUI suite 1095 pass; the 4 reds are two tests red on main too (#3497,
removed by hand gives "changed height 630 !== 561".
2026-10-24 23:49:08 +08:00
yetone f823a53d30 gui tests: panel-usage waits for the allowances to be read before counting the tray panel's tabs
"chromium zh: the tray panel's Usage tab" saw 4 tabs, not 3, on main.
The test counted after a fixed 400ms. The panel keeps its Allowances tab
until the quotas answer has come and holds none, which is right (an
answer not come yet isn't none), and under load that answer came after
400ms. The test now waits for the tab to be hidden first.

Run: with the quotas answer delayed 800ms (QDELAY), the old test fails
and the new one passes. panel-usage.test.cjs undelayed, chromium and
webkit, en and zh.
2026-10-11 02:34:21 +08:00
yetone 2fb538c4d7 panel: the tray panel's usage has All beside Today, 7 days and 30 days, as the window's Usage does (#860, huoranxuanyuan: 托盘里用量只有今天/7天/30天,没有全部)
PANEL_USE_PERIODS gains ["all","All"] (already a t() string, in ja/de/zh), and a saved period is checked against the list so All survives a restart. panel-usage.test.cjs picks All in en and zh, Chromium and WebKit, at the panel's width: the request reads period=all, the segment is on, and the four segments stay on one line inside the bar without scrolling the panel.
2026-10-07 00:29:47 +08:00
Leo 39ec205faa fix: refine usage day selection and CSV filenames (#689)
* fix: refine usage day selection and CSV export

* fix: suppress default outline on usage day bars
2026-10-03 22:33:59 +08:00
Leo 48d524d65a feat: select a day in usage charts (#683) 2026-10-03 21:27:06 +08:00
yetone ff8771ff72 panel: the tray panel's Usage reads again when the panel is opened or focused, and has a Refresh now button (#546: 悬浮窗的用量不会自动刷新) — the panel's Usage was read every 10 s only while the page said it was visible, and a tray panel shown again is not always told it is, so it could show what it read when it was last open. Now a focus or a visibilitychange on the Usage tab reads it at once (not within 2 s of the last read), and the bar has the window's Usage refresh button (an icon, 立即刷新 / Refresh now), spinning while it reads. panel-usage.test.cjs (WebKit, en and zh: the button's label, a click reads once, a focus after 2 s reads once, a second focus at once reads nothing) fails without the change. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-02 17:25:21 +08:00
yetone ffd3949dcb usage: the token total's line names the cache too, so in and out don't look like they should add up to it (John on Discord: 这个总量和输入+输出不相等,是bug么?) — the Usage card's Tokens total counts input, output, cache reads and cache writes (allTokens), but the line under it named only input and output, so 95M over "6.5M in · 785K out" looked wrong; with a 93% cache hit rate nearly all of it is cache reads. The line now ends "· {n} cached" (缓存 {n}) with the cache's reads and writes when there are any. panel-usage.test.cjs checks the cache is named under the total (en and zh); the extra line pushes the provider ranking down to the footer's edge in the test's 560px panel, where WebKit takes a half-hidden row as in view and clicks the footer, so the test scrolls it in with the wheel first, as a reader would. panel-usage, number-units, click-scroll, usage-ledger pass in WebKit. 2026-10-02 16:42:49 +08:00
c0f3fa012a usage: combine gateway and local session requests with model charts and account labels (#239)
* usage: Requests lists the agents' own session-file calls, put to the vendor and account their files prove, charts them by provider, agent or model, shows what was said, and the tray panel gets a Usage tab

The Usage page's Requests tab now covers requests an agent sends with its own sign-in (Claude Desktop's Code tab and Cowork, Claude Code, Codex), which never pass the gateway, and shows more of every request: why it failed, what was said in it, who it was of.

Requests tab: a strip of four totals (tokens, requests, cost, cache hit rate); the trend of one metric — tokens, cost or requests — as columns by the hour, day or week, told apart by provider, agent or model (both remembered), beside a ranking of the same that is its legend and a way in (a click lists only that provider's or agent's requests; a provider picker sits beside the agent's). The ranking is as tall as the chart and scrolls in itself, with no scrollbar: a slim rail in the card's margin shows how much there is and where it is (its thumb dragged, the rail clicked), and the edge with more beyond it fades; under the chart (860px and narrower) it shows whole. A row opens to its details: the vendor's error type and words, request id, endpoint, and what was said in it (input and output, read from the agent's session file when opened, the call that ended nearest the request — nothing stored). A refresh period (off / 5 s / 10 s / 30 s / 1 min) and refresh-now. The Overview says it counts gateway calls only; Requests and the panel say they count both. The tray panel gets a Usage tab (today / 7 / 30 days, provider picker, four totals, a small chart, top five, "Open Usage"), and is as tall as its tallest tab (#124).

Provider and account of a session-file call: never magpie's "claude" or "codex" subscription. Anthropic's when Claude Desktop's session metadata (not Claude-3p) names the account and organization, with that account's email; OpenAI's when Codex's rollout names a provider that is OpenAI's in config.toml — the built-in "openai", or a named one at OpenAI's address or signed in with the ChatGPT account and no base_url (requires_openai_auth) — with the creator account's email when the file records it. Anything else is "Local session", its recorded provider id and session account kept (CSV: session_provider, session_account). The config read is today's: a file names the provider id only.

Gateway: a failed call keeps the vendor's error text and type, request id and endpoint; a Claude subscription's failure uses the status Claude Code reports (api_error_status). A request turned away before any vendor was asked is logged, marked rejected, listed in Requests and left out of every total. The client's own session header is kept as native_session beside X-Magpie-Session, and a session-file call is matched to a gateway record by request id, then by that session, equal tokens and an end within 2 s, only when unique both ways.

Reading: session-file calls live in the session index main keeps on disk, parsed incrementally and outside its lock (Claude Code, Cowork in both Claude folders, Codex); the usage log is read on from where it was; a page builds the ledger once. Days are counted on calendar dates (DST). CSV gains request_id, endpoint, error_message, error_type, source, session_provider, session_account. i18n: one "Endpoint" (终结点), which a second key had turned for Azure's field.

Tested: go vet ./..., go build (also GOOS=linux/windows, -tags nogui) and go test -tags nogui ./... pass. The whole GUI suite in Chromium and WebKit, en and zh (Playwright 1.62.1): all 393 tests pass. On this computer's files (7 days): 3,330 Claude Desktop calls resolve to Anthropic with the account, 1,991 Codex calls on a named ChatGPT-signed-in provider to OpenAI (620 with the account; older rollouts don't record it), 9 Claude Code CLI calls stay Local session.

Co-authored-by: yetone <yetoneful@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* usage: a session-file call of one of magpie's own Codex or Claude accounts is told as that provider, beside the gateway's calls on it — "OpenAI" and "Codex" (or "Anthropic" and "Claude Code") read as two vendors when they were one subscription

Codex: an official route (above) whose creator account and user are one of magpie's Codex sign-ins (the CLI's own or a saved one) is magpie's "codex", with that account's email as the gateway's rows have it. Claude Desktop (not Claude-3p): an account and organization that are one of magpie's Claude sign-ins is magpie's "claude". Only while magpie has that provider signed in; another account, a rollout with no account recorded, or an ambiguous workspace stays OpenAI or Anthropic, and a relay stays Local session.

Tested: TestSessionCallsOfMagpiesAccountsAreItsProviders (the account matched, another account, none recorded, magpie's account through a relay, Desktop in magpie's and another organization, Claude-3p, magpie signed out) and TestLedgerTellsCodexSessionCallsAsMagpiesCodex (a gateway Codex call and a session call of its account one provider of two calls, another account's OpenAI). On this computer (7 days): 3,439 Claude Desktop calls are magpie's Claude, 626 Codex calls its Codex, 1,322 older Codex rollouts with no account stay OpenAI. go test -tags nogui ./... and the usage GUI tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: 修复请求统计缓存膨胀与会话账号误归属 #239

调用明细改为按会话文件分片保存并限制内存缓存,汇总索引仅保留统计数据;网关日志按需读取。

严格匹配订阅账号与用户 ID,排除自定义渠道、非官方端点覆盖、外部 CODEX_HOME 及关闭的供应商。补齐零 token 失败去重、Codex 原始会话 ID、拒绝标记导出和面板显示修复。

通过全量 Go 测试、静态检查、受影响模块的并发检查、52 项浏览器测试及 macOS/Linux/Windows 构建;使用 35 万条合成调用验证索引体积与内存改善。

* fix: 降低请求统计刷新与写入开销并明确本地账号展示 #239

请求分片改为追加帧和字符串去重,分页复用未变化的紧凑快照,采用 LRU 并移出全局锁内的磁盘读取。缓存 Cowork 目录,补齐同前缀改写检测及崩溃临时文件清理。

本地记录仅显示匹配账号或本地会话,明确官方登录标记与请求路由的区别。默认今日与模型维度,Auto Review 复用共享目录定价并单独标注估价参考。

完整 Go 测试、vet、相关 race 和 52 项浏览器回归通过;提供 2000 文件及四个大会话连续追加的可复现性能对照。

* fix: 优化用量徽标与耗时分级并保护分页边界 #239

官方登录、API、订阅和本地会话采用独立颜色与柔和底色,兼容明暗主题。耗时按 10 秒及 30 秒阈值着色,保留估算标识与原始毫秒提示;无有效耗时显示短横线。

限制分页选取范围,避免超大偏移整数溢出及越界空页的无效堆构造。补充阈值、徽标对比度和极端分页参数回归。

* fix: 将账号与来源徽标分为两行展示 #239

* fix: 提高用量表格模型文字对比度 #239

发送模型和已知实际模型使用主题正文次级色,表头与时间同步加深。保留缺失值弱化、转发提示和本地日志来源说明。Chromium 与 WebKit 的中英文、浅深色主题 10 项界面检查通过。

---------

Co-authored-by: yetone <yetoneful@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 17:42:10 +08:00