npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-code-stats

v1.0.0

Published

AI 编码统计工具 - 通过 Git hooks 自动采集 AI 辅助编程的统计数据

Readme

AI Code Stats

通过 Git hooks 自动采集 AI 辅助编程的统计数据。量化你的 AI 编码贡献 — 生成率、采纳率、留存率,一目了然。

特性

  • 🔄 Git hooks 自动追踪,init 一次即可持续采集
  • 🤖 多源检测:注释标记、AI 工具目录扫描、文件变更速度分析、交互式提示
  • 📊 三大核心指标:AI 生成率 / 采纳率 / 留存率
  • 🗄️ 本地 SQLite 存储,数据不外泄
  • 📋 表格和 JSON 两种报告格式
  • 🛠️ 支持 Cursor、Claude Code、GitHub Copilot、Continue、Codeium 等 AI 工具检测

安装

npm install -g ai-code-stats

快速开始

# 在 Git 仓库中初始化
cd your-project
ai-stats init

# 正常开发和提交,hooks 会自动采集数据
# pre-commit 时会询问是否使用了 AI 辅助

# 查看当前状态
ai-stats status

# 生成报告
ai-stats report
ai-stats report --format json

命令

| 命令 | 说明 | |------|------| | ai-stats init | 初始化项目,创建数据库和安装 Git hooks | | ai-stats mark <file> --model <name> --percentage <n> | 手动标记文件的 AI 代码占比 | | ai-stats confirm [session-id] | 确认会话完成 | | ai-stats status | 查看三大核心指标和活跃会话 | | ai-stats report [--format table\|json] | 生成统计报告 | | ai-stats config set\|get\|list <key> [value] | 管理配置 | | ai-stats stop | 停止文件监控守护进程 |

核心指标

AI 生成率 = AI 代码行数 / (AI + 人工) × 100%

采纳率 = 被接受的 AI 代码行数 / AI 生成总行数 × 100%

留存率 = 仍保留的 AI 代码行数 / 已采纳 AI 代码行数 × 100%

AI 代码检测方式

系统按以下优先级合并多个检测源的结果:

  1. 注释标记 — 在代码中添加 // @ai-generated: <model> 注释(支持 //#/* */
  2. AI 工具检测 — 自动扫描 .cursor/.claude/.github/copilot/ 等目录
  3. 文件监控 — 后台检测短时间内大量代码写入(疑似 AI 生成)
  4. 交互式提示 — commit 时询问用户是否使用了 AI

配置

# 设置默认 AI 模型
ai-stats config set default_model gpt-4

# 设置默认报告格式
ai-stats config set default_format json

# 关闭 commit 时的交互式提示
ai-stats config set prompt_on_commit false

# 查看所有配置
ai-stats config list

数据存储

所有数据存储在项目本地 .ai-stats/ 目录中:

.ai-stats/
├── stats.db        # SQLite 数据库
├── config.json     # 配置文件
├── reports/        # 生成的报告
├── pending.json    # 待确认的 AI 变更
└── error.log       # 错误日志

建议将 .ai-stats/ 添加到 .gitignore

开发

# 安装依赖
npm install

# 运行测试
npm test

# 构建
npm run build

技术栈

TypeScript · SQLite (better-sqlite3) · commander.js · simple-git · chokidar · inquirer · Vitest · fast-check

License

MIT