
    epj)                       U d Z ddlZddlZddlZddlZddlmZmZ ddlZddl	Z	ddl
mZ ddlmZmZmZ ddlmZmZmZmZmZmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ m!Z"  ej#        e$          Z%i Z&e'e(d<   dZ)dZ*dZ+de,fdZ- e            Z.e.dz  Z/e/Z0defdZ1dZ2dZ3ddddZ4 e	j5        d          Z6 e7h d          Z8da9de:dee:         fdZ;dee:e:f         fdZ< G d de:e          Z=g d Z>e?e(d!<   dd"Z@d#ee:ef         deAfd$ZBd#ee:ef         deAfd%ZCd&edee:         fd'ZDd#ee:ef         deee:         ee:         f         fd(ZEd#ee:ef         dee:ef         fd)ZF	 dd#ee:ef         d*ee:         dz  deee:ef                  fd+ZGd,e:d-eee:ef                  dee:ef         fd.ZHdeAfd/ZIde:fd0ZJ	 dd1e:d2ee:e:f         dz  deAfd3ZKdd4d5eee:ef                  d6ee:ef         d2ee:e:f         dz  dee:         fd7ZLde:fd8ZM	 dd9e=d:ee:         d;e:dz  de:dz  fd<ZNdeAfd=ZOd>e:deee:ef         e:f         fd?ZPd@edee:         fdAZQdee:         fdBZRdee:         fdCZSde:fdDZTdde:dEe:deAfdFZUdGdHdIeAdeee:ef                  fdJZVdeee:ef                  deee:ef                  fdKZWddLe:dMe:de:fdNZXdOddPdQedRe:dSe:dTeAdUe:dz  de:fdVZY	 	 	 dde:dWe:dMe:dTeAde:f
dXZZe$dYk    ro	  e[dZ            e[d[            e[d\            ej\         eX                      Z]e]d]         r e[d^e]d_          d` e^e]_                    dag                      db            e[dce]_                    dag                        e[dd           e]d         dde         D ]MZ`e`_                    dL          rdfe`dL          dgndhZa e[diea e`d          dje`dk         ddl          dm           Nn e[dne]do                      e[dp            ej\         eZdq                    Z]e]d]         r e[dre]d                      e[dse]_                    dkdt          ddu          dm            e[dv e^e]d>                    dw           e]_                    dx          r e[dye]dx                     n e[dne]do                      e[dz            ej\         eZdqd{                    Z]e]d]         rP e[d|e]d}                      e[dv e^e]d>                    dw            e[d~e]d>         dd          dm           n e[dne]do                     ddddLdddig ddZbdddddddddddgddZc ejd        ddebd eOd           i Zeee:ee,e,f         f         e(d<    ejf                    ZgdZhdZide'de,dz  fdZjde'ddfdZkde:dz  fdZlddMe:dz  ddfdZmd Zn ejd        ddeceneOd           dS )u  
Skills Tool Module

This module provides tools for listing and viewing skill documents.
Skills are organized as directories containing a SKILL.md file (the main instructions)
and optional supporting files like references, templates, and examples.

Inspired by Anthropic's Claude Skills system with progressive disclosure architecture:
- Metadata (name ≤64 chars, description ≤1024 chars) - shown in skills_list
- Full Instructions - loaded via skill_view when needed
- Linked Files (references, templates) - loaded on demand

Directory Structure:
    skills/
    ├── my-skill/
    │   ├── SKILL.md           # Main instructions (required)
    │   ├── references/        # Supporting documentation
    │   │   ├── api.md
    │   │   └── examples.md
    │   ├── templates/         # Templates for output
    │   │   └── template.md
    │   └── assets/            # Supplementary files (agentskills.io standard)
    └── category/              # Category folder for organization
        └── another-skill/
            └── SKILL.md

SKILL.md Format (YAML Frontmatter, agentskills.io compatible):
    ---
    name: skill-name              # Required, max 64 chars
    description: Brief description # Required, max 1024 chars
    version: 1.0.0                # Optional
    license: MIT                  # Optional (agentskills.io)
    platforms: [macos]            # Optional — restrict to specific OS platforms
                                  #   Valid: macos, linux, windows
                                  #   Omit to load on all platforms (default)
    prerequisites:                # Optional — legacy runtime requirements
      env_vars: [API_KEY]         #   Legacy env var names are normalized into
                                  #   required_environment_variables on load.
      commands: [curl, jq]        #   Command checks remain advisory only.
    compatibility: Requires X     # Optional (agentskills.io)
    metadata:                     # Optional, arbitrary key-value (agentskills.io)
      hermes:
        tags: [fine-tuning, llm]
        related_skills: [peft, lora]
    ---

    # Skill Title

    Full instructions and content here...

Available tools:
- skills_list: List skills with metadata (progressive disclosure tier 1)
- skill_view: Load full skill content (progressive disclosure tier 2-3)

Usage:
    from tools.skills_tool import skills_list, skill_view, check_skills_requirements

    # List all skills (returns metadata only - token efficient)
    result = skills_list()

    # View a skill's main content (loads full instructions)
    content = skill_view("axolotl")

    # View a reference file within a skill (loads linked file)
    content = skill_view("axolotl", "references/dataset-formats.md")
    N)get_hermes_homedisplay_hermes_home)Enum)PathPurePosixPathPureWindowsPath)DictAnyListOptionalSetTuple)registry
tool_error)cfg_get)env_var_enabled)EXCLUDED_SKILL_DIRSis_skill_support_path_SKILLS_CACHEg      >@with_disabledfilteredreturnc                 T   ddl m} t          t          |dd          dd          }g }| D ]}	 |                                j        }n# t
          $ r Y )w xY w	 t          j        |          5 }|D ]L}	 |                    d          r#|                    d          j        }	|	|k    r|	}=# t
          $ r Y Iw xY w	 ddd           n# 1 swxY w Y   n# t
          $ r Y nw xY w|	                    t          |          |f           t          |          t          |          |fS )	uN  Cheap change-signature for the skill scan inputs.

    O(#dirs + #categories) stat calls, not a recursive walk. Includes the
    platform the scan's ``skill_matches_platform`` filter will use (read
    from ``agent.skill_utils``'s ``sys`` so test patches of that module
    are honored) — the scan result is platform-dependent.
    r   )skill_utilssysNplatform F)follow_symlinks)agentr   getattrstatst_mtimeOSErrorosscandiris_dirappendstrtuple	frozenset)
dirs_to_scandisabled_skill_utilsr   sigdmitentryems
             7/home/thesage/.hermes/hermes-agent/tools/skills_tool.py_skills_scan_signaturer5   k   s    211111w|UD99:rJJH
C    	!AA 	 	 	H		A !" ! !E! <<<>> '!&E!B!B!KB!Avv$&" ! ! ! !!! ! ! ! ! ! ! ! ! ! ! ! ! ! !  	 	 	D	

CFFA;#JJ	(++X66sk   A
AAC-C
39B-,C
-
B:	7C
9B:	:C
>C
C	CC	C
C#"C#skillsc                  f    t          t                    } | t          k    r| S t                      dz  S )aZ  Return the active profile's skills directory at call time.

    Some long-lived runtimes import this module before the active profile has
    set HERMES_HOME. Keep the legacy SKILLS_DIR module attribute for tests and
    external patchers, but when it has not been patched, resolve from the live
    profile-scoped HERMES_HOME on every call.
    r6   )r   
