diff --git a/ddapm_test_agent/claude_hooks.py b/ddapm_test_agent/claude_hooks.py index d6c9f77e..c064a0e6 100644 --- a/ddapm_test_agent/claude_hooks.py +++ b/ddapm_test_agent/claude_hooks.py @@ -35,6 +35,7 @@ _HOSTNAME = socket.gethostname() _USERNAME = os.environ.get("HOST_USER") or getpass.getuser() +_USER_HANDLE = os.environ.get("DD_USER_HANDLE", "") MODEL_CONTEXT_LIMITS: Dict[str, int] = {} # empty; default fallback handles all models @@ -409,7 +410,9 @@ def _handle_user_prompt_submit(self, session_id: str, body: Dict[str, Any]) -> N session.pending_tools = {} session.deferred_agent_spans = {} session.claimed_task_tools = set() - session.conversation_title = "" + # Don't reset conversation_title — it persists across turns so + # subsequent interactions on the same topic reuse the title. + # The haiku summarization call will update it when the topic changes. session.root_span_emitted = False prompt = body.get("user_prompt", body.get("prompt", "")) @@ -437,7 +440,9 @@ def _handle_user_prompt_submit(self, session_id: str, body: Dict[str, Any]) -> N "source:claude-code-hooks", "language:python", f"hostname:{_HOSTNAME}", - ], + ] + + ([f"user_handle:{_USER_HANDLE}"] if _USER_HANDLE else []) + + ([f"topic:{session.conversation_title}"] if session.conversation_title else []), "meta": { "span": {"kind": "agent"}, "input": {"value": prompt}, @@ -896,12 +901,16 @@ def _handle_stop(self, session_id: str, body: Dict[str, Any]) -> None: if context_delta: session.last_known_input_tokens = context_delta["last_input_tokens"] - root_span_name = session.conversation_title or "claude-code-request" + root_span_name = "claude-code-request" estimated_permission_wait_ms = self._sum_estimated_permission_wait_ms(trace_id=session.trace_id) if root_span: root_span["name"] = root_span_name + if session.conversation_title: + topic_tag = f"topic:{session.conversation_title}" + # Replace existing topic tag (set from preliminary span) or append + root_span["tags"] = [t for t in root_span["tags"] if not t.startswith("topic:")] + [topic_tag] root_span["duration"] = duration root_span["meta"]["input"]["value"] = input_value root_span["meta"]["output"]["value"] = output_value @@ -944,7 +953,9 @@ def _handle_stop(self, session_id: str, body: Dict[str, Any]) -> None: "language:python", f"hostname:{_HOSTNAME}", f"user_name:{_USERNAME}", - ], + ] + + ([f"user_handle:{_USER_HANDLE}"] if _USER_HANDLE else []) + + ([f"topic:{session.conversation_title}"] if session.conversation_title else []), "meta": { "span": {"kind": "agent"}, "input": {"value": input_value},