
    j                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZ dd
ZddZddZddZddZddZddZddZdS )a  Implementation of the ``hermes bundles`` CLI subcommand.

Mirrors the structure of ``hermes_cli/skills_hub.py`` but for skill
bundles. Bundles are tiny YAML files that name a set of skills to load
together via a single ``/<bundle>`` slash command.

Subcommands:
- list: show all bundles
- show: dump one bundle's contents
- create: build a new bundle from arguments or interactively
- delete: remove a bundle
- reload: re-scan the bundles directory
    )annotationsN)ListConsole)Table)_bundles_dirdelete_bundle
get_bundlelist_bundlesreload_bundlessave_bundlescan_bundlesreturnr   c                     t                      S )Nr        7/home/ubuntu/.hermes/hermes-agent/hermes_cli/bundles.py_consoler   "   s     99r   Nonec           	        t                      }t                      }|s'|                    dt                       d           d S t	          dt          |           dd          }|                    dd	           |                    d
d	           |                    dd           |                    d           |D ]n}t          |                    dg                     }|                    d|d          |d         t          |          |                    d          pd           o|                    |           |                    dt                       d           d S )Nz[dim]No bundles installed yet. Create one with:
  hermes bundles create <name> --skill skill1 --skill skill2[/]
Bundles directory: [bold][/]zSkill Bundles ()F)title
show_linesCommandz	bold cyan)styleNameboldSkillsright)justifyDescriptionskills/slugnamedescription z
[dim]Bundles directory: )
r   r   printr   r   len
add_columngetadd_rowstr)argscbundlestableinfoskill_counts         r   	_cmd_listr5   )   s   

AnnG 	<(4< < <	
 	
 	

 	9#g,,999eLLLE	Yk222	V6***	Xw///	]### 
 
$((8R0011VLHH]##)r		
 	
 	
 	
 GGENNNGG<<<<=====r   c                   t                      }t          | j                  }|s2|                    d| j        d           t	          j        d           |                    d|d          d|d          d           |                    d	          r|                    d
|d	                     |                    d|d          d           |                    dt          |d                    d           |d         D ]}|                    d|            |                    d          r |                    d|d                     d S d S )Nz[bold red]Bundle z not found.[/]   z[bold cyan]/r%   z[/]  [bold]r&   r   r'   z  z  [dim]File: pathz  [bold]Skills (r#   ):[/]z    - instructionz  [bold]Instruction:[/]
    )r   r
   r&   r)   sysexitr,   r*   )r/   r0   r3   ss       r   	_cmd_showr>   F   sr   

Adi  D 	?DI???@@@GGE4<EEDLEEEFFFxx ,	*T-(**+++GG-DL---...GG9s4>22999:::(^  	xx G	E]0CEEFFFFFG Gr   c           	        t                      }| j        }t          | j        pg           }| j        pd}| j        pd}t          | j                  }|s|                    d           	 	 t          d          
                                }|sn|                    |           :n@# t          t          f$ r, |                    d           t          j        d           Y nw xY w|s)|                    d           t          j        d           	 t!          |||||          }n# t"          $ r7}	|                    d	|	 d
           t          j        d           Y d }	~	nGd }	~	wt$          $ r7}	|                    d	|	 d           t          j        d           Y d }	~	nd }	~	ww xY w|                    d|            t'          |          }
|
r7|                    d|
d          dt)          |
d                    d           d S d S )Nr(   zd[dim]No skills passed via --skill. Enter one skill name per line.
Submit an empty line to finish.[/]Tzskill> z
[yellow]Cancelled.[/]r7   z8[bold red]A bundle must reference at least one skill.[/])r'   r:   	overwrite
[bold red]z&[/]
[dim]Pass --force to overwrite.[/]r   z[bold green]Created bundle:[/] z  Invoke with: [bold cyan]/r%   z[/]  (loads r#   z skills))r   r&   listskillr'   r:   boolforcer)   inputstripappendEOFErrorKeyboardInterruptr;   r<   r   FileExistsError
ValueErrorr
   r*   )r/   r0   r&   r#   r'   r:   r@   liner8   excr3   s              r   _cmd_createrO   W   s   

