The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(goal): control verbs with trailing words never replace the goal
barnicskolaciac1c8de6b9a8
diff --git a/hermes_cli/goal_command.py b/hermes_cli/goal_command.pyindex e334192f810..98f8ae4e4bf 100644--- a/hermes_cli/goal_command.py+++ b/hermes_cli/goal_command.py@@ -5,7 +5,7 @@ parses subcommands and mutates goal state. It never changes conversation history"""from __future__ import annotations-from dataclasses import dataclass+from dataclasses import dataclass, replaceimport loggingfrom typing import Callable@@ -97,8 +97,20 @@ def _gate_clear(mgr, arg):_GATE_HANDLERS = {"add": _gate_add, "remove": _gate_remove, "rm": _gate_remove, "clear": _gate_clear}_EXACT_HANDLERS = {"": _status, "status": _status, "show": _show, "pause": _pause,- "resume": _resume, "clear": _clear, "stop": _clear, "done": _clear, "unwait": _unwait,+ "resume": _resume, "continue": _resume, "unpause": _resume,+ "clear": _clear, "stop": _clear, "done": _clear, "unwait": _unwait,}+# Non-destructive control verbs: with trailing words the verb still wins, so+# `/goal resume last goal` resumes instead of silently replacing the goal text.+# clear/stop/done stay out — guessing wrong would end a goal the user meant to keep.+_BARE_CONTROL_VERBS = frozenset({"resume", "continue", "unpause", "pause", "status", "show", "unwait"})+++def _bare_control(mgr, verb, rest, render):+ result = _EXACT_HANDLERS[verb](mgr, "", render)+ return replace(result, output=result.output + (+ f"\n(ignored {rest!r}: a control command never sets goal text — use /goal -- <text> "+ "when the goal really starts with a control word.)"))def _gate(mgr, arg, authorize_gate):@@ -135,9 +147,12 @@ def _set(mgr, arg, *, drafting, last_user_message, render, progress):else:headline, contract = goals.parse_contract(arg)contract = contract if not contract.is_empty() else None+ previous = (mgr.state.goal or "").strip() if mgr.state is not None else ""state = mgr.set(headline or arg, contract=contract)output = render("gateway.goal.set", "⊙ Goal set ({budget}-turn budget): {goal}",budget=state.max_turns, goal=state.goal)+ if previous and previous != state.goal:+ output += f"\n(replaced the previous goal)\n was: {previous}"if state.has_contract():label = "Drafted completion contract:" if drafting else "Completion contract:"output += f"\n{label}\n{state.contract.render_block()}"@@ -158,7 +173,8 @@ def _set(mgr, arg, *, drafting, last_user_message, render, progress):def is_goal_control(arg: str) -> bool:"""Whether this command controls an existing goal rather than replacing it."""normalized = arg.strip().lower()- return normalized in _EXACT_HANDLERS or normalized.split(None, 1)[0] in {"wait", "gate"}+ first = normalized.split(None, 1)[0] if normalized else ""+ return normalized in _EXACT_HANDLERS or first in _BARE_CONTROL_VERBS or first in {"wait", "gate"}def dispatch_goal_command(@@ -177,8 +193,14 @@ def dispatch_goal_command(rest = tokens[1].strip() if len(tokens) > 1 else ""prefix = "Invalid goal"try:+ if arg.startswith("--"):+ # Verbatim goal text for goals that start with a control word (`/goal -- pause the cron`).+ return _set(mgr, arg[2:].strip(), drafting=False, last_user_message=last_user_message,+ render=render, progress=progress)if handler := _EXACT_HANDLERS.get(arg.lower()):return handler(mgr, "", render)+ if verb in _BARE_CONTROL_VERBS:+ return _bare_control(mgr, verb, rest, render)if verb == "wait":prefix = "/goal wait"return _wait(mgr, rest)diff --git a/tests/hermes_cli/test_goal_dispatch.py b/tests/hermes_cli/test_goal_dispatch.pyindex b718424d8e4..b5b39b64a11 100644--- a/tests/hermes_cli/test_goal_dispatch.py+++ b/tests/hermes_cli/test_goal_dispatch.py@@ -117,3 +117,30 @@ def test_drafts_start_work_but_inspection_and_literal_prefixes_do_not_draft(assert goals.load_goal(mgr.session_id).goal == 'drafting docs'assert calls == ['build it']assert prompts[-1] == 'drafting docs'+++def _dispatch(mgr, arg):+ from hermes_cli.goal_command import dispatch_goal_command+ return dispatch_goal_command(mgr, arg, authorize_gate=lambda: None)++[email protected]('command, paused', [+ ('resume last goal', False), ('continue', True), ('pause for now', False), ('status please', False),+])+def test_control_verb_with_trailing_words_never_replaces_the_goal(command, paused):+ goals._DB_CACHE.clear()+ mgr = goals.GoalManager(session_id='verb-wins-' + command.replace(' ', '-'))+ mgr.set('original objective')+ if paused:+ mgr.pause(reason='user-paused')+ _dispatch(mgr, command)+ assert goals.load_goal(mgr.session_id).goal == 'original objective'+++def test_double_dash_sets_control_word_goal_and_announces_the_replace():+ goals._DB_CACHE.clear()+ mgr = goals.GoalManager(session_id='verb-escape')+ mgr.set('original objective')+ result = _dispatch(mgr, '-- pause the nightly cron')+ assert goals.load_goal(mgr.session_id).goal == 'pause the nightly cron'+ assert 'was: original objective' in result.output