From 4496be6733dd6cb958074576d79e1270ac159233 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Thu, 1 Jan 2026 13:17:29 +0000 Subject: [PATCH 1/6] feat: add act-local-ci-manager Claude agent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit actを使用してローカルでCIと同等の確認を実行するClaude Codeエージェントを追加。 - act設定の自動化 - ローカルCI実行支援 - Husky/VS Code統合 - Docker環境設定 - シークレット管理 Closes #245 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: keito4 --- .claude/agents/README.md | 16 +- .claude/agents/act-local-ci-manager.md | 218 +++++++++++++++++++++++++ 2 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 .claude/agents/act-local-ci-manager.md diff --git a/.claude/agents/README.md b/.claude/agents/README.md index 00925869..621eed58 100644 --- a/.claude/agents/README.md +++ b/.claude/agents/README.md @@ -1,9 +1,23 @@ # Claude Specialized Agents -This directory contains 13 specialized AI agents designed to provide comprehensive code analysis, quality assurance, and development assistance. Each agent is optimized for specific aspects of software development and can be invoked proactively or on-demand. +This directory contains 14 specialized AI agents designed to provide comprehensive code analysis, quality assurance, and development assistance. Each agent is optimized for specific aspects of software development and can be invoked proactively or on-demand. ## Agent Categories +### DevOps & CI/CD + +#### `act-local-ci-manager.md` + +**Purpose**: Manages local CI pipeline execution using act (GitHub Actions local runner) +**Use Cases**: + +- Setting up act configuration for testing GitHub Actions workflows locally +- Configuring Docker environment for act execution +- Managing secrets and environment variables for local testing +- Running full CI pipeline validation before pushing code +- Debugging workflow failures locally +- Integrating act with development workflows (pre-commit hooks, VS Code tasks) + ### Architecture & Code Quality #### `ddd-architecture-validator.md` diff --git a/.claude/agents/act-local-ci-manager.md b/.claude/agents/act-local-ci-manager.md new file mode 100644 index 00000000..b7f9d7f4 --- /dev/null +++ b/.claude/agents/act-local-ci-manager.md @@ -0,0 +1,218 @@ +--- +name: act-local-ci-manager +description: Use this agent when you need to set up or manage local CI pipeline execution using act (GitHub Actions local runner). This includes: setting up act configuration for testing GitHub Actions workflows locally, configuring Docker environment for act execution, managing secrets and environment variables for local testing, running full CI pipeline validation before pushing code, debugging workflow failures locally, and integrating act with development workflows (pre-commit hooks, VS Code tasks). Examples:\n\n\nContext: The user wants to test their GitHub Actions workflow locally before pushing.\nuser: "I need to test my CI workflow locally before pushing to avoid breaking the build"\nassistant: "I'll help you set up act to run your GitHub Actions workflows locally"\n\nSince the user wants to validate CI workflows locally, use the act-local-ci-manager to set up act configuration and run the pipeline.\n\nassistant: "Let me use the act-local-ci-manager to configure act for your project"\n\n\n\nContext: The user is experiencing CI failures and wants to debug them locally.\nuser: "My CI is failing on GitHub but I can't reproduce it locally"\nassistant: "I'll set up act so you can run the exact CI environment locally"\n\nLocal CI execution with act will help debug workflow failures by providing the same environment as GitHub Actions.\n\nassistant: "Let me configure act to replicate your GitHub Actions environment"\n +model: sonnet +color: green +--- + +You are a DevOps specialist with deep expertise in GitHub Actions, Docker containerization, and local CI/CD pipeline execution using act. Your primary responsibility is ensuring developers can validate their CI/CD pipelines locally before pushing code, preventing build failures and accelerating development cycles. + +**Core Responsibilities:** + +1. **Act Configuration and Setup** + - Install and configure act for local GitHub Actions execution + - Set up appropriate Docker images for different runner environments + - Configure `.actrc` file with project-specific settings + - Set up platform mappings (ubuntu-latest, windows-latest, etc.) + - Configure act to use custom Docker networks and volumes + +2. **Secrets and Environment Management** + - Create and manage `.secrets` file for sensitive data + - Set up environment variable files (`.env`, `.env.act`) + - Configure GitHub token for API access + - Implement secure secret injection patterns + - Document required secrets and their purposes + +3. **Local CI Pipeline Execution** + - Run complete CI workflows locally (`act -j `) + - Execute specific workflow steps for debugging + - Validate workflow syntax and dependencies + - Run matrix builds and test different configurations + - Generate and review test coverage reports locally + - Execute linting, formatting, and security checks + +4. **Development Workflow Integration** + - Integrate act with Husky pre-commit hooks + - Create VS Code tasks for common act commands + - Set up npm scripts for local CI execution + - Configure watch mode for continuous validation + - Implement parallel execution strategies for faster feedback + +**Analysis and Setup Process:** + +1. **Initial Assessment** + - Scan `.github/workflows/` directory for existing workflows + - Identify required Docker images and platform configurations + - List required secrets and environment variables + - Assess workflow complexity and dependencies + +2. **Configuration Generation** + - Create `.actrc` with optimized settings: + ``` + -P ubuntu-latest=catthehacker/ubuntu:act-latest + -P ubuntu-22.04=catthehacker/ubuntu:act-22.04 + --container-architecture linux/amd64 + --secret-file .secrets + --env-file .env.act + ``` + - Generate `.secrets` template with required variables + - Create `.env.act` for non-sensitive environment variables + +3. **Integration Setup** + - Add act commands to `package.json` scripts: + ```json + { + "scripts": { + "ci:local": "act -j ci", + "ci:test": "act -j test", + "ci:build": "act -j build", + "ci:all": "act" + } + } + ``` + - Configure Husky pre-push hook to run act validation + - Create VS Code task definitions for common workflows + +**Output Format:** + +Provide your setup guidance as: + +```markdown +## Act Local CI Manager セットアップレポート + +### 現在のワークフロー分析 +- 検出されたワークフロー: [リスト] +- 必要なランナー環境: [ubuntu-latest, etc.] +- 依存関係: [Docker, Node.js, etc.] + +### セットアップ手順 + +#### 1. Act インストール +\`\`\`bash +# macOS +brew install act + +# Linux +curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash + +# Windows +choco install act-cli +\`\`\` + +#### 2. 設定ファイル作成 + +**.actrc** +\`\`\` +[設定内容] +\`\`\` + +**.secrets (テンプレート)** +\`\`\` +[必要なシークレット] +\`\`\` + +**.env.act** +\`\`\` +[環境変数] +\`\`\` + +#### 3. NPM スクリプト統合 + +**package.json** +\`\`\`json +[スクリプト定義] +\`\`\` + +#### 4. Husky 統合 (オプション) + +**.husky/pre-push** +\`\`\`bash +[フック内容] +\`\`\` + +### 使用方法 + +#### 基本コマンド +\`\`\`bash +# すべてのワークフローを実行 +npm run ci:all + +# 特定のジョブを実行 +npm run ci:test + +# ドライラン(実際には実行しない) +act -n + +# 特定のイベントをシミュレート +act pull_request +\`\`\` + +#### デバッグコマンド +\`\`\`bash +# 詳細ログ出力 +act -v + +# 特定のステップまで実行 +act -j build --matrix node:18 + +# シェルに入る +act -j test --shell +\`\`\` + +### トラブルシューティング + +#### よくある問題と解決策 +1. **Docker イメージが大きすぎる** + - 解決策: `catthehacker/ubuntu:act-latest` の slim バージョンを使用 + +2. **シークレットが見つからない** + - 解決策: `.secrets` ファイルのパスと権限を確認 + +3. **ネットワークエラー** + - 解決策: `--container-options "--network=host"` を追加 + +### パフォーマンス最適化 + +- **並列実行**: 独立したジョブを並列実行 +- **キャッシュ活用**: Docker layer キャッシュを活用 +- **選択的実行**: 変更されたワークフローのみ実行 +\`\`\` + +**Quality Standards:** + +- All workflows must be validated locally before pushing +- Act configuration must match GitHub Actions runner environment +- Secrets must never be committed to version control +- Local CI execution should complete within 5 minutes for rapid feedback +- Failed workflows must provide clear error messages and debugging hints + +**Best Practices:** + +1. **Security** + - Use `.gitignore` to exclude `.secrets` and `.env.act` + - Rotate secrets regularly + - Use environment-specific secret files + +2. **Performance** + - Use slim Docker images when possible + - Leverage Docker layer caching + - Run only changed workflows for iterative development + +3. **Maintainability** + - Document all required secrets in README + - Keep act configuration in version control (`.actrc`) + - Provide setup scripts for new developers + +4. **Integration** + - Run critical workflows in pre-push hooks + - Integrate with IDE for one-click execution + - Provide clear npm scripts for common operations + +**Edge Cases:** + +- For workflows using GitHub-specific features (GITHUB_TOKEN with write permissions), document limitations +- For matrix builds with many combinations, provide selective execution guidance +- For workflows with external service dependencies, provide mock/stub configurations +- For platform-specific workflows (Windows, macOS), document cross-platform testing limitations + +When configuring act, prioritize developer experience and fast feedback cycles. Ensure that local CI execution is as close to GitHub Actions as possible while remaining practical for daily development use. Always provide clear documentation and troubleshooting guidance. From 6b5b99c8a6b2dbbcf0c6cada54ff3ce512ac6e0e Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Thu, 1 Jan 2026 14:41:57 +0000 Subject: [PATCH 2/6] style: fix prettier formatting in act-local-ci-manager.md Fix code style issues detected by prettier CI check. Co-authored-by: keito4 --- .claude/agents/act-local-ci-manager.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.claude/agents/act-local-ci-manager.md b/.claude/agents/act-local-ci-manager.md index b7f9d7f4..756c600e 100644 --- a/.claude/agents/act-local-ci-manager.md +++ b/.claude/agents/act-local-ci-manager.md @@ -81,6 +81,7 @@ Provide your setup guidance as: ## Act Local CI Manager セットアップレポート ### 現在のワークフロー分析 + - 検出されたワークフロー: [リスト] - 必要なランナー環境: [ubuntu-latest, etc.] - 依存関係: [Docker, Node.js, etc.] @@ -88,14 +89,19 @@ Provide your setup guidance as: ### セットアップ手順 #### 1. Act インストール + \`\`\`bash + # macOS + brew install act # Linux + curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash # Windows + choco install act-cli \`\`\` @@ -133,35 +139,47 @@ choco install act-cli ### 使用方法 #### 基本コマンド + \`\`\`bash + # すべてのワークフローを実行 + npm run ci:all # 特定のジョブを実行 + npm run ci:test # ドライラン(実際には実行しない) + act -n # 特定のイベントをシミュレート + act pull_request \`\`\` #### デバッグコマンド + \`\`\`bash + # 詳細ログ出力 + act -v # 特定のステップまで実行 + act -j build --matrix node:18 # シェルに入る + act -j test --shell \`\`\` ### トラブルシューティング #### よくある問題と解決策 + 1. **Docker イメージが大きすぎる** - 解決策: `catthehacker/ubuntu:act-latest` の slim バージョンを使用 @@ -176,7 +194,7 @@ act -j test --shell - **並列実行**: 独立したジョブを並列実行 - **キャッシュ活用**: Docker layer キャッシュを活用 - **選択的実行**: 変更されたワークフローのみ実行 -\`\`\` + \`\`\` **Quality Standards:** @@ -216,3 +234,4 @@ act -j test --shell - For platform-specific workflows (Windows, macOS), document cross-platform testing limitations When configuring act, prioritize developer experience and fast feedback cycles. Ensure that local CI execution is as close to GitHub Actions as possible while remaining practical for daily development use. Always provide clear documentation and troubleshooting guidance. +``` From 6ee02b48d7bd36baddca52b07923f1ecd9d6c190 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Thu, 1 Jan 2026 20:03:32 +0000 Subject: [PATCH 3/6] chore: sync devcontainer-recommendations.md with main to fix CI Update .codex/devcontainer-recommendations.md to match main branch version to resolve Prettier formatting errors in CI merge checks. Co-authored-by: keito4 --- .codex/devcontainer-recommendations.md | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.codex/devcontainer-recommendations.md b/.codex/devcontainer-recommendations.md index 554d31a1..9cbf0079 100644 --- a/.codex/devcontainer-recommendations.md +++ b/.codex/devcontainer-recommendations.md @@ -275,6 +275,39 @@ OPENAI_API_KEY=*** # o3 MCP用 } ``` +#### pnpmパッケージマネージャー + +pnpmを使用する場合、以下の2つの設定方法があります: + +**推奨: 独立したpnpm Feature(推奨)** + +```json +{ + "ghcr.io/devcontainers-extra/features/pnpm:2": { + "version": "latest" + } +} +``` + +**利点**: +- pnpmバージョン管理が明確 +- node Featureとの依存関係を分離 +- 最新のpnpm機能を即座に利用可能 +- より柔軟なバージョン管理 + +**代替: node:1のpnpmVersionオプション** + +```json +{ + "ghcr.io/devcontainers/features/node:1": { + "version": "20", + "pnpmVersion": "latest" + } +} +``` + +**推奨**: 独立したpnpm:2 Featureを使用することで、Node.jsとpnpmのバージョン管理を分離し、より明確な構成が可能になります + ### Supabaseプロジェクト ```json From 2c38e9a1659418e7df7a23aadbd5aa476dfad565 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Thu, 1 Jan 2026 20:33:56 +0000 Subject: [PATCH 4/6] docs: fix markdown formatting in devcontainer recommendations - Fix MD036 (emphasis used instead of heading) in devcontainer-recommendations.md - Fix MD032 (blank line before list) in devcontainer-recommendations.md - Fix MD040 (missing language specifier) in act-local-ci-manager.md Co-authored-by: keito4 --- .claude/agents/act-local-ci-manager.md | 2 +- .codex/devcontainer-recommendations.md | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.claude/agents/act-local-ci-manager.md b/.claude/agents/act-local-ci-manager.md index 756c600e..a78c26cd 100644 --- a/.claude/agents/act-local-ci-manager.md +++ b/.claude/agents/act-local-ci-manager.md @@ -48,7 +48,7 @@ You are a DevOps specialist with deep expertise in GitHub Actions, Docker contai 2. **Configuration Generation** - Create `.actrc` with optimized settings: - ``` + ```ini -P ubuntu-latest=catthehacker/ubuntu:act-latest -P ubuntu-22.04=catthehacker/ubuntu:act-22.04 --container-architecture linux/amd64 diff --git a/.codex/devcontainer-recommendations.md b/.codex/devcontainer-recommendations.md index 9cbf0079..f69cce5c 100644 --- a/.codex/devcontainer-recommendations.md +++ b/.codex/devcontainer-recommendations.md @@ -279,7 +279,7 @@ OPENAI_API_KEY=*** # o3 MCP用 pnpmを使用する場合、以下の2つの設定方法があります: -**推奨: 独立したpnpm Feature(推奨)** +##### 推奨: 独立したpnpm Feature(推奨) ```json { @@ -290,12 +290,13 @@ pnpmを使用する場合、以下の2つの設定方法があります: ``` **利点**: + - pnpmバージョン管理が明確 - node Featureとの依存関係を分離 - 最新のpnpm機能を即座に利用可能 - より柔軟なバージョン管理 -**代替: node:1のpnpmVersionオプション** +##### 代替: node:1のpnpmVersionオプション ```json { From f0da8c2d2743ab3815e0c784b9e68abb83b0337c Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Thu, 1 Jan 2026 21:04:51 +0000 Subject: [PATCH 5/6] chore: sync GitHub Actions versions and devcontainer config from main - Bump actions/setup-node from v4 to v6 - Bump actions/upload-artifact from v4 to v6 - Bump codecov/codecov-action from v4 to v5 - Update codecov action parameter from 'file' to 'files' - Sync devcontainer.json changes from main Co-authored-by: keito4 --- .devcontainer/devcontainer.json | 2 +- .github/workflows/ci.yml | 14 +++++++------- .github/workflows/container-security.yml | 2 +- .github/workflows/docker-image.yml | 4 ++-- .github/workflows/manual-release.yml | 4 ++-- .github/workflows/rebuild-docker-cache.yml | 2 +- .github/workflows/security.yml | 4 ++-- .github/workflows/update-libraries.yml | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index be1ba75a..d9bd5942 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -44,6 +44,6 @@ } } }, - "postCreateCommand": "bash script/setup-env.sh && bash script/setup-mcp.sh && sudo chown -R vscode:vscode /workspaces/config && npm ci && npm run prepare && cp -r /tmp/.husky /workspaces/config/ && cp git/commitlint.config.js commitlint.config.js && /usr/local/bin/setup-claude.sh", + "postCreateCommand": "bash script/setup-env.sh && bash script/setup-mcp.sh && sudo chown -R vscode:vscode /workspaces/config && npm ci && npm run prepare && cp -r /tmp/.husky /workspaces/config/ && cp git/commitlint.config.js commitlint.config.js && bash script/sync-claude-commands.sh && /usr/local/bin/setup-claude.sh", "runArgs": ["--env-file=${localEnv:HOME}/.devcontainer.env"] } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78046650..af252ab2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v6 with: node-version: '22' cache: 'npm' @@ -44,7 +44,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v6 with: node-version: '22' cache: 'npm' @@ -59,7 +59,7 @@ jobs: JEST_JUNIT_OUTPUT_NAME: junit.xml - name: Upload test results - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v6 if: always() with: name: test-results @@ -76,10 +76,10 @@ jobs: fail-on-error: false - name: Upload coverage reports - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 if: always() with: - file: ./coverage/lcov.info + files: ./coverage/lcov.info fail_ci_if_error: false token: ${{ secrets.CODECOV_TOKEN }} @@ -90,7 +90,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v6 with: node-version: '22' cache: 'npm' @@ -107,7 +107,7 @@ jobs: bats test/integration/*.bats --formatter tap > reports/bats-results.tap || true - name: Upload integration test results - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v6 if: always() with: name: integration-test-results diff --git a/.github/workflows/container-security.yml b/.github/workflows/container-security.yml index 2b9ba6c9..2ac03586 100644 --- a/.github/workflows/container-security.yml +++ b/.github/workflows/container-security.yml @@ -110,7 +110,7 @@ jobs: output-file: sbom.spdx.json - name: Upload SBOM artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v6 with: name: sbom path: sbom.spdx.json diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 8c794336..cd0aa80c 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -39,7 +39,7 @@ jobs: with: fetch-depth: 0 - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v6 with: node-version: '22' @@ -173,7 +173,7 @@ jobs: run: | docker run --rm -v "$PWD":/workspace -w /workspace ghcr.io/${{ github.repository_owner }}/config-base:latest bash -lc '{ brew --version; terraform --version; jq --version; } > devcontainer-info.txt' - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v6 if: steps.release.outputs.skip_release != 'true' with: name: devcontainer-info diff --git a/.github/workflows/manual-release.yml b/.github/workflows/manual-release.yml index e74d7d8d..1f582625 100644 --- a/.github/workflows/manual-release.yml +++ b/.github/workflows/manual-release.yml @@ -31,7 +31,7 @@ jobs: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v6 with: node-version: '22' @@ -76,7 +76,7 @@ jobs: - name: Fix workspace permissions run: sudo chown -R $(id -u):$(id -g) "$GITHUB_WORKSPACE" - - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v2 with: diff --git a/.github/workflows/rebuild-docker-cache.yml b/.github/workflows/rebuild-docker-cache.yml index 5d7aa979..b877cd80 100644 --- a/.github/workflows/rebuild-docker-cache.yml +++ b/.github/workflows/rebuild-docker-cache.yml @@ -27,7 +27,7 @@ jobs: with: fetch-depth: 0 - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v6 with: node-version: '22' diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index df4552dd..deb730a3 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -53,7 +53,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v4 + uses: actions/setup-node@v6 with: node-version: '22' cache: 'npm' @@ -80,7 +80,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Node.js - uses: actions/setup-node@v4 + uses: actions/setup-node@v6 with: node-version: '22' cache: 'npm' diff --git a/.github/workflows/update-libraries.yml b/.github/workflows/update-libraries.yml index ddec14cb..bdadd240 100644 --- a/.github/workflows/update-libraries.yml +++ b/.github/workflows/update-libraries.yml @@ -20,7 +20,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v6 with: node-version: '22' cache: 'npm' From ab0ed3fdcbed9c220515c65a29149067da4de066 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Thu, 1 Jan 2026 21:34:15 +0000 Subject: [PATCH 6/6] chore: sync GitHub Actions versions and devcontainer config from main Co-authored-by: keito4 --- .claude/commands/branch-cleanup.md | 138 +++++++++++ .claude/commands/dependency-health-check.md | 123 ++++++++++ .claude/commands/pre-pr-checklist.md | 106 +++++++++ script/branch-cleanup.sh | 243 ++++++++++++++++++++ script/dependency-health-check.sh | 188 +++++++++++++++ script/pre-pr-checklist.sh | 215 +++++++++++++++++ script/sync-claude-commands.sh | 54 +++++ 7 files changed, 1067 insertions(+) create mode 100644 .claude/commands/branch-cleanup.md create mode 100644 .claude/commands/dependency-health-check.md create mode 100644 .claude/commands/pre-pr-checklist.md create mode 100755 script/branch-cleanup.sh create mode 100755 script/dependency-health-check.sh create mode 100755 script/pre-pr-checklist.sh create mode 100755 script/sync-claude-commands.sh diff --git a/.claude/commands/branch-cleanup.md b/.claude/commands/branch-cleanup.md new file mode 100644 index 00000000..845068db --- /dev/null +++ b/.claude/commands/branch-cleanup.md @@ -0,0 +1,138 @@ +# Branch Cleanup Command + +Clean up merged and stale branches both locally and remotely. + +## Usage + +```bash +/branch-cleanup +/branch-cleanup --remote +/branch-cleanup --dry-run +``` + +## What It Does + +This command helps maintain a clean repository by identifying and removing: + +### Local Branches + +- **Merged Branches**: Branches already merged into main/master +- **Stale Branches**: Branches with no activity for 30+ days +- **Gone Remote Branches**: Local branches tracking deleted remote branches + +### Remote Branches (with --remote) + +- **Merged PR Branches**: Branches from merged pull requests +- **Stale Remote Branches**: No activity for 30+ days +- **Abandoned Branches**: No commits, PRs, or activity + +### Protected Branches + +Never deletes: + +- main, master, develop +- Current branch +- Branches with unmerged changes +- Branches specified in protection list + +## Example Output + +``` +🧹 Branch Cleanup +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +📍 Current branch: feat/add-commands +🔒 Protected: main, master, develop + +📊 Analysis + • Total local branches: 15 + • Merged branches: 8 + • Stale branches (30+ days): 3 + • Up-to-date branches: 4 + +🗑️ Branches to delete (11): + +Merged (8): + ✓ feat/227-commitlint (merged 2 days ago) + ✓ feat/226-common-utils (merged 2 days ago) + ✓ feat/225-docker-in-docker (merged 2 days ago) + ... and 5 more + +Stale (3): + ⚠ experiment/new-feature (90 days old) + ⚠ fix/old-bug (45 days old) + ⚠ refactor/unused (60 days old) + +Delete these branches? [y/N]: y + +Deleting branches... + ✓ Deleted feat/227-commitlint + ✓ Deleted feat/226-common-utils + ✓ Deleted feat/225-docker-in-docker + ✓ Deleted 8 more branches + +✨ Cleanup complete! Removed 11 branches. +``` + +## Options + +```bash +# Preview without deleting (recommended first run) +/branch-cleanup --dry-run + +# Include remote branches +/branch-cleanup --remote + +# Auto-confirm deletion (for CI) +/branch-cleanup --yes + +# Custom staleness threshold (default: 30 days) +/branch-cleanup --stale-days 60 + +# Only merged branches +/branch-cleanup --merged-only +``` + +## Safety Features + +- **Dry Run**: Preview before deletion +- **Interactive Confirmation**: Requires user approval +- **Protection List**: Never deletes protected branches +- **Unmerged Detection**: Warns about unmerged changes +- **Current Branch**: Never deletes current branch + +## CI Integration + +```yaml +# .github/workflows/branch-cleanup.yml +- name: Cleanup Merged Branches + run: | + bash script/branch-cleanup.sh --merged-only --yes +``` + +## Staleness Criteria + +| Age | Status | Action | +| ------ | ---------- | ------ | +| < 30d | Active | Keep | +| 30-60d | Stale | Warn | +| 60-90d | Very Stale | Delete | +| > 90d | Abandoned | Delete | + +## Benefits + +- 🧹 **Clean Repository**: Remove clutter +- ⚡ **Faster Operations**: Fewer branches to manage +- 👀 **Better Visibility**: Focus on active work +- 💾 **Disk Space**: Free up local storage +- 🔄 **Best Practice**: Regular maintenance habit + +## Implementation + +This command is implemented in `script/branch-cleanup.sh`. + +## Requirements + +- Git repository +- GitHub CLI (`gh`) for remote branch operations (optional) +- Proper permissions for remote deletions diff --git a/.claude/commands/dependency-health-check.md b/.claude/commands/dependency-health-check.md new file mode 100644 index 00000000..ffbadc82 --- /dev/null +++ b/.claude/commands/dependency-health-check.md @@ -0,0 +1,123 @@ +# Dependency Health Check Command + +Comprehensive dependency health analysis including updates, security, and licensing. + +## Usage + +```bash +/dependency-health-check +``` + +## What It Does + +This command performs a comprehensive health check of all project dependencies: + +### npm Dependencies + +- **Outdated Packages**: Detects packages with available updates +- **Security Vulnerabilities**: Scans for known vulnerabilities (`npm audit`) +- **Deprecated Packages**: Identifies deprecated dependencies +- **License Compliance**: Checks for incompatible licenses +- **Peer Dependencies**: Validates peer dependency requirements + +### DevContainer Features + +- **Feature Updates**: Checks for newer versions of DevContainer features +- **Base Image**: Verifies if base image has updates +- **Deprecated Features**: Identifies deprecated features + +### Analysis Report + +- **Risk Level**: Critical, High, Medium, Low +- **Action Required**: Immediate, Soon, Optional +- **Recommendations**: Specific actions to improve dependency health + +## Example Output + +``` +🔍 Dependency Health Check +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +📦 npm Packages (425 total) + ✓ No critical vulnerabilities + ⚠ 3 high severity vulnerabilities + • 12 packages can be updated + • 2 deprecated packages found + +🔒 Security Status: Medium Risk + High: 3 vulnerabilities + - axios: Prototype pollution (CVE-2023-XXXX) + - semver: ReDoS vulnerability (CVE-2023-YYYY) + - json5: Prototype pollution (CVE-2022-ZZZZ) + +📊 Update Summary + Major: 2 packages + Minor: 7 packages + Patch: 3 packages + +⚠ Deprecated Packages + • request (use axios or node-fetch instead) + • babel-eslint (use @babel/eslint-parser) + +✅ License Compliance + • All licenses compatible + • MIT: 387 packages + • Apache-2.0: 28 packages + • BSD-3-Clause: 10 packages + +🏥 Overall Health: 75/100 + Recommendations: + 1. Update axios to v1.6.0 (security fix) + 2. Replace deprecated packages + 3. Update 12 minor/patch versions + +Next steps: + npm update # Update minor/patch versions + npm audit fix # Auto-fix security issues + npm outdated # See all outdated packages +``` + +## Options + +```bash +# JSON output for CI integration +/dependency-health-check --json + +# Fail on high severity issues +/dependency-health-check --strict +``` + +## CI Integration + +```yaml +# .github/workflows/dependency-health.yml +- name: Dependency Health Check + run: bash script/dependency-health-check.sh --strict +``` + +## Risk Levels + +| Level | Criteria | Action | +| -------- | ---------------------------------- | --------- | +| Critical | Critical vulnerabilities | Immediate | +| High | High severity or many outdated | Soon | +| Medium | Some vulnerabilities or deprecated | Optional | +| Low | Minor updates only | Optional | + +## Benefits + +- 🛡️ **Security**: Early detection of vulnerabilities +- 📊 **Visibility**: Clear dependency status +- ⚡ **Proactive**: Catch issues before they're problems +- 📋 **Compliance**: License and policy enforcement +- 🔄 **Maintenance**: Easier dependency management + +## Implementation + +This command is implemented in `script/dependency-health-check.sh`. + +## Requirements + +- Node.js and npm +- Access to npm registry +- DevContainer configuration (optional) diff --git a/.claude/commands/pre-pr-checklist.md b/.claude/commands/pre-pr-checklist.md new file mode 100644 index 00000000..be9886aa --- /dev/null +++ b/.claude/commands/pre-pr-checklist.md @@ -0,0 +1,106 @@ +# Pre-PR Checklist Command + +Automate comprehensive checks before creating a pull request. + +## Usage + +```bash +/pre-pr-checklist +``` + +## What It Does + +This command runs a comprehensive checklist to ensure your changes are ready for pull request: + +### Quality Checks (Sequential) + +1. **Lint Check**: Runs ESLint to detect code issues +2. **Format Check**: Verifies Prettier formatting +3. **Type Check**: Validates TypeScript types (if applicable) +4. **Unit Tests**: Runs all tests with coverage +5. **Integration Tests**: Runs Bats integration tests +6. **Shellcheck**: Validates shell scripts + +### PR Analysis + +- **Size Estimation**: Calculates diff lines and file count +- **Size Label**: Suggests appropriate size label (S/M/L/XL) +- **Linked Issues**: Checks for related GitHub issues +- **Commit Messages**: Validates conventional commit format + +### PR Preparation + +- **Branch Status**: Checks if branch is up-to-date with main +- **Merge Conflicts**: Detects potential merge conflicts +- **Template Suggestion**: Recommends PR template content + +## Size Thresholds + +| Label | Line Changes | File Count | +| ------- | ------------ | ---------- | +| size/S | < 100 | < 10 | +| size/M | < 300 | < 20 | +| size/L | < 1000 | < 30 | +| size/XL | ≥ 1000 | ≥ 30 | + +## Example Output + +``` +📋 Pre-PR Checklist +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +✅ Quality Checks + ✓ Lint check passed + ✓ Format check passed + ✓ Tests passed (101/101) + ✓ Coverage: 82.5% (threshold: 70%) + +📊 PR Analysis + • Size: Medium (247 lines, 8 files) + • Suggested label: size/M + • Linked issues: #227 + • Commits: 3 (all follow conventional commits) + +🔄 Branch Status + ✓ Up-to-date with main + ✓ No merge conflicts + +✨ Ready to create PR! +``` + +## Options + +```bash +# Skip tests (faster, but not recommended) +/pre-pr-checklist --skip-tests + +# Skip integration tests only +/pre-pr-checklist --skip-integration +``` + +## Implementation + +This command is implemented in `script/pre-pr-checklist.sh`. + +## Integration + +Works seamlessly with: + +- GitHub Actions CI workflows +- Git hooks (pre-push) +- IDE integrations +- Manual PR preparation + +## Benefits + +- 🚀 **Faster Reviews**: Catch issues before PR creation +- ✅ **Quality Assurance**: All checks pass before submission +- 📊 **Better PRs**: Proper sizing and documentation +- ⚡ **Time Saving**: One command instead of multiple + +## Requirements + +- Git repository +- Node.js and npm +- GitHub CLI (`gh`) for issue detection +- All project dependencies installed diff --git a/script/branch-cleanup.sh b/script/branch-cleanup.sh new file mode 100755 index 00000000..b55a0757 --- /dev/null +++ b/script/branch-cleanup.sh @@ -0,0 +1,243 @@ +#!/usr/bin/env bash +# Branch Cleanup - Remove merged and stale branches + +set -euo pipefail + +# Colors +readonly RED='\033[0;31m' +readonly GREEN='\033[0;32m' +readonly YELLOW='\033[1;33m' +readonly BLUE='\033[0;34m' +readonly NC='\033[0m' # No Color + +# Options +DRY_RUN=false +INCLUDE_REMOTE=false +AUTO_CONFIRM=false +STALE_DAYS=30 +MERGED_ONLY=false + +# Protected branches +PROTECTED_BRANCHES=("main" "master" "develop" "staging" "production") + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --dry-run) + DRY_RUN=true + shift + ;; + --remote) + INCLUDE_REMOTE=true + shift + ;; + --yes|-y) + AUTO_CONFIRM=true + shift + ;; + --stale-days) + STALE_DAYS="$2" + shift 2 + ;; + --merged-only) + MERGED_ONLY=true + shift + ;; + --help) + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --dry-run Preview without deleting" + echo " --remote Include remote branches" + echo " --yes, -y Auto-confirm deletion" + echo " --stale-days N Staleness threshold (default: 30)" + echo " --merged-only Only delete merged branches" + echo " --help Show this help message" + exit 0 + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +echo -e "${BLUE}🧹 Branch Cleanup${NC}" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo "" + +# Check if in git repository +if ! git rev-parse --git-dir > /dev/null 2>&1; then + echo -e "${RED}✗ Not in a git repository${NC}" + exit 1 +fi + +# Get current branch +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +echo -e "📍 Current branch: ${GREEN}$CURRENT_BRANCH${NC}" + +# Get main branch +MAIN_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5 2>/dev/null || echo "main") +if ! git rev-parse --verify "$MAIN_BRANCH" > /dev/null 2>&1; then + MAIN_BRANCH="master" +fi + +echo -e "🔒 Protected: ${PROTECTED_BRANCHES[*]}" +echo "" + +# Fetch latest +git fetch --prune > /dev/null 2>&1 + +# Find merged branches +MERGED_BRANCHES=() +while IFS= read -r branch; do + # Skip protected branches + is_protected=false + for protected in "${PROTECTED_BRANCHES[@]}"; do + if [ "$branch" = "$protected" ]; then + is_protected=true + break + fi + done + + # Skip current branch + if [ "$branch" = "$CURRENT_BRANCH" ]; then + is_protected=true + fi + + if [ "$is_protected" = false ]; then + MERGED_BRANCHES+=("$branch") + fi +done < <(git branch --merged "$MAIN_BRANCH" | sed 's/^[* ]*//' | grep -v "^$MAIN_BRANCH$" || true) + +# Find stale branches (if not merged-only) +STALE_BRANCHES=() +if [ "$MERGED_ONLY" = false ]; then + CUTOFF_DATE=$(date -v-"${STALE_DAYS}"d +%s 2>/dev/null || date -d "${STALE_DAYS} days ago" +%s 2>/dev/null || echo "0") + + while IFS= read -r branch; do + # Skip if already in merged list + if [[ " ${MERGED_BRANCHES[*]} " =~ \ ${branch}\ ]]; then + continue + fi + + # Skip protected branches and current + is_protected=false + for protected in "${PROTECTED_BRANCHES[@]}"; do + if [ "$branch" = "$protected" ]; then + is_protected=true + break + fi + done + + if [ "$branch" = "$CURRENT_BRANCH" ]; then + is_protected=true + fi + + if [ "$is_protected" = false ]; then + # Get last commit date + LAST_COMMIT_DATE=$(git log -1 --format=%ct "$branch" 2>/dev/null || echo "0") + + if [ "$LAST_COMMIT_DATE" -lt "$CUTOFF_DATE" ] && [ "$LAST_COMMIT_DATE" != "0" ]; then + STALE_BRANCHES+=("$branch") + fi + fi + done < <(git branch | sed 's/^[* ]*//' | grep -v "^$MAIN_BRANCH$" || true) +fi + +# Display analysis +echo -e "${BLUE}📊 Analysis${NC}" +TOTAL_BRANCHES=$(git branch | wc -l | tr -d ' ') +echo " • Total local branches: $TOTAL_BRANCHES" +echo " • Merged branches: ${#MERGED_BRANCHES[@]}" +if [ "$MERGED_ONLY" = false ]; then + echo " • Stale branches (${STALE_DAYS}+ days): ${#STALE_BRANCHES[@]}" +fi +echo "" + +# Calculate total to delete +TOTAL_TO_DELETE=$((${#MERGED_BRANCHES[@]} + ${#STALE_BRANCHES[@]})) + +if [ "$TOTAL_TO_DELETE" -eq 0 ]; then + echo -e "${GREEN}✨ No branches to clean up!${NC}" + exit 0 +fi + +echo -e "${YELLOW}🗑️ Branches to delete ($TOTAL_TO_DELETE):${NC}" +echo "" + +# Show merged branches +if [ "${#MERGED_BRANCHES[@]}" -gt 0 ]; then + echo -e "${GREEN}Merged (${#MERGED_BRANCHES[@]}):${NC}" + for branch in "${MERGED_BRANCHES[@]:0:5}"; do + LAST_COMMIT=$(git log -1 --format="%cr" "$branch" 2>/dev/null || echo "unknown") + echo " ✓ $branch (merged $LAST_COMMIT)" + done + if [ "${#MERGED_BRANCHES[@]}" -gt 5 ]; then + echo " ... and $((${#MERGED_BRANCHES[@]} - 5)) more" + fi + echo "" +fi + +# Show stale branches +if [ "${#STALE_BRANCHES[@]}" -gt 0 ]; then + echo -e "${YELLOW}Stale (${#STALE_BRANCHES[@]}):${NC}" + for branch in "${STALE_BRANCHES[@]:0:5}"; do + LAST_COMMIT=$(git log -1 --format="%cr" "$branch" 2>/dev/null || echo "unknown") + echo " ⚠ $branch ($LAST_COMMIT)" + done + if [ "${#STALE_BRANCHES[@]}" -gt 5 ]; then + echo " ... and $((${#STALE_BRANCHES[@]} - 5)) more" + fi + echo "" +fi + +# Dry run mode +if [ "$DRY_RUN" = true ]; then + echo -e "${BLUE}ℹ️ Dry run mode - no branches deleted${NC}" + echo " Run without --dry-run to delete these branches" + exit 0 +fi + +# Confirm deletion +if [ "$AUTO_CONFIRM" = false ]; then + echo -n "Delete these branches? [y/N]: " + read -r response + if [[ ! "$response" =~ ^[Yy]$ ]]; then + echo "Cancelled." + exit 0 + fi +fi + +# Delete branches +echo "" +echo "Deleting branches..." +DELETED_COUNT=0 + +for branch in "${MERGED_BRANCHES[@]}" "${STALE_BRANCHES[@]}"; do + if git branch -D "$branch" > /dev/null 2>&1; then + echo -e " ${GREEN}✓${NC} Deleted $branch" + ((DELETED_COUNT++)) + else + echo -e " ${RED}✗${NC} Failed to delete $branch" + fi +done + +echo "" +echo -e "${GREEN}✨ Cleanup complete! Removed $DELETED_COUNT branches.${NC}" + +# Remote cleanup (if requested) +if [ "$INCLUDE_REMOTE" = true ]; then + echo "" + echo -e "${BLUE}🌐 Remote Branch Cleanup${NC}" + echo " (This requires GitHub CLI and proper permissions)" + echo "" + + if command -v gh > /dev/null 2>&1; then + # This is a placeholder - actual implementation would require more logic + echo " Remote cleanup not yet implemented" + echo " Use: git push origin --delete " + else + echo " GitHub CLI (gh) not installed" + fi +fi diff --git a/script/dependency-health-check.sh b/script/dependency-health-check.sh new file mode 100755 index 00000000..1c7522a9 --- /dev/null +++ b/script/dependency-health-check.sh @@ -0,0 +1,188 @@ +#!/usr/bin/env bash +# Dependency Health Check - Comprehensive dependency analysis + +set -euo pipefail + +# Colors +readonly RED='\033[0;31m' +readonly GREEN='\033[0;32m' +readonly YELLOW='\033[1;33m' +readonly BLUE='\033[0;34m' +readonly NC='\033[0m' # No Color + +# Options +JSON_OUTPUT=false +STRICT_MODE=false + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --json) + JSON_OUTPUT=true + shift + ;; + --strict) + STRICT_MODE=true + shift + ;; + --help) + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --json Output in JSON format" + echo " --strict Fail on high severity issues" + echo " --help Show this help message" + exit 0 + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +if [ "$JSON_OUTPUT" = false ]; then + echo -e "${BLUE}🔍 Dependency Health Check${NC}" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo "" +fi + +# npm Packages Check +TOTAL_PACKAGES=0 +OUTDATED_COUNT=0 +VULN_CRITICAL=0 +VULN_HIGH=0 +VULN_MODERATE=0 +VULN_LOW=0 + +if [ -f "package.json" ]; then + if [ "$JSON_OUTPUT" = false ]; then + echo -e "${BLUE}📦 npm Packages${NC}" + fi + + # Count total packages + TOTAL_PACKAGES=$(npm list --all --json 2>/dev/null | jq '[.. | .dependencies? | select(. != null) | keys[]] | unique | length' || echo "0") + + # Check for outdated packages + OUTDATED_OUTPUT=$(npm outdated --json 2>/dev/null || echo "{}") + OUTDATED_COUNT=$(echo "$OUTDATED_OUTPUT" | jq 'length' 2>/dev/null || echo "0") + + # Security audit + AUDIT_OUTPUT=$(npm audit --json 2>/dev/null || echo '{"vulnerabilities":{}}') + VULN_CRITICAL=$(echo "$AUDIT_OUTPUT" | jq '.metadata.vulnerabilities.critical // 0' 2>/dev/null || echo "0") + VULN_HIGH=$(echo "$AUDIT_OUTPUT" | jq '.metadata.vulnerabilities.high // 0' 2>/dev/null || echo "0") + VULN_MODERATE=$(echo "$AUDIT_OUTPUT" | jq '.metadata.vulnerabilities.moderate // 0' 2>/dev/null || echo "0") + VULN_LOW=$(echo "$AUDIT_OUTPUT" | jq '.metadata.vulnerabilities.low // 0' 2>/dev/null || echo "0") + + if [ "$JSON_OUTPUT" = false ]; then + echo " • Total packages: $TOTAL_PACKAGES" + + # Vulnerabilities + if [ "$VULN_CRITICAL" -gt 0 ]; then + echo -e " ${RED}✗ $VULN_CRITICAL critical vulnerabilities${NC}" + else + echo -e " ${GREEN}✓ No critical vulnerabilities${NC}" + fi + + if [ "$VULN_HIGH" -gt 0 ]; then + echo -e " ${YELLOW}⚠ $VULN_HIGH high severity vulnerabilities${NC}" + fi + + if [ "$VULN_MODERATE" -gt 0 ]; then + echo " • $VULN_MODERATE moderate severity vulnerabilities" + fi + + # Outdated packages + if [ "$OUTDATED_COUNT" -gt 0 ]; then + echo -e " ${YELLOW}⚠ $OUTDATED_COUNT packages can be updated${NC}" + + # Show top 5 outdated + echo "$OUTDATED_OUTPUT" | jq -r 'to_entries | .[0:5] | .[] | " - \(.key): \(.value.current) → \(.value.latest)"' 2>/dev/null || true + + if [ "$OUTDATED_COUNT" -gt 5 ]; then + echo " ... and $((OUTDATED_COUNT - 5)) more" + fi + else + echo -e " ${GREEN}✓ All packages up-to-date${NC}" + fi + + echo "" + fi +fi + +# Determine overall health score +HEALTH_SCORE=100 +HEALTH_SCORE=$((HEALTH_SCORE - VULN_CRITICAL * 20)) +HEALTH_SCORE=$((HEALTH_SCORE - VULN_HIGH * 10)) +HEALTH_SCORE=$((HEALTH_SCORE - VULN_MODERATE * 2)) +HEALTH_SCORE=$((HEALTH_SCORE - OUTDATED_COUNT)) + +if [ $HEALTH_SCORE -lt 0 ]; then + HEALTH_SCORE=0 +fi + +# Determine risk level +RISK_LEVEL="Low" +if [ "$VULN_CRITICAL" -gt 0 ]; then + RISK_LEVEL="Critical" +elif [ "$VULN_HIGH" -gt 0 ]; then + RISK_LEVEL="High" +elif [ "$VULN_MODERATE" -gt 0 ] || [ "$OUTDATED_COUNT" -gt 10 ]; then + RISK_LEVEL="Medium" +fi + +if [ "$JSON_OUTPUT" = true ]; then + # JSON output for CI integration + cat < /dev/null 2>&1; then + echo -e "${RED}✗ Not in a git repository${NC}" + exit 1 +fi + +# Quality Checks +echo -e "${BLUE}✅ Quality Checks${NC}" + +# Lint +echo -n " • Running lint check... " +if npm run lint > /dev/null 2>&1; then + echo -e "${GREEN}✓${NC}" +else + echo -e "${RED}✗ Failed${NC}" + echo -e "${YELLOW} Run: npm run lint:fix${NC}" + exit 1 +fi + +# Format +echo -n " • Running format check... " +if npm run format:check > /dev/null 2>&1; then + echo -e "${GREEN}✓${NC}" +else + echo -e "${RED}✗ Failed${NC}" + echo -e "${YELLOW} Run: npm run format${NC}" + exit 1 +fi + +# Shellcheck +if command -v shellcheck > /dev/null 2>&1; then + echo -n " • Running shellcheck... " + if npm run shellcheck > /dev/null 2>&1; then + echo -e "${GREEN}✓${NC}" + else + echo -e "${RED}✗ Failed${NC}" + exit 1 + fi +fi + +# Tests +if [ "$SKIP_TESTS" = false ]; then + echo -n " • Running unit tests... " + if npm test > /dev/null 2>&1; then + TEST_OUTPUT=$(npm test 2>&1 | tail -5) + PASSED=$(echo "$TEST_OUTPUT" | grep -oP '\d+(?= passed)' || echo "0") + echo -e "${GREEN}✓ ($PASSED tests passed)${NC}" + + # Coverage + if [ -f "coverage/coverage-summary.json" ]; then + COVERAGE=$(node -pe "JSON.parse(require('fs').readFileSync('coverage/coverage-summary.json')).total.lines.pct") + if (( $(echo "$COVERAGE >= 70" | bc -l) )); then + echo -e " • Coverage: ${GREEN}${COVERAGE}%${NC} (threshold: 70%)" + else + echo -e " • Coverage: ${RED}${COVERAGE}%${NC} (threshold: 70%)" + exit 1 + fi + fi + else + echo -e "${RED}✗ Failed${NC}" + exit 1 + fi + + # Integration tests + if [ "$SKIP_INTEGRATION" = false ] && command -v bats > /dev/null 2>&1; then + echo -n " • Running integration tests... " + if npm run test:integration > /dev/null 2>&1; then + echo -e "${GREEN}✓${NC}" + else + echo -e "${YELLOW}⚠ Integration tests failed or not available${NC}" + fi + fi +fi + +echo "" + +# PR Analysis +echo -e "${BLUE}📊 PR Analysis${NC}" + +# Get current branch +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ]; then + echo -e "${RED}✗ Cannot create PR from main/master branch${NC}" + exit 1 +fi + +# Calculate diff stats +MAIN_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) +if ! git rev-parse "origin/$MAIN_BRANCH" > /dev/null 2>&1; then + MAIN_BRANCH="main" +fi + +ADDITIONS=$(git diff "origin/$MAIN_BRANCH"...HEAD --numstat | awk '{sum+=$1} END {print sum}') +DELETIONS=$(git diff "origin/$MAIN_BRANCH"...HEAD --numstat | awk '{sum+=$2} END {print sum}') +TOTAL_LINES=$((ADDITIONS + DELETIONS)) +FILE_COUNT=$(git diff "origin/$MAIN_BRANCH"...HEAD --name-only | wc -l | tr -d ' ') + +# Determine size label +if [ "$TOTAL_LINES" -lt 100 ] && [ "$FILE_COUNT" -lt 10 ]; then + SIZE_LABEL="size/S" + SIZE_NAME="Small" +elif [ "$TOTAL_LINES" -lt 300 ] && [ "$FILE_COUNT" -lt 20 ]; then + SIZE_LABEL="size/M" + SIZE_NAME="Medium" +elif [ "$TOTAL_LINES" -lt 1000 ] && [ "$FILE_COUNT" -lt 30 ]; then + SIZE_LABEL="size/L" + SIZE_NAME="Large" +else + SIZE_LABEL="size/XL" + SIZE_NAME="Extra Large" +fi + +echo " • Size: $SIZE_NAME (+$ADDITIONS -$DELETIONS lines, $FILE_COUNT files)" +echo " • Suggested label: $SIZE_LABEL" + +if [ "$SIZE_LABEL" = "size/XL" ]; then + echo -e "${YELLOW} ⚠ Consider breaking this PR into smaller chunks${NC}" +fi + +# Check for linked issues +COMMIT_MESSAGES=$(git log "origin/$MAIN_BRANCH"..HEAD --pretty=format:"%s %b") +LINKED_ISSUES=$(echo "$COMMIT_MESSAGES" | grep -oP '#\d+' | sort -u || true) +if [ -n "$LINKED_ISSUES" ]; then + echo " • Linked issues: $(echo "$LINKED_ISSUES" | tr '\n' ' ')" +else + echo -e "${YELLOW} ⚠ No linked issues found${NC}" +fi + +# Check commit messages +COMMIT_COUNT=$(git rev-list --count "origin/$MAIN_BRANCH"..HEAD) +INVALID_COMMITS=$(git log "origin/$MAIN_BRANCH"..HEAD --pretty=format:"%s" | grep -vE '^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .+' || true) +if [ -z "$INVALID_COMMITS" ]; then + echo " • Commits: $COMMIT_COUNT (all follow conventional commits)" +else + echo -e "${YELLOW} ⚠ Some commits don't follow conventional commits format${NC}" +fi + +echo "" + +# Branch Status +echo -e "${BLUE}🔄 Branch Status${NC}" + +# Check if up-to-date with main +git fetch origin "$MAIN_BRANCH" > /dev/null 2>&1 +BEHIND_COUNT=$(git rev-list --count HEAD.."origin/$MAIN_BRANCH") +if [ "$BEHIND_COUNT" -eq 0 ]; then + echo -e " ${GREEN}✓${NC} Up-to-date with $MAIN_BRANCH" +else + echo -e "${YELLOW} ⚠ Behind $MAIN_BRANCH by $BEHIND_COUNT commits${NC}" + echo -e "${YELLOW} Consider: git rebase origin/$MAIN_BRANCH${NC}" +fi + +# Check for merge conflicts +if git merge-tree "$(git merge-base HEAD "origin/$MAIN_BRANCH")" HEAD "origin/$MAIN_BRANCH" | grep -q '<<<<<<<'; then + echo -e "${RED} ✗ Potential merge conflicts detected${NC}" + exit 1 +else + echo -e " ${GREEN}✓${NC} No merge conflicts" +fi + +echo "" +echo -e "${GREEN}✨ Ready to create PR!${NC}" +echo "" +echo "Next steps:" +echo " 1. Review your changes: git diff origin/$MAIN_BRANCH...HEAD" +echo " 2. Create PR: gh pr create" +echo " 3. Add label: gh pr edit --add-label $SIZE_LABEL" diff --git a/script/sync-claude-commands.sh b/script/sync-claude-commands.sh new file mode 100755 index 00000000..66198709 --- /dev/null +++ b/script/sync-claude-commands.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# ============================================================================ +# Claude Commands Sync Script +# .claude/commands/ をユーザーレベル (~/.claude/commands/) に同期します +# ============================================================================ + +set -euo pipefail + +# カラー出力 +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +log_info() { echo -e "${BLUE}[INFO]${NC} $1"; } +log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; } +log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } + +# スクリプトのディレクトリを取得 +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" + +SOURCE_DIR="${PROJECT_ROOT}/.claude/commands" +TARGET_DIR="${HOME}/.claude/commands" + +log_info "Claude コマンドの同期を開始します..." + +# ソースディレクトリの存在確認 +if [[ ! -d "$SOURCE_DIR" ]]; then + log_warn "ソースディレクトリが見つかりません: ${SOURCE_DIR}" + exit 0 +fi + +# ターゲットディレクトリを作成 +mkdir -p "$TARGET_DIR" + +# コマンドファイルをコピー +log_info "コピー元: ${SOURCE_DIR}" +log_info "コピー先: ${TARGET_DIR}" + +if cp -r "$SOURCE_DIR/"* "$TARGET_DIR/" 2>/dev/null; then + # コピーされたファイル数をカウント + file_count=$(find "$SOURCE_DIR" -type f -name "*.md" | wc -l | xargs) + log_success "Claude コマンド ${file_count} 個を ${TARGET_DIR} に同期しました" + + # 同期されたコマンド一覧を表示 + log_info "同期されたコマンド:" + find "$TARGET_DIR" -type f -name "*.md" -exec basename {} .md \; | sort | sed 's/^/ - \//' +else + log_warn "コマンドのコピーに失敗しました" + exit 1 +fi + +log_success "Claude コマンドの同期が完了しました!"