Files
nroxy/CODEX_STATUS.md

194 lines
6.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Codex Status
Этот файл нужен как быстрый вход для следующего запуска Codex.
## Текущее состояние
- Репозиторий уже не на стадии пустых заглушек: `web`, `worker`, `bot`, `cli`, `db`, `domain`, `providers` имеют рабочий runtime-код.
- Архитектурные границы пока соблюдены:
- бизнес-правила живут в `packages/domain`
- persistence и Prisma-транзакции живут в `packages/db`
- transport/integration adapters живут в `packages/providers`
- `apps/*` в основном собирают transport + use cases
## Реализовано
### `packages/domain`
- quota buckets `100/80/60/40/20/0`
- provider-key pool policy:
- round-robin selection
- retry vs stop decision
- cooldown / manual_review / out_of_funds transitions
- configurable manual-review threshold
- generation use cases:
- `createGenerationRequest`
- `markGenerationRequestSucceeded`
- auth helpers:
- email normalization/validation
- password validation
- password hashing/verification
- session token hashing
- password reset token hashing
- telegram pairing helpers:
- code normalization
- code hashing
- expiration check
### `packages/db`
- Prisma schema and migration history for:
- users
- sessions
- password reset tokens
- subscriptions and plans
- invoices
- generation requests / attempts / assets
- usage ledger
- provider keys / status events / proxies
- Telegram pairing / allowlist / audit log
- bootstrap:
- default subscription plan seed
- migrate-time bootstrap entrypoint
- stores:
- `auth-store`
- `account-store`
- `billing-store`
- `generation-store`
- `worker-store`
- `telegram-pairing-store`
- `telegram-bot-store`
### `packages/providers`
- simulated `nano_banana` adapter
- Telegram Bot API transport
- email transport
- payment provider adapter for invoice creation
### `apps/web`
- auth/session endpoints:
- `POST /api/auth/register`
- `POST /api/auth/login`
- `POST /api/auth/password-reset/request`
- `POST /api/auth/password-reset/confirm`
- `POST /api/auth/logout`
- `GET /api/auth/me`
- `GET /api/auth/sessions`
- `DELETE /api/auth/sessions/:id`
- `POST /api/auth/logout-all`
- account and billing endpoints:
- `GET /api/account`
- `GET /api/billing/invoices`
- `POST /api/billing/invoices`
- `POST /api/admin/invoices/:id/mark-paid`
- generation endpoints:
- `POST /api/generations`
- `GET /api/generations/:id`
- uses cookie-based server sessions instead of temporary `x-user-id`
### `apps/worker`
- polls queued generation requests
- claims one request at a time
- builds provider-key attempt order
- persists `GenerationAttempt`
- persists generated assets
- marks request `succeeded` / `failed`
- consumes quota only on success
- updates provider-key state and audit events
- supports proxy-first then direct fallback inside one key attempt
- runs cooldown recovery sweep back to `active`
### `apps/cli`
- real Telegram pairing commands:
- `nproxy pair <code> [--yes]`
- `nproxy pair list`
- `nproxy pair revoke <telegram-user-id> [--yes]`
- `nproxy pair cleanup [--yes]`
- mutating commands require confirmation unless `--yes`
- successful mutations write audit logs
### `apps/bot`
- Telegram long polling
- allowlist check
- pending pairing creation for unpaired users
- pairing code issuance
- system audit log on pairing initiation
## Проверено
- `docker build -f infra/docker/web.Dockerfile .` проходит
- `docker build -f infra/docker/worker.Dockerfile .` проходит
- `docker build -f infra/docker/bot.Dockerfile .` проходит
- `docker build -f infra/docker/cli.Dockerfile .` проходит
- `docker build -f infra/docker/migrate.Dockerfile .` проходит
- `docker run --env-file .env.example` ранее успешно стартовал для `web`, `worker`, `bot`
- `prisma migrate deploy` ранее успешно проверялся против временного `postgres:16-alpine`
## Что уже есть как product foundation
- регистрация и логин
- серверные сессии в БД
- password reset backend
- session management backend
- account overview backend
- billing invoice creation backend
- paid invoice -> subscription activation flow
- generation request lifecycle backend
- worker execution flow
- Telegram admin pairing flow
## Что ещё отсутствует
### Auth / account
- email verification
- device metadata / session rotation
- frontend account UI
### Billing
- payment reconciliation worker flow
- invoice expiration / cancel flow
- webhook/provider callback handling
- полноценный billing history / admin payment operations surface
### Generations
- реальный provider HTTP adapter вместо simulated `nano_banana`
- object storage upload/download path
- richer request/result payloads for frontend polling
### Web product
- реальный frontend:
- landing
- dashboard
- billing pages
- chat UI
- admin UI
### Bot / ops
- richer admin commands for allowed Telegram admins
- alerts / notifications
- provider health and billing events in bot output
## Следующие шаги
1. Довести billing lifecycle:
- reconciliation flow
- invoice expiration/cancel
- webhook/provider callback handling
2. Заменить simulated image provider adapter на реальный transport adapter
3. Расширить `web` account/billing/generation API под реальный frontend
4. Добавить frontend surfaces поверх уже существующего backend
5. Расширить `bot` для operational alerts и admin commands
## Ограничения и договорённости
- Не переносить бизнес-правила в `apps/*`.
- Provider-specific HTTP код должен оставаться в `packages/providers`.
- Сохранять разделение `GenerationRequest` и `GenerationAttempt`.
- Деплой остаётся `single VPS + Docker Compose`.
- User-facing quota остаётся approximate buckets only.
## Полезные файлы
- `AGENTS.md`
- `docs/plan/system-plan.md`
- `docs/architecture/system-overview.md`
- `docs/ops/deployment.md`
- `docs/ops/provider-key-pool.md`
- `docs/ops/telegram-pairing.md`
## Ограничение текущей среды Codex
- В текущем runtime нет локальных `node`, `npm`, `pnpm`, `corepack`, `tsc` в PATH.
- Проверка делалась через Docker-based builds.