gmuse.cli.main#
CLI interface for gmuse.
This module provides the command-line interface using Typer. It handles:
Argument parsing and validation
Configuration loading and merging
Error handling and user feedback
Clipboard operations
Commands: msg: Generate a commit message from staged changes. info: Display resolved configuration for debugging. auth: Manage secure API credentials. git-completions: Shell completion utilities. git-completions-run: Runtime helper for shell completions.
Example: >>> # From command line: >>> # gmuse commit –hint “security fix”
Module Contents#
Functions#
Show version and exit. |
|
gmuse: AI generated commit messages. |
|
Print resolved LLM configuration and environment values for debugging. |
|
Generate a commit message from staged changes. |
|
Deprecated alias for |
|
Interactive commit workflow: generate, review, and create a git commit. |
|
Load and merge configuration from all sources. |
|
Return True when stdin and stdout are both attached to a TTY. |
|
Copy message to clipboard with user feedback. |
|
Display error message and exit with specified code. |
|
Format the dry-run output for CLI display. |
Data#
API#
- gmuse.cli.main.logger = 'get_logger(...)'#
- gmuse.cli.main.app = 'Typer(...)'#
- gmuse.cli.main.version_callback(value: bool) None#
Show version and exit.
Args: value: True if –version flag was passed.
Raises: typer.Exit: Always exits after printing version.
- gmuse.cli.main.main(version: bool = typer.Option(None, '--version', help='Show the version and exit.', is_eager=True, callback=version_callback)) None#
gmuse: AI generated commit messages.
Generate commit messages from staged changes using AI.
Use ‘gmuse commit’ to generate, review, and create a commit from staged changes. Use ‘gmuse generate’ when you need stdout-only output for scripts.
Examples: gmuse commit # Review and commit gmuse commit –edit # Generate, edit, and commit gmuse commit –yes # Generate and commit immediately gmuse generate # Print message only gmuse generate –format conventional # Conventional commits gmuse info # Show configuration
For more information, visit: https://gmuse.readthedocs.io
- gmuse.cli.main.info() None#
Print resolved LLM configuration and environment values for debugging.
Useful for diagnosing provider selection and which credentials are being used.
- gmuse.cli.main.generate(hint: Optional[str] = typer.Option(None, '--hint', help="Additional guidance for message generation (e.g., 'emphasize security')"), model: Optional[str] = typer.Option(None, '--model', '-m', help="LLM model to use (e.g., 'gpt-4', 'claude-3-opus')"), format: Optional[str] = typer.Option(None, '--format', '-f', help="Message format: 'freeform' (default), 'conventional', or 'gitmoji'"), history_depth: Optional[int] = typer.Option(None, '--history-depth', help='Number of recent commits to use for style context (0-50)'), temperature: Optional[float] = typer.Option(None, '--temperature', help='LLM sampling temperature (0.0-2.0, default: 0.7)'), max_tokens: Optional[int] = typer.Option(None, '--max-tokens', help='Maximum tokens in LLM response (default: 500)'), max_diff_bytes: Optional[int] = typer.Option(None, '--max-diff-bytes', help='Maximum diff size in bytes before truncation (default: 20000)'), include_branch: bool = typer.Option(False, '--include-branch', help='Include current branch name as context for commit message generation'), dry_run: bool = typer.Option(False, '--dry-run', help='Print the assembled prompt without calling the LLM provider')) None#
Generate a commit message from staged changes.
This command is the raw stdout-only primitive intended for scripting and completion use. It prints the generated message to stdout on success.
- gmuse.cli.main.msg(hint: Optional[str] = typer.Option(None, '--hint', help='(Deprecated) Additional guidance for message generation'), copy: bool = typer.Option(False, '--copy', '-c', help='(Deprecated) Copy generated message to clipboard'), model: Optional[str] = typer.Option(None, '--model', '-m'), format: Optional[str] = typer.Option(None, '--format', '-f'), history_depth: Optional[int] = typer.Option(None, '--history-depth'), temperature: Optional[float] = typer.Option(None, '--temperature'), max_tokens: Optional[int] = typer.Option(None, '--max-tokens'), max_diff_bytes: Optional[int] = typer.Option(None, '--max-diff-bytes'), include_branch: bool = typer.Option(False, '--include-branch'), dry_run: bool = typer.Option(False, '--dry-run')) None#
Deprecated alias for
gmuse generate.Emits deprecation guidance to stderr while preserving stdout output so scripts that rely on
gmuse msgcontinue to function.
- gmuse.cli.main.commit(hint: Optional[str] = typer.Option(None, '--hint', help='Hint for message generation'), yes: bool = typer.Option(False, '--yes', '-y', help='Non-interactive: generate and commit immediately'), edit: bool = typer.Option(False, '--edit', help='Generate, open the editor with the draft, and commit'), model: Optional[str] = typer.Option(None, '--model', '-m'), format: Optional[str] = typer.Option(None, '--format', '-f'), history_depth: Optional[int] = typer.Option(None, '--history-depth'), temperature: Optional[float] = typer.Option(None, '--temperature'), max_tokens: Optional[int] = typer.Option(None, '--max-tokens'), max_diff_bytes: Optional[int] = typer.Option(None, '--max-diff-bytes'), include_branch: bool = typer.Option(False, '--include-branch')) None#
Interactive commit workflow: generate, review, and create a git commit.
In interactive terminals this opens a small review loop allowing accept/edit/regenerate/abort. Use –edit to skip the review prompt and open the editor immediately. In non-interactive scripts, use –yes to generate and commit immediately.
- gmuse.cli.main._load_config(model: Optional[str] = None, copy: bool = False, format: Optional[str] = None, history_depth: Optional[int] = None, temperature: Optional[float] = None, max_tokens: Optional[int] = None, max_diff_bytes: Optional[int] = None, include_branch: bool = False) gmuse.config.ConfigDict#
Load and merge configuration from all sources.
Configuration is loaded from multiple sources with the following precedence (highest to lowest):
CLI arguments (passed to this function)
Environment variables (GMUSE_*)
Configuration file (.gmuse.toml or pyproject.toml)
Built-in defaults
Args: model: CLI model override. copy: CLI copy to clipboard flag. format: CLI format override. history_depth: CLI history depth override. temperature: CLI temperature override. max_tokens: CLI max_tokens override. max_diff_bytes: CLI max_diff_bytes override. include_branch: CLI include branch flag.
Returns: Merged and validated configuration dictionary.
Raises: ConfigError: If the merged configuration is invalid.
- gmuse.cli.main._is_interactive_terminal() bool#
Return True when stdin and stdout are both attached to a TTY.
- gmuse.cli.main._copy_to_clipboard(message: str) None#
Copy message to clipboard with user feedback.
Attempts to copy using pyperclip. Displays success message or warning if pyperclip is not installed or clipboard operation fails.
Args: message: The text to copy to clipboard.
- gmuse.cli.main._error_exit(message: str, code: int = 1, hint: Optional[str] = None) None#
Display error message and exit with specified code.
Args: message: The error message to display. code: Exit code (default: 1). hint: Optional helpful hint to display after the error.
Raises: typer.Exit: Always raises to exit the application.
- gmuse.cli.main._format_dry_run_output(model: Optional[str], format: str, truncated: bool, system_prompt: str, user_prompt: str) str#
Format the dry-run output for CLI display.
Produces a plain-text block containing a metadata header and labeled SYSTEM PROMPT / USER PROMPT sections so the user can inspect what would be sent to the LLM provider.
Args: model: Resolved model name (or None if not configured). format: Message format (freeform, conventional, gitmoji). truncated: Whether the staged diff was truncated. system_prompt: The system prompt that would be sent. user_prompt: The user prompt that would be sent.
Returns: Formatted string suitable for printing to stdout.
Example: >>> output = _format_dry_run_output( … model=”gpt-4”, … format=”conventional”, … truncated=False, … system_prompt=”You are a commit helper.”, … user_prompt=”Diff: …”, … ) >>> print(output) MODEL: gpt-4 FORMAT: conventional TRUNCATED: false
SYSTEM PROMPT: You are a commit helper. USER PROMPT: Diff: …