### Pypi Installation Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Command to install Python bindings from Pypi. ```bash pip install code2prompt_rs ``` -------------------------------- ### TL;DR Installation Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Quick installation commands for Cargo and Homebrew. ```bash # Cargo $ cargo install code2prompt # Homebrew $ brew install code2prompt ``` -------------------------------- ### Cline integration example Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Example JSON configuration for integrating the code2prompt MCP server with Cline. ```json { "mcpServers": { "code2prompt": { "command": "bash", "args": [ "-c", "cd /home/olivier/projet/code2prompt-mcp && rye run python /home/olivier/projet/code2prompt-mcp/src/code2prompt_mcp/main.py" ], "env": {} } } } ``` -------------------------------- ### Install from Source Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Command to build and install code2prompt from source. ```bash cargo install --path crates/code2prompt ``` -------------------------------- ### Nix Installation Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Commands to install code2prompt using Nix. ```bash # without flakes: nix-env -iA nixpkgs.code2prompt # with flakes: nix profile install nixpkgs#code2prompt ``` -------------------------------- ### Running Examples Source: https://github.com/mufeedvh/code2prompt/blob/main/crates/code2prompt-python/python-sdk/README.md Command to run the example script. ```bash python examples/basic_usage.py ``` -------------------------------- ### Check Installation Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Commands to verify Rust and Git installation. ```bash cargo --version git --version ``` -------------------------------- ### Install Latest Version from GitHub Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Command to install the latest unpublished version from GitHub. ```bash cargo install --git https://github.com/mufeedvh/code2prompt ``` -------------------------------- ### Install Python SDK Source: https://github.com/mufeedvh/code2prompt/blob/main/README.md Installs the Python SDK for Code2Prompt. ```bash pip install code2prompt-rs ``` -------------------------------- ### Rust and Cargo Installation Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Official command to install Rust and Cargo. ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -------------------------------- ### Build Binary without Installing Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Command to build the binary without installing it. ```bash cargo build --release ``` -------------------------------- ### Install with Homebrew Source: https://github.com/mufeedvh/code2prompt/blob/main/README.md Installs the Code2Prompt CLI tool using Homebrew. ```bash brew install code2prompt ``` -------------------------------- ### Run the server Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Activates the virtual environment and runs the MCP server. ```sh . .venv/bin/activate python -m src/code2prompt_mcp/main.py ``` -------------------------------- ### AUR Installation Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Command to install code2prompt from AUR using paru or yay. ```bash paru/yay -S code2prompt ``` -------------------------------- ### Install with Cargo Source: https://github.com/mufeedvh/code2prompt/blob/main/README.md Installs the Code2Prompt CLI tool using Cargo. ```bash cargo install code2prompt ``` -------------------------------- ### Review-Ready .c2pconfig Example Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/configuration.mdx A configuration optimized for code reviews, setting output to clipboard, including only '.rs' files, excluding test files, disabling line numbers, and enabling absolute paths. ```toml default_output = "clipboard" include_patterns = ["*.rs"] exclude_patterns = ["**/test*","**code2prompt-python*"] line_numbers = false absolute_path = true [user_variables] project = "code2prompt" ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/mufeedvh/code2prompt/blob/main/llms-install.md Clones the code2prompt-mcp repository and installs all required dependencies using rye. ```bash git clone https://github.com/odancona/code2prompt-mcp.git cd code2prompt-mcp rye build ``` -------------------------------- ### Basic .c2pconfig Example Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/configuration.mdx Defines default output, include/exclude patterns, line number preference, output format, and user variables. ```toml # .c2pconfig example default_output = "stdout" # Options: stdout, clipboard, file include_patterns = ["src/**/*.rs", "Cargo.toml"] exclude_patterns = ["**/target/**", "tests/fixtures/**"] line_numbers = true output_format = "markdown" [user_variables] project_name = "MyAwesomeProject" author = "Developer" ``` -------------------------------- ### Pantry Ingredients Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/my_recipes/prompt.md A text file listing available ingredients. ```text Available: pasta, tomato sauce, cheese ``` -------------------------------- ### Local Development Installation Source: https://github.com/mufeedvh/code2prompt/blob/main/crates/code2prompt-python/python-sdk/README.md Commands to clone the repository and install development dependencies. ```bash git clone https://github.com/mufeedvh/code2prompt.git cd code2prompt ``` ```bash python3 -m venv .venv source .venv/bin/activate pip install maturin pytest ``` ```bash cd code2prompt/ # root repo directory maturin develop -r ``` -------------------------------- ### Clone Repository Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Commands to clone the code2prompt repository. ```bash git clone https://github.com/mufeedvh/code2prompt.git cd code2prompt ``` -------------------------------- ### Run Code2Prompt Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Command to run code2prompt after building. ```bash code2prompt --help ``` -------------------------------- ### Source build installation Source: https://github.com/mufeedvh/code2prompt/blob/main/README.md Instructions for building Code2Prompt from source using Git and Cargo. ```sh git clone https://github.com/mufeedvh/code2prompt.git cd code2prompt/ cargo install --path crates/code2prompt ``` -------------------------------- ### Verify Installation Command Source: https://github.com/mufeedvh/code2prompt/blob/main/llms-install.md A sample command to test the Code2Prompt MCP server connection by requesting context analysis for a project. ```bash Please get context from /path/to/project for AI analysis using Code2Prompt. ``` -------------------------------- ### Usage Example Source: https://github.com/mufeedvh/code2prompt/blob/main/crates/code2prompt-python/python-sdk/README.md Example of how to use the CodePrompt class to generate prompts from a codebase. ```python from code2prompt import CodePrompt # Create a new CodePrompt instance prompt = CodePrompt( path="./my_project", include_patterns=["*.py", "*.rs"], # Optional: Only include Python and Rust files exclude_patterns=["**/tests/*"], # Optional: Exclude test files line_numbers=True, # Optional: Add line numbers to code ) # Generate a prompt result = prompt.generate( template=None, # Optional: Custom Handlebars template encoding="cl100k" # Optional: Token encoding (for token counting) ) # Access the generated prompt and metadata print(f"Generated prompt: {result['prompt']}") print(f"Token count: {result['token_count']}") print(f"Model info: {result['model_info']}") # Git operations git_diff = prompt.get_git_diff() branch_diff = prompt.get_git_diff_between_branches("main", "feature") git_log = prompt.get_git_log("main", "feature") ``` -------------------------------- ### Refresh PATH Variable Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Command to refresh the PATH variable after installing Rust. ```bash source $HOME/.cargo/env ``` -------------------------------- ### Usage Example: Local Codebase Analysis Source: https://github.com/mufeedvh/code2prompt/blob/main/llms-install.md Example prompt to request AI analysis of code within a local project using Code2prompt MCP. ```bash Can you analyze the code in my project at /path/to/project? Please use Code2prompt MCP to get the context. ``` -------------------------------- ### Sync Python Dependencies Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Command to sync Python dependencies using rye. ```bash rye sync ``` -------------------------------- ### Usage Example: Specific File Types Analysis Source: https://github.com/mufeedvh/code2prompt/blob/main/llms-install.md Example prompt to request context analysis, filtering by file type and excluding specific directories. ```bash Please get all python files and remove markdown files and the folder tests, use Code2prompt MCP for context. ``` -------------------------------- ### Pizza Recipe Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/my_recipes/prompt.md A text file detailing the ingredients and instructions for making pizza. ```text Ingredients: flour, tomato sauce, cheese, oregano Instructions: Make dough, add toppings, bake. ``` -------------------------------- ### Soup Recipe Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/my_recipes/prompt.md A text file detailing the ingredients and instructions for making soup. ```text Ingredients: carrots, potatoes, chicken broth, onions Instructions: Boil broth, add vegetables, simmer. ``` -------------------------------- ### Install with Cargo (Wayland Support) Source: https://github.com/mufeedvh/code2prompt/blob/main/README.md Installs the Code2Prompt CLI tool with Wayland support for clipboard integration. ```bash cargo install --features wayland code2prompt ``` -------------------------------- ### Install Rye Source: https://github.com/mufeedvh/code2prompt/blob/main/llms-install.md Installs the rye dependency manager using a curl script. Ensure to add rye to your PATH. ```bash curl -sSf https://rye.astral.sh/get | bash ``` -------------------------------- ### Salad Recipe Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/my_recipes/prompt.md A text file detailing the ingredients and instructions for making a salad. ```text Ingredients: lettuce, tomato, cucumber, olive oil Instructions: Chop ingredients, mix, drizzle oil. ``` -------------------------------- ### Pasta Recipe Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/my_recipes/prompt.md A text file detailing the ingredients and instructions for making pasta. ```text Ingredients: pasta, tomato sauce, garlic, basil Instructions: Boil pasta, heat sauce, mix, serve. ``` -------------------------------- ### Build Python Package Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Command to build the Python package using maturin. ```bash rye run maturin develop -r ``` -------------------------------- ### Clone Python Bindings Repository Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/install.mdx Commands to clone the code2prompt repository for Python bindings. ```bash git clone https://github.com/mufeedvh/code2prompt.git cd code2prompt/crates/code2prompt-python ``` -------------------------------- ### Node.js App README Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/node_app/prompt.md A brief description of the Node.js application and a feature idea. ```markdown Simple Node.js app to process JSON data. Feature idea: Add a filter function to sort users by age. ``` -------------------------------- ### Launch Interactive TUI Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Starts the interactive Text-based User Interface for Code2Prompt. ```sh code2prompt path/to/codebase --tui ``` -------------------------------- ### Main Node.js Entry Point Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/node_app/prompt.md The main JavaScript file for the Node.js application, which imports and calls a utility function. ```javascript const { processData } = require("./utils"); console.log("App started"); processData(); ``` -------------------------------- ### Renaissance History Notes Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/history_notes/prompt.md Example content for renaissance history notes. ```text Key figures: Leonardo da Vinci, Michelangelo, Copernicus Cultural shifts: Humanism, art revival, printing press ``` -------------------------------- ### Medieval History Notes Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/history_notes/prompt.md Example content for medieval history notes. ```text Key events: Fall of Rome, Viking raids, Magna Carta Important dates: 476 AD, 793 AD, 1215 AD ``` -------------------------------- ### Revision Goals Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/history_notes/prompt.md Example content for revision goals related to history notes. ```text Focus: Memorize key events, understand causes & consequences Deadline: 2 weeks ``` -------------------------------- ### Sample JSON Data Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/node_app/prompt.md Sample JSON data representing a list of users with their ages. ```json { "users": [ { "name": "Alice", "age": 25 }, { "name": "Bob", "age": 30 } ] } ``` -------------------------------- ### Generate Prompt with Python SDK Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/getting_started.mdx Programmatically generates a prompt from a project directory using the Code2Prompt Python SDK. Requires 'pip install code2prompt_rs'. ```python from code2prompt_rs import Code2Prompt config = { "path": "my_project", "include_patterns": ["*.rs"], "exclude_patterns": ["tests/*"], } c2p = Code2Prompt(**config) prompt = c2p.generate_prompt() print(prompt) ``` -------------------------------- ### WW2 History Notes Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/history_notes/prompt.md Example content for World War 2 history notes. ```text Key events: D-Day, Hiroshima, End of War Leaders: Churchill, Roosevelt, Hitler, Stalin ``` -------------------------------- ### LLM Application MCP Server Configuration Source: https://github.com/mufeedvh/code2prompt/blob/main/llms-install.md Example JSON configuration for an LLM application to connect to the Code2Prompt MCP server. Adjust paths as necessary. ```json { "mcpServers": { "code2prompt": { "command": "bash", "args": [ "-c", "cd /path/to/code2prompt-mcp && rye run python /path/to/code2prompt-mcp/src/code2prompt_mcp/main.py" ], "env": {} } } } ``` -------------------------------- ### Node.js Utility Function Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/node_app/prompt.md A utility JavaScript file containing a function to process data. ```javascript function processData() { console.log("Processing data..."); } module.exports = { processData }; ``` -------------------------------- ### Handlebars Template with Conditional Logic and Loops Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_templates.mdx This example demonstrates using Handlebars helpers like #if and #each to conditionally render file paths and content within a template. ```handlebars {{#if files}} {{#each files}} File: {{this.path}} Content: {{this.content}} {{/each}} {{else}} No files found. {{/if}} ``` -------------------------------- ### Updated utils.js Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/node_app/question.txt This snippet shows the updated utils.js file with the new filterUsersByAge function. ```javascript /** * Filters an array of users by age in ascending order. * @param {Array} users - The array of user objects. * @param {number} age - The age to filter by. * @returns {Array} - The filtered array of users. */ export const filterUsersByAge = (users, age) => { // Sort users by age in ascending order const sortedUsers = [...users].sort((a, b) => a.age - b.age); // Filter users older than or equal to the specified age return sortedUsers.filter(user => user.age >= age); }; ``` -------------------------------- ### Modified index.js Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/assets/examples/node_app/question.txt This snippet shows the modified index.js file demonstrating the user filtering. ```javascript import { filterUsersByAge } from './utils.js'; // Sample user data const users = [ { id: 1, name: 'Alice', age: 30 }, { id: 2, name: 'Bob', age: 25 }, { id: 3, name: 'Charlie', age: 35 }, { id: 4, name: 'David', age: 28 }, ]; // Age to filter by const ageFilter = 30; // Filter users by age const filteredUsers = filterUsersByAge(users, ageFilter); // Display the results console.log(`Users older than or equal to ${ageFilter}:`); filteredUsers.forEach(user => { console.log(`- ${user.name}, Age: ${user.age}`); }); /* Expected output: Users older than or equal to 30: - Alice, Age: 30 - Charlie, Age: 35 */ ``` -------------------------------- ### Create Sample Project Files Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/getting_started.mdx Creates a directory structure and sample Rust files for a project. Used to demonstrate CLI prompt generation. ```bash mkdir -p my_project/{src,tests} touch my_project/src/main.rs my_project/tests/test_1.rs echo 'fn main() { println!("Hello, world!"); }' > my_project/src/main.rs ``` -------------------------------- ### Matching files that start with a or b and end with .txt Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/explanations/glob_patterns.md This glob pattern matches files that begin with either 'a' or 'b', followed by any characters, and end with the .txt extension. ```sh {a,b}*.txt ``` -------------------------------- ### Initialize .c2pconfig File Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/config.mdx Navigate to your project's root directory and create an empty .c2pconfig file using the touch command. ```bash cd path/to/your/project touch .c2pconfig ``` -------------------------------- ### Create Astro Project with Starlight Template Source: https://github.com/mufeedvh/code2prompt/blob/main/website/README.md Command to create a new Astro project using the Starlight template. ```bash yarn create astro@latest -- --template starlight ``` -------------------------------- ### Run Code2Prompt with Configuration Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/config.mdx After saving the .c2pconfig file, run the code2prompt command with the current directory to automatically apply your configurations. ```bash code2prompt . ``` -------------------------------- ### Project Structure Source: https://github.com/mufeedvh/code2prompt/blob/main/website/README.md The typical folder and file structure for an Astro + Starlight project. ```tree .\n├── public/\n├── src/\n│ ├── assets/\n│ ├── content/\n│ │ ├── docs/\n│ └── content.config.ts\n├── astro.config.mjs\n├── package.json\n└── tsconfig.json ``` -------------------------------- ### Run MCP Server with Virtual Environment Activation Source: https://github.com/mufeedvh/code2prompt/blob/main/llms-install.md Activates the virtual environment created by rye and runs the code2prompt-mcp main script. ```bash cd source .venv/bin/activate python code2prompt_mcp.main ``` -------------------------------- ### Define Base Behavior in .c2pconfig Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/config.mdx Configure default output, format, line numbers, tokenizer encoding, and file inclusion/exclusion patterns using TOML syntax. ```toml # Default behavior configuration default_output = "clipboard" # Options: stdout, clipboard, file output_format = "xml" # Options: markdown, json, xml line_numbers = false # Adds line numbers to your code blocks encoding = "o200k" # Matches the tokenizer to your target LLM # Global filtering rules include_patterns = ["src/**/*.rs", "Cargo.toml"] exclude_patterns = [ "**/node_modules/**", "**/target/**", "tests/fixtures/**", "package-lock.json" ] ``` -------------------------------- ### Generate Test Structure Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_filters.mdx Run this script to set up a temporary directory structure for practicing glob patterns. ```bash #!/bin/bash # Create base directory mkdir -p test_dir/{lowercase,uppercase,.secret} # Create files in the structure echo "content foo.py" > "test_dir/lowercase/foo.py" echo "content bar.py" > "test_dir/lowercase/bar.py" echo "content baz.py" > "test_dir/lowercase/baz.py" echo "content qux.txt" > "test_dir/lowercase/qux.txt" echo "content corge.txt" > "test_dir/lowercase/corge.txt" echo "content grault.txt" > "test_dir/lowercase/grault.txt" echo "CONTENT FOO.py" > "test_dir/uppercase/FOO.PY" echo "CONTENT BAR.py" > "test_dir/uppercase/BAR.PY" echo "CONTENT BAZ.py" > "test_dir/uppercase/BAZ.PY" echo "CONTENT QUX.txt" > "test_dir/uppercase/QUX.TXT" echo "CONTENT CORGE.txt" > "test_dir/uppercase/CORGE.TXT" echo "CONTENT GRAULT.txt" > "test_dir/uppercase/GRAULT.TXT" echo "top secret" > "test_dir/.secret/secret.txt" ``` -------------------------------- ### Generate Prompt with CLI Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/getting_started.mdx Generates a prompt from the 'my_project' directory using the code2prompt CLI. The prompt is copied to the clipboard. ```bash code2prompt my_project ``` -------------------------------- ### CLI Prompt Generation with Filtering and Output Options Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/getting_started.mdx Demonstrates advanced CLI usage for prompt generation, including file inclusion/exclusion patterns, specifying an output file, and requesting JSON output. ```bash code2prompt my_project --include="*.rs" --exclude="tests/*" ``` ```bash code2prompt my_project --output-file=my_prompt.txt ``` ```bash code2prompt my_project -O json ``` -------------------------------- ### Print Output as JSON Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Formats the output prompt as JSON, including prompt text, directory name, token count, model info, and file list. ```sh code2prompt path/to/codebase -F JSON ``` -------------------------------- ### Basic Usage Source: https://github.com/mufeedvh/code2prompt/blob/main/README.md Generates a prompt from the current directory and copies it to the clipboard. ```sh code2prompt . ``` -------------------------------- ### Use Custom Handlebars Template Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Generates a prompt using a specified custom Handlebars template file. ```sh code2prompt path/to/codebase -t path/to/template.hbs ``` -------------------------------- ### Generate Prompt from Codebase Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Use this command to generate a prompt from a specified codebase path. ```sh code2prompt path/to/codebase ``` -------------------------------- ### Run MCP Server Directly with Rye Source: https://github.com/mufeedvh/code2prompt/blob/main/llms-install.md Executes the code2prompt-mcp main script directly using rye, ensuring the correct virtual environment is used. ```bash rye run python code2prompt_mcp.main ``` -------------------------------- ### Save to File Source: https://github.com/mufeedvh/code2prompt/blob/main/README.md Generates a prompt from a specified project directory and saves it to a file. ```sh code2prompt path/to/project --output-file prompt.txt ``` -------------------------------- ### Use a Custom Handlebars Template Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_templates.mdx Pass the -t or --template flag followed by the path to your Handlebars template file to customize prompt generation. ```bash code2prompt path/to/codebase -t templates/document-the-code.hbs ``` -------------------------------- ### Generate Prompt and Copy to Clipboard Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx This command generates a prompt from a codebase and automatically copies it to the clipboard. ```sh code2prompt path/to/codebase -c ``` -------------------------------- ### Include Specific File Types Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_filters.mdx Use the --include flag with glob patterns to process only files with specific extensions, like .py. ```bash code2prompt test_dir --include="*.py" ``` -------------------------------- ### Default Behavior: Include All Files Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_filters.mdx When no filters are applied, code2prompt includes all files in the specified directory that respect the .gitignore rules. ```bash code2prompt test_dir ``` -------------------------------- ### generate Method Source: https://github.com/mufeedvh/code2prompt/blob/main/crates/code2prompt-python/python-sdk/README.md Parameters and return value for the generate method. ```python generate(template: Optional[str] = None, encoding: Optional[str] = None) -> Dict ``` -------------------------------- ### Display Token Map Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Shows the token map for the generated prompt, useful for understanding tokenization. ```sh code2prompt path/to/codebase --token-map ``` -------------------------------- ### Display Token Count Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Shows the total token count of the generated prompt. ```sh code2prompt path/to/codebase --tokens ``` -------------------------------- ### Save Prompt to Output File Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Saves the generated prompt to a specified output file. ```sh code2prompt path/to/codebase -O output.txt ``` -------------------------------- ### JSON Output Structure Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Illustrates the structure of the JSON output when using the -F JSON flag. ```json { "prompt": "", "directory_name": "codebase", "token_count": 1234, "model_info": "ChatGPT models, text-embedding-ada-002", "files": [] } ``` -------------------------------- ### Redirect Code2Prompt Output to File via SSH Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/ssh.mdx Use the `--output-file` option to save the generated prompt to a file when running Code2Prompt remotely via SSH. This bypasses the need for clipboard access. ```bash ssh user@remote-server "code2prompt path/to/codebase -O output.txt" ``` -------------------------------- ### CodePrompt Constructor Source: https://github.com/mufeedvh/code2prompt/blob/main/crates/code2prompt-python/python-sdk/README.md Parameters for the CodePrompt constructor. ```python CodePrompt( path: str, include_patterns: List[str] = [], exclude_patterns: List[str] = [], include_priority: bool = False, line_numbers: bool = False, relative_paths: bool = False, exclude_from_tree: bool = False, no_codeblock: bool = False, follow_symlinks: bool = False ) ``` -------------------------------- ### Generate Pull Request with Branch Comparison Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Creates a Pull Request description by comparing staged files against specified branches, using a custom template. ```sh code2prompt path/to/codebase --git-diff-branch 'main, development' --git-log-branch 'main, development' -t templates/write-github-pull-request.hbs ``` -------------------------------- ### get_git_log Method Source: https://github.com/mufeedvh/code2prompt/blob/main/crates/code2prompt-python/python-sdk/README.md Signature for the get_git_log method. ```python get_git_log(branch1: str, branch2: str) -> str ``` -------------------------------- ### Set Model Encoding in .c2pconfig Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/configuration.mdx Configures the tokenizer encoding to match the target LLM, e.g., 'o200k' for GPT-4o or 'cl100k' for GPT-4 and Claude. ```toml encoding = "o200k" ``` -------------------------------- ### Clean Up Test Structure Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_filters.mdx Run this command to remove the temporary directory structure created for practicing glob patterns. ```bash rm -rf test_dir ``` -------------------------------- ### Include and Exclude with Priority Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_filters.mdx Combine --include and --exclude flags to define a more specific filtering strategy. Setting --include-priority=true ensures that include patterns are evaluated first. ```bash code2prompt test_dir --include="*.py" --exclude="**/uppercase/*" --include-priority=true ``` -------------------------------- ### Define Exclude Patterns in .c2pconfig Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/configuration.mdx Specifies glob patterns for files and directories to exclude from processing, such as 'node_modules' or build artifacts. ```toml exclude_patterns = [ "**/node_modules/**", "package-lock.json", "dist/**" ] ``` -------------------------------- ### Launch Code2Prompt TUI Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/tui.mdx Append the --tui flag to the code2prompt command to launch the interactive Terminal User Interface. This is the primary method for accessing the TUI. ```bash code2prompt path/to/your/codebase --tui ``` -------------------------------- ### get_git_diff_between_branches Method Source: https://github.com/mufeedvh/code2prompt/blob/main/crates/code2prompt-python/python-sdk/README.md Signature for the get_git_diff_between_branches method. ```python get_git_diff_between_branches(branch1: str, branch2: str) -> str ``` -------------------------------- ### get_git_diff Method Source: https://github.com/mufeedvh/code2prompt/blob/main/crates/code2prompt-python/python-sdk/README.md Signature for the get_git_diff method. ```python get_git_diff() -> str ``` -------------------------------- ### Filter Files with Glob Patterns Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Includes only files matching the specified glob patterns in prompt generation. ```sh code2prompt path/to/codebase --include="*.rs,*.toml" ``` -------------------------------- ### Add Line Numbers to Source Code Blocks Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Includes line numbers in the source code blocks within the generated prompt. ```sh code2prompt path/to/codebase --line-number ``` -------------------------------- ### Exclude Specific Directory (Short Syntax) Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_filters.mdx The -e flag is a shorthand for the --exclude option, allowing for concise exclusion of directories or file types. ```bash code2prompt test_dir -e "uppercase*" ``` -------------------------------- ### Matching all .txt files in any subdirectory Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/explanations/glob_patterns.md This glob pattern matches all .txt files in the current directory and all its subdirectories recursively. ```sh **/*.txt ``` -------------------------------- ### Inject Custom Context with User Variables Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/configuration.mdx Defines custom variables within the '[user_variables]' section to be passed into Handlebars templates. ```toml [user_variables] project_goal = "Refactor the authentication module for better security." ``` -------------------------------- ### Specify Tokenizer for Token Count Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Calculates token count using a specific tokenizer. Supported tokenizers include cl100k, p50k, p50k_edit, and r50k_bas. ```sh code2prompt path/to/codebase --tokens --encoding=p50k ``` -------------------------------- ### Matching files with extensions .jpg or .png Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/explanations/glob_patterns.md This glob pattern matches files ending with either the .jpg or .png extension. ```sh *.{jpg,png} ``` -------------------------------- ### Matching all files with a single digit before the extension Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/explanations/glob_patterns.md This glob pattern matches files where a single character precedes the .txt extension. ```sh file?.txt ``` -------------------------------- ### Matching all text files in a directory Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/explanations/glob_patterns.md This glob pattern matches all files ending with the .txt extension in the current directory. ```sh *.txt ``` -------------------------------- ### Exclude Files/Folders from Tree Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Excludes files and folders from the source tree based on provided patterns. ```sh code2prompt path/to/codebase --exclude="*.npy,*.wav" --exclude-from-tree ``` -------------------------------- ### Exclude Specific File Types Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_filters.mdx Use the --exclude flag with glob patterns to omit files with certain extensions, such as .txt or .md, from processing. ```bash code2prompt test_dir --exclude="*.txt,*.md" ``` -------------------------------- ### Generate Git Commit Message Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Generates a Git commit message for staged files using a specified template. ```sh code2prompt path/to/codebase --diff -t templates/write-git-commit.hbs ``` -------------------------------- ### Exclude Files with Glob Patterns Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Excludes files matching the specified glob patterns from prompt generation. ```sh code2prompt path/to/codebase --exclude="*.txt,*.md" ``` -------------------------------- ### Exclude Specific Directory Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/tutorials/learn_filters.mdx Use the --exclude flag with a glob pattern to exclude an entire directory, such as 'uppercase', from processing. ```bash code2prompt test_dir --exclude "**/uppercase*" ``` -------------------------------- ### Disable Wrapping Code in Markdown Blocks Source: https://github.com/mufeedvh/code2prompt/blob/main/website/src/content/docs/docs/how_to/cli.mdx Prevents the wrapping of code within markdown code blocks in the generated output. ```sh code2prompt path/to/codebase --no-codeblock ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.