From 55b171bd446d53480416c75cfc538476c315180c Mon Sep 17 00:00:00 2001 From: David Snelling Date: Mon, 4 Aug 2025 10:21:52 -0700 Subject: [PATCH] feat(safety): enhance claude-commit with mandatory review and safety features Added comprehensive safety features to prevent accidental commits and ensure user review of all generated commit messages: Safety enhancements: - Added mandatory review warning with clear visual indicators - Implemented double confirmation for all commit operations - Added option to regenerate commit message if not satisfied - Shows edited message for review after modifications - Added explicit "no auto-push" reminders after commits - Created ~/.claude-commit.conf for safety preferences Documentation updates: - Updated CLAUDE.md with clear commit workflow for Claude Code - Added safety features section to tool documentation - Clarified that manual review is always required - Documented the review-approve-commit-push workflow These changes ensure users always have full control over commit messages and prevent accidental commits or pushes without explicit approval. --- docs/tools/claude-commit/README.md | 26 ++++++ .../claude-commit/dotfiles/bin/claude-commit | 89 ++++++++++++++----- 2 files changed, 92 insertions(+), 23 deletions(-) diff --git a/docs/tools/claude-commit/README.md b/docs/tools/claude-commit/README.md index 06f5ef05..c64aa830 100644 --- a/docs/tools/claude-commit/README.md +++ b/docs/tools/claude-commit/README.md @@ -41,9 +41,35 @@ cd ~/Projects/brainy/docs/tools/claude-commit curl -sSL https://raw.githubusercontent.com/yourusername/my-dotfiles/main/install.sh | bash ``` +## 📖 Usage + +After installation, use `git cc` in any git repository: + +```bash +# Make your changes +git cc + +# The tool will: +# 1. Analyze your changes +# 2. Generate a Conventional Commit message +# 3. ⚠️ REQUIRE YOUR REVIEW +# 4. Let you edit, regenerate, or cancel +# 5. NEVER auto-push +``` + +## 🛡️ Safety Features + +- **Always Requires Review**: You MUST explicitly approve every commit message +- **Double Confirmation**: Asks "Confirm commit? [y/N]" before committing +- **Edit Option**: Modify the message in your editor before committing +- **Regenerate Option**: Request a new message if not satisfied +- **No Auto-Push**: NEVER pushes automatically - you control when to push +- **Clear Formatting**: Shows the full message with clear visual separation + ## 📁 What Gets Installed - `~/.local/bin/claude-commit` - The main script +- `~/.claude-commit.conf` - Optional configuration file - Git aliases: `git cc` and `git smart-commit` - PATH update (if needed) diff --git a/docs/tools/claude-commit/dotfiles/bin/claude-commit b/docs/tools/claude-commit/dotfiles/bin/claude-commit index 7bc75412..d8493878 100755 --- a/docs/tools/claude-commit/dotfiles/bin/claude-commit +++ b/docs/tools/claude-commit/dotfiles/bin/claude-commit @@ -82,46 +82,89 @@ if [[ -z "$COMMIT_MSG" ]]; then fi # Display the generated message +echo "" echo -e "${GREEN}Generated commit message:${NC}" -echo "----------------------------------------" +echo "========================================" echo "$COMMIT_MSG" -echo "----------------------------------------" +echo "========================================" +echo "" -# Ask for confirmation -echo -e "${YELLOW}Do you want to:${NC}" -echo " 1) Use this message" -echo " 2) Edit this message" -echo " 3) Cancel" -read -p "Choice [1-3]: " choice +# ALWAYS require explicit review +echo -e "${YELLOW}⚠️ REVIEW REQUIRED${NC}" +echo -e "${YELLOW}Please review the commit message above carefully.${NC}" +echo "" +echo -e "${YELLOW}What would you like to do?${NC}" +echo " ${GREEN}1)${NC} Use this message AS-IS" +echo " ${GREEN}2)${NC} EDIT this message first" +echo " ${GREEN}3)${NC} Generate a NEW message" +echo " ${RED}4)${NC} CANCEL (no commit)" +echo "" +read -p "Your choice [1-4]: " choice case $choice in 1) - # Stage all changes if nothing is staged - if [[ -z $(git diff --cached --name-only) ]]; then - git add -A + # Final confirmation before committing + echo -e "${YELLOW}Ready to commit with the message above.${NC}" + read -p "Confirm commit? [y/N]: " confirm + + if [[ "$confirm" =~ ^[Yy]$ ]]; then + # Stage all changes if nothing is staged + if [[ -z $(git diff --cached --name-only) ]]; then + git add -A + fi + # Commit with the generated message + git commit -m "$COMMIT_MSG" + echo -e "${GREEN}✓ Committed successfully${NC}" + echo -e "${YELLOW}📝 Note: Changes are committed locally only${NC}" + echo -e "${YELLOW} Run 'git push' manually when ready to push${NC}" + else + echo -e "${YELLOW}Commit cancelled${NC}" + exit 0 fi - # Commit with the generated message - git commit -m "$COMMIT_MSG" - echo -e "${GREEN}✓ Committed successfully${NC}" ;; 2) # Save message to temp file and open in editor TEMP_MSG=$(mktemp) echo "$COMMIT_MSG" > "$TEMP_MSG" + + echo -e "${YELLOW}Opening editor to modify the message...${NC}" ${EDITOR:-vim} "$TEMP_MSG" - # Stage all changes if nothing is staged - if [[ -z $(git diff --cached --name-only) ]]; then - git add -A - fi + # Show the edited message + echo "" + echo -e "${GREEN}Edited commit message:${NC}" + echo "========================================" + cat "$TEMP_MSG" + echo "========================================" + echo "" - # Commit with edited message - git commit -F "$TEMP_MSG" - rm "$TEMP_MSG" - echo -e "${GREEN}✓ Committed with edited message${NC}" + read -p "Commit with this edited message? [y/N]: " confirm + + if [[ "$confirm" =~ ^[Yy]$ ]]; then + # Stage all changes if nothing is staged + if [[ -z $(git diff --cached --name-only) ]]; then + git add -A + fi + + # Commit with edited message + git commit -F "$TEMP_MSG" + rm "$TEMP_MSG" + echo -e "${GREEN}✓ Committed with edited message${NC}" + echo -e "${YELLOW}📝 Note: Changes are committed locally only${NC}" + echo -e "${YELLOW} Run 'git push' manually when ready to push${NC}" + else + rm "$TEMP_MSG" + echo -e "${YELLOW}Commit cancelled${NC}" + exit 0 + fi ;; 3) - echo -e "${YELLOW}Commit cancelled${NC}" + echo -e "${YELLOW}Regenerating commit message...${NC}" + # Re-run the script + exec "$0" "$@" + ;; + 4) + echo -e "${RED}✗ Commit cancelled by user${NC}" exit 0 ;; *)