
    `gj                        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y)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_bundlesc                     t               S )Nr        E/root/.hermes/venv/lib/python3.12/site-packages/hermes_cli/bundles.py_consoler   "   s     9r   c           	     F   t               }t               }|s|j                  dt                d       y t	        dt        |       dd      }|j                  dd	       |j                  d
d	       |j                  dd       |j                  d       |D ]V  }t        |j                  dg             }|j                  d|d    |d   t        |      |j                  d      xs d       X |j                  |       |j                  dt                d       y )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_listr3   )   s   
AnG	((4'7s<	

 	/#g,q9eLE	Yk2	V6*	Xw/	]# 
$((8R01V~LHH]#)r		

 GGENGG((8<=r   c                :   t               }t        | j                        }|s4|j                  d| j                  d       t	        j
                  d       |j                  d|d    d|d    d       |j                  d	      r|j                  d
|d	           |j                  d|d    d       |j                  dt        |d          d       |d   D ]  }|j                  d|         |j                  d      r|j                  d|d           y y )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-   r.   r1   ss       r   	_cmd_showr<   F   s   
Adii D	#DII=?@GGl4<.DL>EFxx	"T-()*+GGmDL>-.GGs4>2359:(^ 	&xx	/]0C/DEF r   c           	        t               }| j                  }t        | j                  xs g       }| j                  xs d}| j
                  xs d}t        | j                        }|sB|j                  d       	 	 t        d      j                         }|sn|j                  |       .	 |s&|j                  d       t        j                  d       	 t!        |||||      }|j                  d        t'        |      }
|
r(|j                  d|
d    dt)        |
d          d       y y # t        t        f$ r) |j                  d       t        j                  d       Y w xY w# t"        $ r4}	|j                  d|	 d	       t        j                  d       Y d }	~	d }	~	wt$        $ r4}	|j                  d|	 d
       t        j                  d       Y d }	~	d }	~	ww xY w)Nr&   zd[dim]No skills passed via --skill. Enter one skill name per line.
Submit an empty line to finish.[/]zskill> z
[yellow]Cancelled.[/]r5   z8[bold red]A bundle must reference at least one skill.[/])r%   r8   	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%   r8   boolforcer'   inputstripappendEOFErrorKeyboardInterruptr9   r:   r   FileExistsError
ValueErrorr
   r(   )r-   r.   r$   r!   r%   r8   r>   liner6   excr1   s              r   _cmd_createrM   W   s   
A99DTZZ-2.F""(bK""(bKTZZ I	1	
	Y'--/d#	   	JK##
 GG-dV45dD	)$v, 8$x.)*(4	
 3 +, 	GG-.HHQK	   	*SE!HIJ 	*SE%&s6   9/D, E' ,5E$#E$'	G0*FG+*GGc                    t               }	 t        | j                        }|j	                  d        y # t        $ r4}|j	                  d| d       t        j                  d       Y d }~Md }~ww xY w)Nr?   r   r5   z[bold green]Deleted bundle:[/] )r   r	   r$   FileNotFoundErrorr'   r9   r:   )r-   r.   r6   rL   s       r   _cmd_deleterP      sf    
ATYY' GG-dV45  	*SE%&s   6 	A3*A..A3c           
        t               }t               }|d   rU|j                  dt        |d          d       |d   D ],  }|j                  d|d    d|j	                  dd              . |d	   rB|j                  d
t        |d	          d       |d	   D ]  }|j                  d|d            |d   s|d	   s|j                  d|d    d       y |j                  d|d    d       y )Naddedz[bold green]Added (r7   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-   r.   diffentrys       r   _cmd_reloadrW      s	   
ADG}	%c$w-&8%9?@'] 	OEGGd5=/uyy/K.LMN	OI	%c$y/&:%;5AB)_ 	,EGGd5=/*+	,=i	#DM?2GHI	*4=/=>r   c                   | j                  d      }|j                  dd      }|j                  t               |j                  dd      }|j	                  d	d
       |j                  t
               |j                  ddd      }|j	                  d	d       |j	                  dddg d       |j	                  dddd       |j	                  dddd       |j	                  dddd !       |j                  t               |j                  d"d#      }|j	                  d	d
       |j                  t               |j                  d$d%      }|j                  t               t                y&)'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)destr@   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-srF   z+Skill name to include (repeat for multiple))actiondefaultr[   z--descriptionz-dr&   zCHuman-readable description shown in /help and `hermes bundles list`)r`   r[   z--instructionz-iz4Extra guidance prepended to the loaded skill contentz--forcez-f
store_truez/Overwrite an existing bundle with the same name)r_   r[   deletezDelete a skill bundlereloadz0Re-scan the bundles directory and report changesN)
add_subparsers
add_parserset_defaultsr3   add_argumentr<   rM   rP   rW   r   )	subparsersubsp_listp_showp_createp_deletep_reloads          r   register_cliro      s    ##)9#:D__V*H_IF
3__V*F_GF
]3
3(?	  H &'QR4":   rR   rC   4>   ;7x.EFH&}5;7I  H ;7 Nr   c                J    t        | dd      }|t        |        y ||        y)z>Dispatch ``hermes bundles <subcommand>`` to the right handler.r\   N)getattrr3   )r-   handlers     r   bundles_commandrs      s'    d.5G$DMr   )returnr   )rt   None)__doc__
__future__r   r9   typingr   rich.consoler   
rich.tabler   agent.skill_bundlesr   r	   r
   r   r   r   r   r   r3   r<   rM   rP   rW   ro   rs   r   r   r   <module>r|      sU    # 
      >:G"1
h6?"5pr   