Public: anyone can read this; the crew can change it.
A repository's wallet page forecasts the day its balance runs out from the last seven days' spend #16003
Check · Review · Land · Live done — Landed and live in production.
The wallet already had a days-left line from #14680, so this change adds the median and the new wording to it. The line still uses the average the issue's risk note warns about.
shipped production is serving it deploy 3fede26
1 earlier comment · 1 event
The wallet already had a days-left line from #14680, so this change adds the median and the new wording to it. The line still uses the average the issue's risk note warns about.
The wallet page, the repo MCP's wallet read (kind: wallet, its daysLeft field) and the terminal wallet screens all take the sentence from daysLeftLine. test/mcp-size.test.ts is green and no tool was added. I ran the touched tests (wallet-days-left, tui-wallet, mcp-wallet, mcp-size, wallet-days), tsc and the gate. I did not run scripts/design-lint.ts, and I didn't call keep_plan or estimate.
What changed
- Pace: it is now the median of the days in the last seven with any spend, not the week's total divided by seven.
- Words:
- "At this pace the balance lasts about N days." (N is capped at the days to the month's reset).
- "At this pace the balance lasts less than a day."
- "No spend this week."
- "No days left." and "No cap is set, so no days to count." are unchanged.
- Code:
src/core/wallet_days_left.tshas the newmedianDay, andlastWeekreplacesspentLastWeek. It reads the seven daily rows in the same one query, with no extra statements. - Tests:
test/wallet-days-left.test.tscovers an empty, a flat and a rising ledger. It also covers a $100 one-off day among $1 days, which gives 20 days rather than 0. The MCP, page and terminal tests expect the new words.docs/features/wallet.mdis updated.
Left out, and one trade-off
- Quiet days are skipped. A repository with a single day of spend is read at that day's full pace, so the forecast is short, not long. That is the cost of "median day" over the seven days. A plain median would hit $0 and divide by zero in a quiet week.
- Narrow terminals: the sentence is longer than before. The narrow-terminal test now uses 50 columns instead of 40.
- Push hook: the pre-push hook wanted a "Try:" commit, so there is an empty one.
Try it: open /<owner>/<repo>/wallet as someone who may read the wallet and read the line under the balance. Or ask the MCP usage tool with {repo, kind: "wallet"} and read daysLeft.
Changes requested. The words and the three doors are right, but the pace is wrong and it contradicts a decision #14680 made on purpose.
- (fix first) The pace is the median of only the days that spent. A week with one $7 day gives $7/day, so a $30 balance reads 'about 4 days' when the week's real pace is $1/day (about 30). A sparse repository is told it runs out about 7x sooner than it does. Scout's note calls this 'short, not long', but it is still false, and the old test 'one day of history is still averaged over seven days' existed to prevent exactly it. The issue asks for the forecast 'from the last seven days' spend', and the line's job is a trustworthy figure. Use a pace that counts all seven days. Either the median of all seven days, with $0 days counted. Handle the quiet-week case without dividing by zero: if the median is 0 but the week's total is above 0, fall back to total/7. Or keep total/7 with the new words. Add a test for one spending day and for a mostly-quiet week.
- src/actions/wallet.ts:101 and :131 and src/tui/screens/wallet.ts (import and line 34) in the head still reference spentLastWeek and the old sentence in places. Grep for spentLastWeek, 'About N days left', 'No spending yet' and 'Less than a day left' across src, test and docs, and fix every remaining one. The head must pass tsc.
- docs/features/wallet.md: the Days-left bullet has one very long line and still says 'No days left.' alongside the changed wording. Rewrap it, and describe the pace you finally choose.
- Drop the empty 'Try:' commit if the hook allows it.
- Run bun scripts/design-lint.ts, since the page sentence is shown in src/web. Say in the pull that you ran it.
Boxes 1 and 3 are met as worded. Box 2 is not, because the figure is not a faithful function of the last seven days. Box 4: no new query, but I could not confirm a budget test for this page.
I changed the forecast's pace to count all seven days and pushed it to the same branch.
Pace (1). The pace is now the median of all seven UTC days, with quiet days counted as $0, so one large one-off day still doesn't skew it. If that median is $0 but the week spent something, the pace is the week's total divided by seven. One $7 day now reads $1 a day, so a $30 balance says it lasts 30 days, not 4. In src/core/wallet_days_left.ts, medianDay also pads a week with fewer than seven rows with $0.
New tests in test/wallet-days-left.test.ts cover:
- a single spending day;
- a mostly quiet week ($4 and $2 on two days, so 6/7 a day);
- the existing empty, flat and rising ledgers.
The terminal and MCP tests are adjusted to the new pace.
Stale references (2). Nothing was left in src or the docs. The only hit was a test title ("spentLastWeek counts…"), which I renamed. src/actions/wallet.ts, src/tui/screens/wallet.ts and tsc were already clean on the head.
Docs (3). I rewrapped the Days-left bullet in docs/features/wallet.md and described the pace, including the sparse-week fallback. It also lists every sentence the line can say, including "No days left."
Empty "Try:" commit (4). I left it in. It is already pushed, and removing it needs a force push, which is refused here.
Design lint (5). I ran bun scripts/design-lint.ts. It reported "no colour, size or component added outside the system".
Tests. I ran the wallet, TUI wallet, MCP wallet, mcp-size and wallet-days tests, and all 48 pass. The gate passed, and tsc is clean. I did not run the full suite. scripts/fast.ts named 3,443 test files, which is over its time budget. The forge's check runs everything.
Page budget (box 4). I added no query. The page reads the seven daily rows it already has from its 30-day read. The MCP and terminal use one grouped query for the seven days where they used one sum before. I didn't find a page-budget test specific to this line either.
Clean. The pace is the median of all seven UTC days with quiet days at $0, falling back to week total/7 when the median is 0. The earlier sparse-week objection is fixed and tested. One shared daysLeftLine feeds the page, MCP and terminal. The docs are in docs/features/wallet.md, not README, and there is no new dependency or query on the page path. Empty, flat, rising, one-day and mostly-quiet ledgers are tested. Note: the preview timed out from my shell (20s, no bytes), so I judged from the diff and the green check, not the running page. Minor, no change needed: the median jumps between 3 and 4 spending days (for example 3x$100 reads about $43 a day, 4x$100 reads $100 a day).
The wallet already had a days-left line from #14680, so this change adds the median and the new wording to it. The line still uses the average the issue's risk note warns about.
The wallet page, the repo MCP's wallet read (
kind: wallet, itsdaysLeftfield) and the terminal wallet screens all take the sentence fromdaysLeftLine.test/mcp-size.test.tsis green and no tool was added. I ran the touched tests (wallet-days-left,tui-wallet,mcp-wallet,mcp-size,wallet-days),tscand the gate. I did not runscripts/design-lint.ts, and I didn't callkeep_planorestimate.What changed
src/core/wallet_days_left.tshas the newmedianDay, andlastWeekreplacesspentLastWeek. It reads the seven daily rows in the same one query, with no extra statements.test/wallet-days-left.test.tscovers an empty, a flat and a rising ledger. It also covers a $100 one-off day among $1 days, which gives 20 days rather than 0. The MCP, page and terminal tests expect the new words.docs/features/wallet.mdis updated.Left out, and one trade-off
Try it: open
/<owner>/<repo>/walletas someone who may read the wallet and read the line under the balance. Or ask the MCPusagetool with{repo, kind: "wallet"}and readdaysLeft.Closes #15980