feat: scripts para automatizar creacion de robots y notificar developers

Nuevos scripts:
- convert-to-robot.sh: convierte scaffold de agente a robot (config
  minimo, agent.go con nil Rules, sin prompts, command_prefix vacio)
- notify-developer.sh: envia DM a los developers (DEVELOPER_MATRIX_USERS)
  al crear un bot o agente, presentandose con nombre y tipo

Mejorado:
- create-full.sh: acepta --type robot para pipeline completo de robots
  (scaffold → build → register → verify → convert → notify)
- .env.example: añade DEVELOPER_MATRIX_USERS para lista de developers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 20:35:44 +00:00
parent 184d7ca0ae
commit 7edbbad6b3
4 changed files with 316 additions and 19 deletions
+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env bash
# notify-developer.sh — envía DM a los desarrolladores al crear un bot/agente
#
# Uso:
# ./dev-scripts/agent/notify-developer.sh <agent-id> <type> <display-name>
#
# Requisitos en .env:
# DEVELOPER_MATRIX_USERS — lista separada por comas de usernames Matrix
# Ejemplo: DEVELOPER_MATRIX_USERS=egutierrez,admin
# MATRIX_TOKEN_<NORM> — token del bot recién creado
# MATRIX_HOMESERVER, MATRIX_SERVER_NAME
source "$(dirname "$0")/../_common.sh"
load_env
ID="${1:-}"
TYPE="${2:-agent}"
DISPLAYNAME="${3:-$ID}"
NORM="$(normalize_id "$ID")"
[[ -z "$ID" ]] && { warn "notify-developer: se necesita agent-id"; exit 0; }
# ── Obtener token del bot ────────────────────────────────────────────────
TOKEN_VAR="MATRIX_TOKEN_${NORM}"
TOKEN="${!TOKEN_VAR:-}"
if [[ -z "$TOKEN" ]]; then
warn "notify-developer: $TOKEN_VAR no encontrado en .env — saltando notificación"
exit 0
fi
# ── Obtener lista de desarrolladores ─────────────────────────────────────
if [[ -z "${DEVELOPER_MATRIX_USERS:-}" ]]; then
warn "notify-developer: DEVELOPER_MATRIX_USERS no definido en .env — saltando"
exit 0
fi
# ── Construir mensaje ────────────────────────────────────────────────────
if [[ "$TYPE" == "robot" ]]; then
EMOJI="🤖"
TYPE_LABEL="Robot"
COMMANDS_MSG="Mis comandos: help, ping, status, info, version"
else
EMOJI="🧠"
TYPE_LABEL="Agente"
COMMANDS_MSG="Escríbeme directamente o usa !help para ver mis comandos"
fi
MSG="${EMOJI} ¡Hola! Soy **${DISPLAYNAME}** (${TYPE_LABEL}). Acabo de ser creado. ${COMMANDS_MSG}."
# ── Enviar DM a cada desarrollador ───────────────────────────────────────
IFS=',' read -ra DEVS <<< "$DEVELOPER_MATRIX_USERS"
for dev in "${DEVS[@]}"; do
dev="$(echo "$dev" | xargs)" # trim spaces
[[ -z "$dev" ]] && continue
USER_ID="@${dev}:${MATRIX_SERVER_NAME}"
info "Enviando DM de $ID a $USER_ID..."
# Crear DM room (o reutilizar existente)
ROOM_RESP=$(curl -sf -X POST "${MATRIX_HOMESERVER}/_matrix/client/v3/createRoom" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"is_direct\": true,
\"invite\": [\"${USER_ID}\"],
\"preset\": \"trusted_private_chat\"
}" 2>&1) || {
warn " No se pudo crear DM room con $USER_ID"
continue
}
ROOM_ID=$(echo "$ROOM_RESP" | grep -o '"room_id":"[^"]*"' | cut -d'"' -f4)
if [[ -z "$ROOM_ID" ]]; then
warn " Respuesta inesperada al crear room: $ROOM_RESP"
continue
fi
# Enviar mensaje
TXN_ID="notify-$(date +%s%N)"
SEND_RESP=$(curl -sf -X PUT \
"${MATRIX_HOMESERVER}/_matrix/client/v3/rooms/${ROOM_ID}/send/m.room.message/${TXN_ID}" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"msgtype\": \"m.text\",
\"body\": \"${MSG}\"
}" 2>&1) || {
warn " No se pudo enviar mensaje a $USER_ID"
continue
}
ok "DM enviado a $USER_ID"
done