A9DTZ-2..F"(bK"(bKTZ  I 	1	
 	
 	
	$Y''--// d###	$ +, 	 	 	GG-...HQKKKKK	  	JKKK##
 
 
    	ISIIIJJJ   	%S%%%&&& GG4d44555dD 
	4$v, 4 4$x.))4 4 4	
 	
 	
 	
 	

 
s6   *;B& &:C#"C#D' '
F'1-E##F'0-F""F'c                   t                      }	 t          | j                  }nD# t          $ r7}|                    d| d           t          j        d           Y d }~nd }~ww xY w|                    d|            d S )NrA   r   r7   z[bold green]Deleted bundle:[/] )r   r	   r&   FileNotFoundErrorr)   r;   r<   )r/   r0   r8   rN   s       r   _cmd_deleterR      s    

ATY''   	%S%%%&&& GG4d4455555s   % 
A&-A!!A&c           
        t                      }t                      }|d         rl|                    dt          |d                    d           |d         D ]7}|                    d|d          d|                    dd                      8|d	         rU|                    d
t          |d	                    d           |d	         D ] }|                    d|d                     !|d         s)|d	         s!|                    d|d          d           d S |                    d|d          d           d S )Naddedz[bold green]Added (r9   z  + r&   u    — r'   r(   removedz[bold red]Removed (z  - z[dim]No changes. totalz bundle(s) loaded.[/]z[dim]Total bundles now: r   )r   r   r)   r*   r,   )r/   r0   diffentrys       r   _cmd_reloadrY      sl   

ADG} O	?c$w-&8&8???@@@'] 	O 	OEGGM5=MMuyy/K/KMMNNNNI ,	Ac$y/&:&:AAABBB)_ 	, 	,EGG*5=**++++= ?i ?	HDMHHHIIIII	=4====>>>>>r   c                   |                      d          }|                    dd          }|                    t                     |                    dd          }|                    d	d
           |                    t
                     |                    ddd          }|                    d	d           |                    dddg d           |                    dddd           |                    dddd           |                    dddd !           |                    t                     |                    d"d#          }|                    d	d
           |                    t                     |                    d$d%          }|                    t                     t                       d&S )'zBuild the ``hermes bundles`` argparse tree.

    Called from ``hermes_cli/main.py`` where it owns the top-level
    ``bundles`` subparser. Keeping registration here means the bundles
    subcommand's argparse tree lives next to its handlers.
    bundles_action)destrB   zList installed skill bundles)help)_bundles_handlershowzShow one bundle's contentsr&   zBundle namecreatezCreate a new skill bundlezrCreate a new bundle. Skills can be passed via --skill (repeat for multiple) or entered interactively when omitted.)r]   r'   z(Bundle name (becomes the /slash command)z--skillz-srH   z+Skill name to include (repeat for multiple))actiondefaultr]   z--descriptionz-dr(   zCHuman-readable description shown in /help and `hermes bundles list`)rb   r]   z--instructionz-iz4Extra guidance prepended to the loaded skill contentz--forcez-f
store_truez/Overwrite an existing bundle with the same name)ra   r]   deletezDelete a skill bundlereloadz0Re-scan the bundles directory and report changesN)
add_subparsers
add_parserset_defaultsr5   add_argumentr>   rO   rR   rY   r   )	subparsersubsp_listp_showp_createp_deletep_reloads          r   register_clirq      s    ##)9#::D__V*H_IIF
333__V*F_GGF
]333
333(?	   H &'QRRR4":     rR     rC     4>     ;777x.EFFH&}555;777I   H ;777 NNNNNr   c                d    t          | dd          }|t          |            dS  ||            dS )z>Dispatch ``hermes bundles <subcommand>`` to the right handler.r^   N)getattrr5   )r/   handlers     r   bundles_commandru      s:    d.55G$GDMMMMMr   )r   r   )r   r   )__doc__
__future__r   r;   typingr   rich.consoler   
rich.tabler   agent.skill_bundlesr   r	   r
   r   r   r   r   r   r5   r>   rO   rR   rY   rq   ru   r   r   r   <module>r|      sl    # " " " " " 



                                            > > > >:G G G G"1
 1
 1
 1
h6 6 6 6? ? ? ?"5 5 5 5p     r   