关于 aica - AI Code Analyzer
aica 是面向开发者的开源代码分析命令行工具,提供 AI 代码审查、Agent 任务和 GitHub Actions 支持。它也可作为 MCP 服务运行,并通过符号与向量搜索检索代码上下文。
主要功能
- 01AI 代码审查
- 02AI Agent 任务
- 03符号与向量搜索
- 04生成变更摘要和提交信息
- 05GitHub Actions 集成
- 06自定义提示词
适用场景
- 01审查差异或指定文件
- 02在 GitHub Actions 中自动审查
- 03生成提交信息和拉取请求
MCP 相关
aica 可通过 stdio 或 SSE 启动 MCP 服务,也能通过 MCP 配置文件连接已配置的 MCP 服务。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
aica - AI 代码分析器
动机
目前已有 pr-agent 和 cursor 等出色的代码审查工具。然而,pr-agent 依赖 GitHub 等代码托管服务,限制了它的适用范围;cursor 则不是开源软件,因此无法完全自定义或与其他工具集成。
因此,我决定创建一款具有以下特点的新工具:
- 可自定义
- 开源
- 跨平台
功能
- AI 编码 Agent
- AI 代码审查
- 支持 MCP(Model Context Protocol)。支持 stdio 和 SSE 传输方式。
- 自动检索代码审查所需的知识
- 基于符号的代码搜索,用于检索知识
- 基于向量的文档搜索,用于检索知识
- 生成变更摘要
- 生成提交消息
- 使用 AI 生成的标题和正文创建拉取请求
- 提示词自定义
- Slack 通知
- 通过
bun build --compile构建单个二进制可执行文件 - 集成 GitHub Actions。(请参阅维基页面进行设置。)
安装
构建并安装二进制文件:
# Install bun before build aica.
#
# Official Install Document:
# https://bun.sh/docs/installation#installing
git clone https://github.com/dotneet/aica.git
cd aica
bun install
bun run build
cp ./dist/aica path-to-your-bin-directory
设置 GitHub Token:
# if GITHUB_TOKEN is not set, aica try to get token from `gh auth token`.
export GITHUB_TOKEN=your_github_token
设置大模型:
# You can set the following items in your environment variables or aica.toml file.
# Configure at least one of the following providers:
# Anthropic (If you use agent, strongly recommend to use claude sonnet model)
export AICA_LLM_PROVIDER=anthropic
export ANTHROPIC_API_KEY=your_api_key
export ANTHROPIC_MODEL=claude-3-5-sonnet-20241022
# OpenAI
export AICA_LLM_PROVIDER=openai
export OPENAI_API_KEY=your_api_key
export OPENAI_MODEL=o3-mini
# Gemini
export AICA_LLM_PROVIDER=google
export GOOGLE_API_KEY=your_api_key
export GOOGLE_MODEL=gemini-2.0-flash
配置
你可以创建 aica.toml 文件来自定义配置。
请参阅 aica.example.toml。
aica.toml 必须放在以下目录之一中。
- 仓库根目录
- ${HOME}/.config/aica/aica.toml
- ${GITHUB_WORKSPACE}/aica.toml
语言
你可以指定 AI 输出所使用的语言。可以通过 AICA_LANGUAGE 或 aica.toml 的 language 部分指定语言。默认情况下,程序会根据 LANG 环境变量自动检测语言。
export AICA_LANGUAGE=Japanese
优先级:
AICA_LANGUAGE- aica.toml 中的
language.language - 根据
LANG自动检测
用法
审查
# review the diff from HEAD
aica review [options] [pattern]
# review specific files
aica review src/main.ts
# review the files matching the specific glob pattern
aica review "src/**/*.ts"
选项:
--dir:目标目录路径--slack:发送通知到 Slack
Agent
# execute AI agent with a prompt
aica agent "your prompt here"
# execute AI agent with a instruction file
aica agent -f instruction.txt
# conversation mode. You can interact with AI agent by typing your prompt.
aica agent
此命令使用 AI Agent 执行任务。Agent 会根据给定的提示词自动确定并执行所需操作。
建议使用 anthropic claude 3.5 sonnet 作为 Agent。
注意:此命令可能会破坏你的文件系统,请谨慎使用。
将 Aica Agent 用作 MCP 服务
# start a MCP server
aica mcp server
# start a MCP server with a config file
aica mcp server --config aica.toml
重新索引
# reindex the code and document databases
aica reindex
摘要
# generate a summary of the diff from HEAD
aica summary [options]
选项:
--dir:目标目录路径
提交变更
此命令会使用 AI 生成的提交消息提交变更。
# commit all changes(including untracked and unstaged changes) with an AI-generated commit message
aica commit [options] # commits all changes (including untracked and unstaged changes) with an AI-generated commit message
aica commit --staged # commits only staged changes with an AI-generated commit message
aica commit --push # commits all changes and pushes to remote repository
选项:
--staged:仅提交已暂存的变更。--dryRun:显示结果但不执行--push:提交后推送到远程仓库
创建拉取请求
此命令会在 GitHub 上创建拉取请求。
# Creates a pull request. If there are changes, they will be committed automatically.
aica create-pr [options]
# Creates a pull request with only staged changes
aica create-pr --staged
选项:
--withSummary:生成相对于 HEAD 的差异摘要(默认:true)--body:拉取请求正文--dryRun:显示结果但不执行--staged:仅包含已暂存的变更
生成提交消息
# generate a one-line commit message based on the diff from HEAD
aica commit-message [options]
选项:
--dir:目标目录路径
查看配置
# show current configuration
aica show-config [options]
选项:
--default:显示默认配置
其他命令
aica --version:显示版本信息aica --help [command]:显示指定命令的帮助信息或常规帮助信息
添加上下文
.cursorrules 和 .clinerules 会自动添加到上下文中。 要自定义上下文,请配置 aica.toml 中的 [rules] 部分。
此外,默认支持 .cursor/rules/*.mdc 文件。 可以通过设置禁用此功能。
MCP(Model Context Protocol)
创建 mcp.json 文件以定义 MCP 服务。
示例:
[
{
"name": "example-server",
"type": "stdio",
"command": "node",
"args": ["./server.js"]
},
{
"name": "example-server",
"type": "sse",
"url": "http://localhost:3001/sse"
}
]
在 aica.toml 中设置 setupFile,如下所示。
[mcp]
setupFile = "mcp.json"
GitHub Actions
设置
详情请参阅维基页面。
命令
你可以通过使用以下命令发表评论来与 AI 功能交互。
# edit the code with AI
/aica edit "your prompt here"
# update summary in the pull request body
/aica summary
# review the latest diff
/aica review
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。