Ë
    ÿ`gj*
  ã                   óÎ   — 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y)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                 ó4   — t         j                  | xs 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    úI/root/.hermes/venv/lib/python3.12/site-packages/tools/skill_provenance.pyÚset_current_write_originr   0   s   € ô ×Ñ˜VÒ3 |Ó4Ð4ó    Útokenc                 ó.   — t         j                  | «       y)z'Restore the prior write origin context.N)r   Úreset)r   s    r   Úreset_current_write_originr   9   s   € ä×Ñ˜Õr   c                  ó*   — t         j                  «       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                  ó$   — 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ØØô.€ˆ{×%Ñ% cÑ*ó ð (Ð ð5 Sð 5¨[×->Ñ->¸sÑ-Có 5ð k×&7Ñ&7¸Ñ&<ð Àó ð

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