Files
daniel156161 076914e5b7 refactor: reorganize client transport and extension internals
- Split client, native, remote, serve, markdown, and SDK internals into focused packages with direct imports.
- Move local and remote transport framing/protocol helpers behind clearer module boundaries.
- Break up the extension injected DOM logic into a separate content dispatch bundle and dedicated content modules.
- Add explicit client handling for passive remote discovery without noisy PQ warnings.
- Keep behavior covered with updated unit, integration, and extension tests.
2026-06-13 23:31:24 +02:00

52 lines
2.1 KiB
Python

"""Tab groups namespace: ``b.groups.*``."""
from __future__ import annotations
from browser_cli.models import BrowserCounts, Group, Tab
from browser_cli.sdk.base import Namespace
class GroupsNS(Namespace):
"""List, create, query, and modify tab groups."""
def list(self) -> list[Group]:
"""Return all tab groups.
When multiple browsers are active and no browser was specified, each Group
includes ``group.browser`` naming its source browser.
"""
return self.multi_list("group.list", {}, self.group_from_target)
def count(self) -> "int | BrowserCounts":
"""Return the number of tab groups.
Returns ``BrowserCounts`` in implicit multi-browser mode.
"""
return self.multi_count("group.count", {})
def query(self, search: str) -> list[Group]:
"""Search groups by name."""
return [self.group_from(g) for g in (self.command("group.query", {"search": search}) or [])]
def create(self, name: str) -> Group:
"""Create a new tab group with *name*. Returns the created Group."""
data = self.command("group.open", {"name": name})
if isinstance(data, dict):
return self.group_from(data)
return Group(id=data, title=name, color="", collapsed=False, tab_count=0)
def tabs(self, group_id: int) -> list[Tab]:
"""Return all tabs inside a group."""
return [self.tab_from(t) for t in (self.command("group.tabs", {"groupId": group_id}) or [])]
def add_tab(self, group: str | int, url: str | None = None) -> int | None:
"""Open a new tab (optionally at URL) inside a group. Returns the new tab ID."""
result = self.command("group.add_tab", {"group": str(group), "url": url})
return self.field(result, "tabId", fallback=result)
def move(self, group: str | int, *, forward: bool = False, backward: bool = False) -> dict | None:
"""Move a tab group forward or backward. Returns the raw move result."""
return self.command("group.move", {"group": str(group), "forward": forward, "backward": backward})
def close(self, group_id: int, *, gentle_mode: str = "auto") -> None:
"""Ungroup (and close) a tab group by ID."""
self.command("group.close", {"groupId": group_id, "gentleMode": gentle_mode})