SKILLS_DIR_SKILLS_DIR_AT_IMPORTr   )
configureds    r4   _skills_dirr;      s4     j!!J***x''    @   i   darwinlinuxwin32)macosr?   windowsz^[A-Za-z_][A-Za-z0-9_]*$>   sshmodaldockerdaytonasingularityvercel_sandboxnamec                 2   ddl m} t          | t                    sdS |                                 }t          |                                          s5t          |                                          st          |          j        rdS  ||          rdS dS )uD  Return an error if a local skill lookup *name* can escape search roots.

    The skill ``name`` is joined onto each trusted search dir to build the
    on-disk lookup path, so it must stay relative and free of ``..`` segments —
    otherwise ``name="../outside"`` or an absolute path could select a skill
    (and read files) outside the skills directory. Mirrors the ``file_path``
    validation done later via ``tools.path_security``. We also reject Windows
    drive paths (e.g. ``C:\skills``), whose ``:`` would otherwise be misread as
    a plugin namespace separator.
    r   )has_traversal_componentzSkill name must be a string.z?Skill name must be a relative path within the skills directory.z9Skill name cannot contain '..' path traversal components.N)	tools.path_securityrK   
isinstancer(   stripr   is_absoluter   drive)rI   rK   	candidates      r4   _skill_lookup_path_errorrR      s     <;;;;;dC   .--

Ii  ,,..Q9%%1133Q 9%%+Q
 QPy)) KJJ4r<   c                     t                      dz  } i }|                                 s|S |                     d          5 }|D ]}|                                }|r|                    d          sxd|v rt|                    d          r
|dd         }|                    d          \  }}}|                                                    d	          ||                                <   	 ddd           n# 1 swxY w Y   |S )
z@Load profile-scoped environment variables from HERMES_HOME/.env.z.envutf-8encoding#=zexport    N"')r   existsopenrN   
startswith	partition)env_pathenv_varsflinekey_values          r4   load_envrf      sU     6)H!H?? 		(	( CA 	C 	CD::<<D CDOOC00 CSD[[??9-- $8D $s 3 3Q(-(;(;E(B(B%	CC C C C C C C C C C C C C C C Os    B)C66C:=C:c                       e Zd ZdZdZdZdS )SkillReadinessStatus	availablesetup_neededunsupportedN)__name__
__module____qualname__	AVAILABLESETUP_NEEDEDUNSUPPORTED r<   r4   rh   rh      s        I!LKKKr<   rh   )	zignore previous instructionszignore all previouszyou are nowzdisregard yourzforget your instructionsznew instructions:zsystem prompt:z<system>z]]>_INJECTION_PATTERNSc                 
    | a d S N)_secret_capture_callback)callbacks    r4   set_secret_capture_callbackrx      s    'r<   frontmatterc                 $    ddl m}  ||           S )u   Check if a skill is compatible with the current OS platform.

    Delegates to ``agent.skill_utils.skill_matches_platform`` — kept here
    as a public re-export so existing callers don't need updating.
    r   )skill_matches_platform)agent.skill_utilsr{   ry   _impls     r4   r{   r{      s'     BAAAAA5r<   c                 $    ddl m}  ||           S )uX  Check if a skill is relevant to the current runtime environment.

    Delegates to ``agent.skill_utils.skill_matches_environment`` — kept here
    as a public re-export so existing callers don't need updating. This is an
    offer-time relevance gate (kanban/docker/s6), NOT a hard-compatibility gate;
    explicit skill loads bypass it.
    r   )skill_matches_environment)r|   r   r}   s     r4   r   r     s'     EDDDDD5r<   re   c                 R    | sg S t          | t                    r| g} d | D             S )Nc                 n    g | ]2}t          |                                          #t          |          3S rr   r(   rN   ).0items     r4   
<listcomp>z2_normalize_prerequisite_values.<locals>.<listcomp>  s3    ===$3t99??+<+<=CII===r<   )rM   r(   )re   s    r4   _normalize_prerequisite_valuesr     s<     	% ==%====r<   c                     |                      d          }|rt          |t                    sg g fS t          |                     d                    t          |                     d                    fS )Nprerequisitesr`   commands)getrM   dictr   )ry   prereqss     r4   _collect_prerequisite_valuesr     so     ooo..G *Wd33 2v&w{{:'>'>??&w{{:'>'>?? r<   c           	         |                      d          }t          |t                    sd g dS |                     d          }t          |t                    r5|                                r!t          |                                          nd }|                     d          }t          |t                    r|g}t          |t
                    sg }g }|D ]}t          |t                    st          |                     d          pd                                          }|sRt          |                     d          pd|                                           }t          |                     d	          p|                     d
          pd                                          }	||t          |                     dd                    d}
|	r|	|
d	<   |                    |
           ||dS )Nsetup)helpcollect_secretsr   r   env_varr   promptEnter value for provider_urlurlsecretT)r   r   r   )r   rM   r   r(   rN   listboolr'   )ry   r   	help_textnormalized_helpcollect_secrets_rawr   r   r   r   r   r2   s              r4   _normalize_setup_metadatar   $  s   OOG$$EeT"" 5444		&!!I i%%	*3//*;*;	I   ))$566%t,, 423)400 ! ,.O# & &$%% 	dhhy))/R006688 	TXXh''G+Gg+G+GHHNNPP488N33LtxxL"MMSSUU 488Hd3344!
 !

  	1$0E.!u%%%%  *  r<   legacy_env_varsc                   	 t          |           	|                     d          }t          |t                    r|g}t          |t                    sg }g t                      dt          t          t          f         dd f	fd}|D ]E}t          |t                    r |d|i           %t          |t                    r ||           F	d         D ]_} ||                    d          |                    d          |                    d	          p	                    d
          d           `|t          |           \  }}|D ]} |d|i           S )Nrequired_environment_variablesr2   r   c                    t          |                     d          p|                     d          pd                                          }|r|v rd S t                              |          sd S |t          |                     d          pd|                                           d}|                     d          p>|                     d          p)|                     d	          p                    d          }t          |t                     r+|                                r|                                |d<   |                     d
          }t          |t                     r+|                                r|                                |d
<   |                     d          rd|d<                       |                               |           d S )NrI   r   r   r   r   )rI   r   r   r   r   required_foroptionalT)r(   r   rN   _ENV_VAR_NAME_REmatchrM   addr'   )r2   env_name
normalizedr   r   requiredseenr   s        r4   _append_requiredz=_get_required_environment_variables.<locals>._append_required_  s   uyy((FEIIi,@,@FBGGMMOO 	8t++F%%h// 	F %))H--N1NH1N1NOOUUWW&
 &

 IIf !yy((!yy! yy  	 	 i%% 	3)//*;*; 	3!*!2!2Jvyy00lC(( 	>\-?-?-A-A 	>)5););)=)=J~&99Z   	*%)Jz"
#####r<   rI   r   r   r   r   r   )rI   r   r   )
r   r   rM   r   r   setr	   r(   r
   r   )
ry   r   required_rawr   r   rd   r   r   r   r   s
          @@@r4   #_get_required_environment_variablesr   Q  s    &k22E??#CDDL,%% &$~lD)) %'HUUD$S#X $4 $ $ $ $ $ $ $ $>  # #dC   	fd^,,,dD!! 	#T"""'( 
 
++((8,,00EEIIf4E4E 	
 	
 	
 	
 9+FF" , ,&'*++++Or<   
skill_namemissing_entriesc                 0   |sg dd dS d |D             }t                      r!t          d          s|dt                      dS t          |dd dS d}g }|D ]9}d| i}|                    d          r|d         |d<   |                    d          r|d         |d<   	 t          |d         |d	         |          }nB# t
          $ r5 t                              d
|d          d           d|d         ddd}Y nw xY wt          |t                    o!t          |                    d                    }t          |t                    o!t          |                    d                    }	|r|	sd}|                    |d                    ;||d dS )NF)missing_namessetup_skippedgateway_setup_hintc                     g | ]
}|d          S rI   rr   )r   r2   s     r4   r   z;_capture_required_environment_variables.<locals>.<listcomp>  s    @@@uU6]@@@r<   HERMES_INTERACTIVEr   r   r   rI   r   z#Secret capture callback failed for Texc_info)success	stored_as	validatedskippedr   r   )_is_gateway_surfacer   _gateway_setup_hintrv   r   	ExceptionloggerwarningrM   r   r   r'   )
r   r   r   r   remaining_namesr2   metadatacallback_resultr   r   s
             r4   '_capture_required_environment_variablesr     sI     
""&
 
 	
 A@@@@M  
_5I%J%J 
*""5"7"7
 
 	
  '*""&
 
 	
 M!#O  ". ". *-99V 	-$V}HV99^$$ 	=',^'<H^$	6fh OO
  		 		 		NNEeFmEEPT     !"6]"	 OOO			 _d33 
	**9
 9
 _d33 
	**9
 9
  	7 	uV}---- )&"  s   B==<C<;C<c                  `    t          d          rdS ddlm}  t           | d                    S )NHERMES_GATEWAY_SESSIONTr   get_session_envHERMES_SESSION_PLATFORM)r   gateway.session_contextr   r   r   s    r4   r   r     sC    /00 t777777 9::;;;r<   c                      t          t          j        dd                                                                                    pdS )NTERMINAL_ENVlocal)r(   r$   getenvrN   lowerrr   r<   r4   _get_terminal_backend_namer     s9    ry112288::@@BBMgMr<   var_nameenv_snapshotc                     |t                      }| |v r"t          |                    |                     S t          t          j        |                     S ru   )rf   r   r   r$   r   )r   r   s     r4   _is_env_var_persistedr     sR     zz<L$$X..///	(##$$$r<   r   required_env_varscapture_resultc                    t          |d                   }|t                      }g }| D ]I}|d         }|                    d          r ||v st          ||          s|                    |           J|S )Nr   rI   r   )r   rf   r   r   r'   )r   r   r   r   	remainingr2   rI   s          r4   %_remaining_required_environment_namesr     s     788MzzI" # #V}99Z   	=  (=dL(Q(Q T"""r<   c                  X    	 ddl m}  | S # t          $ r dt                       dcY S w xY w)Nr   *GATEWAY_SECRET_CAPTURE_UNSUPPORTED_MESSAGEziSecure secret entry is not available. Load this skill in the local CLI to be prompted, or add the key to z/.env manually.)gateway.platforms.baser   r   r   r   s    r4   r   r     s~    bUUUUUU99 b b b b  |O  |Q  |Q  b  b  b  	b  	b  	bbs   
 ))readiness_statusmissing
setup_helpc                 z    | t           j        k    r*|rd                    |          nd}d| d}|r| d| S |S d S )N, zrequired prerequisitesz.Setup needed before using this skill: missing . )rh   rp   join)r   r   r   missing_strnotes        r4   _build_setup_noter     se    
 /<<<,3Qdii(((9QNNNN 	*))Z)))4r<   c                      dS )zOSkills are always available -- the directory is created on first use if needed.Trr   rr   r<   r4   check_skills_requirementsr   $  s    4r<   contentc                 $    ddl m}  ||           S )u   Parse YAML frontmatter from markdown content.

    Delegates to ``agent.skill_utils.parse_frontmatter`` — kept here
    as a public re-export so existing callers don't need updating.
    r   )parse_frontmatter)r|   r   )r   r   s     r4   _parse_frontmatterr   )  s'     433333W%%%r<   
skill_pathc                 ,   t                      g}	 ddlm} |                     |                       n# t          $ r Y nw xY w|D ]L}	 |                     |          }|j        }t          |          dk    r
|d         c S =# t          $ r Y Iw xY wdS )z
    Extract category from skill path based on directory structure.

    For paths like: ~/.hermes/skills/mlops/axolotl/SKILL.md -> "mlops"
    Also works for external skill dirs configured via skills.external_dirs.
    r   get_external_skills_dirs   N)	r;   r|   r   extendr   relative_topartslen
ValueError)r   dirs_to_checkr   
skills_dirrel_pathr   s         r4   _get_category_from_pathr   3  s     !]]OM>>>>>>55778888   #  
	!--j99HNE5zzQQx  	 	 	H	4s!   #5 
AA
6B
BBc                 4   | sg S t          | t                    rd | D             S t          |                                           } |                     d          r|                     d          r
| dd         } d |                     d          D             S )uB  
    Parse tags from frontmatter value.

    Handles:
    - Already-parsed list (from yaml.safe_load): [tag1, tag2]
    - String with brackets: "[tag1, tag2]"
    - Comma-separated string: "tag1, tag2"

    Args:
        tags_value: Raw tags value — may be a list or string

    Returns:
        List of tag strings
    c                 T    g | ]%}|t          |                                          &S rr   r   r   ts     r4   r   z_parse_tags.<locals>.<listcomp>a  s+    8881a8A888r<   []   c                     g | ]=}|                                 |                                                      d           >S )rZ   )rN   r  s     r4   r   z_parse_tags.<locals>.<listcomp>h  s9    OOOqQWWYYOAGGIIOOE""OOOr<   ,)rM   r   r(   rN   r]   endswithsplit)
tags_values    r4   _parse_tagsr  M  s      	 *d## 988
8888 Z&&((JS!! &j&9&9#&>&> &"%
OOJ,<,<S,A,AOOOOr<   c                  "    ddl m}   |             S )u   Load disabled skill names from config.

    Delegates to ``agent.skill_utils.get_disabled_skill_names`` — kept here
    as a public re-export so existing callers don't need updating.
    r   get_disabled_skill_names)r|   r  r  s    r4   _get_disabled_skill_namesr  l  s%     ;:::::##%%%r<   c                  L    	 ddl m}   | d          pdS # t          $ r Y dS w xY w)zResolve the current platform from gateway session context.

    Mirrors the platform-resolution logic in
    ``agent.skill_utils.get_disabled_skill_names`` so that
    ``_is_skill_disabled`` respects ``HERMES_SESSION_PLATFORM``.
    r   r   r   r   )r   r   r   r   s    r4   _get_session_platformr  v  sQ    ;;;;;;899?R?   rrs    
##r   c                 (   	 ddl m}  |            }|                    di           }|p!t          j        d          pt                      }|                    dg           }|rt          |d|          }|| |v p| |v S | |v S # t          $ r Y dS w xY w)	a  Check if a skill is disabled in config.

    Resolves the active platform from (in order of precedence):
    1. Explicit ``platform`` argument
    2. ``HERMES_PLATFORM`` environment variable
    3. ``HERMES_SESSION_PLATFORM`` from gateway session context
    r   )load_configr6   HERMES_PLATFORMr,   platform_disabledNF)hermes_cli.configr  r   r$   r   r  r   r   )rI   r   r  config
skills_cfgresolved_platformglobal_disabledr  s           r4   _is_skill_disabledr    s    111111ZZ"--
$_	2C(D(D_H]H_H_$..R88 	L '
4GIZ [ [ , 00KDO4KK&&   uus   A<B ?B 
BBF)skip_disabledr  c           	      ^   ddl m}m} | rt          nt          }| rt                      nt                      }g }t                      }|                                r|	                    |           |
                     |                       t          ||          }t          j                    }t                              |          }	|	2|	d         |k    r&||	d         z
  t           k     rd |	d         D             S g }
