メインコンテンツへスキップ

Documentation Index

Fetch the complete documentation index at: https://factory-changelog-may12.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Droid ExecはFactory自動化ワークフロー向けに設計されたヘッドレス実行モードです。インタラクティブなCLIとは異なり、droid execはタスクを完了して終了するワンショットコマンドとして動作するため、CI/CDパイプライン、シェルスクリプト、バッチ処理に最適です。
Droid Execクックブックをご覧ください。

概要と目的

Droid Execは以下を目的として設計されたワンショットタスクランナーです:
  • 読みやすいログと、要求時に構造化された成果物を生成
  • 変更/コマンド実行に対してオプトインを強制(デフォルトで安全)
  • 権限違反時に明確なエラーでファストフェイル
  • バッチおよび並列処理のためのシンプルな構成をサポート

非インタラクティブ

CI/CD統合のためにstdout/stderrに書き込むシングル実行

デフォルトで安全

デフォルトで読み取り専用、自律レベルによる変更への明示的オプトイン

構成可能

シェルスクリプト、並列実行、パイプライン統合用に設計

クリーンな出力

自動処理のための構造化出力フォーマットと成果物

実行モデル

  • stdout/stderrに書き込む非インタラクティブなシングル実行。
  • デフォルトはspecモード:エージェントは読み取り専用操作の実行のみ許可。
  • --autoを追加して編集とコマンドを有効化;リスクティアが実行可能な内容を制御。
CLIヘルプ(抜粋):
Usage: droid exec [options] [prompt]

Execute a single command (non-interactive mode)

Arguments:
  prompt                          The prompt to execute

Options:
  -o, --output-format <format>    Output format (default: "text")
  --input-format <format>         Input format: stream-jsonrpc for multi-turn sessions
  -f, --file <path>               Read prompt from file
  --auto <level>                  Autonomy level: low|medium|high
  --skip-permissions-unsafe       Skip ALL permission checks - allows all permissions (unsafe)
  -s, --session-id <id>           Existing session to continue (requires a prompt)
  -m, --model <id>                Model ID to use
  -r, --reasoning-effort <level>  Reasoning effort (defaults per model)
  --spec-model <id>               Model ID to use for spec mode
  --use-spec                      Start in spec mode
  --enabled-tools <ids>           Enable specific tools (comma or space separated list)
  --disabled-tools <ids>          Disable specific tools (comma or space separated list)
  --list-tools                    List available tools for the selected model and exit
  --cwd <path>                    Working directory path
  -h, --help                      display help for command
サポートされているモデル(例):
  • claude-opus-4-7
  • claude-opus-4-6
  • claude-opus-4-6-fast
  • claude-opus-4-5-20251101
  • claude-sonnet-4-6
  • claude-sonnet-4-5-20250929
  • claude-haiku-4-5-20251001
  • gpt-5.2
  • gpt-5.2-codex
  • gpt-5.3-codex
  • gpt-5.3-codex-fast
  • gpt-5.5
  • gpt-5.5-fast
  • gpt-5.5-pro
  • gpt-5.4
  • gpt-5.4-fast
  • gpt-5.4-mini
  • gemini-3.1-pro-preview
  • gemini-3-flash-preview
  • glm-5.1
  • kimi-k2.5
  • kimi-k2.6
  • minimax-m2.7
利用可能なモデルの完全なリストについては、利用可能なモデルを参照してください。

インストール

1

Droid CLIをインストール

curl -fsSL https://app.factory.ai/cli | sh
2

Factory APIキーの取得

Factory設定ページからAPIキーを生成します
3

環境変数の設定

APIキーを環境変数としてエクスポートします:
export FACTORY_API_KEY=fk-...

クイックスタート

  • 直接プロンプト:
    • droid exec "analyze code quality"
    • droid exec "fix the bug in src/main.js" --auto low
  • ファイルから:
    • droid exec -f prompt.md
  • パイプ:
    • echo "summarize repo structure" | droid exec
  • セッション継続:
    • droid exec --session-id <session-id> "continue with next steps"

自律性レベル

Droid execは階層化された自律性システムを使用して、エージェントが実行できる操作を制御します。デフォルトでは、読み取り専用モードで実行され、変更を有効にするには明示的なフラグが必要です。

DEFAULT(フラグなし)- 読み取り専用モード

実行せずに計画された変更をレビューするための最も安全なモード:
  • ✅ ファイルやログの読み取り: cat, less, head, tail, systemctl status
  • ✅ 表示コマンド: echo, pwd
  • ✅ 情報収集: whoami, date, uname, ps, top
  • ✅ Git読み取り操作: git status, git log, git diff
  • ✅ ディレクトリリスト: ls, find(-deleteや-execなし)
  • ❌ ファイルやシステムの変更は不可
  • 使用例: どのような変更が行われるかを安全にレビューする場合
