Files
agents_and_robots/dev-scripts/_common.sh
T
egutierrez bd8e1432e5 feat: add assistant bot with LLM integration and configuration
- Implemented the assistant bot with basic command handling and LLM routing.
- Created configuration file for the assistant bot with personality, behavior, and LLM settings.
- Added system prompt for the assistant bot to define its capabilities and limitations.
- Developed registration script for creating Matrix bot users via Synapse admin API.
- Introduced common development scripts for agent management (start, stop, list, logs).
- Scaffolded new agent creation script to streamline the addition of new agents.
- Implemented agent removal script to disable agents without deleting data.
2026-03-03 23:57:13 +00:00

87 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# _common.sh — sourced by all dev-scripts. Do not run directly.
set -euo pipefail
# ── Colores ────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GRN='\033[0;32m'
YLW='\033[0;33m'
BLU='\033[0;34m'
DIM='\033[2m'
RST='\033[0m'
ok() { echo -e "${GRN}${RST} $*"; }
info() { echo -e "${BLU}${RST} $*"; }
warn() { echo -e "${YLW}!${RST} $*"; }
fail() { echo -e "${RED}${RST} $*" >&2; exit 1; }
dim() { echo -e "${DIM}$*${RST}"; }
# ── Repo root ──────────────────────────────────────────────────────────────
# Scripts can be called from any directory; we always operate from repo root.
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"
# ── .env loader ───────────────────────────────────────────────────────────
load_env() {
local env_file="${1:-.env}"
[[ -f "$env_file" ]] || fail ".env not found at $REPO_ROOT/$env_file — copy .env.example and fill it in"
# Export only lines that are KEY=VALUE (skip comments and blanks)
set -o allexport
# shellcheck disable=SC1090
source <(grep -E '^[A-Z_]+=.+' "$env_file")
set +o allexport
}
# ── Go tooling ─────────────────────────────────────────────────────────────
GO=${GO_BIN:-go}
export PATH="$PATH:/usr/local/go/bin"
command -v "$GO" &>/dev/null || fail "go not found — install Go or set GO_BIN"
# ── Process helpers ────────────────────────────────────────────────────────
RUN_DIR="$REPO_ROOT/run"
mkdir -p "$RUN_DIR"
pid_file() { echo "$RUN_DIR/$1.pid"; }
log_file() { echo "$RUN_DIR/$1.log"; }
read_pid() {
local f; f="$(pid_file "$1")"
[[ -f "$f" ]] && cat "$f" || echo 0
}
is_running() {
local pid; pid="$(read_pid "$1")"
[[ "$pid" -gt 0 ]] && kill -0 "$pid" 2>/dev/null
}
agent_status() {
local id="$1" enabled="$2"
if [[ "$enabled" != "true" ]]; then
echo "disabled"
elif is_running "$id"; then
echo "running"
else
echo "stopped"
fi
}
# ── Agent discovery ────────────────────────────────────────────────────────
# Prints: id|version|enabled|description (one line per agent)
list_agents_raw() {
for cfg in agents/*/config.yaml; do
[[ -f "$cfg" ]] || continue
local id version enabled desc
id=$(grep -m1 '^ id:' "$cfg" | awk '{print $2}')
version=$(grep -m1 '^ version:' "$cfg" | awk '{print $2}' | tr -d '"')
enabled=$(grep -m1 '^ enabled:' "$cfg" | awk '{print $2}')
desc=$(grep -m1 '^ description:' "$cfg" | cut -d'"' -f2)
[[ -n "$id" ]] && echo "${id}|${version}|${enabled}|${desc}|${cfg}"
done
}
# ── Usage helper ──────────────────────────────────────────────────────────
need_arg() {
[[ -n "${1:-}" ]] || { echo "Usage: $0 <agent-id>"; exit 1; }
}