
    "/i                     l    d Z ddlZddlZddlmZ ddlmZ ddee   defdZ	ded	ede
fd
ZdedefdZy)z5Tier configuration loading and capability resolution.    N)Path)Optionalconfig_pathreturnc                 2   | 4t        t              j                  j                  j                  dz  dz  } nt        |       } | j                         st	        d|        t        | dd      5 }t        j                  |      cddd       S # 1 sw Y   yxY w)zBLoad tier_definitions.json from the given path or project default.Nconfigztier_definitions.jsonzTier config not found: rutf-8encoding)r   __file__parentexistsFileNotFoundErroropenjsonload)r   fs     1/mnt/e/genesis-system/core/tiering/tier_config.pyload_tier_configr   	   s    8n++2299HDG^^;'"9+ GHH	k3	1 Qyy|  s   .BB	tier_namer   c                     |j                  di       }|j                  |       }|t        d|        t        |j                  dg             }|j                  d      }|r||v r|t        ||      z  }|S )zPRecursively resolve all capabilities for a tier by following the includes chain.tierszUnknown tier: capabilitiesincludes)get
ValueErrorsetresolve_capabilities)r   r   r   tierr   r   s         r   r   r      s{    JJw#E99YD|>)566txx34LXXj!F&E/,VV<<    md_pathc                 h   t        |       } | j                         st        d|        | j                  d      }t	        j
                  d|t        j                        }|si |dS |j                  d      }|j                  d      }i }d}d}|j                  d	      D ]  }|j                         }	|	r|	j                  d
      r(|	j                  d      rL|J|g }|j                  |	dd j                         j                  d      j                  d             |||<   d|	v sd}|	j                  d      \  }
}}|
j                         }
|j                         j                  d      j                  d      }|
}|dk(  rg ||
<   ||
   }|j                  d      rx|j                  d      rg|dd j                  d      D cg c]0  }|j                         j                  d      j                  d      2 }}|D cg c]  }|s|	 c}||
<   d}z|||
<   d} ||dS c c}w c c}w )zSplit YAML frontmatter from markdown content in an agent definition file.

    Returns dict with keys:
        - 'frontmatter': dict of parsed YAML key-values
        - 'body': str of markdown content after frontmatter
    zAgent definition not found: r
   r   z^---\s*\n(.*?)\n---\s*\n(.*))frontmatterbody      N
#z- "': [],)r   r   r   	read_textrematchDOTALLgroupsplitstrip
startswithappend	partitionendswith)r"   textr4   	yaml_textr%   r$   current_keycurrent_listlinestrippedkey_valueitemitemsis                   r   parse_agent_frontmatterrI   '   s3    7mG>>">wi HIIg.D HH4dBIIFE!400AI;;q>D KKL% "$::<8..s3 t$)@#! 2 2 4 : :3 ? E Ec JK'3K$ (?L$..s3MCE))+CKKM'',2237EK{#%C *3/!!#&5>>#+>HMaPRHYHYZ]H^_++C066s;__/4#:!A#:C ##(C #E"$H '55 `#:s   
5H*H/H/)N)__doc__r   r3   pathlibr   typingr   strdictr   r   r   rI    r!   r   <module>rP      sX    ;  	  (3- 4 C  #  >6S >6T >6r!   