Skip to content

The agent that grows with you

fix(cli): Ctrl+C clears a typed draft before interrupting a running turn

Tekniumbfa443c033aa
diff --git a/hermes_cli/cli_tui_mixin.py b/hermes_cli/cli_tui_mixin.py
index a7788d6261d..d3112761246 100644
--- a/hermes_cli/cli_tui_mixin.py
+++ b/hermes_cli/cli_tui_mixin.py
@@ -941,7 +941,7 @@ class CLITuiMixin:
return True
def _tui_clear_or_exit(self, event) -> None:
- """Idle press: clear text/images like bash; exit when everything is already empty."""
+ """Clear text/images like bash; exit when everything is already empty."""
if event.app.current_buffer.text or self._attached_images:
event.app.current_buffer.reset()
self._attached_images.clear()
@@ -952,8 +952,8 @@ class CLITuiMixin:
def _tui_handle_ctrl_c(self, event):
"""Ctrl+C priority: cancel voice recording → cancel foreground UI/overlay prompt →
- interrupt the running agent (first press) → force exit (second press within 2s) → when
- idle clear the draft or exit."""
+ clear a typed draft, even mid-run (a correction must never kill the turn) → interrupt
+ the running agent → force exit (second press within 2s) → when idle and empty, exit."""
now = time.time()
if self._tui_cancel_voice_recording(event):
return
@@ -965,7 +965,7 @@ class CLITuiMixin:
overlay_cleared = self._tui_clear_blocking_overlays(event)
if overlay_cleared and not (self._agent_running and self.agent):
return
- if self._agent_running and self.agent:
+ if self._agent_running and self.agent and not (event.app.current_buffer.text or self._attached_images):
if now - self._last_ctrl_c_time < 2.0:
print("\n" + t("cli.tui.force_exiting"))
self._should_exit = True
@@ -988,7 +988,7 @@ class CLITuiMixin:
overlay_cleared = self._tui_clear_blocking_overlays(event)
if overlay_cleared and not (self._agent_running and self.agent):
return
- if self._agent_running and self.agent:
+ if self._agent_running and self.agent and not (event.app.current_buffer.text or self._attached_images):
print("\n" + t("cli.tui.interrupting"))
request_hard_interrupt(self.agent)
else:
diff --git a/tests/hermes_cli/test_cli_ctrl_c_draft_priority.py b/tests/hermes_cli/test_cli_ctrl_c_draft_priority.py
new file mode 100644
index 00000000000..418e2e7ddac
--- /dev/null
+++ b/tests/hermes_cli/test_cli_ctrl_c_draft_priority.py
@@ -0,0 +1,53 @@
+"""Ctrl+C / Ctrl+Q in the classic CLI: a typed draft wins over interrupting a running turn.
+
+Mirrors the Ink TUI's ``resolveCtrlCComposerAction``: pressing Ctrl+C to wipe a half-typed
+follow-up must not kill the in-flight turn; the next press on an empty prompt interrupts.
+"""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+import pytest
+from prompt_toolkit.buffer import Buffer
+
+import hermes_cli.cli_tui_mixin as mixin_mod
+
+
+class _Cli(mixin_mod.CLITuiMixin):
+ def __init__(self):
+ self._agent_running = True
+ self.agent = object()
+ self._attached_images = []
+ self._last_ctrl_c_time = 0.0
+ self._should_exit = False
+
+ # Voice / modal / overlay layers sit above the draft check and are covered elsewhere.
+ _close_model_picker = _close_command_palette = _submit_slash_confirm_response = None
+
+ def _tui_cancel_voice_recording(self, event):
+ return False
+
+ def _tui_cancel_foreground_ui(self, event, closers):
+ return False
+
+ def _tui_clear_blocking_overlays(self, event):
+ return False
+
+
[email protected]("handler", ["_tui_handle_ctrl_c", "_tui_handle_ctrl_q"])
+def test_draft_is_cleared_before_a_running_turn_is_interrupted(monkeypatch, handler):
+ interrupts = []
+ monkeypatch.setattr(mixin_mod, "request_hard_interrupt", interrupts.append)
+ cli = _Cli()
+ buffer = Buffer()
+ buffer.text = "half typed follow-up"
+ app = SimpleNamespace(current_buffer=buffer, invalidate=lambda: None,
+ exit=lambda: setattr(cli, "_should_exit", True))
+ event = SimpleNamespace(app=app)
+
+ getattr(cli, handler)(event)
+ assert buffer.text == "" and interrupts == [] and not cli._should_exit
+
+ getattr(cli, handler)(event)
+ assert interrupts == [cli.agent] and not cli._should_exit
diff --git a/website/docs/user-guide/cli.md b/website/docs/user-guide/cli.md
index 5af8fc9e07f..1e7a1145289 100644
--- a/website/docs/user-guide/cli.md
+++ b/website/docs/user-guide/cli.md
@@ -201,7 +201,7 @@ On macOS, `F6`/`F7` mean the physical function keys, not the media/system contro
| `Ctrl+G` | Open the current input buffer in `$EDITOR` (vim/nvim/nano/VS Code/etc.). Save and quit to send the edited text as the next prompt — ideal for long, multi-paragraph prompts. |
| `Ctrl+X Ctrl+E` | Emacs-style alternate binding for the external editor (same behavior as `Ctrl+G`). |
| `Ctrl+S` | **Stash the prompt.** Parks the current draft and clears the composer so you can send something else first. Press `Ctrl+S` again on an empty composer to bring the draft back (cursor at the end, attached images restored). Repeated presses build a stack rather than overwriting, so an earlier draft is never silently lost — with two or more stashed, `Ctrl+S` opens a browse panel (`↑`/`↓` to navigate, `Enter` to restore, `D` to discard, `Esc` or `Ctrl+S` to close). A `📌 N` badge in the status bar shows how many drafts are parked. Multi-line drafts round-trip exactly, including blank lines. The stash lives in memory for the session only — nothing is written to disk, since drafts often contain secrets. |
-| `Ctrl+C` | Interrupt agent (double-press within 2s to force exit) |
+| `Ctrl+C` | Clear a typed draft first (even while the agent works); with an empty prompt, interrupt the agent (double-press within 2s to force exit) |
| `Ctrl+T` / `F6` | Open the full-screen live work monitor (subagents and background processes) without losing the composer draft. The live dock appears automatically above the status bar; arrows select a worker or process, `Enter` shows its recent log, `s` steers a worker, and `x` requests stop with confirmation. See [Monitoring subagents](./features/delegation.md#monitoring-running-subagents-agents). |
| `Ctrl+R` / `F7` | Toggle the live work dock between its multi-row preview and a single summary line without moving composer focus. `Ctrl+R` is the reliable fallback when macOS reserves the function-key row. Besides subagents and background processes, the dock shows a standing `/goal` (active, parked or paused, with turns used) on its top row and the prompts waiting in `/queue` on its bottom rows. |
| `Ctrl+D` | Exit |
@@ -391,7 +391,7 @@ Where the terminal cannot distinguish them, `Alt+Enter` and `Ctrl+J` continue to
While the agent is working, you can send a correction without starting a new turn:
- **Type a new message + Enter** — redirects the active turn using your correction
-- **`Ctrl+C`** — interrupt the current operation (press twice within 2s to force exit)
+- **`Ctrl+C`** — interrupt the current operation (press twice within 2s to force exit); if the prompt holds a draft, the first press clears it and the turn keeps running
- Completed tool work and reasoning already shown stay in context
- A running tool reaches its safe boundary before the correction is applied