t                      }|D ]} ||d          D ]}t#          d |j        D                       r"|j        }	 |                    d	
          dd         }t+          |          \  }}t-          |          sjt/          |          sz|                    d|j                  dt2                   }||v r||v r|                    dd          }|sY|                                                    d          D ]1}|                                }|r|                    d          s|} n2t;          |          t<          k    r|dt<          dz
           dz   }t?          |          }|                     |           |
	                    |||d           # tB          tD          f$ r'}tF          $                    d||           Y d}~d}~wtJ          $ r)}tF          $                    d||d           Y d}~d}~ww xY w|||
ft          |<   d |
D             S )a=  Recursively find all skills in ~/.hermes/skills/ and external dirs.

    Args:
        skip_disabled: If True, return ALL skills regardless of disabled
            state (used by ``hermes skills`` config UI). Default False
            filters out disabled skills.

    Returns:
        List of skill metadata dicts (name, description, category).

    Results are cached per-session; the cache is invalidated when the scan
    signature changes (dir/category mtimes or the disabled-set) and expires
    after a short TTL to bound staleness from in-place SKILL.md edits.
    r   )r   iter_skill_index_filesNr  c                 ,    g | ]}t          |          S rr   r   r   ss     r4   r   z$_find_all_skills.<locals>.<listcomp>  s    +++AQ+++r<      SKILL.mdc              3   (   K   | ]}|t           v V  d S ru   )_EXCLUDED_SKILL_DIRS)r   parts     r4   	<genexpr>z#_find_all_skills.<locals>.<genexpr>  s(      KKD4//KKKKKKr<   rT   rU   i  rI   descriptionr   
rW   r   ...)rI   r,  categoryz Failed to read skill file %s: %sz)Skipping skill at %s: failed to parse: %sTr   c                 ,    g | ]}t          |          S rr   r#  r$  s     r4   r   z$_find_all_skills.<locals>.<listcomp>
  s    $$$DGG$$$r<   )&r|   r   r!  _SKILLS_CACHE_KEY_DISABLED_SKILLS_CACHE_KEY_FILTEREDr   r  r;   r[   r'   r   r5   time	monotonicr   r   _SKILLS_CACHE_TTL_SECONDSanyr   parent	read_textr   r{   r   rI   MAX_NAME_LENGTHrN   r  r]   r   MAX_DESCRIPTION_LENGTHr   r   UnicodeDecodeErrorPermissionErrorr   debugr   )r  r   r!  	cache_keyr,   r+   active_skills_dir	signaturenowcachedr6   
seen_namesscan_dirskill_md	skill_dirr   ry   bodyrI   r,  rb   r/  es                          r4   _find_all_skillsrI    s    SRRRRRRR.;[**A[I &Fsuuu+D+F+FH
 L#!! /-...0022333&|X>>I
.

Cy))F1I""6!9_ 999
 ,+++++FeeJ ! 2 2..xDD 1	 1	HKKHNKKKKK  I+",,g,>>uuE$6w$?$?!T-k:: 0== "vy~>>?O?OP:%%8##)oomR@@" " $

 2 24 8 8 " "#zz|| "(<(< "*.K!E{##&<<<"-.I/E/I.I"JU"RK28<<t$$$ #. (      '8   ?1MMM   ?1W[     	[1	n !*37M)$$V$$$$s=   	?J(	J(,J(J(CJ((L9KL(LLc                 &    t          | d           S )z3Keep every skill listing path ordered the same way.c                 @    |                      d          pd| d         fS )Nr/  r   rI   r   )r%  s    r4   <lambda>z_sort_skills.<locals>.<lambda>  s     z):):)@b!F)(L r<   )rc   )sorted)r6   s    r4   _sort_skillsrO    s    &LLMMMMr<   r/  task_idc                 P    	 t                      }|                                sB|                    dd           t          j        dg g dt                       ddd          S t                      }|st          j        dg g ddd          S  r fd	|D             }t          |          }t          d
 |D                       }t          j        d||t          |          ddd          S # t          $ r(}t          t          |          d          cY d}~S d}~ww xY w)a  
    List all available skills (progressive disclosure tier 1 - minimal metadata).

    Returns only name + description to minimize token usage. Use skill_view() to
    load full content, tags, related files, etc.

    Args:
        category: Optional category filter (e.g., "mlops")
        task_id: Optional task identifier used to probe the active backend

    Returns:
        JSON string with minimal skill info: name, description, category
    T)parentsexist_okz-No skills found. Skills directory created at z/skills/)r   r6   
categoriesmessageFensure_asciiz%No skills found in skills/ directory.c                 F    g | ]}|                     d           k    |S r/  rL  )r   r%  r/  s     r4   r   zskills_list.<locals>.<listcomp>>  s/    QQQ1553D3D3P3P!3P3P3Pr<   c                 b    h | ],}|                     d           |                     d           -S rY  rL  r$  s     r4   	<setcomp>zskills_list.<locals>.<setcomp>E  s5    HHH1aeeJ6G6GHQUU:HHHr<   z@Use skill_view(name) to see full content, tags, and linked files)r   r6   rT  counthintr   N)r;   r[   mkdirjsondumpsr   rI  rO  rN  r   r   r   r(   )r/  rP  r?  
all_skillsrT  rH  s   `     r4   skills_listrc    s   41'MM '')) 
	##D4#@@@:# "$nObOdOdnnn	  #    &''
 		:# "$F	  #     	RQQQQZQQQJ "*--
 HH
HHH
 

 z$(ZZ  	
 	
 	
 		
  1 1 1#a&&%0000000001s+   A#C3 '*C3 A C3 3
D%=D D% D%T
preprocess
session_idrE  	namespacebarere  rf  c          
         ddl m}m} | |            v rt          j        dd| d| dd          S 	 |                     d	          n9# t          $ r,}t          j        dd
| d d| dd          cY d}~S d}~ww xY wi }	 t                    \  }}	n# t          $ r Y nw xY wt          |          s0t          j        dd| d dt          j
        j        dd          S t          fdt          D                       rt                              d|           t!          |                    dd                    }
t%          |
          t&          k    r|
dt&          dz
           dz   }
	 fd |                                |          D             }|r+d                    |          }d| d| d| d|d          d	}nd| d}n# t          $ r d}Y nw xY w}|rI	 ddlm}  || j        |          }n.# t          $ r! t                              d |d!"           Y nw xY wt          j        d!| d |r| | n||
dt          j        j        d#d          S )$z8Read a plugin-provided skill, apply guards, return JSON.r   )_get_disabled_pluginsget_plugin_managerFzPlugin 'z5' is disabled. Re-enable with: hermes plugins enable r   errorrV  rT   rU   Failed to read skill ':': NSkill '$' is not supported on this platform.r   rm  r   c              3   D   K   | ]}|                                 v V  d S ru   )r   )r   pr   s     r4   r+  z&_serve_plugin_skill.<locals>.<genexpr>  s0      
=
=A1
=
=
=
=
=
=r<   zIPlugin skill '%s:%s' contains patterns that may indicate prompt injectionr,  r   r   r.  c                      g | ]
}|k    |S rr   rr   )r   r%  rh  s     r4   r   z'_serve_plugin_skill.<locals>.<listcomp>  s*     
 
 
Dyy yyr<   r   z,[Bundle context: This skill is part of the 'z' plugin.
Sibling skills: z..
Use qualified form to invoke siblings (e.g. z).]

z' plugin.]

preprocess_skill_contentrf  z'Could not preprocess plugin skill %s:%sTr   )r   rI   r   r,  linked_filesr   )hermes_cli.pluginsrj  rk  r`  ra  r8  r   r   r{   rh   rq   re   r6  rs   r   r   r(   r   r   r:  list_plugin_skillsr   agent.skill_preprocessingrx  r7  r=  ro   )rE  rg  rh  re  rf  rj  rk  rH  parsed_frontmatterrd   r,  siblingssib_listbannerrendered_contentrx  r   s     `             @r4   _serve_plugin_skillr  Z  s7    MLLLLLLL))++++z Iy I I=FI I  	
 	
 	
 		

$$g$66 
 
 
z(Y(Y(YT(Y(YVW(Y(YZZ
 
 
 	
 	
 	
 	
 	
 	

 *, 27 ; ;AA    ""455 
z Y9YYtYYY$8$D$J 
 
 
 
 	
 
=
=
=
=)<
=
=
=== 
Wt	
 	
 	

 (,,]B??@@K
;000!">$:Q$>">?%G
 
 
 
))++>>yII
 
 
  	^yy**H`y ` `#+` `?H` `KSTU;` ` ` F ^I]]]F     	JJJJJJ77%     
  	 	 	LL99dUY      	
 : ))4))8>T&4"2444DT&  4 > D	
 	
 
 
 
 
