Files
Yuxin Qiao 6d906d375d Add Poe current balance provider (#1191)
* Add Poe current balance provider

* Add Poe OAuth login and usage-history support with UI summaries

* Fix Poe usage note line-length lint violations

* Format Poe files to satisfy SwiftFormat lint

* Harden Poe OAuth callback parsing

* Align Poe OAuth validation

* Fix rebase fallout: .points case + parser hash refresh

Two rebase fallouts from the Poe PR onto current main:

- MenuCardHeightFingerprint.ValueStyle.heightFingerprint (new on main)
  is missing a .points case; PR added .points to ValueStyle for Poe.
  Without this, swift build fails on main + PR with switch must be
  exhaustive.

- CodexParserHash.generated.swift was kept at the previous main value
  during rebase, but lint.sh check now fails because the main hash is
  itself stale. Re-ran Scripts/regenerate-codex-parser-hash.sh to get
  the correct hash for the current parser source.

Local: swift build green, swift test Poe/ConfigValidation/ProviderConfigEnvironment
suites all pass, lint.sh reports 0 violations across 1021 files.

* Expand Poe login and history test coverage

Add detailed test coverage for the OAuth login flow and the usage
history snapshot value-type:

- PoeLoginRunnerTests: cover the PKCE S256 challenge, the
  authorization URL parameter set, the env-driven client id
  resolver, and additional callback parser edge cases (URL-decoded
  values, whitespace trimming, ignored untracked params, state
  CSRF mismatch, access_denied / error_description, duplicate
  tracked parameters, empty query).
- PoeUsageHistorySnapshotTests: cover the daily / 7-day / 30-day
  summary bucketing, cost aggregation across nil and present
  buckets, topModels / topUsageTypes ordering and "unknown"
  fallback for empty strings, and recentEntries(limit:) clamping
  and ordering.
- Expose pure-function test hooks on PoeLoginRunner (mirroring
  the existing _parseCallbackForTesting pattern) so the new tests
  can drive makeCodeChallenge, makeAuthorizationURL, and
  oauthClientID without network or socket setup.

* Poe: cover callback HTML escape for attacker-controlled errors

Adds focused tests verifying the OAuth callback localhost landing
page HTML-escapes the `error_description` query string before
embedding it in the response body.

The HTML-escape implementation already shipped in
`PoeLoginRunner.httpResponse`; this commit just locks the behavior
in with a regression test so a future refactor cannot silently
regress the escaping.

Scoped to a test-only change to keep the diff narrow.

* Poe: keep balance available when optional history fetch fails

Previously `PoeUsageFetcher.fetchUsage` propagated any failure from
`points_history` to the caller, which caused the entire Poe provider
to report no data and lose the current balance display that the
provider was meant to surface. `points_history` is a best-effort
supplement, not a hard dependency of the current balance.

- Wrap the history fetch in a do/catch; on failure log the error
  and continue with `history: nil` so users still see their point
  balance.
- Extract an internal `_fetchUsage(apiKey:transport:)` helper so the
  flow can be exercised with a stub `ProviderHTTPTransport`, and
  update `fetchHistory` and `perform` to thread the transport
  through (matching the pattern used by other CodexBarCore
  fetchers like Kilo and MiniMax).
- Add focused tests covering both the failure (history 500 keeps
  balance) and success (empty history page still surfaces the
  balance) paths with a `ProviderHTTPTransportStub`.

The public `PoeUsageFetcher.fetchUsage(apiKey:)` signature is
unchanged, so no caller updates are required.

* chore: retrigger CI

* Fix CI lint fallout after merging main

* fix: narrow Poe provider to API key usage

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-06-15 16:31:36 -07:00

1.1 KiB

summary, read_when
summary read_when
Poe provider: API key setup, point balance, and recent usage history.
Configuring Poe usage
Debugging Poe balance or history requests

Poe Provider

CodexBar reads Poe's official usage API with a manually configured API key. It does not perform OAuth login or import browser cookies.

Authentication

Create or copy an API key from Poe API Keys, then add it in CodexBar Settings → Providers → Poe.

You can also set the environment variable:

export POE_API_KEY="..."

Or configure it through the CLI:

printf '%s' "$POE_API_KEY" | codexbar config set-api-key --provider poe --stdin

Data Source

CodexBar requests:

  • GET https://api.poe.com/usage/current_balance
  • GET https://api.poe.com/usage/points_history

The current balance request is required. Recent points history is best-effort, so a history error does not hide a valid balance.

Display

The provider shows the current point balance in the menu and menu bar. When available, recent history is grouped by day and shown in the usage detail.

CLI Usage

codexbar --provider poe