Hierarchical agents

From majesticlabs-dev/majestic-marketplace · View interactive version

Hierarchical agents is an AI agent skill from the GitHub repository majesticlabs-dev/majestic-marketplace. Generate hierarchical AGENTS.md structure for codebases to optimize AI agent token usage. Use when creating AGENTS.md files, documenting codebase structure, setting up agent guidance, organizing project documentation for AI tools, implementing JIT indexing, or working with monorepos that need lightw

How to use this skill

Skill file

Hierarchical Agents Documentation Generator

Purpose

Create a hierarchical AGENTS.md system for codebases that enables AI coding agents to work efficiently with minimal token usage. Generates lightweight root documentation with detailed sub-folder guidance following the "nearest-wins" principle.

When to Use

Process

Follow these phases in order. See references/generation-process.md for complete details.

Phase 1: Repository Analysis

Analyze the codebase:

  1. Repository type (monorepo, multi-package, simple)
  2. Technology stack (languages, frameworks, tools)
  3. Major directories (apps, services, packages)
  4. Build system and testing setup
  5. Key patterns, conventions, anti-patterns

Output: Structured map of the repository before generating any files.

Phase 2: Generate Root AGENTS.md

Root must be lightweight: ~100-200 lines maximum, universal guidance only. Acts as index and navigation hub. Agents read the closest AGENTS.md to the file being edited — sub-folder files override root (nearest-wins).

Create root file with these sections:

  1. Project Snapshot (3-5 lines)
  1. Root Setup Commands (5-10 lines)
  1. Universal Conventions (5-10 lines)
  1. Implementation Rules (2-3 lines) — see example below
  2. Development Workflow (5-7 lines) — see example below
  3. Security & Secrets (3-5 lines)
  1. JIT Index - Directory Map (10-20 lines) — see example below
  1. Acceptance Criteria (3-5 lines)

Example Implementation Rules:

## Implementation Rules

Before adding ANY external dependency (gems, npm packages, GitHub Actions, Docker images, APIs, CDN links):
- Use WebSearch to verify the latest stable version BEFORE implementation
- Never trust training data for version numbers

Example JIT Index:

## JIT Index (what to open, not what to paste)

### Package Structure
- Web UI: `apps/web/` -> [see apps/web/AGENTS.md](apps/web/AGENTS.md)
- API: `apps/api/` -> [see apps/api/AGENTS.md](apps/api/AGENTS.md)
- Shared packages: `packages/**/` -> [see packages/README.md]

### Quick Find Commands
- Search function: `rg -n "functionName" apps/** packages/**`
- Find component: `rg -n "export.*ComponentName" apps/web/src`
- Find API routes: `rg -n "export const (GET|POST)" apps/api`

Example Development Workflow:

## Development Workflow

- Before coding -> describe approach -> wait for approval
- Ambiguous requirements -> ask first
- If task touches >3 files -> decompose first
- After coding -> list breakage risks + suggest tests
- Bug fix -> write failing test -> fix until green
- When corrected -> add lesson to .agents/lessons/

Phase 3: Generate Sub-Folder AGENTS.md Files

Sub-folders have MORE detail than root — specific patterns, technology-specific conventions, real file examples from the codebase.

For EACH major package/directory, create detailed AGENTS.md:

  1. Package Identity (2-3 lines)
  2. Setup & Run (5-10 lines)
  3. Patterns & Conventions (10-20 lines) - MOST IMPORTANT
  4. Touch Points / Key Files (5-10 lines)
  5. JIT Index Hints (5-10 lines)
  6. Common Gotchas (3-5 lines)
  7. Pre-PR Checks (2-3 lines)

Key: Patterns & Conventions must include real file paths with DO/DON'T examples.

Phase 4: Special Considerations

Adapt templates for specific package types (Design System, Database, API, Testing).

See references/generation-process.md for specialized templates.

Directory Structures

Monorepo

AGENTS.md                    # Root (lightweight)
apps/
  web/AGENTS.md             # Frontend details
  api/AGENTS.md             # Backend details
packages/
  ui/AGENTS.md              # Design system details
  shared/AGENTS.md          # Shared code details

Simple Project

AGENTS.md                    # Root (can be more detailed)
src/
  components/AGENTS.md      # Component patterns
  services/AGENTS.md        # Service patterns

Quality Checklist

Maintenance

Update AGENTS.md when:

Related Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.