o
    ~ri9                     @   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>   --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                 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   h/lsinfo/ai/hellotax_ai/llm_service/venv_embed/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   

r3   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-   )r4   r5   r6   leavessub_ctxr"   r   
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   r0   r1   
short_nameoptr   r   r   _iter_optional_params   s$   



rE   excluderG   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``).
    is_flagFr"   r#   r$   r%   )rE   r*   r-   r+   r,   )r   rG   flagsr0   r1   _shortr2   r   r   r   _get_flag_names   s   rK   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#   
)rE   _COMMON_FLAG_ALLOWLISTr*   splitstrip)	rL   	flag_info_pathr   r0   r1   rC   display	help_textr   r   r   _compute_common_flags   s   	rU   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#   rM   r   hf- `r%      ` — rF   z `[z]`)r   rO   rP   r3   r.   rK   _INLINE_FLAG_EXCLUDE)r6   r   rT   r&   r/   entryrI   r   r   r   _render_leaf   s   r[   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__)apprV   )r9   r#   z!Generated with `huggingface_hub vz-`. Run `hf skills add --force` to regenerate.z## CommandsrM   z### `hf rX   z## Common optionsrW   `)huggingface_hubr\   huggingface_hub.cli.hfr]   r   r   sortedr:   r;   r<   r   r-   listr>   r=   rU   _SKILL_YAML_PREFIX
splitlinesr[   dictr   rO   rP   itemsr   get_SKILL_TIPSr.   )r\   r]   	click_appr5   	top_levelgroupsr"   r   group_leavesall_leaf_commandsr4   r?   common_flagslinesr6   groups_dict	group_cmdrT   r1   rS   r   r   r   build_skill_md   sb   










rr   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)rs   rt   r   r   r   _remove_existing  s   r|   
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_IDr|   
write_textrr   )r}   rt   destr   r   r   _install_to$  s   
r   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.Tr~   )	r   r   r   r   r|   
symlink_toosrs   relpath)r   r   rt   	link_pathr   r   r   _create_symlink2  s   
r   previewc                   C   s   t t  dS )z'Print the generated SKILL.md to stdout.N)printrr   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)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.r   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   typerExitr   r   CENTRAL_GLOBALCENTRAL_LOCALGLOBAL_TARGETSLOCAL_TARGETSr-   r   )r   r   r   r   r   r   rt   
skill_destcentral_pathr   targets_dictagent_targetsagent_targetr   r   r   r   
skills_addD  s0   )

r   )r   N)FFFFFNF)1__doc__r   ry   pathlibr   typingr   r   r   clickr   r   r   
typer.mainr   
_cli_utilsr
   r   rc   rh   r   r   r   r   rN   rY   r   re   str__annotations__
skills_clir3   rb   tupler>   rE   setrK   rU   r[   rr   boolr|   r   r   commandr   Optionr   r   r   r   r   <module>   s   
.(
A
