feat: Node Self-Healing, DAGI Audit, Agent Prompts, Infra Invariants

### Backend (city-service)
- Node Registry + Self-Healing API (migration 039)
- Improved get_all_nodes() with robust fallback for node_registry/node_cache
- Agent Prompts Runtime API for DAGI Router integration
- DAGI Router Audit endpoints (phantom/stale detection)
- Node Agents API (Guardian/Steward)
- Node metrics extended (CPU/GPU/RAM/Disk)

### Frontend (apps/web)
- Node Directory with improved error handling
- Node Cabinet with metrics cards
- DAGI Router Card component
- Node Metrics Card component
- useDAGIAudit hook

### Scripts
- check-invariants.py - deploy verification
- node-bootstrap.sh - node self-registration
- node-guardian-loop.py - continuous self-healing
- dagi_agent_audit.py - DAGI audit utility

### Migrations
- 034: Agent prompts seed
- 035: Agent DAGI audit
- 036: Node metrics extended
- 037: Node agents complete
- 038: Agent prompts full coverage
- 039: Node registry self-healing

### Tests
- test_infra_smoke.py
- test_agent_prompts_runtime.py
- test_dagi_router_api.py

### Documentation
- DEPLOY_CHECKLIST_2024_11_30.md
- Multiple TASK_PHASE docs
This commit is contained in:
Apple
2025-11-30 13:52:01 -08:00
parent 0c7836af5a
commit bca81dc719
36 changed files with 10630 additions and 55 deletions

View File

