CLI コマンド実践例

CLI コマンド実践例

概要

Miyabi(旧 AgenticOS)の CLI コマンドの実践的な使用例を紹介します。プロジェクトの初期化から、Issue 作成、Agent 実行、デプロイまでの実際のワークフローを学びます。

対象読者

  • Miyabi の新規ユーザー
  • CLI ツールに慣れている開発者
  • 自動化ワークフローを構築したいエンジニア
  • プロジェクトマネージャー

所要時間

  • 読了時間: 15 分
  • 実践時間: 30-45 分

前提知識

  • ターミナル/コマンドラインの基本操作
  • Git の基礎知識
  • GitHub の基本操作
  • npm/Node.js の基礎

基本コマンド

プロジェクト初期化

# 新規プロジェクトの作成
npx miyabi init my-web-app

# 出力:
# ✨ Miyabi プロジェクトを作成中...
# 📁 ディレクトリ作成: my-web-app/
# 📦 package.json を生成
# 🤖 Agent 設定を初期化
# ✅ プロジェクト作成完了!
#
# 次のステップ:
#   cd my-web-app
#   npm install
#   gh auth login  # GitHub 認証

既存プロジェクトへのインストール

# 既存プロジェクトに Miyabi を追加
cd existing-project

# ドライラン(変更内容を確認)
npx miyabi install --dry-run

# 出力:
# 📋 インストール内容プレビュー:
# ✓ 53個のラベル
# ✓ 12個の GitHub Actions workflow
# ✓ Projects V2 統合
# ✓ 15個の既存 Issue に自動ラベル付与
#
# 実際にインストールしますか? (y/n)

# 実際にインストール
npx miyabi install

ステータス確認

# Agent の状態を確認
npx miyabi status

# 出力:
# 📊 Miyabi システムステータス
#
# 状態          件数   ステータス
# ──────────────────────────────
# 待機中        2      ⏳ Waiting
# 分析中        1      🔄 Active
# 実装中        3      ⚡ Working
# レビュー中    1      🔍 Checking
# 完了          15     ✓ Complete
#
# 📝 最近の PR:
# #42 Add user dashboard
# #41 Fix login redirect
# #40 Document API endpoints

# ウォッチモード(10秒ごとに自動更新)
npx miyabi status --watch

実践例

例 1: 新規 Web アプリの開発

# ステップ 1: プロジェクト作成
npx miyabi init my-web-app
cd my-web-app

# ステップ 2: 機能追加の Issue 作成
gh issue create --title "Add user registration" \
  --body "Users should be able to register with email/password"

gh issue create --title "Add login page" \
  --body "Login form with email/password. Redirect to dashboard after login."

gh issue create --title "Add user dashboard" \
  --body "Show user profile, settings, and recent activity"

# ステップ 3: 10-15分待機
# Agent が自動的に Issue を処理し、PR を作成します

# ステップ 4: PR を確認
gh pr list

# ステップ 5: レビュー&マージ
gh pr review 42 --approve
gh pr merge 42 --squash

例 2: バグ修正

# 方法 1: Issue を作成
gh issue create --title "Fix login redirect loop" \
  --body "After successful login, user gets stuck in redirect loop. Check session handling."

# 方法 2: コミットメッセージで自動 Issue 作成
git commit -m "fix: Login redirect loop investigation #auto"
git push

# どちらの方法も:
# → Issue 作成
# → Agent が修正
# → PR が自動作成される

例 3: ドキュメント作成

# Issue からドキュメント生成
gh issue create --title "Document API endpoints" \
  --body "Add JSDoc comments to all API route handlers in src/api/"

# または PR コメントで依頼
# PR 上でコメント:
# @miyabi document the new API endpoints

# → ドキュメント Issue 作成
# → Agent がドキュメント生成
# → 新しい PR が作成される

例 4: テストカバレッジ向上

# テストカバレッジ向上の Issue
gh issue create --title "Increase test coverage to 80%" \
  --body "Add unit tests for authentication module"

# または PR コメントで:
# @miyabi increase test coverage for this file to 80%

# → テスト Issue 作成
# → Agent がテスト追加
# → PR が作成される

例 5: リファクタリング

# PR コメントでリファクタリング依頼
# PR 上でコメント:
# @miyabi refactor this component to use hooks

# → リファクタリング Issue 作成
# → CodeGenAgent がリファクタリング
# → hooks ベースの実装で新 PR 作成

例 6: 並行開発

# 複数の Issue を一度に作成
gh issue create --title "Feature A"
gh issue create --title "Feature B"
gh issue create --title "Feature C"

# 3つすべてが並行処理される
# 複数の Agent が同時に作業
# 15-20分以内に3つすべての PR が作成される ✅

高度な使用例

並行実行

# 単一 Issue の実行
npm run agents:parallel:exec -- --issues=270 --concurrency=1

# 複数 Issue の並行実行
npm run agents:parallel:exec -- --issues=270,240,276 --concurrency=3

# Task tool 統合モード
USE_TASK_TOOL=true npm run agents:parallel:exec -- --issues=270

# Worktree 分離モード(完全な並行実行)
USE_WORKTREE=true npm run agents:parallel:exec -- --issues=276

