Skip to content

The agent that grows with you

refactor(hermes_cli/subcommands): compact module/function docstrings and drop restating section comments (WHY comments kept)

Tekniume0473f097554
diff --git a/hermes_cli/subcommands/__init__.py b/hermes_cli/subcommands/__init__.py
index 3a39f3ce9cf..26e652e266f 100644
--- a/hermes_cli/subcommands/__init__.py
+++ b/hermes_cli/subcommands/__init__.py
@@ -1,18 +1,8 @@
"""CLI subcommand parser builders for ``hermes <subcommand>``.
-``hermes_cli/main.py:main()`` historically built the entire argparse tree
-inline — 179 ``add_parser`` calls across ~26 subcommand groups, all wedged
-into one 3,300-line function. This package breaks that tree apart: each
-subcommand group owns a ``build_<group>_parser(subparsers, ...)`` function in
-its own module, and ``main()`` calls those builders instead of inlining the
-argument definitions.
-
-Handlers (the ``cmd_*`` functions) still live in ``main.py`` for now and are
-dependency-injected into the builders so these modules never import ``main``
-(which would create a cycle). Shared parser helpers live in
-``_shared.py``.
-
-Part of the god-file decomposition plan (Phase 2).
+Each group owns a ``build_<group>_parser(subparsers, ...)`` in its own module; ``main()``
+calls them. ``cmd_*`` handlers are dependency-injected so no module imports ``main``
+(cycle avoidance). Shared parser helpers live in ``_shared.py``.
"""
from __future__ import annotations
diff --git a/hermes_cli/subcommands/approvals.py b/hermes_cli/subcommands/approvals.py
index 8e6ef783de3..b5cb6ff4896 100644
--- a/hermes_cli/subcommands/approvals.py
+++ b/hermes_cli/subcommands/approvals.py
@@ -1,9 +1,4 @@
-"""``hermes approvals`` subcommand parser.
-
-Follows the cron/security pattern: parser construction lives here, the
-handler is injected by ``main.py`` so this module never imports ``main``
-(cycle avoidance).
-"""
+"""``hermes approvals`` subcommand parser."""
from __future__ import annotations
diff --git a/hermes_cli/subcommands/config.py b/hermes_cli/subcommands/config.py
index d292bec58e8..26b85808d97 100644
--- a/hermes_cli/subcommands/config.py
+++ b/hermes_cli/subcommands/config.py
@@ -14,18 +14,13 @@ def build_config_parser(subparsers, *, cmd_config: Callable) -> None:
description="Manage Hermes Agent configuration")
config_subparsers = config_parser.add_subparsers(dest="config_command")
- # config show (default)
config_subparsers.add_parser("show", help="Show current configuration")
-
- # config edit
config_subparsers.add_parser("edit", help="Open config file in editor")
- # 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)")
add_json_flag(config_get, "Print value as JSON")
- # config set
config_set = config_subparsers.add_parser("set", help="Set a configuration value")
config_set.add_argument(
"key", nargs="?", help="Configuration key (e.g., model, terminal.backend)")
@@ -35,20 +30,12 @@ def build_config_parser(subparsers, *, cmd_config: Callable) -> None:
help="Skip the unknown-key notice printed after writing a key the "
"running version doesn't recognize (the value is saved either way).")
- # config unset
config_unset = config_subparsers.add_parser("unset", help="Remove a configuration value")
config_unset.add_argument("key", nargs="?", help="Configuration key to remove")
- # config path
config_subparsers.add_parser("path", help="Print config file path")
-
- # config env-path
config_subparsers.add_parser("env-path", help="Print .env file path")
-
- # config check
config_subparsers.add_parser("check", help="Check for missing/outdated config")
-
- # config migrate
config_subparsers.add_parser("migrate", help="Update config with new options")
config_parser.set_defaults(func=cmd_config)
diff --git a/hermes_cli/subcommands/cron.py b/hermes_cli/subcommands/cron.py
index 8ddc3cd45df..3e59ae2bf94 100644
--- a/hermes_cli/subcommands/cron.py
+++ b/hermes_cli/subcommands/cron.py
@@ -13,11 +13,9 @@ def build_cron_parser(subparsers, *, cmd_cron: Callable) -> None:
"cron", help="Cron job management", description="Manage scheduled tasks")
cron_subparsers = cron_parser.add_subparsers(dest="cron_command")
- # cron list
cron_list = cron_subparsers.add_parser("list", help="List scheduled jobs")
cron_list.add_argument("--all", action="store_true", help="Include disabled jobs")
- # cron create/add
cron_create = cron_subparsers.add_parser(
"create", aliases=["add"], help="Create a scheduled job")
cron_create.add_argument("schedule", help="Schedule like '30m', 'every 2h', or '0 9 * * *'")
@@ -90,7 +88,6 @@ def build_cron_parser(subparsers, *, cmd_cron: Callable) -> None:
"reported and continue where the last run left off (scouts, "
"monitors, incremental digests). First run is unchanged.")
- # cron edit
cron_edit = cron_subparsers.add_parser("edit", help="Edit an existing scheduled job")
cron_edit.add_argument("job_id", help="Job ID to edit")
cron_edit.add_argument("--schedule", help="New schedule")
@@ -174,7 +171,6 @@ def build_cron_parser(subparsers, *, cmd_cron: Callable) -> None:
"remove", aliases=["rm", "delete"], help="Remove a scheduled job")
cron_remove.add_argument("job_id", help="Job ID to remove")
- # cron status
cron_subparsers.add_parser("status", help="Check if cron scheduler is running")
cron_runs = cron_subparsers.add_parser(
@@ -193,8 +189,7 @@ def build_cron_parser(subparsers, *, cmd_cron: Callable) -> None:
help="Action (default: list)")
cron_incidents.add_argument("incident_id", nargs="?", help="Incident ID to acknowledge (ack)")
- # cron notepad — per-job durable KV scratchpad (injected into the job
- # prompt each run; the running agent writes it via this CLI).
+ # notepad: per-job durable KV, injected into the job prompt each run.
cron_notepad = cron_subparsers.add_parser(
"notepad", help="Read/write a job's durable notepad (persistent KV across runs)")
cron_notepad.add_argument("job_id", help="Job ID the notepad belongs to")
@@ -204,10 +199,8 @@ def build_cron_parser(subparsers, *, cmd_cron: Callable) -> None:
cron_notepad.add_argument("key", nargs="?", help="Notepad key (get/set/delete)")
cron_notepad.add_argument("value", nargs="?", help="Value to store (set)")
- # cron doctor
cron_subparsers.add_parser("doctor", help="Check scheduled jobs for common health issues")
- # cron tick (mostly for debugging)
cron_tick = cron_subparsers.add_parser("tick", help="Run due jobs once and exit")
add_accept_hooks_flag(cron_tick)
add_accept_hooks_flag(cron_parser)
diff --git a/hermes_cli/subcommands/egress.py b/hermes_cli/subcommands/egress.py
index 4958bb2ddce..2298d3a054c 100644
--- a/hermes_cli/subcommands/egress.py
+++ b/hermes_cli/subcommands/egress.py
@@ -5,9 +5,8 @@ from __future__ import annotations
def build_egress_parser(subparsers) -> None:
"""Attach the ``egress`` subcommand to ``subparsers``."""
- # NOTE: this is the OUTBOUND egress firewall (ironsh/iron-proxy).
- # `hermes proxy` (defined elsewhere in this file) is a separate INBOUND
- # OAuth-aggregator reverse proxy. Different direction, different purpose.
+ # OUTBOUND egress firewall (iron-proxy); `hermes proxy` is the separate INBOUND
+ # OAuth-aggregator reverse proxy.
egress_parser = subparsers.add_parser(
"egress", help="Manage the iron-proxy egress credential-injection firewall",
description="Manage iron-proxy, the optional TLS-intercepting egress firewall "
@@ -19,8 +18,7 @@ def build_egress_parser(subparsers) -> None:
_proxy_cli.register_cli(egress_parser)
def _dispatch_egress(args): # noqa: ANN001
- # The egress subparser uses dest='egress_command' to stay disjoint
- # from the inbound OAuth ``hermes proxy`` subparser (dest='proxy_command').
+ # dest='egress_command' stays disjoint from ``hermes proxy`` (dest='proxy_command').
sub = getattr(args, "egress_command", None)
if sub is not None and hasattr(args, "func") and args.func is not _dispatch_egress:
return args.func(args)
diff --git a/hermes_cli/subcommands/gateway.py b/hermes_cli/subcommands/gateway.py
index 04b6198c541..d812c569685 100644
--- a/hermes_cli/subcommands/gateway.py
+++ b/hermes_cli/subcommands/gateway.py
@@ -31,7 +31,6 @@ def build_gateway_parser(
description="Manage the messaging gateway (Telegram, Discord, WhatsApp, Weixin, and more)")
gateway_subparsers = gateway_parser.add_subparsers(dest="gateway_command")
- # gateway run (default)
gateway_run = gateway_subparsers.add_parser(
"run", help="Run gateway in foreground (recommended for WSL, Docker, Termux)")
gateway_run.add_argument(
@@ -66,7 +65,6 @@ def build_gateway_parser(
add_accept_hooks_flag(gateway_run)
add_accept_hooks_flag(gateway_parser)
- # gateway start
gateway_start = gateway_subparsers.add_parser(
"start", help="Start the installed systemd/launchd background service")
_add_system_flag(gateway_start)
@@ -75,13 +73,11 @@ def build_gateway_parser(
help="Kill ALL stale gateway processes across all profiles before starting")
_add_compat_platform_flag(gateway_start)
- # gateway stop
gateway_stop = gateway_subparsers.add_parser("stop", help="Stop 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")
_add_system_flag(gateway_restart)
gateway_restart.add_argument(
@@ -89,7 +85,6 @@ def build_gateway_parser(
help="Kill ALL gateway processes across all profiles before restarting")
_add_compat_platform_flag(gateway_restart)
- # gateway status
gateway_status = gateway_subparsers.add_parser("status", help="Show gateway status")
gateway_status.add_argument("--deep", action="store_true", help="Deep status check")
gateway_status.add_argument(
@@ -98,7 +93,6 @@ def build_gateway_parser(
_add_system_flag(gateway_status)
_add_compat_platform_flag(gateway_status)
- # gateway install
gateway_install = gateway_subparsers.add_parser(
"install", help="Install gateway as a systemd/launchd background service")
gateway_install.add_argument("--force", action="store_true", help="Force reinstall")
@@ -123,17 +117,13 @@ def build_gateway_parser(
gateway_install.add_argument(
"--elevated-handoff", dest="elevated_handoff", action="store_true", help=argparse.SUPPRESS)
- # gateway uninstall
gateway_uninstall = gateway_subparsers.add_parser("uninstall", help="Uninstall gateway service")
_add_system_flag(gateway_uninstall)
- # gateway list
gateway_subparsers.add_parser("list", help="List all profiles and their gateway status")
- # gateway setup
gateway_subparsers.add_parser("setup", help="Configure messaging platforms")
- # gateway migrate-legacy
gateway_migrate_legacy = gateway_subparsers.add_parser(
"migrate-legacy", help="Remove legacy hermes.service units from pre-rename installs",
description="Stop, disable, and remove legacy Hermes gateway unit files "
@@ -146,11 +136,8 @@ def build_gateway_parser(
gateway_migrate_legacy.add_argument(
"-y", "--yes", dest="yes", action="store_true", help="Skip the confirmation prompt")
- # gateway enroll — enroll a self-hosted gateway with a relay connector
- # (connector⇄gateway auth). Redeems a single-use enrollment token for the
- # per-gateway secret + per-tenant delivery key and writes them to .env.
- # See docs/relay-connector-contract.md (and the connector repo's
- # docs/connector-gateway-auth-design.md). EXPERIMENTAL.
+ # enroll: redeem a single-use connector token for the per-gateway secret + per-tenant
+ # delivery key, written to .env. See docs/relay-connector-contract.md. EXPERIMENTAL.
gateway_enroll = gateway_subparsers.add_parser(
"enroll",
help="Enroll this gateway with a relay connector (writes relay auth creds to .env)",
@@ -183,10 +170,8 @@ def build_gateway_parser(
"reconnects on its own.")
gateway_enroll.set_defaults(func=cmd_gateway_enroll)
- # proxy command — local OpenAI-compatible proxy that attaches the user's
- # OAuth-authenticated provider credentials to outbound requests. Lets
- # external apps (OpenViking, Karakeep, Open WebUI, ...) ride a logged-in
- # subscription without copy-pasting static API keys.
+ # proxy: local OpenAI-compatible proxy attaching the user's OAuth provider credentials,
+ # so external apps (Open WebUI, Karakeep, ...) ride a logged-in subscription.
proxy_parser = subparsers.add_parser(
"proxy", help="Local OpenAI-compatible proxy to OAuth providers",
description="Run a local HTTP server that forwards OpenAI-compatible requests "
diff --git a/hermes_cli/subcommands/import_agent.py b/hermes_cli/subcommands/import_agent.py
index c452f7f086d..b6b27ef07d3 100644
--- a/hermes_cli/subcommands/import_agent.py
+++ b/hermes_cli/subcommands/import_agent.py
@@ -1,9 +1,4 @@
-"""``hermes import-agent`` subcommand parser.
-
-Follows the ``hermes claw`` pattern (see ``hermes_cli/subcommands/claw.py``):
-parser building lives here, the handler is injected to avoid importing
-``main``, and the import logic itself lives in ``hermes_cli/agent_import.py``.
-"""
+"""``hermes import-agent`` subcommand parser (logic lives in ``hermes_cli/agent_import.py``)."""
from __future__ import annotations
diff --git a/hermes_cli/subcommands/login.py b/hermes_cli/subcommands/login.py
index 03d8df0584d..359b9a898f9 100644
--- a/hermes_cli/subcommands/login.py
+++ b/hermes_cli/subcommands/login.py
@@ -6,24 +6,12 @@ from typing import Callable
def build_login_parser(subparsers, *, cmd_login: Callable) -> None:
- """Attach the deprecated ``login`` subcommand to ``subparsers``.
+ """Attach the deprecated ``login`` subcommand (handler only prints a deprecation notice).
- ``hermes login`` was removed in favor of ``hermes auth`` / ``hermes model``
- (the runtime handler in ``hermes_cli/auth.py::login_command`` just prints a
- deprecation message and exits). The subparser is kept registered so that
- old scripts/aliases invoking ``hermes login [--flags]`` still receive the
- actionable deprecation message rather than an argparse ``invalid choice:
- 'login'`` error — but:
-
- - The subparser is registered WITHOUT a ``help=`` kwarg so the row is
- omitted from ``hermes --help`` (argparse only lists subcommands that
- have a help string). This hides a command that no longer works (#24756)
- without the ``help=argparse.SUPPRESS`` ``==SUPPRESS==`` leak that
- argparse emits for a top-level subparser on Python 3.12+.
- - ``--provider`` accepts ANY value (no ``choices=``) so that, e.g.,
- ``hermes login --provider anthropic`` reaches the deprecation handler and
- gets pointed at ``hermes model`` instead of crashing in argparse with
- ``invalid choice: 'anthropic'`` before the handler can run.
+ Kept registered so old scripts get the actionable message instead of argparse's
+ ``invalid choice``. Registered WITHOUT ``help=`` so it is omitted from ``hermes --help``
+ (``help=SUPPRESS`` leaks ``==SUPPRESS==`` for top-level subparsers on 3.12+). ``--provider``
+ takes ANY value (no ``choices=``) so the handler is reached rather than argparse erroring.
"""
login_parser = subparsers.add_parser(
"login",
diff --git a/hermes_cli/subcommands/mcp.py b/hermes_cli/subcommands/mcp.py
index 92cb5eda0cb..8f97cb2d6dc 100644
--- a/hermes_cli/subcommands/mcp.py
+++ b/hermes_cli/subcommands/mcp.py
@@ -27,12 +27,8 @@ def build_mcp_parser(subparsers, *, cmd_mcp: Callable) -> None:
mcp_add_p = mcp_sub.add_parser("add", help="Add an MCP server (discovery-first install)")
mcp_add_p.add_argument("name", help="Server name (used as config key)")
mcp_add_p.add_argument("--url", help="HTTP/SSE endpoint URL")
- # dest="mcp_command" so this flag does not clobber the top-level
- # subparser's args.command attribute, which the dispatcher reads to
- # route to cmd_mcp. Without an explicit dest, argparse derives
- # dest="command" from the flag name and sets it to None when the
- # flag is omitted, causing `hermes mcp add ...` to fall through to
- # interactive chat.
+ # dest="mcp_command": the default dest="command" would clobber the top-level
+ # subcommand name the dispatcher routes on (None when omitted → falls into chat).
mcp_add_p.add_argument("--command", dest="mcp_command", help="Stdio command (e.g. npx)")
mcp_add_p.add_argument(
"--args", nargs=argparse.REMAINDER, default=[],
@@ -68,7 +64,7 @@ def build_mcp_parser(subparsers, *, cmd_mcp: Callable) -> None:
"--all", action="store_true",
help="Re-authenticate every OAuth server in config, one at a time")
- # ── Catalog (Nous-approved MCPs shipped with the repo) ─────────────────
+ # Catalog (Nous-approved MCPs shipped with the repo)
mcp_sub.add_parser(
"picker", help="Interactive catalog picker (also the default for `hermes mcp`)")
mcp_sub.add_parser("catalog", help="List Nous-approved MCPs available for one-click install")
diff --git a/hermes_cli/subcommands/monitoring.py b/hermes_cli/subcommands/monitoring.py
index d42b55f6da0..0a17a422e75 100644
--- a/hermes_cli/subcommands/monitoring.py
+++ b/hermes_cli/subcommands/monitoring.py
@@ -1,12 +1,4 @@
-"""``hermes monitoring`` subcommand parser.
-
-Gateway monitoring control and inspection. ``status`` shows whether the
-gateway health & diagnostics export is enabled, where it points, and the
-redaction posture.
-
-The handler is injected to avoid importing ``main`` (mirrors the insights
-subcommand).
-"""
+"""``hermes monitoring`` subcommand parser (gateway health/diagnostics export control)."""
from __future__ import annotations
diff --git a/hermes_cli/subcommands/pause.py b/hermes_cli/subcommands/pause.py
index e32fca59fc5..5b05684a399 100644
--- a/hermes_cli/subcommands/pause.py
+++ b/hermes_cli/subcommands/pause.py
@@ -1,12 +1,8 @@
"""``hermes pause`` / ``hermes resume`` — the global emergency stop.
-``hermes pause`` writes the ESTOP sentinel at ``$HERMES_HOME/ESTOP``, which
-halts cron dispatch, kanban dispatch, and new gateway turns on their next
-check. In-flight work is never killed. ``hermes resume`` removes the
-sentinel and normal operation resumes on the next tick — no restart needed.
-
-Ported from: gastownhall/gastown estop.go (MIT); related prior art:
-#26778 (/panic — kill/exit semantics, different), #44617.
+``pause`` writes the ESTOP sentinel at ``$HERMES_HOME/ESTOP``; cron, kanban and new gateway
+turns halt on their next check (in-flight work is never killed). ``resume`` removes it and
+operation resumes on the next tick — no restart. Ported from gastownhall/gastown estop.go (MIT).
"""
from __future__ import annotations
diff --git a/hermes_cli/subcommands/secrets.py b/hermes_cli/subcommands/secrets.py
index 81cdb3f8213..ba6c8c0e32b 100644
--- a/hermes_cli/subcommands/secrets.py
+++ b/hermes_cli/subcommands/secrets.py
@@ -19,12 +19,9 @@ def build_secrets_parser(subparsers) -> None:
secrets_op = secrets_subparsers.add_parser(
"onepassword", aliases=["op", "1password"], help="1Password (op:// references) integration")
- # Lazy-import secrets_cli: the module imports agent.secret_sources.bitwarden
- # which loads cryptography._rust.pyd. On Windows this maps the native
- # extension into the updater process, causing the self-lock preflight to
- # defer (#86781). secrets_cli defers its backend import to first use
- # (module-level __getattr__ + handler-level _load_bw()), so register_cli
- # at parse time only wires argparse structure with no crypto cost.
+ # Lazy import: secrets_cli pulls cryptography's native extension, which on Windows
+ # maps into the updater process and defers its self-lock preflight. secrets_cli
+ # defers its backend import to first use, so register_cli here costs no crypto load.
from hermes_cli import secrets_cli as _secrets_cli
from hermes_cli import onepassword_secrets_cli as _op_secrets_cli
diff --git a/hermes_cli/subcommands/sync.py b/hermes_cli/subcommands/sync.py
index 08de1e1c8a1..69d4200086e 100644
--- a/hermes_cli/subcommands/sync.py
+++ b/hermes_cli/subcommands/sync.py
@@ -1,25 +1,9 @@
"""``hermes sync`` subcommand parser — Skill Sync.
-Cloned from ``hermes_cli/subcommands/cron.py`` — same injected-handler shape
-(``func=cmd_sync``) so this module does not import ``main`` (cycle avoidance).
-
-Skill Sync covers two surfaces, both under this one command for launch:
-
- Personal — your own skills, across your own devices:
- hermes sync status show gate/opt-in/head state
- hermes sync pull pull and materialize opted-in skills
- hermes sync push push opted-in skills
- hermes sync now reconcile: pull then push
- hermes sync enable <skill> opt a skill into sync
- hermes sync disable <skill> opt a skill out of sync
- hermes sync device [--name] show or set this device's label
-
- Organisation — skills shared with your team:
- hermes sync propose <skill> share a skill with your organisation
-
-Sync is INERT unless the resolved Nous token carries the access-gate claim
-AND a sync base URL is configured. The commands report that state rather than
-failing opaquely.
+Personal sync (status/pull/push/now/enable/disable/device) moves your own skills across
+your devices; ``propose`` shares a skill with your organisation. Sync is INERT unless the
+resolved Nous token carries the access-gate claim AND a sync base URL is configured — the
+commands report that state rather than failing opaquely.
"""
from __future__ import annotations
diff --git a/hermes_cli/subcommands/tools.py b/hermes_cli/subcommands/tools.py
index a0f53c5026c..f83ac9dca73 100644
--- a/hermes_cli/subcommands/tools.py
+++ b/hermes_cli/subcommands/tools.py
@@ -18,12 +18,10 @@ def build_tools_parser(subparsers, *, cmd_tools: Callable) -> None:
help="Print a summary of enabled tools per platform and exit")
tools_sub = tools_parser.add_subparsers(dest="tools_action")
- # hermes tools list [--platform cli]
tools_list_p = tools_sub.add_parser(
"list", help="Show all tools and their enabled/disabled status")
tools_list_p.add_argument("--platform", default="cli", help="Platform to show (default: cli)")
- # hermes tools disable <name...> [--platform cli]
tools_disable_p = tools_sub.add_parser("disable", help="Disable toolsets or MCP tools")
tools_disable_p.add_argument(
"names", nargs="+", metavar="NAME",
@@ -31,14 +29,12 @@ def build_tools_parser(subparsers, *, cmd_tools: Callable) -> None:
tools_disable_p.add_argument(
"--platform", default="cli", help="Platform to apply to (default: cli)")
- # hermes tools enable <name...> [--platform cli]
tools_enable_p = tools_sub.add_parser("enable", help="Enable toolsets or MCP tools")
tools_enable_p.add_argument(
"names", nargs="+", metavar="NAME", help="Toolset name or MCP tool in server:tool form")
tools_enable_p.add_argument(
"--platform", default="cli", help="Platform to apply to (default: cli)")
- # hermes tools post-setup <key>
tools_postsetup_p = tools_sub.add_parser(
"post-setup", help="Run a provider's post-setup install hook (npm/pip/binary)",
description="Run the install/bootstrap hook a tool backend declares — the\n"