{ "version": "v1", "hooks": [ { "name": "Auto-format before git commit", "trigger": "PreToolUse", "matcher": "execute_bash", "action": { "type": "command", "command": "#!/bin/bash\nINPUT=$(cat)\nCOMMAND=$(echo \"$INPUT\" | python3 -c \"import sys,json; print(json.load(sys.stdin).get('tool_input',{}).get('command',''))\" 2>/dev/null)\nif ! echo \"$COMMAND\" | grep -qE 'git\\s+(commit|\\-c .* commit)'; then\n exit 0\nfi\ncd /home/blendux/git/ogit\nOUTPUT=$(opam exec -- dune fmt 2>&1)\nRC=$?\nif [ $RC -eq 0 ]; then\n echo 'Formatting clean — proceeding with commit.'\n exit 0\nfi\n# dune fmt exit 1 means it reformatted files; run again to confirm stable\nOUTPUT2=$(opam exec -- dune fmt 2>&1)\nRC2=$?\nif [ $RC2 -eq 0 ]; then\n CHANGED=$(git diff --name-only)\n if [ -n \"$CHANGED\" ]; then\n git add $CHANGED\n echo \"Reformatted and staged: $CHANGED\"\n fi\n exit 0\nelse\n echo \"dune fmt produced unstable output — blocking commit.\" >&2\n exit 2\nfi", "timeout": 30 } } ] }