
    `gj                        d Z ddlmZmZmZmZmZ g dZg dZi ddddgg d	d
ddgg d	dddgg d	dddgg d	dddgg d	dddgg d	ddg dg d	dddgg d	ddddgg d	dd g d!g d	d"d#g d$g d	d%d&d%gg d	d'd(g d)g d	d*d+d,gg d	d-d.d-gg d	d/d0d/gg d	d1d2g g d	i d3d4d3gg d	d5d6g d7g d	d8d9d8gg d	d:d;d<gg d	d=d>d?gg d	d@dAg dBg d	dCdDg dEg d	dFdGdFgg d	dHdIdHgg d	dJdKg dLg d	dMdNdOgg d	dPdQg dRg d	dSdTg dUg d	dVdWddgdd'gd	dXdYg g dZd	d[d\g d]g d^d_d`dag dbg d	i dcddg deg d	dfdgeg d	dhdieg d	djdkeg d	dldmedFdHgz   g d	dndoeg d	dpdqeg d	drdseg d	dtdueg d	dvdweg d	dxdyeg d	dzd{eg d	d|d}eg d	d~deg d	ddeg dz   g d	ddeg d	ddeg d	deg d	deg d	deg dLz   dg ddeg d	deg d	dg g dd	dZ	d^dde
dedeee
ef      fdZde
dee
   fdZdd^dde
dee
   dedee
   fdZdee
   dee
   fdZdee
   fdZdee
e
f   fdZdee
ee
ef   f   fdZdee
   fdZde
defdZ	 	 dde
de
dee
   dee
   ddf
dZde
dee
ef   fdZedk(  ri ed        ed        ed        ed        e       j3                         D ]@  \  ZZ ee      Zed   rdndZ ede dedded            ed eed          d       B  ed        ed       dD ]?  Z ee      Z ede d        ed ee       ddjA                   e!e                    A  ed        ed        eg d      Z" ed        eddjA                   e!e"                     ed        ed        edddgddgī        ed«      Z# edū        ede#d            eddjA                  e#d                 yy)a  
Toolsets Module

This module provides a flexible system for defining and managing tool aliases/toolsets.
Toolsets allow you to group tools together for specific scenarios and can be composed
from individual tools or other toolsets.

Features:
- Define custom toolsets with specific tools
- Compose toolsets from other toolsets
- Built-in common toolsets for typical use cases
- Easy extension for new toolsets
- Support for dynamic toolset resolution

Usage:
    from toolsets import get_toolset, resolve_toolset, get_all_toolsets
    
    # Get tools for a specific toolset
    tools = get_toolset("research")
    
    # Resolve a toolset to get all tool names (including from composed toolsets)
    all_tools = resolve_toolset("full_stack")
    )ListDictAnySetOptional)4
web_searchweb_extractterminalprocessread_terminalclose_terminal	read_file
write_filepatchsearch_filesvision_analyzeimage_generateskills_list
skill_viewskill_managebrowser_navigatebrowser_snapshotbrowser_clickbrowser_typebrowser_scrollbrowser_backbrowser_pressbrowser_get_imagesbrowser_visionbrowser_consolebrowser_cdpbrowser_dialogtext_to_speechtodomemorysession_searchclarifyexecute_codedelegate_taskcronjobha_list_entitiesha_get_stateha_list_servicesha_call_servicekanban_showkanban_listkanban_completekanban_blockkanban_heartbeatkanban_commentkanban_createkanban_linkkanban_unblockkanban_attachkanban_attach_urlkanban_attachmentscomputer_use)r   r	   r   r'   webz)Web research and content extraction toolsr   r	   descriptiontoolsincludessearchz0Web search only (no content extraction/scraping)x_searchu   Search X (Twitter) posts and threads via xAI's built-in x_search Responses tool. Available when xAI credentials are configured (SuperGrok OAuth or XAI_API_KEY). Off by default; enable in `hermes tools` → X (Twitter) Search.visionzImage analysis and vision toolsr   videozGVideo analysis and understanding tools (opt-in, not in default toolset)video_analyze	image_genz"Creative generation tools (images)r   	video_genu  Video generation tools. Single ``video_generate`` tool covers text-to-video (prompt only) and image-to-video (prompt + image_url), plus reference-to-video. Provider-specific edit/extend workflows may appear as separate tools. Configure via ``hermes tools`` → Video Generation.)video_generatexai_video_editxai_video_extendr;   u   Background desktop control via cua-driver (macOS/Windows/Linux) — screenshots, mouse, keyboard, scroll, drag. Does NOT steal the user's cursor or keyboard focus. Works with any tool-capable model.r
   z7Terminal/command execution and process management toolsr   skillsz\Access, create, edit, and manage skill documents with specialized instructions and knowledge)r   r   r   browserz|Browser automation for web interaction (navigate, click, type, scroll, iframes, hold-click) with web search for finding URLs)r   r   r   r   r   r   r   r   r   r    r!   r"   r   r*   zbCronjob management tool - create, list, update, pause, resume, remove, and trigger scheduled tasksfilez_File manipulation tools: read, write, patch (with fuzzy matching), and search (content + files))r   r   r   r   ttszVText-to-speech: convert text to audio with Edge TTS (free), ElevenLabs, OpenAI, or xAIr#   r$   z.Task planning and tracking for multi-step workr%   zAPersistent memory across sessions (personal notes + user profile)context_enginez2Runtime tools exposed by the active context enginer&   z7Search and recall past conversations with summarizationprojectuG   Desktop Projects — create/switch named workspaces (GUI sessions only))project_listproject_createproject_switchr'   zAAsk the user clarifying questions (multiple-choice or open-ended)code_executionzMRun Python scripts that call tools programmatically (reduces LLM round trips)r(   
