wiki-agents-md
microsoft/skills
为仓库文件夹生成 AGENTS.md 文件,以便向编码代理提供项目特定的背景信息,包括构建命令、测试说明、代码风格、项目结构和操作边界;但仅在缺少 AGENTS.md 文件时才会生成。
...展开全部AGENTS.md 生成器
为仓库文件夹生成高质量 AGENTS.md 文件。每个文件为编码人员提供项目特定的背景信息——构建命令、测试说明、代码风格、结构以及操作边界。
什么是 AGENTS.md
AGENTS.md 与 README.md。README 面向人类;AGENTS.md 面向编码代理。
- 可预测的位置——代理会搜索
AGENTS.md当前目录,然后沿目录树向上遍历 - 嵌套文件 — 子文件夹可以拥有自己的
AGENTS.md,且该文件优先于根目录中的 README - 与 README 分离 — 保持 README 简洁;代理特有的细节(具体命令、边界、约定)放在这里
- 这与
.github/agents/*.agent.md不同——后者是代理角色定义(代理的身份)。AGENTS.md是项目上下文(代理应了解的关于此代码的信息)
关键保护机制:仅在缺失时生成
这是最重要的一条规则。
切勿覆盖现有的 AGENTS.md 文件。
在为任何文件夹生成文件之前:
# Check if AGENTS.md already exists
ls AGENTS.md 2>/dev/null
- 若文件已存在 → 跳过并报告:
"AGENTS.md already exists at— skipping" - 若不存在 → 继续生成
- 此检查适用于每个文件夹,且独立进行
相关文件夹检测
确定哪些文件夹应包含 AGENTS.md:
始终生成:
- 仓库根目录(
/) - Wiki文件夹(
wiki/) — 若由 deep-wiki 生成(需package.json配合 VitePress 使用)
若存在则生成:
tests/,src/,lib/,app/,api/- 单仓库(Monorepo)包:
packages/*/,apps/*/,services/*/ - 任何带有独立构建清单的文件夹:
package.jsonpyproject.tomlCargo.toml*.csproj/*.fsprojgo.modpom.xml/build.gradle
.github/— 仅当其中包含工作流或操作时
始终跳过:
node_modules/,.git/,dist/,build/,out/,target/vendor/,.venv/,venv/,__pycache__/- 任何生成输出或第三方依赖项的目录
六个核心领域
每个优秀的 AGENTS.md 文件都应涵盖这些方面,并根据文件夹中实际存在的内容进行定制。切勿为项目中不存在的内容凭空添加章节。
a) 构建与运行命令 — 置于首位
代理程序会不断引用这些内容。请使用包含参数的精确命令,而非仅列出工具名称。
## Build & Run
npm install # Install dependencies
npm run dev # Start dev server (port 3000)
npm run build # Production build
npm run lint # Run ESLint
请阅读以下资源以查找实际命令:
package.json→scriptssectionMakefile→ 目标pyproject.toml→[tool.poetry.scripts]或[project.scripts]Cargo.toml→ 标准 Cargo 命令- CI 配置 →
.github/workflows/*.yml,Jenkinsfile,.gitlab-ci.yml
b) 测试说明
## Testing
pytest tests/ -v # Run all tests
pytest tests/test_auth.py -v # Run single file
pytest -k "test_login" -v # Run single test by name
pytest --cov=src --cov-report=term # With coverage
包括:
- 测试框架及其配置方法
- 如何运行所有测试、单个文件或单个测试
- 提交前的预期行为(例如,“所有测试必须通过”)
c) 项目结构
## Project Structure
src/
├── api/ # FastAPI route handlers
├── models/ # Pydantic data models
├── services/ # Business logic
└── utils/ # Shared utilities
tests/ # Mirrors src/ structure
包括:
- 关键目录及其内容
- 入口点(例如,
src/main.py,src/index.ts) - 新增功能应添加的位置
d) 代码风格与规范
一个真实的代码示例胜过三段文字的描述。
## Code Style
- snake_case for functions and variables
- PascalCase for classes
- Type hints on all function signatures
- Async/await for I/O operations
### Example
```python
async def get_user_by_id(user_id: str) -> User:
"""Fetch a user by their unique identifier."""
async with get_db_session() as session:
return await session.get(User, user_id)
Detect conventions by reading existing code:
- Naming patterns (camelCase, snake_case, PascalCase)
- Import organization (stdlib → third-party → local)
- Module structure patterns
### e) Git Workflow
```markdown
## Git Workflow
- Branch naming: `feature/`, `fix/`, `chore/`
- Commit messages: conventional commits (`feat:`, `fix:`, `docs:`)
- Run `npm test && npm run lint` before committing
- PR titles follow conventional commit format
仅当仓库中存在规范的证据时才包含此内容(例如:commitlint 配置、PR 模板、贡献指南)。
f) 边界
采用三级体系:
## Boundaries
- ✅ **Always do:** Run tests before committing. Write tests for new features. Use type hints.
- ⚠️ **Ask first:** Adding new dependencies. Changing database schemas. Modifying CI/CD configs. Changing public API signatures.
- 🚫 **Never do:** Commit secrets or credentials. Modify `vendor/` or `node_modules/`. Push directly to `main`. Delete migration files.
根据项目特点调整边界:
- 后端项目:模式变更、API 契约
- 前端项目:破坏性组件 API 变更、设计系统变更
- 基础设施:生产环境配置、IAM权限
生成流程
为特定文件夹生成 AGENTS.md 时:
步骤 1:检查文件是否存在
ls /AGENTS.md 2>/dev/null
若文件已存在,则停止。报告该情况并转至下一个文件夹。
步骤 2:扫描文件夹
识别:
- 主要编程语言(Python、TypeScript、Rust、Go、Java、C#)
- 框架(FastAPI、Next.js、Actix、Spring Boot)
- 构建工具(npm、cargo、poetry、maven、gradle)
- 测试运行器(pytest、vitest、cargo test、JUnit)
步骤 3:读取配置文件
从以下内容中提取实际命令和设置:
package.json脚本Makefile/Justfile目标pyproject.toml脚本和工具配置Cargo.toml元数据.github/workflows/*.yml构建/测试步骤docker-compose.yml服务定义- 代码检查工具配置 (
.eslintrc,ruff.toml,rustfmt.toml)
步骤 4:检测编码规范
读取 3-5 个源文件以识别:
- 命名模式
- 导入组织方式
- 错误处理风格
- 注释风格
- 模块结构
第 5 步:编写 AGENTS.md
仅使用适用的部分。如果文件夹中没有测试,请省略测试部分。如果没有 CI 配置,请省略 Git 工作流。
步骤 6:验证
在编写文件之前:
- 每个命令都应引用真实的脚本、目标或工具
- 每个文件路径都应指向实际存在的文件或目录
- 不得包含如下占位符文本:
或TODO - 不得为不存在的内容编造章节
模板结构
# [Folder Name] — Agent Instructions
## Overview
[1-2 sentences: what this folder/project does, its role in the larger system]
## Build & Run
[Exact commands — install, dev, build, clean]
## Testing
[Framework, run commands, single-test commands]
## Project Structure
[Key directories, entry points, where to add new things]
## Code Style
[Naming conventions + one real code example from this project]
## Boundaries
- ✅ **Always do:** [safe operations]
- ⚠️ **Ask first:** [risky operations]
- 🚫 **Never do:** [dangerous operations]
## Documentation
[Only include if wiki/, llms.txt, or docs/ exist in the repo]
- Wiki: `wiki/` — architecture, API, onboarding guides
- LLM Context: `llms.txt` — project summary for coding agents (full version: `wiki/llms-full.txt`)
- Onboarding: `wiki/onboarding/` — guides for contributors, staff engineers, executives, PMs
请省略不适用的章节。一份包含真实命令的 20 行 AGENTS.md 文件,远胜于一份包含通用填充内容的 200 行文件。
根级与嵌套的 AGENTS.md
根级 AGENTS.md(/AGENTS.md)
涵盖整个项目:
- 整体技术栈与架构
- 全局约定和编码规范
- 开发环境配置
- 仓库范围的边界
- CI/CD 概述
嵌套的 AGENTS.md 文件(例如, tests/AGENTS.md)
涵盖该特定子文件夹:
- 该文件夹的功能及其存在原因
- 特定于该文件夹的命令(例如,
cd tests && pnpm test) - 文件夹专属规范
- 不应重复根级内容
Wiki AGENTS.md(wiki/AGENTS.md)
生成前务必检查 wiki/AGENTS.md 是否存在——与其他所有文件夹采用相同的“仅在缺失时处理”机制。若该文件存在,则跳过。
使用此模板(根据实际项目进行调整):
# Wiki — Agent Instructions
## Overview
Generated VitePress documentation site. Contains architecture docs, onboarding guides, and API references with source-linked citations and dark-mode Mermaid diagrams.
## Build & Run
- Install: `npm install`
- Dev server: `npm run dev`
- Build: `npm run build`
- Preview: `npm run preview`
## Wiki Structure
- `index.md` — Landing page with project overview and navigation
- `onboarding/` — Audience-tailored guides (contributor, staff engineer, executive, product manager)
- `{NN}-{section}/` — Numbered documentation sections
- `llms.txt` — LLM-friendly project summary (links + descriptions)
- `llms-full.txt` — LLM-friendly full content (inlined pages)
- `.vitepress/config.mts` — VitePress config with sidebar and Mermaid setup
- `.vitepress/theme/` — Dark theme (custom.css) and zoom handlers (index.ts)
## Content Conventions
- All Mermaid diagrams use dark-mode colors (fills `#2d333b`, borders `#6d5dfc`, text `#e6edf3`)
- Every page has VitePress frontmatter (`title`, `description`)
- Citations link to source repository with line numbers
- Tables include a "Source" column with linked citations
- Mermaid diagrams followed by `` comment blocks
## Boundaries
- ✅ **Always do:** Add new pages following existing section numbering, use dark-mode Mermaid colors
- ⚠️ **Ask first:** Change theme CSS, modify VitePress config, restructure sections
- 🚫 **Never do:** Delete generated pages without understanding dependencies, use light-mode colors, remove citation links
## Documentation
- Wiki: `./` — This folder is the wiki
- LLM Context: `llms.txt` — Quick summary; `llms-full.txt` — Full content
- Onboarding: `onboarding/` — Four audience-tailored guides
填写实际的章节名称、技术栈及项目特有的规范。
代理程序会读取目录树中距离最近的 AGENTS.md 文件。嵌套文件具有优先级,因此它们应包含特定于该文件夹的详细信息,而非全局信息。
CLAUDE.md 配套文件
每当您在 AGENTS.md ,请同时在同一文件夹中生成一个 CLAUDE.md ——但仅当该文件夹中尚未存在CLAUDE.md时才生成。
该 CLAUDE.md 内容始终为:
# CLAUDE.md
Before beginning work in this repository, read `AGENTS.md` and follow all scoped AGENTS guidance.
这可确保 Claude Code(以及其他会搜索 CLAUDE.md)会被重定向到权威的 AGENTS.md 说明。
同样需注意:在写入前请检查 CLAUDE.md 是否存在。若已存在,则跳过。
质量原则
| 原则 | 良好 | 不妥 |
|---|---|---|
| 具体 | “使用 TypeScript、Vite 和 Tailwind CSS 开发的 React 18 项目” | “React 项目” |
| 可执行 | pytest tests/ -v --tb=short |
“运行测试” |
| 扎实 | 展示项目中的真实代码片段 | 用抽象的术语描述该风格 |
| 实际路径 | src/api/routes/ |
path/to/your/code/ |
| 诚实 | 若无测试,则省略测试部分 | 虚构一个测试部分 |
| 简洁 | 大多数文件夹为30-80行 | 300多行散文式描述 |
应避免的反模式
- ❌ “你是一位乐于助人的编程助手”——表述过于模糊,描述的是感受而非具体行动
- ❌ 通用模板——适用于任何项目的内容毫无价值
- ❌ 虚构的命令/路径——每个命令和路径都必须对应真实的内容
- ❌ 重复 README.md 的内容 —— AGENTS.md 应作为 README 的补充,而非其复制品
- ❌ 包含机密信息 —— 切勿在 AGENTS.md 中放置凭据、API 密钥或令牌
- ❌ 覆盖现有文件 —— 若已存在 AGENTS.md 文件,请勿修改
- ❌ 填充空章节 —— 若无测试,请勿编写测试章节
- ❌ 描述代理应“如何思考”或“感受”——应描述它们应“做什么”
---
name: wiki-agents-md
description: Generates AGENTS.md files for repository folders to provide coding agents with project-specific context including build commands, testing instructions, code style, project structure, and operational boundaries, only where AGENTS.md is missing.
license: MIT
---
# AGENTS.md Generator
Generate high-quality `AGENTS.md` files for repository folders. Each file provides coding agents with project-specific context — build commands, testing instructions, code style, structure, and operational boundaries.
## What is AGENTS.md
`AGENTS.md` complements `README.md`. README is for humans; AGENTS.md is for coding agents.
- **Predictable location** — Agents look for `AGENTS.md` in the current directory, then walk up the tree
- **Nested files** — Subfolders can have their own `AGENTS.md` that takes precedence over the root one
- **Separate from README** — Keeps READMEs concise; agent-specific details (exact commands, boundaries, conventions) go here
- **NOT the same as `.github/agents/*.agent.md`** — Those are agent persona definitions (who the agent is). `AGENTS.md` is project context (what the agent should know about this code)
## Critical Guard: Only Generate If Missing
> **This is the single most important rule.**
**NEVER overwrite an existing AGENTS.md.**
Before generating for ANY folder:
```bash
# Check if AGENTS.md already exists
ls AGENTS.md 2>/dev/null
```
- If it exists → **skip** and report: `"AGENTS.md already exists at <path> — skipping"`
- If it does not exist → proceed with generation
- This check applies to **every folder independently**
## Pertinent Folder Detection
Identify which folders should have an `AGENTS.md`:
### Always generate for:
- **Repository root** (`/`)
- **Wiki folder** (`wiki/`) — if generated by deep-wiki (has `package.json` with VitePress)
### Generate if they exist:
- `tests/`, `src/`, `lib/`, `app/`, `api/`
- Monorepo packages: `packages/*/`, `apps/*/`, `services/*/`
- Any folder with its own build manifest:
- `package.json`
- `pyproject.toml`
- `Cargo.toml`
- `*.csproj` / `*.fsproj`
- `go.mod`
- `pom.xml` / `build.gradle`
- `.github/` — only if it contains workflows or actions
### Always skip:
- `node_modules/`, `.git/`, `dist/`, `build/`, `out/`, `target/`
- `vendor/`, `.venv/`, `venv/`, `__pycache__/`
- Any directory that is generated output or third-party dependencies
## The Six Core Areas
Every good AGENTS.md covers these areas, tailored to what actually exists in the folder. Do not invent sections for things the project doesn't have.
### a) Build & Run Commands — PUT FIRST
Agents reference these constantly. Use exact commands with flags, not just tool names.
```markdown
## Build & Run
npm install # Install dependencies
npm run dev # Start dev server (port 3000)
npm run build # Production build
npm run lint # Run ESLint
```
Read these sources to find real commands:
- `package.json` → `scripts` section
- `Makefile` → targets
- `pyproject.toml` → `[tool.poetry.scripts]` or `[project.scripts]`
- `Cargo.toml` → standard cargo commands
- CI configs → `.github/workflows/*.yml`, `Jenkinsfile`, `.gitlab-ci.yml`
### b) Testing Instructions
```markdown
## Testing
pytest tests/ -v # Run all tests
pytest tests/test_auth.py -v # Run single file
pytest -k "test_login" -v # Run single test by name
pytest --cov=src --cov-report=term # With coverage
```
Include:
- Test framework and how it's configured
- How to run all tests, a single file, a single test
- Expected behavior before commits (e.g., "all tests must pass")
### c) Project Structure
```markdown
## Project Structure
src/
├── api/ # FastAPI route handlers
├── models/ # Pydantic data models
├── services/ # Business logic
└── utils/ # Shared utilities
tests/ # Mirrors src/ structure
```
Include:
- Key directories and what they contain
- Entry points (e.g., `src/main.py`, `src/index.ts`)
- Where to add new features
### d) Code Style & Conventions
One real code example beats three paragraphs of description.
```markdown
## Code Style
- snake_case for functions and variables
- PascalCase for classes
- Type hints on all function signatures
- Async/await for I/O operations
### Example
```python
async def get_user_by_id(user_id: str) -> User:
"""Fetch a user by their unique identifier."""
async with get_db_session() as session:
return await session.get(User, user_id)
```
```
Detect conventions by reading existing code:
- Naming patterns (camelCase, snake_case, PascalCase)
- Import organization (stdlib → third-party → local)
- Module structure patterns
### e) Git Workflow
```markdown
## Git Workflow
- Branch naming: `feature/`, `fix/`, `chore/`
- Commit messages: conventional commits (`feat:`, `fix:`, `docs:`)
- Run `npm test && npm run lint` before committing
- PR titles follow conventional commit format
```
Only include if the repo has evidence of conventions (e.g., commitlint config, PR templates, contributing guides).
### f) Boundaries
Use a three-tier system:
```markdown
## Boundaries
- ✅ **Always do:** Run tests before committing. Write tests for new features. Use type hints.
- ⚠️ **Ask first:** Adding new dependencies. Changing database schemas. Modifying CI/CD configs. Changing public API signatures.
- 🚫 **Never do:** Commit secrets or credentials. Modify `vendor/` or `node_modules/`. Push directly to `main`. Delete migration files.
```
Tailor boundaries to the project:
- Backend projects: schema changes, API contracts
- Frontend projects: breaking component APIs, design system changes
- Infrastructure: production configs, IAM permissions
## Generation Process
When generating an AGENTS.md for a specific folder:
### Step 1: Check existence
```bash
ls <folder>/AGENTS.md 2>/dev/null
```
If it exists, **stop**. Report and move to the next folder.
### Step 2: Scan the folder
Identify:
- Primary language (Python, TypeScript, Rust, Go, Java, C#)
- Framework (FastAPI, Next.js, Actix, Spring Boot)
- Build tool (npm, cargo, poetry, maven, gradle)
- Test runner (pytest, vitest, cargo test, JUnit)
### Step 3: Read config files
Extract real commands and settings from:
- `package.json` scripts
- `Makefile` / `Justfile` targets
- `pyproject.toml` scripts and tool configs
- `Cargo.toml` metadata
- `.github/workflows/*.yml` build/test steps
- `docker-compose.yml` service definitions
- Linter configs (`.eslintrc`, `ruff.toml`, `rustfmt.toml`)
### Step 4: Detect conventions
Read 3-5 source files to identify:
- Naming patterns
- Import organization
- Error handling style
- Comment style
- Module structure
### Step 5: Compose the AGENTS.md
Use only the sections that apply. If the folder has no tests, omit the testing section. If there's no CI config, omit git workflow.
### Step 6: Validate
Before writing the file:
- Every command references a real script, target, or tool
- Every file path references an actual file or directory
- No placeholder text like `<your-project>` or `TODO`
- No invented sections for things that don't exist
## Template Structure
```markdown
# [Folder Name] — Agent Instructions
## Overview
[1-2 sentences: what this folder/project does, its role in the larger system]
## Build & Run
[Exact commands — install, dev, build, clean]
## Testing
[Framework, run commands, single-test commands]
## Project Structure
[Key directories, entry points, where to add new things]
## Code Style
[Naming conventions + one real code example from this project]
## Boundaries
- ✅ **Always do:** [safe operations]
- ⚠️ **Ask first:** [risky operations]
- 🚫 **Never do:** [dangerous operations]
## Documentation
[Only include if wiki/, llms.txt, or docs/ exist in the repo]
- Wiki: `wiki/` — architecture, API, onboarding guides
- LLM Context: `llms.txt` — project summary for coding agents (full version: `wiki/llms-full.txt`)
- Onboarding: `wiki/onboarding/` — guides for contributors, staff engineers, executives, PMs
```
Omit any section that doesn't apply. A 20-line AGENTS.md with real commands beats a 200-line one with generic filler.
## Root vs Nested AGENTS.md
### Root AGENTS.md (`/AGENTS.md`)
Covers the entire project:
- Overall tech stack and architecture
- Global conventions and coding standards
- Dev environment setup
- Repository-wide boundaries
- CI/CD overview
### Nested AGENTS.md (e.g., `tests/AGENTS.md`)
Covers that specific subfolder:
- What this folder does and why it exists
- Folder-specific commands (e.g., `cd tests && pnpm test`)
- Folder-specific conventions
- Should NOT repeat root-level content
### Wiki AGENTS.md (`wiki/AGENTS.md`)
**ALWAYS check** if `wiki/AGENTS.md` exists before generating — same only-if-missing guard as all other folders. If it exists, skip it.
Use this template (adapt to the actual project):
```markdown
# Wiki — Agent Instructions
## Overview
Generated VitePress documentation site. Contains architecture docs, onboarding guides, and API references with source-linked citations and dark-mode Mermaid diagrams.
## Build & Run
- Install: `npm install`
- Dev server: `npm run dev`
- Build: `npm run build`
- Preview: `npm run preview`
## Wiki Structure
- `index.md` — Landing page with project overview and navigation
- `onboarding/` — Audience-tailored guides (contributor, staff engineer, executive, product manager)
- `{NN}-{section}/` — Numbered documentation sections
- `llms.txt` — LLM-friendly project summary (links + descriptions)
- `llms-full.txt` — LLM-friendly full content (inlined pages)
- `.vitepress/config.mts` — VitePress config with sidebar and Mermaid setup
- `.vitepress/theme/` — Dark theme (custom.css) and zoom handlers (index.ts)
## Content Conventions
- All Mermaid diagrams use dark-mode colors (fills `#2d333b`, borders `#6d5dfc`, text `#e6edf3`)
- Every page has VitePress frontmatter (`title`, `description`)
- Citations link to source repository with line numbers
- Tables include a "Source" column with linked citations
- Mermaid diagrams followed by `<!-- Sources: ... -->` comment blocks
## Boundaries
- ✅ **Always do:** Add new pages following existing section numbering, use dark-mode Mermaid colors
- ⚠️ **Ask first:** Change theme CSS, modify VitePress config, restructure sections
- 🚫 **Never do:** Delete generated pages without understanding dependencies, use light-mode colors, remove citation links
## Documentation
- Wiki: `./` — This folder is the wiki
- LLM Context: `llms.txt` — Quick summary; `llms-full.txt` — Full content
- Onboarding: `onboarding/` — Four audience-tailored guides
```
Fill in the real section names, technologies, and project-specific conventions.
Agents read the nearest AGENTS.md in the directory tree. Nested files take precedence, so they should contain folder-specific details, not global ones.
## CLAUDE.md Companion File
Whenever you generate an `AGENTS.md` in a folder, also generate a `CLAUDE.md` in the same folder — **only if `CLAUDE.md` does not already exist**.
The `CLAUDE.md` content is always exactly:
```markdown
# CLAUDE.md
<!-- Generated for repository development workflows. Do not edit directly. -->
Before beginning work in this repository, read `AGENTS.md` and follow all scoped AGENTS guidance.
```
This ensures Claude Code (and similar tools that look for `CLAUDE.md`) are redirected to the authoritative `AGENTS.md` instructions.
**Same guard applies:** check if `CLAUDE.md` exists before writing. If it exists, skip it.
## Quality Principles
| Principle | Good | Bad |
|-----------|------|-----|
| **Specific** | "React 18 with TypeScript, Vite, Tailwind CSS" | "React project" |
| **Executable** | `pytest tests/ -v --tb=short` | "run the tests" |
| **Grounded** | Show a real code snippet from the project | Describe the style in abstract terms |
| **Real paths** | `src/api/routes/` | `path/to/your/code/` |
| **Honest** | Omit testing section if no tests exist | Invent a testing section |
| **Concise** | 30-80 lines for most folders | 300+ lines of prose |
## Anti-Patterns to Avoid
- ❌ **"You are a helpful coding assistant"** — too vague, describes feelings not actions
- ❌ **Generic boilerplate** — content that could apply to any project provides no value
- ❌ **Invented commands/paths** — every command and path must reference something real
- ❌ **Duplicating README.md** — AGENTS.md complements README, doesn't copy it
- ❌ **Including secrets** — never put credentials, API keys, or tokens in AGENTS.md
- ❌ **Overwriting existing files** — if AGENTS.md exists, do not touch it
- ❌ **Padding empty sections** — if there are no tests, don't write a testing section
- ❌ **Describing what agents should "think" or "feel"** — describe what they should DO





首页
