structural-search by 0xdarkmatter/claude-mods
npx skills add https://github.com/0xdarkmatter/claude-mods --skill structural-search通过抽象语法树(AST)结构搜索代码。查找正则表达式无法可靠匹配的语义模式。
| 工具 | 命令 | 用途 |
|---|---|---|
| ast-grep | sg -p 'pattern' | 基于 AST 的代码搜索 |
| 模式 | 匹配内容 | 示例 |
|---|---|---|
$NAME | 命名标识符 | function $NAME() {} |
$_ | 任意单个节点 |
Search code by its abstract syntax tree (AST) structure. Finds semantic patterns that regex cannot match reliably.
| Tool | Command | Use For |
|---|---|---|
| ast-grep | sg -p 'pattern' | AST-aware code search |
| Pattern | Matches | Example |
|---|---|---|
$NAME | Named identifier | function $NAME() {} |
$_ |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
console.log($_)$$$ | 零个或多个节点 | function $_($$$) {} |
# 1. 查找 console.log 调用
sg -p 'console.log($_)'
# 2. 查找 React hooks
sg -p 'const [$_, $_] = useState($_)'
sg -p 'useEffect($_, [$$$])'
# 3. 查找函数定义
sg -p 'function $NAME($$$) { $$$ }'
sg -p 'def $NAME($$$): $$$' --lang python
# 4. 查找导入语句
sg -p 'import $_ from "$_"'
sg -p 'from $_ import $_' --lang python
# 5. 查找异步模式
sg -p 'await $_'
sg -p 'async function $NAME($$$) { $$$ }'
# 6. 查找错误处理
sg -p 'try { $$$ } catch ($_) { $$$ }'
sg -p 'if err != nil { $$$ }' --lang go
# 7. 查找潜在问题
sg -p '$_ == $_' # 使用 == 而非 ===
sg -p 'eval($_)' # 安全风险
sg -p '$_.innerHTML = $_' # XSS 攻击向量
# 8. 预览重构
sg -p 'console.log($_)' -r 'logger.info($_)'
# 9. 应用重构
sg -p 'var $NAME = $_' -r 'const $NAME = $_' --rewrite
# 10. 搜索特定语言
sg -p 'pattern' --lang typescript
| 任务 | 命令 |
|---|---|
| 查找模式 | sg -p 'pattern' |
| 特定语言 | sg -p 'pattern' --lang python |
| 替换(预览) | sg -p 'old' -r 'new' |
| 替换(应用) | sg -p 'old' -r 'new' --rewrite |
| 显示上下文 | sg -p 'pattern' -A 3 |
| JSON 输出 | sg -p 'pattern' --json |
| 仅文件列表 | sg -p 'pattern' -l |
| 统计匹配数 | sg -p 'pattern' --count |
| 运行 YAML 规则 | sg scan |
完整模式集,请加载:
./references/js-ts-patterns.md - JavaScript/TypeScript 模式./references/python-patterns.md - Python 模式./references/go-rust-patterns.md - Go 和 Rust 模式./references/security-ops.md - 安全漏洞检测./references/advanced-usage.md - YAML 规则与工具集成./assets/rule-template.yaml - 自定义规则入门模板每周安装量
19
代码仓库
GitHub 星标数
8
首次出现
2026年1月24日
安全审计
安装于
claude-code18
opencode17
gemini-cli16
codex16
cursor14
antigravity13
| Any single node |
console.log($_) |
$$$ | Zero or more nodes | function $_($$$) {} |
# 1. Find console.log calls
sg -p 'console.log($_)'
# 2. Find React hooks
sg -p 'const [$_, $_] = useState($_)'
sg -p 'useEffect($_, [$$$])'
# 3. Find function definitions
sg -p 'function $NAME($$$) { $$$ }'
sg -p 'def $NAME($$$): $$$' --lang python
# 4. Find imports
sg -p 'import $_ from "$_"'
sg -p 'from $_ import $_' --lang python
# 5. Find async patterns
sg -p 'await $_'
sg -p 'async function $NAME($$$) { $$$ }'
# 6. Find error handling
sg -p 'try { $$$ } catch ($_) { $$$ }'
sg -p 'if err != nil { $$$ }' --lang go
# 7. Find potential issues
sg -p '$_ == $_' # == instead of ===
sg -p 'eval($_)' # Security risk
sg -p '$_.innerHTML = $_' # XSS vector
# 8. Preview refactoring
sg -p 'console.log($_)' -r 'logger.info($_)'
# 9. Apply refactoring
sg -p 'var $NAME = $_' -r 'const $NAME = $_' --rewrite
# 10. Search specific language
sg -p 'pattern' --lang typescript
| Task | Command |
|---|---|
| Find pattern | sg -p 'pattern' |
| Specific language | sg -p 'pattern' --lang python |
| Replace (preview) | sg -p 'old' -r 'new' |
| Replace (apply) | sg -p 'old' -r 'new' --rewrite |
| Show context | sg -p 'pattern' -A 3 |
| JSON output | sg -p 'pattern' --json |
| File list only | sg -p 'pattern' -l |
| Count matches | sg -p 'pattern' --count |
| Run YAML rules | sg scan |
For complete patterns, load:
./references/js-ts-patterns.md - JavaScript/TypeScript patterns./references/python-patterns.md - Python patterns./references/go-rust-patterns.md - Go and Rust patterns./references/security-ops.md - Security vulnerability detection./references/advanced-usage.md - YAML rules and tool integration./assets/rule-template.yaml - Starter template for custom rulesWeekly Installs
19
Repository
GitHub Stars
8
First Seen
Jan 24, 2026
Security Audits
Installed on
claude-code18
opencode17
gemini-cli16
codex16
cursor14
antigravity13
AI新闻播客制作技能:实时新闻转对话式播客脚本与音频生成
1,200 周安装