#!/bin/bash # ============================================================================= # SCRIPT: validate-propagation.sh # PROPOSITO: Validar que la propagacion de documentacion esta completa # SISTEMA: SIMCO + CAPVED # VERSION: 1.0.0 # ============================================================================= set -e WORKSPACE_ROOT="${HOME}/workspace" RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo "==============================================" echo " VALIDACION DE PROPAGACION SIMCO" echo "==============================================" echo "" ERRORS=0 WARNINGS=0 # ----------------------------------------------------------------------------- # Funcion: Verificar que archivo existe # ----------------------------------------------------------------------------- check_file_exists() { local file="$1" local description="$2" if [ -f "$file" ]; then echo -e "${GREEN}[OK]${NC} $description" return 0 else echo -e "${RED}[FAIL]${NC} $description - Archivo no existe: $file" ((ERRORS++)) return 1 fi } # ----------------------------------------------------------------------------- # Funcion: Verificar que directorio existe # ----------------------------------------------------------------------------- check_dir_exists() { local dir="$1" local description="$2" if [ -d "$dir" ]; then echo -e "${GREEN}[OK]${NC} $description" return 0 else echo -e "${RED}[FAIL]${NC} $description - Directorio no existe: $dir" ((ERRORS++)) return 1 fi } # ----------------------------------------------------------------------------- # Funcion: Verificar WORKSPACE-STATUS.md actualizado # ----------------------------------------------------------------------------- check_workspace_status() { local status_file="${WORKSPACE_ROOT}/orchestration/WORKSPACE-STATUS.md" echo "" echo "--- Verificando WORKSPACE-STATUS.md ---" if [ -f "$status_file" ]; then # Verificar que fue actualizado en los ultimos 7 dias local last_modified=$(stat -c %Y "$status_file" 2>/dev/null || stat -f %m "$status_file" 2>/dev/null) local now=$(date +%s) local diff=$((now - last_modified)) local days=$((diff / 86400)) if [ $days -gt 7 ]; then echo -e "${YELLOW}[WARN]${NC} WORKSPACE-STATUS.md no actualizado en $days dias" ((WARNINGS++)) else echo -e "${GREEN}[OK]${NC} WORKSPACE-STATUS.md actualizado (hace $days dias)" fi else echo -e "${RED}[FAIL]${NC} WORKSPACE-STATUS.md no existe" ((ERRORS++)) fi } # ----------------------------------------------------------------------------- # Funcion: Verificar proyecto individual # ----------------------------------------------------------------------------- check_project() { local project_path="$1" local project_name=$(basename "$project_path") echo "" echo "--- Verificando proyecto: $project_name ---" local orch_path="${project_path}/orchestration" # Verificar estructura basica check_dir_exists "${orch_path}" "orchestration/" check_dir_exists "${orch_path}/00-guidelines" "00-guidelines/" check_dir_exists "${orch_path}/inventarios" "inventarios/" check_dir_exists "${orch_path}/estados" "estados/" check_dir_exists "${orch_path}/trazas" "trazas/" # Verificar archivos obligatorios check_file_exists "${orch_path}/00-guidelines/CONTEXTO-PROYECTO.md" "CONTEXTO-PROYECTO.md" check_file_exists "${orch_path}/00-guidelines/HERENCIA-SIMCO.md" "HERENCIA-SIMCO.md" check_file_exists "${orch_path}/PROXIMA-ACCION.md" "PROXIMA-ACCION.md" # Verificar inventarios check_file_exists "${orch_path}/inventarios/MASTER_INVENTORY.yml" "MASTER_INVENTORY.yml" # Verificar registro de subagentes check_file_exists "${orch_path}/estados/REGISTRO-SUBAGENTES.json" "REGISTRO-SUBAGENTES.json" } # ----------------------------------------------------------------------------- # Funcion: Verificar referencias en inventarios no estan rotas # ----------------------------------------------------------------------------- check_inventory_references() { local inventory_file="$1" local base_path="$2" echo "" echo "--- Verificando referencias en: $(basename $inventory_file) ---" if [ ! -f "$inventory_file" ]; then echo -e "${YELLOW}[SKIP]${NC} Archivo no existe" return fi # Extraer rutas de archivos del inventario (simplificado) local refs=$(grep -oE 'file:\s*"?[^"]+\.(ts|sql|tsx|md)"?' "$inventory_file" 2>/dev/null | sed 's/file:\s*"//g' | sed 's/"//g' || true) local broken=0 for ref in $refs; do # Convertir ruta relativa a absoluta si es necesario if [[ ! "$ref" = /* ]]; then ref="${base_path}/${ref}" fi if [ ! -f "$ref" ]; then echo -e "${RED}[BROKEN]${NC} Referencia rota: $ref" ((broken++)) fi done if [ $broken -eq 0 ]; then echo -e "${GREEN}[OK]${NC} Todas las referencias validas" else ((ERRORS += broken)) fi } # ----------------------------------------------------------------------------- # MAIN # ----------------------------------------------------------------------------- # Verificar core echo "" echo "========== CORE ==========" check_dir_exists "${WORKSPACE_ROOT}/core/orchestration" "core/orchestration" check_file_exists "${WORKSPACE_ROOT}/core/orchestration/directivas/simco/_INDEX.md" "SIMCO Index" # Verificar cada proyecto echo "" echo "========== PROYECTOS ==========" for project_dir in ${WORKSPACE_ROOT}/projects/*/; do if [ -d "$project_dir" ]; then check_project "$project_dir" fi done # Verificar WORKSPACE-STATUS check_workspace_status # ----------------------------------------------------------------------------- # RESUMEN # ----------------------------------------------------------------------------- echo "" echo "==============================================" echo " RESUMEN DE VALIDACION" echo "==============================================" echo "" if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then echo -e "${GREEN}RESULTADO: PROPAGACION COMPLETA${NC}" echo "Todos los archivos y referencias estan correctos." exit 0 elif [ $ERRORS -eq 0 ]; then echo -e "${YELLOW}RESULTADO: PROPAGACION CON ADVERTENCIAS${NC}" echo "Advertencias: $WARNINGS" echo "Errores: 0" exit 0 else echo -e "${RED}RESULTADO: PROPAGACION INCOMPLETA${NC}" echo "Errores: $ERRORS" echo "Advertencias: $WARNINGS" echo "" echo "Corrige los errores antes de continuar." exit 1 fi