The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): retain session worktrees when the viewer detaches
David Dudok de Wit22275bb226f1
diff --git a/hermes_cli/main_tui_launch.py b/hermes_cli/main_tui_launch.pyindex b785484f25f..641b7da4339 100644--- a/hermes_cli/main_tui_launch.py+++ b/hermes_cli/main_tui_launch.py@@ -459,9 +459,9 @@ def _launch_tui(with contextlib.suppress(OSError):os.unlink(active_session_file)if wt_info:- with contextlib.suppress(Exception):- from cli import _cleanup_worktree- _cleanup_worktree(wt_info)+ # Quitting detaches a viewer; the gateway may still be executing in+ # this checkout and future resumes retain its frozen cwd.+ print(f"Worktree retained for this session: {wt_info['path']}", file=sys.stderr)# Exit code 42 = TUI requested an update. Relaunch as `hermes update`;# preserve_inherited=False keeps --tui and other flags out of the subcommand.diff --git a/tests/hermes_cli/test_gateway_launch_lifetime.py b/tests/hermes_cli/test_gateway_launch_lifetime.pynew file mode 100644index 00000000000..9e01c09fa06--- /dev/null+++ b/tests/hermes_cli/test_gateway_launch_lifetime.py@@ -0,0 +1,29 @@+"""Detached owners must not lose the checkout their session still uses."""+from pathlib import Path+import subprocess+import sys++import pytest+++def test_tui_detach_preserves_real_clean_worktree(tmp_path, monkeypatch):+ from hermes_cli import main_tui_launch+ repo = tmp_path / 'repo'+ repo.mkdir()+ subprocess.run(['git', 'init', '-q', str(repo)], check=True)+ subprocess.run(['git', '-C', str(repo), '-c', 'user.name=Test', '-c', '[email protected]',+ 'commit', '--allow-empty', '-qm', 'fixture'], check=True)+ checkout = tmp_path / 'worktree'+ subprocess.run(['git', '-C', str(repo), 'worktree', 'add', '-qb', 'fixture-work', str(checkout)], check=True)+ monkeypatch.chdir(repo)+ monkeypatch.setenv('HERMES_PYTHON', sys.executable)+ monkeypatch.setattr(main_tui_launch, '_setup_tui_worktree', lambda: {+ 'path': str(checkout), 'repo_root': str(repo), 'branch': 'fixture-work'})+ monkeypatch.setattr(main_tui_launch, '_make_tui_argv', lambda *_: (['node'], Path('.')))+ monkeypatch.setattr(main_tui_launch.subprocess, 'call', lambda *_, **__: 0)+ monkeypatch.setattr(main_tui_launch, '_print_tui_exit_summary', lambda *_: None)+ with pytest.raises(SystemExit) as exited:+ main_tui_launch._launch_tui(worktree=True)+ assert exited.value.code == 0+ assert checkout.is_dir()+ assert (checkout / '.git').is_file()diff --git a/website/docs/user-guide/cli.md b/website/docs/user-guide/cli.mdindex fd9fa547736..a61f03f603d 100644--- a/website/docs/user-guide/cli.md+++ b/website/docs/user-guide/cli.md@@ -62,6 +62,10 @@ hermes -w -z "Fix issue #123" # Single query in worktree### Worktree cleanup`hermes -w` sessions create disposable worktrees under `<repo>/.worktrees/`.+With `hermes --tui -w`, closing the terminal detaches from the gateway-owned+session. Its worktree is retained even when clean: the turn may still be running+there, and resuming the session uses the same working directory. Review and prune+it after the session's work is finished.A conservative pruner runs automatically at startup (it only removes clean,fully-merged scratch trees past an age threshold), but preserved trees andmerged local branches still accumulate on busy machines. Reclaim them