4.2 KiB
Agent Guidelines & Code Standards
Required orientation and documentation maintenance
Before changing code, read docs/README.md and the documents it routes to for the area you are touching. Treat the source code, tests, generated API reference, and migrations as authoritative when a document disagrees with implementation.
Documentation is part of the change, not a follow-up task:
- Update the relevant file in
docs/whenever behavior, architecture, configuration, data ownership, API contracts, operations, safety boundaries, or development workflow changes. - Update
docs/README.mdwhen adding, renaming, or removing a document. - Run
npm run docs:apiafter changingsrc/web/api-catalog.ts; verify withnpm run docs:api:check. - Prefer durable explanations and links to owning source files over copied implementation details, line counts, credentials, production IDs, or other facts likely to drift.
- During final review, explicitly check whether the documentation still describes the code that will be committed.
Do not start, restart, deploy, or otherwise enable live outreach unless the user explicitly authorizes that operational action. A code or documentation request does not imply permission to run the bot. Never expose .env, imported account dumps, cookies, Matrix tokens, dashboard tokens, private media, or database contents.
Refactoring Goal
Refactor code to improve maintainability, testability, and clarity. Break down large components into smaller, single-purpose classes/modules.
Engineering Standards
1. Single Responsibility Principle (SRP)
- Avoid "God Classes" (e.g., massive
Serviceclasses that do everything). - Extract logic into dedicated handlers, managers, or utilities.
- Example: Instead of one
BotServicehandling login, monitoring, and messaging, split intoAuthService,MonitorService, andMessagingService.
2. Design Patterns
- Dependency Injection: Pass dependencies via constructors. This makes swapping implementations (e.g., for testing) easier.
- Factory Pattern: Use factories for creating complex objects (e.g., configuring different AI models).
- Strategy Pattern: Good for interchangeable algorithms (e.g., differentsubreddit selection strategies).
3. TypeScript Best Practices
- Strict Typing: No
any. Define interfaces/types for all data structures (especially API/Reddit responses). - Zod Validation: Use
zod(already in deps) to validate external data (config files, API responses). - Async/Await: properly handle promises. Use
p-queueorp-retryfor rate-limited operations.
4. Testing
- TDD is not required. Agents may implement changes before writing or updating tests.
- Add or update tests when they provide useful coverage for new functionality or bug fixes.
- Tests live in
tests/(mirroringsrc/structure) and run viavitest(npm test). - Prefer behavior-focused tests (inputs → outputs / observable side effects) over tests that pin internal structure.
5. Project Specifics
- Tech Stack: Node.js, TypeScript, Playwright, Express, SQLite, Vitest.
- Directories:
src/services/for business logic.src/web/for Express server and UI.src/browser/for Playwright interactions.tests/for vitest specs, mirroringsrc/layout.
- Logging: Use
winstonfor structured logging. Do not useconsole.login production code.
Workflow for Agents
- Orient: Read
docs/README.md, the relevant topic documents, and the owning code/tests. - Analyze: Before writing code, read the file and understand the context.
- Plan: Identify what needs to change and check if the change violates SRP.
- Implement: Make the scoped change. Create new small files when SRP calls for it.
- Test: Add or update useful tests as appropriate for the change.
- Document: Update the routed documentation for any changed contract or workflow.
- Refactor: Tidy the implementation and tests while preserving behavior.
- Verify: Run the relevant tests, documentation checks, and type checks (
npm run buildortsc --noEmit) in proportion to the change.
When Dokploy access is explicitly requested, use the credentials in the ignored .env file. Do not print, copy, commit, or blindly source that file.