agentleFS
Hugging FaceKnown publisherhuggingface/huggingface_hub_rust/AGENTS.md

huggingface_hub_rust

AGENTS.md24 starsChanged 8 months agoApache-2.0View on GitHub

Async Rust client library for the Hugging Face Hub API. This is the Rust equivalent of the Python huggingface_hub library. The primary entry point is the HFClient struct, which wraps an Arc<HFClientInner> for cheap cloning. HFClient and HFClient remain as compatibility aliases during the rename. All methods are async and use reqwest as the HTTP client. Paginated endpoints return impl Stream<Item = Result<T>> via futures::stream::try_unfold. Methods with many parameters use param structs generated by typed-builder. Key capabilities: These rules apply…

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

25 rules. About 0 are common, 17 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈17

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Commit creation, commit history, diffs between revisions

    line 11
  2. Distinctive:

    NO trivial comments — do not add comments that restate what the code does

    line 22
  3. Very specific:

    No wildcard imports (e.g., use foo::*), except pub use re-exports in lib.rs

    line 24
  4. Distinctive:

    All imports are at the top of the file or top of module

    line 25
  5. Very specific:

    Use Result<T, E> with explicit error handling — never panic

    line 30
  6. Distinctive:

    Prefer structured logging (tracing/log macros with fields, not string formatting)

    line 37
  7. Very specific:

    Add all dependencies to Cargo.toml (workspace root) or huggingface_hub/Cargo.toml (crate-level)

    line 41
  8. Distinctive:

    Prefer well-maintained crates from crates.io

    line 42
  9. Very specific:

    Place in the same file using #[cfg(test)] modules

    line 49
  10. Very specific:

    Run read-only tests: HF_TOKEN=HF_xxx cargo test -p huggingface-hub --test integration_test

    line 57
  11. Very specific:

    Write operation tests (create/delete repos, upload files) require HF_TEST_WRITE=1

    line 58
  12. Very specific:

    Run all tests including writes: HF_TOKEN=HF_xxx HF_TEST_WRITE=1 cargo test -p huggingface-hub --test integration_test

    line 59
  13. Distinctive:

    ALWAYS run both after making changes — do not skip this step

    line 65
  14. Distinctive:

    Verify that every change is minimal and necessary — do not include unrelated modifications

    line 69
  15. Distinctive:

    Before writing any code:

    line 132
  16. Distinctive:

    Plan: Write an implementation plan that includes testing strategy (unit tests, integration tests, manual verification steps).

    line 135
  17. Distinctive:

    When changing public interfaces or adding user-facing capabilities:

    line 137
  18. Very specific:

    ALWAYS update the relevant examples in huggingface_hub/examples/ and any affected README snippets so they match the current public API.

    line 139
  19. Distinctive:

    ALWAYS add at least one example for new functionality unless an existing example already demonstrates that exact workflow clearly.

    line 140
  20. Distinctive:

    Prefer examples that show the intended high-level interface, not just the lowest-level parameter structs, especially for new ergonomic APIs …

    line 141
  21. Distinctive:

    When reviewing a pull request, follow these rules:

    line 145
  22. Distinctive:

    Use phrases like "consider...", "what do you think about...", "we might want to..."

    line 150
  23. Distinctive:

    When unsure, ask a clarifying question instead of assuming something is wrong

    line 152
  24. Distinctive:

    Add inline comments at specific diff locations for targeted feedback

    line 166
  25. Distinctive:

    Do NOT prefix substantive feedback (public API changes, correctness issues, missing tests) — these require attention

    line 168

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

huggingface-hub

Async Rust client library for the Hugging Face Hub API. This is the Rust equivalent of the Python huggingface_hub library.

The primary entry point is the HFClient struct, which wraps an Arc<HFClientInner> for cheap cloning. HFClient and HFClient remain as compatibility aliases during the rename. All methods are async and use reqwest as the HTTP client. Paginated endpoints return impl Stream<Item = Result<T>> via futures::stream::try_unfold. Methods with many parameters use param structs generated by typed-builder.

