9557109a17
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
28 lines
652 B
Bash
28 lines
652 B
Bash
#!/usr/bin/env bash
|
|
# Shared helpers for brain scripts
|
|
# Source guard
|
|
[ -n "${__BRAIN_COMMON_LOADED:-}" ] && return 0
|
|
__BRAIN_COMMON_LOADED=1
|
|
|
|
log_info() { printf "[INFO] %s\n" "$*" >&2; }
|
|
log_warn() { printf "[WARN] %s\n" "$*" >&2; }
|
|
log_error() { printf "[ERROR] %s\n" "$*" >&2; }
|
|
|
|
require_cmd() {
|
|
local cmd="$1"
|
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
log_error "Required command not found: $cmd"
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
make_backup_dir() {
|
|
local target="$1"
|
|
local ts
|
|
ts=$(date +%Y%m%d-%H%M%S)
|
|
local backup="${target%/}/.brain-backup-${ts}"
|
|
mkdir -p "$backup"
|
|
printf "%s" "$backup"
|
|
}
|