Skip to content

feat: ollama cloud usage meter#67

Open
Rtas-17 wants to merge 3 commits into
CodeZeno:mainfrom
Rtas-17:feat/ollama-cloud-usage-meter
Open

feat: ollama cloud usage meter#67
Rtas-17 wants to merge 3 commits into
CodeZeno:mainfrom
Rtas-17:feat/ollama-cloud-usage-meter

Conversation

@Rtas-17

@Rtas-17 Rtas-17 commented Jul 24, 2026

Copy link
Copy Markdown

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/settings but 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 to signin.ollama.com. So this PR includes:

  1. A standalone ollama-login-helper.exe process 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.
  2. A new tray menu item: right-click → Models → "Log in to Ollama…" — feature-gated behind --features ollama-login-webview (off by default because wry/tao add ~6 MB to the release binary).
  3. Environment-variable fallback: setting OLLAMA_CLOUD_SESSION in env or ~/.claude/settings.json#env.OLLAMA_CLOUD_SESSION also works for headless setups.

What this PR adds

  • src/models.rs: new optional ollama field on AppUsageData
  • src/poller.rs: new poll_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, returns AuthExpired when logged out, returns ParseFailed when 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 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 cookies, writes them to disk, then exits.
  • Cargo.toml: registers the ollama-login-webview feature, optional wry/tao deps, and the second [[bin]] target for ollama-login-helper
  • src/localization/*: new ollama_model and ollama_window_title strings across all 11 language files

Test plan

  • cargo test passes (12/12 verified locally, including the new ollama parser tests)
  • cargo build --release clean, no warnings
  • cargo build --release --features ollama-login-webview clean
  • Live: tray shows Ollama bar; toggling Models → Ollama shows/hides it and persists across restarts
  • Live: with a captured cookie, the Ollama bar shows the real session/weekly percentages

I 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

  • Ollama returns an HTML page, not JSON, so I matched the actual aria-label structure with explicit regexes. I added a separate OllamaParseError enum so changes to ollama.com layout surface as PollError::RequestFailed rather than panicking.
  • The webview login is a separate process because wry's EventLoop::run() on Windows must own the Win32 message pump — running it inside the tray's DispatchMessageW handler starves the event loop and WebView2 doesn't paint.
  • The tray process never embeds wry/tao. The helper exe is the only thing that depends on it. Default builds add zero new dependencies.
  • The Ollama parser deliberately fails (rather than showing fake zeros) when there's no cookie. The tray displays ! in the bar to make the missing-auth state obvious.

Why this is upstream-friendly

  • No new runtime dependencies in the default build (wry/tao are feature-gated).
  • Parser unit tests cover the happy path, zero-usage, and structure-change cases.
  • Cookie capture is non-invasive — the tray just writes a plain text file the poller reads back.

What's not in this PR

Risks

  • Ollama.com layout change would break parsing. Mitigated by explicit OllamaParseError::AuthExpired and ParseFailed returning rather than panicking, plus the test fixtures.
  • The cookie is captured in a regular WebView2 process rather than the user's Chrome profile, so it's a separate session. This is fine for Ollama Cloud auth because Ollama doesn't bind to the browser identity like Anthropic does — only the session cookie matters.

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.

Rtas-17 added 2 commits July 24, 2026 19:00
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.
Copilot AI review requested due to automatic review settings July 24, 2026 18:44

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.

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-helper binary 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.

Comment thread src/window.rs
Comment thread src/window.rs
Comment thread src/poller.rs Outdated
Comment thread src/ollama_login_helper.rs
Comment thread src/ollama_login_helper.rs
@Rtas-17 Rtas-17 mentioned this pull request Jul 25, 2026
5 tasks
- 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>
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