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

A bet can carry a daily spend cap, and the crew holds at it with a plain note #13996

Merged opened this

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

Merged

A bet can now carry a daily spend cap, and the crew holds its queued runs once the day's spend reaches it. The new test file and the 39-file selection I chose (bets, MCP table, held runs, migrations, docs) pass. tsc and bun scripts/gate.ts --fix are clean.

Notes

shipped production is serving it deploy 4adf612

opened this

A bet can now carry a daily spend cap, and the crew holds its queued runs once the day's spend reaches it. The new test file and the 39-file selection I chose (bets, MCP table, held runs, migrations, docs) pass. tsc and bun scripts/gate.ts --fix are clean. The broad fast.ts run named 2,559 test files, so I didn't run it. The remaining tests run in the forge's check on this push.

What changed

  • Cap field. A bet has a nullable cap_usd column (migration 20261116110000-bet-cap, pinned) that must be above zero. parseCap in src/crew/bet_cap.ts accepts dollars and cents (5, $2.50) up to $100,000. It treats empty, "none" or "off" as clearing the cap, and refuses everything else.
  • Setting it. capBet in src/actions/bets.ts is owner-only, refuses an ended bet, and emits bet.capped. You reach it from:
    • the bet page, as a "Set the cap" form;
    • the MCP bet tool, as the cap verb;
    • the terminal Bets screen, on the $ key.
  • The hold. In src/crew/dispatch.ts, a queued run on a scope of a running, capped bet is held once the bet's spend since 00:00 UTC reaches the cap.
    • Spend is summed from usage rows on the bet's scope issues (betSpentSince, src/core/bets.ts).
    • The run stays queued and its log says queued, not started: the bet "X" is at its daily cap of $N (UTC day); it resumes at 00:00 UTC.
    • Vitals counts it as held by "a bet's daily cap", not as a failure.
    • A run already running is never touched.
  • Resume. Once the UTC day turns, the spend no longer counts and the run starts as usual.
  • Test (test/bet-cap.test.ts):
    • parsing and the UTC day boundary;
    • owner-only setting and the database check refusing a zero cap;
    • the hold at the cap and the release after midnight;
    • the real dispatcher holding a queued run as cap, then starting it once the spend is yesterday's.

Left out

  • The cap does not apply to runs queued on issues that are not scopes of the bet.
  • Spend is dated by the run's last usage report, so a run that straddles midnight counts on the day it ended.
  • The hold only applies while the bet is running, so a stopped bet is not held.
  • Changed src/web/ without before/after pictures: the commit says No look, since the page is unchanged until a cap is set.

Try it Open /<owner>/<repo>/bets/<id> on a running bet and set a cap. Or call MCP bet with verb: "cap", cap: "5". Or press $ on the Bets screen.

🤖 Generated with Claude Code

Closes #13979

7 earlier comments · 1 event
commented

A bet can now carry a daily spend cap, and the crew holds its queued runs once the day's spend reaches it. The new test file and the 39-file selection I chose (bets, MCP table, held runs, migrations, docs) pass. tsc and bun scripts/gate.ts --fix are clean. The broad fast.ts run named 2,559 test files, so I didn't run it. The remaining tests run in the forge's check on this push.

What changed

  • Cap field. A bet has a nullable cap_usd column (migration 20261116110000-bet-cap, pinned) that must be above zero. parseCap in src/crew/bet_cap.ts accepts dollars and cents (5, $2.50) up to $100,000. It treats empty, "none" or "off" as clearing the cap, and refuses everything else.
  • Setting it. capBet in src/actions/bets.ts is owner-only, refuses an ended bet, and emits bet.capped. You reach it from:
    • the bet page, as a "Set the cap" form;
    • the MCP bet tool, as the cap verb;
    • the terminal Bets screen, on the $ key.
  • The hold. In src/crew/dispatch.ts, a queued run on a scope of a running, capped bet is held once the bet's spend since 00:00 UTC reaches the cap.
    • Spend is summed from usage rows on the bet's scope issues (betSpentSince, src/core/bets.ts).
    • The run stays queued and its log says queued, not started: the bet "X" is at its daily cap of $N (UTC day); it resumes at 00:00 UTC.
    • Vitals counts it as held by "a bet's daily cap", not as a failure.
    • A run already running is never touched.
  • Resume. Once the UTC day turns, the spend no longer counts and the run starts as usual.
  • Test (test/bet-cap.test.ts):
    • parsing and the UTC day boundary;
    • owner-only setting and the database check refusing a zero cap;
    • the hold at the cap and the release after midnight;
    • the real dispatcher holding a queued run as cap, then starting it once the spend is yesterday's.

Left out

  • The cap does not apply to runs queued on issues that are not scopes of the bet.
  • Spend is dated by the run's last usage report, so a run that straddles midnight counts on the day it ended.
  • The hold only applies while the bet is running, so a stopped bet is not held.
  • Changed src/web/ without before/after pictures: the commit says No look, since the page is unchanged until a cap is set.

Try it Open /<owner>/<repo>/bets/<id> on a running bet and set a cap. Or call MCP bet with verb: "cap", cap: "5". Or press $ on the Bets screen.

🤖 Generated with Claude Code

commented

<!-- look-pages ecce51b8683e --> Look pages for ecce51b, from the gate:

  • look pages (inferred): this pull changes src/web/pages/bets.ts; the forge pictures /preview-admin/sample/bets (src/web/pages/bets.ts), the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

A bet can carry a daily spend cap in UTC days. The crew holds its queued runs at the cap with a plain note, and they resume the next day. This push fixes the failing gate check.

  • Fix: the gate rejected the two Bun.sleep(20) polls at test/bet-cap.test.ts:136 and :143. Both wait on a live dispatcher tick, so a real timer is the point there. Each line now ends with // real-timer: <why>, and the test logic is unchanged.
  • Verified here: bun scripts/gate.ts exits 0 after the commit, bun x tsc --noEmit is clean, and test/bet-cap.test.ts passes (8 tests).
  • Not run here: the full suite. The forge's check runs it on this push.
  • Left alone: the gate still prints a note about one over-100-column comment line in src/runs/held.ts. It doesn't fail the check, and the nightly rewrap handles it on main.
  • To try it: open /bets on the preview at https://lab--13996--forge-trevato-apps.open-platform.sh, set a daily cap on a bet, and let the crew queue a run once that day's spend reaches it. The run should show as held, and it should start again the next UTC day.
commented

<!-- look-pages d51d752411d3 --> Look pages for d51d752, from the gate:

  • look pages (inferred): this pull changes src/web/pages/bets.ts; the forge pictures /preview-admin/sample/bets (src/web/pages/bets.ts), the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

This pull adds an optional daily spend cap to a bet, counted by UTC day. The crew holds the bet's queued runs once that day's spend reaches the cap, and they start again the next day. A held run stays queued, not failed, and its log says "daily cap of $5.00". Nothing is pushed this round, because the feedback needed no change.

The feedback is the gate's automated note naming the look page it will picture, /preview-admin/sample/bets. That page is the right one, since the pull changes src/web/pages/bets.ts, so I added no Looks: or No look: line. I did not run the tests or the gate again, because nothing changed.

  • What changed: the cap is set from the bet's page and validated at the boundary. Backing a bet leaves its cap alone. The cap check lives in its own small module, and the dispatcher consults it before starting a queued run.
  • Test fix: the gate's real-timer rule failed on the two Bun.sleep(20) polls in test/bet-cap.test.ts. They wait on a live dispatcher tick, so both lines now end with // real-timer: <why>.
  • Left out: the cap is not a hard stop for a run already in flight, only a hold on starting queued ones. Only UTC days are supported, with no per-timezone days.
  • To try it: on the preview at https://lab--13996--forge-trevato-apps.open-platform.sh, open /bets, set a daily cap on a bet, and let the crew queue a run once that day's spend reaches it. The run shows as held until the next UTC day.
Changes requested — before the latest push

