Skip to main content

Prepare multiple source code files for AI prompts, with clipboard support.

Project description

aiprep

Overview

The aiprep script is a versatile tool designed to streamline interactions with AI tools. It allows you to combine multiple files into a single, formatted output that is ready to paste into an AI prompt. The script handles filenames and code block delimiters (backticks) to ensure proper formatting, preserving the context and structure of your files when interacting with AI tools.

A key feature of this script is its ability to reformat markdown-style code blocks. This ensures that the pasted content renders properly within AI tools, avoiding issues like losing the code block formatting or having markdown render incorrectly in responses.

Features

  • Combine multiple files into a single, clipboard-ready output.
  • Format the output with filenames and backticks for code blocks.
  • Recursively collect files matching patterns with --recursive.
  • Remove or re-add backticks to ensure correct rendering in AI prompts and responses.
  • Skip invalid files with a warning, ensuring smooth processing.

Why Modify Codeblocks?

When pasting formatted content into AI tools, the rendered markdown can sometimes interfere with the interaction:

  • If markdown is left unprocessed, code blocks might not render correctly when AI responds.
  • By removing and re-adding code block delimiters (backticks), the script ensures that your input retains the correct format and structure. This allows the AI to display and interpret code blocks correctly without inadvertently rendering markdown in its output.

The --deblock and --reblock options allow you to address this issue:

  • -d, --deblock: Replace triple backticks with double backticks (```) to prevent markdown rendering in AI outputs.
  • -r, --reblock: Restore triple backticks after processing to re-enable proper code block formatting.

Installation

Install from PyPI

pip install aiprep

System dependencies

For clipboard functionality, ensure you have xclip installed (Linux):

sudo apt-get install xclip

Note: macOS and Windows clipboard support works out of the box via pyperclip dependency.

Usage

Run the script with the desired functionality using the following options:

Options

  • -c, --combine: Combine multiple files into a single clipboard-friendly format with filenames and codeblocks.
  • -d, --deblock: Replace triple backticks with double backticks (```) in the specified files.
  • -r, --reblock: Replace double backticks (```) with triple backticks in the specified files.
  • --recursive: Recursively include files matching the given glob patterns.
  • -h, --help: Show usage instructions.

Examples

Combine Files into Clipboard

aiprep -c file1.py file2.py file3.py

Recursively Combine All .py Files

aiprep -c --recursive "*.py"

This combines the content of all Python files in the current directory and subdirectories, formats them with filenames and triple backticks, and copies the result to your clipboard.

Modify Codeblocks

Replace triple backticks with double backticks:

aiprep -d file1.md file2.md

Restore double backticks to triple backticks:

aiprep -r file1.md file2.md

Help

aiprep -h

Expected Output (Copied to Clipboard)

For -c, the combined output will have the following format:

file1.py:

<contents of file1.py>

file2.py:

<contents of file2.py>

file3.py:

<contents of file3.py>

Notes

  • Ensure all specified files exist. Non-existent or invalid file paths will be skipped with a warning.
  • Use the --deblock and --reblock options carefully to handle code block rendering issues when interacting with AI tools.
  • --recursive works with glob patterns (e.g., "*.py") to collect matching files in all directories.

Purpose

This script is designed to optimize workflows for loading multiple source code files into AI tools. By preparing files in a clipboard-ready format and ensuring proper rendering of code blocks, it eliminates common issues with markdown formatting in AI responses, allowing you to focus on content rather than formatting.

License

Feel free to use, modify, and distribute this script as needed. No restrictions apply.

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

aiprep-1.0.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiprep-1.0.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file aiprep-1.0.2.tar.gz.

File metadata

  • Download URL: aiprep-1.0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aiprep-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1da9eb04e1027d61f14360bdcc51b66a5e7dfb08106cd18ebb0bc4be1fdcf96e
MD5 efc83661f04a39237839f9d586eb5aa7
BLAKE2b-256 8385bbc969764be534d5b20cf25f556f74ab6ef1f022c0a6d7261d04ddbcc10b

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiprep-1.0.2.tar.gz:

Publisher: pypi-publish.yml on jeremiah-k/aiprep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiprep-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: aiprep-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aiprep-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 09f95d3751431e09de327d8203b43f98c5d3f4676bf5d4bb19fbc16946fdfd57
MD5 6fd8b9ec3b88baf53d3c500dcd0b45a1
BLAKE2b-256 dc86294c81b1a94272afa64dcd9f2ace76a72aef2d743af0374cf47656f726b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiprep-1.0.2-py3-none-any.whl:

Publisher: pypi-publish.yml on jeremiah-k/aiprep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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