CodexBar icon indicating copy to clipboard operation
CodexBar copied to clipboard

Feature request: Add WordPress Studio Code provider for monthly quota and local model-cost estimates

Open SJY051 opened this issue 3 months ago • 3 comments

Summary

Add a first-party WordPress Studio Code provider that shows the WordPress.com account's monthly AI quota usage and reset time, plus a local per-model token and estimated-cost breakdown.

I plan to contribute the implementation following CodexBar's provider guide.

Problem

WordPress Studio Code currently exposes monthly AI usage only inside Studio settings. CodexBar cannot show:

  • monthly quota used/remaining;
  • the next monthly reset;
  • local token usage by model;
  • an API-equivalent estimated cost by model.

The account quota is shared across Studio sites and devices, while session logs are local to one Mac. Those two data sources must remain visually and semantically distinct.

Available data sources

Exact account quota

Studio fetches:

GET https://public-api.wordpress.com/wpcom/v2/studio-app/ai-assistant/quota
Authorization: Bearer <existing Studio OAuth access token>

The response includes:

  • cost_usage
  • cost_cap
  • cost_reset_date

Source: https://github.com/Automattic/studio/blob/7834b4d6a20381f6c8a36eaaeb8958a5cfaf55d0/packages/common/lib/studio-assistant-quota.ts

The cost_* unit is not publicly documented as USD. The provider should therefore use cost_usage / cost_cap only for the exact monthly percentage and use cost_reset_date for the reset countdown. It should not label these values as dollars.

Local model breakdown

