STEP 2210 — Hook edit safety helper (tempfile+mv atomic)

2026-09-23 · rei-aios-59 · 2nd batch of 6 items sequential #2 · fm-hook-edit-via-edit-tool-transient-syntax-error 対応
Summary: chat-Claude corrigendum #1 Point 3 「hook ファイル を 一時ファイル に 書いてから mv で 置き換えれば、 置き換え は 原子的、 他 tab は 常に 旧版 or 新版 のどちらか を 読む = 中途半端 state 不可能」 の script + permanent memory rule land。 fm-hook-edit-via-edit-tool-transient-syntax-error 対応 (STEP 2206 initial commit の 「syntax error near unexpected token (」 実 emerge)。

Implementation

scripts/edit-hook-safely.sh (~85 line)

Usage

# Case A: 全内容 差替
cat new-content > | scripts/edit-hook-safely.sh .githooks/pre-commit
# or
scripts/edit-hook-safely.sh .githooks/pre-commit < path/to/new.sh

# Case B: transform 適用
scripts/edit-hook-safely.sh .githooks/pre-commit --filter sed 's/foo/bar/g'

Self-test

$ echo -n "" | scripts/edit-hook-safely.sh scripts/edit-hook-safely.sh
ERROR: new content is empty — refusing to overwrite scripts/edit-hook-safely.sh
exit=2 ✓
file preserved (3621 bytes, still executable) ✓

memory/feedback_hook_file_edit_use_tempfile_mv_atomic_2026-09-23.md

Permanent feedback memory rule:

Effect

未来 .githooks/* を 編集する 時 (Item #6 optimization 追加調整、 attribution check rule 追加、 Section 8 拡張 等)、 concurrent commit の transient syntax error 事故 回避。 STEP 2206 initial commit の incident 再発予防。

Honest scope

Next candidates (defer marker)