# convoy validate

> Parse every .cvy file in a folder, resolve references, and check every language rule. Needs no server unless a provider names a type that is not built in. Exits 3 on errors.

```text
convoy validate [--dir <path>] [--json] [--graph]
```

`validate` never contacts a model. It contacts convoyd only when a provider names a type that is not built in, to read that type's schema. A swarm on the built-in types validates with no server at all.

## What it does

1. Loads every `*.cvy` file in the folder and merges them into one configuration.
2. For providers whose type is not built in, asks convoyd (`--server`) to resolve the types, in one call. The server fetches a type it does not hold, but never runs provider code for this.
3. Resolves references, builds the dependency graph, and checks every rule in [Validation rules](/docs/dsl/validation/), including each provider's attributes and each agent's `tools`, `settings`, and `model` against its type.
4. Prints each diagnostic with its source line, warnings first, then errors, separated by blank lines.
5. Exits 3 if there is any error, otherwise prints `validate: ok (N agents, M topics)` and exits 0.

## When the server is down

`validate` keeps each type's manifest it receives in your user cache folder (`convoy/providers/` under it), indexed by server, source, and constraint. When convoyd cannot be reached, it checks the swarm against the cached manifest and warns with [TS017](/docs/dsl/validation/#ts017), naming the version and how old the copy is. With nothing cached, TS017 says the type was not checked, and the swarm still validates. The cache is a convenience: the server's answer always wins, and [`convoy run`](/docs/cli/run/) is checked on the server regardless.

```console
$ convoy validate
Warning: Provider type checked against a cached copy (TS017)

  on providers.cvy line 2, in provider "fast":
   2:   source = "acme/acme"

No server could be reached, so provider "fast" was checked against the cached
manifest of acme/acme 1.4.2, cached 3 days ago. convoy run checks it on the server.

validate: ok (6 agents, 4 topics)
```

Some checks need the server and cannot run here: whether convoyd has a default overseer (`overseer_missing`), whether its environment has the provider keys (`missing_env`), and the server's price for the overseer model when it comes from server flags (`unpriced_model`). Those surface on [`convoy run`](/docs/cli/run/).

## Flags

| Flag | Meaning |
| --- | --- |
| `--json` | Print `{"valid": bool, "diagnostics": [...]}` on stdout |
| `--graph` | Print the dependency graph in DOT format and exit 0 if there are no errors |

Each JSON diagnostic has `severity`, `code`, `summary`, `detail`, and `range` (`file`, `start` and `end` with `line` and `column`).

## Examples

```console
$ convoy validate
validate: ok (6 agents, 4 topics)
```

A warning does not fail validation:

```console
$ convoy validate
main.cvy:31: warning: agent "writer" watches topics and keeps the default max_turns (50)

validate: ok (6 agents, 4 topics)
```

An error does:

```console
$ convoy validate
main.cvy:44: error: agent "critic" watches topic "reviews", which is not declared
  did you mean topic "review"?

main.cvy:19: error: references form a cycle: agent.writer -> agent.critic -> agent.writer
$ echo $?
3
```

Render the graph:

```console
$ convoy validate --graph | dot -Tsvg > swarm.svg
```

Machine-readable output:

```console
$ convoy validate --json
{"valid":false,"diagnostics":[{"severity":"error","code":"TS020","summary":"undeclared topic","detail":"agent \"critic\" watches topic \"reviews\"","range":{"file":"main.cvy","start":{"line":44,"column":12},"end":{"line":44,"column":31}}}]}
```

## Exit codes

| Code | Cause |
| --- | --- |
| `0` | No errors (warnings allowed) |
| `3` | At least one error |

## API endpoint

`POST /v1/providers:resolve`, only for provider types that are not built in.

## Related

- [Validation rules](/docs/dsl/validation/) is the full list of checks.
- [Language rules](/docs/dsl/)
- [convoy run](/docs/cli/run/) validates first, then sends.
- [convoy goal](/docs/cli/goal/) validates its own output in a loop.
