claudeshift-cli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ """claudeshift: Profile vault and telemetry engine for AI CLIs."""
2
+
3
+ __version__ = "0.1.0"
claudeshift/cli.py ADDED
@@ -0,0 +1,634 @@
1
+ from __future__ import annotations
2
+
3
+ import platform
4
+ import sys
5
+ import time
6
+ from collections import Counter
7
+ from pathlib import Path
8
+
9
+ import typer
10
+ from rich.console import Console
11
+ from rich.live import Live
12
+ from rich.panel import Panel
13
+ from rich.table import Table
14
+
15
+ from claudeshift import __version__
16
+ from claudeshift.config.paths import resolve_runtime_paths
17
+ from claudeshift.core.vault import VaultEngine, VaultError
18
+ from claudeshift.licensing.entitlements import ProFeatureRequiredError, get_entitlements
19
+ from claudeshift.licensing.gumroad import (
20
+ GUMROAD_PRODUCT_URL,
21
+ LicenseError,
22
+ activate_gumroad_license,
23
+ deactivate_license,
24
+ load_verified_license,
25
+ )
26
+ from claudeshift.providers.base import inspect_all_providers
27
+ from claudeshift.providers.plan_detector import detect_active_plan
28
+ from claudeshift.telemetry.analytics import compute_usage_report
29
+ from claudeshift.telemetry.dashboard import (
30
+ build_live_monitor_renderable,
31
+ build_usage_summary_renderable,
32
+ )
33
+ from claudeshift.telemetry.exporter import export_csv, export_json
34
+ from claudeshift.telemetry.parser import TelemetryScanner, UsageEvent
35
+ from claudeshift.telemetry.pricing import (
36
+ PLAN_QUOTAS,
37
+ PlanQuota,
38
+ load_pricing_overrides,
39
+ sync_live_pricing_catalog,
40
+ )
41
+
42
+ app = typer.Typer(
43
+ name="claudeshift",
44
+ help="Fast local profile switcher, MCP vault, and usage monitor for AI CLIs.",
45
+ no_args_is_help=True,
46
+ add_completion=False,
47
+ )
48
+ console = Console()
49
+
50
+ license_app = typer.Typer(help="Activate and manage your claudeshift Pro license (Gumroad).")
51
+ app.add_typer(license_app, name="license")
52
+
53
+ pricing_app = typer.Typer(help="Manage and sync live AI model pricing definitions.")
54
+ app.add_typer(pricing_app, name="pricing")
55
+
56
+
57
+ def _format_bytes(size: int) -> str:
58
+ if size < 1024:
59
+ return f"{size} B"
60
+ if size < 1024 * 1024:
61
+ return f"{size / 1024:.1f} KB"
62
+ return f"{size / (1024 * 1024):.2f} MB"
63
+
64
+
65
+ def _handle_error(exc: Exception) -> None:
66
+ if isinstance(exc, ProFeatureRequiredError):
67
+ console.print(
68
+ Panel(
69
+ f"[bold yellow]{exc.detail}[/bold yellow]\n\n"
70
+ f"[bold]Get a lifetime Pro license ($19):[/bold] [link=https://mgm15.gumroad.com/l/claudeshift-cli][cyan]{GUMROAD_PRODUCT_URL}[/cyan][/link]\n"
71
+ "[dim]Already have a key? Run:[/dim] [cyan]claudeshift license activate <YOUR-KEY>[/cyan]",
72
+ title="[bold magenta]claudeshift PRO Feature[/bold magenta]",
73
+ border_style="magenta",
74
+ )
75
+ )
76
+ raise typer.Exit(code=2)
77
+ console.print(f"[bold red]Error:[/bold red] {exc}")
78
+ raise typer.Exit(code=1)
79
+
80
+
81
+ def _resolve_plan_choice(
82
+ target_home: Path,
83
+ plan_arg: str,
84
+ provider: str,
85
+ events: list[UsageEvent],
86
+ plan_hint: str = "",
87
+ ) -> tuple[PlanQuota, str, str]:
88
+ """Return (PlanQuota, source_label, dominant_provider)."""
89
+ dominant = provider if provider != "all" else "claude"
90
+ if provider == "all" and events:
91
+ counts = Counter(e.provider for e in events)
92
+ dominant = counts.most_common(1)[0][0]
93
+
94
+ choice = plan_arg.strip().lower()
95
+ if choice == "auto":
96
+ detected = detect_active_plan(
97
+ target_home=target_home,
98
+ provider=provider,
99
+ dominant_provider=dominant,
100
+ session_plan_hint=plan_hint,
101
+ )
102
+ return detected.plan, f"auto:{detected.source}", detected.provider
103
+
104
+ if choice in PLAN_QUOTAS:
105
+ return PLAN_QUOTAS[choice], "manual", dominant
106
+
107
+ valid = ", ".join(["auto", *PLAN_QUOTAS.keys()])
108
+ raise VaultError(f"Unknown plan '{plan_arg}'. Valid options: {valid}")
109
+
110
+
111
+ def _version_callback(value: bool) -> None:
112
+ if value:
113
+ console.print(f"[bold cyan]claudeshift[/bold cyan] v{__version__}")
114
+ raise typer.Exit()
115
+
116
+
117
+ @app.callback()
118
+ def main(
119
+ version: bool = typer.Option(
120
+ False,
121
+ "--version",
122
+ "-v",
123
+ help="Show claudeshift version and exit.",
124
+ callback=_version_callback,
125
+ is_eager=True,
126
+ ),
127
+ ) -> None:
128
+ """claudeshift CLI root."""
129
+
130
+
131
+ @app.command()
132
+ def doctor() -> None:
133
+ """Inspect runtime paths, sandbox isolation, tier, subscriptions, and detected AI CLI providers."""
134
+ paths = resolve_runtime_paths()
135
+ ent = get_entitlements(paths.config_dir)
136
+ statuses = inspect_all_providers(paths.target_home, is_sandbox=paths.is_sandbox)
137
+
138
+ mode_badge = (
139
+ "[bold yellow]SANDBOX MODE (Isolated)[/bold yellow]"
140
+ if paths.is_sandbox
141
+ else "[bold green]LIVE HOME[/bold green]"
142
+ )
143
+ tier_badge = "[bold magenta]PRO[/bold magenta]" if ent.is_pro else "[bold cyan]FREE[/bold cyan]"
144
+
145
+ info_lines = [
146
+ f"[bold]Mode:[/bold] {mode_badge}",
147
+ f"[bold]Edition:[/bold] {tier_badge} [dim]({ent.license_source})[/dim]",
148
+ f"[bold]Target Home:[/bold] {paths.target_home}",
149
+ f"[bold]Vault Dir:[/bold] {paths.vault_dir}",
150
+ f"[bold]Config Dir:[/bold] {paths.config_dir}",
151
+ f"[bold]Runtime:[/bold] Python {sys.version.split()[0]} on {platform.system()} {platform.release()}",
152
+ ]
153
+ console.print(
154
+ Panel(
155
+ "\n".join(info_lines),
156
+ title=f"[bold cyan]claudeshift v{__version__} :: System Doctor[/bold cyan]",
157
+ border_style="cyan",
158
+ )
159
+ )
160
+
161
+ table = Table(title="Detected AI CLI & Desktop Providers", header_style="bold magenta")
162
+ table.add_column("ID", style="cyan", no_wrap=True)
163
+ table.add_column("Provider", style="white")
164
+ table.add_column("Status", no_wrap=True)
165
+ table.add_column("Detected Plan", style="green")
166
+ table.add_column("Detected Paths", style="dim")
167
+
168
+ for st in statuses:
169
+ if paths.is_sandbox:
170
+ status_str = "[bold green]DETECTED[/bold green]" if st.has_data else "[dim]not found[/dim]"
171
+ elif st.installed and st.has_data:
172
+ status_str = "[bold green]DETECTED (installed)[/bold green]"
173
+ elif st.has_data and not st.installed:
174
+ status_str = "[bold yellow]DATA ONLY (uninstalled)[/bold yellow]"
175
+ elif st.installed and not st.has_data:
176
+ status_str = "[cyan]INSTALLED (no data)[/cyan]"
177
+ else:
178
+ status_str = "[dim]not found[/dim]"
179
+
180
+ found_str = ", ".join(p.name for p in st.found_paths) if st.found_paths else "-"
181
+ plan_str = "-"
182
+ if st.has_data and st.spec.id in {"claude", "codex", "gemini"}:
183
+ det = detect_active_plan(paths.target_home, provider=st.spec.id)
184
+ plan_str = f"{det.plan.label} ({det.source})"
185
+ table.add_row(st.spec.id, st.spec.display_name, status_str, plan_str, found_str)
186
+
187
+ console.print(table)
188
+
189
+
190
+ @app.command()
191
+ def save(
192
+ name: str = typer.Argument(..., help="Profile name (e.g., work, personal, client-a)."),
193
+ provider: str = typer.Option(
194
+ "claude", "--provider", "-p", help="Provider ID (claude, codex, gemini, cursor)."
195
+ ),
196
+ overwrite: bool = typer.Option(False, "--overwrite", "-f", help="Update an existing profile."),
197
+ note: str = typer.Option("", "--note", "-n", help="Optional note for this profile."),
198
+ ) -> None:
199
+ """Capture the current live AI CLI configuration into the vault as a named profile."""
200
+ paths = resolve_runtime_paths()
201
+ engine = VaultEngine(paths)
202
+ try:
203
+ manifest = engine.save_profile(name=name, provider=provider, overwrite=overwrite, note=note)
204
+ except (VaultError, ProFeatureRequiredError) as exc:
205
+ _handle_error(exc)
206
+ return
207
+
208
+ mcp_list = ", ".join(manifest.identity.mcp_servers) if manifest.identity.mcp_servers else "none"
209
+ console.print(
210
+ Panel(
211
+ f"[bold green]Saved profile '[cyan]{manifest.name}[/cyan]'[/bold green] ({manifest.provider})\n"
212
+ f"[bold]Account:[/bold] {manifest.identity.account or '-'}\n"
213
+ f"[bold]Model:[/bold] {manifest.identity.model or '-'}\n"
214
+ f"[bold]MCPs:[/bold] {mcp_list}\n"
215
+ f"[bold]Payload:[/bold] {manifest.file_count} files ({_format_bytes(manifest.total_bytes)}) — SHA-256 verified",
216
+ title="[bold green]Vault Snapshot Created[/bold green]",
217
+ border_style="green",
218
+ )
219
+ )
220
+
221
+
222
+ @app.command()
223
+ def use(
224
+ name: str = typer.Argument(..., help="Profile name to activate."),
225
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider ID."),
226
+ no_sync: bool = typer.Option(
227
+ False, "--no-sync", help="Skip syncing current active profile before switching."
228
+ ),
229
+ ) -> None:
230
+ """Atomically switch the active profile with SHA-256 verification and crash rollback."""
231
+ paths = resolve_runtime_paths()
232
+ engine = VaultEngine(paths)
233
+ try:
234
+ res = engine.use_profile(name=name, provider=provider, sync_current=not no_sync)
235
+ except (VaultError, ProFeatureRequiredError) as exc:
236
+ _handle_error(exc)
237
+ return
238
+
239
+ sync_note = f" (auto-synced '{res.previous_profile}')" if res.synced_previous else ""
240
+ backup_note = f"\n[bold]Safety Backup:[/bold] [dim]{res.backup_id}[/dim]" if res.backup_id else ""
241
+ console.print(
242
+ Panel(
243
+ f"[bold green]Switched {res.provider} → [cyan]{res.active_profile}[/cyan][/bold green]{sync_note}\n"
244
+ f"[bold]Switch Time:[/bold] {res.elapsed_ms} ms (atomic swap){backup_note}",
245
+ title="[bold cyan]claudeshift Active[/bold cyan]",
246
+ border_style="cyan",
247
+ )
248
+ )
249
+
250
+
251
+ @app.command("list")
252
+ def list_cmd(
253
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider ID."),
254
+ ) -> None:
255
+ """List saved profiles, accounts, models, and MCP servers."""
256
+ paths = resolve_runtime_paths()
257
+ engine = VaultEngine(paths)
258
+ try:
259
+ profiles = engine.list_profiles(provider=provider)
260
+ active = engine.get_active_profile(provider=provider)
261
+ except VaultError as exc:
262
+ _handle_error(exc)
263
+ return
264
+
265
+ if not profiles:
266
+ console.print(
267
+ f"[yellow]No profiles saved for '{provider}' yet.[/yellow] "
268
+ f"Run: [cyan]claudeshift save work -p {provider}[/cyan]"
269
+ )
270
+ return
271
+
272
+ table = Table(title=f"Saved Profiles ({provider})", header_style="bold magenta")
273
+ table.add_column("Active", justify="center", no_wrap=True)
274
+ table.add_column("Name", style="cyan", no_wrap=True)
275
+ table.add_column("Account / Auth", style="white")
276
+ table.add_column("Model", style="green")
277
+ table.add_column("MCP Servers", style="dim")
278
+ table.add_column("Size", justify="right", style="dim")
279
+
280
+ for m in profiles:
281
+ marker = "[bold green]●[/bold green]" if m.name == active else ""
282
+ mcps = ", ".join(m.identity.mcp_servers) if m.identity.mcp_servers else "-"
283
+ table.add_row(
284
+ marker,
285
+ m.name,
286
+ m.identity.account or "-",
287
+ m.identity.model or "-",
288
+ mcps,
289
+ _format_bytes(m.total_bytes),
290
+ )
291
+ console.print(table)
292
+
293
+
294
+ @app.command()
295
+ def current(
296
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider ID."),
297
+ ) -> None:
298
+ """Show the currently active profile name."""
299
+ paths = resolve_runtime_paths()
300
+ engine = VaultEngine(paths)
301
+ try:
302
+ active = engine.get_active_profile(provider=provider)
303
+ except VaultError as exc:
304
+ _handle_error(exc)
305
+ return
306
+
307
+ if active:
308
+ console.print(f"[bold cyan]{provider}[/bold cyan] active profile: [bold green]{active}[/bold green]")
309
+ else:
310
+ console.print(f"[yellow]No active tracked profile for '{provider}'.[/yellow]")
311
+
312
+
313
+ @app.command()
314
+ def remove(
315
+ name: str = typer.Argument(..., help="Profile name to delete from vault."),
316
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider ID."),
317
+ ) -> None:
318
+ """Delete a saved profile from the vault (does not touch live files)."""
319
+ paths = resolve_runtime_paths()
320
+ engine = VaultEngine(paths)
321
+ try:
322
+ engine.remove_profile(name=name, provider=provider)
323
+ except VaultError as exc:
324
+ _handle_error(exc)
325
+ return
326
+ console.print(f"[green]Removed profile '[cyan]{name}[/cyan]' from {provider} vault.[/green]")
327
+
328
+
329
+ @app.command()
330
+ def backups(
331
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider ID."),
332
+ ) -> None:
333
+ """[PRO] List automatic pre-switch safety snapshots."""
334
+ paths = resolve_runtime_paths()
335
+ engine = VaultEngine(paths)
336
+ try:
337
+ items = engine.list_backups(provider=provider)
338
+ except (VaultError, ProFeatureRequiredError) as exc:
339
+ _handle_error(exc)
340
+ return
341
+
342
+ if not items:
343
+ console.print(f"[dim]No backups recorded yet for '{provider}'.[/dim]")
344
+ return
345
+
346
+ table = Table(title=f"Safety Backups ({provider})", header_style="bold magenta")
347
+ table.add_column("Backup ID", style="cyan", no_wrap=True)
348
+ table.add_column("Created (UTC)", style="white")
349
+ table.add_column("Reason", style="dim")
350
+ table.add_column("Size", justify="right", style="dim")
351
+
352
+ for b in items:
353
+ table.add_row(b.backup_id, b.created_at, b.reason, _format_bytes(b.total_bytes))
354
+ console.print(table)
355
+
356
+
357
+ @app.command()
358
+ def restore(
359
+ backup_id: str = typer.Argument(..., help="Backup ID from 'claudeshift backups'."),
360
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider ID."),
361
+ ) -> None:
362
+ """[PRO] Restore live configuration from a pre-switch safety backup."""
363
+ paths = resolve_runtime_paths()
364
+ engine = VaultEngine(paths)
365
+ try:
366
+ info = engine.restore_backup(backup_id=backup_id, provider=provider)
367
+ except (VaultError, ProFeatureRequiredError) as exc:
368
+ _handle_error(exc)
369
+ return
370
+ console.print(f"[bold green]Restored {info.provider} from backup '[cyan]{info.backup_id}[/cyan]'.[/bold green]")
371
+
372
+
373
+ @app.command()
374
+ def diff(
375
+ profile_a: str = typer.Argument(..., help="First profile name."),
376
+ profile_b: str = typer.Argument(..., help="Second profile name."),
377
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider ID."),
378
+ ) -> None:
379
+ """[PRO] Compare MCP servers and config file hashes between two profiles."""
380
+ paths = resolve_runtime_paths()
381
+ engine = VaultEngine(paths)
382
+ try:
383
+ d = engine.diff_profiles(profile_a=profile_a, profile_b=profile_b, provider=provider)
384
+ except (VaultError, ProFeatureRequiredError) as exc:
385
+ _handle_error(exc)
386
+ return
387
+
388
+ lines = [
389
+ f"[bold]MCP only in {d.profile_a}:[/bold] {', '.join(d.only_in_a_mcp) or '-'}",
390
+ f"[bold]MCP only in {d.profile_b}:[/bold] {', '.join(d.only_in_b_mcp) or '-'}",
391
+ f"[bold]Shared MCPs:[/bold] {', '.join(d.shared_mcp) or '-'}",
392
+ "",
393
+ f"[bold]Changed files ({len(d.changed_files)}):[/bold] {', '.join(d.changed_files) or 'none'}",
394
+ f"[bold]Only in {d.profile_a}:[/bold] {', '.join(d.only_in_a_files) or 'none'}",
395
+ f"[bold]Only in {d.profile_b}:[/bold] {', '.join(d.only_in_b_files) or 'none'}",
396
+ ]
397
+ console.print(
398
+ Panel(
399
+ "\n".join(lines),
400
+ title=f"[bold magenta]Profile Diff: {d.profile_a} ↔ {d.profile_b} ({d.provider})[/bold magenta]",
401
+ border_style="magenta",
402
+ )
403
+ )
404
+
405
+
406
+ @app.command()
407
+ def usage(
408
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider to scan (claude, codex, all)."),
409
+ plan: str = typer.Option(
410
+ "auto", "--plan", help="Plan: auto | pro | max5 | max20 | codex_go | codex_plus | codex_pro | api."
411
+ ),
412
+ budget: float | None = typer.Option(None, "--budget", help="Custom 5-hour USD budget override."),
413
+ ) -> None:
414
+ """Show offline token consumption, auto-detected subscription gauge, and real model breakdown."""
415
+ paths = resolve_runtime_paths()
416
+ load_pricing_overrides(paths.config_dir)
417
+ scanner = TelemetryScanner(paths.target_home, paths.vault_dir)
418
+ events, stats = scanner.scan(provider=provider)
419
+
420
+ if not events:
421
+ console.print(
422
+ f"[yellow]No local usage logs found for '{provider}' under {paths.target_home}.[/yellow]"
423
+ )
424
+ return
425
+
426
+ try:
427
+ resolved_plan, plan_source, dominant = _resolve_plan_choice(
428
+ paths.target_home, plan, provider, events, plan_hint=str(stats.get("plan_hint") or "")
429
+ )
430
+ except VaultError as exc:
431
+ _handle_error(exc)
432
+ return
433
+
434
+ engine = VaultEngine(paths)
435
+ active = engine.get_active_profile(dominant)
436
+ report = compute_usage_report(
437
+ events,
438
+ plan_id=resolved_plan.id,
439
+ custom_budget_usd=budget,
440
+ scan_stats=stats,
441
+ resolved_plan=resolved_plan,
442
+ plan_source=plan_source,
443
+ )
444
+ console.print(build_usage_summary_renderable(report, active))
445
+
446
+
447
+ @app.command()
448
+ def monitor(
449
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider to monitor (claude, codex, all)."),
450
+ plan: str = typer.Option(
451
+ "auto", "--plan", help="Plan: auto | pro | max5 | max20 | codex_go | codex_plus | codex_pro | api."
452
+ ),
453
+ budget: float | None = typer.Option(None, "--budget", help="Custom 5-hour USD budget override."),
454
+ interval: float = typer.Option(2.0, "--interval", "-i", help="Refresh interval in seconds."),
455
+ once: bool = typer.Option(False, "--once", help="Render a single frame and exit."),
456
+ ) -> None:
457
+ """[PRO] Live real-time quota radar, burn-rate speedometer, ETA countdown, and project costs."""
458
+ paths = resolve_runtime_paths()
459
+ load_pricing_overrides(paths.config_dir)
460
+ ent = get_entitlements(paths.config_dir)
461
+ if not ent.live_dashboard:
462
+ _handle_error(
463
+ ProFeatureRequiredError(
464
+ feature="live_dashboard",
465
+ detail="Live Quota Radar & Burn-Rate Dashboard require claudeshift Pro.",
466
+ )
467
+ )
468
+ return
469
+
470
+ scanner = TelemetryScanner(paths.target_home, paths.vault_dir)
471
+ engine = VaultEngine(paths)
472
+
473
+ def _frame():
474
+ events, stats = scanner.scan(provider=provider)
475
+ resolved_plan, plan_source, dominant = _resolve_plan_choice(
476
+ paths.target_home, plan, provider, events, plan_hint=str(stats.get("plan_hint") or "")
477
+ )
478
+ active = engine.get_active_profile(dominant)
479
+ report = compute_usage_report(
480
+ events,
481
+ plan_id=resolved_plan.id,
482
+ custom_budget_usd=budget,
483
+ scan_stats=stats,
484
+ resolved_plan=resolved_plan,
485
+ plan_source=plan_source,
486
+ )
487
+ return build_live_monitor_renderable(report, active, interval_sec=interval)
488
+
489
+ if once:
490
+ console.print(_frame())
491
+ return
492
+
493
+ try:
494
+ with Live(_frame(), console=console, refresh_per_second=2, screen=False) as live:
495
+ while True:
496
+ time.sleep(max(0.5, interval))
497
+ live.update(_frame())
498
+ except KeyboardInterrupt:
499
+ console.print("\n[dim]Stopped live monitor.[/dim]")
500
+
501
+
502
+ @app.command("export")
503
+ def export_cmd(
504
+ output: Path = typer.Argument(..., help="Destination file path (e.g., report.csv or report.json)."),
505
+ fmt: str = typer.Option("auto", "--format", "-f", help="Export format: auto | csv | json."),
506
+ provider: str = typer.Option("claude", "--provider", "-p", help="Provider to export (claude, codex, all)."),
507
+ plan: str = typer.Option("auto", "--plan", help="Plan profile for JSON summary metrics."),
508
+ ) -> None:
509
+ """[PRO] Export local token usage & cost telemetry to CSV or JSON for billing and audits."""
510
+ paths = resolve_runtime_paths()
511
+ load_pricing_overrides(paths.config_dir)
512
+ ent = get_entitlements(paths.config_dir)
513
+ if not ent.csv_export:
514
+ _handle_error(
515
+ ProFeatureRequiredError(
516
+ feature="csv_export",
517
+ detail="CSV/JSON billing & usage exports require claudeshift Pro.",
518
+ )
519
+ )
520
+ return
521
+
522
+ resolved_fmt = fmt.lower()
523
+ if resolved_fmt == "auto":
524
+ resolved_fmt = "json" if output.suffix.lower() == ".json" else "csv"
525
+ if resolved_fmt not in {"csv", "json"}:
526
+ _handle_error(VaultError("Unsupported format. Use --format csv or --format json."))
527
+ return
528
+
529
+ scanner = TelemetryScanner(paths.target_home, paths.vault_dir)
530
+ events, stats = scanner.scan(provider=provider)
531
+ if not events:
532
+ console.print(f"[yellow]No usage events found to export for '{provider}'.[/yellow]")
533
+ return
534
+
535
+ if resolved_fmt == "csv":
536
+ dest = export_csv(events, output)
537
+ else:
538
+ resolved_plan, plan_source, _ = _resolve_plan_choice(
539
+ paths.target_home, plan, provider, events, plan_hint=str(stats.get("plan_hint") or "")
540
+ )
541
+ report = compute_usage_report(
542
+ events,
543
+ plan_id=resolved_plan.id,
544
+ scan_stats=stats,
545
+ resolved_plan=resolved_plan,
546
+ plan_source=plan_source,
547
+ )
548
+ dest = export_json(report, events, output)
549
+
550
+ console.print(
551
+ f"[bold green]Exported {len(events)} usage events ({resolved_fmt.upper()}) → [cyan]{dest}[/cyan][/bold green]"
552
+ )
553
+
554
+
555
+ @pricing_app.command("sync")
556
+ def pricing_sync() -> None:
557
+ """Download the latest live model pricing catalog (GPT-6, Claude 5.x, Gemini 3.x, etc.)."""
558
+ paths = resolve_runtime_paths()
559
+ try:
560
+ count, dest = sync_live_pricing_catalog(paths.config_dir)
561
+ except RuntimeError as exc:
562
+ _handle_error(exc)
563
+ return
564
+ console.print(
565
+ f"[bold green]Synced {count} live AI model pricing entries → [cyan]{dest}[/cyan][/bold green]"
566
+ )
567
+
568
+
569
+ @license_app.command("activate")
570
+ def license_activate(
571
+ key: str = typer.Argument(..., help="Your Gumroad license key."),
572
+ ) -> None:
573
+ """Verify your Gumroad license key online and unlock claudeshift Pro."""
574
+ paths = resolve_runtime_paths()
575
+ try:
576
+ record = activate_gumroad_license(paths.config_dir, license_key=key)
577
+ except LicenseError as exc:
578
+ _handle_error(exc)
579
+ return
580
+
581
+ console.print(
582
+ Panel(
583
+ f"[bold green]claudeshift PRO Activated![/bold green]\n"
584
+ f"[bold]Key:[/bold] [cyan]{record.key_masked}[/cyan]\n"
585
+ f"[bold]Licensed To:[/bold] {record.email or '-'}\n"
586
+ f"[bold]Activations:[/bold] {record.uses}\n"
587
+ f"[bold]Offline Grace:[/bold] Valid until [dim]{record.grace_until}[/dim]",
588
+ title="[bold magenta]License Verified (Gumroad)[/bold magenta]",
589
+ border_style="magenta",
590
+ )
591
+ )
592
+
593
+
594
+ @license_app.command("status")
595
+ def license_status() -> None:
596
+ """Display current license tier, verification state, and offline grace window."""
597
+ paths = resolve_runtime_paths()
598
+ record, reason = load_verified_license(paths.config_dir)
599
+
600
+ if record is None:
601
+ console.print(
602
+ Panel(
603
+ f"[bold cyan]Edition:[/bold cyan] FREE\n"
604
+ f"[bold]State:[/bold] [dim]{reason}[/dim]\n\n"
605
+ "Upgrade to PRO for unlimited profiles, rolling backups, live quota radar, and CSV/JSON exports.\n"
606
+ "Activate with: [cyan]claudeshift license activate <YOUR-GUMROAD-KEY>[/cyan]",
607
+ title="[bold cyan]claudeshift License Status[/bold cyan]",
608
+ border_style="cyan",
609
+ )
610
+ )
611
+ return
612
+
613
+ console.print(
614
+ Panel(
615
+ f"[bold magenta]Edition:[/bold magenta] PRO (Verified)\n"
616
+ f"[bold]Key:[/bold] [cyan]{record.key_masked}[/cyan]\n"
617
+ f"[bold]Licensed To:[/bold] {record.email or '-'}\n"
618
+ f"[bold]Activated At:[/bold] {record.activated_at}\n"
619
+ f"[bold]Offline Grace:[/bold] {record.grace_until}",
620
+ title="[bold magenta]claudeshift License Status[/bold magenta]",
621
+ border_style="magenta",
622
+ )
623
+ )
624
+
625
+
626
+ @license_app.command("deactivate")
627
+ def license_deactivate() -> None:
628
+ """Remove the locally cached Pro license from this machine."""
629
+ paths = resolve_runtime_paths()
630
+ removed = deactivate_license(paths.config_dir)
631
+ if removed:
632
+ console.print("[green]Deactivated local Pro license. Reverted to FREE tier.[/green]")
633
+ else:
634
+ console.print("[dim]No active local license found.[/dim]")
File without changes