rai-lint:强制每次提交标注 AI 署名
anchildress1/rai-lint
rai-lint 是一款强制在每次 Git 提交中标注 Responsible AI(RAI)署名的工具,缺少有效 AI 署名 footer 的提交会被直接拒绝。
What is this? 🤖
RAI Lint enforces Responsible AI (RAI) attribution in every commit. No more "who wrote this?" moments. No more mystery code. Just honest, trackable AI contributions.
Read the full story: Did AI Erase Attribution? Your Git History Is Missing a Co-Author
%%{init: {'theme':'dark'}}%%
flowchart LR
A[Developer Commits] --> B{Has AI Footer?}
B -->|Yes| C[Commit Accepted ✅]
B -->|No| D[Commit Rejected ❌]
C --> E[Clear AI Attribution]
D --> F[Add Footer & Retry]
Loading
Why does this exist?
Because transparency matters. When AI writes code, everyone should know. This isn't about fear or compliance theater—it's about building trust and maintaining clear audit trails.
Features 🎯
🔒 Enforcement by DefaultBlocks commits without valid AI attribution footers. No exceptions. 🌍 Dual-Language SupportNative plugins for both JavaScript/TypeScript ( |
📊 Five Attribution LevelsFrom human-only to AI-generated, track exactly who did what. ⚡ Zero Config StartWorks out-of-the-box with sensible defaults. Customize when ready. |
Required Commit Footers 🏷
Every commit must include:
- One AI attribution footer (pick the one that fits)
- Signed-off-by footer (your human accountability stamp —
git commit -s)
💡 Complete audit trail: AI attribution plus human accountability.
gitlint-raienforces both out of the box; for commitlint, enable the plugin'srai-signed-off-byrule alongsiderai-footer-exists.
AI Attribution Footers
Pick one of these based on AI involvement:
| Footer Format | When to Use | Example |
|---|---|---|
Authored-by |
Human-only work, zero AI involvement | Authored-by: Jane Doe <jane@example.com> |
Commit-generated-by |
Trivial AI help (docs, messages, reviews) | Commit-generated-by: ChatGPT <chatgpt@openai.com> |
Assisted-by |
AI helped, but human did primary work | Assisted-by: GitHub Copilot <copilot@github.com> |
Co-authored-by |
Roughly 50/50 AI and human split | Co-authored-by: Verdent AI <verdent@verdent.ai> |
Generated-by |
Majority AI-generated code | Generated-by: GitHub Copilot <copilot@github.com> |
Signed-off-by Footer
Human accountability. This is YOUR stamp confirming you reviewed and take responsibility for the AI attribution above.
Format: Signed-off-by: Your Name <your.email@example.com>
Automate it: git commit -s (or --signoff)
Note
All patterns are case-insensitive and follow the Git trailer format. Email addresses must use angle brackets (Name <email@example.com>) — this is stricter than Git's spec but matches Git's own convention and ensures consistency.
Both plugins ship a rai-signed-off-by rule that enforces this footer. gitlint-rai enables it by default (rule id UC2; opt out with ignore=rai-signed-off-by in .gitlint). For commitlint, add 'rai-signed-off-by': [2, 'always'] to your rules.
Installation 📦
Node.js / Commitlint
npm install --save-dev commitlint-plugin-rai
Configure in commitlint.config.js:
export default { extends: ['@commitlint/config-conventional'], plugins: ['commitlint-plugin-rai'], rules: { 'rai-footer-exists': [2, 'always'], 'rai-signed-off-by': [2, 'always'], }, };
Python / Gitlint
uv add gitlint-rai
Run the bundled gitlint-rai CLI (recommended) — it loads the RAI rules automatically and accepts all gitlint arguments:
gitlint-rai --msg-filename .git/COMMIT_EDITMSG
Or point plain gitlint at the installed package in .gitlint:
[general] extra-path=/path/to/site-packages/gitlint_rai
Get that path with:
python -c "import gitlint_rai, pathlib; print(pathlib.Path(gitlint_rai.__file__).parent)"Quick Start 🚀
Hook Integration
Lefthook
commit-msg: commands: commitlint: run: npx --no-install commitlint --edit {1}
Husky
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'pre-commit
repos: - repo: local hooks: - id: gitlint name: gitlint entry: gitlint-rai args: [--msg-filename] language: python additional_dependencies: ['gitlint-rai'] stages: [commit-msg]
See Your Numbers 📊
Once footers are landing, rai-commit-badge reads them back out of your history and publishes a shields.io badge. Mark the spot, and the action fills it in:
<!--START_SECTION:rai-badge--> <!--END_SECTION:rai-badge-->
It weights each commit by lines changed and scores the five footers on an ordinal scale, so a typo fix doesn't outvote a generated module.
The split is deliberate: rai-lint gates, rai-commit-badge measures. Neither does the other's job.
Monorepo Structure 🛠️
rai-lint/
├── packages/
│ ├── node-commitlint/ # Node.js/ESM plugin
│ │ ├── src/
│ │ │ ├── rules/
│ │ │ │ ├── rai-footer-exists.ts
│ │ │ │ └── rai-signed-off-by.ts
│ │ │ └── index.ts
│ │ |── package.json
│ │ ├── tests/
│ │
│ └── python-gitlint/ # Python plugin
│ ├── gitlint_rai/
│ │ ├── __init__.py
│ │ └── rules.py
│ ├── tests/
│ └── pyproject.toml
│
├── docs/ # Documentation
Contributing 🤝
Contributions welcome! See CONTRIBUTING.md for guidelines.
License 📄
This runs on the PolyForm Shield License 1.0.0 — not open source, but permissive for everyday use.
In plain English: use it, modify it, ship it in your product or CI pipeline, enforce commit messages on your team. The one thing Shield forbids is competing — reselling, rebranding, or hosting this as a paid or free substitute for the tool itself. Planning that? Email me first: anchildress1@gmail.com.
Redistributing? Keep the license (or its URL) and any Required Notice: lines intact. That's the whole ask.
Show Some Love 🫶
If you find this project useful or want to support its development, consider starring the repo or connecting with me!
Stop guessing. Start tracking.
Co-authored-by: Claude, Codex, Verdent AI & GitHub Copilot
来源:GitHub · github.com