Metadata-Version: 2.4
Name: delta-reduce
Version: 0.1.1
Summary: A delta-reduction CLI tool for minimising files
Requires-Python: >=3.12
Description-Content-Type: text/markdown

# delta-reduce

A delta-reduction tool for minimising a file to the smallest version that still satisfies a given test. Similar in spirit to [CReduce](https://github.com/csmith-project/creduce), but simpler: it only deletes lines, not arbitrary sub-expressions or tokens.

## How it works

The tool repeatedly tries to delete chunks of lines from the input file. It scans from the bottom of the file upward, testing each deletion. The chunk size starts at the full file size and is reduced as the algorithm makes passes over the file. After 4 successful deletions the chunk size grows again, speeding up reduction when progress is easy. This repeats until a full pass removes nothing.

Multiple passes alternate an offset of 0 and 1 to avoid missing deletions that straddle chunk boundaries.

## Installation

```sh
pip install delta-reduce
```

## Usage

```sh
delta-reduce --test <script> --input <file> [-n <threads>]
```

| Option | Description |
|---|---|
| `--test SCRIPT` | Script that exits 0 if the candidate file is acceptable, non-zero otherwise. |
| `--input FILE` | File to reduce. Overwritten in place as progress is made. |
| `-n N` | Number of parallel threads (default: 4). |
| `-v`, `--verbose` | Print each tested deletion with its line range, chunk size, duration, and result. |

The original file is backed up to `<file>.orig` on the first run. Subsequent runs will not overwrite it.

## Test script interface

The script is invoked with its working directory set to a temporary directory containing the candidate file under the original filename. Any external resources must be referenced by absolute path.

```sh
#!/bin/sh
# Example: keep reducing as long as the file still triggers a compiler error
gcc -c input.c 2>&1 | grep -q 'use of undeclared identifier'
```

## Development

```sh
uv venv && uv pip install -e .
pytest
```
