Repository navigation
Conversation
Muse Code ships no usage endpoint, but the key mint the CLI itself uses answers one: POST /muse-code/key with the OAuth login returns the same key back (idempotent, so a running Muse is never rotated out) plus the live window and weekly plan percentages with reset stamps. The collector also reads sessions and prompts from Muse's session index and sums per-call token events from its session logs, cached by mtime and size. Muse reports cached tokens inside input_tokens, so buckets decompose the split and every token counts once. Enables the muse provider by default, ships its mark, and tests the record, the cache, and the sign-in hint. 💘 Generated with Crush Assisted-by: Crush:glm-5.3
|
| for offset in range(6, -1, -1): | ||
| date = (current - dt.timedelta(days=offset)).strftime("%Y-%m-%d") | ||
| recent.append({"date": date, "messageCount": bucket_total(days.get(date) or zero_bucket())}) | ||
| return {"modelUsage": models, "recentDays": recent} |
There was a problem hiding this comment.
token_stats() never returns todayTotalTokens. The panel reads that field for its combined “tokens today” count; it does not derive it from recentDays. Muse therefore contributes zero even when today's log contains tokens. Return today's bucket total as todayTotalTokens and assert it in the test.
Knowledge Base Used: Agent accounts and provider usage
| count = max(0, int(prompt_count or 0)) | ||
| day = days.setdefault(date, [0, 0]) | ||
| day[0] += 1 | ||
| day[1] += count |
There was a problem hiding this comment.
index_stats() assigns each session's entire prompt_count to its creation date. When a user resumes yesterday's session today, those new prompts still count toward yesterday, so todayPrompts stays zero. Count today's prompts from dated prompt events, or omit the daily prompt figure when the index cannot supply it.
| current = dict(files) | ||
| root = data_dir() / "sessions" | ||
| if not reuse_only and root.is_dir(): |
There was a problem hiding this comment.
--limits-only reuses the cache without checking its age and skips scanning even when no valid cache exists. The panel uses this mode on opening and for every background refresh while another provider's accounts are near their limit. Muse token stats can stay empty or stop updating for that entire period. Fall back to scanning when the cache is missing or too old.
| except (urllib.error.URLError, json.JSONDecodeError, OSError, ValueError): | ||
| return { | ||
| "limits": [], | ||
| "tier": "", | ||
| "status": "Limits temporarily unavailable", | ||
| "authHelp": "Meta's usage endpoint could not be read; retrying shortly.", | ||
| "retry": True, |
There was a problem hiding this comment.
collect_limits() treats HTTP 401 and 403 responses like a temporary network failure. An expired or rejected login tells the user to wait for retries instead of running muse login, and keeps requesting another probe every 30 seconds. Handle rejected credentials separately, provide the login instruction, and leave automatic retries for temporary failures.
|
Thanks for the Muse collector! Two things before this goes further:
Greptile's P1s ( |
What
Muse Code joins the Agents panel: live 5-hour and weekly plan meters, tokens by day and by model, and session/prompt counts.
How
POST https://api.meta.ai/muse-code/keywith the OAuth login from~/.config/muse/auth.jsonreturns the same key back (idempotent, so a running Muse is never rotated out) plussubs_usage: window and weeklyused_percentwith epoch reset stamps and the tier name.session-index.db); token totals by day and model are summed from the per-call usage events in its session logs. Muse reports a call's cached tokens insideinput_tokens, so the buckets decompose the split (non-cached input, output, cache read, cache write) and each token is counted exactly once.(mtime, size)in~/.cache/omarchy/agents-muse-cache.json;--forcere-parses,--limits-onlyreuses the cache.museprovider by default in the plugin manifest and ships its mark (muse.svg+ light twin).Testing
test/shell.d/agent-usage-muse-test.shcovers the full record from fixtures (mint response monkeypatched, a session log with cache-heavy calls, a session index), the cache hit/force/limits-only paths, and the unsigned state../test/clipasses (125 ok); the five./test/shellfailures on this machine are pre-existing onmain(graphical, session-dependent) and unchanged by this PR.💘 Generated with Crush