Repository navigation
feat(bin): add a lightweight read-only web page showing every Claude seat's quota - #12
Merged
Merged
Conversation
…'s quota fm-seat-board.sh renders each seat's quota-axi report (account, window percent-left/reset, extra-usage spend, attention lines) as one local page on 127.0.0.1, caching reads to stay under quota-axi's rate limit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
can you make a very lightweight web ui that essentially just displays the result of the quota-axi for all seats? pass to a fast worker to just do it in a easy simple way
Context: Claude seats are managed by bin/fm-seat.sh and bin/fm-seat-lib.sh (docs/claude-seats.md); quota-axi reads each seat's Claude quota. The page is for glancing at every seat's remaining quota in one place.
What Changed
bin/fm-seat-board.sh, which serves a read-only local page on127.0.0.1(default port 4405, set with--port) throughpython3 -m http.server. The page shows the quota-axi report for the default login and every named seat: account email, percent left and reset time for each window, extra-usage spend against its cap, any attention line, and which seat is active for new workers. Arendersubcommand prints one page to stdout without starting a server.fm-seat-lib.sh'sfm_seat_quota_json, which doesn't refresh credentials or trigger keychain prompts. Each seat's report is cached forFM_SEAT_BOARD_CACHE_SECONDS(default 60s), so reloading the page doesn't hit the quota endpoint again. Output is HTML-escaped.tests/fm-seat-board.test.sh, which checks rendering, escaping, port parsing and cache behavior, and adds a "Glancing at every seat at once" section todocs/claude-seats.md.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change adds a small, self-contained script that only reads data and serves on 127.0.0.1. It calls the existing fm_seat_quota_json path, which passes --no-credential-refresh. The fix round correctly resolved all five chosen findings: the leading --port dispatch, port validation, behavior tests replacing the grep tests, the cache keyed on the config dir, and reuse of fm_seat_quota_json. It introduced no new defects.
Testing
I ran the seat board for real in isolated lab homes: served it on 127.0.0.1, opened it in Playwright and took a screenshot, drove argument edge cases and a real Ctrl-C through a pty, checked caching and that nothing was modified, and did one render with the real quota-axi against the default login. The page lists every seat (default plus named seats) with email, percent left per window, reset times, extra-usage spend against its cap, attention lines, and which seat is active. Markup in quota-axi text shows as literal text, which fixes round 1's bash 5.2+ escaping failure. Page reloads do not call quota-axi again. Bad or missing --port values exit 2 without hanging. Ctrl-C stops the server cleanly. All scenarios passed. One test note: an early Ctrl-C attempt looked like a failure only because processes started with
&in this harness ignore SIGINT; the real pty test is the valid one.--provider claude --no-credential-refresh --full --json--port <n>works with or withoutserve; missing or non-numeric --port and unknown arguments print usage and exit 2 without hanging--port 4491andserve --port 4492both served the pageEvidence: Raw HTTP response served on 127.0.0.1:4491
Source: Raw HTTP response served on 127.0.0.1:4491
Evidence: Page rendered with the real quota-axi against the default login (email redacted)
Source: Page rendered with the real quota-axi against the default login (email redacted)
Evidence: Ctrl-C through a real pty
Source: Ctrl-C through a real pty
Evidence: Bad-argument exit codes
Source: Bad-argument exit codes
Evidence: Cache and read-only transcript
Source: Cache and read-only transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 6 issues found → auto-fixed ✅
bin/fm-seat-board.sh:237- The header documentsfm-seat-board.sh [serve] [--port <n>], soserveshould be optional. But the top-level dispatchcase "${1:-serve}"only matchesserve,renderand-h. Sofm-seat-board.sh --port 4500hits*) usageand exits 2 without starting a server. Fix: treat a leading--port(or any leading flag) asserveand pass all the arguments through, e.g. add a--port) cmd_serve "$@" ;;arm.bin/fm-seat-board.sh:207-fm-seat-board.sh serve --portwith no value gets stuck in an endless loop. When only one argument is left,shift 2fails and shifts nothing, so thewhile [ $# -gt 0 ]loop sees--portagain forever. The port value is also never checked. Fix: check that$2exists and is numeric (e.g.[ $# -ge 2 ] || usage) before shifting.tests/fm-seat-board.test.sh:184- Two new tests only grep the script's own source, which the test-quality rule forbids.test_serve_prints_127_0_0_1_only_and_never_0_0_0_0greps for '127.0.0.1' and '0.0.0.0'.test_serve_never_invokes_allow_keychain_promptgreps for '--allow-keychain-prompt' and 'fm_seat_quota_read'. Neither checks behavior: a comment containing the string would satisfy them. Replace them with behavior checks, for example have the fake quota-axi record its argv duringrenderand assert that--no-credential-refreshis present and--allow-keychain-promptis absent. Otherwise, remove them.bin/fm-seat-board.sh:96- The cache file is named only after the seat, under a global~/.cache/fm-seat-board. It does not depend on FM_HOME, the seats root, or CLAUDE_CONFIG_DIR. Two homes with different seat roots, or a different CLAUDE_CONFIG_DIR fordefault, share one cache file. So rendering the board in a second home within 60s can show the first home's email and quota under the same seat name. Fix: build the cache key from the resolved config dir ($dir) instead of the name, or put the cache under FM_HOME.bin/fm-seat-board.sh:104-seat_quota_cachedrepeats the read-and-check thatfm_seat_quota_jsonin bin/fm-seat-lib.sh already does (read, reject empty,jq -e .). Callout=$(fm_seat_quota_json "$dir") || out=instead, so there is one place that decides what counts as a usable report.bin/fm-seat-board.sh:112- When a fresh read fails, the last cached report is shown with no sign that it is stale. For example, after quota-axi times out on a seat for an hour, the page still shows hour-old percentages as if they were current, next to a fresh 'generated' timestamp. Consider showing the cache file's age when falling back to it.🔧 Fix applied.
✅ Re-checked - no issues remain.
🔧 **Test** - 2 issues found → auto-fixed ✅
bin/fm-seat-board.sh:66- html_escape does not escape anything on bash 5.2 and later. With bash's patsub_replacement option (on by default), an unquoted&in the replacement of${s//</&lt;}stands for the matched text. So<becomes<lt;,>becomes>gt;and"becomes"quot;. Live proof: a seat whose email is[email protected] <b>x</b>was served as[email protected] <lt;b>gt;x<lt;/b>gt;, and the screenshot shows the<b>rendered as real bold markup. Any markup in quota-axi's email or state.error text is injected into the page unescaped. Fix: quote the replacements, e.g.s=${s//&/'&amp;'},s=${s//</'&lt;'},s=${s//>/'&gt;'},s=${s//\"/'&quot;'}. This form works on both bash 3.2 and 5.3. Add a render test with a fake quota-axi email or error containing<b>&"and assert the output contains&lt;b&gt;&amp;&quot;. The existing tests pass only because no fixture contains a special character.<b>x</b>was served as<lt;b>gt;x<lt;/b>gt;and rendered bold in seat-board.png. Cause: bash 5.2+ patsub_replacement in html_escape--provider claude --no-credential-refresh --full --json, with 0 keychain-prompt occurrences; lab config/claude-seat still 'work' and no new config filesbash tests/fm-seat-board.test.sh(all 8 behavior tests pass)Livebin/fm-seat-board.sh --port 4591against an isolated lab: throwaway FM_HOME, seats root with work/personal/spare seats, active seatwork, a fake quota-axi on PATH that logs its argv, and cache dir under /tmp. Fetched the page with curl and a Playwright full-page screenshotlsof -iTCP:4591 -sTCP:LISTENto confirm the server binds only to 127.0.0.15 page reloads plus 12s wait while counting the fake quota-axi's call log, and checking the argv of every call for --no-credential-refresh and the absence of --allow-keychain-promptChecked lab config/claude-seat and the config dir after serving to confirm nothing was changedRan barebin/fm-seat-board.sh(no args) in a pty: default port 4405, curl 200, sent Ctrl-C (\x03), then confirmed the port was closed, the scratch docroot removed and no processes leftStopped the --port 4591 server's python child to confirm the EXIT trap kills the regen loop and removes the docrootfm-seat-board.sh serve --port,--port,serve --port abc,--port 45x,bogusunder a 5s perl alarm: all exit 2 with usage and none hangbash -ccomparison of unquoted vs quoted${s//</&lt;}on bash 5.3.9 and /bin/bash 3.2 to confirm the escaping root cause and a portable fix🔧 Fix applied.
✅ Re-checked - no issues remain.
--provider claude --no-credential-refresh --full --json--port <n>works with or withoutserve; missing or non-numeric --port and unknown arguments print usage and exit 2 without hanging--port 4491andserve --port 4492both served the pageFM_HOME=/tmp/fmsb-lab/home bin/fm-seat-board.sh --port 4491: server started with noserveword, lab home had 4 seats and a fake quota-axi on PATH that records its arguments; fetched withcurl http://127.0.0.1:4491/Playwright: opened http://127.0.0.1:4491/, took a full-page screenshot, and ran DOM checks (0 injected <b> elements, 0 injected <script> elements, email shown as literal text)lsof -iTCP:4491 -sTCP:LISTENplus curl to the LAN IP: the server listens on 127.0.0.1 onlyRecorded quota-axi arguments: every call was--provider claude --no-credential-refresh --full --json, never--allow-keychain-promptCache check: 5 page reloads plus 1renderwithin 60s; quota-axi call count before and afterRead-only check: the lab home's config/claude-seat and seats root were unchanged after serving and renderingbin/fm-seat-board.sh serve --port,--port,serve --port abc,bogusunder a 5s kill guard: all exit 2, none hangbin/fm-seat-board.sh serve --port 4492: explicit serve with a custom port serves all 4 seatsPython pty driver sending \x03 (a real Ctrl-C) tobin/fm-seat-board.sh --port 4493: port freed, no processes left, scratch dir removedFM_HOME=/tmp/fmsb-real/home bin/fm-seat-board.sh renderwith the real quota-axi against the ambient default login (empty seats root, throwaway cache); email redacted in the evidence; checked the cached report for credential fields✅ **Document** - passed
✅ No issues found.
🔧 **Lint** - 1 issue found → auto-fixed ✅
🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.