feat: add commit attribution with per-file AI contribution tracking#3115
feat: add commit attribution with per-file AI contribution tracking#3115
Conversation
…ia git notes Track character-level AI vs human contributions per file and store detailed attribution metadata as git notes (refs/notes/ai-attribution) after each successful git commit. This enables open-source AI disclosure and enterprise compliance audits without polluting commit messages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📋 Review SummaryThis PR introduces a commit attribution system that tracks character-level AI contributions per file and stores them as git notes after successful commits. The implementation is well-structured with comprehensive test coverage (21 new tests), follows existing code conventions, and provides a non-blocking mechanism for AI contribution tracking. The approach of using git notes keeps commit messages clean while enabling compliance audits. 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
…ted file exclusion
- Replace line-based diff with Claude's prefix/suffix character-level algorithm
for precise contribution calculation (e.g. "Esc"→"esc" = 1 char, not whole line)
- Compute real AI vs human contribution percentages at commit time by analyzing
git diff --stat output: humanChars = max(0, diffSize - trackedAiChars)
- Add generated file exclusion (lock files, dist/, .min.js, .d.ts, etc.)
ported from Claude Code's generatedFiles.ts
- Add file deletion tracking via recordDeletion()
- Update git notes payload format: {aiChars, humanChars, percent} per file
with real percentages instead of hardcoded 100%
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… PR attribution Align with Claude Code's full attribution feature set: - Surface tracking: read QWEN_CODE_ENTRYPOINT env var (cli/ide/api/sdk), include surfaceBreakdown in git notes payload - Prompt counting: incrementPromptCount() hooked into client.ts message loop, tracks promptCount/permissionPromptCount/escapeCount - Session persistence: toSnapshot()/restoreFromSnapshot() for serializing attribution state; ChatRecordingService.recordAttributionSnapshot() writes to session JSONL; client.ts restores on session resume - PR attribution: addAttributionToPR() in shell.ts detects `gh pr create` and appends "🤖 Generated with Qwen Code (N-shotted by Qwen-Coder)" - Session baseline: saves content hash on first AI edit of each file for precise human/AI contribution detection - generatePRAttribution() method for programmatic access Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…iled commit counter preservation - Handle initial commit (no HEAD~1) by detecting parent with rev-parse and falling back to --root for first commit in repo - Exclude Cron-triggered messages from promptCount (not user-initiated) - Add commitSucceeded parameter to clearAttributions() so failed/disabled commits don't reset the prompts-since-last-commit counter - Add test for clearAttributions(false) behavior Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Motivation
When developers use AI agents to write code, there is no way to distinguish AI-generated changes from human-authored ones in git history. This creates challenges for:
This PR adds automatic, per-file AI contribution tracking that attaches structured metadata to commits without polluting commit messages.
How it works
Example output
{ "version": 1, "generator": "Qwen-Coder", "files": { "src/services/commitAttribution.ts": { "aiCharsAdded": 3200, "aiCharsRemoved": 0, "aiCreated": true, "aiContributionPercent": 100 }, "src/tools/shell.ts": { "aiCharsAdded": 1500, "aiCharsRemoved": 0, "aiCreated": false, "aiContributionPercent": 100 } }, "summary": { "totalAiCharsAdded": 4700, "totalAiCharsRemoved": 0, "totalFilesTouched": 2, "overallAiPercent": 100 } }Design decisions
Edge case behavior
Changed files
New files
Modified files
Test plan
Generated with Claude Code