# Run harness checks (validate + arch + traceability)
# If arch fails due to module-size/dependency-depth regression only,
# auto-update baselines and re-stage them instead of blocking the commit.
if ! node packages/cli/dist/bin/harness.js ci check --skip entropy,docs,perf,security,deps,phase-gate 2>&1 | tee /tmp/harness-pre-commit.log; then
  if grep -q "REGRESSION" /tmp/harness-pre-commit.log && ! grep -q "complexity.*REGRESSION" /tmp/harness-pre-commit.log; then
    echo "Auto-updating arch baselines for module-size/dependency-depth growth..."
    npx harness check-arch --update-baseline >/dev/null 2>&1
    npx harness check-arch --update-baseline --module packages/cli >/dev/null 2>&1
    git add .harness/arch/baselines.json packages/cli/.harness/arch/baselines.json 2>/dev/null
  else
    exit 1
  fi
fi
npx lint-staged
