code-review-and-qualit…
Reviews a code change for correctness, security, maintainability, architecture, performance, and verification gaps, or performs a…
Produces a ready-to-run ast-grep command or reusable YAML lint/codemod rule, validated against positive and negative fixtures. Use when search or rewrite depends on syntax structure: finding all call shapes, avoiding regex matches in comments/strings, batch-changing signatures,
$ npx -y skills add hylarucoder/hai-stack --skill hai-ast-grep --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/hai-ast-grepContext preview
The summary Claude sees to decide when to auto-load this skill.
Produces a ready-to-run ast-grep command or reusable YAML lint/codemod rule, validated against positive and negative fixtures. Use when search or rewrite depends on syntax structure: finding all call shapes, avoiding regex matches in comments/strings, batch-changing signatures,
name: hai-ast-grep description: | Produces a ready-to-run ast-grep command or reusable YAML lint/codemod rule, validated against positive and negative fixtures. Use when search or rewrite depends on syntax structure: finding all call shapes, avoiding regex matches in comments/strings, batch-changing signatures, or enforcing a structural rule(结构化搜索、批量改写、写 lint 规则). Do not use for plain-text replacement or type-semantic refactors that require a compiler/type checker.
ast-grep uses tree-sitter to parse code into AST, enabling precise pattern matching. Reach for it whenever a search or refactor depends on syntax structure: one-off searches and rewrites run straight from the CLI, reusable lint/codemod rules are written in YAML. Either way the job is not "write a pattern" — it is to ship a pattern or rule validated against a positive AND a negative case, so it catches what it should and nothing it shouldn't.
One-off `ast-grep run` commands need no project config. Reusable project scans use `sgconfig.yml` and rule directories; read `references/project-setup.md` only when creating or changing that setup.
Most day-to-day search and refactor work never needs YAML or sgconfig — `ast-grep run` (the default subcommand) does it directly:
# Search: every fetch call site, regardless of formatting ast-grep run -p 'fetch($URL)' -l ts src/ # Search with context lines, or machine-readable output for a report ast-grep run -p 'console.log($$$)' -C 2 src/ ast-grep run -p 'console.log($$$)' --json=stream src/ # One-off rewrite: review each match interactively (-i), or apply all (-U) ast-grep run -p 'console.log($$$A)' -r 'logger.log($$$A)' -l ts -i src/ ast-grep run -p 'oldFn($A, $B)' -r 'newFn($B, $A)' -l ts -U src/
Flags that matter:
| Flag | Meaning | |------|---------| | `-p <pattern>` | the AST pattern to match | | `-r <template>` | rewrite template — in `run`; in `scan`, `-r` means rule FILE, don't mix them up | | `-l <lang>` | language (`ts`, `tsx`, `py`, `go`, `rs`…); inferred from file extensions when omitted | | `-i` | interactive accept/reject per match — default this before any mass rewrite | | `-U` | apply all rewrites; without it matches are only reported | | `-C <n>` / `--json` | context lines / JSON output |
Deliver the pattern, the exact command, and a match summary. Escalate to a YAML rule only when the match needs `constraints` / `not` / `inside` narrowing, or will be re-run (CI guard, reusable codemod).
Check-only, no fix — for CI / editor diagnostics:
# rules/no-console-log.yml id: no-console-log language: JavaScript severity: warning message: Avoid console.log in production code rule: pattern: console.log($$$ARGS)
Validate:
ast-grep scan -r rules/no-console-log.yml src/
To auto-fix, add ONE `fix:` line to the lint rule above — nothing else changes:
# ... same rule as above, plus: fix: logger.log($$$ARGS)
Apply the fix (note the `--update-all` flag — `scan` without it only reports):
ast-grep scan -r rules/no-console-log.yml --update-all src/
1. **Explore** the pattern via CLI before writing YAML: `ast-grep run -p 'console.log($ARG)' src/`. Inspect node types with `--debug-query ast` when the pattern won't match:
ast-grep run -p 'console.log($ARG)' --debug-query ast
2. **Write** the rule file (`.yml`) — start with the lint form (pattern + message + severity). 3. **Validate against a POSITIVE fixture** — code that should match: `ast-grep scan -r rule.yml fixtures/`. Confirm it matches. 4. **Validate against a NEGATIVE fixture** — code that looks similar but should NOT match. If it matches, you have a false positive: add `constraints`, `not`, `inside`, or `has` to narrow the rule, then re-run both fixtures. 5. **Add `fix:`** only if a mechanical rewrite is wanted, then dry-run before `--update-all`. 6. **Deliver** using the deliverable shape below (and `references/output-template.md`) — never hand back a bare YAML block.
Use `$VAR` for one node and `$$$ARGS` for multiple nodes. For `kind`, `regex`, `all`, `any`, `not`, `has`, `inside`, transforms, and fix configuration, read [references/rule-syntax.md](references/rule-syntax.md). For language-specific starting points, read [references/common-patterns.md](references/common-patterns.md).
Hand back the rule in this shape — not a bare YAML block. These are the five headers from `references/output-template.md`; read that file for the full template before finalizing.
`ast-grep scan -r <rule-file>` command, and result.
The canonical delivery shape is `references/output-template.md`; do not invent a second schema.
ast-grep is the right hammer only when the match depends on syntax structure — search, lint, or rewrite. Route elsewhere when:
让 Coding Agent 把软件迭代做对:从真实问题出发,完成改动,用证据确认结果。 支持:大多数能读取 Skills(SKILL.md)的 Coding Agent,例如 Claude Code、Codex。 hai-stack 由 @海拉鲁编程客 创建。它把一次软件迭代拆成判断、设计、动手、确认、沉淀五步,每一步都有对应的技能。
Reviews a code change for correctness, security, maintainability, architecture, performance, and verification gaps, or performs a…
Audits an entity model field by field: what should exist, what exists now, where each value belongs (column, config, computed…
Challenges an overly conservative, incremental, or compatibility-led proposal with a bold target model, a concrete…
Pressure-tests an ambitious proposal and returns a landing judgment, one minimum viable proof, explicit cuts, success/failure…
Investigates architecture and change complexity from repository runtime paths to bounded modules, React components, and shared…
Audits documentation for internal contradictions and/or mismatches with code, config, schemas, and approved contracts. Use for…