mufeedvh / code2prompt

A CLI tool to convert your codebase into a single LLM prompt with source tree, prompt templating, and token counting.
MIT License
1.45k stars 77 forks source link

I would like to discuss exclude and clipboad. #31

Open yasainet opened 1 month ago

yasainet commented 1 month ago

Basically, I am a Mac developer. However, I sometimes develop on Ubuntu with Windows WSL2 due to circumstances.

I can use Mac without any problem, but in WSL2 environment, the following commands do not work as expected.

1.code2prompt /home/USER/PJ --exclude="**/package-lock.json"

The purpose is to exclude package-lock.json existing in PJ/server, PJ/client, etc. However, the output result includes the contents of package-lock.json. Is there a way to properly use --exclude?

  1. code2prompt /home/USER/PJ

I am expecting the output results to be saved to the clipboard as a result of running this command, but sometimes they are not. So, I use the following command every time. code2prompt /home/USER/PJ --ouput /home/USER/PJ/output.txt.

It accomplishes the purpose, but it is better to be saved to the clipboard.

Can you give me some advice on how to solve this problem?


P.S. Very nice app, can't develop anymore without it! I look forward to more in the future.

Translated with DeepL.com (free version)

yspmymt commented 1 month ago

Same! I have to delete the code myself every time to pass it to the AI, but it is quite difficult.

ODAncona commented 1 month ago

How the Glob Pattern Tool Works

The tool uses glob patterns to include or exclude files and directories, and works similarly to tools like tree or grep. Here’s a detailed explanation:

Key Concepts

  1. Include List ($\mathbf{A}$): A set containing the glob patterns for files and directories you want to include.
  2. Exclude List ($\mathbf{B}$): A set containing the glob patterns for files and directories you want to exclude.
  3. Universe ($\mathbf{\Omega}$): The set of all files and directories.

When you specify an --exclude list and/or an --include list, the following logic applies:

Here’s a visual representation of the last case:

Venn Diagram

Question 1

In your case, the command is indeed correct code2prompt <pathtoyourcodebase> --exclude "**/package.json" It can still appear in the directory tree, if you don't want it you can use the flag --exclude-from-tree. I tried on my own on some JS project and it's working fine.

Question 2

Code2prompt use the ARboard crate for managing the clipboard. You should go check whether this package is working in WSL. Otherwise, I suggest to use the no-clipboard option with the -o (--output) flag to dump your codebase into a file. You can take a look at the PR #26 or #30.

yasainet commented 1 month ago

@somas1

Read code2prompt --help

  -e, --exclude <EXCLUDE>.
          Optional comma-separated list of file extensions to exclude

      --exclude-files <EXCLUDE_FILES>
          Optional comma-separated list of file names to exclude

      --exclude-folders <EXCLUDE_FOLDERS>
          Optional comma-separated list of folder paths to exclude

      --tokens
          Display the token count of the generated prompt.

This option may solve your problem!

yasainet commented 1 month ago

If --help is different, run --version. The behavior of the command may be slightly different depending on the version.

gretel commented 1 month ago

am trying to exclude a couple of files matching by extension and i don't get it to work with none of the available parameters. lastly, tried

code2prompt --filter html,log,json,scss,handlebars .

and a couple of more combinations just to find the excluded/filterered files included in any case 😞

yasainet commented 1 month ago

using glob patterns🥳

How about asking ChatGPT the following?

You can apply this method to do many things!

gretel commented 1 month ago

talking to me like i am stupid while not posting the answer you seem to know?

y00njaekim commented 1 month ago

@gretel To exclude specific file extensions, you can use the --exclude option followed by a comma-separated list of extensions without the glob pattern. For excluding files with specific filenames, you can use the --exclude-files option. Here's an example that demonstrates both:

code2prompt . --exclude="kts,xml,json,bat,properties,pro" --exclude-files="gradlew"

This command will exclude files with the extensions .kts, .xml, .json, .bat, .properties, and .pro, as well as any file named "gradlew". This approach provides a clear and straightforward way to specify exclusions without relying on glob patterns.

yasainet commented 1 month ago

I am Japanese and my English is not good. I am sorry for my comment, I thought it might be useful for you.

Please understand that I write all my comments using DeepL translation.

Also, asking ChatGPT is very effective and I really encourage you to try it. Because not only will it achieve the purpose of this project, but it will also be useful when new requests come up in the future.

steelep commented 1 week ago

Nice tool. FYI I too am also seeing the auto copy to the clipboard not working. I have tried both the cargo release and building from the source. (I've tried under $USER and sudo to no avail). I'm running stock Ubuntu 22.04.