Repository navigation
feat(core): report Command Code quota to Oh My Pi usage surfaces - #120
Conversation
The registered provider config carried models, oauth and streamSimple but no `usage` field, so Oh My Pi had no usage provider for this provider: its accounts were culled from the usage surfaces and the quota the provider already fetches stayed unreachable there. Register an OMP `UsageProvider` built from the existing quota layer. `fetchUsage` calls `fetchCommandCodeQuota` with the host's fetch and the credential OMP hands over — an already-resolved API key or an OAuth bearer, both through the placeholder-aware helper `/commandcode-quota` uses — and maps the snapshot onto OMP's report: the 5-hour and weekly usage windows, credits remaining and used against the billing-period pool, and the plan in metadata. The used/remaining fractions are published explicitly because OMP's session and ACP text renderer reads them without resolving `used`/`limit`. Sections the API does not report stay out of the limits and are listed in the report's notes instead, so an unreachable endpoint is never displayed as zero usage; a failed fetch returns no report at all. pi has no `usage` field in `ProviderConfig` and ignores it.
pierreraby
left a comment
There was a problem hiding this comment.
Verified locally from this branch (dba622e): npm run typecheck clean, test:usage 10/10, test:quota (23) and test:quota-command (3) pass, format:check clean. Also ran the host tests against the real binaries with a mock API: test-pi-local.mjs PASS on pi 0.87.1, test-omp-compat.mjs PASS on omp 17.2.7 (CI covers 18.x). Trial merge into current main is clean, and npm pack --dry-run confirms src/usage.ts ships in the tarball (files covers src/).
Spot-checked the mapping against the sources: the resetAt seconds→ms round-trip is consistent (src/quota.ts:57 normalizes to seconds, src/usage.ts:165 converts back with * 1000); credentials go through the same pickCommandCodeApiKey helper as /commandcode-quota (src/usage.ts:243, src/quota-command.ts:44); null on failure and no zero-filled limits hold (src/usage.ts:247,257). On the installed pi 0.87.1, ProviderConfig (dist/core/extensions/types.d.ts:1161) has no usage field and the runner forwards the config object unvalidated, so the extra field is ignored as the PR says.
Three non-blocking nits:
src/usage.ts:48— the OMP types are mirrored structurally, so a future OMP schema change would break silently with only the mirrored tests catching it. Worth a shape test or a pinned host-version reference at some point, not a merge blocker.src/usage.ts:252—context?.fetchwhileUsageFetchContext(src/usage.ts:94-96) declaresfetchrequired. Either makes the field optional or requires the context.tests/test-usage.ts— hermetic and thorough through the real quota fetch; a raw-secondsresetAtfixture (<1e12) would pin thenormalizeResetAtbranch through this path too.
LGTM — happy to merge once the branch is updated and CI is green again.
|
@aarisr — quick follow-up on the scope note: I verified on OMP 18.3.4 that If you haven't filed it on |
|
Thanks for checking this on 18.3.4. Yes, please go ahead and open the
upstream Oh My Pi issue with that repro and link it back here. That
keeps the provider-side change and the remaining CLI gap clearly
separated.
…On Sat, 26 Sep 2026 23:38:45 -0700, Pierre Raby ***@***.***> wrote:
pierreraby left a comment [(patlux/pi-commandcode-provider#120)](#120 (comment))
***@***.***(https://github.com/aarisr) — quick follow-up on the scope note: I verified on OMP 18.3.4 that omp usage still doesn't consult extension usage providers (empty reports, account listed under accountsWithoutUsage), while the session /usage surfaces do pick it up. So the provider side of [#120](#120) is doing its job; the CLI gap is upstream.
If you haven't filed it on can1357/oh-my-pi yet, I'm happy to open the issue with the 18.3.4 repro — just say the word. A link here would help track it either way.
—
Reply to this email directly, [view it on GitHub](#120?email_source=notifications&email_token=BTTXABMS4RRKDPJNJHMTNFT5RCYXLA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBVGM2DKNRSGQYKM4TFMFZW63VQOJSXM2LFO5PXEZLROVSXG5DFMSSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-5853456240), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/BTTXABMYZ26SM3GCWPRLJ3D5RCYXLAVCNFSNUABGKJSXA33TNF2G64TZHMYTEMRZG44DMMRYG45US43TOVSTWNJVHE3DKMJTGEZTFILWAI).
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for [iOS](https://github.com/notifications/mobile/ios/BTTXABNIJBE73CYEXGT2WUT5RCYXLA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBVGM2DKNRSGQYKM4TFMFZW63VQOJSXM2LFO5PXEZLROVSXG5DFMSSWK5TFNZ2KUZTPN52GK4S7NFXXG) and [Android](https://github.com/notifications/mobile/android/BTTXABPA5OQT2Y7DP52VWW35RCYXLA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOBVGM2DKNRSGQYKM4TFMFZW63VQOJSXM2LFO5PXEZLROVSXG5DFMSSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA). Download it today!
You are receiving this because your review was requested.
|
|
Upstream issue opened as requested: can1357/oh-my-pi#13579 — with a minimal network-free repro extension (gist linked in the issue) confirming never consults extension usage providers on 18.3.4, whether loaded via |
Problem
createProviderConfigregisteredname,baseUrl,apiKey,api,streamSimple,headers,oauthandmodels— and nousagefield. Oh My Pi resolves usage providers from that field, so it had none forcommandcode:usageProviderFor("commandcode")stayed undefined, the stored credentials were treated as "a provider with no usage concept", and the quota this provider already fetches for/commandcode-quotawas unreachable from OMP's usage surfaces.With OMP 18.2.6 on the same account,
omp usage --provider commandcodewas the only way to see the credentials at all, and none of them reported anything:Change
pi.registerProvider("commandcode", …)now carriesusage: UsageProvider(src/usage.ts), whosefetchUsagereusesfetchCommandCodeQuotafromsrc/quota.ts— the same four alpha endpoints and the same credential resolution/commandcode-quotauses — instead of adding a second HTTP path.UsageReportcredits.windowLimits.fiveHour5h/ "5 Hour", window5h(5 h)credits.windowLimits.weekly7d/ "Weekly", window7d(7 d)credits.remainingCredits+summary.totalCostcredits/ "Credits", unitusd,used= billing-period spend,limit= remaining + spend,remaining= remainingsubscription.planId/statusmetadata.planType/metadata.planStatusaccount.loginmetadata.accountId, limits'scope.accountIdRules the mapping follows:
quota.unavailablebecomes the report'snotes, and those sections produce no limits: withbilling/creditsdown there is no window row and no credit row; withusage/summarydown the credit row carriesremainingand nolimit/used, because the pool isremaining + spendand the spend is unknown. Nothing is zero-filled, which is what the provider README requires.null.used/limitand clamped like the built-in providers do, because OMP's session and ACP/usagetext renderer readsamount.usedFractionwithout resolving the pair. Without them a window renders as0.00 usedwith an empty bar. They are set only where both inputs are known.metadata.orgIdis deliberately unset: OMP reads it as an org gate and would list every org-less stored credential as an account without usage data.pi has no
usagefield inProviderConfigand ignores the extra key, so the config type is widened locally (CommandCodeProviderConfig) instead of shimming the host.Evidence
npm run test:usage— 10 pass. The tests drive the realfetchCommandCodeQuotawith a mockedfetchImpl, so HTTP payload → credential → report is covered together:The unavailable-endpoint case is the one that fails without the mapping honouring
quota.unavailable: it would emit acreditsrow of zeros ($0.00 / $0.00 · 0.0% used), which is indistinguishable downstream from a real measurement.End to end, live API, with this checkout installed as the OMP plugin:
Session
/usagedashboard over a real account (omp18.2.6) — the Command Code column is new:The dashboard grid percentage is the free fraction —
freePct = Math.max(0, Math.round((1 - window.fraction) * 100))(@oh-my-pi/pi-tuisrc/overlays/usage-dashboard.ts:424) — so100%on the windows means untouched (0.00 of 3.00used), not exhausted. The detail view says it in words:The host recorded the same fetch itself: 9 rows in OMP's
usage_historyforprovider = 'commandcode', a5h/7d/creditstriple per credential (two OAuth, one API key), withcredits.used_fraction = 0.6019436072— the live$6.02 / $10.00:ACP
/usagetext (omp acp) with the same plugin — one of these runs also caught a transient upstream failure ofbilling/subscriptionsandusage/summary, which is what the notes rule is for:and, when those endpoints failed,
Plan unavailable from Command Code/Usage summary unavailable from Command Codeabove the same window rows, with the credit row reduced to what remained known.Scope note
omp usageitself does not load plugin extensions in 18.2.6 or 18.3.2:src/cli/usage-cli.tsbuildsnew ModelRegistry(authStorage)without extension providers, so an extension-only usage provider is never consulted there. This change is what OMP's documentedusagecontract asks for, it is what makes every extension-aware surface (session/usagedashboard, ACP text, usage history, credential ranking) report the quota today, and it needs no further change here once that command loads extensions. The CLI gap is reported to OMP separately.Checks
npm run typecheck— passnpm run format:check— passnpm run test:usage— 10 passnpm run test:unit— passOMP_COMPAT_REQUIRED=1 node tests/test-omp-compat.mjs(realomp18.2.6) — PASSOMP_COMPAT_REQUIRED=1 node tests/test-omp-compat.mjsneedsOMP_AUTH_BROKER_URLunset locally: with a broker URL in the environment the isolated test HOME has no broker token and OMP exits withMissingApiKeyErrorbefore the extension loads. Same onmain.PI_LOCAL_REQUIRED=1 node tests/test-pi-local.mjs— fails locally withNo models matching "commandcode"against the installed pi 0.79.0, identically on an unmodifiedmaincheckout; the CI job installs@earendil-works/pi-coding-agent@latest.node --test tests/test-release.mjs— 3 failures in the git-release-guard tarball fixtures (object is not iterable), identical on an unmodifiedmaincheckout and unrelated to this change (local npm/Node combination).