Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .claude/commands/repo-maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,81 @@ Git hooks(pre-commit)の設定状況を確認:
- ⚠️ Husky 未設定 → セットアップを提案
- 📝 設定内容: pre-commit, commit-msg

### 3.2.1 Check-file-length Setup Check

pre-commit フックに `check-file-length` が含まれているか確認・追加:

**確認ロジック:**

```bash
PRECOMMIT=".husky/pre-commit"
SCRIPT_DEST="script/check-file-length.sh"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Path mismatch with existing setup script.

Line 319 specifies script/check-file-length.sh (singular), and line 360 appends this path to the pre-commit hook. However, the existing script/setup-file-length-check.sh copies the script to scripts/check-file-length.sh (plural, see context snippet 1 lines 24-36). This inconsistency means:

  • If a repository was previously set up using the automated setup script, it has the script at scripts/check-file-length.sh
  • If this repo-maintenance logic runs, it will add a hook calling script/check-file-length.sh
  • The hook will fail because the script is at a different path
🔧 Proposed fix

Align with the existing setup script by using scripts/ (plural):

-SCRIPT_DEST="script/check-file-length.sh"
+SCRIPT_DEST="scripts/check-file-length.sh"

And update the hook invocation:

-echo "bash script/check-file-length.sh" >> "$PRECOMMIT"
+echo "bash scripts/check-file-length.sh" >> "$PRECOMMIT"

Also update line 343:

-mkdir -p script
+mkdir -p scripts

Based on relevant code snippet from script/setup-file-length-check.sh:24-36 showing the existing setup script uses "scripts/" directory.

Also applies to: 360-360

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/repo-maintenance.md at line 319, The SCRIPT_DEST variable
is pointing to the wrong path ("script/check-file-length.sh") causing the
pre-commit hook to reference a non-existent file; change SCRIPT_DEST to
"scripts/check-file-length.sh" and update any hook append/invocation that adds
the script to the pre-commit hook so it calls scripts/check-file-length.sh (the
same path used by setup-file-length-check.sh), ensuring all references (the
variable SCRIPT_DEST and the pre-commit hook append/invocation) are consistent.

SCRIPT_SRC_DEVCONTAINER="/usr/local/script/check-file-length.sh"
SCRIPT_RAW_URL="https://raw.githubusercontent.com/keito4/config/main/script/check-file-length.sh"

has_precommit=false
has_file_length=false

[ -f "$PRECOMMIT" ] && has_precommit=true
grep -q "check-file-length" "$PRECOMMIT" 2>/dev/null && has_file_length=true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Verify script existence before marking hook configured

The check marks check-file-length as configured based only on a string match in pre-commit, so a stale or broken hook entry (for example, a path that no longer exists) is treated as ✅ and skipped. In that case maintenance does not repair the setup and commits can still fail or bypass the intended check; the detection should require both hook presence and a valid script target before skipping.

Useful? React with 👍 / 👎.

```

**結果パターン:**

| 状態 | 対応 |
| ---------------------------------------- | ----------------------------- |
| pre-commit あり + check-file-length あり | ✅ スキップ |
| pre-commit あり + check-file-length なし | ⚠️ → full mode で自動追加 |
| pre-commit なし | ⏭️ Husky 未設定のためスキップ |

**MODE が `full` かつ追加が必要な場合の実行内容:**

1. スクリプトを取得(優先順位順):

```bash
mkdir -p script
if [ -f "$SCRIPT_SRC_DEVCONTAINER" ]; then
# DevContainer 環境: コンテナ内スクリプトをコピー
cp "$SCRIPT_SRC_DEVCONTAINER" "$SCRIPT_DEST"
elif [ ! -f "$SCRIPT_DEST" ]; then
# ローカル環境: GitHub から取得
curl -fsSL "$SCRIPT_RAW_URL" -o "$SCRIPT_DEST"
fi
chmod +x "$SCRIPT_DEST"
```

2. pre-commit フックに追記:

