find-similar-functions
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSimilar Function Finder
相似函数查找工具使用指南
Use this skill before writing new JavaScript or TypeScript code that might overlap with existing helpers. The goal is to discover nearby functions, methods, constants, types, and interfaces early enough to reuse or extend them instead of creating duplicate behavior.
truffler在编写可能与现有辅助函数重叠的JavaScript或TypeScript代码前,请使用此技能。目标是尽早发现相关的函数、方法、常量、类型和接口,以便复用或扩展它们,而非创建重复的功能。
trufflerWorkflow
工作流程
- State the behavior you are about to implement in a few words.
- Derive 3-6 search queries from the intended behavior:
- the proposed function or class name
- domain nouns, such as ,
symbol,path,file,route, ortokenconfig - verbs, such as ,
parse,normalize,discover,scan,format,rank,score, orresolvevalidate - common abbreviations and synonyms, such as for
btnorbuttonforcfgconfig
- Run against the narrowest useful root first, then broaden if needed.
truffler - Inspect the top matches with normal code-reading tools before editing.
- Prefer reusing, extending, or moving existing code when the behavior substantially matches. Create new code only after the search shows there is not a suitable existing symbol.
- In your final response, briefly mention what you found and whether you reused something or intentionally added a new implementation.
- 用几句话描述你即将实现的功能。
- 根据预期功能生成3-6个搜索查询词:
- 拟命名的函数或类名称
- 领域名词,例如 、
symbol、path、file、route或tokenconfig - 动词,例如 、
parse、normalize、discover、scan、format、rank、score或resolvevalidate - 常见缩写和同义词,例如用 指代
btn,用button指代cfgconfig
- 先在最精准的根目录下运行 ,若需要再扩大范围。
truffler - 使用常规代码阅读工具检查排名靠前的匹配结果,再进行编辑。
- 当现有符号的功能与需求高度匹配时,优先选择复用、扩展或迁移现有代码。仅当搜索结果显示没有合适的现有符号时,再创建新代码。
- 在最终回复中,简要说明你发现了什么,以及是复用了现有代码还是有意添加了新实现。
Command Recipes
命令示例
When is installed in the target project:
trufflerbash
truffler "normalize path" src --kind function,method,constant,type --limit 20
truffler "score" src --kind function,method --format json --limit 15When working inside this repository:
trufflerbash
bun src/cli.ts "discover file" src --kind function,method,constant,type --limit 20
bun src/cli.ts "format result" src --kind function,method --format json --limit 15When the project has no installed binary and you should not add dependencies, use if network/package execution is acceptable for the environment:
bunxbash
bunx @rayhanadev/truffler "parse config" src --kind function,method,type --limit 20If cannot be run, say so and fall back to the repository's available search tools. Still follow the same deduplication intent: search before implementing.
truffler当目标项目中已安装 时:
trufflerbash
truffler "normalize path" src --kind function,method,constant,type --limit 20
truffler "score" src --kind function,method --format json --limit 15在 自身代码库中工作时:
trufflerbash
bun src/cli.ts "discover file" src --kind function,method,constant,type --limit 20
bun src/cli.ts "format result" src --kind function,method --format json --limit 15当项目未安装二进制文件且不应添加依赖时,如果环境允许网络/包执行,可使用 :
bunxbash
bunx @rayhanadev/truffler "parse config" src --kind function,method,type --limit 20若无法运行 ,请说明情况并改用代码库中可用的搜索工具。仍需遵循相同的去重原则:先搜索再实现。
trufflerSearch Strategy
搜索策略
Start with symbols most likely to represent reusable behavior:
bash
truffler "<query>" <root> --kind function,method,constant,type,interface --limit 20Use JSON output when you need structured fields for ranking, locations, signatures, or automation:
bash
truffler "<query>" <root> --format json --limit 20Broaden deliberately:
- If a precise function name has no match, search the domain noun and verb separately.
- If a utility may live outside , try known library, package, app, or test roots.
src/ - If there are many matches, restrict and reduce the root rather than skimming unrelated output.
--kind - If top matches look close, read the implementation and nearby tests or call sites before deciding.
从最可能代表可复用功能的符号开始搜索:
bash
truffler "<query>" <root> --kind function,method,constant,type,interface --limit 20当需要用于排序、定位、签名或自动化的结构化字段时,使用JSON输出:
bash
truffler "<query>" <root> --format json --limit 20有策略地扩大搜索范围:
- 如果精确的函数名称没有匹配结果,分别搜索领域名词和动词。
- 如果工具类可能位于 之外,尝试已知的库、包、应用或测试根目录。
src/ - 如果匹配结果过多,限制 参数并缩小根目录范围,而非浏览无关输出。
--kind - 如果排名靠前的结果看起来相近,在做决定前先查看实现代码及相关测试或调用位置。
Reuse Decision Guide
复用决策指南
Consider an existing symbol reusable when it already handles the same input shape, side effects, error behavior, and return shape, or when a small extension would preserve its current contract.
Avoid reusing a symbol just because its name is close. Fuzzy matches can surface unrelated code. Inspect signatures, implementation, callers, and tests before changing anything.
When no suitable symbol exists, keep the new implementation near the closest related module and align with that module's naming, error handling, and test style.
当现有符号已处理相同的输入格式、副作用、错误行为和返回格式,或只需少量扩展即可保持其现有约定时,可认为该符号可复用。
不要仅因名称相近就复用符号。模糊匹配可能会显示无关代码。在修改任何内容前,务必检查签名、实现、调用方和测试。
当没有合适的符号时,将新实现放在最接近的相关模块附近,并与该模块的命名、错误处理和测试风格保持一致。
Reporting Template
报告模板
Use a short note like this when the search affects your implementation:
markdown
I checked for existing symbols with `truffler` using queries like `normalize`, `path`, and `resolve`. The closest match was `normalizePath` in `src/files.ts`, so I reused that behavior instead of adding a separate helper.If nothing relevant exists:
markdown
I searched with `truffler` for `parse`, `config`, and `loadConfig` across `src/`; the matches were unrelated, so I added a new helper in the nearest module.当搜索结果影响你的实现时,可使用如下简短说明:
markdown
我使用 `truffler` 以 `normalize`、`path` 和 `resolve` 为查询词进行了搜索。最接近的匹配是 `src/files.ts` 中的 `normalizePath`,因此我复用了该功能,而非添加单独的辅助函数。若未找到相关内容:
markdown
我使用 `truffler` 在 `src/` 目录下搜索了 `parse`、`config` 和 `loadConfig`;匹配结果均不相关,因此我在最近的模块中添加了一个新的辅助函数。