Skip to main content

A tool to stringify code using rsync and manage presets, forked from rstring.

Project description

Rctx: Rsync-Powered Code Stringification (Fork of Rstring)

PyPI version License: MIT

Rctx is a developer tool that uses Rsync to efficiently gather and stringify code from your projects. It's designed to streamline the process of preparing code context for AI programming assistants, making it easy to get intelligent insights about your codebase. This is a fork of the original rstring project.

When you run rctx, it copies the selected file contents to your clipboard, prepended with a tree view of the matched files. The output is formatted using Markdown code blocks for easy pasting into LLMs or documents.

Rctx demo

Quickly prompt an LLM with your whole project!

Installation

Rctx requires Python 3.8+. We recommend using pipx for installation, as it installs Rctx in an isolated environment, preventing conflicts with other packages.

Using pipx (recommended)

  1. Install pipx if you haven't already. Follow the official pipx installation guide for your operating system.

  2. Install Rctx:

    pipx install rctx
    

Using pip

If you prefer to use pip, you can install Rctx with:

pip install rctx

Updating Rctx

To update Rctx to the latest version:

With pipx:

pipx upgrade rctx

With pip:

pip install --upgrade rctx

For more detailed information about pipx and its usage, refer to the pipx documentation.

Quick Start

Basic usage (copies tree + content to clipboard):

rctx  # Use the default preset

Specify includes/excludes (copies tree + content to clipboard):

rctx --include=*/ --include=*.py --exclude=* # traverse all dirs, include .py files, exclude everything else

Get help:

rctx --help

Use a specific preset:

rctx --preset my_preset

Get a summary view (includes detailed summary, tree, and content, copied to clipboard):

rctx --summary

Advanced Usage

Custom Presets

Create a new preset:

rctx --save-preset python --include=*/ --include=*.py --exclude=*  # save it
rctx --preset python  # use it

File Preview

Limit output to first N lines of each file:

rctx --preview-length=10

Gitignore Integration

By default, Rctx automatically excludes .gitignore patterns. To ignore .gitignore:

rctx --no-gitignore

Interactive mode:

Enter interactive mode to continuously preview and select matched files:

rctx -i

Understanding Rctx

  1. Under the Hood: Rctx efficiently selects files based on filters by running rsync --archive --itemize-changes --dry-run --list-only <your filters>. This means you can use Rsync's powerful include/exclude patterns to customize file selection.

  2. Preset System: The default configuration file is at ~/.rctx.yaml. The 'common' preset is used by default and includes sensible exclusions for most projects.

  3. Output Format (copied to clipboard): A tree view of the selected files is prepended, followed by:

    --- path/to/file1.py ---
    ```python
    [File contents]
    

    --- path/to/file2.js ---

    [File contents]
    
    
    
  4. Binary Files: Content of binary files is represented as a hexdump preview within a plain code block.

  5. Clipboard Integration: Output (tree + content) is automatically copied to clipboard unless disabled with --no-clipboard. A colored tree is printed to the console.

  6. Git Integration: By default, Rctx respects .gitignore patterns. Use --no-gitignore to ignore them.

Pro Tips

  1. Explore the default preset: Check ~/.rctx.yaml to see how the 'common' preset works.

  2. Refer to Rsync documentation: Rctx uses Rsync for file selection. Refer to the Filter Rules section of the rsync man page to understand how include/exclude patterns work.

  3. Customize for your project: Create a project-specific preset for quick context gathering.

  4. Use with AI tools: Rctx is great for preparing code context for AI programming assistants, thanks to its Markdown output.

  5. Large projects may produce substantial output: Use --preview-length or specific patterns for better manageability.

Development

If you'd like to contribute to Rctx or set it up for local development, follow these steps:

  1. Clone the repository:

    git clone https://github.com/your-username/rctx.git # Update with your fork's URL
    cd rctx
    
  2. Create a virtual environment and activate it:

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
    
  3. Install the development dependencies:

    pip install -r requirements-dev.txt
    
  4. Install the package in editable mode:

    pip install -e .
    

    This will make the rctx command available in your environment, linked to your local source code.

  5. Run the tests:

    pytest
    

Running Rctx Locally (after pip install -e .)

Once installed in editable mode, you can run rctx directly:

rctx --help
rctx --include=*.md

Alternatively, without editable install, or to be explicit:

  1. Make sure you're in the project root directory and your virtual environment is activated.
  2. Run Rctx using the Python interpreter:
    python -m rctx [options]
    
    For example:
    python -m rctx --include=*/ --include=*.py --exclude=*
    

Contributing

We welcome contributions to Rctx! Here are some guidelines:

  1. Fork the repository and create your branch from main.
  2. If you've added code that should be tested, add tests.
  3. Ensure the test suite passes.
  4. Make sure your code lints.
  5. Issue a pull request!

For more details on contributing, please see our CONTRIBUTING.md file (if one exists, or create one).

Support and Contributing

  • Issues and feature requests: GitHub Issues
  • Contributions: Pull requests are welcome!

License

Rctx is released under the MIT License. See the LICENSE file for details.

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

rctx-0.9.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

rctx-0.9.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file rctx-0.9.0.tar.gz.

File metadata

  • Download URL: rctx-0.9.0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for rctx-0.9.0.tar.gz
Algorithm Hash digest
SHA256 bf16c21e248381ae8d8cb43ddde08e640581b33a95207cd4b07a5f9e7436f9d5
MD5 c029f7918f14b521b2fbd7d5bdf76ed8
BLAKE2b-256 0a19f7eaa2b647e3e779e2745adca1c7c08703b9e9bd044e5c211d1295771b29

See more details on using hashes here.

Provenance

The following attestation bundles were made for rctx-0.9.0.tar.gz:

Publisher: package.yml on noreff/rctx

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

File details

Details for the file rctx-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: rctx-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for rctx-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0663c6a856215be53f0ef56066d921f5d3aa2f6f581d0e4a824304dd42febe2
MD5 95d334767720aa1e9a897bb3d88cd97c
BLAKE2b-256 23599ded665f04c36c4db9e6bc2c6d29c6254d49c50cdde3737160d154fe4b87

See more details on using hashes here.

Provenance

The following attestation bundles were made for rctx-0.9.0-py3-none-any.whl:

Publisher: package.yml on noreff/rctx

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