The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Inspired by Factory Droid: /queue prompts are now listable, editable, and reorderable before they run
Tekniumce318290bddd
diff --git a/hermes_cli/cli_loops_mixin.py b/hermes_cli/cli_loops_mixin.pyindex 1af5ef97202..cfb366a98fd 100644--- a/hermes_cli/cli_loops_mixin.py+++ b/hermes_cli/cli_loops_mixin.py@@ -18,6 +18,20 @@ def _preview(payload: str) -> str:return f"{payload[:80]}{'...' if len(payload) > 80 else ''}"+_QUEUE_USAGE = ("Usage: /queue <prompt> | /queue list | /queue edit N <prompt> | "+ "/queue rm N | /queue move FROM TO | /queue clear")+# management verb -> (handler, takes a leading item index). Verbs without an index are+# only management when they stand alone; index verbs only when a number follows.+_QUEUE_VERBS: dict[str, tuple[str, bool]] = {+ "list": ("_queue_list", False), "ls": ("_queue_list", False), "show": ("_queue_list", False),+ "clear": ("_queue_clear", False),+ "edit": ("_queue_edit", True), "set": ("_queue_edit", True),+ "rm": ("_queue_remove", True), "remove": ("_queue_remove", True), "delete": ("_queue_remove", True),+ "del": ("_queue_remove", True), "pop": ("_queue_remove", True),+ "move": ("_queue_move", True),+}++def _print_decision_message(decision: dict) -> bool:"""Print a manager decision's ``message`` (if any) via _cprint; True when one was printed."""from cli import _cprint@@ -265,15 +279,125 @@ class CLILoopsMixin:except Exception as e:print(f"Plugin system error: {e}")+ # ── /queue: enqueue, list, edit, rm, move, clear ─────────────────+ # Inspired by Factory Droid v0.203 "edit queued messages": a queued next-turn+ # prompt can be inspected and changed before it is sent.++ def _pending_input_items(self) -> list:+ """Snapshot of queued next-turn prompts (raw items; may include ``_VoiceInputMessage``)."""+ with self._pending_input.mutex:+ return list(self._pending_input.queue)++ def _replace_pending_input_items(self, items: list) -> None:+ """Swap the queued prompts under the queue's own mutex so put/get bookkeeping stays consistent."""+ q = self._pending_input+ with q.mutex:+ q.queue.clear()+ q.queue.extend(items)+ q.unfinished_tasks = len(items)+ if items:+ q.not_empty.notify_all()++ def _queue_enqueue(self, text: str) -> None:+ from cli import _cprint+ payload = self._expand_paste_references(text)+ self._pending_input.put(payload)+ when = " for the next turn" if self._agent_running else ""+ _cprint(f" Queued{when}: {_preview(payload)}")++ def _queue_list(self, rest: str) -> None:+ from cli import _VoiceInputMessage, _cprint+ items = self._pending_input_items()+ if not items:+ _cprint(" Queue is empty." + ("" if rest else " " + _QUEUE_USAGE))+ return+ _cprint(f" Queue ({len(items)} pending):")+ for idx, item in enumerate(items, 1):+ tag = " [voice]" if isinstance(item, _VoiceInputMessage) else ""+ _cprint(f" {idx}. {_preview(str(item).replace(chr(10), ' '))}{tag}")++ def _queue_clear(self, rest: str) -> None:+ from cli import _cprint+ count = len(self._pending_input_items())+ self._replace_pending_input_items([])+ _cprint(f" Cleared {count} queued prompt{'s' if count != 1 else ''}.")++ def _queue_item_index(self, token: str, items: list) -> int | None:+ from cli import _cprint+ idx = int(token)+ if 1 <= idx <= len(items):+ return idx - 1+ _cprint(f" Queue item {idx} not found. Current size: {len(items)}")+ return None++ def _queue_remove(self, rest: str) -> None:+ from cli import _cprint+ items = self._pending_input_items()+ pos = self._queue_item_index(rest, items)+ if pos is None:+ return+ removed = items.pop(pos)+ self._replace_pending_input_items(items)+ _cprint(f" Removed queue item {pos + 1}: {_preview(str(removed))}")++ def _queue_edit(self, rest: str) -> None:+ from cli import _VoiceInputMessage, _cprint+ idx_text, _, new_prompt = rest.partition(" ")+ if not new_prompt.strip():+ _cprint(" Usage: /queue edit <number> <new prompt>")+ return+ items = self._pending_input_items()+ pos = self._queue_item_index(idx_text, items)+ if pos is None:+ return+ new_text = self._expand_paste_references(new_prompt.strip())+ # A voice-queued item keeps its sentinel so the concise voice-response prefix+ # still applies (#65827).+ items[pos] = _VoiceInputMessage(new_text) if isinstance(items[pos], _VoiceInputMessage) else new_text+ self._replace_pending_input_items(items)+ _cprint(f" Updated queue item {pos + 1}: {_preview(new_text)}")++ def _queue_move(self, rest: str) -> None:+ from cli import _cprint+ bits = rest.split()+ if len(bits) != 2 or not bits[1].isdigit():+ _cprint(" Usage: /queue move <from> <to>")+ return+ items = self._pending_input_items()+ src = self._queue_item_index(bits[0], items)+ dst = self._queue_item_index(bits[1], items)+ if src is None or dst is None:+ return+ items.insert(dst, items.pop(src))+ self._replace_pending_input_items(items)+ _cprint(f" Moved queue item {src + 1} to {dst + 1}.")+def _cmd_queue(self, cmd_original: str):+ """``/queue <prompt>`` enqueues; a leading management verb whose arguments fit+ (``list``/``clear`` alone, ``edit N …``/``rm N``/``move A B``) manages the queue+ instead. Anything else — ``clear the logs``, ``edit the config`` — is still a prompt;+ ``/queue add <prompt>`` forces enqueueing."""from cli import _cprint, _slash_args- payload = self._expand_paste_references(_slash_args(cmd_original))+ payload = _slash_args(cmd_original)if not payload:- _cprint(" Usage: /queue <prompt>")+ self._queue_list("")+ return+ verb, _, rest = payload.partition(" ")+ verb, rest = verb.lower(), rest.strip()+ if verb == "add":+ if rest:+ self._queue_enqueue(rest)+ else:+ _cprint(" Usage: /queue add <prompt>")+ return+ handler, takes_index = _QUEUE_VERBS.get(verb, (None, False))+ is_management = handler is not None and (+ rest.split(None, 1)[0].isdigit() if takes_index and rest else not rest+ )+ if is_management:+ getattr(self, handler)(rest)else:- self._pending_input.put(payload)- when = " for the next turn" if self._agent_running else ""- _cprint(f" Queued{when}: {_preview(payload)}")+ self._queue_enqueue(payload)def _cmd_steer(self, cmd_original: str):# Inject a message after the next tool call without interrupting: while thediff --git a/hermes_cli/commands.py b/hermes_cli/commands.pyindex 6a38112c4e6..e87d9b4699f 100644--- a/hermes_cli/commands.py+++ b/hermes_cli/commands.py@@ -106,8 +106,10 @@ COMMAND_REGISTRY: list[CommandDef] = [CommandDef("journey", "Open the learning journey timeline","Session", aliases=("learning", "memory-graph"), cli_only=True,args_hint="[list|delete <id>|edit <id>]", subcommands=("list", "delete", "edit")),- CommandDef("queue", "Queue a prompt for the next turn (doesn't interrupt)", "Session",- aliases=("q",), args_hint="<prompt>", busy_policy="dispatch", busy_handler="queue"),+ CommandDef("queue", "Queue a prompt for the next turn, or list/edit/rm/move/clear queued prompts", "Session",+ aliases=("q",), args_hint="[<prompt>|list|edit N <prompt>|rm N|move A B|clear]",+ subcommands=("list", "edit", "rm", "move", "clear", "add"),+ busy_policy="dispatch", busy_handler="queue"),CommandDef("steer", "Inject a message after the next tool call without interrupting", "Session",args_hint="<prompt>", busy_policy="dispatch", busy_handler="steer"),CommandDef("goal", "Set a standing goal Hermes works on across turns until achieved", "Session",diff --git a/tests/hermes_cli/test_cli_init.py b/tests/hermes_cli/test_cli_init.pyindex 1438cd08ee7..7bcb49b1639 100644--- a/tests/hermes_cli/test_cli_init.py+++ b/tests/hermes_cli/test_cli_init.py@@ -137,6 +137,56 @@ class TestBusyInputMode:cli.process_command("/queue follow up")assert cli._pending_input.get_nowait() == "follow up"+ def test_queue_command_can_edit_remove_move_and_clear_pending_items(self):+ cli = _make_cli()+ cli.process_command("/queue first prompt")+ cli.process_command("/queue second prompt")+ cli.process_command("/queue edit 2 replacement prompt")+ assert cli._pending_input_items() == ["first prompt", "replacement prompt"]++ cli.process_command("/queue move 2 1")+ assert cli._pending_input_items() == ["replacement prompt", "first prompt"]++ cli.process_command("/queue rm 2")+ assert cli._pending_input_items() == ["replacement prompt"]++ cli.process_command("/queue clear")+ assert cli._pending_input_items() == []+ # queue.Queue bookkeeping must stay consistent after clear+ assert cli._pending_input.unfinished_tasks == 0+ assert cli._pending_input.empty()++ def test_queue_command_preserves_prompts_that_start_with_non_subcommand_words(self):+ cli = _make_cli()+ cli.process_command("/queue maybe run later")+ assert cli._pending_input.get_nowait() == "maybe run later"++ def test_queue_add_allows_prompts_that_start_with_management_words(self):+ cli = _make_cli()+ cli.process_command("/queue add clear the logs after tests")+ assert cli._pending_input.get_nowait() == "clear the logs after tests"++ def test_queue_edit_preserves_voice_sentinel(self):+ cli = _make_cli()+ # Import AFTER _make_cli: the harness reloads the cli module, so the+ # sentinel class must come from the same (reloaded) module the+ # instance's handler compares against.+ import cli as _cli_mod+ cli._pending_input.put(_cli_mod._VoiceInputMessage("spoken prompt"))+ cli.process_command("/queue edit 1 corrected prompt")+ items = cli._pending_input_items()+ assert len(items) == 1+ assert isinstance(items[0], _cli_mod._VoiceInputMessage)+ assert str(items[0]) == "corrected prompt"++ def test_queue_out_of_range_indices_leave_queue_untouched(self):+ cli = _make_cli()+ cli.process_command("/queue only item")+ cli.process_command("/queue rm 5")+ cli.process_command("/queue edit 3 nope")+ cli.process_command("/queue move 1 9")+ assert cli._pending_input_items() == ["only item"]+diff --git a/website/docs/reference/slash-commands.md b/website/docs/reference/slash-commands.mdindex b0c5f00b203..80b1405cbf4 100644--- a/website/docs/reference/slash-commands.md+++ b/website/docs/reference/slash-commands.md@@ -49,7 +49,7 @@ Type `/` in the CLI to open the autocomplete menu. Built-in commands are case-in| `/diff [staged\|all\|session] [--stat] [path...]` | Show git changes in the working directory. Default: unstaged changes plus untracked files. `staged` shows what's staged for commit, `all` everything since HEAD, and `session` the cumulative diff of everything Hermes changed here (from the earliest retained checkpoint baseline — requires checkpoints to be enabled; complements `/rollback diff <N>`). `--stat` prints just the changed-file summary; path arguments restrict the diff. || `/snapshot [create\|restore <id>\|prune]` (alias: `/snap`) | Create or restore state snapshots of Hermes config/state. `create [label]` saves a snapshot, `restore <id>` reverts to it, `prune [N]` removes old snapshots, or list all with no args. Database restores write through SQLite's backup API so live processes (gateway, dashboard) see the restored data safely; if that path fails while another process still holds the database open, the restore refuses instead of risking corruption — stop the holder and retry. || `/stop` | Kill all running background processes |-| `/queue <prompt>` (alias: `/q`) | Queue a prompt for the next turn (doesn't interrupt the current agent response). |+| `/queue <prompt>` (alias: `/q`) | Queue a prompt for the next turn (doesn't interrupt the current agent response). In the CLI, `/queue` with no arguments lists the pending queue, and `/queue list`, `/queue edit N <new prompt>`, `/queue rm N`, `/queue move A B`, and `/queue clear` inspect and manage queued prompts before they are sent. Prompts that begin with a management word can be force-queued with `/queue add <prompt>`. || `/steer <prompt>` | Inject a mid-run note that arrives at the agent **after the next tool call** — no interrupt, no new user turn. The text is appended to the last tool result's content once the current tool completes, giving the agent new context without breaking the current tool-calling loop. Use this to nudge direction mid-task (e.g. "focus on the auth module" while the agent is running tests). || `/goal <text>` | Set a standing goal Hermes works toward across turns — our take on the Ralph loop. After each turn an auxiliary judge model decides whether the goal is done; if not, Hermes auto-continues. Subcommands: `/goal status`, `/goal pause`, `/goal resume`, `/goal clear`. Budget defaults to 20 turns (`goals.max_turns`); any real user message preempts the continuation loop, and state survives `/resume`. See [Persistent Goals](/user-guide/features/goals) for the full walkthrough. || `/subgoal <text>` | Append a user-supplied criterion to the active goal mid-loop. The continuation prompt surfaces all subgoals to the agent verbatim, and the judge factors them into its DONE/CONTINUE verdict — so the goal isn't marked done until the original goal **and** every subgoal are met. Subcommands: `/subgoal` (list), `/subgoal remove <N>`, `/subgoal clear`. Requires an active `/goal`. |