Add configurable commit message styles#2
Conversation
- Add style management subcommand (list, show, set, clear, create, delete) - Bundle conventional and simple built-in style templates - Support --style CLI flag for one-off style override - Allow user-defined custom styles in ~/.claude-commit/styles/ - Style instructions override auto-detection from git history
JohannLai
left a comment
There was a problem hiding this comment.
Thanks for the PR! The style system is a nice feature — clean API design with good layering (CLI flag > config default > auto-detect). A few things to address before merging:
Bug: console.print() with file=sys.stderr
In main(), the style-not-found error block uses:
console.print(f"[red]❌ Style '{style_name}' not found.[/red]", file=sys.stderr)
console.print("[yellow] Run ...[/yellow]", file=sys.stderr)Rich's Console.print() does not accept a file keyword — this will raise a TypeError at runtime. Should use error_console.print() instead (which is already configured with stderr=True).
Inconsistency: get_user_styles_dir() ignores custom config_path
Config.__init__ accepts a config_path parameter (used heavily in tests), but get_user_styles_dir() hardcodes Path.home() / ".claude-commit" / "styles". This means tests that use tmp_path for config will still read/write styles from the real home directory.
Suggest deriving from self.config_path.parent:
def get_user_styles_dir(self) -> Path:
return self.config_path.parent / "styles"Missing tests
The project now has a test suite (tests/). This PR should include tests for the new config methods (get_style, set_style, clear_style, list_styles, create_custom_style, delete_custom_style) and the handle_style_command function. Most of these are pure logic and straightforward to test.
Minor: handle_style_command doesn't use error_console
handle_alias_command uses print(..., file=sys.stderr) for errors (which works), but for consistency with the rest of the codebase you might want to keep the same pattern. Not a blocker.
Overall the design is solid — the style override injection into the system prompt and the conditional step1 logic both make sense. Just the file=sys.stderr bug needs fixing before merge.
|
Also, sorry about the conflicts — I recently added a test suite and refactored some helpers in |
Summary
conventionalandsimple) and support user-created custom styles stored in~/.claude-commit/styles/claude-commit stylesub-command for managing styles (list, show, set, clear, create, delete) and a--styleCLI flag for per-run overridesChanges
config.py: Add style management methods: get/set/clear default style, list available styles (bundled+user), read style content, and create/delete custom stylesmain.py: Wire style system into commit generation: resolve style from CLI flag or config, inject style instructions into the system prompt, and skip git history detection when a style is active. Addstylesub-command handler and--style/-sargumentstyles/conventional.txt: Built-in conventional commits style definitionstyles/simple.txt: Built-in simple/plain style definitionpyproject.toml: Includestyles/*.txtas package data