The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Merge remote-tracking branch 'origin/main' into fix/goal-set-no-repaste
Teknium28747b4034cf
diff --cc hermes_cli/goals.pyindex 27a0fae7597,0f1d870209e..311ed5a64f3--- a/hermes_cli/goals.py+++ b/hermes_cli/goals.py@@@ -909,58 -929,26 +929,75 @@@ def judge_goalreturn verdict, reason, parse_failed, wait_directive, False+ def count_active_delegations(session_id: Optional[str]) -> int:+ """Live async delegation batches spawned by this session (fail-safe 0)."""+ if not session_id:+ return 0+ try:+ from tools.async_delegation import _LIVE_STATES, _session_records+ return len(_session_records(_LIVE_STATES, "", "", str(session_id)))+ except Exception:+ return 0+++# `/goal <text>` kicks the loop by sending the goal as the next user turn. When that text IS what+# the user just said (a pasted handoff note, a plan the agent already has), re-sending it makes the+# agent spend a turn deciding it is a replay (11 API calls, 6 min, in one run) and duplicates ~2k+# tokens of context. The pointer is used only when the goal is substantially the WHOLE last+# message: a short goal that merely appears inside a longer one ("ship the API" after a message+# offering API or UI work) selects one option, and two different goals must not kick identically.+GOAL_ALREADY_SEEN_KICK = "[Goal set] Continue with the goal you were just given; there is no need to re-read it."+_GOAL_REPASTE_MIN_CHARS = 400+_GOAL_REPASTE_MIN_SHARE = 0.8+++def goal_kick_prompt(goal: str, last_user_message: Any) -> str:+ """The goal text, or ``GOAL_ALREADY_SEEN_KICK`` when ``last_user_message`` is essentially that text."""+ content = last_user_message+ if isinstance(content, list):+ content = " ".join(str(b.get("text", "")) for b in content if isinstance(b, dict))+ goal_norm, last_norm = " ".join(str(goal or "").split()), " ".join(str(content or "").split())+ if (+ len(goal_norm) >= _GOAL_REPASTE_MIN_CHARS+ and goal_norm in last_norm+ and len(goal_norm) >= _GOAL_REPASTE_MIN_SHARE * len(last_norm)+ ):+ return GOAL_ALREADY_SEEN_KICK+ return goal+++def last_user_message_content(history: Any) -> Any:+ """Content of the newest ``role == "user"`` message in an OpenAI-shaped history, else ``""``."""+ for msg in reversed(history or []):+ if isinstance(msg, dict) and msg.get("role") == "user":+ return msg.get("content")+ return ""+++def last_user_message_from_db(session_id: Optional[str]) -> Any:+ """Newest user message of ``session_id`` from the SessionDB (gateway/TUI surfaces have no live+ history object at slash-command time); ``""`` on any error."""+ if not session_id:+ return ""+ try:+ db = _get_session_db()+ if db is None:+ return ""+ rows = db.get_messages(str(session_id), limit=20, latest=True)+ return last_user_message_content(rows)+ except Exception:+ return ""++- def gather_background_processes(task_id: Optional[str] = None) -> List[Dict[str, Any]]:+ def gather_background_processes(task_id: Optional[str] = None, *, owner_task_id: Optional[str] = None) -> List[Dict[str, Any]]:"""Fail-safe snapshot of RUNNING ``process_registry`` sessions for the judge; ``[]`` on any error- so the loop degrades to its pre-wait-barrier behavior."""+ so the loop degrades to its pre-wait-barrier behavior.++ ``owner_task_id`` restricts the snapshot to processes the goal's OWN session spawned. The registry's+ ``task_id`` is the container key, which collapses to one value for every agent in the process, so+ without this filter a fan-out parent's judge saw every subagent's pollers and parked the goal on a+ grandchild's ``proc_*`` session (one run: 7 of 7 root verdicts were WAIT on child-owned processes;+ parked 3 h 22 min at the end while nothing of its own was running)."""try:from tools.process_registry import process_registry