hermes-agent/hermes_cli/main_profile_recovery.py
kshitijk4poor bca2e3c5a4 docs(profiles): say the interactive uninstall menu still offers a full wipe
The stale-profile recovery paragraph claimed uninstall only runs in a
mode that keeps user data. Plain interactive `hermes uninstall` is let
through and its menu still offers Full uninstall of the default root,
behind its confirmation prompts. Say so, and note in the predicate why
--full is refused (it wipes without asking) while the menu is not.
2026-09-29 15:45:52 +05:30

46 lines
2.1 KiB
Python

"""Which commands may run in the default home when the sticky ``active_profile`` is gone.
``_apply_profile_override`` fails closed when ``active_profile`` names a deleted profile:
running an ordinary command in the default profile would read or write the wrong profile's
state. The commands here are the way out of that state, so they must still reach their handler.
"""
from __future__ import annotations
import argparse
import contextlib
import io
def _uninstall_keeps_data(args: list[str]) -> bool:
"""True when ``uninstall <args>`` removes no user data.
Parsed with the real ``uninstall`` subparser so abbreviations (``--dat``, ``--fu``) resolve
exactly as they will for the handler. ``--full`` wipes the default root, which also holds
every other profile under ``profiles/``, without asking, so it is refused like ``--data``.
The plain interactive menu still offers a full wipe, but only behind its own confirmations.
"""
from hermes_cli.subcommands.uninstall import build_uninstall_parser
parser = argparse.ArgumentParser(add_help=False)
build_uninstall_parser(parser.add_subparsers(dest="command"), cmd_uninstall=lambda _args: None)
# The real parser prints help/usage errors once the handler runs; this probe stays silent.
# --help exits 0 (harmless, let it through); an unparseable argv fails closed.
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
try:
ns, _ = parser.parse_known_args(["uninstall", *args])
except SystemExit as exit_:
return exit_.code == 0
return not (ns.data or ns.full)
def is_stale_profile_recovery_command(argv: list[str]) -> bool:
"""``profile list``, ``profile use default``, or an ``uninstall`` that keeps user data."""
from hermes_cli._parser import command_argv
command = command_argv(argv)
if command[:2] == ["profile", "list"]:
return True
if command[:2] == ["profile", "use"]:
return len(command) > 2 and command[2].casefold() == "default"
return command[:1] == ["uninstall"] and _uninstall_keeps_data(command[1:])