# Analyze and plan refactoring without making changes
droid exec "Analyze the authentication system and create a detailed plan for migrating from session-based auth to OAuth2. List all files that would need changes and describe the modifications required."

# Review code quality and generate report
droid exec "Review the codebase for security vulnerabilities, performance issues, and code smells. Generate a prioritized list of improvements needed."

# Understand project structure
droid exec "Analyze the project architecture and create a dependency graph showing how modules interact with each other."

--auto low - 低リスクな操作

基本的なファイル操作を有効にし、システム変更をブロックします:
  • ✅ プロジェクトディレクトリ内でのファイル作成/編集
  • ❌ システム変更やパッケージインストールは不可
  • 使用例: ドキュメント更新、コード整形、コメント追加
# Safe file operations
droid exec --auto low "add JSDoc comments to all functions"
droid exec --auto low "fix typos in README.md"

--auto medium - 開発オペレーション

重大な副作用を持つ可能性があるオペレーションですが、これらの副作用は通常無害で、簡単に復旧できます。 低リスクオペレーションに一般的な開発タスクを追加します:
  • 信頼できるソースからのパッケージインストール:npm install、pip install(sudoなし)
  • 信頼できるエンドポイントへのネットワークリクエスト:既知のAPIへのcurl、wget
  • ローカルリポジトリを変更するGitオペレーション:git commit、git checkout、git pull(git pushは除く)
  • make、npm run build、mvn compileなどのツールによるコードビルド
  • ❌ git push、sudoコマンド、本番環境の変更は不可
  • 使用例: ローカル開発、テスト、依存関係管理
# Development tasks
droid exec --auto medium "install deps, run tests, fix issues"
droid exec --auto medium "update packages and resolve conflicts"

--auto high - 本番運用

信頼できないソースからのデータ転送や未知のコードの実行などセキュリティに影響を与える可能性のあるコマンド、または不可逆的なデータ損失や本番システム・デプロイメントの変更などの重大な副作用を伴うコマンド。
  • 任意/信頼できないコードの実行: curl | bash、eval、ダウンロードしたスクリプトの実行
  • 外部アクセスを許可する可能性のあるポートの公開やファイアウォールルールの変更
  • リモートリポジトリを変更するGitプッシュ操作: git push、git push —force
  • 本番デプロイメント、データベースマイグレーション、その他の機密操作への不可逆的な操作
  • パスワードや鍵などの機密情報にアクセスまたは変更するコマンド
  • ❌ 引き続きブロック: sudo rm -rf /、システム全体の変更
  • 使用例: CI/CDパイプライン、自動デプロイメント
# Full workflow automation
droid exec --auto high "fix bug, test, commit, and push to main"
droid exec --auto high "deploy to staging after running tests"

--skip-permissions-unsafe - すべてのチェックをバイパス

危険: このモードは確認なしですべての操作を許可します。Dockerコンテナや使い捨てVMなどの完全に隔離された環境でのみ使用してください。
  • ⚠️ 確認なしですべての操作を許可
  • ⚠️ 不可逆的な操作を実行可能
  • —autoフラグと組み合わせることはできません
  • 使用例: 隔離された環境
# In a disposable Docker container for CI testing
docker run --rm -v $(pwd):/workspace alpine:latest sh -c "
  apk add curl bash &&
  curl -fsSL https://app.factory.ai/cli | sh &&
  droid exec --skip-permissions-unsafe 'Install all system dependencies, modify system configs, run integration tests that require root access, and clean up test databases'
"

# In ephemeral GitHub Actions runner for rapid iteration
# where the runner is destroyed after each job
droid exec --skip-permissions-unsafe "Modify /etc/hosts for test domains, install custom kernel modules, run privileged container tests, and reset network interfaces"

# In a temporary VM for security testing
droid exec --skip-permissions-unsafe "Run penetration testing tools, modify firewall rules, test privilege escalation scenarios, and generate security audit reports"

フェイルファースト動作

リクエストされたアクションが現在の自律レベルを超える場合、droid execは以下を実行します:
  1. 明確なエラーメッセージと共に即座に停止
  2. 非ゼロの終了コードを返す
  3. 部分的な変更を一切実行しない
これにより、自動化スクリプトやCI/CDパイプラインでの予測可能な動作が保証されます。

出力形式とアーティファクト

Droid execは異なる用途に対応する3つの出力形式をサポートします:

text(デフォルト)

直接使用やログ用の人間が読みやすい出力:
$ droid exec --auto low "create a python file that prints 'hello world'"
Perfect! I've created a Python file named `hello_world.py` in your home directory that prints 'hello world' when executed.

json

スクリプトや自動化での解析用の構造化JSON出力:
$ droid exec "summarize this repository" --output-format json
{
  "type": "result",
  "subtype": "success",
  "is_error": false,
  "duration_ms": 5657,
  "num_turns": 1,
  "result": "This is a Factory documentation repository containing guides for CLI tools, web platform features, and onboarding procedures...",
  "session_id": "8af22e0a-d222-42c6-8c7e-7a059e391b0b"
}
JSON形式を使用する場面:
  • スクリプトで結果を解析する必要がある場合
  • プログラム的に成功/失敗をチェックする場合
  • 継続のためにセッションIDを抽出する場合
  • パイプラインで結果を処理する場合

生のJSON-RPC上にカスタムフローを構築する

カスタム統合では、Droidを長時間実行されるサブプロセスとして起動し、stdin/stdout経由でJSON-RPCの完全な制御面を操作できます:
droid exec --input-format stream-jsonrpc --output-format stream-jsonrpc --auto low
これは、Droidを中心に独自のインタラクションモデルを構築するための最も低レベルな統合方法です。プロセスからターンを送信し、アシスタント出力をストリーミングし、権限を処理し、設定を更新し、MCP/ツールを管理し、作業を中断し、セッションを再開またはフォークできます。 stdinの各行は1つのJSON-RPCリクエストです。stdoutの各行はJSON-RPCレスポンス、サーバーからのリクエスト、または通知です。カスタムクライアントは通常、以下を行います:
  • プロジェクトのcwdと必要なフラグでdroid execを起動する
  • 一意のIDを持つ改行区切りのJSON-RPCリクエストを書き込む
  • droid.initialize_sessionまたはdroid.load_sessionで開始する
  • droid.add_user_messageでターンを送信する
  • stdoutを1行ずつ読み取り、idでレスポンスを対応付ける
  • droid.session_notificationイベントでアシスタントのテキスト差分、ツールイベント、トークン使用量、エラー、ターン完了を処理する
  • droid.request_permissiondroid.ask_userなどのサーバーからクライアントへのリクエストに応答する
  • その他のセッションメソッドを呼び出して、作業の中断、設定の更新、MCPサーバー/ツールの管理、コンテキストの確認、セッションのフォーク、履歴のコンパクト化を行う
  • タイムアウト、プロセスのクリーンアップ、セッション永続化を実装する
生のstdin/stdoutの上に、以下のようなカスタムインタラクションフローを構築できます:
  • 独自のUXとコントロールを持つWeb、デスクトップ、IDE向けのエージェント体験
  • ユーザー操作をDroidのターンにルーティングするチャットまたはコパイロット画面
  • Droidタスクを実行し、進捗をビルドログに表示するCIやワークフローランナー
  • 作業をキューに入れ、セッションを再開し、会話をフォークし、結果を永続化するオーケストレーター
  • ツール権限リクエストを承認、拒否、変換、監査するポリシーレイヤー
  • Droidイベントを独自のプロトコル、メッセージバス、テレメトリ、ストレージ層に接続するブリッジ
プロトコルのリファレンスと実装パターンについては、TypeScript SDKの低レベルクライアントとプロセストランスポートを参照してください。 可能な場合はSDKの使用を推奨します:
  • TypeScript: @factory/droid-sdk は、Node.jsアプリ、ストリーミング、マルチターンセッション、構造化出力、権限、ツール制御、SDKバックエンドのMCPツールに対応
  • Python: droid-sdk は、asyncioアプリ、ストリーミング、直接的なクライアント制御、通知、権限、型付きイベント処理に対応
自動化されたパイプラインの場合、エージェントに特定のアーティファクトを書くよう指示することもできます:
droid exec --auto low "Analyze dependencies and write to deps.json"
droid exec --auto low "Generate metrics report in CSV format to metrics.csv"

作業ディレクトリ

  • --cwd を使用して実行範囲を指定する:
droid exec --cwd /home/runner/work/repo "Map internal packages and dump graphviz DOT to deps.dot"

モデルと推論力

モデルを -m で選択し、推論力を -r で調整してください。利用可能なモデルについては利用可能なモデルをご覧ください。
droid exec -m claude-sonnet-4-5-20250929 -r medium -f plan.md
--use-spec を使用して仕様モードで開始します。このモードでは、エージェントが実行前に計画を立てます:
droid exec --use-spec --auto low "refactor the auth module"
仕様フェーズで異なるモデルを使用することもできます:
droid exec --use-spec --spec-model claude-haiku-4-5-20251001 --auto medium "implement feature X"

