STEP 2207 — Infra trilogy: cron 統合 + atomic-commit auto-add + hook find optimization

2026-09-23 · rei-aios-59 · 6 items sequential #4+#5+#6 batched · 「commit/hook/cron infrastructure」 domain 統合
★ Corrigendum #1 (2026-09-23、 chat-Claude 3 point feedback embed 後)

Item #6 効果欄 refined (predicted → measured): 初版 「予測 5-6 min → 数十秒」 は 未実測値 = fm-narrative-fit-without-numerical-verify 同型 pattern。 実測: STEP 2205 (Item #6 fix 前) commit ~15 min → STEP 2206 retry (Item #6 fix 後) commit ~5 min = 約 3x speedup (「数十秒」 の 20-40x speedup ではない)。

Hook edit transient syntax error 予防 (chat-Claude 補足): pending の 「事前 lock or staging discipline」 は 不要。 hook file を tempfile に write して mv で 原子的 置換 pattern を 使えば、 他 tab は 常に 旧版 or 新版 の どちらか を 読む = 中途半端な state 読み込み 不能。 Edit tool 直接 書き換え が 原因 なので、 hook 編集時 のみ 「temp write + mv」 workflow に。 未来 の hook edit discipline rule として 記録。

Attribution: [via 藤本さん paste of chat-Claude(cloud) 3 point corrigendum feedback / verify + fix: rei-aios-59]
Summary: 6 items sequential 残 3 infrastructure items を 単一 STEP に batched land: Item #4 refresh-watchlist cron 統合、 Item #5 git-atomic-commit.sh untracked auto-add fix、 Item #6 pre-commit hook find MEMORY.md optimization。 Batching rationale: 3 items 全 「commit/hook/cron infrastructure」 domain、 個別 STEP は commit cost 過大 (10-15 min × 3 = 30-45 min overhead)。 未来 audit 引き当て点 として 本 site page に 3 items 個別 documented。

Batching decision (「順番」 遵守 の 解釈)

藤本さん directive: 「順番にお願い致します」 6 items sequential。 strict 「1 item = 1 STEP」 で 実行すると 各 commit 10-15 min の pre-commit hook cost が 総計 30-45 min となり session budget 圧迫。 Items #1+#2+#3 は 主要 domain (radar/scorer) で 個別 STEP land (STEP 2204/2205/2206)、 Items #4+#5+#6 は 全 infrastructure domain semantic 関連あり = batching 適用、 「順番」 は 保持 (残 3 items が 順番 通り 単一 STEP に land)。

Item #4: refresh-watchlist cron 統合

File: scripts/research-radar/daily-radar.ts (+5 line、 fetchers array 追加)

{ name: 'Refresh watchlist', path: path.join(SCRIPTS_DIR, 'refresh-watchlist.ts') },

Daily-radar 稼働時 自動実行、 14 tracked paper × 3s = ~42s 追加 (daily-radar 全体 ~15 min の 5% 未満)、 tracked paper 撤回状態変化 (Niu 型) 自動検出 → collatz-watch.json auto-update。

Item #5: git-atomic-commit.sh untracked auto-add fix

File: scripts/git-atomic-commit.sh (+13 line)

fm addressed: fm-atomic-commit-only-rejects-untracked-files (STEP 2203/2204 emerge)

if [ "$force" -eq 0 ]; then
  untracked_to_add=()
  for f in "${files[@]}"; do
    if [ -f "$f" ] && ! git ls-files --error-unmatch "$f" >/dev/null 2>&1; then
      untracked_to_add+=("$f")
    fi
  done
  if [ ${#untracked_to_add[@]} -gt 0 ]; then
    git add -- "${untracked_to_add[@]}"
  fi
fi

Effect: STEP 2203-2206 で 私 が 明示 pre-add していた workflow が unnecessary に、 直接 scripts/git-atomic-commit.sh -F msg.txt -- new_file.md で 動作。

Item #6: pre-commit hook find MEMORY.md optimization

File: .githooks/pre-commit (attribution check section 拡張)

fm addressed: fm-pre-commit-hook-slow-find-memory-md (STEP 2203/2204 emerge: pre-commit hook 5-6 min 停止)

Root cause: attribution check の nested loop 内 find "$repo_root" -type f -name "$base" が per-reference で 全 repo scan、 Windows filesystem 経由で 極遅、 30+ references × 5-6 min = 分単位 total wait。

Fix: basename cache を ONCE per commit で build、 nested loop 内 は grep lookup:

attribution_basename_cache=$(mktemp)
trap 'rm -f "$attribution_basename_cache" ...' EXIT
find "$repo_root" \
  \( -name node_modules -o -name .git -o -path '*/notepad/entries' \) -prune -o \
  -type f \( -name '*.md' -o -name '*.lean' -o -name '*.ts' \) -print > "$attribution_basename_cache"

# inner loop (was: find call per reference):
found=$(grep -E "/${base}$" "$attribution_basename_cache" | ...)

Complexity change: O(N × full_find) → O(1 × full_find + N × string_grep)

New failure modes addressed

fmItemFix layer
fm-atomic-commit-only-rejects-untracked-files#5script auto-detect + git-add
fm-pre-commit-hook-slow-find-memory-md#6basename cache one-shot

Honest scope