Metadata-Version: 2.4
Name: logicedit
Version: 0.1.7
Summary: Extensible JSONL task editing library for code and formula inputs.
License: Proprietary
Keywords: csp,jsonl,logic-programs,formula-editing,data-augmentation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: func-timeout
Requires-Dist: python-constraint
Requires-Dist: z3-solver
Provides-Extra: dev
Requires-Dist: build>=1.2.2; extra == "dev"
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: twine>=5.1.1; extra == "dev"
Provides-Extra: release
Requires-Dist: build>=1.2.2; extra == "release"
Requires-Dist: twine>=5.1.1; extra == "release"

# logicedit

`logicedit` processes JSON or JSONL task records, applies controlled line edits, runs edited variants through registered tools, evaluates tool outputs, and writes successful variants back as JSONL.

## Features

- Dataclass-based record models with `extra_options` for forward-compatible schema changes.
- `single_edit` mode for independent edits from the original input.
- `cumulative_edit` mode for greedy accepted edits applied on top of prior edits.
- Tool registry with in-memory tools, Python-file adapters, and a built-in Z3 solver adapter.
- Explicit required tool selection via `tool`.
- Configurable label comparison strategies for label-preserving and label-variation workflows.
- Minimal examples with a mock tool and mock editor.

## Install

```bash
python3 -m pip install -e .[dev]
```

This installs the library dependencies, including `z3-solver` for the built-in Z3 backend.

## TestPyPI Release Flow

Build and upload to TestPyPI first:

```bash
make publish-testpypi
```

Install the published package from TestPyPI:

```bash
make install-testpypi
```

If you prefer the raw commands:

```bash
python3 -m build
python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
python3 -m pip install \
  --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ \
  logicedit
```

## Run

```bash
python3 -m logicedit.cli \
  --input /path/to/tasks.jsonl \
  --output /path/to/successes.jsonl \
  --tool csp_solver.py \
  --edit-mode single_edit \
  --number-of-edits 3 \
  --label-variation \
  --single-edit-ids 0,2,4
```

`number_of_edits` accepts either a positive integer or `"all"`.

- In `single_edit` mode, the library evaluates independent edits from the original input and saves every successful independent edit. `number_of_edits` is ignored in this mode. Use `--single-edit-ids` or `extra_options.selected_edit_ids` to restrict which editable units are considered.
- In `cumulative_edit` mode, `number_of_edits` controls how many accepted cumulative edits are saved. `"all"` means the runner walks the editable statements from first to last, tries the available operator edits for each statement against the `label_variation` condition, applies the first acceptable edit, and then moves to the next statement.
- `--tool` is mandatory on the CLI. The library no longer defaults silently to `csp_solver`.
- `--no-label-variation` is the default behavior: only save records whose tool output matches the original label.
- `--label-variation` inverts that rule: only save records whose tool output differs from the original label.

Available tool families:

- `csp_solver.py` or another Python tool file: uses the Python-file adapter. Point `extra_options.tool_search_paths` at the folder containing it. The adapter can call plain functions such as `run(input_text)` and also supports the `CSP_Program` class shape found in the source files.
- `z3_solver`: uses the built-in vendored Z3 backend and Z3-specific operator edits in the `# Constraints` section: `AND -> OR`, `XOR -> OR`, `OR -> XOR`, and `NOT` removal.

The library only searches tool paths you provide or the input file directory added by the CLI.

Example Z3 run:

```bash
python3 -m logicedit.cli \
  --input /path/to/z3_tasks.jsonl \
  --output /path/to/z3_successes.jsonl \
  --tool z3_solver \
  --edit-mode cumulative_edit \
  --number-of-edits all
```

## Example Record

```json
{
  "id": "logical_deduction_0",
  "tool": "csp_solver.py",
  "input_type": "code",
  "edit_mode": "single_edit",
  "number_of_edits": 2,
  "label_variation": false,
  "expected_answer": "D",
  "logic_program": "Domain:\n...\nConstraints:\nThe blue book is to the right of the yellow book. ::: blue_book > yellow_book\n...\n\nQuery:\n..."
}
```

Example Z3 record:

```json
{
  "id": "ar_lsat_0",
  "tool": "z3_solver",
  "input_type": "code",
  "edit_mode": "single_edit",
  "number_of_edits": 2,
  "label_variation": true,
  "expected_answer": "B",
  "logic_program": "# Declarations\n...\n\n# Constraints\nrule ::: A AND B\n...\n\n# Options\nQuestion ::: ...\n..."
}
```

## Test

```bash
python3 -m pytest
```
