|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +## Ground rules (always) |
| 4 | +- Be conservative, explicit, and boring. |
| 5 | +- When unsure, ask; don’t guess. |
| 6 | +- Make minimal, targeted changes; avoid refactors unless requested/necessary. |
| 7 | +- Preserve existing structure, conventions, and tooling. |
| 8 | +- Don’t add dependencies without strong justification. |
| 9 | + |
| 10 | +## TypeScript |
| 11 | +- Write strict, idiomatic TS; follow the repo’s tsconfig and lint rules. |
| 12 | +- No `any` (use `unknown`, generics, or proper types). |
| 13 | +- Prefer `interface` for public shapes; `type` for unions/helpers. |
| 14 | +- Prefer immutability (`readonly`, `ReadonlyArray`) where practical. |
| 15 | +- Narrow with type guards; avoid assertions and `!` except as a last resort. |
| 16 | +- Prefer exhaustive handling (`never` checks) for unions. |
| 17 | +- Treat caught errors as `unknown` and narrow before use. |
| 18 | + |
| 19 | +## Node.js |
| 20 | +- Target the repo’s supported Node LTS (don’t assume versions; check config/docs). |
| 21 | +- Prefer `async/await`; never swallow rejections. |
| 22 | +- Avoid module top-level side effects (I/O, network, reading env, global mutations) unless explicitly intended. |
| 23 | +- Env vars: validate centrally; read at runtime (not import-time); don’t mutate in app code (tests only with scoped setup/teardown). |
| 24 | +- Error handling: rethrow with context; preserve `cause` when available; don’t throw strings. |
| 25 | +- Library code should not log; CLIs may log intentionally with consistent exit codes. |
| 26 | + |
| 27 | +## Testing (Vitest) |
| 28 | +- New logic requires tests unless truly trivial (types-only, re-exports, comments/formatting). |
| 29 | +- Tests must be deterministic and isolated; avoid shared mutable state. |
| 30 | +- Prefer behavioral tests; mock sparingly. |
| 31 | +- No committed `.only`/`.skip` (unless explicitly justified). |
| 32 | +- Bug fixes must include a regression test. |
| 33 | +- Avoid snapshots unless they add clear value and are stable. |
| 34 | + |
| 35 | +## Style, docs, and security |
| 36 | +- Follow existing formatting/lint; keep functions small and readable. |
| 37 | +- Prefer named exports. |
| 38 | +- Update docs/comments when behavior changes (comments explain “why”, not “what”). |
| 39 | +- Never log secrets; validate/sanitize external inputs (paths/URLs/user data). |
| 40 | +- Dependency adds must be justified (need, alternatives, maintenance/license/security impact). |
| 41 | + |
| 42 | +## MUST NOT |
| 43 | +- Change public APIs or introduce breaking changes without explicit instruction. |
| 44 | +- Perform stylistic rewrites or micro-optimizations. |
| 45 | + |
| 46 | +## Verify before committing |
| 47 | +- Typecheck + lint + tests pass. |
| 48 | +- New behavior has coverage (including failure paths); no unintended snapshot changes. |
| 49 | +- No unnecessary diff churn; no accidental top-level side effects; env usage is validated and intentional. |
0 commit comments