feat(mimo): opt-in local tracker fallback for MiMo card#1284
feat(mimo): opt-in local tracker fallback for MiMo card#1284LeoLin990405 wants to merge 1 commit into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed June 4, 2026, 3:06 AM ET / 07:06 UTC. Summary Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path. Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Review detailsBest possible solution: Retry the Codex review after fixing the execution failure. Do we have a high-confidence way to reproduce the issue? Unclear. The review failed before ClawSweeper could establish a reproduction path. Is this the best way to solve the issue? Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model gpt-5.5, reasoning high; reviewed against 65e39f4dcb3a. Label changesLabel changes:
Label justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0bcd990d4c
ℹ️ 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 Self.shouldFallbackToLocal(error: error), | ||
| let local = MiMoLocalUsageFallback.snapshot() | ||
| { | ||
| return self.makeResult(usage: local.toUsageSnapshot(), sourceLabel: "local") |
There was a problem hiding this comment.
Let the local cache make MiMo fetching available
When MiMo is in auto mode with no cached/importable browser session, isAvailable() returns false, and ProviderFetchPipeline.fetch skips fetch() entirely before this fallback branch can run. That means the documented opt-in path for users with only ~/.codexbar/mimo-local-usage.json and no platform cookies still ends in noAvailableStrategy instead of showing local usage; the strategy needs to report available when the local cache exists or expose a separate local strategy.
Useful? React with 👍 / 👎.
| let weekInput = Self.intValue(week["input"]) | ||
| let weekOutput = Self.intValue(week["output"]) | ||
| let weekCacheRead = Self.intValue(week["cache_read"]) | ||
| let weekTotal = weekInput + weekOutput + weekCacheRead |
There was a problem hiding this comment.
Include cache-creation tokens in local totals
For sessions that contain cache_creation_input_tokens, the tracker writes cache_create into each window, but the fallback snapshot only sums input/output/cache_read for today/week/all-time. Those cache-creation tokens are billable local activity and are displayed by the script summary, so omitting them here underreports the MiMo card totals and progress for any cached-prompt session that creates cache entries.
Useful? React with 👍 / 👎.
The MiMo provider only reaches platform.xiaomimimo.com via SSO cookies, which break in common scenarios: Chrome session cookies clear on Chrome relaunch, macOS keychain access to Chrome Safe Storage is blocked, the user has no SSO login on this machine, etc. When this happens the MiMo card surfaces "Xiaomi MiMo login required" indefinitely with no escape hatch (tp-prefixed inference API keys for token-plan-sgp.xiaomimimo.com cannot query platform quota — two independent auth systems). This PR adds an implicit opt-in local fallback. When the platform fetch fails with missingCookie / invalidCookie / loginRequired / invalidCredentials, the MiMo strategy reads `~/.codexbar/mimo-local-usage.json` (populated by `Scripts/mimo-usage.py` which scans `~/.claude-envs/mimo/.claude/projects/**/ *.jsonl` for any local Claude Code wrapper pointed at MiMo) and returns a snapshot wrapped as `sourceLabel: "local"`. - New `MiMoLocalUsageFallback.swift` reads the JSON cache and constructs a `MiMoUsageSnapshot` with today/week/lifetime token sums in `planCode` and a progress bar showing weekly tokens vs lifetime baseline. - `MiMoWebFetchStrategy.fetch()` wraps the existing logic in try/catch and invokes the fallback only when the cache file exists (zero behavior change for users who do not opt in). - `MenuCardView.usageNotes(input:)` suppresses the "Balance updates in near-real time / Daily billing finalizes at 07:00 UTC" footer when sourceLabel is "local" since neither applies to local accounting. - `Scripts/mimo-usage.py` ships the sample tracker (Python 3, no external deps). Setup is documented in `docs/mimo.md` "Local fallback (opt-in)". - New `MiMoLocalUsageFallbackTests` cover missing/malformed cache, normal parse with progress bar, and idle-week surfacing lifetime baseline. ## Tests - `swift test --filter MiMoLocalUsageFallbackTests` ## Validation - `swift build --target CodexBarCore` passes locally. - `swift build --target CodexBar` passes locally. - Local `swift test` is blocked before reaching these tests by the local Command Line Tools environment (`KeyboardShortcuts` `#Preview` macro plugins are unavailable without full Xcode); CI should be the test signal. ## Scope No changes to OAuth/cookie paths, provider ordering, settings UI, package targets, or non-MiMo providers. Behavior is identical to current main when `~/.codexbar/mimo-local-usage.json` does not exist.
0bcd990 to
f923238
Compare
|
Pushed an amend: |
|
@clawsweeper re-review The previous review marker references commit Real-behavior proof (after installing The Menu screenshot will be attached in a follow-up comment from the PR author (gh CLI doesn't support image upload). Zero behavior change for users without |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Summary
Xiaomi MiMo login required.MiMoWebFetchStrategy.fetch()wraps existing cookie logic in try/catch and falls back toMiMoLocalUsageFallback.snapshot()only when~/.codexbar/mimo-local-usage.jsonexists (zero behavior change for users who do not opt in).sourceLabel == "local"since neither applies to local accounting.Scripts/mimo-usage.py(Python 3, no external deps) as a sample tracker — scans~/.claude-envs/mimo/.claude/projects/**/*.jsonlfor any Claude Code wrapper pointed at MiMo (e.g.cc-mimowithANTHROPIC_BASE_URL=https://token-plan-sgp.xiaomimimo.com/anthropic) and aggregatesinput_tokens/output_tokens/cache_read_input_tokensper today / week / all_time window.docs/mimo.md→ "Local fallback (opt-in)".Why
The MiMo provider currently only reaches platform.xiaomimimo.com via SSO cookies, which break in common macOS scenarios:
api-platform_serviceTokenetc.) clear on Chrome relaunch (they're session-level:expires=0in Chrome SQLite).Disable Keychain access/ TCC blocks reading Chrome Safe Storage to decrypt the cookie value.When this happens the MiMo card shows
Xiaomi MiMo login requiredindefinitely with no escape hatch —tp--prefixed inference API keys (token-plan-sgp.xiaomimimo.com/anthropic) cannot query platform quota; they are two independent auth systems per Xiaomi's own docs.The local fallback is implicit opt-in: it activates only when the cache file exists. Users without a local wrapper / tracker see no change; current behavior preserved exactly.
Tests
MiMoLocalUsageFallbackTestscovering:snapshot()returns nil → fallback skippedValidation
swift build --target CodexBarCorepasses locally.swift build --target CodexBarpasses locally.swift test --filter MiMoLocalUsageFallbackTestsis blocked before reaching the new tests by the local Command Line Tools environment (KeyboardShortcuts#Previewmacro plugins are unavailable without full Xcode); CI should be the test signal.Scope
No changes to OAuth/cookie paths, provider selection ordering, settings UI,
Package.swift, or non-MiMo providers. Behavior is identical to currentmainwhen~/.codexbar/mimo-local-usage.jsondoes not exist.