agentleFS
JoviDeCroockJoviDeCroock/pracht/skills/add-images/SKILL.md

add-images

Skill106 starsChanged 7 months agoMITView on GitHub

Wire `@pracht/image`: the `<Image>` component, a loader for the deploy target, `?pracht` build-time imports with blur placeholders, and the optimization endpoint. Use for "add images", "optimize images", "responsive images", "next/image equivalent", "blur placeholders", "images cause layout shift".

  • Reads credentials
  • Installs packages

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Put configureImage() where both the server and the browser evaluate it — the top of src/routes.ts is the canonical spot:

    line 61
  2. Very specific:

    Import both loaders from @pracht/image.

    line 82
  3. Very specific:

    Check in the browser: the <img> carries srcset/sizes, the LCP image is fetchpriority="high", and no layout shift occurs on reload.

    line 194
  4. Very specific:

    Never leave localOrigin unset — relative sources are resolved only against it, so a forged Host cannot turn the endpoint into an open proxy.

    line 200
  5. Very specific:

    Always allowlist remote hosts with remotePatterns.

    line 203
  6. Very specific:

    When configureImage() customizes deviceSizes/imageSizes, pass the matching allowedWidths — the endpoint rejects widths outside its …

    line 205
  7. Very specific:

    Do not use priority on more than the one above-the-fold image per route.

    line 208
  8. Very specific:

    Use an immutable one-year cacheControl only when every source URL is content-addressed.

    line 215
  9. Very specific:

    Never overwrite an existing vite.config.ts, image API route, or configureImage() call — diff first and confirm with AskUserQuestion.

    line 217

≈ “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

Pracht Add Images

@pracht/image splits the problem the way next/image does: the <Image> component decides which widths to render, a loader decides what URL serves each width (https://pracht.resynapse.dev/docs/images). The component renders a plain <img> — SSR-safe, zero hydration, works with hydration: "none".

Step 1: Choose the backend for the deployment target

MCP: if pracht dev-mcp is registered, prefer its inspect_*, doctor, and verify tools to the CLI.

pracht inspect build --json   # adapterTarget (requires a prior `pracht build`)
TargetLoaderNotes
NodedefaultLoader + the built-in endpointneeds sharp; put a CDN in front
CloudflarecloudflareLoaderImage Resizing must be enabled on the zone; sharp does not run on Workers
VercelvercelLoaderneeds an images section in the project config; Vercel only serves widths listed in images.sizes
NetlifynetlifyLoaderImage CDN; remote sources need images.remote_images in netlify.toml; no sharp endpoint
Static hostpassthroughLoaderno image service — srcset is omitted
Any target, no runtime service?pracht&pracht-static importsprebuilt WebP variants, no loader involved

Confirm the choice with AskUserQuestion when the app deploys to more than one target — a per-target configureImage() behind an env flag is the usual answer.

Step 2: Install

pnpm add @pracht/image
pnpm add sharp              # only for the built-in Node endpoint
pnpm add -D sharp           # only for `?pracht` imports / static variants

sharp stays an optional peer dependency; the vite plugin fails with an install hint when a ?pracht import needs it, and the endpoint answers 500 with the same hint at runtime.

Step 3: Configure the loader once

Put configureImage() where both the server and the browser evaluate it — the top of src/routes.ts is the canonical spot:

import { cloudflareLoader, configureImage } from "@pracht/image";

configureImage({
  loader: cloudflareLoader,
  // deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
  // imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
  // quality: 75,
});

createDefaultLoader("/my/endpoint") builds a default-style loader for a custom endpoint path. Root-absolute endpoints pick up Vite's deploy base automatically; provider loaders (cloudflareLoader, vercelLoader, netlifyLoader) deliberately stay at the origin root.

For Netlify, use configureImage({ loader: import.meta.env.DEV ? passthroughLoader : netlifyLoader }) so pracht dev renders original images. Import both loaders from @pracht/image. For remote sources, merge the allowed URL patterns into the existing netlify.toml:

[images]
remote_images = ['https://images\.example\.com/.*']

Local source files need no image-service configuration; Netlify negotiates the output format and caches resized images. Skip the Node endpoint step.

Step 4: Render images

import { Image } from "@pracht/image";

<Image
  src="/banner.jpg"
  alt="Product banner"
  width={1200}
  height={280}
  sizes="(max-width: 1200px) 100vw, 1200px"
  priority
/>;
  • alt is required — use alt="" for decorative images.
  • width/height are required unless fill; they reserve space and prevent layout shift. Missing dimensions log a console.error in dev.
  • sizes (or fill) switches the srcset to w descriptors across deviceSizes; a fixed image gets 1x/2x candidates snapped to the breakpoint list so caches stay small.
  • priority on above-the-fold images swaps loading="lazy" + decoding="async" for loading="eager" + fetchpriority="high". Use it for the LCP image only.
  • fill positions the image absolutely inside the nearest positioned ancestor and defaults sizes to 100vw; pair with style={{ objectFit: "cover" }}.

Step 5: Build-time imports and static variants

Register the plugin — the main pracht() plugin does not include it:

// vite.config.ts
import { prachtImage } from "@pracht/image/vite";

export default { plugins: [prachtImage(), pracht({ /* … */ })] };
import hero from "./hero.jpg?pracht";                 // { src, width, height, blurDataURL }
import banner from "./banner.jpg?pracht&pracht-static"; // + prebuilt WebP variants

<Image src={hero} alt="Hero" placeholder="blur" />;
<Image src={banner} alt="Banner" sizes="(max-width: 960px) 100vw, 960px" />;
  • Dimensions come from sharp metadata with EXIF orientation applied, so a rotated portrait reports its display size.
  • blurDataURL is an 8px WebP data URI generated at build time. SVGs skip it, animated GIFs blur their first frame.
  • pracht-static emits content-hashed WebP files at staticWidths, takes precedence over the global loader, and is cached in Vite's cacheDir keyed by source bytes. It requires an absolute Vite base; SVG and animated sources pass through unchanged.
  • Root-relative publicDir imports keep stable public URLs and bypass the runtime loader.
  • Types: "types": ["@pracht/image/client"] in tsconfig, or a triple-slash reference in any .d.ts.

@pracht/markdown uses ?pracht&pracht-static automatically for relative Markdown images and renders them with getImageProps() — see /add-content.

Step 6: Mount the optimization endpoint (Node-compatible runtimes only)

// src/api/_pracht/image.ts
import { createImageHandler } from "@pracht/image/node";

const imageHandler = createImageHandler({
  // Required in every environment, including dev. Your own env var, not a
  // framework one — set it to the app's public origin and use the same value
  // as nodeAdapter({ canonicalOrigin }).
  localOrigin: process.env.PRACHT_ORIGIN,
  // remotePatterns: [{ protocol: "https", hostname: "*.example.com", pathname: "/uploads" }],
  // allowedWidths: [640, 1280],   // required when configureImage() customizes the breakpoints
});

export const GET = imageHandler;
export const HEAD = imageHandler;

That file maps to /api/_pracht/image, exactly what defaultLoader targets — no further configuration. The endpoint negotiates WebP via Accept (pass formats: ["image/avif", "image/webp"] for AVIF), never enlarges beyond the source, passes SVG/GIF through, and answers Cache-Control: public, max-age=14400, must-revalidate with Vary: Accept. It drops the query string from relative image files (/hero.png?v=2 → /hero.png), so if the app cache-busts or signs local images with a query parameter, keep it with sourceQueryParams: ["v"]. It also caches results in memory for no longer than cacheControl allows and encodes at most four at once (cache, maxConcurrency); a custom fetchImage turns the shared cache off unless cache is set.

Step 7: Verify

pracht dev            # set PRACHT_ORIGIN to the exact origin it prints
pracht build
pracht verify --json

Check in the browser: the <img> carries srcset/sizes, the LCP image is fetchpriority="high", and no layout shift occurs on reload. Then run /audit-bundles and /audit-seo if image work was part of a performance pass.

Rules

  1. Never leave localOrigin unset — relative sources are resolved only against it, so a forged Host cannot turn the endpoint into an open proxy. The handler answers 500 until it is configured, including in dev.
  2. Always allowlist remote hosts with remotePatterns; never proxy arbitrary URLs.
  3. When configureImage() customizes deviceSizes/imageSizes, pass the matching allowedWidths — the endpoint rejects widths outside its allowlist by design, and skipping this silently breaks the srcset.
  4. Do not use priority on more than the one above-the-fold image per route.
  5. placeholder="blur" writes an inline style attribute: a CSP without style-src-attr 'unsafe-inline' silently drops it (and fill positioning), and img-src must include data:. See https://pracht.resynapse.dev/docs/recipes/csp.
  6. Platform loaders generate URLs that only resolve on the deployed platform — fall back to passthroughLoader behind import.meta.env.DEV for local previews.
  7. Use an immutable one-year cacheControl only when every source URL is content-addressed.
  8. Never overwrite an existing vite.config.ts, image API route, or configureImage() call — diff first and confirm with AskUserQuestion.

$ARGUMENTS

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.