重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
code-structural-search by oimiragieo/agent-studio
npx skills add https://github.com/oimiragieo/agent-studio --skill code-structural-search使用 ast-grep 进行基于 AST 的代码模式匹配。
Skill({ skill: 'code-structural-search', args: 'pattern-here --lang ts' });
ast-grep 通过 tree-sitter 支持 20 多种语言:
| 语言 | 标志 | 文件扩展名 |
|---|---|---|
| JavaScript | --lang js | .js, .jsx |
| TypeScript | --lang ts | .ts, .tsx |
| Python |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
--lang py |
| .py, .pyi |
| Go | --lang go | .go |
| Rust | --lang rs | .rs |
| Java | --lang java | .java |
| C | --lang c | .c, .h |
| C++ | --lang cpp | .cpp, .cc, .hpp, .hh |
| C# | --lang cs | .cs |
| Kotlin | --lang kt | .kt, .kts |
| Swift | --lang swift | .swift |
| PHP | --lang php | .php |
| Ruby | --lang rb | .rb |
| Lua | --lang lua | .lua |
| Elixir | --lang ex | .ex, .exs |
| HTML | --lang html | .html, .htm |
| CSS | --lang css | .css |
| JSON | --lang json | .json |
| Bash | --lang bash | .sh, .bash |
| Thrift | --lang thrift | .thrift |
查找所有函数:
function $NAME($ARGS) { $$ }
查找恰好有 2 个参数的函数:
function $NAME($A, $B) { $$ }
查找异步函数:
async function $NAME($ARGS) { $$ }
查找类方法:
class $NAME {
$METHOD($ARGS) { $$ }
}
查找箭头函数:
const $NAME = ($ARGS) => { $$ }
查找 console.log 语句:
console.log($$$)
查找 try-catch 块:
try { $$ } catch ($ERR) { $$ }
查找所有函数:
def $NAME($ARGS): $$$
查找类定义:
class $NAME: $$$
查找异步函数:
async def $NAME($ARGS): $$$
查找导入语句:
import $MODULE
查找 from 导入语句:
from $MODULE import $$$
查找所有函数:
func $NAME($ARGS) $RETURN { $$ }
查找结构体定义:
type $NAME struct { $$$ }
查找接口定义:
type $NAME interface { $$$ }
查找所有函数:
fn $NAME($ARGS) -> $RETURN { $$ }
查找 impl 块:
impl $NAME { $$$ }
查找 pub 函数:
pub fn $NAME($ARGS) -> $RETURN { $$ }
查找所有方法:
public $RETURN $NAME($ARGS) { $$ }
查找类定义:
public class $NAME { $$$ }
查找接口定义:
public interface $NAME { $$$ }
| 符号 | 含义 | 示例 |
|---|---|---|
$NAME | 单个节点/标识符 | function $NAME() {} |
$$$ | 零个或多个语句/节点 | class $NAME { $$$ } |
$$ | 零个或多个语句(块) | if ($COND) { $$ } |
$_ | 匿名通配符(丢弃) | console.log($_) |
与 Ripgrep (grep) 对比:
与语义搜索(Phase 1)对比:
使用 ripgrep 进行广泛搜索:
Skill({ skill: 'ripgrep', args: 'authenticate --type ts' })
使用 ast-grep 进行结构细化:
Skill({ skill: 'code-structural-search', args: 'function authenticate($$$) { $$ } --lang ts' })
使用 Phase 1 进行语义理解:
Skill({ skill: 'code-semantic-search', args: 'authentication logic' })
查找未经验证的输入:
router.post($PATH, ($REQ, $RES) => { $$ })
查找 SQL 查询(潜在的注入点):
db.query(`SELECT * FROM ${$VAR}`)
查找 eval 用法:
eval($$$)
查找深度嵌套的函数:
function $NAME($ARGS) {
if ($COND) {
if ($COND2) {
if ($COND3) { $$ }
}
}
}
查找长参数列表(>5 个参数):
function $NAME($A, $B, $C, $D, $E, $F, $$$) { $$ }
查找未使用的变量:
const $NAME = $VALUE;
查找旧 API 用法:
oldAPI.deprecatedMethod($$$)
查找回调模式(转换为 async/await):
$FUNC($ARGS, ($ERR, $DATA) => { $$ })
查找 React 类组件(转换为钩子):
class $NAME extends React.Component { $$$ }
--lang 标志指定语言 — 没有语言标志时,ast-grep 会应用启发式方法,产生误报;指定 --lang ts、--lang py 等以获得准确的 AST 解析。$$$ 表示可变参数列表,而不是 * 或 . — ast-grep 使用元变量语法($NAME、$$$、$$);在模式中使用正则表达式或通配符语法会导致静默失败。| 反模式 | 失败原因 | 正确方法 |
|---|---|---|
不使用 --lang 标志 | 应用了错误的解析器;产生误报和漏报 | 始终指定 --lang ts、--lang py 等 |
| 不使用 ripgrep 预过滤就在整个项目范围内运行 | 在大型代码库上速度慢;产生许多无关结果 | 首先使用 ripgrep 识别候选文件 |
| 使用正则表达式进行结构匹配 | 在多行、空格变化、嵌套情况下失效 | 使用 ast-grep AST 模式($NAME、$$$ 等) |
| 未在整个代码库上测试模式 | 不正确的模式会静默地返回无结果 | 首先在一个已知匹配项上测试 |
使用 * 或 . 作为通配符 | 不是有效的 ast-grep 语法;被忽略或出错 | 使用 $NAME 表示单个节点,$$$ 表示序列 |
开始前: 阅读 .claude/context/memory/learnings.md
完成后:
.claude/context/memory/learnings.md.claude/context/memory/issues.md.claude/context/memory/decisions.md假设中断:如果不在内存中,就视为未发生。
每周安装数
57
仓库
GitHub 星标数
19
首次出现时间
2026年2月8日
安全审计
安装于
gemini-cli57
github-copilot57
kimi-cli56
amp56
codex56
opencode56
Use ast-grep for AST-based code pattern matching.
Skill({ skill: 'code-structural-search', args: 'pattern-here --lang ts' });
ast-grep supports 20+ languages via tree-sitter:
| Language | Flag | File Extensions |
|---|---|---|
| JavaScript | --lang js | .js, .jsx |
| TypeScript | --lang ts | .ts, .tsx |
| Python | --lang py | .py, .pyi |
| Go | --lang go | .go |
| Rust | --lang rs | .rs |
| Java | --lang java | .java |
| C | --lang c | .c, .h |
| C++ | --lang cpp | .cpp, .cc, .hpp, .hh |
| C# | --lang cs | .cs |
| Kotlin | --lang kt | .kt, .kts |
| Swift | --lang swift | .swift |
| PHP | --lang php | .php |
| Ruby | --lang rb | .rb |
| Lua | --lang lua | .lua |
| Elixir | --lang ex | .ex, .exs |
| HTML | --lang html | .html, .htm |
| CSS | --lang css | .css |
| JSON | --lang json | .json |
| Bash | --lang bash | .sh, .bash |
| Thrift | --lang thrift | .thrift |
Find all functions:
function $NAME($ARGS) { $$ }
Find functions with exactly 2 arguments:
function $NAME($A, $B) { $$ }
Find async functions:
async function $NAME($ARGS) { $$ }
Find class methods:
class $NAME {
$METHOD($ARGS) { $$ }
}
Find arrow functions:
const $NAME = ($ARGS) => { $$ }
Find console.log statements:
console.log($$$)
Find try-catch blocks:
try { $$ } catch ($ERR) { $$ }
Find all functions:
def $NAME($ARGS): $$$
Find class definitions:
class $NAME: $$$
Find async functions:
async def $NAME($ARGS): $$$
Find imports:
import $MODULE
Find from imports:
from $MODULE import $$$
Find all functions:
func $NAME($ARGS) $RETURN { $$ }
Find struct definitions:
type $NAME struct { $$$ }
Find interface definitions:
type $NAME interface { $$$ }
Find all functions:
fn $NAME($ARGS) -> $RETURN { $$ }
Find impl blocks:
impl $NAME { $$$ }
Find pub functions:
pub fn $NAME($ARGS) -> $RETURN { $$ }
Find all methods:
public $RETURN $NAME($ARGS) { $$ }
Find class definitions:
public class $NAME { $$$ }
Find interface definitions:
public interface $NAME { $$$ }
| Symbol | Meaning | Example |
|---|---|---|
$NAME | Single node/identifier | function $NAME() {} |
$$$ | Zero or more statements/nodes | class $NAME { $$$ } |
$$ | Zero or more statements (block) | if ($COND) { $$ } |
$_ |
vs Ripgrep (grep):
vs Semantic Search (Phase 1):
Broad search with ripgrep:
Skill({ skill: 'ripgrep', args: 'authenticate --type ts' })
Structural refinement with ast-grep:
Skill({ skill: 'code-structural-search', args: 'function authenticate($$$) { $$ } --lang ts' })
Semantic understanding with Phase 1:
Skill({ skill: 'code-semantic-search', args: 'authentication logic' })
Find unvalidated inputs:
router.post($PATH, ($REQ, $RES) => { $$ })
Find SQL queries (potential injection):
db.query(`SELECT * FROM ${$VAR}`)
Find eval usage:
eval($$$)
Find deeply nested functions:
function $NAME($ARGS) {
if ($COND) {
if ($COND2) {
if ($COND3) { $$ }
}
}
}
Find long parameter lists ( >5 params):
function $NAME($A, $B, $C, $D, $E, $F, $$$) { $$ }
Find unused variables:
const $NAME = $VALUE;
Find old API usage:
oldAPI.deprecatedMethod($$$)
Find callback patterns (convert to async/await):
$FUNC($ARGS, ($ERR, $DATA) => { $$ })
Find React class components (convert to hooks):
class $NAME extends React.Component { $$$ }
--lang flag — without a language flag, ast-grep applies heuristics that produce false positives; specify --lang ts, --lang py, etc. for accurate AST parsing.$$$ for variable argument lists, not * or . — ast-grep uses metavariable syntax ($NAME, , ); regex or glob syntax in patterns produces silent failures.| Anti-Pattern | Why It Fails | Correct Approach |
|---|---|---|
No --lang flag | Wrong parser applied; produces false positives and misses | Always specify --lang ts, --lang py, etc. |
| Running project-wide without ripgrep pre-filter | Slow on large codebases; many irrelevant results | Use ripgrep to identify candidate files first |
| Regex for structural matching | Breaks on multi-line, whitespace variations, nesting | Use ast-grep AST patterns ($NAME, $$$, etc.) |
| Untested pattern on full codebase | Incorrect patterns silently return nothing |
Before starting: Read .claude/context/memory/learnings.md
After completing:
.claude/context/memory/learnings.md.claude/context/memory/issues.md.claude/context/memory/decisions.mdASSUME INTERRUPTION: If it's not in memory, it didn't happen.
Weekly Installs
57
Repository
GitHub Stars
19
First Seen
Feb 8, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
gemini-cli57
github-copilot57
kimi-cli56
amp56
codex56
opencode56
Flutter/Dart代码审查最佳实践:提升应用性能与质量的完整检查清单
1,100 周安装
| Anonymous wildcard (discard) |
console.log($_) |
$$$$$| Test on one known match first |
Using * or . for wildcards | Not valid ast-grep syntax; ignored or errors | Use $NAME for single node, $$$ for sequences |