Skip to content

fix(hook): recognise a CRLF blank line when slicing the body - #159

Merged
clickmatos merged 1 commit into
mainfrom
fix/hook-crlf-body-slice
Aug 13, 2026
Merged

fix(hook): recognise a CRLF blank line when slicing the body#159
clickmatos merged 1 commit into
mainfrom
fix/hook-crlf-body-slice

Conversation

@lucastribioliclickbus

@lucastribioliclickbus lucastribioliclickbus commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #144, which merged one commit before this fix reached it.

Root cause

#144 taught the hook's already-attributed guard to read only the body, so it looks at the same slice the engine does (%b, the message minus its first paragraph):

sed '1,/^$/d' "$COMMIT_MSG_FILE" | grep -qiE "..."

/^$/ matches only a truly empty line. On a CRLF message the separator line is \r, so sed finds no separator, deletes through to EOF, and the guard sees no body at all. It then misses an Assisted-by: (or Made-with:) that is already there, and the hook appends a redundant Co-Authored-By.

Direction is benign — a duplicated trailer, never a missing one — but it puts the hook back out of step with the engine, which handles CRLF fine (f35641a in #144 trims the trailing \r from the captured value).

Fix

[[:space:]] covers carriage return, so widening the address closes the gap with no extra process in the pipe and nothing outside POSIX ERE:

sed '1,/^[[:space:]]*$/d' "$COMMIT_MSG_FILE" | grep -qiE "..."

It also tolerates a separator line carrying stray spaces. The grep pattern is byte-for-byte unchanged.

Verification

Guard behaviour across both line endings, driving the real hook with env -u AI_AGENT CLAUDE_CODE=1 sh iris/hooks/prepare_commit_msg.sh <file> "" and comparing the file before/after:

Message Expected Result
CRLF, body has Assisted-by: Claude Code no append no append (was a duplicate)
CRLF, body has Co-Authored-By: Claude Code no append no append
CRLF, body has Co-Authored-By: Claudemir Santos append append
CRLF, single paragraph (no body) append append
LF, body has Assisted-by: Claude Code no append no append
LF, body has Made-with: Cursor no append no append
LF, separator line is spaces only no append no append
LF, single paragraph append append
LF, body has Co-Authored-By: Claudemir Santos append append
LF, body with no trailer append append
LF, indented trailer example append append
scissors line present append above the scissors append above the scissors

Confirmed the bug first by reinstating /^$/ in a copy of the hook: the CRLF case ended with both the original Assisted-by: and an appended Co-Authored-By:.

Also: sh -n clean, pytest tests/ -q 286 passed, python scripts/check_analysis_chain.py OK, and real git commit runs in a scratch repo (-m, and editor with commit.verbose=true) still produce exactly one trailer, inserted above the scissors line.

Note on how this got separated

#144 was merged at 18:10 UTC with head 6fd7d79; this commit was pushed to that branch about an hour later, so it never entered the PR — the branch had already been merged, which is also why no pull_request event fired for the push. Nothing was lost, it just needs its own PR. Everything else from #144 and #145 is on main.

Follow-up worth its own issue

Nothing in tests/ exercises prepare_commit_msg.sh — the suite covers the Python side only. Across #144 the guard changed five times and every change either introduced or exposed a bug (indentation mismatch, _ as a word character, \b outside POSIX ERE, a value glued to the colon, the scissors append, and now CRLF). All six were caught by review, none by a test. A table of message shapes driving the .sh via subprocess, plus an assertion that the shell alternation and _AI_TOOL_PATTERNS carry the same tool list, would cover the lot. Happy to open it if you want it.


This PR fixes the prepare-commit-msg hook so it correctly slices off the subject paragraph when the commit message uses CRLF line endings.

What changed

  • In iris/hooks/prepare_commit_msg.sh, the sed expression that extracts the commit-message body was changed from:
    • sed '1,/^$/d' …
    • to sed '1,/^[[:space:]]*$/d' …
  • A comment was added explaining that the blank-line separator must tolerate whitespace-only lines, including the lone \r left by CRLF line endings.

Functional impact

  • Previously, a CRLF-formatted message had a \r on the blank line between the subject and body, so /^$/ did not match it. The hook then treated the entire message as the subject, discarded it, and failed to see an existing AI tool trailer in the body. As a result, it could wrongly append an AI attribution line to commits that already had one.
  • Now the separator matches any whitespace-only line, so the body is sliced correctly and the hook reliably detects existing Co-Authored-By, Assisted-by, or Made-with trailers regardless of line ending style.

`/^$/` only matches a truly empty line, so on a CRLF message — where the
separator line is `\r` — sed found no separator and deleted the whole file.
The guard then saw no body, missed an `Assisted-by:` already present, and the
hook appended a duplicate `Co-Authored-By`.

`[[:space:]]` covers carriage return, so the address closes the gap with no
extra process in the pipe and nothing outside POSIX. It also tolerates a
separator line carrying stray spaces.

Verified across 12 message shapes in both line endings, including the
single-paragraph cases that must still be appended to, and the scissors path.

Assisted-by: Claude Code <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clickbus-iris Ready Ready Preview Aug 13, 2026 8:59pm

Request Review

@kody-ai

kody-ai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@clickmatos
clickmatos merged commit 5f35934 into main Aug 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants