AlexandrAI AGENTS.md
agents-md

AlexandrAI Tools Gestational Age Agent Guide

Agent guide for LMP-to-reference gestational weeks, days, total days, and trimester classification.

AGENTS.md

Guidance for coding agents working on AlexandrAI Tools Gestational Age in the alexandrai-tools project.

Project overview

This guide covers src/tools/gestational-age. calcGestationalAge converts LMP and reference dates to UTC epoch days, rejects malformed date strings, rejects reference dates before LMP, calculates elapsed total days, derives completed weeks and remaining days, and maps completed weeks to trimester 1, 2, or 3.

Primary source files

  • src/tools/gestational-age/index.ts defines meta, GestationalAgeResult, isoToEpochDay, trimesterFor, and calcGestationalAge.
  • src/tools/gestational-age/index.test.ts covers zero days, exact weeks, 10 weeks 3 days, trimester thresholds, month boundary, invalid LMP, and as-of before LMP.
  • src/tools/gestational-age/Body.astro owns LMP/reference inputs and result display.
  • src/tools/gestational-age/i18n.ts owns localized labels and health-scope copy.
  • 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

  • Convert date strings to UTC epoch days before subtracting.
  • Return an invalid LMP error when LMP cannot be parsed.
  • Return an invalid reference-date error when reference date cannot be parsed.
  • Reject reference dates earlier than LMP.
  • Calculate weeks as floor of total days divided by seven.
  • Calculate days as total days modulo seven.
  • Use trimester 1 below week 13, trimester 2 below week 27, and trimester 3 from week 27 onward.

Testing

Test same-day output, exact week boundaries, week-plus-day output, trimester threshold edges, month and year boundaries, invalid strings, as-of before LMP, and health disclaimer copy.

PR checklist

  • npm test passes for gestational-age.
  • Date, random, or hash behavior is documented exactly as implemented.
  • Health outputs remain framed as estimates, not medical decisions.
  • UI labels, validation, and pure helper tests stay aligned.