Skip to content

Add omp (Oh My Pi) usage collector to the agents panel - #13845

Open
Bekkenes wants to merge 10 commits into
omacom:quattrofrom
Bekkenes:feature/omp-agent-usage
Open

Bekkenes wants to merge 10 commits into
omacom:quattrofrom
Bekkenes:feature/omp-agent-usage

Conversation

@Bekkenes

@Bekkenes Bekkenes commented Sep 30, 2026 •

Copy link
Copy Markdown

Summary

Adds an omp (Oh My Pi) usage collector so the agents panel gains a tab for machines that code with omp, which today shows nothing because no collector covers it.

omp is provider-agnostic, so unlike the claude/codex collectors (which read Anthropic/OpenAI transcript formats) this one reads omp's own statistics and reports them directly.

Changes

  • bin/omarchy-agent-usage-omp — new collector. Runs omp stats --json and maps its output into the standard record contract:
    • all-time per-model tokens (input / output / cache read / cache write),
    • the 7-day token chart and today's prompts/tokens,
    • a session count read from the JSONL files under ~/.omp/agent/sessions/ (which omp stats walks but does not surface as a count).
  • DeepSeek prepaid balance — when omp runs on DeepSeek, the collector calls get-user-balance with omp's own stored key (omp token deepseek) and reports the live remaining balance. DeepSeek exposes only remaining credits (granted / topped-up), never the original funding amount, so the record carries remaining alone (funded/spent stay 0) and the panel shows a plain balance readout rather than a spend gauge. tierLabel is set to Prepaid only in that case.
  • shell/plugins/agents/manifest.json — registers omp in the widget's default providers.
  • shell/plugins/agents/README.md — adds the collector row and an omp section.

Notes

  • No rate-limit meters: DeepSeek exposes no usage-limits endpoint and omp usage returns no reports for it, so limits stays empty and the tab shows the balance readout instead.
  • todayTokensByModel is omitted: omp stats reports per-day totals and all-time per-model tokens, but not per-day-per-model tokens.

Testing

  • ./test/cli passes (112 ok, exit 0), including the command-metadata checks for the new executable bin.
  • test/shell.d/agent-usage-omp-scanner-test.sh (new) covers the omp stats --json mapping, session counting, run_stats failure/timeout paths, and the DeepSeek balance path.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the existing non-blocking refresh cost still present.

Findings

  1. P2 Limits refresh scans all stats ▶

Summary

Adds Oh My Pi usage to the agents panel.

  • The Agents panel now shows Oh My Pi activity and DeepSeek credits.

No new actionable issues were found.

Reviews (10) · Last reviewed commit: "Merge remote-tracking branch 'upstream/q..." · Reviewed by Greptile

Comment thread bin/omarchy-agent-usage-omp Resolved
Comment thread bin/omarchy-agent-usage-omp Resolved
Comment thread bin/omarchy-agent-usage-omp Resolved
Comment on lines +294 to +304
parser.add_argument("--force", action="store_true")
parser.add_argument("--limits-only", action="store_true")
args = parser.parse_args()

binary = find_omp()
if not binary:
record = base_record(usageStatusText="omp unavailable", authHelpText="omp not found in PATH")
print(json.dumps(record, separators=(",", ":"), sort_keys=True))
return 0

data = run_stats(binary)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Limits refresh scans all stats The collector accepts --limits-only but still runs the full stats scan and balance request. Opening the panel requests a limits-only refresh, so it repeats potentially slow work even though omp has no limits to update.

Comment thread bin/omarchy-agent-usage-omp Resolved
@Bekkenes

Copy link
Copy Markdown
Author

Addressed all five — fix pushed.

