agentmap 0.4.0

CLI tool to prepare codebases for AI agents by generating outlines, memory files, and reading rules
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# agentmap

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-1.70%2B-orange.svg)](https://www.rust-lang.org/)

**Prepare codebases for AI agents** by generating structured documentation that helps AI assistants understand and navigate your code effectively.

[πŸ‡»πŸ‡³ TiαΊΏng Việt](README.vi.md)

## What It Does

agentmap scans your codebase and generates a **hierarchical documentation structure** organized by modules:

```
.agentmap/
β”œβ”€β”€ INDEX.md              # L0: Global routing table
β”œβ”€β”€ modules/
β”‚   └── {module-slug}/
β”‚       β”œβ”€β”€ MODULE.md     # L1: Module summary
β”‚       β”œβ”€β”€ outline.md    # L1: Symbol maps for this module
β”‚       β”œβ”€β”€ memory.md     # L1: Warnings/TODOs for this module
β”‚       └── imports.md    # L1: Dependencies for this module
└── files/
    └── {file-slug}.md    # L2: Deep docs for complex files (optional)
```

### Content Hierarchy

| Level | File | Purpose | Size |
|-------|------|---------|------|
| L0 | `INDEX.md` | Global routing table with module overview | O(modules) |
| L1 | `MODULE.md` | Module summary, file list, entry points | O(files in module) |
| L1 | `outline.md` | Symbol maps for large files in module | O(large files) |
| L1 | `memory.md` | Warnings and TODOs scoped to module | O(markers) |
| L1 | `imports.md` | Intra/inter-module dependencies | O(imports) |
| L2 | `files/*.md` | Deep documentation for complex files | O(symbols) |

## Why?

AI coding assistants struggle with large codebases because they can't see the full picture. agentmap provides:

- **Hierarchical navigation** so AI loads only what it needs (not entire codebase docs)
- **Module detection** that groups files into semantic units automatically
- **Symbol maps** so AI knows what's in large files without reading them entirely
- **Scoped context** so each module's docs contain only relevant information

## Installation

### Quick Install (Recommended)

```bash
curl -fsSL https://raw.githubusercontent.com/nguyenphutrong/agentmap/main/scripts/install.sh | sh
```

### From crates.io

```bash
cargo install agentmap
```

### From Source

```bash
git clone https://github.com/nguyenphutrong/agentmap
cd agentmap
cargo install --path .
```

### Manual Download

Download prebuilt binaries from [GitHub Releases](https://github.com/nguyenphutrong/agentmap/releases).

## Usage

### Basic

```bash
# Generate docs for current directory (hierarchical mode - default)
agentmap

# Output to custom directory
agentmap -o docs/ai

# Preview without writing files
agentmap --dry-run

# Verbose output
agentmap -v
```

### Remote Repositories

```bash
# Analyze a GitHub repository directly
agentmap github.com/user/repo
agentmap https://github.com/vercel/next.js

# With depth limiting for large repos
agentmap --depth 3 github.com/facebook/react
```

### Git Diff Mode

```bash
# Show only files changed since a branch
agentmap --diff main

# Compare against a specific commit
agentmap --diff HEAD~5
```

### JSON Output

```bash
# Output analysis as JSON (for tooling integration)
agentmap --json > analysis.json

# Combine with other flags
agentmap --json --depth 2 github.com/user/repo
```

### Options

```
Usage: agentmap [OPTIONS] [PATH]

Arguments:
  [PATH]  Target directory or GitHub URL [default: .]

Options:
  -o, --output <OUTPUT>              Output directory [default: .agentmap]
  -t, --threshold <THRESHOLD>        Line threshold for "large" files [default: 500]
  -c, --complex-threshold <COMPLEX>  Symbol threshold for L2 file docs [default: 30]
  -d, --depth <DEPTH>                Max directory depth (0 = unlimited) [default: 0]
      --diff <REF>                   Compare against git branch/commit
      --json                         Output JSON to stdout instead of markdown files
      --check                        Check if docs are stale (exit 1 if regeneration needed)
      --config <FILE>                Path to config file
      --force                        Force regenerate all modules (ignore cache)
  -i, --ignore <IGNORE>              Additional patterns to ignore
  -l, --lang <LANG>                  Filter by language
      --no-gitignore                 Don't respect .gitignore
      --dry-run                      Preview output without writing
  -v, --verbose...                   Increase verbosity (-v, -vv, -vvv)
  -q, --quiet                        Suppress all output
  -h, --help                         Print help
  -V, --version                      Print version

Commands:
  watch   Watch for file changes and regenerate docs automatically
  hooks   Manage git hooks for automatic regeneration
  init    Initialize agentmap configuration
  update  Update agentmap to the latest version
```

## Watch Mode

Keep documentation in sync automatically during development:

```bash
# Start watching for changes (regenerates on file save)
agentmap watch

# Custom debounce delay (default: 300ms)
agentmap watch --debounce 500
```

Watch mode leverages the incremental manifest system, so only changed modules are regenerated.

## Git Hooks

Automate documentation regeneration at key git events:

```bash
# Install hooks (pre-commit, post-checkout, post-merge)
agentmap hooks install

# Remove hooks
agentmap hooks remove

# Skip hooks temporarily
AGENTMAP_SKIP=1 git commit -m "quick fix"
```

Installed hooks:
- **pre-commit**: Regenerates docs and stages `.agentmap/`
- **post-checkout**: Regenerates after branch switch (background)
- **post-merge**: Regenerates after pull/merge (background)

## Configuration File

Create `agentmap.toml` for project-specific settings:

```bash
# Generate default config file
agentmap init --config

# Use custom config location
agentmap --config custom.toml
```

Example `agentmap.toml`:

```toml
output = ".agentmap"
threshold = 500
complex_threshold = 1000
ignore = ["*.test.ts", "fixtures/", "__mocks__/"]

[watch]
debounce_ms = 300
```

CLI flags override config file values.

## AI Tool Templates

Generate ready-to-use configuration templates for popular AI coding tools:

```bash
# Generate all templates (.cursorrules, CLAUDE.md, AGENTS.md)
agentmap init --templates

# Generate specific templates only
agentmap init --templates=cursor
agentmap init --templates=claude,opencode
```

Supported tools:
- **Cursor** (`.cursorrules`) - Instructions for Cursor IDE
- **Claude Code** (`CLAUDE.md`) - Instructions for Claude Code
- **OpenCode** (`AGENTS.md`) - Instructions for OpenCode

Templates are **non-destructive**: they append to existing files and skip if agentmap section already exists.

## CI Integration

Validate documentation freshness in CI pipelines:

```bash
# Check if docs are stale (exit 0 = fresh, exit 1 = stale)
agentmap --check

# Combine with diff mode
agentmap --check --diff main
```

Example GitHub Actions workflow:

```yaml
name: Check Agentmap
on: [pull_request]

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install agentmap
        run: cargo install agentmap
      - name: Check docs freshness
        run: agentmap --check
```

## Module Detection

agentmap automatically detects module boundaries using language-specific conventions:

| Language | Explicit Boundary | Example |
|----------|-------------------|---------|
| Rust | `mod.rs`, `lib.rs` | `src/analyze/mod.rs` β†’ module `src-analyze` |
| Python | `__init__.py` | `src/utils/__init__.py` β†’ module `src-utils` |
| JavaScript/TypeScript | `index.{js,ts,tsx}` | `src/components/index.ts` β†’ module `src-components` |
| Any | 5+ source files in directory | `src/helpers/` with 5+ files β†’ implicit module |

### Module Slug Naming

Directory paths are converted to slugs using hyphens:
- `src/analyze/lang` β†’ `src-analyze-lang`
- `lib/utils` β†’ `lib-utils`

## Example Output

### INDEX.md (L0 Global)

```markdown
# Project

## Reading Protocol

**Start here**, then navigate to specific modules.

1. Read this INDEX for overview
2. Go to relevant `modules/{name}/MODULE.md`
3. Check module's `outline.md` for large files
4. Check module's `memory.md` for warnings

## Entry Points

- `src/main.rs`
- `src/lib.rs`

## Modules

| Module | Type | Files | Warnings | Hub |
| ------ | ---- | ----- | -------- | --- |
| [src]modules/src/MODULE.md | rust | 2 | - |  |
| [src/analyze]modules/src-analyze/MODULE.md | rust | 5 | ⚠️ 2 |  |
| [src/generate]modules/src-generate/MODULE.md | rust | 8 | - | πŸ”— |
```

### MODULE.md (L1 Module)

```markdown
# Module: src/analyze

[← Back to INDEX](../../INDEX.md)

**Type:** rust | **Files:** 5

**Entry point:** `src/analyze/mod.rs`

## Files

| File | Lines | Large |
| ---- | ----- | ----- |
| `src/analyze/graph.rs` | 98 |  |
| `src/analyze/parser.rs` | 650 | πŸ“„ |
| `src/analyze/mod.rs` | 10 |  |

## Child Modules

- [src-analyze-lang]../src-analyze-lang/MODULE.md

## Documentation

- [outline.md]outline.md - Symbol maps for large files
- [memory.md]memory.md - Warnings and TODOs
- [imports.md]imports.md - Dependencies
```

### outline.md (L1 Module-Scoped)

```markdown
# Outline: src/analyze

[← MODULE.md](MODULE.md) | [← INDEX.md](../../INDEX.md)

## src/analyze/parser.rs (650 lines)

| Line | Kind | Name | Visibility |
| ---- | ---- | ---- | ---------- |
| 15 | fn | parse_symbols | pub |
| 89 | fn | extract_functions | (private) |
| 156 | struct | ParseResult | pub |
```

### memory.md (L1 Module-Scoped)

```markdown
# Memory: src/analyze

[← MODULE.md]MODULE.md | [← INDEX.md]../../INDEX.md

## ⚠️ Warnings

### πŸ”΄ `WARNING` (src/analyze/parser.rs:42)
> Edge case not handled for nested generics

## πŸ”§ Technical Debt

### 🟑 `TODO` (src/analyze/graph.rs:128)
> Optimize cycle detection algorithm
```

## Supported Languages

| Language | Symbol Extraction | Import Graph | Memory Markers | Module Detection |
|----------|-------------------|--------------|----------------|------------------|
| Rust | βœ… Functions, structs, enums, traits, impls | βœ… | βœ… | βœ… `mod.rs` |
| Python | βœ… Functions, classes, methods | βœ… | βœ… | βœ… `__init__.py` |
| JavaScript/TypeScript | βœ… Functions, classes, arrow functions | βœ… | βœ… | βœ… `index.{js,ts}` |
| Go | βœ… Functions, structs, interfaces, methods | βœ… | βœ… | βœ… implicit |
| Swift | βœ… Functions, classes, structs, enums, protocols | βœ… | βœ… | βœ… implicit |
| Dart | βœ… Functions, classes, mixins, extensions | βœ… | βœ… | βœ… implicit |
| Ruby | βœ… Methods, classes, modules | βœ… | βœ… | βœ… implicit |
| C# | βœ… Methods, classes, structs, interfaces | βœ… | βœ… | βœ… implicit |
| Java | βœ… Methods, classes, interfaces, enums | βœ… | βœ… | βœ… implicit |

## Memory Markers

agentmap extracts these comment patterns:

| Pattern | Category | Priority |
|---------|----------|----------|
| `TODO`, `FIXME`, `XXX`, `BUG`, `HACK` | Technical Debt | Medium |
| `WARNING`, `WARN` | Warnings | High |
| `SAFETY`, `INVARIANT` | Safety | High |
| `RULE`, `POLICY` | Business Rules | High |
| `DEPRECATED` | Technical Debt | High |
| `NOTE` | Notes | Low |

## Integration with AI Tools

### Claude Code / Cursor

Add to your project's AI instructions:

```
Before working on this codebase, read:
1. .agentmap/INDEX.md - for project overview and module routing
2. Navigate to relevant module's MODULE.md for details
3. Check module's memory.md for warnings before editing
4. Consult module's outline.md for large file navigation
```

### GitHub Copilot

Include `.agentmap/` in your workspace context.

### JSON Integration

For programmatic access:

```bash
agentmap --json | jq '.modules[] | {slug, file_count, warning_count}'
```

JSON output includes:
- `modules[]` - Array of module metadata (slug, path, file_count, warning_count, symbol_count, is_hub)
- `files[]` - All scanned files with metadata
- `memory[]` - All memory markers with locations
- `entry_points[]` - Detected entry points
- `hub_files[]` - Files imported by 3+ others

## Development

```bash
# Run tests
cargo test

# Run with verbose output
cargo run -- -vv .

# Check for issues
cargo clippy
```

## License

MIT License - see [LICENSE](LICENSE) for details.