code2prompt icon indicating copy to clipboard operation
code2prompt copied to clipboard

I would like to discuss exclude and clipboad.

Open yasainet opened this issue 1 year ago β€’ 12 comments

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)

yasainet avatar Jul 08 '24 09:07 yasainet

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

yspmymt avatar Jul 08 '24 10:07 yspmymt

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:

  • $\neg A \cap \neg B$: No include list, no exclude list $\rightarrow$ Include everything: $\mathbf{\Omega}$
  • $\neg A \cap B$: No include list, with exclude list $\rightarrow$ Include everything except what matches the exclude list: $\mathbf{\Omega} \setminus \mathbf{B}$
  • $A \cap \neg B$: With include list, no exclude list $\rightarrow$ Include only what matches the include list: $\mathbf{A}$
  • $A \cap B$: With include list and exclude list $\rightarrow$ Include what matches the include list, exclude what matches the exclude list. Decide what to do with the intersection based on the include_priority parameter:
    • Include: $\mathbf{A} \setminus (\mathbf{A} \cap \mathbf{B})$
    • Exclude: $\mathbf{B} \setminus (\mathbf{A} \cap \mathbf{B})$

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.

ODAncona avatar Jul 09 '24 07:07 ODAncona

@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 avatar Jul 12 '24 10:07 yasainet

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

yasainet avatar Jul 12 '24 10:07 yasainet

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 😞

gretel avatar Jul 12 '24 15:07 gretel

using glob patternsπŸ₯³

How about asking ChatGPT the following?

  • Please exclude the following extensions from the grob pattern
  • .html, .log...

You can apply this method to do many things!

yasainet avatar Jul 12 '24 20:07 yasainet

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

gretel avatar Jul 13 '24 21:07 gretel

@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.

y00njaekim avatar Jul 14 '24 07:07 y00njaekim

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.

yasainet avatar Jul 14 '24 20:07 yasainet

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.

steelep avatar Aug 20 '24 13:08 steelep

Thank you for this tool! But I also have a problem with the exclude flag.

I have the following Filetree and I can't get the exclude pattern to work, despite following the suggested patterns here and also asking ChatGPT.

app git:main
❯ tree
.
β”œβ”€β”€ README.md
β”œβ”€β”€ context.md
└── src
    β”œβ”€β”€ backend
    β”‚Β Β  β”œβ”€β”€ deno.json
    β”‚Β Β  β”œβ”€β”€ deno.lock
    β”‚Β Β  β”œβ”€β”€ http
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ add story.bru
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ bruno.json
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ environments
    β”‚Β Β  β”‚Β Β  β”‚Β Β  └── localhost.bru
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ status.bru
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ stories.bru
    β”‚Β Β  β”‚Β Β  └── story.bru
    β”‚Β Β  β”œβ”€β”€ main.ts
    β”‚Β Β  β”œβ”€β”€ routes
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ status.ts
    β”‚Β Β  β”‚Β Β  └── stories.ts
    β”‚Β Β  β”œβ”€β”€ server.ts
    β”‚Β Β  └── stores
    β”‚Β Β      └── stories.ts
    β”œβ”€β”€ frontend
    β”‚Β Β  β”œβ”€β”€ README.md
    β”‚Β Β  β”œβ”€β”€ deno.lock
    β”‚Β Β  β”œβ”€β”€ eslint.config.js
    β”‚Β Β  β”œβ”€β”€ index.html
    β”‚Β Β  β”œβ”€β”€ node_modules
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ @eslint
    β”‚Β Β  β”‚Β Β  β”‚Β Β  └── js -> ../.deno/@[email protected]/node_modules/@eslint/js
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ @types
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ react -> ../.deno/@[email protected]/node_modules/@types/react
    β”‚Β Β  β”‚Β Β  β”‚Β Β  └── react-dom -> ../.deno/@[email protected]/node_modules/@types/react-dom
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ @vitejs
    β”‚Β Β  β”‚Β Β  β”‚Β Β  └── plugin-react -> ../.deno/@[email protected]/node_modules/@vitejs/plugin-react
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ eslint -> .deno/[email protected]/node_modules/eslint
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ eslint-plugin-react-hooks -> .deno/[email protected]/node_modules/eslint-plugin-react-hooks
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ eslint-plugin-react-refresh -> .deno/[email protected]/node_modules/eslint-plugin-react-refresh
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ globals -> .deno/[email protected]/node_modules/globals
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ react -> .deno/[email protected]/node_modules/react
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ react-dom -> .deno/[email protected]/node_modules/react-dom
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ typescript -> .deno/[email protected]/node_modules/typescript
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ typescript-eslint -> .deno/[email protected]/node_modules/typescript-eslint
    β”‚Β Β  β”‚Β Β  └── vite -> .deno/[email protected]/node_modules/vite
    β”‚Β Β  β”œβ”€β”€ package-lock.json
    β”‚Β Β  β”œβ”€β”€ package.json
    β”‚Β Β  β”œβ”€β”€ public
    β”‚Β Β  β”‚Β Β  └── vite.svg
    β”‚Β Β  β”œβ”€β”€ src
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ App.css
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ App.tsx
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ assets
    β”‚Β Β  β”‚Β Β  β”‚Β Β  └── react.svg
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ index.css
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ main.tsx
    β”‚Β Β  β”‚Β Β  └── vite-env.d.ts
    β”‚Β Β  β”œβ”€β”€ tsconfig.app.json
    β”‚Β Β  β”œβ”€β”€ tsconfig.json
    β”‚Β Β  β”œβ”€β”€ tsconfig.node.json
    β”‚Β Β  └── vite.config.ts
    └── shared
        └── types
            └── story.ts

