# Quota A side panel that shows what every account connected to a 9Router server has left. One card per account, with a coloured bar per quota (green above 80%, orange down to 31%, red at 30% or less), search, an order switch, provider filter chips, an anonymous mode that hides account names, and a notification when a quota runs low or resets. It sits in the right-hand panel stack next to Files and Changes. ![Quota](preview.png) ## What you see A column that fills its block (the shipped right panel is 499px wide; anything from 280px works), on the theme `background`. Top to bottom: - **Header**, `px 14`, `pt 10`, `pb 8`, 1px `border` below, three or four rows: - Title row, 26px high: a 14px gauge icon (`dim`), "Quota" (13px, semibold), a spacer, then four 24px icon buttons with 14px icons and 6px radius: bell (alerts), eye (anonymous mode), refresh, settings. A button is `dim`, `foreground` with a `hover` background on hover; the bell is `accent` when alerts are OFF (bell-off icon), the eye is `accent` when anonymous mode is ON (eye-off icon), refresh is `accent` while loading. - Search row (6px above): an input 26px high, 56% wide, `px 9`, 7px radius, 1px border (`input`, `accent` while focused), `background` fill, 11.5px text, placeholder "Search accounts". At the right edge a pill showing `↕ ` plus the current order: "Lowest first", "Resets soon" or "Name". - Summary row, 20px high: "N accounts" (10.5px, `dim`), and when any are low "· N running low" (10.5px, semibold, `blocked`); at the right "Expand all" / "Collapse all" (10.5px, `dim`, 20px high, `px 6`, 5px radius, `hover` background). - Chips row (6px above), wrapping, 4px gap: only when there are two or more providers, "All N" then one chip per provider with its account count ("Antigravity 4", "Kiro 4", ...), biggest first; and "Hide disabled · N" when any account is disabled. A chip is a 22px pill, `px 9`, 11px radius, 1px `border`, `surface` fill, 10.5px label in `muted` and a 10px count in `dim`. The active one has an `accent` border, a `selected` fill and a `foreground` label. - **List**, scrolls vertically, `px 14`, `py 14`, 14px between cards. Each account is a card: 10px radius, 1px `input` border, `surface` fill, content clipped to the corners. - Card head, `raised` fill, `px 12`, `py 10`, 8px gaps: a 13px chevron (down when open, right when closed, `dim`; an empty 13px spacer when the account has no quotas), an 8px round status dot, a text block 64% wide, and the card's worst percentage at the right (12.5px, semibold). The text block has the account name (12px, semibold, `foreground`; `dim` when the account is disabled) over the plan line (10px, `dim`, `plan` plus ` · disabled` for a disabled one). Both truncate. - Closed card with quotas: under the head, a 3px bar of the worst percentage, `px 12`, 2px above and 11px below. - Open card: a 1px `border` line, then rows with `px 12`, `py 12`, 14px apart. A row has 5px between its lines: 1. the quota name (11.5px, `foreground`, 65% wide, truncated) and, right-aligned, the percentage (11.5px, semibold, status colour) followed by "left" (10px, `dim`). An unlimited quota shows "∞" and no "left". 2. a 4px bar, rounded, on a `hover` track, the fill in the status colour and as wide as the percentage. 3. the amount used (10px, `dim`, 45% wide, e.g. `63.5 / 100`, `$0 / $2.5`) and, right-aligned, "resets 6d 16h" (10px, `dim`, empty when there is no reset time). - An account whose usage call failed shows a 13px alert icon and the error (10.5px) in red under the head. One with only a message shows that text in `dim`. - Status colours are fixed, not theme colours: above 80% `#22c55e`, 31 to 80% `#f59e0b`, 30% or less `#ef4444`, no percentage `dim`. The head's dot, the head's percentage and the bars all use the same rule on the card's worst quota (the row's own for rows). - **Setup form** (first run, or the settings button): replaces the list. A `dim` 11px sentence "Sign in to your 9Router server. The password is kept in data/9router-quota.json as plain text.", two 32px inputs (server URL, placeholder `https://9r.example.com`; password, masked, placeholder "Dashboard password"), a solid "Connect" button (28px, `solid` fill) and, when a server is already saved, an outlined "Cancel". An error shows in `blocked` under the inputs. - Other states: "Loading…" while the first load runs; "No connected account reports quota. Kiro, Antigravity and Codex usually do." when nothing reports; "No account matches the search or filter." when the search or filter hides everything; a bordered card with an alert icon and the message for a panel-level error. ## How it behaves - **Data.** The saved URL and password sign in with `POST /api/auth/login` (JSON `{ "password": ... }`, the answer sets a cookie). Then `GET /api/providers` lists `connections` (`id`, `name`, `email`, `provider`, `isActive`), and each one is asked `GET /api/usage/` for `{ plan, message, error, quotas: { : { displayName, total, used, remaining, remainingPercentage, unlimited, unit, resetAt } } }`. Three usage calls run at once. A 401 signs in again once. Disabled connections are asked too. - **Percentage left.** `unlimited` is 100. Else `remainingPercentage` when it is a number, else `(remaining or total - used) / total`, clamped to 0..100 and rounded; no total means 100. `unit: "USD"` puts a `$` before both amounts. Integers of 1000 or more go through `toLocaleString("en-US")`, other fractions are shown with one decimal. - **Reset text.** Time left until `resetAt`: under an hour `42m`, under a day `4h 13m` (or `4h`), else `5d 3h` (or `5d`). - **Rows per account.** Sorted by the soonest reset first (no reset last), then by name. When an account has any of the Antigravity buckets (`gemini_session`, `gemini_weekly`, `claude_gpt_session`, `claude_gpt_weekly`), only the buckets are shown, plus rows whose name or key matches `image|video|audio|speech|tts|embed`. The account's worst percentage is its lowest row. - **Which accounts show.** Those with at least one quota, an error, or a message that does not say "not available". A connection that had nothing to show (or failed) is not asked again for 30 minutes. - **Refresh.** On open, then every 5 minutes (only while signed in, so a wrong password is never retried on a timer), and when the refresh button is pressed (which signs in again). While a refresh runs the button is `accent`. If the server has not answered after 45 seconds the panel says "The server did not answer. Check the URL, then press refresh." If the server locks the login out (`retryAfter` seconds) the panel says "Locked out by the server. Try again in Ns." and does not try before then. The panel redraws every 30 seconds so reset times keep moving. - **Order and open state.** The list order is the pill: lowest first (the worst percentage, accounts with only an error last), soonest reset, or name. A card opens by itself when its worst percentage is 30 or less, or when it has no quotas (message or error); otherwise it starts closed. A click on the head toggles it and wins over that rule. "Expand all" / "Collapse all" applies to the cards in view. - **Search and filter.** The search text matches the real account name, the plan and the provider name, case-insensitively, as you type. A provider chip shows only that provider; a saved chip whose provider no longer has an account falls back to "All". "Hide disabled · N" hides disabled accounts and reads "Disabled hidden · N" with an `accent` look while on. The summary counts what is in view. - **Anonymous mode (eye).** Account names (cards, and any error or message that quotes the name or an email) turn into the first character plus seven dots, e.g. `A•••••••`. Plans, providers, quotas and numbers stay. The tooltip says "Anonymous mode on: names hidden" / "Hide account names". - **Alerts (bell).** After each refresh, every quota of an enabled account is compared with the last refresh. A quota that dropped to 30% or less raises one notification "Quota running low" (level `warning`; with several, "N quotas running low"); one that came back above 30% raises "Quota reset" (level `success`). The body lists up to three as ` · : 12% left` / `: back to 100%` and "+N more". The first refresh after the panel opens only records levels, disabled accounts and unlimited quotas never alert, and the names are masked while anonymous mode is on. The bell turns this off. - **Remembered.** Anonymous mode, the provider chip, the order, hide-disabled and alerts survive restarts in `data/9router-quota-ui.json`. Which cards were opened by hand does not. - **Tooltips.** Every icon button and pill has one (Refresh also says "updated just now" or "updated 3m ago"). - Agent statuses (working, blocked, done, idle) have no effect on this mod. ## Built from Files: `mods/quota/main.js`, `mod.json` (`{ "place": "none" }`), and icons `gauge.svg`, `chevron-down.svg`, `chevron-right.svg`, `refresh-cw.svg`, `settings.svg`, `circle-alert.svg`, `eye.svg`, `eye-off.svg`, `bell.svg`, `bell-off.svg` (24px viewBox, `stroke="currentColor"`, stroke-width 2, round caps and joins, Lucide-style). Draw them with `svg("mods/quota/.svg").size(14)`. No `keys.json` is needed. Save `main.js` as UTF-8 without a BOM (it contains `∞ • … ↕ ·`). - `main.js` default-exports a `View` (class `Quota`) and imports `View`, `div`, `svg` from `gpui-kit`; `v_flex`, `h_flex`, `InputState`, `Input` from `gpui-base`; `appHome`, `exec`, `readTextFile`, `writeTextFile`, `theme`, `notify` from `herdr`. - **Network through curl.** The shell's `fetch()` cannot read response headers, so the cookie cannot be kept with it. Every call is `exec("curl", ["-sS", "-m", "20", ...args, "-w", "\n%{http_code}", url])`: the body is everything before the last line, the status is the last line. Login uses `-c -X POST -H "Content-Type: application/json" --data-raw `, every other call `-b `. - **Files** under `appHome()/data/`: `9router-quota.json` (`{ "url", "password" }`, plain text), `9router-quota.cookies` (curl's jar), `9router-quota-ui.json` (`{ anon, filter, sort, hideOff, alerts }`). Both JSON files are read in `init` with `readTextFile` and written with `writeTextFile(path, text, previousText)`, keeping the text last read or written so the stale check passes. - **Timers.** `cx.timer.every(5 min)` refreshes (only when signed in), `cx.timer.every(30 s)` calls `cx.notify()`, `cx.timer.after(45 s)` is the watchdog of one refresh. Work runs in `cx.spawn(async cx => ...)`; after an awaited write only the task's own `cx` is valid. - **State** is set in `init`: `groups`, `error`, `loading`, `updated`, `setup`, `config`, `raw`, `signedIn`, `attempt`, `retryAt`, `skip` (connection id to the time it had nothing), `open` (id to hand-set open state), `anon`, `filter`, `sort`, `hideOff`, `alerts`, `levels` (`"|"` to "was low"), `baseline`, `query`, `prefsRaw`, `focusedField`; `InputState`s for URL, password (`set_masked(true)`) and search, each with `focus` and `blur` handlers (an accent border while focused) and, for the URL and password, `submit` calling save; the search `change` handler copies the value into `query`. - **Layout of the rows.** Columns are shares of the card (`w("65%")`, `w("45%")`, `w("64%")`) with the right-hand cell `flex_1().min_w(0)` and `text_right()` or `justify_end()`. Truncated text needs `overflow_hidden().truncate()` and a definite width. - **Elements used.** Root `v_flex().id("quota").size_full().min_h(0)` with the header and then the body (`v_flex().flex_1().min_h(0).overflow_y_scrollbar()`); `.hover(s => s.bg(...))`, `.tooltip(text)` (needs `.id()`), `.cursor_pointer()`, `.on_click`, `.when(cond, el => ...)`, `.children([...])`, `flex_wrap()`, `rounded_full()`. - **Colours.** `theme()` for `background`, `surface`, `raised`, `hover`, `selected`, `border`, `input`, `foreground`, `muted`, `dim`, `accent`, `blocked`, `solid`, `solid_foreground`; the three status colours are literals. - **Programs and commands.** Only `curl`, through `exec`. No herdr commands. `notify({ title, body, level })` posts the alerts. - **Putting it in a window.** The mod has `place: none`, so it needs a block. In a layout, add `{ "id": "quota", "type": "block", "content": { "mod": "quota" } }` as a child of the right panel's `stack` beside Files and Changes, and a "Quota" button (gauge icon) in the tab bar that selects that child like the Files and Changes buttons do. Shipped layouts and the shipped tab bar are read-only: clone them first (`herdr-app do layout.clone`, `herdr-app do mod.clone --name tabs --as my-tabs`) and point the layout at the clone. Without a layout change it still opens as a pane: `herdr-app do pane.split --direction right --mod quota`. ## Watch out - **Do not measure the panel to size columns.** `on_size_change` reported a width that was smaller than the real panel, so fixed-pixel columns stopped short of the right edge and left a strip of empty space. Percent shares plus a `flex_1` cell fill the real width. - **Do not use `theme().blocked` or the ANSI colours for the bands.** Their hue differs per theme and "blocked" is not orange. The bands are literal hex values. - **No blur in gpui-kit.** Anonymous mode replaces the text; it does not blur it. It leaves plan lines, provider chips and quota names visible, and the search box matches the real name, so typing a name still finds it. - **The password is stored and sent in plain text.** It lives in `data/9router-quota.json`, and each login hands it to `curl` as a command-line argument for an instant, where other programs on the machine could read it. Never commit those files. Prefer a 9Router dashboard password you use nowhere else. - **Unofficial API.** The three endpoints and the quota fields are what a 9Router dashboard answers today, not a documented contract. A server that answers differently shows an error card or an empty panel. - **Do not poll without a session.** A timer that signs in on its own would retry a wrong password until the server locks the login out; the 5-minute refresh only runs after a successful sign-in. - **Limits.** Three usage requests in parallel; no cap on the number of accounts; all cards are built on every redraw, so hundreds of accounts would be slow. There is no clear button in the search box, no manual refresh per account, and no history or burn-rate estimate. - **Alerts need the app running.** They fire from the 5-minute refresh while Herdr is open; nothing runs when it is closed. Closing and reopening the panel resets the baseline. - **Windows.** Assumes `curl` is on PATH (it ships with current Windows). `toLocaleString("en-US")` did not add thousands separators in this runtime (`1000 / 1000` shows plain), which is fine. - `tooltip` only works on an element that has an `id`. `Input.new(state)` takes the same sizing methods as a div (`.w("56%")`, `.h(26)`). ## Done when - `herdr-app check mods/quota` passes and `herdr-app status` lists no errors. - With no saved server the panel shows the setup form; a wrong password shows the server's error under the inputs and nothing is retried by a timer. - Against a stub server that answers the three endpoints (login with a cookie, a providers list of three connections, one usage answer each: an Antigravity-style one with the four buckets and an image row, a credit one with `total 1000, used 138.1`, an unlimited one) the list shows one card per account, the Antigravity card shows only its buckets and the image row, the credit card shows `138.1 / 1000` and `86% left` in green, and the unlimited row shows `∞`. - The bar colours switch exactly at 80/81 and 30/31 percent. - Clicking a card head opens or closes it; "Expand all" / "Collapse all" applies to the cards in view; a card at 30% or less starts open and the others closed. - Typing in the search box narrows the cards as you type; the pill cycles Lowest first, Resets soon, Name; a provider chip filters; "Hide disabled · N" hides disabled accounts; the summary line follows. - The eye turns names into `X•••••••` everywhere, including an error that quotes the name, and stays on after a restart. - Changing the stub's answer so a quota falls from 50% to 20% raises one "Quota running low" notification on the next refresh, and a rise from 20% to 100% raises "Quota reset"; with the bell off nothing is posted; the very first refresh posts nothing. - A stub that never answers leaves the refresh button spinning no longer than 45 seconds and then shows the "did not answer" message.