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
Merged
Conversation
…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>
This was referenced May 21, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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— returnscurrent+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 fortoken/secret/api_key/password/bearer/authorizationkeys; expects zero matches).Frontend (web/)
pages/CostStatePage.tsx— 4 sections:$87.43 / $200.00headline, rung pill, horizontal progress bar with tick marks at 75/90/100% and fill colour matched to active rung. Projection callout color-tones based onprojected_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"/sea-tickets.lib/api.ts— newCostRungtype + 4 interfaces (CostCurrent,RateLimitPulse+RateLimitWindow,DeferredTicket,ReconciliationEntry,CostStateResponse). Reuses existingModelTier+Criticalityfrom prior panels.App.tsx—/cost-stateroute + nav entry (DollarSign icon) between/boot-statusand/kora-control.Flip-over plan
When KR-P2-K lands and
CostStateHolder.current()+.rate_limit_pulse()+.recent_reconciliations(limit=N)+ a substrate scan forstate == deferred_cost_limittickets exist, swapget_cost_statebody to project from those and drop thestubflag. 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 -bonweb/— cleannpx vite buildonweb/— cleanModelTier+Criticalityeach defined exactly once (reused, not duplicated)/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 ticketDependency notes
CostStateHolder.current()+.rate_limit_pulse()+.recent_reconciliations(limit=N)+ a substrate query fordeferred_cost_limittickets are the accessors that flip this from stub to real🤖 Generated with Claude Code