This commit is contained in:
Keep Creating Online
2025-01-13 22:09:21 -05:00
parent 438e597484
commit c9090b5813
7 changed files with 105 additions and 135 deletions

View File

@@ -27,12 +27,8 @@ RePrompt/
│ ├── 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
│ ├── index.html # The webpage file
── requirements.txt # Python dependencies
```
## Installation
@@ -44,29 +40,7 @@ git clone https://github.com/PR0M3TH3AN/RePrompt
cd RePrompt
```
### 2. Context Files (Optional)
The tool looks for these files to provide additional context to AI assistants. While not required for basic functionality, they enhance the AI's understanding of your project:
```bash
src/static_files/
├── overview.txt # General project description and purpose
├── important_info.txt # Critical information AI should know
└── to-do_list.txt # Current project tasks and goals
```
These files are read when generating the context file. If they don't exist, the tool will still work but those sections will be empty in the generated context. Update these files with relevant information about your project to improve AI assistance.
Example `overview.txt`:
```txt
# Project Overview
This project is designed to [describe main purpose]. It [explain key functionality]
and helps users to [describe main benefits].
```
### 3. Set Up Virtual Environment
### 2. Set Up Virtual Environment
#### Windows:
@@ -88,13 +62,13 @@ python3 -m venv venv
source venv/bin/activate
```
### 4. Install Dependencies
### 3. Install Dependencies
```bash
cd src
```
### 3. Install Dependencies
### 4. Install Dependencies
Update pip first:
@@ -182,18 +156,6 @@ DEFAULT_EXCLUDED_DIRS = [
DEFAULT_EXCLUDED_FILES = ["repo-context.txt"]
```
### Add Custom Sections
Modify `config.yaml` to add custom sections:
```yaml
custom_sections:
- file: changelog.txt
section_title: "Changelog"
- file: LICENSE.txt
section_title: "License"
```
## Troubleshooting
### Common Issues
@@ -238,7 +200,3 @@ custom_sections:
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
```
```

View File

