gmuse.commit#
Commit message generation service.
This module provides the core business logic for generating commit messages. It orchestrates git operations, prompt building, and LLM interaction.
- Public API:
generate_message: Main entry point for generating commit messages
gather_context: Collect context from git repository
- Data Classes:
GenerationContext: Context gathered for generation
GenerationResult: Result of message generation
Module Contents#
Classes#
Context gathered for commit message generation. |
|
Result of commit message generation. |
Functions#
Gather all context needed for commit message generation. |
|
Generate a commit message from staged changes. |
Data#
Default maximum diff size in bytes (~5000 tokens). |
API#
- gmuse.commit.logger = 'get_logger(...)'#
- gmuse.commit.DEFAULT_MAX_DIFF_BYTES: Final[int] = 20000#
Default maximum diff size in bytes (~5000 tokens).
This serves as the default value but can be overridden via configuration using max_diff_bytes parameter.
- class gmuse.commit.GenerationContext#
Context gathered for commit message generation.
This dataclass encapsulates all the information collected from the git repository that is used to generate a commit message.
- Attributes:
diff: Staged changes from git history: Recent commit history for style context (None if empty) repo_instructions: Project-level guidance from .gmuse file (None if absent) branch_info: Current branch information (None if not included or unavailable) diff_was_truncated: Whether the diff was truncated to fit limits
- diff: gmuse.git.StagedDiff = None#
- history: Optional[gmuse.git.CommitHistory] = None#
- repo_instructions: Optional[gmuse.git.RepositoryInstructions] = None#
- branch_info: Optional[gmuse.git.BranchInfo] = None#
- diff_was_truncated: bool = False#
- class gmuse.commit.GenerationResult#
Result of commit message generation.
- Attributes:
message: The generated commit message text context: The context that was used for generation
- message: str = None#
- context: gmuse.commit.GenerationContext = None#
- gmuse.commit.gather_context(history_depth: int = 5, max_diff_bytes: int = DEFAULT_MAX_DIFF_BYTES, include_branch: bool = False, branch_max_length: int = 60) gmuse.commit.GenerationContext#
Gather all context needed for commit message generation.
This function collects staged changes, commit history, repository instructions, and optionally branch information needed to generate a contextually appropriate commit message.
- Args:
history_depth: Number of recent commits to fetch for style context max_diff_bytes: Maximum diff size in bytes before truncation include_branch: Whether to include current branch information branch_max_length: Maximum length for branch summary
- Returns:
GenerationContext with all gathered information
- Raises:
NotAGitRepositoryError: If not in a git repository NoStagedChangesError: If no files are staged
- gmuse.commit.generate_message(config: gmuse.config.ConfigDict, hint: Optional[str] = None, context: Optional[gmuse.commit.GenerationContext] = None) gmuse.commit.GenerationResult#
Generate a commit message from staged changes.
This is the main entry point for commit message generation. It orchestrates context gathering, prompt building, and LLM interaction.
- Args:
config: Merged configuration dictionary hint: Optional user hint for message generation context: Pre-gathered context (if None, will be gathered automatically)
- Returns:
GenerationResult with the message and context used
- Raises:
NotAGitRepositoryError: If not in a git repository NoStagedChangesError: If no files are staged LLMError: If LLM interaction fails InvalidMessageError: If generated message fails validation
- Example:
>>> from gmuse.config import merge_config >>> config = merge_config() >>> result = generate_message(config, hint="security fix") >>> print(result.message) 'fix(auth): patch XSS vulnerability in login form'