import click from rich.console import Console from rich.table import Table from browser_cli.commands import _handle console = Console() @click.group("perf") def perf_group(): """Inspect and tune browser-cli performance behavior.""" @perf_group.command("status") def perf_status(): """Show performance profile, throttle and running jobs.""" result = _handle("perf.status") or {} console.print(f"Profile: [bold]{result.get('performanceProfile', 'auto')}[/bold]") console.print(f"Audible tabs: {'yes' if result.get('audible') else 'no'}") throttle = result.get("throttle") or {} console.print(f"Throttle: batch={throttle.get('batchSize')} pause={throttle.get('pauseMs')}ms mode={throttle.get('mode')}") jobs = result.get("jobs") or [] if not jobs: console.print("[yellow]No running jobs[/yellow]") return table = Table(show_header=True, header_style="bold cyan") table.add_column("Job") table.add_column("Command") table.add_column("Status") table.add_column("Progress", justify="right") table.add_column("Phase") for job in jobs: total = job.get("total") current = job.get("current") or 0 percent = job.get("percent") or 0 progress = f"{current}/{total} ({percent}%)" if total else f"{percent}%" table.add_row(job.get("id", ""), job.get("command", ""), job.get("status", ""), progress, job.get("phase", "")) console.print(table) @perf_group.command("profile") @click.argument("profile", type=click.Choice(["auto", "normal", "gentle", "ultra"])) def perf_profile(profile): """Set global performance profile.""" result = _handle("perf.set_profile", {"profile": profile}) or {} console.print(f"[green]Performance profile set to {result.get('performanceProfile', profile)}[/green]")