agent-md-refactor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAgent MD Refactor
Agent MD 重构
Refactor bloated agent instruction files (AGENTS.md, CLAUDE.md, COPILOT.md, etc.) to follow progressive disclosure principles - keeping essentials at root and organizing the rest into linked, categorized files.
重构臃肿的Agent说明文件(AGENTS.md、CLAUDE.md、COPILOT.md等),遵循渐进式披露原则——将核心内容保留在根文件中,其余内容整理为分类明确的关联文件。
Triggers
触发场景
Use this skill when:
- "refactor my AGENTS.md" / "refactor my CLAUDE.md"
- "split my agent instructions"
- "organize my CLAUDE.md file"
- "my AGENTS.md is too long"
- "progressive disclosure for my instructions"
- "clean up my agent config"
在以下场景中使用此技能:
- "重构我的AGENTS.md" / "重构我的CLAUDE.md"
- "拆分我的Agent说明文档"
- "整理我的CLAUDE.md文件"
- "我的AGENTS.md太长了"
- "为我的说明文档应用渐进式披露"
- "清理我的Agent配置文档"
Quick Reference
快速参考
| Phase | Action | Output |
|---|---|---|
| 1. Analyze | Find contradictions | List of conflicts to resolve |
| 2. Extract | Identify essentials | Core instructions for root file |
| 3. Categorize | Group remaining instructions | Logical categories |
| 4. Structure | Create file hierarchy | Root + linked files |
| 5. Prune | Flag for deletion | Redundant/vague instructions |
| 阶段 | 操作 | 输出 |
|---|---|---|
| 1. 分析 | 查找矛盾内容 | 需要解决的冲突列表 |
| 2. 提取 | 识别核心内容 | 根文件的核心说明 |
| 3. 分类 | 对剩余内容分组 | 逻辑分类结果 |
| 4. 结构化 | 创建文件层级 | 根文件 + 关联子文件 |
| 5. 精简 | 标记待删除内容 | 冗余/模糊的说明内容 |
Process
流程
Phase 1: Find Contradictions
阶段1:查找矛盾内容
Identify any instructions that conflict with each other.
Look for:
- Contradictory style guidelines (e.g., "use semicolons" vs "no semicolons")
- Conflicting workflow instructions
- Incompatible tool preferences
- Mutually exclusive patterns
For each contradiction found:
markdown
undefined识别所有相互冲突的说明。
需要关注:
- 矛盾的风格指南(例如:"使用分号" vs "不使用分号")
- 冲突的工作流说明
- 不兼容的工具偏好
- 互斥的模式
对于每个发现的矛盾:
markdown
undefinedContradiction Found
发现矛盾内容
Instruction A: [quote]
Instruction B: [quote]
Question: Which should take precedence, or should both be conditional?
Ask the user to resolve before proceeding.
---说明A: [引用内容]
说明B: [引用内容]
问题: 哪一个应该优先,还是两者都应设置为条件性规则?
在继续前请询问用户解决这些矛盾。
---Phase 2: Identify the Essentials
阶段2:识别核心内容
Extract ONLY what belongs in the root agent file. The root should be minimal - information that applies to every single task.
Essential content (keep in root):
| Category | Example |
|---|---|
| Project description | One sentence: "A React dashboard for analytics" |
| Package manager | Only if not npm (e.g., "Uses pnpm") |
| Non-standard commands | Custom build/test/typecheck commands |
| Critical overrides | Things that MUST override defaults |
| Universal rules | Applies to 100% of tasks |
NOT essential (move to linked files):
- Language-specific conventions
- Testing guidelines
- Code style details
- Framework patterns
- Documentation standards
- Git workflow details
仅提取属于根Agent文件的内容。根文件应尽可能精简——仅包含适用于每一项任务的信息。
核心内容(保留在根文件中):
| 分类 | 示例 |
|---|---|
| 项目描述 | 一句话描述:"用于数据分析的React仪表盘" |
| 包管理器 | 仅当不是npm时(例如:"使用pnpm") |
| 非标准命令 | 自定义的构建/测试/类型检查命令 |
| 关键覆盖规则 | 必须覆盖默认设置的内容 |
| 通用规则 | 适用于100%任务的规则 |
非核心内容(移至关联文件):
- 特定语言的约定
- 测试指南
- 代码风格细节
- 框架模式
- 文档标准
- Git工作流细节
Phase 3: Group the Rest
阶段3:对剩余内容分组
Organize remaining instructions into logical categories.
Common categories:
| Category | Contents |
|---|---|
| TS conventions, type patterns, strict mode rules |
| Test frameworks, coverage, mocking patterns |
| Formatting, naming, comments, structure |
| Commits, branches, PRs, reviews |
| Patterns, folder structure, dependencies |
| REST/GraphQL conventions, error handling |
| Auth patterns, input validation, secrets |
| Optimization rules, caching, lazy loading |
Grouping rules:
- Each file should be self-contained for its topic
- Aim for 3-8 files (not too granular, not too broad)
- Name files clearly:
{topic}.md - Include only actionable instructions
将剩余说明整理为逻辑分类。
常见分类:
| 分类 | 内容 |
|---|---|
| TS约定、类型模式、严格模式规则 |
| 测试框架、覆盖率、模拟模式 |
| 格式化、命名、注释、结构 |
| 提交、分支、PR、评审 |
| 模式、文件夹结构、依赖 |
| REST/GraphQL约定、错误处理 |
| 认证模式、输入验证、密钥管理 |
| 优化规则、缓存、懒加载 |
分组规则:
- 每个文件应围绕其主题独立成篇
- 目标为3-8个文件(既不过于细分,也不过于宽泛)
- 文件命名清晰:
{topic}.md - 仅包含可执行的说明
Phase 4: Create the File Structure
阶段4:创建文件结构
Output structure:
project-root/
├── CLAUDE.md (or AGENTS.md) # Minimal root with links
└── .claude/ # Or docs/agent-instructions/
├── typescript.md
├── testing.md
├── code-style.md
├── git-workflow.md
└── architecture.mdRoot file template:
markdown
undefined输出结构:
project-root/
├── CLAUDE.md (或 AGENTS.md) # 精简的根文件,包含关联链接
└── .claude/ # 或 docs/agent-instructions/
├── typescript.md
├── testing.md
├── code-style.md
├── git-workflow.md
└── architecture.md根文件模板:
markdown
undefinedProject Name
项目名称
One-sentence description of the project.
一句话描述项目。
Quick Reference
快速参考
- Package Manager: pnpm
- Build:
pnpm build - Test:
pnpm test - Typecheck:
pnpm typecheck
- 包管理器: pnpm
- 构建:
pnpm build - 测试:
pnpm test - 类型检查:
pnpm typecheck
Detailed Instructions
详细说明
For specific guidelines, see:
- TypeScript Conventions
- Testing Guidelines
- Code Style
- Git Workflow
- Architecture Patterns
**Each linked file template:**
```markdown如需特定指南,请查看:
- TypeScript约定
- 测试指南
- 代码风格
- Git工作流
- 架构模式
**每个关联文件的模板:**
```markdown{Topic} Guidelines
{主题} 指南
Overview
概述
Brief context for when these guidelines apply.
简要说明这些指南的适用场景。
Rules
规则
Rule Category 1
规则分类1
- Specific, actionable instruction
- Another specific instruction
- 具体的可执行说明
- 另一条具体说明
Rule Category 2
规则分类2
- Specific, actionable instruction
- 具体的可执行说明
Examples
示例
Good
正确示例
```typescript
// Example of correct pattern
```
typescript
// 正确模式的示例Avoid
避免示例
```typescript
// Example of what not to do
```
---typescript
// 应避免的示例
---Phase 5: Flag for Deletion
阶段5:标记待删除内容
Identify instructions that should be removed entirely.
Delete if:
| Criterion | Example | Why Delete |
|---|---|---|
| Redundant | "Use TypeScript" (in a .ts project) | Agent already knows |
| Too vague | "Write clean code" | Not actionable |
| Overly obvious | "Don't introduce bugs" | Wastes context |
| Default behavior | "Use descriptive variable names" | Standard practice |
| Outdated | References deprecated APIs | No longer applies |
Output format:
markdown
undefined识别应完全移除的说明。
符合以下条件则删除:
| 标准 | 示例 | 删除原因 |
|---|---|---|
| 冗余 | "使用TypeScript"(在.ts项目中) | Agent已知晓此信息 |
| 过于模糊 | "编写干净的代码" | 不具备可执行性 |
| 过于明显 | "不要引入bug" | 浪费上下文信息 |
| 默认行为 | "使用描述性变量名" | 标准实践 |
| 过时 | 引用已废弃的API | 不再适用 |
输出格式:
markdown
undefinedFlagged for Deletion
标记待删除内容
| Instruction | Reason |
|---|---|
| "Write clean, maintainable code" | Too vague to be actionable |
| "Use TypeScript" | Redundant - project is already TS |
| "Don't commit secrets" | Agent already knows this |
| "Follow best practices" | Meaningless without specifics |
---| 说明 | 原因 |
|---|---|
| "编写干净、可维护的代码" | 过于模糊,不具备可执行性 |
| "使用TypeScript" | 冗余 - 项目已为TS项目 |
| "不要提交密钥" | Agent已知晓此信息 |
| "遵循最佳实践" | 无具体内容,无意义 |
---Execution Checklist
执行检查清单
[ ] Phase 1: All contradictions identified and resolved
[ ] Phase 2: Root file contains ONLY essentials
[ ] Phase 3: All remaining instructions categorized
[ ] Phase 4: File structure created with proper links
[ ] Phase 5: Redundant/vague instructions removed
[ ] Verify: Each linked file is self-contained
[ ] Verify: Root file is under 50 lines
[ ] Verify: All links work correctly[ ] 阶段1:所有矛盾已识别并解决
[ ] 阶段2:根文件仅包含核心内容
[ ] 阶段3:所有剩余说明已完成分类
[ ] 阶段4:已创建带正确关联的文件结构
[ ] 阶段5:冗余/模糊说明已移除
[ ] 验证:每个关联文件独立成篇
[ ] 验证:根文件少于50行
[ ] 验证:所有链接可正常访问Anti-Patterns
反模式
| Avoid | Why | Instead |
|---|---|---|
| Keeping everything in root | Bloated, hard to maintain | Split into linked files |
| Too many categories | Fragmentation | Consolidate related topics |
| Vague instructions | Wastes tokens, no value | Be specific or delete |
| Duplicating defaults | Agent already knows | Only override when needed |
| Deep nesting | Hard to navigate | Flat structure with links |
| 应避免 | 原因 | 替代方案 |
|---|---|---|
| 所有内容保留在根文件 | 臃肿,难以维护 | 拆分为关联文件 |
| 分类过多 | 碎片化严重 | 合并相关主题 |
| 模糊的说明 | 浪费token,无价值 | 具体化或删除 |
| 重复默认行为 | Agent已知晓 | 仅在需要时覆盖默认设置 |
| 深层嵌套 | 难以导航 | 扁平化结构+关联链接 |
Examples
示例
Before (Bloated Root)
重构前(臃肿的根文件)
markdown
undefinedmarkdown
undefinedCLAUDE.md
CLAUDE.md
This is a React project.
这是一个React项目。
Code Style
代码风格
- Use 2 spaces
- Use semicolons
- Prefer const over let
- Use arrow functions ... (200 more lines)
- 使用2个空格缩进
- 使用分号
- 优先使用const而非let
- 使用箭头函数 ...(200多行)
Testing
测试
- Use Jest
- Coverage > 80% ... (100 more lines)
- 使用Jest
- 覆盖率>80% ...(100多行)
TypeScript
TypeScript
- Enable strict mode ... (150 more lines)
undefined- 启用严格模式 ...(150多行)
undefinedAfter (Progressive Disclosure)
重构后(渐进式披露)
markdown
undefinedmarkdown
undefinedCLAUDE.md
CLAUDE.md
React dashboard for real-time analytics visualization.
用于实时数据分析可视化的React仪表盘。
Commands
命令
- - Start development server
pnpm dev - - Run tests with coverage
pnpm test - - Production build
pnpm build
- - 启动开发服务器
pnpm dev - - 运行带覆盖率的测试
pnpm test - - 生产构建
pnpm build
Guidelines
指南
- Code Style
- Testing
- TypeScript
---- 代码风格
- 测试
- TypeScript
---Verification
验证
After refactoring, verify:
- Root file is minimal - Under 50 lines, only universal info
- Links work - All referenced files exist
- No contradictions - Instructions are consistent
- Actionable content - Every instruction is specific
- Complete coverage - No instructions were lost (unless flagged for deletion)
- Self-contained files - Each linked file stands alone
重构完成后,验证以下内容:
- 根文件精简 - 少于50行,仅包含通用信息
- 链接可用 - 所有引用的文件均存在
- 无矛盾 - 说明内容一致
- 内容可执行 - 每条说明都具体明确
- 覆盖完整 - 无说明丢失(除非标记为待删除)
- 文件独立成篇 - 每个关联文件可单独使用