VOOZH about

URL: https://deepwiki.com/guanguans/ai-commit/7.2-commit-types-configuration

⇱ Commit Types Configuration | guanguans/ai-commit | DeepWiki


Loading...
Menu

Commit Types Configuration

This page documents the types array and the related type_mark, type_prompt_mark, and type_prompt configuration keys in config/ai-commit.php. It covers how commit type selection works in the CLI and how the selected type is injected into the AI prompt.

For the full prompt template structure (including the conventional prompt and the diff_mark substitution), see Prompt Templates Configuration. For how configuration layers are merged and overridden, see Configuration File Format and Precedence.


Purpose of Commit Types

The types configuration controls the list of commit types presented to the user when running ai-commit commit. After the user selects a type, the selection influences what instruction is injected into the AI prompt, either directing the AI to use a specific conventional commit type or allowing it to choose one automatically.


The types Array

The types key in config/ai-commit.php is an ordered associative array mapping a short type key to a human-readable description.

config/ai-commit.php50-63

KeyDescription
autoAutomatically generate commit type
featA new feature
fixA bug fix
docsDocumentation only changes
styleChanges that do not affect the meaning of the code
refactorA code change that neither fixes a bug nor adds a feature
perfA code change that improves performance
testAdding missing tests or correcting existing tests
buildChanges that affect the build system or external dependencies
ciChanges to CI configuration files and scripts
choreOther changes that don't modify src or test files
revertReverts a previous commit

The first entry in this array has special significance: it is treated as the "automatic" mode. When the first entry is selected, the AI is not constrained to a specific type (see How the First Entry is Treated below).

Sources: config/ai-commit.php50-63


Type-Related Configuration Keys

Three additional keys control how the selected type gets formatted and embedded in the AI prompt.

Config KeyDefault ValuePurpose
type_mark<type>Placeholder in the prompt template replaced by the selected type value
type_prompt_mark<type-prompt>Placeholder in the prompt template replaced by the formatted type instruction
type_prompt- Use commit type \%s`.`sprintf format string producing the type instruction injected at <type-prompt>

config/ai-commit.php39-48

The type_prompt value is a PHP sprintf format string. %s is replaced at runtime with the selected type key (e.g., feat, fix).

Sources: config/ai-commit.php39-48


How Type Selection Works in the CLI

Diagram: Type Selection Flow in CommitCommand


Sources: app/Commands/CommitCommand.php65-70 app/Commands/CommitCommand.php236-253

The relevant code path is:

  1. Type list retrievalCommitCommand::handle() calls $this->configManager->get('types') to load the full types array. app/Commands/CommitCommand.php67-70

  2. Interactive selection$this->choice(...) presents the keys and descriptions to the user with array_key_first($types) as the default selection (i.e., auto). app/Commands/CommitCommand.php66-70

  3. Prompt constructionCommitCommand::promptFor() receives the selected type string and performs placeholder substitution. app/Commands/CommitCommand.php236-253


How the First Entry is Treated

The first key in the types array is the "auto" mode. promptFor compares the selected type against array_key_first($this->configManager->get('types')):

  • If the first type is selected (default: auto): the type variable is reset to the literal type_mark value (<type>), and typePrompt is set to an empty string. This causes the <type-prompt> placeholder in the prompt template to be replaced with nothing, giving the AI freedom to choose the commit type. The <type> placeholder in the format string (<type>(<scope>): <subject>) remains as a literal token for the AI to interpret.

  • If any other type is selected (e.g., feat): sprintf($this->configManager->get('type_prompt'), $type) produces the string - Use commit type \feat`., which is then substituted into the location of the prompt. Theplaceholder in the format line is replaced withfeat`.

app/Commands/CommitCommand.php237-248


Placeholder Substitution Diagram

Diagram: Placeholder Resolution in promptFor()


Sources: app/Commands/CommitCommand.php236-253 config/ai-commit.php39-48


Customizing Commit Types

The types array can be overridden in a local .ai-commit.json file or the global ~/.ai-commit/.ai-commit.json. Because the configuration system performs a deep merge, you can replace the entire types array by providing a new one in your local or global config.

Example local .ai-commit.json to restrict to only feat and fix:


Note: The first key must still serve as your "auto" entry. The promptFor method uses array_key_first to detect it — order matters. JSON objects preserve insertion order in PHP (as of PHP 7.1+), so the first defined key will be treated as the auto type.

For details on local vs. global config merging, see Configuration File Format and Precedence.

Sources: app/Commands/CommitCommand.php240-243 config/ai-commit.php50-63


Customizing the Type Prompt Instruction

The type_prompt format string can also be overridden. For example, to make the instruction more emphatic:


This string is passed directly to sprintf with the selected type key as the only argument, so exactly one %s placeholder is required.

Sources: app/Commands/CommitCommand.php238 config/ai-commit.php47-48


Summary of Config Keys for Commit Types

KeyTypeDefaultRole
typesarray<string, string>12-entry arrayDefines selectable commit types; first entry is "auto"
type_markstring<type>Prompt placeholder replaced by selected type
type_prompt_markstring<type-prompt>Prompt placeholder replaced by type instruction
type_promptstring- Use commit type \%s`.`sprintf template for the type instruction

Sources: config/ai-commit.php39-63