Skip to content

feat(cli): CLI-to-Web upgrade flow with entitlement storage (#405)#444

Open
Prateeks16 wants to merge 6 commits into
sreerevanth:mainfrom
Prateeks16:feat/monetization-upgrade-405
Open

feat(cli): CLI-to-Web upgrade flow with entitlement storage (#405)#444
Prateeks16 wants to merge 6 commits into
sreerevanth:mainfrom
Prateeks16:feat/monetization-upgrade-405

Conversation

@Prateeks16

Copy link
Copy Markdown
Contributor

Closes part of #405 (CLI client slice).

Stacked on #443 (#406). This branch builds on the RS256 entitlement verification from #406, so the diff currently includes those files until #443 merges. Review #443 first.

What

Adds the client side of the premium monetization flow: a CLI command that hands off to web checkout and stores the resulting entitlement.

Changes

  • agentwatch upgrade — generates a short-lived, single-use checkout session token and opens the browser to the hosted checkout portal, passing the token so the web flow can bind the entitlement back to this CLI run. After paying, the user runs agentwatch upgrade --activate <token> to verify (RS256) and store the entitlement. --status shows the current tier; --no-browser / --dry-run for headless use.
  • checkout.pynew_session() (random secrets token + 10-min expiry) and checkout_url().
  • entitlement_store.py — persists/loads the entitlement token in ~/.agentwatch/config.toml. Every load re-verifies cryptographically, so a hand-edited or tampered store simply falls back to free tier — storage is not the security boundary.
  • _ensure_premium(feature) — feature gate that prompts agentwatch upgrade on free tier.

Acceptance criteria mapping (#405)

  • ✅ Running a premium feature on free tier prompts the user to upgrade (_ensure_premium).
  • agentwatch upgrade opens the browser to the payment portal.
  • ✅ The CLI receives and stores the premium entitlement token post-payment (--activate → verified → config.toml).
  • ⏳ Payment-gateway processing and webhook provisioning are backend concerns — out of scope for this client PR.

Test

pytest tests/test_monetization.py   # 12 passed
ruff check                          # clean

Note for maintainers (pre-existing, not introduced here)

Cold import agentwatch.cli.main fails with a circular import (governancetracing.collector), and agentwatch/cli/main.py registers two Typer groups named session. Both reproduce on main independent of this PR; flagging for a separate fix. Existing test_cli_api_key / test_cli_export failures on Windows are also pre-existing.

🤖 Generated with Claude Code

…forcement (sreerevanth#406)

Add the client-side verification primitive for premium entitlements:
a JWT signed by the backend with an RS256 private key, verified by the
CLI against the matching public key. Asymmetric signing means the client
holds only the public key and cannot mint its own tokens, so premium
gating becomes a signature check rather than a patchable boolean.

- verify_entitlement(): RS256-only decode, required claims, expiry, and
  optional machine binding; fails closed if PyJWT is unavailable.
- current_machine_id(): stable, hashed device fingerprint for binding.
- require_feature(): entitlement-gated feature check (no bare boolean).
- pyjwt added to the optional `crypto` extra.

Scope: client verification + device binding only. Server-side
enforcement and token issuance are tracked in sreerevanth#405.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 19, 2026 17:01

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Prateeks16, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 32 minutes and 6 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a1528ede-7198-4276-85ec-b448519f155a

📥 Commits

Reviewing files that changed from the base of the PR and between e3012c5 and 1721805.

📒 Files selected for processing (8)
  • agentwatch/cli/main.py
  • agentwatch/security/checkout.py
  • agentwatch/security/entitlement_store.py
  • agentwatch/security/license.py
  • pyproject.toml
  • tests/test_cli_export.py
  • tests/test_license.py
  • tests/test_monetization.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

🧪 PR Test Results

Check Result
Tests (pytest tests/) ✅ success
Lint (ruff check .) ✅ success
Coverage (agentwatch) 73.76%

Python 3.12 · commit 1721805

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Prateeks16 Prateeks16 force-pushed the feat/monetization-upgrade-405 branch from f411898 to ccead56 Compare June 19, 2026 17:04
Prateeks16 and others added 4 commits June 19, 2026 22:39
…lement (sreerevanth#406)

Guard the 'sub'/'tier'/'features' claims so a malformed token raises
LicenseInvalidError at the boundary instead of an uncaught TypeError,
preserving the typed error contract. (exp is already validated as numeric
by PyJWT during decode.) Adds regression tests for non-numeric exp,
non-string tier, and non-iterable features.

Addresses CodeRabbit review feedback on sreerevanth#443.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nth#405)

Add the client side of the premium monetization flow, paired with the
RS256 entitlement verification from sreerevanth#406.

- agentwatch upgrade: generates a short-lived, single-use checkout
  session token, opens the browser to the hosted checkout, then stores
  the entitlement token returned via --activate (verified before save).
  --status shows the current tier; --no-browser/--dry-run for headless.
- checkout.py: session-token handoff + checkout URL builder.
- entitlement_store.py: persists/loads the entitlement in
  ~/.agentwatch/config.toml; every load is cryptographically verified, so
  a tampered store falls back to free tier.
- _ensure_premium(): feature gate that prompts upgrade on free tier.

Scope: CLI client only. Payment-gateway processing and webhook
provisioning are backend concerns (out of scope here).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…erevanth#405)

Pre-existing bug surfaced by CI: `agentwatch/cli/main.py` reassigned
`session_app` to a fresh `typer.Typer(name="session")` near the rollback/
prune definitions and re-registered it, so the "session" group resolved to
that partial group and `session export` / `session list` failed with
"No such command 'export'" (10 failing tests). Remove the stray reassignment
and an earlier empty duplicate so all session subcommands share one group.

Also fix test_export_invalid_format, which read result.stderr (not
separately captured by this Click version) — use result.output.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants