Skip to content

workflowsdiy/code2prompt-gui

Repository files navigation

Code2Prompt GUI Helper Screenshot

Code2Prompt GUI Helper

A Python desktop application built with tkinter to provide a graphical user interface for interacting with the code2prompt CLI tool. This helper makes it easier to select files and folders from a project and configure various code2prompt options before generating a prompt.

Features

  • Project Directory Selection: Easily browse and select your target project folder.
  • Interactive File/Folder Tree:
    • Displays a tree view of your project's structure (files and directories).
    • Shows file sizes.
    • Allows users to visually select/deselect items.
    • Clicking a folder toggles the selection state for the folder and all its children.
    • Buttons for "Select All" and "Deselect All".
  • Initial Filtering: Automatically excludes common large/unwanted directories (e.g., node_modules, .git, venv) from the initial scan for better performance.
  • code2prompt Option Configuration:
    • Specify an output file for the generated prompt (otherwise copies to clipboard).
    • Use a custom Handlebars template file.
    • Option to display token count, with selection of tokenizer encoding (cl100k, p50k, etc.).
    • Toggle line numbers in code blocks.
    • Toggle wrapping code in markdown code blocks.
    • Add additional custom glob patterns for exclusion.
  • Command Generation & Execution:
    • Constructs the code2prompt command based on your selections and options.
    • Displays the generated command for review.
    • Executes the code2prompt CLI tool as a subprocess.
  • Output Display: Shows stdout and stderr from the code2prompt execution directly in the GUI.

Prerequisites

  1. Python 3: (Python 3.9+ recommended, as tkinter is standard).
  2. code2prompt CLI Tool: Must be installed and accessible in your system's PATH.
  3. tkinter: Usually included with standard Python distributions. If you encounter an import error for tkinter or _tkinter (unlikely on most desktop setups), you may need to install it for your Python distribution (e.g., sudo apt-get install python3-tk on Debian/Ubuntu).

Setup

  1. Save the Script: Save the provided Python code as code2prompt_tkinter_helper.py in a convenient location on your system.
  2. No External Python Libraries (beyond standard library for Tkinter): This script is designed to use Python's built-in tkinter module for the GUI and standard modules like os, pathlib, subprocess, and argparse (though argparse is used in the script but the GUI version doesn't take CLI args itself anymore for the project path).

How to Use

  1. Run the Script: Open your terminal or command prompt, navigate to the directory where you saved code2prompt_tkinter_helper.py, and run:

    python code2prompt_tkinter_helper.py

    The GUI window will appear.

  2. Select Project Folder:

    • Click the "Browse..." button next to "Project Folder".
    • Navigate to and select the root directory of the codebase you want to process.
    • The path will appear in the input field.
  3. Scan Project:

    • Once a path is selected, the "Scan Project" button will become enabled. Click it.
    • The script will scan the directory (respecting initial hardcoded excludes like node_modules, venv, .git, etc.) and populate the "Files & Folders" tree view.
  4. Select/Deselect Files and Folders:

    • The tree view displays your project structure.
      • [X] or [ ] indicates selection status.
      • [D] for directories, [F] for files.
      • File sizes are shown.
    • To toggle selection: Single-click on any item (file or folder) in the tree.
      • If you click a folder, that folder and all its children (files and subfolders) will have their selection status toggled.
    • "Select All" Button: Marks all scanned items (that passed initial filtering) for inclusion.
    • "Deselect All" Button: Marks all scanned items for exclusion.
    • The visual [X] / [ ] prefix in the tree will update to reflect the current selection status.
  5. Configure code2prompt Options:

    • On the right-hand side, fill in the desired options for the code2prompt command:
      • Output File: If you want the prompt saved to a file, enter the filename (e.g., my_project_prompt.md). Leave blank to copy to clipboard (default code2prompt behavior).
      • Template File: Path to a custom .hbs template if you're using one.
      • Display Token Count: Check this to enable token counting.
      • Tokenizer Encoding: If token count is enabled, select your desired encoding (defaults to cl100k).
      • Add Line Numbers: Check to add line numbers to code blocks.
      • No Markdown Codeblock: Check to disable wrapping code in markdown ``` fences.
      • Additional Excludes: Add any further comma-separated glob patterns for exclusion (e.g., *.test.js,docs/**/*.png).
  6. Generate & Run Command:

    • Once you are satisfied with your file/folder selections and options, click the "Generate & Run code2prompt" button.
    • The application will:
      • Determine the necessary --exclude arguments for code2prompt based on your deselections in the tree.
      • Construct the full code2prompt command.
      • Display this command in the "code2prompt Output" area.
      • Execute the command.
  7. View Output:

    • The STDOUT and STDERR from the code2prompt execution will be displayed in the "code2prompt Output" text area.
    • A success or failure message will also be shown. If an output file was specified and the command was successful, it will confirm the file was written.

Notes

  • Initial Excludes: The script has a hardcoded list of common directories/files to exclude from the initial scan (e.g., node_modules, .git). You can modify this list directly in the initial_excludes_str variable within the script if needed.
  • Exclusion Logic: The helper primarily works by building a list of --exclude arguments for code2prompt. If you deselect a folder, that folder's relative path is added to the exclude list. code2prompt then handles recursively excluding its contents.
  • Performance: For very large projects, the initial scan and tree population might take a few moments. The tree interaction itself should be responsive.
  • code2prompt Path: This helper assumes code2prompt is installed and available in your system's PATH. If not, subprocess will fail to find it.

This helper tool aims to streamline the process of generating targeted prompts from large codebases using the powerful code2prompt CLI.

About

code2prompt-gui

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages