Skip to main content

A Python tool that consolidates code from a repository into a unified format for AI-assisted analysis and manipulation.

Project description

Here’s the updated README file to match the provided code and setup configuration:


code2claude: Code Consolidator

A Python tool that consolidates code from a repository into a unified format for AI-assisted analysis and manipulation.

Code Consolidator is a Python tool that traverses a code repository, extracts code from specified files, and consolidates it into a unified format. The consolidated code is optimized for AI-assisted analysis and manipulation, enabling seamless collaboration between humans and AI in understanding and working with the codebase.

Features

  • Traverse a repository: Identifies relevant code files based on specified file extensions.
  • Code extraction: Extracts code from each file without any preprocessing.
  • Code consolidation: Consolidates the extracted code into a single, unified format (XML or raw).
  • Metadata inclusion: Includes file paths for context.
  • Skip options: Optionally skips test files and specified folders.
  • Selective inclusion: Filters files containing a specified string in the file path.

Installation

From PyPI:

pip install code2claude

From source:

  1. Clone the repository:

    git clone https://github.com/ad3002/code2claude
    
  2. Navigate to the project directory:

    cd code2claude
    
  3. Install the required dependencies:

    pip install -r requirements.txt
    

Usage

python code2claude.py -r /path/to/repo -o output.xml -f xml --skiptests --skipfolders folder1,folder2 --contain keyword -e .py .js
  • -r/--repo_path: Path to the code repository (required).
  • -o/--output_file: Path to the output file (default: consolidated_code.code).
  • -f/--format: Output format, either xml or raw (default: xml).
  • --skiptests: Skip test files that contain "test" in their name (default: False).
  • -s/--skipfolders: Comma-separated list of folders to skip (default: False).
  • --contain: Include files containing this string in the file path.
  • -e/--extensions: Space-separated list of file extensions to include (default: .py).

Example Command

python code2claude.py -r /path/to/repo -o consolidated_code.xml -f xml --skiptests True -s folder_to_skip --contain utils -e .py .java

Output Formats

XML Format:

<file>
   <path>/path/to/file.py</path>
   <content>
      # Python code here
   </content>
</file>

...

Raw Format:

###### /path/to/file.py ###
# Python code here
###### end of file /path/to/file.py ###

Possbile prompt for the AI system

<prompt>
   <consolidated_code>
      <instruction>Claude, please, see the attached file</instruction>
   </consolidated_code>

   <question>
   Your question or request goes here. For example:
   - Can you identify any potential performance issues in the code?
   - How can I refactor the code to improve readability and maintainability?
   - Are there any security vulnerabilities or best practices violations in the code?
   </question>
</prompt>

Statistics

During code consolidation, the tool also gathers and displays statistics about the consolidated files. This includes:

  • Number of Files: The total number of files that were consolidated.
  • Number of Lines: The number of lines in each file and the total number of lines across all files.
  • Number of Characters: The total number of characters in the consolidated code.

Example of Statistics Output

After running the command, the following information will be displayed:

Consolidated 10 files:
    /path/to/file1.py: 120 lines
    /path/to/file2.py: 98 lines
    ...
    /path/to/file10.py: 150 lines
Total lines: 1000
Total chars: 25000
  • Consolidated X files: Indicates how many files were consolidated.
  • [File path]: Y lines: Shows the file path and the number of lines in that file.
  • Total lines: The total number of lines across all files.
  • Total chars: The total number of characters in the consolidated code.

This statistics section provides insights into the size and structure of your project, which can be helpful for further code analysis and optimization.

How to improve the code before running the consolidator

Remember, the specific details and format of the consolidated code may vary based on your project's needs and the programming language being used. The key is to provide a clear, organized, and well-documented representation of your codebase that facilitates effective analysis and collaboration between humans and AI.

To process the consolidated code as a whole and provide effective analysis and manipulation, there are a few additional things that would be helpful:

  1. Code Structure and Organization:

    • Clearly indicate the boundaries between different code files or modules within the consolidated code. This can be done using comments, delimiters, or specific markers.
    • Include information about the file paths or module names to provide context about the code's organization.
    • Maintain a consistent indentation level throughout the consolidated code to ensure readability.
  2. Dependency and Import Statements:

    • If the code relies on external libraries or modules, include the necessary import statements at the beginning of the consolidated code.
    • If there are inter-dependencies between the code files, ensure that the order of the consolidated code reflects the proper dependency hierarchy.
  3. Documentation and Comments:

    • Include relevant comments and documentation within the code to provide explanations and context.
    • Use docstrings to describe the purpose, parameters, and return values of functions and classes.
    • Provide high-level comments to explain the overall structure and flow of the code.
  4. Test Cases and Examples:

    • If available, include test cases or example usage of the code within the consolidated format.
    • This helps in understanding how the code is intended to be used and what expected outcomes should be.
  5. Configuration and Environment:

    • If the code relies on specific configuration files or environment variables, include them or provide instructions on how to set them up.
    • Specify any required dependencies or libraries that need to be installed for the code to run successfully.
  6. Error Handling and Logging:

    • Include error handling and logging statements within the code to aid in debugging and understanding potential issues.
    • Provide information on how to interpret and resolve common errors or exceptions that may occur.
  7. Code Analysis Preferences:

    • If you have specific preferences or requirements for code analysis, such as focusing on certain aspects like performance, security, or style, mention them along with the consolidated code.
    • This helps me tailor the analysis and provide targeted insights based on your priorities.

By incorporating these additional elements, you can provide a more comprehensive and context-rich representation of your codebase. It enables me to understand the code's structure, dependencies, and intended usage more effectively, leading to more accurate and valuable analysis and manipulation.

Contributing

Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code2claude-0.3.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

code2claude-0.3.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file code2claude-0.3.0.tar.gz.

File metadata

  • Download URL: code2claude-0.3.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.19

File hashes

Hashes for code2claude-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ae6d7a48b0808aedbb141ba6212333aa8aa5d96103bfec36b8dccc038a1f5e3e
MD5 4c1e3c5e13d51bb5a86f14e1df0aabeb
BLAKE2b-256 9dea57f96cda244a04e067a0d90d101d1ae99bcd91ab1e780299b328969b8756

See more details on using hashes here.

File details

Details for the file code2claude-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: code2claude-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.19

File hashes

Hashes for code2claude-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ae72454ba552f61bd3f1a0906450cab40c866bb65bc89389480c539da463ef1
MD5 b570f74be0c83a2ee61b11956572a3a4
BLAKE2b-256 9cc0fa86917eccc1938a2e22f951e9f991a815d9179b56570b27e029f5cc2359

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page