The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Merge origin/main into feat/hermes-relay-client-dimensions
Alex Fournier44897dd6f003
diff --cc tests/hermes_cli/test_relay_shared_metrics_runtime.pyindex 67a72ccc358,ec5f4e3c7f4..dc8328a86a2--- a/tests/hermes_cli/test_relay_shared_metrics_runtime.py+++ b/tests/hermes_cli/test_relay_shared_metrics_runtime.py@@@ -30,13 -30,11 +30,14 @@@ class _Relayself.events: list[tuple[Any, ...]] = []self._callbacks: dict[str, Any] = {}self._starts: dict[Any, dict[str, Any]] = {}+ self._tool_starts: dict[Any, dict[str, Any]] = {}self._scope_starts: dict[Any, dict[str, Any]] = {}self._scope = contextvars.ContextVar("relay_scope", default=None)+ self._scope_stack = contextvars.ContextVar("relay_scope_stack", default=None)self._scope_serial = 0- self.ScopeType = SimpleNamespace(Agent="agent", Function="function")+ self.ScopeType = SimpleNamespace(+ Agent="agent", Function="function", Tool="tool"+ )self.LLMRequest = _Requestself.scope = SimpleNamespace(push=self._scope_push,@@@ -93,20 -102,11 +106,22 @@@def _scope_event(self, name: str, **kwargs: Any) -> None:self.events.append(("scope.event", name, kwargs))+ event = SimpleNamespace(+ kind="mark",+ category=None,+ name=name,+ scope_category=None,+ category_profile=None,+ metadata=kwargs.get("metadata"),+ data=kwargs.get("data"),+ )+ for callback in list(self._callbacks.values()):+ callback(event)def _get_scope_stack(self) -> Any:- current = self._scope.get()+ stack = self._scope_stack.get()+ current = stack[-1] if stack else None+ self._scope.set(current)self.events.append(("scope.sync", current))return current@@@ -2077,166 -1395,4 +2326,172 @@@ def test_failed_flush_keeps_daily_exporassert metrics["hermes.task_run.finished"]["value"] == 2assert flush_attempts == 2assert "Hermes shared-metrics task flush failed" in caplog.text++++def test_skill_lifecycle_flows_through_relay_to_a_privacy_safe_package(+ direct_runtime,+ tmp_path,+):+ common = {+ "skill_name": "private-skill-name",+ "provenance": "agent_created",+ }+ lifecycle.invoke_hook("on_skill_lifecycle", **common, action="created")+ lifecycle.invoke_hook(+ "on_skill_lifecycle",+ **common,+ action="loaded",+ use_count=1,+ reused=False,+ reuse_after_patch=False,+ )+ lifecycle.invoke_hook("on_skill_lifecycle", **common, action="patched")+ lifecycle.invoke_hook(+ "on_skill_lifecycle",+ **common,+ action="loaded",+ use_count=2,+ reused=True,+ reuse_after_patch=True,+ )++ runtime = relay_shared_metrics._get_runtime()+ assert runtime is not None+ runtime.shutdown()++ marks = [event for event in direct_runtime.events if event[0] == "scope.event"]+ assert [event[1] for event in marks] == [+ "hermes.skill.lifecycle",+ "hermes.skill.load",+ "hermes.skill.lifecycle",+ "hermes.skill.load",+ ]+ assert "private-skill-name" not in json.dumps(marks)++ outbox = tmp_path / "hermes-home" / "telemetry" / "shared_metrics" / "outbox"+ [package_path] = list(outbox.glob("*.json"))+ package = json.loads(package_path.read_text(encoding="utf-8"))+ skill_metrics = [+ metric+ for metric in package["metrics"]+ if metric["name"].startswith("hermes.skill.")+ ]+ assert {metric["name"] for metric in skill_metrics} == {+ "hermes.skill.lifecycle.count",+ "hermes.skill.load.count",+ }+ assert "private-skill-name" not in json.dumps(package)++++def test_skill_lifecycle_with_only_task_id_uses_unique_task_scope(direct_runtime):+ runtime = relay_shared_metrics._get_runtime()+ assert runtime is not None+ task = runtime.start_task({+ "session_id": "session-1",+ "task_id": "task-1",+ "platform": "cli",+ })+ assert task is not None++ lifecycle.invoke_hook(+ "on_skill_lifecycle",+ action="created",+ skill_name="private-skill-name",+ provenance="agent_created",+ task_id="task-1",+ )++ [mark] = [+ event+ for event in direct_runtime.events+ if event[0] == "scope.event" and event[1] == "hermes.skill.lifecycle"+ ]+ assert mark[2]["handle"] == task.handle++++def test_skill_task_only_correlation_does_not_guess_across_sessions(direct_runtime):+ runtime = relay_shared_metrics._get_runtime()+ assert runtime is not None+ for session_id in ("session-1", "session-2"):+ assert runtime.start_task({+ "session_id": session_id,+ "task_id": "shared-task",+ "platform": "cli",+ }) is not None++ lifecycle.invoke_hook(+ "on_skill_lifecycle",+ action="created",+ skill_name="private-skill-name",+ provenance="agent_created",+ task_id="shared-task",+ )++ [mark] = [+ event+ for event in direct_runtime.events+ if event[0] == "scope.event" and event[1] == "hermes.skill.lifecycle"+ ]+ assert "handle" not in mark[2]++++def test_late_skill_lifecycle_is_not_reemitted_at_the_root(direct_runtime):+ base = {+ "session_id": "session-1",+ "task_id": "task-1",+ "turn_id": "turn-1",+ "platform": "cli",+ }+ lifecycle.invoke_hook("pre_llm_call", **base)+ lifecycle.invoke_hook(+ "on_session_end",+ **base,+ completed=True,+ failed=False,+ interrupted=False,+ turn_exit_reason="text_response(stop)",+ )++ lifecycle.invoke_hook(+ "on_skill_lifecycle",+ **base,+ action="loaded",+ skill_name="private-skill-name",+ provenance="local",+ use_count=2,+ reused=True,+ reuse_after_patch=False,+ )++ assert [+ event+ for event in direct_runtime.events+ if event[0] == "scope.event" and event[1] == "hermes.skill.load"+ ] == []++++def test_skill_lifecycle_does_not_fallback_across_an_explicit_session(+ direct_runtime,+):+ runtime = relay_shared_metrics._get_runtime()+ assert runtime is not None+ assert runtime.start_task({+ "session_id": "session-1",+ "task_id": "task-1",+ "platform": "cli",+ }) is not None++ lifecycle.invoke_hook(+ "on_skill_lifecycle",+ action="created",+ skill_name="private-skill-name",+ provenance="local",+ session_id="wrong-session",+ task_id="task-1",+ )++ assert [+ event+ for event in direct_runtime.events+ if event[0] == "scope.event" and event[1] == "hermes.skill.lifecycle"+ ] == []diff --cc tools/approval.pyindex 8ebc47a4621,151e5340655..f5e7f0beb15--- a/tools/approval.py+++ b/tools/approval.py@@@ -3110,28 -3170,24 +3170,43 @@@ def _run_approval_gate),}+ _fire_approval_hook(+ "pre_approval_request",+ command=display_target,+ description=description,+ pattern_key=pattern_key,+ pattern_keys=[pattern_key],+ session_key=session_key,+ surface="cli",+ )choice = prompt_dangerous_approval(display_target, description,approval_callback=approval_callback)+ _fire_approval_hook(+ "post_approval_response",+ command=display_target,+ description=description,+ pattern_key=pattern_key,+ pattern_keys=[pattern_key],+ session_key=session_key,+ surface="cli",+ choice=choice,+ )+ if choice == "timeout":+ return {+ "approved": False,+ "message": (+ f"BLOCKED: Action timed out without user response. The user "+ f"has NOT consented to this action. Do NOT retry it, do NOT "+ f"rephrase it, and do NOT attempt the same outcome via a "+ f"different path. Silence is not consent."+ ),+ "pattern_key": pattern_key,+ "description": description,+ "outcome": "timeout",+ "user_consent": False,+ }+if choice == "deny":return {"approved": False,