sT   A 
B!A?9B?B
B 
B*)B*9AG G%$G%-H (H21H2	file_pathc                 $  YZ[\]^_ 	 t          |           }|rt          j        d|ddd          S d}d| v r3ddlm}m} dd	lm}m}	  ||           \  \}
 |\          s t          j        dd
\ d|  ddd          S  |              |	            }|	                    |           }|]|
                                s5|                    |            t          j        dd|  d| ddd          S t          |\|
||          S |                    \          }|rBt          j        dd|
 d\ d\fd|D             d\ dt          |           ddd          S |
r\ d|
 }ddlm} |r+t          |          }|rt          j        d|ddd          S g }t!                      }|
                                r|                    |           |                     |                       |st          j        dddd          S d_d}ddlm} g Zt)                      ^dt*          t,                   dt,          ddfZ^fd }|D ]K}|| z  }t/          |          s;|                                r'|d!z  
                                r |||d!z             nh|                    d"          
                                rAt/          |                    d"                    s |d|                    d"                     |r||z  }t/          |          s;|                                r'|d!z  
                                r |||d!z             nh|                    d"          
                                rAt/          |                    d"                    s |d|                    d"                      ||d!          D ]}|j        j        | k    r ||j        |           $	 |                    d#$          }t;          |          \  }}n# t<          $ r i }Y nw xY w|                    d%          | k    r ||j        |           |                     |  d"          D ](}|j        d!k    rt/          |          s |d|           )Mt          Z          d&k    rd' ZD             }tC          j"        tF                    $                    d(| t          Z          d)%                    |                     t          j        dd*|  d+t          Z           d,|d-d.d          S ZrZd         \  _}|r|
                                sLd/ tM          tO                                dd0         D             }t          j        dd|  d1|d2dd          S 	 |                    d#$          }n6# t<          $ r)}t          j        dd3|  d+| dd          cY d}~S d}~ww xY wd4}|(                                g} 	 |                     d5 |d&d         D                        n# t<          $ r Y nw xY w| D ]=}!	 |(                                )                    |!           d} n# tT          $ r Y :w xY w|+                                YtY          Yfd6tZ          D                       }"|s|"rtg }#|r|#                    d7|            |"r|#                    d8           tC          j"        tF                    $                    d9| d)%                    |#                     i }$	 t;          |          \  }$}n# t<          $ r i }$Y nw xY wt]          |$          s-t          j        dd|  d:t^          j0        j1        d;d          S |$                    d%|j        j                  }%te          |%          rt          j        dd|% d<dd          S |r։_rdd=l3m4}&m5}'  |'|          rt          j        dd>d?dd          S _|z  }( |&|(_          })|)rt          j        d|)d?dd          S |(
                                sg g g g g d@}*_                     dA          D ]/}+|+6                                r|+j        d!k    rto          |+)                    _                    },|,8                    dB          r|*dC                             |,           w|,8                    dD          r|*dE                             |,           |,8                    dF          r|*dG                             |,           |,8                    dH          r|*dI                             |,           |+j9        dJv r|*dK                             |,           1dL |*:                                D             }*t          j        ddM| dN|  d|*dOdPd          S 	 |(                    d#$          }nO# tv          $ rB t          j        d4| |dQ|(j         dR|(<                                j=         dSd4dTd          cY S w xY w	 ddUl>m?}-  |-|(           n-# t<          $ r  t          A                    dV|(d4W           Y nw xY wt          j        d4| |||(j9        to          |(          dXd          S |$}.g }/g }0g }1g }2_rX_dCz  }3|3
                                r!_fdY|3B                    dZ          D             }/_dEz  }4|4
                                r9d[D ]6}5|0                    _fd\|4                     |5          D                        7_dGz  }6|6
                                ra|6                     dA          D ]K}+|+6                                r5|1                    to          |+)                    _                               L_dIz  }7|7
                                r9d]D ]6}5|2                    _fd^|7B                    |5          D                        7i }8|.                    d_          }9t          |9t                    r|9                    d`i           pi }8t          |8                    da          p|.                    dadb                    }:t          |8                    dc          p|.                    dcdb                    };i }<|/r|/|<dC<   |0r|0|<dE<   |1r|1|<dG<   |2r|2|<dI<   	 to          |)                    |                    }=nO# tT          $ rB |j        j        r,to          |)                    |j        j                            n|j        }=Y nw xY w|.                    d%_s|jF        n_j                  }>t          |.          \  }?}t          |.|?          }@t                      }At                      [[fdd|@D             }Bt          |>|B          }C|Brt                      [t          |@|C[e          ]t          ]          }D]fdf|@D             }E|Er@	 ddglNmO}F  |F|E           n-# t<          $ r  t          A                    dh|>d4W           Y nw xY w|.                    dig           }Gt          |Gt                    sg }Gg }H|GrD	 ddjlQmR}I  |I|G          }H|Hrd4}Dn-# t<          $ r  t          A                    dk|>d4W           Y nw xY w|}J|rC	 ddllSmT}K  |K|_|m          }Jn-# t<          $ r  t          A                    dn|>d4W           Y nw xY wd}L_r$	 ddolmU}MmV}NmW}O  |N_|          r |O_|          }Pdb}Qdb}R|Pr	 t          jX        |dpz  |Pz  |Mz                      d#$                    }Sto          |S                    dq          p|S                    dr          pdb          }Qto          |S                    ds          pdb          }Rn# t<          $ r Y nw xY w|P|Qpd|Rpddt}Ldu|P dv|Qrdw|Q dvndbz   |Rrdx|R ndbz   dyz   }T|T|Jz   }Jn-# t<          $ r  t          A                    dz|>d4W           Y nw xY wi d{d4d%|>d||.                    d|db          da|:dc|;d}|Jd~|=d_rto          _          ndd|Ld|<r|<ndd|<rdndd|@dg d]d|Hdg d|D|Cd         |Drt^          jY        j1        nt^          jZ        j1        to          |          d}Ut          d |@D             d          }V|Vr|V|Ud<   |Cd         r|Cd         |Ud<   	 ddUl>m?}-  |-|           n-# t<          $ r  t          A                    dV|d4W           Y nw xY w|Dr`d ]D             d |HD             z   }Wt          t^          jY        |W|V          }X|At          v r|Xr|X d|A^                                 d}X|Xr|X|Ud<   |.                    d          r|.d         |Ud<   t          |9t                    r|9|Ud_<   t          j        |Ud          S # t<          $ r(}t          to          |          d          cY d}~S d}~ww xY w)a  
    View the content of a skill or a specific file within a skill directory.

    Args:
        name: Name or path of the skill (e.g., "axolotl" or "03-fine-tuning/axolotl").
            Qualified names like "plugin:skill" resolve to plugin-provided skills.
        file_path: Optional path to a specific file within the skill (e.g., "references/api.md")
        task_id: Optional task identifier used to probe the active backend
        preprocess: Apply configured SKILL.md template and inline shell rendering
            to main skill content. Internal slash/preload callers disable this
            because they render the skill message themselves.

    Returns:
        JSON string with skill content or error message
    Fz>Use a skill name or relative path within the skills directory.)r   rm  r]  rV  Nro  r   )is_valid_namespaceparse_qualified_name)discover_pluginsrk  zInvalid namespace 'z' in 'z('. Namespaces must match [a-zA-Z0-9_-]+.rl  rq  z' file no longer exists at uT   . The registry entry has been cleaned up — try again after the plugin is reloaded.rd  z' not found in plugin 'z'.c                     g | ]	} d | 
