
    `gj*                    R    d Z ddlmZ ddlZddlmZ d
dZdddZddZddZ	dd	Z
y)u   Shell completion script generation for hermes CLI.

Walks the live argparse parser tree to generate accurate, always-up-to-date
completion scripts — no hardcoded subcommand lists, no extra dependencies.

Supports bash, zsh, and fish.
    )annotationsN)Anyc                   g }i }| j                   D ]  }t        |t        j                        rt	               }|j
                  D ]n  }|j                  }||v r|j                  |       |j                  j                  |      }|Ct        |      }t        |j                  xs d      |d<   |||<   p |j                  s|j                  d |j                  D                ||dS )zRecursively extract subcommands and flags from a parser.

    Uses _SubParsersAction._choices_actions to get canonical names (no aliases)
    along with their help text.
     helpc              3  D   K   | ]  }|j                  d       s|  yw)-N)
startswith).0os     H/root/.hermes/venv/lib/python3.12/site-packages/hermes_cli/completion.py	<genexpr>z_walk.<locals>.<genexpr>)   s     OqQ\\#=NOs     )flagssubcommands)_actions
isinstanceargparse_SubParsersActionset_choices_actionsdestaddchoicesget_walk_cleanr   option_stringsextend)	parserr   r   actionseenpseudoname	subparserinfos	            r   r   r      s     E"$K// Pfh889 !UD 11 
){{4<"NN..t4	$Y'%fkk&7R8V$(D!
) ""LLOF$9$9OO#P& ;77    c                l    | j                  dd      j                  dd      j                  dd      d| S )z+Strip shell-unsafe characters and truncate.'r   "\N)replace)textmaxlens     r   r   r   .   s4    <<R ((b199$CGVLLr&   c           
     >   t        |       }dj                  t        |d               }g }t        |d         D ]  }|d   |   }|dk(  rM|d   rHdj                  t        |d               }d}|j                  d| d|j	                  dd       d       ]|d   r6dj                  t        |d               }|j                  d	| d
| d       |d   sdj                  |d         }|j                  d	| d
| d        dj                  |      }	d|	 d| dS )N r   profilez#use delete show alias rename exportzs        profile)
            case "$prev" in
                profile)
                    COMPREPLY=($(compgen -W "zP" -- "$cur"))
                    return
                    ;;
                |z)
                    COMPREPLY=($(compgen -W "$(_hermes_profiles)" -- "$cur"))
                    return
                    ;;
            esac
            ;;z        z')
            COMPREPLY=($(compgen -W "z/" -- "$cur"))
            return
            ;;r   
a  # Hermes Agent bash completion
# Add to ~/.bashrc:
#   eval "$(hermes completion bash)"

_hermes_profiles() {
    local profiles_dir="$HOME/.hermes/profiles"
    local profiles="default"
    if [ -d "$profiles_dir" ]; then
        for f in "$profiles_dir"/*/; do
            [ -d "$f" ] && profiles="$profiles $(basename "$f")"
        done
    fi
    echo "$profiles"
}

_hermes_completion() {
    local cur prev
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # Complete profile names after -p / --profile
    if [[ "$prev" == "-p" || "$prev" == "--profile" ]]; then
        COMPREPLY=($(compgen -W "$(_hermes_profiles)" -- "$cur"))
        return
    fi

    if [[ $COMP_CWORD -ge 2 ]]; then
        case "${COMP_WORDS[1]}" in
z\
        esac
    fi

    if [[ $COMP_CWORD -eq 1 ]]; then
        COMPREPLY=($(compgen -W "z>" -- "$cur"))
    fi
}

complete -F _hermes_completion hermes
)r   joinsortedappendr+   )
r   treetop_cmdscasescmdr%   subcmdsprofile_actionsr   	cases_strs
             r   generate_bashr=   7   s   =DxxtM234HEd=)* $M"3')] 3 hhvd=&9:;GCOLLA BI	 J# $3#:#:3#D"E F!" - hhvd=&9:;GLL3%  99@	 B!" ']HHT']+ELL3%  99> @!"?$L 		% I:  "
 #+ ,E' 'r&   c                r   t        |       }g }t        |d         D ];  }t        |d   |   j                  dd            }|j	                  d| d| d       = dj                  |      }g }t        |d         D ]   }|d   |   }|d   s|dk(  rug }t        |d         D ];  }	t        |d   |	   j                  dd            }
|j	                  d	|	 d|
 d       = dj                  |      }|j	                  d
| d       g }t        |d         D ];  }	t        |d   |	   j                  dd            }
|j	                  d|	 d|
 d       = dj                  |      }|j                  dd      }|j	                  d| d| d| d| d| d| d       # dj                  |      }d| d| dS )Nr   r   r   z                ':r(   r2   r0   z                        'aA                  profile)
                    case ${line[2]} in
                        use|delete|show|alias|rename|export)
                            _hermes_profiles
                            ;;
                        *)
                            local -a profile_cmds
                            profile_cmds=(
z
                            )
                            _describe 'profile command' profile_cmds
                            ;;
                    esac
                    ;;z                    'r	   _z                z)
                    local -a z_cmds
                    z_cmds=(
z6
                    )
                    _describe 'z
 command' z_cmds
                    ;;a  #compdef hermes
# Hermes Agent zsh completion
# Add to ~/.zshrc:
#   eval "$(hermes completion zsh)"

_hermes_profiles() {
    local -a profiles
    profiles=(default)
    if [[ -d "$HOME/.hermes/profiles" ]]; then
        profiles+=($HOME/.hermes/profiles/*(N/:t))
    fi
    _describe 'profile' profiles
}

_hermes() {
    local context state line
    typeset -A opt_args

    _arguments -C \
        '(-)'{-h,--help}'[Show help and exit]' \
        '(-)'{-V,--version}'[Show version and exit]' \
        '(-)'{-p,--profile}'[Profile name]:profile:_hermes_profiles' \
        '1:command:->commands' \
        '*::arg:->args'

    case $state in
        commands)
            local -a subcmds
            subcmds=(
zz
            )
            _describe 'hermes command' subcmds
            ;;
        args)
            case ${line[1]} in
zD
            esac
            ;;
    esac
}

compdef _hermes hermes
)r   r4   r   r   r5   r3   r+   )r   r6   top_cmds_linesr9   	help_texttop_cmds_str	sub_casesr%   	sub_linesscshsub_strsafesub_cases_strs                 r   generate_zshrK      sU   =D "Nd=)* F4.s377CD	 1#a	{!DEF 99^,LId=)* +M"3'M") $&IT-01 ID/377CD  #<RD"Q!GHI ii	*G? ) )*" IT-01 ED/377CD  #8AbT!CDE ii	*G;;sC(D"3% (004v 6''+fI) 225j G)*G+X IIi(M:    G* *r&   c                   t        |       }t        |d         }dj                  |      }g d}|D ]@  }|d   |   }t        |j	                  dd            }|j                  d| d| d| d	       B |j                  d       |j                  d
       h d}|D ]  }|d   |   }|d   s|j                  d|        t        |d         D ]@  }	|d   |	   }
t        |
j	                  dd            }|j                  d| d|	 d| d	       B |dk(  s|t        |      D ]  }|j                  d| d         |j                  d       dj                  |      S )Nr   r/   )z# Hermes Agent fish completionz# Add to your config:z##   hermes completion fish | sourcer   z!# Helper: list available profileszfunction __hermes_profilesz    echo defaultz%    if test -d $HOME/.hermes/profilesz*        for d in $HOME/.hermes/profiles/*/z            basename $dz        endz    endendr   z$# Disable file completion by defaultzcomplete -c hermes -fr   z-# Complete profile names after -p / --profilezQcomplete -c hermes -f -s p -l profile -d 'Profile name' -xa '(__hermes_profiles)'r   z# Top-level subcommandsr   r   z:complete -c hermes -f -n 'not __fish_seen_subcommand_from z' -a z -d 'r(   z# Subcommand completions>   useshowaliasdeleteexportrenamez# z6complete -c hermes -f -n '__fish_seen_subcommand_from r0   zU; and __fish_seen_subcommand_from profile' -a '(__hermes_profiles)' -d 'Profile name'r2   )r   r4   r3   r   r   r5   )r   r6   r7   rC   linesr9   r%   rB   profile_name_actionsrF   sinforG   r    s                r   generate_fishrW      s   =Dd=)*H88H%LE2  
M"3'488FB/0	33?. AeI;a)	

 
LL	LL+,Q M"3'M"r#Z m,- 	B'+E		&"-.BLL336% 8Trd!%	 ) !56 77=h ?AB. 
LL99Ur&   )r   argparse.ArgumentParserreturnzdict[str, Any])<   )r,   strr-   intrY   r[   )r   rX   rY   r[   )__doc__
__future__r   r   typingr   r   r   r=   rK   rW    r&   r   <module>ra      s4    #  8>MTvbRDr&   