Studio sessions are stored under ~/.studio/sessions/YYYY/MM/DD/*.jsonl. Assistant message entries contain model/provider context and token usage.

Only WordPress.com proxy sessions (studio-wpcom-anthropic and studio-wpcom-openai) should be included. Direct Anthropic BYOK sessions must be excluded.

Studio currently records zero model pricing in its Pi runtime, so any displayed dollar amount must be recomputed from token counts and official model pricing and labeled as an API-equivalent estimate, not a WordPress Studio charge.

Runtime source: https://github.com/Automattic/studio/blob/7834b4d6a20381f6c8a36eaaeb8958a5cfaf55d0/apps/cli/ai/runtimes/pi/index.ts

Proposed first-PR scope

  • Add a stable WordPress Studio Code provider ID.
  • Read the existing unexpired Studio OAuth token from ~/.studio/shared.json at fetch time.
  • Do not copy the token into CodexBar configuration or Keychain.
  • Show exact monthly quota percentage and reset countdown.
  • Scan current-month local Studio sessions for per-model tokens.
  • Show API-equivalent estimated cost per model with an explicit local-estimate disclaimer.
  • Exclude BYOK sessions.
  • Keep the provider out of the widget initially (widgetSelectable: false).
  • Use mocked HTTP and temporary fixture files for tests; no live-account probes.

Out of scope for the first PR

  • A Studio login flow.
  • Persisting or refreshing Studio credentials.
  • Treating quota units as USD.
  • Reconciling account-wide quota with one Mac's local sessions.
  • Full 7/30/90-day Cost History and widget integration.

Acceptance criteria

  • A valid Studio login and quota response produce the monthly used percentage and reset time.
  • Expired credentials and 401/403/429/5xx responses fail safely without exposing credentials or response bodies.
  • cost_cap <= 0 does not fabricate a percentage.
  • Local model totals include only WordPress.com proxy sessions.
  • Unknown models retain token totals and omit cost instead of reporting $0.
  • Date-sensitive model pricing uses the session date.
  • No OAuth token or session content is logged or emitted by the CLI.

Maintainer questions

  1. Is relying on Studio's existing WordPress.com quota endpoint acceptable for a CodexBar provider?
  2. Would wordpressstudio be the preferred stable provider ID?
  3. Is the per-model estimate best shown in provider details for the first PR, with full Cost Usage integration deferred?
  4. Is there a preferred approved source for the WordPress/Studio provider icon?

Official Studio Code documentation: https://developer.wordpress.com/docs/developer-tools/studio/studio-code/

SJY051 avatar Aug 12 '26 05:08 SJY051

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed September 3, 2026, 4:50 PM ET / 20:50 UTC.

Summary Keep open for product-direction review. The request fits CodexBar’s provider mission, but its automatic reuse of Studio OAuth state and local session logs crosses the repository’s explicit auth, privacy, and filesystem sign-off boundary.

Reproducibility: not applicable. this requests new provider coverage rather than reporting broken existing behavior.

Ways to help us reproduce this

  • Add a screenshot or short recording showing the behavior.
  • Add expected vs actual behavior.

Maintainer decision needed

Question Recommendation
Should CodexBar support a native WordPress Studio provider that reuses Studio’s local OAuth state and session logs for quota and local estimates? Approve a bounded native provider: Authorize a first-party implementation limited to fixed read-only Studio paths, no token persistence, redacted failures, and clearly separate account quota from local estimates.

Why: Current plugins cannot access either required data source, while VISION.md requires sign-off for this provider’s auth, privacy, and filesystem boundary.

Next step A maintainer must choose the Studio credential, filesystem, pricing, and privacy contract before implementation can safely begin.

Security Needs attention: The requested reuse of a Studio OAuth token and local session files is a concrete credential and privacy boundary that needs approval before implementation.

Review details

Best possible solution:

If approved, implement a narrow native provider with fixed read-only paths, no credential persistence or logging, mocked quota and session fixtures, explicit local-estimate labeling, and provider-owned details before considering broader cost-history or widget support.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this requests new provider coverage rather than reporting broken existing behavior.

Is this the best way to solve the issue?

Unclear until product approval: a native provider is necessary for the full requested scope because plugins cannot read local files or OAuth, but the access boundary requires maintainer sign-off.

AGENTS.md: found and applied where relevant.

Remaining risk / open question:

  • Automatically reading a third-party OAuth file and local session logs needs an explicit consent, retention, failure, and format-drift contract before CodexBar can safely ship it.
  • The proposed account quota and local API-equivalent estimates describe different scopes; presentation must prevent users from interpreting local estimates as WordPress charges.

Codex review notes: model internal, reasoning high; reviewed against 5996f7fc3b76.

Label changes

Label changes:

  • add clawsweeper:needs-security-review: Current issue advisory state selects this label.

Label justifications:

  • P3: This is a new, non-urgent provider capability awaiting product approval rather than a regression in existing behavior.
Evidence reviewed

Security concerns:

  • [medium] Approve the Studio credential boundary first A native provider would read a third-party OAuth token and send it to a remote quota endpoint, so maintainers must define consent, path allowlisting, redaction, and format-drift handling before accepting the feature. Confidence: 0.93

What I checked:

  • Vision sign-off boundary: VISION.md: The repository encourages provider coverage but explicitly requires sign-off for provider additions with broad filesystem access or unclear auth/privacy behavior; this request includes both automatic reads of Studio state and bearer-token use. (VISION.md:20, 5996f7fc3b76)
  • Current plugin boundary: Local provider plugins cannot use local files or OAuth, so the existing plugin route cannot implement the requested Studio-token and session-log reads. (docs/plugins.md:15, 5996f7fc3b76)
  • Plugin exclusion from requested surfaces: Plugins are excluded from built-in OAuth, local cost scanners, and provider-specific payloads, confirming that a full implementation would require a native provider boundary rather than an external plugin. (docs/plugins.md:244, 5996f7fc3b76)
  • First-party provider architecture: First-party providers are descriptor-driven, with provider-owned credential adapters and ordered fetch strategies shared by the app and CLI; that is the appropriate implementation seam if maintainers approve the access boundary. (docs/provider.md:42, 5996f7fc3b76)
  • No current WordPress Studio provider: The closed first-party provider enum contains no WordPress Studio case, and a case-insensitive current-tree search found no WordPress implementation or documentation. (Sources/CodexBarCore/Providers/Providers.swift:21, 5996f7fc3b76)
  • Provider-boundary history: Recent provider-architecture work was authored by Peter Steinberger in commit 770ec06d2fc450f544699237882396d375d0689b, which remains on main and is contained by released versions through v0.56.4. (docs/provider.md:42, 770ec06d2fc4)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

clawsweeper[bot] avatar Aug 12 '26 05:08 clawsweeper[bot]

Studio’s pinned upstream code confirms the bearer quota endpoint and its cost_usage, cost_cap, and cost_reset_date fields. The requested reuse of Studio’s local OAuth state and local session accounting needs file capabilities unavailable to bundled plugins. A manual-token, quota-only plugin would be a smaller, different scope. Keeping this open for that scope choice; quota units should not be labeled USD.

steipete avatar Sep 24 '26 23:09 steipete

Thanks @SJY051. WordPress Studio Code has no documented quota endpoint; closing until one exists. If you want to drive this, a PR is very welcome and I will reopen; providers land as bundled JS plugins (see docs/plugins.md), so most of these are small.

steipete avatar Oct 07 '26 16:10 steipete