|
1 | | -# Chat UI Development Instructions |
| 1 | +# AI Agent Guide: Atlas UI 3 |
2 | 2 |
|
3 | | -**ALWAYS follow these instructions first and fallback to additional search and context gathering only if the information in these instructions is incomplete or found to be in error.** |
| 3 | +Concise rules for getting productive fast in this repo. Prefer these over exploration; fall back to code/docs only if something is missing. |
4 | 4 |
|
5 | | -## Working Effectively |
6 | | - |
7 | | -### Prerequisites and Setup |
8 | | -- **CRITICAL**: Install `uv` Python package manager - this project requires `uv`, NOT pip or conda: |
9 | | - ```bash |
10 | | - # Install uv (required) |
11 | | - curl -LsSf https://astral.sh/uv/install.sh | sh |
12 | | - # OR as fallback: pip install uv |
13 | | - uv --version # Verify installation |
14 | | - ``` |
15 | | -- **Node.js 18+** and npm for frontend development |
16 | | -- **Python 3.12+** for backend |
17 | | - |
18 | | -### Initial Environment Setup |
19 | | -```bash |
20 | | -# Create Python virtual environment (takes ~1 second) |
21 | | -uv venv |
22 | | -source .venv/bin/activate # Windows: .venv\Scripts\activate |
23 | | - |
24 | | -# Install Python dependencies (takes ~2-3 minutes) |
25 | | -uv pip install -r requirements.txt |
26 | | - |
27 | | -# Setup environment configuration |
28 | | -cp .env.example .env |
29 | | -# Edit .env and set DEBUG_MODE=true for development |
30 | | - |
31 | | -# Create required directories |
32 | | -mkdir -p logs |
33 | | -``` |
34 | | - |
35 | | -### Build Process |
36 | | -```bash |
37 | | -# Install frontend dependencies (takes ~15 seconds) |
38 | | -cd frontend |
39 | | -npm install |
40 | | - |
41 | | -# Build frontend (takes ~5 seconds) |
42 | | -# CRITICAL: Use npm run build, NOT npm run dev (WebSocket issues) |
43 | | -npm run build |
44 | | - |
45 | | -# Verify build output exists |
46 | | -ls -la dist/ # Should contain index.html and assets/ |
47 | | -``` |
48 | | - |
49 | | -### Running the Application |
50 | | -```bash |
51 | | -# Start backend (Terminal 1) |
52 | | -cd backend |
53 | | -python main.py |
54 | | -# Server starts on http://localhost:8000 |
55 | | -# NEVER use uvicorn --reload (causes problems) |
56 | | - |
57 | | -# Frontend is already built and served by backend |
58 | | -# Open http://localhost:8000 to access application |
59 | | -``` |
60 | | - |
61 | | -## Testing |
62 | | - |
63 | | -### Run All Tests (NEVER CANCEL - takes up to 2 minutes total) |
64 | | -```bash |
65 | | -# Backend tests (takes ~5 seconds) - NEVER CANCEL, set timeout 60+ seconds |
66 | | -./test/run_tests.sh backend |
67 | | - |
68 | | -# Frontend tests (takes ~6 seconds) - NEVER CANCEL, set timeout 60+ seconds |
69 | | -./test/run_tests.sh frontend |
70 | | - |
71 | | -# E2E tests (may fail if auth not configured, takes ~70 seconds) - NEVER CANCEL, set timeout 120+ seconds |
72 | | -./test/run_tests.sh e2e |
| 5 | +## Do this first |
| 6 | +- Use uv (not pip/conda). One-time: install uv. Then: |
| 7 | + ```bash |
| 8 | + uv venv && source .venv/bin/activate |
| 9 | + uv pip install -r requirements.txt |
| 10 | + bash agent_start.sh # builds frontend, starts backend, seeds/mocks |
| 11 | + ``` |
| 12 | +- Manual quick run (alternative): |
| 13 | + ```bash |
| 14 | + (frontend) cd frontend && npm install && npm run build |
| 15 | + (backend) cd backend && python main.py # don’t use uvicorn --reload |
| 16 | + ``` |
73 | 17 |
|
74 | | -# All tests together - NEVER CANCEL, set timeout 180+ seconds |
75 | | -./test/run_tests.sh all |
| 18 | +## Architecture (big picture) |
76 | 19 | ``` |
77 | | - |
78 | | -### Code Quality and Linting |
79 | | -```bash |
80 | | -# Python linting (install ruff first if not available) |
81 | | -source .venv/bin/activate |
82 | | -uv pip install ruff |
83 | | -ruff check backend/ # Takes ~1 second |
84 | | - |
85 | | -# Frontend linting (takes ~1 second) |
86 | | -cd frontend |
87 | | -npm run lint |
| 20 | +backend/ FastAPI app + WebSocket |
| 21 | + main.py → /ws, serves frontend/dist, includes /api/* routes |
| 22 | + infrastructure/app_factory.py → wires LLM (LiteLLM), MCP, RAG, files, config |
| 23 | + application/chat/service.py → ChatService orchestrator and streaming |
| 24 | + modules/mcp_tools/ → FastMCP client, tool/prompt discovery, auth filtering |
| 25 | + modules/config/manager.py → Pydantic configs + layered search |
| 26 | + domain/rag_mcp_service.py → RAG over MCP discovery/search/synthesis |
| 27 | + core/compliance.py → compliance-levels load/validate/allowlist |
| 28 | +frontend/ React 19 + Vite + Tailwind; state via contexts (Chat/WS/Marketplace) |
88 | 29 | ``` |
89 | 30 |
|
90 | | -## Validation Scenarios |
91 | | - |
92 | | -### Manual Application Testing |
93 | | -After making changes, ALWAYS validate by running through these scenarios: |
94 | | - |
95 | | -1. **Basic Application Load**: |
| 31 | +## Configuration & feature flags |
| 32 | +- Layering (in priority): env vars → config/overrides → config/defaults → legacy backend/configfiles*. Env vars APP_CONFIG_OVERRIDES/DEFAULTS control search roots. |
| 33 | +- Files: llmconfig.yml, mcp.json, mcp-rag.json, help-config.json; environment in .env (copy .env.example). |
| 34 | +- Feature flags (AppSettings): FEATURE_TOOLS_ENABLED, FEATURE_RAG_MCP_ENABLED, FEATURE_COMPLIANCE_LEVELS_ENABLED, FEATURE_AGENT_MODE_AVAILABLE. |
| 35 | + |
| 36 | +## MCP + RAG conventions |
| 37 | +- MCP servers live in mcp.json (tools/prompts) and mcp-rag.json (RAG-only inventory). Fields: groups, is_exclusive, transport|type, url|command/cwd, compliance_level. |
| 38 | +- Transport detection order: explicit transport → command (stdio) → URL protocol (http/sse) → type fallback. |
| 39 | +- Tool names exposed to LLM are fully-qualified: server_toolName. “canvas_canvas” is a pseudo-tool always available. |
| 40 | +- RAG over MCP tools expected: rag_discover_resources, rag_get_raw_results, optional rag_get_synthesized_results. RAG resources and servers may include complianceLevel. |
| 41 | + |
| 42 | +## Compliance levels (explicit allowlist) |
| 43 | +- Definitions in config/(overrides|defaults)/compliance-levels.json. core/compliance.py loads, normalizes aliases, and enforces allowed_with. |
| 44 | +- Validated on load for LLM models, MCP servers, and RAG MCP servers. When FEATURE_COMPLIANCE_LEVELS_ENABLED=true: |
| 45 | + - /api/config includes model and server compliance_level |
| 46 | + - domain/rag_mcp_service filters servers and per-resource „complianceLevel“ using ComplianceLevelManager.is_accessible(user, resource) |
| 47 | + |
| 48 | +## Key APIs/contracts |
| 49 | +- WebSocket: /ws. Messages: chat, download_file, reset_session, attach_file. Backend streams token_stream, tool_use, canvas_content, intermediate_update. |
| 50 | +- REST: /api/config (models/tools/prompts/data_sources/rag_servers/features), /api/compliance-levels, /admin/* for configs/logs (admin group required). |
| 51 | + |
| 52 | +## Developer workflows |
| 53 | +- Tests (don’t cancel): |
96 | 54 | ```bash |
97 | | - # Test homepage loads |
98 | | - curl -s http://localhost:8000/ | grep "Chat UI" |
99 | | - |
100 | | - # Test API responds |
101 | | - curl -s http://localhost:8000/api/config | jq .app_name |
| 55 | + ./test/run_tests.sh backend | frontend | e2e | all |
102 | 56 | ``` |
| 57 | +- Lint: uv pip install ruff && ruff check backend/; frontend: npm run lint. |
| 58 | +- Logs: project_root/logs/app.jsonl (override with APP_LOG_DIR). Use /admin/logs/*. |
103 | 59 |
|
104 | | -2. **Chat Interface Testing**: |
105 | | - - Open http://localhost:8000 in browser |
106 | | - - Verify page loads without console errors |
107 | | - - Test sending a simple message: "Hello, how are you?" |
108 | | - - Verify WebSocket connection works (real-time response) |
109 | | - - Test settings panel opens without errors |
110 | | - |
111 | | -3. **MCP Tools Testing** (if enabled): |
112 | | - - Open settings panel |
113 | | - - Verify MCP servers are discovered |
114 | | - - Test a simple tool like calculator: "What's 2+2?" |
115 | | - |
116 | | -## Important Development Notes |
117 | | - |
118 | | -### Critical Restrictions |
119 | | -- **NEVER use `uvicorn --reload`** - it causes development problems |
120 | | -- **NEVER use `npm run dev`** - it has WebSocket connection issues |
121 | | -- **ALWAYS use `npm run build`** for frontend development |
122 | | -- **ALWAYS use `uv`** for Python package management, not pip |
123 | | -- **NEVER CANCEL builds or tests** - they may take time but must complete |
124 | | - |
125 | | -### Key File Locations |
126 | | -- **Backend**: `/backend/` - FastAPI application with WebSocket support |
127 | | -- **Frontend**: `/frontend/` - React + Vite application |
128 | | -- **Build Output**: `/frontend/dist/` - served by backend |
129 | | -- **Configuration**: `.env` file (copy from `.env.example`) |
130 | | -- **Tests**: `/test/` directory with individual test scripts |
131 | | -- **Documentation**: `/docs/` directory |
132 | | - |
133 | | -### Project Architecture |
134 | | -- **Backend**: FastAPI serving both API and static frontend files |
135 | | -- **Frontend**: React 19 with Vite, Tailwind CSS, builds to `dist/` |
136 | | -- **Communication**: WebSocket for real-time chat, REST API for configuration |
137 | | -- **MCP Integration**: Model Context Protocol for extensible tool support |
138 | | -- **Authentication**: Configurable, set `DEBUG_MODE=true` to skip for development |
139 | | - |
140 | | -### Common Issues and Solutions |
141 | | - |
142 | | -1. **"uv not found"**: Install uv package manager (most common issue) |
143 | | -2. **WebSocket connection fails**: Use `npm run build` instead of `npm run dev` |
144 | | -3. **Backend won't start**: Check `.env` file exists and `APP_LOG_DIR` path is valid |
145 | | -4. **Frontend not loading**: Ensure `npm run build` completed successfully |
146 | | -5. **Tests failing**: Ensure all dependencies installed and environment configured |
147 | | - |
148 | | -### Performance Expectations |
149 | | -- **Python venv creation**: ~1 second |
150 | | -- **Python dependencies**: ~2-3 minutes |
151 | | -- **Frontend dependencies**: ~15 seconds |
152 | | -- **Frontend build**: ~5 seconds |
153 | | -- **Backend tests**: ~5 seconds |
154 | | -- **Frontend tests**: ~6 seconds |
155 | | -- **E2E tests**: ~70 seconds (may fail without proper auth config) |
156 | | -- **Python linting**: ~1 second |
157 | | -- **Frontend linting**: ~1 second |
158 | | - |
159 | | -### Container Development |
160 | | -The project supports containerized development: |
161 | | -```bash |
162 | | -# Build test container (may take 5-10 minutes first time) |
163 | | -docker build -f Dockerfile-test -t atlas-ui-3-test . |
164 | | - |
165 | | -# Run tests in container - NEVER CANCEL, set timeout 300+ seconds |
166 | | -docker run --rm atlas-ui-3-test bash /app/test/run_tests.sh all |
167 | | -``` |
168 | | - |
169 | | -**Note**: Docker builds may fail in some environments due to SSL certificate issues with package repositories. If Docker builds fail, use the local development approach instead. |
170 | | - |
171 | | -## Validation Workflow |
| 60 | +## Repo conventions (important) |
| 61 | +- Use uv; do not use npm run dev; do not use uvicorn --reload. |
| 62 | +- File naming: avoid generic names (utils.py, helpers.py). Prefer descriptive names; backend/main.py is the entry-point exception. |
| 63 | +- No emojis in code or docs. Prefer files ≤ ~400 lines when practical. |
| 64 | +- Auth assumption: in prod, reverse proxy injects X-Authenticated-User; dev falls back to test user. |
172 | 65 |
|
173 | | -Before committing changes: |
174 | | -1. **Build**: Ensure both frontend and backend build successfully |
175 | | -2. **Test**: Run test suite - `./test/run_tests.sh all` |
176 | | -3. **Lint**: Run both Python and frontend linting |
177 | | -4. **Manual**: Test key application scenarios in browser |
178 | | -5. **Exercise**: Test specific functionality you modified |
| 66 | +## Extend by example |
| 67 | +- Add a tool server: edit config/overrides/mcp.json (set groups, transport, url/command, compliance_level). Restart or call discovery on startup. |
| 68 | +- Add a RAG provider: edit config/overrides/mcp-rag.json; ensure it exposes rag_* tools; UI consumes /api/config.rag_servers. |
| 69 | +- Change agent loop: set AGENT_LOOP_STRATEGY to react | think-act | act; ChatService uses app_settings.agent_loop_strategy. |
179 | 70 |
|
180 | | -**ALWAYS** set appropriate timeouts for long-running operations and NEVER cancel builds or tests prematurely. |
| 71 | +Common pitfalls: “uv not found” → install uv; frontend not loading → npm run build; missing tools → check MCP transport/URL and server logs; empty lists → check auth groups and compliance filtering. |
0 commit comments