S )ro  rr   )r   r%  rg  s     r4   r   zskill_view.<locals>.<listcomp>  s'    ,S,S,SA	-?-?A-?-?,S,S,Sr<   zThe 'z' plugin provides z
 skill(s).)r   rm  available_skillsr]  /r   zISkills directory does not exist yet. It will be created on first install.)r!  sdsmdr   c                     	 |                                 }n# t          $ r |}Y nw xY w|v rd S                     |                               | |f           d S ru   )resolver   r   r'   )r  r  rc   
candidatesseen_mds      r4   _recordzskill_view.<locals>._recordY  sy    kkmm   g~~KKr3i(((((s    ''r'  .mdrT   rU   rI   r  c                 2    g | ]\  }}t          |          S rr   )r(   )r   rd   r  s      r4   r   zskill_view.<locals>.<listcomp>  s"    777&!SSXX777r<   u3   Skill name collision for '%s': %d candidates — %sz; zAmbiguous skill name 'rp  u    skills match across your local skills dir and external_dirs. Refusing to guess — load one explicitly by its categorized path.zPass the full relative path instead of the bare name (e.g., 'category/skill-name'), or rename one of the colliding skills so each name is unique.)r   rm  matchesr]  c                     g | ]
}|d          S r   rr   r$  s     r4   r   zskill_view.<locals>.<listcomp>  s    RRRq6RRRr<      z' not found.z+Use skills_list to see all available skillsrn  Tc              3   >   K   | ]}|                                 V  d S ru   )r  )r   r/   s     r4   r+  zskill_view.<locals>.<genexpr>  s*       C C C C C C C Cr<   c              3       K   | ]}|v V  	d S ru   rr   )r   ru  _content_lowers     r4   r+  zskill_view.<locals>.<genexpr>  s(      !S!S!!~"5!S!S!S!S!S!Sr<   zHskill file is outside the trusted skills directory (~/.hermes/skills/): zBskill content contains patterns that may indicate prompt injectionz#Skill security warning for '%s': %srr  rs  zT' is disabled. Enable it with `hermes skills` or inspect the files directly on disk.)validate_within_dirrK   z%Path traversal ('..') is not allowed.z.Use a relative path within the skill directory)
references	templatesassetsscriptsother*zreferences/r  z
templates/r  zassets/r  zscripts/r  >   .py.sh.tex.yml.json.yamlr  r  c                     i | ]
\  }}|||S rr   rr   )r   kvs      r4   
<dictcomp>zskill_view.<locals>.<dictcomp>K  s#    "Q"Q"QDAqq"Q1a"Q"Q"Qr<   zFile 'z' not found in skill 'z0Use one of the available file paths listed above)r   rm  available_filesr]  z[Binary file: z, size: z bytes])r   rI   filer   	is_binary)!mark_background_review_skill_readz4Could not record background-review skill read for %sr   )r   rI   r  r   	file_type_source_pathc                 T    g | ]$}t          |                                        %S rr   r(   r   r   ra   rF  s     r4   r   zskill_view.<locals>.<listcomp>  s:     # # #67Ci0011# # #r<   *.md)r  *.pyz*.yamlz*.ymlz*.jsonz*.tex*.shc                 T    g | ]$}t          |                                        %S rr   r  r  s     r4   r   zskill_view.<locals>.<listcomp>  s=        !  i 8 899  r<   )r  r  z*.bashz*.jsz*.tsz*.rbc                 T    g | ]$}t          |                                        %S rr   r  r  s     r4   r   zskill_view.<locals>.<listcomp>  s-    VVV1Q]]95566VVVr<   r   hermestagsr   related_skillsc                 j    g | ]/}|                     d           t          |d                   -|0S )r   rI   )r   r   )r   rH  r   s     r4   r   zskill_view.<locals>.<listcomp>  sS     %
 %
 %
55$$%
 *!F)\BB	%
%
 %
 %
