AGENTS.md
Guidance for coding agents working on AlexandrAI Tools Regex Tester in the alexandrai-tools project.
Project overview
This guide covers src/tools/regex-tester/index.ts. The tool creates a JavaScript RegExp from user-supplied pattern and flags, returns match text, index, and capture groups, handles invalid patterns as ok false, and avoids infinite loops for global or sticky zero-length matches.
Primary source files
- src/tools/regex-tester/index.ts defines meta, RegexMatch, RegexResult, and testRegex.
- src/tools/regex-tester/index.test.ts covers global matches, indexes, capture groups, invalid patterns, empty patterns, and no-match cases.
- src/tools/regex-tester/Body.astro owns the browser controls and results table.
- src/tools/regex-tester/i18n.ts owns localized help copy.
- src/lib/tools.ts registers metadata for hub and route rendering.
Setup commands
npm install npm test npm run typecheck npm run build npm run dev
Change rules
- Return ok true with no matches for an empty pattern so the UI can remain idle.
- Catch RegExp constructor errors and return ok false instead of throwing.
- For global or sticky regexes, reset lastIndex before matching.
- Increment lastIndex after zero-length matches to prevent infinite loops.
- Return capture groups as strings and normalize missing groups to empty strings.
- Do not evaluate user input as code; only construct RegExp.
- If adding replacement or highlighting, keep pure result generation separate from DOM rendering.
Testing
Test global matches, sticky flags, non-global single match behavior, indexes, capture groups, optional missing groups, invalid flags, invalid pattern syntax, zero-length matches, empty pattern, and no-match behavior.
PR checklist
- npm test passes for regex-tester.
- Zero-length global matches cannot loop forever.
- Invalid input returns structured errors.
- UI rendering escapes match text before display.