feat(usage): host-driven feeds for every provider, plus the extension seam
The first pass had one provider and one shape. dawn wants /usage to cover what she actually pays for - antigravity, hyper, opencode-go, zai, deepseek, alibaba - and to reuse the same rules from a macOS app, so the query became a definition instead of a function. A feed is now driven by the host: `advance(state, responses)` returns either the requests to send or the finished report. The host owns HTTP, which is what lets one definition run in the CLI, in the Zig core, and in a tray. It also covers the providers that need more than one call - hyper reads /v1/teams before it can ask for that team's billing - without inventing a second concept for them. - packages/ai/docs/usage-feeds.md is the contract: report shape, credential kinds, and the unit rules (percent vs fraction vs remaining-fraction vs dollars; epoch seconds vs milliseconds vs ISO-8601) that every provider gets wrong in its own way. - seven feeds: openai-codex, anthropic (the normalised limits[] array, not the codenamed windows), google-antigravity (including the antigravity/... user-agent its endpoint gates on), hyper (plan allocation vs remaining credits, two-step, dollar balance), opencode-go, zai, and deepseek, which is balance-only and therefore has no windows at all. - reports gained `balance` and `notes`, so a provider without a percentage is not forced into one, and `skipped` became {provider, reason} - a key-only alibaba now says "needs a session credential" instead of going quiet. - credentials are provider-defined: oauth, apiKey, or a captured session. alibaba's token-plan keys are inference-only, so its quota needs a console session, and scripts/capture-alibaba-session.mjs turns a browser HAR export into the 0600 session file the bridge reads. - pi.registerProvider(..., { usage }) registers a feed from an extension into the same lookup, so a provider dawn builds herself is covered by /usage with no new wiring, and unregistering drops it. Documented in docs/custom-provider.md. Verified: 64 tests across the five usage suites (every feed driven through the host loop with scripted responses, no network in any of them), coding-agent usage 12/12 plus the CLI and interactive suites, tsgo and biome clean.
12345678910111213141516171819202122232425{ "code": "200", "data": { "DataV2": { "ret": [ "SUCCESS::接口调用成功" ], "data": { "msg": "Success.", "code": "SUCCESS", "data": [], "requestId": "00000000-0000-0000-0000-000000000005", "success": true } }, "success": true, "httpStatus": 200, "errorCode": "", "api": "zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/reset-card/list", "errorMsg": "" }, "httpStatusCode": "200", "requestId": "00000000-0000-0000-0000-000000000006", "successResponse": true}123456789101112131415161718192021222324252627282930313233{ "code": "200", "data": { "DataV2": { "ret": [ "SUCCESS::接口调用成功" ], "data": { "msg": "Success.", "code": "SUCCESS", "data": { "instanceCode": "sfm_tokenplansolo_public_intl-sg-sanitized001", "specCode": "pro", "remainingDays": 29, "startTime": 1789415534000, "endTime": 1792080000000, "autoRenewFlag": false, "status": "VALID" }, "requestId": "00000000-0000-0000-0000-000000000003", "success": true } }, "success": true, "httpStatus": 200, "errorCode": "", "api": "zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/subscription", "errorMsg": "" }, "httpStatusCode": "200", "requestId": "00000000-0000-0000-0000-000000000004", "successResponse": true}12345678910111213141516171819202122232425262728{ "code": "200", "data": { "DataV2": { "ret": [ "SUCCESS::接口调用成功" ], "data": { "msg": "Success.", "code": "SUCCESS", "data": { "per1WeekResetTime": 1790021160000, "per1WeekPercentage": 0.83603712139856 }, "requestId": "00000000-0000-0000-0000-000000000001", "success": true } }, "success": true, "httpStatus": 200, "errorCode": "", "api": "zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage", "errorMsg": "" }, "httpStatusCode": "200", "requestId": "00000000-0000-0000-0000-000000000002", "successResponse": true}123456789101112131415161718192021222324252627282930313233{ "account": { "uuid": "00000000-0000-4000-8000-000000000000", "full_name": "Example User", "display_name": "example", "email": "user@example.com", "has_claude_max": false, "has_claude_pro": false, "created_at": "2026-06-09T11:28:39.481128Z" }, "organization": { "uuid": "11111111-1111-4111-8111-111111111111", "name": "Example Org", "organization_type": "claude_team", "billing_type": "stripe_subscription", "rate_limit_tier": "default_raven", "seat_tier": "team_standard", "has_extra_usage_enabled": false, "subscription_status": "active", "subscription_created_at": "2026-06-29T10:33:57.742144Z", "cc_onboarding_flags": {}, "claude_code_trial_ends_at": null, "claude_code_trial_duration_days": null, "payment_auth_hosted_invoice_url": null, "claude_ai_completion_feedback_enabled": true }, "application": { "uuid": "22222222-2222-4222-8222-222222222222", "name": "Claude Code", "slug": "claude-code" }, "enabled_plugins": []}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394{ "five_hour": { "utilization": 0.0, "resets_at": null, "limit_dollars": null, "used_dollars": null, "remaining_dollars": null, "locked_reason": null }, "seven_day": { "utilization": 94.0, "resets_at": "2026-09-16T08:00:00.037593+00:00", "limit_dollars": null, "used_dollars": null, "remaining_dollars": null, "locked_reason": null }, "seven_day_oauth_apps": null, "seven_day_opus": null, "seven_day_sonnet": null, "seven_day_cowork": null, "seven_day_omelette": null, "tangelo": null, "iguana_necktie": null, "omelette_promotional": null, "nimbus_quill": { "utilization": 0.0, "resets_at": null, "limit_dollars": null, "used_dollars": null, "remaining_dollars": null, "locked_reason": null }, "cinder_cove": null, "copper_kite": null, "harbor_lantern": null, "amber_ladder": null, "juniper_tide": null, "cedar_ember": null, "extra_usage": { "is_enabled": false, "monthly_limit": null, "used_credits": null, "utilization": null, "currency": null, "decimal_places": null, "disabled_reason": null, "user_disabled": true, "spend_limit_reached": false, "credits_ever_enabled": true, "daily": null, "weekly": null }, "limits": [ { "kind": "session", "group": "session", "percent": 0, "severity": "normal", "resets_at": null, "scope": null, "is_active": false }, { "kind": "weekly_all", "group": "weekly", "percent": 94, "severity": "critical", "resets_at": "2026-09-16T08:00:00.037593+00:00", "scope": null, "is_active": true } ], "spend": { "used": { "amount_minor": 0, "currency": "USD", "exponent": 2 }, "limit": null, "percent": 0, "severity": "normal", "enabled": false, "disabled_reason": null, "cap": null, "balance": null, "auto_reload": null, "disclaimer": "Usage credits cover you when you hit your plan limits. [Learn more](https://support.claude.com/articles/12429409)", "can_purchase_credits": false, "can_toggle": false }, "member_dashboard_available": false, "seven_day_breakdown": null}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198{ "buckets": [ { "tokenType": "WTUS", "modelId": "chat_20706", "remainingFraction": 1 }, { "tokenType": "WTUS", "modelId": "chat_23310", "remainingFraction": 1 }, { "resetTime": "2026-09-16T04:40:57Z", "tokenType": "WTUS", "modelId": "claude-opus-4-6-thinking", "remainingFraction": 1 }, { "resetTime": "2026-09-16T04:40:57Z", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 1 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-2.5-flash", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-2.5-flash-lite", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-2.5-flash-thinking", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-2.5-pro", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3-flash", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3-flash-agent", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.1-flash-image", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.1-flash-lite", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.1-pro-high", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.1-pro-low", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.5-flash-extra-low", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.5-flash-lite", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.5-flash-low", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.6-flash-high", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.6-flash-low", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.6-flash-medium", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.6-flash-tiered", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.7-flash-high", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.7-flash-low", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.7-flash-medium", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.7-flash-tiered", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-high", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-low", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-medium", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-15T23:46:00Z", "tokenType": "WTUS", "modelId": "gemini-pro-agent", "remainingFraction": 0.16592255 }, { "resetTime": "2026-09-16T04:40:57Z", "tokenType": "WTUS", "modelId": "gpt-oss-120b-medium", "remainingFraction": 1 }, { "tokenType": "WTUS", "modelId": "tab_flash_lite_preview", "remainingFraction": 1 }, { "tokenType": "WTUS", "modelId": "tab_jump_flash_lite_preview", "remainingFraction": 1 } ]}1234567891011{ "is_available": true, "balance_infos": [ { "currency": "USD", "total_balance": "0.03", "granted_balance": "0.00", "topped_up_balance": "0.03" } ]}1234567891011121314151617181920212223242526272829303132333435{ "plan": { "id": "redacted-plan-id", "name": "Shred", "description": "Great for solo developers working with AI every day", "type": "paid", "price_cents": 2000, "period": "month", "hypercredits": 250 }, "status": "active", "balances": { "plan": { "usd": "11.83", "hypercredits": "237" }, "purchased": { "usd": "0.00", "hypercredits": "0" }, "total": { "usd": "11.83", "hypercredits": "237" } }, "billing_period": { "start": "2026-09-15T22:26:04Z", "end": "2026-10-15T22:26:04Z" }, "hypercredit_refresh": { "last_at": "2026-09-15T22:26:09.702198Z", "next_at": "2026-09-16T22:26:09.702198Z" }, "credit_refresh_scope": "team"}12345678910{ "items": [ { "id": "usr_789456123", "email": "user@example.com", "name": "Example User", "role": "admin" } ]}12345678910{ "items": [ { "id": "team_20439d8c54af", "name": "Example Team", "created_at": "2026-09-15T22:25:23.652189Z", "updated_at": "2026-09-15T22:25:23.652189Z" } ]}12345678910111213141516171819{ "usage": { "rolling": { "status": "ok", "percent": 0, "resetsAt": "2026-09-16T04:40:14.037Z" }, "weekly": { "status": "ok", "percent": 0, "resetsAt": "2026-09-21T00:00:00.037Z" }, "monthly": { "status": "rate-limited", "percent": 100, "resetsAt": "2026-09-29T07:01:56.037Z" } }}12345678910111213141516171819202122232425262728293031323334353637383940{ "code": 200, "msg": "Operation successful", "data": { "limits": [ { "type": "TIME_LIMIT", "unit": 5, "number": 1, "usage": 100, "currentValue": 0, "remaining": 100, "percentage": 0, "nextResetTime": 1792027143998, "usageDetails": [ { "modelCode": "search-prime", "usage": 0 }, { "modelCode": "web-reader", "usage": 0 }, { "modelCode": "zread", "usage": 0 } ] }, { "type": "TOKENS_LIMIT", "unit": 3, "number": 5, "percentage": 0 } ], "level": "lite" }, "success": true}