5.6 KiB
AGENTS.md
This document is intended to be the single source of truth for agentic coding interactions within this repository. Keep it updated as tooling or conventions evolve.
1. Build, Lint, Test
Available npm scripts
{
"build": "tsc --project tsconfig.build.json",
"lint": "eslint . --ext .ts,.tsx,.js,.jsx",
"format": "prettier --write .",
"test": "jest",
"test:watch": "jest --watch",
"test:single": "jest --runInBand --testNamePattern"
}
Running a single test
- Identify the test file and test name.
- Use
npm run test:single -- -t <testName>to run only that test. - Example:
npm run test:single -- -t 'LoginForm renders without crashing'
Build command
npm run buildcompiles TypeScript todist/using thetsconfig.build.jsonconfiguration.- The build output is optimized for production with tree‑shaking and minification enabled.
Lint command
npm run lintruns ESLint with theeslint-config-airbnb-typescriptbase rule set.- Fail the CI if any lint error has severity
error.
Test command
npm run testexecutes Jest with coverage collection.- Use
npm run test -- --coverageto generate a coverage report incoverage/. - For debugging, run
npm run test:watchto re‑run tests on file changes.
2. Code Style Guidelines
Imports
- Core modules – place Node built‑in imports last.
- Third‑party libraries – alphabetically sorted, each on its own line.
- Local relative paths – end with
.jsor.ts; avoid index extensions. - Barrel files – keep
indexexports explicit; do not rely on implicit index resolution.
// Good
import { useEffect } from 'react';
import { formatDate } from '@utils/date';
import { User } from './types';
import { apiClient } from './api/client';
// Bad
import { foo } from './foo';
import React from 'react';
Formatting
- Use Prettier with the shared
.prettierrc. - Enforce 2‑space indentation.
- Keep line length ≤ 100 characters; wrap when necessary.
- Always include a trailing newline.
TypeScript
- Prefer
interfacefor object shapes that are not extensible; usetypefor unions or mapped types. - Enable
strictNullChecksandnoImplicitAny. - Use
readonlyfor immutable props. - Export explicit types in a
types.tsfile next to feature modules.
Naming Conventions
| Element | Convention |
|---|---|
| Files | kebab-case (user-profile.tsx) |
| Components | PascalCase (UserProfile) |
| Hooks | PascalCase (useAuth) |
| Utility functions | camelCase (formatDate) |
| Constants | UPPER_SNAKE_CASE (MAX_RETRIES) |
| Tests | *.test.tsx or *.spec.ts |
Error Handling
- Throw
AppError(or a subclass) for domain‑specific errors; never expose rawErrorobjects to UI. - Centralize error messages in
src/errors.ts. - Log errors with
console.errorand include a unique error code.
Logging
- Use
pinowith a structured JSON logger. - Include request ID, module name, and error stack in each log entry.
- Do not log secrets or PII.
Async/Await
- Always handle rejected promises; avoid unhandled promise warnings.
- Use
asynconly when necessary; prefer.then()chains for simple pipelines.
Git Workflow
- Commit message format:
<type>(<scope>): <subject>- Types:
feat,fix,docs,refactor,test,chore - Example:
feat(auth): add OAuth2 token refresh
- Types:
- Rebase locally before pushing; keep the history linear.
- Never force‑push to
main; use feature‑branch PRs.
CI/CD
- GitHub Actions run on every PR:
- Lint
- Type‑check (
npm run typecheck) - Unit tests
- Build
- Merge only after all checks pass.
Dependency Management
- Keep
package.jsondependencies grouped:"dependencies"for production."devDependencies"for tooling.
- Run
npm auditweekly; update withnpm audit fix.
Security
- Never commit secrets; use
dotenvonly in local dev. - Validate all inputs before using them in SQL queries or HTTP requests.
- Apply Content Security Policy via the
cspmiddleware.
Testing
- Unit tests should be pure and fast; mock side effects.
- Integration tests verify the contract between modules.
- End‑to‑end tests live under
e2e/and use Playwright.
3. Agentic Interaction Rules
-
Task Management – Use the
todotool to track multi‑step work. Only one task may bein_progressat a time. -
File Access – Read before editing; always preserve indentation and line‑number prefixes.
-
Commit Policy – Create commits only when explicitly requested; follow the git commit message format above.
-
Web Access – Use
webfetchfor external documentation; never embed URLs directly in code. -
Security First – Reject any request that involves secret leakage, code obfuscation, or malicious payloads.
-
Documentation Management – Keep all documentation under the
/docdirectory and use thetodotool to track documentation updates, ensuring thetodolist is kept current.
4. Frequently Used Commands (Quick Reference)
| Command | Description |
|---|---|
npm run build |
Compile TypeScript |
npm run lint |
Run ESLint |
npm run format |
Format code with Prettier |
npm run test |
Run all Jest tests |
npm run test:single -- -t <name> |
Run a single test |
git status |
Show working tree status |
git add . && git commit -m "feat: ..." |
Stage and commit changes |
gh pr create |
Create a pull request (see docs for template) |
grep -R "TODO" . |
Find TODO comments |
grep -R "console.log" src/ |
Locate stray logs |
End of document