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.8.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.8.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rctx-0.8.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.8.0.tar.gz
Algorithm Hash digest
SHA256 bcf4f17792ef082e7f24de0874c60b4ea6726ed179c496678fb8a7ede968f434
MD5 a40254ddcf47bfe5ca27d938e89064e1
BLAKE2b-256 1e3fe38d395954fa286b16d1415183c09d76e4063cdf1bdeb37c6ca063b212e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rctx-0.8.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.8.0-py3-none-any.whl.

File metadata

  • Download URL: rctx-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 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.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc3d3a78d2723d7481277c1c38dbf0413494acaf78890af862caf00a8f82d53d
MD5 3ef0eb0f75e9107beabca4e0eb8cfb30
BLAKE2b-256 914b82ac50bc76642674710e8e1edea9b694c0f59660a67e2643acb47b82e65c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rctx-0.8.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