ツール制御

モデルで利用可能なツールを一覧表示する:
droid exec --list-tools
droid exec --model gpt-5-codex --list-tools --output-format json
特定のツールを有効または無効にする:
# Enable additional tools
droid exec --enabled-tools ApplyPatch "refactor files"

# Disable specific tools
droid exec --auto medium --disabled-tools execute-cli "run edits only"

カスタムモデル

~/.factory/settings.jsonファイルにカスタムモデルを追加することで、droid execで使用するカスタムモデルを設定できます:
{
  "customModels": [
    {
      "model": "gpt-5.1-codex-custom",
      "displayName": "My Custom Model",
      "baseUrl": "https://api.openai.com/v1",
      "apiKey": "your-api-key-here",
      "provider": "openai"
    }
  ]
}
カスタムモデルを使用するには、custom: プレフィックスの後に表示名(スペースをダッシュで置き換えたもの)とインデックスを続けます:
droid exec --model "custom:My-Custom-Model-0" "analyze this codebase"
複数のカスタムモデルを設定している場合:
{
  "customModels": [
    {
      "model": "kimi-k2",
      "displayName": "Kimi K2 [Groq]",
      "baseUrl": "https://api.groq.com/openai/v1",
      "apiKey": "your-groq-key",
      "provider": "generic-chat-completion-api",
      "maxOutputTokens": 16384
    },
    {
      "model": "openai/gpt-oss-20b",
      "displayName": "GPT-OSS-20B [OpenRouter]",
      "baseUrl": "https://openrouter.ai/api/v1",
      "apiKey": "YOUR_OPENROUTER_KEY",
      "provider": "generic-chat-completion-api",
      "maxOutputTokens": 32000
    }
  ]
}
次のように参照します:
  • --model "custom:Kimi-K2-[Groq]-0"
  • --model "custom:GPT-OSS-20B-[OpenRouter]-1"
インデックスはcustomModels配列の位置に対応します(0ベース)。
推論努力(-r / --reasoning-effort)はカスタムモデルではまだサポートされていませんが、近日対応予定です。

バッチと並列パターン

シェルループ(制限された並行性):
# Process files in parallel (GNU xargs -P)
find src -name "*.ts" -print0 | xargs -0 -P 4 -I {} \
  droid exec --auto low "Refactor file: {} to use modern TS patterns"
バックグラウンドジョブの並列化:
# Process multiple directories in parallel with job control
for path in packages/ui packages/models apps/factory-app; do
  (
    cd "$path" &&
    droid exec --auto low "Run targeted analysis and write report.md"
  ) &
done
wait  # Wait for all background jobs to complete
チャンク化された入力:
# Split large file lists into manageable chunks
git diff --name-only origin/main...HEAD | split -l 50 - /tmp/files_
for f in /tmp/files_*; do
  list=$(tr '\n' ' ' < "$f")
  droid exec --auto low "Review changed files: $list and write to review.json"
done
rm /tmp/files_*  # Clean up temporary files
ワークフロー自動化 (CI/CD):
# Dead code detection and cleanup suggestions
name: Code Cleanup Analysis
on:
  schedule:
    - cron: '0 1 * * 0' # Weekly on Sundays
  workflow_dispatch:
jobs:
  cleanup-analysis:
    strategy:
      matrix:
        module: ['src/components', 'src/services', 'src/utils', 'src/hooks']
    steps:
      - uses: actions/checkout@v4
      - run: droid exec --cwd "${{ matrix.module }}" --auto low "Identify unused exports, dead code, and deprecated patterns. Generate cleanup recommendations in cleanup-report.md"

ユニークな使用例

ライセンスヘッダー執行機能:
git ls-files "*.ts" | xargs -I {} \
  droid exec --auto low "Ensure {} begins with the Apache-2.0 header; add it if missing"
APIコントラクト差分チェック(読み取り専用):
droid exec "Compare openapi.yaml operations to our TypeScript client methods and write drift.md with any mismatches"
セキュリティスイープ:
droid exec --auto low "Run a quick audit for sync child_process usage and propose fixes; write findings to sec-audit.csv"

終了動作

  • 0: 成功
  • 0以外: 失敗(権限違反、ツールエラー、目標未達成)。CIでは0以外を失敗として扱う。

ベストプラクティス

  • --auto lowを優先し、変更を最小限に抑えてスクリプト化されたステップでcommit/pushする。
  • 完全にサンドボックス化されていない限り、--skip-permissions-unsafeの使用は避ける。
  • パイプラインで検証可能なアーティファクトを出力するようエージェントに指示する。
  • モノレポでスコープを制限するために--cwdを使用する。