AGENTS.md
Guidance for coding agents working on AlexandrAI Tools Prime Number Checker in the alexandrai-tools project.
Project overview
This guide covers src/tools/prime-number-checker/index.ts. The tool rejects non-integers and values less than two for isPrime, checks divisibility through the square root, factorizes by repeated trial division, finds the smallest prime greater than n, and caps analyzePrime input at one hundred billion for browser responsiveness.
Primary source files
- src/tools/prime-number-checker/index.ts defines meta, MAX_PRIME_INPUT, PrimeAnalysisResult, isPrime, factorize, nextPrime, and analyzePrime.
- src/tools/prime-number-checker/index.test.ts covers small primes, composites, non-integers, factors, semiprimes, next primes, safe analysis, and over-limit analysis errors.
- src/tools/prime-number-checker/Body.astro owns browser controls.
- src/tools/prime-number-checker/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 false from isPrime for non-integers and values less than two.
- Special-case two as prime.
- Skip even divisors after checking even numbers.
- Return an empty factor list for values less than two.
- Return the smallest prime strictly greater than n from nextPrime.
- Return ok false from analyzePrime for non-integers and too-large inputs.
- Keep MAX_PRIME_INPUT aligned with UI copy and responsiveness expectations.
Testing
Test small primes, known composites, non-integers, negative values, one and zero, factorization with repetition, semiprimes, nextPrime from prime and composite inputs, analyzePrime output, max boundary, and performance-sensitive large values.
PR checklist
- npm test passes for prime-number-checker.
- 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.