Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

ai-coding-utils

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai-coding-utils

AI 编码工具集 — 分析 git 分支的 AI/Human 代码贡献比例

latest
npmnpm
Version
0.1.4
Version published
Weekly downloads
25
66.67%
Maintainers
1
Weekly downloads
 
Created
Source

ai-coding-utils

分析 Git 分支主线中 AI 与人工代码贡献比例的 CLI 工具。通过识别 commit message 中的 Co-Authored-By 标记,按开发者统计 AI 生成代码与手写代码的行数占比。

使用

npx ai-coding-utils commit-stats [branch] [base]

参数:

  • [branch] — 目标分支(默认当前分支)
  • [base] — 基准分支(默认自动检测 main/master)

选项:

  • -d, --dir <path> — 指定 Git 仓库路径
  • --from <ref> — 指定范围起点(commit/tag/branch),跳过自动分叉点检测
  • --from-root — 从仓库起点统计目标分支完整主线历史,适合从零开发且代码都在 main/master 的项目
  • --debug-author <name> — 调试指定开发者的每条 commit 判定明细

示例:

# 分析当前分支相对于 main 的代码贡献
npx ai-coding-utils commit-stats

# 分析指定分支
npx ai-coding-utils commit-stats feature/login

# 指定基准分支
npx ai-coding-utils commit-stats feature/login develop

# 从零开发的项目,统计 main 完整主线历史
npx ai-coding-utils commit-stats main --from-root

# 在指定 feature 分支上调试某个开发者的 commit 判定过程
npx ai-coding-utils commit-stats feature/login --debug-author Philoveritas

AI 识别规则

通过检测 commit message 中是否包含 Co-Authored-By:.*noreply 来判断该 commit 是否为 AI 辅助生成。例如:

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

调试模式下会按 commit 打印完整 message、改动行数、匹配规则、命中证据和最终判定结果,便于核对识别是否符合预期。

统计口径

commit-stats 默认按目标分支的 first-parent 主线统计,并排除 merge commits。

  • 合并进来的 main 或其他旁支提交不会计入 AI/Human 行数占比
  • merge commit 自身也不会参与统计,避免把集成代码误算成主线开发代码
  • 统计目标是“这个分支主线开发出来的代码”,不是“这个范围内所有可达 commit”
  • 行数统计默认聚焦实际代码文件,排除锁文件、文档、纯文本、常见配置文件、构建产物和依赖目录
  • --debug-author 会展示每条 commit 纳入统计的行数,以及被过滤掉的非代码文件行数

输出示例

按开发者输出彩色表格,包含:

  • 每位开发者的 AI 生成行数与手写行数
  • AI/人工代码占比
  • 总 commit 数与总行数汇总

开发

# 监听模式
pnpm dev

# 构建
pnpm build

技术栈

  • TypeScript + ESM
  • commander — CLI 参数解析
  • execa — Git 命令执行
  • chalk + cli-table3 — 终端输出格式化
  • ora — 加载动画

环境要求

  • Node.js >= 18
  • Git

Keywords

ai

FAQs

Package last updated on 15 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts