From 0228845ffc69a9deda0c4a96b6f66d71dfb792df Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 20:45:41 -0700 Subject: [PATCH] refactor(hermes_cli/subcommands): hoist add_yes_flag/add_json_flag into _shared, dedupe gateway --system and peer remote-subparser builders, compact dashboard docs --- hermes_cli/subcommands/_shared.py | 24 ++++----- hermes_cli/subcommands/approvals.py | 10 ++-- hermes_cli/subcommands/claw.py | 6 ++- hermes_cli/subcommands/computer_use.py | 10 ++-- hermes_cli/subcommands/config.py | 4 +- hermes_cli/subcommands/dashboard.py | 68 ++++++-------------------- hermes_cli/subcommands/gateway.py | 26 +++++----- hermes_cli/subcommands/import_agent.py | 4 +- hermes_cli/subcommands/memory.py | 4 +- hermes_cli/subcommands/peer.py | 42 ++++++---------- hermes_cli/subcommands/plugins.py | 6 ++- hermes_cli/subcommands/prompt_size.py | 5 +- hermes_cli/subcommands/security.py | 6 +-- hermes_cli/subcommands/sessions.py | 10 ++-- hermes_cli/subcommands/skills.py | 24 ++++----- hermes_cli/subcommands/uninstall.py | 5 +- hermes_cli/subcommands/verify.py | 5 +- 17 files changed, 108 insertions(+), 151 deletions(-) diff --git a/hermes_cli/subcommands/_shared.py b/hermes_cli/subcommands/_shared.py index c9fffb94c4..6cf86df360 100644 --- a/hermes_cli/subcommands/_shared.py +++ b/hermes_cli/subcommands/_shared.py @@ -1,10 +1,6 @@ -"""Shared parser helpers used across multiple CLI subcommand builders. +"""Shared argparse helpers for the ``hermes_cli/subcommands/*`` builders. -These were module-level helpers in ``hermes_cli/main.py``. They are pulled -into a neutral module so both ``main.py`` and every -``hermes_cli/subcommands/.py`` builder can import them without an -import cycle. ``main.py`` re-exports them for backwards compatibility, so -existing references keep working. +Import-cycle-free (no ``main`` import); ``main.py`` re-exports for compatibility. """ from __future__ import annotations @@ -13,12 +9,18 @@ import argparse def add_accept_hooks_flag(parser: argparse.ArgumentParser) -> None: - """Attach the ``--accept-hooks`` flag. - - Shared across every agent subparser so the flag works regardless of CLI - position. - """ + """Attach ``--accept-hooks`` (shared by every agent subparser so it works in any position).""" parser.add_argument( "--accept-hooks", action="store_true", default=argparse.SUPPRESS, help="Auto-approve unseen shell hooks without a TTY prompt " "(equivalent to HERMES_ACCEPT_HOOKS=1 / hooks_auto_accept: true).") + + +def add_yes_flag(parser: argparse.ArgumentParser, help: str = "Skip confirmation prompt") -> None: + """Attach ``--yes/-y`` (store_true) with the given help text.""" + parser.add_argument("--yes", "-y", action="store_true", help=help) + + +def add_json_flag(parser: argparse.ArgumentParser, help: str) -> None: + """Attach ``--json`` (store_true) with the given help text.""" + parser.add_argument("--json", action="store_true", help=help) diff --git a/hermes_cli/subcommands/approvals.py b/hermes_cli/subcommands/approvals.py index 56e042bbd2..8e6ef783de 100644 --- a/hermes_cli/subcommands/approvals.py +++ b/hermes_cli/subcommands/approvals.py @@ -10,6 +10,8 @@ from __future__ import annotations import argparse from typing import Callable +from hermes_cli.subcommands._shared import add_json_flag + def build_approvals_parser(subparsers, *, cmd_approvals: Callable) -> None: """Attach the ``approvals`` subcommand to ``subparsers``.""" @@ -33,9 +35,7 @@ def build_approvals_parser(subparsers, *, cmd_approvals: Callable) -> None: "--apply", dest="apply_indices", metavar="N[,M...]", help="Merge the numbered proposals (from a prior run) into " "command_allowlist in config.yaml") - suggest_parser.add_argument( - "--json", action="store_true", - help="Emit machine-readable JSON instead of human-readable text") + add_json_flag(suggest_parser, "Emit machine-readable JSON instead of human-readable text") suggest_parser.add_argument( "--days", type=int, default=90, help="How far back to scan session history (default: 90; 0 = all)") @@ -62,9 +62,7 @@ def build_approvals_parser(subparsers, *, cmd_approvals: Callable) -> None: "--env-type", dest="env_type", default="local", help="Terminal backend type to evaluate against (default: local; " "isolated container backends like docker skip the guards)") - test_parser.add_argument( - "--json", action="store_true", - help="Emit machine-readable JSON instead of human-readable text") + add_json_flag(test_parser, "Emit machine-readable JSON instead of human-readable text") test_parser.add_argument( "command_words", nargs=argparse.REMAINDER, diff --git a/hermes_cli/subcommands/claw.py b/hermes_cli/subcommands/claw.py index 87f486c350..98c2996095 100644 --- a/hermes_cli/subcommands/claw.py +++ b/hermes_cli/subcommands/claw.py @@ -4,6 +4,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_yes_flag + def build_claw_parser(subparsers, *, cmd_claw: Callable) -> None: """Attach the ``claw`` subcommand to ``subparsers``.""" @@ -42,7 +44,7 @@ def build_claw_parser(subparsers, *, cmd_claw: Callable) -> None: claw_migrate.add_argument( "--skill-conflict", choices=["skip", "overwrite", "rename"], default="skip", help="How to handle skill name conflicts (default: skip)") - claw_migrate.add_argument("--yes", "-y", action="store_true", help="Skip confirmation prompts") + add_yes_flag(claw_migrate, "Skip confirmation prompts") # claw cleanup claw_cleanup = claw_subparsers.add_parser( @@ -53,5 +55,5 @@ def build_claw_parser(subparsers, *, cmd_claw: Callable) -> None: claw_cleanup.add_argument( "--dry-run", action="store_true", help="Preview what would be archived without making changes") - claw_cleanup.add_argument("--yes", "-y", action="store_true", help="Skip confirmation prompts") + add_yes_flag(claw_cleanup, "Skip confirmation prompts") claw_parser.set_defaults(func=cmd_claw) diff --git a/hermes_cli/subcommands/computer_use.py b/hermes_cli/subcommands/computer_use.py index 69e20b172b..009a1b3696 100644 --- a/hermes_cli/subcommands/computer_use.py +++ b/hermes_cli/subcommands/computer_use.py @@ -4,6 +4,8 @@ from __future__ import annotations import sys +from hermes_cli.subcommands._shared import add_json_flag + def _cu_install(args) -> int: from hermes_cli.tools_config import _cua_driver_contract_status, install_cua_driver @@ -155,9 +157,8 @@ def build_computer_use_parser(subparsers) -> None: computer_use_doctor.add_argument( "--skip", action="append", default=[], metavar="CHECK", help="Skip the listed checks. Repeat for multiple. Wins over --include.") - computer_use_doctor.add_argument( - "--json", action="store_true", - help="Emit the raw structured payload as JSON (same shape as `tools/call`).") + add_json_flag(computer_use_doctor, + "Emit the raw structured payload as JSON (same shape as `tools/call`).") computer_use_perms = computer_use_sub.add_parser( "permissions", help="Check or grant macOS Accessibility + Screen Recording (macOS)", description="Computer Use drives the Mac through cua-driver, whose TCC grants\n" @@ -168,8 +169,7 @@ def build_computer_use_parser(subparsers) -> None: computer_use_perms_sub = computer_use_perms.add_subparsers(dest="computer_use_perms_action") computer_use_perms_status = computer_use_perms_sub.add_parser( "status", help="Report Accessibility + Screen Recording grant state (read-only)") - computer_use_perms_status.add_argument( - "--json", action="store_true", help="Emit the normalized permission payload as JSON.") + add_json_flag(computer_use_perms_status, "Emit the normalized permission payload as JSON.") computer_use_perms_sub.add_parser( "grant", help="Request the grants (opens the dialog attributed to CuaDriver)") _perms_actions = {"grant": _cu_perms_grant, "status": _cu_perms_status} diff --git a/hermes_cli/subcommands/config.py b/hermes_cli/subcommands/config.py index 9ea16b5e89..d292bec58e 100644 --- a/hermes_cli/subcommands/config.py +++ b/hermes_cli/subcommands/config.py @@ -4,6 +4,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_json_flag + def build_config_parser(subparsers, *, cmd_config: Callable) -> None: """Attach the ``config`` subcommand to ``subparsers``.""" @@ -21,7 +23,7 @@ def build_config_parser(subparsers, *, cmd_config: Callable) -> None: # config get config_get = config_subparsers.add_parser("get", help="Print a resolved configuration value") config_get.add_argument("key", nargs="?", help="Configuration key (e.g., model)") - config_get.add_argument("--json", action="store_true", help="Print value as JSON") + add_json_flag(config_get, "Print value as JSON") # config set config_set = config_subparsers.add_parser("set", help="Set a configuration value") diff --git a/hermes_cli/subcommands/dashboard.py b/hermes_cli/subcommands/dashboard.py index 2bd4523967..fe6ead7edc 100644 --- a/hermes_cli/subcommands/dashboard.py +++ b/hermes_cli/subcommands/dashboard.py @@ -13,14 +13,7 @@ from typing import Callable def _add_server_runtime_args(parser) -> None: - """Attach the runtime flags shared by ``dashboard`` and ``serve``. - - Both subcommands boot the *same* ``web_server.start_server`` (the - JSON-RPC/WebSocket gateway). ``dashboard`` opens a browser UI on top of - it; ``serve`` is the headless backend the desktop app and remote clients - connect to. The shared server logic lives in one place — only the - browser-opening behavior and help framing differ. - """ + """Runtime flags shared by ``dashboard`` and ``serve`` (same ``web_server.start_server``).""" parser.add_argument( "--port", type=int, default=9119, help="Port (default 9119, 0 for auto-assign by OS)") parser.add_argument("--host", default="127.0.0.1", help="Host (default 127.0.0.1)") @@ -41,15 +34,11 @@ def _add_server_runtime_args(parser) -> None: "to that profile instead of routing to the machine-level server. " "Default behavior is unified: profile launches attach to (or start) " "ONE machine-level server and preselect the profile.") - # Internal flag set by the unified-launch re-exec (cmd_dashboard) to - # preselect the launching profile in the SPA switcher. Hidden from --help. + # Internal: set by the unified-launch re-exec to preselect the launching profile. parser.add_argument("--open-profile", dest="open_profile", default="", help=argparse.SUPPRESS) - # Lifecycle flags — mutually exclusive with each other and with the - # start-a-server flags above (if both are passed, --stop / --status win - # because they exit before the server is started). The server has no - # service manager and no PID file, so these scan the process table for - # `hermes dashboard` / `hermes serve` cmdlines and SIGTERM them directly — - # the same path `hermes update` uses to clean up stale servers. + # Lifecycle flags win over the start-a-server flags (they exit first). No service + # manager / PID file: they scan the process table for `hermes dashboard|serve` + # cmdlines and SIGTERM them — the same path `hermes update` uses. parser.add_argument( "--stop", action="store_true", help="Stop all running Hermes web server processes and exit") parser.add_argument( @@ -57,15 +46,9 @@ def _add_server_runtime_args(parser) -> None: def _configure_serve_parser(parser, *, cmd_dashboard: Callable) -> None: - """Attach the canonical ``serve`` arguments to *parser*. - - Kept separate from the full subcommand tree so Desktop's hot path can parse - only the command it launches. Both callers use this exact function, keeping - the lean parser and normal CLI semantics in lockstep. - """ + """Canonical ``serve`` arguments; shared by the full tree and Desktop's lean hot-path parser.""" _add_server_runtime_args(parser) - # Accepted but redundant: ``serve`` is always headless. Kept so callers - # using the legacy flag do not trip an argparse error. + # Redundant (serve is always headless) but accepted so legacy callers don't error. parser.add_argument("--no-open", action="store_true", help=argparse.SUPPRESS) parser.add_argument( "--ssh-session-token-file", dest="ssh_session_token_file", metavar="PATH", default=None, @@ -92,14 +75,7 @@ def build_serve_parser( def build_dashboard_parser( subparsers, *, cmd_dashboard: Callable, cmd_dashboard_register: Callable) -> None: - """Attach the ``dashboard`` and ``serve`` subcommands. - - Both share the same backend (``cmd_dashboard`` → ``start_server``). - ``dashboard`` is the browser UI; ``serve`` is the headless backend used by - the desktop app and remote clients. They are independent surfaces — neither - "launches" the other — so the desktop app spawns ``serve``, never - ``dashboard``. - """ + """Attach ``dashboard`` (browser UI) and ``serve`` (headless backend the desktop spawns).""" dashboard_parser = subparsers.add_parser( "dashboard", help="Start the web UI dashboard", description="Launch the Hermes Agent web dashboard for managing config, API keys, and sessions", @@ -107,26 +83,15 @@ def build_dashboard_parser( _add_server_runtime_args(dashboard_parser) dashboard_parser.add_argument( "--no-open", action="store_true", help="Don't open browser automatically") - # Backward-compat shim: older Hermes desktop app shells (<= 0.15.x) spawn the - # backend as `hermes dashboard --no-open --tui --host ... --port ...`. The - # `--tui` flag was removed from this subcommand in cae6b5486 (embedded chat is - # always on now). When a user's CLI updates past that commit but their desktop - # app binary has not, argparse used to hard-error with "unrecognized arguments: - # --tui" and exit(2) — the backend died before becoming ready and the GUI just - # showed "Hermes couldn't start" with no actionable cause. Accept and silently - # ignore the flag so an old app + new CLI degrades gracefully instead of - # bricking. Hidden from --help; safe to delete once the floor app version is - # well past 0.16.0. + # Compat shim: desktop shells <= 0.15.x spawn `hermes dashboard --no-open --tui ...`; + # `--tui` was removed (embedded chat always on). Accept + ignore so an old app with a + # new CLI doesn't die on "unrecognized arguments". Drop once the app floor is > 0.16.0. dashboard_parser.add_argument("--tui", action="store_true", help=argparse.SUPPRESS) dashboard_parser.set_defaults(func=cmd_dashboard) - # serve command — the headless backend server - # - # `serve` boots the exact same gateway as `dashboard` but never opens a - # browser. It exists so the Hermes Desktop app (and headless remote - # backends) can launch a backend WITHOUT invoking `dashboard`: the desktop - # app and the web dashboard are independent surfaces that merely share this - # server, and neither should appear to launch the other. + # `serve`: same gateway as `dashboard`, never opens a browser. Exists so the desktop + # app / remote backends launch a backend WITHOUT invoking `dashboard` — independent + # surfaces that merely share this server. serve_parser = subparsers.add_parser( "serve", help="Start the Hermes backend server (headless; powers the desktop app and remote backends)", @@ -135,10 +100,7 @@ def build_dashboard_parser( "a browser UI.") _configure_serve_parser(serve_parser, cmd_dashboard=cmd_dashboard) - # `hermes dashboard register` — register a self-hosted dashboard OAuth - # client with Nous Portal and write the client_id into ~/.hermes/.env. - # Nested subparser so bare `hermes dashboard` keeps launching the server - # (set_defaults(func=cmd_dashboard) above remains the default). + # `register` is nested so bare `hermes dashboard` keeps launching the server. dashboard_subparsers = dashboard_parser.add_subparsers(dest="dashboard_subcommand") dashboard_register_parser = dashboard_subparsers.add_parser( "register", diff --git a/hermes_cli/subcommands/gateway.py b/hermes_cli/subcommands/gateway.py index c00d1ca015..04b6198c54 100644 --- a/hermes_cli/subcommands/gateway.py +++ b/hermes_cli/subcommands/gateway.py @@ -11,14 +11,17 @@ from hermes_cli.subcommands._shared import add_accept_hooks_flag def _add_compat_platform_flag(parser: argparse.ArgumentParser) -> None: """Accept stale `gateway --platform X` docs without advertising it. - Gateway service lifecycle commands operate on the gateway process, not a - single messaging adapter. Photon briefly printed a per-platform start - command during setup; keep that command parseable so users following the - old hint don't get blocked by argparse before the gateway can start. + Lifecycle commands operate on the gateway process, not one adapter; Photon briefly + printed a per-platform start command during setup, so keep it parseable. """ parser.add_argument("--platform", dest="platform", help=argparse.SUPPRESS) +def _add_system_flag(parser: argparse.ArgumentParser) -> None: + parser.add_argument( + "--system", action="store_true", help="Target the Linux system-level gateway service") + + def build_gateway_parser( subparsers, *, cmd_gateway: Callable, cmd_proxy: Callable, cmd_gateway_enroll: Callable ) -> None: @@ -66,8 +69,7 @@ def build_gateway_parser( # gateway start gateway_start = gateway_subparsers.add_parser( "start", help="Start the installed systemd/launchd background service") - gateway_start.add_argument( - "--system", action="store_true", help="Target the Linux system-level gateway service") + _add_system_flag(gateway_start) gateway_start.add_argument( "--all", action="store_true", help="Kill ALL stale gateway processes across all profiles before starting") @@ -75,15 +77,13 @@ def build_gateway_parser( # gateway stop gateway_stop = gateway_subparsers.add_parser("stop", help="Stop gateway service") - gateway_stop.add_argument( - "--system", action="store_true", help="Target the Linux system-level gateway service") + _add_system_flag(gateway_stop) gateway_stop.add_argument( "--all", action="store_true", help="Stop ALL gateway processes across all profiles") # gateway restart gateway_restart = gateway_subparsers.add_parser("restart", help="Restart gateway service") - gateway_restart.add_argument( - "--system", action="store_true", help="Target the Linux system-level gateway service") + _add_system_flag(gateway_restart) gateway_restart.add_argument( "--all", action="store_true", help="Kill ALL gateway processes across all profiles before restarting") @@ -95,8 +95,7 @@ def build_gateway_parser( gateway_status.add_argument( "-l", "--full", action="store_true", help="Show full, untruncated service/log output where supported") - gateway_status.add_argument( - "--system", action="store_true", help="Target the Linux system-level gateway service") + _add_system_flag(gateway_status) _add_compat_platform_flag(gateway_status) # gateway install @@ -126,8 +125,7 @@ def build_gateway_parser( # gateway uninstall gateway_uninstall = gateway_subparsers.add_parser("uninstall", help="Uninstall gateway service") - gateway_uninstall.add_argument( - "--system", action="store_true", help="Target the Linux system-level gateway service") + _add_system_flag(gateway_uninstall) # gateway list gateway_subparsers.add_parser("list", help="List all profiles and their gateway status") diff --git a/hermes_cli/subcommands/import_agent.py b/hermes_cli/subcommands/import_agent.py index efc51abe8c..c452f7f086 100644 --- a/hermes_cli/subcommands/import_agent.py +++ b/hermes_cli/subcommands/import_agent.py @@ -9,6 +9,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_yes_flag + def build_import_agent_parser(subparsers, *, cmd_import_agent: Callable) -> None: """Attach the ``import-agent`` subcommand to ``subparsers``.""" @@ -30,5 +32,5 @@ def build_import_agent_parser(subparsers, *, cmd_import_agent: Callable) -> None parser.add_argument( "--overwrite", action="store_true", help="Overwrite existing Hermes items on name conflicts (default: skip)") - parser.add_argument("--yes", "-y", action="store_true", help="Skip confirmation prompts") + add_yes_flag(parser, "Skip confirmation prompts") parser.set_defaults(func=cmd_import_agent) diff --git a/hermes_cli/subcommands/memory.py b/hermes_cli/subcommands/memory.py index 0f51fcb13e..d11565f3cf 100644 --- a/hermes_cli/subcommands/memory.py +++ b/hermes_cli/subcommands/memory.py @@ -4,6 +4,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_yes_flag + def build_memory_parser(subparsers, *, cmd_memory: Callable) -> None: """Attach the ``memory`` subcommand to ``subparsers``.""" @@ -24,7 +26,7 @@ def build_memory_parser(subparsers, *, cmd_memory: Callable) -> None: memory_sub.add_parser("off", help="Disable external provider (built-in only)") _reset_parser = memory_sub.add_parser( "reset", help="Erase all built-in memory (MEMORY.md and USER.md)") - _reset_parser.add_argument("--yes", "-y", action="store_true", help="Skip confirmation prompt") + add_yes_flag(_reset_parser) _reset_parser.add_argument( "--target", choices=["all", "memory", "user"], default="all", help="Which store to reset: 'all' (default), 'memory', or 'user'") diff --git a/hermes_cli/subcommands/peer.py b/hermes_cli/subcommands/peer.py index 6670513b95..477fa07003 100644 --- a/hermes_cli/subcommands/peer.py +++ b/hermes_cli/subcommands/peer.py @@ -416,33 +416,21 @@ def build_peer_parser(subparsers) -> None: rm_p = peer_sub.add_parser("remove", aliases=["rm"], help="Remove a peer") rm_p.add_argument("name", help="Peer name") - dm_p = peer_sub.add_parser("dm", help="Message an agent on a peer gateway and print its reply") - dm_p.add_argument( - "target", help=" or / (named profile on a multiplexed peer)") - dm_p.add_argument("message", nargs="?", default=None, help="Message text (or stdin)") - dm_p.add_argument("--json", action="store_true", default=False, help="Emit a JSON result") + def _remote(name: str, help: str, *, run_id: bool): + sp = peer_sub.add_parser(name, help=help) + sp.add_argument("target", help=" or / (named profile on a multiplexed peer)") + if run_id: + sp.add_argument("run_id", help="Run ID returned by 'hermes peer run'") + else: + sp.add_argument("message", nargs="?", default=None, help="Message text (or stdin)") + if name == "run": + sp.add_argument( + "--idempotency-key", default=None, help="Stable retry key (generated when omitted)") + sp.add_argument("--json", action="store_true", default=False, help="Emit a JSON result") - run_p = peer_sub.add_parser( - "run", help="Start a long peer turn asynchronously and return its run ID") - run_p.add_argument( - "target", help=" or / (named profile on a multiplexed peer)") - run_p.add_argument("message", nargs="?", default=None, help="Message text (or stdin)") - run_p.add_argument( - "--idempotency-key", default=None, help="Stable retry key (generated when omitted)") - run_p.add_argument("--json", action="store_true", default=False, help="Emit a JSON result") - - status_p = peer_sub.add_parser( - "status", help="Read the status and final output of an asynchronous peer run") - status_p.add_argument( - "target", help=" or / (named profile on a multiplexed peer)") - status_p.add_argument("run_id", help="Run ID returned by 'hermes peer run'") - status_p.add_argument("--json", action="store_true", default=False, help="Emit a JSON result") - - stop_p = peer_sub.add_parser( - "stop", help="Stop one asynchronous peer run without affecting another turn") - stop_p.add_argument( - "target", help=" or / (named profile on a multiplexed peer)") - stop_p.add_argument("run_id", help="Run ID returned by 'hermes peer run'") - stop_p.add_argument("--json", action="store_true", default=False, help="Emit a JSON result") + _remote("dm", "Message an agent on a peer gateway and print its reply", run_id=False) + _remote("run", "Start a long peer turn asynchronously and return its run ID", run_id=False) + _remote("status", "Read the status and final output of an asynchronous peer run", run_id=True) + _remote("stop", "Stop one asynchronous peer run without affecting another turn", run_id=True) parser.set_defaults(func=cmd_peer) diff --git a/hermes_cli/subcommands/plugins.py b/hermes_cli/subcommands/plugins.py index bb887bae74..7e61df6ce8 100644 --- a/hermes_cli/subcommands/plugins.py +++ b/hermes_cli/subcommands/plugins.py @@ -4,6 +4,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_json_flag + def build_plugins_parser(subparsers, *, cmd_plugins: Callable) -> None: """Attach the ``plugins`` subcommand to ``subparsers``.""" @@ -40,7 +42,7 @@ def build_plugins_parser(subparsers, *, cmd_plugins: Callable) -> None: "term", nargs="?", default="", help="Search term matched fuzzily against name, description, and tags " "(omit to browse the full index)") - plugins_search.add_argument("--json", action="store_true", help="Print machine-readable JSON") + add_json_flag(plugins_search, "Print machine-readable JSON") plugins_search.add_argument( "--capability", metavar="CAP", help="Filter by declared capability (e.g. tools, platform, commands)") @@ -65,7 +67,7 @@ def build_plugins_parser(subparsers, *, cmd_plugins: Callable) -> None: plugins_list.add_argument( "--plain", action="store_true", help="Print compact plain-text output instead of a Rich table") - plugins_list.add_argument("--json", action="store_true", help="Print machine-readable JSON") + add_json_flag(plugins_list, "Print machine-readable JSON") plugins_enable = plugins_subparsers.add_parser("enable", help="Enable a disabled plugin") plugins_enable.add_argument("name", help="Plugin name to enable") diff --git a/hermes_cli/subcommands/prompt_size.py b/hermes_cli/subcommands/prompt_size.py index 8cdc34025f..16d6d41789 100644 --- a/hermes_cli/subcommands/prompt_size.py +++ b/hermes_cli/subcommands/prompt_size.py @@ -4,6 +4,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_json_flag + def build_prompt_size_parser(subparsers, *, cmd_prompt_size: Callable) -> None: """Attach the ``prompt-size`` subcommand to ``subparsers``.""" @@ -15,6 +17,5 @@ def build_prompt_size_parser(subparsers, *, cmd_prompt_size: Callable) -> None: prompt_size_parser.add_argument( "--platform", default="cli", help="Platform to simulate (cli, telegram, discord, ...). Default: cli") - prompt_size_parser.add_argument( - "--json", action="store_true", help="Emit the breakdown as JSON") + add_json_flag(prompt_size_parser, "Emit the breakdown as JSON") prompt_size_parser.set_defaults(func=cmd_prompt_size) diff --git a/hermes_cli/subcommands/security.py b/hermes_cli/subcommands/security.py index 74f561e612..0d2f3b443d 100644 --- a/hermes_cli/subcommands/security.py +++ b/hermes_cli/subcommands/security.py @@ -4,6 +4,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_json_flag + def build_security_parser(subparsers, *, cmd_security: Callable) -> None: """Attach the ``security`` subcommand to ``subparsers``.""" @@ -19,9 +21,7 @@ def build_security_parser(subparsers, *, cmd_security: Callable) -> None: audit_parser = security_subparsers.add_parser( "audit", help="Run a one-shot supply-chain audit", description="Query OSV.dev for known vulnerabilities in installed components.") - audit_parser.add_argument( - "--json", action="store_true", - help="Emit machine-readable JSON instead of human-readable text") + add_json_flag(audit_parser, "Emit machine-readable JSON instead of human-readable text") audit_parser.add_argument( "--fail-on", default="critical", choices=["low", "moderate", "high", "critical"], help="Exit non-zero when any finding meets this severity (default: critical)") diff --git a/hermes_cli/subcommands/sessions.py b/hermes_cli/subcommands/sessions.py index ff6b8aeae3..1603f53288 100644 --- a/hermes_cli/subcommands/sessions.py +++ b/hermes_cli/subcommands/sessions.py @@ -5,6 +5,8 @@ from __future__ import annotations from pathlib import Path from typing import Callable +from hermes_cli.subcommands._shared import add_json_flag, add_yes_flag + def build_sessions_parser(subparsers, *, cmd_sessions: Callable) -> None: """Attach the ``sessions`` subcommand to ``subparsers``.""" @@ -75,7 +77,7 @@ def build_sessions_parser(subparsers, *, cmd_sessions: Callable) -> None: p.add_argument( "--dry-run", action="store_true", help="List matching sessions without changing anything") - p.add_argument("--yes", "-y", action="store_true", help="Skip confirmation") + add_yes_flag(p, "Skip confirmation") sessions_export = sessions_subparsers.add_parser( "export", help="Export sessions to JSONL, Markdown, or QMD") @@ -119,7 +121,7 @@ def build_sessions_parser(subparsers, *, cmd_sessions: Callable) -> None: sessions_delete = sessions_subparsers.add_parser("delete", help="Delete a specific session") sessions_delete.add_argument("session_id", help="Session ID to delete") - sessions_delete.add_argument("--yes", "-y", action="store_true", help="Skip confirmation") + add_yes_flag(sessions_delete, "Skip confirmation") sessions_prune = sessions_subparsers.add_parser( "prune", help="Delete old sessions (filterable by time window, source, title, ...)") @@ -267,9 +269,7 @@ def build_sessions_parser(subparsers, *, cmd_sessions: Callable) -> None: "session_ids", nargs="+", help="Session ID(s) or unique prefix(es) to unpin") sessions_pinned = sessions_subparsers.add_parser("pinned", help="List pinned sessions") - sessions_pinned.add_argument( - "--json", action="store_true", - help="Emit machine-readable JSON (for backup/restore scripting)") + add_json_flag(sessions_pinned, "Emit machine-readable JSON (for backup/restore scripting)") sessions_retitle = sessions_subparsers.add_parser( "retitle-skills", help="Re-title sessions whose auto-title came from a /skill's own text", diff --git a/hermes_cli/subcommands/skills.py b/hermes_cli/subcommands/skills.py index 90bcb41945..13ca145307 100644 --- a/hermes_cli/subcommands/skills.py +++ b/hermes_cli/subcommands/skills.py @@ -4,6 +4,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_json_flag, add_yes_flag + def build_skills_parser(subparsers, *, cmd_skills: Callable) -> None: """Attach the ``skills`` subcommand to ``subparsers``.""" @@ -77,9 +79,8 @@ def build_skills_parser(subparsers, *, cmd_skills: Callable) -> None: "minimax"], help="Filter by source or provider (e.g. nvidia, openai)") skills_search.add_argument("--limit", type=int, default=25, help="Max results") - skills_search.add_argument( - "--json", action="store_true", - help="Output JSON instead of a table (full identifiers, scripting-friendly)") + add_json_flag( + skills_search, "Output JSON instead of a table (full identifiers, scripting-friendly)") skills_install = skills_subparsers.add_parser("install", help="Install a skill") skills_install.add_argument( @@ -93,8 +94,7 @@ def build_skills_parser(subparsers, *, cmd_skills: Callable) -> None: ) skills_install.add_argument( "--force", action="store_true", help="Install despite blocked scan verdict") - skills_install.add_argument( - "--yes", "-y", action="store_true", help="Skip confirmation prompt (needed in TUI mode)") + add_yes_flag(skills_install, "Skip confirmation prompt (needed in TUI mode)") skills_inspect = skills_subparsers.add_parser( "inspect", help="Preview a skill without installing") @@ -127,8 +127,7 @@ def build_skills_parser(subparsers, *, cmd_skills: Callable) -> None: skills_uninstall = skills_subparsers.add_parser( "uninstall", help="Remove a hub-installed skill") skills_uninstall.add_argument("name", help="Skill name to remove") - skills_uninstall.add_argument( - "--yes", "-y", action="store_true", help="Skip confirmation prompt") + add_yes_flag(skills_uninstall) skills_reset = skills_subparsers.add_parser( "reset", @@ -140,8 +139,7 @@ def build_skills_parser(subparsers, *, cmd_skills: Callable) -> None: skills_reset.add_argument( "--restore", action="store_true", help="Also delete the current copy and re-copy the bundled version") - skills_reset.add_argument( - "--yes", "-y", action="store_true", help="Skip confirmation prompt when using --restore") + add_yes_flag(skills_reset, "Skip confirmation prompt when using --restore") skills_list_modified = skills_subparsers.add_parser( "list-modified", help="List bundled skills you've edited (which `hermes update` keeps)", @@ -149,7 +147,7 @@ def build_skills_parser(subparsers, *, cmd_skills: Callable) -> None: "synced, i.e. the ones `hermes update` reports as user-modified and skips. " "Use `hermes skills diff ` to see changes and `hermes skills reset " "` to resume updates.") - skills_list_modified.add_argument("--json", action="store_true", help="Output the list as JSON") + add_json_flag(skills_list_modified, "Output the list as JSON") skills_diff = skills_subparsers.add_parser( "diff", help="Show how your copy of a bundled skill differs from the stock version", @@ -168,8 +166,7 @@ def build_skills_parser(subparsers, *, cmd_skills: Callable) -> None: skills_opt_out.add_argument( "--remove", action="store_true", help="Also delete already-present unmodified bundled skills") - skills_opt_out.add_argument( - "--yes", "-y", action="store_true", help="Skip confirmation prompt when using --remove") + add_yes_flag(skills_opt_out, "Skip confirmation prompt when using --remove") skills_opt_in = skills_subparsers.add_parser( "opt-in", help="Re-enable bundled-skill seeding (undo opt-out)", @@ -190,8 +187,7 @@ def build_skills_parser(subparsers, *, cmd_skills: Callable) -> None: skills_repair_official.add_argument( "--restore", action="store_true", help="Restore from official optional source, backing up existing matching copies") - skills_repair_official.add_argument( - "--yes", "-y", action="store_true", help="Skip confirmation prompt when using --restore") + add_yes_flag(skills_repair_official, "Skip confirmation prompt when using --restore") skills_publish = skills_subparsers.add_parser("publish", help="Publish a skill to a registry") skills_publish.add_argument("skill_path", help="Path to skill directory") diff --git a/hermes_cli/subcommands/uninstall.py b/hermes_cli/subcommands/uninstall.py index 540e2ac475..bcc0adbe27 100644 --- a/hermes_cli/subcommands/uninstall.py +++ b/hermes_cli/subcommands/uninstall.py @@ -4,6 +4,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_yes_flag + def build_uninstall_parser(subparsers, *, cmd_uninstall: Callable) -> None: """Attach the ``uninstall`` subcommand to ``subparsers``.""" @@ -20,8 +22,7 @@ def build_uninstall_parser(subparsers, *, cmd_uninstall: Callable) -> None: "--gui-summary", action="store_true", help="Print a JSON summary of installed GUI/agent artifacts and exit " "(used by the desktop app to gate uninstall options)") - uninstall_parser.add_argument( - "--yes", "-y", action="store_true", help="Skip confirmation prompts") + add_yes_flag(uninstall_parser, "Skip confirmation prompts") uninstall_parser.add_argument( "--dry-run", action="store_true", help="Print what uninstall would remove without changing anything") diff --git a/hermes_cli/subcommands/verify.py b/hermes_cli/subcommands/verify.py index ae4adb8cff..80fdf7c881 100644 --- a/hermes_cli/subcommands/verify.py +++ b/hermes_cli/subcommands/verify.py @@ -8,6 +8,8 @@ from __future__ import annotations from typing import Callable +from hermes_cli.subcommands._shared import add_json_flag + # Keep in sync with agent/verify/runner.py defaults; not imported here to # avoid paying an extra module import on every `hermes` invocation. DEFAULT_PHASE_TIMEOUT = 600.0 @@ -44,6 +46,5 @@ def build_verify_parser(subparsers, *, cmd_verify: Callable) -> None: verify_parser.add_argument( "--ready-timeout", type=float, default=DEFAULT_READY_TIMEOUT, help=f"Readiness poll timeout in seconds (default: {DEFAULT_READY_TIMEOUT:.0f})") - verify_parser.add_argument( - "--json", action="store_true", help="Emit a machine-readable JSON result") + add_json_flag(verify_parser, "Emit a machine-readable JSON result") verify_parser.set_defaults(func=cmd_verify)