关于 code-context-finder
Code Context Finder 是一种编码技能,结合知识图谱搜索与代码关系分析,帮助开发者在探索、调试或修改代码库时查找既有决策、依赖关系、调用者和相关测试。
主要功能
- 01自动检测上下文需求
- 02搜索知识图谱实体
- 03分析导入与依赖关系
- 04查找调用方和测试
适用场景
- 01探索不熟悉的模块
- 02追踪错误涉及的组件
- 03重构前检查依赖
- 04架构工作中查阅既有决策
MCP 相关
它使用 MCP memory 工具搜索和打开知识图谱实体,并查看图谱关系。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ 89jobrien/ steve --skill code-context-finder安装后在 Claude Code 中输入/code-context-finder确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/detection-triggers.mdsearch-patterns.mdscripts/find-code-relationships.py详细介绍
代码上下文查找器
概述
通过结合知识图谱搜索与代码关系分析,在编码时查找并呈现相关上下文。使用智能检测识别何时需要更多上下文,然后检索:
- 知识图谱实体:以往的决策、项目背景、相关概念
- 代码关系:依赖项、导入、函数调用、类层次结构
何时使用(智能检测)
检测到以下情况时,此技能会自动启用:
| 触发条件 | 搜索内容 |
|---|---|
| 打开不熟悉的文件 | 在知识图谱中查找文件/模块背景,在代码中查找导入/依赖项 |
| 开发新功能 | 以往的决策、相关概念、类似实现 |
| 调试错误 | 相关问题、错误模式、受影响的组件 |
| 重构代码 | 依赖文件、调用方/被调用方、测试覆盖率 |
| 做出架构决策 | 以往的 ADR、相关设计文档、既定模式 |
| 修改配置/基础设施文件 | 相关部署、环境说明、以往的问题 |
如需查看检测触发条件参考,请加载 references/detection_triggers.md。
核心工作流
1. 检测上下文需求
识别表明需要上下文的触发条件:
Signals to watch:
- New/unfamiliar file opened
- Error messages mentioning unknown components
- Questions about "why" or "how" something works
- Changes to shared/core modules
- Architectural or design discussions
2. 搜索知识图谱
使用 MCP memory 工具查找相关实体:
# Search for related context
mcp__memory__search_nodes(query="<topic>")
# Open specific entities if known
mcp__memory__open_nodes(names=["entity1", "entity2"])
# View relationships
mcp__memory__read_graph()
搜索策略:
- 模块/文件名 → 项目背景
- 错误类型 → 以往的问题、解决方案
- 功能名称 → 以往的决策、理由
- 人名 → 所有权、专业领域
3. 分析代码关系
查找代码层面的上下文:
# Find what imports this module
grep -r "from module import" --include="*.py"
grep -r "import module" --include="*.py"
# Find function callers
grep -r "function_name(" --include="*.py"
# Find class usages
grep -r "ClassName" --include="*.py"
# Find test coverage
find . -name "*test*.py" -exec grep -l "module_name" {} \;
如需查看常见搜索模式,请加载 references/search_patterns.md。
4. 综合上下文
简洁地呈现发现:
## Context Found
**Knowledge Graph:**
- [Entity]: Relevant observation
- [Decision]: Prior architectural choice
**Code Relationships:**
- Imported by: file1.py, file2.py
- Depends on: module_a, module_b
- Tests: test_module.py (5 tests)
**Suggested Actions:**
- Review [entity] before modifying
- Consider impact on [dependent files]
快速参考
知识图谱查询
| 意图 | 查询模式 |
|---|---|
| 查找项目背景 | search_nodes("project-name") |
| 查找以往的决策 | search_nodes("decision") 或 search_nodes("<feature>") |
| 查找相关概念 | search_nodes("<concept>") |
| 查找相关人员/负责人 | search_nodes("<person-name>") |
| 浏览全部内容 | read_graph() |
代码关系查询
| 意图 | 命令 |
|---|---|
| 查找导入方 | grep -r "from X import|import X" |
| 查找调用方 | grep -r "function(" |
| 查找实现 | grep -r "def function|class Class" |
| 查找测试 | find -name "*test*" -exec grep -l "X" |
| 查找配置 | grep -r "X" *.json *.yaml *.toml |
与编码工作流集成
修改前
- 在知识图谱中查找模块/功能的相关背景
- 查找所有导入/依赖目标项的文件
- 定位相关测试
- 如果涉及架构,回顾以往的决策
修改后
- 如果做出了重要决策,更新知识图谱
- 记录新的模式或经验
- 将观察结果添加到现有实体中
调试时
- 在知识图谱中搜索类似错误
- 查找所有通往受影响组件的代码路径
- 检查相关问题/决策
- 如果解决方案具有新颖性,则记录下来
资源
references/
detection_triggers.md- 智能检测的详细触发模式search_patterns.md- 代码关系的常见搜索模式
scripts/
find_code_relationships.py- 分析导入、依赖项和调用图
评论
支持 Markdown