> ## Documentation Index
> Fetch the complete documentation index at: https://docs.therefrain.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# compose

> 複数の手順書を1つの分岐付き手順書にマージします。

## 概要

```bash theme={null}
npx @refrainai/cli compose -- \
  --branch-on <varName> \
  --case "match:path.yaml" \
  --output <path> \
  [options]
```

複数の生成済み手順書を、変数の値に基づく条件分岐を持つ1つの手順書にマージします。同じワークフローで入力に応じて異なるパスがある場合に有用です。

## 必須引数

| 引数                | 説明                 |
| ----------------- | ------------------ |
| `--output <path>` | 合成した手順書 YAML の出力パス |

## オプション引数

| 引数                         | デフォルト | 説明                   |
| -------------------------- | ----- | -------------------- |
| `--branch-on <varName>`    | -     | 分岐条件の変数名（省略時は対話的に入力） |
| `--case "match:path.yaml"` | -     | ケース定義 — 複数指定可        |
| `--goal <text>`            | -     | 合成した手順書のゴール説明        |
| `--locale <code>`          | `en`  | UI 言語: `en` または `ja` |

<Note>
  `--branch-on` や `--case` を省略すると、CLI が対話モードに入り入力を求めます。
</Note>

## 動作の仕組み

<Steps>
  <Step title="入力の収集">
    分岐変数、ケース、ゴールを収集（CLI 引数または対話的に）。
  </Step>

  <Step title="手順書の読み込み">
    各ケースの YAML ファイルを読み込みバリデーション。
  </Step>

  <Step title="変数のマージ">
    全ケースの変数をマージ。分岐変数を `source: prompt` で追加。
  </Step>

  <Step title="分岐の構築">
    全ケースのステップを1つの `branches` ステップに組み立て。
  </Step>

  <Step title="プレビューと編集">
    合成した手順書をプレビューし、保存前に調整が可能。
  </Step>

  <Step title="出力の書き込み">
    最終 YAML を Zod でバリデーションし、出力パスに書き込み。
  </Step>
</Steps>

## 使用例

### CLI 引数で合成

```bash theme={null}
npx @refrainai/cli compose -- \
  --branch-on accountType \
  --case "personal:./flows/personal-signup.yaml" \
  --case "business:./flows/business-signup.yaml" \
  --goal "アカウントタイプに基づいてサインアップを完了" \
  --output ./flows/signup-combined.yaml
```

これにより以下のような手順書が作成されます：

1. ユーザーに `accountType` を入力させる
2. `"personal"` の場合 → 個人サインアップのステップを実行
3. `"business"` の場合 → 法人サインアップのステップを実行

### 対話モード

```bash theme={null}
npx @refrainai/cli compose -- \
  --output ./flows/combined.yaml
```

CLI が分岐変数、ケース、ゴールを対話的に質問します。

## 出力構造

合成された手順書は `branches` を持つ1つのステップを含みます：

```yaml theme={null}
title: アカウントタイプに基づいてサインアップを完了
variables:
  accountType:
    source: prompt
    description: "分岐変数"
    required: true
  # ... 全ケースからマージされた変数
steps:
  - ordinal: 0
    description: "accountType で分岐"
    branches:
      value: "{{accountType}}"
      cases:
        - match: "personal"
          steps:
            # ... personal-signup.yaml のステップ
        - match: "business"
          steps:
            # ... business-signup.yaml のステップ
```

分岐スキーマの詳細は[ループ・分岐](/ja/yaml/loops-and-branches#分岐)を参照してください。
