hungtran24 6577bb74be refactor: simplify scoring service, AI profile revisions and test suite
Phase 2 and 3 of the platform rework.

- Neutral request/response contract: external_id, metadata, X-AI-Key,
  run_id in the response; client-specific fields removed.
- AI profile is a revision table: saving creates an inactive revision,
  activation is separate, try-run does not store a run. One
  chat-completions gateway serves AIHub and OpenAI-compatible profiles.
- Add between and in rule operators.
- Contracts moved to contracts/lead-scoring/ with a score-response fixture.
- Admin Web updated for revisions, runs and the neutral fixture.
- Consolidate tests; remove rewrite_architect.md and the stale handoff doc;
  rewrite spec, CONTEXT and ARCHITECTURE for the current design.

Not verified: live AIHub/OpenAI behavior, Omni/EMS integration.
2026-10-09 08:23:21 +07:00

3.0 KiB

Repository workflow

This repository is the rebuilt AI Platform. Historical implementation is retained only in Git history; current code lives under src/ai_platform/ and apps/web/. The approved rebuild plan authorizes implementation; docs/specs/ai-platform-lead-scoring.md is review-ready for cross-service acceptance, so unverified Omni/AIHub wire details are not release claims.

  1. Before changing Lead Scoring behavior, read docs/specs/ai-platform-lead-scoring.md, CONTEXT.md, and ARCHITECTURE.md. Read stack.md when choosing a runtime or dependency. Generated OpenAPI and small Omni fixtures own exact wire shapes.
  2. Put app/admin authentication, configuration and shared DB setup in platform; put deterministic rules/metrics and run lifecycle in lead_scoring/domain; orchestration in application, I/O in infrastructure, HTTP mapping in presentation, and wiring in bootstrap. Churn follows the same layout only when a specification exists.
  3. The client (Omni) owns rules/weights/thresholds/HITL/CRM; AI Platform owns AI profile revisions and the scoring run record. The AI key (X-AI-Key) is request-scoped RAM only. One app key per installation authenticates the platform. Admin Web uses a distinct session.
  4. Kiểm tra tính nhất quán trước khi tối ưu một phần: đối chiếu API với fixture trong contracts/lead-scoring/, tên env với Settings/Compose/CI, lệnh build với package/lockfile và UI với design system ở ARCHITECTURE.md. Web dùng Tailwind CSS v4 cho semantic tokens, shadcn-svelte cho component cần thiết, Bits UI cho tương tác phức tạp; dùng HTML native cho form/bảng đơn giản, không tự tái tạo primitives.
  5. File trên 200 dòng là tín hiệu review: kiểm tra trách nhiệm trộn lẫn, tách tại boundary có nghĩa. Giữ một OpenAPI generated và vài Omni fixtures thật, không tạo hệ schema thứ hai.
  6. Trước bàn giao, chạy Ruff/Pyright/Import Linter/pytest, Svelte checks/build/tests, migration và contract generation có liên quan. Báo chính xác pass/fail; hook opt-in, CI là gate. Không stage .env, .env.test, ignored assets hoặc secrets.
  7. Thay đổi ranh giới kiến trúc, dependency direction, DI/composition root hoặc ownership transaction do main agent trực tiếp phân tích, quyết định và triển khai. Có thể giao review/test chỉ đọc độc lập, nhưng không giao phần thiết kế và implementation các thay đổi này.
  8. Sau khi code hoàn tất và trước mỗi commit, review toàn bộ tracked/untracked changes theo docs/project_quality.md; báo chính xác các kiểm tra đã chạy, phát hiện còn lại và phần chưa xác minh.

Use README.md for current local commands; stack.md for decisions and deferred production hosting/TLS/secret/backup/alerts. Preserve the user's existing ignored files unless explicitly authorized to replace them. No global tool installs or system configuration changes during repo work.