@@ -0,0 +1,244 @@
# 🚀 DEPLOY CHECKLIST — daarion.space
**Дата:** 2024-11-30
**Версія:** MVP Node Self-Healing + DAGI Audit + Agent Prompts
---
## 📋 Що деплоїмо
### Backend (city-service)
- ✅ Node Registry + Self-Healing API
- ✅ Improved `get_all_nodes()` з fallback
- ✅ Agent Prompts Runtime API
- ✅ DAGI Router Audit API
- ✅ Node Agents API (Guardian/Steward)
### Frontend (apps/web)
- ✅ Node Directory з покращеним error handling
- ✅ Node Cabinet з метриками
- ✅ DAGI Router Card
- ✅ Node Metrics Card
### Scripts
-`check-invariants.py` — перевірка інваріантів
-`node-bootstrap.sh` — самореєстрація ноди
-`node-guardian-loop.py` — self-healing loop
### Міграції (НОВІ)
- `034_agent_prompts_seed.sql`
- `035_agent_dagi_audit.sql`
- `036_node_metrics_extended.sql`
- `037_node_agents_complete.sql`
- `038_agent_prompts_full_coverage.sql`
- `039_node_registry_self_healing.sql`
---
## 🔧 КРОК 1: Локально — Закомітити та запушити
```bash
cd /Users/apple/github-projects/microdao-daarion
# Додати всі зміни
git add .
# Закомітити
git commit -m "feat: Node Self-Healing, DAGI Audit, Agent Prompts, Infra Invariants
- Node Registry for self-healing (migration 039)
- Improved get_all_nodes() with robust fallback
- Agent Prompts Runtime API for DAGI Router
- DAGI Router Audit endpoints
- Node metrics and Guardian/Steward APIs
- check-invariants.py for deploy verification
- node-bootstrap.sh for node self-registration
- node-guardian-loop.py for continuous self-healing
- Updated Node Directory UI with better error handling
- Node Cabinet with metrics cards and DAGI Router card"
# Запушити
git push origin main
```
---
## 🖥️ КРОК 2: На сервері NODE1 (Hetzner)
### 2.1. SSH на сервер
```bash
ssh root@<NODE1_IP>
# або через ваш алиас
ssh node1
```
### 2.2. Перейти в директорію проєкту
```bash
cd /opt/daarion
# або ваш шлях до проєкту
```
### 2.3. Оновити код
```bash
git pull origin main
```
### 2.4. Застосувати міграції
```bash
# Підключитися до PostgreSQL
docker exec -it daarion-postgres psql -U daarion_user -d daarion
# Або напряму через psql
PGPASSWORD=<password> psql -h localhost -U daarion_user -d daarion
# Виконати міграції послідовно:
\i migrations/034_agent_prompts_seed.sql
\i migrations/035_agent_dagi_audit.sql
\i migrations/036_node_metrics_extended.sql
\i migrations/037_node_agents_complete.sql
\i migrations/038_agent_prompts_full_coverage.sql
\i migrations/039_node_registry_self_healing.sql
# Вийти
\q
```
### 2.5. Перебілдити і перезапустити сервіси
```bash
# Зупинити сервіси
docker compose -f docker-compose.all.yml down
# Перебілдити
docker compose -f docker-compose.all.yml build
# Запустити
docker compose -f docker-compose.all.yml up -d
```
### 2.6. Перевірити здоров'я
```bash
# Перевірити статус контейнерів
docker ps | grep daarion
# Перевірити логи city-service
docker logs -f daarion-city-service --tail 100
# Перевірити /healthz
curl http://localhost:7001/healthz
# Перевірити /public/nodes
curl http://localhost:7001/public/nodes | jq
```
---
## 🔍 КРОК 3: Перевірка інваріантів
```bash
# На сервері (або локально якщо є доступ)
python3 scripts/check-invariants.py --base-url http://localhost:7001
# Очікуваний результат:
# ✅ ALL INVARIANTS PASSED
# або
# ⚠️ WARNINGS (деякі можуть бути нормальними)
```
---
## 🧪 КРОК 4: Smoke-тести
```bash
# Якщо встановлено pytest
pytest tests/test_infra_smoke.py -v --base-url http://localhost:7001
```
---
## 🌐 КРОК 5: Перевірка в браузері
1. **Node Directory:** https://daarion.space/nodes
- Повинні відображатися NODE1 і NODE2
- Без "Помилка завантаження нод"
2. **Node Cabinet:** https://daarion.space/nodes/node-1-hetzner-gex44
- Метрики CPU/GPU/RAM/Disk
- DAGI Router Card
- Guardian/Steward агенти
3. **Agents:** https://daarion.space/agents
- System Prompts для агентів
---
## 🔄 КРОК 6 (опційно): Node Bootstrap
Якщо ноди не з'являються після міграції:
```bash
# На NODE1
NODE_ID=node-1-hetzner-gex44 \
NODE_NAME="NODE1 — Hetzner GEX44" \
NODE_ENVIRONMENT=production \
NODE_ROLES=production,gpu,ai_runtime,storage,matrix \
./scripts/node-bootstrap.sh
# На NODE2 (якщо потрібно)
NODE_ID=node-2-macbook-m4max \
NODE_NAME="NODE2 — MacBook Pro M4 Max" \
NODE_ENVIRONMENT=development \
NODE_ROLES=development,gpu,ai_runtime,testing \
./scripts/node-bootstrap.sh
```
---
## ❌ Rollback (якщо щось пішло не так)
```bash
# Відкотити код
git reset --hard HEAD~1
git push -f origin main
# На сервері
git pull origin main
docker compose -f docker-compose.all.yml down
docker compose -f docker-compose.all.yml up -d
```
---
## 📊 Очікуваний результат
Після успішного деплою:
| Компонент | URL | Очікуваний статус |
|-----------|-----|-------------------|
| Health | /healthz | `{"status": "ok"}` |
| Nodes | /public/nodes | `{"items": [...], "total": 2}` |
| Node Cabinet | /nodes/{id} | Метрики + DAGI + Agents |
| Invariants | check-invariants.py | ✅ PASSED |
---
## 🆘 Troubleshooting
### "Failed to fetch nodes"
1. Перевірити логи: `docker logs daarion-city-service`
2. Перевірити чи є записи в node_cache: `SELECT * FROM node_cache;`
3. Застосувати міграцію 039
### "node_registry does not exist"
```sql
\i migrations/039_node_registry_self_healing.sql
```
### "Ноди не відображаються"
```bash
# Перевірити node_cache
docker exec -it daarion-postgres psql -U daarion_user -d daarion -c "SELECT node_id, node_name FROM node_cache;"
# Якщо порожньо — запустити bootstrap
./scripts/node-bootstrap.sh
```