Skip to content

Conversation

@claude89757
Copy link

@claude89757 claude89757 commented Feb 3, 2026

Summary

This PR adds support for CodeBuddy (Tencent Cloud AI Coding Assistant) as a new usage provider. CodeBuddy is a popular AI coding assistant in China, and this integration enables users to track their credit usage directly from CodexBar.

Local Test

image

Features

Core Implementation

  • Cookie-based authentication: Extracts session cookies from Chrome browser (default)
  • Enterprise ID auto-detection: Automatically detects and stores enterprise ID from API responses
  • Credit usage fetching: Polls POST /billing/meter/get-enterprise-user-usage for usage data
  • Daily usage tracking: Fetches and displays daily usage breakdown with chart visualization
  • Session keepalive: Maintains active session to prevent timeout

Files Added (12 new files)

CodexBarCore/Providers/CodeBuddy/

  • CodeBuddyAPIError.swift - Error types for API failures
  • CodeBuddyCookieHeader.swift - Cookie header management and enterprise ID extraction
  • CodeBuddyCookieImporter.swift - Browser cookie import logic
  • CodeBuddyModels.swift - API response models
  • CodeBuddyProviderDescriptor.swift - Provider metadata and configuration
  • CodeBuddySessionKeepalive.swift - Session keepalive functionality
  • CodeBuddySettingsReader.swift - Settings reader for provider configuration
  • CodeBuddyUsageFetcher.swift - Main usage fetching logic
  • CodeBuddyUsageSnapshot.swift - Usage snapshot conversion

CodexBar/Providers/CodeBuddy/

  • CodeBuddyProviderImplementation.swift - Provider implementation
  • CodeBuddyProviderRuntime.swift - Runtime management
  • CodeBuddySettingsStore.swift - Settings store for UI

Views

  • CodeBuddyDailyUsageChartMenuView.swift - Daily usage chart visualization

Files Modified (17 files)

  • Updated provider enums to include CodeBuddy
  • Added CodeBuddy to provider registry
  • Extended menu bar and widget support
  • Added log category for debugging
  • Integrated with CLI token account display

Tests

  • CodeBuddyTests.swift - Comprehensive unit tests covering:
    • JSON parsing for usage responses
    • Daily usage response parsing
    • Usage snapshot calculations (percentage, formatting)
    • Cookie header extraction
    • Enterprise ID parsing from cURL commands

Usage Display

  • Menu bar shows format: 1,121 / 25,000 (used / limit credits)
  • Percentage calculation: credit / limitNum × 100
  • Dashboard link: https://tencent.sso.codebuddy.cn/profile/usage

Authentication Flow

  1. User triggers cookie import for CodeBuddy
  2. System extracts session and session_2 cookies from tencent.sso.codebuddy.cn domain
  3. Cookies are cached in Keychain
  4. Enterprise ID is auto-detected from initial API probe
  5. Subsequent API calls include proper authentication headers

Testing

  • Unit tests pass (swift test)
  • Follows existing provider patterns
  • Uses Chrome as default browser for cookie import

Related

This follows the same architecture patterns as other providers (Claude, Gemini, Copilot, etc.).

Implements CodeBuddy (Tencent Cloud AI assistant) integration with:
- Cookie-based authentication from Chrome browser
- Enterprise ID auto-detection from API responses
- Credit usage fetching from billing API
- Daily usage chart visualization
- Session keepalive functionality
- Unit tests for models, snapshots, and cookie parsing

Follows existing provider patterns and architecture.
Copy link

@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: f2be96b90b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +25 to +33
/// Default enterprise ID for most CodeBuddy users
private static let defaultEnterpriseID = "etahzsqej0n4"

var codebuddyEnterpriseID: String {
get {
let stored = self.configSnapshot.providerConfig(for: .codebuddy)?.enterpriseID
// Use default if not explicitly set
return stored ?? Self.defaultEnterpriseID
}

Choose a reason for hiding this comment

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

P2 Badge Avoid hard-coded enterprise ID fallback

The getter always returns defaultEnterpriseID when the user hasn’t configured one, which makes the provider look configured and forces API calls to use a hard-coded enterprise ID. In practice, users who haven’t set their own enterprise ID will either get repeated 403s or (if the cookie happens to allow it) see usage for the wrong enterprise. This should be nil/empty until explicitly set or auto-detected so availability and fetches reflect the user’s actual enterprise.

Useful? React with 👍 / 👎.

Copy link
Author

Choose a reason for hiding this comment

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

Re: enterprise ID default - The CodeBuddy API requires x-enterprise-id header, returning 400 without it. The default enables out-of-box functionality, and users can customize it via Settings → Enterprise ID field. Cookie validation still gates actual data access regardless of enterprise ID value.

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.

1 participant