|
| 1 | +"""Telemetry commands for basic-memory CLI.""" |
| 2 | + |
| 3 | +import typer |
| 4 | +from rich.console import Console |
| 5 | +from rich.panel import Panel |
| 6 | + |
| 7 | +from basic_memory.cli.app import app |
| 8 | +from basic_memory.config import ConfigManager |
| 9 | + |
| 10 | +console = Console() |
| 11 | + |
| 12 | +# Create telemetry subcommand group |
| 13 | +telemetry_app = typer.Typer(help="Manage anonymous telemetry settings") |
| 14 | +app.add_typer(telemetry_app, name="telemetry") |
| 15 | + |
| 16 | + |
| 17 | +@telemetry_app.command("enable") |
| 18 | +def enable() -> None: |
| 19 | + """Enable anonymous telemetry. |
| 20 | +
|
| 21 | + Telemetry helps improve Basic Memory by collecting anonymous usage data. |
| 22 | + No personal data, note content, or file paths are ever collected. |
| 23 | + """ |
| 24 | + config_manager = ConfigManager() |
| 25 | + config = config_manager.config |
| 26 | + config.telemetry_enabled = True |
| 27 | + config_manager.save_config(config) |
| 28 | + console.print("[green]Telemetry enabled[/green]") |
| 29 | + console.print("[dim]Thank you for helping improve Basic Memory![/dim]") |
| 30 | + |
| 31 | + |
| 32 | +@telemetry_app.command("disable") |
| 33 | +def disable() -> None: |
| 34 | + """Disable anonymous telemetry. |
| 35 | +
|
| 36 | + You can re-enable telemetry anytime with: bm telemetry enable |
| 37 | + """ |
| 38 | + config_manager = ConfigManager() |
| 39 | + config = config_manager.config |
| 40 | + config.telemetry_enabled = False |
| 41 | + config_manager.save_config(config) |
| 42 | + console.print("[yellow]Telemetry disabled[/yellow]") |
| 43 | + |
| 44 | + |
| 45 | +@telemetry_app.command("status") |
| 46 | +def status() -> None: |
| 47 | + """Show current telemetry status and what's collected.""" |
| 48 | + from basic_memory.telemetry import get_install_id, TELEMETRY_DOCS_URL |
| 49 | + |
| 50 | + config = ConfigManager().config |
| 51 | + |
| 52 | + status_text = "[green]enabled[/green]" if config.telemetry_enabled else "[yellow]disabled[/yellow]" |
| 53 | + |
| 54 | + console.print(f"\nTelemetry: {status_text}") |
| 55 | + console.print(f"Install ID: [dim]{get_install_id()}[/dim]") |
| 56 | + console.print() |
| 57 | + |
| 58 | + what_we_collect = """ |
| 59 | +[bold]What we collect:[/bold] |
| 60 | + - App version, Python version, OS, architecture |
| 61 | + - Feature usage (which MCP tools and CLI commands) |
| 62 | + - Sync statistics (entity count, duration) |
| 63 | + - Error types (sanitized, no file paths) |
| 64 | +
|
| 65 | +[bold]What we NEVER collect:[/bold] |
| 66 | + - Note content, file names, or paths |
| 67 | + - Personal information |
| 68 | + - IP addresses |
| 69 | +""" |
| 70 | + |
| 71 | + console.print( |
| 72 | + Panel( |
| 73 | + what_we_collect.strip(), |
| 74 | + title="Telemetry Details", |
| 75 | + border_style="blue", |
| 76 | + expand=False, |
| 77 | + ) |
| 78 | + ) |
| 79 | + console.print(f"[dim]Details: {TELEMETRY_DOCS_URL}[/dim]") |
0 commit comments