mirror of
https://github.com/PR0M3TH3AN/RePrompt.git
synced 2025-09-07 14:38:43 +00:00
update
This commit is contained in:
70
README.md
70
README.md
@@ -43,7 +43,7 @@ git clone <repository-url>
|
||||
cd <repository-directory>
|
||||
```
|
||||
|
||||
*Replace `<repository-url>` with the actual URL of your repository and `<repository-directory>` with the cloned directory name.*
|
||||
_Replace `<repository-url>` with the actual URL of your repository and `<repository-directory>` with the cloned directory name._
|
||||
|
||||
### Step 2: Set Up Python Virtual Environment (Optional but Recommended)
|
||||
|
||||
@@ -58,18 +58,14 @@ Using a virtual environment isolates your project's dependencies, preventing con
|
||||
2. **Activate the Virtual Environment**:
|
||||
|
||||
- **macOS and Linux**:
|
||||
|
||||
```bash
|
||||
source venv/bin/activate
|
||||
```
|
||||
|
||||
|
||||
- **Windows (Command Prompt)**:
|
||||
```bash
|
||||
venv\Scripts\activate.bat
|
||||
```
|
||||
|
||||
- **Windows (PowerShell)**:
|
||||
```bash
|
||||
venv\Scripts\Activate.ps1
|
||||
venv\Scripts\activate
|
||||
```
|
||||
|
||||
### Step 3: Install Required Packages
|
||||
@@ -90,29 +86,29 @@ Customize the `config.yaml` file to control which directories and files are incl
|
||||
- **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.
|
||||
|
||||
*Refer to the [Customization](#customization) section for detailed instructions.*
|
||||
_Refer to the [Customization](#customization) section for detailed instructions._
|
||||
|
||||
### Step 5: Running the Script
|
||||
|
||||
Execute the script to generate the `repo-context.txt` file.
|
||||
|
||||
- **Unix-like Systems (macOS, Linux)**:
|
||||
|
||||
|
||||
```bash
|
||||
chmod +x generate_repo-context.py # Make the script executable (optional)
|
||||
./generate_repo-context.py
|
||||
chmod +x generate_repo_context.py # Make the script executable (optional)
|
||||
./generate_repo_context.py
|
||||
```
|
||||
|
||||
Or simply:
|
||||
|
||||
```bash
|
||||
python3 generate_repo-context.py
|
||||
python3 generate_repo_context.py
|
||||
```
|
||||
|
||||
- **Windows**:
|
||||
|
||||
```bash
|
||||
python generate_repo-context.py
|
||||
python generate_repo_context.py
|
||||
```
|
||||
|
||||
## Output
|
||||
@@ -137,19 +133,19 @@ Specify directories that should be omitted from the directory tree and file incl
|
||||
|
||||
```yaml
|
||||
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
|
||||
- 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
|
||||
```
|
||||
|
||||
*Add or remove directories as needed.*
|
||||
_Add or remove directories as needed._
|
||||
|
||||
#### 2. **Important Files**
|
||||
|
||||
@@ -157,19 +153,19 @@ List the crucial files whose content should be included in the context file. Pat
|
||||
|
||||
```yaml
|
||||
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
|
||||
- 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
|
||||
- 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
|
||||
```
|
||||
|
||||
*Update the list based on your project's structure.*
|
||||
_Update the list based on your project's structure._
|
||||
|
||||
#### 3. **Additional Configuration (Optional)**
|
||||
|
||||
@@ -200,11 +196,11 @@ custom_sections:
|
||||
section_title: "License"
|
||||
```
|
||||
|
||||
*Customize these sections as per your project requirements.*
|
||||
_Customize these sections as per your project requirements._
|
||||
|
||||
## Additional Notes
|
||||
|
||||
- **Static Files**: Ensure that `overview.txt`, `important_info.txt`, and `to-do_list.txt` are present in the same directory as `generate_repo-context.py`.
|
||||
- **Static Files**: Ensure that `overview.txt`, `important_info.txt`, and `to-do_list.txt` are present in the same directory as `generate_repo_context.py`.
|
||||
- **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 the script.
|
||||
- **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 `start_path` in the script or make it configurable.
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Script Name: generate_repo-context.py
|
||||
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.
|
||||
@@ -23,8 +23,8 @@ Usage:
|
||||
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
|
||||
./generate_repo_context.py # Unix-like systems
|
||||
python generate_repo_context.py # Windows
|
||||
|
||||
The script will create `repo-context.txt` with the specified structure.
|
||||
"""
|
||||
|
208
src/app.py
208
src/app.py
@@ -1,138 +1,170 @@
|
||||
```python
|
||||
import streamlit as st
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import yaml
|
||||
from generate_repo_context import main as generate_context_main
|
||||
import shutil
|
||||
import os
|
||||
import tempfile
|
||||
import yaml
|
||||
from tkinter import Tk
|
||||
from tkinter.filedialog import askdirectory
|
||||
import subprocess
|
||||
import sys # Add this import
|
||||
|
||||
# Configuration
|
||||
CONFIG_FILE = "config.yaml"
|
||||
OUTPUT_FILE = "repo-context.txt"
|
||||
STATIC_FILES_DIR = Path(__file__).parent / "static_files"
|
||||
GLOBAL_FILES_DIR = Path(__file__).parent / "global_files"
|
||||
REPOS_DIR = Path(__file__).parent / "repositories"
|
||||
SAVED_CONFIG_FILE = Path(__file__).parent / "saved_config.yaml"
|
||||
SCRIPT_DIR = Path(__file__).parent
|
||||
|
||||
# Default exclusions
|
||||
DEFAULT_EXCLUDED_DIRS = ["node_modules", "venv", "__pycache__", ".git", "dist", "build", "logs", ".idea", ".vscode"]
|
||||
DEFAULT_EXCLUDED_FILES = ["repo-context.txt"]
|
||||
|
||||
# Ensure necessary directories exist
|
||||
REPOS_DIR.mkdir(exist_ok=True)
|
||||
GLOBAL_FILES_DIR.mkdir(exist_ok=True)
|
||||
STATIC_FILES_DIR.mkdir(exist_ok=True)
|
||||
|
||||
# Load configuration
|
||||
# Load saved configuration
|
||||
def load_saved_config():
|
||||
if SAVED_CONFIG_FILE.exists():
|
||||
try:
|
||||
with open(SAVED_CONFIG_FILE, "r") as f:
|
||||
return yaml.safe_load(f)
|
||||
except yaml.YAMLError:
|
||||
return {}
|
||||
return {}
|
||||
|
||||
# Save configuration
|
||||
def save_config(config):
|
||||
with open(SAVED_CONFIG_FILE, "w") as f:
|
||||
yaml.dump(config, f)
|
||||
|
||||
# Load application configuration
|
||||
def load_config():
|
||||
config_path = Path(__file__).parent / CONFIG_FILE
|
||||
config_path = SCRIPT_DIR / CONFIG_FILE
|
||||
if not config_path.exists():
|
||||
st.error(f"Configuration file {CONFIG_FILE} not found.")
|
||||
st.stop()
|
||||
try:
|
||||
with open(config_path, 'r') as f:
|
||||
config = yaml.safe_load(f)
|
||||
return config
|
||||
with open(config_path, "r") as f:
|
||||
return yaml.safe_load(f)
|
||||
except yaml.YAMLError as e:
|
||||
st.error(f"Error parsing configuration file: {e}")
|
||||
st.stop()
|
||||
|
||||
config = load_config()
|
||||
exclude_dirs = config.get("exclude_dirs", [])
|
||||
important_files = config.get("important_files", [])
|
||||
custom_sections = config.get("custom_sections", [])
|
||||
app_config = load_config()
|
||||
saved_config = load_saved_config()
|
||||
|
||||
exclude_dirs = app_config.get("exclude_dirs", DEFAULT_EXCLUDED_DIRS)
|
||||
|
||||
# Streamlit App
|
||||
st.title("Repository Context Generator")
|
||||
|
||||
st.sidebar.header("Clone Repository")
|
||||
repo_url = st.sidebar.text_input("Repository URL", "")
|
||||
repo_name = st.sidebar.text_input("Repository Name", "")
|
||||
if st.sidebar.button("Clone Repository"):
|
||||
if repo_url and repo_name:
|
||||
repo_path = REPOS_DIR / repo_name
|
||||
if repo_path.exists():
|
||||
st.sidebar.warning("Repository already cloned.")
|
||||
else:
|
||||
try:
|
||||
subprocess.run(['git', 'clone', repo_url, str(repo_path)], check=True)
|
||||
st.sidebar.success("Repository cloned successfully.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
st.sidebar.error(f"Error cloning repository: {e}")
|
||||
# Folder Selection
|
||||
st.sidebar.header("Select a Folder")
|
||||
if st.sidebar.button("Choose Folder"):
|
||||
root = Tk()
|
||||
root.withdraw() # Hide the main window
|
||||
root.attributes("-topmost", True) # Bring the dialog to the front
|
||||
folder_path = askdirectory() # Open folder selection dialog
|
||||
root.destroy()
|
||||
|
||||
if folder_path:
|
||||
st.session_state["selected_repo_path"] = folder_path
|
||||
st.sidebar.success(f"Selected folder: {folder_path}")
|
||||
else:
|
||||
st.sidebar.error("Please provide both Repository URL and Name.")
|
||||
st.sidebar.error("No folder selected.")
|
||||
|
||||
st.header("Select Repository")
|
||||
available_repos = [d.name for d in REPOS_DIR.iterdir() if d.is_dir()]
|
||||
selected_repo = st.selectbox("Choose a repository", available_repos)
|
||||
# Load previously selected folder
|
||||
selected_repo_path = st.session_state.get("selected_repo_path", None)
|
||||
|
||||
if selected_repo:
|
||||
repo_path = REPOS_DIR / selected_repo
|
||||
if selected_repo_path:
|
||||
st.header(f"Selected Repository: {selected_repo_path}")
|
||||
repo_path = Path(selected_repo_path)
|
||||
|
||||
st.subheader("File Filtering")
|
||||
# Retrieve all files in the repository
|
||||
file_list = []
|
||||
# Retrieve directories and files in the repository
|
||||
all_directories = []
|
||||
all_files = []
|
||||
for root, dirs, files in os.walk(repo_path):
|
||||
rel_root = Path(root).relative_to(repo_path)
|
||||
dirs[:] = [d for d in dirs if d not in DEFAULT_EXCLUDED_DIRS]
|
||||
for d in dirs:
|
||||
file_list.append(str(rel_root / d) + "/")
|
||||
all_directories.append(str(rel_root / d) + "/")
|
||||
for f in files:
|
||||
file_list.append(str(rel_root / f))
|
||||
all_files.append(str(rel_root / f))
|
||||
|
||||
# File inclusion and exclusion
|
||||
include_prompt = st.multiselect("Include in Prompt", options=file_list)
|
||||
exclude_prompt = st.multiselect("Exclude from Prompt", options=file_list)
|
||||
include_tree = st.multiselect("Include in Directory Tree", options=file_list)
|
||||
exclude_tree = st.multiselect("Exclude from Directory Tree", options=file_list)
|
||||
# Directory selection for Directory Tree
|
||||
selected_directories = st.multiselect(
|
||||
"Include in Directory Tree", options=all_directories, default=saved_config.get("selected_directories", [])
|
||||
)
|
||||
|
||||
st.subheader("Global Files")
|
||||
st.write("Files in the `global_files/` directory are included in every context.")
|
||||
# Automatically include files within selected directories unless explicitly excluded
|
||||
included_files = [
|
||||
f for f in all_files if any(str(Path(f).parent) in d for d in selected_directories)
|
||||
]
|
||||
|
||||
# Display current global files
|
||||
global_files = [f.name for f in GLOBAL_FILES_DIR.iterdir() if f.is_file()]
|
||||
st.write("### Current Global Files:")
|
||||
for gf in global_files:
|
||||
st.write(f"- {gf}")
|
||||
# File exclusions
|
||||
excluded_files = st.multiselect(
|
||||
"Exclude Specific Files",
|
||||
options=[f for f in included_files if f not in DEFAULT_EXCLUDED_FILES],
|
||||
default=[
|
||||
f for f in saved_config.get("excluded_files", [])
|
||||
if f in included_files and f not in DEFAULT_EXCLUDED_FILES
|
||||
],
|
||||
)
|
||||
|
||||
# Upload new global files
|
||||
uploaded_file = st.file_uploader("Add Global File", type=["txt", "xml", "md"])
|
||||
if uploaded_file:
|
||||
save_path = GLOBAL_FILES_DIR / uploaded_file.name
|
||||
with open(save_path, "wb") as f:
|
||||
f.write(uploaded_file.getbuffer())
|
||||
st.success(f"Global file `{uploaded_file.name}` added.")
|
||||
st.write("### Final Included Files")
|
||||
st.write([f for f in included_files if f not in excluded_files])
|
||||
|
||||
# Generate Context File
|
||||
st.subheader("Generate Context File")
|
||||
if st.button("Generate Context File"):
|
||||
try:
|
||||
# Create a temporary directory to store the output
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
temp_output = Path(tmpdirname) / OUTPUT_FILE
|
||||
# Update config.yaml based on user selections
|
||||
updated_config = {
|
||||
"source_directory": str(repo_path),
|
||||
"exclude_dirs": DEFAULT_EXCLUDED_DIRS,
|
||||
"important_files": [f for f in included_files if f not in excluded_files],
|
||||
"custom_sections": app_config.get("custom_sections", []),
|
||||
}
|
||||
|
||||
# Prepare parameters
|
||||
generate_context_main(
|
||||
config_path=Path(__file__).parent / CONFIG_FILE,
|
||||
source_dir=config.get("source_directory", "src"),
|
||||
start_path=repo_path,
|
||||
exclude_dirs=exclude_dirs,
|
||||
important_files=important_files,
|
||||
custom_sections=custom_sections,
|
||||
include_prompt=include_prompt,
|
||||
exclude_prompt=exclude_prompt,
|
||||
include_tree=include_tree,
|
||||
exclude_tree=exclude_tree,
|
||||
global_files_dir=GLOBAL_FILES_DIR,
|
||||
output_file=temp_output
|
||||
)
|
||||
# Write updated config.yaml
|
||||
with open(SCRIPT_DIR / CONFIG_FILE, "w") as f:
|
||||
yaml.dump(updated_config, f)
|
||||
|
||||
# Read the generated context file
|
||||
with open(temp_output, 'r', encoding='utf-8') as f:
|
||||
# Run the script as a subprocess
|
||||
result = subprocess.run(
|
||||
[sys.executable, str(SCRIPT_DIR / "generate_repo_context.py")],
|
||||
cwd=SCRIPT_DIR,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
st.success("Context file generated successfully.")
|
||||
st.write(f"Script output:\n{result.stdout}")
|
||||
|
||||
# Check if the file was created
|
||||
generated_file = SCRIPT_DIR / OUTPUT_FILE
|
||||
if generated_file.exists():
|
||||
with open(generated_file, "r", encoding="utf-8") as f:
|
||||
context_content = f.read()
|
||||
|
||||
# Provide download link
|
||||
st.download_button(
|
||||
label="Download repo-context.txt",
|
||||
data=context_content,
|
||||
file_name='repo-context.txt',
|
||||
mime='text/plain'
|
||||
file_name="repo-context.txt",
|
||||
mime="text/plain",
|
||||
)
|
||||
st.success("Context file generated successfully.")
|
||||
except Exception as e:
|
||||
else:
|
||||
st.error("Context file not found after script execution.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
st.error(f"Error generating context file: {e}")
|
||||
st.error(f"Script output:\n{e.stdout}\n\n{e.stderr}")
|
||||
|
||||
# Save configuration for future use
|
||||
if st.button("Save Configuration"):
|
||||
save_config({
|
||||
"selected_directories": selected_directories,
|
||||
"excluded_files": excluded_files,
|
||||
})
|
||||
st.success("Configuration saved successfully.")
|
||||
else:
|
||||
st.write("Please select a folder to begin.")
|
||||
|
@@ -1,39 +1,28 @@
|
||||
# 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"
|
||||
- file: changelog.txt
|
||||
section_title: Changelog
|
||||
- file: LICENSE.txt
|
||||
section_title: License
|
||||
exclude_dirs:
|
||||
- node_modules
|
||||
- venv
|
||||
- __pycache__
|
||||
- .git
|
||||
- dist
|
||||
- build
|
||||
- logs
|
||||
- .idea
|
||||
- .vscode
|
||||
important_files:
|
||||
- src\app.py
|
||||
- src\config.yaml
|
||||
- src\generate_repo_context.py
|
||||
- src\index.html
|
||||
- src\README.md
|
||||
- src\requirements.txt
|
||||
- src\saved_config.yaml
|
||||
- src\global_files\format_response.md
|
||||
- src\static_files\important_info.txt
|
||||
- src\static_files\overview.txt
|
||||
- src\static_files\to-do_list.txt
|
||||
source_directory: C:\Users\user\Documents\GitHub\Context-Tool
|
||||
|
@@ -1,19 +1,38 @@
|
||||
```python
|
||||
#!/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, a to-do list, and global files.
|
||||
Appends an XML section based on specified rules.
|
||||
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:
|
||||
python -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 `static_files` 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
|
||||
@@ -203,7 +222,7 @@ def write_custom_sections(custom_sections: List[Dict], script_dir: Path, output_
|
||||
for section in custom_sections:
|
||||
file_name = section.get('file')
|
||||
section_title = section.get('section_title', 'Custom Section')
|
||||
file_path = script_dir / file_name
|
||||
file_path = script_dir / "static_files" / file_name
|
||||
write_static_file(file_path, output_file, section_title)
|
||||
|
||||
def append_xml_section(output_file: Path):
|
||||
@@ -296,7 +315,7 @@ def main():
|
||||
|
||||
# Write custom sections if any
|
||||
if custom_sections:
|
||||
write_custom_sections(custom_sections, script_dir / "static_files", output_file)
|
||||
write_custom_sections(custom_sections, script_dir, output_file)
|
||||
|
||||
# Write to-do list
|
||||
todo_path = script_dir / "static_files" / "to-do_list.txt"
|
||||
@@ -309,147 +328,3 @@ def main():
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## **app.py**
|
||||
|
||||
```python
|
||||
import streamlit as st
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import yaml
|
||||
from generate_repo_context import main as generate_context_main
|
||||
import shutil
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
# Configuration
|
||||
CONFIG_FILE = "config.yaml"
|
||||
OUTPUT_FILE = "repo-context.txt"
|
||||
STATIC_FILES_DIR = Path(__file__).parent / "static_files"
|
||||
GLOBAL_FILES_DIR = Path(__file__).parent / "global_files"
|
||||
REPOS_DIR = Path(__file__).parent / "repositories"
|
||||
|
||||
# Ensure necessary directories exist
|
||||
REPOS_DIR.mkdir(exist_ok=True)
|
||||
GLOBAL_FILES_DIR.mkdir(exist_ok=True)
|
||||
STATIC_FILES_DIR.mkdir(exist_ok=True)
|
||||
|
||||
# Load configuration
|
||||
def load_config():
|
||||
config_path = Path(__file__).parent / CONFIG_FILE
|
||||
if not config_path.exists():
|
||||
st.error(f"Configuration file {CONFIG_FILE} not found.")
|
||||
st.stop()
|
||||
try:
|
||||
with open(config_path, 'r') as f:
|
||||
config = yaml.safe_load(f)
|
||||
return config
|
||||
except yaml.YAMLError as e:
|
||||
st.error(f"Error parsing configuration file: {e}")
|
||||
st.stop()
|
||||
|
||||
config = load_config()
|
||||
exclude_dirs = config.get("exclude_dirs", [])
|
||||
important_files = config.get("important_files", [])
|
||||
custom_sections = config.get("custom_sections", [])
|
||||
|
||||
# Streamlit App
|
||||
st.title("Repository Context Generator")
|
||||
|
||||
st.sidebar.header("Clone Repository")
|
||||
repo_url = st.sidebar.text_input("Repository URL", "")
|
||||
repo_name = st.sidebar.text_input("Repository Name", "")
|
||||
if st.sidebar.button("Clone Repository"):
|
||||
if repo_url and repo_name:
|
||||
repo_path = REPOS_DIR / repo_name
|
||||
if repo_path.exists():
|
||||
st.sidebar.warning("Repository already cloned.")
|
||||
else:
|
||||
try:
|
||||
subprocess.run(['git', 'clone', repo_url, str(repo_path)], check=True)
|
||||
st.sidebar.success("Repository cloned successfully.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
st.sidebar.error(f"Error cloning repository: {e}")
|
||||
else:
|
||||
st.sidebar.error("Please provide both Repository URL and Name.")
|
||||
|
||||
st.header("Select Repository")
|
||||
available_repos = [d.name for d in REPOS_DIR.iterdir() if d.is_dir()]
|
||||
selected_repo = st.selectbox("Choose a repository", available_repos)
|
||||
|
||||
if selected_repo:
|
||||
repo_path = REPOS_DIR / selected_repo
|
||||
|
||||
st.subheader("File Filtering")
|
||||
# Retrieve all files in the repository
|
||||
file_list = []
|
||||
for root, dirs, files in os.walk(repo_path):
|
||||
rel_root = Path(root).relative_to(repo_path)
|
||||
for d in dirs:
|
||||
file_list.append(str(rel_root / d) + "/")
|
||||
for f in files:
|
||||
file_list.append(str(rel_root / f))
|
||||
|
||||
# File inclusion and exclusion
|
||||
include_prompt = st.multiselect("Include in Prompt", options=file_list)
|
||||
exclude_prompt = st.multiselect("Exclude from Prompt", options=file_list)
|
||||
include_tree = st.multiselect("Include in Directory Tree", options=file_list)
|
||||
exclude_tree = st.multiselect("Exclude from Directory Tree", options=file_list)
|
||||
|
||||
st.subheader("Global Files")
|
||||
st.write("Files in the `global_files/` directory are included in every context.")
|
||||
|
||||
# Display current global files
|
||||
global_files = [f.name for f in GLOBAL_FILES_DIR.iterdir() if f.is_file()]
|
||||
st.write("### Current Global Files:")
|
||||
for gf in global_files:
|
||||
st.write(f"- {gf}")
|
||||
|
||||
# Upload new global files
|
||||
uploaded_file = st.file_uploader("Add Global File", type=["txt", "xml", "md"])
|
||||
if uploaded_file:
|
||||
save_path = GLOBAL_FILES_DIR / uploaded_file.name
|
||||
with open(save_path, "wb") as f:
|
||||
f.write(uploaded_file.getbuffer())
|
||||
st.success(f"Global file `{uploaded_file.name}` added.")
|
||||
|
||||
# Generate Context File
|
||||
if st.button("Generate Context File"):
|
||||
try:
|
||||
# Create a temporary directory to store the output
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
temp_output = Path(tmpdirname) / OUTPUT_FILE
|
||||
|
||||
# Prepare parameters
|
||||
generate_context_main(
|
||||
config_path=Path(__file__).parent / CONFIG_FILE,
|
||||
source_dir=config.get("source_directory", "src"),
|
||||
start_path=repo_path,
|
||||
exclude_dirs=exclude_dirs,
|
||||
important_files=important_files,
|
||||
custom_sections=custom_sections,
|
||||
include_prompt=include_prompt,
|
||||
exclude_prompt=exclude_prompt,
|
||||
include_tree=include_tree,
|
||||
exclude_tree=exclude_tree,
|
||||
global_files_dir=GLOBAL_FILES_DIR,
|
||||
output_file=temp_output
|
||||
)
|
||||
|
||||
# Read the generated context file
|
||||
with open(temp_output, 'r', encoding='utf-8') as f:
|
||||
context_content = f.read()
|
||||
|
||||
# Provide download link
|
||||
st.download_button(
|
||||
label="Download repo-context.txt",
|
||||
data=context_content,
|
||||
file_name='repo-context.txt',
|
||||
mime='text/plain'
|
||||
)
|
||||
st.success("Context file generated successfully.")
|
||||
except Exception as e:
|
||||
st.error(f"Error generating context file: {e}")
|
39
src/global_files/format_response.md
Normal file
39
src/global_files/format_response.md
Normal file
@@ -0,0 +1,39 @@
|
||||
Present a complete plan to solve the problem and implement it in the codebase.
|
||||
|
||||
At the end of your response, respond with the following XML section (if applicable).
|
||||
|
||||
XML Section:
|
||||
- Do not get lazy. Always output the full code in the XML section.
|
||||
- Enclose this entire section in a markdown codeblock
|
||||
- Include all of the changed files
|
||||
- Specify each file operation with CREATE, UPDATE, or DELETE
|
||||
- For CREATE or UPDATE operations, include the full file code
|
||||
- Include the full file path (relative to the project directory, good: app/page.tsx, bad: /Users/mckaywrigley/Desktop/projects/new-chat-template/app/page.tsx)
|
||||
- Enclose the code with ![CDATA[__CODE HERE__]]
|
||||
- Use the following XML structure:
|
||||
|
||||
```xml
|
||||
<code_changes>
|
||||
<changed_files>
|
||||
<file>
|
||||
<file_operation>__FILE OPERATION HERE__</file_operation>
|
||||
<file_path>__FILE PATH HERE__</file_path>
|
||||
<file_code><![CDATA[
|
||||
__FULL FILE CODE HERE__
|
||||
]]></file_code>
|
||||
</file>
|
||||
__REMAINING FILES HERE__
|
||||
</changed_files>
|
||||
</code_changes>
|
||||
```
|
||||
|
||||
Other rules:
|
||||
- DO NOT remove <ai_context> sections. These are to provide you additional context about each file.
|
||||
- If you create a file, add an <ai_context> comment section at the top of the file.
|
||||
- If you update a file make sure its <ai_context> stays up-to-date
|
||||
- DO NOT add comments related to your edits
|
||||
- DO NOT remove my existing comments
|
||||
|
||||
We may go back and forth a few times. If we do, remember to continue to output the entirety of the code in an XML section (if applicable).
|
||||
|
||||
Take all the time you need.
|
134
src/index.html
Normal file
134
src/index.html
Normal file
@@ -0,0 +1,134 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Generate context files for repositories with ease. Streamline AI coding assistant interactions."
|
||||
/>
|
||||
<title>Repository Context Generator</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: #f4f4f9;
|
||||
color: #333;
|
||||
}
|
||||
header {
|
||||
background: #6200ea;
|
||||
color: white;
|
||||
padding: 20px 0;
|
||||
text-align: center;
|
||||
}
|
||||
header h1 {
|
||||
margin: 0;
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
header p {
|
||||
margin: 0;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
.container {
|
||||
max-width: 900px;
|
||||
margin: 20px auto;
|
||||
padding: 0 20px;
|
||||
}
|
||||
.cta {
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
margin: 20px 0;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
.cta h2 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
.cta p {
|
||||
margin: 0 0 20px;
|
||||
}
|
||||
.cta a {
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
background: #6200ea;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 4px;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
.cta a:hover {
|
||||
background: #4500b3;
|
||||
}
|
||||
footer {
|
||||
background: #333;
|
||||
color: white;
|
||||
text-align: center;
|
||||
padding: 10px 0;
|
||||
margin-top: 20px;
|
||||
}
|
||||
footer p {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
footer a {
|
||||
color: #6200ea;
|
||||
text-decoration: none;
|
||||
}
|
||||
footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Repository Context Generator</h1>
|
||||
<p>Your tool for creating comprehensive repository context files</p>
|
||||
</header>
|
||||
|
||||
<div class="container">
|
||||
<section class="cta">
|
||||
<h2>Get Started</h2>
|
||||
<p>
|
||||
Generate a context file for your repository, including key details,
|
||||
directory structure, and more.
|
||||
</p>
|
||||
<a href="http://localhost:8501" target="_blank">Open the Application</a>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>How It Works</h2>
|
||||
<p>
|
||||
This tool simplifies interactions with AI coding assistants by
|
||||
generating a structured context file. You can customize directory
|
||||
exclusions, include important files, and add global documentation.
|
||||
</p>
|
||||
<ul>
|
||||
<li>Clone repositories easily via the app.</li>
|
||||
<li>Customize context settings to suit your project.</li>
|
||||
<li>Download the generated context file directly from the app.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Features</h2>
|
||||
<ul>
|
||||
<li>Supports multiple repositories.</li>
|
||||
<li>Includes static documentation sections.</li>
|
||||
<li>Customizable exclusions and global file inclusions.</li>
|
||||
<li>Syntax-highlighted file contents.</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<p>
|
||||
© 2025 Repository Context Generator. Built with
|
||||
<a href="https://streamlit.io" target="_blank">Streamlit</a>.
|
||||
</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
1103
src/repo-context.txt
Normal file
1103
src/repo-context.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
Flask
|
||||
Flask-Cors
|
||||
GitPython
|
||||
PyYAML
|
||||
streamlit
|
5
src/saved_config.yaml
Normal file
5
src/saved_config.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
excluded_files: []
|
||||
selected_directories:
|
||||
- src/
|
||||
- src\global_files/
|
||||
- src\static_files/
|
Reference in New Issue
Block a user