delegationz:Spawn subagents with isolated context for complex subtasksr)   homeassistantz0Home Assistant smart home control and monitoring)r+   r,   r-   r.   kanbanu  Kanban multi-agent coordination — only active when the agent is spawned by the kanban dispatcher (HERMES_KANBAN_TASK env set). The dispatcher runs inside the gateway by default; see `kanban.dispatch_in_gateway` in config.yaml. Lets workers mark tasks done with structured handoffs, block for human input, heartbeat during long ops, comment on threads, attach files, and (for orchestrators) list, unblock, and fan out tasks.)r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   discordzSDiscord read and participate tools (fetch messages, search members, create threads)discord_adminzKDiscord server management (list channels/roles, pin messages, assign roles)yuanbaozAYuanbao platform tools - group info, member queries, DM, stickers)yb_query_group_infoyb_query_group_members
yb_send_dmyb_search_stickeryb_send_sticker
feishu_docz!Read Feishu/Lark document contentfeishu_doc_readfeishu_drivez:Feishu/Lark document comment operations (list, reply, add))feishu_drive_list_comments!feishu_drive_list_comment_repliesfeishu_drive_reply_commentfeishu_drive_add_commentspotifyzCNative Spotify playback, search, playlist, album, and library tools)spotify_playbackspotify_devicesspotify_queuespotify_searchspotify_playlistsspotify_albumsspotify_library	debuggingz%Debugging and troubleshooting toolkitsafez$Safe toolkit without terminal access)r<   rC   rF   codingzbCoding-focused toolset: files, terminal, search, web docs, skills, todo, delegate, vision, browser) r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   r%   r&   r'   r(   r)   T)r>   r?   r@   posturez
hermes-acpum   Editor integration (VS Code, Zed, JetBrains) — coding-focused tools without messaging, audio, or clarify UI)r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   r%   r&   r(   r)   zhermes-api-serveru|   OpenAI-compatible API server — full agent tools accessible via HTTP (no interactive UI tools like clarify or send_message))#r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   r%   r&   r(   r)   r*   r+   r,   r-   r.   z
hermes-clizHFull interactive CLI toolset - all default tools plus cronjob managementzhermes-cronzMDefault cron toolset - same core tools as hermes-cli; gated by `hermes tools`hermes-telegramzPTelegram bot toolset - full access for personal use (terminal has safety checks)hermes-discordz]Discord bot toolset - full access (terminal has safety checks via dangerous command approval)hermes-whatsappzMWhatsApp bot toolset - similar to Telegram (personal messaging, more trusted)hermes-slackzNSlack bot toolset - full access for workspace use (terminal has safety checks)hermes-signalz?Signal bot toolset - encrypted messaging platform (full access)hermes-bluebubbleszNBlueBubbles iMessage bot toolset - Apple iMessage via local BlueBubbles serverhermes-homeassistantzDHome Assistant bot toolset - smart home event monitoring and controlhermes-emailz>Email bot toolset - interact with Hermes via email (IMAP/SMTP)hermes-mattermostzAMattermost bot toolset - self-hosted team messaging (full access)hermes-matrixzDMatrix bot toolset - decentralized encrypted messaging (full access)hermes-dingtalkzBDingTalk bot toolset - enterprise messaging platform (full access)hermes-feishuzLFeishu/Lark bot toolset - enterprise messaging via Feishu/Lark (full access))ra   rc   rd   re   rf   hermes-weixinzFWeixin bot toolset - personal WeChat messaging via iLink (full access)hermes-qqbotzBQQBot toolset - QQ messaging via Official Bot API v2 (full access)z=WeCom bot toolset - enterprise WeChat messaging (full access)zJWeCom callback toolset - enterprise self-built app messaging (full access)uZ   Yuanbao Bot 元宝消息平台工具集 - 群信息、成员查询、私聊、贴纸表情ztools.yuanbao_tools)r>   r?   moduler@   z7SMS bot toolset - interact with Hermes via SMS (Twilio)z=Webhook toolset - receive and process external webhook eventsz7Gateway toolset - union of all messaging platform tools)rs   rt   ru   rv   rw   rx   ry   rz   
hermes-smsr{   r|   r}   r~   hermes-wecomhermes-wecom-callbackr   r   hermes-webhookhermes-yuanbao)r   r   r   r   r   zhermes-gatewayinclude_registrynamer   returnc                   t         j                  |       }|s>|syi |t        |j                  dg             t        |j                  dg             dS 	 ddlm} |rGt        t        |j                  dg             t        |j                  |             z        }i |d|iS | }d|  }|j                  |       }| t               vr|}|syd|  d	}nLt               j                         D 	ci c]  \  }}	|t         vr|	| }
}}	|
j                  |       }|rd| d	}||j                  |      g d
S # t
        $ r |r|cY S dcY S w xY wc c}	}w )a  
    Get a toolset definition by name.

    Args:
        name (str): Name of the toolset
        include_registry (bool): When True (default), merge in tools that
            plugins/overlays registered into this toolset via the registry.
            When False, return only the static ``TOOLSETS`` definition (the
            composite-authored view). Platform reverse-mapping in
            ``_get_platform_tools`` uses False so that a tool registered into a
            toolset but absent from a platform's static composite does not drop
            the whole toolset from inference. See issue #49622.

    Returns:
        Dict: Toolset definition with description, tools, and includes
        None: If toolset not found. With include_registry=False the static
            view only recognizes names literally present in ``TOOLSETS``, so
            registry/MCP-only toolsets AND registry-derived aliases return None
            (they have no static counterpart).
    Nr?   r@   )r?   r@   r   registryzPlugin toolset: zMCP server 'z' toolsr=   )TOOLSETSgetlisttools.registryr   	Exceptionsortedsetget_tool_names_for_toolsetget_toolset_alias_target_get_plugin_toolset_names_get_registry_toolset_aliasesitems)r   r   toolsetr   merged_toolsregistry_toolsetr>   alias_targetalias	canonicalreverse_aliasess              ;/root/.hermes/venv/lib/python3.12/site-packages/toolsets.pyget_toolsetr   L  s   * ll4 G 

