# CLI Command Reference

Comprehensive documentation for all Shipyard commands and runtime flags.

---

## Global Usage

```bash
shipyard [command] [flags]
```

### Global Flags
- `-h, --help`: Display help for Shipyard or subcommands.

### Exit Codes

| Code | Meaning |
|---|---|
| `0` | Success. For `run`, `compare`, and gating commands: the verdict passed. |
| `1` | Gate blocked or the run/validate verdict failed. |
| `2` | Usage error: missing or unusable inputs. |

---

## Commands

### 1. `shipyard init`
Initializes evaluation resources (single evals, evalset benchmark suites, or CI pipelines).

```bash
shipyard init [evalset|eval|ci] [name] [flags]
```

#### Subcommands:
- `eval [name]`: Scaffolds a single evaluation directory.
- `evalset [name]`: Scaffolds an evalset suite directory.
- `ci [name]`: Scaffolds a gated CI pipeline (see below).

#### Flags:
- `-n, --name string`: Name of the resource to create (prompts interactively if not provided).
- `-p, --path string`: Parent path where the folder will be created (defaults to `.`).

#### Examples:
```bash
# Initialize an evaluation called "bench-sql" in the current directory
shipyard init eval bench-sql

# Initialize an evaluation in a specific directory
shipyard init eval auth-flow --path ./benchmarks/security

# Initialize an evalset suite
shipyard init evalset swe-bench
```

---

### 2. `shipyard run`
Runs an evaluation or an evalset suite.

```bash
shipyard run [path] [flags]
```

#### Arguments:
- `path`: Target evaluation directory (containing `eval.toml`) or evalset directory (containing `evalset.toml`). Defaults to current directory (`.`).

#### Flags:
| Flag | Type | Description |
|---|---|---|
| `--run-name string` | string | Explicit name of the run (creates `rollouts/{run-name}/`). |
| `--run-id string` | string | Alias for `--run-name`. |
| `--agent string` | string | Agent or plugin runtime override (e.g. `claude-code`, `langgraph`, `codex`). |
| `--provider string` | string | LLM provider runtime override (e.g. `openai`, `anthropic`, `gemini`, `ollama`). |
| `--model string` | string | Model name runtime override (e.g. `gpt-4o-mini`, `claude-3-5-sonnet-20241022`). |
| `--command string` | string | Agent execution command override (e.g. `'python my_agent.py'`). |
| `--env string` | string | Environment runtime override (e.g. `docker`, `local`, `custom`). |
| `--keep-env` | bool | Preserve sandbox container/process after run for post-mortem debugging (default `false`). Implies `--keep-workdir`. |
| `--repeat int` | int | Run each eval `K` times. Aggregates `pass@k`, `pass^k`, mean ± σ, and flake detection. Overrides `repeat` in `eval.toml`. Repeats are isolated: the workspace is restored between repeats (and after the run) so each repeat is an independent sample. |
| `--report list` | string | Comma-separated report formats: `markdown`, `json`, `junit`. Writes `<path>/shipyard-report.md`, `<path>/shipyard-report.json`, and `<path>/shipyard-junit.xml`. |
| `--json` | bool | Print machine-readable suite results JSON to stdout instead of the human output. The exit code still reflects the verdict. |
| `--dry-run` | bool | Print the resolved plan (agent plugin, command, model, environment type, image/dockerfile, mount, repeat, config hash, suite digest, gate policy) and execute nothing. Costs zero tokens. |
| `--no-redact` | bool | Disable best-effort credential scrubbing of captured artifacts. |
| `--keep-workdir` | bool | Leave agent changes in the eval workspace after the run (default: the workspace is restored so the next run starts clean). `--keep-env` implies it. |

#### Examples:

```bash
# Run the evaluation in current directory
shipyard run

# Run a specific benchmark suite
shipyard run ./benchmarks/core-evalset

# Override agent and model on the fly
shipyard run ./tests/memory-leak --provider anthropic --model claude-3-5-sonnet-20241022

# Debug an evaluation in Docker without destroying the container
shipyard run ./tests/memory-leak --keep-env

# Run locally for fast iteration
shipyard run ./tests/memory-leak --env local

# Three isolated repeats per eval, aggregate stats in the rollout
shipyard run evalsets/starter-eval --repeat 3

# Reports for a CI test pane, plus machine-readable results on stdout
shipyard run evalsets/starter-eval --repeat 3 --report markdown,junit --json

# See exactly what would run, without spending a token
shipyard run evalsets/starter-eval --dry-run

# Leave the agent's changes in place after the run
shipyard run ./tests/memory-leak --keep-workdir
```

#### Exit Codes:
- `0`: Every eval passed.
- `1`: At least one eval failed or errored.

---

### 3. `shipyard baseline save`
Freezes a completed run into `baselines/<name>.json`. The baseline is
schema-stable, carries the suite digest, `k`, creation metadata, and the full
per-eval aggregates, and is designed to be committed. See
[Baselines & Compare](/docs/baselines-and-compare).

```bash
shipyard baseline save [path] --name main [--run-id X | --results file] [--json] [--created-by who]
```

#### Flags:
| Flag | Type | Description |
|---|---|---|
| `--name string` | string | Baseline name (default `main`). Writes `baselines/<name>.json` under the target. |
| `--run-id string` | string | Read a specific rollout instead of the newest completed run. |
| `--results string` | string | Build the baseline from a `results.json` file instead of local rollouts. |
| `--json` | bool | Print the written baseline document to stdout. |
| `--created-by string` | string | Record who produced the baseline (defaults to `shipyard`). |

