A high-performance knowledge-base map generator CLI (rust language) tool that scans a structured directory of documents and compiles a comprehensive, sorted index map (map.json).
This tool is designed to generate machine-readable sitemaps for multi-agent systems, AI assistants (such as Windsurf, Cursor, or Claude Code), and static site generators. By maintaining a single map.json index, AI agents can immediately understand your entire knowledge base structure, file descriptions, and paths without wasting token context scanning the filesystem.
- 🚀 High Performance: Written in Rust for blazing-fast recursive directory scanning, parsing, and JSON serialization.
- 📂 Flexible Schema: Supports nested directories, tracking files and categories recursively.
- 📝 Intelligent Metadata Extraction:
- YAML Frontmatter: Parses Markdown files (
.md) starting with---for explicitnameanddescriptiontags. - Smart Fallback for Markdown: If frontmatter is missing, it auto-generates a
kebab-casename from the filename and extracts the first non-empty paragraph or heading as the description. - Programming Language Source Code Files Integration: Parses
.zig,.ts,.py,.c,.cpp,.h,.hppsource files, automatically using the first line-level comment (//,/**,/*,///,#!,//!) as the description.
- YAML Frontmatter: Parses Markdown files (
- 🔀 Deterministic Sorting: Alphabetically sorts all paths and files recursively to ensure git diffs are clean and predictable.
- Rust / Cargo: Rust Toolchain (v1.75+ or newer recommended)
The generator expects a directory named docs/ in the working directory where it is run:
my-knowledge-base/
- docs/
- index.md # Markdown with/without frontmatter
- getting-started.md
- advanced-topics/
- configuration.md
- example.rust # Code samples with comments
Add a YAML frontmatter block at the top of your markdown files:
---
name: getting-started
description: A beginner's guide to setting up and configuring the environment.
---
# Getting Started
This is the body of the markdown document...If no frontmatter is found, the tool will kebab-case the filename (e.g. getting-started) and use the first paragraph/heading as the description.
Add a documentation comment at the very top of your programming source code files:
//! An example demonstrating standard library HashMap usage.
const std = @import("std");
...Clone this scripts directory or place it in your repository:
# Navigate to the scripts directory
cd scripts/
# Build the release binary
cargo build --releaseTo run the tool and generate the map, execute the compiled binary from your workspace root (where the docs/ folder is located):
# From workspace root
./scripts/target/release/md-mapThis will read your ./docs/ folder and output a ./map.json file in the same workspace root directory:
Updated map.json with 3 top-level entries.The generated map.json is a deterministic tree representing your documentation structure.
- Root Level: A sorted JSON array of entries.
- File Entry: Contains the file's metadata and relative path.
{
"name": "getting-started",
"description": "A beginner's guide to setting up and configuring the environment.",
"path": "getting-started.md"
}- Directory / Category Entry: Contains a title, a trailing slash relative path, and a
childrenarray.
{
"description": "Advanced Topics",
"path": "advanced-topics/",
"children": [
{
"name": "configuration",
"description": "Deep-dive into advanced configuration parameters.",
"path": "advanced-topics/configuration.md"
}
]
}This tool is entirely context-agnostic. Any workspace containing structured files under a docs/ directory can immediately use it to index its contents.
To support other language specifications or custom metadata extraction (e.g. parsing Python docstrings, JSDoc comment blocks, or JSON config files), modify file_metadata in src/main.rs:
// In src/main.rs
fn file_metadata(full_path: &Path, basename: &str) -> (String, String) {
...
// Add custom handlers here for other extensions like .py, .ts, etc.
}To optimize interactions with AI code assistants (like Windsurf, Cursor, or Claude Code), add the index map directly to your agent system instructions (.agents or workspace README.md):
### AI Prompting Guideline
To understand the structure of the documentation and knowledge base, read `./map.json` at the start of your workflow.
When creating or updating files, always run:
`./scripts/target/release/md-map` (or the equivalent map update command) to ensure map.json remains synchronized.