Skip to content

Tracking usage - #2

Merged
jpollock merged 14 commits into
mainfrom
tracking-usage
Feb 2, 2026
Merged

jpollock merged 14 commits into
mainfrom
tracking-usage

Conversation

@jpollock

@jpollock jpollock commented Feb 2, 2026

Copy link
Copy Markdown
Owner

No description provided.

jpollock and others added 14 commits January 31, 2026 18:39
Implements Phase 1 of RFC 001 - local-only anonymous analytics:

- Config management with atomic writes and proper permissions (0600)
- Event tracking with JSONL storage (~/.lwp/analytics/events.jsonl)
- Opt-in prompt for first run (defaults to opt-out in non-interactive)
- CI/CD auto-detection (disabled when CI env vars present)
- Command exclusion for sensitive commands (wpe.*, analytics.*)
- Event rotation at 10k limit (keeps newest 80%)
- Summary generation for CLI dashboard

Privacy: Only tracks command names, success/failure, and duration.
Never tracks arguments, site names, paths, or any PII.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Integrates the analytics module into the CLI:

Commands:
- `lwp analytics status` - Show enabled/disabled and event count
- `lwp analytics on` - Enable analytics
- `lwp analytics off` - Disable analytics
- `lwp analytics show` - View summary (or --json for raw events)
- `lwp analytics reset` - Delete all data and disable

Tracking:
- Commander hooks track command execution automatically
- First-run opt-in prompt (skipped for help/update/analytics commands)
- Failed commands tracked via try/catch wrapper
- Command path derived from Commander hierarchy (e.g., "sites.list")

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Tests for the analytics module covering:

- Config management (read/write, corruption handling)
- Environment detection (CI, LWP_ANALYTICS override)
- Event tracking (recording, exclusions)
- JSONL parsing and summary generation
- File permissions

Refactored path initialization to use lazy functions for testability.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Analytics now enabled by default to maximize data collection
- First-run shows informational message instead of asking for consent
- Users can easily disable with `lwp analytics off`
- Updated RFC to reflect decision change
- Updated tests for new default behavior

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…d path

The preAction hook receives (thisCommand, actionCommand) where thisCommand
is the root program and actionCommand is the actual command being executed.
Using thisCommand resulted in commands being tracked as "unknown".

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Tests cover:
- analytics status (current state, event count)
- analytics on/off (enable/disable tracking)
- analytics show (summary and --json output)
- analytics reset (clear events)
- command exclusion (analytics.* not tracked)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
… transmission

- Add installationId (UUID) to config, persisted across sessions
- Add session_id (UUID) generated per CLI invocation
- Extend event format with cli_version, os, node_version
- Add error_category support for failure tracking
- Add transmitEvent() for server transmission (fire-and-forget)
- Add resetAnalytics() to regenerate installationId
- Update status command to show installationId
- Update tests for Phase 2 fields

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add D1 schema for events table with indexes
- Implement POST /v1/events endpoint for event ingestion
- Implement GET /v1/stats endpoint for aggregate statistics
- Add health check endpoint
- Add CORS support for cross-origin requests

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add secretKey generation (32 random bytes, base64) for HMAC signing
- Sign all event transmissions with HMAC-SHA256
- First request sends secretKey, server stores for future verification
- Add installations table to D1 for storing secret keys
- Protect /v1/stats endpoint with ADMIN_TOKEN
- Add /dashboard/:installationId with signed URL (1 hour expiry)
- Add `lwp analytics dashboard` command

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add tests for getSecretKey()
- Add tests for getDashboardUrl()
- Update resetAnalytics test to verify secretKey regeneration
- Add tests for X-Signature and X-Secret-Key headers
- Verify first request sends secretKey, subsequent requests don't

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@jpollock
jpollock merged commit 58deeec into main Feb 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant