P5 exit: usage metering, credit billing, promo codes, 3-step wizard

- LlmEvent::Usage across all three providers (Scripted deterministic
  word-count accounting; Anthropic message_start/delta usage; OpenAI-compat
  stream_options include_usage)
- tc-billing: ceil(tokens/1000) min 1 credit; lots drain oldest-first under
  FOR UPDATE; balance clamps at zero while the usage ledger records the
  full obligation; promo codes redeem exactly once via CAS (migration 0006)
- Runtime charges every completed run (billing failure never fails a run);
  proven: 1 token in + 3 out -> 1 credit deducted
- API: GET /api/team/usage, POST /api/credits/redeem (409 on reuse, audited)
- Credits page: balance, 7-day usage meter with runway estimate, PromoRedeem
- /claws/new is the full §9 wizard: ?step=identity|access|slack deep-linked
  progress, accent swatches + name randomizer, access toggles, optional
  Slack step, explicit review-and-confirm (creation = live agent), animated
  provisioning state -> straight into chat
- E2E: chat decrements the visible balance and fills the usage meter;
  WELCOME500 adds exactly 500 once then refuses; wizard round trip

140 Rust + 63 frontend tests + 23 Playwright journeys.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Omar Sobh
2026-06-10 07:19:34 -05:00
co-authored by Claude Fable 5
parent 91327e3618
commit a8efada690
37 changed files with 1261 additions and 86 deletions
@@ -0,0 +1,34 @@
{
"db_name": "PostgreSQL",
"query": "SELECT COALESCE(SUM(tokens_in), 0)::BIGINT AS \"tokens_in!\",\n COALESCE(SUM(tokens_out), 0)::BIGINT AS \"tokens_out!\",\n COALESCE(SUM(credits), 0)::BIGINT AS \"credits!\"\n FROM usage_events\n WHERE workspace_id = $1 AND created_at > now() - interval '7 days'",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "tokens_in!",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "tokens_out!",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "credits!",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Uuid"
]
},
"nullable": [
null,
null,
null
]
},
"hash": "909cb1586b68326590bd3b399bf3284b9084585e3b6fa6d92393c76c0d2f9534"
}