Skip to content

実装: .gitattributes を追加し .claude/skills 配下スクリプトの CRLF 破損を防ぐ #97

Closed

Description

@squne121

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: deterministic

Parent 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 build

Stop 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

Activity

  1. added
    enhancement
    state/queued
    phase/implementation
    on May 20, 2026
  2. squne121 commented on May 22, 2026

    @squne121
    OwnerAuthor

    結論

    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.

    • text=auto

    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 は維持しつつ、以下を追加した方がよいです。

    • 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 指定が含まれる。
    • AC7: PR本文に「既存 working tree の CRLF 破損修復・実行 bit 修復は本PRの対象外」と明記されている。

    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つです。

    1. 実装: .claude/skills 配下スクリプトの executable bit を監査し CI guard を追加する

    2. 運用: line-ending 正規化後の git add --renormalize 適用範囲を設計する

    #97 のPRでは .gitattributes 以外を触らない、という制約を守るのが重要です。

  3. squne121 commented on May 22, 2026

    @squne121
    OwnerAuthor

    Issue 本文更新: review-issue needs-fix 対応

    review-issue が needs-fix を返したため、以下の差分を本文に反映しました。

    変更内容

    1. [BLOCKING] ## Runtime Verification Applicability セクション追加

      • ## Notes 直前に挿入
      • decision: not_applicable / 理由: .gitattributes 追加のみで静的検証で完結
    2. acceptance_criteria_count 更新

      • 3 → 7(AC4〜AC7 追加に伴う)
    3. ## In Scope 拡張

      • *.sh / *.py のみ → スクリプト・ソース・設定系拡張子一式(*.sh, *.bash, *.zsh, *.py, *.js, *.ts, *.tsx, *.json, *.jsonc, *.yml, *.yaml, *.md, *.toml, *.lock)
      • Windows 専用ファイル(*.bat, *.cmd, *.ps1, *.sln)の eol=crlf 明示行(オプション)追加
      • バイナリアセット一覧を詳細化
    4. ## Acceptance Criteria に AC4〜AC7 を追加

      • AC4: git ls-files --eol による属性確認
      • AC5: tracked ファイルへの CRLF 混入検証(Python スクリプト)
      • AC6: バイナリ拡張子 binary 指定の確認
      • AC7: PR 本文への免責明記
    5. ## Verification Commands 改善

      • AC2: .sh と .py を個別に検証するパターンへ変更(片方のみ存在する誤通過を排除)
      • AC4〜AC6 対応のコマンドブロックを追加
      • Standard gates 末尾維持

    バックアップ

    更新前の本文: /tmp/issue_97_backup.txt(5990 bytes)

    変更ソース

    review-issue feedback による needs-fix 返却への対応。title_update.required = false(タイトル変更なし)。

  4. squne121 commented on May 22, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: iteration 1 追加修正 (2026-05-22T03:47:41Z)

    • C5 修正: AC7 に対応する # AC7 VC コメントブロックを追加(AC:7 ↔ VC:7 を揃える)
    • AC7 の VC は PR 作成後に実行する設計(gh pr view コマンドをコメントアウト形式で記載)
  5. squne121 commented on May 22, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 完了 (2026-05-22T03:51:58Z)

    改善履歴

    # 変更 詳細
    1 Runtime Verification Applicability 追加(C9 修正) decision: not_applicable(静的検証のみで完結)
    2 acceptance_criteria_count 更新 3 → 7
    3 In Scope 拡張 *.sh / *.py のみ → スクリプト・ソース・設定系全般 + バイナリアセット明示
    4 AC4〜AC7 追加 git ls-files --eol / CRLF 検証 Python / binary 属性確認 / PR 免責明記
    5 VC AC2 強化 `*(sh
    6 VC AC4〜AC7 追加 各 AC に対応するコマンドブロックを追加

    事実確認(codebase-investigator + web-researcher)

    次アクション

    issue-contract-review を実行してから implement-issue で着手してください。

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      follow_up_issues:
        - request_dedupe_key: "executable-bit-audit-ci-guard-claude-skills"
          issue_number: 205
          issue_url: "https://github.com/squne121/loop-protocol/issues/205"
          status: created
    
        - request_dedupe_key: "git-add-renormalize-design-post-gitattributes"
          issue_number: 206
          issue_url: "https://github.com/squne121/loop-protocol/issues/206"
          status: created
    
      note_only_observations: []
  6. squne121 commented on May 22, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-05-22T04:30:00Z)

    • status: go
    • Outcome: リポジトリ root に .gitattributes ファイルが追加され、.sh / .py を含むテキストファイルが text eol=lf で正規化される
    • Acceptance Criteria: AC1〜AC7(7 件)
    • Verification Commands: 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
    • Allowed Paths: .gitattributes
    • Worktree: .claude/worktrees/issue-97-gitattributes-crlf-prevention
    • Branch: worktree-issue-97-gitattributes-crlf-prevention
    • VC preflight: baseline fail = 2 (AC1, AC2), 想定外 pass = 0, 実行不可 = 0

    Warnings(VC quality notes)

    • AC3/AC4: git check-attr / git ls-files --eol は inspection 型 VC(assertion なし)。実装後の出力内容で人間が目視確認推奨
    • AC5: baseline PASS(tracked files は既に LF)。regression guard として機能
    • AC6: ugrep が missing file に対し exit 0 + warning を返す動作。実装後は grep が正常にマッチすることで AC 充足
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      issue_url: https://github.com/squne121/loop-protocol/issues/97
      next_action: implement_issue
      worktree: .claude/worktrees/issue-97-gitattributes-crlf-prevention
      branch: worktree-issue-97-gitattributes-crlf-prevention
  7. squne121 commented on May 22, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-05-22T04:04:42Z)

    • PR: chore: .gitattributes を追加し CRLF 破損を構造的に防ぐ #212
    • Worktree: .claude/worktrees/issue-97-gitattributes-crlf-prevention
    • Branch: worktree-issue-97-gitattributes-crlf-prevention
    • Verification: AC1〜AC7 全 PASS、標準 4 ゲート (typecheck/lint/test/build) 全 PASS
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
  8. squne121 commented on May 22, 2026

    @squne121
    OwnerAuthor

    post-merge-cleanup: 完了 (2026-05-22T05:35:00Z)

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      follow_up_issues:
        - request_dedupe_key: "follow-up:squne121/loop-protocol:pr/212:core-autocrlf-guide"
          issue_number: 214
          issue_url: "https://github.com/squne121/loop-protocol/issues/214"
          status: created
    
        - request_dedupe_key: "follow-up:squne121/loop-protocol:pr/212:exec-bit-audit-extension"
          issue_number: 213
          issue_url: "https://github.com/squne121/loop-protocol/issues/213"
          status: created
    
        - request_dedupe_key: "follow-up:squne121/loop-protocol:pr/212:renormalize-implementation"
          issue_number: null
          issue_url: null
          status: skipped_premature
          note: "#206(調査・設計)がOPENのため、実施タスクは #206 クローズ後に起票"
    
      note_only_observations:
        - dedupe_key: "consolidation-205-206"
          summary: "Gemini 調査で #205 / #206 は統合不要と判定。#205 (exec bit audit) → #206 (renormalize 設計) の依存順序を維持"

    Cleanup 完了事項

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementphase/implementationstate/queued

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions