o
    0i9                     @   s  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dZde
d efd!d"Zd#ed$ed%e e d e e!e e e
f  fd&d'Z"de
fd(d)Z#dd*de
d+ee$e  d e e fd,d-Z%d.e e!e e e
f  d eee!eef f fd/d0Z&d%e e de
d efd1d2Z'd efd3d4Z(d5ed6e)d dfd7d8Z*d9ed6e)d efd:d;Z+d<ed=ed6e)d efd>d?Z,e-d@d]dAdBZ.ej-dCg dDdE	F	F	F	F	F		Fd^dGee)ej/dHdIdf dJee)ej/dKdLdf dMee)ej/dNdOdf dPee)ej/dQdRdf dSee)ej/dTdUdVdf dWeee ej/dXdf d6ee)ej/dYdZdf d dfd[d\Z0dS )_a  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`.
u  
## Mounting repos as local filesystems

To mount Hub repositories or buckets as local filesystems — no download, no copy, no waiting — use `hf-mount`. Files are fetched on demand. GitHub: https://github.com/huggingface/hf-mount

Install: `curl -fsSL https://raw.githubusercontent.com/huggingface/hf-mount/main/install.sh | sh`

Some command examples:
- `hf-mount start repo openai-community/gpt2 /tmp/gpt2` — mount a repo (read-only)
- `hf-mount start --hf-token $HF_TOKEN bucket myuser/my-bucket /tmp/data` — mount a bucket (read-write)
- `hf-mount status` / `hf-mount stop /tmp/data` — list or unmount

## 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>   z--typez--quietz
--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                 C   s   g }| j D ]F}|jr|jdkrq|jr|jdrqtdd t|dg D d}|durBt|jdd p6d	}|	| d
|  q|jrK|	|j qd

|S )zMFormat required params: positional as UPPER_CASE, options as ``--name TYPE``.--help_c                 s   s    | ]
}| d r|V  qdS )--N)
startswith).0o r   T/home/kim/smarthome/.venv/lib/python3.10/site-packages/huggingface_hub/cli/skills.py	<genexpr>{   s    z!_format_params.<locals>.<genexpr>optsNname VALUE )paramsrequiredhuman_readable_namer   r   nextgetattrtypeupperappendjoin)r   partsp	long_name	type_namer   r   r   _format_paramss   s   

r0   groupctx
path_partsc                 C   s~   g }t | ||d d}| |D ],}| ||}|du s|jr qg ||}t|tr5|t||| q|||f q|S )zXRecursively walk a Click Group, returning (full_path_parts, cmd) for every leaf command.)parent	info_nameN)	r   list_commandsr   hidden
isinstancer   extend_collect_leaf_commandsr*   )r1   r2   r3   leavesZsub_ctxr   r   Z
child_pathr   r   r   r;      s   
r;   c                 c   s    | j D ];}|js|jdkrq|jr|jdrqd}d}t|dg D ]}|dr/|p-|}q#|dr6|}q#|r?|||fV  qdS )zKYield (param, long_name, short_name) for each optional, non-internal param.r   r   Nr   r   -)r#   r$   r%   r   r   r'   )r   r-   r.   
short_nameoptr   r   r   _iter_optional_params   s$   



r@   excluderB   c                C   sl   g }t | D ]-\}}}|r||v rqt|ddr|| qt|jdd p(d}|| d|  q|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``).
    Zis_flagFr   r    r!   r"   )r@   r'   r*   r(   r)   )r   rB   flagsr-   r.   Z_shortr/   r   r   r   _get_flag_names   s   rD   leaf_commandsc           	      C   s   i }| D ]A\}}t |D ]8\}}}|tvrq||vs$|rDd|| d vrD|r-| d| n|}t|ddp6ddd  }||f||< qq|S )z0Collect display info for flags in the allowlist.z / r   r   Nr    
)r@   _COMMON_FLAG_ALLOWLISTr'   splitstrip)	rE   Z	flag_info_pathr   r-   r.   r>   display	help_textr   r   r   _compute_common_flags   s   	rM   c                 C   sx   |j pddd  }t|}dg| |r|gng  }dd| d| }t|td}|r:|d	d| d
7 }|S )z6Render a single leaf command as a markdown list entry.r    rF   r   hf- `r"      ` — rA   z `[z]`)r   rH   rI   r0   r+   rD   _INLINE_FLAG_EXCLUDE)r3   r   rL   r#   r,   entryrC   r   r   r   _render_leaf   s   rS   c                  C   sJ  ddl m}  ddlm} t|}t|dd}g }g }t||D ]%}|||}|d u s0|jr1q!t	|t
r>|||f q!||g|f q!g }t|}	|D ]\}}
t|
||g}|||f |	| qOt|	}tt }|d |d|  d |d |d	 |d |D ]\}}|t|| qt|}|D ]8\}}|| }|jpdd
d  }|d |d| d|  |d |D ]\}}|t|| qq|r|d |d |d t| D ]$\}\}}t||}|r|d| d|  q|d| d q|t  d
|S )Nr   )__version__)apprN   )r6   r    z!Generated with `huggingface_hub vz-`. Run `hf skills add --force` to regenerate.z## CommandsrF   z### `hf rP   z## Common optionsrO   `)Zhuggingface_hubrT   Zhuggingface_hub.cli.hfrU   r   r   sortedr7   r8   r9   r   r*   listr;   r:   rM   _SKILL_YAML_PREFIX
splitlinesrS   dictr   rH   rI   itemsr   get_SKILL_TIPSr+   )rT   rU   Z	click_appr2   Z	top_levelgroupsr   r   Zgroup_leavesZall_leaf_commandsr1   r<   Zcommon_flagslinesr3   Zgroups_dictZ	group_cmdrL   r.   rK   r   r   r   build_skill_md   sb   










ra   pathforcec                 C   sR   |   s
|  s
dS |std|  d|  r#|  s#t|  dS |   dS )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)rb   rc   r   r   r   _remove_existing  s   rk   
skills_dirc                 C   sL   |    } | jddd | t }t|| |  |d jt d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_IDrk   
write_textra   )rl   rc   destr   r   r   _install_to$  s   
rw   agent_skills_dircentral_skill_pathc                 C   sD   |    } | jddd | t }t|| |tj||  |S )zMCreate a relative symlink from agent directory to the central skill location.Trm   )	rq   rr   rs   rt   rk   
symlink_toosrb   relpath)rx   ry   rc   	link_pathr   r   r   _create_symlink2  s   
r~   previewc                   C   s   t t  dS )z'Print the generated SKILL.md to stdout.N)printra   r   r   r   r   skills_preview>  s   r   add)zhf skills addzhf skills add --globalzhf skills add --claude --cursorz2hf skills add --codex --opencode --cursor --global)ZexamplesFr   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.rv   z=Install into a custom destination (path to skills directory).z--forcez-Overwrite existing skills in the destination.c                 C   s   |r'| s|s|s|s|rt d tjddt||}t dt d|  dS |r+tnt}t||}	t dt d|	  |r@tnt}
g }| rM|	|
d  |rV|	|
d	  |r_|	|
d
  |rh|	|
d  |D ]}t
||	|}t d|  qjdS )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   typerZExitrw   rt   CENTRAL_GLOBALCENTRAL_LOCALGLOBAL_TARGETSLOCAL_TARGETSr*   r~   )r   r   r   r   r   rv   rc   Z
skill_destZcentral_pathry   Ztargets_dictZagent_targetsZagent_targetr}   r   r   r   
skills_addD  s0   )

r   )r   N)FFFFFNF)1__doc__r{   rh   pathlibr   typingr   r   r   Zclickr   r   r   Z
typer.mainr   Z
_cli_utilsr
   rt   rY   r^   r   r   r   r   rG   rQ   r   r[   str__annotations__Z
skills_clir0   rX   tupler;   r@   setrD   rM   rS   ra   boolrk   rw   r~   commandr   Optionr   r   r   r   r   <module>   s   
.(
A
