NB: this README was generated from the project itself.
A Rust CLI tool that uses AI to generate comprehensive README documentation for codebases by analyzing source files.
Summarize is a developer tool that solves the problem of understanding and documenting codebases with minimal effort. It scans your project's source files, sends them to an AI model (by default GPT-4o-mini), and generates a detailed README that helps developers quickly understand the project structure, key abstractions, and usage patterns.
- Scan source files in a directory based on file extensions or glob patterns
- Stream file contents to handle large codebases without memory issues
- Generate comprehensive documentation using AI that understands code context
- Customizable file selection to focus on the most relevant parts of your codebase
- Support for different AI models
To build from source, ensure you have Rust installed (2024 edition), then:
git clone https://github.com/yourusername/summarize.git
cd summarize
cargo build --release
The binary will be available at ./target/release/summarize
.
# Generate README for current directory
summarize
# Specify a directory to analyze
summarize --dir /path/to/project
# Only include specific file types
summarize --file-types rs js ts
# Use glob patterns to include specific files
summarize --globs "src/**/*.rs" "lib/**/*.rs"
# Use a different AI model
summarize --model gpt-4o-mini
OPTIONS:
-d, --dir <DIR> The directory to walk. Defaults to the current dir
-f, --file-types <FILE_TYPES> The file types to include (e.g. 'kt', 'rs')
-g, --globs <GLOBS> Globs to include
-m, --model <MODEL> AI model to use [default: gpt-4o-mini]
-h, --help Print help
Summarize works in three main steps:
- File Collection: The tool scans the specified directory for source files that match the given file types or glob patterns.
let mut stream = files::stream(FindOpts {
dir: dir.clone(),
file_types: args.file_types.clone(),
globs: args.globs.clone(),
});
- File Processing: It reads each file and builds a prompt containing the file contents.
while let Some(res) = stream.next().await {
let info = res?;
let path = info.path.to_string_lossy();
let contents = String::from_utf8_lossy(&info.bs).to_string();
buf.push_str(&header);
buf.push_str(&format!("\n## Path:{}\n\n{}\n", path, contents));
}
- AI Generation: The collected file contents are sent to the AI model, which analyzes the code and generates a comprehensive README.
let client = Client::default();
let resp: ChatResponse = client
.exec_chat(model, reqs, None)
.await
.context("failed to call model")?;
Here's an example of generating a README for a Rust project:
$ cd /path/to/my/rust/project
$ summarize --file-types rs --globs "src/**/*.rs"
The tool will scan all Rust files in the src directory, analyze them, and output a comprehensive README to the console, which you can then save to your project.
main.rs
: Entry point that parses command-line arguments and runs the main functionlib.rs
: Core logic including argument definitions, AI client setup, and main processing loopfiles.rs
: File handling utilities for finding and streaming file contents
The project relies on several key dependencies:
- clap: Command-line argument parsing
- genai: Client for interacting with AI models
- ignore: Fast file system traversal (similar to ripgrep)
- tokio: Asynchronous runtime for efficient file processing
- futures-util: Utilities for working with asynchronous streams
If you're interested in contributing to this project, here are some good places to start:
- Prompt Engineering: Improve the prompt template in
prompt.md
to generate better READMEs - File Filtering: Enhance the file selection logic to better handle different project structures
- Output Options: Add support for writing output to a file and other formatting options
- Model Selection: Implement support for additional AI models and providers
- Performance: Optimize file processing for very large codebases
[License Information]
Contributions are welcome! Please feel free to submit a Pull Request.