Key capabilities:

  • Repository info, listing, creation, deletion, and settings updates
  • File upload, download, listing, and deletion
  • Commit creation, commit history, diffs between revisions
  • Branch and tag management
  • User and organization info
  • Xet high-performance transfers (behind the xet feature flag)

Code Standards

These rules apply to ALL code written or modified in this repo:

Style

  • NO trivial comments — do not add comments that restate what the code does
  • Descriptive variable and function names
  • No wildcard imports (e.g., use foo::*), except pub use re-exports in lib.rs
  • All imports are at the top of the file or top of module
  • Latest stable Rust features are allowed

Error Handling

  • Use Result<T, E> with explicit error handling — never panic
  • Define custom error types using thiserror for domain-specific errors
  • Provide helpful, actionable error messages

Performance

  • Be mindful of allocations in hot paths
  • Prefer structured logging (tracing/log macros with fields, not string formatting)

Dependencies

  • Add all dependencies to Cargo.toml (workspace root) or huggingface_hub/Cargo.toml (crate-level)
  • Prefer well-maintained crates from crates.io
  • Shared dependencies belong in the workspace [dependencies] table, not per-crate

Testing

Unit Tests

  • Place in the same file using #[cfg(test)] modules
  • Run: cargo test -p huggingface-hub

Integration Tests

  • Located in huggingface_hub/tests/integration_test.rs
  • Require a valid HF_TOKEN environment variable and internet access
  • Tests skip gracefully when HF_TOKEN is not set (no failures)
  • Run read-only tests: HF_TOKEN=HF_xxx cargo test -p huggingface-hub --test integration_test
  • Write operation tests (create/delete repos, upload files) require HF_TEST_WRITE=1
  • Run all tests including writes: HF_TOKEN=HF_xxx HF_TEST_WRITE=1 cargo test -p huggingface-hub --test integration_test

Formatting and Linting

  • Format: cargo +nightly fmt
  • Lint: cargo clippy -p huggingface-hub --all-features -- -D warnings
  • ALWAYS run both after making changes — do not skip this step

Minimal Changes

  • Verify that every change is minimal and necessary — do not include unrelated modifications

Project Layout

Agents MUST update this section when adding new crates or large modules.

