Make the multitenant branch use a clean PLATFORM_*/TENANT_* model, remove active AGENT_NAME runtime usage, collapse hostd ownership into the shared platform, add operator audit surfaces, and add read-only tenant lifecycle commands. --- Build: pass | Tests: pass — 151 passed (14 files)
83 lines
2.5 KiB
Bash
83 lines
2.5 KiB
Bash
#!/usr/bin/env bash
|
|
# common.sh — Shared config for memory scripts
|
|
# Source this: . "$(dirname "$0")/common.sh"
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
|
|
# shellcheck source=scripts/date-format.sh
|
|
. "$PROJECT_DIR/scripts/date-format.sh"
|
|
|
|
# Load .env
|
|
if [ -f "$PROJECT_DIR/.env" ]; then
|
|
set -a
|
|
# shellcheck disable=SC1091
|
|
. "$PROJECT_DIR/.env"
|
|
set +a
|
|
fi
|
|
|
|
# Database connection (uses .pgpass for password)
|
|
# DB_HOST: prefer WARDEN_DB_IP, fall back to AGENT_SUBNET_BASE/.3
|
|
DB_HOST="${WARDEN_DB_IP:-${AGENT_SUBNET_BASE:-${WARDEN_SUBNET_BASE:-10.0.1}}.3}"
|
|
DB_PORT="5432"
|
|
|
|
# DB name and user: prefer explicit env overrides, derive from TENANT_ID otherwise.
|
|
# Normalises TENANT_ID to a valid Postgres identifier (lowercase, non-alnum → _).
|
|
_norm_agent() {
|
|
printf '%s' "${1:-clawdie}" \
|
|
| tr '[:upper:]' '[:lower:]' \
|
|
| tr -cs 'a-z0-9' '_' \
|
|
| sed 's/^_*//;s/_*$//'
|
|
}
|
|
_AGENT_BASE="$(_norm_agent "${TENANT_ID:-clawdie}")"
|
|
[ -z "$_AGENT_BASE" ] && _AGENT_BASE="clawdie"
|
|
DB_NAME="${MEMORY_DB_NAME:-${_AGENT_BASE}_brain}"
|
|
DB_USER="${MEMORY_DB_USER:-${_AGENT_BASE}_brain}"
|
|
unset -f _norm_agent
|
|
unset _AGENT_BASE
|
|
|
|
# Embedding config — reads from .env; local llama-server defaults
|
|
# Override any of these in .env to switch provider / model.
|
|
EMBED_BASE_URL="${EMBED_BASE_URL:-http://localhost:8080/v1}"
|
|
EMBED_API_URL="${EMBED_BASE_URL}/embeddings"
|
|
EMBED_MODEL="${EMBED_MODEL:-bge-m3}"
|
|
EMBED_DIMENSIONS="${EMBED_DIMENSIONS:-1024}"
|
|
EMBED_PROVIDER="${EMBED_PROVIDER:-local}"
|
|
|
|
# Chunk config
|
|
CHUNK_MAX_CHARS=500
|
|
PG_SLOVENIAN_MONTHS="ARRAY['jan','feb','mar','apr','maj','jun','jul','avg','sep','okt','nov','dec']"
|
|
|
|
# psql wrapper — safe, no interpolation in SQL
|
|
pg() {
|
|
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" \
|
|
--no-align --tuples-only --quiet "$@"
|
|
}
|
|
|
|
# psql with headers (for display)
|
|
pg_pretty() {
|
|
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" "$@"
|
|
}
|
|
|
|
# Check dependencies
|
|
require_cmd() {
|
|
command -v "$1" >/dev/null 2>&1 || { echo "Error: $1 not found" >&2; exit 1; }
|
|
}
|
|
|
|
require_cmd psql
|
|
require_cmd curl
|
|
require_cmd python3
|
|
|
|
pg_display_date_expr() {
|
|
local column="${1:-created_at}"
|
|
printf "(to_char(%s, 'DD') || '.' || (%s)[extract(month from %s)::int] || '.' || to_char(%s, 'YYYY'))" \
|
|
"$column" "$PG_SLOVENIAN_MONTHS" "$column" "$column"
|
|
}
|
|
|
|
pg_display_datetime_expr() {
|
|
local column="${1:-created_at}"
|
|
printf "(%s || ' ' || to_char(%s, 'HH24:MI'))" \
|
|
"$(pg_display_date_expr "$column")" "$column"
|
|
}
|