#### Examples:
```bash
# Newest run under the target
shipyard baseline save evalsets/starter-eval --name main

# A chosen run, with attribution
shipyard baseline save evalsets/starter-eval --name main \
  --run-id 2026-10-15T08-00-00Z --created-by release-bot

# From a results.json produced by another CI job
shipyard baseline save evalsets/starter-eval --name main --results ./results.json
```

---

### 4. `shipyard compare`
Compares a candidate run against a baseline and applies the gate policy. Per
eval, reports `improved | same | regressed | flaked | errored | skipped`, prints
the 95% Student-t noise margin, and exits with the verdict. See
[Gate policy](/docs/gate-policy).

```bash
shipyard compare [path] --baseline baselines/main.json [--candidate results.json] [--run-id X] [--json] [--allow-suite-mismatch] [--policy file]
```

#### Flags:
| Flag | Type | Description |
|---|---|---|
| `--baseline string` | string | Path to the baseline file. Required. |
| `--candidate string` | string | `results.json` to compare instead of local rollouts. |
| `--run-id string` | string | Compare a specific local rollout. |
| `--json` | bool | Print the delta document to stdout. |
| `--allow-suite-mismatch` | bool | Compare only evals whose definitions match, and say so. Blocks if none remain. |
| `--policy string` | string | Gate policy file to apply to this comparison. |

#### Examples:
```bash
# Gate a pull request against the committed baseline
shipyard compare evalsets/starter-eval --baseline baselines/main.json \
  --candidate results.json

# Machine-readable output for a bot
shipyard compare evalsets/starter-eval --baseline baselines/main.json --json

# Stricter CI policy
shipyard compare evalsets/starter-eval --baseline baselines/main.json \
  --policy .shipyard/gate.toml
```

#### Exit Codes:
- `0`: Gate passed.
- `1`: Gate blocked (regression, flake, infra error, or definition mismatch).
- `2`: Usage error (missing or unusable inputs).

---

### 5. `shipyard validate`
Static linter for an eval or evalset. Catches a broken eval before any
container starts: TOML parses, referenced files exist (instruction, rubric,
Dockerfile, agent entrypoints), policy is sane (thresholds 0..1, `repeat >= 1`,
gate values), the instruction is non-empty, duplicate eval names in an evalset
are flagged, and a rubric probe runs (Python rubrics must parse, `rubric --help`
is attempted; syntax and import errors fail, stdin-contract rubrics are fine).

```bash
shipyard validate [path] [--json] [--skip-rubric-probe]
```

#### Flags:
| Flag | Type | Description |
|---|---|---|
| `--json` | bool | Print findings as JSON. |
| `--skip-rubric-probe` | bool | Skip the rubric probe (parsing/running the rubric). |

#### Examples:
```bash
shipyard validate evalsets/starter-eval
shipyard validate ./fix-memory-leak --json
```

#### Exit Codes:
- `0`: No errors (warnings do not fail).
- `1`: At least one error.

---

### 6. `shipyard report`
Re-renders reports from an existing run's `results.json`, so the run and the
report can be different CI jobs (or different machines).

```bash
shipyard report [path] --results <results.json> --format markdown,json,junit --out <dir|-> [--baseline <file>] [--baseline-name main]
```

#### Flags:
| Flag | Type | Description |
|---|---|---|
| `--results string` | string | Path to a `results.json` produced by `shipyard run --json` (or a prior report). Required. |
| `--format list` | string | Comma-separated formats: `markdown`, `json`, `junit`. |
| `--out string` | string | Output directory, or `-` for stdout. |
| `--baseline string` | string | Baseline file to include delta information in the report. |
| `--baseline-name string` | string | Baseline name to label the delta with when using the default path. |

#### Examples:
```bash
# Render all three formats into a directory
shipyard report evalsets/starter-eval --results ./results.json \
  --format markdown,json,junit --out ./shipyard-out

# Markdown straight to stdout
shipyard report evalsets/starter-eval --results ./results.json \
  --format markdown --out -
```

---

### 7. `shipyard init ci`
Scaffolds a gated CI pipeline wired to the released `shipyard-ci` templates,
creates `baselines/` with a README, and appends the `[gate]` policy to an
existing `evalset.toml` when it is missing.

```bash
shipyard init ci --provider github|gitlab|jenkins|argo [--target evalset/] [--baseline baselines/main.json] [--repeat 3] [--path .]
```

#### Flags:
| Flag | Type | Description |
|---|---|---|
| `--provider string` | string | CI provider to scaffold for: `github`, `gitlab`, `jenkins`, or `argo`. Required. |
| `--target string` | string | Evalset directory the pipeline runs (defaults to the current directory). |
| `--baseline string` | string | Baseline path the pipeline compares against (defaults to `baselines/main.json`). |
| `--repeat int` | int | Repeats for the pipeline's candidate run (defaults to `3`). |
| `--path string` | string | Where to write the pipeline files (defaults to `.`). |

#### Examples:
```bash
# GitHub Actions workflow, gating evalsets/starter-eval against baselines/main.json
shipyard init ci --provider github --target evalsets/starter-eval --repeat 3

# GitLab pipeline files
shipyard init ci --provider gitlab --target evalsets/starter-eval
```
