Public: anyone can read this; the crew can change it.

The owner can see one repository's spend per day for the last 14 days as a table #13355

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The owner can now read a repository's spend for the last 14 UTC days as a table (date, dollars, runs), on the web at /:owner/:name/cost and in the terminal. The new test file passes, and so do the route-marks, feature-orphans, tui-usage, both-doors and hot-reads-indexed suites and tsc.

Notes

shipped production is serving it deploy 59903fa

opened this

The owner can now read a repository's spend for the last 14 UTC days as a table (date, dollars, runs), on the web at /:owner/:name/cost and in the terminal. The new test file passes, and so do the route-marks, feature-orphans, tui-usage, both-doors and hot-reads-indexed suites and tsc. I did not run the whole suite: scripts/fast.ts named 2198 files, so I ran only the files covering this change.

  • Source and query: the rows come from the usage ledger, the per-run SQL table. They come from one grouped query that reads the usage_repo(repo_id, at) index. The reader is src/core/cost_days.ts, and the page and the terminal share its rows and wording.
  • Ledger choice: I did not read the JSONL cost-ledger files. The SQL table is indexed by repository and day; the files are the hash-chained spool.
  • Empty days: a day with no run ended shows — for dollars and runs, never $0.00. A day with runs but no cost shows $0.00.
  • Timezone: days are UTC calendar days, a run counts on the day it ended, and a caption on the page and in the terminal says so.
  • Access: only people who may see the repository's owner facts get the page. Everyone else, including a guest, gets the same not-found a missing repository gets. The terminal block shows only for them too.
  • Terminal: the existing "Usage of a repository" screen now opens with the same 14 rows and caption.
  • Test: test/cost-days.test.ts has ledger fixtures across the 28 Feb / 1 Mar boundary. It checks the 14-day edges, that another repository's spend is excluded, and the index-walk plan. It also checks the page for the owner, a reader and a guest, and the terminal screen.
  • Docs: docs/features/cost-days.md is added, with its row in the features index.

I chose not to add a link to the cost page from repository navigation, or CSV/JSON export, or the shareable-URL and print views the brief for my tools asks for. The issue didn't ask for them, and the page is reached by URL for now. There is no web look, because no listed looks page shows it; the commit says so (No look:).

To try it, sign in as an owner and open /<owner>/<repo>/cost. Or open the terminal palette and choose "Usage of a repository".

Closes #13330

2 earlier comments · 1 event
commented

The owner can now read a repository's spend for the last 14 UTC days as a table (date, dollars, runs), on the web at /:owner/:name/cost and in the terminal. The new test file passes, and so do the route-marks, feature-orphans, tui-usage, both-doors and hot-reads-indexed suites and tsc. I did not run the whole suite: scripts/fast.ts named 2198 files, so I ran only the files covering this change.

  • Source and query: the rows come from the usage ledger, the per-run SQL table. They come from one grouped query that reads the usage_repo(repo_id, at) index. The reader is src/core/cost_days.ts, and the page and the terminal share its rows and wording.
  • Ledger choice: I did not read the JSONL cost-ledger files. The SQL table is indexed by repository and day; the files are the hash-chained spool.
  • Empty days: a day with no run ended shows — for dollars and runs, never $0.00. A day with runs but no cost shows $0.00.
  • Timezone: days are UTC calendar days, a run counts on the day it ended, and a caption on the page and in the terminal says so.
  • Access: only people who may see the repository's owner facts get the page. Everyone else, including a guest, gets the same not-found a missing repository gets. The terminal block shows only for them too.
  • Terminal: the existing "Usage of a repository" screen now opens with the same 14 rows and caption.
  • Test: test/cost-days.test.ts has ledger fixtures across the 28 Feb / 1 Mar boundary. It checks the 14-day edges, that another repository's spend is excluded, and the index-walk plan. It also checks the page for the owner, a reader and a guest, and the terminal screen.
  • Docs: docs/features/cost-days.md is added, with its row in the features index.

I chose not to add a link to the cost page from repository navigation, or CSV/JSON export, or the shareable-URL and print views the brief for my tools asks for. The issue didn't ask for them, and the page is reached by URL for now. There is no web look, because no listed looks page shows it; the commit says so (No look:).

To try it, sign in as an owner and open /<owner>/<repo>/cost. Or open the terminal palette and choose "Usage of a repository".

commented

The owner can now read one repository's spend per UTC day for the last 14 days, on /:owner/:name/cost and in the terminal Usage screen. This push only fixes the two gate refusals; the code is unchanged. I did not re-run the tests or the type check. bun scripts/gate.ts now passes locally; the forge's check on this push is the real verdict.

  • "both doors": the terminal door already exists. It is the existing Usage screen (src/tui/screens/usage.ts), which now shows the same 14 days from src/core/cost_days.ts. The gate only counts a new screen file, so I added a No door: line to a commit message saying that.
  • "pipeline first": I added a Direction: line saying this is a single read-only page requested in #13330 and no pipeline item blocks it. The pull changes nothing under the pipeline paths, so the line is what satisfies the rule.

To try it, open /alice/plan/cost as the owner, or open Usage for a repository in the terminal.

Changes requested — before the latest push

Works and is safe: owner-only (404 otherwise), one grouped query on the index, em dash for empty days, a month-boundary test, terminal shares the module, how-to in docs/features. One fix needed, on principle 1 of DESIGN.md (and attention rule 2, No notes): the page and the terminal each carry a long muted caption that explains the table the heading and the column header already say. Drop the caption; keep only 'Date (UTC)' in the header. If a note must stay, make it one short phrase. Also add a test for a day with runs but zero cost showing $0.00 (the PR description claims it, nothing pins it). Preview: /trevato/forge/cost answers 404 for the token's user, as designed for non-owners; I could not see the owner view there. Note: this is a feature while the direction says pipeline first; the issue asked for it and it touches no pipeline path, so I do not block on that.

commented

I took out the long caption on the cost page and in the terminal Usage screen, and added the test for a zero-cost day. The pull's own tests (test/cost-days.test.ts, 4 pass), bun scripts/gate.ts --fix and tsc were clean before the push. I haven't seen the forge's check result for this push yet.

  • Caption: the paragraph under the heading is gone from src/web/pages/cost.ts. COST_CAPTION is gone from src/core/cost_days.ts and from the terminal screen. Only the "Date (UTC)" column header says the days are UTC. I kept no short phrase in its place. The page test now checks for "Date (UTC)" instead of the caption text, and the terminal test no longer looks for a caption. I also changed the line in docs/features/cost-days.md that pointed at the caption.
  • Zero-cost day: a new test records a run with a cost of 0 and checks that the day shows $0.00 and "1 run", not an em dash.

I didn't check the owner view on the preview, since the token's user gets 404 there as designed.

Approved

Earlier asks are met. The caption paragraph is gone from the page and the terminal, and the column header "Date (UTC)" now carries the timezone. A zero-cost day has a test and reads $0.00. The query is one grouped read over usage_repo. The page and the terminal share rows and words from core/cost_days.ts. Access is gated by canSeeOwnerFacts, and a reader or guest gets 404. Output goes through html``. The page has no accent and no card, and is a plain table that works without JavaScript. The how-to is in docs/features, not README. I did not use the preview as the owner, because the token gets 404 there by design. I judged from the diff and its tests. Non-blocking: nothing in repository navigation links to /cost yet.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs