Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

feat(KR-P2-COST-PANEL): cost ladder admin UI (burn + rung + deferred tickets) against stub#49

Merged
rafe-walker merged 1 commit into
mainfrom
feat/kora-KR-P2-COST-PANEL
May 21, 2026
Merged

feat(KR-P2-COST-PANEL): cost ladder admin UI (burn + rung + deferred tickets) against stub#49
rafe-walker merged 1 commit into
mainfrom
feat/kora-KR-P2-COST-PANEL

Conversation

@rafe-walker

Copy link
Copy Markdown
Owner

Summary

Read-only operator panel for Kora's monthly Agent SDK credit ladder per R4.1 §9.6 — current burn against the $200/mo pool, active rung, downshift state, deferred-for-cost tickets, and reconciliation history. Pairs with future KR-P2-K (cost-state runtime + reconciliation).

This is the 5th panel in the proven stub-first pattern (#26 OPS → flipped in #35, #31 SEA, #37 CONTROL, #45 BOOT). The pattern is empirically known to flip cleanly.

Endpoint (kora_cli/web_server.py)

GET /api/cost-state — returns current + rate_limit_pulse + deferred_tickets[] + reconciliation_history[] + stub: true. No POST/PUT/DELETE; cost-rung transitions are automatic in KR-P2-K's runtime and the "extra-usage OFF" hard cap is an Anthropic-console toggle.

No raw credentials in the response shape — dollar amounts + model tier + ticket IDs only. Enforced by test_no_credential_shaped_keys_in_response (regex-walks the payload for token / secret / api_key / password / bearer / authorization keys; expects zero matches).

Frontend (web/)

pages/CostStatePage.tsx — 4 sections:

  1. Burn summary — big $87.43 / $200.00 headline, rung pill, horizontal progress bar with tick marks at 75/90/100% and fill colour matched to active rung. Projection callout color-tones based on projected_end_of_period_usd / credit_pool_usd:
    • > 1.0 → red "Projected to exceed $200 by month-end"
    • > 0.9 → amber "On track to cross the 90% rung"
    • else → green "On track within budget" (the stub's 43.7%-used / $128 projection lands here, per the §7 smoke note)
  2. Active rung & downshift — rung pill + effective-model-tier badge + downshift indicator + extra-usage hard-cap status (destructive alert if extra-usage is ON)
  3. Rate-limit pulse — requests + tokens bars showing remaining/limit ratio, tone-coded
  4. Deferred + reconciliation — collapsible; default-expanded when there are deferred tickets so operator sees them immediately. Deferred ticket entries link to /sea-tickets.

lib/api.ts — new CostRung type + 4 interfaces (CostCurrent, RateLimitPulse + RateLimitWindow, DeferredTicket, ReconciliationEntry, CostStateResponse). Reuses existing ModelTier + Criticality from prior panels.

App.tsx/cost-state route + nav entry (DollarSign icon) between /boot-status and /kora-control.

Flip-over plan

When KR-P2-K lands and CostStateHolder.current() + .rate_limit_pulse() + .recent_reconciliations(limit=N) + a substrate scan for state == deferred_cost_limit tickets exist, swap get_cost_state body to project from those and drop the stub flag. The page itself doesn't change.

Test plan

  • tests/kora_cli/test_web_server_cost_state.py — 11/11 green, covers all 10 §5 scenarios + extra contract guard (hard_stop_100 ⇒ extra_usage_off must be True; never silently accept a hard-stop with the Anthropic console cap turned off)
  • test_web_server_{boot_status,kora_control,sea_tickets,cron_profiles,host_header,mcp,gateway_identity}.py — 67/67 still green (78 total)
  • npx tsc -b on web/ — clean
  • npx vite build on web/ — clean
  • §8 grep checks (5 total): STUB banner present, endpoint registered, zero write-side routes, zero credential-shaped keys in payload, ModelTier + Criticality each defined exactly once (reused, not duplicated)
  • Manual smoke: navigate to /cost-state, verify STUB banner renders, verify burn-summary progress bar shows tick marks at 75/90/100% with green fill, verify projection callout reads green "On track within budget" for the stub's 43.7%-used case, verify deferred-tickets section auto-expands because the stub has 1 deferred ticket

Dependency notes

  • KR-P2-K (future CC#1 bucket) builds the cost-state runtime + reconciliation
  • CostStateHolder.current() + .rate_limit_pulse() + .recent_reconciliations(limit=N) + a substrate query for deferred_cost_limit tickets are the accessors that flip this from stub to real

🤖 Generated with Claude Code

…tickets) against stub

Read-only operator panel for Kora's monthly Agent SDK credit ladder.
Pairs with future CC#1 KR-P2-K (cost-state runtime + reconciliation)
and goes in ahead of the runtime wire-in; v1 returns a realistic
mid-month sample (43.7% used, 75% rung active, Opus → Sonnet
downshift, one frontier-only deferred ticket, two in-tolerance
reconciliations) with ``stub: True`` so the panel renders
meaningfully and the operator can verify the rung-progression UI
before any real spending.

5th panel in the proven stub-first pattern. Predecessors: PR #26
OPS, #31 SEA, #37 CONTROL, #45 BOOT. OPS-PANEL already flipped
stub → real in PR #35, so the pattern is empirically known to flip
cleanly.

Backend (kora_cli/web_server.py):
  GET /api/cost-state — read-only stub. No POST/PUT/DELETE:
  cost-rung transitions are automatic in KR-P2-K's runtime; the
  "extra-usage OFF" hard cap is an Anthropic-console toggle
  (out-of-process). Response shape carries dollar amounts + model
  tier + ticket IDs only — never raw credentials (test guards
  enforce no token/secret/api_key/password/bearer-shaped keys
  appear in the payload).

Frontend:
  - CostStatePage.tsx — 4 sections:
    * Burn summary: big "$87.43 / $200.00" headline, rung pill,
      horizontal progress bar with tick marks at 75/90/100% and
      fill colour matched to active rung (success/warning/
      destructive). Projection callout banner color-tones based
      on ratio of projected end-of-period vs pool (green "on
      track", amber "on track to cross 90%", red "projected to
      exceed").
    * Active rung & downshift: rung pill + effective model-tier
      badge (opus/sonnet/haiku) + downshift-active indicator +
      extra-usage hard-cap status (green check or destructive
      alert if extra-usage is ON).
    * Rate-limit pulse: side-by-side requests + tokens bars
      showing remaining/limit ratio, tone-coded (success > 25%,
      warning < 25%, destructive < 10% remaining).
    * Deferred + reconciliation: collapsible. Default-expanded
      when there are deferred tickets (operator should see them
      immediately for context), collapsed otherwise. Deferred
      table links each ticket to /sea-tickets for detail.
  - api.ts — new CostRung type + 4 interfaces; reuses existing
    ModelTier + Criticality from prior panels (verified single-
    definition via the §8 grep check).
  - App.tsx — /cost-state route + nav entry (DollarSign icon)
    between /boot-status and /kora-control per spec §3.

Tests: tests/kora_cli/test_web_server_cost_state.py — 11 tests
covering all 10 §5 scenarios + 1 extra contract guard
(hard_stop_100 ⇒ extra_usage_off must be True; never silently
accept a hard-stop with the Anthropic console cap turned off).
78/78 across full web_server suite pass. tsc -b + vite build clean.

§8 pre-push grep checks (5 total): STUB banner present, endpoint
registered, zero write-side routes, zero credential-shaped fields
in the cost-state response, ModelTier + Criticality each defined
exactly once (reused, not duplicated).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant