Skip to content

Use authoritative usageUnitsAvailable for Augment credits limit#338

Open
bcharleson wants to merge 30 commits intosteipete:mainfrom
bcharleson:fix/augment-credits-limit
Open

Use authoritative usageUnitsAvailable for Augment credits limit#338
bcharleson wants to merge 30 commits intosteipete:mainfrom
bcharleson:fix/augment-credits-limit

Conversation

@bcharleson
Copy link
Contributor

Summary

  • The creditsLimit computed property on AugmentCreditsResponse now prefers the API-provided usageUnitsAvailable field as the total allocation instead of always deriving it from usageUnitsRemaining + usageUnitsConsumedThisBillingCycle.
  • Falls back to the existing derived calculation when usageUnitsAvailable is absent or zero, so the change is fully backward-compatible.

Motivation

The usageUnitsAvailable field was already being parsed from the Augment API response but was never used. Relying on the derived sum (remaining + consumed) could theoretically produce an inaccurate total if Augment adjusts credits mid-cycle, applies bonus allocations, or changes how remaining/consumed are reported. Using the authoritative API value ensures the usage progress bar percentage aligns with Augment's own dashboard.

Test plan

  • Verified the progress bar percentage matches Augment dashboard after rebuild
  • Confirmed fallback path still works when usageUnitsAvailable is nil
  • swift build and swift test pass

Made with Cursor

bcharleson and others added 30 commits January 1, 2026 20:28
Initialize augmentCookieSourceRaw from UserDefaults in init, matching
the pattern used by other providers. Without this, the cookie source
always falls back to .auto after relaunch, causing users who select
.manual or .off to lose their preference.

Addresses Codex bot review feedback on PR steipete#120.
…ry pattern

- Remove early return for non-session cookies
- Now continues searching other browsers if session cookies not found
- Matches Cursor/Factory behavior: only returns when valid session cookies present
- Prevents false positives from random augmentcode.com cookies
- Add NextAuth and AuthJS cookie variants for broader compatibility
- Add comprehensive comment noting list may not be exhaustive
- Improve logging to help discover missing cookie names
- Log specific matched cookies when found
- Warn users when cookies exist but don't match known session cookies
- Request users report unrecognized cookies to improve detection

This addresses potential authentication failures if Augment uses
non-standard cookie names not in our current list.
- Remove CodexBar 2.app and CodexBar_Dev.app from git (should never be committed)
- Improve .gitignore to catch all app bundle variations (CodexBar_*.app/)
- Add development setup documentation (docs/DEVELOPMENT_SETUP.md)
- Add script to create stable dev signing certificate (Scripts/setup_dev_signing.sh)

This prevents build artifacts from polluting the repository and provides
guidance for reducing keychain permission prompts during development.
Upstream changes:
- feat(vertexai): Add Vertex AI provider with token cost tracking
- feat(vertex): Add direct token cost tracking with _vrtx_ detection
- fix(vertex): Disable direct token cost tracking to avoid double-counting
- docs: Add Vertex AI provider documentation
- style: Fix swiftformat and swiftlint violations

These changes add support for Google Cloud Vertex AI with gcloud OAuth
and token cost tracking from local Claude logs.
…ry pattern

- Remove early return for non-session cookies
- Now continues searching other browsers if session cookies not found
- Matches Cursor/Factory behavior: only returns when valid session cookies present
- Prevents false positives from random augmentcode.com cookies
- Add NextAuth and AuthJS cookie variants for broader compatibility
- Add comprehensive comment noting list may not be exhaustive
- Improve logging to help discover missing cookie names
- Log specific matched cookies when found
- Warn users when cookies exist but don't match known session cookies
- Request users report unrecognized cookies to improve detection

This addresses potential authentication failures if Augment uses
non-standard cookie names not in our current list.
- Detect session expiration (401) and trigger automatic recovery
- Open Augment dashboard in browser to re-authenticate
- Re-import cookies after browser updates them
- Send user notification if automatic recovery fails
- Use modern UserNotifications framework instead of deprecated NSUserNotification
- Improve error handling to try all endpoints before giving up

Fixes issue where users had to manually log out and log back in when session expires.
- Keepalive now runs regardless of whether Augment is enabled
- This ensures automatic session recovery even when provider is disabled
- Added 'Refresh Session' button to Augment menu for manual recovery
- No more need to manually log out and log back in!

The keepalive will:
1. Detect when session expires (401 errors)
2. Automatically open Augment in browser to re-authenticate
3. Re-import fresh cookies
4. Verify the new session is valid
5. Send notification if recovery fails
- Reduce keepalive check interval from 5 minutes to 1 minute for faster detection
- Reduce minimum refresh interval from 2 minutes to 1 minute
- Throw sessionExpired error on 401 responses instead of generic networkError
- Add immediate recovery trigger in UsageStore when sessionExpired detected
- Automatically recover sessions without manual logout/login required
- Add onSessionRecovered callback to AugmentSessionKeepalive
- Automatically refresh Augment usage after session recovery completes
- Ensures menu updates with fresh data after recovery
- Fixes issue where error message persisted after successful recovery
- Add AuggieCLIProbe to fetch credits from 'auggie account status'
- Add BinaryLocator.resolveAuggieBinary() to locate auggie CLI
- Update AugmentProviderDescriptor to try CLI first, fallback to web
- Parse billing cycle end date from CLI output
- Eliminates browser cookie prompts for users with auggie CLI installed
- Faster and more reliable than web scraping
- Add automatic session recovery when Augment cookies expire
- Add manual 'Refresh Session' button in menu bar
- Trigger usage refresh after successful session recovery
- Add CookieHeaderStore for encrypted cookie storage
- Add ZaiTokenStore for encrypted token storage
- Always-on keepalive monitoring for Augment sessions
- Replace print() statements with proper CodexBarLog.logger() calls
- Add static logger instances for augment-keepalive and session-keepalive
- Maintain backward compatibility with existing logger callback
- All 358 tests passing
Merging 9 commits from upstream (2cd166f..d0a79d9):
- Fix Claude OAuth scope errors
- Linux platform compatibility fixes
- Augment CLI macOS gating
- Browser cookie source detection hardening
- Non-macOS provider stub alignment

All changes are compatible with our Augment integration.
No conflicts expected - our changes are in different areas.

Upstream changes enhance cross-platform compatibility without
affecting our Augment session keepalive and cookie management.
…eepalive

This merge brings comprehensive Augment integration improvements:

🚀 CLI Integration
- Add support for 'auggie account status' CLI command
- Eliminates browser cookie prompts for CLI users
- Faster and more reliable than web scraping
- Automatic fallback to web if CLI unavailable
- Parses billing cycle end date from CLI output

🔄 Session Keepalive
- Automatic session recovery when Augment cookies expire
- Manual 'Refresh Session' button in menu
- Triggers usage refresh after successful recovery
- Always-on keepalive monitoring

🔐 Encrypted Credential Storage
- Secure keychain storage for cookies and tokens
- Automatic migration from old storage format

All 364 tests passing ✅
Ensures all 12 provider icons are verified in ProviderIconResourcesTests
- Merged upstream changes including new providers (Amp, JetBrains, Kimi, OpenCode, Synthetic)
- Updated ProviderIconResourcesTests to verify all 17 provider icons
- Fixed duplicate function in StatusItemController+Actions
- Cleaned up merge artifacts (duplicate files)
- Your Augment integration was already merged upstream (PR steipete#142)

New providers added upstream:
- Amp provider
- JetBrains AI provider
- Kimi provider (2 variants)
- OpenCode provider
- Synthetic provider

Major upstream improvements:
- Config-backed CLI output
- Provider sidebar redesign
- Beta update channel
- Keychain access gating
- File logging support
- Menu bar metric preferences
- Token account multi-account support
breakdown.total represents the USED amount (included + bonus credits consumed),
not the plan limit. This was causing usage to always show 100% (used/used)
instead of the correct percentage (used/limit).

API response structure:
- plan.used: credits consumed (in cents)
- plan.limit: actual plan allowance (in cents)
- breakdown.total: same as used, NOT the limit
Prevents 'resource fork, Finder information, or similar detritus not allowed' errors during code signing by using ditto --norsrc to copy the app bundle and strip all extended attributes and resource forks before final signing.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…nd CI updates

Brings in 36 upstream commits including:
- Claude OAuth refresh hardening and delegated refresh coordinator
- Keychain prompt storm reduction and access gate
- Token account precedence over config apiKey
- Status overlay fix for disabled providers in merged mode
- GitHub Actions Node 24 upgrade
- Comprehensive new test coverage for OAuth and keychain flows
The creditsLimit computed property now prefers the API-provided
usageUnitsAvailable field as the total allocation, falling back
to the derived remaining + consumed calculation only when the
field is absent. This ensures the progress bar percentage aligns
with Augment's own reported totals.

Co-authored-by: Cursor <cursoragent@cursor.com>
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