agentleFS
KewtonKewton/CommandMate/.claude/skills/rebuild/SKILL.md

rebuild

Skill44 starsChanged 16 days agoMITView on GitHub

サーバーをリビルドして再起動する。「リビルド」「再起動」「サービス再起動」「本番環境を再起動」「ビルドして起動」などの指示で使用する。

  • Reads credentials

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Rebuild

サーバーを停止し、ビルドしてバックグラウンドで再起動します。

⚠️ 最初に決めること: ビルドは要るのか(Issue #2132)

ビルドは「アプリケーションのコードが変わったとき」だけ必要です。 npm run build は .next/BUILD_ID を書き換えるため、開いているブラウザタブが chunk を取得できなくなって壊れます (.commandmate/verify.yaml が skipInPrimaryCheckout: true でビルドを外しているのと同じ理由)。

状況使うものビルド
src/ などコードを変更したこのスキル(build-and-start.sh --daemon)する
.env / 設定だけ変えた./scripts/restart-nobuild.shしない
クラッシュしたサーバーを復帰させたい./scripts/restart-nobuild.shしない
停止中のサーバーを起こすだけ./scripts/start.sh --daemonしない

ビルド不要と判断したら Step 2 の代わりに次を 1 回の Bash 呼び出しで実行し、完了報告形式はそのまま使う:

cd {TARGET_DIR} && ./scripts/restart-nobuild.sh
cd {TARGET_DIR} && CM_PORT={port} ./scripts/restart-nobuild.sh   # ポート指定あり

手製の nohup npm start を使わないこと。 その前に source scripts/load-env.sh を叩く形になりますが、 このスクリプトは bash 専用で、zsh から source すると .env を 1 変数も読み込みません (Issue #2132 以降はエラーで失敗しますが、正しい手段は上記の 2 スクリプトです)。

使用方法

/rebuild                        # 現在のリポジトリで実行
/rebuild feature/235-worktree   # 指定ブランチのWorktreeで実行
/rebuild --port 3011            # ポート3011で起動
/rebuild feature/235-worktree --port 3011  # ブランチ指定+ポート指定

パラメータ

  • branch_name: 対象ブランチ名(省略可)。指定時は git worktree list からディレクトリを解決する。
  • --port {number}: 起動ポート番号(省略可)。指定時は CM_PORT 環境変数を設定してサーバーを起動する。未指定時はデフォルト(3000)。

実行手順

Step 1: 実行ディレクトリの決定

  1. ブランチ名が指定された場合:
    • git worktree list を実行し、指定ブランチに対応するディレクトリを取得する
    • 見つからない場合はエラー終了(「ブランチ '{branch_name}' に対応するWorktreeが見つかりません」)
    • 見つかったディレクトリを TARGET_DIR とする
  2. ブランチ名が未指定の場合:
    • 現在の作業ディレクトリ(プロジェクトルート)を TARGET_DIR とする

Step 2: サーバー停止・ビルド・再起動

停止とビルド・再起動を 1回のBash呼び出し で実行する(ユーザーへの許可確認を1回に抑えるため)。

ポート指定なしの場合:

cd {TARGET_DIR} && ./scripts/stop.sh && ./scripts/build-and-start.sh --daemon

ポート指定ありの場合:

cd {TARGET_DIR} && CM_PORT={port} ./scripts/stop.sh && CM_PORT={port} ./scripts/build-and-start.sh --daemon

注意: ポート競合が発生した場合は lsof -nP -iTCP:{port} -sTCP:LISTEN -t で待ち受け中のプロセスを特定し、killしてから再試行する。 -sTCP:LISTEN を外すと、そのポートに接続しているだけのプロセス(CommandMate を開いているブラウザの network service、他セッションの CLI など)まで返り、止めると CommandMate 以外のタブの通信も一斉に切れる(Issue #2473)。

完了報告形式

✅ サーバー再起動完了!

📋 サーバー情報:
  ディレクトリ: {TARGET_DIR}
  ブランチ:     {branch_name}
  PID:          [プロセスID]
  ポート:       {port} (デフォルト: 3000)
  URL:          http://localhost:{port}
  ログ:         {TARGET_DIR}/logs/server.log

🔧 操作コマンド:
  ログ確認: tail -f {TARGET_DIR}/logs/server.log
  停止:     cd {TARGET_DIR} && CM_PORT={port} ./scripts/stop.sh

注意:

  • ./scripts/stop.sh / ./scripts/build-and-start.sh / ./scripts/start.sh / ./scripts/restart-nobuild.sh はプロジェクトルートの .env ファイルを自動読み込みする(CM_PORT, CM_DB_PATH 等)。
  • --port オプションで CM_PORT を明示指定した場合、.env の値より優先される(環境変数が既にセットされている場合は .env で上書きされない仕様)。
  • 複数ポートで起動している場合、特定ポートだけ停止するには必ず CM_PORT={port} を付けること。
  • 起動ログに [env] ... の警告が出た場合、.env は存在するのに 1 変数も読み込めていない(Issue #2132)。その状態では Web Push・DB パス・worktree ルートがすべて既定値になっているので、報告して原因を潰すこと。

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.