#!/usr/bin/env bash # remove.sh — deshabilita un agente (enabled: false). No borra datos. # # Uso: # ./dev-scripts/remove.sh assistant-bot source "$(dirname "$0")/_common.sh" need_arg "${1:-}" TARGET="$1" found=false while IFS='|' read -r id _version _enabled _desc cfg; do [[ "$id" != "$TARGET" ]] && continue found=true # Detener si está corriendo if is_running "$id"; then local_pid="$(read_pid "$id")" info "Deteniendo $id (PID $local_pid)..." kill -TERM "$local_pid" 2>/dev/null || true sleep 1 kill -0 "$local_pid" 2>/dev/null && kill -9 "$local_pid" 2>/dev/null || true rm -f "$(pid_file "$id")" ok "$id detenido" fi # Marcar como disabled en el config (reemplaza solo la primera ocurrencia) if grep -q 'enabled: true' "$cfg"; then # sed compatible con Linux y macOS sed -i 's/enabled: true/enabled: false/' "$cfg" ok "$id marcado como disabled en $cfg" else warn "$id ya estaba marcado como disabled" fi dim " Datos preservados en agents/$id/data/" done < <(list_agents_raw) "$found" || fail "Agente '$TARGET' no encontrado"