用途:使用正则表达式搜索文件内容,主要用于在代码库中定位函数定义、查找特定文本模式、确认哪些文件包含某段内容,以及分析代码结构。它针对代码和文本文件做了优化。
主要能力:优先使用 ripgrep(rg),并以 grep 作为回退;支持三种输出模式(content、files_with_matches、count);可用 glob 过滤包含或排除的文件;支持匹配前后上下文行;支持大小写敏感与不敏感搜索;支持多行模式(仅 rg);遵循 .gitignore;可用 --max-results 限制结果数量(默认 1000)。
使用方式:通过 Node 运行脚本,例如基础搜索:node /job/.pi/skills/content-search/search.js --pattern "console.log"。常用选项包括 --pattern(必填,正则)、--path(默认 .)、--include、--exclude、--output-mode、--case-insensitive、--context-before、--context-after、--multiline、--max-results。示例:按文件过滤 node /job/.pi/skills/content-search/search.js --pattern "function.init" --include ".js" --include "*.ts";仅列出含匹配的文件用 --output-mode files_with_matches;统计每文件匹配数用 --output-mode count。
输出格式:content 模式返回 matches 数组(含 file、line、content、before、after)与 totalMatches;files_with_matches 模式返回 files 与 totalFiles;count 模式返回 counts(file、count)与 totalMatches。
适用场景:查找函数定义、导入语句、TODO/FIXME、错误处理等;用 --include 缩小范围,存在性检查可用 files_with_matches,排除 node_modules 可用 --exclude "node_modules/*"。
限制:不适用于二进制文件搜索(应使用 file 命令)、仅文件名匹配(应使用 find 或 glob)、仅对文件名做正则(应使用 find -regex)。多行模式仅 ripgrep 支持。资料未提供安装方式、价格与平台信息。