'++gr23W[[R89
 	
,+ GR()(55d;<=
 2'17L11$TF+K44T:L,..'$TF'2 %B$C$I$I$K
 yH$ u
 

  ##D)(w7K #445EF ;  ,!w+t+,(
s   D7 1E7EE
Etoolset_namec                 *   t        t              }t        |       }|rd|v st        t        |             |z
  S t        |d         |z
  }|j	                  dg       D ]5  }t        |      }|sd|v s|j                  t        |d         |z
         7 |S )uj  Return a ``hermes-*`` bundle's platform-specific tools, excluding core.

    Platform bundles are defined as ``_HERMES_CORE_TOOLS + [platform extras]``.
    When a bundle name appears in ``disabled_toolsets``, subtracting the whole
    bundle would strip core tools (terminal, read_file, …) shared by every
    other enabled toolset, emptying the model's tool list (#33924). This
    returns only the bundle's non-core delta (its own extras plus those of any
    one-level ``includes``), so disabling a bundle removes its platform tools
    while leaving core intact.

    Bundle nesting is one level deep in practice (only ``hermes-gateway``
    includes other bundles, and those leaves don't nest further), so a single
    ``includes`` pass is sufficient. Unknown/garbage names fall back to the
    full resolution minus core — never re-introducing the core wipe.
    r?   r@   )r   _HERMES_CORE_TOOLSr   resolve_toolsetr   update)r   corets_def	to_removeincinc_defs         r   bundle_non_core_toolsr     s      !"D&Fw&(?<01D88F7O$t+Izz*b) ;c"w')S!12T9:;     Nvisitedc                *   |
