Hai Ast Grep logo

Hai Ast Grep

Community
hylarucoder
hai-ast-grep

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.

Overview

Publisherhylarucoder
Repositoryhai-stack
Skill namehai-ast-grep
Stars
284
Forks
15
Bundled files
5
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by hylarucoder on GitHub. Read the source before you install it.

Installation

Install the Hai Ast Grep AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/hylarucoder/hai-stack.git /tmp/hai-stack
mkdir -p .claude/skills
cp -r /tmp/hai-stack/skills/hai-ast-grep .claude/skills/hai-ast-grep
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Hai Ast Grep in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Hai Ast Grep on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Hai Ast Grep is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

hai-ast-grep

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.

Project Configuration

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.

Everyday CLI Usage (no rule file)

Most day-to-day search and refactor work never needs YAML or sgconfig — ast-grep run (the default subcommand) does it directly:

bash
# 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:

FlagMeaning
-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
-iinteractive accept/reject per match — default this before any mass rewrite
-Uapply all rewrites; without it matches are only reported
-C <n> / --jsoncontext 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).

Rule Workflow

Lint Rule (most common)

Check-only, no fix — for CI / editor diagnostics:

yaml
# 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:

bash
ast-grep scan -r rules/no-console-log.yml src/

Rewrite Rule (optional)

To auto-fix, add ONE fix: line to the lint rule above — nothing else changes:

yaml
# ... same rule as above, plus:
fix: logger.log($$$ARGS)

Apply the fix (note the --update-all flag — scan without it only reports):

bash
ast-grep scan -r rules/no-console-log.yml --update-all src/

Development Flow (canonical workflow — follow these steps)

  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:
    bash
    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.

Syntax references

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. For language-specific starting points, read references/common-patterns.md.

Deliverable Shape

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.

  • Goal — what code pattern this finds or rewrites.
  • Rule — the .yml (id, language, rule, message, severity).
  • Fix, if applicable — the added fix: line.
  • Validation — positive fixture, negative fixture, exact ast-grep run or ast-grep scan -r <rule-file> command, and result.
  • Notes — false positives avoided (how), and known limits (cases intentionally not covered).

The canonical delivery shape is references/output-template.md; do not invent a second schema.

Use a Different Skill When

ast-grep is the right hammer only when the match depends on syntax structure — search, lint, or rewrite. Route elsewhere when:

  • Plain text or regex find-and-replace with no syntax-tree shape (rename a string literal, swap a URL, find a unique identifier that grep already nails) — just use grep / a normal edit / sed; an AST pattern is overkill.
  • One-off edit in a single file — edit it directly; a rule only pays off across many call sites.
  • Type-aware or semantic refactor (driven by types rather than syntax) — use the compiler or an available type-safety workflow.
  • Subjective code-quality review — use code-review-and-quality; for implementation, use an available refactoring workflow.
  • Pure formatting / whitespace / import order — that is a formatter's job (Prettier, Biome, gofmt), not a structural rule.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Hai Ast Grep AI skill do?

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.

Why use Hai Ast Grep on TypingMind?

Because you install it once and use it with any model. Hai Ast Grep is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Hai Ast Grep in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/hylarucoder/hai-stack/tree/main/skills/hai-ast-grep. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Hai Ast Grep?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Hai Ast Grep?

As many as you like. As long as a model supports skills, you can use Hai Ast Grep with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Hai Ast Grep AI skill free?

It is published on GitHub by hylarucoder. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