find-similar

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Find Similar Patterns

查找相似模式

A conceptual framework for systematically finding similar or analogous code patterns in a codebase.
This skill is factual, not prescriptive. It helps find and report what exists. It does not recommend whether to use, ignore, or modify findings.
Tools available: Grep, Glob, Read, Bash (git commands)

这是一个用于在代码库中系统性查找相似或类似代码模式的概念框架。
本技能是事实性的,而非规范性的。 它帮助查找并报告已存在的内容,不建议是否使用、忽略或修改查找结果。
可用工具: Grep、Glob、Read、Bash(git命令)

Similarity Types

相似类型

"Similar" can mean different things. Identify which type matters before searching.
TypeWhat It MeansExample
LexicalSame names, keywords, identifiers"Where else do we call
formatDate
?"
StructuralSame code shape, different names"Where else do we have retry logic?"
AnalogousSame role in a different domain"What's the equivalent handler in another domain?"
ConceptualSame purpose, potentially different approach"How do we handle validation elsewhere?"

“相似”可以有不同含义。在搜索前需明确关注的类型。
类型含义示例
词汇相似相同的名称、关键字、标识符“我们在其他哪些地方调用了
formatDate
?”
结构相似代码结构相同,名称不同“我们在其他哪些地方有重试逻辑?”
功能类似在不同领域中承担相同角色“另一个领域中的等效处理器是什么?”
概念相似目的相同,实现方式可能不同“我们在其他地方是如何处理验证的?”

Search Strategy

搜索策略

Level 1: Direct Search

第1级:直接搜索

Search for the thing itself or obvious variations.
  • Exact terms, function names, type names
  • Known synonyms or alternate spellings
  • Import/export statements
Stop if: Found clear matches.
搜索目标本身或明显的变体。
  • 精确术语、函数名、类型名
  • 已知同义词或拼写变体
  • 导入/导出语句
停止条件: 找到明确匹配项。

Level 2: Sibling/Peer Discovery

第2级:同级/同类文件发现

Find files that serve the same role.
  • Files in the same directory
  • Files with the same naming pattern (e.g.,
    *.handler.ts
    ,
    use*.ts
    )
  • Files in parallel directories (e.g.,
    domains/users/
    domains/projects/
    )
Stop if: Found peers that reveal the pattern.
查找承担相同角色的文件。
  • 同一目录下的文件
  • 具有相同命名模式的文件(例如:
    *.handler.ts
    use*.ts
  • 平行目录下的文件(例如:
    domains/users/
    domains/projects/
停止条件: 找到能揭示模式的同类文件。

Level 3: Reference Tracing

第3级:引用追踪

Follow the dependency graph.
  • Where is X defined?
  • What imports/uses X?
  • What does X import/use?
Stop if: Found the relevant connected files.
跟随依赖关系图。
  • X在哪里定义?
  • 哪些地方导入/使用了X?
  • X导入/使用了哪些内容?
停止条件: 找到相关的关联文件。

Level 4: Conceptual Expansion

第4级:概念扩展

Broaden the search with related concepts.
  • Synonyms and related terms
  • Different implementations of the same idea
  • Cross-domain analogues
Stop if: Found conceptually similar code, or exhausted reasonable search terms.

用相关概念扩大搜索范围。
  • 同义词和相关术语
  • 同一想法的不同实现
  • 跨领域的类似实现
停止条件: 找到概念相似的代码,或穷尽合理的搜索词。

Confidence Levels

置信度等级

ConfidenceCriteria
HIGHExact or near-exact match; clearly the same pattern
MEDIUMSimilar structure or purpose; some differences
LOWConceptually related; different approach or partial match
Factors that affect confidence:
  • Same directory/domain → higher
  • Same naming conventions → higher
  • Same imports/dependencies → higher
  • Different structure or approach → lower

置信度判定标准
完全或近乎完全匹配;明显是相同模式
结构或目的相似;存在一些差异
概念相关;实现方式不同或部分匹配
影响置信度的因素:
  • 同一目录/领域 → 置信度更高
  • 相同命名规范 → 置信度更高
  • 相同导入/依赖 → 置信度更高
  • 结构或实现方式不同 → 置信度更低

What to Capture (adapt to your context)

需要记录的内容(根据实际情况调整)

Useful information to track for each finding:
  • Location — file path and line range
  • Similarity type — which of the four types applies
  • Confidence — how close is the match
  • Why similar — brief explanation of the relationship
For negative results, note what was searched so coverage can be verified.

为每个查找结果记录以下有用信息:
  • 位置 — 文件路径和行号范围
  • 相似类型 — 符合上述四种类型中的哪一种
  • 置信度 — 匹配的接近程度
  • 相似原因 — 关于关联关系的简要说明
对于未找到结果的情况,记录已搜索的内容,以便验证覆盖范围。

Tips

提示

  • Start narrow, expand as needed — Don't search the entire codebase if a directory search suffices
  • Use file organization as signal — Sibling files often reveal local conventions
  • Git history can help — Files that change together are often related
  • Report what you searched — Helps verify coverage and enables follow-up
  • 从窄范围开始,必要时再扩大 — 如果目录搜索足够,不要搜索整个代码库
  • 利用文件组织作为信号 — 同级文件通常能体现本地规范
  • Git历史记录有帮助 — 一起变更的文件通常相关
  • 报告搜索范围 — 有助于验证覆盖范围并支持后续跟进