---
name: setup-mac
description: 新Macセットアップオーケストレータ。新規Mac環境構築時または既存環境リセット後に使用。Xcode license/Homebrew/dotfiles deploy/brew bundle/mise/fisher/chsh/SSH切替を順次実行し、sudo/MAS Apple ID 等の対話プロンプトを安全に通す。
---

# /setup-mac

新しい Mac のセットアップを実施する。canonical 実装は `~/.dotfiles/scripts/setup.sh`。
このskillはそれを対話的にオーケストレートする。

## 前提（ユーザに確認すること）

skill 起動直後、以下を順に確認してから先に進む:

1. **Claude Code が起動・ログイン済み** （これが満たされているなら自明）
2. **1Password Desktop インストール済み + サインイン済み**
   - 未インストールなら App Store または https://1password.com/downloads から入手
   - サインイン後、Settings → Developer → "Use the SSH agent" を ON
3. **1Password で SSH 鍵を生成済み** （ed25519 推奨）
   - 生成方法: 1Password → New Item → SSH Key → ed25519
4. **GitHub アカウントで上記の SSH 公開鍵を登録済み** （signing key にも有効化）

これらが揃っていない場合、揃うまでガイドして待つ。

## 実行手順

### Step 1. setup.sh を取得して実行

`~/.dotfiles` が未存在の場合は curl で setup.sh を直接取得して実行:

```bash
curl -fsSL https://raw.githubusercontent.com/ukwhatn/dotfiles/main/scripts/setup.sh | bash
```

または `~/.dotfiles` が既に clone 済みなら:

```bash
bash ~/.dotfiles/scripts/setup.sh
```

このスクリプトは以下を実行する（idempotent）:

1. Xcode CLT 確認 + license 承諾（sudo prompt）
2. Homebrew インストール
3. dotfiles を `~/.dotfiles` に clone
4. rsync で `~/.dotfiles/*` を `$HOME/` にデプロイ
5. `brew bundle` 実行（**注意: sudo / MAS Apple ID の対話プロンプトが出る**）
6. `mise install`
7. fisher + fish plugins インストール
8. login shell を fish に切替
9. dotfiles remote を SSH に変更
10. 動作確認

### Step 2. 対話プロンプトの監視

setup.sh 実行中、以下の対話プロンプトを user に伝える:

- **sudo password** （Xcode license, fish を /etc/shells に追加, sudo cask install 等）
- **MAS Apple ID sign-in** （Spark, Xcode）: App Store アプリで Apple ID にサインインしてから brew bundle 再実行

エラーが出たら原因を切り分け:
- `sudo: a terminal is required` → user が別ターミナルで該当コマンドを手動実行
- `App Spark needs to be installed` → App Store サインイン後 `brew bundle install` 再実行
- `Cask already installed` → 無害、無視

### Step 3. 残り手動ステップ（ユーザ操作）

setup.sh 完了後、以下を case-by-case でガイド:

1. **GitHub signing key 設定**
   - 1Password で生成した公開鍵をコピー
   - `git config --global user.signingkey "ssh-ed25519 AAAA..."`
   - `git config --global commit.gpgsign true`

2. **GitHub CLI 認証**
   - `gh auth login` を実行
   - SSH を選択、Web 経由で認証
   - 必要なら GHE host も: `gh auth login -h github.dena.jp`

3. **SSH 疎通確認**
   - `ssh -T git@github.com` → "Hi <username>! You've successfully authenticated"

4. **業務用 fish functions** （任意）
   - 私用 helper を使う場合: `git clone git@github.com:ukwhatn/functions.git ~/work-fish-functions`
   - `~/.config/fish/config.fish` に `source ~/work-fish-functions/*.fish` を追記

5. **アプリ起動 + 権限付与**
   - Karabiner-Elements: アクセシビリティ・入力監視
   - Raycast: アクセシビリティ
   - 1Password: アクセシビリティ・ロック解除

6. **ターミナル再起動**
   - login shell が fish になっていることを確認: `echo $SHELL`

### Step 4. 動作確認 + レポート

最後に以下を確認して報告:
- `fish --version` / `mise current` / `gh auth status` / `brew bundle check`
- `git -C ~/.dotfiles remote -v` が SSH になっているか
- `ssh -T git@github.com` 成功

完了報告に含める:
- ✅ 完了項目
- ⚠ user の追加対応待ち項目（gh auth login 等）
- ⚠ 既知の制限（zoom の sudo, MAS の Apple ID）

## トラブルシューティング

| 症状 | 対処 |
|------|------|
| `xcodebuild -license` で sudo 必要 | `! sudo xcodebuild -license accept` を別ターミナルで |
| `brew bundle` で cask sudo 必要 | 該当 cask を手動 `brew install --cask <name>` |
| fisher install で curl 失敗 | ネットワーク確認、proxy 設定確認 |
| `mise install` で python ビルド失敗 | Xcode license / CLT を再確認、`mise install python@3.13.9 --verbose` |
| `chsh` で `非標準シェル` エラー | `/etc/shells` への fish 追加が未済、sudo で追加 |

## 重要

- **このskillは破壊的操作を含む**（chsh, /etc/shells書込, dotfiles deploy）
- setup.sh は idempotent なので複数回実行しても安全
- 既存設定が消えそうな状況では rsync 前に user 確認
