A CLI tool to generate prompts with project structure and file contents
Project description
kopipasta
A CLI tool to generate prompts with project structure, file contents, and web content, while handling environment variables securely and offering snippets for large files also interactive patch selection, allowing you to include only the most relevant parts of your code.
- An LLM told me that kopi means Coffee in some languages.. and a Diffusion model then made this delicious soup.
Installation
You can install kopipasta using pipx (or pip):
pipx install kopipasta
Usage
To use kopipasta, run the following command in your terminal:
kopipasta [files_or_directories_or_urls]
Replace [files_or_directories_or_urls]
with the paths to the files or directories you want to include in the prompt, as well as any web URLs you want to fetch content from.
Example:
kopipasta src/ config.json https://example.com/api-docs
This will generate a prompt including:
- The project structure
- Contents of the specified files and directories (with snippet options for large files)
- Content fetched from the provided URLs (with snippet options for large content)
- Handling of environment variables found in a
.env
file (if present)
Files and directories typically excluded in version control (based on common .gitignore patterns) are ignored.
The generated prompt will be displayed in the console and automatically copied to your clipboard.
Features
- Generates a structured prompt with project overview, file contents, web content, and task instructions
- Offers snippet options for large files (>100 KB) and web content (>10,000 characters)
- Fetches and includes content from web URLs
- Detects and securely handles environment variables from a
.env
file - Ignores files and directories based on common .gitignore patterns
- Allows interactive selection of files to include
- Automatically copies the generated prompt to the clipboard
Environment Variable Handling
If a .env
file is present in the current directory, kopipasta will:
- Read and store the environment variables
- Detect these variables in file contents and web content
- Prompt you to choose how to handle each detected variable:
- (m)ask: Replace the value with asterisks
- (s)kip: Replace the value with "[REDACTED]"
- (k)eep: Leave the value as-is
This ensures sensitive information is handled securely in the generated prompt.
Snippet Functionality
For large files (>100 KB) and web content (>10,000 characters), kopipasta offers a snippet option:
- For files: The first 50 lines or 4 KB (4,096 bytes), whichever comes first
- For web content: The first 1,000 characters
This helps manage the overall prompt size while still providing useful information about the content structure.
Example output
❯ kopipasta . https://example.com/api-docs
Directory: .
Files:
- __init__.py
- main.py (120 KB, ~120000 chars, ~30000 tokens)
- large_data.csv (5 MB, ~5000000 chars, ~1250000 tokens)
- .env
(y)es add all / (n)o ignore all / (s)elect individually / (q)uit? y
main.py is large. Use (f)ull content or (s)nippet? s
large_data.csv is large. Use (f)ull content or (s)nippet? s
Added all files from .
Added web content from: https://example.com/api-docs
File and web content selection complete.
Current prompt size: 10500 characters (~ 2625 tokens)
Summary: Added 3 files from 1 directory and 1 web source.
Detected environment variables:
- API_KEY=12345abcde
How would you like to handle API_KEY? (m)ask / (k)eep: m
Enter the task instructions: Implement new API endpoint
Generated prompt:
# Project Overview
## Project Structure
|-- ./ |-- init.py |-- main.py |-- large_data.csv |-- .env
## File Contents
### __init__.py
```python
# Initialize package
main.py (snippet)
import os
import pandas as pd
API_KEY = os.getenv('API_KEY')
def process_data(file_path):
df = pd.read_csv(file_path)
# Rest of the function...
# More code...
large_data.csv (snippet)
id,name,value
1,John,100
2,Jane,200
3,Bob,150
4,Alice,300
# ... (first 50 lines or 4 KB)
Web Content
https://example.com/api-docs (snippet)
API Documentation
Endpoint: /api/v1/data
Method: GET
Authorization: Bearer **********
...
Task Instructions
Implement new API endpoint
Task Analysis and Planning
Before starting, explain the task back to me in your own words. Ask for any clarifications if needed. Once you're clear, ask to proceed.
Then, outline a plan for the task. Finally, use your plan to complete the task.
Prompt has been copied to clipboard. Final size: 1500 characters (~ 375 tokens)
## License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file kopipasta-0.17.0.tar.gz
.
File metadata
- Download URL: kopipasta-0.17.0.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86f7e3457a2ae4fdbf3ab7e5f0b303feacfbd5b340b20b50a901bc72b50f48d3 |
|
MD5 | c76b39d77920ce506b75ecd9f9c234ea |
|
BLAKE2b-256 | d0476739f926f5c6c7a39ec18a318e06e96897e7fae7f6df7f0b7464cb9e8c29 |
File details
Details for the file kopipasta-0.17.0-py3-none-any.whl
.
File metadata
- Download URL: kopipasta-0.17.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78b7d522ed04109992726192d008a5853ad69a115f23df7e030a9ea0fbe13e77 |
|
MD5 | 1c6ccbc56d7051cef72c60669847de11 |
|
BLAKE2b-256 | 65049dfda542c8ec9e1206a2c90f212c0773178d08cfe0d9eaca639f6502ba79 |