AlexandrAI AGENTS.md
agents-md

AlexandrAI Tools Rotate PDF Agent Guide

Agent guide for normalizing PDF rotations to quarter turns and applying them to every page.

AGENTS.md

Guidance for coding agents working on AlexandrAI Tools Rotate PDF in the alexandrai-tools project.

Project overview

This guide covers src/tools/rotate-pdf. normalizeAngle maps arbitrary integer degrees, including negative and large values, to 0, 90, 180, or 270. Body.astro loads a selected PDF, adds the requested rotation to each page's current rotation, normalizes the result, applies pdf-lib degrees, saves the document, and downloads rotated.pdf.

Primary source files

  • src/tools/rotate-pdf/index.ts defines meta, RotationDeg, and normalizeAngle.
  • src/tools/rotate-pdf/index.test.ts covers 0, 90, 180, 270, 360, 450, negative quarter turns, and 720.
  • src/tools/rotate-pdf/Body.astro owns the selected rotation, pdf-lib load/save flow, and download action.
  • src/tools/rotate-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

  • Keep public rotation values constrained to quarter turns.
  • Normalize current page rotation plus requested rotation before setting the page rotation.
  • Handle negative and greater-than-full-turn inputs in normalizeAngle.
  • Wrap 360 and 720 back to zero.
  • Use each page's existing rotation as input rather than overwriting blindly.
  • Apply the same selected rotation to every page unless page selection is explicitly added.
  • If arbitrary angles are ever supported, replace the RotationDeg contract and tests together.

Testing

Test all quarter-turn inputs, negative values, values above one full turn, non-quarter values if UI can produce them, existing page rotations, all-page application, save/download behavior, and invalid PDF errors.

PR checklist

  • npm test passes for rotate-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.