agentleFS
discord-phpdiscord-php/DiscordPHP/.agents/skills/helpers-and-infra-keeper/SKILL.md

helpers-and-infra-keeper

Skill1.1k starsChanged 36 days agoMITView on GitHub

Work with DiscordPHP's infrastructure utilities — CacheWrapper, CacheConfig, BigInt, Multipart, Endpoint::bind URL templates, Collection base class, and domain Exceptions. Use when changing cache behavior, REST endpoint routing, file uploads, big-integer ID math, or adding/modifying exceptions.

Trending

More talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 2 mentionsMar 2026: 0 mentionsApr 2026: 1 mentionMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 3 mentionsSep 2026: 13 mentionsOct 2026: 9 mentionsNov 2026: 2 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the discord-php/DiscordPHP repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about discord-php/DiscordPHP

The biggest 5 of 52 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 52

Talked about on GitHub and Bluesky (52 times).

On GitHub · 50

45 more on GitHub

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 1 is distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    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. Very specific:

    Use this skill when work touches src/Discord/Helpers/*, src/Discord/Exceptions/*, Endpoint::bind() patterns, or the external Collection / …

    line 12
  2. Very specific:

    If a feature needs configurable cache behavior (TTL, compression, sweep interval), add it as a property on CacheConfig.

    line 40
  3. Distinctive:

    When a REST write succeeds, the cache write must happen in the same promise chain — not after a refetch.

    line 44
  4. Very specific:

    All REST endpoints are defined as Endpoint constants in the external discord-php/http package:

    line 48
  5. Very specific:

    Rule: never build URL strings by hand.

    line 62
  6. Very specific:

    After implementing an operation, or deciding not to, run composer openapi:update and commit the baseline.

    line 72
  7. Very specific:

    All repositories extend Collection from discord-php-helpers/collection.

    line 78
  8. Very specific:

    Rule: use BigInt for any permission flag arithmetic or snowflake comparison that could run on 32-bit PHP.

    line 98
  9. Very specific:

    When adding a new typed exception: extend \Exception or the nearest domain parent, keep the name *Exception, and put it in …

    line 123

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill 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
SKILL.md

Skill: helpers-and-infra-keeper

Use this skill when work touches src/Discord/Helpers/*, src/Discord/Exceptions/*, Endpoint::bind() patterns, or the external Collection / discord-php/http packages.

These are cross-cutting infrastructure utilities. They have no domain logic, but nearly every other layer depends on them.

Read in this order

  1. src/Discord/Helpers/CacheWrapper.php — PSR-16 + React cache bridge
  2. src/Discord/Helpers/CacheConfig.php — cache options (compression, sweep, TTL)
  3. src/Discord/Helpers/LegacyCacheWrapper.php — fallback for older cache implementations
  4. src/Discord/Helpers/BigInt.php — 32-bit PHP GMP polyfill for snowflake IDs and permission bitfields
  5. src/Discord/Helpers/Multipart.php — multipart/form-data builder for file uploads
  6. src/Discord/Repository/AbstractRepository.php — how repositories consume CacheWrapper and $endpoints
  7. src/Discord/Discord.php — options['cache'] wiring to CacheWrapper/CacheConfig

Cache infrastructure

Three-class hierarchy

ClassRole
CacheConfigValue object holding cache options passed in Discord::__construct() options['cache']
CacheWrapperMain wrapper: bridges React's async cache (PSR-16 + react/cache) to repository storage. Handles compression if configured.
LegacyCacheWrapperDefault when no external cache is configured. Wraps an in-memory store. Used by default.

Rule: repositories do not interact with cache stores directly. They always go through CacheWrapper. Do not bypass it.

When to use CacheConfig

If a feature needs configurable cache behavior (TTL, compression, sweep interval), add it as a property on CacheConfig. Do not scatter cache tuning across individual repositories.

Cache coherence rule

When a REST write succeeds, the cache write must happen in the same promise chain — not after a refetch. This is enforced by convention, not framework. Break the chain and you get stale cache.

Endpoint::bind() — URL template pattern

All REST endpoints are defined as Endpoint constants in the external discord-php/http package:

use Discord\Http\Endpoint;

protected $endpoints = [
    'get'    => Endpoint::CHANNEL,
    'update' => Endpoint::CHANNEL,
    'delete' => Endpoint::CHANNEL,
];

Routes with parameters use :param placeholders. Binding happens via Endpoint::bind($endpoint, $params) where $params is a key-value map matching the placeholders.

Rule: never build URL strings by hand. Always use Endpoint::bind() or assign a named Endpoint constant. Raw string concatenation bypasses rate-limit bucket identification.

Finding endpoint constants

Browse vendor/discord-php/http/src/Endpoint.php for available constants. If a Discord API endpoint is missing, add it to the external package — do not define it inline in DiscordPHP source.

Checking against Discord's OpenAPI description

composer openapi (scripts/openapi-check.php) compares the library with the live preview of Discord's OpenAPI description. It lists the operations DiscordPHP never sends a request for, and routes with no Endpoint constant. It also lists what Discord has changed since the commit recorded in scripts/openapi-baseline.json: endpoints added or removed, parameters and responses, schema properties and enum values. It reads the library's source to see which request each constant is sent with. It recognises a repository's $endpoints table (all/get send GET, create POST, update PATCH, delete DELETE, and other keys whatever method sends $this->endpoints['key']), a direct call like ->post(Endpoint::bind(Endpoint::X, …)), or a variable assigned the endpoint and sent later in the same method. Keep new request code in one of those shapes, or the check will report the operation as unsent.

After implementing an operation, or deciding not to, run composer openapi:update and commit the baseline. Record the reason for every gap that remains in its unimplemented map. A daily workflow (.github/workflows/openapi.yml) runs the same check and opens an issue labelled openapi when it finds something new.

The check also reads Discord's stable description (specs/openapi.json) at the same commit. Operations, parameters, properties and enum values that only the preview has are marked [preview only]; the issue then carries a caution and the openapi-preview label. Discord may change or remove them at any time. Anything implemented from them gets @since X.Y.Z OpenAPI Preview in its docblock and a sentence saying it is only in Discord's OpenAPI preview and may change or be removed at any time, so users do not rely on it. composer openapi -- --all lists everything only in the preview. When the check reports something as now in the stable edition too, remove its preview flag.

Collection base class

All repositories extend Collection from discord-php-helpers/collection. Key behaviors inherited:

  • discriminator-keyed storage ($discrim — defaults to 'id')
  • typed item enforcement ($class)
  • get($key), has($key), first(), find(callable), filter(callable)
  • JSON serialization

AbstractRepository adds REST/cache behavior on top. Do not re-implement collection operations in repositories — use the inherited helpers.

BigInt

BigInt provides GMP-based arithmetic for environments where PHP is compiled as 32-bit, where Discord snowflake IDs and 64-bit permission bitfields overflow native integers.

Usage pattern:

use Discord\Helpers\BigInt;

$perms = BigInt::bitAnd($memberPerms, $requiredPerm);

Rule: use BigInt for any permission flag arithmetic or snowflake comparison that could run on 32-bit PHP. Do not assume PHP_INT_SIZE === 8.

Multipart

Multipart builds multipart/form-data request bodies for file attachment uploads. It is used by MessageBuilder and similar builders when attachments are present.

It has no cache or domain logic — treat it as a serialization helper.

Exception hierarchy

src/Discord/Exceptions/ contains domain-specific exceptions. Do not use generic \RuntimeException or \InvalidArgumentException when a typed exception already exists:

ExceptionWhen to throw
IntentExceptionInvalid or missing gateway intents at startup
PartRequestFailedExceptionA part fetch or REST operation failed
InvalidOverwriteExceptionA permission overwrite is malformed
AttachmentSizeExceptionAttachment exceeds size limit
FileNotFoundExceptionFile path not found for upload
BufferTimedOutExceptionAudio buffer read timed out
LibSodiumNotFoundExceptionext-sodium not available (voice)
OpusNotFoundExceptionOpus codec binary not available
FFmpegNotFoundExceptionFFmpeg binary not found
DCANotFoundExceptionDCA tool not found

When adding a new typed exception: extend \Exception or the nearest domain parent, keep the name *Exception, and put it in src/Discord/Exceptions/.

Companion surfaces

TouchingAlso inspect
CacheWrapper or CacheConfigDiscord.php options['cache'] wiring, AbstractRepository cache usage, LegacyCacheWrapper fallback
Endpoint constants$endpoints arrays in all affected repositories, rate-limit bucket behavior
BigIntPermission parts (Permission, RolePermission, ChannelPermission), snowflake comparison sites
MultipartMessageBuilder attachment handling, HTTP client request formation
An exception classCallers that catch the specific type, docs/guide if it's user-facing

Design tripwires

  • Building REST URL strings by hand instead of using Endpoint::bind()
  • Writing to a cache store directly inside a repository, bypassing CacheWrapper
  • Re-implementing collection iteration helpers that Collection already provides
  • Using PHP_INT_SIZE === 8 as a safe assumption for permission arithmetic — use BigInt
  • Throwing \RuntimeException when a typed domain exception already exists
  • Adding domain logic (Discord resource rules) to any class in Helpers/ or Exceptions/
  • Putting new audio stream or voice crypto helpers in Helpers/ — those belong in Voice/* or the external voice package

Reference files

  • src/Discord/Helpers/CacheWrapper.php — main cache bridge
  • src/Discord/Helpers/CacheConfig.php — cache options value object
  • src/Discord/Helpers/LegacyCacheWrapper.php — default in-memory cache
  • src/Discord/Helpers/BigInt.php — 32-bit PHP GMP polyfill
  • src/Discord/Helpers/Multipart.php — file upload form builder
  • src/Discord/Repository/AbstractRepository.php — how CacheWrapper and Endpoint are consumed
  • src/Discord/Exceptions/IntentException.php — representative typed exception
  • src/Discord/Exceptions/PartRequestFailedException.php — REST failure exception
  • vendor/discord-php/http/src/Endpoint.php — all REST endpoint constants

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.