feat(cli): track CLI version headers and admin usage analytics

Merged
RI
2mo ago
+2286-804

Summary (AI generated)

  • Capgo CLI now sends x-cli-version, x-cli-command, x-cli-node, and x-cli-os (plus optional capgkey) on Capgo API calls, especially /private/config
  • Backend records CLI usage to Cloudflare Analytics Engine (cli_usage) on workerd, or Postgres public.cli_usage for self-host / Supabase functions
  • Admin dashboard adds a CLI tab with version/command breakdowns, daily trend, and top API-key activity

Motivation (AI generated)

We lack visibility into which CLI versions and commands customers run against Capgo cloud. Config fetches are a natural, low-cost signal to attribute CLI adoption and upgrade lag without instrumenting every hot private route.

Business Impact (AI generated)

Enables support and product to see CLI version distribution, popular commands, and API-key activity. Helps prioritize deprecations, spot stuck old CLI versions, and measure command usage that drives retention and upgrade messaging.

Test Plan (AI generated)

  • bunx vitest run tests/cli-usage.unit.test.ts tests/admin-stats.unit.test.ts
  • Confirm CLI /private/config request includes the new x-cli-* headers (and capgkey when a saved key exists)
  • On workerd with CLI_USAGE bound, confirm Analytics Engine receives writeDataPoints
  • On self-host, confirm rows land in public.cli_usage after config pull
  • Open admin dashboard /admin/dashboard/cli and verify totals, charts, and top API keys for a date range
  • Create Cloudflare Analytics Engine dataset cli_usage in the CF dashboard if missing, then deploy worker bindings

Generated with AI

Made with Cursor


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features

    • Added an admin CLI usage dashboard with date filtering, summaries, charts, and API-key usage details.
    • Added CLI usage analytics and support for tracking command, version, operating system, and Node.js metadata.
    • Added optional custom Supabase anonymous-key configuration during onboarding.
    • Expanded CLI API support for app, version, channel, organization, bundle, and preview operations.
  • Bug Fixes

    • Improved pagination, missing-resource handling, error reporting, and cleanup safeguards across CLI workflows.