mirror of
https://github.com/PR0M3TH3AN/RePrompt.git
synced 2025-09-07 06:28:43 +00:00
update
This commit is contained in:
38
.gitignore
vendored
38
.gitignore
vendored
@@ -6,9 +6,6 @@ __pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# Encrypted index file should be backed up, hence not ignored
|
||||
!.deterministic_password_generator/password_indices.csv
|
||||
|
||||
# Ignore system files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
@@ -16,7 +13,38 @@ Thumbs.db
|
||||
# Ignore logs and temporary files
|
||||
*.log
|
||||
*.tmp
|
||||
logs/
|
||||
tmp/
|
||||
|
||||
# Python env
|
||||
# Ignore Python environment and configuration files
|
||||
.env
|
||||
*.env
|
||||
*.env
|
||||
*.config.yaml
|
||||
saved_config.yaml
|
||||
|
||||
# Ignore application-generated files
|
||||
repo-context.txt
|
||||
|
||||
# Ignore static files generated for UI
|
||||
static_files/*.txt
|
||||
static_files/*.log
|
||||
|
||||
# Ignore IDE configuration files
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Ignore dependency management files
|
||||
*.lock
|
||||
|
||||
# Ignore build artifacts
|
||||
build/
|
||||
dist/
|
||||
*.egg-info/
|
||||
|
||||
# Ignore test output files
|
||||
tests/__pycache__/
|
||||
tests/*.py[cod]
|
||||
|
||||
# Ignore specific output folders or other user-defined directories
|
||||
output/
|
||||
generated/
|
||||
|
253
README.md
253
README.md
@@ -1,3 +1,5 @@
|
||||
Here's the improved README.md:
|
||||
|
||||
# RePrompt: A Context Generator
|
||||
|
||||
This app is to be used in conjunction with [mckaywrigley's xml parser](https://github.com/mckaywrigley/o1-xml-parser/tree/main).
|
||||
@@ -12,168 +14,219 @@ The **RePrompt** is a tool designed to create a comprehensive context file (`rep
|
||||
- **File Content Integration**: Includes syntax-highlighted contents of key files.
|
||||
- **Static Content Integration**: Adds static sections from files such as `overview.txt` and `to-do_list.txt`.
|
||||
- **Save & Load Configurations**: Retain file inclusion/exclusion preferences for future sessions.
|
||||
- **Default Exclusions**: Automatically excludes `node_modules`, `venv`, `__pycache__`, and `repo-context.txt` to avoid unnecessary content in the context.
|
||||
|
||||
---
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Features](#features)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [Setup Guide](#setup-guide)
|
||||
- [Step 1: Clone the Repository](#step-1-clone-the-repository)
|
||||
- [Step 2: Set Up a Python Virtual Environment](#step-2-set-up-a-python-virtual-environment)
|
||||
- [Step 3: Install Required Packages](#step-3-install-required-packages)
|
||||
- [Step 4: Run the Streamlit Application](#step-4-run-the-streamlit-application)
|
||||
- [How to Use](#how-to-use)
|
||||
- [Selecting a Folder](#selecting-a-folder)
|
||||
- [Configuring Inclusions and Exclusions](#configuring-inclusions-and-exclusions)
|
||||
- [Generating the Context File](#generating-the-context-file)
|
||||
- [Saving and Loading Configurations](#saving-and-loading-configurations)
|
||||
- [Customization](#customization)
|
||||
- [Contributing](#contributing)
|
||||
- [License](#license)
|
||||
|
||||
---
|
||||
- **Default Exclusions**: Automatically excludes common directories and files to avoid unnecessary content.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- **Python 3.7 or higher**: Ensure Python is installed on your system. Download it from [python.org](https://www.python.org/downloads/).
|
||||
- **Streamlit**: The tool is built using the Streamlit web framework.
|
||||
- **Git**: To clone the repository. Download from [git-scm.com](https://git-scm.com/downloads).
|
||||
- **Python 3.7 or higher**: Download from [python.org](https://www.python.org/downloads/)
|
||||
- **Git**: Download from [git-scm.com](https://git-scm.com/downloads)
|
||||
|
||||
---
|
||||
## Directory Structure
|
||||
|
||||
## Setup Guide
|
||||
```
|
||||
repository-context-generator/
|
||||
├── src/
|
||||
│ ├── app.py # Main Streamlit application
|
||||
│ ├── generate_repo_context.py # Context generation script
|
||||
│ ├── config.yaml # Configuration file
|
||||
│ ├── requirements.txt # Python dependencies
|
||||
│ ├── global_files/ # Global files for all contexts
|
||||
│ └── static_files/ # Static content files
|
||||
│ ├── overview.txt # Project overview
|
||||
│ ├── important_info.txt # Important information
|
||||
│ └── to-do_list.txt # Project to-do list
|
||||
```
|
||||
|
||||
### Step 1: Clone the Repository
|
||||
## Installation
|
||||
|
||||
Clone this repository to your local machine using Git:
|
||||
### 1. Clone the Repository
|
||||
|
||||
```bash
|
||||
git clone <repository-url>
|
||||
cd <repository-directory>
|
||||
cd repository-context-generator
|
||||
```
|
||||
|
||||
_Replace `<repository-url>` with the actual repository URL._
|
||||
### 2. Create Required Directories and Files
|
||||
|
||||
---
|
||||
```bash
|
||||
mkdir -p src/static_files src/global_files
|
||||
touch src/static_files/overview.txt
|
||||
touch src/static_files/important_info.txt
|
||||
touch src/static_files/to-do_list.txt
|
||||
```
|
||||
|
||||
### Step 2: Set Up a Python Virtual Environment
|
||||
### 3. Set Up Virtual Environment
|
||||
|
||||
A virtual environment helps isolate dependencies:
|
||||
#### Windows:
|
||||
|
||||
1. Create a virtual environment:
|
||||
```bash
|
||||
# Create virtual environment
|
||||
python -m venv venv
|
||||
|
||||
```bash
|
||||
python3 -m venv venv
|
||||
```
|
||||
# Activate using Command Prompt
|
||||
venv\Scripts\activate.bat
|
||||
|
||||
2. Activate the virtual environment:
|
||||
- **macOS and Linux**:
|
||||
```bash
|
||||
source venv/bin/activate
|
||||
```
|
||||
- **Windows**:
|
||||
```bash
|
||||
venv\Scripts\activate
|
||||
```
|
||||
# OR activate using PowerShell
|
||||
.\venv\Scripts\Activate.ps1
|
||||
```
|
||||
|
||||
---
|
||||
#### macOS/Linux:
|
||||
|
||||
### Step 3: Install Required Packages
|
||||
```bash
|
||||
# Create virtual environment
|
||||
python3 -m venv venv
|
||||
|
||||
Install the required dependencies using `pip`:
|
||||
# Activate
|
||||
source venv/bin/activate
|
||||
```
|
||||
|
||||
### 4. Install Dependencies
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
---
|
||||
Required packages:
|
||||
|
||||
### Step 4: Run the Streamlit Application
|
||||
```txt
|
||||
streamlit
|
||||
PyYAML
|
||||
Flask
|
||||
Flask-Cors
|
||||
GitPython
|
||||
pyperclip
|
||||
```
|
||||
|
||||
Start the application with the following command:
|
||||
## Running the Application
|
||||
|
||||
```bash
|
||||
cd src
|
||||
streamlit run app.py
|
||||
```
|
||||
|
||||
The application will open in your default web browser. If not, follow the link provided in the terminal (e.g., `http://localhost:8501`).
|
||||
The application will open in your default web browser at `http://localhost:8501`.
|
||||
|
||||
---
|
||||
## Usage
|
||||
|
||||
## How to Use
|
||||
### 1. Initial Setup
|
||||
|
||||
### Selecting a Folder
|
||||
- Create a basic `config.yaml` file in the src directory:
|
||||
|
||||
1. Use the **Choose Folder** button in the sidebar to open a folder selection dialog.
|
||||
2. Select the root folder of the repository for which you want to generate the context file.
|
||||
```yaml
|
||||
exclude_dirs:
|
||||
- node_modules
|
||||
- venv
|
||||
- __pycache__
|
||||
- .git
|
||||
- dist
|
||||
- build
|
||||
- logs
|
||||
- .idea
|
||||
- .vscode
|
||||
|
||||
---
|
||||
important_files: []
|
||||
custom_sections: []
|
||||
```
|
||||
|
||||
### Configuring Inclusions and Exclusions
|
||||
### 2. Select Repository
|
||||
|
||||
1. **Directory Tree**: Use the directory multiselect to include specific directories in the context file.
|
||||
2. **File Exclusions**: Automatically include files within selected directories but exclude specific files if needed.
|
||||
3. **Default Exclusions**:
|
||||
- The following are excluded by default: `node_modules`, `venv`, `__pycache__`, `.git`, `dist`, `build`, `logs`, `.idea`, `.vscode`, and `repo-context.txt`.
|
||||
- Click "Choose Folder" in the sidebar
|
||||
- Navigate to your target repository
|
||||
- Select the folder
|
||||
|
||||
---
|
||||
### 3. Configure Files
|
||||
|
||||
### Generating the Context File
|
||||
- Select directories to include in the "Include in Directory Tree" section
|
||||
- Exclude specific files if needed
|
||||
- Review the "Final Included Files" list
|
||||
|
||||
1. After configuring inclusions and exclusions, click the **Generate Context File** button.
|
||||
2. The context file will be created, and a **Download** button will appear for you to save the `repo-context.txt`.
|
||||
### 4. Generate Context
|
||||
|
||||
---
|
||||
|
||||
### Saving and Loading Configurations
|
||||
|
||||
- **Save Configuration**: Use the "Save Configuration" button to save your current settings (selected directories and excluded files).
|
||||
- **Load Configuration**: The app automatically loads the saved configuration at startup.
|
||||
|
||||
---
|
||||
- Click "Generate Context File"
|
||||
- Download or copy the generated context
|
||||
- Save your configuration if desired
|
||||
|
||||
## Customization
|
||||
|
||||
### Modifying Default Exclusions
|
||||
### Modify Default Exclusions
|
||||
|
||||
To modify the default exclusions, edit the `DEFAULT_EXCLUDED_DIRS` and `DEFAULT_EXCLUDED_FILES` lists in `app.py`:
|
||||
Edit `DEFAULT_EXCLUDED_DIRS` and `DEFAULT_EXCLUDED_FILES` in `app.py`:
|
||||
|
||||
```python
|
||||
DEFAULT_EXCLUDED_DIRS = ["node_modules", "venv", "__pycache__", ".git", "dist", "build", "logs", ".idea", ".vscode"]
|
||||
DEFAULT_EXCLUDED_DIRS = [
|
||||
"node_modules",
|
||||
"venv",
|
||||
"__pycache__",
|
||||
".git",
|
||||
"dist",
|
||||
"build",
|
||||
"logs",
|
||||
".idea",
|
||||
".vscode"
|
||||
]
|
||||
|
||||
DEFAULT_EXCLUDED_FILES = ["repo-context.txt"]
|
||||
```
|
||||
|
||||
---
|
||||
### Add Custom Sections
|
||||
|
||||
### Using the Configuration File
|
||||
Modify `config.yaml` to add custom sections:
|
||||
|
||||
The `config.yaml` file allows further customization:
|
||||
```yaml
|
||||
custom_sections:
|
||||
- file: changelog.txt
|
||||
section_title: "Changelog"
|
||||
- file: LICENSE.txt
|
||||
section_title: "License"
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Tcl_AsyncDelete Warning**
|
||||
|
||||
1. **Exclude Directories**:
|
||||
```yaml
|
||||
exclude_dirs:
|
||||
- node_modules
|
||||
- venv
|
||||
- __pycache__
|
||||
```
|
||||
2. **Important Files**:
|
||||
```yaml
|
||||
important_files:
|
||||
- main.py
|
||||
- app.py
|
||||
Tcl_AsyncDelete: async handler deleted by the wrong thread
|
||||
```
|
||||
|
||||
---
|
||||
This warning can be safely ignored; it doesn't affect functionality.
|
||||
|
||||
2. **Permission Denied When Creating Directories**
|
||||
|
||||
- Run terminal/command prompt as administrator
|
||||
- Check folder permissions
|
||||
- Ensure you have write access to the installation directory
|
||||
|
||||
3. **Package Installation Failures**
|
||||
|
||||
```bash
|
||||
# If pip install fails, try:
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
4. **Streamlit Port Already in Use**
|
||||
- Kill any running Streamlit processes
|
||||
- Change the port:
|
||||
```bash
|
||||
streamlit run app.py --server.port 8502
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Feel free to submit pull requests or open issues for bug fixes, enhancements, or feature requests.
|
||||
|
||||
---
|
||||
1. Fork the repository
|
||||
2. Create a feature branch
|
||||
3. Commit your changes
|
||||
4. Push to the branch
|
||||
5. Open a Pull Request
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the [MIT License](LICENSE).
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
---
|
||||
|
||||
## Support
|
||||
|
||||
For issues and feature requests, please create an issue in the GitHub repository.
|
||||
|
@@ -1,97 +0,0 @@
|
||||
# =========================================
|
||||
# AI Code Context Generator Configuration
|
||||
# =========================================
|
||||
|
||||
# Primary source directory containing the main codebase.
|
||||
# Update this if your main code is not in 'src/'.
|
||||
source_directory: src
|
||||
|
||||
# List of directories to exclude from the directory tree and file inclusions.
|
||||
# These directories and their contents will be omitted from the generated context.
|
||||
# Customize this list based on your project's structure.
|
||||
exclude_dirs:
|
||||
- node_modules # Node.js dependencies
|
||||
- venv # Python virtual environment
|
||||
- __pycache__ # Python bytecode cache
|
||||
- build # Build output directories
|
||||
- dist # Distribution packages
|
||||
- .git # Git repository metadata
|
||||
- .github # GitHub workflows and configurations
|
||||
- .vscode # Visual Studio Code settings
|
||||
- logs # Log files
|
||||
- tmp # Temporary files and directories
|
||||
|
||||
# List of important files to include in the context.
|
||||
# Paths should be relative to the 'source_directory' specified above.
|
||||
# These files are crucial for understanding the project's functionality.
|
||||
# Modify this list to include files relevant to your project.
|
||||
important_files:
|
||||
- main.py # Entry point of the application
|
||||
- app.py # Application configuration
|
||||
- config/settings.py # Configuration settings
|
||||
- utils/helpers.py # Utility helper functions
|
||||
- models/user.py # User model definitions
|
||||
- controllers/auth_controller.py # Authentication controller
|
||||
- services/email_service.py # Email service integration
|
||||
- routes/api_routes.py # API route definitions
|
||||
- database/db_connection.py # Database connection setup
|
||||
- tests/test_main.py # Main application tests
|
||||
|
||||
# =========================================
|
||||
# Instructions for Customization
|
||||
# =========================================
|
||||
|
||||
# 1. **source_directory**:
|
||||
# - Set this to the primary directory containing your source code.
|
||||
# - Example:
|
||||
# - For a project with main code in 'app/', set `source_directory: app`
|
||||
|
||||
# 2. **exclude_dirs**:
|
||||
# - Review the list and remove any directories that are essential for your project context.
|
||||
# - Add any additional directories that you want to exclude by appending them to the list.
|
||||
# - Example:
|
||||
# - If your project uses a `docs/` directory for documentation, you might choose to exclude it:
|
||||
# - docs
|
||||
|
||||
# 3. **important_files**:
|
||||
# - Identify the key files in your project that define its core functionality.
|
||||
# - Ensure the paths are relative to your `source_directory`.
|
||||
# - Add or remove files as necessary to reflect your project's structure.
|
||||
# - Example:
|
||||
# - For a JavaScript project, you might include:
|
||||
# - index.js
|
||||
# - src/app.js
|
||||
# - src/routes/index.js
|
||||
# - src/controllers/userController.js
|
||||
|
||||
# =========================================
|
||||
# Additional Configuration (Optional)
|
||||
# =========================================
|
||||
|
||||
# Uncomment and customize the sections below if your project requires more advanced configurations.
|
||||
|
||||
# # List of file types to include based on extensions.
|
||||
# # Useful if you want to include all files of certain types without specifying each one.
|
||||
# file_type_inclusions:
|
||||
# - .js
|
||||
# - .ts
|
||||
# - .java
|
||||
# - .rb
|
||||
# - .go
|
||||
|
||||
# # List of file types to exclude based on extensions.
|
||||
# # This can help in omitting large binary files or irrelevant file types.
|
||||
# file_type_exclusions:
|
||||
# - .log
|
||||
# - .tmp
|
||||
# - .png
|
||||
# - .jpg
|
||||
# - .gif
|
||||
|
||||
# # Custom sections to include additional information.
|
||||
# # You can define more sections by adding corresponding static files.
|
||||
custom_sections:
|
||||
- file: changelog.txt
|
||||
section_title: "Changelog"
|
||||
- file: LICENSE.txt
|
||||
section_title: "License"
|
@@ -1,289 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Script Name: generate_repo_context.py
|
||||
Description: Generates a context file (`repo-context.txt`) for AI coding assistants.
|
||||
Includes an overview, important information, a directory tree with exclusions,
|
||||
content of important files with syntax highlighting, and a to-do list.
|
||||
|
||||
Usage:
|
||||
1. Ensure you have Python 3.7 or higher installed.
|
||||
|
||||
2. (Optional) Set up a Python virtual environment:
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate # On Unix or MacOS
|
||||
venv\Scripts\activate.bat # On Windows (Command Prompt)
|
||||
venv\Scripts\Activate.ps1 # On Windows (PowerShell)
|
||||
|
||||
3. Install the required Python packages:
|
||||
pip install -r requirements.txt
|
||||
|
||||
4. Configure `config.yaml` as needed.
|
||||
|
||||
5. Place `overview.txt`, `important_info.txt`, and `to-do_list.txt` in the script directory.
|
||||
|
||||
6. Run the script:
|
||||
./generate_repo_context.py # Unix-like systems
|
||||
python generate_repo_context.py # Windows
|
||||
|
||||
The script will create `repo-context.txt` with the specified structure.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
import mimetypes
|
||||
import logging
|
||||
from typing import List, Dict
|
||||
from datetime import datetime # Added import for datetime
|
||||
|
||||
# Configuration Constants
|
||||
CONFIG_FILE = "config.yaml"
|
||||
OUTPUT_FILE = "repo-context.txt"
|
||||
|
||||
# Static Text Files and Their Corresponding Section Titles
|
||||
STATIC_FILES = [
|
||||
{"file": "overview.txt", "section_title": "Overview"},
|
||||
{"file": "important_info.txt", "section_title": "Important Information"},
|
||||
{"file": "to-do_list.txt", "section_title": "To-Do List"}
|
||||
]
|
||||
|
||||
# Mapping of File Extensions to Programming Languages for Syntax Highlighting
|
||||
LANGUAGE_MAP = {
|
||||
'.py': 'python',
|
||||
'.json': 'json',
|
||||
'.env': 'bash',
|
||||
'.js': 'javascript',
|
||||
'.html': 'html',
|
||||
'.css': 'css',
|
||||
'.csv': 'csv',
|
||||
'.md': 'markdown',
|
||||
'.txt': '', # Plain text
|
||||
# Add more mappings as needed
|
||||
}
|
||||
|
||||
# Extensions of Binary Files to Skip
|
||||
BINARY_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.db', '.exe', '.bin']
|
||||
|
||||
def setup_logging():
|
||||
"""Configures the logging format and level."""
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='[%(levelname)s] %(message)s'
|
||||
)
|
||||
|
||||
def load_config(config_path: Path) -> Dict:
|
||||
"""
|
||||
Loads configuration from a YAML file.
|
||||
|
||||
Args:
|
||||
config_path (Path): Path to the YAML configuration file.
|
||||
|
||||
Returns:
|
||||
dict: Configuration dictionary containing 'exclude_dirs' and 'important_files'.
|
||||
"""
|
||||
if not config_path.exists():
|
||||
logging.error(f"Configuration file {config_path} not found.")
|
||||
sys.exit(1)
|
||||
try:
|
||||
with open(config_path, 'r') as f:
|
||||
config = yaml.safe_load(f)
|
||||
logging.info(f"Loaded configuration from {config_path}.")
|
||||
return config
|
||||
except yaml.YAMLError as e:
|
||||
logging.error(f"Error parsing configuration file: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
def generate_directory_tree(start_path: Path, exclude_dirs: List[str]) -> List[str]:
|
||||
"""
|
||||
Generates a directory tree as a list of strings, excluding specified directories.
|
||||
|
||||
Args:
|
||||
start_path (Path): The root directory to start generating the tree from.
|
||||
exclude_dirs (list): List of directory patterns to exclude.
|
||||
|
||||
Returns:
|
||||
list: List of strings representing the directory tree.
|
||||
"""
|
||||
tree_lines = []
|
||||
root = start_path.resolve()
|
||||
for dirpath, dirnames, filenames in os.walk(start_path):
|
||||
current_path = Path(dirpath)
|
||||
rel_path = current_path.relative_to(root)
|
||||
|
||||
# Skip excluded directories
|
||||
if any(current_path.match(excl) or excl in rel_path.parts for excl in exclude_dirs):
|
||||
dirnames[:] = [] # Don't traverse further into subdirectories
|
||||
continue
|
||||
|
||||
# Determine the indentation level
|
||||
depth = len(rel_path.parts)
|
||||
indent = " " * depth
|
||||
connector = "├── " if depth > 0 else "."
|
||||
if depth > 0:
|
||||
tree_lines.append(f"{indent}{connector}{current_path.name}/")
|
||||
else:
|
||||
tree_lines.append(f"{connector}")
|
||||
|
||||
# Add files in the current directory
|
||||
for filename in sorted(filenames):
|
||||
file_rel_path = rel_path / filename
|
||||
if any(file_rel_path.match(excl) or excl in file_rel_path.parts for excl in exclude_dirs):
|
||||
continue
|
||||
file_indent = " " * (depth + 1)
|
||||
tree_lines.append(f"{file_indent}├── {filename}")
|
||||
|
||||
logging.info("Directory tree generated.")
|
||||
return tree_lines
|
||||
|
||||
def write_directory_tree(tree_lines: List[str], output_file: Path):
|
||||
"""
|
||||
Writes the directory tree to the output file within markdown code blocks.
|
||||
|
||||
Args:
|
||||
tree_lines (list): List of strings representing the directory tree.
|
||||
output_file (Path): Path to the output file where the tree will be written.
|
||||
"""
|
||||
with output_file.open('a', encoding='utf-8') as f:
|
||||
f.write("## Directory Tree with Exclusions\n\n")
|
||||
f.write("```\n")
|
||||
for line in tree_lines:
|
||||
f.write(line + "\n")
|
||||
f.write("```\n\n")
|
||||
logging.info("Directory tree written to the context file.")
|
||||
|
||||
def write_file_content(file_path: Path, output_file: Path):
|
||||
"""
|
||||
Writes the content of a file to the output file within markdown code blocks with syntax highlighting.
|
||||
|
||||
Args:
|
||||
file_path (Path): Path to the file whose content is to be written.
|
||||
output_file (Path): Path to the output file where the content will be written.
|
||||
"""
|
||||
ext = file_path.suffix
|
||||
language = LANGUAGE_MAP.get(ext, '')
|
||||
try:
|
||||
relative_display_path = file_path.relative_to(file_path.parents[1])
|
||||
except ValueError:
|
||||
# If relative_to fails, fallback to absolute path
|
||||
relative_display_path = file_path
|
||||
with output_file.open('a', encoding='utf-8') as f:
|
||||
f.write(f"## {relative_display_path}\n")
|
||||
if language:
|
||||
f.write(f"```{language}\n")
|
||||
else:
|
||||
f.write("```\n")
|
||||
try:
|
||||
if ext in BINARY_EXTENSIONS:
|
||||
# Skip binary files
|
||||
f.write(f"*Binary file ({ext}) cannot be displayed.*\n")
|
||||
else:
|
||||
with open(file_path, 'r', encoding='utf-8', errors='ignore') as file_content:
|
||||
content = file_content.read()
|
||||
f.write(content)
|
||||
except Exception as e:
|
||||
f.write(f"*Error reading file: {e}*\n")
|
||||
f.write("\n```\n\n")
|
||||
logging.info(f"Included content from {file_path}.")
|
||||
|
||||
def write_static_file(file_path: Path, output_file: Path, section_title: str):
|
||||
"""
|
||||
Writes the content of a static text file to the output file with a section header.
|
||||
|
||||
Args:
|
||||
file_path (Path): Path to the static text file.
|
||||
output_file (Path): Path to the output file where the content will be written.
|
||||
section_title (str): Title of the section to be added before the content.
|
||||
"""
|
||||
if not file_path.exists():
|
||||
logging.warning(f"Static file {file_path} not found, skipping...")
|
||||
return
|
||||
with output_file.open('a', encoding='utf-8') as f:
|
||||
f.write(f"## {section_title}\n\n")
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8', errors='ignore') as sf:
|
||||
content = sf.read()
|
||||
f.write(content + "\n\n")
|
||||
except Exception as e:
|
||||
f.write(f"*Error reading {file_path.name}: {e}*\n\n")
|
||||
logging.error(f"Error reading {file_path}: {e}")
|
||||
logging.info(f"Included static section: {section_title}.")
|
||||
|
||||
def write_custom_sections(custom_sections: List[Dict], script_dir: Path, output_file: Path):
|
||||
"""
|
||||
Writes custom sections to the output file based on configuration.
|
||||
|
||||
Args:
|
||||
custom_sections (list): List of dictionaries with 'file' and 'section_title'.
|
||||
script_dir (Path): Directory where the script is located.
|
||||
output_file (Path): Path to the output file.
|
||||
"""
|
||||
for section in custom_sections:
|
||||
file_name = section.get('file')
|
||||
section_title = section.get('section_title', 'Custom Section')
|
||||
file_path = script_dir / file_name
|
||||
write_static_file(file_path, output_file, section_title)
|
||||
|
||||
def main():
|
||||
"""Main function that orchestrates the generation of the repository context file."""
|
||||
setup_logging()
|
||||
|
||||
# Determine the script's directory
|
||||
script_dir = Path(__file__).parent.resolve()
|
||||
|
||||
# Load configuration
|
||||
config_path = script_dir / CONFIG_FILE
|
||||
config = load_config(config_path)
|
||||
exclude_dirs = config.get("exclude_dirs", [])
|
||||
important_files = config.get("important_files", [])
|
||||
custom_sections = config.get("custom_sections", [])
|
||||
|
||||
# Define the starting path (default to 'src' directory or as specified)
|
||||
source_dir = config.get("source_directory", "src")
|
||||
start_path = script_dir.parent / source_dir
|
||||
if not start_path.exists():
|
||||
logging.error(f"Source directory {start_path} does not exist.")
|
||||
sys.exit(1)
|
||||
|
||||
output_file = script_dir / OUTPUT_FILE
|
||||
output_file.unlink(missing_ok=True) # Remove if exists
|
||||
|
||||
# Write a header to the output file
|
||||
with output_file.open('w', encoding='utf-8') as f:
|
||||
f.write(f"# Repository Context\n\n")
|
||||
f.write(f"Generated on: {datetime.now().strftime('%Y-%m-%d')}\n\n") # Updated line
|
||||
|
||||
# Write static sections
|
||||
for static in STATIC_FILES:
|
||||
static_path = script_dir / static["file"]
|
||||
write_static_file(static_path, output_file, static["section_title"])
|
||||
|
||||
# Generate and write the directory tree
|
||||
tree_lines = generate_directory_tree(start_path, exclude_dirs)
|
||||
write_directory_tree(tree_lines, output_file)
|
||||
|
||||
# Write important files
|
||||
with output_file.open('a', encoding='utf-8') as f:
|
||||
f.write("## Important Files\n\n")
|
||||
for relative_file in important_files:
|
||||
file_path = start_path / relative_file
|
||||
if file_path.exists():
|
||||
write_file_content(file_path, output_file)
|
||||
else:
|
||||
with output_file.open('a', encoding='utf-8') as f:
|
||||
f.write(f"*File `{relative_file}` not found, skipping...*\n\n")
|
||||
logging.warning(f"Important file {relative_file} not found, skipping...")
|
||||
|
||||
# Write custom sections if any
|
||||
if custom_sections:
|
||||
write_custom_sections(custom_sections, script_dir, output_file)
|
||||
|
||||
# Write to-do list
|
||||
todo_path = script_dir / "to-do_list.txt"
|
||||
write_static_file(todo_path, output_file, "To-Do List")
|
||||
|
||||
logging.info(f"Context file created: {output_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@@ -1,30 +0,0 @@
|
||||
#########################################################
|
||||
# o1-Preview to o1-Mini hand-off
|
||||
#########################################################
|
||||
#########################################################
|
||||
|
||||
Can you please update my existing code with the recommendations below it?
|
||||
|
||||
Here is the original code:
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
|
||||
And here is the update we need to incorporate:
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
|
||||
#########################################################
|
||||
#########################################################
|
||||
|
@@ -1,4 +0,0 @@
|
||||
# requirements.txt
|
||||
|
||||
# PyYAML is required for parsing YAML configuration files
|
||||
PyYAML>=6.0
|
251
src/README.md
251
src/README.md
@@ -1,251 +0,0 @@
|
||||
Certainly! Below is the updated `README.md` for your **Repository Context Generator Web App**, which includes detailed run commands and clarifies the setup process. This update ensures that users can easily follow the steps to install, activate the virtual environment, install dependencies, and run the Streamlit application.
|
||||
|
||||
---
|
||||
|
||||
# Repository Context Generator Web App
|
||||
|
||||
The **Repository Context Generator** is a Streamlit-based web application designed to create a comprehensive context file (`repo-context.txt`) for AI coding assistants like ChatGPT. This context file aggregates essential information from your repository, including an overview, key details, a directory tree with exclusions, contents of important files with syntax highlighting, and a to-do list. Additionally, it supports the inclusion of global files that are incorporated into every generated context, regardless of the selected repository.
|
||||
|
||||
## **Features**
|
||||
|
||||
- **Repository Selection**: Choose from existing repositories or add new ones by providing their Git URLs.
|
||||
- **File Filtering**: Select which files to include or exclude from the prompt and directory tree.
|
||||
- **Global Files Management**: Add files that will be included in every generated context.
|
||||
- **Context File Generation**: Generate and download a tailored `repo-context.txt` file.
|
||||
- **XML Section Integration**: Automatically append an XML section adhering to specified formatting rules.
|
||||
|
||||
## **Prerequisites**
|
||||
|
||||
- **Python 3.7 or higher**: Ensure Python is installed on your system. Download it from [python.org](https://www.python.org/downloads/).
|
||||
- **Git**: To clone repositories. Download from [git-scm.com](https://git-scm.com/downloads).
|
||||
|
||||
## **Directory Structure**
|
||||
|
||||
```
|
||||
repository-context-generator/
|
||||
├── app.py
|
||||
├── generate_repo_context.py
|
||||
├── config.yaml
|
||||
├── requirements.txt
|
||||
├── global_files/
|
||||
│ └── global.xml
|
||||
├── static_files/
|
||||
│ ├── overview.txt
|
||||
│ ├── important_info.txt
|
||||
│ └── to-do_list.txt
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## **Setup Guide**
|
||||
|
||||
### **1. Clone the Repository**
|
||||
|
||||
Clone this repository to your local machine using Git:
|
||||
|
||||
```bash
|
||||
git clone <repository-url>
|
||||
cd repository-context-generator
|
||||
```
|
||||
|
||||
_Replace `<repository-url>` with the actual URL of your repository._
|
||||
|
||||
### **2. Set Up Python Virtual Environment (Optional but Recommended)**
|
||||
|
||||
Using a virtual environment isolates your project's dependencies, preventing conflicts with other projects.
|
||||
|
||||
#### **a. Create a Virtual Environment**
|
||||
|
||||
```bash
|
||||
python -m venv venv
|
||||
```
|
||||
|
||||
#### **b. Activate the Virtual Environment**
|
||||
|
||||
- **On Windows (Command Prompt):**
|
||||
|
||||
```cmd
|
||||
venv\Scripts\activate.bat
|
||||
```
|
||||
|
||||
- **On Windows (PowerShell):**
|
||||
|
||||
```powershell
|
||||
.\venv\Scripts\Activate.ps1
|
||||
```
|
||||
|
||||
**Note:** If you encounter an execution policy error in PowerShell, you may need to adjust the execution policy:
|
||||
|
||||
```powershell
|
||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
```
|
||||
|
||||
Then, try activating the virtual environment again.
|
||||
|
||||
- **On macOS and Linux:**
|
||||
|
||||
```bash
|
||||
source venv/bin/activate
|
||||
```
|
||||
|
||||
**Successful Activation:**
|
||||
|
||||
Once activated, your terminal prompt should change to indicate that you're now working within the virtual environment, e.g., `(venv) $`.
|
||||
|
||||
### **3. Install Required Packages**
|
||||
|
||||
With the virtual environment activated, install the necessary Python packages using `pip`:
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### **4. Configure the Application**
|
||||
|
||||
Customize the `config.yaml` file to control which directories and files are included or excluded in the generated context.
|
||||
|
||||
1. **Locate `config.yaml`**: It's in the root directory of the cloned repository.
|
||||
|
||||
2. **Edit `config.yaml`**:
|
||||
- **Exclude Directories**: Modify the `exclude_dirs` section to exclude any directories you don't want in the context.
|
||||
- **Important Files**: List the key files under the `important_files` section that should be included with their content.
|
||||
- **Custom Sections**: Define any additional sections you want to include.
|
||||
|
||||
_Refer to the [Customization](#customization) section for detailed instructions._
|
||||
|
||||
### **5. Add Static and Global Files**
|
||||
|
||||
Ensure that the following files are present:
|
||||
|
||||
- **Static Files**: Place `overview.txt`, `important_info.txt`, and `to-do_list.txt` inside the `static_files/` directory.
|
||||
- **Global Files**: Place any global files (e.g., `global.xml`) inside the `global_files/` directory.
|
||||
|
||||
### **6. Running the Application**
|
||||
|
||||
Launch the Streamlit web application:
|
||||
|
||||
```bash
|
||||
streamlit run app.py
|
||||
```
|
||||
|
||||
This command will open the application in your default web browser. If it doesn't open automatically, navigate to [http://localhost:8501](http://localhost:8501) in your browser.
|
||||
|
||||
**Additional Run Commands:**
|
||||
|
||||
- **Deactivate the Virtual Environment (When Done):**
|
||||
|
||||
```bash
|
||||
deactivate
|
||||
```
|
||||
|
||||
- **Reactivating the Virtual Environment:**
|
||||
|
||||
Navigate back to the project directory and activate the virtual environment as described in **Step 2b**.
|
||||
|
||||
## **Customization**
|
||||
|
||||
### **Modifying `config.yaml`**
|
||||
|
||||
The `config.yaml` file allows you to tailor the context generation process to your project's needs.
|
||||
|
||||
```yaml
|
||||
# Configuration for Repository Context Generator
|
||||
|
||||
# Primary source directory containing the main codebase.
|
||||
# Update this if your main code is not in 'src/'.
|
||||
source_directory: src
|
||||
|
||||
# List of directories to exclude from the directory tree and file inclusions.
|
||||
exclude_dirs:
|
||||
- node_modules # Node.js dependencies
|
||||
- venv # Python virtual environment
|
||||
- __pycache__ # Python bytecode cache
|
||||
- build # Build output directories
|
||||
- dist # Distribution packages
|
||||
- .git # Git repository metadata
|
||||
- .github # GitHub workflows and configurations
|
||||
- .vscode # Visual Studio Code settings
|
||||
- logs # Log files
|
||||
- tmp # Temporary files and directories
|
||||
|
||||
# List of important files to include in the context.
|
||||
# Paths should be relative to the 'source_directory' specified above.
|
||||
important_files:
|
||||
- main.py # Entry point of the application
|
||||
- app.py # Application configuration
|
||||
- config/settings.py # Configuration settings
|
||||
- utils/helpers.py # Utility helper functions
|
||||
- models/user.py # User model definitions
|
||||
- controllers/auth_controller.py # Authentication controller
|
||||
- services/email_service.py # Email service integration
|
||||
- routes/api_routes.py # API route definitions
|
||||
- database/db_connection.py # Database connection setup
|
||||
- tests/test_main.py # Main application tests
|
||||
|
||||
# Custom sections to include additional information.
|
||||
custom_sections:
|
||||
- file: changelog.txt
|
||||
section_title: "Changelog"
|
||||
- file: LICENSE.txt
|
||||
section_title: "License"
|
||||
```
|
||||
|
||||
**Instructions for Customization:**
|
||||
|
||||
1. **`source_directory`**:
|
||||
|
||||
- Set this to the primary directory containing your source code.
|
||||
- Example: For a project with main code in `app/`, set `source_directory: app`.
|
||||
|
||||
2. **`exclude_dirs`**:
|
||||
|
||||
- Review the list and remove any directories that are essential for your project context.
|
||||
- Add any additional directories you want to exclude by appending them to the list.
|
||||
- Example: If your project uses a `docs/` directory for documentation, you might choose to exclude it:
|
||||
```yaml
|
||||
- docs
|
||||
```
|
||||
|
||||
3. **`important_files`**:
|
||||
|
||||
- Identify the key files in your project that define its core functionality.
|
||||
- Ensure the paths are relative to your `source_directory`.
|
||||
- Add or remove files as necessary to reflect your project's structure.
|
||||
- Example: For a JavaScript project, you might include:
|
||||
```yaml
|
||||
- index.js
|
||||
- src/app.js
|
||||
- src/routes/index.js
|
||||
- src/controllers/userController.js
|
||||
```
|
||||
|
||||
4. **`custom_sections`**:
|
||||
- Define additional sections by specifying the file and its corresponding section title.
|
||||
- Ensure the specified files exist in the `static_files/` directory or provide their paths accordingly.
|
||||
|
||||
## **Additional Notes**
|
||||
|
||||
- **Global Files**: Files placed in the `global_files/` directory are included in every generated context, regardless of the selected repository. For example, `global.xml` can be used to enforce specific formatting rules across all contexts.
|
||||
|
||||
- **Syntax Highlighting**: The script supports syntax highlighting for common file types like `.py`, `.js`, `.json`, etc. To add more file types, update the `LANGUAGE_MAP` in `generate_repo_context.py`.
|
||||
|
||||
- **Source Directory**: By default, the script assumes your main source code is in the `src/` directory. If your project uses a different structure, update the `source_directory` in `config.yaml`.
|
||||
|
||||
- **Error Handling**: The application includes basic error handling to notify users of missing files or configuration issues. Ensure all necessary files are present to avoid errors.
|
||||
|
||||
## **Contributing**
|
||||
|
||||
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
|
||||
|
||||
## **License**
|
||||
|
||||
This project is licensed under the [MIT License](LICENSE).
|
||||
|
||||
---
|
||||
|
||||
## **Conclusion**
|
||||
|
||||
By following the above setup and utilizing the provided scripts, you can efficiently generate comprehensive context files for your repositories directly from your browser. The integration of global files ensures consistency across all generated contexts, while the interactive interface simplifies repository management and file filtering.
|
||||
|
||||
Feel free to customize and extend the application to better fit your specific requirements. Contributions and feedback are highly appreciated!
|
||||
|
||||
---
|
2191
src/repo-context.txt
2191
src/repo-context.txt
File diff suppressed because it is too large
Load Diff
@@ -1,5 +0,0 @@
|
||||
excluded_files: []
|
||||
selected_directories:
|
||||
- src/
|
||||
- src\global_files/
|
||||
- src\static_files/
|
Reference in New Issue
Block a user