# Changelog

All notable changes to this project are documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

---

## [1.1.0] — 2026-08-07

Real-world large-Python feedback: better failures, correct indent unit, dry-run, syntax UX.

### Added

- **Match-failure diagnostics** (`diagnoseMatchFailure`): when `oldText` is not found,
  reports closest candidate file lines, first differing line (expected vs actual),
  whitespace-only vs content drift, and re-read hints. Caps size for context.
- **`dryRun: true`** tool parameter: match, diff, and Python syntax check without
  writing or creating a backup.
- **Trailing blank / newline retry**: if match fails, retry after trimming trailing
  blank lines from `oldText` (common on large multi-line blocks). Still fail-closed
  on structure/content mismatch.
- **Python syntax error remapping**: temp `py_compile` paths rewritten to the real
  file path; exposes proposed-file line numbers; attributes errors to the edit that
  introduced the line and shows a local `newText` snippet when possible.
- **`formatIndentHint`**, **`detectSpaceIndentUnit`**, **`remapPythonCompileError`**,
  **`formatSyntaxErrorAttribution`**, **`trimTrailingBlankLines`** (exported helpers).
- **`appliedRanges`** on `applyEdits` result for syntax attribution.

### Fixed

- **Indent unit detection**: no longer reports “8 spaces” for 4-space files when
  nested bodies dominate. Uses GCD of observed indent levels (unit), not mode of
  absolute depth. Success/error messages say e.g. `4-space indent unit (levels seen: 4, 8, 12)`.
- Relative-indent prefilter by first non-blank content line (faster on large files;
  same match results).

### Changed

- Prompt guidelines: dry-run, successive-edit re-read, large-block accuracy, use diagnostics.
- Session banner: `editomatic v1.1.0`.

### Upgrade

```bash
pi install npm:edit-o-matic
```

---

## [1.0.8] — 2026-08-08

### Changed

- **Myers O(ND) line diff** replaces the old index-aligned `generateSimpleDiff`.
  Insertions/deletions that change line counts no longer produce interleaved
  garbage in the UI. Public name `generateSimpleDiff` is unchanged for
  compatibility; also exported as `generateMyersDiff`, plus `myersLineDiff`
  and `formatDiffEdits` for testing/reuse.
- Diff display still uses Pi's `renderDiff` format (`-N` / `+N` / context) with
  configurable context lines and ` ...` elision between distant hunks.

### Upgrade

```bash
pi install npm:edit-o-matic
```

---

## [1.0.7] — 2026-08-08

### Added

- **`formatFileIndentContext`** — richer prompt injection: indent style, min base
  indent, short line examples, and a Python “indentation is syntax” reminder.
- **`countLines`** helper (exported) for consistent line accounting.
- Multi-edit regression tests (descending apply + mixed relative-indent with
  line-count changes).

### Changed

- **Multi-edit apply order** is bottom-to-top by original position so earlier
  regions are not displaced by later replacements. Exact matches use Phase-1
  byte indices; non-exact regions re-validate structure and re-locate via
  relative-indent fingerprint when needed.
- Matching details in summaries are tagged with edit index (`[0] …`).
- Tool prompt guidelines emphasize Python indent-as-syntax and recovery via re-read.
- README polished into a single clean production doc for the integrity suite.
- Session banner: `editomatic v1.0.7 loaded — production integrity suite`.

### Upgrade

```bash
pi install npm:edit-o-matic
```

This completes the planned integrity workstream (matching guards, write-path
safety, multi-edit hardening, prompt context). Further changes will be normal
maintenance.

---

## [1.0.6] — 2026-08-08

### Added

- **Sidecar backup** before overwrite: writes `*.editomatic-bak` with the previous
  file contents. Success summaries include a restore command
  (`cp path.editomatic-bak path`).
- **Atomic write**: new content goes to `*.editomatic-tmp`, then rename over the
  target (same-filesystem atomic replace).
- **Python syntax gate** (best-effort): for `.py` / `.pyw` / `.pyi`, if `python3`
  or `python` is on `PATH`, runs `python -m py_compile` on the proposed content
  **before** writing. Syntax errors abort the write; the original file is left
  unchanged and the error includes the compiler message + a diff when available.
- Env overrides:
  - `EDITOMATIC_NO_BACKUP=1` — skip sidecar backup
  - `EDITOMATIC_SKIP_PYTHON_CHECK=1` — skip py_compile
