- Replace hardcoded "klavdija" tmux session names with $AGENT_NAME in glass.sh and run-klavdija.sh - Replace hardcoded 192.168.100.x fallbacks with 10.0.1.x throughout scripts/memory/ and heartbeat.sh defaults - Fix heartbeat PGPASSWORD: use inline `VAR=val cmd` form so psql actually receives the password in the subshell - Fix heartbeat curl hangs: add --max-time to all curl calls - Add run-klavdija.sh and src/transcription.ts (previously untracked) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --- Build: pass | Tests: pass — Tests 431 passed (431)
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 AGENT_NAME otherwise.
|
|
# Normalises AGENT_NAME 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 "${AGENT_NAME:-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"
|
|
}
|