The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: sessions list prints a footer when --limit cuts the listing
teknium1536a07bec284
diff --git a/hermes_cli/cli_output.py b/hermes_cli/cli_output.pyindex 6c85046f24a..3b286aef001 100644--- a/hermes_cli/cli_output.py+++ b/hermes_cli/cli_output.py@@ -26,6 +26,18 @@ def print_header(text: str) -> None:print(color(f"\n {text}", Colors.YELLOW))+def print_truncated(more: int | None, hint: str = "") -> None:+ """Footer for a capped listing so a cut list never reads as the whole list.++ ``more`` is the exact number of hidden rows, or ``None`` when the caller only probed+ one row past its cap (``LIMIT n+1``) and knows just that at least one more exists.+ ``hint`` names how to see the rest (``"use --limit 40 to see more"``).+ """+ count = f"{more} more" if more is not None else "more not shown"+ suffix = f" ({hint})" if hint else ""+ print(color(f" … {count}{suffix}", Colors.DIM))++def line_input(prompt_text: str) -> str:"""Read non-secret text with normal cursor-editing keys on a real TTY.diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.pyindex 6a8ab05b491..25e5d4f5db8 100644--- a/hermes_cli/sessions_cmd.py+++ b/hermes_cli/sessions_cmd.py@@ -14,6 +14,7 @@ import sysfrom functools import partialfrom pathlib import Path+from hermes_cli.cli_output import print_truncatedfrom hermes_cli.sessions_cmd_browse import _relative_time, _session_browse_picker@@ -55,7 +56,7 @@ def _print_dry_run_preview(candidates, filters) -> None:for row in candidates[:100]:print(f" {row.get('id')} {row.get('source', '')}")if len(candidates) > 100:- print(f" ... {len(candidates) - 100} more")+ print_truncated(len(candidates) - 100)_FILTER_ARGS = (@@ -262,7 +263,14 @@ def _default_exclude(args):def _cmd_list(db, args):from hermes_state_sessions import workspace_key as _ws_key- sessions = db.list_sessions_rich(source=args.source, exclude_sources=_default_exclude(args), limit=args.limit)+ # LIMIT lives in the query, so probe one row past the cap: it is the only way to know the+ # page was cut without a second COUNT query (``--limit 0`` is ``LIMIT 0``: no rows, no probe).+ limit = args.limit+ sessions = db.list_sessions_rich(+ source=args.source, exclude_sources=_default_exclude(args), limit=limit + 1 if limit > 0 else limit,+ )+ truncated = limit > 0 and len(sessions) > limit+ sessions = sessions[:limit] if truncated else sessions# Workspace filter: workspace key (git repo root, else cwd) — path substring or exact basename._ws_filter = (getattr(args, "workspace", None) or "").strip()@@ -300,6 +308,8 @@ def _cmd_list(db, args):print(header + "\n" + "─" * rule)for s in sessions:print(fmt(s))+ if truncated:+ print_truncated(None, f"use --limit {limit * 2} to see more")# -- export -----------------------------------------------------------------@@ -593,7 +603,7 @@ def _prune_never_active_keyed(db, args):print(f" {s['id']} {format_epoch(s.get('started_at')):<17} {(s.get('source') or '-'):<10} "f"{s.get('session_key') or '-'}")if len(candidates) > len(shown):- print(f" … {len(candidates) - len(shown)} more")+ print_truncated(len(candidates) - len(shown))if args.dry_run:print("Dry run — nothing deleted.")return@@ -674,7 +684,7 @@ def _cmd_prune_or_archive(db, args, action):print(f" {s['id']} {format_epoch(s.get('last_active')):<17} {s['source']:<10} {model:<24} "f"{s['message_count']:>4} msgs {(s.get('title') or '')[:36]}")if len(candidates) > len(shown):- print(f" … and {len(candidates) - len(shown)} more")+ print_truncated(len(candidates) - len(shown))if args.dry_run:print(f"Dry run — nothing {'deleted' if prune else 'archived'}.")returndiff --git a/tests/hermes_cli/test_sessions_list_truncation.py b/tests/hermes_cli/test_sessions_list_truncation.pynew file mode 100644index 00000000000..76a6e717fc9--- /dev/null+++ b/tests/hermes_cli/test_sessions_list_truncation.py@@ -0,0 +1,39 @@+"""``hermes sessions list`` tells the user when ``--limit`` cut the listing (#111989).++The cap is applied inside the SQL query, so the lister probes one row past it; the footer+must appear only when that probe row exists.+"""++from argparse import Namespace++import pytest++from hermes_cli import sessions_cmd+++def db(tmp_path):+ from hermes_state import SessionDB+ db = SessionDB(db_path=tmp_path / "state.db")+ for i in range(6):+ db.create_session(f"sess_{i}", "cli")+ db.append_message(f"sess_{i}", "user", f"hello {i}")+ yield db+ db.close()+++def _list(db, limit, capsys):+ sessions_cmd._cmd_list(db, Namespace(limit=limit, source=None, workspace=None))+ return capsys.readouterr().out+++def test_footer_when_more_sessions_than_limit(db, capsys):+ out = _list(db, 4, capsys)+ ids = [line.split()[-1] for line in out.splitlines() if line.startswith("hello")]+ assert len(ids) == 4 # the probe row is never rendered+ assert "… more not shown (use --limit 8 to see more)" in out+++def test_no_footer_when_listing_fits(db, capsys):+ assert "more" not in _list(db, 6, capsys) # exactly the limit+ assert "more" not in _list(db, 20, capsys) # fewer than the limitdiff --git a/website/docs/user-guide/sessions.md b/website/docs/user-guide/sessions.mdindex 32389d862b0..ffedb37b2d0 100644--- a/website/docs/user-guide/sessions.md+++ b/website/docs/user-guide/sessions.md@@ -320,6 +320,8 @@ hermes sessions list --source telegramhermes sessions list --limit 50```+When more sessions exist than `--limit` allows, the listing ends with a `… more not shown (use --limit N to see more)` footer, so a capped page is never mistaken for the full list.+When sessions have titles, the output shows titles, previews, and relative timestamps:```