Feature Commit Tracking

L3
ModelContextProtocolGithubClaude Code

Research development history across branches to track when specific features were introduced and create comprehensive documentation.

Created by Zijian Wu
2025-08-15
Repository AnalysisRelease Coordination

Model Ranking

Click on the dots to view the trajectory of each task run
Model
Run Results
Pass@4
Pass^4
Avg Time
Avg Turns
Input Tokens
Output Tokens
Total Tokens
Claude
claude-4-1-opus
0
/1
--
78.4s
4.0
243,270
492
243,762
Claude
claude-4-sonnet
0
/4
130.1s
7.8
810,032
979
811,011
DeepSeek
deepseek-chat
0
/4
190.1s
11.5
678,269
634
678,903
Gemini
gemini-2-5-pro
0
/4
63.0s
2.0
13,044
5,643
18,686
OpenAI
gpt-5
0
/4
95.4s
3.5
134,738
3,572
138,311
Grok
grok-4
0
/4
30.6s
-
-
-
-
MoonshotAI
k2
0
/4
186.2s
7.0
262,035
388
262,423
OpenAI
o3
0
/4
106.8s
7.5
630,621
1,815
632,436
Qwen
qwen-3-coder
0
/4
103.6s
6.3
557,633
475
558,107

Task State


Instruction



Verify

*.py
Python
import sys
import os
import requests
from typing import Dict, List, Optional, Tuple
import base64
import re
from dotenv import load_dotenv


def _get_github_api(
    endpoint: str, headers: Dict[str, str], org: str, repo: str = "claude-code"
) -> Tuple[bool, Optional[Dict]]:
    """Make a GET request to GitHub API and return (success, response)."""
    url = f"https://api.github.com/repos/{org}/{repo}/{endpoint}"
    try:
        response = requests.get(url, headers=headers)
        if response.status_code == 200:
            return True, response.json()
        elif response.status_code == 404:
            return False, None
        else:
            print(f"API error for {endpoint}: {response.status_code}", file=sys.stderr)
            return False, None
    except Exception as e:
        print(f"Exception for {endpoint}: {e}", file=sys.stderr)
        return False, None


def _get_file_content(
    file_path: str,
    headers: Dict[str, str],
    org: str,
    repo: str = "claude-code",
    ref: str = "main",
) -> Optional[str]:
    """Get the content of a file from the repository."""
    success, result = _get_github_api(
        f"contents/{file_path}?ref={ref}", headers, org, repo
    )
    if not success or not result:
        return None

    try:
        content = base64.b64decode(result.get("content", "")).decode("utf-8")
        return content
    except Exception as e:
        print(f"Content decode error for {file_path}: {e}", file=sys.stderr)
        return None


def _verify_commit_exists(
    commit_sha: str, headers: Dict[str, str], org: str, repo: str = "claude-code"
) -> Tuple[bool, Optional[Dict]]:
    """Verify that a commit exists and return its details."""
    success, commit_data = _get_github_api(f"commits/{commit_sha}", headers, org, repo)
    return success, commit_data


def _parse_feature_table(content: str) -> List[Dict]:
    """Parse the feature commit table from markdown content."""
    features = []

    lines = content.split("\n")
    in_table = False

    for line in lines:
        # Look for table header
        if (
            "| Feature Name | Commit SHA | Author | Branch | Date | Files Changed | Commit Message |"
            in line
        ):
            in_table = True
            continue
        if in_table and line.startswith("|---"):
            continue

        # Parse table rows
        if in_table and line.startswith("|"):
            parts = [p.strip() for p in line.split("|")]
            if len(parts) >= 8:  # Should have 7 columns plus empty parts at start/end
                feature_name = parts[1].strip()
                commit_sha = parts[2].strip()
                author = parts[3].strip()
                branch = parts[4].strip()
                date = parts[5].strip()
                files_changed = parts[6].strip()
                commit_message = parts[7].strip()

                if feature_name and commit_sha and author and branch and date:
                    features.append(
                        {
                            "name": feature_name,
                            "sha": commit_sha,
                            "author": author,
                            "branch": branch,
                            "date": date,
                            "files_changed": files_changed,
                            "commit_message": commit_message,
                        }
                    )

        # Stop at end of table section
        if in_table and line and not line.startswith("|") and "##" in line:
            break

    return features


