Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/Dwsy/agent --skill ast-grep명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
Operate Glimpse-APPs with progressive context — app list in system, domain detail via tools on demand.
Load prior knowledge from role memory before starting any task.
Use when user asks to design, choose, explain, or implement UI transitions, motion patterns, easing/timing choices, state-change animations, shared-element effects, drill-down navigation, tab/filter/list/detail switching, or vague requests like "make this feel smoother", "more iOS", "more natural", or "animate this UI" that need concrete motion taxonomy and implementation guidance.
SOC 직업 분류 기준
SKILL.md 표시 중
| name | ast-grep |
| description | 语法感知的代码搜索、linting 和重写工具。支持基于 AST 的结构化代码搜索和批量代码转换。 |
AST-Grep (ast-grep/sg) 是一个快速且用户友好的工具,用于代码搜索、linting 和大规模代码重写。
| 路径类型 | 说明 |
|---|---|
| 使用方式 | 命令行工具,需要安装 ast-grep |
| 调用场景 | 语法感知的代码搜索、结构化代码分析、批量代码转换 |
| 工作目录 | 项目根目录 |
# macOS
brew install ast-grep
# Linux
cargo install ast-grep
# 验证安装
ast-grep --version
使用 AST(抽象语法树)进行代码搜索,而非简单的文本匹配。
# 搜索特定模式
ast-grep --lang python -p "def $FUNC($$$ARGS):"
# 搜索函数调用
ast-grep --lang ts -p "console.log($$$MSG)"
# 搜索条件语句
ast-grep --lang ts -p "if ($$COND) { $$$BODY }"
基于 AST 的代码检查,比传统 linter 更精确。
# 扫描项目
ast-grep scan -r sgconfig.yml
# 扫描特定目录
ast-grep scan src/
# 扫描特定文件
ast-grep scan src/main.ts
批量转换代码模式。
# 简单替换
ast-grep run -p "oldFunction($$$ARGS)" -r "newFunction($$ARGS)" --lang ts
# 复杂转换(使用 YAML 规则)
ast-grep run -r rule.yml
测试 ast-grep 规则是否正确。
# 测试规则
ast-grep test -r rule.yml
# 测试特定模式
ast-grep test -p "pattern" --lang ts
test_match_code_rule 验证规则
inside 或 has,确保使用 stopBy: end匹配单个 AST 节点,基于内在属性。
pattern - 模式匹配# 字符串模式
pattern: console.log($ARG)
# 对象模式(更精细的控制)
pattern:
selector: field_definition
context: class { $F }
strictness: relaxed
kind - 节点类型匹配kind: call_expression
regex - 正则表达式匹配regex: ^[a-z]+$
nthChild - 位置匹配# 数字
nthChild: 1
# An+B 公式
nthChild: 2n+1
# 对象形式
nthChild:
position: 1
reverse: true
ofRule:
kind: function_declaration
range - 范围匹配range:
start:
line: 0
column: 0
end:
line: 0
column: 10
基于目标节点与其他节点的关系过滤目标。
inside - 在父节点内inside:
pattern: class $C { $$$ }
stopBy: end
has - 包含子节点has:
pattern: await $EXPR
stopBy: end
precedes - 在节点之前precedes:
pattern: return $VAL
follows - 在节点之后follows:
pattern: import $M from '$P'
stopBy - 搜索终止控制# neighbor(默认):在直接周围节点不匹配时停止
stopBy: neighbor
# end:搜索到方向末尾(inside 为根,has 为叶子)
stopBy: end
# 规则对象:在周围节点匹配提供的规则时停止(包含)
stopBy:
pattern: class $END
field - 字段匹配has:
field: operator
pattern: $$OP
使用逻辑操作组合其他规则。
all - 逻辑与(AND)all:
- kind: call_expression
- pattern: console.log($ARG)
any - 逻辑或(OR)any:
- pattern: console.log($ARG)
- pattern: console.warn($ARG)
- pattern: console.error($ARG)
not - 逻辑非(NOT)not:
pattern: console.log($ARG)
matches - 规则重用matches: my-utility-rule-id
$VAR - 单个命名节点捕获# 有效
pattern: console.log($GREETING)
# 匹配
console.log('Hello World')
$$VAR - 单个未命名节点捕获# 匹配操作符
rule:
kind: binary_expression
has:
field: operator
pattern: $$OP
$$$VAR - 多节点捕获# 匹配零个或多个节点(非贪婪)
pattern: console.log($$$)
# 匹配可变参数
pattern: function $FUNC($$$ARGS) { $$$ }
_VAR - 非捕获元变量# 不捕获,可以匹配不同内容
pattern: $_FUNC($_FUNC)
# 匹配
test(a)
testFunc(1 + 1)
stopBy: end:对于关系规则,确保搜索到方向末尾has:
pattern: await $EXPR
stopBy: end
pattern: console.log($ARG)
rule:
kind: function_declaration
has:
pattern: await $EXPR
# 先确认节点类型
kind: call_expression
# 再使用 has 或 inside
has:
pattern: console.log($ARG)
inside:
pattern: class $C { $$$ }
stopBy: end
# rule.yml
id: no-console-log
language: ts
rule:
pattern: console.log($$$MSG)
# complex-rule.yml
id: prefer-const
language: ts
rule:
all:
- pattern: let $VAR = $INIT
- not:
pattern: $VAR = $EXPR
# fix-rule.yml
id: no-var
language: ts
rule:
pattern: var $VAR = $INIT
fix: const $VAR = $INIT
# async-without-await.yml
id: async-without-await
language: ts
rule:
all:
- pattern: async function $FUNC($$$ARGS) { $$$BODY }
- not:
has:
pattern: await
stopBy: end
# 查找所有 console.log
ast-grep -p "console.log($$$MSG)" --lang ts
# 查找所有未使用的变量
ast-grep -p "let $VAR = $INIT" --lang ts | grep -v "$VAR ="
# 替换 var 为 const
ast-grep run -p "var $VAR = $INIT" -r "const $VAR = $INIT" --lang ts
# 重命名函数
ast-grep run -p "oldFunc($$$ARGS)" -r "newFunc($$ARGS)" --lang ts
# 查找潜在的安全问题
ast-grep -p "eval($$$EXPR)" --lang js
# 查找 SQL 注入风险
ast-grep -p "query('$$SQL')" --lang py
# 迁移旧 API 到新 API
ast-grep run -p "oldApi($$$ARGS)" -r "newApi($$ARGS)" --lang ts
# 批量更新导入
ast-grep run -p "from 'old-lib' import $$IMPORT" -r "from 'new-lib' import $$IMPORT" --lang ts
| 特性 | ast-grep | grep | ripgrep |
|---|---|---|---|
| 语法感知 | 是 | 否 | 否 |
| 代码结构理解 | 是 | 否 | 否 |
| 跨语言支持 | 是 | 否 | 否 |
| 性能 | 快 | 快 | 最快 |
| 重写功能 | 是 | 否 | 否 |
当需要理解代码结构时,使用 ast-grep 进行语法感知搜索:
# 查找特定模式
ast-grep -p "pattern" --lang <language>
使用 ast-grep 进行批量代码转换:
# 应用重构规则
ast-grep run -r rule.yml
使用 ast-grep 验证代码质量:
# 扫描潜在问题
ast-grep scan -r sgconfig.yml
stopBy: end 确保关系规则搜索完整