From cfcafb5b234c57a0107e4ddf098eb4de7a4faf7c Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 22:42:47 -0700 Subject: [PATCH] refactor(hermes_cli): merge sessions_cmd filter-arg tables into one _FILTER_ARGS predicate --- hermes_cli/sessions_cmd.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.py index c8c26e8e35..d20c667ab0 100644 --- a/hermes_cli/sessions_cmd.py +++ b/hermes_cli/sessions_cmd.py @@ -59,16 +59,15 @@ def _print_dry_run_preview(candidates, filters) -> None: print(f" ... {len(candidates) - 100} more") -_TIME_FILTER_ARGS = ("older_than", "newer_than", "before", "after") -_NON_TIME_FILTER_ARGS = ( - "source", "title", "end_reason", "cwd", "min_messages", "max_messages", "model", "provider", - "user", "chat_id", "chat_type", "branch", "min_tokens", "max_tokens", "min_cost", "max_cost", - "min_tool_calls", "max_tool_calls", +_FILTER_ARGS = ( + "older_than", "newer_than", "before", "after", "source", "title", "end_reason", "cwd", "min_messages", + "max_messages", "model", "provider", "user", "chat_id", "chat_type", "branch", "min_tokens", "max_tokens", + "min_cost", "max_cost", "min_tool_calls", "max_tool_calls", ) -def _any_filter_args(args, names) -> bool: - return any(getattr(args, a, None) is not None for a in names) +def _any_filter_args(args) -> bool: + return any(getattr(args, a, None) is not None for a in _FILTER_ARGS) def _export_dir(output) -> Path: @@ -301,8 +300,7 @@ def _cmd_list(db, args): lambda s: f"{_preview(s, 48):<50} {_ago(s):<13} {s['source']:<6} {s['id']}"), } header, rule, fmt = layouts[(has_ws, has_titles)] - print(header) - print("─" * rule) + print(header + "\n" + "─" * rule) for s in sessions: print(fmt(s)) @@ -312,7 +310,7 @@ def _cmd_list(db, args): def _cmd_export(db, args): from hermes_cli.session_filters import build_prune_filters filters = None - if _any_filter_args(args, _TIME_FILTER_ARGS + _NON_TIME_FILTER_ARGS): + if _any_filter_args(args): try: filters = build_prune_filters(args) except ValueError as e: @@ -655,7 +653,7 @@ def _cmd_prune_or_archive(db, args, action): # Bare `prune` keeps the historical "older than 90 days" default. ANY filter — including --source — # suppresses the implicit cutoff (`prune --source cron` matches ALL cron sessions); the preview + # confirmation below is the safety net. - if action == "prune" and not _any_filter_args(args, _TIME_FILTER_ARGS + _NON_TIME_FILTER_ARGS): + if action == "prune" and not _any_filter_args(args): args.older_than = "90" try: