
    "/i0                     h    d Z ddlZddlmZ ddlmZmZmZ  ej                  d      Z	 G d d      Z
y)	u  TierGate — runtime feature flag gate for Genesis agent tiers.

Determines what capabilities, tools, models, and budgets are available
based on the agent's product tier (BASIC, STANDARD, PRO, ENTERPRISE).

Default is ENTERPRISE — all existing code continues working unchanged.
    N)Optional   )load_tier_configresolve_capabilitiesparse_agent_frontmatterzcore.tiering.tier_gatec                   ,   e Zd ZdZg dZ ee      D  ci c]  \  }}||
 c}}} Zddedee   fdZ	dede
fd	Zdefd
ZdefdZdefdZdefdZdefdZdefdZdefdZdefdZdefdZdede
fdZdefdZededd fd       Zyc c}}} w )TierGatezRuntime capability gate for Genesis product tiers.

    Usage:
        gate = TierGate("ENTERPRISE")
        if gate.has("native_voice"):
            start_voice_client()
        if gate.has("ide_access"):
            enable_file_writes()
    )BASICSTANDARDPRO
ENTERPRISEN	tier_nameconfig_pathc                    |j                         }|| j                  vrt        j                  d| d       d}|| _        t        |      | _        | j                  j                  di       j                  | j                  i       | _        t        | j                  | j                        | _
        t        j                  d| j                   dt        | j                         d       y )NzUnknown tier 'z', defaulting to ENTERPRISEr   tierszTierGate initialized: z (z capabilities))upper
TIER_ORDERloggerwarningr   r   _configget
_tier_datar   _all_capabilitiesinfolen)selfr   r   s      //mnt/e/genesis-system/core/tiering/tier_gate.py__init__zTierGate.__init__    s    OO%	DOO+NN^I;6QRS$I"'4,,**7B7;;DNNBO!5dnndll!S$T^^$4 5D**+,N<	
    
capabilityreturnc                     || j                   v S )z1Check if this tier includes the given capability.)r   )r   r    s     r   haszTierGate.has0   s    T3333r   c                 ,    t        | j                        S )z;Return the full resolved set of capabilities for this tier.)setr   r   s    r   get_all_capabilitieszTierGate.get_all_capabilities4   s    4))**r   c                 L    t        | j                  j                  di             S )z)Return the model selection for this tier.model_stack)dictr   r   r&   s    r   get_model_stackzTierGate.get_model_stack8       DOO''r:;;r   c                 t    | j                   j                  dd      | j                   j                  dd      dS )z(Return budget constraints for this tier.daily_budget_usdg      ?	max_turns2   )r.   r/   r   r   r&   s    r   get_budget_limitszTierGate.get_budget_limits<   s7     !% 3 34F L,,["=
 	
r   c                 :    | j                   j                  dd      S )zAReturn the default autonomy level (0=full auto, 3=advisory only).autonomy_level   r1   r&   s    r   get_autonomy_levelzTierGate.get_autonomy_levelC   s    ""#3Q77r   c                 L    t        | j                  j                  dg             S )z;Return the list of allowed Claude Code tools for this tier.tool_access)listr   r   r&   s    r   get_tool_accesszTierGate.get_tool_accessG   r,   r   c                 v    | j                   j                  dg       }t        |t              r|gS t	        |      S )zReturn the list of allowed MCP tools for this tier.

        Returns a list of tool name patterns. "ALL" means unrestricted.
        Patterns with wildcards (e.g. "kg_*") match tool names by prefix.
        	mcp_tools)r   r   
isinstancestrr9   )r   mcps     r   get_mcp_toolszTierGate.get_mcp_toolsK   s5     oo!!+r2c35LCyr   c                 :    | j                   j                  dd      S )z8Return allowed domain overlay count. -1 means unlimited.domain_overlaysr   r1   r&   s    r   get_domain_overlayszTierGate.get_domain_overlaysV   s    ""#4a88r   c                 N    | j                   j                  d| j                        S )z$Return the human-readable tier name.display_name)r   r   r   r&   s    r   get_display_namezTierGate.get_display_nameZ   s    "">4>>BBr   c                 :    | j                   j                  dd      S )z3Return the agent definition filename for this tier.
agent_file r1   r&   s    r   get_agent_filezTierGate.get_agent_file^   s    ""<44r   minimum_tierc                     |j                         }|| j                  vry| j                  | j                     | j                  |   k\  S )z7Check if this tier is at or above the given tier level.F)r   
TIER_LEVELr   )r   rK   s     r   at_leastzTierGate.at_leastb   s@    #))+t.t~~.$//,2OOOr   c                 N    d| j                    dt        | j                         dS )NzTierGate(tier=z, capabilities=))r   r   r   r&   s    r   __repr__zTierGate.__repr__i   s)    /s4CYCY?Z>[[\]]r   agent_md_pathc                     t        |      }|d   j                  dd      }t        j                  d| d|         | |      S )zCreate a TierGate from a .claude/agents/*.md file's YAML frontmatter.

        Parses the 'tier' field from the frontmatter and initializes
        the gate with that tier name.
        frontmattertierr   z TierGate.from_agent_definition: u
    → tier=)r   )r   r   r   r   )clsrR   parsedr   s       r   from_agent_definitionzTierGate.from_agent_definitionl   sK     )7=)--flC	6}oZPY{[\Y''r   )r   N)__name__
__module____qualname____doc__r   	enumeraterM   r>   r   r   boolr#   r%   r'   r*   r+   r2   intr6   r9   r:   r@   rC   rF   rJ   rN   rQ   classmethodrX   ).0idxnames   000r   r	   r	      s    <J-6z-BCC	T$)CJ
# 
8C= 
 4c 4d 4+c +< <
4 
8C 8< <	t 	9S 9C# C5 5PS PT P^# ^ 	(# 	(* 	( 	(_ Ds   Br	   )r\   loggingtypingr   tier_configr   r   r   	getLoggerr   r	    r   r   <module>ri      s7      X X			3	4e( e(r   