Skip to content

refactor: template 層の集約 — require-profile guard 統一 + safe-gh hook JSON の partial 化 (PR-4/4, Refs #189) - #193

Merged
kosako merged 1 commit into
mainfrom
refactor-template-partials-189
Jul 10, 2026
Merged

refactor: template 層の集約 — require-profile guard 統一 + safe-gh hook JSON の partial 化 (PR-4/4, Refs #189)#193
kosako merged 1 commit into
mainfrom
refactor-template-partials-189

Conversation

@kosako

@kosako kosako commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Refs #189 の PR-4/4(最終)。ultracode 監査 CONFIRMED 所見(template ×2)。

変更内容(render byte-identical)

  1. capability-lookup 前文の統一
    • 二重 index 綴り(index (index .profiles .profile) "capabilities")を単一 index に正規化(dot_claude/settings.json.tmpl / dot_codex/hooks.json.tmpl / dot_codex/rules/default.rules.tmpl)
    • guard 無しだった 4 template の先頭に require-profile include を追加(unknown profile 時の nil-index panic → 可読 fail。到達可能なのは template 単独評価時のみで、通常経路は .chezmoiignore の require-profile が先に fail するため実挙動不変)
    • trim marker の要注意点: private_dot_ssh/config.tmpl のみ {{ template ... -}}(左 trim 無し)。直前がリテラルのコメント行で、{{- だと直前の改行を食って 1 byte 変わる(監査の検証フェーズで実在確認済みの落とし穴)
  2. safe-gh PreToolUse hook JSON の partial 化(.chezmoitemplates/safe-gh-hook-json)

挙動不変の検証(実施済み)

  • render byte-identical: personal / work 両 profile の全 managed target を変更前 baseline と diff -r → 完全一致(hooks block は personal の committed render に含まれるため partial 経路も byte 検証済み)
  • 全テスト suite green: test-claude-settings(hook 登録の exact pin: event/matcher/command 絶対 path)/ test-codex-settings(exact pin + timeout=10 + top-level keys={hooks} の codex hooks.json: top-level description が Codex 0.142.5 で parse error → template から除去(#181 follow-up) #185 parse-safety)/ test-render(managed set + unknown profile の fail-closed)/ test-ssh / ほか全 suite
  • 監査の敵対検証フェーズが同一提案を scratchpad 複製 repo に独立適用し、chezmoi v2.70.5 で byte-identical を再現済み(本実装はその処方どおり)

レビュー観点

  • partial の trim 構造(先頭 {{ "" }} アンカー / 末尾 trim comment / timeout の {{- if hasKey }})が byte-identity を壊さないか
  • ssh config の挿入行が {{ template ... -}}(左 trim 無し)になっているか
  • require-profile 追加による副作用(出力 0 byte・fail-only)の見落とし

🤖 Generated with Claude Code

https://claude.ai/code/session_016qw8BkUDu5WdwhYfiFFX5n

…rd 統一 + safe-gh hook JSON の partial 化 (Refs #189)

ultracode 監査の CONFIRMED 所見 2 件 (template)。render 出力は両 profile
とも byte-identical (検証は PR 本文)。

- capability-lookup 前文の綴りを正規化: 二重 index
  (index (index .profiles .profile) "capabilities") を単一 index に
  統一 (3 template)。guard 無しだった 4 template の先頭に require-profile
  include を追加 (unknown profile の nil-index panic を可読 fail に。
  require-profile は全 action trim 付き fail-only で出力 0 byte)。
  private_dot_ssh/config.tmpl のみ左 trim 無しの {{ template }} 形
  (直前がリテラルのコメント行で {{- だと改行を食い 1 byte 変わる)
- safe-gh PreToolUse hook の JSON block (#137/#181 parity 対) を
  .chezmoitemplates/safe-gh-hook-json の dict 引数 partial に集約。
  差分 3 点 (agentDir path / timeout 有無 / 末尾カンマ) は dict 引数と
  caller 側で表現し、片側だけ直す事故の温床を解消。partial は末尾
  改行なし・末尾カンマなしで出力し caller が所有 (byte-identity の要)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016qw8BkUDu5WdwhYfiFFX5n
@kosako

kosako commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

Codex 相互レビュー結果(author=Claude → reviewer=Codex)

codex exec(gpt-5.6-sol, read-only, reasoning=medium)によるレビュー。

判定: ✅ merge 可(must 0 件) — should 0 / nit 0

重点観点の検証結果(Codex 出力より):

  • partial の trim 構造 / Claude・Codex caller の改行・カンマ所有 / ssh の左 trim 非使用: 問題なし
  • require-profile の fail-only・通常時 0 byte / 単一 index への正規化: 問題なし
  • テスト・docs のソース文字列 pin 見落とし: なし
  • 独立検証: 変更 4 target を main と HEAD から直接 render し、personal / work の全 8 組で末尾改行含む SHA-256 一致。missing / unknown profile も全 4 target で期待する可読エラーを確認

author 側検証: 両 profile 全 managed target の baseline diff -r 一致 / 全 16 suite green(hook exact pin・#185 parse-safety 含む)。

@kosako
kosako merged commit fd5b3d1 into main Jul 10, 2026
2 checks passed
@kosako
kosako deleted the refactor-template-partials-189 branch July 10, 2026 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant