# CLIを使用したアーティファクトの管理

> CLIを使用したアーティファクトの管理 - ワークロードアーティファクトを支えるコードの作成、検査、構築、および管理を行うためのdr artifactコマンド。

This Markdown file sits beside the HTML page at the same path (with a `.md` suffix). It summarizes the topic and lists links for tools and LLM context.

Companion generated at `2026-07-27T18:44:30.817774+00:00` (UTC).

## Primary page

- [CLIを使用したアーティファクトの管理](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md): Full documentation for this topic (Markdown sidecar).

## Sections on this page

- [Subcommands](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#subcommands): In-page section heading.
- [dr artifact create](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-create): In-page section heading.
- [仕様ファイルの形式](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#spec-file-format): In-page section heading.
- [仕様ファイルの検証](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#spec-file-validation): In-page section heading.
- [コンテナのライフサイクル](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#container-lifecycles): In-page section heading.
- [例](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#artifact-create-examples): In-page section heading.
- [dr artifact list](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-list): In-page section heading.
- [例](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#artifact-list-examples): In-page section heading.
- [dr artifact get](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-get): In-page section heading.
- [例](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#artifact-get-examples): In-page section heading.
- [dr artifact delete](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-delete): In-page section heading.
- [dr artifact lock](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-lock): In-page section heading.
- [dr artifact build create](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-build-create): In-page section heading.
- [前提条件](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#build-create-prerequisites): In-page section heading.
- [例](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#build-create-examples): In-page section heading.
- [dr artifact build get](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-build-get): In-page section heading.
- [dr artifact build list](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-build-list): In-page section heading.
- [dr artifact build logs](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-build-logs): In-page section heading.
- [dr artifact code init](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-code-init): In-page section heading.
- [前提条件](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#code-init-prerequisites): In-page section heading.
- [例](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#code-init-examples): In-page section heading.
- [dr artifact code sync](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-code-sync): In-page section heading.
- [前提条件](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#code-sync-prerequisites): In-page section heading.
- [競合の処理](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#conflict-handling): In-page section heading.
- [JSONモード](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#json-mode): In-page section heading.
- [例](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#code-sync-examples): In-page section heading.
- [dr artifact code versions](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-code-versions): In-page section heading.
- [出力](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#versions-output): In-page section heading.
- [前提条件](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#versions-prerequisites): In-page section heading.
- [例](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#code-versions-examples): In-page section heading.
- [dr artifact code checkout](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#dr-artifact-code-checkout): In-page section heading.
- [例](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#code-checkout-examples): In-page section heading.
- [Error handling](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#error-handling): In-page section heading.
- [Exit codes](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#exit-codes): In-page section heading.

## Documentation content

> [!NOTE] プレミアム機能
> Workload APIはプレミアム機能です。 この機能を有効にする方法については、DataRobotの担当者または管理者にお問い合わせください。

`dr artifact` コマンドグループは、ターミナルからワークロードアーティファクト、サーバー側のイメージビルド、およびそれらを支えるローカルコードを管理します。 コマンドの構成は以下のとおりです。

```
dr artifact <command> [flags] 
```

このグループは、3つのサブコマンドグループに分かれています。

| サブコマンド | 説明 |
| --- | --- |
| dr artifact | サーバー上でアーティファクトを作成、一覧表示、検査、ロック、および削除します。 |
| dr artifact build | アーティファクトにおいて、サーバー側のイメージビルドをトリガー、監視、および検査します。 |
| dr artifact code | ローカルのプロジェクトディレクトリをアーティファクトにリンクし、コードを双方向に同期します。 |

> [!NOTE] Codeコマンドの状態ディレクトリ
> `code` のコマンドは、プロジェクトのルートにある `.wapi/` 状態ディレクトリを管理し、各ディレクトリがどのアーティファクト、カタログ、バージョンに紐付けられているかを追跡します。 このモデルは概念的に `.git/` に似ています。つまり、ローカルでの作業はプロジェクトのルートで行われ、 `.wapi/` は各操作でのドリフトを検出するために使用されるリモートバインディングと最後に同期された状態を記録します。

開始する前に、コマンドグループを有効にし、認証を行います。 `dr artifact` および `dr workload` はデフォルトでは非表示になっています。1つの環境変数を設定することで、両方を有効にできます。

```
export DATAROBOT_CLI_FEATURE_WORKLOAD=true
dr auth login 
```

以下は、これらのコマンドを使用した典型的なコードからワークロードへのフローです。

```
# Create the artifact on the server
dr artifact create --spec-file spec.json

# Link a local directory to it (use the printed ID)
dr artifact code init <artifact-id>

# Upload code and let sync fill in the codeRef
dr artifact code sync

# Build the container image server-side and wait for completion
dr artifact build create <artifact-id> --wait

# Lock the artifact for production
dr artifact lock <artifact-id> 
```

詳細については、 [サブコマンド](https://docs.datarobot.com/ja/docs/workload-api/workload-interfaces/workload-cli/artifact-cli.html.md#subcommands) にある各サブコマンドの詳細なドキュメントを参照してください。

## Subcommands

| サブコマンド | 説明 |
| --- | --- |
| dr artifact create | JSONまたはYAMLの仕様ファイルからワークロードアーティファクトを作成します。 |
| dr artifact list | 必要に応じてフィルターを設定して、ワークロードアーティファクトを一覧表示します。 |
| dr artifact get | ID指定で単一のワークロードアーティファクトの詳細を表示します。 |
| dr artifact delete | ID指定でワークロードアーティファクトを削除します。 |
| dr artifact lock | ドラフトアーティファクトをロックし、変更不可にします。 |
| dr artifact build create | アーティファクトにおいて、サーバー側のイメージビルドをトリガーします。 |
| dr artifact build get | ID指定で単一のビルドの詳細を表示します。 |
| dr artifact build list | アーティファクトのビルドを一覧表示します。 |
| dr artifact build logs | 特定のビルドのビルドログを出力します。 |
| dr artifact code init | プロジェクトディレクトリを既存のワークロードアーティファクトにリンクします。 |
| dr artifact code sync | このディレクトリとリンクされたアーティファクトの間で、ローカルでの編集内容をプッシュし、リモートでの変更内容をプルします。 |
| dr artifact code versions | このプロジェクトディレクトリがリンクされているアーティファクトのカタログバージョン履歴を一覧表示します。 |
| dr artifact code checkout | 特定のカタログバージョンを.wapi/.checkouts/<version-id>/にダウンロードし、読み取り専用で確認できるようにします。 |

### dr artifact create

JSONまたはYAMLの仕様ファイルからワークロードアーティファクトを作成します。

```
dr artifact create --spec-file <path> [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| --spec-file <path> | JSONまたはYAMLの仕様ファイルへのパス。 必須。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

#### 仕様ファイルの形式

仕様ファイルでは、ワークロードアーティファクトが定義されています。 JSON形式とYAML形式の両方がサポートされています。 まずは、以下の例を参照してください。

**最低限の仕様（構築済みのイメージ）:**
```
{
  "name": "my-agent",
  "spec": {
    "containerGroups": [{
      "containers": [{
        "imageUri": "nginx:latest",
        "port": 8080,
        "primary": true
      }]
    }]
  }
} 
```

**最低限の仕様（指定されたDockerfileからの構築）:**
```
{
  "name": "my-agent",
  "spec": {
    "containerGroups": [{
      "containers": [{
        "primary": true,
        "port": 8080,
        "imageBuildConfig": { "dockerfile": { "source": "provided" } }
      }]
    }]
  }
} 
```

**詳細仕様（既存のカタログバージョンに接続）:**
```
{
  "name": "my-agent",
  "description": "Optional description shown in the DataRobot UI.",
  "spec": {
    "containerGroups": [{
      "containers": [{
        "primary": true,
        "port": 8080,
        "imageBuildConfig": {
          "dockerfile": { "source": "provided" },
          "codeRef": {
            "datarobot": {
              "catalogId": "67890abcdef1234567890abc",
              "catalogVersionId": "67890abcdef1234567890def"
            }
          }
        }
      }]
    }]
  }
} 
```


#### 仕様ファイルの検証

以下の検証ルールが適用されます。

- クライアント側： name を空にしないでください。 spec.containerGroups には少なくとも1つのエントリーが含まれている必要があります。各グループの containers 配列には、少なくとも1つのエントリーが含まれている必要があります。
- サーバー側：Workload APIはフィールドレベルの構造を検証し、不一致がある場合はJSONパスの詳細とともに 422 を返します。
- 未知のフィールドはサーバーにそのまま渡されるため、サーバーが受け付けるフィールドであれば、ここですべて受け付けます。 仕様ファイルは厳密に解析されません。

#### コンテナのライフサイクル

以下のコンテナライフサイクルがサポートされています。

1. 構築済みのイメージ — エントリーコンテナで imageUri （および port と primary ）を設定します。
2. 提供されたDockerfileからの構築 — imageBuildConfig.dockerfile.source = "provided" を設定して、同期されたコード内の ./Dockerfile から構築します。
3. 生成されたDockerfileからの構築 — imageBuildConfig.dockerfile.source = "generated" を、 executionEnvironmentId 、 executionEnvironmentVersionId 、および entrypoint とともに設定して、サーバーがベースイメージからDockerfileを生成するようにします。

> [!NOTE] コード同期によるcodeRefの設定
> `dr artifact code sync` を実行すると、最初のアップロード後に `imageBuildConfig.codeRef` が自動的に設定されます。そのため、通常、新しく作成されたアーティファクトには、コードを同期するまでは `codeRef` が設定されていません。

#### 例

**デフォルトである人間が読み取れる形式の出力を使用して作成する:**
```
dr artifact create --spec-file spec.json 
```

```
ID:          67890abcdef1234567890abc
Name:        my-agent
Status:      draft
Catalog ID:  —
Version ID:  —
Created:     2026-05-14 10:00 UTC
Updated:     2026-05-14 10:00 UTC 
```

**機械で読み取れるJSON出力を使用して作成する:**
```
dr artifact create --spec-file spec.json --output-format json 
```

```
{
  "id": "67890abcdef1234567890abc",
  "name": "my-agent",
  "status": "draft",
  "catalogId": "",
  "versionId": "",
  "createdAt": "2026-05-14T10:00:00Z",
  "updatedAt": "2026-05-14T10:00:00Z"
} 
```


### dr artifact list

必要に応じてフィルターを設定して、ワークロードアーティファクトを一覧表示します。

```
dr artifact list [--limit <n>] [--status draft|locked] [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| --limit <n> | 返されるアーティファクトの最大数。 デフォルトは100です。 正の整数にする必要があります。 |
| --status <draft\ \| locked> | ステータスでフィルターします。 オプション。省略した場合は、すべてのステータスが返されます。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

#### 例

**すべてのアーティファクトを一覧表示する:**
```
dr artifact list 
```

枠付きの表として表示されます。

```
╭──────────────────────────┬───────────┬────────┬──────────────────────────┬──────────────────────────┬──────────────────────╮
│ ARTIFACT ID              │ NAME      │ STATUS │ CATALOG ID               │ VERSION ID               │ UPDATED              │
├──────────────────────────┼───────────┼────────┼──────────────────────────┼──────────────────────────┼──────────────────────┤
│ 67890abcdef1234567890abc │ my-agent  │ draft  │ —                        │ —                        │ 2026-05-14 10:00 UTC │
│ 67890abcdef1234567890aaa │ chat-app  │ locked │ 67890abcdef1234567890cat │ 67890abcdef1234567890ver │ 2026-05-13 14:32 UTC │
╰──────────────────────────┴───────────┴────────┴──────────────────────────┴──────────────────────────┴──────────────────────╯ 
```

一致するアーティファクトがない場合、テキスト出力は「アーティファクトが見つかりません。」となり、JSON出力は `{"artifacts": []}` となります。

**ステータスによるフィルター（JSON出力）:**
```
dr artifact list --status draft --output-format json 
```

```
{
  "artifacts": [
    {
      "id": "67890abcdef1234567890abc",
      "name": "my-agent",
      "status": "draft",
      "catalogId": "",
      "versionId": "",
      "createdAt": "2026-05-14T10:00:00Z",
      "updatedAt": "2026-05-14T10:00:00Z"
    }
  ]
} 
```


### dr artifact get

ID指定で単一のワークロードアーティファクトの詳細を表示します。

```
dr artifact get <artifact-id> [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| <artifact-id> | アーティファクトID。 必須。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

#### 例

**ID指定でアーティファクトを取得する:**
```
dr artifact get 67890abcdef1234567890abc 
```

```
ID:          67890abcdef1234567890abc
Name:        my-agent
Status:      draft
Catalog ID:  —
Version ID:  —
Created:     2026-05-14 10:00 UTC
Updated:     2026-05-14 10:00 UTC 
```

**ID指定でアーティファクトを取得する（JSON出力）:**
```
dr artifact get 67890abcdef1234567890abc --output-format json 
```

```
{
  "id": "67890abcdef1234567890abc",
  "name": "my-agent",
  "status": "draft",
  "catalogId": "",
  "versionId": "",
  "createdAt": "2026-05-14T10:00:00Z",
  "updatedAt": "2026-05-14T10:00:00Z"
} 
```


### dr artifact delete

ID指定でワークロードアーティファクトを削除します。 2つのサーバー側ルールが適用されます：ロックされたアーティファクトは削除できません。また、ワークロードによってまだ参照されているドラフトアーティファクトは、ワークロードが最初に削除されるまで削除できません。

```
dr artifact delete <artifact-id> [-y|--yes] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| <artifact-id> | アーティファクトID。 必須。 |
| -y, --yes | 確認プロンプトをスキップします。 |

### dr artifact lock

ドラフトアーティファクトをロックすると、そのアーティファクトは変更不可になり、本番環境のワークロードで使用できるようになります。 ロックは元に戻せません。さらに変更を加えるには、アーティファクトのクローンを作成するか、新しいアーティファクトを作成してください。

```
dr artifact lock <artifact-id> [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| <artifact-id> | アーティファクトID。 必須。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

> [!NOTE] ロックは元に戻せません
> ロックされると、アーティファクトの名前、説明、および仕様は変更不可となり、そのアーティファクトは削除できなくなります。 さらに変更を加えるには、 `dr artifact create` で新しいドラフトアーティファクトを作成してください。

### dr artifact build create

アーティファクトにおいて、サーバー側のイメージビルドをトリガーします。 プラットフォームは、アーティファクトの現在の `codeRef` からコンテナイメージを構築し、それをDataRobotの内部レジストリにプッシュした後、アーティファクトの `imageUri` にその情報を設定します。 構築できるのはドラフトアーティファクトのみです。

```
dr artifact build create [<artifact-id>] [--wait] [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| <artifact-id> | アーティファクトID。 dr artifact code initを通じてリンクされたディレクトリ内で実行する場合は省略可能です。IDは.wapi/config.jsonから読み込まれます。 |
| --wait | ビルドが最終状態（succeededまたはfailed）に達するまでポーリングを行い、失敗した場合はビルドログの末尾を出力します。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

#### 前提条件

- アーティファクトは draft ステータスである必要があります。
- アーティファクトには、少なくとも1つの同期済みカタログバージョンを指す codeRef が含まれている必要があります。 アーティファクトにコードがない場合は、最初に dr artifact code sync を実行します。

#### 例

```
# Commands
# Trigger a build from a linked directory (no artifact-id needed)
dr artifact build create

# Trigger a build by artifact ID and return immediately
dr artifact build create 67890abcdef1234567890abc

# Trigger a build and wait for it to finish
dr artifact build create 67890abcdef1234567890abc --wait 
```

### dr artifact build get

ID指定で単一のビルドの詳細を表示します。

```
dr artifact build get <artifact-id> <build-id> [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| <artifact-id> | アーティファクトID。 必須。 |
| <build-id> | ビルドID。 必須。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

### dr artifact build list

アーティファクトのビルドを最新順に一覧表示します。

```
dr artifact build list <artifact-id> [--limit <n>] [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| <artifact-id> | アーティファクトID。 必須。 |
| --limit <n> | 返されるビルドの最大数。 デフォルトは100です。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

### dr artifact build logs

特定のビルドのビルドログを出力します。 位置引数を1つ指定して呼び出した場合、アーティファクトIDは現在のディレクトリにある `.wapi/config.json` から読み込まれます。 2つ指定して呼び出した場合、最初の引数がアーティファクトIDとなります。

```
dr artifact build logs [<artifact-id>] <build-id> [--level <level>] [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| <artifact-id> | アーティファクトID。 リンクされたディレクトリ内で実行する場合は省略可能です。その場合、IDは.wapi/config.jsonから読み込まれます。 |
| <build-id> | ビルドID。 必須。 |
| --level <level> | 表示されるログの最低レベル：debug、info、warn、error。 デフォルトはinfoです。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

### dr artifact code init

プロジェクトディレクトリを既存のワークロードアーティファクトにリンクします。 プロジェクトのルートに `.wapi/` 状態ディレクトリを作成し、そのディレクトリがどのアーティファクト、カタログ、およびバージョンに関連付けられているかを記録します。 他の `code` コマンドを実行する前に必要です。

```
dr artifact code init [<artifact-id>] [--dir <path>] [-y|--yes] [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| <artifact-id> | オプションです。 対話モードで省略した場合は、プロンプトが表示されます。 |
| --dir <path> | プロジェクトのディレクトリ。 デフォルトは現在のディレクトリです。 |
| -y, --yes | 対話型のプロンプトをスキップし、デフォルトを使用します。 DATAROBOT_CLI_NON_INTERACTIVE=trueを設定して有効にすることもできます。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

#### 前提条件

- そのアーティファクトはすでに存在している必要があります。 dr artifact create を使用するか、DataRobot UIで作成してください。
- アーティファクトは draft ステータスである必要があります。 ロックされたアーティファクトは変更不可です。

#### 例

```
# Commands
# Interactive: prompts for the directory
dr artifact code init 67890abcdef1234567890abc

# Non-interactive: link the current directory
dr artifact code init 67890abcdef1234567890abc --yes

# Link a sibling directory
dr artifact code init 67890abcdef1234567890abc --dir ./service 
```

### dr artifact code sync

このディレクトリとリンクされたアーティファクトの間で、ローカルでの編集内容をプッシュし、リモートでの変更内容をプルします。 最後に確認された状態との3方向の差分を計算し、競合を自動的に解決し（リモート側の変更が優先され、ローカルバージョンは `*.LOCAL.<timestamp>` という形式のコピーとして保存されます）、その結果得られたプランを1回のバージョン管理された操作で適用します。

```
dr artifact code sync [--dir <path>] [--dry-run | --diff] [-y|--yes] [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| --dir <path> | プロジェクトのディレクトリ。 デフォルトは現在のディレクトリです。 |
| --dry-run | 何も書き込まずにプランを表示します。 リモート書き込みの前に終了します。 |
| --diff | プランと、ファイルごとの統合差分を表示します。 --dry-runとは同時に指定できません。 リモート書き込みの前に終了します。 |
| -y, --yes | プラン後のプロンプトを自動確認します。対話型ディレクトリプロンプトもスキップします。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

#### 前提条件

ディレクトリは、すでに `dr artifact code init` によってリンクされている必要があります。 そうでない場合、コマンドは `not linked: run 'dr artifact code init <artifact-id>' first` を返します。

#### 競合の処理

同じファイルが両側で異なる場合、 `sync` はリモート側のバージョンを採用し、ローカルコピーを `<path>.LOCAL.<timestamp>` という名前で並行して書き込むことで、自動的に解決します。 対話モードでは、競合が発生するとコマンドが一時停止するため、プランを確認して中止することができます。 `--yes` を指定すると、プロンプトをスキップして無条件に適用します。

#### JSONモード

JSONモードでは、プランは常に最初のドキュメントとして出力されます。 `--dry-run` も `--diff` も設定されておらず、かつプランに明示的な確認が必要ない場合、実行結果は2番目のJSONドキュメントとして出力されます。

#### 例

```
# Commands
# Preview what would change
dr artifact code sync --dry-run

# Preview with per-file diffs
dr artifact code sync --diff

# Push and pull; prompt on conflicts
dr artifact code sync

# Push and pull non-interactively
dr artifact code sync --yes 
```

### dr artifact code versions

このプロジェクトディレクトリがリンクされているアーティファクトのカタログバージョン履歴を一覧表示します。

```
dr artifact code versions [--dir <path>] [--limit <n>] [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| --dir <path> | プロジェクトのディレクトリ。 デフォルトは現在のディレクトリです。 |
| --limit <n> | 返されるバージョンの最大数。 デフォルトは100です。 正の整数にする必要があります。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

#### 出力

出力には、アーティファクトの `codeRef` が現在指しているバージョンに `*` が付いて表示され、ローカルの `.wapi/` 状態が最後に同期されたバージョンが報告されます。 これにより、バージョンのずれが一目でわかります。最後に同期されたバージョン以外のバージョンの横に `*` が付いている場合、 `sync` を実行するとローカルファイルが更新されます。

#### 前提条件

- ディレクトリは、 dr artifact code init を通じてリンクされている必要があります。 そうでない場合： not linked to an artifact. Run 'dr artifact code init <id>' first
- リンクされたカタログにバージョンが存在するためには、少なくとも1回の同期が行われている必要があります。 そうでない場合： no code has been synced yet. Run 'dr artifact code sync' first

#### 例

```
# Commands
dr artifact code versions
dr artifact code versions --limit 10
dr artifact code versions --output-format json 
```

### dr artifact code checkout

特定のカタログバージョンを `.wapi/.checkouts/<version-id>/` にダウンロードし、読み取り専用で確認できるようにします。 作業ディレクトリおよび `.wapi/` の同期状態は、一切変更されません。

```
dr artifact code checkout [<version-id>] [--dir <path>] [--clean] [-y|--yes] [--output-format text|json] 
```

| 引数/フラグ | 説明 |
| --- | --- |
| <version-id> | 完全なバージョン ID または一意のプレフィックス。 省略した場合（かつ--yesが設定されていない場合）、プロンプトが表示されます。 |
| --dir <path> | プロジェクトのディレクトリ。 デフォルトは現在のディレクトリです。 |
| --clean | ダウンロードする代わりに、チェックアウトディレクトリを削除します。 位置引数を指定しない場合は、すべてのチェックアウトが削除されます。位置引数を指定した場合は、一致するチェックアウトのみが削除されます。 |
| -y, --yes | 対話型のプロンプトをスキップします。 |
| --output-format <text\ \| json> | 出力形式。 デフォルトはtextです。 |

#### 例

```
# Commands
# Prompt for a version, then download
dr artifact code checkout

# Download a specific version (full ID or any unique prefix)
dr artifact code checkout abcdef12

# Download into a different project directory
dr artifact code checkout abcdef12 --dir ./service

# Remove all checkouts
dr artifact code checkout --clean

# Remove a single checkout
dr artifact code checkout abcdef12 --clean 
```

## Error handling

| エラー | 原因と解決策 |
| --- | --- |
| not authenticated | まずdr auth loginを実行してください。すべてのdr artifactコマンドには認証が必要です。 |
| invalid spec: required field 'name' is missing or empty | 仕様ファイルのnameが欠落しているか、空になっています。 空ではない文字列を追加してください。 |
| invalid spec: 'spec.containerGroups' must contain at least one entry | spec.containerGroups配列が空です。 少なくとも1つのグループを追加します。 |
| file not found: <path> | --spec-fileのパスは存在しません。 パスを確認してください。 |
| invalid status "...": use draft or locked | artifact listに渡された--statusの値は、受け入れ可能ないずれの値にも該当しません。 |
| artifact <id> not found | そのアーティファクトIDは存在しません。 dr artifact listでIDを確認してください。 |
| artifact is locked (immutable); cannot init on a registered artifact | ロックされたアーティファクトは、リンクしたり、変更を加えたりすることはできません。 dr artifact createを使用して、新しいドラフトアーティファクトを作成します。 |
| not linked: run 'dr artifact code init <artifact-id>' first | ディレクトリに.wapi/状態がありません。 まずdr artifact code initを実行します。 |
| init aborted: project already linked | ディレクトリにはすでに.wapi/状態が存在します。 dr artifact code syncを使用するか、.wapi/を削除してリンクを再設定してください。 |
| no code has been synced yet. Run 'dr artifact code sync' first | リンク先のアーティファクトには、まだカタログバージョンがありません。 syncを実行してコードをアップロードしてください。 |

## Exit codes

| コード | Meaning |
| --- | --- |
| 0 | Success. |
| 1 | エラー（検証失敗、APIエラー、競合、未認証など）。 |
| 130 | 中断されました（Ctrl+C）。 |
