A simple-to-use Python script to generate, maintain, and integrate a visual tree map of your repository directory structure. This tool offers a range of features including repo map insertion as comments into existing files, Git integration, and robust file handling.
When using a Language Model (LLM) and a large codebase, including a repository map can improve accuracy of generated code. We manually copy/paste the repo map file or include it as a comment at the top of each code file to provide the LLM with essential context. This can lead to better code comprehension and more precise interactions.
# Repository Map
repo_map_generator/
βββ misc/
β βββ cat_pictures/
βββ secret_plans/
βββ girl_scout_thin_mints_recipe.md
βββ world_domination_checklist.md
βββ next_gen_ai/
βββ TODO.py
βββ skynet_prototype.py
File: girl_scout_thin_mints_recipe.md
- π³ Generate a tree-like map of your repository
- π Create a standalone Markdown file with the repository map
- π [Optional] Update relevant files in the repository to add a comment with the current repo map at the top of the file.
- πΎ [Optional] Git integration for automatic commits
- π [Optional] Backup functionality to preserve original files
- π¨ Support for various file types with appropriate comment styles
- π« Intelligent file and directory exclusions
- π Long path handling for backups
- π Detailed metrics and execution summary
- Python 3.6+
- Git (optional, for version control integration)
- Place the
repo_map_generator.py
file in the root directory of your repository. - Run the script with:
python repo_map_generator.py
This will generate a repo_map.md
file in the current directory.
Option | Description |
---|---|
--update-files |
Update existing files with the repository map |
--backup |
Create backups before modifying files (use with --update-files) |
--output FILENAME |
Specify the output file name (default: repo_map.md) |
--verbose |
Enable verbose logging |
--force |
Force update files even if backup fails |
Example:
python repo_map_generator.py --update-files --backup --output my_repo_map.md --verbose
- Traverses the directory structure
- Generates a tree-like representation
- Creates a Markdown file with the map
- Optionally updates files with the new map (with user confirmation)
- Provides options for backing up files before modifications
- Handles binary files and long paths
- Offers Git integration for committing changes
Modify EXCLUDE_FILES
, EXCLUDE_DIRS
, and COMMENT_STYLES
in the script to customize behavior. These comprehensive sets allow for fine-tuned control over which files and directories are included or excluded from the map.
When used in a Git repository, the script offers an option to automatically commit changes:
- After updating files, it prompts to commit changes
- If confirmed, stages modified files and creates a commit
- Commit message: "Update repository map"
This ensures your repository map updates are properly versioned.
The script now provides a detailed summary of its execution, including:
- Total files processed
- Files modified
- Files skipped
- Backup size
- Errors encountered
- Total execution time
- Preview changes before applying
- Option to create backups before modifying files
- Binary file detection to avoid corrupting non-text files
- Handling of long file paths for backups
Contributions are welcome! Please feel free to submit issues or pull requests.
For questions or issues, please open an issue on the GitHub repository.