Repository navigation
Description
Parent Issue
なし(単独改善 Issue)
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "リポジトリ root に .gitattributes を追加し、.claude/skills 配下のシェル/Python スクリプトを eol=lf で正規化することで、Windows/WSL 環境の改行コード自動変換による CRLF 破損を構造的に防ぐ"
change_kind: workflow
allowed_paths:
- .gitattributes
acceptance_criteria_count: 7
verification_kind: deterministicParent Goal Ref
該当なし(parent Issue を持たない単独改善)。
Current Validated Scope
リポジトリ root への .gitattributes 1 ファイル新規追加のみ。.sh / .py を中心とした改行コード正規化属性の定義に閉じる。
Remaining Parent Gaps
- 本 Issue 完了後も、既に working tree で CRLF 化しているファイル(観測例:
.claude/skills/ssot-discovery/scripts/match-ssot.sh,.claude/skills/open-pr/scripts/open_pr.py,.claude/skills/create-issue/scripts/verify-anchors.sh)はgit checkout -- <path>等での手動復旧が別途必要。これは本 Issue の Allowed Paths 外であり扱わない。 - スクリプトの実行 bit(mode 755)の混入・喪失は
.gitattributesでは管理できないため別途検討対象。
Background
issue-refinement-loop(Issue #79)の作業中、ssot-discovery skill の match-ssot.sh を実行したところ以下のエラーで失敗した:
.claude/skills/ssot-discovery/scripts/match-ssot.sh: line 11: $'\r': command not found
.claude/skills/ssot-discovery/scripts/match-ssot.sh: line 12: set: pipefail: invalid option name
調査の結果、working tree で以下 3 本のスクリプトが CRLF 改行に変換され(さらに file mode が 755 → 644 に変化)、コミット済みの LF 版から乖離していた:
.claude/skills/ssot-discovery/scripts/match-ssot.sh.claude/skills/open-pr/scripts/open_pr.py.claude/skills/create-issue/scripts/verify-anchors.sh
リポジトリには .gitattributes が存在せず、Windows / WSL 環境のエディタや core.autocrlf 設定によってシェルスクリプトが容易に CRLF 化し、Linux 上の bash 実行で壊れる。.claude/skills/ 配下には多数の .sh / .py スクリプトがあり、CRLF 混入は再発しやすい運用リスクである。
.gitattributes で .sh / .py 等を text eol=lf 指定すれば、git が改行コードを LF に正規化し、環境差による CRLF 破損を構造的に防げる。
Outcome
リポジトリ root に .gitattributes ファイルが追加され、*.sh / *.py を含むテキストファイルが text eol=lf で正規化される。git check-attr text eol -- <スクリプトパス> が対象スクリプトに対して eol: lf を返す状態になり、CRLF 改行がコミット時に LF へ正規化される。
In Scope
- リポジトリ root への
.gitattributes新規作成 * text=autoのデフォルト行- スクリプト・ソース・設定系拡張子(
*.sh,*.bash,*.zsh,*.py,*.js,*.ts,*.tsx,*.json,*.jsonc,*.yml,*.yaml,*.md,*.toml,*.lock)をtext eol=lfで正規化する明示行 - Windows 専用ファイル(
*.bat,*.cmd,*.ps1,*.sln)をtext eol=crlfで明示する行(オプション) - バイナリアセット(
*.png,*.jpg,*.jpeg,*.gif,*.webp,*.ico,*.mp3,*.wav,*.ogg,*.mp4,*.zip,*.gz,*.pdf,*.ttf,*.otf,*.woff,*.woff2)をbinary指定して誤正規化を防ぐ行
Out of Scope
- 既に working tree で CRLF 化しているファイルの手動復旧(
git checkout/git add --renormalize) - 既存コミット履歴の改行コード一括書き換え
.editorconfigなど別ファイルの新設- スクリプトの実行 bit(mode)の修正
core.autocrlf等のローカル git 設定変更
Allowed Paths
.gitattributes
Acceptance Criteria
- AC1: リポジトリ root に
.gitattributesファイルが存在する。 - AC2:
.gitattributesに*.shと*.pyをtext eol=lfで正規化する指定行が含まれる。 - AC3:
git check-attr text eol -- .claude/skills/ssot-discovery/scripts/match-ssot.sh .claude/skills/open-pr/scripts/open_pr.py .claude/skills/create-issue/scripts/verify-anchors.shが 3 ファイルすべてに対してeol: lfを返す。 - AC4:
git ls-files --eol -- '.claude/skills/**/*.sh' '.claude/skills/**/*.py'の出力で、対象ファイルのattr/text eol=lfが確認できる。 - AC5: tracked な
.claude/skills/**/*.shと.claude/skills/**/*.pyに CRLF が含まれていないことを検証する。 - AC6:
.gitattributesに主要バイナリ拡張子のbinary指定が含まれる(*.png,*.jpg,*.mp3,*.wav,*.zip,*.pdf,*.ttf,*.woff,*.woff2等)。 - AC7: PR 本文に「既存 working tree の CRLF 破損修復・実行 bit 修復は本 PR の対象外」と明記されている。
Verification Commands
# AC1: .gitattributes が repo root に存在する
test -f .gitattributes && echo "PASS: present" || echo "FAIL: absent"
# AC2: .sh / .py を個別に確認(片方だけ存在しても通ってしまうパターンを排除)
grep -nE '^\*\.sh[[:space:]]+text[[:space:]]+eol=lf$' .gitattributes && echo "PASS: *.sh" || echo "FAIL: *.sh not found"
grep -nE '^\*\.py[[:space:]]+text[[:space:]]+eol=lf$' .gitattributes && echo "PASS: *.py" || echo "FAIL: *.py not found"
# AC3: 代表スクリプト3本に eol=lf 属性が適用される
git check-attr text eol -- \
.claude/skills/ssot-discovery/scripts/match-ssot.sh \
.claude/skills/open-pr/scripts/open_pr.py \
.claude/skills/create-issue/scripts/verify-anchors.sh
# AC4: .claude/skills 配下スクリプトへの属性適用確認
git ls-files --eol -- \
'.claude/skills/**/*.sh' \
'.claude/skills/**/*.py'
# AC5: tracked な .sh/.py ファイルに CRLF が含まれていないこと
python3 - <<'PY'
from pathlib import Path
import subprocess, sys
paths = subprocess.check_output(
["git", "ls-files", ".claude/skills"],
text=True,
).splitlines()
bad = []
for p in paths:
if not (p.endswith(".sh") or p.endswith(".py")):
continue
data = Path(p).read_bytes()
if b"\r\n" in data:
bad.append(p)
if bad:
print("FAIL: CRLF detected:")
print("\n".join(bad))
sys.exit(1)
print("PASS: no CRLF in tracked .sh/.py files under .claude/skills")
PY
# AC6: binary attributes exist
grep -nE '^\*\.(png|jpg|jpeg|gif|webp|ico|mp3|wav|ogg|mp4|zip|gz|pdf|ttf|otf|woff|woff2)[[:space:]]+binary$' .gitattributes | head -5
# AC7: PR 本文に免責事項が明記されていること(PR 作成後に確認)
# gh pr view --json body --jq '.body' | grep -q "対象外" && echo "PASS: disclaimer present" || echo "FAIL: disclaimer missing"
# Standard gates
pnpm typecheck
pnpm lint
pnpm test
pnpm buildStop Conditions
- 既にコミット済みファイル内容の CRLF→LF 一括再正規化(
git add --renormalize)が必要だと判明した場合は、本 Issue では扱わず別 Issue へ分割する .gitattributes追加が CI / lint / build の挙動を変える兆候が出た場合は停止し人間判断へ戻す- スクリプトの実行 bit(mode 755)管理まで対象を広げる必要が出た場合は停止する(
.gitattributesは exec bit を管理しない) .editorconfig等の別ファイル新設が必要だと判明した場合は停止し別 Issue へ分割する- Allowed Paths(
.gitattributes)を超える変更が必要になった場合は停止する - 改行コード正規化対象の拡張子判断で曖昧さが残る場合は人間判断へ戻す
Required Skills
なし
Delivery Rule
- 1 Issue = 1 PR
- Draft PR 既定
- PR 本文に
Closes #<本Issue番号>を記載する
Runtime Verification Applicability
- decision: not_applicable
- reason:
.gitattributesファイルの追加のみで、プロセス起動・通信・I/O は不要。test -f/grep/git check-attrおよびpnpm typecheck/lint/test/buildの静的検証で完結する。
Notes
- 観測元: issue-refinement-loop(Issue 実装: create_issue_txn.py の sub-issue-readback retry 固定 + implementation Issue 標準ラベル自動付与(#61 統合) #79)作業中の
ssot-discoveryskill 実行失敗。 .gitattributes追加後、既存の CRLF 破損 working tree ファイルは別途git checkout -- <path>で復旧が必要(Out of Scope)。
Activity
squne121 commentedon May 22, 2026
結論
Issue #97 は 方向性は正しい です。.gitattributes を root に置き、.sh / .py を text eol=lf に固定する方針は、Windows / WSL / Linux 混在環境で shell wrapper や Python script の CRLF 破損を防ぐ実装として妥当です。Git 公式仕様上も、text は index へ LF 正規化し、eol=lf は checkout 時も LF を使わせる指定です。
ただし、現Issueのままだと 「狭すぎるスコープ」と「弱すぎる検証」の両方で品質不足 です。特に .sh / .py だけでは .claude/skills/** 配下の将来追加スクリプト、Node/TS系設定、Markdown/YAMLの正規化方針が曖昧に残ります。また、AC3 の git check-attr は属性適用だけを確認し、実際に CRLF 混入を防げたかは確認しません。
敵対的レビュー
深刻度 指摘 問題 改善
Blocker .gitattributes 追加だけでは既存 working tree 破損を直せない Issue本文でも既存の CRLF 化済み3ファイルは Out of Scope としているが、実装者が「これで完全解決」と誤認しやすい PR本文に「prevent future checkouts / commits only。既存WT修復は別Issue」と明記
Blocker AC が git check-attr だけ eol: lf が返っても、index/working tree に CRLF が残っていない証明にはならない git ls-files --eol と CRLF grep を追加
High 対象拡張子が .sh / .py に偏りすぎ .claude/skills には shell wrapper 以外に Markdown / YAML / JSON / TS / JS / config が増える可能性がある。#198 では match-ssot.sh 周辺に Python化・YAML生成・npm script追加が予定されている repo全体の一般テキストは * text=auto、実行・生成・設定系は明示 eol=lf
High バイナリ指定が「必要に応じて」で曖昧 GitHub Docs もバイナリ破損回避のため .gitattributes で明示することを推奨している 画像・音声・フォント・圧縮ファイルを最小セットで binary
Medium
grep -nE '*.(sh py).*eol=lf'は弱い *.sh text eol=lf と *.py text eol=lf の両方が必要なのに、片方だけでも出力が出るMedium 実行 bit 問題との境界が弱い Issue本文は mode 755→644 も観測しているが、.gitattributes では解決不能と書くだけでは follow-up が残る follow-up Issue を明示: executable bit audit / CI guard
Medium 標準ゲートが過剰 .gitattributes 1ファイル変更に pnpm build まで必須にすると、既存baseline failに巻き込まれやすい pnpm ゲートは baseline regression check と明記。主証跡は Git line-ending checks
推奨 .gitattributes
最小修正なら以下でよいです。
Default: let Git classify text/binary, normalize text in the index.
Scripts and source-like files that must remain LF on checkout.
*.sh text eol=lf
*.bash text eol=lf
*.zsh text eol=lf
*.py text eol=lf
*.js text eol=lf
*.ts text eol=lf
*.tsx text eol=lf
*.json text eol=lf
*.jsonc text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.md text eol=lf
*.toml text eol=lf
*.lock text eol=lf
Windows-specific files may use CRLF when such files appear later.
*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf
*.sln text eol=crlf
Binary assets: never normalize or diff as text.
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.webp binary
*.ico binary
*.mp3 binary
*.wav binary
*.ogg binary
*.mp4 binary
*.zip binary
*.gz binary
*.pdf binary
*.ttf binary
*.otf binary
*.woff binary
*.woff2 binary
Git公式例でも * text=auto、*.sh text eol=lf、画像を -text 相当で扱うパターンが示されています。GitHub Docs も .gitattributes は root に置き、commit することで各Contributorの core.autocrlf より一貫した挙動を得られると説明しています。
Issue #97 本文の修正案
Acceptance Criteria の強化
現在の AC は維持しつつ、以下を追加した方がよいです。
git ls-files --eol -- .claude/skills/**/*.sh .claude/skills/**/*.pyの出力で、対象ファイルのattr/text eol=lfが確認できる。.claude/skills/**/*.shと.claude/skills/**/*.pyに CRLF が含まれていないことを検証する。.gitattributesに主要バイナリ拡張子のbinary指定が含まれる。Verification Commands の改善
AC1
test -f .gitattributes && echo "PASS: present" || echo "FAIL: absent"
AC2: .sh / .py を個別に確認
grep -nE '^*.sh[[:space:]]+text[[:space:]]+eol=lf$' .gitattributes
grep -nE '^*.py[[:space:]]+text[[:space:]]+eol=lf$' .gitattributes
AC3/AC4: Git attribute 適用確認
git check-attr text eol --
.claude/skills/ssot-discovery/scripts/match-ssot.sh
.claude/skills/open-pr/scripts/open_pr.py
.claude/skills/create-issue/scripts/verify-anchors.sh
git ls-files --eol --
'.claude/skills//*.sh'
'.claude/skills//*.py'
AC5: tracked shell/python files に CRLF が混入していないこと
python3 - <<'PY'
from pathlib import Path
import subprocess, sys
paths = subprocess.check_output(
["git", "ls-files", ".claude/skills"],
text=True,
).splitlines()
bad = []
for p in paths:
if not (p.endswith(".sh") or p.endswith(".py")):
continue
data = Path(p).read_bytes()
if b"\r\n" in data:
bad.append(p)
if bad:
print("FAIL: CRLF detected:")
print("\n".join(bad))
sys.exit(1)
print("PASS: no CRLF in tracked .sh/.py files under .claude/skills")
PY
AC6: binary attributes exist
grep -nE '^*.(png|jpg|jpeg|gif|webp|ico|mp3|wav|ogg|mp4|zip|gz|pdf|ttf|otf|woff|woff2)[[:space:]]+binary$' .gitattributes
git add --renormalize . は Git公式・GitHub Docs の推奨手順に含まれますが、#97 の Allowed Paths が .gitattributes のみである以上、今回のPRでは実行しない方がよいです。実行すると既存ファイル差分が大量に出る可能性があり、Issueのスコープを壊します。
関連Issue / PRとの関係
#97 の直接の観測元は #79 作業中の match-ssot.sh 実行失敗です。Issue本文には $'\r': command not found と set: pipefail: invalid option name が記録され、対象として match-ssot.sh、open_pr.py、verify-anchors.sh の3ファイルが挙げられています。
PR #103 でも作業中の観測として「skill スクリプトの CRLF 破損」「.gitattributes 不在が根本原因」「Issue #97 で対応予定」と明記されています。つまり #97 は孤立Issueではなく、AIエージェント運用中に実害が出た再発防止Issueです。
#198 は将来的に .claude/skills/ssot-discovery/scripts/match-ssot.sh や YAML / npm script 追加を扱うため、#97 は #198 より先に入れる価値があります。先に line ending policy を固定しておけば、生成スクリプトや wrapper 追加時のCRLF混入リスクを減らせます。
最終判断
GO。ただし Issue本文を少し強化してから実装した方がよいです。
このIssueでやるべきことは「.gitattributes を追加して将来の CRLF 混入を構造的に抑える」までです。既存 working tree の復旧、git add --renormalize、実行 bit 監査、CI guard は別Issueに分けるべきです。
推奨する追加 follow-up は次の2つです。
実装: .claude/skills 配下スクリプトの executable bit を監査し CI guard を追加する
運用: line-ending 正規化後の git add --renormalize 適用範囲を設計する
#97 のPRでは .gitattributes 以外を触らない、という制約を守るのが重要です。
squne121 commentedon May 22, 2026
Issue 本文更新: review-issue needs-fix 対応
review-issueがneeds-fixを返したため、以下の差分を本文に反映しました。変更内容
[BLOCKING]
## Runtime Verification Applicabilityセクション追加## Notes直前に挿入decision: not_applicable/ 理由:.gitattributes追加のみで静的検証で完結acceptance_criteria_count更新3→7(AC4〜AC7 追加に伴う)## In Scope拡張*.sh/*.pyのみ → スクリプト・ソース・設定系拡張子一式(*.sh,*.bash,*.zsh,*.py,*.js,*.ts,*.tsx,*.json,*.jsonc,*.yml,*.yaml,*.md,*.toml,*.lock)*.bat,*.cmd,*.ps1,*.sln)のeol=crlf明示行(オプション)追加## Acceptance Criteriaに AC4〜AC7 を追加git ls-files --eolによる属性確認binary指定の確認## Verification Commands改善.shと.pyを個別に検証するパターンへ変更(片方のみ存在する誤通過を排除)Standard gates末尾維持バックアップ
更新前の本文:
/tmp/issue_97_backup.txt(5990 bytes)変更ソース
review-issuefeedback によるneeds-fix返却への対応。title_update.required = false(タイトル変更なし)。squne121 commentedon May 22, 2026
issue-refinement-loop: iteration 1 追加修正 (2026-05-22T03:47:41Z)
# AC7VC コメントブロックを追加(AC:7 ↔ VC:7 を揃える)gh pr viewコマンドをコメントアウト形式で記載)squne121 commentedon May 22, 2026
issue-refinement-loop: 完了 (2026-05-22T03:51:58Z)
改善履歴
decision: not_applicable(静的検証のみで完結)事実確認(codebase-investigator + web-researcher)
* text=auto+*.sh text eol=lf+ binary 指定パターンが推奨。git add --renormalize は Git 2.16+ 公式推奨手順。次アクション
issue-contract-reviewを実行してからimplement-issueで着手してください。squne121 commentedon May 22, 2026
Contract Snapshot (2026-05-22T04:30:00Z)
go.gitattributesファイルが追加され、.sh/.pyを含むテキストファイルがtext eol=lfで正規化されるtest -f .gitattributes/grep -nE *.sh/*.py eol=lf/git check-attr/git ls-files --eol/ Python CRLF チェック / binary grep /pnpm typecheck|lint|test|build.gitattributes.claude/worktrees/issue-97-gitattributes-crlf-preventionworktree-issue-97-gitattributes-crlf-preventionWarnings(VC quality notes)
git check-attr/git ls-files --eolは inspection 型 VC(assertion なし)。実装後の出力内容で人間が目視確認推奨ugrepが missing file に対し exit 0 + warning を返す動作。実装後は grep が正常にマッチすることで AC 充足squne121 commentedon May 22, 2026
implement-issue: 実装完了 (2026-05-22T04:04:42Z)
.claude/worktrees/issue-97-gitattributes-crlf-preventionworktree-issue-97-gitattributes-crlf-preventionchore: .gitattributes を追加し CRLF 破損を構造的に防ぐ (#97) (#212)
squne121 commentedon May 22, 2026
post-merge-cleanup: 完了 (2026-05-22T05:35:00Z)
Cleanup 完了事項
worktree-issue-97-gitattributes-crlf-prevention削除済み/home/squne/projects/LOOP_PROTOCOL/.claude/worktrees/issue-97-gitattributes-crlf-prevention削除済み(git worktree prune経由)