t               }| dv rQt               }t               D ]/  }t        ||j                         |      }|j	                  |       1 t        |      S | |v rg S |j                  |        t        | |      }|s|r| j                  d      r|| t        d      d 	 ddl
m} |j                        rSt        t              }	 ddlm}	 |j	                  fd|	j                   j#                         D               t'        |      S 	 g S g S t        |j)                  d	g             }
|j)                  d
g       D ]!  }t        |||      }|
j	                  |       # t        |
      S # t$        $ r Y ww xY w# t$        $ r Y g S w xY w)a<  
    Recursively resolve a toolset to get all tool names.

    This function handles toolset composition by recursively resolving
    included toolsets and combining all tools.

    Args:
        name (str): Name of the toolset to resolve
        visited (Set[str]): Set of already visited toolsets (for cycle detection)
        include_registry (bool): When True (default), include tools that
            plugins/overlays registered into a toolset. When False, resolve only
            the static ``TOOLSETS`` definition (includes are still resolved, but
            statically). Platform reverse-mapping uses False so a registry-added
            tool cannot drop the whole toolset from inference (see #49622 and
            ``_get_platform_tools``).

    Returns:
        List[str]: List of all tool names in the toolset
    N>   *allr   zhermes-r   )platform_registryr   c              3   T   K   | ]  }|j                   k(  r|j                   ! y wN)r   r   ).0eplatform_names     r   	<genexpr>z"resolve_toolset.<locals>.<genexpr>  s)      ,'( yyM9 FF,s   %(r?   r@   )r   get_toolset_namesr   copyr   r   addr   
startswithlengateway.platform_registryr   is_registeredr   r   r   _toolsvaluesr   r   r   )r   r   r   	all_toolsr   resolvedr   r   plugin_toolsr   r?   included_nameincluded_toolsr   s                @r   r   r     s   ( % |!e	-/ 	'L&|W\\^VfgHX&	' i  
 w	KK $1ABG 	 : Y1MG$22=A#&'9#:L;$++ ,,4OO,B,B,D,   -- B 	r	 GR()E
 !Z4 %(Rbc^$% %=% %   	s6   +&F 8E6 

F 6	F?F FF 	FFtoolset_namesc                 r    t               }| D ]  }t        |      }|j                  |         t        |      S )z
    Resolve multiple toolsets and combine their tools.
    
    Args:
        toolset_names (List[str]): List of toolset names to resolve
        
    Returns:
        List[str]: Combined list of all tool names (deduplicated)
    )r   r   r   r   )r   r   r   r?   s       r   resolve_multiple_toolsetsr     s?     I  %  )r   c                      	 ddl m}  | j                         D ch c]  }|t        vr| c}S c c}w # t        $ r t               cY S w xY w)u   Return toolset names registered by plugins (from the tool registry).

    These are toolsets that exist in the registry but not in the static
    ``TOOLSETS`` dict — i.e. they were added by plugins at load time.
    r   r   )r   r   get_registered_toolset_namesr   r   r   )r   r   s     r   r   r     sU    + !) E E G
