# AGENTS.md — Coding Guidelines for Agentic Operations This guide covers build/test commands, code style, and core rules for agents working in the Tidyco APQP repository. ## Quick Commands ### Testing ```bash npm test # Run all Jest tests npm test -- path/to/test.test.js # Run a single test file npm test -- --testNamePattern="name" # Run tests matching a pattern npm run check:all # Full validation suite (see below) ``` ### Validation & Checks ```bash npm run check:load-order # Verify script load order in index.html npm run check:syntax # Validate JavaScript syntax npm run check:rls # Audit RLS policies npm run check:subscriptions # Check realtime cleanup npm run check:mobile # Verify mobile breakpoints npm run check:modals # Audit modal state handling npm run check:state # Track global state variables npm run check:coverage # Generate test coverage report ``` ### Linting & Formatting (NPI portal only) ```bash npm run lint:npi # Run ESLint on NPI portal npm run format:npi # Run Prettier on NPI portal ``` ### Documentation (Wiki) ```bash npm run wiki:build-index # Rebuild wiki search index npm run wiki:check # Full wiki validation ``` ## Architecture Snapshot - **Framework**: Vanilla JavaScript SPA (no build pipeline) - **Backend**: Supabase (Auth, Postgres, Realtime) - **Package Manager**: npm - **Testing**: Jest with jsdom environment - **Linting**: ESLint (NPI portal) - **Formatting**: Prettier - **Script Load Order** (critical): `state.js → auth.js → db.js → helpers.js → navigation.js → realtime.js → portals → app.js` ## Hard Rules (Non-Negotiable) 1. **Script Order**: Always preserve exact load order in `index.html`. Verify with `npm run check:load-order`. 2. **No Duplicate `const`**: Never introduce duplicate variable declarations in the same scope. 3. **Global State**: Keep mutable state in `core/js/state.js` with defaults initialized. 4. **HTML Escaping**: Use `esc()` helper for any user data rendered into HTML strings (prevents XSS). 5. **Navigation**: Use `navigate()` function for route changes so realtime cleanup runs. 6. **Auth-Only RLS**: Do NOT filter client queries by `user_id`; rely on Supabase RLS policies. 7. **Documentation**: Keep new plans/docs in `plans/` unless it is a core root doc. 8. **Mobile-First CSS**: Use both breakpoints: - `@media (max-width: 767px)` (mobile) - `@media (min-width: 768px)` (desktop) 9. **Guide Updates**: When adding/changing features on content pages, update the matching entry in `GUIDE_CONTENT` in `utils/js/guide.js`. ## Code Style & Conventions ### Imports & Globals - No module imports (vanilla JS SPA). All dependencies loaded via `