feat: ollama cloud usage meter#67
Open
Rtas-17 wants to merge 3 commits into
Open
Conversation
Working tree before branch split. Will be reorganized into feat/ollama-cloud-usage-meter, feat/minimax-usage-meter, and feat/fable-5-usage-meter as separate commits.
Adds an Ollama Cloud (ollama.com) usage meter alongside Claude Code, Codex, and Antigravity. The Ollama Cloud usage page is HTML, not an API, so this commits a browser-style session cookie capture path: - src/models.rs: new optional 'ollama' field on AppUsageData - src/poller.rs: new fetch_ollama_usage() + parse_ollama_usage() that scrape the aria-labelled percentages from ollama.com/settings using a captured session cookie. Includes parser tests. - src/window.rs: new bar in the widget, models menu entry, localization, draw code. All gated behind the same toggle pattern as the other providers. - src/main.rs: registers the new modules - src/ollama_login.rs: tray-side helper that spawns the webview login process - src/ollama_login_helper.rs: standalone WebView2 process (only built with --features ollama-login-webview) that opens an embedded Edge window, captures the cookie after WorkOS auth, and writes it to disk. - Cargo.toml: registers the ollama-login-webview feature, wry/tao optional deps, and the second [[bin]] target for ollama-login-helper - src/localization/*: new ollama_model and ollama_window_title strings How users get a cookie: right-click the tray -> Models -> 'Log in to Ollama...' (or set OLLAMA_CLOUD_SESSION in env). Without a cookie the bar shows '!' until the user authenticates. Verified locally: cookie capture works against ollama.com/settings, returns session=100% and weekly=44.2% for the test account. 12/12 tests pass, builds clean for both --features ollama-login-webview and the default feature set.
There was a problem hiding this comment.
Pull request overview
Adds an Ollama Cloud usage meter to the existing multi-provider usage monitor, including polling/scraping Ollama’s authenticated settings page and optional WebView2-based login helper tooling.
Changes:
- Extend the usage data model and poller to optionally fetch/parse Ollama session + weekly usage from
https://ollama.com/settings. - Update the widget/tray UI to render and toggle an Ollama meter, including localized model/window strings.
- Add a feature-gated
ollama-login-helperbinary and tray integration to capture an authenticated cookie via WebView2.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/window.rs | Adds Ollama state, UI rendering, tray/menu toggles, and polling integration. |
| src/poller.rs | Adds Ollama polling/scraping, parsing helpers, and unit tests; updates polling aggregation. |
| src/ollama_login.rs | Adds tray-side helper spawner for the feature-gated login flow. |
| src/ollama_login_helper.rs | Adds the standalone WebView2 login helper that captures cookies to disk. |
| src/models.rs | Extends AppUsageData with an optional ollama usage section. |
| src/main.rs | Registers the optional ollama_login module behind the feature gate. |
| src/localization/* | Adds ollama_model and ollama_window_title strings across languages. |
| src/localization/mod.rs | Extends the Strings struct to include Ollama strings. |
| Cargo.toml | Adds the ollama-login-webview feature, optional deps, and the helper [[bin]] target. |
| Cargo.lock | Updates lockfile for new optional dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Give Ollama its own TrayIconKind so it no longer shares Antigravity's tray slot/styling when both are enabled. - Use Ollama-specific auth balloon copy when only Ollama is enabled. - Fix GNOME-shell typo in the poller comment. - Set windows_subsystem = "windows" on ollama-login-helper so tray login does not spawn an extra console window. - Document why the session cookie file stays plaintext (same trust boundary as OLLAMA_CLOUD_SESSION / settings.json overrides). Co-authored-by: Cursor <cursoragent@cursor.com>
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
Adds an Ollama Cloud (ollama.com) usage meter alongside the existing Claude Code, Codex, and Antigravity meters. Ollama exposes a quota page at
https://ollama.com/settingsbut it is HTML, not an API — the only public Ollama Cloud API key only identifies the plan tier, not consumption — so this PR scrapes the aria-labelled percentages from the authenticated settings page using a captured browser session cookie.How the user authenticates
Ollama Cloud auth is WorkOS-hosted; a raw
Cookie:header from a non-Chrome process fails the session-binding check and returns 303 tosignin.ollama.com. So this PR includes:ollama-login-helper.exeprocess that opens an embedded WebView2 window (via wry+tao), lets the user complete WorkOS auth, and writes the resulting cookie to%LOCALAPPDATA%\ClaudeCodeUsageMonitor\ollama_session_cookie.txt.--features ollama-login-webview(off by default because wry/tao add ~6 MB to the release binary).OLLAMA_CLOUD_SESSIONin env or~/.claude/settings.json#env.OLLAMA_CLOUD_SESSIONalso works for headless setups.What this PR adds
src/models.rs: new optionalollamafield onAppUsageDatasrc/poller.rs: newpoll_ollama()+read_ollama_session_cookie()+fetch_ollama_usage()+parse_ollama_usage()that scrape aria-labelled percentages from ollama.com/settings. Parser unit tests included (parses the real page structure, returnsAuthExpiredwhen logged out, returnsParseFailedwhen structure changes, etc.).src/window.rs: new bar in the widget, Models → Ollama toggle entry, localization entries, draw code. All gated behind the same toggle pattern as the other providers.src/main.rs: registers the new modulessrc/ollama_login.rs: tray-side helper that spawns the webview login processsrc/ollama_login_helper.rs: standalone WebView2 process (only built with--features ollama-login-webview) that opens an embedded Edge window, captures cookies, writes them to disk, then exits.Cargo.toml: registers theollama-login-webviewfeature, optional wry/tao deps, and the second[[bin]]target forollama-login-helpersrc/localization/*: newollama_modelandollama_window_titlestrings across all 11 language filesTest plan
cargo testpasses (12/12 verified locally, including the new ollama parser tests)cargo build --releaseclean, no warningscargo build --release --features ollama-login-webviewcleanI verified all of these on Windows 11 locally with the dev account — cookie capture works against ollama.com/settings, returns session=100% and weekly=44.2%.
Design notes
OllamaParseErrorenum so changes to ollama.com layout surface asPollError::RequestFailedrather than panicking.EventLoop::run()on Windows must own the Win32 message pump — running it inside the tray'sDispatchMessageWhandler starves the event loop and WebView2 doesn't paint.!in the bar to make the missing-auth state obvious.Why this is upstream-friendly
What's not in this PR
~/.hermes/auth.jsonintegration — local-fork feature, depends on Hermes internals, not proposed for upstream.Risks
OllamaParseError::AuthExpiredandParseFailedreturning rather than panicking, plus the test fixtures.Let me know if you'd like the PR split or merged differently — happy to split out the webview login helper into a follow-up PR if you'd rather review the parsing change alone first.