The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(cli): move resume-arg steps and panel wrap helpers to siblings
Teknium7c74dc87e4cb
diff --git a/hermes_cli/cli_tui_mixin.py b/hermes_cli/cli_tui_mixin.pyindex 39fd414b4a8..61c1dd7387c 100644--- a/hermes_cli/cli_tui_mixin.py+++ b/hermes_cli/cli_tui_mixin.py@@ -39,6 +39,7 @@ from prompt_toolkit.widgets import TextAreafrom typing import Optionalfrom hermes_cli.cli_footer_split import FooterSplit+from hermes_cli.cli_tui_wrap import _prefix_wrapped_rows, _wrap_rows# Rows below an overlay panel taken by spinner/tool-progress, status bar, input, separators and# prompt symbol (measured ~6 during live PTY approval prompts) — shared by every panel budget.@@ -110,25 +111,6 @@ class _Panel:return self.lines-def _wrap_rows(wrap, items, width, indent) -> list[tuple[int, str]]:- """``(index, wrapped_line)`` pairs so selected styling can be re-applied per row."""- return [(i, w) for i, label in enumerate(items) for w in wrap(label, width, subsequent_indent=indent)]---def _prefix_wrapped_rows(wrap, label, width, first_prefix, indent) -> list[str]:- """Wrap ``label``, then prefix the rows with ``first_prefix`` / ``indent``.-- The prefix is applied *after* wrapping on purpose. Folding it into the- string handed to the wrapper charges those columns against the label's own- width budget — so a selected row wraps one line early and strands the ``❯``- cursor on a row of its own — and whitespace-trimming wrappers drop the- leading indent entirely, leaving long unselected labels flush against the- panel border, out of alignment with every other row.- """- rows = wrap(label, width)- return [(first_prefix if i == 0 else indent) + row for i, row in enumerate(rows)]--class CLITuiMixin:"""prompt_toolkit TUI construction, key-binding handlers, and overlay display fragments."""diff --git a/hermes_cli/cli_tui_wrap.py b/hermes_cli/cli_tui_wrap.pynew file mode 100644index 00000000000..f40aa03ebbb--- /dev/null+++ b/hermes_cli/cli_tui_wrap.py@@ -0,0 +1,20 @@+"""Row-wrapping helpers for the classic CLI's prompt_toolkit panels (moved from ``cli_tui_mixin``)."""+++def _wrap_rows(wrap, items, width, indent) -> list[tuple[int, str]]:+ """``(index, wrapped_line)`` pairs so selected styling can be re-applied per row."""+ return [(i, w) for i, label in enumerate(items) for w in wrap(label, width, subsequent_indent=indent)]+++def _prefix_wrapped_rows(wrap, label, width, first_prefix, indent) -> list[str]:+ """Wrap ``label``, then prefix the rows with ``first_prefix`` / ``indent``.++ The prefix is applied *after* wrapping on purpose. Folding it into the+ string handed to the wrapper charges those columns against the label's own+ width budget — so a selected row wraps one line early and strands the ``❯``+ cursor on a row of its own — and whitespace-trimming wrappers drop the+ leading indent entirely, leaving long unselected labels flush against the+ panel border, out of alignment with every other row.+ """+ rows = wrap(label, width)+ return [(first_prefix if i == 0 else indent) + row for i, row in enumerate(rows)]diff --git a/hermes_cli/main.py b/hermes_cli/main.pyindex 4ab26c77bbd..3907a239f72 100644--- a/hermes_cli/main.py+++ b/hermes_cli/main.py@@ -1506,42 +1506,6 @@ def _apply_in_dir(args) -> None:args.no_restore_cwd = True-def _import_foreign_resume(args) -> None:- """--resume @claude / @codex: import a foreign session and resume it."""- _resume_foreign = getattr(args, "resume", None)- if not (isinstance(_resume_foreign, str) and _resume_foreign.strip().lower() in ("@claude", "@codex")):- return- from hermes_cli.foreign_sessions import import_foreign_session, pick_foreign_session-- _picked = pick_foreign_session(_resume_foreign.strip().lower().lstrip("@"))- if _picked is None:- sys.exit(1)- try:- _imported_id = import_foreign_session(_picked.source, _picked.path)- except ValueError as e:- print(f"Error: {e}")- sys.exit(1)- print(f"✓ Imported as {_imported_id} — resuming it now.")- print(f" (later: hermes --resume {_imported_id})")- args.resume = _imported_id---def _recreate_resumed_tui_worktree(args) -> None:- """A resumed session whose frozen cwd is a ``--tui -w`` tree that quit removed gets that tree- back before attaching, or the owner refuses every turn ``workspace_unavailable`` (N8)."""- if not getattr(args, "resume", None) or getattr(args, "worktree", False):- return- cwd = ""- with _session_db() as db: # a store error is swallowed: nothing to recreate- cwd = ((db.get_session(args.resume) or {}).get("cwd") or "").strip()- if not cwd or os.path.isdir(cwd):- return- from hermes_cli.tui_worktree_resume import recreate_tui_worktree- tree = recreate_tui_worktree(cwd, args.resume)- if tree:- print(f"↪ recreated the session's worktree: {tree}")--def _resolve_chat_session_args(args, use_tui: bool) -> None:"""Normalize --in / --resume / --continue on ``args`` before agent init.@@ -1569,14 +1533,15 @@ def _resolve_chat_session_args(args, use_tui: bool) -> None:_resolve_continue_arg(args, use_tui=use_tui)- _import_foreign_resume(args)+ from hermes_cli.main_resume_args import import_foreign_resume, recreate_resumed_tui_worktree+ import_foreign_resume(args)resume_val = getattr(args, "resume", None)if resume_val:# On miss keep the original so _init_agent reports "Session not found" with it.args.resume = _resolve_session_by_name_or_id(resume_val) or resume_val- _recreate_resumed_tui_worktree(args)+ recreate_resumed_tui_worktree(args)# cd back into a resumed session's recorded cwd (opt out: --no-restore-cwd;# --worktree owns its own dir). A missing dir warns and stays put.diff --git a/hermes_cli/main_resume_args.py b/hermes_cli/main_resume_args.pynew file mode 100644index 00000000000..81ce3cb76ba--- /dev/null+++ b/hermes_cli/main_resume_args.py@@ -0,0 +1,42 @@+"""``hermes chat`` resume-argument steps split out of ``hermes_cli.main``: ``--resume @claude/@codex``+imports, and recreating a removed ``--tui -w`` worktree a resumed session needs (N8)."""++import os+import sys+++def import_foreign_resume(args) -> None:+ """--resume @claude / @codex: import a foreign session and resume it."""+ _resume_foreign = getattr(args, "resume", None)+ if not (isinstance(_resume_foreign, str) and _resume_foreign.strip().lower() in ("@claude", "@codex")):+ return+ from hermes_cli.foreign_sessions import import_foreign_session, pick_foreign_session++ _picked = pick_foreign_session(_resume_foreign.strip().lower().lstrip("@"))+ if _picked is None:+ sys.exit(1)+ try:+ _imported_id = import_foreign_session(_picked.source, _picked.path)+ except ValueError as e:+ print(f"Error: {e}")+ sys.exit(1)+ print(f"✓ Imported as {_imported_id} — resuming it now.")+ print(f" (later: hermes --resume {_imported_id})")+ args.resume = _imported_id+++def recreate_resumed_tui_worktree(args) -> None:+ """A resumed session whose frozen cwd is a ``--tui -w`` tree that quit removed gets that tree+ back before attaching, or the owner refuses every turn ``workspace_unavailable`` (N8)."""+ if not getattr(args, "resume", None) or getattr(args, "worktree", False):+ return+ cwd = ""+ from hermes_cli.main import _session_db+ with _session_db() as db: # a store error is swallowed: nothing to recreate+ cwd = ((db.get_session(args.resume) or {}).get("cwd") or "").strip()+ if not cwd or os.path.isdir(cwd):+ return+ from hermes_cli.tui_worktree_resume import recreate_tui_worktree+ tree = recreate_tui_worktree(cwd, args.resume)+ if tree:+ print(f"↪ recreated the session's worktree: {tree}")