AlexandrAI AGENTS.md
agents-md

AlexandrAI Tools Average Calculator Agent Guide

Agent guide for parsing numeric lists and computing mean, median, modes, range, count, and sum.

AGENTS.md

Guidance for coding agents working on AlexandrAI Tools Average Calculator in the alexandrai-tools project.

Project overview

This guide covers src/tools/average-calculator/index.ts. The tool parses comma, whitespace, and newline separated numeric input, drops blank and non-finite tokens, returns a structured error for empty arrays, and computes sorted descriptive statistics including mean, median, all tied modes, range, count, and sum.

Primary source files

  • src/tools/average-calculator/index.ts defines meta, StatsResult, parseNumbers, calcStats, and calcStatsFromString.
  • src/tools/average-calculator/index.test.ts covers comma, space, and newline parsing, skipped non-numeric tokens, blank input, mean, odd and even median, modes, multiple modes, range, sum, count, empty arrays, and mixed delimiters.
  • src/tools/average-calculator/Body.astro owns browser controls.
  • src/tools/average-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

  • Split numeric input on commas and whitespace.
  • Drop blank tokens before Number conversion.
  • Drop non-finite numeric results.
  • Return ok false with an error when no numbers remain.
  • Compute median from a sorted copy without mutating the caller array.
  • Return an empty modes array when every value is unique.
  • Return every value tied for max frequency when a mode exists.

Testing

Test parsing delimiters, invalid tokens, Infinity and NaN tokens, empty input, negative numbers, decimals, unsorted input, even and odd medians, no mode, one mode, multiple modes, range, sum, count, and calcStatsFromString.

PR checklist

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