r<   r   c                 4    g | ]}|d          v|d          S r   rr   )r   rH  remaining_missing_required_envss     r4   r   zskill_view.<locals>.<listcomp>  s7     
 
 
y ??? fI???r<   )register_env_passthroughz/Could not register env passthrough for skill %srequired_credential_files)register_credential_filesz0Could not register credential files for skill %srw  ry  z)Could not preprocess skill content for %s)ORG_PROVENANCE_FILEis_org_mirror_pathorg_id_of_path_orgauthor_deviceauthor_user_idts)org_id	shared_byas_ofu\   > [!NOTE] ORG-SHARED SKILL — provenance
> This skill is shared by your organisation (org ``z, last updated by `z, as of uP  ). It was reviewed and approved for the whole
> team — treat it as third-party instructions rather than your own notes.
> You MAY improve it in place like any other skill. Your edits are kept locally
> and are never overwritten by org updates; share them back with
> `hermes sync propose` (or automatically, if your org enables it).

z'Could not resolve org provenance for %sr   r,  r   pathrF  org_provenancerz  
usage_hintzzTo view linked files, call skill_view(name, file_path) where file_path is e.g. 'references/api.md' or 'assets/config.yaml'r   required_commands&missing_required_environment_variablesmissing_credential_filesmissing_required_commandsrj   r   )r   r   r  c              3   P   K   | ]!}|                     d           |d          V  "dS )r   NrL  )r   rH  s     r4   r+  zskill_view.<locals>.<genexpr>  s5      QQ155==Q1V9QQQQQQr<   r   r   c                     g | ]}d | S )zenv $rr   )r   r   s     r4   r   zskill_view.<locals>.<listcomp>  s.       '/"""  r<   c                     g | ]}d | S )zfile rr   )r   r  s     r4   r   zskill_view.<locals>.<listcomp>  s+       #'  r<   r   zW-backed skills need these requirements available inside the remote environment as well.
setup_notecompatibilityr^  )`rR   r`  ra  r|   r  r  r{  r  rk  find_plugin_skillr[   remove_plugin_skillr  r|  r   r   r;   r'   r   r!  r   r   r   _is_skill_support_pathr&   with_suffixr7  rI   r8  r   r   r   rgloblogging	getLoggerrl   r   r   rO  rI  r  r   r   r   r6  rs   r{   rh   rq   re   r  rL   r  rK   is_filer(   r]   suffixitemsr;  r!   st_sizetools.skill_manager_toolr  r   r=  globrM   r   r  stemr   r   r   rf   r   r   r   tools.env_passthroughr  r   tools.credential_filesr  r}  rx  r  r  r  loadsrp   ro   nextr   _REMOTE_ENV_BACKENDSupperr   )`rI   r  rP  re  lookup_errorlocal_category_namer  r  r  rk  rh  pmplugin_skill_mdri   r   all_dirsr?  rE  r!  r  
search_dirdirect_pathcategorized_pathfound_skill_md
fm_contentfmrd   found_mdpathsr   rH  _outside_skills_dir_trusted_dirs_td_injection_detected	_warningsr~  resolved_namer  rK   target_filetraversal_errorr  ra   relr  ry   reference_filestemplate_filesasset_filesscript_filesreferences_dirtemplates_dirext
assets_dirscripts_dirhermes_metar   r  r  rz  r   r   r   r   backendmissing_required_env_varsr   rj   available_env_namesr  required_cred_files_rawmissing_cred_filesr  r  rx  r  r  r  r  prov_orgauthorr  provheaderresultr   missing_itemsr  r  r  r   rg  r  r  rF  s`                                                                                            @@@@@@@r4   
skill_viewr    s:   *T1
 055 	:$)\ 
 #    +/ $;;RRRRRRRROOOOOOOO22488OIt%%i00 
z#(E) E E4 E E E  "'	 	 	 	 ##%%B 22488O*&--// **4000:',!7$ !7 !7#2!7 !7 !7  &+    +#)&    --i88I 	z#(!U4!U!U	!U!U!U,S,S,S,S,S,S,S _	 _ _S^^ _ _ _	  "'     <)2&;&;T&;&;#>>>>>>  
	34GHHL z#(!- ` 
 "'    'MM##%% 	/OO-...0022333 	:$h  #    	 	=<<<<<8:
uu	) 	)T 	)d 	) 	) 	) 	) 	) 	) 	) # :	, :	,J %t+K*;77	>&&((	> !:-5577	>
 [:%=>>>>((//6688 >AW''..B B > k55e<<===
 # G#-0C#C ./?@@G(//11G *J6>>@@G
 G,.>.KLLLL%11 &((G#9$0077$ $G
 GD"2">">u"E"EFFF #9"8Z"P"P 
C 
C!(-55GN1>BBB!/!9!97!9!K!KJ.z::EB    BBB66&>>T))GN1>BBB ',,\\\:: , ,=J..7M8 8. GD(+++	, z??Q77J777Eh''//Ec*ootyy'7'7   :$] ] ]#j// ] ] ]  %C  #   $  	0",Q-Ix 
	x00 
	RRL9I9K9K,L,LSbS,QRRRI:$9t999(1I	  #   		(('(::GG 	 	 	:$BdBBqBB  #        	 #*22445	   C Chqrrl C C CCCCC 	 	 	D	  	 	C  ""..s333&+#   
 !!!S!S!S!S?R!S!S!SSS 	s"5 	sI" x  !vlt!v!vwww" g  !efffh''//0UW[]a]f]fgp]q]qrrr-/	$$6w$?$?! 	$ 	$ 	$!#	$ &&899 	:$QtQQQ(<(H(N 
 #    +..vx7KLLm,, 
	:$`- ` ` `  #	 	 	 	  p	 p	XXXXXXXX '&y11 z#(!H P 
 "'    $i/K 21+yIIO z#(!0 P 
 "'    %%'' , #%!# !# # #-- A AAyy{{ Aqv';';!!--	":":;;>>-88 A+L9@@EEEE ^^L99 A+K8??DDDD ^^I66 A+H5<<SAAAA ^^J77 A+I6==cBBBBX *   ,G4;;C@@@ #R"QO4I4I4K4K"Q"Q"Qz#(!S)!S!S4!S!S!S+: R	  "'   %///AA%   z#' $ )#qK4D#q#qkN^N^N`N`Nh#q#q#q%)  "'	 	 	 	 	 		VVVVVV11+>>>>   J!       :# %&!,!3 %($4$4	 	 #    )  %	&5N$$&& # # # #;I;N;Nv;V;V# # # &3M##%%   C #))   %2%8%8%=%=      #X-J  "" J#))#.. J JAyy{{ J#**3q}}Y/G/G+H+HIII#i/K!!## M  C ''VVVV@P@PQT@U@UVVV    ??:..h%% 	;",,x44:K;??622Qkoofb6Q6QRR$OO,--VAQSU1V1V
 

  	9)8L& 	7(6L% 	1%0L" 	3&2L#	v8//0ABBCCHH 	v 	v 	vLTOLbus8//0FGGHHHhphuHHH	v !__FHMM	
 

 :+FF?
 
 -..zz%
 %
 %
 %
&%
 %
 %
! A%
 
 % 	&#::L*O%+
 +
 +
'
 ;<<

 
 
 
&
 
 

  
		JJJJJJ(()<====   E!       #.//2Mr"R"R1488 	)&(##%" 	LLLLLL%>%>?V%W%W"% (#'L   F!       # 	NNNNNN#;#;&$ $ $  
    ?VZ        9	8          &%i1BCC +A-~i9JKKHFB !!#':$5&,%-&.%/ ':%: #,)W)"="=$ $D &) $ 9 9 !&#'88,<#=#=!&#%& &F
 "%TXXd^^%9r!:!:BB( ! ! ! D! #+%+^t!#t& &N($( ( ( ?EL:::::"N /18?b???b	:
//   (.0@'@$   =!      
t
J
 ;??="==
 D	

 n
 '
 H
 9>Y$
 n
 LBLLd
   W  W
 -.?
  
  56U!
" '(:#
$ (%
& L'
( ,O<!6 4 A G G%/5  MM5
 
 
: QQ.?QQQSWXX
 	.#-F< ./ 	P+9:N+OF'(		RRRRRR--h7777 	 	 	LLF      	  	2 3R   +=  M
 +$1 J
 ...:. *  V  VW]]__  V  V  V
 2'1|$ ???++ 	C&1/&BF?#h%% 	*!)F:z&u5555 1 1 1#a&&%0000000001s  *AH AAH A3AH 8AH AAH %;AH !A0AH G!AH 4(PAH P,)AH +P,,DAH :A.AH *W  AH 
W4W/)W4*AH /W44AH 'X7 6AH 7
YAH YAH )Y75AH 7
ZAH ZB1AH 6]	 AH 	]AH ]>AH AAH #2AH ,AH F"AH 'g> =AH >A	i
AH 	i

AH i  AH  'j
AH 	j

1AH <H7AH 4"t AH A	u# AH "u##CAH (x: 9AH :'y$!AH #y$$4AH z/ .AH /'{AH {AH !{6 5AH 6'| AH |  AH )(A@ B!  A@ !
.+A@ -..0A@ @AH @'AA	AAH AAA	A	CAH DAD0 D/AH D0'AEEAH EAEEB4AH H
AIHAH<H6AIH<AI__main__u   🎯 Skills Tool Testz<============================================================u   
📋 Listing all skills:r   zFound r\  z skills in rT  z categorieszCategories: z
First 10 skills:
   r  z] r   u     • z: r,  <   r.  zError: rm  u   
📖 Viewing skill 'axolotl':axolotlzName: zDescription: zN/Ad   zContent length: z charsrz  zLinked files: uE   
📄 Viewing reference file 'axolotl/references/dataset-formats.md':zreferences/dataset-formats.mdzFile: r  z	Preview:    rc  zVList available skills (name + description). Use skill_view(name) to load full content.objectstringz*Optional category filter to narrow results)typer,  )r"  
propertiesr   )rI   r,  
parametersr  ah  Skills allow for loading information about specific tasks and workflows, as well as scripts and templates. Load a skill's full content or access its linked files (references, templates, scripts). First call returns SKILL.md content plus a 'linked_files' dict showing available references/templates/scripts. To access those, call again with file_path parameter.zThe skill name (use skills_list to see available skills). For plugin-provided skills, use the qualified form 'plugin:skill' (e.g. 'superpowers:writing-plans').zOPTIONAL: Path to a linked file within the skill (e.g., 'references/api.md', 'templates/config.yaml', 'scripts/validate.py'). Omit to get the main SKILL.md content.)rI   r  c                 p    t          |                     d          |                    d                    S )Nr/  rP  )r/  rP  )rc  r   )argskws     r4   rM  rM    s2    {*%%rvvi/@/@      r<   u   📚)rI   toolsetschemahandlercheck_fnemoji_skill_view_tracker   u   Skill content unchanged since it was loaded earlier in this conversation — refer to the earlier skill_view result; it is still current and complete. (Re-issued after context compression, this returns the full content again.)payloadc                     |                      d          }|sdS 	 t          j        |          }||j        |j        fS # t
          $ r Y dS w xY w)zIStat the skill file a successful skill_view served, for change detection.r  N)r   r$   r!   st_mtime_nsr  r#   )r/  srcsts      r4   _skill_view_fingerprintr4    se    
