feat(cache): add cookie cache clearing to Debug tab and CLI#592
feat(cache): add cookie cache clearing to Debug tab and CLI#592coygeek wants to merge 2 commits intosteipete:mainfrom
Conversation
Add a "Clear cookie cache" button to the Debug → Caches section, alongside the existing "Clear cost cache" button. This allows users to clear stale or corrupt browser cookie caches from the GUI without needing to run manual Keychain commands. Also add a `codexbar cache clear` CLI command with --cookies, --cost, and --all flags, plus optional --provider for per-provider clearing. Changes: - CookieHeaderCache: add clearAll() that iterates all providers - PreferencesDebugPane: add "Clear cookie cache" button in Caches section - CLICacheCommand: new file implementing `cache clear` subcommand - CLIEntry: wire up `cache clear` command path - CLIHelp/CLIIO: add cache help text and help routing Closes steipete#591 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f7d7f20aa
ℹ️ 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".
| if case .found = KeychainCacheStore.load(key: key, as: Entry.self) { | ||
| self.clear(provider: provider) |
There was a problem hiding this comment.
Clear provider caches even when decode fails
clearAll() only calls self.clear(provider:) when KeychainCacheStore.load(..., as: Entry.self) returns .found, so corrupted keychain entries (.invalid) and legacy-file-only caches are skipped. In those states, cache clear --cookies/the Debug button can report nothing cleared while stale cookie data remains (or gets re-migrated later), which defeats the main recovery path for broken cookie cache state.
Useful? React with 👍 / 👎.
clearAll() previously only cleared `.found` entries, skipping `.invalid` (corrupt) keychain entries and legacy-file-only caches. Since the primary use case is recovering from broken cookie state, unconditionally clear both corrupt keychain entries and orphaned legacy files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cef0db91eb
ℹ️ 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".
| let clearCookies = cookies || all | ||
| let clearCost = cost || all | ||
|
|
||
| if !clearCookies && !clearCost { |
There was a problem hiding this comment.
Reject --provider without cookie-clear flags
--provider is currently accepted whenever any clear action is chosen, but it is only used inside the cookie-clearing branch. In practice, codexbar cache clear --cost --provider claude silently ignores the provider and still exits success after clearing cost cache, which is misleading for users and scripts that expect provider-scoped behavior. Add validation so --provider requires --cookies (or explicitly documented semantics with --all) instead of being ignored.
Useful? React with 👍 / 👎.
| let had = CookieHeaderCache.load(provider: provider) != nil | ||
| CookieHeaderCache.clear(provider: provider) |
There was a problem hiding this comment.
Report provider clears correctly for invalid cookie entries
The provider-specific path derives cleared from CookieHeaderCache.load(...) != nil, but load returns nil for invalid/corrupt keychain payloads even when those entries are then removed. This causes cache clear --cookies --provider <name> to report cleared: 0/"nothing to clear" in corrupt-entry scenarios, producing incorrect CLI output and unreliable JSON for automation.
Useful? React with 👍 / 👎.
Summary
codexbar cache clearCLI command with--cookies,--cost, and--allflags, plus optional--providerfor per-provider clearingCookieHeaderCache.clearAll()public API that iterates all providers and clears cached entries from KeychainMotivation
When browser cookie imports become corrupt or stale (e.g., from a Firefox profile with bad session data), there is currently no user-facing way to clear the cached cookie entries. The only workaround is running a manual Keychain command:
This is not discoverable. Toggling the provider off/on or changing cookie source to "Off" and back doesn't clear the Keychain cache either.
Changes
Sources/CodexBarCore/CookieHeaderCache.swiftclearAll()methodSources/CodexBar/PreferencesDebugPane.swiftSources/CodexBarCLI/CLICacheCommand.swiftcache clearsubcommandSources/CodexBarCLI/CLIEntry.swiftcache clearcommand pathSources/CodexBarCLI/CLIHelp.swiftSources/CodexBarCLI/CLIIO.swiftcache/clearto helpCLI Usage
Test plan
codexbar cache clear --cookiesand verify text outputcodexbar cache clear --cookies --provider claudefor single-provider clearingcodexbar cache clear --all --format json --prettyfor JSON outputCloses #591
🤖 Generated with Claude Code