AGENTS.md
Guidance for coding agents working on AlexandrAI Tools GCD LCM Calculator in the alexandrai-tools project.
Project overview
This guide covers src/tools/gcd-lcm-calculator/index.ts. The tool truncates inputs to integers, uses absolute values, computes GCD with the Euclidean algorithm, computes LCM through a divided-by-GCD product, returns zero for LCM when either input is zero, and reduces lists for aggregate GCD and LCM.
Primary source files
- src/tools/gcd-lcm-calculator/index.ts defines meta, gcd, lcm, gcdList, and lcmList.
- src/tools/gcd-lcm-calculator/index.test.ts covers common divisors, identical numbers, zero inputs, coprime numbers, negative inputs, pairwise LCM, empty lists, single-element lists, and list reductions.
- src/tools/gcd-lcm-calculator/Body.astro owns browser controls.
- src/tools/gcd-lcm-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
- Use Math.trunc before GCD and LCM calculations.
- Use absolute values so negative inputs behave like their positive counterparts.
- Return zero for gcd(0, 0).
- Return zero from lcm when either input is zero.
- Return zero for empty gcdList and lcmList.
- Reduce lists using the pairwise helpers.
- If BigInt support is added, keep number-based helpers or add parallel BigInt helpers.
Testing
Test positive inputs, negative inputs, decimals, zeros, gcd of zero and zero, coprime inputs, identical inputs, pairwise LCM, list GCD, list LCM, empty lists, singletons, and overflow-sensitive values.
PR checklist
- npm test passes for gcd-lcm-calculator.
- Return types, edge cases, and numeric limits remain documented.
- Pure math helpers stay browser-local and side-effect free.
- UI labels, metadata, and tests update together for behavior changes.