@@ -14,32 +14,55 @@ if 'copied' not in st.session_state:
# Configuration
CONFIG_FILE = "config.yaml"
OUTPUT_FILE = "repo-context.txt"
GLOBAL_FILES_DIR = Path(__file__).parent / "global_files"
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"]
DEFAULT_EXCLUDED_FILES = [
"repo-context.txt",
"package-lock.json",
"yarn.lock",
".gitattributes",
".gitignore",
".dockerignore",
".env",
"*.pem",
"*.crt",
"*.key",
".eslintrc",
".prettierrc",
".browserslistrc",
".editorconfig",
"client.crt",
"client-key.pem",
"docker-compose.yml",
".env.local",
".env.development",
".env.production"
]
# Ensure necessary directories exist
GLOBAL_FILES_DIR.mkdir(exist_ok=True)
# Load saved configuration from repository directory
def load_saved_config(repo_path):
saved_config_path = repo_path / "saved_config.yaml"
try:
if saved_config_path.exists():
with open(saved_config_path, "r") as f:
saved_config = yaml.safe_load(f)
return saved_config if saved_config else {}
return {}
except Exception:
return {}
# 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)
# Save configuration to repository directory
def save_config(config, repo_path):
try:
if not config: # Don't save empty configs
return
saved_config_path = repo_path / "saved_config.yaml"
with open(saved_config_path, "w") as f:
yaml.dump(config, f, default_flow_style=False)
except Exception:
pass
# Load application configuration
def load_config():
@@ -54,9 +77,13 @@ def load_config():
st.error(f"Error parsing configuration file: {e}")
st.stop()
app_config = load_config()
saved_config = load_saved_config()
# Clear config.yaml
def clear_config():
config_path = SCRIPT_DIR / CONFIG_FILE
with open(config_path, "w") as f:
yaml.dump({}, f)
app_config = load_config()
exclude_dirs = app_config.get("exclude_dirs", DEFAULT_EXCLUDED_DIRS)
# Initialize session state for selected_repo_path if not present
@@ -100,6 +127,7 @@ selected_repo_path = st.session_state.get("selected_repo_path", None)
if selected_repo_path:
st.header(f"Selected Repository: {selected_repo_path}")
repo_path = Path(selected_repo_path)
current_config = load_saved_config(repo_path) # Load config from repo directory
st.subheader("File Filtering")
# Retrieve directories and files in the repository
@@ -109,31 +137,52 @@ if selected_repo_path:
rel_root = Path(root_dir).relative_to(repo_path)
# Exclude default directories
dirs[:] = [d for d in dirs if d not in DEFAULT_EXCLUDED_DIRS]
# Add directories
for d in dirs:
all_directories.append(str(rel_root / d) + "/")
# Add files (including root files)
for f in files:
all_files.append(str(rel_root / f))
# Skip files that match any of the default excluded patterns
if any(f.endswith(excluded.replace('*', '')) for excluded in DEFAULT_EXCLUDED_FILES if '*' in excluded) or \
f in DEFAULT_EXCLUDED_FILES:
continue
file_path = str(rel_root / f)
if file_path.startswith('.'): # Handle root files
file_path = file_path[2:] # Remove './'
all_files.append(file_path)
# Directory selection for Directory Tree
# Filter out any saved directories that don't exist in current options
saved_directories = current_config.get("selected_directories", [])
valid_saved_directories = [d for d in saved_directories if d in all_directories]
selected_directories = st.multiselect(
"Include in Directory Tree",
options=all_directories,
default=saved_config.get("selected_directories", [])
default=valid_saved_directories
)
# Automatically include files within selected directories unless explicitly excluded
# Include all files in selected directories AND root files
included_files = [
f for f in all_files if any(str(Path(f).parent) in d for d in selected_directories)
f for f in all_files if (
any(str(Path(f).parent) in d for d in selected_directories) or # Files in selected directories
str(Path(f).parent) == '.' or # Root files
str(Path(f).parent) == '' # Also handles root files
)
]
# File exclusions
available_files = [f for f in included_files if f not in DEFAULT_EXCLUDED_FILES]
saved_exclusions = [f for f in current_config.get("excluded_files", [])
if f in available_files and f not in DEFAULT_EXCLUDED_FILES]
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
],
options=available_files,
default=saved_exclusions
)
st.write("### Final Included Files")
@@ -148,13 +197,13 @@ if selected_repo_path:
"source_directory": str(repo_path),
"exclude_dirs": DEFAULT_EXCLUDED_DIRS,
"important_files": final_included_files,
"custom_sections": app_config.get("custom_sections", []),
"custom_sections": app_config.get("custom_sections", [])
}
# Write updated config.yaml
with open(SCRIPT_DIR / CONFIG_FILE, "w") as f:
yaml.dump(updated_config, f)
# Run the script as a subprocess
result = subprocess.run(
[sys.executable, str(SCRIPT_DIR / "generate_repo_context.py")],
@@ -164,16 +213,27 @@ if selected_repo_path:
text=True,
)
# Clear config.yaml after generation
clear_config()
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
# Check if the file was created in script directory first
generated_file = SCRIPT_DIR / "repo-context.txt"
if generated_file.exists():
# Read content
with open(generated_file, "r", encoding="utf-8") as f:
context_content = f.read()
# Replace the current copy button section with this:
# Copy file to repository directory
repo_context_file = repo_path / "repo-context.txt"
with open(repo_context_file, "w", encoding="utf-8") as f:
f.write(context_content)
# Delete the file from script directory
generated_file.unlink()
if context_content.strip(): # Ensure content is not empty
# Add Download Button with unique key
st.download_button(
@@ -193,6 +253,8 @@ if selected_repo_path:
height=400,
key="context_content"
)
st.success(f"Context file saved to: {repo_context_file}")
else:
st.error("Generated content is empty. Please review your repository and configurations.")
else:
@@ -209,7 +271,7 @@ if selected_repo_path:
save_config({
"selected_directories": selected_directories,
"excluded_files": excluded_files,
})
}, repo_path)
st.success("Configuration saved successfully.")
else:
st.write("Please select a folder to begin.")

View File

@@ -1,12 +1 @@
custom_sections:
- file: changelog.txt
section_title: Changelog
- file: LICENSE.txt
section_title: License
exclude_dirs:
-
important_files:
-
source_directory:
{}

View File

@@ -1,39 +0,0 @@
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.