diff --git a/.claude/commands/update-claude-code.md b/.claude/commands/update-claude-code.md new file mode 100644 index 00000000..95ff03dd --- /dev/null +++ b/.claude/commands/update-claude-code.md @@ -0,0 +1,57 @@ +# Update Claude Code + +Claude Code の最新バージョンをチェックして更新します。 + +## 実行内容 + +1. npm/global.json から現在の `@anthropic-ai/claude-code` のバージョンを取得 +2. npm registry から最新バージョンを取得 +3. バージョンを比較して、更新が必要な場合は global.json を更新 +4. リリースノートのURLを表示 + +## 使用方法 + +```bash +/update-claude-code +``` + +## 実装 + +```bash +#!/usr/bin/env bash +set -euo pipefail + +# スクリプトのディレクトリを取得 +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" + +# 環境変数を設定して自動更新を有効化 +export AUTO_UPDATE=true +export CI=true + +# Claude Code更新スクリプトを実行 +if [[ -f "${PROJECT_ROOT}/script/update-claude-code.sh" ]]; then + bash "${PROJECT_ROOT}/script/update-claude-code.sh" +else + echo "Error: update-claude-code.sh が見つかりません" + exit 1 +fi + +# 更新があった場合の後処理 +if git diff --quiet npm/global.json; then + echo "✓ Claude Code は既に最新です" +else + echo "" + echo "更新が完了しました。変更をコミットしてください:" + echo " git add npm/global.json" + echo " git commit -m 'chore: update Claude Code to latest version'" + echo "" + git diff npm/global.json +fi +``` + +## 注意事項 + +- このコマンドは config リポジトリ内で実行する必要があります +- 更新後は手動でコミットとプッシュが必要です +- CI環境では自動的に更新されます(確認プロンプトなし) diff --git a/.github/workflows/update-libraries.yml b/.github/workflows/update-libraries.yml index 0e052e81..ddec14cb 100644 --- a/.github/workflows/update-libraries.yml +++ b/.github/workflows/update-libraries.yml @@ -28,6 +28,42 @@ jobs: - name: Refresh libraries run: npm run update:libs + - name: Generate update summary + id: summary + run: | + { + echo "summary</dev/null 2>&1 && [[ -f npm/global.json ]]; then + CLAUDE_VERSION=$(jq -r '.dependencies["@anthropic-ai/claude-code"].version' npm/global.json) + echo "### 🤖 Claude Code" + echo "Current version: **${CLAUDE_VERSION}**" + echo "" + echo "[Release Notes](https://github.com/anthropics/claude-code/releases)" + fi + fi + echo "EOF" + } >> $GITHUB_OUTPUT + - name: Create pull request uses: peter-evans/create-pull-request@v6 with: @@ -39,6 +75,14 @@ jobs: body: | Automated update generated by `npm run update:libs`. - - Ensures Codex/Claude Code toolchain definitions stay current - - Refreshes npm devDependencies and global CLI manifest + ${{ steps.summary.outputs.summary }} + + --- + + **What's Updated:** + - Codex/Claude Code toolchain definitions + - NPM devDependencies + - Global CLI manifest (npm/global.json) + + **Auto-generated by:** [update-libraries.yml](.github/workflows/update-libraries.yml) labels: dependencies diff --git a/README.md b/README.md index 89dc398c..06ac2241 100644 --- a/README.md +++ b/README.md @@ -237,10 +237,22 @@ Run the `commit_changes.sh` script with `REPO_PATH` set to this repository to ch ### Updating Codex & Claude Tooling +#### Update All Libraries + - Run `npm run update:libs` (wrapper for `script/update-libraries.sh`) to refresh npm devDependencies together with Codex/Claude Code CLI definitions captured in `npm/global.json`. - The script performs `npm-check-updates`, `npm install`, and re-synchronizes global CLI versions via `npm view version` before running lint/tests to verify the updated toolchain. - Packages that currently require newer Node.js releases (`semantic-release`, `@semantic-release/github`) are excluded by default. Override the exclusion list with `UPDATE_LIBS_REJECT="pkg1,pkg2" npm run update:libs` when you are ready to bump them. - `.github/workflows/update-libraries.yml` executes the same script weekly and opens a PR whenever it produces changes, ensuring Codex/Claude Code tooling stays current without manual effort. + +#### Update Claude Code Only + +- Run `npm run update:claude` (wrapper for `script/update-claude-code.sh`) to check and update **only** the `@anthropic-ai/claude-code` package to the latest version. +- The script compares the current version in `npm/global.json` with the latest available version on npm registry. +- If a newer version is available, it automatically updates `npm/global.json` and displays the release notes URL. +- Use `/update-claude-code` Claude command for interactive update within Claude Code sessions. + +#### Commit Requirements + - Commits that touch release-critical files (`package*.json`, `npm/global.json`, `.devcontainer/codex*`, `.codex/**`) **must** use a release-triggering Conventional Commit type (`feat`, `fix`, `perf`, `revert`, or `docs`). Commitlint enforces this so semantic-release can publish automatically when tooling versions change. #### Global CLI version source of truth diff --git a/package.json b/package.json index 51755e84..8a196515 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "test:watch": "jest --runInBand --watch", "test:coverage": "jest --runInBand --coverage", "update:libs": "bash script/update-libraries.sh", + "update:claude": "bash script/update-claude-code.sh", "prepare": "husky" }, "devDependencies": { diff --git a/script/update-claude-code.sh b/script/update-claude-code.sh new file mode 100755 index 00000000..04da07ec --- /dev/null +++ b/script/update-claude-code.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# ============================================================================ +# Claude Code Version Update Script +# @anthropic-ai/claude-code の最新バージョンをチェックして更新します +# ============================================================================ + +set -euo pipefail + +# カラー出力 +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +RED='\033[0;31m' +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"; } +log_error() { echo -e "${RED}[ERROR]${NC} $1"; } + +# スクリプトのディレクトリを取得 +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" + +GLOBAL_FILE="${PROJECT_ROOT}/npm/global.json" +PACKAGE="@anthropic-ai/claude-code" + +log_info "Claude Code バージョン更新を開始します..." + +# jqの存在確認 +if ! command -v jq &> /dev/null; then + log_error "jq が必要です。インストールしてください: brew install jq" + exit 1 +fi + +# npmの存在確認 +if ! command -v npm &> /dev/null; then + log_error "npm が必要です。" + exit 1 +fi + +# global.jsonの存在確認 +if [[ ! -f "$GLOBAL_FILE" ]]; then + log_error "global.json が見つかりません: ${GLOBAL_FILE}" + exit 1 +fi + +# 現在のバージョンを取得 +current_version=$(jq -r ".dependencies[\"${PACKAGE}\"].version" "$GLOBAL_FILE") +log_info "現在のバージョン: ${current_version}" + +# 最新バージョンを取得 +log_info "最新バージョンを確認中..." +latest_version=$(npm view "$PACKAGE" version 2>/dev/null) + +if [[ -z "$latest_version" ]]; then + log_error "最新バージョンの取得に失敗しました" + exit 1 +fi + +log_info "最新バージョン: ${latest_version}" + +# バージョン比較 +if [[ "$current_version" == "$latest_version" ]]; then + log_success "Claude Code は既に最新バージョンです (${current_version})" + exit 0 +fi + +log_warn "バージョンが異なります: ${current_version} → ${latest_version}" + +# 更新するかどうかを確認(CI環境では自動的に更新) +if [[ "${CI:-false}" != "true" ]] && [[ "${AUTO_UPDATE:-false}" != "true" ]]; then + read -p "更新しますか? (y/N): " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + log_info "更新をキャンセルしました" + exit 0 + fi +fi + +# global.jsonを更新 +log_info "global.json を更新中..." +tmp_file=$(mktemp) +jq --arg version "$latest_version" \ + ".dependencies[\"${PACKAGE}\"].version = \$version" "$GLOBAL_FILE" > "$tmp_file" +mv "$tmp_file" "$GLOBAL_FILE" + +log_success "Claude Code を ${current_version} → ${latest_version} に更新しました" + +# リリースノートのURLを表示 +log_info "リリースノート: https://github.com/anthropics/claude-code/releases" + +log_success "更新完了!" diff --git a/script/update-libraries.sh b/script/update-libraries.sh index 9fc5b942..74b14b8c 100755 --- a/script/update-libraries.sh +++ b/script/update-libraries.sh @@ -2,11 +2,25 @@ set -euo pipefail +# カラー出力 +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + REPO_PATH="${REPO_PATH:-$(cd "$(dirname "$0")/.." && pwd)}" cd "$REPO_PATH" log() { - printf '==> %s\n' "$1" + printf "${BLUE}==> %s${NC}\n" "$1" +} + +log_success() { + printf "${GREEN}✓ %s${NC}\n" "$1" +} + +log_warn() { + printf "${YELLOW}⚠ %s${NC}\n" "$1" } if ! command -v npx >/dev/null 2>&1; then @@ -32,14 +46,36 @@ if [[ -f "$GLOBAL_FILE" ]] && command -v jq >/dev/null 2>&1; then tmp_file=$(mktemp) cp "$GLOBAL_FILE" "$tmp_file" + # 更新されたパッケージを追跡 + declare -a updated_packages=() + while IFS= read -r pkg; do - latest_version=$(npm view "$pkg" version) + current_version=$(jq -r ".dependencies[\"$pkg\"].version" "$GLOBAL_FILE") + latest_version=$(npm view "$pkg" version 2>/dev/null || echo "$current_version") + + if [[ "$current_version" != "$latest_version" ]]; then + log_warn "Updating $pkg: $current_version → $latest_version" + updated_packages+=("$pkg: $current_version → $latest_version") + fi + jq --arg pkg "$pkg" --arg version "$latest_version" \ '.dependencies[$pkg].version = $version' "$tmp_file" >"${tmp_file}.next" mv "${tmp_file}.next" "$tmp_file" done < <(jq -r '.dependencies | keys[]' "$GLOBAL_FILE") mv "$tmp_file" "$GLOBAL_FILE" + + # 更新サマリーを表示 + if [[ ${#updated_packages[@]} -gt 0 ]]; then + echo "" + log "Updated packages summary:" + for update in "${updated_packages[@]}"; do + echo " - $update" + done + echo "" + else + log_success "All global packages are already up to date" + fi else log "Skipping global CLI manifest update (missing $GLOBAL_FILE or jq)" fi @@ -48,4 +84,12 @@ log "Running verification pipeline (lint + tests)" npm run lint npm test -log "Library update complete" +log_success "Library update complete" + +# Claude Code のバージョンを特別に表示 +if [[ -f "$GLOBAL_FILE" ]] && command -v jq >/dev/null 2>&1; then + claude_version=$(jq -r '.dependencies["@anthropic-ai/claude-code"].version' "$GLOBAL_FILE") + echo "" + log_success "Claude Code version: ${claude_version}" + echo "" +fi