8+ 
 	
 

  us   3 .3 3 A	A	c                  R    	 ddl m}  | j                         S # t        $ r i cY S w xY w)z@Return explicit toolset aliases registered in the live registry.r   r   )r   r   get_registered_toolset_aliasesr   r   s    r   r   r   '  s-    +6688 	s    &&c                      t        t              } t               }t               D ]F  }|}|j	                         D ]  \  }}||k(  s|t        vs|} n || v r4t        |      }|sB|| |<   H | S )z
    Get all available toolsets with their definitions.

    Includes both statically-defined toolsets and plugin-registered ones.
    
    Returns:
        Dict: All toolset definitions
    )dictr   r   r   r   r   )resultaliasests_namedisplay_namer   r   r   s          r   get_all_toolsetsr   0  s     (^F+-G,. 
+ ' 	E9G#X(=$	 6!l+#*F< 
+ Mr   c                     t        t        j                               } t               }t	               D ]L  }|j                         D ]&  \  }}||k(  s|t        vs| j                  |        ; | j                  |       N t        |       S )z
    Get names of all available toolsets (excluding aliases).

    Includes plugin-registered toolset names.
    
    Returns:
        List[str]: List of toolset names
    )r   r   keysr   r   r   r   r   )namesr   r   r   r   s        r   r   r   I  s      E+-G,.  ' 	E9G#X(=		% 	
 IIg %=r   c                 P    | dv ry| t         v ry| t               v ry| t               v S )z
    Check if a toolset name is valid.
    
    Args:
        name (str): Toolset name to validate
        
    Returns:
        bool: True if valid, False otherwise
    >   r   r   T)r   r   r   )r   s    r   validate_toolsetr   `  s8     |x(**0222r   r>   r?   r@   c                 .    ||xs g |xs g dt         | <   y)a
  
    Create a custom toolset at runtime.
    
    Args:
        name (str): Name for the new toolset
        description (str): Description of the toolset
        tools (List[str]): Direct tools to include
        includes (List[str]): Other toolsets to include
    r=   N)r   r   r>   r?   r@   s       r   create_custom_toolsetr   t  s       #"NHTNr   c           
          t        |       }|syt        |       }| |d   |d   |d   |t        |      t        |d         dS )z
    Get detailed information about a toolset including resolved tools.
    
    Args:
        name (str): Toolset name
        
    Returns:
        Dict: Detailed toolset information
    Nr>   r?   r@   )r   r>   direct_toolsr@   resolved_tools
tool_countis_composite)r   r   r   bool)r   r   r   s      r   get_toolset_infor     s]     $G$T*N }-(J'(.)WZ01 r   __main__zToolsets System Demoz<============================================================z
Available Toolsets:z(----------------------------------------r   z[composite]z[leaf]z   20z - z     Tools: r   z totalz
Toolset Resolution Examples:)r<   r
   rp   ro   z
  :z    Resolved to z tools: z, z
Multiple Toolset Resolution:)r<   rC   r
   z*  Combining ['web', 'vision', 'terminal']:z    Result: z
Custom Toolset Creation:	my_customz$My custom toolset for specific tasksr   z  Created 'my_custom' toolset:z    Description: z    Resolved tools: r   )NN)$__doc__typingr   r   r   r   r   r   _HERMES_WEBHOOK_SAFE_TOOLSr   strr   r   r   r   r   r   r   r   r   r   r   r   __name__printr   r   r   info	compositer   r?   joinr   combinedcustom_info r   r   <module>r      s	  0 2 1
2 n h	B.h Ih ?
 	h2 8"#3h> `!"?hJ ;"#KhV 5 J
Whn R !!ohB Pi(ChN u>OhZ  V
 
[hr {sh@ xEAhL 
o"#MhX GYhd Zehp Kqh| P"#}hH `EIhT ZUh` f !ahl S!"mh~ I\hJ D
 #Khr lsh~ d!"hJ Z
 
Khb :#$chn S
 oh@ \
 AhX >i(FOYhd =2ehx {
  )yhx  G
 !yh^	  V
8 =_	h`
 a#a
hl
  g#	m
hB i#ChN v#'
 
 Oh` f#ahl g#mhx X#yhD g#EhP ]#Qh\ W#]hh Z#iht ]#uh@ [#AhL e# '
 
 
Mhd _#ehp [#qh~ W# d# t# '
 
 ( Q# W+ Q rGhX 8< Fc F FcSVh@X FR C 8OUY O# OC Od O^bcf^g OdT#Y 49 &3s8 "tCH~ $sDcN23 249 .33 34 3. 	
 9 3i	
 
03 4S> : z	
 !	(O	
!"	(O)+113 Bg%%).%9Mx	9+QtBis7=+A*BCDS&6!789@A	B 

*+	(O8 Q%TF!n UHTYYve}5M4NOPQ
 

*+	(O()FGH	
67	L6(#345
67	
&'	(O:nh'	 #;/K	
*+	k-89
:;	 ;7G+H!I J
KLI r   