fetch-rules

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Fetch Rules

获取规则

Purpose

用途

This skill emulates Cursor's rule selection behavior for AI agents.
It discovers and selects rules from:
  • Project Rules (
    .cursor/rules/
    )
    • .mdc
      files with frontmatter (
      description
      ,
      globs
      ,
      alwaysApply
      )
    • .md
      files without frontmatter (treated as always-apply)
  • AGENTS.md files (root and nested subdirectories)
  • Legacy
    .cursorrules
    at repo root (deprecated but still supported)
本Skill模拟Cursor针对AI Agent的规则选择行为。
它会从以下位置发现并选择规则:
  • 项目规则
    .cursor/rules/
    • 带前置元数据(
      description
      globs
      alwaysApply
      )的
      .mdc
      文件
    • 无前置元数据的
      .md
      文件(视为始终应用)
  • AGENTS.md文件(根目录及嵌套子目录)
  • 旧版
    .cursorrules
    (仓库根目录,已弃用但仍支持)

Rule Selection Semantics

规则选择语义

Rule TypeSelection Behavior
alwaysApply: true
Always included
Simple
.md
(no frontmatter)
Always included
globs: ...
Included when any candidate file matches
description: ...
Included when prompt overlaps with description keywords
No metadata (
.mdc
only)
Included only when explicitly referenced
AGENTS.md
Always included when in scope (directory hierarchy)
Candidate files come from
--files
,
--use-git-diff
, and file-like paths found in
--prompt
.
规则类型选择行为
alwaysApply: true
始终包含
简单
.md
(无前置元数据)
始终包含
globs: ...
当任意候选文件匹配时包含
description: ...
当提示与描述关键词重叠时包含
无元数据(仅
.mdc
仅在显式引用时包含
AGENTS.md
处于作用域(目录层级)时始终包含
候选文件来自
--files
--use-git-diff
以及
--prompt
中指定的类文件路径。

Requirements

要求

  • bash
    (macOS / Linux default)
  • git
    optional (only if you use
    --use-git-diff
    )
No Python, Node, or jq required.
  • bash
    (macOS / Linux默认自带)
  • git
    (可选,仅在使用
    --use-git-diff
    时需要)
无需Python、Node或jq。

Usage

使用方法

Run commands from this skill directory (the directory containing this
SKILL.md
). Do not hardcode agent install paths.
bash
bash scripts/fetch_rules.sh --prompt "<your request>"
Optional file hints:
bash
bash scripts/fetch_rules.sh --prompt "<request>" --files path/to/a.ts path/to/b.sql
bash scripts/fetch_rules.sh --prompt "<request>" --use-git-diff
Force-include a rule by filename:
bash
bash scripts/fetch_rules.sh --prompt "<request>" --explicit global.mdc
bash scripts/fetch_rules.sh --prompt "<request>" --explicit react-patterns.md
从本Skill所在目录(包含此
SKILL.md
的目录)运行命令。请勿硬编码Agent安装路径。
bash
bash scripts/fetch_rules.sh --prompt "<你的请求>"
可选文件提示:
bash
bash scripts/fetch_rules.sh --prompt "<请求内容>" --files path/to/a.ts path/to/b.sql
bash scripts/fetch_rules.sh --prompt "<请求内容>" --use-git-diff
通过文件名强制包含某条规则:
bash
bash scripts/fetch_rules.sh --prompt "<请求内容>" --explicit global.mdc
bash scripts/fetch_rules.sh --prompt "<请求内容>" --explicit react-patterns.md

Supported Formats

支持的格式

FormatLocationDescription
.mdc
.cursor/rules/
Rules with YAML frontmatter for fine-grained control
.md
.cursor/rules/
Simple markdown rules (always applied)
AGENTS.md
Root or subdirsSimple agent instructions (always applied in scope)
.cursorrules
Root onlyLegacy format (deprecated, will be removed)
格式位置描述
.mdc
.cursor/rules/
带YAML前置元数据的规则,支持细粒度控制
.md
.cursor/rules/
简单Markdown规则(始终应用)
AGENTS.md
根目录或子目录简单Agent指令(在作用域内始终应用)
.cursorrules
仅根目录旧版格式(已弃用,后续将移除)

Notes

注意事项

  • If multiple rules share the same filename, the rule in the closest scoped directory wins (deepest scope).
  • Glob matching uses bash pattern matching (
    [[ file == pattern ]]
    ). Cursor-style
    **
    works effectively as
    *
    in this matcher.
  • AGENTS.md
    files are combined hierarchically—parent directories' instructions apply alongside more specific subdirectory instructions.
  • 若多条规则文件名相同,作用域最接近的目录中的规则优先(层级最深的目录)。
  • 通配符匹配使用bash模式匹配(
    [[ file == pattern ]]
    )。在此匹配器中,Cursor风格的
    **
    等效于
    *
  • AGENTS.md
    文件会按层级合并——父目录的指令会与更具体的子目录指令一同生效。