workspace-v1/01-fase-control-plane/PROMPTS/PROMPT-DEVOPS-AGENT.md
Adrian Flores Cortes 967ab360bb Initial commit: Workspace v1 with 3-layer architecture
Structure:
- control-plane/: Registries, SIMCO directives, CI/CD templates
- projects/: Gamilit, ERP-Suite, Trading-Platform, Betting-Analytics
- shared/: Libs catalog, knowledge-base

Key features:
- Centralized port, domain, database, and service registries
- 23 SIMCO directives + 6 fundamental principles
- NEXUS agent profiles with delegation rules
- Validation scripts for workspace integrity
- Dockerfiles for all services
- Path aliases for quick reference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 00:35:19 -06:00

11 KiB

PROMPT: DEVOPS-AGENT - FASE 1

Fase: 1 - Control Plane Agente: DevOps-Agent Version: 1.0.0


PROMPT DE INICIALIZACION

Seras DevOps-Agent trabajando en la migracion del workspace
para realizar: Crear los registries y scripts de validacion (Fase 1)

## CONTEXTO

El Architecture-Analyst ya creo la estructura base del Control Plane en:
  /home/adrian/Documentos/workspace-v1/control-plane/

Tu tarea es crear los archivos de registry y los scripts de validacion
que garantizaran que no haya conflictos de puertos, dominios o BDs.

## TUS TAREAS ESPECIFICAS

### 1. Crear ports.registry.yml

Ubicacion: control-plane/registries/ports.registry.yml

Proposito: Registro centralizado de todos los puertos usados en el workspace

Estructura requerida:
```yaml
version: "1.0.0"
updated: "2025-12-18"

rules:
  public_ingress_only:
    description: "Solo reverse proxy expone puertos publicos"
    allowed_public_ports: [80, 443]
  internal_ranges:
    backend_api: "3000-3099"
    frontend_web: "3100-3199"
    databases: "5432-5499"
    cache: "6379-6399"

allocations:
  infrastructure:
    traefik:
      public: [80, 443]
      dashboard: { internal: 8080 }
    postgres:
      internal: 5432
    redis:
      internal: 6379

  # Por cada proyecto: nombre, puertos internos, ambientes
  gamilit:
    api:
      internal: 3000
      environment: [dev, prod]
    web:
      internal: 3001
      environment: [dev, prod]

  erp_suite:
    # ... completar

2. Crear domains.registry.yml

Ubicacion: control-plane/registries/domains.registry.yml

Proposito: Registro de dominios/hosts por proyecto y ambiente

3. Crear databases.registry.yml

Ubicacion: control-plane/registries/databases.registry.yml

Proposito: Registro de BDs, roles y permisos

4. Crear services.registry.yml

Ubicacion: control-plane/registries/services.registry.yml

Proposito: Catálogo de servicios con sus metadatos

5. Crear scripts de validacion

Ubicacion: control-plane/devtools/scripts/validation/

Scripts a crear:

  • validate-ports.sh
  • validate-domains.sh
  • validate-databases.sh
  • validate-all.sh

INFORMACION DEL WORKSPACE ACTUAL

Para llenar los registries, consultar:

  1. Puertos actuales:
# Buscar en docker-compose
grep -r "ports:" /home/adrian/Documentos/workspace --include="*.yml" --include="*.yaml"

# Buscar en package.json (scripts de start)
grep -r '"start"' /home/adrian/Documentos/workspace/projects --include="package.json"
  1. Bases de datos:
# Buscar nombres de BD
grep -r "DB_NAME\|DATABASE_URL\|createDatabase" /home/adrian/Documentos/workspace
  1. Proyectos existentes: Ver: /home/adrian/Documentos/workspace/orchestration/referencias/PROYECTOS-ACTIVOS.yml

FORMATO DE SCRIPTS DE VALIDACION

#!/bin/bash
# validate-ports.sh
# Valida puertos contra ports.registry.yml

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REGISTRY="${SCRIPT_DIR}/../../registries/ports.registry.yml"

if [ ! -f "$REGISTRY" ]; then
    echo "ERROR: Registry no encontrado: $REGISTRY"
    exit 1
fi

echo "=== Validando puertos ==="

# Logica de validacion...
# 1. Leer puertos permitidos del registry
# 2. Buscar puertos en archivos compose
# 3. Comparar y reportar conflictos

echo "=== Validacion completada ==="

RESTRICCIONES

  • Los registries deben ser YAML valido
  • Los scripts deben ser ejecutables (chmod +x)
  • NO modificar nada en el workspace actual
  • Usar datos reales extraidos del workspace actual
  • Incluir comentarios explicativos en cada archivo

VALIDACION

# Verificar YAML valido
python3 -c "import yaml; yaml.safe_load(open('ports.registry.yml'))"

# Verificar scripts ejecutables
chmod +x validate-*.sh
./validate-all.sh

ENTREGABLES

  1. ports.registry.yml completo
  2. domains.registry.yml completo
  3. databases.registry.yml completo
  4. services.registry.yml completo
  5. Scripts de validacion funcionales
  6. README.md en registries/ explicando cada archivo

PROTOCOLO

  1. Primero analizar el workspace actual para extraer datos reales
  2. Crear los registries con datos reales
  3. Crear scripts de validacion
  4. Probar scripts
  5. Documentar en IMPLEMENTACION/00-EJECUCION.md

---

## TEMPLATE: ports.registry.yml

```yaml
# ==============================================================================
# PORTS REGISTRY - Control Plane
# ==============================================================================
# Proposito: Registro centralizado de puertos para evitar conflictos
# Mantenido por: DevOps-Agent
# Actualizado: 2025-12-18
# ==============================================================================