huggingface_hub_rust/
├── Cargo.toml                      # Workspace root
├── AGENTS.md                       # This file
├── .gitignore
├── huggingface_hub/                         # Main library crate (package: huggingface-hub)
│   ├── Cargo.toml                  # Crate manifest, dependencies, features
│   ├── src/
│   │   ├── lib.rs                  # Public re-exports, crate docs
│   │   ├── client.rs               # HFClient, HFClientBuilder, HFClientInner, auth headers, URL builders
│   │   ├── repository.rs           # HFRepository/HFRepo handle, repo-scoped params, repo-bound methods
│   │   ├── bucket.rs               # HFBucket handle with factory method and URL helpers
│   │   ├── constants.rs            # Env var names, default URLs, repo type helpers
│   │   ├── error.rs                # HFError enum, Result alias, NotFoundContext
│   │   ├── pagination.rs           # Generic paginate<T>() with Link header parsing
│   │   ├── cache.rs                # Cache path computation, locking, ref read/write, symlink, scan, delete
│   │   ├── diff.rs                 # Raw diff parsing (parse_raw_diff, stream_raw_diff), HFFileDiff, GitStatus
│   │   ├── xet.rs                  # Xet high-performance transfer stubs (behind "xet" feature)
│   │   ├── types/
│   │   │   ├── mod.rs              # Module declarations, re-exports
│   │   │   ├── cache.rs            # CachedFileInfo, CachedRepoInfo, HFCacheInfo, DeleteCacheRevision
│   │   │   ├── repo.rs             # RepoType, RepoInfo, ModelInfo, DatasetInfo, SpaceInfo, RepoTreeEntry
│   │   │   ├── user.rs             # User, Organization, OrgMembership
│   │   │   ├── commit.rs           # CommitInfo, GitCommitInfo, GitRefs, CommitOperation, AddSource
│   │   │   ├── params.rs           # All *Params structs with TypedBuilder
│   │   │   ├── buckets/
│   │   │   │   ├── mod.rs          # BucketInfo, BucketUrl, BucketTreeEntry, BucketFileMetadata types
│   │   │   │   └── sync.rs         # SyncPlan, SyncOperation, SyncAction types
│   │   │   ├── bucket_params.rs    # Bucket parameter structs with TypedBuilder
│   │   │   └── spaces.rs           # SpaceRuntime, SpaceVariable (behind "spaces" feature)
│   │   └── api/
│   │       ├── mod.rs              # Module declarations
│   │       ├── repo.rs             # Repo info, listing, existence checks, create/delete/update/move
│   │       ├── cache.rs            # scan_cache, delete_cache_revisions
│   │       ├── files.rs            # File listing, download, upload, create_commit, snapshot_download
│   │       ├── commits.rs          # Commit listing, diffs, branch/tag management
│   │       ├── users.rs            # whoami, auth_check, user/org info, followers
│   │       ├── spaces.rs           # Space runtime, secrets, variables, hardware, pause/restart
│   │       └── buckets/
│   │           ├── mod.rs          # All bucket API methods (create, delete, list, move, tree, batch, download)
│   │           └── sync.rs         # HFBucket::sync() — plan computation and execution
│   ├── src/bin/hfrs/commands/buckets/  # CLI bucket subcommands
│   │   ├── mod.rs
│   │   ├── create.rs
│   │   ├── list.rs
│   │   ├── info.rs
│   │   ├── delete.rs
│   │   ├── remove.rs
│   │   ├── move_bucket.rs
│   │   ├── cp.rs
│   │   └── sync.rs
│   └── tests/
│       └── integration_test.rs     # Integration tests against live Hub API

Feature Development

Before writing any code:

  1. Branch: Confirm you are on a feature branch, not main. If on main, create a branch named <username>/<short-description>.
  2. Plan: Write an implementation plan that includes testing strategy (unit tests, integration tests, manual verification steps). Add this plan as a comment on the PR.

When changing public interfaces or adding user-facing capabilities:

  • ALWAYS update the relevant examples in huggingface_hub/examples/ and any affected README snippets so they match the current public API.
  • ALWAYS add at least one example for new functionality unless an existing example already demonstrates that exact workflow clearly.
  • Prefer examples that show the intended high-level interface, not just the lowest-level parameter structs, especially for new ergonomic APIs like repo handles.

Code Review

When reviewing a pull request, follow these rules:

Tone

  • Collegiate and constructive — write as a peer, not an authority
  • Use phrases like "consider...", "what do you think about...", "we might want to..."
  • Acknowledge good decisions and clean patterns, not just problems
  • When unsure, ask a clarifying question instead of assuming something is wrong

What to Review

  • Correctness — logic errors, edge cases, off-by-one errors
  • Readability — naming consistency, code clarity, helpful error messages
  • Maintainability — temporary workarounds tracked, types in the right crate, clean abstractions
  • Testability — missing tests for new endpoints/logic, weakened assertions, coverage gaps
  • Performance — unnecessary allocations in hot paths, unbounded response sizes, missing concurrency limits
  • Security — auth checks on new routes, input validation, error message information leakage

How to Structure Feedback

  • Post a summary comment on the PR: overview of the changes, key observations, cross-cutting concerns
  • Add inline comments at specific diff locations for targeted feedback
  • Prefix minor style suggestions with nit: — these are optional and the author may skip them
  • Do NOT prefix substantive feedback (public API changes, correctness issues, missing tests) — these require attention

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.