```bash
# すでに lint-staged を呼んでいる行の後に追加

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Minor: Comment doesn't match implementation.

Line 357's comment states "すでに lint-staged を呼んでいる行の後に追加" (add after the line that calls lint-staged), but the actual code on lines 358-360 simply appends to the end of the pre-commit file without any logic to locate or insert after the lint-staged invocation. Either implement intelligent insertion or update the comment to reflect the actual behavior.

♻️ Option 1: Update comment to match implementation
-# すでに lint-staged を呼んでいる行の後に追加
+# pre-commit の末尾に追加
♻️ Option 2: Implement intelligent insertion
# Insert after lint-staged line if it exists, otherwise append to end
if grep -q "lint-staged" "$PRECOMMIT" 2>/dev/null; then
  # Insert after the last lint-staged line
  sed -i '/lint-staged/a\\n# check-file-length\necho "[husky] Running file length check..."\nbash scripts/check-file-length.sh || exit 1' "$PRECOMMIT"
else
  # Append to end
  ...
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/repo-maintenance.md at line 357, The comment "すでに
lint-staged を呼んでいる行の後に追加" claims insertion after the lint-staged invocation but
the current logic just appends to the pre-commit file; either update that
comment to state "append to end of pre-commit" or implement intelligent
insertion: detect the last occurrence of "lint-staged" in the pre-commit file
(grep -q "lint-staged" or similar) and use sed to insert the block (the
check-file-length echo and bash scripts/check-file-length.sh || exit 1 lines)
after that line, falling back to appending if no match is found; refer to the
"lint-staged" string and the inserted block (check-file-length /
scripts/check-file-length.sh) when making the change.

echo "" >> "$PRECOMMIT"
echo "# check-file-length" >> "$PRECOMMIT"
echo "bash script/check-file-length.sh" >> "$PRECOMMIT"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Insert file-length hook before terminal exits

This appends the new hook lines to the end of .husky/pre-commit, but in repositories where the hook already ends with exit 0 (or another unconditional exit), the appended bash script/check-file-length.sh never runs even though maintenance reports it as added. Please insert the command before terminal exit statements (or rewrite the hook block) so the check is guaranteed to execute.

Useful? React with 👍 / 👎.

Comment on lines +358 to +360

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Major: Hook invocation format inconsistent with existing setup script.

Lines 358-360 append a hook invocation without error handling (|| exit 1) or logging. The existing script/setup-file-length-check.sh appends THREE lines including an echo statement for logging and || exit 1 to ensure the pre-commit fails if the check fails (see context snippet 2 lines 65-80):

echo "echo \"[husky] Running file length check...\""
echo "bash scripts/check-file-length.sh || exit 1"

Without || exit 1, the pre-commit hook will continue even if file length violations are detected, defeating the purpose of the check.

🔧 Proposed fix to align with existing setup script
-echo "" >> "$PRECOMMIT"
-echo "# check-file-length" >> "$PRECOMMIT"
-echo "bash script/check-file-length.sh" >> "$PRECOMMIT"
+{
+  echo ""
+  echo "echo \"[husky] Running file length check...\""
+  echo "bash scripts/check-file-length.sh || exit 1"
+} >> "$PRECOMMIT"

Based on relevant code snippet from script/setup-file-length-check.sh:65-80 showing the ACTUAL hook format produced by the existing setup script.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/repo-maintenance.md around lines 358 - 360, The pre-commit
hook lines being appended (using PRECOMMIT and "bash
script/check-file-length.sh") lack the logging echo and the "|| exit 1" failure
propagation used by script/setup-file-length-check.sh; update the invocation to
match the existing pattern by appending an echo logging line like the one
produced by setup-file-length-check.sh and invoke the checker as "bash
scripts/check-file-length.sh || exit 1" (ensure the script path matches the
project convention: scripts/check-file-length.sh) so the hook logs when it runs
and fails the commit on violations.

```

3. `.filelengthignore` がなければテンプレートから生成:

```bash
IGNORE_TEMPLATE="/usr/local/share/config-templates/.filelengthignore.template"
if [ ! -f ".filelengthignore" ]; then
if [ -f "$IGNORE_TEMPLATE" ]; then
cp "$IGNORE_TEMPLATE" .filelengthignore
else
cat > .filelengthignore << 'EOF'
# 自動生成ファイル
**/*.generated.*
**/database.types.ts
EOF
fi
fi
```

**結果:**

- ✅ check-file-length が pre-commit に設定済み
- 🔧 check-file-length を pre-commit に追加しました
- ⏭️ Husky 未設定のためスキップ

### 3.3 Pre-PR Checklist Validation

PR 作成前のチェック項目を検証:
Expand Down Expand Up @@ -572,6 +647,7 @@ npm install -D @biomejs/biome knip
## Setup (2/4)
├── Team Protection: ✅ Branch protection enabled
├── Husky: ✅ Git hooks configured
├── check-file-length: ✅ Configured in pre-commit (or 🔧 Added / ⏭️ Skipped)
├── Pre-PR Checklist: ✅ CI workflow exists
├── CLAUDE.md: ✅ Symlink to AGENTS.md
└── CI/CD: ✅ Standard level configured
Expand Down Expand Up @@ -762,6 +838,7 @@ Run this command regularly to maintain repository health:
| Environment | `/codespaces-secrets` | Codespaces シークレット同期 |
| Setup | `/setup-team-protection` | GitHub保護ルール設定 |
| Setup | `/setup-husky` | Git hooks設定 |
| Setup | (check-file-length auto-setup) | ファイル行数チェック追加 |
| Setup | `/pre-pr-checklist` | PR前チェックリスト |
| Setup | (CLAUDE.md symlink check) | CLAUDE.md シンボリックリンク |
| Setup | `/setup-ci` | CI/CDワークフロー設定 |
Expand Down