AGENTS.md
Guidance for coding agents working on AlexandrAI Tools Image Compressor in the alexandrai-tools project.
Project overview
This guide covers src/tools/image-compressor. clampQuality constrains quality to zero through one, estimateLabel formats byte counts as B, KB, or MB, and Body.astro uses a quality slider, JPEG or WebP mode, canvas toBlob output, before and after size labels, saved percentage, and compressed file downloads.
Primary source files
- src/tools/image-compressor/index.ts defines meta, clampQuality, and estimateLabel.
- src/tools/image-compressor/index.test.ts covers quality boundaries, pass-through values, B labels, KB labels, MB labels, and the 1024 byte edge.
- src/tools/image-compressor/Body.astro owns image preview, quality slider, format toggle, canvas encoding, stats display, Blob download, and clear state.
- src/tools/image-compressor/i18n.ts owns localized labels.
- src/lib/tools.ts registers the tool metadata.
Setup commands
npm install npm test npm run typecheck npm run build npm run dev
Change rules
- Clamp quality before passing it to canvas toBlob.
- Keep UI slider values as percentages and convert them to zero through one for encoding.
- Support JPEG and WebP output only unless format controls and tests are expanded.
- Use the original file size when computing saved percentage.
- Handle negative savings because output can be larger than input.
- Use file extensions that match the selected MIME type.
- Keep outputBlob as the download source and reset it on clear.
Testing
Test clampQuality, estimateLabel thresholds, JPEG and WebP mode toggles, slider conversion, original-size zero fallback, output larger than input, Blob download extension, no-image behavior, and clear-state reset.
PR checklist
- npm test passes for image-compressor.
- Canvas processing stays browser-local and deterministic enough for tests.
- Pure helper behavior, UI controls, and i18n labels stay aligned.
- Download format, filename, and reset behavior are covered.