Skip to content

Add LongCat usage provider#2217

Closed
joeVenner wants to merge 10 commits into
steipete:mainfrom
joeVenner:codex/longcat-provider
Closed

Add LongCat usage provider#2217
joeVenner wants to merge 10 commits into
steipete:mainfrom
joeVenner:codex/longcat-provider

Conversation

@joeVenner

@joeVenner joeVenner commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds the LongCat provider as a standalone branch.
  • Covers browser/manual cookie usage, quota/fuel-pack parsing, provider registration, docs, icons, and parser hash update.
  • Fixes saved manual cookie projection into CLI/config fetch contexts and propagates LongCat auth failures from quota probes while containing non-auth optional failures.

Verification

  • swift test --filter LongCat
  • swift test --filter ProviderConfigEnvironmentTests
  • make check

LeoLin990405 and others added 8 commits July 16, 2026 12:52
Cookie-based web provider for LongCat (Meituan) that surfaces console
token quota (总额度) and fuel-pack balance (加油包) by reading the
longcat.chat platform session, mirroring the Kimi/MiniMax cookie pattern.

Field mapping is locked against captured live responses:
- GET /api/v1/user-current        -> data.name
- GET /api/lc-platform/v1/tokenUsage          -> data.usage.{total,used,available}Token
- GET /api/lc-platform/v1/pending-fuel-packages -> data.totalQuota + data.list[]

The public API key path exposes no usage endpoint, so usage is read from
the web console session (all longcat.chat cookies are forwarded since the
Meituan passport cookie name is undocumented). The user-current body is
never logged (it carries a session token + phone).

Wires .longcat into the provider/icon enums, descriptor registry, settings
snapshot/builder, implementation registry, logging, widget, cost-usage and
debug switches; adds brand icon, docs provider-id list, CHANGELOG entry and
unit tests covering the live response shapes.
Addresses Codex review on steipete#1697:
- user-current now propagates envelope auth failures (HTTP 200 + code
  401/403 -> .invalidSession) instead of swallowing them with try?, so
  expired cookies prompt re-auth rather than reporting an empty snapshot.
- Remove the never-assigned todayTokens / freeQuota fields and the
  unreachable tertiary 'Today' window; LongCat's tokenUsage is a quota
  snapshot with no per-day figure.
- Add envelope unit tests (invalid-session + success unwrap).
Addresses Codex re-review on steipete#1697: resolveCookieOverride read
context.env["LONGCAT_MANUAL_COOKIE"] directly, bypassing
LongCatSettingsReader.cookieHeader(), so the lower-case
longcat_manual_cookie alias and quote-trimming never reached the env
fetch path for CLI/daemon users. Route the env value through the reader
first. (The P3 changelog 'today's token usage' wording was already
dropped during the rebase onto main.)
Addresses Codex re-review on steipete#1697 (2 P2):
- Off now fully disables web auth: resolveCookieOverride returns nil when
  cookieSource is .off, so a lingering LONGCAT_MANUAL_COOKIE env value can
  no longer keep the web strategy available.
- Browser cookie/keychain import is gated to the Auto source only; Manual
  no longer silently falls back to a browser session when the pasted
  header is missing/invalid (it surfaces as unavailable instead).
- Add regression tests for the Off/Auto env-override gating.
Address maintainer-bar nits before review:
- Thread an injectable ProviderHTTPTransport through fetchUsage/get (mirrors
  the Doubao fetcher) and add scripted-transport tests: 401/403 and blocked
  3xx login redirects surface as .invalidSession, and a full live-shaped
  response maps account + token quota + fuel pack.
- Pin fuel-pack parsing to the fields verified against live longcat.chat
  responses (availableToken / expireTime) instead of probing a speculative
  list of candidate key names.

@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: 008ed4cae8

ℹ️ 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".


@MainActor
func settingsSnapshot(context: ProviderSettingsSnapshotContext) -> ProviderSettingsSnapshotContribution? {
.longcat(context.settings.longcatSettingsSnapshot(tokenOverride: context.tokenOverride))

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 Wire LongCat cookies into CLI snapshots

This app-side snapshot wiring does not cover the CLI path: TokenAccountCLIContext.makeCookieBackedSnapshot/makeSnapshot has no LongCat case, and the environment resolver does not project a config cookieHeader into LONGCAT_MANUAL_COOKIE. In the scenario where a user runs codexbar usage --provider longcat with LongCat credentials saved in the config, the fetch context is built with settings == nil, so LongCatCookieHeader only sees process env and reports missing cookies even though the config contains them.

Useful? React with 👍 / 👎.

Comment on lines +49 to +53
if let data = try? await self.get(
self.tokenUsagePath,
cookieHeader: cookieHeader,
transport: transport,
required: false)

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 Surface auth failures from quota probes

When /api/v1/user-current succeeds but the actual quota endpoint redirects or returns 401/403 (for example an SSO cookie still identifies the user but the platform session has expired), this try? converts LongCatAPIError.invalidSession into nil and the provider publishes a successful snapshot with no quota data. Auth failures from the protected usage probes should be rethrown while still allowing genuinely optional non-auth failures to be ignored.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal priority bug or improvement with limited blast radius. 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. labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed July 16, 2026, 4:44 PM ET / 20:44 UTC.

Summary
Adds a disabled-by-default LongCat provider with browser or manual-cookie authentication, quota and fuel-pack parsing, app and CLI registration, documentation, icons, and focused tests.

Reproducibility: not applicable. This PR adds a new provider rather than repairing an established LongCat contract, and no real current-head account run has been published.

Review metrics: 2 noteworthy metrics.

  • Change Scope: 33 files; +1,406 / -81. The provider spans core fetching, credentials, app and CLI registration, widgets, documentation, generated metadata, and tests.
  • Automated Checks: 8 passed. CI supports implementation quality, but it does not substitute for a real LongCat account run or credential-boundary review.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted current-head real behavior proof for quota, fuel-pack expiry, saved-cookie CLI use, and invalid-session handling.
  • [P1] Consolidate the open LongCat branches and obtain approval for the whole-cookie boundary or narrow it to the required cookies.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only tests and CI are provided; before merge, add redacted current-head app or terminal evidence showing real quota, fuel-pack expiry, saved-cookie CLI use, and invalid-session handling. Screenshots, recordings, copied live output, or logs are acceptable when they directly show the result; redact cookies, API keys, phone numbers, account details, endpoints, and other private data. Updating the PR body should trigger a fresh review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] No contributor-supplied real behavior evidence shows quota parsing, fuel-pack expiry, saved-cookie CLI use, or expired-session handling against a real LongCat account.
  • [P1] Forwarding every longcat.chat browser cookie broadens the credential boundary beyond a named minimal authentication token, even though requests are same-host and use isolated transport.
  • [P1] Two open PRs contain substantially the same LongCat integration, so merging without selecting a canonical branch risks duplicated review and divergent follow-up fixes.

Maintainer options:

  1. Prove And Narrow Before Merge (recommended)
    Identify the minimum required cookie set from a redacted live run, update the importer and focused tests, and attach current-head proof for app and CLI behavior.
  2. Explicitly Accept Same-Host Whole-Jar Use
    A maintainer may accept the broader cookie scope after reviewing redacted live proof and confirming the redirect guard and isolated transport contain credential exposure.
  3. Consolidate Or Pause The Duplicate Branches
    Select one of the two open LongCat PRs for continued review, or pause the integration if neither can establish the authentication contract and real behavior.

Next step before merge

  • [P1] A maintainer must select the canonical LongCat branch and decide whether the complete-cookie authentication boundary is acceptable after contributor-supplied live proof.

Maintainer decision needed

  • Question: May CodexBar forward the entire longcat.chat browser cookie jar for LongCat authentication, and which open LongCat PR should be the landing branch?
  • Rationale: Tests cannot establish which cookies are truly required or authorize the resulting credential boundary, while two open branches currently contain the same provider implementation.
  • Likely owner: steipete — Repository ownership and recent provider architecture work make this the strongest available owner for the credential-scope and landing-path decision.
  • Options:
    • Narrow And Consolidate (recommended): Designate one landing PR, use redacted live diagnostics to identify the minimal required cookies, and retain the isolated same-host transport and regression tests.
    • Approve Whole-Jar Authentication: Designate one landing PR and explicitly accept forwarding the full longcat.chat cookie jar after reviewing redacted live success and invalid-session proof.
    • Pause The Provider: Pause both landing candidates until LongCat's authentication contract can be documented or safely demonstrated.

