本文へ移動
cccskills
無料GitHub で公開

ast-grep

Write and debug ast-grep rules for structural code search and rewrite. Use when tasks require AST-aware matching (not plain text), such as finding specific syntax shapes, relational patterns (inside/has), composite logic (all/any/not), or precise code refactors across a codebase.

インストール方法を見る

含まれるファイル(3)

  • SKILL.md3.1 KB
  • references/rule_reference.md10.4 KB
  • references/windows.md1.1 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

ast-grep Code Search

Overview

Translate user intent into sg patterns/rules, validate quickly, then run against target scope.

General Workflow

Step 1: Understand the Query

Pin down:

  • target syntax shape
  • language
  • file scope
  • include/exclude constraints

Step 2: Start with the Smallest Pattern

Use sg run --pattern first.

sg run --pattern 'console.log($ARG)' --lang javascript src

Step 3: Escalate to YAML Rule for Structure Logic

For relational/composite logic (inside / has / precedes / follows / all / any / not / matches), use sg scan --rule.

# rule.yml
id: async-with-await
language: javascript
rule:
  kind: function_declaration
  has:
    pattern: await $EXPR
    stopBy: end
sg scan --rule rule.yml src

Step 4: Validate and Search

Test on a tiny sample first, then search the project.

echo "async function f(){ await g() }" | sg scan --rule rule.yml --stdin
sg scan --rule rule.yml src --json=compact

CLI Quick Reference

Inspect Code Structure (--debug-query)

Use when kind/pattern mismatch is unclear.

sg run --pattern 'class $NAME { $$$BODY }' \
  --lang javascript \
  --debug-query=pattern

Test Rules (scan with --stdin)

echo "const x = await fetch();" | sg scan --inline-rules "id: test
language: javascript
rule:
  pattern: await \$EXPR" --stdin --json=compact

Search with Patterns (run)

sg run --pattern 'function $NAME($$$)' --lang javascript src --json=compact

Search with Rules (scan)

sg scan --rule rule.yml src
sg scan --inline-rules "id: find-async
language: javascript
rule:
  kind: function_declaration
  has:
    pattern: await \$EXPR
    stopBy: end" src

Tips for Writing Effective Rules

Default to stopBy: end for Deep Searches

For relational rules (inside, has), default to:

has:
  pattern: await $EXPR
  stopBy: end

This ensures the search traverses the entire subtree rather than stopping at the first non-matching node.

Start Simple, Then Add Complexity

  1. pattern
  2. kind
  3. add inside/has
  4. add all/any/not

Metavariable Rules

  1. Use exact metavariable forms only: $A, $$OP, $$$ARGS.
  2. Keep metavariable text as the only content in its AST node.
  3. If a rule depends on previously captured metavariables, combine sub-rules in all to guarantee match order.

No-Match Triage

  1. Run with --json=compact.
  2. If output is [], treat as no match and refine pattern/scope.
  3. If stderr has parser/arg errors, fix language, pattern, or flags first.

Resources

references/

  • rule_reference.md: Full rule syntax (atomic, relational, composite, metavariables)
  • windows.md: PowerShell quoting/escaping tips and Vue SFC script-block workflow

Load only the reference needed for the current task.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

gh-cli

無料

使用 GitHub CLI (`gh`) 执行非交互式 GitHub 协作与自动化任务(PR、Issue、Actions、Release、API 查询/修改)。当用户要求“用 gh 命令完成任务”、需要结构化 JSON 输出(`--json`/`--jq`)、批量处理 PR/Issue(如“批量 review 多个 PR”)、按策略合并(如“检查通过后自动 squash 合并”)时使用此 skill。

日本語の概要は準備中です。原文の説明を表示しています。

BiFangKNT/mtga1,1692026年6月18日 更新

pwsh

無料

在 Windows PowerShell 5.1 与 PowerShell 7 中编写和执行稳定命令,重点处理引号、管道符、原生命令参数传递与跨版本兼容。遇到 `--jq`/过滤表达式被 PowerShell 误解析、同一命令在 pwsh5 与 pwsh7 行为不一致、或需要为 pwsh7.3+ 增加参数传递适配时使用此 skill。

日本語の概要は準備中です。原文の説明を表示しています。

BiFangKNT/mtga1,1692026年6月18日 更新

tauri

無料

构建、调试与发布 Tauri v2 应用的工程化工作流。覆盖项目初始化(create-tauri-app)、前端与 Rust 命令通信(`#[tauri::command]` + `invoke`)、状态管理、Capabilities 权限建模、插件接入、跨平台构建与问题排查。当用户需求涉及“创建 Tauri 项目”“把 Web 前端接到 Rust 后端”“最小权限配置(fs/http/shell)”“接入 Tauri 官方插件”“执行 tauri dev/build”“排查 Tauri 构建或运行错误”时使用此 skill。

日本語の概要は準備中です。原文の説明を表示しています。

BiFangKNT/mtga1,1692026年6月18日 更新

Maintain, debug, and recover MTGA's Trae native custom-model route. Use when Trae native integration fails, Trae updates shift ai_agent.dll hook offsets, errors such as 4028/4054/429 appear, native rewriter or SseOpenPayload URL rewriting needs diagnosis, or Codex needs to avoid repeating prior renderer-JS/private-protocol dead ends.

日本語の概要は準備中です。原文の説明を表示しています。

BiFangKNT/mtga1,1692026年6月18日 更新

UI/UX design intelligence with searchable database

日本語の概要は準備中です。原文の説明を表示しています。

BiFangKNT/mtga1,1692026年6月18日 更新

uv

無料

在 Windows/macOS/Linux 上使用 `uv` 执行 Python 运行、依赖同步、锁文件管理、Python 版本管理与工具命令(`uv run`、`uv sync`、`uv lock`、`uv python`、`uv tool`)。当任务涉及“用 uv 运行脚本/命令”“临时依赖(`--with`)”“锁文件一致性(`--locked`/`--frozen`)”“跨平台 shell(bash/zsh/PowerShell)下排查 uv 执行问题”时使用此 skill。

日本語の概要は準備中です。原文の説明を表示しています。

BiFangKNT/mtga1,1692026年6月18日 更新

BiFangKNT のスキルをすべて見る

このスキルの問題を報告する