This script analyzes a codebase to measure and report the impact of AI-generated code contributions. It provides detailed insights about AI vs human contributions, helping teams understand the role of AI in their development process.
-
Repository Analysis: Automatically detects and analyzes git repositories:
-
Uses current directory if it's a git repo
-
Searches parent directories for a git repo
-
Falls back to cloning a specified repository if needed
# Basic repository setup repo_path = os.getcwd() repo_config = RepoConfig.from_repo_path(repo_path) repo_operator = RepoOperator(repo_config=repo_config) project = ProjectConfig.from_repo_operator(repo_operator=repo_operator, programming_language=ProgrammingLanguage.PYTHON) codebase = Codebase(projects=[project])
-
-
Comprehensive Statistics:
- Total number of commits and AI vs human contribution percentages
- Files with significant AI contribution (>50%)
- AI-touched symbols and their impact
- Detailed contributor breakdown (human and AI contributors)
# Run the analysis ai_authors = ["github-actions[bot]", "dependabot[bot]"] results = analyze_ai_impact(codebase, ai_authors) # Access statistics stats = results["stats"] print(f"Total commits: {stats['total_commits']}") print(f"AI commits: {stats['ai_commits']} ({stats['ai_percentage']:.1f}%)") print(f"Files with >50% AI: {stats['ai_file_count']} of {stats['total_file_count']}") # View contributors for author, count in results["contributors"]: is_ai = any(ai_name in author for ai_name in ai_authors) print(f"{'🤖' if is_ai else '👤'} {author}: {count} commits")
-
High-Impact Code Detection:
- Identifies AI-written code that is heavily used by other parts of the codebase
- Shows dependency relationships for AI-contributed code
# Access high-impact AI symbols for symbol in results["high_impact_symbols"]: print(f"Symbol: {symbol['name']} ({symbol['filepath']})") print(f"Used by {symbol['usage_count']} other symbols") print(f"Last edited by: {symbol['last_editor']}") # View top AI-contributed files for file_path, percentage in stats["top_ai_files"]: print(f"{file_path}: {percentage:.1f}% AI contribution")
-
Detailed Attribution:
- Maps symbols to git history
- Tracks last editor and complete editor history for each symbol
- Flags AI-authored symbols
# Get attribution information for a specific symbol symbol = codebase.get_symbol("path/to/file.py:MyClass.my_method") # Access attribution data print(f"Last editor: {symbol.last_editor}") print(f"Editor history: {symbol.editor_history}") print(f"AI authored: {symbol.is_ai_authored}") # Find all AI-authored symbols ai_symbols = [s for s in codebase.get_symbols() if s.is_ai_authored] for symbol in ai_symbols: print(f"AI symbol: {symbol.name}")
The script generates:
- Console output with summary statistics
- Detailed analysis in
ai_impact_analysis.json - Attribution information added to codebase symbols
python run.pyThe script will automatically:
- Initialize and analyze the codebase
- Process git history
- Generate attribution information
- Output detailed statistics
You can also visualize the AI impact analysis results using a dashboard. For setup and usage instructions, please see the documentation in the /dashboard subdirectory.
After running the analysis, symbols in the codebase will have the following attribution information:
symbol.last_editor: The last person who edited the symbolsymbol.editor_history: List of all editors who have touched the symbolsymbol.is_ai_authored: Boolean indicating if the symbol was authored by AI
Feel free to submit issues and enhancement requests!