Skip to content

fix(scripts): let smart-commit.sh take a message, body and trailers - #464

Merged
stackbilt-admin merged 4 commits into
mainfrom
fix/issue-459-smart-commit-message
Nov 28, 2026
Merged

stackbilt-admin merged 4 commits into
mainfrom
fix/issue-459-smart-commit-message

Conversation

@stackbilt-admin

@stackbilt-admin stackbilt-admin commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

core.adf (load-bearing) says commits go through scripts/smart-commit.sh only. But the script accepted only --dry-run and --merge, and it generated every subject itself: any package change became feat(<scope>): apply logical updates, with no body or trailers. No agent or maintainer could follow the rule, so every commit bypassed it. This PR makes the rule followable without changing it.

New options (scripts/smart-commit.sh --help)

  • -m <message>, repeatable. Each one becomes a paragraph, as with git commit -m.
  • -F <file> takes the whole message (subject, body and trailers) from a file; -F - reads it from stdin. A message file inside the repo (located with git rev-parse, so path spelling doesn't matter) is never committed, except on --merge, where git add -u would still include a tracked message file you modified.
  • --trailer 'Key: value', repeatable and single-line. Trailers are placed by git interpret-trailers --no-divider: appended to an existing trailer block, or added as a new paragraph, a --- line in the body stays body text, and body lines starting with # (such as #459 caused this) are not treated as comments.

Behaviour

  • With a message, all substantive changes go into one commit with that message.
  • Without one, the grouped default (generated subjects per group) is unchanged.
  • --dry-run prints the message and the files, and commits nothing.
  • --merge uses the message instead of --no-edit.
  • These all exit 2 before anything is staged: bad input, -m together with -F, a trailer with no message, an empty message, a malformed trailer, a missing file, and an unknown argument.
  • The pre-commit hook runs on every path. The script sets core.hooksPath .githooks and checks the hook exists before any commit path, including --merge, which on main could commit without the hook. It never passes --no-verify.
  • If a commit fails (for example the hook refuses), its files are unstaged, so the script can simply be rerun.
  • Paths are listed with core.quotePath=false, so non-ASCII file names are committed rather than skipped as "whitespace-only".

Not changed: the rule in .ai/core.adf. Whether to relax it ("Conventional Commits; the script is available") is the owner's governance call, so this PR leaves it as is.

Verification (local; GitHub Actions isn't running in this repo right now)

  • Dogfooded: both commits on this branch were made with the script itself, using -m, a body and --trailer (see git log). The hook ran each time (tsc plus adf evidence: PASS).
  • New test packages/cli/src/__tests__/smart-commit-script.test.ts (26 cases) runs the real script in a throwaway git repo. Of the cases added after each review, those targeting a fixed bug fail against the previous script (9 after round 1; 3 after round 2). The rest are regression coverage for behaviour that already worked.
    • It covers: custom subject, body and trailers in one commit; -F with trailers merged into the file's trailer block; -F -; a --- body line; an in-repo message file not committed; non-ASCII, space-named, deleted and renamed files; a failing hook blocking the commit, unstaging and allowing a rerun; --merge running the hook with core.hooksPath unset and a failing hook blocking the merge; --dry-run with no commit and a clean index; the grouped default unchanged; # body lines; Refs:#1; -F relative to a subdirectory and from a differently spelled cwd (Windows); a pre-staged index; a failing hook on the grouped path; no --dry-run feat warning; and 8 rejection cases (exit 2, no commit), including a multi-line trailer.
    • A hook marker proves the pre-commit hook ran.
    • On Windows it uses Git's bash, because plain bash can resolve to WSL. It skips if no bash 4+ is found.
    • It uses a 60 s timeout, like the repo's other process-spawning tests.
    • Result: 26/26 pass.
  • pnpm exec tsc --build tsconfig.build.json, pnpm exec tsc --noEmit -p tsconfig.json, and adf evidence --auto-measure --ci all pass.
  • Full suite: the first run hit timeouts, because four other agents' builds and tests were running at the same moment. A serial rerun of the failing files left only the known Windows-only failures (bootstrap bootstrap: phases 6/7 collect warnings without printing them; absoluteAiDirArg misses Windows paths on POSIX #307, context-refresh and serve-context path separators) and one load timeout in adf-vendor-doctor-score. A clean full run is still to come, on a quiet machine.

Closes #459
Part of #437

🤖 Generated with Claude Code

kovermier and others added 4 commits November 28, 2026 08:07
core.adf requires commits via scripts/smart-commit.sh, but the script took only --dry-run and --merge and generated every subject itself (any package change became "feat(<scope>): apply logical updates"), with no body or trailers. Agents could not follow the rule, so every commit bypassed it.

Add -m (repeatable, one paragraph each), -F <file> and --trailer 'Key: value' (placed by git interpret-trailers). With a message, all substantive changes go into one commit; without one, the grouped default is unchanged. --merge and --dry-run honor the message. Bad input exits 2 before anything is staged. The pre-commit hook still runs on every path.

Tests run the real script in a throwaway repo (Git's bash on Windows, since plain bash can be WSL).

Closes: #459
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each case spawns bash and several git processes; under load on Windows they exceeded vitest's 5s default. Use 60s for the tests and the setup hook, matching the repo's other process-spawning tests.

Refs: #459
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Set core.hooksPath and check the hook before every path, --merge included; before, --merge could commit without the hook.
- Pass --no-divider to git interpret-trailers so a '---' line in the body is not read as a patch divider.
- Reject multi-line --trailer values (one flag could forge a second trailer); allow 'Key:value' like git.
- -F - reads the message from stdin.
- Never commit a -F message file that lives inside the repo.
- If a commit fails (e.g. the hook), unstage its files so the script can be rerun.
- List paths with core.quotePath=false so non-ASCII files are committed, not skipped.
- No 'feat: commit created' warning under --dry-run.

Tests cover each case, including --merge with an unset hooksPath and a failing hook; the new cases fail against the previous script.

Refs: #459
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Round-2 review of #464:
- Find an in-repo message file with git rev-parse (--show-toplevel and --show-prefix) instead of comparing pwd strings, whose spelling can differ from git's top level on Windows (Temp paths, case), which let the file leak into the commit.
- Run interpret-trailers with an unused core.commentChar so body lines such as '#459 caused this' are not treated as comments and the trailers stay after the body.
- A failing hook on the grouped path now says that earlier group commits were kept.
- Tests: '#' body lines, 'Refs:#1', -F relative to a subdirectory, a differently spelled cwd (Windows), a pre-staged index, a failing hook on the grouped path, no --dry-run feat warning.

Refs: #459
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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