diff --git a/.claude/commands/README.md b/.claude/commands/README.md index fad4d9e6..532e2e4b 100644 --- a/.claude/commands/README.md +++ b/.claude/commands/README.md @@ -4,6 +4,36 @@ This directory contains pre-configured commands that provide automated workflows ## Available Commands +### Maintenance + +#### `repo-maintenance.md` + +**Purpose**: Comprehensive repository maintenance - run all health checks and updates +**Features**: + +- Environment health checks (container, DevContainer version, Claude Code) +- CI/CD setup checks (team protection, Husky, pre-PR checklist) +- Repository cleanup (branches, git gc) +- New feature discovery from config repository + +**Usage**: + +``` +/repo-maintenance # Full maintenance +/repo-maintenance --mode quick # Quick check (no updates) +/repo-maintenance --mode check-only # Read-only checks +/repo-maintenance --skip security # Skip specific category +/repo-maintenance --create-pr # Create PR for changes +``` + +**Modes**: + +| Mode | Description | +| ---------- | ---------------------------------- | +| full | Run all updates and checks | +| quick | Important checks only (no updates) | +| check-only | Read-only status checks | + ### Git Workflow #### `git-sync.md` diff --git a/.claude/commands/repo-maintenance.md b/.claude/commands/repo-maintenance.md new file mode 100644 index 00000000..5042e6ca --- /dev/null +++ b/.claude/commands/repo-maintenance.md @@ -0,0 +1,436 @@ +--- +description: Comprehensive repository maintenance - run all health checks and updates +allowed-tools: Read, Write, Edit, Bash(git:*), Bash(gh:*), Bash(npm:*), Bash(node:*), Bash(jq:*), Bash(find:*), Bash(test:*), Bash(ls:*), Bash(grep:*), Bash(cat:*), Bash(echo:*), Bash(date:*), Bash(curl:*), Task, Skill +argument-hint: [--mode full|quick|check-only] [--skip CATEGORY] [--create-pr] +--- + +# Repository Maintenance Workflow + +このコマンドはリポジトリの包括的なメンテナンスを実行し、初期化や機能追加された内容を取り込みます。 + +## Overview + +以下のカテゴリのチェック・更新を順次実行します: + +1. **Environment** - 開発環境の健全性と更新 +2. **Setup** - CI/CD およびリポジトリ保護の設定 +3. **Cleanup** - リポジトリのクリーンアップ +4. **Discovery** - 新機能の発見と取り込み + +## Execution Modes + +| Mode | 説明 | 実行内容 | +| ---------- | ---------------------------------- | -------------------------------- | +| full | 全カテゴリの更新とチェックを実行 | 更新 + チェック + クリーンアップ | +| quick | 重要なチェックのみ実行(更新なし) | チェックのみ | +| check-only | 状態確認のみ(変更なし) | 読み取り専用のチェック | + +## Step 1: Parse Arguments and Initialize + +引数から設定を読み取る: + +- `--mode MODE`: 実行モード(デフォルト: `full`) +- `--skip CATEGORY`: スキップするカテゴリ(カンマ区切りで複数指定可) +- `--create-pr`: 更新があった場合にPRを作成 + +デフォルト設定: + +``` +MODE=full +SKIP_CATEGORIES=[] +CREATE_PR=false +``` + +初期化メッセージを表示: + +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +🔧 Repository Maintenance +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Mode: {MODE} +Skip: {SKIP_CATEGORIES or "None"} +Create PR: {CREATE_PR} + +Starting comprehensive maintenance... +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +``` + +## Step 2: Environment Category + +### 2.1 Container Health Check + +コンテナ環境の健全性を確認: + +実行内容: + +- 必須ツールの存在確認(git, node, npm, docker) +- Claude Code ツールの確認(claude) +- 開発ツールの確認(eslint, prettier) +- バージョン検証 + +これは `/container-health` コマンドと同等の処理を実行します。 + +結果を記録: + +- ✅ すべて正常 +- ⚠️ 一部に問題あり(詳細をリスト) +- ❌ 重大な問題あり(詳細をリスト) + +### 2.2 DevContainer Version Check + +config-base イメージのバージョンを確認: + +1. `.devcontainer/devcontainer.json` から現在のバージョンを取得 +2. GitHub API から最新バージョンを取得 +3. バージョンを比較 + +```bash +gh api repos/keito4/config/releases/latest --jq '.tag_name' +``` + +結果: + +- ✅ 最新バージョン使用中 +- ⚠️ 更新可能: v{current} → v{latest} + +### 2.3 DevContainer Update (full mode only) + +MODE が `full` かつ更新がある場合: + +`/config-base-sync-update` コマンドを実行するか確認してから実行。 + +**Note**: このステップは対話的確認を行う。自動実行の場合は `--yes` フラグで確認をスキップ。 + +### 2.4 Claude Code Update Check + +npm/global.json の Claude Code バージョンを確認: + +```bash +npm view @anthropic-ai/claude-code version +``` + +結果: + +- ✅ 最新バージョン +- ⚠️ 更新可能 + +MODE が `full` の場合は `/update-claude-code` コマンドを実行。 + +### 2.5 Claude Settings Sync Check (full mode only) + +このリポジトリが config リポジトリの場合のみ実行: + +`/sync-claude-settings` の実行を確認。 + +## Step 3: Setup Category + +### 3.1 Team Protection Setup (full mode only) + +GitHub リポジトリの保護ルールを確認・設定: + +実行内容: + +- ブランチ保護ルールの確認 +- 必須ステータスチェックの設定 +- レビュー要件の設定 +- Dependabot、脆弱性アラートの有効化 + +これは `/setup-team-protection` コマンドと同等の処理を実行します。 + +結果: + +- ✅ 保護ルール設定済み +- ⚠️ 未設定の保護ルールあり(詳細をリスト) +- 🔧 設定を適用 + +### 3.2 Husky Setup Check + +Git hooks(pre-commit)の設定状況を確認: + +実行内容: + +- Husky のインストール状況確認 +- pre-commit フックの存在確認 +- commitlint の設定確認 +- lint-staged の設定確認 + +これは `/setup-husky` コマンドと同等の処理を実行します。 + +結果: + +- ✅ Husky 設定済み +- ⚠️ Husky 未設定 → セットアップを提案 +- 📝 設定内容: pre-commit, commit-msg + +### 3.3 Pre-PR Checklist Validation + +PR 作成前のチェック項目を検証: + +実行内容: + +- lint、format、test の実行可否確認 +- CI ワークフローの存在確認 +- PR テンプレートの存在確認 + +これは `/pre-pr-checklist` コマンドの設定確認と同等の処理を実行します。 + +結果: + +- ✅ すべてのチェック項目が設定済み +- ⚠️ 不足している項目あり(詳細をリスト) + +## Step 4: Cleanup Category + +### 4.1 Branch Cleanup + +ブランチの状態を確認: + +実行内容: + +- マージ済みブランチの検出 +- 古いブランチ(30日以上)の検出 +- 削除されたリモートブランチの検出 + +これは `/branch-cleanup --dry-run` コマンドと同等の処理を実行します。 + +結果: + +- 🗑️ 削除候補: X ブランチ + - マージ済み: Y + - 古いブランチ: Z + +MODE が `full` の場合: + +- 対話的に削除を確認 +- または `--yes` フラグで自動削除 + +### 4.2 Git Repository Cleanup + +Git リポジトリのクリーンアップ: + +```bash +git gc --auto +git prune +``` + +## Step 5: Discovery Category (full mode only) + +### 5.1 Config Contribution Discovery + +config リポジトリから取り込み可能な新機能を発見: + +実行内容: + +- 新しいコマンドの検出 +- 新しいワークフローの検出 +- 推奨設定の更新確認 + +これは `/config-contribution-discover` コマンドと同等の処理を実行します。 + +結果: + +- 🆕 新機能: X 件 +- 📝 更新推奨: Y 件 + +## Step 6: Generate Summary Report + +全ステップの結果をまとめたレポートを生成: + +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +📋 Maintenance Summary Report +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +## Environment (1/4) +├── Container Health: ✅ Healthy (Score: 95/100) +├── DevContainer: ⚠️ Update available (v1.13.1 → v1.15.0) +├── Claude Code: ✅ Up to date +└── Claude Settings: ✅ Synced + +## Setup (2/4) +├── Team Protection: ✅ Branch protection enabled +├── Husky: ✅ Git hooks configured +└── Pre-PR Checklist: ✅ CI workflow exists + +## Cleanup (3/4) +├── Branches: 🗑️ 8 merged branches can be deleted +└── Git GC: ✅ Repository optimized + +## Discovery (4/4) +└── New Features: 🆕 2 new commands available + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +## Overall Health Score: 82/100 + +## Action Items (Priority Order) + +### 🔴 Immediate (Setup) +1. Configure branch protection rules + Run: /setup-team-protection +2. Setup Git hooks (Husky) + Run: /setup-husky + +### 🟡 Soon (Updates) +3. Update DevContainer to v1.15.0 + Run: /config-base-sync-update + +### 🟢 Recommended (Maintenance) +4. Delete 8 merged branches + Run: /branch-cleanup +5. Review 2 new config features + Run: /config-contribution-discover + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +``` + +## Step 7: Create PR (Optional) + +`--create-pr` が指定されており、かつ変更がある場合: + +### 7.1 Check for Changes + +```bash +git status --porcelain +``` + +変更がない場合: + +- "No changes to commit. Skipping PR creation." +- 終了 + +### 7.2 Create Branch + +```bash +git checkout -b maintenance/$(date +%Y%m%d) +``` + +### 7.3 Commit Changes + +```bash +git add -A +git commit -m "chore: repository maintenance $(date +%Y-%m-%d) + +## Changes +- [List of changes from each category] + +## Health Score +- Before: X/100 +- After: Y/100 + +🤖 Generated with [Claude Code](https://claude.com/claude-code) + +Co-Authored-By: Claude " +``` + +### 7.4 Push and Create PR + +```bash +git push -u origin maintenance/$(date +%Y%m%d) + +gh pr create \ + --base main \ + --title "chore: Repository maintenance $(date +%Y-%m-%d)" \ + --body "$(cat <<'EOF' +## Summary + +Automated repository maintenance performed on $(date +%Y-%m-%d). + +## Changes + +### Environment +- [List changes] + +### Setup +- [List changes] + +### Cleanup +- [List changes] + +### Discovery +- [List changes] + +## Health Score +- Before: X/100 +- After: Y/100 + +## Checklist +- [ ] CI passes +- [ ] No breaking changes +- [ ] Review action items + +🤖 Generated with [Claude Code](https://claude.com/claude-code) +EOF +)" +``` + +## Step 8: Final Report + +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +✅ Repository Maintenance Complete +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Mode: {MODE} +Duration: {elapsed_time} +Health Score: {score}/100 + +Categories Processed: +✅ Environment: {status} +✅ Setup: {status} +✅ Cleanup: {status} +✅ Discovery: {status} + +{if PR created} +PR Created: {PR_URL} +{endif} + +Next Steps: +1. Review the summary report above +2. Address action items by priority +3. {if PR created} Review and merge the PR {endif} + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Run this command regularly to maintain repository health: + /repo-maintenance --mode quick # Quick daily check + /repo-maintenance --mode full # Weekly full maintenance +``` + +--- + +## Progress Reporting + +各ステップの進捗を報告: + +- ✅ Step N: [完了した操作] +- 🔄 Step N: [実行中の操作] +- ⏭️ Step N: [スキップ(理由)] +- ❌ Step N: [失敗 - 理由] + +## Error Handling + +エラー発生時: + +1. 具体的なエラー内容を報告 +2. 可能な限り次のステップに進む(致命的エラー以外) +3. 最終レポートにエラーを含める +4. 修正方法を提案 + +## Related Commands + +このコマンドは以下のコマンドを内部的に呼び出します: + +| カテゴリ | コマンド | 説明 | +| ----------- | ------------------------------- | ----------------------- | +| Environment | `/container-health` | コンテナ健全性 | +| Environment | `/config-base-sync-check` | DevContainer バージョン | +| Environment | `/config-base-sync-update` | DevContainer 更新 | +| Environment | `/update-claude-code` | Claude Code 更新 | +| Environment | `/sync-claude-settings` | Claude 設定同期 | +| Setup | `/setup-team-protection` | GitHub保護ルール設定 | +| Setup | `/setup-husky` | Git hooks設定 | +| Setup | `/pre-pr-checklist` | PR前チェックリスト | +| Cleanup | `/branch-cleanup` | ブランチクリーンアップ | +| Discovery | `/config-contribution-discover` | 新機能発見 |