feat(cli): add commit message normalizer - #236
Open
gregggreg wants to merge 2 commits into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Standardizes commit message format for this repository by adding a dependency-free
internal/commitmsgpackage 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 ofNightshift-Task/Nightshift-Ref/Co-Authored-By. Handles rawCOMMIT_EDITMSGinput: git comment lines and the--verbosediff 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 asfile:line: severity: message (rule).scripts/commit-msg.sh— git hook installed bymake install-hooks, falling back togo runin a fresh clone and printing the spec plus a--no-verifyescape hatch on failure.buildPlanPromptandbuildImplementPromptnow quotecommitmsg.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, inParse/Validate/Normalizeso the CLI, the hook and any future CI check agree. Without this the hook rejectsgit merge --no-ff(leaving the repo mid-merge) and everygit commit --fixup, breakinggit rebase --autosquash.Verified in a scratch repo with the hook installed:
git merge --no-ff,git commit --fixup=HEAD,git rebase -i --autosquashandgit revertall pass, whileFixed the thing.is still rejected with actionable issues.Verification
gofmt -l .clean,go vet ./...,go build ./..., andgo 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-normalizercover overlapping scope with a different design — only one of these should land.🤖 Generated with Claude Code