AGENTS.md
Guidance for coding agents working on AlexandrAI Tools Discount Calculator in the alexandrai-tools project.
Project overview
This guide covers src/tools/discount-calculator/index.ts. The tool applies a primary percentage discount to an original price, optionally applies a second percentage discount to the already-discounted price, clamps only the second discount to zero through one hundred, and returns final price, amount saved, and effective percentage saved.
Primary source files
- src/tools/discount-calculator/index.ts defines meta, DiscountResult, and calcDiscount.
- src/tools/discount-calculator/index.test.ts covers single discounts, stacked coupons, zero second discount, invalid prices, invalid primary percentages, clamped second percentages, and full discounts.
- src/tools/discount-calculator/Body.astro owns browser controls.
- src/tools/discount-calculator/i18n.ts owns localized copy.
- src/lib/tools.ts registers metadata.
Setup commands
npm install npm test npm run typecheck npm run build npm run dev
Change rules
- Return a zero result when originalPrice is less than or equal to zero.
- Return a zero result when primary discount is less than zero or greater than one hundred.
- Apply the primary discount before any second discount.
- Clamp the second discount to zero through one hundred.
- Compute amountSaved as originalPrice minus finalPrice.
- Compute effectivePct from amountSaved divided by originalPrice.
- Keep display rounding outside pure calculation unless tests and UI update together.
Testing
Test one discount, stacked discounts, zero second discount, second discount below zero, second discount above one hundred, full discount, zero and negative prices, invalid primary percentages, fractional percentages, and effectivePct accuracy.
PR checklist
- npm test passes for discount-calculator.
- Formula, invalid-input policy, and rounding policy remain documented.
- Pure helpers stay arithmetic-only and browser-local.
- UI labels, metadata, and tests update together for behavior changes.