Metadata-Version: 2.4
Name: xtrshow
Version: 0.2.0
Summary: The bridge between your local codebase and LLMs.
Author-email: Michael Godfrey <michael@aloecraft.org>
License: Apache-2.0
Project-URL: Homepage, https://github.com/Aloecraft-org/xtrshow
Project-URL: Repository, https://github.com/Aloecraft-org/xtrshow
Keywords: cli,tui,llm,ai,copilot,patch
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: windows-curses; sys_platform == "win32"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: license-file

# xtrshow

<div align="center">

<img src="doc/icon.png" style="height:96px; width:96px;"/>

**The bridge between your local codebase and LLMs.**

[![PyPI Version](https://img.shields.io/pypi/v/xtrshow.svg)](https://pypi.org/project/xtrshow/)
[![Python Versions](https://img.shields.io/pypi/pyversions/xtrshow.svg)](https://pypi.org/project/xtrshow/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

[![CI Status](https://github.com/Aloecraft-org/xtrshow/actions/workflows/main.yml/badge.svg)](https://github.com/Aloecraft-org/xtrshow/actions/workflows/main.yml)
[![Downloads](https://static.pepy.tech/badge/xtrshow)](https://pepy.tech/project/xtrshow)


</div>

`xtrshow` is a lightweight CLI suite designed to optimize the "Context Injection" and "Code Application" loop when working with AI coding assistants (ChatGPT, Claude, Gemini, etc.).

It consists of two tools:
1.  **`xtrshow`**: A TUI to select, compress, and format code context for your LLM.
2.  **`xtrpatch`**: A surgical patching tool to apply LLM-generated changes back to your source code safely.

## Installation

```bash
pip install xtrshow
```

## The Workflow

### 1. Extract Context (`xtrshow`)

Stop manually copying and pasting files.

Run `xtrshow` in your directory. Navigate with arrow keys, select files with `Space`, and hit `Enter` (or use `-o` to save to a file).

```bash
# Open interactive TUI
xtrshow

# Or pipe directly to clipboard (Mac/Linux)
xtrshow | pbcopy 
```

The output is formatted specifically for LLMs, including file paths and line numbers (enabled by default) to assist in referencing specific code blocks.

### 2. Prompt the LLM

Paste the output into your LLM. When asking for changes, include the following instruction to get a compatible patch:

> "Provide changes using the Multi-File Search and Replace Block format."

### 3. Apply Changes (`xtrpatch`)

Save the LLM's response to a file (e.g., `response.txt`) and apply it:

```bash
xtrpatch response.txt
```

`xtrpatch` is whitespace-insensitive and uses fuzzy matching, making it significantly more robust than standard `git apply` when dealing with LLM hallucinations or formatting errors.

---

## Features

### Safety First (Atomic Backups)

`xtrpatch` never destroys code.

* Every time a file is patched, the original is backed up to `.xtrpatch/<file>.orig`.
* Backups are versioned (`file.py.orig`, `file.py.1.orig`, `file.py.2.orig`).
* The patch itself is archived alongside the backup.

### Reverting

Made a mistake? You can unwind changes easily:

```bash
# Revert a specific file to its state before the last patch
xtrpatch --revert src/main.py

# Revert all files modified by a specific patch file
xtrpatch --revert response.txt

```

### File Creation

If the LLM wants to create a new file, `xtrpatch` handles that too.

```text
--- a/src/new_feature.py
<<<<
====
def hello():
    print("New file created!")
>>>>

```

## Patch Format Specification

`xtrpatch` uses a custom, hallucination-resistant format:

```text
--- a/path/to/file.py
<<<< 50
def old_function():
    return False
====
def old_function():
    return True
>>>>

```

* **Header:** `--- a/path/to/file`
* **Start:** `<<<< LINE_HINT` (Line number is optional but recommended for disambiguation)
* **Search Block:** The existing code to find.
* **Divider:** `====`
* **Replace Block:** The new code.
* **End:** `>>>>`

## License

Apache 2.0
