Install
openclaw skills install oc-codebase-intelligenceIntelligent codebase analysis and understanding with caching. Automatically explores project structure, identifies modules, analyzes dependencies, and answers questions about the codebase. Use when onboarding to a new project, before refactoring, or when you need to understand code relationships.
openclaw skills install oc-codebase-intelligence智能代码库分析工具,自动理解项目结构、模块边界和依赖关系。
Version: 1.1
Features: 增量索引缓存、符号搜索、智能问答、架构图生成、C/C++ 支持 (NEW)
cd /path/to/project
python3 /path/to/codebase-intelligence/scripts/main.py analyze .
第一次会创建 .codebase-intelligence/ 目录并缓存索引。后续查询秒开!
# 查找代码位置
python3 main.py ask "Where is authentication implemented?"
# 了解工作流程
python3 main.py ask "How does the user login flow work?"
# 查找如何修改
python3 main.py ask "What files need to change to add OAuth?"
# 查找类定义
python3 main.py analyze --symbol "UserManager" --symbol-type class
# 查找函数
python3 main.py analyze --symbol "authenticate" --symbol-type func
# 查看文件依赖什么
python3 main.py deps src/auth.py
# 查看什么依赖这个文件
python3 main.py deps src/utils.py --reverse
# Mermaid 图
python3 main.py diagram --format mermaid
# 流程图
python3 main.py diagram --format mermaid-flow --entry-points main.py app.py
| 命令 | 功能 | 示例 |
|---|---|---|
analyze | 分析代码库(带缓存) | main.py analyze . --stats |
analyze --search | 搜索文件 | main.py analyze --search "auth" |
analyze --symbol | 查找符号 | main.py analyze --symbol "User" |
ask | 智能问答 | main.py ask "How does X work?" |
deps | 依赖分析 | main.py deps src/main.py --reverse |
diagram | 生成图表 | main.py diagram --format mermaid |
index | 更新索引 | main.py index --export index.json |
# 第一次:建立索引(可能需要几秒)
python3 main.py analyze .
# 第二次:秒开!
python3 main.py analyze . # 瞬间完成
自动索引:
支持问题类型:
| 语言 | 符号解析 | 依赖提取 |
|---|---|---|
| Python | ✅ | ✅ |
| JavaScript/TypeScript | ✅ | ✅ |
| Go | ✅ | ✅ |
| Java | ✅ | ✅ |
| Rust | ✅ | ⚠️ |
| Ruby | ⚠️ | ⚠️ |
| PHP | ⚠️ | ⚠️ |
# 1. 获取整体概览
python3 main.py analyze /path/to/project --stats
# 2. 了解主要模块
python3 main.py analyze --search "module"
# 3. 查找核心类
python3 main.py analyze --symbol "App" --symbol-type class
# 4. 了解工作流程
python3 main.py ask "How does data flow through the system?"
# 5. 生成架构图
python3 main.py diagram --format mermaid-component
# 1. 检查谁依赖要重构的模块
python3 main.py deps src/old-module.py --reverse --depth 3
# 2. 了解影响范围
python3 main.py ask "What would break if I refactor the auth module?"
# 3. 查看修改建议
python3 main.py ask "How to migrate from class X to class Y?"
# 查看变更影响
python3 main.py ask "What depends on src/utils/helpers.py?"
在 .codebase-intelligence.json 中配置:
{
"ignore": [
"node_modules",
".git",
"*.test.js",
"vendor/"
],
"entryPoints": [
"src/main.py",
"src/index.js"
]
}
默认缓存位置:<project>/.codebase-intelligence/codebase_index.pkl
也可以指定:
python3 main.py analyze . --cache-dir /path/to/cache
python3 main.py analyze --stats
包含:
python3 main.py index --export index.json
结构化数据,包含完整索引信息。
python3 main.py diagram --format mermaid
可直接在 Markdown/GitHub/GitLab 中渲染。
| 项目规模 | 首次索引 | 增量更新 |
|---|---|---|
| 小 (<100文件) | <1s | <0.1s |
| 中 (100-1000文件) | 2-5s | <0.5s |
| 大 (1000-5000文件) | 10-30s | <2s |
skills/codebase-intelligence/
├── SKILL.md # 本文件
└── scripts/
├── main.py # ⭐ 统一入口
├── indexer.py # 索引引擎(带缓存)
├── ask_v2.py # 智能问答
├── analyze.py # 基础分析
├── deps.py # 依赖分析
└── diagram.py # 图表生成
# .git/hooks/pre-commit
python3 scripts/main.py index
# .github/workflows/analysis.yml
- name: Analyze Codebase
run: |
python3 scripts/main.py analyze --stats
python3 scripts/main.py diagram --format mermaid > architecture.md
当前状态:可用,适合日常使用
待完善: