
从规则文件中提取并索引 AI 编码指令
概览
从规则文件(CLAUDE.md、AGENTS.md、.cursorrules 等)中提取并索引 AI 编码指令。 你已经写好了规则。根节点有个 CLAUDE.md,Codex 的 AGENTS.md,一个 .cursorrules 文件,还有其他存在于 .cursor/rules/ 或 .github/instructions/ 下的代码。但当你打开代理会话并说“审查此 PR”时,它并不会看到所有规则。 repo-rules-agent 会从仓库中的每个规则文件中构建一个可查询索引。一个针对当前工作的范围查询——例如 --task code-review --lang py --severity must——返回的是实际适用的 ~15 条规则,而不是 8,000 个规则文件的标记。 - 在四个优先级层级中,扫描 ~40 个已知规则文件约定——根文件、工具特定路径、带 globs 的规则目录,以及递归的 **Extract**Index**Query** 返回当前任务范围的规则。按任务、语言、严重度、范围筛选;输出为表、JSON 或提示就绪模块。
概述(AI 翻译)
从规则文件(CLAUDE.md、AGENTS.md、.cursorrules 等)中提取并索引 AI 编码指令。
为什么?
你已经写好了规则。根节点有个CLAUDE.md,一个是Codex的AGENTS.md,一个是.cursorrules文件,还有其他属于.cursor/rules/或.github/instructions/的文档。但当你打开代理会话并说“审查此PR”时,它并不会看到所有规则。
repo-rules-agent 会从你仓库中的每个规则文件中构建一个可查询索引。一个范围限定在你面前工作的查询——例如 --task code-review --lang py --severity must——返回的是实际适用的 ~15 条规则,而不是 8,000 个规则文件的标记。
它是如何运作的
四个阶段:发现→提取→索引→查询。
- Discover 扫描了 ~40 个已知规则文件约定,跨越四个优先级——根文件、工具特定路径、带 globs 的规则目录,以及递归的
**层。它解析@include风格的指令,因此仅作为指向AGENTS.md的指针CLAUDE.md算作一个源,而非两个。 - Extract 通过 OpenAI 工具调用协议将每个文件发送到 LLM。该模型填充经过 pydantic 验证的模式——参见规则模型。
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Rules Agent
Extract and index AI coding instructions from rules files (CLAUDE.md, AGENTS.md, .cursorrules, etc.).
Why?
You’ve written the rules. There’s a CLAUDE.md at the root, an AGENTS.md for Codex, a .cursorrules file, and whatever else lives under .cursor/rules/ or .github/instructions/. But when you open an agent session and say “review this PR,” it doesn’t see all of them.
repo-rules-agent builds one queryable index from every rules file in your repo. A query scoped to the work in front of you — e.g. --task code-review --lang py --severity must — returns the ~15 rules that actually apply, not 8,000 tokens of rules files.
How it works
Four stages: discover → extract → index → query.
- Discover sweeps ~40 known rules-file conventions across four priority tiers — root files, tool-specific paths, rules directories with globs, and a recursive
**tier. It resolves@include-style directives, so aCLAUDE.mdthat’s just a pointer toAGENTS.mdcounts as one source, not two. - Extract sends each file to an LLM via the OpenAI tool-calling protocol. The model fills a pydantic-validated schema — see Rule Model. Large files are chunked on Markdown headings via chonkie.
- Index merges near-duplicates by text similarity and flags potential conflicts — similar rules with contradictory severities — for human resolution.
- Query returns rules scoped to the current task. Filter by task, language, severity, scope; output as a table, JSON, or a prompt-ready block.
Dependencies
uv— Python package managergit— used for blob SHA computation during indexing- Ollama — required if you use the default local provider; not needed if you configure OpenAI, Anthropic, or another hosted provider
Setup
# Install dependencies
uv sync
Configuration
The tool works with any OpenAI-compatible API provider. By default, it connects to a local Ollama instance; OpenAI and Anthropic are also supported.
Copy .env.example to .env and uncomment the provider you want to use:
cp .env.example .env
# Edit .env with your API keys
The .env file is gitignored and loaded automatically at startup via python-dotenv. Shell environment variables take precedence over .env values, so you can always override a .env setting with an explicit export.
Providers
Local (Ollama — default, no API key needed):
ollama pull glm-4.7-flash:latest
uv run repo-rules-agent index /path/to/repo
Local models vary in tool-calling reliability; for the highest-quality extraction, use OpenAI or Anthropic.
Anthropic (add to .env):
RULES_AGENT_LLM__BASE_URL=https://api.anthropic.com/v1
RULES_AGENT_LLM__API_KEY_ENV=ANTHROPIC_API_KEY
RULES_AGENT_LLM__EXTRACTION_MODEL=claude-haiku-4-5
推荐工具
换一个关键词,或者移除筛选条件。
安装
npx skillfish add unblocked/repo-rules-agent