Commit

From paulpas/agent-skill-router · View interactive version

Commit is an AI agent skill from the GitHub repository paulpas/agent-skill-router. Implements intelligent commit with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense

How to use this skill

Skill file

Commit

Orchestrates intelligent skill selection and execution for commit workflows. Applies the 5 Laws of Elegant Defense to guide data naturally through the orchestration pipeline, preventing errors before they occur. Selects optimal skills based on multi-factor scoring including text similarity, historical performance, and system availability.

TL;DR Checklist

┌───────────────────────────────────────────────────────────────────────────────┐

│ Orchestration Flow │

└───────────────────────────────────────────────────────────────────────────────┘

User Request

↓

┌─────────────────┐

│ Parse Request │

│ & Extract │

│ Features │

└────────┬────────┘

↓

┌─────────────────────────────────────────────────────────────────────┐

│ Evaluate Available Skills │

│ │

│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │

│ │ Skill A │ │ Skill B │ │ Skill C │ │

│ │ - Match Score│ │ - Match Score│ │ - Match Score│ │

│ │ - Confidence │ │ - Confidence │ │ - Confidence │ │

│ │ - History │ │ - History │ │ - History │ │

│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │

│ │ │ │ │

│ └─────────────────┴─────────────────┘ │

│ ↓ │

│ Select Best Skill │

└─────────────────────────────────────────────────────────────────────┘

↓

┌─────────────────┐

│ Execute Skill │

└────────┬────────┘

↓

┌─────────────────┐

│ Handle Result │

└────────┬────────┘

↓

┌─────────────────────────────────────────────────────────────────────┐

│ Error Handling & Fallback │

│ │

│ Success? ────────► Return Result │

│ │

│ Fail? ────────┐ │

│ ↓ │

│ ┌──────────────────────────────────────────────────────────┐ │

│ │ Fallback Chain │ │

│ │ │ │

│ │ 1. Retry with adjusted parameters │ │

│ │ 2. Try Alternative Skill (if available) │ │

│ │ 3. Defer to Human Operator (if critical) │ │

│ │ 4. Log & Return Error │ │

│ └──────────────────────────────────────────────────────────┘ │

└─────────────────────────────────────────────────────────────────────┘

When to Use

Use this skill when:

When NOT to Use

Avoid this skill for:

Core Workflow

  1. Parse and Analyze Request - Extract intent, entities, and constraints from user input.

Checkpoint: All required parameters must be present and in valid format before proceeding.

  1. Score Available Skills - Calculate match scores using multi-factor algorithm:

Checkpoint: Skip to fallback if no skill scores above threshold.

  1. Select Optimal Skill - Choose skill with highest score that meets minimum confidence.

Checkpoint: Verify skill has not been disabled or deprecated.

  1. Execute with Fallback - Run skill execution wrapped in retry and fallback logic.

Checkpoint: Log all execution attempts for audit trail.

  1. Return or Fallback - Either return successful result or apply fallback chain:

Checkpoint: Record outcome with timing and confidence metadata.

Implementation Patterns

Pattern 1: Skill Selection Logic

def prepare_commit_payload(
    staged_files: List[str],
    user_intent: str,
    commit_rules: Dict
) -> Dict:
    """Analyze staged changes and generate a validated commit payload.
    
    Implements Law 2 (Parse at boundary) by validating file paths and intent.
    Implements Law 3 (Atomic Predictability) by returning a new payload dict.
    """
    if not staged_files:
        raise ValueError("No files staged for commit")
    
    # Extract change types and scope
    change_types = _classify_changes(staged_files)
    scope = _determine_scope(staged_files, commit_rules.get("scope_rules"))
    
    # Generate conventional commit message based on intent and changes
    type_map = {"feat": "feat", "fix": "fix", "refactor": "refactor", "chore": "chore"}
    commit_type = type_map.get(change_types.get("primary", "chore"), "chore")
    
    description = _generate_description(user_intent, change_types)
    body = _extract_affected_components(staged_files)
    
    # Validate against commit rules (Law 4: Fail Fast)
    if len(description) > 72:
        raise ValueError("Commit description exceeds 72 characters")
    if not commit_rules.get("allow_empty", False) and change_types.get("lines_changed", 0) == 0:
        raise ValueError("Commit would be empty")
        
    return {
        "type": commit_type,
        "scope": scope,
        "description": description,
        "body": body,
        "files": staged_files,
        "timestamp": time.time()
    }

Pattern 2: Execution with Fallback

def execute_commit_workflow(
    commit_payload: Dict,
    repo_path: str,
    fallback_strategy: str = "interactive"
) -> Dict:
    """Execute git commit with domain-specific fallback chain.
    
    Implements Law 1 (Early Exit) and Law 4 (Fail Loud) for git operations.
    Fallback chain: amend -> interactive staging -> manual patch review.
    """
    if not commit_payload.get("description"):
        raise ValueError("Commit payload missing description")
        
    commit_cmd = f"git -C {repo_path} commit -m \"{commit_payload['type']}: {commit_payload['description']}\""
    if commit_payload.get("body"):
        commit_cmd += f"\n\n{commit_payload['body']}"
        
    try:
        # Attempt direct commit
        result = subprocess.run(commit_cmd, shell=True, capture_output=True, text=True, check=True)
        return {
            "success": True,
            "commit_hash": result.stdout.strip(),
            "strategy": "direct",
            "attempts": 1
        }
    except subprocess.CalledProcessError as e:
        stderr = e.stderr.lower()
        
        # Fallback 1: Pre-commit hook failure or linting issue
        if "pre-commit" in stderr or "lint" in stderr:
            return _apply_hook_fallback(repo_path, commit_payload)
            
        # Fallback 2: Empty commit or no changes detected
        if "nothing added" in stderr or "no changes" in stderr:
            return _apply_amend_fallback(repo_path, commit_payload)
            
        # Fallback 3: Conflict or merge state
        if "conflict" in stderr or "merge" in stderr:
            return _apply_interactive_fallback(repo_path, commit_payload, fallback_strategy)
            
        # Fail Loud: Unhandled git error
        raise GitCommitError(f"Unhandled commit failure: {stderr}") from e

MUST DO

MUST NOT DO

TL;DR Checklist

TL;DR for Code Generation

Output Template

When applying this skill, produce:

  1. Selected Skills - List of skill names with confidence scores
  2. Selection Rationale - Why each skill was chosen (match score, history, availability)
  3. Execution Plan - Order of execution with dependencies
  4. Fallback Strategy - Which fallback skills will be tried and in what order
  5. Risk Assessment - Any potential failure points and their impact
  6. Timing Estimates - Expected latency including fallback scenarios

Related Skills

| Skill | Purpose |

|---|---|

| changelog-automation | Changelog generation from commit history |



Constraints

MUST DO

MUST NOT DO

Live References

Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.