跳到正文
Skillpedia
通用编程6.2k · #14387

code-search

它能做什么

这项技能帮助智能体使用 ripgrep 和 Git 快速搜索代码,而不是逐个读取整个文件。适合需要找到某个函数定义或使用位置的开发者。

适用场景

  • ✓当你需要找到某个函数、类或符号的定义位置时。
  • ✓当你想找出项目中某个名称被使用的每一处时。
  • ✓当你需要查明某行代码何时或为何被修改的时候。

技能链接

https://github.com/agentscope-ai/agentscope-java/blob/main/agentscope-examples/agents/agentscope-codingagent/src/main/resources/workspace-templates/skills/code-search/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/agentscope-ai/agentscope-java/blob/main/agentscope-examples/agents/agentscope-codingagent/src/main/resources/workspace-templates/skills/code-search/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请在这个项目中找出函数 calculateTax 被定义或调用的每一处。”

每周 5 个新技能,1 分钟读完。

工作原理

这项技能使用 ripgrep 进行正则表达式搜索,并可按文件类型筛选;使用 Git 历史命令追踪某个字符串何时被添加,或某行是谁修改的。它会让搜索结果保持精简,使输出保持较小。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Code Search

The built-in grep tool matches LITERAL text only. For real regular-expression search and history-aware lookups, drive ripgrep and git through execute.

Ripgrep (regex)

  • Symbol definition: rg -n "fn\s+\w+\(" src/, rg -n --type java "class \w+Service".
  • Usages of a name: rg -n "\bmyFunction\b".
  • Limit by file type: rg -n --type ts "useEffect\(".
  • List files only: rg -l "TODO"; find files by name: rg --files | rg <name> or use glob.

Git history search

  • When a string was introduced/removed: git log -S "<string>" --oneline.
  • Who/why a line changed: git blame -L <start>,<end> <file>.
  • Search tracked files: git grep -n "<regex>".

Tips

  • Prefer a targeted regex over reading whole files when locating symbols or call sites.
  • Escape regex metacharacters when you want a literal match, or pass -F to ripgrep.
  • Narrow scope with a path argument to keep output small (tool output is truncated).
常见问题

它需要 ripgrep 吗?

需要。这项技能使用 ripgrep 进行正则表达式搜索。

它能搜索 Git 历史吗?

能。它可以找出某个字符串何时被添加或删除,以及某行由谁修改。

为什么不直接读取整个文件?

有针对性的搜索能让结果更简短,也更便于处理。

详情

作者的原始描述

Search a codebase efficiently with ripgrep regular expressions, file globs, and git history search. Use to locate symbols, usages, and definitions instead of reading whole files.

repo: agentscope-ai/agentscope-java

热度

GitHub 星标
6.2k
排名
#14387
许可证
Apache-2.0
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能