#!/bin/bash
# [Testament] Agent Guardrails
# Validates build scripts and content integrity.

echo "--- [Testament] Running Guardrails ---"

# 1. Python Syntax
echo "[1/3] Validating Python scripts..."
for f in ; do
  python3 -m py_compile "$f" || { echo "Syntax error in $f"; exit 1; }
done
echo "Python OK."

# 2. Markdown Integrity
echo "[2/3] Checking chapter consistency..."
if [ -d "chapters" ]; then
  CHAPTER_COUNT=0
  if [ "$CHAPTER_COUNT" -lt 1 ]; then
    echo "WARNING: No chapters found in chapters/ directory."
  else
    echo "Found $CHAPTER_COUNT chapters."
  fi
else
  echo "WARNING: chapters/ directory not found."
fi

# 3. Build Artifact Check
echo "[3/3] Running Semantic Linker..."
if [ -f "build/semantic_linker.py" ]; then
  python3 build/semantic_linker.py || { echo "Semantic Linker failed"; exit 1; }
else
  echo "Skipping Semantic Linker (script not found)."
fi

echo "--- Guardrails Passed ---"
