Skip to content

feat(cli): add commit message normalizer - #236

Open
gregggreg wants to merge 2 commits into
marcus:mainfrom
gregggreg:commit-normalize-normalizer-v2
Open

feat(cli): add commit message normalizer#236
gregggreg wants to merge 2 commits into
marcus:mainfrom
gregggreg:commit-normalize-normalizer-v2

Conversation

@gregggreg

Copy link
Copy Markdown

Summary

Standardizes commit message format for this repository by adding a dependency-free internal/commitmsg package and wiring one canonical spec into everything that describes or enforces the format.

Scope assumption: this enforces a standard format going forward. It does not rewrite historical commits — history rewriting is destructive and out of scope.

What's here

  • internal/commitmsg — stdlib-only parse / validate / normalize for Conventional-Commits-style messages: type(scope)!: subject, 72-char header cap, imperative-mood heuristic, blank line before body, body wrapped at 72 columns (code blocks, indented text, lists and URLs left alone), and a single trailing trailer block with hoisting and dedup of Nightshift-Task / Nightshift-Ref / Co-Authored-By. Handles raw COMMIT_EDITMSG input: git comment lines and the --verbose diff are stripped.
  • spec.go — one canonical human-readable spec string. --print-spec, the hook's failure output, the README, the CLI reference and the orchestrator's agent prompts all quote it, so they cannot drift apart.
  • nightshift commit-msg--check / --fix / --print-spec / --quiet, reading a file or stdin, reporting issues as file:line: severity: message (rule).
  • scripts/commit-msg.sh — git hook installed by make install-hooks, falling back to go run in a fresh clone and printing the spec plus a --no-verify escape hatch on failure.
  • Orchestrator promptsbuildPlanPrompt and buildImplementPrompt now quote commitmsg.PromptSpec(task.Type) instead of hardcoded trailer blurbs, so autonomous agents are told exactly what the hook enforces.

Git-generated messages are exempt

Headers git writes itself — Merge , Revert ", fixup! , squash! , amend! — bypass validation entirely, in Parse/Validate/Normalize so the CLI, the hook and any future CI check agree. Without this the hook rejects git merge --no-ff (leaving the repo mid-merge) and every git commit --fixup, breaking git rebase --autosquash.

Verified in a scratch repo with the hook installed: git merge --no-ff, git commit --fixup=HEAD, git rebase -i --autosquash and git revert all pass, while Fixed the thing. is still rejected with actionable issues.

Verification

gofmt -l . clean, go vet ./..., go build ./..., and go test ./... all pass. 118 tests across the two new packages, written against the format rather than the implementation.

Note for the reviewer

Draft PR #186 and branch chore/commit-message-normalizer cover overlapping scope with a different design — only one of these should land.

🤖 Generated with Claude Code

Add an internal/commitmsg package that parses, validates and normalizes
commit messages against one Conventional Commits format, and expose it
three ways from a single canonical spec: a nightshift commit-msg
subcommand, a commit-msg git hook installed by make install-hooks, and
the orchestrator's plan and implement prompts.

Scope note: this makes the repository enforce one format going forward.
Rewriting historical commits is destructive and deliberately out of
scope.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
Git writes merge, revert and fixup!/squash!/amend! headers itself, and
the user cannot choose their format. Validating them made the installed
commit-msg hook reject `git merge --no-ff` (leaving the repo mid-merge)
and every `git commit --fixup`, which in turn broke
`git rebase --autosquash`.

Parse now flags those headers as GitGenerated, and Validate and
Normalize pass them straight through, so the CLI, the hook and any
future CI check all agree. The exemption is documented in the canonical
spec, so --print-spec, the hook's failure output, the README, the CLI
reference and the agent prompts all describe it too.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
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.

1 participant