#!/usr/bin/env bash # start.sh — inicia uno o todos los agentes habilitados en background # # Uso: # ./dev-scripts/start.sh # inicia todos los habilitados # ./dev-scripts/start.sh assistant-bot # inicia uno específico source "$(dirname "$0")/_common.sh" load_env TARGET="${1:-}" start_agent() { local id="$1" cfg="$2" local log; log="$(log_file "$id")" local pid_f; pid_f="$(pid_file "$id")" info "Iniciando $id..." # Lanza el launcher en background, desacoplado del terminal nohup "$GO" run ./cmd/launcher -c "$cfg" \ >> "$log" 2>&1 & local pid=$! echo "$pid" > "$pid_f" # Espera un momento y verifica que el proceso siga vivo sleep 1 if kill -0 "$pid" 2>/dev/null; then ok "$id PID $pid → logs: $log" else rm -f "$pid_f" fail "$id arrancó pero murió — revisa: tail -f $log" fi } started=0 while IFS='|' read -r id version enabled desc cfg; do # Filtrar por TARGET si se especificó uno [[ -n "$TARGET" && "$id" != "$TARGET" ]] && continue if [[ "$enabled" != "true" ]]; then warn "$id (disabled en config, saltar)" continue fi if is_running "$id"; then warn "$id (ya corriendo, PID $(read_pid "$id"))" continue fi start_agent "$id" "$cfg" ((started++)) || true done < <(list_agents_raw) [[ "$started" -eq 0 && -z "$TARGET" ]] && warn "Ningún agente iniciado." [[ -n "$TARGET" && "$started" -eq 0 ]] && fail "Agente '$TARGET' no encontrado o ya está corriendo." true