#!/usr/bin/env bash
# Fails if the combined KB file is stale or was hand-edited.
# Intended for a pre-commit hook or a CI step. Not installed automatically —
# see CLAUDE.md -> "Knowledge Base Maintenance" for how to wire it in.
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"

./scripts/build-kb.sh
if ! git diff --exit-code -- docs/kb/BUSINESS_KNOWLEDGE_BASE.md; then
  echo
  echo "docs/kb/BUSINESS_KNOWLEDGE_BASE.md is out of date or was edited by hand." >&2
  echo "Edit the per-module files under docs/kb/ instead, then run scripts/build-kb.sh." >&2
  exit 1
fi
echo "docs/kb/BUSINESS_KNOWLEDGE_BASE.md is up to date."
