JA Getting Started Quick Start - aku11i/phantom GitHub Wiki

クイックスタートガイド

English | 日本語

Phantomを5分で起動して実行しましょう!このガイドではインストールと基本的な使用方法を説明します。

インストール

グローバルインストール(推奨)

# npmを使用
npm install -g @aku11i/phantom

# pnpmを使用
pnpm add -g @aku11i/phantom

# インストールの確認
phantom --version

必要条件

  • Node.js v22.0.0以上
  • Git(worktreeサポート付き)

基本的な使用方法

最初のPhantomを作成

「phantom」はGit worktreeのことで、リポジトリにリンクされた独立した作業ディレクトリです。

# 任意のGitリポジトリに移動
cd your-git-repo

# 現在のブランチからphantomを作成
phantom create my-feature

# 特定のブランチからphantomを作成
phantom create bugfix-123 origin/production

Phantomの操作

すべてのPhantomをリスト表示

phantom list

# 出力例:
# NAME           BRANCH              PATH
# my-feature     feature/new-ui      /var/tmp/phantom/repo/my-feature
# bugfix-123     fix/critical-bug    /var/tmp/phantom/repo/bugfix-123

Phantom内でコマンドを実行

# phantom内で任意のコマンドを実行
phantom exec my-feature npm test
phantom exec my-feature git status

# 複数のコマンドを実行
phantom exec my-feature "npm install && npm test"

インタラクティブシェル

# phantom内でインタラクティブシェルを開始
phantom shell my-feature

# phantom のディレクトリに移動済み
# 通常通りコマンドを実行
npm install
npm test
git commit -m "Add feature"

# 完了したら終了
exit

Phantomの場所を取得

# phantomへのパスを表示
phantom where my-feature
# 出力: /var/tmp/phantom/repo/my-feature

# スクリプトで使用
cd $(phantom where my-feature)

Phantomを削除

# phantom(worktree)を削除
phantom delete my-feature

# これはworktreeを削除しますが、ブランチは保持されます

実際の使用例

例1: 機能開発

# 新機能用のphantomを作成
phantom create new-dashboard

# phantomに入る
phantom shell new-dashboard

# phantomシェル内で:
git checkout -b feature/dashboard
npm install
npm run dev
# 変更、テスト、コミット...
exit

# メインworktreeに戻り、他の作業を続ける

例2: クイックバグ修正

# プロダクションブランチからphantomを作成
phantom create hotfix origin/production

# 修正を実行
phantom exec hotfix "git checkout -b hotfix/security-patch"
phantom exec hotfix "npm test"

# 変更を確認
phantom shell hotfix
git diff
git commit -m "Fix security vulnerability"
git push origin hotfix/security-patch
exit

# クリーンアップ
phantom delete hotfix

例3: コードレビュー

# 同僚のPRをレビュー
phantom create review-pr-42 origin/feature/new-api

# テストを実行してコードをチェック
phantom exec review-pr-42 npm test
phantom exec review-pr-42 npm run lint

# インタラクティブに探索
phantom shell review-pr-42

例4: 並行開発

# 複数の機能を同時に作業
phantom create feature-a
phantom create feature-b
phantom create feature-c

# 並行してテストを実行
phantom exec feature-a npm test &
phantom exec feature-b npm test &
phantom exec feature-c npm test &
wait

# すべてのステータスを確認
phantom list

コマンドリファレンス

コマンド 説明
create 新しいphantomを作成 phantom create <name> [branch]
delete phantomを削除 phantom delete <name>
list すべてのphantomをリスト表示 phantom list
exec phantom内でコマンドを実行 phantom exec <name> <command>
shell phantomシェルに入る phantom shell <name>
where phantomのパスを取得 phantom where <name>
--version バージョンを表示 phantom --version
--help ヘルプを表示 phantom --help

ヒントとベストプラクティス

1. 命名規則

phantomには説明的な名前を使用:

  • フィーチャーブランチ: feature-loginfeature-dashboard
  • バグ修正: fix-memory-leakbugfix-123
  • レビュー: review-pr-42review-api-changes

2. 定期的なクリーンアップ

# phantomをリスト表示してクリーンアップできるものを確認
phantom list

# 完了したphantomを削除
phantom delete old-feature

3. Gitワークフローでの使用

# 各PRレビュー用にphantomを作成
phantom create pr-$(git rev-parse --short HEAD)

# 各アクティブチケット用にphantomを作成
phantom create ticket-JIRA-123

4. スクリプティング

# スクリプトで使用
PHANTOM_PATH=$(phantom where my-feature)
if [ -d "$PHANTOM_PATH" ]; then
    cd "$PHANTOM_PATH"
    npm test
fi

一般的な使用ケース

複数の開発サーバーの実行

# 異なるバージョンを同時に起動
phantom exec v1 "npm run dev -- --port 3001" &
phantom exec v2 "npm run dev -- --port 3002" &
phantom exec v3 "npm run dev -- --port 3003" &

AIエージェント開発

複数のAIコーディングセッションの実行に最適:

# AIエージェント用の隔離環境を作成
phantom create ai-agent-1
phantom create ai-agent-2

# 各エージェントは独自のphantomで作業
# 並行セッション間での競合や混乱なし

継続的インテグレーションテスト

# 複数の設定に対してテスト
phantom create test-node-20
phantom create test-node-22

phantom exec test-node-20 "nvm use 20 && npm test"
phantom exec test-node-22 "nvm use 22 && npm test"

トラブルシューティング

Phantom作成が失敗する

  • Gitリポジトリ内にいることを確認
  • ブランチが存在することを確認: git branch -a
  • Git worktreeサポートを確認: git worktree list

コマンドが見つからない

  • インストールを確認: npm list -g @aku11i/phantom
  • Node.jsバージョンを確認: node --version(v22+が必要)
  • 再インストールを試す: npm install -g @aku11i/phantom

権限エラー

  • Phantomはデフォルトで/tmpにworktreeを作成
  • 書き込み権限があることを確認
  • ディスク容量を確認: df -h

次のステップ

⚠️ **GitHub.com Fallback** ⚠️