Files
hermes-agent/hermes_cli/subcommands/browser.py
T
Teknium b81ab901f3 refactor(cli): extract the last 16 inline parser groups from main() into hermes_cli/subcommands/
moa, fallback, worktree, browser, secrets, egress, migrate, whatsapp-cloud,
checkpoints, bundles, curator, pets, journey, computer-use, sessions and
completion each become a build_<group>_parser() builder. Closure handlers
that only closed over their own parser moved verbatim; sessions/completion
take the handler by injection. --help/usage/defaults byte-identical for all
399 parsers in the tree (in-process dump before/after).
2026-09-02 13:29:44 -07:00

64 lines
2.4 KiB
Python

"""``hermes browser`` subcommand parser.
Extracted from ``hermes_cli/main.py:main()`` (god-file Phase 2 follow-up).
Handlers are injected or imported lazily so this module never imports ``main``.
"""
from __future__ import annotations
import sys
def build_browser_parser(subparsers) -> None:
"""Attach the ``browser`` subcommand to ``subparsers``."""
browser_parser = subparsers.add_parser(
"browser",
help="Real-profile browsing helpers (close a browser locking its profile)",
description=(
"Helpers for real-profile browsing (browser.use_real_profile). "
"close-profile terminates the browser process tree holding your "
"default profile so Hermes can copy it — DESTRUCTIVE (unsaved tabs "
"in that browser are lost). The agent runs this only after you "
"approve closing the browser."
),
)
browser_subparsers = browser_parser.add_subparsers(dest="browser_action")
browser_close = browser_subparsers.add_parser(
"close-profile",
help="Close the browser locking your real profile (asks nothing — "
"run only with the user's explicit OK; loses unsaved tabs)",
)
browser_close.add_argument(
"--browser",
help="Override detected default browser (chrome/edge/brave/brave-origin/chromium)",
)
def _dispatch_browser(_args):
from hermes_cli.browser_connect import (
UNSUPPORTED_CHANNEL,
close_browser_holding_profile,
detect_default_chromium,
real_profile_data_dir,
)
action = getattr(_args, "browser_action", None)
if action != "close-profile":
browser_parser.print_help()
return 2
browser = getattr(_args, "browser", None) or detect_default_chromium()
if not browser or browser == UNSUPPORTED_CHANNEL:
print("✗ No supported Chromium default browser detected.", file=sys.stderr)
return 1
src = real_profile_data_dir(browser)
if not src:
print(f"✗ Could not resolve the {browser} profile directory.", file=sys.stderr)
return 1
closed, msg = close_browser_holding_profile(src)
if closed:
print(f"✓ {msg}")
return 0
print(f"✗ {msg}", file=sys.stderr)
return 1
browser_parser.set_defaults(func=_dispatch_browser)