Skip to content

The agent that grows with you

refactor(hermes_cli): drop dead module-level clarify/approval callbacks, dedupe secret result dicts

Teknium1659c5c58cf4
diff --git a/hermes_cli/callbacks.py b/hermes_cli/callbacks.py
index 4e37e621917..b8a0c897ab9 100644
--- a/hermes_cli/callbacks.py
+++ b/hermes_cli/callbacks.py
@@ -1,4 +1,4 @@
-"""Interactive prompt callbacks for terminal_tool integration."""
+"""Secret-capture prompt for the interactive CLI (``_secret_capture_callback`` backend)."""
import queue
import time as _time
@@ -10,36 +10,33 @@ from hermes_constants import display_hermes_home
def _invalidate(cli) -> None:
- if hasattr(cli, "_app") and cli._app:
+ if getattr(cli, "_app", None):
cli._app.invalidate()
def _clear_secret_input(cli) -> None:
"""Drop stale draft input so Enter never stores it as the secret."""
- if hasattr(cli, "_clear_secret_input_buffer"):
- try:
+ try:
+ if hasattr(cli, "_clear_secret_input_buffer"):
cli._clear_secret_input_buffer()
- except Exception:
- pass
- elif hasattr(cli, "_app") and cli._app:
- try:
+ elif getattr(cli, "_app", None):
cli._app.current_buffer.reset()
- except Exception:
- pass
+ except Exception:
+ pass
+
+
+def _skipped(var_name: str, reason: str, message: str) -> dict:
+ return {
+ "success": True, "reason": reason, "stored_as": var_name,
+ "validated": False, "skipped": True, "message": message,
+ }
def _secret_result(var_name: str, value: str) -> dict:
"""Store ``value`` (or report a skip when empty) and build the callback result dict."""
if not value:
cprint(f"\n{_DIM} ⏭ Secret entry skipped{_RST}")
- return {
- "success": True,
- "reason": "cancelled",
- "stored_as": var_name,
- "validated": False,
- "skipped": True,
- "message": "Secret setup was skipped.",
- }
+ return _skipped(var_name, "cancelled", "Secret setup was skipped.")
stored = save_env_value_secure(var_name, value)
cprint(f"\n{_DIM} ✓ Stored secret in {display_hermes_home()}/.env as {var_name}{_RST}")
return {
@@ -49,56 +46,6 @@ def _secret_result(var_name: str, value: str) -> dict:
}
-def clarify_callback(cli, question, choices, multi_select=False):
- """Prompt for clarifying question through the TUI.
-
- Blocks until the user responds; returns the choice or a timeout message. ``multi_select``
- shows checkboxes (Space to toggle, Enter to confirm).
- """
- from cli import CLI_CONFIG
- from tools.clarify_gateway import resolve_clarify_timeout
-
- # Canonical clarify timeout, shared with the gateway/TUI path. `<= 0`
- # means unlimited (never auto-skip mid-think) → a null deadline.
- timeout = resolve_clarify_timeout(CLI_CONFIG)
- response_queue = queue.Queue()
- is_open_ended = not choices
- effective_multi = multi_select and not is_open_ended
-
- cli._clarify_state = {
- "question": question,
- "choices": choices if not is_open_ended else [],
- "selected": 0,
- "multi_select": effective_multi,
- "selected_indices": set() if effective_multi else None,
- "response_queue": response_queue,
- }
- cli._clarify_deadline = None if timeout <= 0 else _time.monotonic() + timeout
- cli._clarify_freetext = is_open_ended
- _invalidate(cli)
-
- while True:
- try:
- result = response_queue.get(timeout=1)
- cli._clarify_deadline = None
- return result
- except queue.Empty:
- # None deadline = unlimited: never auto-skip, just keep polling.
- if cli._clarify_deadline is not None and cli._clarify_deadline - _time.monotonic() <= 0:
- break
- _invalidate(cli)
-
- cli._clarify_state = None
- cli._clarify_freetext = False
- cli._clarify_deadline = None
- _invalidate(cli)
- cprint(f"\n{_DIM}(clarify timed out after {timeout}s — agent will decide){_RST}")
- return (
- "The user did not provide a response within the time limit. "
- "Use your best judgement to make the choice and proceed."
- )
-
-
def prompt_for_secret(cli, var_name: str, prompt: str, metadata=None) -> dict:
"""Prompt for a secret value through the TUI (e.g. API keys for skills).
@@ -116,16 +63,14 @@ def prompt_for_secret(cli, var_name: str, prompt: str, metadata=None) -> dict:
value = ""
return _secret_result(var_name, value)
- timeout = 120
response_queue = queue.Queue()
-
cli._secret_state = {
"var_name": var_name,
"prompt": prompt,
"metadata": metadata or {},
"response_queue": response_queue,
}
- cli._secret_deadline = _time.monotonic() + timeout
+ cli._secret_deadline = _time.monotonic() + 120
if hasattr(cli, "_ring_bell"):
cli._ring_bell(prompt=True, context=f"secret needed ({var_name})")
_clear_secret_input(cli)
@@ -149,62 +94,4 @@ def prompt_for_secret(cli, var_name: str, prompt: str, metadata=None) -> dict:
_clear_secret_input(cli)
_invalidate(cli)
cprint(f"\n{_DIM} ⏱ Timeout — secret capture cancelled{_RST}")
- return {
- "success": True,
- "reason": "timeout",
- "stored_as": var_name,
- "validated": False,
- "skipped": True,
- "message": "Secret setup timed out and was skipped.",
- }
-
-
-def approval_callback(cli, command: str, description: str) -> str:
- """Prompt for dangerous command approval through the TUI.
-
- Shows a selection UI with choices: once / session / always / deny. When the command is longer
- than 70 characters, a "view" option is included so the user can reveal the full text before
- deciding.
- """
- lock = getattr(cli, "_approval_lock", None)
- if lock is None:
- import threading
- cli._approval_lock = threading.Lock()
- lock = cli._approval_lock
-
- with lock:
- from cli import CLI_CONFIG
- timeout = CLI_CONFIG.get("approvals", {}).get("timeout", 300)
- response_queue = queue.Queue()
- choices = ["once", "session", "always", "deny"]
- if len(command) > 70:
- choices.append("view")
-
- cli._approval_state = {
- "command": command,
- "description": description,
- "choices": choices,
- "selected": 0,
- "response_queue": response_queue,
- }
- cli._approval_deadline = _time.monotonic() + timeout
- _invalidate(cli)
-
- while True:
- try:
- result = response_queue.get(timeout=1)
- except queue.Empty:
- if cli._approval_deadline - _time.monotonic() <= 0:
- break
- _invalidate(cli)
- continue
- cli._approval_state = None
- cli._approval_deadline = 0
- _invalidate(cli)
- return result
-
- cli._approval_state = None
- cli._approval_deadline = 0
- _invalidate(cli)
- cprint(f"\n{_DIM} ⏱ Timeout — denying command{_RST}")
- return "timeout"
+ return _skipped(var_name, "timeout", "Secret setup timed out and was skipped.")