++n
%
%C tWS\\R^RZ00   tts   "> 
AAc                 n   | sdS |                     d          s|                     d          dk    rdS t          |          }|dS t          |                     d          p|          |pdf}t          5  t                              t          |           i           }|||<   t          |          t          k    r`	 |                    t          t          |                               n# t          t          f$ r Y nw xY wt          |          t          k    `ddd           dS # 1 swxY w Y   dS )zARecord a served skill_view so an identical repeat can be deduped.Nrj   r   rI   r   )r   r4  r(   _skill_view_tracker_lockr-  
setdefaultr   _SKILL_VIEW_DEDUP_CAPpopr  iterStopIterationKeyError)rP  rI   r  r/  fprc   caches          r4   _record_skill_viewr?  *  s     {{>"" gkk2D&E&E&W&W	 	)	)B	zw{{6""*d++Y_"
=C	!  #..s7||R@@c
%jj000		$tE{{++,,,,!8,    %jj000                 s7   7AD*>/C.-D*.D?D*DD**D.1D.c                    | sdS t           5  t                              t          |                     }|s	 ddd           dS t	          |                                          D ]T\  }\  }}}|\  }}	|	|pdk    r|t          |          k    rwt          |                              d|z             sR|                    dt          |          z             s-t          |                              d          d         |k    r	 t          j	        |          }
|
j
        |
j        f||fk    r$|                    |d            ddd           dS n3# t          $ r& |                    |d           Y  ddd           dS w xY wt          j        dd||pddd	t           d
d	          c cddd           S 	 ddd           n# 1 swxY w Y   dS )z|Return a dedup stub when this exact skill file was already served
    to this task and is unchanged on disk; None otherwise.Nr   r  ro  r  T	unchangedr'  F)r   statusrI   r  dedupcontent_returnedrU  rV  )r6  r-  r   r(   r   r  r  r  r$   r!   r1  r  r9  r#   r`  ra  _SKILL_VIEW_DEDUP_MESSAGE)rP  rI   r  r>  rc   r2  mtime_nssizerec_namerec_fpr3  s              r4   _check_skill_view_deduprJ  A  s     t	! ! !#''G55 	! ! ! ! ! ! ! ! +/u{{}}*=*= 	 	&C&#x"Hf)/r**3t99$$SYY-?-?h-O-O$$--cCIIo>> %D		,,R0H<<WS\\NBJ/Hd3CCCIIc4(((%! ! ! ! ! ! ! !  D    		#t$$$t+! ! ! ! ! ! ! !& :#)$%3!(-8  #    -! ! ! ! ! ! ! !	! ! ! ! ! ! ! ! ! ! ! ! ! ! !D 4sB   +GCG>EGG F5GF)GGGc                     t           5  | t                                           n(t                              t	          |           d           ddd           dS # 1 swxY w Y   dS )zClear the skill_view dedup cache (all tasks when task_id is None).

    Called on context compression: the original skill content is
    summarized away, so a re-view must return full content again.
    N)r6  r-  clearr9  r(   )rP  s    r4   reset_skill_view_deduprM  k  s     
" 8 8?%%''''##CLL$777	8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   AAA!Ac                    |                      dd          }|                     d          }t          |||                      d                    }||S t          ||                      d          |          }	 t          j        |          }t          |t                    r|                     d          rvt          |||                      d          |           |                     d          p|}|r8dd	lm	}m
}	  |	t          |                      |t          |                     n# t          $ r Y nw xY w|S )
ztInvoke skill_view, then bump view_count on success. Best-effort: a
    telemetry failure never breaks the tool call.rI   r   rP  r  N)r  rP  r   r   )bump_use	bump_view)r   rJ  r  r`  r  rM   r   r?  tools.skill_usagerO  rP  r(   r   )
r&  r'  rI   rP  stubr  parsedresolvedrO  rP  s
             r4   _skill_view_with_bumprU  x  s^    88FBDffYG #7D$((;2G2GHHD--w  FF##fd## 	(

9(=(= 	(wdhh{.C.CVLLL zz&))1TH (AAAAAAAA	#h--((( X'''   Ms   :B4D/ /
D<;D<)r   Nru   )NN)NNT)o__doc__r`  r  r3  	threadinghermes_constantsr   r   r$   reenumr   pathlibr   r   r   typingr	   r
   r   r   r   r   tools.registryr   r   r  r   utilsr   r|   r   r)  r   r  r  rl   r   r   r   __annotations__r5  r1  r2  r)   r5   HERMES_HOMEr8   r9   r;   r9  r:  _PLATFORM_MAPcompiler   r*   r  rv   r(   rR   rf   rh   rs   r   rx   r   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  rI  rO  rc  r  r  printr  r  r   r   skillcatSKILLS_LIST_SCHEMASKILL_VIEW_SCHEMAregisterr-  Lockr6  r8  rE  r4  r?  rJ  rM  rU  rr   r<   r4   <module>rj     s  A A AF        A A A A A A A A 				 				       8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 / / / / / / / / % % % % % % ! ! ! ! ! !       
 
	8	$	$ t     , ' 7e 7 7 7 7H o8#
" (T ( ( ( (  
  
 2:9::  yJJJ     3 8C=    6$sCx.    $         3      
 
 
 T 
 
 
( ( ( (
S#X 4    	4S> 	d 	 	 	 	># >$s) > > > >	c3h	
49d3i 	 	 	 	*4S> *d38n * * * *^ )-B Bc3hB#Y%B 
$sCx.B B B BJKK$sCx.)K 
#s(^K K K K\<T < < < <NC N N N N
 :>% %%!%c3h$!6%	% % % % +/	  DcN+cN sCx.4'	
 
#Y   (bS b b b b " *#Y d
 	4Z	   4    
& &d38nc.A(B & & & & #    4PtCy P P P P>&3s8 & & & &s     S C 4    4 /4 l% l% l%t l%T#s(^8L l% l% l% l%^Nd38n- N$tCH~2F N N N N
B1 B1# B1s B1c B1 B1 B1 B1Z !e e eee e
 e d
e 	e e e eT 	i1 i1
i1i1 i1 	i1
 	i1 i1 i1 i1\ z	E
!"""	E(OOO 
E
&'''TZ&&Fi 
+_VG___VZZb5Q5Q1R1R___	
 	
 	
 	;VZZb99;;<<<"###H%crc* 	Q 	QE/4yy/D/DL+eJ'++++"CEO3OfOO}1Ecrc1JOOOPPPP	Q 	)w))*** 
E
+,,,TZ

9--..Fi +'vf~''(((Ifjj>>ttDIIIJJJ?VI%6!7!7???@@@::n%% 	=E;6.#9;;<<<)w))*** 
E
RSSSTZ

9.MNNOOFi +'vf~''(((?VI%6!7!7???@@@6&+DSD16667777)w))*** k K 
 	 	     ~ !  A 
 !  F 	
 	
 H   &  	  '
	 	 	 	" 68 T#tE5L112 7 7 7)9>++  ' 	T 	edl 	 	 	 	$ 4    .'t ' ' ' 'T
8 
8C$J 
8$ 
8 
8 
8 
8% % %P  	!&
     r<   