feat: import agents_and_robots platform as unibots (Matrix-out, unibus transport)
Reemplaza el scaffold del echobot por la plataforma completa de bots traida desde ~/DataProyects/Github/agents_and_robots tras la operacion Matrix-out: los bots ya no hablan por Matrix sino por el bus unibus (modelo todo-rooms + E2E via shell/transportunibus sobre github.com/enmanuel/unibus/pkg/client). - go.mod: replace de unibus -> ../unibus y de fn-registry -> ../../../.. (paths relativos reajustados a la nueva ubicacion dentro de fn_registry). - app.md: bump a 0.2.0, descripcion + arquitectura + comandos + gotchas reales. - modulo Go conservado como github.com/enmanuel/agents (sin reescribir imports). agents_and_robots queda archivado como museo de la era Matrix.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
# dev-scripts/cron/ — Gestión de automatizaciones cron
|
||||
|
||||
Scripts para crear, listar y aplicar automatizaciones del catálogo `crons/`.
|
||||
|
||||
## Scripts
|
||||
|
||||
### `new.sh` — Scaffolder interactivo
|
||||
|
||||
Crea una nueva automatización en `crons/<nombre>/`:
|
||||
|
||||
```bash
|
||||
./dev-scripts/cron/new.sh
|
||||
```
|
||||
|
||||
Pregunta: nombre, descripción, tipo de acción (`send_message` o `llm_prompt`) y cron expression.
|
||||
Crea `schedule.yaml` y el archivo de prompt/mensaje vacío.
|
||||
Imprime el bloque YAML listo para añadir a `config.yaml`.
|
||||
|
||||
### `list.sh` — Listar automatizaciones
|
||||
|
||||
Lista todas las automatizaciones del catálogo con nombre, tipo, cron y descripción:
|
||||
|
||||
```bash
|
||||
./dev-scripts/cron/list.sh
|
||||
```
|
||||
|
||||
### `apply.sh` — Aplicar a un agente
|
||||
|
||||
Añade una automatización al `config.yaml` de un agente:
|
||||
|
||||
```bash
|
||||
./dev-scripts/cron/apply.sh <nombre> <agent-id>
|
||||
|
||||
# Ejemplo:
|
||||
./dev-scripts/cron/apply.sh good-morning assistant-bot
|
||||
```
|
||||
|
||||
Usa `yq` si está disponible para parchear el YAML directamente.
|
||||
Si `yq` no está instalado, imprime el bloque YAML para copiar a mano.
|
||||
|
||||
Recuerda editar `output_room` en `config.yaml` con la sala real del agente.
|
||||
|
||||
## Catálogo
|
||||
|
||||
Las automatizaciones viven en `crons/`. Ver `crons/README.md` para la documentación completa.
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env bash
|
||||
# apply.sh <name> <agent-id>
|
||||
# Añade la automatización <name> al config.yaml del agente <agent-id>.
|
||||
# Usa yq si está disponible; en caso contrario imprime el bloque YAML para copiar a mano.
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
|
||||
if [[ $# -ne 2 ]]; then
|
||||
echo "Uso: $0 <nombre-automatizacion> <agent-id>" >&2
|
||||
echo "Ejemplo: $0 good-morning assistant-bot" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NAME="$1"
|
||||
AGENT_ID="$2"
|
||||
|
||||
SCHEDULE_FILE="$REPO_ROOT/crons/$NAME/schedule.yaml"
|
||||
AGENT_CONFIG="$REPO_ROOT/agents/$AGENT_ID/config.yaml"
|
||||
|
||||
if [[ ! -f "$SCHEDULE_FILE" ]]; then
|
||||
echo "Error: no existe crons/$NAME/schedule.yaml" >&2
|
||||
echo "Usa ./dev-scripts/cron/list.sh para ver las automatizaciones disponibles." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "$AGENT_CONFIG" ]]; then
|
||||
echo "Error: no existe agents/$AGENT_ID/config.yaml" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse schedule.yaml fields
|
||||
kind=""
|
||||
template=""
|
||||
cron_expr=""
|
||||
|
||||
while IFS= read -r line; do
|
||||
case "$line" in
|
||||
" kind:"*) kind="${line#*kind:}"; kind="${kind// /}" ;;
|
||||
" template:"*) template="${line#*template:}"; template="${template# }" ;;
|
||||
default_cron:*) cron_expr="${line#default_cron:}"; cron_expr="${cron_expr# }"; cron_expr="${cron_expr//\"/}" ;;
|
||||
esac
|
||||
done < "$SCHEDULE_FILE"
|
||||
|
||||
if [[ -z "$kind" || -z "$template" || -z "$cron_expr" ]]; then
|
||||
echo "Error: schedule.yaml incompleto (falta kind, template o default_cron)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build YAML block
|
||||
YAML_BLOCK=" - name: $NAME
|
||||
cron: \"$cron_expr\"
|
||||
output_room: \"\" # TODO: reemplaza con la sala real del agente
|
||||
action:
|
||||
kind: $kind
|
||||
template: \"$template\""
|
||||
|
||||
# Try yq first
|
||||
if command -v yq &>/dev/null; then
|
||||
# Check if schedules key already has this entry
|
||||
existing=$(yq ".schedules // [] | .[] | select(.name == \"$NAME\") | .name" "$AGENT_CONFIG" 2>/dev/null || true)
|
||||
if [[ -n "$existing" ]]; then
|
||||
echo "Advertencia: el agente $AGENT_ID ya tiene un schedule llamado '$NAME'. No se añade de nuevo."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Append using yq
|
||||
yq -i ".schedules += [{\"name\": \"$NAME\", \"cron\": \"$cron_expr\", \"output_room\": \"\", \"action\": {\"kind\": \"$kind\", \"template\": \"$template\"}}]" "$AGENT_CONFIG"
|
||||
echo "✓ Añadido schedule '$NAME' a agents/$AGENT_ID/config.yaml"
|
||||
echo "→ Edita output_room en agents/$AGENT_ID/config.yaml para apuntar a la sala correcta."
|
||||
else
|
||||
echo "yq no está disponible. Añade manualmente el siguiente bloque a agents/$AGENT_ID/config.yaml:"
|
||||
echo ""
|
||||
echo "schedules:"
|
||||
echo "$YAML_BLOCK"
|
||||
echo ""
|
||||
echo "→ Edita output_room para apuntar a la sala correcta del agente."
|
||||
fi
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# list.sh — Lista todas las automatizaciones del catálogo crons/ con nombre, tipo y descripción.
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
CRONS_DIR="$REPO_ROOT/crons"
|
||||
|
||||
if [[ ! -d "$CRONS_DIR" ]]; then
|
||||
echo "No se encontró el directorio crons/." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Collect entries: name, kind, default_cron, description
|
||||
entries=()
|
||||
while IFS= read -r -d '' schedule_file; do
|
||||
name=""
|
||||
description=""
|
||||
kind=""
|
||||
cron_expr=""
|
||||
|
||||
while IFS= read -r line; do
|
||||
case "$line" in
|
||||
name:*) name="${line#name:}"; name="${name// /}" ;;
|
||||
description:*) description="${line#description:}"; description="${description# }"; description="${description#\"}"; description="${description%\"}" ;;
|
||||
" kind:"*) kind="${line#*kind:}"; kind="${kind// /}" ;;
|
||||
default_cron:*) cron_expr="${line#default_cron:}"; cron_expr="${cron_expr# }"; cron_expr="${cron_expr//\"/}" ;;
|
||||
esac
|
||||
done < "$schedule_file"
|
||||
|
||||
if [[ -n "$name" ]]; then
|
||||
entries+=("$name|$kind|$cron_expr|$description")
|
||||
fi
|
||||
done < <(find "$CRONS_DIR" -name "schedule.yaml" -print0 | sort -z)
|
||||
|
||||
if [[ ${#entries[@]} -eq 0 ]]; then
|
||||
echo "No hay automatizaciones en crons/."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Print header
|
||||
printf "%-22s %-15s %-15s %s\n" "NOMBRE" "TIPO" "CRON" "DESCRIPCIÓN"
|
||||
printf "%-22s %-15s %-15s %s\n" "------" "----" "----" "-----------"
|
||||
|
||||
for entry in "${entries[@]}"; do
|
||||
IFS='|' read -r name kind cron_expr description <<< "$entry"
|
||||
printf "%-22s %-15s %-15s %s\n" "$name" "$kind" "$cron_expr" "$description"
|
||||
done
|
||||
Executable
+94
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env bash
|
||||
# new.sh — Scaffolder interactivo para automatizaciones cron
|
||||
# Crea crons/<name>/schedule.yaml y el archivo de prompt/mensaje vacío.
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
|
||||
echo "=== Nueva automatización cron ==="
|
||||
echo ""
|
||||
|
||||
# Nombre
|
||||
read -rp "Nombre de la automatización (ej: weekly-report): " NAME
|
||||
NAME="${NAME// /-}"
|
||||
NAME="${NAME,,}" # lowercase
|
||||
if [[ -z "$NAME" ]]; then
|
||||
echo "Error: el nombre no puede estar vacío." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -d "$REPO_ROOT/crons/$NAME" ]]; then
|
||||
echo "Error: ya existe crons/$NAME/" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Descripción
|
||||
read -rp "Descripción breve: " DESCRIPTION
|
||||
if [[ -z "$DESCRIPTION" ]]; then
|
||||
echo "Error: la descripción no puede estar vacía." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Tipo de acción
|
||||
echo ""
|
||||
echo "Tipo de acción:"
|
||||
echo " 1) send_message — envía un mensaje estático o plantilla"
|
||||
echo " 2) llm_prompt — llama al LLM con un prompt y envía la respuesta"
|
||||
read -rp "Selecciona [1/2]: " ACTION_TYPE_NUM
|
||||
case "$ACTION_TYPE_NUM" in
|
||||
1) ACTION_KIND="send_message"; PROMPT_FILE="message.md" ;;
|
||||
2) ACTION_KIND="llm_prompt"; PROMPT_FILE="prompt.md" ;;
|
||||
*)
|
||||
echo "Error: selección inválida. Usa 1 o 2." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Cron expression
|
||||
DEFAULT_CRON="0 9 * * *"
|
||||
read -rp "Cron expression [default: $DEFAULT_CRON]: " CRON_EXPR
|
||||
CRON_EXPR="${CRON_EXPR:-$DEFAULT_CRON}"
|
||||
|
||||
# Crear estructura
|
||||
CRON_DIR="$REPO_ROOT/crons/$NAME"
|
||||
PROMPTS_DIR="$CRON_DIR/prompts"
|
||||
mkdir -p "$PROMPTS_DIR"
|
||||
|
||||
# schedule.yaml
|
||||
cat > "$CRON_DIR/schedule.yaml" <<EOF
|
||||
# Automatización: $NAME
|
||||
name: $NAME
|
||||
description: "$DESCRIPTION"
|
||||
|
||||
# Cron por defecto
|
||||
default_cron: "$CRON_EXPR"
|
||||
|
||||
# Acción
|
||||
action:
|
||||
kind: $ACTION_KIND
|
||||
# Relativo a la raíz del proyecto
|
||||
template: crons/$NAME/prompts/$PROMPT_FILE
|
||||
|
||||
# Sala de salida por defecto (vacío = el agente debe configurar output_room)
|
||||
default_output_room: ""
|
||||
EOF
|
||||
|
||||
# Archivo de prompt/mensaje
|
||||
touch "$PROMPTS_DIR/$PROMPT_FILE"
|
||||
|
||||
echo ""
|
||||
echo "✓ Creado: crons/$NAME/schedule.yaml"
|
||||
echo "✓ Creado: crons/$NAME/prompts/$PROMPT_FILE"
|
||||
echo ""
|
||||
echo "Edita crons/$NAME/prompts/$PROMPT_FILE con el contenido deseado."
|
||||
echo ""
|
||||
echo "Añade esto a agents/<id>/config.yaml:"
|
||||
echo ""
|
||||
echo " schedules:"
|
||||
echo " - name: $NAME"
|
||||
echo " cron: \"$CRON_EXPR\""
|
||||
echo " output_room: \"!TUROOM:matrix-af2f3d.organic-machine.com\""
|
||||
echo " action:"
|
||||
echo " kind: $ACTION_KIND"
|
||||
echo " template: \"crons/$NAME/prompts/$PROMPT_FILE\""
|
||||
echo ""
|
||||
echo "O usa: ./dev-scripts/cron/apply.sh $NAME <agent-id>"
|
||||
Reference in New Issue
Block a user