#!/usr/bin/env bash set -u RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' NC='\033[0m' ok() { printf "${GREEN}[OK]${NC} %s\n" "$1"; } warn() { printf "${YELLOW}[WARN]${NC} %s\n" "$1"; } fail() { printf "${RED}[FAIL]${NC} %s\n" "$1"; } EXIT_CODE=0 echo "── 1) Verificando estructura base ─────────────────────" required=( "AGENTS.md" "CHECKPOINTS.md" "harness/agents.matrix.yml" "harness/workflow.stages.yml" "harness/policies/governance.md" "harness/policies/security.md" "harness/policies/quality.md" "harness/contracts/handoff.md" "harness/contracts/evidence.schema.json" "harness/model-routing.yml" "spec/product.md" "spec/tech.md" "spec/acceptance.md" "backlog/features.json" "work/current.md" "work/history.md" "work/runtime-status.json" "scripts/install.sh" "scripts/agent_status.py" "scripts/new_ticket.py" "scripts/pi_orquestra.sh" "platforms/pi/README.md" "platforms/pi/extensions/orquestra-status/index.ts" "platforms/pi/extensions/orquestra-web-fetch.ts" ) for f in "${required[@]}"; do if [ -f "$f" ]; then ok "Existe $f" else fail "Falta $f" EXIT_CODE=1 fi done required_dirs=("project") for d in "${required_dirs[@]}"; do if [ -d "$d" ]; then ok "Existe directorio $d" else fail "Falta directorio $d" EXIT_CODE=1 fi done root_product_files=$(find . -mindepth 1 -maxdepth 1 -type f \( \ -name '*.py' -o -name '*.js' -o -name '*.ts' -o -name '*.go' -o -name '*.rs' -o \ -name '*.java' -o -name '*.php' -o -name '*.rb' \ \) -print 2>/dev/null) if [ -n "$root_product_files" ]; then fail "Archivos de producto/código en la raíz no permitidos; usar project/: $root_product_files" EXIT_CODE=1 else ok "Sin archivos de producto/código en la raíz" fi echo "" echo "── 2) Validando requisitos Pi ─────────────────────────" if command -v pi >/dev/null 2>&1; then ok "Pi instalado: $(command -v pi)" else fail "Pi es obligatorio antes de instalar Orquestra" EXIT_CODE=1 fi if [ -d ".pi/subagents" ] || [ -f ".pi/subagents.json" ]; then fail "Orquestra es secuencial: no debe instalar .pi/subagents ni .pi/subagents.json" EXIT_CODE=1 else ok "Sin subagentes project-local" fi if [ -d ".pi/extensions" ]; then extra_extensions=$(find .pi/extensions -mindepth 1 -maxdepth 1 \ ! -name orquestra-status \ ! -name orquestra-web-fetch.ts \ -print 2>/dev/null) if [ -n "$extra_extensions" ]; then fail "Extensiones project-local no declaradas: $extra_extensions" EXIT_CODE=1 else ok "Extensiones project-local declaradas" fi else warn "Sin .pi/extensions; la instalación debe copiar extensiones Orquestra en proyectos" fi echo "" echo "── 3) Validando backlog + runtime ─────────────────────" python3 - <<'PY' import json import pathlib import sys root = pathlib.Path('.') path = root / 'backlog' / 'features.json' try: data = json.loads(path.read_text(encoding='utf-8')) except Exception as e: print(f"[FAIL] backlog/features.json inválido: {e}") sys.exit(1) valid = set(data.get('rules', {}).get('valid_status', ["pending", "in_progress", "blocked", "done"])) features = data.get('features', []) if not isinstance(features, list): print('[FAIL] features debe ser una lista') sys.exit(1) in_progress = [f for f in features if f.get('status') == 'in_progress'] if len(in_progress) > 1: print(f"[FAIL] Hay {len(in_progress)} features in_progress (máximo 1)") sys.exit(1) for f in features: fid = str(f.get('id', '')).strip() status = f.get('status') if status not in valid: print(f"[FAIL] Estado inválido en feature {fid}: {status}") sys.exit(1) if status == 'done': d = root / 'work' / 'artifacts' / fid req = ['reviewer.json', 'security.json', 'qa.json', 'leader-close.json'] missing = [name for name in req if not (d / name).is_file()] if missing: print(f"[FAIL] Feature {fid} done sin artefactos: {', '.join(missing)}") sys.exit(1) expected = { 'reviewer.json': 'reviewer', 'security.json': 'security', 'qa.json': 'qa', 'leader-close.json': 'leader', } for filename, agent in expected.items(): try: obj = json.loads((d / filename).read_text(encoding='utf-8')) except Exception as e: print(f"[FAIL] {fid}/{filename} inválido: {e}") sys.exit(1) if obj.get('agent') != agent: print(f"[FAIL] {fid}/{filename} agent debe ser '{agent}'") sys.exit(1) if obj.get('verdict') != 'APPROVED': print(f"[FAIL] {fid}/{filename} no está APPROVED") sys.exit(1) runtime_path = root / 'work' / 'runtime-status.json' try: runtime = json.loads(runtime_path.read_text(encoding='utf-8')) except Exception as e: print(f"[FAIL] work/runtime-status.json inválido: {e}") sys.exit(1) required_runtime = ['feature_id', 'stage', 'agent', 'action', 'state', 'next_agent', 'waiting_for', 'updated_at', 'timeline'] missing_runtime = [key for key in required_runtime if key not in runtime] if missing_runtime: print(f"[FAIL] work/runtime-status.json incompleto: {', '.join(missing_runtime)}") sys.exit(1) if not isinstance(runtime.get('timeline'), list): print('[FAIL] work/runtime-status.json timeline debe ser una lista') sys.exit(1) print(f"[OK] backlog válido ({len(features)} features)") print('[OK] runtime-status válido') PY if [ $? -ne 0 ]; then EXIT_CODE=1; fi echo "" echo "── 4) Verificación de tests/build (opcional auto-detect) ─" if [ -f "Makefile" ] && grep -qE '^test:' Makefile; then if make test; then ok "make test OK"; else fail "make test falló"; EXIT_CODE=1; fi elif [ -f "package.json" ]; then if command -v npm >/dev/null 2>&1; then if npm test --silent --if-present; then ok "npm test OK"; else fail "npm test falló"; EXIT_CODE=1; fi else warn "package.json detectado pero npm no está disponible" fi elif [ -d "tests" ]; then if command -v pytest >/dev/null 2>&1; then if pytest -q; then ok "pytest OK"; else fail "pytest falló"; EXIT_CODE=1; fi else if python3 -m unittest discover -s tests -v; then ok "unittest OK"; else fail "unittest falló"; EXIT_CODE=1; fi fi else ok "Sin suite de producto detectada; no aplica al harness base" fi echo "" echo "── 5) Resumen ─────────────────────────────────────────" if [ $EXIT_CODE -eq 0 ]; then ok "Orquestra verificado. Puedes trabajar." else fail "Orquestra NO verificado. Corrige antes de continuar." fi exit $EXIT_CODE