docs(agents): require extracting new logic from server.js into lib/
This commit is contained in:
@@ -58,6 +58,17 @@ This document defines how AI agents should work with the WhatIDo codebase. Follo
|
|||||||
- **Validation**: Inline helper functions (`reqInt`, `reqStr`, `optInt`, etc.) — use them
|
- **Validation**: Inline helper functions (`reqInt`, `reqStr`, `optInt`, etc.) — use them
|
||||||
- **Security first**: All uploads validated, path traversal blocked, rate limits on public routes
|
- **Security first**: All uploads validated, path traversal blocked, rate limits on public routes
|
||||||
|
|
||||||
|
### 1a. Модульность: `server.js` не раздувать, код выносить в `lib/`
|
||||||
|
|
||||||
|
`server.js` — монолит, и главная задача — не раздувать его дальше, а постепенно **полностью разобрать на модули в `lib/`**. Правила обязательны при любой работе:
|
||||||
|
|
||||||
|
- **Новую логику/функции в `server.js` не добавлять.** Вся новая бизнес-логика, хелперы, конструкторы, обработчики пишутся в модуль `lib/<домен>.js` (CommonJS, `module.exports`) и подключаются через `require`. В `server.js` остаётся только «шлюз»: роут, валидация (`reqInt`/`reqStr`/…), middleware (`requireAuth` и т.п.), вызов функции из `lib/`, ответ
|
||||||
|
- **Касание существующего кода = повод вынести**: если правишь функцию в `server.js` и она изолируема от роутов — она переезжает в `lib/` в той же задаче
|
||||||
|
- **Куда выносить**: новые модули — всегда в `lib/`. Существующие корневые модули (`storage.js`, `redis.js`, `diff.js`, `backup-restore.js`, `worker.js`) переезжают постепенно отдельными задачами, не в рамках нерелевантных изменений
|
||||||
|
- **Контракт модуля `lib/`**: CommonJS, без глобального state, параметры явные (пул/клиент, зависимости — через параметры или `require` уже существующих корневых модулей), параметризованные SQL-запросы, ошибки — `try/catch` со статусами на стороне роута. Роут в `server.js` не должен содержать бизнес-логику за пределами валидации и вызова модуля
|
||||||
|
- **Стиль и инварианты не меняются**: код-стайл (пункт 1), инварианты `storage.*`/`redis.js`, security checklist — действуют внутри `lib/` так же, как в `server.js`
|
||||||
|
- Исключение — **точечные правки** уже существующего кода в `server.js`, которые не выносятся (напрямую в роуте, критичны для порядка middleware); не выносить их без нужды в задачи, где это не цель
|
||||||
|
|
||||||
### 2. Database
|
### 2. Database
|
||||||
- **Schema**: Defined in `db/init.sql` (runs on first container start)
|
- **Schema**: Defined in `db/init.sql` (runs on first container start)
|
||||||
- **Migrations**: `db/migration.sql` for existing DBs — update both when changing schema
|
- **Migrations**: `db/migration.sql` for existing DBs — update both when changing schema
|
||||||
@@ -599,6 +610,7 @@ guards against.
|
|||||||
- ❌ Expose DB port (5432) outside docker network
|
- ❌ Expose DB port (5432) outside docker network
|
||||||
- ❌ Use `eval`, `Function` constructor, or dynamic code execution
|
- ❌ Use `eval`, `Function` constructor, or dynamic code execution
|
||||||
- ❌ Add comments to code (this file excepted)
|
- ❌ Add comments to code (this file excepted)
|
||||||
|
- ❌ Добавлять новую логику/функции в `server.js` — выносить в `lib/<домен>.js` и подключать `require`'ом (см. 1a)
|
||||||
- ❌ Read/search the repo in the main agent when the work can be delegated to a subagent
|
- ❌ Read/search the repo in the main agent when the work can be delegated to a subagent
|
||||||
- ❌ Load whole files (`server.js`, `worker.js`, `storage.js`, `redis.js`, `public/js/*.js`, `README.md`) or raw command output into the main context — delegate and filter (`grep -n`, `head`, line ranges)
|
- ❌ Load whole files (`server.js`, `worker.js`, `storage.js`, `redis.js`, `public/js/*.js`, `README.md`) or raw command output into the main context — delegate and filter (`grep -n`, `head`, line ranges)
|
||||||
- ❌ Give a subagent an open-ended "explore the whole project" task, or omit the project rules from its `systemPrompt` — it does not inherit the main context
|
- ❌ Give a subagent an open-ended "explore the whole project" task, or omit the project rules from its `systemPrompt` — it does not inherit the main context
|
||||||
|
|||||||
Reference in New Issue
Block a user