使用说明
Axon Go是一个用于AI代码代理的MCP服务器知识图。
Axon的Go重写——为AI代码代理构建知识图。
⚠️ 这是对原版的Go重写 轴突 Harsh Kedia的项目。 原始概念、设计和Python实现的所有功劳都归功于原作者。此Go实现旨在提供单二进制部署、改进的并发性和100%的功能奇偶性。
将任何代码库索引到结构化知识图中——每个依赖关系、调用链、集群和执行流——然后通过智能MCP工具公开它,这样AI代理就不会错过代码。
$ axon-go analyze .
Walking files... 142 files found
Parsing code... 142/142
Tracing calls... 847 calls resolved
Analyzing types... 234 type relationships
Detecting communities... 8 clusters found
Detecting execution flows... 34 processes found
Finding dead code... 8 unreachable symbols
Analyzing git history... 18 coupled file pairs
Generating embeddings... 623 vectors stored
Done in 0.8s — 623 symbols, 1,847 edges, 8 clusters, 34 flows
为什么去?
Go重写提供了对Python原始版本的几个改进:
- ✅ 单二进制部署 --不需要Python运行时、pip或virtualenv
- ✅ 100%特征奇偶校验 --所有12个流水线阶段,13个CLI命令,完整的MCP服务器
- ✅ 多语言支持 --Go、Python和TypeScript解析器
- ✅ 更好的并发性 --用于并行文件处理的Goroutines
- ✅ 观看模式 --对文件更改进行实时重新索引
快速开始
安装
# Install from source
git clone https://github.com/Benny93/axon-go.git
cd axon-go
make build
# Or install via go install
go install github.com/Benny93/axon-go@latest
基本用法
# Index a repository
axon-go analyze .
# Start MCP server with watch mode (auto re-indexes on changes)
axon-go serve --watch
# Search the knowledge graph
axon-go query "authentication handler"
# Get 360° view of a symbol
axon-go context UserService
# Analyze blast radius
axon-go impact ValidateUser --depth 2
# Find dead code
axon-go dead-code
MCP工具
Axon Go为AI代码代理提供了7个MCP工具:
| 工具 | 说明 |
|---|---|
axon_query |
混合搜索(FTS+矢量与RRF融合) |
axon_context |
360°符号视图(调用者、被调用者、类型引用) |
axon_impact |
带深度控制的爆破半径分析 |
axon_dead_code |
带豁免的死代码检测 |
axon_detect_changes |
变更检测和影响分析 |
axon_list_repos |
列出索引存储库 |
axon_cypher |
原始图形查询(存根,目前不支持) |
MCP配置示例
重要!在将其用于项目之前,您需要运行 axon-go analyze . 在你的项目中。
~/.qwen/settings.json中qwen-cli的配置示例
...
"mcp": {
"allowed": ["axon-go"]
},
"mcpServers": {
"axon-go": {
"args": [
"serve",
"--watch"
],
"command": "<pathtoGoBin>/go/bin/axon-go",
"timeout": 60000,
"trust": true,
"env": {},
"includeTools": [
"axon_query",
"axon_context",
"axon_impact",
"axon_dead_code",
"axon_list_repos",
"axon_cypher"
]
}
}
命令行命令
| 命令 | 描述 |
|---|---|
analyze [path] |
将知识库索引到知识图中 |
query <query> |
使用混合搜索(FTS+矢量)进行搜索 |
context <symbol> |
获得符号的360°视图 |
impact <symbol> |
分析爆破半径(可配置深度) |
dead-code |
列出无法访问/死代码符号 |
watch |
带有实时重新索引的观看模式 |
diff <range> |
结构分支比较 |
setup |
为AI工具配置MCP |
mcp |
启动MCP服务器 |
serve [--watch] |
具有可选监视模式的MCP服务器 |
list |
列出索引存储库 |
status |
显示索引状态 |
clean [-f] |
删除索引 |
管道阶段
Axon Go通过12个阶段处理代码:
flowchart TD
A[Source Code<br/>Go, Python, TS/JS] --> B[Phase 1: File Walking<br/>Discover files, respect .gitignore]
subgraph Structure[Structure Analysis]
B --> C[Phase 2: Structure<br/>File/Folder nodes]
C --> D[Phase 3: Parsing<br/>Extract symbols]
D --> E[Phase 4: Imports<br/>Resolve imports]
E --> F[Phase 5: Calls<br/>Trace call chains]
F --> G[Phase 6: Heritage<br/>Inheritance/interfaces]
G --> H[Phase 7: Types<br/>Type references]
end
subgraph Analysis[Global Analysis]
H --> I[Phase 8: Communities<br/>Louvain clustering]
I --> J[Phase 9: Processes<br/>Execution flows]
J --> K[Phase 10: Dead Code<br/>3-pass analysis]
K --> L[Phase 11: Git Coupling<br/>Co-change history]
end
subgraph Storage[Storage & Indexing]
L --> M[Phase 12: Embeddings<br/>TF-IDF vectors]
M --> N[(BadgerDB<br/>Key-Value Store)]
M --> O[FTS Index<br/>BM25]
M --> P[Vector Index<br/>Cosine Similarity]
end
subgraph Access[Access Layer]
N --> Q[MCP Server<br/>7 Tools]
O --> Q
P --> Q
N --> R[CLI<br/>13 Commands]
O --> R
P --> R
end
subgraph Consumers[Consumers]
Q --> S[AI Agents<br/>Claude Code, Cursor]
R --> T[Developers<br/>Terminal]
end
style Structure fill:#e1f5ff
style Analysis fill:#fff4e1
style Storage fill:#e8f5e9
style Access fill:#f3e5f5
style Consumers fill:#ffebee
| 阶段 | 名称 | 描述 |
|---|---|---|
| 1 | 文件漫游 | 发现文件,尊重.gitignore |
| 2 | 结构 | 创建具有CONTAINS边的文件/文件夹节点 |
| 3 | 解析 | 提取符号(函数、类等) |
| 4 | 导入 | 解析导入语句 |
| 5 | 调用 | 跟踪函数/方法调用 |
| 6 | 遗产 | 跟踪扩展/实施关系 |
| 7 | 类型 | 分析USES_TYPE关系 |
| 8 | 社区 | 检测代码簇(Louvain算法) |
| 9 | 进程 | 检测来自入口点的执行流 |
| 10 | 死代码 | 3遍分析,有豁免 |
| 11 | Git耦合 | 分析共同变更历史 |
| 12 | 嵌入 | 生成用于语义搜索的TF-IDF向量 |
支持的语言
| 语言 | 分析器 | 状态 |
|---|---|---|
| 去吧 | go/parser (AST) |
✅ 全力支持 |
| Python | 基于正则表达式 | ✅ 全力支持 |
| Types/TSX | 基于正则表达式 | ✅ 全力支持 |
| JavaScript | 基于正则表达式 | ✅ 全力支持 |
存储
- 后端: BadgerDB(嵌入式键值存储)
- 全文搜索: 自定义BM25实施
- 矢量搜索: 具有余弦相似性的TF-IDF嵌入
- 混合搜索: 互易秩融合(RRF)
例子
MCP工具使用
Axon Go的知识图谱(由BadgerDB提供支持)通过MCP工具公开。以下是AI代理如何与之交互:
启动MCP服务器:
axon-go serve --watch
工具调用示例:
// 1. Search for symbols related to "authentication"
{
"tool": "axon_query",
"arguments": {
"query": "authentication handler",
"limit": 10
}
}
// 2. Get 360° view of a symbol (callers, callees, type refs)
{
"tool": "axon_context",
"arguments": {
"symbol": "UserService.ValidateUser"
}
}
// 3. Analyze blast radius before refactoring
{
"tool": "axon_impact",
"arguments": {
"symbol": "Database.Connect",
"depth": 2
}
}
// 4. Find unreachable/dead code
{
"tool": "axon_dead_code"
}
// 5. Detect changes and their impact
{
"tool": "axon_detect_changes",
"arguments": {
"paths": ["src/auth.go", "src/user.go"]
}
}
// 6. List all indexed repositories
{
"tool": "axon_list_repos"
}
示例工作流:重构函数
- 找到符号:
axon_query("user validation logic") - 了解依赖关系:
axon_context("UserService.ValidateUser") - 检查冲击:
axon_impact("UserService.ValidateUser", depth=2) - 做出改变 (AI编辑代码)
- 确认无破损:
axon_detect_changes(paths=["src/user.go"])
BadgerDB后端(内部)
MCP工具查询存储在BadgerDB中的知识图。密钥存储方法:
| 方法 | 说明 |
|---|---|
Initialize(path, readOnly) |
在路径上打开BadgerDB |
GetNode(ctx, id) |
检索图形节点 |
GetCallers(ctx, symbol) |
查找某个符号的所有调用者 |
GetCallees(ctx, symbol) |
查找此符号所调用的所有符号 |
HybridSearch(ctx, query, limit) |
组合关键字+矢量搜索 |
VectorSearch(ctx, vector, limit) |
通过嵌入进行语义搜索 |
GetDeadCode(ctx) |
查找无法访问的符号 |
GetNodesByLabel(ctx, label) |
按标签查询节点 |
项目结构
axon-go/
├── cmd/ # CLI commands
├── internal/
│ ├── embeddings/ # TF-IDF embedding generation
│ ├── graph/ # Knowledge graph data model
│ ├── ingestion/ # 12-phase pipeline
│ ├── parsers/ # Language parsers
│ └── storage/ # BadgerDB backend
├── mcp/ # MCP server
├── Makefile # Build targets
└── go.mod # Go module definition
发展
# Build
make build
# Run tests
make test
# Run linter
make lint
# Run all checks
make check
# Clean build artifacts
make clean
从Python Axon迁移
# Uninstall Python version
pip uninstall axon
# Install Go version
go install github.com/Benny93/axon-go@latest
# Re-index (index format is different)
axon-go analyze .
保持不变的是:
- 所有CLI命令的工作方式相同
- MCP工具具有相同的名称和行为
- 输出格式兼容
改进之处:
- 单二进制部署
- 通过goroutines提高并发性
致谢
这个项目是Go重写的 轴突 通过 严厉的凯迪亚.
- 原始概念和设计: 严厉的凯迪亚
- Python实现: 严厉的凯迪亚
- Go实施: 本杰明·沃尔默
最初的愿景、架构和Python实现的所有功劳都属于原作者。这个Go实现旨在通过改进的部署特性来保留和扩展这项工作。
许可证
MIT许可证
贡献
欢迎投稿!
- 分叉存储库
- 创建要素分支
- 进行更改
- 运行测试:
make test - 运行门楣:
make lint - 提交拉取请求
内置于❤️ 使用Go