Skip to content

Add Replicate provider for current-month spend - #2869

Open
Egnus wants to merge 9 commits into
steipete:mainfrom
Egnus:feat/replicate-provider
Open

Add Replicate provider for current-month spend#2869
Egnus wants to merge 9 commits into
steipete:mainfrom
Egnus:feat/replicate-provider

Conversation

@Egnus

@Egnus Egnus commented Aug 11, 2026

Copy link
Copy Markdown

Summary

  • Adds a Replicate provider that reads current-month spend from the billing dashboard JSON APIs using browser session cookies (Automatic + Manual).
  • Menu bar shows dollar spend for the current month; the provider card also surfaces prepaid credit balance when the billing payload includes it (spend limit omitted in v1 — no JSON read API).
  • Documents setup/troubleshooting and notes that public API tokens cannot supply spend.
  • Follow-up fixes from review: Chrome-only automatic import, account-kind identity, refresh after sign-in HTML, Linux manual-cookie CLI exemption.

Live proof (redacted)

Built and ran the local PR branch (not Homebrew). Session came from Arc via Manual Cookie (Automatic is Chrome-only by design).

Commands used

cd /Users/ibm/Projects/codexbar/CodexBar
git checkout feat/replicate-provider

# App binary (packaging failed on Widget/Xcode plugin; SwiftPM release binary is enough)
pkill -x CodexBar || true
open -n .build/release/CodexBar

# Or rebuild if needed:
# swift build -c release --product CodexBar
# swift build -c release --product CodexBarCLI

# Configure once in the app UI:
# Settings → Providers → enable Replicate
# Cookie source → Manual
# Paste Cookie header from Arc DevTools on https://replicate.com/account/billing
# (must include sessionid=…; do not commit/paste cookies into GitHub)

.build/release/CodexBarCLI usage --provider replicate --verbose

Before Manual cookie (Automatic / no Chrome session)

[replicate] fetch strategies:
  - replicate.web (web) available error=No Replicate session cookies found in browsers.
Error: No Replicate session cookies found in browsers.

After Manual cookie from Arc (success)

[replicate] fetch strategies:
  - replicate.web (web) available
== Replicate (web) ==
Spend: 100% left [============]
$1.25 spent this month · $36.71 credit

Amounts matched Replicate Billing for the current calendar month. No cookies, session IDs, or account identifiers included here.

Focused tests already run on the branch

swift test --filter Replicate

Test plan

  • Enable Replicate while signed into replicate.com/account/billing; confirm spend matches dashboard ($1.25 month spend)
  • Confirm credit balance appears when present ($36.71 credit)
  • Manual Cookie header path works (Arc → Manual)
  • Missing/stale browser session surfaces an actionable error (not $0): No Replicate session cookies found in browsers.
  • CodexBarCLI usage --provider replicate --verbose succeeds
  • Automatic Chrome import (not exercised here — contributor uses Arc; Automatic is Chrome-only)
  • make check / full suite on maintainer CI

@clawsweeper re-review

Egnus and others added 7 commits August 11, 2026 16:38
Lock the cookie-authenticated JSON URLs before implementing the provider fetch pipeline.

Co-authored-by: Cursor <cursoragent@cursor.com>
Map current-month spend into providerCost and card detail without inventing quota windows.

Co-authored-by: Cursor <cursoragent@cursor.com>
Authenticate dashboard JSON with browser cookies and map HTTP failures to clear errors.

Co-authored-by: Cursor <cursoragent@cursor.com>
Wire cookie-based web fetch strategy and spend-oriented menu metadata.

Co-authored-by: Cursor <cursoragent@cursor.com>
Expose billing-session cookie configuration without requiring an API token.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use explicit self for static helper calls and demote bootstrap notes to line comments.

Co-authored-by: Cursor <cursoragent@cursor.com>
Clarify that spend comes from the web billing session, not API tokens.

Co-authored-by: Cursor <cursoragent@cursor.com>
@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 4:39 PM ET / 20:39 UTC.

ClawSweeper review

What this changes

