§
    ²Ùýi*
  ã                   óÀ   — U d Z ddlZ ej        dd¬¦  «        Zej        e         ed<   dZded	ej        e         fd
„Zdej        e         d	dfd„Z	d	efd„Z
d	efd„ZdS )uº  Skill write-origin provenance â€” ContextVar for distinguishing agent-sediment skill writes from foreground user-directed writes.

The curator only consolidates/prunes skills it autonomously created via the
background self-improvement review fork. Skills a user asks a foreground
agent to write belong to the user and must never be auto-curated.

This module exposes a ContextVar that run_agent.py sets before each tool
loop so tool handlers (e.g. skill_manage create) can check whether they
are executing inside the background-review fork.

The signal piggybacks on AIAgent._memory_write_origin, which is already
set to "background_review" for review-fork instances (see
_spawn_background_review in run_agent.py) and defaults to "assistant_tool"
for normal (foreground) agents.

Usage:
    from tools.skill_provenance import (
        set_current_write_origin,
        reset_current_write_origin,
        get_current_write_origin,
    )

    token = set_current_write_origin("background_review")
    try:
        ...  # tool runs here
    finally:
        reset_current_write_origin(token)

    # inside a tool:
    if get_current_write_origin() == "background_review":
        mark_agent_created(skill_name)
é    NÚskill_write_originÚ
foreground)ÚdefaultÚ_write_originÚbackground_reviewÚoriginÚreturnc                 ó:   — t                                | pd¦  «        S )z™Bind the active write origin to the current context.

    Returns a Token the caller must pass to reset_current_write_origin
    in a finally block.
    r   )r   Úset)r   s    ú;/home/piyush/.hermes/hermes-agent/tools/skill_provenance.pyÚset_current_write_originr   0   s   € õ ×Ò˜VÐ3 |Ñ4Ô4Ð4ó    Útokenc                 ó:   — t                                | ¦  «         dS )z'Restore the prior write origin context.N)r   Úreset)r   s    r   Úreset_current_write_originr   9   s   € å×Ò˜ÑÔÐÐÐr   c                  ó4   — t                                ¦   «         S )uO  Return the active write origin.

    Default: "foreground" â€” any tool call made by a regular (non-review)
    agent, from the CLI, the gateway, cron, or a subagent.

    "background_review" â€” the self-improvement review fork; only skills
    created under this origin should be marked agent-created for curator
    management.
    )r   Úget© r   r   Úget_current_write_originr   >   s   € õ ×ÒÑÔÐr   c                  ó0   — t          ¦   «         t          k    S )zQConvenience: True iff the current write origin is the background
    review fork.)r   ÚBACKGROUND_REVIEWr   r   r   Úis_background_reviewr   K   s   € õ $Ñ%Ô%Õ):Ò:Ð:r   )Ú__doc__ÚcontextvarsÚ
ContextVarr   ÚstrÚ__annotations__r   ÚTokenr   r   r   Úboolr   r   r   r   ú<module>r!      sú   ððð ð ðB Ð Ð Ð ð .D¨[Ô-CØØð.ñ .ô .€ˆ{Ô% cÔ*ð ð ñ ð (Ð ð5 Sð 5¨[Ô->¸sÔ-Cð 5ð 5ð 5ð 5ð kÔ&7¸Ô&<ð Àð ð ð ð ð

 #ð 
ð 
ð 
ð 
ð;˜dð ;ð ;ð ;ð ;ð ;ð ;r   