
    *"hj                    h    d Z ddlmZ ddlZddlmZ ddlmZ  ej                  e	      Z
	 	 	 	 ddZy)	z
Session-level skill aggregation: if ANY interaction in a session
references a skill, the entire session is included in that skill's group.
    )annotationsN)defaultdict   NO_SKILL_KEYc                   t        t              }| D ]U  }|j                  d      xs
 t               }|s|t           j                  |       ;|D ]  }||   j                  |        W t        d |D              }t        |j                  t        g             }t        j                  dt        |       ||       t        |      S )aa  Group sessions by skill.

    Each session must have ``_skills_referenced`` (a set of skill names)
    attached by the summarization stage.

    - If a session references skill X, it goes into skill X's group.
    - If a session references both A and B, it appears in both groups.
    - If no skill is referenced, it goes into :data:`NO_SKILL_KEY`.
    _skills_referencedc              3  4   K   | ]  }|t         k7  sd   yw)   Nr   ).0ks     =/root/.hermes/SkillClaw/evolve_server/pipeline/aggregation.py	<genexpr>z.aggregate_sessions_by_skill.<locals>.<genexpr>&   s     C!l1BACs   zC[Aggregation] %d sessions -> %d skill groups + %d no-skill sessions)r   listgetsetr   appendsumlenloggerinfodict)sessionsgroupssessionskills
skill_nameskill_group_countno_skill_counts          r   aggregate_sessions_by_skillr       s     %0$5F 312;ce< ''0$ 3
z"))'233 CvCCL"56N
KKMH	 <    )r   z
list[dict]returnzdict[str, list[dict]])__doc__
__future__r   loggingcollectionsr   core.constantsr   	getLogger__name__r   r     r!   r   <module>r+      s?   
 #  # )			8	$r!   