loop: ensure proper blank line before git commit trailers

The prepare-commit-msg hook was incorrectly adding only a single newline
before trailers in some cases, resulting in missing blank lines between
the commit message body and trailers like Co-Authored-By and Change-ID.

This was particularly noticeable after rebasing where commit messages
would have:
- Subject line
- Single newline (no blank line)
- Trailers

The fix improves the logic to:
- Check if file ends with newline using tail -c 1
- If no trailing newline: add two newlines (complete line + blank line)
- If trailing newline exists: check if last line is empty
- If last line has content: add one newline for blank line
- If last line is empty: add nothing (blank line already exists)

This ensures there's always exactly one blank line before trailers,
following proper git commit message formatting conventions.

Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s796b26b31c71b2e2k
diff --git a/loop/agent.go b/loop/agent.go
index 0a4555b..f9450ab 100644
--- a/loop/agent.go
+++ b/loop/agent.go
@@ -2055,9 +2055,24 @@
 
 # Only modify if at least one trailer needs to be added
 if [ "$needs_co_author" = true ] || [ "$needs_change_id" = true ]; then
-  # Ensure there's a blank line before trailers
-  if [ -s "$commit_file" ] && [ "$(tail -1 "$commit_file" | tr -d '\n')" != "" ]; then
-    echo "" >> "$commit_file"
+  # Ensure there's a proper blank line before trailers
+  if [ -s "$commit_file" ]; then
+    # Check if file ends with newline by reading last character
+    last_char=$(tail -c 1 "$commit_file")
+
+    if [ "$last_char" != "" ]; then
+      # File doesn't end with newline - add two newlines (complete line + blank line)
+      echo "" >> "$commit_file"
+      echo "" >> "$commit_file"
+    else
+      # File ends with newline - check if we already have a blank line
+      last_line=$(tail -1 "$commit_file")
+      if [ -n "$last_line" ]; then
+        # Last line has content - add one newline for blank line
+        echo "" >> "$commit_file"
+      fi
+      # If last line is empty, we already have a blank line - don't add anything
+    fi
   fi
 
   # Add trailers if needed