#!/usr/bin/env bash # Resolve Gatekeep config files for remote-referenceable Action installs. # Prefer optional consumer override dir; else bundled defaults under action_path. # # Expects: GATEKEEP_ROOT, GATEKEEP_ACTION, CONFIG_DIR (may be empty) # Usage: source "$GATEKEEP_ACTION/scripts/lib-config.sh" # cfg=$(gatekeep_config_file models.json) gatekeep_config_file() { local name="$1" local root="${GATEKEEP_ROOT:-.}" local action="${GATEKEEP_ACTION:-.}" local cdir="${CONFIG_DIR:-}" # Optional consumer override (only if config-dir set and file exists) if [[ -n "$cdir" && -f "$root/$cdir/$name" ]]; then printf '%s\n' "$root/$cdir/$name" return 0 fi # Bundled defaults shipped inside the Action (remote uses: / copy-in) if [[ -f "$action/defaults/$name" ]]; then printf '%s\n' "$action/defaults/$name" return 0 fi # Legacy pack layouts (dev / old copy-in) if [[ -f "$action/../config/$name" ]]; then printf '%s\n' "$action/../config/$name" return 0 fi if [[ -f "$action/../defaults/$name" ]]; then printf '%s\n' "$action/../defaults/$name" return 0 fi echo "gatekeep: missing config $name (no consumer override, no Action defaults)" >&2 return 1 } # Prefer providers.yaml, then providers.yml, then legacy providers.json / models.json gatekeep_providers_config() { local f for f in providers.yaml providers.yml providers.json models.json; do if fpath="$(gatekeep_config_file "$f" 2>/dev/null)"; then printf '%s\n' "$fpath" return 0 fi done echo "gatekeep: missing providers.yaml (or legacy providers.json / models.json)" >&2 return 1 }