#!/bin/sh
npx --no -- commitlint --edit $1

# Append codegraph impact summary if available
IMPACT=$(codegraph diff-impact --staged --json -T 2>/dev/null || node src/cli.js diff-impact --staged --json -T 2>/dev/null || true)
if [ -n "$IMPACT" ]; then
  SUMMARY=$(echo "$IMPACT" | node -e "
    let d=''; process.stdin.on('data',c=>d+=c);
    process.stdin.on('end',()=>{
      try {
        const j=JSON.parse(d);
        if(j.summary && j.summary.functionsChanged > 0)
          console.log('Impact: '+j.summary.functionsChanged+' functions changed, '+(j.summary.totalAffected||j.summary.callersAffected||0)+' affected');
      } catch {}
    });
  " 2>/dev/null || true)
  if [ -n "$SUMMARY" ]; then
    echo "" >> "$1"
    echo "$SUMMARY" >> "$1"
  fi
fi
