diff --git a/.claude/commands/README.md b/.claude/commands/README.md index 63d3aecc..16b5f9c7 100644 --- a/.claude/commands/README.md +++ b/.claude/commands/README.md @@ -578,8 +578,6 @@ npm run update:all -- --skip-libs --skip-claude # Actions のみ | --------------------------- | ------------------------- | --------------------------------------- | | `setup-claude.sh` | DevContainer postCreate | Claude Code CLI の初期設定 | | `setup-claude-build.sh` | DevContainer Dockerfile | ビルド時の Claude Code セットアップ | -| `setup-env.sh` | DevContainer postCreate | 環境変数のセットアップ | -| `setup-mcp.sh` | DevContainer postCreate | MCP 設定のセットアップ | | `setup-lsp.sh` | DevContainer postCreate | LSP サーバーのセットアップ | | `install-npm-globals.sh` | DevContainer postCreate | グローバル npm パッケージのインストール | | `install-skills.sh` | DevContainer postStart | Claude スキルのインストール | diff --git a/.claude/commands/devcontainer-checklist.md b/.claude/commands/devcontainer-checklist.md index 40d17899..a2df12ac 100644 --- a/.claude/commands/devcontainer-checklist.md +++ b/.claude/commands/devcontainer-checklist.md @@ -350,8 +350,8 @@ cat .claude-plugin/plugin.json | jq '.lspServers | keys' ```bash # 環境変数を再生成 -bash script/setup-env.sh -bash script/setup-mcp.sh +bash script/credentials.sh fetch +cp credentials/devcontainer.env ~/.devcontainer.env && chmod 600 ~/.devcontainer.env # DevContainerを完全に再ビルド # VS Code: "Dev Containers: Rebuild Container" diff --git a/.claude/devcontainer-recommendations.md b/.claude/devcontainer-recommendations.md index bb1b850f..b7075dab 100644 --- a/.claude/devcontainer-recommendations.md +++ b/.claude/devcontainer-recommendations.md @@ -89,16 +89,10 @@ Claude CodeでMCPサーバーを利用する場合、`.mcp.json`の配置とマ #### `.mcp.json`の生成方法 ```bash -# postCreateCommandで自動生成(推奨) -bash script/setup-mcp.sh +# .mcp.json はリポジトリに直接コミットされています +# カスタマイズが必要な場合はリポジトリの .mcp.json を直接編集してください ``` -`setup-mcp.sh`は以下を実行: - -- `credentials/mcp.env`から環境変数を読み込み -- `.mcp.json.template`から`.mcp.json`を生成 -- ワークスペースルート(`/workspaces//.mcp.json`)に配置 - #### MCP設定例(`.mcp.json`) ```json @@ -131,7 +125,7 @@ bash script/setup-mcp.sh ```json { - "postCreateCommand": "bash script/setup-env.sh && bash script/setup-mcp.sh && /usr/local/bin/setup-claude.sh" + "postCreateCommand": "/usr/local/bin/setup-claude.sh" } ``` @@ -147,7 +141,7 @@ bash script/setup-mcp.sh "source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached", "source=${localEnv:HOME}/.config/gh,target=/home/vscode/.config/gh,type=bind,consistency=cached" ], - "postCreateCommand": "bash script/setup-env.sh && bash script/setup-mcp.sh && /usr/local/bin/setup-claude.sh", + "postCreateCommand": "/usr/local/bin/setup-claude.sh", "runArgs": ["--env-file=${localEnv:HOME}/.devcontainer.env"] } ``` @@ -751,7 +745,7 @@ NODE_ENV=development 2. **Claude Code認証エラー** - `ANTHROPIC_API_KEY`の値を確認 - - 1Passwordから最新のAPIキーを取得: `OP_ACCOUNT=your.1password.com bash script/setup-env.sh` + - 1Passwordから最新のAPIキーを取得: `OP_ACCOUNT=your.1password.com bash script/credentials.sh fetch && cp credentials/devcontainer.env ~/.devcontainer.env` - 環境変数が正しく読み込まれているか確認: `echo $ANTHROPIC_API_KEY` 3. **`.codex`や`.claude`の設定が反映されない** @@ -779,10 +773,9 @@ NODE_ENV=development ls -la /workspaces//.mcp.json ls -la ~/.claude/.mcp.json ``` - - `.mcp.json`が生成されない場合: - - `credentials/mcp.env`が存在するか確認 - - `script/setup-env.sh`を先に実行 - - 手動で実行: `bash script/setup-mcp.sh` + - `.mcp.json`が存在しない場合: + - リポジトリの`.mcp.json`を確認(直接コミットされています) + - カスタマイズが必要な場合はリポジトリの`.mcp.json`を直接編集 - 環境変数が展開されているか確認: ```bash cat .mcp.json | grep '\${' diff --git a/README.md b/README.md index c54e0320..8012896a 100644 --- a/README.md +++ b/README.md @@ -259,10 +259,8 @@ config/ │ ├── security-credential-scan.sh │ ├── setup-claude-build.sh │ ├── setup-claude.sh -│ ├── setup-env.sh │ ├── setup-file-length-check.sh │ ├── setup-lsp.sh -│ ├── setup-mcp.sh │ ├── setup-scheduled-agents.sh # Scheduled remote agents セットアップ │ ├── setup-team-protection.sh │ ├── update-agents-md.sh # AGENTS.md 自動生成セクション更新 @@ -481,15 +479,17 @@ git config --global user.signingkey ~/.ssh/id_ed25519.pub For multiple 1Password accounts: ```bash - OP_ACCOUNT=my.1password.com bash script/setup-env.sh - bash script/setup-mcp.sh + OP_ACCOUNT=my.1password.com bash script/credentials.sh fetch + cp credentials/devcontainer.env ~/.devcontainer.env + chmod 600 ~/.devcontainer.env ``` For single account: ```bash - bash script/setup-env.sh - bash script/setup-mcp.sh + bash script/credentials.sh fetch + cp credentials/devcontainer.env ~/.devcontainer.env + chmod 600 ~/.devcontainer.env ``` This creates `~/.devcontainer.env` which is **required** for DevContainer startup. @@ -511,9 +511,9 @@ git config --global user.signingkey ~/.ssh/id_ed25519.pub The automated setup creates: -- `~/.devcontainer.env` - DevContainer environment variables (600 permissions) +- `credentials/devcontainer.env` - DevContainer environment variables (600 permissions) - `credentials/mcp.env` - MCP environment variables (600 permissions) -- `.mcp.json` - MCP configuration file (600 permissions) +- `~/.devcontainer.env` - Installed from `credentials/devcontainer.env` (must be copied manually) All generated files are automatically excluded from Git via `.gitignore`. @@ -816,19 +816,18 @@ Use the automated setup scripts to generate environment files from 1Password: ```bash # For multiple 1Password accounts -OP_ACCOUNT=my.1password.com bash script/setup-env.sh -bash script/setup-mcp.sh +OP_ACCOUNT=my.1password.com bash script/credentials.sh fetch +cp credentials/devcontainer.env ~/.devcontainer.env && chmod 600 ~/.devcontainer.env # For single account -bash script/setup-env.sh -bash script/setup-mcp.sh +bash script/credentials.sh fetch +cp credentials/devcontainer.env ~/.devcontainer.env && chmod 600 ~/.devcontainer.env ``` This automatically creates: -- `~/.devcontainer.env` - DevContainer environment variables +- `credentials/devcontainer.env` - DevContainer environment variables - `credentials/mcp.env` - MCP environment variables -- `.mcp.json` - MCP configuration file All files are set with 600 permissions and excluded from Git. @@ -852,7 +851,7 @@ If you need to customize `.mcp.json`: chmod 600 .mcp.json ``` -#### When to Run Setup Scripts +#### When to Regenerate Credentials The environment variable setup is required at specific times: @@ -861,42 +860,32 @@ The environment variable setup is required at specific times: Before using DevContainer for the first time, run on your **host machine**: ```bash -OP_ACCOUNT=my.1password.com bash script/setup-env.sh +OP_ACCOUNT=my.1password.com bash script/credentials.sh fetch +cp credentials/devcontainer.env ~/.devcontainer.env && chmod 600 ~/.devcontainer.env ``` -This creates `~/.devcontainer.env` which is required for DevContainer startup via `runArgs`. +This creates `~/.devcontainer.env` which is required for DevContainer startup. -**2. DevContainer Startup (Automatic)** +**2. Credential Updates (Manual)** -When DevContainer starts, `postCreateCommand` automatically runs: - -- `setup-env.sh` - Regenerates environment files inside container -- `setup-mcp.sh` - Generates `.mcp.json` from template - -**3. Credential Updates (Manual)** - -Re-run setup scripts when: +Re-run when: - API keys are rotated in 1Password - New credentials are added to templates - Environment variables need to be refreshed ```bash -# On host machine -OP_ACCOUNT=my.1password.com bash script/setup-env.sh - -# Inside DevContainer (or rebuild container) -bash script/setup-env.sh -bash script/setup-mcp.sh +bash script/credentials.sh fetch +cp credentials/devcontainer.env ~/.devcontainer.env && chmod 600 ~/.devcontainer.env ``` -**4. Template Updates (Manual)** +**3. Template Updates (Manual)** After modifying `credentials/templates/*.env.template`, regenerate: ```bash -bash script/setup-env.sh -bash script/setup-mcp.sh +bash script/credentials.sh fetch +cp credentials/devcontainer.env ~/.devcontainer.env && chmod 600 ~/.devcontainer.env ``` #### How It Works @@ -930,15 +919,16 @@ make version-dry-run #### Credential Management ```bash -# Automated setup (recommended) -bash script/setup-env.sh # Generate environment variables from 1Password -bash script/setup-mcp.sh # Generate MCP configuration +# Fetch credentials from 1Password +bash script/credentials.sh fetch # For multiple 1Password accounts -OP_ACCOUNT=my.1password.com bash script/setup-env.sh +OP_ACCOUNT=my.1password.com bash script/credentials.sh fetch + +# Install DevContainer environment file +cp credentials/devcontainer.env ~/.devcontainer.env && chmod 600 ~/.devcontainer.env -# Legacy method -make credentials # Fetch credentials from 1Password +# Other credential management make clean-credentials # Clean up credential files make list-credentials # List available credential templates ``` diff --git a/credentials/README.md b/credentials/README.md index c49e41a2..f33ae803 100644 --- a/credentials/README.md +++ b/credentials/README.md @@ -33,21 +33,14 @@ credentials/ 3. **環境変数を自動セットアップ** ```bash - bash script/setup-env.sh + bash script/credentials.sh fetch + cp credentials/devcontainer.env ~/.devcontainer.env && chmod 600 ~/.devcontainer.env ``` このスクリプトは以下を自動生成します: - - `~/.devcontainer.env` - DevContainer 環境変数 + - `credentials/devcontainer.env` - DevContainer 環境変数 - `credentials/mcp.env` - MCP 設定用環境変数 -4. **MCP 設定を生成** - - ```bash - bash script/setup-mcp.sh - ``` - - `.mcp.json` が自動生成されます。 - ## サポートされているMCPサーバー このリポジトリは以下のMCP (Model Context Protocol) サーバーをサポートしています: @@ -199,29 +192,15 @@ cp credentials/templates/devcontainer.env.template ~/.devcontainer.env **解決策**: 1. スクリプトの実行権限確認: `ls -l script/setup-*.sh` -2. 手動実行でデバッグ: `bash -x script/setup-env.sh` - -### .mcp.json が生成されない +2. 手動実行でデバッグ: `bash -x script/credentials.sh fetch` -**症状**: `envsubst: command not found` +### MCP設定を変更したい -**解決策**: - -1. `envsubst` インストール: - ```bash - brew install gettext - brew link --force gettext - ``` -2. `credentials/mcp.env` が正しく生成されているか確認: - ```bash - cat credentials/mcp.env - ``` +`.mcp.json` はリポジトリに直接コミットされています。変更が必要な場合はリポジトリの `.mcp.json` を直接編集してください。 ## 関連ファイル -- `.mcp.json.template`: MCP 設定テンプレート(環境変数参照) -- `script/setup-env.sh`: 環境変数自動セットアップスクリプト -- `script/setup-mcp.sh`: MCP 設定自動生成スクリプト +- `script/credentials.sh`: クレデンシャル取得スクリプト - `.zsh/configs/pre/.env.secret.template`: シェル環境変数トークンのテンプレート - `.claude/settings.local.json.template`: Claude Code ローカル設定のテンプレート - `script/export.sh`: 設定エクスポートスクリプト(フィルタリング機能含む) diff --git a/docs/doppler-setup-guide.md b/docs/doppler-setup-guide.md index d0218736..f152911e 100644 --- a/docs/doppler-setup-guide.md +++ b/docs/doppler-setup-guide.md @@ -181,7 +181,7 @@ export DOPPLER_TOKEN=dp.pt.xxxxx ## 既存の 1Password 管理からの移行 -このリポジトリでは `script/setup-env.sh` + 1Password CLI でシークレットを管理しているが、 +このリポジトリでは `script/credentials.sh` + 1Password CLI でシークレットを管理しているが、 プロジェクトごとに Doppler に移行する場合の手順: 1. 1Password のシークレットを Doppler の `dev` config にインポート diff --git a/script/README.md b/script/README.md index 712102b7..57eb6fbf 100644 --- a/script/README.md +++ b/script/README.md @@ -67,18 +67,6 @@ Manage GitHub Codespaces secrets across multiple repositories. **Claude command**: `/codespaces-secrets` -### setup-env.sh - -Sets up environment variables for DevContainer from credential files. - -**Usage**: `./script/setup-env.sh` - -### setup-mcp.sh - -Sets up MCP (Model Context Protocol) configuration for Claude Code. - -**Usage**: `./script/setup-mcp.sh` - ## Claude Code Development ### setup-claude.sh diff --git a/script/lib/agents-md-data.sh b/script/lib/agents-md-data.sh index f83ce928..256b1e75 100644 --- a/script/lib/agents-md-data.sh +++ b/script/lib/agents-md-data.sh @@ -4,7 +4,6 @@ # shellcheck disable=SC2034 # all variables are sourced and consumed externally declare -A DOT_DIR_PURPOSE=( - [.agents]="AI agent skills and configurations" [.codex]="Codex AI agent configuration" [.context]="Shared intermediate artifacts (complexity reports etc.)" [.cursor]="Cursor editor settings" @@ -32,7 +31,6 @@ declare -A REG_DIR_PURPOSE=( [dot]="Dotfiles (DevContainer .zshrc, peco)" [eslint]="ESLint configuration and plugins" [git]="Git hooks and configuration" - [next]="Next.js project templates" [nix]="nix-darwin + home-manager (macOS environment)" [npm]="npm global configuration and library management" [script]="Utility shell scripts" diff --git a/script/lib/output.sh b/script/lib/output.sh index 9d2c805c..9f3b1f95 100755 --- a/script/lib/output.sh +++ b/script/lib/output.sh @@ -115,15 +115,6 @@ log_info() { output::info "$@"; } log_success() { output::success "$@"; } log_warn() { output::warning "$@"; } -# errors:: namespace aliases (migrated from errors.sh) -errors::fatal() { output::fatal "$@"; } -errors::warn() { output::warning "$@"; } -errors::info() { output::info "$@"; } -errors::success() { output::success "$@"; } -errors::require_command() { output::require_command "$@"; } -errors::require_file() { output::require_file "$@"; } -errors::require_directory() { output::require_directory "$@"; } - # Bash-compatible short aliases info() { output::info "$@"; } success() { output::success "$@"; } diff --git a/script/setup-env.sh b/script/setup-env.sh deleted file mode 100755 index 84b8ad91..00000000 --- a/script/setup-env.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env bash -# ============================================================================ -# 環境変数セットアップスクリプト -# credentials.sh のラッパースクリプト -# ============================================================================ -# このスクリプトは credentials.sh を使用して環境変数ファイルを生成します。 -# 後方互換性のために維持されていますが、新規利用は credentials.sh を推奨します。 - -set -euo pipefail - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(dirname "$SCRIPT_DIR")" -CREDENTIALS_DIR="$REPO_ROOT/credentials" - -# shellcheck source=script/lib/output.sh -source "$SCRIPT_DIR/lib/output.sh" - -main() { - print_info "環境変数セットアップを開始します" - print_info "" - - # credentials.sh を使用してすべてのクレデンシャルを取得 - if "$SCRIPT_DIR/credentials.sh" fetch; then - print_info "" - - # DevContainer 用環境ファイルをホームディレクトリにコピー - if [[ -f "$CREDENTIALS_DIR/devcontainer.env" ]]; then - cp "$CREDENTIALS_DIR/devcontainer.env" "$HOME/.devcontainer.env" - chmod 600 "$HOME/.devcontainer.env" - print_success "DevContainer 環境変数を ~/.devcontainer.env にコピーしました" - fi - - print_info "" - print_success "環境変数セットアップが完了しました" - else - print_error "クレデンシャルの取得に失敗しました" - print_info "" - print_info "以下のいずれかの方法で設定してください:" - print_info "1. 1Password CLI をインストール:" - print_info " brew install --cask 1password-cli" - print_info " op signin" - print_info "" - print_info "2. 手動で環境ファイルを作成:" - print_info " cp $CREDENTIALS_DIR/templates/devcontainer.env.template ~/.devcontainer.env" - print_info " # ファイルを編集して op:// 参照を実際の値に置換" - print_info "" - exit 1 - fi -} - -main "$@" diff --git a/script/setup-mcp.sh b/script/setup-mcp.sh deleted file mode 100755 index 7ebfa497..00000000 --- a/script/setup-mcp.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env bash -# MCP 設定セットアップスクリプト -# 環境変数を使用して .mcp.json を生成します - -set -euo pipefail - -# ディレクトリパス -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(dirname "$SCRIPT_DIR")" -MCP_TEMPLATE="$REPO_ROOT/.mcp.json.template" -MCP_OUTPUT="$REPO_ROOT/.mcp.json" -MCP_ENV="$REPO_ROOT/credentials/mcp.env" - -# shellcheck source=script/lib/output.sh -source "$SCRIPT_DIR/lib/output.sh" - -# envsubst の利用可否をチェック -check_envsubst() { - if ! command -v envsubst >/dev/null 2>&1; then - print_error "envsubst コマンドが見つかりません" - print_info "" - print_info "インストール方法:" - print_info " macOS: brew install gettext && brew link --force gettext" - print_info " Ubuntu/Debian: apt-get install gettext-base" - return 1 - fi - return 0 -} - -# メイン処理 -main() { - print_info "MCP 設定セットアップを開始します" - print_info "" - - # envsubst の確認 - if ! check_envsubst; then - exit 1 - fi - - # テンプレートファイルの確認 - if [[ ! -f "$MCP_TEMPLATE" ]]; then - print_error "テンプレートファイルが見つかりません: $MCP_TEMPLATE" - exit 1 - fi - - # MCP 環境変数ファイルの確認 - if [[ ! -f "$MCP_ENV" ]]; then - print_warning "MCP 環境変数ファイルが見つかりません: $MCP_ENV" - print_info "" - print_info "先に script/setup-env.sh を実行してください:" - print_info " bash $SCRIPT_DIR/setup-env.sh" - print_info "" - print_info "または手動で作成してください:" - print_info " cp $REPO_ROOT/credentials/templates/mcp.env.template $MCP_ENV" - print_info " # ファイルを編集して op:// 参照を実際の値に置換" - print_info "" - exit 1 - fi - - # MCP 環境変数を読み込み - print_info "環境変数を読み込み中..." - set -a - # shellcheck disable=SC1090 - source "$MCP_ENV" - set +a - - # envsubst で変数置換して .mcp.json を生成 - print_info ".mcp.json を生成中..." - - if envsubst < "$MCP_TEMPLATE" > "$MCP_OUTPUT"; then - chmod 600 "$MCP_OUTPUT" - print_success ".mcp.json を生成しました: $MCP_OUTPUT" - print_info "" - print_success "MCP 設定セットアップが完了しました" - else - print_error ".mcp.json の生成に失敗しました" - exit 1 - fi -} - -main "$@" diff --git a/test/integration/core-scripts.bats b/test/integration/core-scripts.bats index ff38657f..a8863e25 100644 --- a/test/integration/core-scripts.bats +++ b/test/integration/core-scripts.bats @@ -31,11 +31,6 @@ load ../test_helper/test_helper [ -x "$REPO_ROOT/script/pre-pr-checklist.sh" ] } -@test "setup-mcp.sh exists and is executable" { - assert_file_exists "$REPO_ROOT/script/setup-mcp.sh" - [ -x "$REPO_ROOT/script/setup-mcp.sh" ] -} - @test "setup-lsp.sh exists and is executable" { assert_file_exists "$REPO_ROOT/script/setup-lsp.sh" [ -x "$REPO_ROOT/script/setup-lsp.sh" ] @@ -83,11 +78,6 @@ load ../test_helper/test_helper [ -x "$REPO_ROOT/script/create-codespace.sh" ] } -@test "setup-env.sh exists and is executable" { - assert_file_exists "$REPO_ROOT/script/setup-env.sh" - [ -x "$REPO_ROOT/script/setup-env.sh" ] -} - @test "setup-file-length-check.sh exists and is executable" { assert_file_exists "$REPO_ROOT/script/setup-file-length-check.sh" [ -x "$REPO_ROOT/script/setup-file-length-check.sh" ] diff --git a/test/integration/lib_functions.bats b/test/integration/lib_functions.bats index e074fc08..5f39f0af 100644 --- a/test/integration/lib_functions.bats +++ b/test/integration/lib_functions.bats @@ -65,19 +65,6 @@ load ../test_helper/test_helper grep -q "output::require_directory()" "${REPO_ROOT}/script/lib/output.sh" } -# Backward compatibility: errors:: namespace aliases -@test "output.sh provides errors::fatal alias" { - grep -q "errors::fatal()" "${REPO_ROOT}/script/lib/output.sh" -} - -@test "output.sh provides errors::warn alias" { - grep -q "errors::warn()" "${REPO_ROOT}/script/lib/output.sh" -} - -@test "output.sh provides errors::require_command alias" { - grep -q "errors::require_command()" "${REPO_ROOT}/script/lib/output.sh" -} - @test "config::filter_gitconfig filters personal information" { # Create a test gitconfig with personal info local test_input="${TEST_TEMP_DIR}/test.gitconfig" @@ -164,18 +151,3 @@ EOF [[ "$output" == *"Operation completed"* ]] } -# Backward compatibility: test errors:: aliases work -@test "errors:: aliases work through output.sh" { - source "${REPO_ROOT}/script/lib/output.sh" - - run errors::require_command ls - [ "$status" -eq 0 ] - - run errors::info "Test info" - [ "$status" -eq 0 ] - [[ "$output" == *"Test info"* ]] - - run errors::success "Test success" - [ "$status" -eq 0 ] - [[ "$output" == *"Test success"* ]] -}