Balance gauge stays full + Exhausted balance disappears (findings 1–2, one root cause). Confirmed. DeepSeek's total_balance, granted_balance, and topped_up_balance are all remaining credits, and granted + topped-up sums to total — the endpoint exposes no original-funding figure, so funded = topped_up + granted always equaled remaining, pinning spent to 0 and the gauge to full. The collector now reports remaining only (funded/spent = 0); the panel already renders a plain "$X remaining" readout when funded is 0. Removed the total <= 0 guard so an exhausted $0.00 balance still surfaces instead of vanishing.

Stats timeout aborts collection. Confirmed — subprocess.TimeoutExpired is a SubprocessError, not OSError, so it escaped run_stats and main. run_stats now catches (TimeoutExpired, OSError) and returns None, degrading to "no stats" rather than crashing and leaving the stale record.

Limits refresh scans all stats. Ack — --limits-only is a deliberate no-op, the same documented choice as the fireworks collector: omp has no limits to update and no stats cache to reuse. Left as-is.

Collector mapping lacks tests. Added test/shell.d/agent-usage-omp-scanner-test.sh: the omp stats --json mapping, session counting, run_stats failure/timeout paths, and the DeepSeek balance path (including zero-balance and no-key cases).

./test/cli 112 ok / 0 failures; new scanner test 12/12.

DeepSeek's get-user-balance reports only remaining credits — granted and
topped-up sum to the current total — and never the original funding amount,
so treating granted + topped-up as "funded" pinned spent to 0 and left the
panel's balance gauge permanently full. Report remaining alone with
funded/spent at 0, and keep an exhausted $0.00 balance visible instead of
dropping it.

Also catch the stats subprocess timeout so a slow `omp stats` degrades to
"no stats" rather than raising through the collector and leaving stale data.

Add test/shell.d/agent-usage-omp-scanner-test.sh covering the stats mapping,
session counting, run_stats failure/timeout paths, and the DeepSeek balance
path.
Comment thread bin/omarchy-agent-usage-omp Resolved
@sanjyay

sanjyay commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Independent community review

This is an independent community review unaffiliated with the Omarchy team, intended to help prepare PRs for maintainer review.

Nice work on the omp usage collector and addressing the initial feedback.

The implementation cleanly integrates with the agents panel:

  • omp stats --json metrics (requests, tokens, 7-day series, model buckets) map cleanly into the standard usage schema.
  • Session counting directly walks ~/.omp/agent/sessions/ JSONL files as documented.
  • DeepSeek balance parsing reports remaining with funded: 0.0, spent: 0.0, correctly rendering a balance readout rather than an artificially fixed spend meter, and maintains visibility for exhausted $0.00 balances.
  • Error handling properly catches (subprocess.TimeoutExpired, OSError) and degrades to the standard fallback record if the binary times out, fails, or is missing.
  • Manifest registration and README documentation are complete and consistent.
  • Test coverage in test/shell.d/agent-usage-omp-scanner-test.sh thoroughly exercises mapping, timeout/failure paths, zero balances, and session counting.

All test suites (test/shell.d/agent-usage-omp-scanner-test.sh, ./test/cli, and all agent-usage* tests) pass cleanly in the test environment.

If you'd prefer not to receive these independent reviews on your PRs, reply to this comment, and I won't review your future PRs.

The omp collector had no assets/<id>.svg, so the panel hero fell back to the
generic bar glyph next to Claude's and Codex's real marks. Ship the Oh My Pi
logo (the Pi symbol with an orange plugin connector, from oh-my-pi's
assets/icon.svg) as a white mark for dark surfaces plus a dark twin for light
surfaces, following the codex.svg / codex-light.svg convention.

@chessing234 chessing234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please fix the usage aggregation and time-window handling below; the hourly and multi-provider fixtures reproduce incorrect totals.

Comment thread bin/omarchy-agent-usage-omp Outdated
bucket["outputTokens"] = number(entry.get("totalOutputTokens"))
bucket["cacheReadInputTokens"] = number(entry.get("totalCacheReadTokens"))
bucket["cacheCreationInputTokens"] = number(entry.get("totalCacheWriteTokens"))
model_usage[model] = bucket

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please accumulate these buckets instead of overwriting them: omp groups byModel by (model, provider) (upstream), so using the same model through two providers loses the first provider's usage. calling this function with 100 and 40 input tokens under the same model returns 40 instead of 140; please add that case to the fixture.

