mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
fix(tui): report actual session on exit
This commit is contained in:
committed by
Teknium
parent
164e33aa46
commit
653b5ec128
@@ -44,6 +44,7 @@ Usage:
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -759,9 +760,20 @@ def _resolve_session_by_name_or_id(name_or_id: str) -> Optional[str]:
|
||||
return None
|
||||
|
||||
|
||||
def _print_tui_exit_summary(session_id: Optional[str]) -> None:
|
||||
def _read_tui_active_session_file(path: Optional[str]) -> Optional[str]:
|
||||
if not path:
|
||||
return None
|
||||
try:
|
||||
data = json.loads(Path(path).read_text(encoding="utf-8"))
|
||||
sid = str(data.get("session_id") or "").strip()
|
||||
return sid or None
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _print_tui_exit_summary(session_id: Optional[str], active_session_file: Optional[str] = None) -> None:
|
||||
"""Print a shell-visible epilogue after TUI exits."""
|
||||
target = session_id or _resolve_last_session(source="tui")
|
||||
target = _read_tui_active_session_file(active_session_file) or session_id or _resolve_last_session(source="tui")
|
||||
if not target:
|
||||
return
|
||||
|
||||
@@ -1036,7 +1048,13 @@ def _launch_tui(
|
||||
"""Replace current process with the TUI."""
|
||||
tui_dir = PROJECT_ROOT / "ui-tui"
|
||||
|
||||
import tempfile
|
||||
|
||||
env = os.environ.copy()
|
||||
active_session_file = os.path.join(
|
||||
tempfile.gettempdir(), f"hermes-tui-active-session-{os.getpid()}.json"
|
||||
)
|
||||
env["HERMES_TUI_ACTIVE_SESSION_FILE"] = active_session_file
|
||||
env["HERMES_PYTHON_SRC_ROOT"] = os.environ.get(
|
||||
"HERMES_PYTHON_SRC_ROOT", str(PROJECT_ROOT)
|
||||
)
|
||||
@@ -1070,7 +1088,12 @@ def _launch_tui(
|
||||
code = 130
|
||||
|
||||
if code in (0, 130):
|
||||
_print_tui_exit_summary(resume_session_id)
|
||||
_print_tui_exit_summary(resume_session_id, active_session_file)
|
||||
|
||||
try:
|
||||
os.unlink(active_session_file)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
sys.exit(code)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user