AGENTS.md
Guidance for coding agents working on AlexandrAI Tools XML Formatter in the alexandrai-tools project.
Project overview
This guide covers src/tools/xml-formatter/index.ts. The tool tokenizes XML into special nodes, tags, and text, checks tag balance with a stack, supports minify mode by stripping inter-tag whitespace after validation, and pretty-prints with configurable spaces per indentation level.
Primary source files
- src/tools/xml-formatter/index.ts defines meta, XmlResult, tagName, and formatXml.
- src/tools/xml-formatter/index.test.ts covers indentation, unclosed tags, minify mode, blank input, self-closing tags, comments, mismatches, and CDATA.
- src/tools/xml-formatter/Body.astro owns controls for formatting and minifying.
- src/tools/xml-formatter/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
- Keep empty and whitespace-only XML as a valid no-op.
- Validate tag balance before returning minified output.
- Treat comments, processing instructions, DOCTYPE, and CDATA as atomic nodes.
- Use a stack to detect unexpected closing tags, mismatched tags, and unclosed tags.
- Do not claim full XML schema validation; this is structural formatting and balance checking.
- Do not send XML content to a server.
- When changing tokenizer behavior, add tests for special nodes and malformed tags.
Testing
Test pretty indentation, minify mode, empty input, malformed tags, unexpected closing tags, mismatches, unclosed tags, self-closing tags, comments, CDATA, processing instructions, DOCTYPE, and nested text.
PR checklist
- npm test passes for xml-formatter.
- Formatter errors do not throw into the UI.
- Minify mode still validates tag balance.
- XML content remains browser-local.