feat: stop and rename a session from its tmux window

Add "stop" and "rename" to the Alt+p tool palette so a session can be
managed from inside its own harness window, mirroring the TUI's s/r keys:

- stop kills the harness window (stop_session_for_window).
- rename prompts for a nickname, pre-filled with the current one. The
  name is read from /dev/tty via readline (the fzf pipe leaves our stdin
  spent) and never passes through tmux's command parser, so there's
  nothing to quote-escape.

Extract require_session_id_for_window as the shared resolve-or-raise
guard behind the tool/stop/rename branches, dropping the duplicated
"not an hqt session window" check.

Also removes the now-shipped feature plans and specs under docs/.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 10:55:27 -04:00
parent ff357156d0
commit fc95bf9830
23 changed files with 243 additions and 9370 deletions
+98
View File
@@ -75,6 +75,102 @@ def test_tool_cmd_clone_dispatches_to_clone(monkeypatch, tmp_path):
assert calls["clone"] == "hqt-5"
def test_tool_cmd_stop_dispatches_to_stop(monkeypatch, tmp_path):
monkeypatch.setattr(
"hqt.config.get_settings", lambda: Settings(db_path=tmp_path / "t.db")
)
calls = {}
async def fake_stop(self, window):
calls["stop"] = window
monkeypatch.setattr(
"hqt.sessions.service.SessionService.stop_session_for_window", fake_stop
)
result = CliRunner().invoke(cli.main, ["tool", "stop", "hqt-5"])
assert result.exit_code == 0, result.output
assert calls["stop"] == "hqt-5"
def test_tool_cmd_rename_applies_new_nickname(monkeypatch, tmp_path):
from types import SimpleNamespace
monkeypatch.setattr(
"hqt.config.get_settings", lambda: Settings(db_path=tmp_path / "t.db")
)
monkeypatch.setattr(
"hqt.sessions.service.SessionService.session_id_for_window",
lambda self, window: 5,
)
monkeypatch.setattr(
"hqt.sessions.service.SessionService.get_session",
lambda self, sid: SimpleNamespace(nickname="old"),
)
# Prefill the prompt with the current nickname; user edits to "new".
seen = {}
def fake_read(prompt, prefill=""):
seen["prefill"] = prefill
return "new"
monkeypatch.setattr(cli, "_read_line_from_tty", fake_read)
calls = {}
monkeypatch.setattr(
"hqt.sessions.service.SessionService.rename_session",
lambda self, sid, nickname: calls.setdefault("args", (sid, nickname)),
)
result = CliRunner().invoke(cli.main, ["tool", "rename", "hqt-5"])
assert result.exit_code == 0, result.output
assert seen["prefill"] == "old"
assert calls["args"] == (5, "new")
def test_tool_cmd_rename_aborted_leaves_name(monkeypatch, tmp_path):
from types import SimpleNamespace
monkeypatch.setattr(
"hqt.config.get_settings", lambda: Settings(db_path=tmp_path / "t.db")
)
monkeypatch.setattr(
"hqt.sessions.service.SessionService.session_id_for_window",
lambda self, window: 5,
)
monkeypatch.setattr(
"hqt.sessions.service.SessionService.get_session",
lambda self, sid: SimpleNamespace(nickname="old"),
)
monkeypatch.setattr(cli, "_read_line_from_tty", lambda prompt, prefill="": None)
calls = {}
monkeypatch.setattr(
"hqt.sessions.service.SessionService.rename_session",
lambda self, sid, nickname: calls.setdefault("args", (sid, nickname)),
)
result = CliRunner().invoke(cli.main, ["tool", "rename", "hqt-5"])
assert result.exit_code == 0, result.output
assert "args" not in calls # None return = aborted, no DB write
def test_tool_cmd_rename_unknown_window_raises(monkeypatch, tmp_path):
monkeypatch.setattr(
"hqt.config.get_settings", lambda: Settings(db_path=tmp_path / "t.db")
)
monkeypatch.setattr(
"hqt.sessions.service.SessionService.session_id_for_window",
lambda self, window: None,
)
result = CliRunner().invoke(cli.main, ["tool", "rename", "hqt-5"])
assert result.exit_code == 1
assert "not an hqt session window" in result.output
def test_tool_cmd_reset_windows_dispatches_to_manager(monkeypatch, tmp_path):
monkeypatch.setattr(
"hqt.config.get_settings", lambda: Settings(db_path=tmp_path / "t.db")
@@ -150,6 +246,8 @@ def test_palette_cmd_shows_popup_for_session_window(monkeypatch, tmp_path):
popup_cmd = argv[-1]
assert "fzf" in popup_cmd
assert "nvim" in popup_cmd and "clone" in popup_cmd
assert "stop" in popup_cmd
assert "rename" in popup_cmd
assert "reset-windows" in popup_cmd
# the window is baked into the command for `hqt tool {} <window>`
assert "hqt-5" in popup_cmd