/ scripts / validate-cursor-plan-names.sh
validate-cursor-plan-names.sh
 1  #!/usr/bin/env bash
 2  # Validate that all .cursor/plans/*.plan.md filenames follow the naming convention.
 3  # See .cursor/rules/dotfiles-plan-naming.mdc. Run from repo root.
 4  # On failure, run scripts/rename-cursor-plans.sh to fix.
 5  
 6  set -e
 7  
 8  # Pattern: YYYY-MM-DD_<username>_<plan-slug>.plan.md
 9  # Username: lowercase, dots (e.g. felipe.silveira). Slug: lowercase, hyphens, no spaces.
10  VALID_REGEX='^[0-9]{4}-[0-9]{2}-[0-9]{2}_[a-z0-9.]+_[a-z0-9][a-z0-9.-]*\.plan\.md$'
11  
12  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13  PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
14  PLANS_DIR="${PROJECT_ROOT}/.cursor/plans"
15  
16  cd "${PROJECT_ROOT}"
17  
18  if [ ! -d "${PLANS_DIR}" ]; then
19    exit 0
20  fi
21  
22  invalid=()
23  while IFS= read -r -d '' path; do
24    base="$(basename "$path")"
25    if ! echo "$base" | grep -qE "${VALID_REGEX}"; then
26      invalid+=("$base")
27    fi
28  done < <(find "${PLANS_DIR}" -maxdepth 1 -name '*.plan.md' -print0 2>/dev/null || true)
29  
30  if [ ${#invalid[@]} -gt 0 ]; then
31    echo "cursor-plan-names: the following plan filenames do not match the convention:" >&2
32    printf '  %s\n' "${invalid[@]}" >&2
33    echo "See .cursor/rules/dotfiles-plan-naming.mdc. Run: task plan:rename (or scripts/rename-cursor-plans.sh)" >&2
34    exit 1
35  fi
36  
37  exit 0