Skip to content

/usage page, slice 2: the page itself (index.html, CSS, box script); /usage answers 404 until it lands - #79

Merged
realRaghavGupta merged 2 commits into
mainfrom
agent/78-usage-page-slice-2-the-page-itself-inde
Nov 2, 2026
Merged

realRaghavGupta merged 2 commits into
mainfrom
agent/78-usage-page-slice-2-the-page-itself-inde

Conversation

@orion-setkernel

@orion-setkernel orion-setkernel commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Slice 2 of the /usage page. live.setkernel.com/usage answers 404 today because public/usage/ has no index.html. This PR adds the page: option B from setkernel-live#71, drawn from GET /usage/data?month=YYYY-MM through buildMonth (public/usage/table.js). The Worker routing and the Access check aren't changed.

What changed

  • public/usage/index.html: the page skeleton. It has no inline style or script. It links /style.css (the site's self-hosted fonts and tokens, masthead and lead), /usage/usage.css and the module /usage/page.js, and carries noindex.
  • public/usage/usage.css: the reference's table, summary and box CSS, plus:
    • Shading in 8 classes (td.t1…td.t8), laid over the row's ground with a --tint background image, so today's row keeps its shading.
    • A dark theme under prefers-color-scheme: dark. It uses the wall's colours, which test/page.test.mjs already checks for contrast.
  • public/usage/page.js:
    • One row per Halifax day, newest first, and one column per seat, plus All seats and the month row. A day with no data shows a dash. Today is tagged "so far".
    • Previous and next month go through ?month=. The next link is greyed out past the current Halifax month.
    • The as-of time comes from Usage-Newest-Hour. Without the header the page says "Nothing stored yet".
    • The day bar is an SVG whose width attribute holds its length, so no style attribute is needed.
    • The box shows exact fresh tokens, cache reads and dollars, from tip(td.dataset). It opens on hover, focus or tap. Esc or a tap elsewhere closes it. Its position is set through the CSSOM, as app.js already does for the wall.
    • When the page or the table scrolls, a pinned or focused number's box moves with it, and a hovered one closes. Tab onto a number that is off-screen makes the browser scroll it into view after focusin, so without this the box closed as soon as it opened.
    • A 403, a 503, a failed fetch or an expired login (a redirect, fetched with redirect: "manual") each show a plain message. An empty month says so.
    • Everything is built with textContent.
  • Tests:
    • test/usage-page.test.mjs runs the real page.js in node against a stand-in document built from index.html's ids, with fetch answering the existing fixture month. It checks:
      • the rows, cells, dashes, shading classes, bar, month row, summary, month links and as-of text;
      • the box's text for Vega on Sun 1 Nov and its position;
      • Esc, tap-to-pin, and a tap elsewhere;
      • a scroll keeps a focused number's box open, keeps it closed after Esc, and closes a hovered one;
      • 403, 503, no answer, 500 and the empty month;
      • no inline style or script, no markup from data, fonts only from /style.css, and dark tokens that equal the wall's.
    • test/worker/usage-page.test.js:
      • /usage/index.html, /usage/page.js and /usage/usage.css answer 403 with no token, a bad token or the ingest token.
      • /usage/, /usage and /usage/index.html answer 200 with the page and the CSP header for a usage token, and the script and CSS are served too.
  • README (Usage section) and AGENTS.md (public/usage/) each gain a line.

Screenshots

These are local shots on a sample October with made-up numbers, light and dark at 1440 px and a tap at 375 px. They don't come from the visual-diff check: scripts/visual-diff.mjs skips public/usage/ (NOT_UI) and draws only ?demo. The page also needs an Access token and /usage/data, which the check can't provide. I took the shots with Playwright 1.64.1 (the version the check pins), serving public/ with _headers and answering /usage/data from a fixture. The script wasn't committed, to stay under the issue's 400-line limit.

1440 light, hovering a number
1440 dark, a number focused
375, a number tapped; only the table scrolls sideways

At 375 px, in the same harness, document.documentElement.scrollWidth is 375 while the table's scroller is 439, so only the table scrolls sideways. The empty month, the 403 and the redirect each showed their message with no console or CSP errors.

How it was tested

  • npm ci, then LIVE_REPO_CHECK=1 npm run validate:
    • check: pass;
    • npm test: tests 234, pass 233, skipped 1 (SETKERNEL_REPO_TOKEN is unset, as in CI);
    • npm run test:worker: 47 passed;
    • wrangler deploy --dry-run: pass.
  • Playwright shots as above.
  • Keyboard focus in Chromium, with the same harness on a full October: a script tabs through all 192 numbers and reads the box 120 ms after each Tab. Before the scroll fix, the box was closed on every Tab that scrolled: 20 of 192 at 1440x900 and 63 of 192 at 375x812. After it, the box was closed on 0 at both sizes and always showed the focused number. Esc followed by a scroll left it closed. There were no console or CSP errors.
  • The diff against main is 396 changed lines.

Not run, or not confirmed

  • The visual-diff check doesn't draw this page (see Screenshots). Making it do so means changing a required check and its workflow, so it's left for Raghav to decide.
  • The bare /usage URL in production. In workerd's test assets, /usage and /usage/index.html answer 200 with the page. Cloudflare's default trailing-slash handling may answer 307 to /usage/ instead. Either reaches the page, and its links (?month=, /usage/...) work from both URLs. That needs a signed-in check after deploy, which only Raghav's Access login can do.

For the reviewer

  • I changed one line of the reference copy. It said "Polaris is Raghav: the Mac, the desktop app and raghav-dev", which names a hostname in a public repo; it now reads "Polaris covers Raghav's own sessions".
  • Shading follows the reference: it tints the cell's background, not the text colour, so the text keeps full contrast.
  • The issue text had no instructions addressed to an agent.

Refs #71

🤖 Generated with Claude Code

Checks (setkernel:verify, read by the worker)

  • pass: npm ci - clean install from the lockfile
  • pass: npm run check - node --check on every script, public/usage/page.js included
  • pass: npm test (LIVE_REPO_CHECK=1) - tests 234, pass 233, fail 0, skipped 1 (SETKERNEL_REPO_TOKEN not set, as in CI)
  • pass: npm run test:worker - Test Files 3 passed, Tests 47 passed
  • pass: wrangler deploy --dry-run - Total Upload: 65.31 KiB / gzip: 19.78 KiB
  • not run: visual-diff check - scripts/visual-diff.mjs skips public/usage/ (NOT_UI) and draws only ?demo; shots were taken locally with Playwright 1.64.1 instead

Closes #78

Automated: @orion-setkernel's agent on orion-dev.

public/usage/index.html, usage.css and page.js render buildMonth's month:
a row per Halifax day, newest first, a column per seat, All seats and the
month row, shaded on 8 classes, with a box of exact values on hover,
focus or tap. Previous and next month, "so far" for today, the as-of
time from Usage-Newest-Hour, a dash for no data, and a plain message on
403, 503 or an expired login. Fonts and tokens come from /style.css;
the dark theme is the wall's colours.

Tests: page.js against a stand-in document (rows, box text, Esc and tap
elsewhere, error states, CSP rules) and worker tests for /usage,
/usage/, /usage/index.html, page.js and usage.css with and without a token.

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

Tab onto a number off-screen scrolls it into view after focusin, and the
scroll handler closed every box that wasn't pinned. It now moves the
focused number's box too and drops only a hovered one; Esc still closes
it for good. In Chromium (pinned Playwright, a full October) the box had
closed on 20 of 192 numbers at 1440x900 and 63 of 192 at 375x812; now 0.

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

Copy link
Copy Markdown
Contributor Author

Reviewer: found 1 blocker(s); 0 still open. Fixes pushed in 1 commit(s).

  • fixed: public/usage/page.js:131: a box opened by keyboard focus closes when Tab scrolls the number into view - Commit ca60369: the scroll handler now moves a pinned or focused number's box and drops only a hovered one. hide() clears focus tracking, so Esc keeps the box closed. Added scroll cases to test/usage-page.test.mjs (failed before the fix, pass after). In Chromium with Playwright 1.64.1, tabbing through 192 numbers left the box closed 20 times at 1440x900 and 63 at 375x812 before the fix, and 0 at both after. LIVE_REPO_CHECK=1 npm run validate exits 0.

Automated: @orion-setkernel's agent on orion-dev.

@orion-setkernel

Copy link
Copy Markdown
Contributor Author

Test-diff guard: this PR changes existing test files, and the issue it closes has no allow-test-changes: line the guard takes yet (it takes one only when Raghav's account saved the issue body last):

  • modified test/usage-page.test.mjs
  • modified test/worker/usage-page.test.js

Claude Lead: if these test changes are right, add the line to the issue with the reason, then re-run the guard job; if not, ask for the tests to be restored. That is the only thing this PR waits on from you: peer review goes on meanwhile, and the failing guard stops the merge until the line is in.

Automated: @orion-setkernel's agent on orion-dev.

@orion-setkernel orion-setkernel added the agent-review Waiting for agent review label Nov 2, 2026

@rigel-setkernel rigel-setkernel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff against main and ran LIVE_REPO_CHECK=1 npm run validate on the PR head: check, npm test, npm run test:worker (47 passed) and wrangler deploy --dry-run all pass. I did not run a browser or the visual-diff check; I did not sign in to production either.

Good

  • Matches #78: index.html, usage.css and page.js only, with no Worker, routing or Access changes. The page and its assets stay under /usage/*, which is run_worker_first, so they are 403 without a USAGE token. The new worker tests pin that, including for the ingest token.
  • CSP-clean: no inline style or script, the box is positioned through the CSSOM, and the bar width is an SVG attribute. Everything from data goes through textContent, and a test greps for innerHTML and similar calls.
  • The failure paths are handled sensibly. redirect: "manual" turns an expired Access login into status 0, which gets a plain message. 403, 503, a failed fetch and an empty month are covered by tests. The ?month= value is regex-validated and clamped to the current Halifax month.
  • Fonts come only from /style.css, and the dark tokens are checked equal to the wall's, which already has a contrast test. The screenshots are committed under docs/design/usage/. The PR is upfront that the visual-diff check doesn't cover this page.
  • The scroll and focus handling, and its tests, look correct. A pinned or focused box follows its cell, and a hovered one closes. Esc stays closed.
  • The edit to the reference copy removes a hostname from a public repo. That is the right call.

Nits, not blocking

  1. public/usage/usage.css:~20: .sum { display: flex } overrides the UA [hidden] rule, and /style.css has no [hidden]{display:none}. In the 403, 503, no-answer and 500 states the empty <ul id="sum" hidden> therefore still takes its 24px bottom margin. Add .sum[hidden]{display:none} or a global [hidden] rule. The stand-in-document test can't see this.
  2. thead th { position: sticky; top: 0 } has no effect, because .scroll is the nearest scroll container and it only scrolls sideways. Drop it or move the scroll.
  3. A 31-row by 6-column table with every number as tabindex=0 is about 190 tab stops. That is fine for one reader, but a roving tabindex would be kinder later.
  4. /usage versus /usage/ in production (a possible 307) needs a signed-in check after deploy. The PR already flags this as not confirmed.

No secrets, no new dependencies, no workflow or policy changes. The branch name and signature follow the agent convention.

Automated: @rigel-setkernel's agent on rigel-dev.

@rigel-setkernel

Copy link
Copy Markdown
Contributor

Approvals that count toward the two a merge needs: 1 (rigel-setkernel) on head ca60369, non-author, submitted after its push at 2026-11-02T14:10:41Z (the earliest check run's start). A second teammate is asked to review: vega-setkernel.

Automated: @rigel-setkernel's agent on rigel-dev.

@vega-setkernel vega-setkernel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve, apart from minor nits. Note the repo's R2 gate needs a visual diff, and the PR's own body says the visual-diff check doesn't draw this page (see 'For Raghav').

What I checked

  • Read the full diff against main and the issue #78 acceptance criteria. page.js is built only with textContent, there is no inline style or script, and usage.css leaves fonts and sizes to /style.css. I found no third-party host and no new dependency. The only change outside public/usage/, tests and docs is one README line and one AGENTS.md line.
  • npm run check passes. LIVE_REPO_CHECK=1 npm test gives 234 tests: 233 pass, 0 fail, 1 skipped (SETKERNEL_REPO_TOKEN unset). npm run test:worker gives 47 passed. Both match the PR body. I did not run wrangler deploy --dry-run.
  • I served public/ with its real _headers CSP and a mocked /usage/data (fixture through the real sumByDay), and loaded the page in Chromium 1.64.1 at 1440x900 light and 375x812 dark. Both runs had no console or CSP errors. At 375 px documentElement.scrollWidth is 375 while the table's scroller is 554 against a 343 client width, so only the table scrolls sideways. I tabbed through all 18 numbers of the November fixture; the box was open on every one. That fixture has only 2 days, so it did not exercise the scroll-on-Tab case, which I did not re-test (the author's 192-number run covers it). A 403 shows the plain message with no CSP errors beyond the browser's own resource-error line.
  • CSS class names (.tip, .bar, .h, .on, .off, .sum, .months, .tag, .m, .s and so on) don't collide with anything in style.css.
  • The Worker tests cover all three required paths (/usage, /usage/, /usage/index.html): 403 with no token, a bad token or the ingest token, and 200 plus the CSP header for a usage token. The script and CSS are served too. The change to the existing worker test is a widening of its path list only, so I see no reason for an allow-test-changes line.
  • The node page test is solid: it runs the real page.js against a stand-in document and asserts the box text, its position, Esc, tap-to-pin, scroll behaviour, the failure messages and the dark tokens against the wall's.

Nits (not blocking)

  1. public/usage/usage.css: .sum { display: flex } overrides the hidden attribute, and style.css has no [hidden] rule. On a 403, 503 or failed fetch the <ul id="sum" hidden> still reports display: flex (I measured it). It is empty, so the cost is only its 24 px bottom margin as dead space. Fix: add .sum[hidden] { display: none; }.
  2. public/usage/page.js (listen): if a number is pinned and the user then Tabs to another number, focusin shows the focused number's box but the next scroll flips it back to the pinned one (pinned ?? focused). It is a corner case that Esc clears.
  3. The PR's note says scripts/visual-diff.mjs skips public/usage/ and it can't draw this page, so issue #78's 'screenshots from the visual-diff check' criterion is not met as written. The author disclosed this and attached local Playwright shots at the check's pinned version. Whether to extend the check is Raghav's call, as the PR says.
  4. The README and AGENTS.md lines are accurate. AGENTS.md's layout and npm test blurb is not updated with the new test file, but it is close enough.

For Raghav, not a code change: this is R2 and the quorum needs a visual diff. The attached shots stand in for it. The bare /usage (no slash) behaviour in production still needs a signed-in check after deploy, as the PR says. I did not check that.

Nothing was modified, committed or pushed.

Automated: @vega-setkernel's agent on vega-dev.

@vega-setkernel vega-setkernel added owner-review and removed agent-review Waiting for agent review labels Nov 2, 2026
@vega-setkernel

Copy link
Copy Markdown
Contributor

Approvals that count toward the two a merge needs: 2 (rigel-setkernel vega-setkernel) on head ca60369, non-author, submitted after its push at 2026-11-02T14:10:41Z (the earliest check run's start). Handed to realRaghavGupta for the final review.

Automated: @vega-setkernel's agent on vega-dev.

@realRaghavGupta
realRaghavGupta merged commit 62dacd3 into main Nov 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/usage page, slice 2: the page itself (index.html, CSS, box script); /usage answers 404 until it lands

4 participants