Skip to content

Show Muse Token Spend Without Hiding Weekly Usage - #128

Merged
mstallone merged 3 commits into
mainfrom
feat/muse-spend-tiles
Sep 5, 2026
Merged

Show Muse Token Spend Without Hiding Weekly Usage#128
mstallone merged 3 commits into
mainfrom
feat/muse-spend-tiles

Conversation

@mstallone

Copy link
Copy Markdown
Owner

TL;DR

Muse now shows local token history and estimated Spark API-rate spend from session logs, while Five-Hour Usage and Weekly Usage stay always visible.

What was happening

  • Muse only had subscription meters. There was no token tracking, usage trend, or priced spend, so Spark usage could not be valued at Meta's published rates.
  • Adding spend tiles the usual way would seed them into On Demand and risk hiding Weekly again for existing layouts.

What this changes

  • Reads model_completed events from Muse Code journals (~/.local/share/muse/sessions/, including nested subagent logs).
  • Prices Standard Spark at $1.25 / $0.15 cached / $4.25 output per million tokens, and Contributor SKUs at $0.10 / $0.002 / $0.20. Cache writes bill at the input rate. Reasoning is not added on top of output.
  • Usage Trend and Today / Yesterday / Last 30 Days start on demand. Five-Hour and Weekly stay above the fold and starred.
  • Spend still loads when mint cannot (Connect, expired session, logs-only, or 429 with no last-good meters). The mint backoff from Honor Muse Mint Error Envelopes and Back Off on 429 #126 is unchanged.
  • Session logs alone can auto-enable the provider.

Heads-up

  • Targets mstallone/runway, not upstream.
  • These dollars are estimated API-rate value, not billed subscription spend.
  • Contributor SKUs must not resolve to Standard rates; alias rules put contributor first.

Tests

  • swift test --filter Muse
  • swift test --filter 'ModelPricing|PricingBundledResource'

Subscription meters alone cannot show Spark cost. Read local Muse
session logs, price them at Meta's published rates, and keep Five-Hour
and Weekly always visible.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are a few concrete correctness/documentation issues in the changed code/docs (notably Muse auto-enablement footprint detection and an omission in privacy docs) that should be addressed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR extends the Muse provider to derive machine-local token history and estimated API-rate spend from Muse Code session journals, while keeping the subscription meters (Five-Hour Usage / Weekly Usage) always visible in the default layout.

Changes:

  • Add a new MuseLogUsageScanner and wire it into MuseProvider to populate Usage Trend + spend tiles from local session.jsonl logs (including subagent logs).
  • Add Muse Spark Standard/Contributor pricing + alias rules to pricing_supplement.json, plus test coverage validating resolution and rates.
  • Update default layout seeding and documentation so Muse spend/history stays below-the-fold and does not hide Weekly for existing layouts.
File summaries
File Description
Tests/RunwayTests/PricingBundledResourceTests.swift Adds assertions for Muse Spark pricing + contributor separation.
Tests/RunwayTests/MuseProviderTests.swift Adds coverage for log-backed spend/history behavior and stable descriptor/layout seeding.
Tests/RunwayTests/MuseLogUsageScannerTests.swift New tests for parsing, aggregation, pricing, dedup, and subagent discovery.
Sources/Runway/Stores/DefaultLayout.swift Seeds Muse trend + spend tiles as On Demand while keeping meters always visible/pinned.
Sources/Runway/Resources/pricing_supplement.json Adds Muse Spark rates and alias rules.
Sources/Runway/Providers/SpendTileMapper.swift Updates documentation comment to include Muse as a log-backed spend source.
Sources/Runway/Providers/Muse/MuseProvider.swift Integrates local log scanning + pricing into Muse refresh and snapshot assembly.
Sources/Runway/Providers/Muse/MuseLogUsageScanner.swift New scanner for Muse session journals producing LogUsageScan for shared spend/history UI.
Sources/Runway/Providers/JSONLScanCacheCoordination.swift Ensures Muse JSONL scan caches flush with the shared coordination point.
Sources/Runway/Providers/IncrementalJSONLScanner.swift Updates doc comment to include Muse as a consumer.
Sources/Runway/Providers/DailyUsageAccumulator.swift Updates doc comment to include Muse in shared accumulation flow.
Sources/Runway/Pricing/ModelRates.swift Updates doc comment to include Muse as a spend-imputation consumer.
Sources/Runway/Models/WidgetDescriptor+Factories.swift Updates doc comment to include Muse in the spend-tile descriptor set.
README.md Notes Muse now supports local daily spend in the provider list.
docs/settings.md Adds Muse to the list of spend-tracking providers for Total Spend.
docs/providers/muse.md Expands Muse provider docs for log-derived history/spend behavior and troubleshooting.
docs/privacy.md Updates local cache description to include Muse (but needs a small correction).
docs/pricing.md Documents Muse Spark pricing behavior and maintainer notes for supplement upkeep.
docs/icloud-sync.md Adds Muse to machine-local history sources merged via iCloud sync.
docs/dashboard.md Adds Muse to Total Spend + model breakdown + Usage Trend documentation and default layout notes.
docs/architecture.md Updates architecture docs to include Muse in shared JSONL scanning/caching.
AGENTS.md Updates contributor guidance to include Muse in the pricing pipeline description.
Review details
  • Files reviewed: 22/22 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Sources/Runway/Providers/Muse/MuseLogUsageScanner.swift Outdated
Comment thread Sources/Runway/Resources/pricing_supplement.json
Comment thread docs/privacy.md Outdated
An empty sessions directory is not usable history. Auto-enable only
when a session.jsonl exists, matching what the scanner can actually read.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new Muse log footprint probe and rate-limit detection include avoidable performance and fragility issues that should be addressed before merging.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

Sources/Runway/Providers/Muse/MuseProvider.swift:214

  • rateLimited is derived by comparing user-facing error strings (museErrorText(snapshot) == MuseUsageError...errorDescription). Using localized/formatting text for control flow is brittle (any wording tweak or localization would silently break the detection). Since rateLimitedUntil is already tracked, prefer deriving this from state (rateLimitedUntil and now).
  • Files reviewed: 22/22 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread Sources/Runway/Providers/Muse/MuseLogUsageScanner.swift
Stop the footprint walk at the first session.jsonl, and treat mint
cooldown from rateLimitedUntil instead of comparing localized 429 text.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It changes Muse’s provider runtime behavior, pricing resolution, default layout seeding, and adds a new log-scanning pipeline that should be validated by a human reviewer for edge cases and user-facing correctness.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

Tests/RunwayTests/MuseProviderTests.swift:649

  • museLogScanner(tokens:) creates a unique temp directory under FileManager.default.temporaryDirectory but never removes it. Other tests in this suite generally clean up temporary fixtures (e.g., via defer removeItem(at:)), and leaving these directories behind can accumulate across repeated local/CI runs.
  • Files reviewed: 22/22 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@mstallone

Copy link
Copy Markdown
Owner Author

Stopping the Copilot loop here.

Round 1: empty-directory auto-enable was real; privacy Grok mention was a one-word fix on a line this PR already owned. Same-day updated_at timestamp is not needed — this is the first supplement revision of 2026-09-05.

Round 2: early-exit footprint walk and rateLimitedUntil instead of error-string matching were real and landed.

Round 3 is a test temp-dir cleanup nit. It does not change Muse spend, prices, or keeping Five-Hour and Weekly always visible.

Local Bugbot is clean. CI is green.

@mstallone
mstallone merged commit 6c04f7e into main Sep 5, 2026
3 checks passed
@mstallone
mstallone deleted the feat/muse-spend-tiles branch September 5, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants