AssetDiet (On-Demand Local Media Audit & Compression)
Use 092Abdullah/AssetDiet (npm: assetdiet-mcp) strictly as an ephemeral 100% local CLI via npx [email protected] — zero cloud uploads and zero permanent 16-tool MCP schema bloat in chat sessions.
1. Non-Negotiable Guardrails
- NEVER register the MCP server: Never run
assetdiet setuporassetdiet mcp. Always invoke CLI subcommands directly (audit,scan,optimize,restore,doctor). - Pin the audited version (
[email protected]): Avoid unpinned@latestin automated runs so supply-chain behavior matches the audited release. - Read-only audit before writes: Always run
auditfirst and show potential savings + duplicate groups before mutating repository assets (unless the user explicitly asked to apply--policy safeimmediately). - Expo / React Native & App Icon protection: In Expo / React Native projects (
app.json/app.config.ts), native app icons, splash screens, notification icons, and staticrequire('./foo.png')assets often require.pngextensions — keep--policy safe(same extension, lossless/SSIM ≥ 0.98) unless targeting a pure web folder (public/,static/) with explicit user approval for.webpconversion.
2. Step-by-Step Workflow
Step 1: Read-Only Audit (Zero File Changes)
# Quick 3-line scorecard summary (total size, savings, SHA-256 duplicate groups)
npx [email protected] audit <targetPath> --policy safe --summary
# Full per-file breakdown (or add --json for structured filtering)
npx [email protected] audit <targetPath> --policy safe
Step 2: Optimize Safely with Atomic Journal & Backup
safepolicy (Default — Recommended): Compresses in-place (Sharplossless/85,SVGOkeepingviewBox), keeps the exact file extensions, never touches source code imports, and removes duplicate byte copies only when they have0code references:# Optional dry-run preview npx [email protected] optimize <targetPath> --policy safe --dry-run # Execute with atomic backup (.assetdiet/backups/<runId>/) npx [email protected] optimize <targetPath> --policy safebalancedpolicy (Web-only.png/.jpg→.webp+ code reference migration — ask confirmation first):
Afternpx [email protected] optimize <targetPath> --policy balanced --dry-run npx [email protected] optimize <targetPath> --policy balancedbalanced, immediately inspectgit statusandgit diffon all modified.ts/.tsx/.jsx/.css/.htmlimports and run the project's build/typecheck.
Step 3: Instant Rollback & .assetdiet/ Git Hygiene
- Save the
Run IDprinted byoptimize. If any asset looks degraded or an import breaks, restore byte-for-byte originals in one command:npx [email protected] restore --run <runId> --path <targetPath> - Never commit
.assetdiet/backups to Git: Ensure.assetdiet/is listed in.gitignore(or delete.assetdiet/once visual/build verification passes and the user confirms).