The cap itself is sound: validated at the boundary, owner-only, held (not failed) with a plain note, resumed the next UTC day, and the dispatcher test is real. Three things to fix in one round.

  1. (first) Tests cover only the action, the parser and the dispatcher. The three doors this change adds have no test that would fail without them: the web cap verb in betAct plus the form on the bet page, the MCP bet verb cap, and the terminal $ key on the Bets screen. Add one test for each: a non-owner is refused, a bad amount is refused with the plain message, and a good one is stored.
  2. Phone: the cap field is a plain text input, so a 360px phone opens the full keyboard. Give it inputmode="decimal", and a shorter label ('Daily cap in dollars') with the UTC detail as a hint, not in the label.
  3. Words: the page and the terminal print the cap raw ($2.5, $5), while the hold note prints $2.50 and $5.00. Format the cap one way everywhere, with two decimals.

Next after these: say on the bet page when the bet is held right now (today's spend vs the cap), so the owner sees the hold where they set it, not only in a run log.

commented

A bet can carry a daily spend cap in UTC days. The crew holds its queued runs at the cap with a plain note, and they start again the next UTC day. A held run stays queued rather than failing, and a run already in flight is not killed. This push addresses juniper's review. bun x tsc --noEmit, the gate and the design lint are clean. The bet tests, the TUI bets tests and the other bet tests all pass; the full suite is left to the forge's check.

  • Tests for the three new doors: each now has a test that refuses a non-owner, refuses a bad amount with the plain message ("a cap is a positive amount in dollars…"), and stores a good one. They cover the web cap verb, the MCP bet verb cap, and the terminal $ key on the Bets screen, and sit in test/bets.test.ts beside the existing door tests.
  • Phone: the cap field has inputmode="decimal" and autocomplete="off", and the label is "Daily cap in dollars" with "UTC day, empty for none" as the hint. I added an optional inputmode to the field component in src/web/ui.ts to do this.
  • Money format: every cap on the page, in the terminal list and prompt, in the hold note and in the field's value is now written with two decimals ($2.50, $5.00), through one money in src/crew/bet_cap.ts.
  • The "next" item, done: the owner's view of a running bet says $0.00 of $3.00 spent today, or held now: $3.00 of $3.00 spent today, resumes at 00:00 UTC once the cap is reached. A test covers it.

I did not add a separate hold badge or any live update of that line. It is read when the page loads.

To try it, open /bets/<id> on the preview at https://lab--13996--forge-trevato-apps.open-platform.sh, set a cap, and back the bet. The $ key in the terminal's Bets screen does the same.

commented

<!-- look-pages b6cf8d7b8640 --> Look pages for b6cf8d7, from the gate:

  • look pages (inferred): this pull changes src/web/pages/bets.ts, src/web/ui.ts; the forge pictures / (src/web/ui.ts), /docs (src/web/ui.ts), /explore (src/web/ui.ts) and 23 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

No code changed in this round: the feedback is the gate's automatic note about which pages it will picture, and it asks for no fix. The note says the pull touches src/web/pages/bets.ts and src/web/ui.ts, so it will picture /, /docs, /explore and 23 other pages whose routes import ui.ts.

bun scripts/design-lint.ts passes ("no colour, size or component added outside the system"). The src/web/ change itself is unchanged from b6cf8d7.

What this pull does:

  • A bet can carry a daily spend cap, counted over the UTC day.
  • When a bet reaches its cap, the crew holds its queued runs. The bet page says so in plain words.
  • Held runs resume the next UTC day.
  • The tests cover the web, MCP and terminal doors.
  • The cap field has a decimal keyboard and a shorter label, and money is shown in one format.

I did not add a "Looks:" or "No look:" line, since the inferred page list fits the change.

Approved

Clean. The cap is validated at the boundary (positive, cents, bounded, DB CHECK), owner-only through one action shared by the page, MCP and terminal. The hold leaves the run queued with a plain note and a distinct vitals cause, never kills a running run, and resumes on the UTC day turn. Each door has a test, and the dispatcher test is real. The how-to is in docs/features/bets.md, not README. Minor, not blocking: a blank line splits the Daily cap bullet from its list in docs/features/bets.md.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs