Skip to content

Conversation

@bcharleson
Copy link
Contributor

Summary

This PR adds significant improvements to Augment integration:

🚀 CLI Integration (New!)

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

🔄 Session Keepalive Improvements

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

Technical Details

New Files

  • AuggieCLIProbe.swift - Fetches credits from auggie CLI
  • BinaryLocator.resolveAuggieBinary() - Locates auggie executable

Modified Files

  • AugmentProviderDescriptor.swift - Updated fetch pipeline to try CLI first
  • AugmentSessionKeepalive.swift - Enhanced session recovery
  • PathEnvironment.swift - Added auggie binary resolution
  • StatusItemController+Actions.swift - Added manual refresh button
  • CookieHeaderStore.swift - Encrypted storage for cookies
  • ZaiTokenStore.swift - Encrypted storage for tokens

Fetch Strategy Priority

  1. CLI (auggie account status) - No prompts! ✅
  2. Web (browser cookies) - Fallback if CLI unavailable

Benefits

  • ✅ No more browser cookie prompts for CLI users
  • ✅ Faster credit checks
  • ✅ More reliable authentication
  • ✅ Automatic session recovery
  • ✅ Manual refresh option
  • ✅ Billing cycle end date display

Testing

  • Tested with auggie CLI v1.x
  • Verified fallback to web when CLI unavailable
  • Confirmed session recovery works
  • Menu bar displays credits and billing cycle correctly

Builds on the merged PR #120 (Augment integration) with additional improvements.

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: 70e1fba474

ℹ️ 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 +93 to +100
func shouldFallback(on error: Error, context _: ProviderFetchContext) -> Bool {
// Fallback to web if CLI fails (not authenticated, etc.)
if let cliError = error as? AuggieCLIError {
switch cliError {
case .notAuthenticated, .noOutput:
return true
case .parseError:
return false // Don't fallback on parse errors - something is wrong

Choose a reason for hiding this comment

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

P2 Badge Allow web fallback when CLI parsing fails

In auto mode, shouldFallback returns false for AuggieCLIError.parseError, so any CLI output format change (or localization) will stop the pipeline and skip the web strategy even if browser cookies are valid. This introduces a regression where Augment usage fails solely because the CLI output changed, despite the web fallback still being available. Consider falling back to the web strategy on parse errors (or treating parse errors as non-fatal in auto mode).

Useful? React with 👍 / 👎.

Comment on lines 76 to +84
private func restartAugmentKeepaliveIfNeeded() {
#if os(macOS)
let shouldRun = self.isEnabled(.augment)
// Always keep the keepalive running - it handles session recovery even when provider is disabled
let isRunning = self.augmentKeepalive != nil

if shouldRun, !isRunning {
if !isRunning {
self.startAugmentKeepalive()
} else if !shouldRun, isRunning {
Task { @MainActor in
self.augmentKeepalive?.stop()
self.augmentKeepalive = nil
print("[CodexBar] Augment session keepalive stopped (provider disabled)")
}
}
// Never stop the keepalive - it's needed for automatic session recovery

Choose a reason for hiding this comment

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

P2 Badge Respect provider disablement for keepalive

The keepalive is now always started and never stopped even when the Augment provider is disabled. That means the app will continue importing browser cookies and pinging Augment endpoints in the background, which can trigger browser access prompts, session recovery browser opens, or notifications for users who explicitly disabled the provider. This is a behavioral regression compared to the previous “only run when enabled” logic and undermines the expectation that disabling a provider stops its background activity.

Useful? React with 👍 / 👎.

…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
@bcharleson bcharleson force-pushed the feature/sessionkeepalive branch from 5f6e8df to 246f37f Compare January 7, 2026 13:07
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