def verify_task() -> bool:
    """Verify the feature commit tracking task."""
    # Load environment variables from .mcp_env
    load_dotenv(".mcp_env")

    # Get GitHub token and org
    github_token = os.environ.get("MCP_GITHUB_TOKEN")
    github_org = os.environ.get("GITHUB_EVAL_ORG")

    if not github_token:
        print("Error: MCP_GITHUB_TOKEN environment variable not set", file=sys.stderr)
        return False

    if not github_org:
        print("Error: GITHUB_EVAL_ORG environment variable not set", file=sys.stderr)
        return False

    headers = {
        "Authorization": f"Bearer {github_token}",
        "Accept": "application/vnd.github.v3+json",
    }

    # Expected feature commits based on exploration
    expected_features = {
        "Shell Completion Scripts": "8a0febdd09bda32f38c351c0881784460d69997d",
        "CHANGELOG Version 1.0.65": "94dcaca5d71ad82644ae97f3a2b0c5eb8b63eae0",
        "Rust Extraction Improvements": "50e58affdf1bfc7d875202bc040ebe0dcfb7d332",
    }

    # Expected authors for each commit
    expected_authors = {
        "8a0febdd09bda32f38c351c0881784460d69997d": "gitmpr",
        "94dcaca5d71ad82644ae97f3a2b0c5eb8b63eae0": "QwertyJack",
        "50e58affdf1bfc7d875202bc040ebe0dcfb7d332": "alokdangre",
    }

    # Expected commit messages for each commit
    expected_messages = {
        "8a0febdd09bda32f38c351c0881784460d69997d": "feat: add shell completions (bash, zsh, fish)",
        "94dcaca5d71ad82644ae97f3a2b0c5eb8b63eae0": "Merge branch 'anthropics:main' into main",
        "50e58affdf1bfc7d875202bc040ebe0dcfb7d332": "Enhance Rust extraction and output handling in workflows",
    }

    # Expected dates for each commit (YYYY-MM-DD format)
    expected_dates = {
        "8a0febdd09bda32f38c351c0881784460d69997d": "2025-08-01",
        "94dcaca5d71ad82644ae97f3a2b0c5eb8b63eae0": "2025-08-02",
        "50e58affdf1bfc7d875202bc040ebe0dcfb7d332": "2025-08-09",
    }

    print("Verifying feature commit tracking task...")

    # 1. Check if FEATURE_COMMITS.md exists in main branch
    print("1. Checking if FEATURE_COMMITS.md exists...")
    content = _get_file_content("FEATURE_COMMITS.md", headers, github_org)
    if not content:
        print("Error: FEATURE_COMMITS.md not found in main branch", file=sys.stderr)
        return False
    print("✓ FEATURE_COMMITS.md found")

    # 2. Check required sections exist
    print("2. Checking required sections...")
    required_sections = [
        "# Feature Development Tracking",
        "## Overview",
        "## Feature Commit History",
    ]

    for section in required_sections:
        if section not in content:
            print(f"Error: Missing required section '{section}'", file=sys.stderr)
            return False
    print("✓ All required sections present")

    # 3. Parse and validate feature table
    print("3. Parsing and validating feature table...")
    features = _parse_feature_table(content)

    if len(features) < 3:
        print(
            f"Error: Expected at least 3 features, found {len(features)}",
            file=sys.stderr,
        )
        return False

    # 4. Verify each expected feature is present with correct commit SHA
    print("4. Verifying feature commit SHAs...")
    found_features = {}
    for feature in features:
        found_features[feature["name"]] = feature["sha"]

    for feature_name, expected_sha in expected_features.items():
        if feature_name not in found_features:
            print(
                f"Error: Feature '{feature_name}' not found in table", file=sys.stderr
            )
            return False

        actual_sha = found_features[feature_name]
        if actual_sha != expected_sha:
            print(
                f"Error: Wrong SHA for '{feature_name}'. Expected: {expected_sha}, Got: {actual_sha}",
                file=sys.stderr,
            )
            return False

    print("✓ All feature commit SHAs are correct")

    # 5. Verify each commit exists and has correct author
    print("5. Verifying commit details...")
    for feature in features:
        if feature["sha"] in expected_features.values():
            success, commit_data = _verify_commit_exists(
                feature["sha"], headers, github_org
            )
            if not success:
                print(f"Error: Commit {feature['sha']} not found", file=sys.stderr)
                return False

            # Check author
            expected_author = expected_authors.get(feature["sha"])
            if expected_author:
                actual_author = commit_data.get("author", {}).get("login", "")
                if actual_author != expected_author:
                    print(
                        f"Error: Wrong author for {feature['sha']}. Expected: {expected_author}, Got: {actual_author}",
                        file=sys.stderr,
                    )
                    return False

            # Check commit message (compare with table entry)
            expected_message = expected_messages.get(feature["sha"])
            if expected_message and "commit_message" in feature:
                if feature["commit_message"] != expected_message:
                    print(
                        f"Error: Wrong commit message in table for {feature['sha']}. Expected: '{expected_message}', Got: '{feature['commit_message']}'",
                        file=sys.stderr,
                    )
                    return False

            # Also verify against actual commit data
            if expected_message:
                actual_message = (
                    commit_data.get("commit", {}).get("message", "").split("\n")[0]
                )  # First line only
                if actual_message != expected_message:
                    print(
                        f"Error: Wrong commit message for {feature['sha']}. Expected: '{expected_message}', Got: '{actual_message}'",
                        file=sys.stderr,
                    )
                    return False

            # Check date format (YYYY-MM-DD)
            if not re.match(r"^\d{4}-\d{2}-\d{2}$", feature["date"]):
                print(
                    f"Error: Invalid date format for {feature['name']}: {feature['date']}",
                    file=sys.stderr,
                )
                return False

            # Check actual date matches expected
            expected_date = expected_dates.get(feature["sha"])
            if expected_date:
                if feature["date"] != expected_date:
                    print(
                        f"Error: Wrong date for {feature['sha']}. Expected: {expected_date}, Got: {feature['date']}",
                        file=sys.stderr,
                    )
                    return False

    print("✓ All commit details verified")

    # 6. Verify the table format is correct
    print("6. Verifying table format...")
    table_header = "| Feature Name | Commit SHA | Author | Branch | Date | Files Changed | Commit Message |"
    if table_header not in content:
        print("Error: Table header format is incorrect", file=sys.stderr)
        return False

    # Check that all features have complete information
    for feature in features:
        if not all(
            [
                feature["name"],
                feature["sha"],
                feature["author"],
                feature["branch"],
                feature["date"],
                feature.get("commit_message", ""),
            ]
        ):
            print(
                f"Error: Incomplete information for feature: {feature['name']}",
                file=sys.stderr,
            )
            return False

    print("✓ Table format is correct and complete")

    print("\n✅ All verification checks passed!")
    print("Feature commit tracking completed successfully:")
    print("  - File: FEATURE_COMMITS.md created in main branch")
    print(f"  - Features tracked: {len(features)}")
    print("  - All expected commit SHAs verified")
    print("  - All commit authors verified")
    print("  - Analysis summary complete")

    return True


if __name__ == "__main__":
    success = verify_task()
    sys.exit(0 if success else 1)