version: "1.0.0"
updated: "2025-12-18"

# ------------------------------------------------------------------------------
# REGLAS GLOBALES
# ------------------------------------------------------------------------------
rules:
  public_ingress_only:
    description: "Solo el reverse proxy expone puertos al publico"
    enforcement: "required"
    allowed_public_ports:
      - 80   # HTTP
      - 443  # HTTPS

  internal_ranges:
    description: "Rangos reservados por tipo de servicio"
    backend_api: "3000-3099"
    frontend_web: "3100-3199"
    microservices: "3200-3299"
    databases: "5432-5499"
    cache: "6379-6399"
    monitoring: "9000-9099"

# ------------------------------------------------------------------------------
# ASIGNACIONES - INFRAESTRUCTURA
# ------------------------------------------------------------------------------
infrastructure:
  traefik:
    description: "Reverse proxy principal"
    public:
      - 80
      - 443
    internal:
      dashboard: 8080

  postgres:
    description: "Base de datos PostgreSQL"
    internal: 5432

  redis:
    description: "Cache Redis"
    internal: 6379

  prometheus:
    description: "Metricas"
    internal: 9090

  grafana:
    description: "Dashboards"
    internal: 9091

# ------------------------------------------------------------------------------
# ASIGNACIONES - PROYECTOS
# ------------------------------------------------------------------------------
projects:

  gamilit:
    description: "Plataforma de gamificacion educativa"
    services:
      api:
        internal: 3000
        protocol: "http"
        healthcheck: "/health"
      web:
        internal: 3001
        protocol: "http"
      websocket:
        internal: 3002
        protocol: "ws"

  erp_suite:
    description: "Suite ERP multi-vertical"
    services:
      api:
        internal: 3010
        protocol: "http"
        healthcheck: "/health"
      web:
        internal: 3011
        protocol: "http"

  erp_construccion:
    description: "Vertical construccion"
    services:
      api:
        internal: 3012
        protocol: "http"
      web:
        internal: 3013
        protocol: "http"

  erp_mecanicas:
    description: "Vertical mecanicas diesel"
    services:
      api:
        internal: 3014
        protocol: "http"
      web:
        internal: 3015
        protocol: "http"

  trading:
    description: "Plataforma de trading"
    services:
      api:
        internal: 3020
        protocol: "http"
      web:
        internal: 3021
        protocol: "http"
      ml_engine:
        internal: 3022
        protocol: "http"
      llm_agent:
        internal: 3023
        protocol: "http"

  betting:
    description: "Analytics de apuestas"
    services:
      api:
        internal: 3030
        protocol: "http"
      web:
        internal: 3031
        protocol: "http"

