git-atomic-commit — Multi-tab safe git commit

STEP: 1554 / Script: scripts/git-atomic-commit.sh / Feedback rule: memory/feedback_multi_tab_commit_atomic.md / Trigger: STEP 1544/1550 実測 incident 2 件

Problem — Multi-tab の staging collision

実測 incident 1: STEP 1544 commit 1a8deb61d contamination (2026-08-29)

意図した 4 files (game-verdict-connector.ts + test + public + dist-renderer) が commit されず、 代わりに別 tab の step-1537-verdict-puzzle + step-1541-flow-state 系 9 files が入った。 自 files は untracked (?) に戻り staging drop。 復旧に別 commit d23bc29bf 必要。

実測 incident 2: STEP 1550 first commit attempt (2026-08-29)

「no changes added to commit」 で失敗。 全 staging 消失。 同時に別 tab で STEP 1548/1549/1551 の 3 commit landing。 復旧に原子的 git add && git commit 必要 (commit 83be73c6e)。

Root cause

.git/index は repo あたり単一の shared file。 Multi-tab workflow で:

Tab A: git add MY_FILES        → index = {MY_FILES staged}
Tab B: git add THEIR_FILES     → index が mutate される (併記 or 置換)
Tab A: git commit -m "..."     → 現在の index (= B 変更後) を commit
                                 → 結果: 自 files 欠落 or 別 files 混入

Git 自体は multi-writer 前提の設計ではない。 pre-commit hook が git add を追加すること (inbox merger 等) も index を触るため race window を広げる。

Solution — git commit --only FILES

Atomic 5 stage: single git process 内で実行、 他 tab の add/reset/commit に免疫。

  1. 現在の index を保存
  2. 指定 FILES の working-tree state を一時 index に snapshot
  3. pre-commit hook を一時 index に対して実行 (hook の git add は一時 index に追加)
  4. 一時 index を commit
  5. 保存した元 index を復元 (他 tab の staging preservation)

Usage — scripts/git-atomic-commit.sh

# Basic (multi-file):
scripts/git-atomic-commit.sh -m "STEP 1550 Lean 4 ..." -- \
  data/lean4-transfer/step1550_game_verdict.lean \
  src/mcp/rei-mcp-server.ts \
  public/tools/step-1550-lean4-game-verdict/index.html

# With --force (dist-renderer mirror 等 gitignored file):
scripts/git-atomic-commit.sh -m "..." --force -- \
  dist-renderer/tools/step-1550-lean4-game-verdict/index.html

# Long HEREDOC message via file:
cat > /tmp/msg.txt <<'EOF'
STEP 1550 Lean 4 for game_verdict — 12 theorem zero sorry

Body...
EOF
scripts/git-atomic-commit.sh -F /tmp/msg.txt -- file1 file2

# Help:
scripts/git-atomic-commit.sh -h

Options

Flag意味
-m MSGCommit message (short)
-F FILECommit message from file (long HEREDOC 用)
--forcegit add -f 事前実行 (gitignored file 用、 dist-renderer/ mirror 等)
--Files delimiter (以降は全て files 扱い)
-hHelp

Exit codes

Code意味
0OK
1Usage error (bad flags, missing file)
2No files specified
3+git commit error (git 自体の exit code + 2)

Discipline (feedback rule 化)

memory/feedback_multi_tab_commit_atomic.md で永久 rule 化:

Multi-tab 予防 protocol 2 層構造

tool役割導入 STEP
1 (集約)Inbox pattern (docs/recent-updates-inbox/ + memory/hooks/)単一 append point (RECENT_UPDATES.md / MEMORY.md) への直接編集を禁じ、 unique file 経由で merger が atomic 集約2026-08-27 (STEP 1414+1415+mapping arc 3 tab 併走 collision root cause fix)
1.5 (番号)Central STEP counter (scripts/claim-step.ts)STEP 番号 collision 予防 (SAC-4 49/50 renumber root cause fix)2026-08-27
2 (commit)scripts/git-atomic-commit.shgit index race を --only FILES で回避、 別 tab の staging に免疫2026-08-29 (STEP 1554、 本 STEP)
Honest scope: