Hub operations

From VectorSpaceLab/AREX-Skill · View interactive version

Hub operations is an AI agent skill from the GitHub repository VectorSpaceLab/AREX-Skill. Operate Hugging Face Hub repositories and API resources with authenticated or mocked Python workflows, explicit revision control, safe mutations, and actionable error recovery.

How to use this skill

Skill file

Hub Operations

Use this sub-skill for Python workflows that discover or mutate Hub API

resources: repositories, files and commits, refs, collections, cards,

discussions and pull requests, and webhook registrations. It is grounded in

huggingface_hub 1.29.0.

Trigger And Route

This is the routing surface, not a full API manual. Select the smallest

linked reference that covers the request, then keep the operation and

verification boundaries visible.

| Request signal | Route | Read next |

|---|---|---|

| create/inspect/search a repo, list files/tree/commits, or manage refs | repository and discovery | API reference |

| upload/copy/delete files, create a commit or PR, or pin a parent SHA | files and commits | Workflows |

| cards, metadata, collections, discussions, or PR review | collaboration and metadata | API reference and Workflows |

| webhook registration, scope, enable/disable, or deletion | webhook resources | Workflows |

| token precedence, access, 401/403/404/409/412/429, or ambiguous mutation | authentication and recovery | Troubleshooting |

| deterministic unit-style behavior without Hub access | mocked HfApi case | Mocked recovery case |

Use this route when the request includes one or more of:

or Space repository;

Route elsewhere when the primary task is:

downloads-and-storage route;

route;

cli-and-automation route;

sibling hosted-compute-and-integrations route.

Webhook registration is owned here; receiving payloads in a server is not.

Space repository metadata is owned here; running or scaling the Space is not.

Operating Contract

  1. Classify the operation. Label every step READ-ONLY, MUTATION, or

DESTRUCTIVE. Do not hide a mutation inside an inspection step.

  1. Resolve identity. Record repo_id, repo_type, revision, endpoint,

and token source before calling the API. Prefer explicit

namespace/name; Python uses singular repo types: model, dataset,

space.

  1. Authenticate safely. Prefer HF_TOKEN or a previously saved login.

Never hardcode, log, print, serialize, or include a token in an exception

report. Use a write-scoped token only for mutations.

  1. Inspect before mutation. Fetch the target object and revision, confirm

ownership/type/visibility, capture the current SHA when concurrency matters,

and preview local paths or remote resources affected.

  1. Use explicit mutation intent. Set a meaningful commit_message; pass

repo_type; choose revision; use create_pr=True when review is safer;

use parent_commit for optimistic concurrency.

  1. Verify the result. Assert returned IDs/types and inspect the resulting

revision. For PR commits, verify CommitInfo.pr_revision and inspect that

ref rather than assuming main changed.

  1. Guard destructive actions. Require an exact target display, a dry-run

plan, and explicit confirmation immediately before delete, merge, move, or

visibility reduction. Re-inspect after confirmation if the workflow waited.

  1. Recover narrowly. Branch on typed exceptions and HTTP status. Retry

only operations shown to be safe, bounded, and still valid after re-read.

Safety confirmations

Deletion, move, visibility reduction, branch/tag deletion, collection or

webhook deletion, irreversible comment hiding, and PR merge require a

read-only plan, a dry-run gate, exact target confirmation, an immediate SHA or

state recheck, one mutation, and a post-check. --yes or APPLY=1 is only a

mechanism; non-interactive use must receive approval from an upstream reviewed

control. See the guarded workflow.

Core Concepts

namespace for creation, but explicit IDs are safer in automation.

space; never pass plural forms to Python methods.

Mutating methods normally default to main; verify the method-specific

constraints before combining revision and create_pr.

existing target. It does not prove that the existing resource has the

requested visibility or settings. Collections spell this exists_ok.

Do not pass both private and visibility.

concurrency check. On conflict, fetch the new head and re-evaluate; do not

blindly drop the check.

pr_url, pr_num, and pr_revision; main is unchanged until merge.

credentials, signed URLs, or private payload content in it.

Limit iteration and test for None; an info query usually contains more

detail than a list query.

Choose The Client Surface

Use HfApi(...) when several calls should share an endpoint, token,

user-agent, or headers. Root-level helpers such as create_repo,

upload_file, and list_models expose the same public operations and are

convenient for isolated calls. Keep one configured client through a workflow

so endpoint and credentials cannot drift.

Read API reference before writing calls or

interpreting RepoUrl, info, collection, discussion, webhook, or commit

objects. It contains signatures verified from the installed 1.29.0 package.

Read workflows when implementing create → inspect →

upload → revision/PR flows, discovery, refs, cards, collections, discussions,

webhook resources, or a check-before-delete plan. Examples explicitly mark

read-only and mutation boundaries.

Read troubleshooting when credentials,

identity, access, revisions, concurrency, upload patterns, rate limits,

network failures, or destructive safeguards are involved. Follow its typed,

bounded recovery rules instead of broad retries.

Output Expectations

Return or record, without secrets:

secrets (notably webhook resources);

present, or resource is absent after an approved deletion;

ambiguity.

Stop rather than guess when target ownership, repo type, destructive intent,

credential scope, or post-conflict content validity cannot be established.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.