# すべての機能を有効化
USE_TASK_TOOL=true USE_WORKTREE=true \
  npm run agents:parallel:exec -- --issues=270,276 --concurrency=2

モニタリングとレポート

# システムステータス確認
npx miyabi status

# 詳細レポート表示
cat .ai/parallel-reports/agents-parallel-*.json | jq

# 成功率の集計
jq '.summary.success_rate' .ai/parallel-reports/*.json | \
  awk '{sum+=$1; count++} END {print sum/count "%"}'

# デバイス別統計
jq -r '.device_identifier' .ai/parallel-reports/*.json | \
  sort | uniq -c

# 平均実行時間
jq '.total_duration_ms' .ai/parallel-reports/*.json | \
  awk '{sum+=$1; count++} END {print sum/count/1000 "秒"}'

デバッグモード

# デバッグログを有効化
DEBUG=agents:* npm run agents:parallel:exec -- --issues=270

# ドライラン(実行せず計画のみ確認)
npm run agents:parallel:exec -- --issues=270 --dry-run

# 詳細な進捗表示
npm run agents:parallel:exec -- --issues=270 --verbose

優先度処理

Critical バグの自動検出

# AI が自動的に優先度を判定
gh issue create --title "URGENT: Production login failing" \
  --body "Critical bug: All users unable to login. 500 error in auth service."

# AI が自動的に以下を割り当て:
# - type:bug
# - priority:P0-Critical
# - agent:codegen
# → 最優先で処理される

学習タスク

# 実験的な機能(AI が検出)
gh issue create --title "Experiment: Try new AI model" \
  --body "Research and experiment with Claude 3.5 Opus for code generation"

# AI が自動的に以下を検出:
# - special:experiment
# - special:learning
# → Agent が探索的な作業として認識

コマンドリファレンス

プロジェクト管理

# プロジェクト情報取得
npm run project:info

# Issue/PR をプロジェクトに追加
npm run project:add

# プロジェクトレポート生成
npm run project:report

Label 管理

# 手動で AI ラベリング実行
npm run ai:label owner repo issue-number

# Label を同期
npm run sync:labels

Webhook テスト

# Issue webhook テスト
npm run webhook:test:issue

# PR webhook テスト
npm run webhook:test:pr

# コメント webhook テスト
npm run webhook:test:comment

ステートマシン

# 状態を確認
npm run state:check

# 状態遷移を実行
npm run state:transition

ベストプラクティス

1. 具体的な Issue 説明

# ✅ 良い例
gh issue create --title "Add password reset via email" \
  --body "
## 要件
- ユーザーがメールアドレスを入力してパスワードリセットをリクエスト
- リセットリンクをメールで送信
- リンクの有効期限は24時間

## 受け入れ条件
- [ ] リセットフォームが機能する
- [ ] メールが送信される
- [ ] リンクが24時間で期限切れになる
"

# ❌ 悪い例
gh issue create --title "Fix password" --body "Password doesn't work"

2. Issue の分割

# ✅ 良い例: 小さな Issue に分割
gh issue create --title "Add login UI"
gh issue create --title "Add login API endpoint"
gh issue create --title "Add login tests"

# ❌ 悪い例: 巨大な Issue
gh issue create --title "Complete authentication system"

3. 自然な言語の使用

# AI はコンテキストを理解します
gh issue create --title "Users report slow dashboard loading" \
  --body "The dashboard takes 5+ seconds to load. We should optimize the queries."

# → AI が自動的に以下を判定:
# - type: performance
# - severity: medium
# - agent: codegen

トラブルシューティング

Issue: Agent が動作しない

# 認証状態を確認
gh auth status

# Token を更新
gh auth refresh

# 環境変数を確認
echo $GITHUB_TOKEN
echo $ANTHROPIC_API_KEY

Issue: PR が作成されない

# Issue のラベルを確認
gh issue view 270

# Agent ログを確認
cat .ai/logs/*.md

# 手動で Agent を実行
npm run agents:parallel:exec -- --issues=270

Issue: ビルドエラー

# 依存関係を再インストール
rm -rf node_modules package-lock.json
npm install

# TypeScript エラーを確認
npm run typecheck

# Lint エラーを修正
npm run lint -- --fix

ヒントとコツ

エイリアスの設定

# ~/.bashrc または ~/.zshrc に追加
alias mi="npx miyabi"
alias mis="npx miyabi status"
alias mii="npx miyabi init"

# 使用例
mi status
mii my-new-project

GitHub CLI エイリアス

# ~/.config/gh/config.yml
aliases:
  feat: issue create --label "✨feature"
  bug: issue create --label "🐛bug"
  docs: issue create --label "📚documentation"

# 使用例
gh feat --title "Add dark mode"
gh bug --title "Fix navbar alignment"

関連ドキュメント

次のステップ

  1. Agent の仕組み を理解する
  2. 自動化 Workflow を設定する
  3. 高度な機能 を探索する

最終更新: 2025-10-10 バージョン: 2.0.0 ソース: CLI_USAGE_EXAMPLES.md メンテナー: Miyabi Team