feat(menubar): Local/Combined usage toggle — Swift, stacked on #567 (#566)#568
Open
ozymandiashh wants to merge 2 commits into
Open
feat(menubar): Local/Combined usage toggle — Swift, stacked on #567 (#566)#568ozymandiashh wants to merge 2 commits into
ozymandiashh wants to merge 2 commits into
Conversation
…tagentseal#566) The macOS menubar reads `codeburn status --format menubar-json`, which only ever reflected the local machine. Multi-device "Combined" usage existed only in the terminal `devices` command. This exposes combined + per-device usage through the menubar-json contract so the menubar can mirror the combined dashboard. - Extract the per-device summary + combined reduce that was inline in renderDevices into a reusable pure `summarizeDeviceUsage(results, window?)`. Error/unreachable devices are excluded from the combined sums (kept in perDevice); deviceCount counts all, reachableCount counts the reachable ones. renderDevices now formats from it with byte-identical output. - Add an optional `combined?: CombinedUsage` block to MenubarPayload (perDevice list + combined totals incl. calls/sessions). Absent by default. - Add `--scope local|combined` to `status` (default local). `combined` builds the local payload, pulls paired devices (pullDevices isolates per-peer failures), and attaches the summary. - Correctness guards: reject `--scope combined` with `--days` (non-contiguous, not representable over the sharing query) and with `--provider`/`--project`/ `--exclude` (the sharing query carries no filters, so peers would report unfiltered usage). Window-scope the cache-token sum to the selected period (cache lives in 365-day daily history; current carries no cache counts). TS/CLI only. The menubar Local/Combined toggle + render is a follow-up.
Mirror the combined multi-device dashboard in the macOS menubar via a Local/Combined scope toggle (Settings -> Display). Builds on the menubar-json `--scope combined` contract. - MenubarScope enum (.local default) persisted in UserDefaults; PayloadCacheKey gains a scope dimension so local and combined payloads cache separately. - DataClient.fetch(scope:): a pure statusSubcommand builder appends `--scope combined` only for combined, forces `--provider all` (the CLI rejects combined with a provider/project/exclude filter), and coerces multi-day selections to local (the CLI rejects combined + --days). - MenubarPayload decodes the optional `combined` block (per-device + totals); nil when absent (back-compat). - The badge always stays on the local payload; the combined network pull lives on a separate cache key and falls back to local with a "Combined unavailable" indicator, so a slow/offline peer never blocks the badge. - Hero shows combined totals + a per-device breakdown in Combined scope; the token metric stays input+output (cache excluded) to match local; the per-device daily-budget warning is suppressed for a multi-device total; selecting Combined resets the provider tab to All. Tests run via `swift test` (CommandLineTools Testing.framework on the rpath, no Xcode): scope persistence, argv (local/combined/provider-forcing/multi-day), cache-key partition, badge-survives-combined-failure, combined decode, token consistency, provider reset, budget suppression.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Swift half of #566: a Local/Combined toggle in the macOS menubar, on top of the menubar-json
--scope combinedcontract.Stacked on #567. The first commit here is #567 (the data-layer PR); review/merge that first. Once #567 lands I'll rebase so this shows only the
mac/diff. (Until then the diff below includes #567's TS changes.)What changed (Swift,
mac/)MenubarScopetoggle (Settings -> Display), default Local (Combined is opt-in). Persisted in UserDefaults;PayloadCacheKeygains a scope dimension so local/combined cache separately.DataClient.fetch(scope:)via a purestatusSubcommandbuilder: appends--scope combinedonly for combined, forces--provider all(the CLI rejects combined with a filter), and coerces multi-day to local (the CLI rejects combined +--days).MenubarPayloaddecodes the optionalcombinedblock; nil when absent (back-compat).Testing
swift test-> 62 tests pass (scope persistence, argv local/combined/provider-forcing/multi-day-coerce, cache-key partition, badge-survives-combined-failure, combined decode, token consistency, provider reset, budget suppression).vitest28 targeted tests +tsc+ semgrep, all green.