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.3.tar.gz (5.9 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.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiprep-1.0.3.tar.gz
  • Upload date:
  • Size: 5.9 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.3.tar.gz
Algorithm Hash digest
SHA256 baffddb0ed0b30e1be7fa2c25d3978574c2dff0ede4e89707f694b5197344b9d
MD5 cef793bfac97597e930f1c1b904956e6
BLAKE2b-256 90f123b78314975d54dcc282da5b5b5997d2424fc1eab92653413c7d9aa094cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiprep-1.0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: aiprep-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5de1341804f0e050db587c88d1532a81d8d9b9d0632aa7e5666cfc238b2313c2
MD5 84faf3ee3c5d6edecbeaeaaa76ea1929
BLAKE2b-256 9a93894a3ff11559ad4ce6b1526732aba0db458c50a5f396d2333acfd32298d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiprep-1.0.3-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