Security
Needs attention: The isolated transport is a useful containment measure, but forwarding the complete longcat.chat cookie jar creates a credential-scope decision that requires explicit review.

Review details

Best possible solution:

Land one consolidated LongCat PR that preserves the isolated transport and fixed CLI/auth behavior, supplies redacted live app or terminal proof, and either narrows the cookie set or records explicit approval for same-host whole-jar forwarding.

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

Not applicable: this PR adds a new provider rather than repairing an established LongCat contract, and no real current-head account run has been published.

Is this the best way to solve the issue?

Unclear: the provider architecture and fixed error handling follow established patterns, but the best mergeable solution must consolidate the duplicate branches, provide live proof, and resolve the whole-cookie credential scope.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a bounded new-provider integration with meaningful auth sensitivity but no demonstrated regression or emergency impact.
  • merge-risk: 🚨 auth-provider: Merging establishes a new manual and browser-cookie authentication path whose real saved-cookie and expired-session behavior is not yet demonstrated.
  • merge-risk: 🚨 security-boundary: The implementation forwards every longcat.chat browser cookie because the minimal authentication cookie set is unknown.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only tests and CI are provided; before merge, add redacted current-head app or terminal evidence showing real quota, fuel-pack expiry, saved-cookie CLI use, and invalid-session handling. Screenshots, recordings, copied live output, or logs are acceptable when they directly show the result; redact cookies, API keys, phone numbers, account details, endpoints, and other private data. Updating the PR body should trigger a fresh review, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

Security concerns:

  • [medium] Approve Or Narrow Complete Cookie-Jar Forwarding — Sources/CodexBarCore/Providers/LongCat/LongCatCookieImporter.swift:25
    The importer builds a request header from every longcat.chat cookie because the required authentication cookie is unknown; this exposes more browser-session material than a named minimal token and should be narrowed or explicitly approved with redacted live proof.
    Confidence: 0.94

What I checked:

  • Current-main capability gap: Current main's provider enum does not register LongCat, so the requested provider remains absent and this work is still necessary. citeturn10view0. (Sources/CodexBarCore/Providers/Providers.swift:58, bad4bebebc39)
  • Prior findings resolved: Head 7a9941a projects saved LongCat cookies into CLI/config environments and preserves invalid-session failures from protected quota probes; the earlier review cycles report no remaining line-level findings after these changes. (Sources/CodexBarCore/Config/ProviderConfigEnvironment.swift:105, 7a9941a28ad3)
  • Automated validation only: The PR body reports focused Swift tests and make check, and all eight hydrated check runs pass, but no current-head app run, terminal transcript, screenshot, recording, or redacted live output demonstrates a real LongCat account. (Tests/CodexBarTests/LongCatProviderTests.swift:1, 7a9941a28ad3)
  • Credential-scope boundary: The importer intentionally constructs a Cookie header from every longcat.chat cookie because the required authentication cookie is undocumented; requests use an isolated cookie-free transport, but the broad credential scope still requires explicit approval and live proof. (Sources/CodexBarCore/Providers/LongCat/LongCatCookieImporter.swift:25, 7a9941a28ad3)
  • Overlapping open implementation: The original open LongCat PR contains the same central provider work and supplied the initial commits now present here; it is not a safe superseding target because it also lacks positive real-behavior proof. citeturn11view0. (56f18929e34e)
  • Repository policy applied: The full AGENTS.md was read; its Chrome-only cookie-import preference and prohibition on unrequested live account or Keychain probes shaped this review. citeturn1view0. (AGENTS.md:1, bad4bebebc39)

Likely related people:

  • steipete: Repository ownership and prior work across provider descriptors, settings snapshots, and provider wiring make this the strongest available owner for the authentication-boundary and canonical-branch decision. (role: repository owner and recent provider architecture contributor; confidence: high; commits: 33a5f4362eab, 22a07ef225df, bdb213f0199f; files: Sources/CodexBarCore/Providers/ProviderDescriptor.swift, Sources/CodexBarCore/Providers/ProviderSettingsSnapshot.swift, Sources/CodexBar/Providers/Shared/ProviderImplementationRegistry.swift)
  • LeoLin990405: Introduced the LongCat implementation carried by this branch and previously contributed merged provider integrations using related descriptor and web-fetch patterns. (role: feature introducer and adjacent provider contributor; confidence: high; commits: 56f18929e34e, f5fa8138092d, 4c092ce344c5; files: Sources/CodexBarCore/Providers/LongCat/LongCatUsageFetcher.swift, Sources/CodexBarCore/Providers/LongCat/LongCatCookieImporter.swift, Sources/CodexBarCore/Providers/LongCat/LongCatProviderDescriptor.swift)
  • kiranmagic7: Introduced and maintained Kimi cookie-backed provider behavior that is a relevant precedent for browser authentication, parsing, and credential handling. (role: adjacent cookie-provider contributor; confidence: medium; commits: 2c7283b6fe45, d3551e736b55; files: Sources/CodexBarCore/Providers/Kimi/KimiUsageFetcher.swift, Sources/CodexBarCore/Providers/Kimi/KimiCookieImporter.swift)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

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.
Review history (7 earlier review cycles)
  • reviewed 2026-07-16T12:33:11.522Z sha ad26479 :: found issues before merge. :: [P2] Wire saved LongCat cookies into CLI snapshots | [P2] Preserve authentication failures from quota probes
  • reviewed 2026-07-16T13:15:26.970Z sha ad26479 :: needs real behavior proof before merge. :: [P2] Wire saved LongCat cookies into CLI snapshots | [P2] Propagate authentication failures from quota probes
  • reviewed 2026-07-16T16:19:50.932Z sha 7a9941a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-16T17:02:17.809Z sha 7a9941a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-16T18:29:07.694Z sha 7a9941a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-16T19:16:27.605Z sha 7a9941a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-16T20:01:42.716Z sha 7a9941a :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added 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. and removed proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 16, 2026
@joeVenner

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the prior LongCat findings at 7a9941a: saved config cookies now project into CLI/provider env, optional quota/fuel probes propagate invalid-session auth failures, and non-auth optional failures stay contained. Local verification passed: swift test --filter LongCat; swift test --filter ProviderConfigEnvironmentTests; make check.

@clawsweeper

clawsweeper Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@joeVenner

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The previous review placeholder for 7a9941a appears stale after its lease expired. Current head fixes saved manual cookie projection into CLI/config fetch contexts and propagates auth failures from LongCat quota probes, with local verification: swift test --filter LongCat; swift test --filter ProviderConfigEnvironmentTests; make check. Please re-review current head.

@clawsweeper

clawsweeper Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@joeVenner

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The review placeholder for 7a9941a expired without a verdict. Current head fixes cookie projection/auth failure handling and has local verification in the PR body. Please re-review current head.

@joeVenner

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The review placeholder for 7a9941a expired again without a verdict. CI is clean; current head and PR body include the LongCat cookie/auth fixes and verification. Please re-review current head.

@joeVenner

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The review placeholder for 7a9941a expired again without a verdict. CI is clean; current head includes the LongCat fixes and PR verification. Please re-review current head.

1 similar comment
@joeVenner

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The review placeholder for 7a9941a expired again without a verdict. CI is clean; current head includes the LongCat fixes and PR verification. Please re-review current head.

@steipete

Copy link
Copy Markdown
Owner

Thanks @joeVenner for the clean LongCat implementation and for working through the manual-cookie details. We merged the older overlapping implementation in #1697 after bringing it forward to current main, hardening cookie scoping/profile fallback, and adding focused coverage, so I’m closing this as a duplicate.

Your overlapping manual-cookie and CLI improvements were useful in the comparison. Focused follow-ups for any remaining behavior are welcome.

@steipete steipete closed this Jul 17, 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. P2 Normal priority bug or improvement with limited blast radius. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants