Skip to main content

generate_commit_message

Function generate_commit_message 

Source
pub fn generate_commit_message(
    diff: &str,
    registry: &AgentRegistry,
    runtime: &mut PipelineRuntime<'_>,
    commit_agent: &str,
    template_context: &TemplateContext,
    workspace: &dyn Workspace,
    prompt_history: &HashMap<String, String>,
) -> Result<CommitMessageResult>
Expand description

Generate a commit message using the standard agent pipeline with fallback.

This function uses the standard agent pipeline with fallback, which provides:

  • Proper stdout/stderr logging
  • Configurable fallback chains
  • Retry logic with exponential backoff
  • Agent error classification

Multi-stage retry logic:

  1. Try initial prompt
  2. On fallback/empty result, try strict JSON prompt
  3. On failure, try V2 strict prompt (with negative examples)
  4. On failure, try ultra-minimal prompt
  5. On failure, try emergency prompt
  6. Only use hardcoded fallback after all prompt variants exhausted

§Agent Cycling Behavior

This function implements proper strategy-first cycling by trying each strategy with all agents before moving to the next strategy:

  • Strategy 1 (initial): Agent 1 → Agent 2 → Agent 3
  • Strategy 2 (strict JSON): Agent 1 → Agent 2 → Agent 3
  • Strategy 3 (strict JSON V2): Agent 1 → Agent 2 → Agent 3
  • etc.

This approach is more efficient because if a particular strategy works well with any agent, we succeed quickly rather than exhausting all strategies on the first agent before trying others.

§Arguments

  • diff - The git diff to generate a commit message for
  • registry - The agent registry for resolving agents and fallbacks
  • runtime - The pipeline runtime for execution services
  • commit_agent - The primary agent to use for commit generation
  • template_context - Template context for user template overrides
  • workspace - Workspace filesystem for file operations
  • prompt_history - Prompt history for checkpoint/resume determinism

§Returns

Returns Ok(CommitMessageResult) with the generated message and metadata.