Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问clear审计异常

ast-grep-code-analysisast grep 代码分析

Agent Skill

ast-grep-code-analysis 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,469

周安装

60

GitHub Stars

52

下载量

475
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:ast-grep-code-analysis(ast grep 代码分析)
来源仓库:https://github.com/zenobi-us/dotfiles
仓库路径:skills/ast-grep-code-analysis
安装命令:
npx skills add https://github.com/zenobi-us/dotfiles --skill ast-grep-code-analysis
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/zenobi-us/dotfiles --skill ast-grep-code-analysis

简介

ast-grep-code-analysis 用于通过 AST 模式匹配分析代码结构,识别潜在问题。

  • 适合在代码审查、安全扫描或架构优化时查找特定语法模式。
  • 需先安装 ast-grep 工具,支持多种编程语言和自定义规则集。
  • 使用前请确认环境已配置好 ast-grep,并检查其对项目文件的访问权限。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

AST-Grep Code Analysis

[!NOTE] This skill requires that as-grep is installed and configured in your development environment. If it's not installed we can use mise -g --pin ast-grep

Overview

AST-Grep Code Analysis uses Abstract Syntax Tree pattern matching to systematically identify code issues, replacing manual line-by-line inspection with structural pattern recognition.

Core principle: Code structure reveals more than surface reading - AST patterns expose hidden relationships, security vulnerabilities, and architectural issues that manual inspection misses.

When to Use

digraph when_to_use {
    "Need to analyze code?" [shape=diamond];
    "Complex/nested structure?" [shape=diamond];
    "Security review needed?" [shape=diamond];
    "Performance analysis?" [shape=diamond];
    "Use ast-grep patterns" [shape=box];
    "Manual review sufficient" [shape=box];

    "Need to analyze code?" -> "Complex/nested structure?" [label="yes"];
    "Complex/nested structure?" -> "Security review needed?" [label="yes"];
    "Security review needed?" -> "Performance analysis?" [label="yes"];
    "Performance analysis?" -> "Use ast-grep patterns" [label="yes"];
    "Complex/nested structure?" -> "Manual review sufficient" [label="no"];
    "Security review needed?" -> "Manual review sufficient" [label="no"];
    "Performance analysis?" -> "Manual review sufficient" [label="no"];
}

Use when:

  • Code has nested functions, complex control flow, or multiple abstraction layers
  • Security review required (authentication, authorization, data handling)
  • Performance analysis needed (React hooks, loops, async patterns)
  • Large codebase where manual inspection is impractical
  • Need to identify patterns across multiple files
  • Time pressure requires systematic approach over ad-hoc analysis

Do NOT use when:

  • Simple, straightforward code (< 50 lines)
  • Single-file utilities with obvious structure
  • When quick glance is sufficient for the task

Core Pattern

Before (Manual Inspection):

// Agent manually reads line by line
if (data[i].admin) {
  userObj.token = generateToken(data[i].id); // "This looks insecure"
}

After (AST Pattern Matching):

# ast-grep rule: insecure-token-generation
rule:
  pattern: |
    function $FUNC($ARGS) {
      const secret = $SECRET;
      return btoa(JSON.stringify($PAYLOAD) + '.' + $SECRET);
    }
  meta:
    severity: ERROR
    message: "Hardcoded secret in token generation"

Quick Reference

Analysis TypeAST Pattern FocusCommon Issues Found
SecurityString literals in crypto functionsHardcoded secrets, weak encryption
PerformanceReact hooks dependenciesInfinite re-renders, memory leaks
StructureFunction nesting depthComplex control flow, maintainability
Data FlowVariable assignments and usageUnused variables, implicit dependencies

Implementation

Installation and Setup

# Install ast-grep
npm install -g @ast-grep/cli

# Initialize configuration
ast-grep init

# Create rules directory
mkdir -p sg-rules/security sg-rules/performance sg-rules/structure

Essential Security Patterns

Hardcoded Secrets Detection:

# sg-rules/security/hardcoded-secrets.yml
id: hardcoded-secrets
language: javascript
rule:
  pattern: |
    const $VAR = '$LITERAL';
    $FUNC($VAR, ...)
  meta:
    severity: ERROR
    message: "Potential hardcoded secret detected"

Insecure Token Generation:

# sg-rules/security/insecure-tokens.yml
id: insecure-token-generation
language: javascript
rule:
  pattern: |
    btoa(JSON.stringify($OBJ) + '.' + $SECRET)
  meta:
    severity: ERROR
    message: "Insecure token generation using base64"

Performance Pattern Detection

React Hook Dependencies:

# sg-rules/performance/react-hook-deps.yml
id: react-hook-dependency-array
language: typescript
rule:
  pattern: |
    useEffect(() => {
      $BODY
    }, [$FUNC])
  meta:
    severity: WARNING
    message: "Function dependency in useEffect may cause infinite re-renders"

Missing useCallback Optimization:

# sg-rules/performance/missing-use-callback.yml
id: missing-use-callback
language: typescript
rule:
  pattern: |
    const $FUNC = ($ARGS) => {
      $BODY
    };
  inside:
    kind: function_declaration
    has:
      kind: arrow_function
  meta:
    severity: INFO
    message: "Consider wrapping function in useCallback for optimization"

Structural Analysis Patterns

Deep Nesting Detection:

# sg-rules/structure/deep-nesting.yml
id: deep-nesting
language: javascript
rule:
  any:
    - pattern: |
        if ($COND1) {
          if ($COND2) {
            if ($COND3) {
              $BODY
            }
          }
        }
    - pattern: |
        for ($INIT) {
          for ($INIT2) {
            for ($INIT3) {
              $BODY
            }
          }
        }
  meta:
    severity: WARNING
    message: "Deep nesting detected - consider refactoring"

Running Analysis

# Run all security rules
ast-grep run -r sg-rules/security/

# Run performance analysis on React components
ast-grep run -r sg-rules/performance/ --include="*.tsx,*.jsx"

# Generate comprehensive report
ast-grep run -r sg-rules/ --format=json > analysis-report.json

# Interactive analysis
ast-grep run -r sg-rules/ --interactive

Common Mistakes

MistakeWhy It HappensFix
Too generic patternsTrying to catch everythingFocus on specific, high-impact patterns
Missing contextPatterns don't consider surrounding codeUse inside and has constraints
False positivesOverly broad matchingAdd negative constraints with not
Language-specific assumptionsJavaScript patterns applied to TypeScriptCreate separate rules per language
No severity prioritizationAll issues marked as errorUse appropriate severity levels

Real-World Impact

Before AST Analysis:

  • Manual code review: 2-3 hours for medium codebase
  • Missed security vulnerabilities: 40-60%
  • Inconsistent analysis between reviewers
  • No systematic approach to pattern detection

After AST Analysis:

  • Automated pattern detection: 5-10 minutes
  • Security vulnerability detection: 90%+
  • Consistent, repeatable analysis
  • Comprehensive coverage of known anti-patterns

Example Results:

$ ast-grep run -r sg-rules/
src/components/UserProfile.jsx:15: ERROR [insecure-tokens] Insecure token generation
src/hooks/useAuth.js:8: ERROR [hardcoded-secrets] Potential hardcoded secret
src/components/UserProfile.jsx:23: WARNING [react-hook-deps] Function dependency may cause re-renders
src/utils/processData.js:45: WARNING [deep-nesting] Deep nesting detected

Found 4 issues (2 errors, 2 warnings)

Integration Workflow

  1. Setup: Create rule sets for security, performance, structure
  2. Baseline: Run analysis on existing codebase to establish patterns
  3. Iterate: Refine rules based on false positives/negatives
  4. Automate: Integrate into CI/CD pipeline for continuous analysis
  5. Monitor: Track issue reduction over time

Required Background: Understanding of AST concepts, pattern matching, and code structure analysis. AST patterns reveal what manual inspection misses - systematic, comprehensive, and repeatable code analysis.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

26.24%
按下载量换算125

OpenCode

21.66%
按下载量换算103

Antigravity

19.3%
按下载量换算92

Gemini CLI

13.24%
按下载量换算63

kiro-cli

8.57%
按下载量换算41

windsurf

3.65%
按下载量换算17

安全审计

Gen Agent Trust Hub

未通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills