
    Li7                     L   U d Z ddlZddlZddlmZ ddlmZmZ ddlZddl	m
Z
mZmZ ddlmZ ddlmZ d	Zd
ZdZ ed      Z ed      Z ed       ed       ed       ed      dZ ed       ed       ed       ed      dZh dZdhZdddZeeef   ed<    ed      Zde
d efd!Zd"ed#ed$e e   d e e!e e   e
f      fd%Z"de
fd&Z#dd'de
d(ee$e      d e e   fd)Z%d*e e!e e   e
f      d eee!eef   f   fd+Z&d$e e   de
d efd,Z'd efd-Z(d.ed/e)d dfd0Z*d1ed/e)d efd2Z+d3ed4ed/e)d efd5Z,ej[                  d6      dPd7       Z.ej[                  d8g d9:      	 	 	 	 	 	 	 dQd;ee) ej^                  d<d=      f   d>ee) ej^                  d?d@      f   dAee) ej^                  dBdC      f   dDee) ej^                  dEdF      f   dGee) ej^                  dHdIdJ      f   dKeee    ej^                  dL      f   d/ee) ej^                  dMdN      f   d dfdO       Z0y)Ra  Contains commands to manage skills for AI assistants.

Usage:
    # install the hf-cli skill in common .agents/skills directory (either in current directory or user-level)
    hf skills add
    hf skills add --global

    # install the hf-cli skill for Claude (project-level, in current directory)
    hf skills add --claude

    # install for Cursor (project-level, in current directory)
    hf skills add --cursor

    # install for multiple assistants (project-level)
    hf skills add --claude --codex --opencode --cursor

    # install globally (user-level)
    hf skills add --claude --global

    # install to a custom directory
    hf skills add --dest=~/my-skills

    # overwrite an existing skill
    hf skills add --claude --force
    N)Path)	AnnotatedOptional)CommandContextGroup)get_command   )typer_factoryzhf-clia  ---
name: hf-cli
description: "Hugging Face Hub CLI (`hf`) for downloading, uploading, and managing repositories, models, datasets, and Spaces on the Hugging Face Hub. Replaces now deprecated `huggingface-cli` command."
---

Install: `curl -LsSf https://hf.co/cli/install.sh | bash -s`.

The Hugging Face Hub CLI tool `hf` is available. IMPORTANT: The `hf` command replaces the deprecated `huggingface-cli` command.

Use `hf --help` to view available functions. Note that auth commands are now all under `hf auth` e.g. `hf auth whoami`.
z
## Tips

- Use `hf <command> --help` for full options, descriptions, usage, and real-world examples
- Authenticate with `HF_TOKEN` env var (recommended) or with `--token`
z.agents/skillsz~/.agents/skillsz~/.codex/skillsz~/.claude/skillsz~/.cursor/skillsz~/.config/opencode/skills)codexclaudecursoropencodez.codex/skillsz.claude/skillsz.cursor/skillsz.opencode/skills>   --type--quiet
--revision--token--formatr   zKOutput format: `--format json` (or `--json`) or `--format table` (default).zXUse a User Access Token. Prefer setting `HF_TOKEN` env var instead of passing `--token`.)r   r   _COMMON_FLAG_HELP_OVERRIDESz Manage skills for AI assistants.)helpcmdreturnc           	         g }| j                   D ]  }|j                  r|j                  dk(  r|j                  r|j                  j	                  d      rGt        d t        |dg       D        d      }|@t        |j                  dd      j                         xs d}|j                  | d	|        |j                  s|j                  |j                          d	j                  |      S )
zMFormat required params: positional as UPPER_CASE, options as ``--name TYPE``.--help_c              3   D   K   | ]  }|j                  d       s|  yw)--N)
startswith).0os     `/var/www/html/lcp-python-backend/venv/lib/python3.12/site-packages/huggingface_hub/cli/skills.py	<genexpr>z!_format_params.<locals>.<genexpr>p   s     Rq||D?Q!Rs     optsNname VALUE )paramsrequiredhuman_readable_namer$   r   nextgetattrtypeupperappendjoin)r   partsp	long_name	type_names        r!   _format_paramsr5   h   s    EZZ 
0zzQ22h>66aff'',RWQ%;RTXY	 399;FwILLI;a	{34VVLL../
0 88E?    groupctx
path_partsc                 &   g }t        | ||d         }| j                  |      D ]i  }| j                  ||      }||j                  r$g ||}t	        |t
              r|j                  t        |||             W|j                  ||f       k |S )zXRecursively walk a Click Group, returning (full_path_parts, cmd) for every leaf command.)parent	info_name)	r   list_commandsr	   hidden
isinstancer   extend_collect_leaf_commandsr/   )r7   r8   r9   leavessub_ctxr$   r   
child_paths           r!   rB   rB   y   s    .0FeC:b>BG##G, -.;#**(z(4(
c5!MM0gzJKMM:s+,- Mr6   c              #   N  K   | j                   D ]  }|j                  s|j                  dk(  r|j                  r|j                  j	                  d      rGd}d}t        |dg       D ].  }|j	                  d      r|xs |}|j	                  d      s-|}0 |s|||f  yw)zKYield (param, long_name, short_name) for each optional, non-internal param.r   r   Nr#   r   -)r(   r)   r*   r$   r   r,   )r   r2   r3   
short_nameopts        r!   _iter_optional_paramsrJ      s     ZZ +::..(:66aff'',	
1fb) 	!C~~d#%,	$ 
		!
 Y
**+s   BB%B%
B%excluderL   c                    g }t        |       D ]k  \  }}}|r||v rt        |dd      r|j                  |       -t        |j                  dd      j	                         xs d}|j                  | d|        m |S )zReturn long-form flag names (--foo) for optional, non-internal params.

    Boolean flags are bare (``--dry-run``).  Value-taking options include a
    type hint (``--include TEXT``, ``--max-workers INTEGER``).
    is_flagFr$   r%   r&   r'   )rJ   r,   r/   r-   r.   )r   rL   flagsr2   r3   _shortr4   s          r!   _get_flag_namesrQ      s     E 5c : 59fyG+1i'LL#399;FwILLI;a	{345 Lr6   leaf_commandsc                    i }| D ]w  \  }}t        |      D ]d  \  }}}|t        vr||vs|sd||   d   vs"|r| d| n|}t        |dd      xs dj                  d      d   j	                         }||f||<   f y |S )z0Collect display info for flags in the allowlist.z / r   r   Nr%   
)rJ   _COMMON_FLAG_ALLOWLISTr,   splitstrip)	rR   	flag_info_pathr   r2   r3   rH   display	help_texts	            r!   _compute_common_flagsr\      s     -/I# <
s(=c(B 	<$Ay* 66	)jU)T]J^_`Ja=a;EZLI;79$Q5;BB4HKQQS	(/';	)$	<< r6   c                    |j                   xs dj                  d      d   j                         }t        |      }dg| |r|gng z   }ddj	                  |       d| }t        |t              }|r|d	dj	                  |       d
z  }|S )z6Render a single leaf command as a markdown list entry.r%   rT   r   hf- `r'      ` — rK   z `[z]`)r   rV   rW   r5   r0   rQ   _INLINE_FLAG_EXCLUDE)r9   r   r[   r(   r1   entryrO   s          r!   _render_leafrc      s    R&&t,Q/557IC FJvF82>E#((5/"&4EC)=>E3sxx'r**Lr6   c                     ddl m}  ddlm} t	        |      }t        |d      }g }g }t        |j                  |            D ][  }|j	                  ||      }||j                  r$t        |t              r|j                  ||f       H|j                  |g|f       ] g }t        |      }	|D ]7  \  }}
t        |
||g      }|j                  ||f       |	j                  |       9 t        |	      }t        t         j#                               }|j                  d       |j                  d|  d       |j                  d       |j                  d	       |j                  d       |D ]   \  }}|j                  t%        ||             " t'        |      }|D ]  \  }}||   }|j(                  xs dj+                  d
      d   j-                         }|j                  d       |j                  d| d|        |j                  d       |D ]   \  }}|j                  t%        ||             "  |r|j                  d       |j                  d       |j                  d       t        |j/                               D ]M  \  }\  }}t0        j3                  ||      }|r|j                  d| d|        9|j                  d| d       O |j                  t4        j#                                d
j7                  |      S )Nr   )__version__)appr^   )r=   r%   z!Generated with `huggingface_hub vz-`. Run `hf skills add --force` to regenerate.z## CommandsrT   z### `hf r`   z## Common optionsr_   `)huggingface_hubre   huggingface_hub.cli.hfrf   r	   r   sortedr>   r?   r@   r   r/   listrB   rA   r\   _SKILL_YAML_PREFIX
splitlinesrc   dictr   rV   rW   itemsr   get_SKILL_TIPSr0   )re   rf   	click_appr8   	top_levelgroupsr$   r   group_leavesall_leaf_commandsr7   rC   common_flagslinesr9   groups_dict	group_cmdr[   r3   rZ   s                       r!   build_skill_mdr{      s   +*C I
)t
,C13I&(Fy..s34 ,##C.;#**c5!MM4+&tfc]+, GIL9=i )e'sTF;T6N+  ()
 )):;L .99;<E	LL	LL4[MAnop	LL	LL	LL$ 4
C\*c234 v,K$ 8f%	^^)r006q9??A	RxvVI;78R% 	8OJLLj#67	88 R()R/5l6H6H6J/K 	/+I+377	9MIs7)6)=>s7)1-.	/ 
LL'')*99Ur6   pathforcec                     | j                         s| j                         sy|st        d|  d      | j                         r&| j                         st	        j
                  |        y| j                          y)zRRemove existing file/directory/symlink if force is True, otherwise raise an error.NzSkill already exists at z#.
Re-run with --force to overwrite.)exists
is_symlink
SystemExitis_dirshutilrmtreeunlink)r|   r}   s     r!   _remove_existingr     sW    KKMT__.3D69]^__{{}T__.dr6   
skills_dirc                     | j                         j                         } | j                  dd       | t        z  }t	        ||       |j                          |dz  j                  t               d       |S )zYDownload and install the skill files into a skills directory. Returns the installed path.Tparentsexist_okzSKILL.mdzutf-8)encoding)
expanduserresolvemkdirDEFAULT_SKILL_IDr   
write_textr{   )r   r}   dests      r!   _install_tor     sj    &&(002JTD1((DT5!JJL	J"">#3g"FKr6   agent_skills_dircentral_skill_pathc                     | j                         j                         } | j                  dd       | t        z  }t	        ||       |j                  t        j                  j                  ||              |S )zMCreate a relative symlink from agent directory to the central skill location.Tr   )	r   r   r   r   r   
symlink_toosr|   relpath)r   r   r}   	link_paths       r!   _create_symlinkr   '  sg    '224<<>4$7 #33IY&);=MNOr6   previewc                  *    t        t                      y)z'Print the generated SKILL.md to stdout.N)printr{    r6   r!   skills_previewr   3  s     
.
r6   add)zhf skills addzhf skills add --globalzhf skills add --claude --cursorz2hf skills add --codex --opencode --cursor --global)examplesr   z--claudezInstall for Claude.r   z--codexzInstall for Codex.r   z--cursorzInstall for Cursor.r   z
--opencodezInstall for OpenCode.global_z--globalz-gzJInstall globally (user-level) instead of in the current project directory.r   z=Install into a custom destination (path to skills directory).z--forcez-Overwrite existing skills in the destination.c                    |rM| s|s|s|s|r!t        d       t        j                  d      t        ||      }t        dt         d|        y|rt
        nt        }t        ||      }	t        dt         d|	        |rt        nt        }
g }| r|j                  |
d          |r|j                  |
d	          |r|j                  |
d
          |r|j                  |
d          |D ]  }t        ||	|      }t        d|         y)a0  Download a skill and install it for an AI assistant.

    Default location is in the current directory (.agents/skills) or user-level (~/.agents/skills).
    If custom agents are specified (e.g. --claude --codex --cursor --opencode, etc), the skill will be symlinked to the agent's skills directory.
    zT--dest cannot be combined with --claude, --codex, --cursor, --opencode, or --global.r
   )codezInstalled 'z' to Nz' to central location: r   r   r   r   zCreated symlink: )r   typerExitr   r   CENTRAL_GLOBALCENTRAL_LOCALGLOBAL_TARGETSLOCAL_TARGETSr/   r   )r   r   r   r   r   r   r}   
skill_destcentral_pathr   targets_dictagent_targetsagent_targetr   s                 r!   
skills_addr   9  s   R UfGhi**!$$ u-
,-U:,?@ &->-L$\59	K())@AS@T
UV &->-L "M\(34\'23\(34\*56% /#L2DeL	!)-./r6   )r   N)FFFFFNF)1__doc__r   r   pathlibr   typingr   r   r   clickr   r   r   
typer.mainr	   
_cli_utilsr   r   rl   rq   r   r   r   r   rU   ra   r   rn   str__annotations__
skills_clir5   rk   tuplerB   rJ   setrQ   r\   rc   r{   boolr   r   r   commandr   Optionr   r   r6   r!   <module>r      s  4 
   &  ) ) " %    %&() #$%&%&01	 /"#$#$'(	 T !{  ^i/ T#s(^ 
  BC
 C "% g 49 QUV[\`ad\egn\nVoQp  +w +$ DH  hs3x.@ DQTI $d3i012	#uS#X
&	T#Y 	W 	 	> >B	4 	 	 	D  $ 	d 	 	T 	VZ 	 I 
 	   UZQVTYZ_ 	 	 	3;/dLELL:OPPQ;/T<5<<	8LMMN;/ dLELL:OPPQ;/ lell<>UVVW	;/
 ]	
	;/ P	
	;/& @	
	';/4 
5;/;/r6   