code-context-finder

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code 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:
TriggerWhat to Search
Opening unfamiliar fileKnowledge graph for file/module context, code for imports/dependencies
Working on new featurePrior decisions, related concepts, similar implementations
Debugging errorsRelated issues, error patterns, affected components
Refactoring codeDependent files, callers/callees, test coverage
Making architectural decisionsPast ADRs, related design docs, established patterns
Touching config/infra filesRelated deployments, environment notes, past issues
For detection triggers reference, load
references/detection_triggers.md
.
该工具会在检测到以下场景时自动激活:
触发条件搜索内容
打开不熟悉的文件知识图谱中的文件/模块上下文、代码的导入/依赖关系
开发新功能过往决策、相关概念、类似实现方案
调试错误相关问题、错误模式、受影响组件
重构代码依赖文件、调用方/被调用方、测试覆盖率
制定架构决策过往ADR、相关设计文档、已确立的模式
修改配置/基础设施文件相关部署记录、环境说明、过往问题
如需参考检测触发的详细模式,请加载
references/detection_triggers.md

Core 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内存工具查找相关实体:
undefined

Search 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, expertise
mcp__memory__read_graph()

**搜索策略:**

- 模块/文件名 → 项目上下文
- 错误类型 → 过往问题、解决方案
- 功能名称 → 过往决策、设计依据
- 人员姓名 → 归属权、专业领域

3. Analyze Code Relationships

3. 分析代码关系

Find code-level context:
python
undefined
查找代码层面的上下文:
python
undefined

Find 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
undefined

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]
undefined
知识图谱:
代码关系:
  • 被导入方: file1.py, file2.py
  • 依赖于: module_a, module_b
  • 测试文件: test_module.py(5个测试用例)
建议操作:
  • 修改前查看entity
  • 考虑对[依赖文件]的影响
undefined

Quick Reference

快速参考

Knowledge Graph Queries

知识图谱查询

IntentQuery Pattern
Find project context
search_nodes("project-name")
Find prior decisions
search_nodes("decision")
or
search_nodes("<feature>")
Find related concepts
search_nodes("<concept>")
Find people/owners
search_nodes("<person-name>")
Browse all
read_graph()
意图查询模式
查找项目上下文
search_nodes("project-name")
查找过往决策
search_nodes("decision")
or
search_nodes("<feature>")
查找相关概念
search_nodes("<concept>")
查找人员/负责人
search_nodes("<person-name>")
浏览全部内容
read_graph()

Code Relationship Queries

代码关系查询

IntentCommand
Find importers
grep -r "from X import|import X"
Find callers
grep -r "function("
Find implementations
grep -r "def function|class Class"
Find tests
find -name "*test*" -exec grep -l "X"
Find configs
grep -r "X" *.json *.yaml *.toml
意图命令
查找导入方
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

Integration with Coding Workflow

与编码工作流的集成

Before Making Changes

修改代码前

  1. Check knowledge graph for context on module/feature
  2. Find all files that import/depend on target
  3. Locate relevant tests
  4. Review prior decisions if architectural
  1. 检查知识图谱中关于该模块/功能的上下文
  2. 找到所有导入/依赖目标文件的文件
  3. 定位相关测试文件
  4. 若涉及架构层面,查看过往决策

After Making Changes

修改代码后

  1. Update knowledge graph if significant decision made
  2. Note new patterns or learnings
  3. Add observations to existing entities
  1. 若做出重大决策,更新知识图谱
  2. 记录新的模式或经验总结
  3. 将观察结果添加至现有实体中

When Debugging

调试时

  1. Search knowledge graph for similar errors
  2. Find all code paths to affected component
  3. Check for related issues/decisions
  4. Document solution if novel
  1. 在知识图谱中搜索类似错误
  2. 找到受影响组件的所有代码路径
  3. 查看相关问题/决策
  4. 若为新解决方案,进行文档记录

Resources

资源

references/

references/

  • detection_triggers.md
    - Detailed trigger patterns for smart detection
  • search_patterns.md
    - Common search patterns for code relationships
  • detection_triggers.md
    - 智能检测的详细触发模式
  • search_patterns.md
    - 代码关系的常见搜索模式

scripts/

scripts/

  • find_code_relationships.py
    - Analyze imports, dependencies, and call graphs
  • find_code_relationships.py
    - 分析导入项、依赖关系和调用图的脚本