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

@huchenghe/ai-git

v1.0.1

Published

AI-powered Git context analyzer - 自动分析Git变更、生成Commit Message和代码审查报告

Downloads

356

Readme

ai-git 🚀

AI-powered Git context analyzer — 自动分析 Git 暂存区变更,生成详细的 Markdown 报告,并支持 AI 生成 Commit Message 和代码审查。

GitHub npm version License

功能特性

  • Git 变更分析 — 自动分析 git diff --cached 暂存区变更
  • Markdown 报告 — 生成结构化的变更分析报告
  • 敏感信息脱敏 — 自动检测并脱敏密码、Token、API Key 等敏感信息
  • 交互模式 — 可选择性地包含特定文件
  • AI 集成 — 自动调用 AI 生成 Commit Message 和代码审查
  • 剪贴板复制 — 自动复制报告或 Commit Message 到剪贴板
  • 独立 AI 工具 — 提供独立的 ai-run 命令直接调用 AI 接口

安装

全局安装(推荐)

npm install -g @huchenghe/ai-git
# 或
pnpm add -g @huchenghe/ai-git

安装后即可在任何 Git 仓库中使用 ai-git 命令。

项目内安装

npm install --save-dev @huchenghe/ai-git
# 或
pnpm add -D @huchenghe/ai-git

从源码安装

git clone https://github.com/huchenghepang/ai-git.git
cd ai-git
bun install
bun run build
npm link

快速开始

1. Git 变更分析

在任意 Git 仓库中,先暂存文件:

git add <file>
# 或
git add .

然后运行:

ai-git

这将分析暂存区变更并生成 Markdown 报告,同时自动复制到系统剪贴板。

2. 使用 AI 生成 Commit Message

单次会话设置环境变量:

export AI_API_KEY="your-api-key"
export AI_URL="https://api.deepseek.cn"
export AI_MODEL="deepseek-v4-flash"

全局设置 在 ~/.bashrc~/.zshrc 中添加:

export AI_API_KEY="your-api-key"
export AI_URL="https://api.deepseek.cn"
export AI_MODEL="deepseek-v4-flash"

然后运行:

ai-git -u

AI 会自动分析代码变更并生成符合 Conventional Commits 规范的 Commit Message。

3. 使用 JSON 格式进行 AI 代码审查

ai-git -e -u -j

这将输出详细的 JSON 格式代码审查报告,包含:

  • 各维度评分(代码规范、复杂度、安全性、可维护性、测试覆盖、性能)
  • 代码亮点和问题列表
  • 综合评分和建议

命令参考

| 命令 | 说明 | |------|------| | ai-git | Git 变更上下文分析器(默认) | | ai-git-review | 快捷命令:ai-git -e -u -j 一键完整 AI 审查 | | ai-run | 独立的 AI 请求工具 |

ai-git — Git 变更分析器

ai-git [选项]

| 选项 | 说明 | |------|------| | -a | 包含完整文件内容(不截断) | | -f <number> | 设置文件最大行数(默认: 50000) | | -l <number> | 设置 diff 上下文行数(默认: 3) | | -i | 交互模式(选择要包含的文件) | | -o <path> | 指定输出文件路径 | | -m <format> | 输出格式(默认: md) | | -r | 禁用敏感信息脱敏 | | -s | 跳过敏感信息检测 | | -u | 上传到 AI 进行分析 | | -j | 强制 AI 输出 JSON 格式(需同时使用 -u) | | -h | 显示帮助信息 |

使用示例:

# 基本分析
ai-git

# 交互模式选择文件
ai-git -i

# 指定输出文件
ai-git -o ./my-report.md

# AI 生成 commit message
ai-git -u

# AI 代码审查(JSON 格式)
ai-git -u -j

# 交互模式 + AI 审查
ai-git -i -u -j

# 包含完整文件内容
ai-git -a

ai-git-review — 快捷命令:一键 AI 代码审查 🚀

等价于 ai-git -e -u -j,一步完成完整 AI 代码审查。

ai-git-review

直接输出 JSON 格式的代码审查报告,包含评分、问题列表、亮点和建议。

ai-run — 独立 AI 请求工具

ai-run [选项] <prompt>
ai-run [选项] --file <path>

| 选项 | 说明 | |------|------| | --json, --forceJson | 强制输出 JSON 格式 | | --file <path>, -f <path> | 从文件读取 prompt 内容 | | --help, -h | 显示帮助信息 |

使用示例:

# 直接传入 prompt
ai-run "请写一首诗"

# 从文件读取
ai-run --file ./prompt.txt

# 强制 JSON 输出
ai-run --json "分析这段代码"

环境变量

| 变量 | 说明 | 默认值 | |------|------|--------| | AI_API_KEY | AI 服务 API 密钥 | —(必填) | | AI_URL | AI 服务地址(如 https://api.openai.com) | —(必填) | | AI_MODEL | AI 模型名称 | deepseek-v4-flash | | AI_TIMEOUT | 请求超时时间(毫秒) | 30000 | | MAX_CHARS | AI 请求最大字符数 | 120000 |

环境变量配置示例

# 方式 1: 直接 export
export AI_API_KEY="sk-xxxxx"
export AI_URL="https://api.openai.com/v1"
export AI_MODEL="gpt-4"

# 方式 2: 单行执行
AI_API_KEY="sk-xxxxx" AI_URL="https://api.openai.com/v1" ai-git -u

输出示例

运行 ai-git 后,会在 logs/commit/ 目录下生成类似如下的 Markdown 报告:

# Git 变更分析报告
- 生成时间: 2026-06-11 12:00:00
- 仓库: my-project
- 分支: feature/new-feature

## 一、变更概览
### 统计信息
 3 files changed, 150 insertions(+), 20 deletions(-)

### 变更文件列表
M       src/utils/ai.ts
A       src/utils/parse-url.ts
M       src/index.ts

## 二、代码变更详情 (git diff --cached)
...

开发指南

本地开发

# 克隆项目
git clone https://github.com/huchenghepang/ai-git.git
cd ai-git

# 安装依赖
bun install

# 启动开发模式
bun src/index.ts

发布到 npm

# 一键发布(交互式选择版本)
bun run release

# 或直接指定版本类型
bun run release -- patch    # 补丁版本 1.0.0 → 1.0.1
bun run release -- minor    # 小版本    1.0.0 → 1.1.0
bun run release -- major    # 大版本    1.0.0 → 2.0.0
bun run release -- 2.0.0    # 自定义版本号

# 该命令会自动完成:
#   1. 检查 Git 工作区是否干净
#   2. 更新版本号
#   3. 执行构建
#   4. 发布到 npm
#   5. Git 打标签并推送

本地测试

发布前可在本地全局测试:

# 方式 1: 直接链接
npm link
# 然后在任意目录测试
ai-git --help

# 方式 2: 使用 .tgz 包
npm pack
npm install -g ./ai-git-1.0.0.tgz

技术栈

许可证

MIT