AGENTS.md
Guidance for coding agents working on AlexandrAI Tools Recipe Scaler in the alexandrai-tools project.
Project overview
This guide covers src/tools/recipe-scaler. formatQuantity formats positive numbers as whole values, common fractions, mixed numbers, or compact decimals. scaleLine detects a leading mixed number, fraction, decimal, or integer, scales it by the ratio, and keeps the remaining ingredient text. scaleRecipe applies the serving ratio to each non-empty line.
Primary source files
- src/tools/recipe-scaler/index.ts defines meta, FRACTIONS, formatQuantity, scaleLine, and scaleRecipe.
- src/tools/recipe-scaler/index.test.ts covers whole numbers, common fractions, mixed numbers, decimal fallback, integer lines, decimal lines, fraction lines, mixed-number lines, no-number lines, ratio one, empty lines, and invalid servings.
- src/tools/recipe-scaler/Body.astro owns servings, ingredient textarea, and scaled output.
- src/tools/recipe-scaler/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
- Return zero for non-positive quantities in formatQuantity.
- Prefer common fractions when the fractional part is within tolerance.
- Return mixed numbers when whole and fraction parts both exist.
- Fall back to compact two-decimal output for awkward fractions.
- Only scale quantities that appear at the start of a line.
- Pass lines without leading quantities through unchanged.
- Return original lines when original or desired servings are not positive.
Testing
Test each supported leading quantity form, awkward decimals, common fraction tolerance, empty lines, invalid serving counts, ratio one, preserving ingredient text, whitespace handling, and multi-line UI output.
PR checklist
- npm test passes for recipe-scaler.
- Calculator formulas, units, and rounding expectations are documented.
- Currency and display formatting remain outside pure helpers.
- Invalid-input behavior is covered by tests and UI validation.