Skip to content

Add Codebuff provider support#837

Merged
ratulsarna merged 7 commits intomainfrom
codex/pr-778-audit
May 4, 2026
Merged

Add Codebuff provider support#837
ratulsarna merged 7 commits intomainfrom
codex/pr-778-audit

Conversation

@ratulsarna
Copy link
Copy Markdown
Collaborator

Supersedes #778.

Thanks to @anandghegde for the original Codebuff provider contribution. This branch keeps that work and adds the follow-up fixes for Codebuff usage auth, credential parsing, API-key behavior, provider-order coverage, subscription tier parsing, and weekly reset metadata.

Validation:

  • swift test --filter Codebuff
  • swift test --filter SettingsStoreTests
  • pnpm check
  • ./Scripts/compile_and_run.sh

anandghegde and others added 6 commits May 4, 2026 13:58
Add a new CodexBar provider for Codebuff (https://www.codebuff.com), the
successor to the Manicode CLI. The provider surfaces live credit balance
and the weekly rate-limit window in the menu bar alongside the other
providers.

Data sources:
  * POST https://www.codebuff.com/api/v1/usage
      -> credit usage / quota / remaining balance / next reset /
         auto-topup state.
  * GET  https://www.codebuff.com/api/user/subscription
      -> subscription tier + weekly rate limit + billing period end.

Auth token resolution mirrors the Kilo pattern:
  1. CODEBUFF_API_KEY env var.
  2. API key configured in Settings -> Providers -> Codebuff.
  3. ~/.config/manicode/credentials.json (authToken field) written by
     the official `codebuff login` CLI.

New core files under Sources/CodexBarCore/Providers/Codebuff/:
CodebuffSettingsReader, CodebuffProviderDescriptor,
CodebuffUsageFetcher, CodebuffUsageSnapshot, CodebuffUsageError.
App-side files under Sources/CodexBar/Providers/Codebuff/:
CodebuffProviderImplementation, CodebuffSettingsStore. Lime-green SVG
icon added to Resources.

Registers .codebuff in UsageProvider + IconStyle + the descriptor /
implementation registries, the token resolver, config env propagation,
and all exhaustive switches across CostUsageScanner, UsageStore,
CodexBarCLI settings snapshot, and the widget views.

Unit tests added:
  * CodebuffSettingsReaderTests (11 cases) — env, quotes, auth-file
    parsing, descriptor shape.
  * CodebuffUsageFetcherTests (16 cases) — URL building, status code
    mapping, usage/subscription parsers, snapshot -> UsageSnapshot
    mapping, missing-creds fast-path.
  * ProviderTokenResolverTests — 3 new cases for env vs auth-file
    precedence and malformed credentials handling.

Verified: `swift build` and targeted `swift test` runs green
(27 new Codebuff tests + 12 resolver tests + the provider registry
coverage subset).

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
When the Codebuff API responds with partial credit data (only
creditsUsed or only creditsRemaining and no total quota), the fallback
branch previously set usedPercent=0, which rendered as a fully healthy
bar despite the code treating the payload as degenerate. Flip it to
100% exhausted so missing quota data stays visible to the user — this
matches Kilo's behaviour for zero/unknown totals.

Address review feedback on PR #778. Add regression tests for both the
used-only and remaining-only fallback branches plus an empty-snapshot
case.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- CodebuffUsageFetcher.fetchUsage: bound the wait for the optional
  /api/user/subscription call with a 2 s grace period after the primary
  /api/v1/usage response. A slow or hanging subscription endpoint no
  longer blocks the menu refresh up to the 15 s request timeout.
- CodebuffUsageSnapshot: stop encoding the credit balance
  ("X/Y credits") and weekly detail in RateWindow.resetDescription.
  Generic renderers prepend "Resets " when resetsAt is absent, which
  surfaced misleading lines like "Resets 250/1,000 credits" when the
  payload omitted next_quota_reset.
- Update snapshot test to assert resetDescription is nil for both the
  primary credits window and the secondary weekly window.
The .codebuff branch of ProviderConfigEnvironment.applyAPIKeyOverride was unconditionally writing the Settings-saved api key into CODEBUFF_API_KEY, clobbering any process env var already set by the user/CI. Only write the config token when the base environment does not already contain a non-empty CODEBUFF_API_KEY, so runtime/CI overrides win (matching ProviderTokenResolver.codebuffResolution precedence and the existing DeepSeek behavior). Adds two tests mirroring the DeepSeek precedence pattern.
@ratulsarna ratulsarna marked this pull request as ready for review May 4, 2026 10:51
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b4ecfb3ce0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Sources/CodexBarCore/Providers/Codebuff/CodebuffUsageFetcher.swift Outdated
Comment thread Sources/CodexBarCore/Providers/Codebuff/CodebuffUsageFetcher.swift Outdated
@ratulsarna
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ratulsarna ratulsarna merged commit d20a9bf into main May 4, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants