diff --git a/docs/subsystems/gateway-sessions.md b/docs/subsystems/gateway-sessions.md index abd601aeb..9be8c64c5 100644 --- a/docs/subsystems/gateway-sessions.md +++ b/docs/subsystems/gateway-sessions.md @@ -74,6 +74,28 @@ Requests, the Requests ledger and model lists keep each call's own id. Verification: `TestUsageAliasCountsTwoIdsAsOne`, `TestSessionsCountAliasedModelsAsOne`, `TestAliasStatsLeavesItsInputAlone`. +The Usage page can clear its figures (CrazyMouse_TT on X): a model's row's +"…" has "Clear usage…", and "Clear all usage…" sits under the lists. Each +asks first, then `POST /api/usage/clear` adds a mark to `usageCleared` in +settings.json ([`settings.ClearUsage`](../../internal/settings/settings.go)): +a provider and model as the Models list names them (the alias, the +provider's shown id), or neither for everything, and the time in Unix +milliseconds. usage.jsonl is never rewritten. The usage pages leave out +each call at or before a mark that matches it +([`cleared.go`](../../internal/usage/cleared.go)): the Overview +(`summarizeFrom`), and the Requests page, its heatmap and the CSV through +`Filter.keepsRow`; the request index keys its meta on the marks +(`clearedKey`), so a cached page is read again. Gateway keys' spending +limits, the allowances' window holds and Codex's reads go by `usage.Visit` +and the raw log, so they still count every cleared call: a clear never +lifts a limit, and the confirmation says so. The marks ride the settings +part of a sync, so a clear holds on the computers it syncs with, over +their shared days and the agents' session-file rows too, and a later clear +of the same model or of everything takes an earlier one's place. Usage › +Sessions is not cleared. Verification: `TestClearedUsageLeavesThePages`, +`TestClearUsageKeepsOneMarkAModel`, `TestUsageClearRoute`, +`usage-clear.test.cjs`. + Claude Desktop gateway rows can have a local name even without a CLI transcript (#1675). [`DesktopTitles`](../../internal/sessions/desktop_titles.go) reads `claude-code-sessions/*/*/local_*.json` and diff --git a/docs/subsystems/sync-backup.md b/docs/subsystems/sync-backup.md index 2492fbb37..8128bed64 100644 --- a/docs/subsystems/sync-backup.md +++ b/docs/subsystems/sync-backup.md @@ -47,6 +47,12 @@ session resumes in (`SessionTerminal`) and what the menu bar shows. Launch at login is the system's own setting (`internal/autostart`) and the listen address is `MAGPIE_ADDR`, so neither is in a bundle. +The Usage page's clears (`usageCleared`, see +[gateway sessions](gateway-sessions.md)) are a preference, not a computer's +own, so they ride the settings part: a model cleared on one computer is +cleared on the others, their shared usage days included. The usage files +themselves are never rewritten by a clear. + The providers part works the same way for which account an agent is kept signed in to (`KeepLogin`, `KeepLoginAs`, `SwitchOnly`): one person keeps a personal account at home and a work account at the office, and sync set diff --git a/internal/gui/api.go b/internal/gui/api.go index 5d6ace58f..0dd5de632 100644 --- a/internal/gui/api.go +++ b/internal/gui/api.go @@ -1350,6 +1350,8 @@ func Handler(w Windows, gw *gateway.Server) http.Handler { in.UsageAgentsHidden = cur.UsageAgentsHidden // and the names models' usage is counted under (magpie model alias) in.UsageAliases = cur.UsageAliases + // and the clears of usage made on the Usage page + in.UsageCleared = cur.UsageCleared // and the clients it counts as agents, set there too (#1958) in.ClientAgents = cur.ClientAgents // how agents' lists name models, set on its own for the agents to be told diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 573e06d91..fc040268f 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -1197,6 +1197,8 @@ body.masked :hover > .acct-eye, body.masked .pq-card:hover .acct-eye, body.maske .us-hid .list[hidden] { display: none; } .row.stat.hid > :not(.us-unhide) { opacity: .55; } .usage-note { padding: 10px 4px 2px; font-size: 11px; color: var(--faint); user-select: text; -webkit-user-select: text; } +.usage-clear { margin: 0; padding: 2px 0 6px; } +.usage-clear button { font-size: 11px; } .usage-pane { display: flex; flex-direction: column; flex: none; } .usage-pane[hidden] { display: none; } diff --git a/internal/gui/assets/plugins/usage/client.js b/internal/gui/assets/plugins/usage/client.js index 56a9ad637..31519a69c 100644 --- a/internal/gui/assets/plugins/usage/client.js +++ b/internal/gui/assets/plugins/usage/client.js @@ -50,6 +50,7 @@ magpie.plugin("usage", (ctx) => {

+