feat: add performance controls for large browser ops
- Add throttled large-operation handling for tab, group, and session commands. - Introduce performance profiles, audible-tab aware gentle mode, and job progress tracking. - Support background session restores with status/cancel commands and lazy placeholders. - Expose new perf and extension CLI groups plus matching Python SDK methods. - Preserve pinned tabs during session snapshots and debounce auto-save updates. - Bump browser-cli and extension versions to 0.10.0 and add pytest-cov to dev deps. - Add coverage for performance controls, background jobs, lazy restores, and tab metadata.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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]")
|
||||
Reference in New Issue
Block a user