|
| 1 | +--- |
| 2 | +description: Create comprehensive, hierarchical AGENTS.md documentation across the codebase |
| 3 | +--- |
| 4 | + |
| 5 | +# MANDATORY RULES — VIOLATION IS FORBIDDEN |
| 6 | + |
| 7 | +- **Response language follows `language` setting in `.agent/config/user-preferences.yaml` if configured.** |
| 8 | +- **NEVER skip steps.** Execute from Step 0 in order. Explicitly report completion of each step before proceeding. |
| 9 | +- **You MUST use MCP tools throughout the entire workflow.** This is NOT optional. |
| 10 | + - Use code analysis tools (`get_symbols_overview`, `find_symbol`, `search_for_pattern`, `list_dir`, `view_file`) for code exploration. |
| 11 | + - Use file writing tools to generate `AGENTS.md` files. |
| 12 | +- **Exclude directories:** Respect the project's `.gitignore` as the source of truth for excluding directories (e.g., `node_modules`, `dist`, `build`, etc.). Additionally, exclude framework auto-generated or native shell directories that do not contain core business logic (e.g., Flutter's `android`, `ios`, `macos`, `linux`, `windows`, `web`). Do not generate `AGENTS.md` for these ignored or excluded paths. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## Step 0: Preparation |
| 17 | + |
| 18 | +1. Read `.agent/skills/workflow-guide/SKILL.md` and confirm Core Rules. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Step 1: Map Directory Structure |
| 23 | + |
| 24 | +**Identify all valid directories recursively.** |
| 25 | + |
| 26 | +- **Target Level 0:** `/` (root) |
| 27 | +- **Target Levels:** Drill down iteratively (e.g., Level 1: `/src`, `/docs`, `/tests`, `/apps`, `/packages`; Level 2: nested structure). |
| 28 | +- **Empty Directory Handling:** |
| 29 | + - If no files and no subdirectories: **Skip**. |
| 30 | + - If only config files or generated files: minimal `AGENTS.md`. |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## Step 2: Create Work Plan |
| 35 | + |
| 36 | +Determine generation order. |
| 37 | +**IMPORTANT:** Generation MUST happen top-down (parent first) to ensure parent tags are correct. |
| 38 | + |
| 39 | +Plan the work across directory levels. Report the depth plan to the user. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +## Step 3: Content Generation Level by Level |
| 44 | + |
| 45 | +For each directory in the plan: |
| 46 | + |
| 47 | +1. **Read all directory content** using `list_dir` and analyze the purpose using `get_symbols_overview` or reading key files. |
| 48 | +2. **Determine Parent Reference:** |
| 49 | + - Root has no parent tag. |
| 50 | + - Any child has: `<!-- Parent: {relative_path_to_parent}/AGENTS.md -->`. |
| 51 | +3. **Template Format to Use:** |
| 52 | + |
| 53 | +```markdown |
| 54 | +<!-- Parent: ../AGENTS.md --> <!-- Adjust this relative path appropriately. Omit entirely for root directory. --> |
| 55 | +<!-- Generated: {timestamp} | Updated: {timestamp} --> |
| 56 | + |
| 57 | +# {Directory Name} |
| 58 | + |
| 59 | +## Purpose |
| 60 | +{One-paragraph description of what this directory contains and its role} |
| 61 | + |
| 62 | +## Key Files |
| 63 | +| File | Description | |
| 64 | +|------|-------------| |
| 65 | +| `file.ts` | Detailed one-line purpose | |
| 66 | + |
| 67 | +## Subdirectories |
| 68 | +| Directory | Purpose | |
| 69 | +|-----------|---------| |
| 70 | +| `subdir/` | What it contains (see `subdir/AGENTS.md`) | |
| 71 | + |
| 72 | +## For AI Agents |
| 73 | +### Working In This Directory |
| 74 | +{Special instructions for AI agents modifying files here} |
| 75 | + |
| 76 | +### Dependencies |
| 77 | +{Internal or external parts of the codebase this depends on} |
| 78 | + |
| 79 | +<!-- MANUAL: Any manually added notes below this line are preserved on regeneration --> |
| 80 | +``` |
| 81 | + |
| 82 | +1. **Parallel Generation:** |
| 83 | + - If directories are large or complex, use `oh-my-ag agent:spawn {agent_id} "Write AGENTS.md based on this directory" session_id -w {path}` to distribute the context load across suitable domain agents. |
| 84 | + - For simple directories, you can write them directly. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## Step 4: Compare and Update Existing (If Applicable) |
| 89 | + |
| 90 | +If an `AGENTS.md` file already exists: |
| 91 | + |
| 92 | +1. Parse the existing file. |
| 93 | +2. Compare structural changes (new files, removed subdirectories). |
| 94 | +3. **CRITICAL:** Preserve the manual annotation block intact. Everything after `<!-- MANUAL:` must be copied exactly. |
| 95 | +4. Merge contents and update the generated timestamp. |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Step 5: Validate Hierarchy |
| 100 | + |
| 101 | +Use tools to perform a sweeping check on all generated `AGENTS.md` files: |
| 102 | + |
| 103 | +1. Ensure all `<!-- Parent: -->` references resolve to an existing `AGENTS.md` file. |
| 104 | +2. Verify all listed `Key Files` exist in the directory. |
| 105 | +3. Remove orphaned `AGENTS.md` files where directories no longer exist or parent links are broken. |
0 commit comments