Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
When you feel too lazy to selectively copy code from all the various files in your project, just copy it all! Inspired by repo2prompt.
You can install dir2prompt
using pip:
pip install dir2prompt
To generate a prompt from a directory, use the d2p
command followed by the desired options:
d2p --dir [directory path] --filters [file extensions] --outpath [output path] --outfile [output file name] --ignore-dir [directories to ignore] --ignore-file [files to ignore] --config [path to config file]
For ease of use, you can select a directory by passing it in as a positional argument
d2p [directory path]
If both the positional argument and the --dir
flag are provided, the --dir
flag takes priority.
--dir
: The directory to generate the prompt for (default: current directory).
--filters
: File extensions to include in the prompt (default: all files).
--outpath
: The output path for the prompt file (default: current directory).
--outfile
: The name of the output file (default: <directory_name>_prompt
).
--ignore-dir
: Additional directories to ignore (e.g., experiments
, run*
).
--ignore-file
: Additional file types to ignore (e.g., .pt
, .rs
).
--config
: Path to a custom config file (default: config.json
in the package directory).
Here's an example of how to use dir2prompt
to generate a prompt:
d2p --dir project --filters .py .txt .md .ipynb --ignore-dir experiments __pycache__ --ignore-file old.py
This command will generate a prompt for the specified directory, including only files with the extensions .py
, .txt
, .md
, .ipynb
, ignoring the experiments
and __pycache__
directories, and ignoring the old.py
file.
Note that ignored directories are not included in the directory tree, but that ignored files are. However, the content of the ignored files will not be written to the final prompt under the <files>
tag. This might be changed later...
In this example, the generated prompt will be saved as a .txt
file in the directory that d2p
is called in with the name project_prompt.txt
, and will have the following structure:
<dir_name>_prompt.txt
<context>
<directory_tree>
project/
├── README.md
├── requirements.txt
└── src/
├── __init__.py
├── main.py
├── old.py
├── production.ipynb
└── testing.rs
</directory_tree>
<files>
<file>
<path>README.md</path>
<content>
# Project Title
This is an example Python project.
</content>
</file>
<file>
<path>requirements.txt</path>
<content>
numpy==1.21.0
pandas==1.3.0
</content>
</file>
<file>
<path>src/__init__.py</path>
<content>
EMPTY FILE
</content>
</file>
<file>
<path>src/main.py</path>
<content>
import numpy as np
import pandas as pd
def main():
print("Hello, World!")
if __name__ == "__main__":
main()
</content>
</file>
<file>
<path>src/production.ipynb</path>
<content>
---------- Cell 1 (markdown) ----------
### Biologically inspired artificial neuron
$$
y = mx + b
$$
---------- Cell 2 (code) ----------
def neuron(x, m, b):
return m * x + b
</content>
</file>
</files>
</context>
You can then feed this prompt into an LLM to provide it with context about your project 🦾
dir2prompt
uses a config file, config.json
, to list common directories and files that should be ignored and excluded from the prompt. You can customize the behavior by supplying your own config file using the --config
option:
example.json
{
"IGNORE_DIRS": [
"experiments",
"run*",
...
],
"IGNORE_FILES": [
".pt",
".rs",
...
]
}
dir2prompt
is released under the MIT License 🤓
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
FAQs
Generate prompts for long-context LLMs using the content in your directory
We found that dir2prompt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.