Comment thread bin/omarchy-agent-usage-omp Outdated

return {
"todayPrompts": number(
next(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please sum all of today's request buckets here: current omp emits hourly buckets for its default 24-hour window (upstream), while next() keeps only the first hour. a fixture with 3 requests at midnight and 5 at 01:00 returns todayPrompts: 3 instead of 8.



def run_stats(binary: str) -> dict | None:
"""Run `omp stats --json` and return the parsed object, or None on failure."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please obtain the history needed for the seven-day and all-time fields before populating them: omp stats --json calls getDashboardStats() without a range, which in v18.4.4 filters the overall, model, and time-series data to the last 24 hours. the current mapping consequently fills older days with zero, reports a rolling day as all-time usage, and hides the tab after a day without requests even when older sessions exist.

- Sum per-model buckets across (model, provider) instead of overwriting
- Sum all of today's hourly buckets for todayPrompts
- Read seven-day and all-time fields from ~/.omp/stats.db, since
  `omp stats --json` reports only the last 24 hours
@Bekkenes

Copy link
Copy Markdown
Author

Addressed all three — fix pushed (ae06276b).

Model buckets accumulate across providers. summarize now sums into the existing per-model bucket instead of overwriting, so the same model run through two providers adds up. Fixture added: deepseek-chat via deepseek (100 input) + via fireworks (40 input) → 140.

Today's request buckets are summed. todayPrompts now sums every hourly bucket matching today instead of keeping only the first. Fixture added: 3 at midnight + 5 at 01:00 → 8.

Seven-day and all-time fields read full history. omp stats --json calls getDashboardStats() without a range, so it caps at 24h. The collector now also reads ~/.omp/stats.db (the messages table, which omp keeps in full) for the seven-day series, all-time totals, per-model buckets, and active days; the 24h payload still covers the today row and remains the fallback when the DB is missing/unreadable. This also stops the tab from hiding after a quiet day when older sessions exist.

test/shell.d/agent-usage-omp-scanner-test.sh 20/20; ./test/cli and the other agent-usage*/agents-panel tests pass.

Comment thread bin/omarchy-agent-usage-omp Resolved
Comment thread bin/omarchy-agent-usage-omp Resolved
- Fetch DeepSeek balance regardless of recent usage so a quiet account still shows its credits
- Stream the stats DB read instead of materializing every message
- Fall back to the stats DB when omp stats fails instead of erasing the last record
Comment thread bin/omarchy-agent-usage-omp Resolved
…login

When omp stats times out or fails, the collector kept the last good
history but set authHelpText to the account prompt, so the panel told
users to run 'omp login' for a transient stats failure. Point the help
text at the actual problem instead and cover it in the scanner test.
@jandrusk

jandrusk commented Oct 1, 2026

Copy link
Copy Markdown

Re-review pass after ae06276 / 8670123 / d83bc94: multi-provider model buckets, summing today's hourly request buckets, stats.db history for 7-day/all-time, streaming the DB cursor, quiet-account DeepSeek balance, and the stats-failure fallback that leaves the previous record alone all look addressed. The CHANGES_REQUESTED review can be dismissed once a maintainer confirms those fixtures.

One responsible-disclosure-style note (not a blocker if this matches other collectors): omp token deepseek --raw puts the key on stdout of a child process for the HTTPS call. That's the same pattern as reading a stored token, but worth keeping stderr suppressed and never logging the key — which you already do. LGTM on the collector shape pending the formal re-review.

A fresh omp install has no ~/.omp/agent/sessions/ directory: sessions live
in the session_rollup table of ~/.omp/stats.db, which is also where the
collector already reads its history. Counting loose JSONL files therefore
reported 0 sessions on a real machine.

Read today's and total sessions from session_rollup, keeping the JSONL glob
as a fallback for older layouts, and cover both paths in the scanner test.
@Bekkenes

Bekkenes commented Oct 5, 2026

Copy link
Copy Markdown
Author

Thanks for the review. All three items are addressed, plus the Greptile notes:

  • byModel buckets now accumulate across (model, provider) pairs instead of overwriting, with a fixture covering the same model on two providers.
  • Today's requests sum every hourly bucket in the 24-hour window, with a fixture covering two hours.
  • Seven-day and all-time fields are read from ~/.omp/stats.db before they are populated, since omp stats --json filters to the last 24 hours.

Testing against a real omp 18.6.1 install surfaced one more correction: session counts were read from ~/.omp/agent/sessions/*.jsonl, but a fresh omp install has no such directory — sessions live in the session_rollup table of ~/.omp/stats.db, the same database the collector already reads for history. Counting loose JSONL files reported 0 sessions on a real machine, so the collector now counts from session_rollup and keeps the JSONL glob as a fallback for older layouts (commit ee22dec8).

On the remaining Greptile note (--limits-only still scanning stats): that one is intentional. omarchy-agent-usage-update writes each collector's full output straight to ~/.local/state/omarchy/agents/usage/<agent>.json with no merge step, so a limits-only run must still emit a complete record or it would blank the panel data. omp has no rate-limit endpoint to refresh, so there is no cheaper path — the same reasoning the existing fireworks collector documents. Happy to change it if you would prefer otherwise.

./test/cli passes and test/shell.d/agent-usage-omp-scanner-test.sh covers the mapping, session counting, history, and DeepSeek balance paths.

@Bekkenes

Bekkenes commented Oct 5, 2026

Copy link
Copy Markdown
Author

@chessing234 all three requested changes are addressed (plus the Greptile notes), and ee22dec8 adds a session-count fix found while testing against a real omp install. Could you take another look when you have a moment?

Comment thread bin/omarchy-agent-usage-omp Resolved
session_counts() read only started_at from session_rollup, so a session
that began before midnight but ran into today was left out of
todaySessions. The JSONL fallback (mtime) and the other collectors count
any session with activity today, so the panel undercounted resumed and
long-running sessions.

Count a session toward today when max(started_at, ended_at) falls on
today, and extend the fixture with a session started yesterday 23:00 that
ended today 01:00.
@Bekkenes

Bekkenes commented Oct 5, 2026

Copy link
Copy Markdown
Author

@chessing234 the new Greptile note (today's sessions undercounted for a session resumed across midnight) is fixed in 247589bf — sessions are now counted by last activity (max(started_at, ended_at)), with a fixture covering the cross-midnight case. ./test/cli 112/112 and the omp scanner test 25/25. Could you take another look when you have a moment?

quattro gained a Grok provider in shell/plugins/agents; its manifest.json
description and providers block conflicted with this branch's omp entry.
Resolved by keeping both: the description names all five agents, and the
providers block enables claude, codex, grok, fireworks, and omp.
…t-usage

# Conflicts:
#	shell/plugins/agents/README.md
#	shell/plugins/agents/manifest.json
@Bekkenes

Copy link
Copy Markdown
Author

Merged upstream/quattro into the branch (247 commits) and resolved the two conflicts — manifest.json and README.md now carry both kimi and omp. The PR is back to MERGEABLE.

The three changes you requested on Sep 30 are addressed:

  1. Model buckets accumulate across providers — ae06276b
  2. Today's request buckets are summed — ae06276b
  3. Seven-day / all-time read full history from stats.db — ae06276b

Plus the Greptile follow-ups since: quiet-account balance (8670123), stats-failure fallback (d83bc94), session counting from session_rollup (ee22dec8), and cross-midnight session counts (247589bf).

Could you take another look and dismiss the changes-requested review if it's settled? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants