The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(cli): /loop gets a live-work dock row with a ticking countdown
Tekniumcba95563d41b
diff --git a/hermes_cli/cli_loops_mixin.py b/hermes_cli/cli_loops_mixin.pyindex 6a2da8ec63e..c7a0a066d81 100644--- a/hermes_cli/cli_loops_mixin.py+++ b/hermes_cli/cli_loops_mixin.py@@ -723,8 +723,9 @@ class CLILoopsMixin:_cprint(f" {_DIM}{t('cli.loop.paused_interrupted')}{_RST}")returndecision = mgr.complete_tick(self._last_assistant_response_text())+ # With the live-work dock up its loop row carries the countdown; the one-shot line would go stale.if (not _print_decision_message(decision) and decision.get("status") == "active"- and mgr.state is not None):+ and mgr.state is not None and getattr(self, "_subagent_monitor", None) is None):_cprint(f" {_DIM}{t('cli.loop.remaining', label=mgr.state.remaining_label())}{_RST}")def _maybe_continue_goal_after_turn(self) -> None:diff --git a/hermes_cli/cli_session_dock.py b/hermes_cli/cli_session_dock.pyindex da30559f8c5..e62509d4b4c 100644--- a/hermes_cli/cli_session_dock.py+++ b/hermes_cli/cli_session_dock.py@@ -1,11 +1,15 @@-"""Goal + queued-prompt rows for the classic CLI live-work dock.+"""Goal, loop + queued-prompt rows for the classic CLI live-work dock.-Sibling of ``cli_process_dock``: the dock paints an active ``/goal`` and the prompts waiting in-``/queue`` under the subagent and process blocks, so both are visible while the agent works-instead of only through ``/goal status`` and ``/queue list``.+Sibling of ``cli_process_dock``: the dock paints an active ``/goal``, a standing ``/loop`` with its+countdown, and the prompts waiting in ``/queue`` around the subagent and process blocks, so they are+visible while the agent works instead of only through ``/goal status``, ``/loop status`` and+``/queue list``."""from __future__ import annotations+import math+import time+# Queued prompts drain one per turn; past this many the dock shows a ``+N more`` line.QUEUE_ROWS = 3@@ -22,6 +26,43 @@ def goal_line(cli) -> str:return mgr.status_line()+def countdown(seconds: float) -> str:+ """Time left until the next wakeup, rounded UP: whole minutes until the last one, then seconds.++ Minute steps keep an idle prompt's dock to one repaint a minute (the spinner thread repaints only+ when the dock text changes); per-second repaints of a 45-minute wait would fight terminal viewport+ restoration for nothing.+ """+ left = max(0, math.ceil(seconds))+ if left < 60:+ return f"{left}s"+ hours, minutes = divmod(math.ceil(left / 60), 60)+ return f"{hours}h{minutes:02d}m" if hours else f"{minutes}m"+++def loop_row(cli, now: float | None = None) -> tuple[str, str, str]:+ """``(badge, line, prompt)`` for an active or paused /loop, else ``('', '', '')``.++ ``line`` is the expanded dock row (``↻ loop · every 5m · 2 runs · next in 4m · <prompt>``),+ ``badge`` the collapsed heading's count fragment (``↻ loop next in 4m``). Same rule as :func:`goal_line`:+ only the manager the CLI already holds is read, never state.db.+ """+ mgr = getattr(cli, "_loop_manager", None)+ if mgr is None or mgr.session_id != getattr(cli, "session_id", None) or not mgr.has_loop():+ return "", "", ""+ s = mgr.state+ runs = f"{s.ticks_fired}/{s.times} runs" if s.times else f"{s.ticks_fired} run{'s' if s.ticks_fired != 1 else ''}"+ if s.status == "paused":+ reason = f" · {s.paused_reason}" if s.paused_reason else ""+ return "⏸ loop paused", f"⏸ loop paused{reason} · {runs} · {s.prompt}", s.prompt+ if s.awaiting_response:+ when = "running now"+ else:+ remaining = s.next_due_at - (time.time() if now is None else now)+ when = f"next in {countdown(remaining)}" if remaining > 0 else "due, waiting for idle"+ return f"↻ loop {when}", f"↻ loop · {s.cadence_label()} · {runs} · {when} · {s.prompt}", s.prompt++def _prompt_text(item) -> str:if isinstance(item, tuple): # (text, images) from an image-attached submititem = item[0]diff --git a/hermes_cli/cli_subagent_monitor.py b/hermes_cli/cli_subagent_monitor.pyindex a9ceb8d0d4a..18126e89fef 100644--- a/hermes_cli/cli_subagent_monitor.py+++ b/hermes_cli/cli_subagent_monitor.py@@ -1,6 +1,6 @@-"""Classic CLI live-work dock (subagents, background processes, active goal, queued prompts) and-scoped controls; no agent-loop state is changed. Process rows come from ``cli_process_dock``,-goal/queue rows from ``cli_session_dock``."""+"""Classic CLI live-work dock (subagents, background processes, active goal, standing loop, queued+prompts) and scoped controls; no agent-loop state is changed. Process rows come from+``cli_process_dock``, goal/loop/queue rows from ``cli_session_dock``."""from __future__ import annotationsimport json@@ -32,6 +32,9 @@ class SubagentMonitor:self.entries = []self.processes = []self.goal = ''+ self.loop = ''+ self.loop_badge = ''+ self.loop_prompt = ''self.queued = []self.selected_id = Noneself._signature = None@@ -42,7 +45,7 @@ class SubagentMonitor:@propertydef has_rows(self):- return bool(self.entries or self.processes or self.goal or self.queued)+ return bool(self.entries or self.processes or self.goal or self.loop or self.queued)@propertydef roster(self):@@ -78,13 +81,17 @@ class SubagentMonitor:row.pop('running_seconds', None)processes = procs.process_rows(now)goal = session_rows.goal_line(self.cli)+ loop_badge, loop, loop_prompt = session_rows.loop_row(self.cli, now)queued = session_rows.queued_prompts(self.cli)- signature = json.dumps([entries, processes, goal, queued], sort_keys=True, default=str)+ signature = json.dumps([entries, processes, goal, loop, queued], sort_keys=True, default=str)changed = signature != self._signatureself._signature = signatureself.entries = entriesself.processes = processesself.goal = goal+ self.loop = loop+ self.loop_badge = loop_badge+ self.loop_prompt = loop_promptself.queued = queuedif self.selected is None:roster = self.roster@@ -128,7 +135,7 @@ class SubagentMonitor:def _counts(self, *, session=True):"""Count fragment: ``2 live``, ``1 proc``, ``2 live · 3 procs``; the collapsed heading- (``session=True``) adds ``goal active|paused|parked`` and ``N queued``."""+ (``session=True``) adds ``goal active|paused|parked``, the loop badge and ``N queued``."""parts = []if self.entries:parts.append(t('cli.subagents.count_live', count=len(self.entries)))@@ -142,6 +149,8 @@ class SubagentMonitor:if session and self.goal:parts.append(t('cli.subagents.goal_parked' if self.goal.startswith('⏳') else'cli.subagents.goal_paused' if self.goal.startswith('⏸') else 'cli.subagents.goal_active'))+ if session and self.loop_badge:+ parts.append(self.loop_badge)if session and self.queued:parts.append(t('cli.subagents.count_queued', count=len(self.queued)))return ' · '.join(parts)@@ -163,7 +172,8 @@ class SubagentMonitor:return self._agent_activity(self.entries[0])if self.processes:return procs.process_activity(self.processes[0])- return self.goal or t('cli.subagents.next_queued', text=self.queued[0])+ # The loop's state is already the heading's badge; its prompt is the activity.+ return self.goal or self.loop_prompt or t('cli.subagents.next_queued', text=self.queued[0])def dock_text(self, *, columns, rows):if not self.has_rows:@@ -192,7 +202,7 @@ class SubagentMonitor:heading += ' · ' + _clip(activity, room)return _clip(' ' + heading, max(0, columns))columns = max(0, columns - 2)- lines = [_clip(f' {self.goal}', columns)] if self.goal else []+ lines = [_clip(f' {row}', columns) for row in (self.goal, self.loop) if row]budget = max(1, min(4, (rows - 10) // 3))# Both blocks present: split the row budget so neither hides the other entirely.agent_budget = budget if not self.processes else max(1, budget - max(1, budget // 2))diff --git a/tests/hermes_cli/test_session_dock.py b/tests/hermes_cli/test_session_dock.pyindex e30441249df..abea3fdc838 100644--- a/tests/hermes_cli/test_session_dock.py+++ b/tests/hermes_cli/test_session_dock.py@@ -105,3 +105,31 @@ def test_dock_drops_the_prompt_a_turn_takes_from_the_queue_before_the_turn_runs(assert cli.chat.call_args.args[0] == "hello"assert seen == [[]]assert not monitor.has_rows+++def test_dock_loop_row_counts_down_to_the_next_wakeup(hermes_home):+ """A standing /loop gets a dock row whose countdown moves with the clock (it used to be a+ one-shot ``next in 45m`` transcript line that never changed)."""+ from hermes_cli.cli_subagent_monitor import SubagentMonitor+ from hermes_cli.loops import LoopManager++ mgr = LoopManager(session_id="sid-a")+ mgr.set("check the deploy", interval_seconds=45 * 60)+ mgr.fire_tick()+ mgr.complete_tick("deploy still running")+ due = mgr.state.next_due_at+ dock = SubagentMonitor(SimpleNamespace(agent=None, session_id="sid-a", _loop_manager=mgr,+ _pending_input=queue.Queue()))++ assert dock.refresh(now=due - 45 * 60) and dock.has_rows+ assert dock.dock_text(columns=100, rows=40).strip() == "↻ loop · every 45m · 1 run · next in 45m · check the deploy"+ assert dock.refresh(now=due - 30 * 60 + 1) and "next in 30m" in dock.loop # rounds up, never early+ assert dock.refresh(now=due - 42) and "next in 42s" in dock.loop+ assert not dock.refresh(now=due - 42) # unchanged text → no repaint+ dock.collapsed = True+ assert dock.dock_text(columns=100, rows=40).strip() == "↻ loop next in 42s · Ctrl+R restore · check the deploy"++ mgr.pause("user-paused")+ assert dock.refresh(now=due) and dock.loop == "⏸ loop paused · user-paused · 1 run · check the deploy"+ mgr.clear()+ assert dock.refresh(now=due) and not dock.has_rows