This PR adds an opt-in Replicate provider that reads browser or manually supplied session cookies to show current-month spend and prepaid credit in CodexBar.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The PR is a coherent, default-disabled provider addition with focused tests and redacted live manual-cookie proof. It should remain open for owner sign-off because it adds a cookie-authenticated provider based on dashboard endpoints, a category VISION.md reserves for review.

Priority: P3
Reviewed head: 386fec159f5affb288e34048dbaef68ec1d04557
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch follows the existing provider architecture, resolves the prior review findings, and has credible real-session evidence; owner sign-off remains separate from implementation quality.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body includes a redacted after-fix terminal run against a real Replicate billing session, with observed spend and credit values matching the dashboard.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes a redacted after-fix terminal run against a real Replicate billing session, with observed spend and credit values matching the dashboard.
Evidence reviewed 5 items Provider implementation: The branch registers a default-disabled Replicate descriptor with manual and Chrome-only automatic cookie sources, then uses fixed Replicate billing URLs to produce a shared usage snapshot.
Focused coverage: The branch adds parser, credential-path, HTTP-request, account-kind, Chrome-only import, Linux manual-cookie CLI, and menu-display coverage.
Real behavior proof: The PR body contains a redacted after-fix CLI run using an actual manual Replicate billing session, reporting $1.25 current-month spend and $36.71 prepaid credit matching the dashboard.
Findings None None.
Security None None.

How this fits together

CodexBar provider descriptors connect settings and credential sources to fetch strategies, which normalize provider data into snapshots for the menu bar, provider card, and CLI. This change adds Replicate’s billing-session flow to that shared pipeline.

flowchart LR
A[Provider settings] --> B[Cookie source]
B --> C[Replicate billing session]
C --> D[Billing dashboard APIs]
D --> E[Usage snapshot]
E --> F[Menu bar and provider card]
Loading

Decision needed

Question Recommendation
Should CodexBar support Replicate billing through an opt-in browser-session/manual-cookie provider despite the dashboard API and privacy-maintenance commitment? Sponsor the bounded provider: Approve the default-disabled integration with Chrome-only automatic import and manual-cookie fallback, accepting maintenance of Replicate’s dashboard contract.

Why: VISION.md requires sign-off for provider additions that affect authentication, user privacy, or data storage; this is a product and maintenance choice rather than a mechanical patch defect.

Before merge

  • Resolve merge risk (P1) - Replicate access relies on cookie-authenticated dashboard endpoints rather than a public billing API, so endpoint or session changes will require ongoing maintenance; the provider is disabled by default.
  • Complete next step (P2) - The remaining blocker is owner sponsorship of the authenticated-provider and privacy-maintenance direction, not a narrow repair.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production vs. test delta production +1,191/-0, tests +426/-0 The provider is a substantial new authenticated integration, with focused coverage for its parser, cookie paths, CLI exemption, and display behavior.

Merge-risk options

Maintainer options:

  1. Sponsor the cookie-authenticated provider (recommended)
    Approve the opt-in Replicate integration with its documented manual-cookie fallback and accept maintenance of the billing-session contract.
  2. Defer dashboard-session support
    Pause the PR if the project does not want to maintain a provider whose spend data depends on Replicate’s web session and dashboard APIs.

Technical review

Best possible solution:

If sponsored, land the default-disabled descriptor-based integration with its fixed HTTPS origin, Chrome-only automatic import, manual-cookie fallback, and existing focused regression coverage.

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

Not applicable: this PR adds a new provider rather than repairing a reported failure; its redacted live CLI transcript does demonstrate the manual-cookie path after the change.

Is this the best way to solve the issue?

Unclear pending owner sign-off: the descriptor-based implementation follows current provider patterns, but VISION.md requires approval for provider additions that affect authentication or privacy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4befde4bbdf0.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a redacted after-fix terminal run against a real Replicate billing session, with observed spend and credit values matching the dashboard.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes a redacted after-fix terminal run against a real Replicate billing session, with observed spend and credit values matching the dashboard.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This is an optional, default-disabled provider addition rather than a regression in an existing core workflow.
  • merge-risk: 🚨 auth-provider: The provider’s result depends on browser/manual session-cookie selection, validation, and refresh behavior.
  • merge-risk: 🚨 security-boundary: The new integration imports and uses billing-session cookies, even though requests stay on fixed HTTPS Replicate origins.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes a redacted after-fix terminal run against a real Replicate billing session, with observed spend and credit values matching the dashboard.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a redacted after-fix terminal run against a real Replicate billing session, with observed spend and credit values matching the dashboard.

