Repository navigation
Add Muse usage collector to the agents panel - #10610
andresantonioriveros wants to merge 4 commits into
Conversation
8919758 to
64f9ed9
Compare
Local metering (tokens, prompts, sessions, per-day and per-model breakdowns) from native muse sessions and opencode, following the claude/codex record contract. No limits section: the enforceable limits are not observable locally, so none are shown.
64f9ed9 to
55092d9
Compare
Probe the client's own key endpoint (POST api.meta.ai/muse-code/key) for subs_usage session + weekly percents with reset times plus the tier name — the same figures the TUI's /usage overlay shows. Limits stay strictly additive and authoritative: - Subscriber with a usage snapshot: Session (5-hour) + Weekly (7-day) meters, cached 60s, expired windows filtered. - Subscriber without a snapshot yet: tier kept, limits unavailable. - Pay-as-you-go (is_subs_active=false, no subs_usage): silent local metering only — not an error, not expired, no retry. - 401/403: Sign-in expired. Transport failure: retryAdvised with fallback. Malformed responses: generic unavailable, no retry. No estimated meters from manual caps: without an authoritative probe the panel shows measured usage only. The OAuth token travels only in the Authorization header; neither it nor the minted key is persisted. Includes a stub-based limits test (subscriber, PAYG, no-snapshot, expired, malformed login, MUSE_AUTH_PATH) and README docs.
|
I opened #10849 independently and compared the implementations. Yours has broader local usage coverage and parser handling, and I'd be happy to contribute the complementary pieces from mine here. I just caught your latest subscription-window commit. The remaining pieces I'd propose are event-ID deduplication (including retained-frame children), exclusion of As a separate follow-up, mine clears limits after a failed probe rather than retaining cached percentages, while keeping local token usage visible; a later successful probe restores the meters. That behavior could be reviewed independently of the counting fixes, preserving your PAYG handling and opencode support. Would you be open to a PR against your branch with the deduplication fixes first? If we consolidate the work here, I'm happy to close #10849 in favor of this PR. |
|
Hey @nissuor! I saw the subscription documentation was updated with the new subscription and rate limits, but seems like the pay-as-you-go option most people might be using (ex. opencode zen or omarchy credit users) still doesn't report usage back. Happy to merge those, I can undo 8f7d602 so you add a PR with subscription changes on top of this, let me know what's the best way to dedup! |
|
Thanks! No need to undo the subscription commit — I based the counting fixes directly on it: andresantonioriveros#2 The PR deduplicates valid completion record IDs across plain records, retained-frame children, and copied sessions, and excludes The focused Muse suites pass; the PR body documents the full-suite baseline failures on my machine. We can keep the hide-limits-on-failure behavior as a separate follow-up. Agreed that subscription windows should not be presented as coverage of hosted-proxy/PAYG throttling. |
|
Verified the current head on Omarchy Local stats are right. An independent count of The limits probe is not. On this signed-in Muse Code Power Usage account, I would treat "active subscription, no |
|
Follow-up on the limits probe, now with a fix running locally. The "Muse limits unavailable" card is not a transient missing snapshot on Muse Code Power Usage. Treat In tier_hint = str(payload.get("subs_tier_name") or "") if isinstance(payload, dict) else ""
if isinstance(payload, dict) and payload.get("is_subs_active") is True:
return {"ok": False, "silent": True, "tierLabel": tier_hint}In if probe.get("silent"):
if probe.get("tierLabel"):
result["tierLabel"] = probe["tierLabel"]
return resultThe snapshot test should then expect |
cristianuibar
left a comment
There was a problem hiding this comment.
Token collection on this head is right and should land. One limits behavior will show a permanent error card on a real Muse Code Power Usage login, and the test currently requires that card. The local fix and the numbers are in the comments above. Two line notes below are the code change.
| return {"ok": False, "payg": True} | ||
| tier_hint = str(payload.get("subs_tier_name") or "") if isinstance(payload, dict) else "" | ||
| return {"ok": False, "tierLabel": tier_hint, | ||
| "helpText": "Muse's usage endpoint returned no usage. Local Muse stats are still shown."} |
There was a problem hiding this comment.
This branch is what a Muse Code Power Usage account hits on every probe, not a snapshot that is about to appear. POST /muse-code/key returns is_subs_active: true and subs_tier_name, and the body has no subs_usage key at all.
Return silent here when is_subs_active is true, the same way pay-as-you-go returns early above. In collect_limits, honor silent by keeping tierLabel, leaving limits empty, and not setting usageStatusText. A response that is neither active nor pay-as-you-go can still use this help text.
The README section "Muse limits" should say an active plan with no subs_usage shows the tier and local tokens, not an error.
| fail "Muse collector keeps the tier without a usage snapshot" "$nosnap" | ||
| pass "Muse collector keeps the tier without a usage snapshot" | ||
|
|
||
| [[ $(jq -r '.usageStatusText' <<<"$nosnap") == "Muse limits unavailable" ]] || |
There was a problem hiding this comment.
This assertion locks in the bug. For is_subs_active: true and no subs_usage, expect usageStatusText and authHelpText to be empty, limits empty, and tierLabel still Muse Code Everyday Usage. Do not expect Muse limits unavailable.
I ran that behavior against Muse Code 1.3.0: tier Muse Code Power Usage, no status text, 11072 prompts / 253 sessions, matching an independent model_completed count. The red card in the panel went away as soon as the record was rewritten.
Taking a look. Thanks for reviewing this and the detailed pointers! |
Active plans that return no subs_usage (Muse Code Power Usage answers this way on every probe) are a steady state, not a missing snapshot: keep the tier, show local metering only, no error card. Unknown shapes without is_subs_active still warn.
|
Thank you! Brought in with your authorship in #14040, with kept limits marked stale after a failed check, OpenCode V2 sessions read, and Zen's Muse Spark left to the OpenCode record. |
Muse (Meta Muse Spark) support for the Agents bar panel: a new
musecollector following theclaude/codexrecord contract, with local metering plus subscription windows.What it adds
bin/omarchy-agent-usage-muse(777 lines): token, prompt, session, per-day and per-model stats from nativemuseCLI sessions ($XDG_DATA_HOME-aware,MUSE_DATA_DIRoverride) plus opencode sessions on themetaprovider ormuse-sparkmodels. Subagent trees roll up into the parent session; symlinked files, symlinked directories, oversized model names/negative counts fail closed; short scan cache with locking likecodex. Completions deduplicate by native record ID across session files and retained-frame children, and.msp-view*copies are excluded. Subscription windows come from the client's own key endpoint (MUSE_AUTH_PATH, else~/.config/muse/auth.json).manifest.jsonentry, Simple Icons Meta mark (+ light-surface twin),shell/plugins/agents/README.mdrow +### Muse limitssection,manual/17-ai.mdmention.test/shell.d/agent-usage-muse-scanner-test.sh: 17 scanner tests (totals, subagent rollup, per-model buckets, run_model/retained_frame/timestamp shapes, odd timestamp/token shapes, symlinks incl. directory escape, oversized/negative values, corrupt DB, cache reuse incl. --limits-only, XDG paths).test/shell.d/agent-usage-muse-limits-test.sh: 14 stub-based limits tests (subscriber percents/resets/tier, probe reuse, PAYG silence, no-snapshot tier, expired sign-in, malformed logins,MUSE_AUTH_PATH, token hygiene).test/shell.d/agent-usage-muse-dedup-test.sh: 3 dedup tests (unique completions across plain records/retained frames/copied sessions, view exclusion with missing/malformed IDs still counted, pre-dedup cache rescan). By @nissuor via Why not use the 1Password AUR? #2.subs_tier_namewhen subscribed, neutralAccountfor pay-as-you-go.Sign-in expiredon 401/403,Muse limits unavailablewith cached fallback on other failures, silent otherwise.Limits: subscription windows, PAYG-aware
Since this PR opened, Muse Code GA'd subscriptions (Aug 31) and the client's key endpoint returns
subs_usagesession + weekly percents — the same figures as the TUI's/usage. The collector probes it additively; local metering is unchanged and always runs:is_subs_active:true, nosubs_usageon some gateways): tier kept,Muse limits unavailable.is_subs_active:false): silent local metering only — not an error, not expired, no retry.Sign-in expired; transport failure →retryAdvised+ cached fallback; malformed responses → generic unavailable, no retry.Still no estimated meters from manual caps, and no per-key throttle headers: I built and live-tested an
x-ratelimit-*probe and removed it — those buckets read0%through real429s (200+ proxy requests verified), so without an authoritative probe the panel shows measured usage only. Token travels only in theAuthorizationheader; neither it nor the minted key is persisted.Verification
python3 -m py_compile+git diff --checkclean; repotest/cli,bin-style,agent-usage-update, andagents-panelsuites green.Account→ plan name, meters appear oncesubs_usageis present); old-vs-new parity checks return identical local stats across all fields; token absent from record and caches.