code-context-finder
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Context Finder
代码上下文查找器(Code Context Finder)
Overview
概述
Find and surface relevant context while coding by combining knowledge graph search with code relationship analysis. Uses smart detection to identify when additional context would be helpful, then retrieves:
- Knowledge graph entities: Prior decisions, project context, related concepts
- Code relationships: Dependencies, imports, function calls, class hierarchies
通过结合知识图谱搜索与代码关系分析,在编码过程中查找并展示相关上下文。利用智能检测识别何时需要额外上下文支持,随后检索:
- Knowledge graph entities:过往决策、项目上下文、相关概念
- Code relationships:依赖关系、导入项、函数调用、类层级
When to Use (Smart Detection)
适用场景(智能检测触发)
This skill activates automatically when detecting:
| Trigger | What to Search |
|---|---|
| Opening unfamiliar file | Knowledge graph for file/module context, code for imports/dependencies |
| Working on new feature | Prior decisions, related concepts, similar implementations |
| Debugging errors | Related issues, error patterns, affected components |
| Refactoring code | Dependent files, callers/callees, test coverage |
| Making architectural decisions | Past ADRs, related design docs, established patterns |
| Touching config/infra files | Related deployments, environment notes, past issues |
For detection triggers reference, load .
references/detection_triggers.md该工具会在检测到以下场景时自动激活:
| 触发条件 | 搜索内容 |
|---|---|
| 打开不熟悉的文件 | 知识图谱中的文件/模块上下文、代码的导入/依赖关系 |
| 开发新功能 | 过往决策、相关概念、类似实现方案 |
| 调试错误 | 相关问题、错误模式、受影响组件 |
| 重构代码 | 依赖文件、调用方/被调用方、测试覆盖率 |
| 制定架构决策 | 过往ADR、相关设计文档、已确立的模式 |
| 修改配置/基础设施文件 | 相关部署记录、环境说明、过往问题 |
如需参考检测触发的详细模式,请加载。
references/detection_triggers.mdCore Workflow
核心工作流程
1. Detect Context Need
1. 检测上下文需求
Identify triggers that suggest context would help:
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. Search Knowledge Graph
2. 搜索知识图谱
Use MCP memory tools to find relevant entities:
undefined使用MCP内存工具查找相关实体:
undefinedSearch for related context
Search for related context
mcp__memory__search_nodes(query="<topic>")
mcp__memory__search_nodes(query="<topic>")
Open specific entities if known
Open specific entities if known
mcp__memory__open_nodes(names=["entity1", "entity2"])
mcp__memory__open_nodes(names=["entity1", "entity2"])
View relationships
View relationships
mcp__memory__read_graph()
**Search strategies:**
- Module/file names → project context
- Error types → past issues, solutions
- Feature names → prior decisions, rationale
- People names → ownership, expertisemcp__memory__read_graph()
**搜索策略:**
- 模块/文件名 → 项目上下文
- 错误类型 → 过往问题、解决方案
- 功能名称 → 过往决策、设计依据
- 人员姓名 → 归属权、专业领域3. Analyze Code Relationships
3. 分析代码关系
Find code-level context:
python
undefined查找代码层面的上下文:
python
undefinedFind what imports this module
Find what imports this module
grep -r "from module import" --include=".py"
grep -r "import module" --include=".py"
grep -r "from module import" --include=".py"
grep -r "import module" --include=".py"
Find function callers
Find function callers
grep -r "function_name(" --include="*.py"
grep -r "function_name(" --include="*.py"
Find class usages
Find class usages
grep -r "ClassName" --include="*.py"
grep -r "ClassName" --include="*.py"
Find test coverage
Find test coverage
find . -name "test.py" -exec grep -l "module_name" {} ;
For common search patterns, load `references/search_patterns.md`.find . -name "test.py" -exec grep -l "module_name" {} ;
如需参考常见搜索模式,请加载`references/search_patterns.md`。4. Synthesize Context
4. 整合上下文
Present findings concisely:
markdown
undefined简洁呈现检索结果:
markdown
undefinedContext 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]
undefined知识图谱:
代码关系:
- 被导入方: file1.py, file2.py
- 依赖于: module_a, module_b
- 测试文件: test_module.py(5个测试用例)
建议操作:
- 修改前查看entity
- 考虑对[依赖文件]的影响
undefinedQuick Reference
快速参考
Knowledge Graph Queries
知识图谱查询
| Intent | Query Pattern |
|---|---|
| Find project context | |
| Find prior decisions | |
| Find related concepts | |
| Find people/owners | |
| Browse all | |
| 意图 | 查询模式 |
|---|---|
| 查找项目上下文 | |
| 查找过往决策 | |
| 查找相关概念 | |
| 查找人员/负责人 | |
| 浏览全部内容 | |
Code Relationship Queries
代码关系查询
| Intent | Command |
|---|---|
| Find importers | |
| Find callers | |
| Find implementations | |
| Find tests | |
| Find configs | |
| 意图 | 命令 |
|---|---|
| 查找导入方 | |
| 查找调用方 | |
| 查找实现代码 | |
| 查找测试文件 | |
| 查找配置文件 | |
Integration with Coding Workflow
与编码工作流的集成
Before Making Changes
修改代码前
- Check knowledge graph for context on module/feature
- Find all files that import/depend on target
- Locate relevant tests
- Review prior decisions if architectural
- 检查知识图谱中关于该模块/功能的上下文
- 找到所有导入/依赖目标文件的文件
- 定位相关测试文件
- 若涉及架构层面,查看过往决策
After Making Changes
修改代码后
- Update knowledge graph if significant decision made
- Note new patterns or learnings
- Add observations to existing entities
- 若做出重大决策,更新知识图谱
- 记录新的模式或经验总结
- 将观察结果添加至现有实体中
When Debugging
调试时
- Search knowledge graph for similar errors
- Find all code paths to affected component
- Check for related issues/decisions
- Document solution if novel
- 在知识图谱中搜索类似错误
- 找到受影响组件的所有代码路径
- 查看相关问题/决策
- 若为新解决方案,进行文档记录
Resources
资源
references/
references/
- - Detailed trigger patterns for smart detection
detection_triggers.md - - Common search patterns for code relationships
search_patterns.md
- - 智能检测的详细触发模式
detection_triggers.md - - 代码关系的常见搜索模式
search_patterns.md
scripts/
scripts/
- - Analyze imports, dependencies, and call graphs
find_code_relationships.py
- - 分析导入项、依赖关系和调用图的脚本
find_code_relationships.py