30 directories, 33 files

This is the command that I am using:

code2prompt . --exclude="**/deno.lock,**/package-lock.json" --output="context.md"

nikbrunner avatar Oct 13 '24 08:10 nikbrunner

Hello @nikbrunner,

Thank you to raise this issue. I wasn't able to reproduce your issue. Maybe you omitted the --exclude-from-tree command which is responsible to remove the excluded file from the directory tree ? However, when I tried to reproduce, deno.lock or package.json files content were properly excluded from context.md even though they appear in the directory tree.

I understand this feature is confusing because you don't expect your excluded file to remain in the directory tree. However, it's sometimes practical to keep them in the tree in order to feed extra context...

Can you confirm the files content is properly excluded from context.md ?

Here's the script I used to reproduce your situation:

#!/bin/bash

# Define the directory structure and files
declare -A structure=(
  ["README.md"]="README.md"
  ["context.md"]="context.md"
  ["src/backend/deno.json"]="deno.json"
  ["src/backend/deno.lock"]="deno.lock"
  ["src/backend/http/add story.bru"]="add story.bru"
  ["src/backend/http/bruno.json"]="bruno.json"
  ["src/backend/http/environments/localhost.bru"]="localhost.bru"
  ["src/backend/http/status.bru"]="status.bru"
  ["src/backend/http/stories.bru"]="stories.bru"
  ["src/backend/http/story.bru"]="story.bru"
  ["src/backend/main.ts"]="main.ts"
  ["src/backend/routes/status.ts"]="status.ts"
  ["src/backend/routes/stories.ts"]="stories.ts"
  ["src/backend/server.ts"]="server.ts"
  ["src/backend/stores/stories.ts"]="stories.ts"
  ["src/frontend/README.md"]="README.md"
  ["src/frontend/deno.lock"]="deno.lock"
  ["src/frontend/eslint.config.js"]="eslint.config.js"
  ["src/frontend/index.html"]="index.html"
  ["src/frontend/package-lock.json"]="package-lock.json"
  ["src/frontend/package.json"]="package.json"
  ["src/frontend/public/vite.svg"]="vite.svg"
  ["src/frontend/src/App.css"]="App.css"
  ["src/frontend/src/App.tsx"]="App.tsx"
  ["src/frontend/src/assets/react.svg"]="react.svg"
  ["src/frontend/src/index.css"]="index.css"
  ["src/frontend/src/main.tsx"]="main.tsx"
  ["src/frontend/src/vite-env.d.ts"]="vite-env.d.ts"
  ["src/frontend/tsconfig.app.json"]="tsconfig.app.json"
  ["src/frontend/tsconfig.json"]="tsconfig.json"
  ["src/frontend/tsconfig.node.json"]="tsconfig.node.json"
  ["src/frontend/vite.config.ts"]="vite.config.ts"
  ["src/shared/types/story.ts"]="story.ts"
)

# Create directories and files
for path in "${!structure[@]}"; do
  # Extract the file content
  content="${structure[$path]}"
  
  # Create the directory structure
  mkdir -p "$(dirname "$path")"
  
  # Write the file content
  echo "$content" > "$path"
done

echo "All files and directories have been created successfully!"

ODAncona avatar Dec 27 '24 10:12 ODAncona

How can I exclude an entire folder like node_modules?

0xCUB3 avatar Mar 20 '25 11:03 0xCUB3

@0xCUB3

Two syntax are possible depending on where node_modules is located

code2prompt . --include "*.js,*.html" --exclude "node_modules/"

code2prompt . --include "*.js,*.html" --exclude "**/node_modules/**"

ODAncona avatar Mar 20 '25 17:03 ODAncona