Evidence

What I checked:

Likely related people:

  • steipete: Recent history shows sustained ownership of the provider registry, authentication boundaries, and cookie-backed provider patterns that this change extends. (role: recent provider-architecture contributor; confidence: high; commits: f5a1f799186e, 0954a74a0b9d, 330ae4384b18; files: Sources/CodexBarCore/Providers/ProviderManifest.swift, Sources/CodexBarCore/ProviderHTTPClient.swift, Sources/CodexBarCore/Providers/Notion/NotionProviderDescriptor.swift)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-11T15:42:59.512Z sha d98c576 :: needs real behavior proof before merge. :: [P2] Preserve account kind before populating Organization | [P2] Keep automatic cookie import Chrome-only
  • reviewed 2026-08-11T15:51:50.954Z sha 9f10038 :: needs real behavior proof before merge. :: [P2] Preserve account kind before populating Organization | [P2] Keep automatic cookie import Chrome-only | [P2] Refresh cached cookies after sign-in HTML | [P2] Exempt manual-cookie CLI usage from browser support
  • reviewed 2026-08-11T17:14:01.175Z sha 9f10038 :: needs real behavior proof before merge. :: [P2] Preserve account kind before populating Organization | [P2] Keep automatic cookie import Chrome-only | [P2] Refresh cached cookies after sign-in HTML | [P2] Exempt manual-cookie CLI usage from web rejection
  • reviewed 2026-08-11T17:25:09.289Z sha 386fec1 :: needs real behavior proof before merge. :: none

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d98c576ea2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

cookieHeader: session.cookieHeader,
timeout: context.webTimeout)
return self.makeResult(usage: usage, sourceLabel: "web")
} catch ReplicateUsageError.invalidCredentials where cookieSource != .manual {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Refresh the cookie cache after sign-in HTML

When an automatic/cached Replicate session expires, the billing URL redirects to the same-origin sign-in page and returns HTTP 200, so resolveAccount throws parseFailed rather than invalidCredentials. Because this retry path only clears and re-imports cookies for invalidCredentials, automatic users can stay stuck on a stale cached header with a parse error until they manually clear the cache; treat the missing account props/sign-in page as an auth failure or refresh the cache for that parse failure too.

Useful? React with 👍 / 👎.

/// Preserve Chrome-first behavior, then Firefox and Safari; other Chromium forks remain manual-only.
private static var browserCookieOrder: BrowserCookieImportOrder? {
#if os(macOS)
[.chrome, .firefox, .safari]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep automatic cookie import Chrome-only

With Automatic selected, this default import order falls through to Firefox and Safari whenever Chrome has no usable Replicate session, which can trigger extra browser/Full Disk/Keychain prompts during a normal refresh. The repo guidance is to default browser-cookie imports to Chrome only when possible and let users opt into broader browser lists when needed, so this new provider should not widen automatic import by default.

Useful? React with 👍 / 👎.

Comment on lines +69 to +72
cli: ProviderCLIConfig(
name: "replicate",
aliases: ["r8"],
versionDetector: nil))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exempt manual-cookie CLI usage from web rejection

On non-macOS, CLIUsageCommand.sourceModeRequiresWebSupport rejects .auto for any provider whose fetch plan includes .web unless the descriptor's CLI config declares a browser-support exemption. Replicate can fetch with a manual cookie without any macOS browser import, but this CLI config does not exempt settings.replicate.cookieSource == .manual, so Linux CLI users with a pasted Cookie header get the web-source-unsupported response instead of a fetch.

Useful? React with 👍 / 👎.

Do not fail spend when unused_credit JSON decode or parsing fails; leave creditBalance nil instead.

Co-authored-by: Cursor <cursoragent@cursor.com>
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. label Aug 11, 2026
Thread account kind so personal users are not labeled as organizations, default automatic import to Chrome only, refresh stale sessions after sign-in HTML, and exempt manual cookies on Linux CLI.
@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant