AlexandrAI AGENTS.md
agents-md

AlexandrAI Tools Profit Margin Calculator Agent Guide

Agent guide for profit, gross margin percentage, and markup percentage calculations.

AGENTS.md

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

Project overview

This guide covers src/tools/profit-margin-calculator/index.ts. The tool validates finite positive cost and revenue, returns null for invalid inputs, computes profit as revenue minus cost, computes margin percentage against revenue, and computes markup percentage against cost.

Primary source files

  • src/tools/profit-margin-calculator/index.ts defines meta, ProfitResult, and calcProfit.
  • src/tools/profit-margin-calculator/index.test.ts covers positive profit, zero profit, losses, non-positive cost, non-positive revenue, and non-finite inputs.
  • src/tools/profit-margin-calculator/Body.astro owns browser controls.
  • src/tools/profit-margin-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 null for non-finite cost or revenue.
  • Return null when cost is less than or equal to zero.
  • Return null when revenue is less than or equal to zero.
  • Allow cost greater than revenue and produce negative profit.
  • Compute marginPct as profit divided by revenue times one hundred.
  • Compute markupPct as profit divided by cost times one hundred.
  • Keep display rounding outside pure logic.

Testing

Test profit, zero profit, loss, negative margin, negative markup, zero cost, negative cost, zero revenue, non-finite inputs, fractional currency-like values, and UI formatting.

PR checklist

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