8 Commits
Author SHA1 Message Date
Sunil 5beffaeb17 Merge remote-tracking branch 'upstream/main' into fix/simplify-ignore-git-revert
# Conflicts:
#	hooks/simplify-ignore-test.sh
#	hooks/simplify-ignore.sh
2026-10-10 17:11:41 +05:30
Sunil e9e172d909 fix(hooks): simplify-ignore keeps a change reverted with git and re-hides the file 2026-10-06 00:14:30 +05:30
Sunil 807bba68af fix(hooks): simplify-ignore never loses a block whose placeholder was removed 2026-10-05 23:55:43 +05:30
ayobamiseun 7b31a90852 fix(hooks): insert protected block content literally under bash 5.2
The round-trip test added in this PR failed on ubuntu-latest while passing
on macOS: after Read → Stop, a protected block containing a backslash came
back altered (byte 109, line 3 of the fixture).

expand_file rebuilds each line with `${line//$placeholder/$block_content}`.
Bash 5.2 enables patsub_replacement by default, which makes the replacement
side of that expansion special: an unquoted `&` expands to the matched text
and backslashes are consumed. Block content is raw code and routinely
contains `&&` and backslashes, so on any bash 5.2 host every protected block
with either character was corrupted when it was expanded back. Bash 3.2 on
macOS has no such option, which is why local runs never showed it.

Turn the option off at the top of the hook; older bashes reject the shopt,
so the error is ignored there. Extend the byte-fidelity fixture with `&&`
and `&` so the ampersand case is guarded alongside the backslash one.
2026-09-18 09:49:16 +01:00
mavericksea-aiandClaude Opus 5 510259aca0 fix(hooks): keep the rewrite in the cache when simplify-ignore falls back
When a Stop leaves no BLOCK_ placeholder to expand, the hook has to restore
the backup to recover the protected block — which overwrote whatever had
replaced the file. Copy that content into the cache as <id>.recovered first
and name both paths in the warning, so the rewrite is merged back by hand
rather than lost.

Adds a test that the fallback keeps the rewritten content in the cache, and
a minimal lifecycle test (Read, a direct write with no event, Stop) asserting
the write survives.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 01:59:59 +00:00
mavericksea-aiandClaude Opus 5 b1ac22c7d2 fix(hooks): expand simplify-ignore files at Stop instead of restoring backups
The Stop branch restores every cached file from its backup, but that
backup is written on PreToolUse Read and refreshed only by the
PostToolUse Edit|Write branch. A change made to a filtered file through
any other route between Read and Stop — a Bash command, a formatter, an
external editor — is overwritten at session end. Reproduced in #295:
Bash wrote const editable = 2 and read it back, Stop left const
editable = 1 on disk, with no crash and no failed tool call.

The hook protects the content of an annotated block, not the file: the
header documents the backup as holding the model's changes, and Edit and
Write already preserve them. So Stop now runs the same placeholder
expansion the Edit|Write branch runs, against the file as it is on disk.
Whatever wrote the file wrote its filtered form with the placeholders
intact, so expanding it restores the protected blocks and keeps the
change, whichever route it came from.

The expansion body moves into an expand_file function that both branches
call, so the fuzzy-match and deleted-block warnings apply at Stop too.
When no cached BLOCK_<hash> is left, the file was rewritten wholesale and
the hook cannot place the block; it falls back to the backup as before,
now with a warning instead of in silence. That residual is documented in
SIMPLIFY-IGNORE.md. With no outside write, expansion reproduces the
backup exactly, so Read→Stop and Read→Edit→Stop are byte-identical.

Test 11 drives the real hook through Read, an Edit event, a write with no
event after it, and Stop; it fails at be4e44a on the two assertions for
the lost write. Suite: 28 passed, 0 failed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 01:35:47 +00:00
Addy Osmani 111eade87e For #7 some additional minor tweaks 2026-03-27 18:38:08 -07:00
Federico Bartoli 1730a69454 Add simplify-ignore hook for block-level code protection
Single bash script that prevents the model from seeing (and accidentally
simplifying) code blocks marked with simplify-ignore annotations during
/code-simplify sessions.

Hook flow:
- PreToolUse Read: backs up file, replaces blocks with BLOCK_<hash> placeholders
- PostToolUse Edit|Write: expands placeholders, applies model changes, re-filters
- Stop: restores files from backup when session ends

Features:
- Hash-based tokens (content-addressed, unambiguous round-trip)
- Multi-block support per file
- Optional reason string: /* simplify-ignore-start: perf-critical */
- Language-aware placeholders (preserves comment syntax per language)
- Glob-safe parameter expansion (Bash 3.2 compatible)
- Atomic locking with stale lock recovery
- Trailing newline preservation
- Self-healing recovery from interrupted sessions
- Cross-platform: Bash 3.2+, jq, shasum/sha1sum (macOS, Linux, Git Bash)

Implements #2
2026-03-18 05:20:14 +01:00