AGENTS.md
Guidance for coding agents working on AlexandrAI Tools Images to PDF in the alexandrai-tools project.
Project overview
This guide covers src/tools/images-to-pdf. The helper accepts image/jpeg, image/jpg, and image/png, infers JPEG or PNG MIME types from file names when needed, and rejects other extensions. Body.astro creates a PDFDocument, embeds each image with embedPng or embedJpg, adds one page at the image's native dimensions, draws the image full-page, and downloads images.pdf.
Primary source files
- src/tools/images-to-pdf/index.ts defines meta, ALLOWED_MIME_TYPES, AllowedMimeType, isSupportedImage, and inferMimeType.
- src/tools/images-to-pdf/index.test.ts covers accepted JPEG/JPG/PNG MIME types, rejected GIF/PDF/empty types, and extension inference for lowercase and uppercase file names.
- src/tools/images-to-pdf/Body.astro owns multi-file input, MIME fallback, pdf-lib image embedding, page creation, save, download, and clear actions.
- src/tools/images-to-pdf/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
- Accept only JPEG and PNG inputs unless tests and embedding code are expanded.
- Use MIME type first, then infer from file extension when MIME is missing.
- Reject unsupported files with a message naming the offending file.
- Use embedPng only for PNG MIME and embedJpg for JPEG or JPG MIME.
- Create one PDF page per image.
- Set each page to the embedded image's native width and height.
- Keep file order stable so the resulting PDF follows the user's selection order.
Testing
Test supported and unsupported MIME types, extension inference, uppercase extensions, mixed image order, unsupported files in a batch, page dimensions, one-image and many-image conversions, download filename, and state reset after clear.
PR checklist
- npm test passes for images-to-pdf.
- PDF and binary file processing remain browser-local.
- Pure helper behavior, UI state, and i18n labels stay aligned.
- Invalid input, empty output, and download behavior are covered by tests.