Files
scripts/okf-hub/okf-normalize-types.sh

87 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# okf-normalize-types.sh — normaliza type taxonomy para vocabulário canónico OKF
# Uso: okf-normalize-types.sh [--dry-run]
# §5 do OKF-Compliance-Plan-Global.md
set -euo pipefail
HUB_ROOT="/media/ealmeida/Dados/Hub"
DRY_RUN=false
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
# Canonical type mappings (lowercase → Canonical)
declare -A TYPE_MAP=(
["procedimento"]="Playbook"
["procedure"]="Playbook"
["playbook"]="Playbook"
["reference"]="Reference"
["api"]="Reference"
["spec"]="Specification"
["index"]="Index"
["changelog"]="Changelog"
["status"]="Status"
["document"]="Document"
["template"]="Template"
["client profile"]="Client Profile"
["note"]="note"
)
is_excluded() {
local rel="$1"
[[ "$rel" == *99-Arquivo/* ]] && return 0
[[ "$rel" == *.stversions/* ]] && return 0
[[ "$rel" == *.obsidian/* ]] && return 0
[[ "$rel" == *.ijfw/* ]] && return 0
[[ "$rel" == *_templates/* ]] && return 0
[[ "$rel" == *90-Templates/* ]] && return 0
[[ "$rel" == *.git/* ]] && return 0
[[ "$rel" == *node_modules/* ]] && return 0
[[ "$rel" == *.github/* ]] && return 0
[[ "$rel" == *.wayland/* ]] && return 0
[[ "$rel" == *.hermes/* ]] && return 0
local base
base="$(basename "$rel")"
[[ "$base" == "MEMORY.md" ]] && return 0
[[ "$base" == "CLAUDE.md" ]] && return 0
[[ "$base" == "GEMINI.md" ]] && return 0
[[ "$base" == "AGENTS.md" ]] && return 0
return 1
}
CHANGED=0
TOTAL=0
echo "Normalizing type taxonomy in $HUB_ROOT..."
[[ "$DRY_RUN" == "true" ]] && echo "(DRY-RUN mode — no files modified)"
echo ""
while IFS= read -r -d '' f; do
rel="${f#$HUB_ROOT/}"
is_excluded "$rel" && continue
# Get current type
current_type="$(awk 'BEGIN{n=0} /^---[[:space:]]*$/{n++; if(n==2) exit} n==1 && /^type:/{print; exit}' "$f" 2>/dev/null || true)"
[[ -z "$current_type" ]] && continue
# Extract value after "type:"
type_val="$(echo "$current_type" | sed 's/^type: *//' | tr -d '"' | tr -d "'" | xargs)"
# Check if needs normalization
type_lower="$(echo "$type_val" | tr '[:upper:]' '[:lower:]')"
canonical="${TYPE_MAP[$type_lower]:-}"
if [[ -n "$canonical" ]] && [[ "$canonical" != "$type_val" ]]; then
((TOTAL++)) || true
echo " $rel: '$type_val' → '$canonical'"
if [[ "$DRY_RUN" != "true" ]]; then
sed -i "s/^type:.*$/type: $canonical/" "$f"
((CHANGED++)) || true
fi
fi
done < <(find "$HUB_ROOT" -name '*.md' -not -path '*/.git/*' -not -path '*/node_modules/*' -print0)
echo ""
echo "────────────────────────────────────"
echo "To normalize: $TOTAL | Changed: $CHANGED"
[[ "$DRY_RUN" == "true" ]] && echo "(Re-run without --dry-run to apply)"