# ------------------------------------------------------------------------------
# VALIDACION
# ------------------------------------------------------------------------------
validation:
  script: "devtools/scripts/validation/validate-ports.sh"
  run_on:
    - "pre-commit"
    - "ci-pipeline"
  fail_on_conflict: true

TEMPLATE: validate-ports.sh

#!/bin/bash
# ==============================================================================
# validate-ports.sh - Validacion de puertos contra registry
# ==============================================================================

set -e

# Colores
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Rutas
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONTROL_PLANE="${SCRIPT_DIR}/../.."
REGISTRY="${CONTROL_PLANE}/registries/ports.registry.yml"

echo -e "${YELLOW}=== Validando puertos contra registry ===${NC}"
echo "Registry: $REGISTRY"

# Verificar que existe el registry
if [ ! -f "$REGISTRY" ]; then
    echo -e "${RED}ERROR: Registry no encontrado${NC}"
    exit 1
fi

# Funcion para extraer puertos del registry
get_allowed_ports() {
    # Usar python para parsear YAML de forma segura
    python3 << EOF
import yaml
import sys

with open('$REGISTRY', 'r') as f:
    data = yaml.safe_load(f)

ports = set()

# Infraestructura
for svc, config in data.get('infrastructure', {}).items():
    if isinstance(config, dict):
        if 'internal' in config:
            ports.add(config['internal'])
        if 'public' in config:
            if isinstance(config['public'], list):
                ports.update(config['public'])
            else:
                ports.add(config['public'])

# Proyectos
for proj, proj_config in data.get('projects', {}).items():
    for svc, svc_config in proj_config.get('services', {}).items():
        if 'internal' in svc_config:
            ports.add(svc_config['internal'])

for p in sorted(ports):
    print(p)
EOF
}

# Funcion para buscar puertos en compose files
find_compose_ports() {
    local search_path="${1:-.}"
    grep -rhoP '(?<=:)\d{4,5}(?=[\s:"])' "$search_path" \
        --include="docker-compose*.yml" \
        --include="compose*.yml" 2>/dev/null | sort -u || true
}

# Obtener puertos permitidos
echo -e "\n${YELLOW}Puertos registrados:${NC}"
ALLOWED=$(get_allowed_ports)
echo "$ALLOWED" | tr '\n' ' '
echo ""

# Buscar puertos en uso
echo -e "\n${YELLOW}Buscando puertos en compose files...${NC}"

ERRORS=0

# Buscar en workspace-v1/repos si existe
if [ -d "${CONTROL_PLANE}/../repos" ]; then
    USED=$(find_compose_ports "${CONTROL_PLANE}/../repos")

    for port in $USED; do
        if ! echo "$ALLOWED" | grep -q "^${port}$"; then
            echo -e "${RED}ERROR: Puerto $port no esta en registry${NC}"
            ERRORS=$((ERRORS + 1))
        fi
    done
fi

# Resultado
echo ""
if [ $ERRORS -eq 0 ]; then
    echo -e "${GREEN}=== Validacion exitosa ===${NC}"
    exit 0
else
    echo -e "${RED}=== Validacion fallida: $ERRORS errores ===${NC}"
    exit 1
fi

NOTAS PARA EL AGENTE

  • Los registries son la fuente de verdad para configuracion
  • Los scripts de validacion DEBEN ejecutarse en CI
  • Priorizar datos reales sobre placeholders
  • Documentar cualquier puerto/BD encontrado que no este listado