- Unit tests for write-safety helpers (`test/write-safety.test.ts`).

### Changed

- Tool description and session banner updated for write-safety (v1.0.6).
- Prompt guidelines remind models to preserve **relative** indentation in multi-line `oldText`.

### Upgrade

```bash
pi install npm:edit-o-matic
```

If an edit ever looks wrong, restore from the backup next to the file:

```bash
cp path/to/file.py.editomatic-bak path/to/file.py
```

---

## [1.0.5] — 2026-08-07

### Integrity notice (please upgrade)

**Versions before 1.0.5 could silently corrupt indent-sensitive files** (notably Python)
when progressive fallback matching stripped leading whitespace, matched the wrong
region, and re-applied a flat indent shift. Multi-edit calls could cascade that
damage. Exact and simple fuzzy matches were usually fine; the risk was highest when
the model’s `oldText` had wrong absolute indentation and the tool fell through to
aggressive strategies.

**If you used editomatic on Python (or YAML / other indent-significant) files
before 1.0.5:** review recent edits, restore from git or backups if anything looks
wrong, and upgrade immediately.

This release prioritizes **fail closed** over silent corruption: the tool may
reject more borderline edits so it never applies a structure-destroying match.

### Fixed

- **Relative-indent matching** replaces pure “strip all leading whitespace”
  fallbacks. Absolute indent may still drift; **relative structure between lines
  must match**. Wrong-block / flattened-structure matches are rejected.
- **`reindentReplacement` base indent** now uses the **minimum** non-blank visual
  indent of the matched region (not the first non-zero indent line). Nested
  methods under classes no longer get shifted incorrectly when the model sends
  de-indented absolute levels with correct relative shape.
- **Fuzzy byte-offset fallback removed.** Normalized offsets/lengths are never
  applied to original content (that path could eat adjacent characters). Fuzzy
  matches always require a safe line range; missing range throws instead of writing.
- **Empty `newText`** is true deletion through reindent (no phantom whitespace line).
- **Ambiguous relative blocks** (e.g. identical methods in two classes) throw with
  a clear error instead of replacing the first occurrence.

### Added

- `relativeIndentFingerprint`, `minNonBlankVisualIndent`, `findRelativeIndentMatches`
  for structure-preserving match validation.
- **`EDITOMATIC_STRICT=1`** (or `true` / `yes`): emergency lockdown — only exact
  and fuzzy matching; relative-indent fallback disabled.
- Python-focused **corruption regression tests** (nested methods, wrong-class
  ambiguity, multi-edit cascade, structure-destroying strip refused).
- This changelog and an upgrade callout in the README.

### Changed

- Matching cascade is now: **exact → fuzzy → relative-indent** (no combined /
  line-by-line strip cascade that ignored structure).
- Session load notification includes the package version and points at this
  changelog when a hotfix notice is active.

### Upgrade

```bash
# Pi global package
pi install npm:edit-o-matic

# Or project-local
pi install npm:edit-o-matic -l
```

Optional lockdown while validating:

```bash
export EDITOMATIC_STRICT=1
```

---

## [1.0.4] — 2026-08-07

### Changed

- Version bump and package metadata for npm / Pi package catalog.

### Notes

- Included whitespace/indentation matching improvements from the 1.0.x line
  (tab/space convention preservation, ambiguity detection, sequential edit search
  on original content, prompt indentation context injection).
- Did **not** include the fail-closed relative-indent guards shipped in **1.0.5**.
  Users on 1.0.4 should upgrade.

---

## [1.0.0] — 2026-07-31

### Added

- Initial public release of `editomatic` for Pi.
- Progressive fallback matching for local/quantized LLM edit drift.
- Tool registration as `editomatic`, BOM/line-ending preservation, basic tests.

---

[1.0.8]: https://github.com/bighornwoods/edit-o-matic/compare/v1.0.7...v1.0.8
[1.0.7]: https://github.com/bighornwoods/edit-o-matic/compare/v1.0.6...v1.0.7
[1.0.6]: https://github.com/bighornwoods/edit-o-matic/compare/v1.0.5...v1.0.6
[1.0.5]: https://github.com/bighornwoods/edit-o-matic/compare/v1.0.4...v1.0.5
[1.0.4]: https://github.com/bighornwoods/edit-o-matic/releases/tag/v1.0.4
[1.0.0]: https://github.com/bighornwoods/edit-o-matic/releases/tag/v1.0.0
