# ATIP 2: CLI Binding (`atip/2`)

Status: **2.0.0-draft**, 2026-12-01. Normative binding for the command-line transport of `spec/core.md`.

Contents: 1 Scope and mapping summary · 2 Command words, argv grammar and argument `cli` metadata · 3 Output selection,
reserved flags and text mode · 4 Output channels and interactive limits · 5 Help, version, `schema` and `skills show` ·
6 Outcome and exit status · 7 `--input`, step rendering and batches · 8 Streams · 9 CLI design and catalog rules ·
10 Conformance and checker verification.

---

## 1. Scope and mapping summary

1.1. **Purpose.** This document specifies how an `atip/2` tool exposes operations as a command-line executable (`cli`
binding): how argv words and `--input` map to `{operation, arguments}`, how the response envelope or stream is printed
on stdout, how `ok` and `error.refused` map to process exit statuses, and how a caller renders a step `{operation,
arguments}` into argv.

1.2. **Summary of CLI mappings.**

| Aspect | Core (`spec/core.md`) | CLI binding | Section |
|---|---|---|---|
| Operation `finding_close` | Operation id (`_`-separated words) | Command words `<tool> finding close` | 2.1 |
| Group or bare tool | Refused, `OPERATION_REQUIRED` | Exit 2, `OPERATION_REQUIRED` | 2.1, 6.1 |
| Unknown operation word | Refused, `OPERATION_NOT_FOUND` | Exit 2, `OPERATION_NOT_FOUND` | 2.1, 6.1 |
| Non-control arguments | Members of the input document | Flags (`--for-agent`), positional operands (`cli.position`), or keys in `--input <JSON\|FILE\|->` | 2, 7 |
| Control arguments | `commit`, `planDigest`, `limit`, `cursor`, `all`, `fields` | Flags only (`--commit`, `--plan-digest`, `--limit`, `--cursor`, `--all`, `--fields a,b`); never in `--input` | 3.3, 7.3 |
| Output selection | Always envelope or stream | `--json`; without `--json`, text mode for a person (outside the protocol) | 3.1 |
| Envelope | `{ok, data\|error, meta}` | With `--json`, one compact UTF-8 JSON line on stdout | 4.1 |
| Outcome | `ok: true`; `error.refused: false`; `error.refused: true` | Exit 0; exit 1; exit 2 | 6.1 |
| Stream | `start`, `event`, `end` items | With `--json`, NDJSON on stdout (one compact JSON line per item); exit from `end.result` | 8 |
| Step `{operation, arguments}` | Transport-free step in `meta.next` | `<tool> <words…> [control flags…] [--input=<JSON>] --json` | 7.4 |
| Discovery and guide | `schema`, `skills_show` | `<tool> schema … --json`, `<tool> skills show [NAME] [--json]`, plus first line of root `--help` | 5 |

## 2. Command words, argv grammar and argument `cli` metadata

### 2.1. Command path and option derivation

2.1.1. On the command line, an operation id (`finding_close`, `billing_invoice_send`, `schema`, `skills_show`) is
written as its `_`-separated words (`<tool> finding close`, `<tool> billing invoice send`, `<tool> schema`,
`<tool> skills show`). A request that stops at a group word or runs the bare executable without an operation is refused
with `OPERATION_REQUIRED` (exit 2), `expected` the children of that group (or the root entries). An unknown command word
is refused with `OPERATION_NOT_FOUND` (exit 2), `expected` the operation and group ids valid at that position: the
children of the deepest group the words before it name, or the root entries, as `spec/core.md` 4.1.2 says.

2.1.2. Every non-positional argument (`cli.position` absent) has a long option flag derived from its camelCase name
(`spec/core.md` 4.1.4) by converting each uppercase ASCII letter `A`–`Z` to `-` followed by its lowercase letter and
prefixing `--`: `forAgent` becomes `--for-agent`, `planDigest` becomes `--plan-digest`, `idempotencyKey` becomes
`--idempotency-key`, `dryRun` becomes `--dry-run`.

### 2.2. Argv syntax

2.2.1. Every conforming CLI parser MUST accept at least this grammar, and callers (examples, guides, rendered steps) use
only it. It is RFC 5234 ABNF over argv elements: `SEP` separates argv elements, and a `-word` rule matches one whole
argv element.

```abnf
invocation    = *( global SEP ) path *( SEP argument ) [ SEP "--" *( SEP operand-word ) ]
path          = command-word *( SEP command-word )
command-word  = name
argument      = option / free-operand
option        = long-switch / long-joined / long-separate / short-form
long-switch   = "--" name                         ; a boolean argument, or one occurrence of a cli.count argument
long-joined   = "--" name "=" value               ; value: the rest of the element, possibly empty
long-separate = "--" name SEP plain-word          ; the next element is the value; it does not start with "-"
short-form    = "-" ALPHA [ SEP plain-word ]      ; only for declared cli.short options
global        = option                            ; options accepted before the path, e.g. --json
free-operand  = plain-word                        ; before "--"
plain-word    = "-" / ( first-char *CHAR )        ; a non-empty element not starting with "-", or exactly "-"
operand-word  = *CHAR                             ; after "--", any element is an operand
value         = *CHAR
name          = lower *( lower / DIGIT ) *( "-" 1*( lower / DIGIT ) )
lower         = %x61-7A
DIGIT         = %x30-39
ALPHA         = %x41-5A / %x61-7A
first-char    = %x01-2C / %x2E-10FFFF             ; any character except "-"
CHAR          = %x01-10FFFF                       ; any Unicode scalar value except NUL
```

2.2.2. A repeatable option is given once per value on argv, in order, or as a comma-separated list when it declares
`cli.commaList: true` (2.3.2); a `cli.count` option is given once per occurrence (`--verbose --verbose` produces `2`).
`--name=value` equals `--name value`; a value that is empty or starts with `-` (other than `-` alone) is written in the
joined form `--name=value`, and a tool MUST accept the joined form for every valued option. The first `--` element ends
options, and a tool MUST accept positional operands after `--`. A short option (`-f`) equals its long option and is
never joined (`-f=val`) or bundled (`-abc`).

2.2.3. On argv and in `cli.env` environment variables, an `integer` argument word matches `-?(0|[1-9][0-9]*)` within
±(2^53−1), a `number` argument word is parsed in JSON number syntax to the nearest finite binary64 value
(`spec/annex-domains.md` V3), a `boolean` switch flag sets `true`, and a `json` argument word is parsed as UTF-8 JSON
(refusing top-level `null`). Inside an `--input` JSON document, `integer` and `number` values MUST be JSON numbers,
never strings (`spec/core.md` 4.2.1).

### 2.3. Argument `cli` metadata and comma lists

2.3.1. In the CLI `schema` catalog (`spec/core.md` 12.5.1), an argument object MAY carry `cli`:

| Member | Type | Default | Meaning |
|---|---|---|---|
| `position` | integer ≥ 0 | absent | Zero-based positional operand index (`0`, `1`, …). When absent, the argument is a flag option. |
| `variadic` | boolean | `false` | Only on the highest-numbered `position` (which MUST also have `repeatable: true`): the operand accepts one or more positional words as an array. |
| `short` | string (`^[a-zA-Z]$`) | absent | One-letter short flag (`-s`). Prohibited when `position` is present. |
| `valueName` | string | Upper-case snake name (`FOR_AGENT`) | Placeholder shown in `--help` (`^[A-Z0-9_\|:=@.-]*[A-Z][A-Z0-9_\|:=@.-]*$`). Omitted for `boolean` and `cli.count`. |
| `env` | string (`^[A-Z][A-Z0-9_]*$`) | absent | Environment variable read when the argument is given neither on argv nor in `--input`. Prohibited when `position` is present. |
| `commaList` | boolean | `false` | One argv or `env` value is split on `,` into array elements (2.3.2). Prohibited when `position` is present. |
| `count` | boolean | `false` | Only on `valueType: "integer"` with `position` absent: each `--name` flag occurrence increments the integer from `0`. |

2.3.2. **Comma lists (`cli.commaList`).** A repeatable option (`repeatable: true`, `position` absent) whose `valueType`
is `string`, `integer`, `number`, `path` or `enum` MAY declare `cli.commaList: true`. A comma `,` is then never part of
one of its values on any channel (9.2 rule 6). Each of its argv values (`--tag=a,b`, `--tag a,b`, `-t a,b`) and its
`cli.env` value is split on `,` into elements in order; each piece is validated as one value of the argument
(`valueType`, `possibleValues`, `domain`), pieces are not trimmed, and multiple flag occurrences concatenate in order
(`--tag a,b --tag c` yields `["a", "b", "c"]`). An empty piece (`a,,b`, `a,`, or `""`) is refused with `INPUT_INVALID`
(reason `INVALID_VALUE`), `received` the empty piece. `default` and an `--input` value are typed JSON arrays and are not
split on commas: an array element in `--input` that contains `,` fails the argument's `domain`.

2.3.3. **Context precedence (`meta.context`).** For any argument that declares `cli.env`, an explicit value on argv or
in `--input` takes precedence over the environment variable, which takes precedence over discovery or `default`
(`spec/core.md` 5.7).

## 3. Output selection, reserved flags and text mode

### 3.1. Output selection (`--json`) and text mode

3.1.1. Without `--json`, a command runs in **text mode** and prints human-readable output, which is outside the
protocol.

3.1.2. Every operation whose outputs (`spec/core.md` 12.5.4) include a `report`, an `artifact` or a `stream` MUST
accept `--json`. With `--json`, a `report` or `artifact` operation prints one compact response envelope (4.1), and a
`stream` operation prints NDJSON stream lines (8).

3.1.3. The output kind and the JSON shape MUST NOT depend on whether stdout or stdin is a terminal, on environment
variables (such as `CI` or `TERM`), or on user configuration. Response content MAY reflect declared inputs (`cli.env`
values, context, state), and text-mode styling MAY follow `NO_COLOR` and `TERM`.

3.1.4. An invocation is in **JSON mode** whenever the argv element `--json` appears anywhere before the first `--`
element, even when argv parsing subsequently fails, so that every parse or framing failure with `--json` prints a JSON
failure envelope on stdout. `--json` MUST be accepted anywhere after the command words and before `--`, and MAY be
accepted before the command words.

### 3.2. Artifacts (`kind: "artifact"`)

In the CLI catalog, an output entry MAY declare `kind: "artifact"` with a required `mediaType` (`^[a-z]+/[a-zA-Z0-9.+-]+$`).
In text mode (without `--json`), the operation writes the raw artifact bytes of that `mediaType` to stdout; in JSON mode
(with `--json`), it prints a standard response envelope whose `data` validates against the output's `schemaRef`.

### 3.3. Reserved CLI flags

Every tool uses these reserved flag names when it offers the corresponding capability:

| CLI flag | Core argument or transport role | Allowed in `--input` |
|---|---|---|
| `--json` | Transport output selection (3.1) | Never (not an argument) |
| `--input <JSON\|FILE\|->` | Transport input document framing (7.1) | Never (not an argument) |
| `--help`, `-h` | Human help text (5.1) | Never (not an argument) |
| `--version`, `-V` | Human version text (5.1) | Never (not an argument) |
| `--commit` | Control argument `commit: true` (`spec/core.md` 7.5) | Never (control argument) |
| `--plan-digest <DIGEST>` | Control argument `planDigest` (`spec/core.md` 7.5) | Never (control argument) |
| `--limit <N>` | Control argument `limit` (`spec/core.md` 8.1) | Never (control argument) |
| `--cursor <CURSOR>` | Control argument `cursor` (`spec/core.md` 8.1) | Never (control argument) |
| `--all` | Control argument `all: true` (`spec/core.md` 8.1) | Never (control argument) |
| `--fields <PATHS>` | Control argument `fields` (`spec/core.md` 8.2), split on `,` outside bracketed keys (`spec/annex-fields.md` F1) | Never (control argument) |
| `--dry-run` | Reserved argument `dryRun: true` (`spec/core.md` 7.6) | Yes (`"dryRun": true`) |
| `--idempotency-key <KEY>` | Reserved argument `idempotencyKey` (`spec/core.md` 7.4) | Yes (`"idempotencyKey": "…"`) |
| `--wait` | Reserved argument `wait: true` (`spec/core.md` 9.2) | Yes (`"wait": true`) |
| `--timeout <DURATION>` | Reserved argument `timeout` (`spec/core.md` 9.2) | Yes (`"timeout": "…"`) |

`--fields` is accepted with the same comma-separated path syntax in both JSON mode and text mode.

## 4. Output channels and interactive limits

4.1. **stdout in JSON mode.** In JSON mode, stdout MUST contain exactly one compact UTF-8 JSON envelope followed by a
single LF (`\n`), both on success and on failure (or, for a `stream` output that starts, one compact UTF-8 JSON line
per stream item, 8.1).

4.2. **stderr in JSON mode.** In JSON mode, stderr MUST NOT carry the result or the error and SHOULD be empty except for
human progress diagnostics; callers MUST NOT parse stderr.

4.3. **Text mode channels.** In text mode, errors and progress diagnostics go to stderr; a refusal (`error.refused:
true`, exit 2) prints nothing on stdout, while an operation that ran and failed (`error.refused: false`, exit 1) MAY
print its human-readable findings on stdout. In text mode, a tool MAY print `meta.next` steps as human command lines
using the rendering rule of 7.4; that text is outside the protocol.

4.4. **No interactive prompts.** A tool MUST NOT prompt for missing input, confirmation or credentials on a terminal or
stdin; a missing required value or missing `--commit --plan-digest` is refused immediately. Only `--input -` and an
argument whose documentation explicitly accepts `-` read stdin, at most once per invocation.

4.5. **Failures before tool code.** Any failure that reaches the tool's own code in JSON mode MUST emit a failure
envelope on stdout. A catastrophic failure before the tool's code runs (such as a dynamic linker or runtime failure)
exits non-zero with stdout empty (Table T10).

## 5. Help, version, `schema` and `skills show`

### 5.1. `--help` and `--version`

5.1.1. `--help` (and `-h`) and `--version` (and `-V`) print human-readable text on stdout and exit 0; that text is not
part of the JSON protocol, and `--version` SHOULD print `<tool> <version>`.

5.1.2. The machine-readable self-description is `schema`, never `--help`. When `--help` is passed together with
`--json`, the tool MUST resolve the command words first (so an unknown command word still refuses with
`OPERATION_NOT_FOUND`) and then refuse with `INPUT_INVALID` (exit 2), `field` `""`, and `hint` pointing to `schema` for
that operation or group (`{"text": "use schema for machine-readable self-description", "operation": "schema",
"arguments": {"operation": "<id>"}}`, or `{"operation": "schema"}` at the root). Passing `--version` with `--json` is
refused the same way after resolving command words, with `INPUT_INVALID` (exit 2), `field` `""`, and `hint.text`
directing the caller to `<tool> --version` or `meta.toolVersion`.

5.1.3. **Agent discovery pointer in `--help`.** At L1, the first line of the root `--help` output MUST name
`<tool> schema --json` (and every subcommand `--help` SHOULD); it MUST NOT advertise `schema` if the tool does not
implement it. At L2, that first line of the root `--help` output MUST also name `<tool> skills show`.

### 5.2. Invoking `schema` on the CLI

On the CLI, `schema` (`spec/core.md` 12.1) is invoked as:

```
<tool> schema --json                                  tree (data.kind: "tree")
<tool> schema <OPERATION> --json                      group or operation (data.kind: "group" or "operation")
<tool> schema <OPERATION> --schemas --json            JSON Schemas and rejects (data.kind: "schemas")
<tool> schema --errors --json                         error registry (data.kind: "errors")
<tool> schema --error <CODE> --json                   one error entry (data.kind: "error")
<tool> schema --warnings --json                       warning registry (data.kind: "warnings")
<tool> schema --warning <CODE> --json                 one warning entry (data.kind: "warning")
<tool> schema --search "<TASK>" --json                ranked tree (data.kind: "tree", OPTIONAL)
```

`<OPERATION>` is the positional argument `operation` (`cli.position: 0`): the tool MUST accept an operation or group id
(`finding_close`, `finding`), and MAY also accept the space-separated path words (`finding close`) by joining them with
`_`. As with every operation at L1, `schema` also accepts `--input` (`<tool> schema --input='{"operation":"finding_close","schemas":true}' --json`).
Without `--json`, `schema` prints human-readable text, which MAY be the JSON document.

### 5.3. Invoking `skills show` on the CLI

At L2, the guide operation `skills_show` (`spec/core.md` 12.8) is invoked as `<tool> skills show [NAME] [--full] [--json]`
(where `name` has `cli.position: 0`, optional, and `--input` is also accepted). Without `--json`, it prints the guide's
Markdown text on stdout and exits 0; with `--json`, it prints a response envelope whose `data` conforms to
`schema/guide.schema.json`. Every fenced code line in a guide's Markdown `text` that starts with `<tool> ` MUST parse
by 2.2 once `<UPPER_CASE>` placeholders are replaced with valid values (shell pipelines are exempt).

## 6. Outcome and exit status

6.1. **The exit status rule (Table T3).** `ok` is `true` if and only if the process exit status is `0`:

| Outcome / condition | `ok` | `error.refused` | CLI exit status | Meaning |
|---|---|---|---|---|
| Success (including preview, dry run, accepted work, and monitor without `--wait` in any state) | `true` | — | `0` | The operation did what was asked |
| Non-refusal failure: `FAILED`, `INCOMPLETE`, `TIMEOUT`, `INTERNAL`, `UNVERIFIABLE`, `BATCH_INCOMPLETE` | `false` | `false` | `1` | The operation ran, and its answer is negative, incomplete or timed out |
| Refusal: `INVALID`, `REQUIRED`, `NOT_FOUND`, `EXISTS`, `CONFLICT`, `STALE`, `EXPIRED`, `DENIED`, `UNSUPPORTED`, `TOO_LARGE`, `CORRUPT`, `UNAVAILABLE` (including all other core codes) | `false` | `true` | `2` | The operation refused to run before starting work; nothing changed |

No other exit status is emitted by the tool's own code (except for a passthrough command that declares its exit behaviour
in `effectNote`, `spec/core.md` 3.4).

6.2. **Accepted work on the CLI (Table T7).** Starting an `async` operation exits `0` with `meta.work: {id, state:
"working"}`. Running the monitor operation without `--wait` exits `0` in every state (`working`, `done`, `failed`,
`cancelled`). Running the monitor with `--wait` (and optional `--timeout <DURATION>`) exits `0` when `state` reaches
`"done"`, exits `1` with the tool's `<SUBJECT>_FAILED` or `<SUBJECT>_INCOMPLETE` code (`refused: false`) when `state` is
`"failed"` or `"cancelled"`, exits `1` with the tool's `<SUBJECT>_TIMEOUT` code (`refused: false`, `retryable: true`)
when the wait times out while still `"working"`, and exits `2` with `<SUBJECT>_NOT_FOUND` (`refused: true`) when the work
id is unknown.

6.3. **Signals.** A process terminated by an unhandled signal ends without printing an envelope, reported by the
operating system as a signal wait status or as exit `128 + n` by a shell launcher. A tool SHOULD release locks or
temporary resources it claimed and retain default `SIGPIPE` behaviour.

6.4. **Framing failures (Table T10).**

| Situation | CLI behaviour in JSON mode |
|---|---|
| Malformed argv syntax (unclosed option, unexpected operand, unknown flag, `--input` twice or without value) | Exit `2`, failure envelope with `INPUT_INVALID` (or finer replacement), reason `SYNTAX` or `UNKNOWN_ARGUMENT` |
| `--input` payload exceeds `input.maxBytes` or batch exceeds `input.maxItems` | Exit `2`, failure envelope with `INPUT_TOO_LARGE` (`TOO_MANY_BYTES` or `TOO_MANY_ITEMS`), `field` `""` |
| `--input` file unreadable, stdin is a TTY with `--input -`, empty source, invalid JSON, non-object JSON, or control argument in document | Exit `2`, failure envelope with `INPUT_INVALID` and corresponding reason (`UNREADABLE`, `STDIN_TTY`, `EMPTY`, `NOT_JSON`, `NOT_OBJECT`, `BATCH_UNSUPPORTED`, `CONTROL_IN_DOCUMENT`) |
| Argument value fails `Input` schema, `required`, `domain`, `constraints` or `validators` | Exit `2`, failure envelope with `INPUT_INVALID` (or declared code) and JSON Pointer in `error.field` |
| Runtime cannot start before tool code runs | Non-zero exit status, stdout empty |

## 7. `--input`, step rendering and batches

Shape: `schema/cli-input.schema.json`, `schema/batch-report.schema.json`.

### 7.1. `--input` availability and sources

7.1.1. At L1, **every operation** MUST accept `--input <JSON|FILE|->`, so that a caller can execute any step
`{operation, arguments}` without consulting the catalog to know which arguments are positional operands or flags (7.4).

7.1.2. A value starting with `{` or `[` is parsed as inline UTF-8 JSON; `-` reads UTF-8 from stdin until EOF; any other
value is read as a file-system path relative to the current working directory (prefix a file literally named `{x}` as
`./{x}`). An empty argument value, an empty file or stdin, or an unreadable file is refused with `INPUT_INVALID` (reason
`EMPTY` or `UNREADABLE`), `field` `""`. Giving `--input` more than once or without a value is refused with
`INPUT_INVALID` (reason `SYNTAX`).

7.1.3. Passing `--input -` when stdin is attached to a terminal (TTY) is refused immediately with `INPUT_INVALID`,
reason `STDIN_TTY`, `field` `""`.

7.1.4. `input.maxBytes` (when declared on the operation) is enforced on the raw byte length of the `--input` source
before JSON parsing (`INPUT_TOO_LARGE`, reason `TOO_MANY_BYTES`, `field` `""`).

### 7.2. `--input` document shape

7.2.1. A single invocation's `--input` payload is one JSON object (`schema/cli-input.schema.json`) whose keys are the
operation's camelCase argument names (`spec/core.md` 4.2.1)—positional operands included, by their `name`, never in an
`operands` array. Values follow `spec/core.md` 4.2.1: numbers are JSON numbers (never numeric strings), booleans are
`true` or `false`, repeatable arguments are arrays, and `null` is refused except inside a `json` argument value.

7.2.2. A JSON array of objects, or a file or stdin containing more than one whitespace-separated JSON object (NDJSON),
is a **batch** (7.5). Passing an array or NDJSON to an operation that does not declare `input.batch: true` is refused
with `INPUT_INVALID`, reason `BATCH_UNSUPPORTED`, `field` `""`.

### 7.3. Control arguments and merging `--input` with argv

7.3.1. The six control arguments (`commit`, `planDigest`, `limit`, `cursor`, `all`, `fields`, `spec/core.md` 4.3.2)
and the transport flags (`json`, `input`, `help`, `version`) MUST NOT appear as keys inside an `--input` object or batch
item. If any control argument key appears in `--input`, the tool refuses with `INPUT_INVALID`, reason
`CONTROL_IN_DOCUMENT`, `field` `"/<key>"` (`"/commit"`, `"/limit"`).

7.3.2. **Processing and merge with argv.** Steps 1–6 read no workspace state; the first failure answers with exit 2 and
nothing changed:

1. **Read and frame** `--input` (7.1–7.2): enforce `input.maxBytes` (`INPUT_TOO_LARGE`) and parse JSON (`INPUT_INVALID`
   with `EMPTY`, `UNREADABLE`, `STDIN_TTY`, `NOT_JSON`, `NOT_OBJECT`, `BATCH_UNSUPPORTED`, or `CONTROL_IN_DOCUMENT`).
2. **Parse argv** options and positional operands according to 2.2 (without checking `required` or `constraints` yet, so
   that `--input` may supply required arguments). Malformed argv refuses here with `INPUT_INVALID`.
3. **Compare and merge** explicit arguments given on argv with those in the `--input` document: if an argument is given
   explicitly on both argv and `--input` with different normalised values (arrays compared in element order, objects by
   members), refuse with `INPUT_CONFLICT`, `field` `"/<name>"` (`"/round"`). If both give the exact same value, merge
   them.
4. **Fill absent arguments** from declared `cli.env` environment variables, then from declared `default` values. Values
   from `cli.env` or `default` are not considered explicitly given for `constraints` (`spec/core.md` 12.5.3).
5. **Validate the merged input document** against the operation's derived `Input` schema (`UNKNOWN_ARGUMENT`,
   `MISSING_ARGUMENT`, `INVALID_VALUE`), `constraints` (`CONSTRAINT` or the constraint's `code`), and `validators` (the
   validator's `code`). Every argument error sets `error.field` to the argument's RFC 6901 JSON Pointer (`"/finding"`,
   `"/tags/0"`), regardless of whether the value came from argv, `cli.env` or `--input`.
6. **Execute** the operation (`spec/core.md` 4.4 step 4).

When `--input` is not used, steps 2, 4, 5 and 6 run identically on the input document assembled from argv, reporting the
same error codes and JSON Pointers in `error.field`.

### 7.4. Rendering a step `{operation, arguments}` to CLI argv (Table T9)

A caller renders a core step `{operation, arguments}` into a CLI invocation without needing the tool's catalog by
applying this rule:

1. Start with the executable `<tool>`, followed by the words of `operation` split on `_`.
2. For each of the six control arguments present in `arguments`, append its CLI flag in order:
   - `commit: true` → `--commit`
   - `planDigest: "<v>"` → `--plan-digest=<v>`
   - `limit: <n>` → `--limit=<n>`
   - `cursor: "<v>"` → `--cursor=<v>`
   - `all: true` → `--all`
   - `fields: ["<a>", "<b>"]` → `--fields=<a>,<b>`
3. Let `rest` be `arguments` with those six control keys removed. If `rest` has at least one key, append
   `--input=<compact JSON of rest>`. The order of the members inside that word carries no meaning: a tool and a
   checker read it as parsed JSON.
4. Append `--json`.

For example, the commit step `{"operation": "purge", "arguments": {"before": "2020-01-01", "commit": true, "planDigest":
"sha256:9f2c…"}}` renders to:

```
<tool> purge --commit --plan-digest=sha256:9f2c… --input='{"before":"2020-01-01"}' --json
```

Because every operation accepts `--input` (7.1.1), this rendering always works even when `"before"` is declared as a
positional operand (`cli.position: 0`). A human user or a caller that has read the catalog may equally invoke the flag
and operand form (`<tool> purge --before 2020-01-01 --json`), and the tool MUST produce the same response for both forms.

### 7.5. Batches

7.5.1. An operation that is not `destructive` MAY accept batch input on the CLI by declaring `input: {maxBytes, batch:
true, maxItems}` and an output with `batch: true` in its CLI operation document (`spec/core.md` 12.5.4). A batch is
submitted via `--input` as a JSON array of at least one input document or as NDJSON (7.2.2). A batch with more than
`input.maxItems` items is refused before execution with `INPUT_TOO_LARGE`, reason `TOO_MANY_ITEMS`, `field` `""`.

7.5.2. **Preflight and execution.** Preflight runs 7.3.2 steps 1–5 on every item in the batch before any item executes.
Execution then runs items sequentially in index order (`0`, `1`, …) and stops at the first item that fails:

| Outcome | Exit | `ok` | `error.code` | `data` |
|---|---|---|---|---|
| Any item fails preflight (steps 1–5) | `2` | `false` | The first failing item's code, `refused: true`, `field` `"/<index>/…"` | Omitted |
| Every item succeeds | `0` | `true` | — | Batch report (`schema/batch-report.schema.json`), every item `status: "written"` or `"unchanged"` with `data` |
| Item `<index>` fails during step 6 | `1` | `false` | `BATCH_INCOMPLETE`, `refused: false`, `field` `"/<index>"` | Partial batch report: items `< <index>` `"written"` or `"unchanged"` with `data`; item `<index>` `"failed"` with `error`; items `> <index>` `"skipped"` |

7.5.3. A batch is not an atomic transaction: items before a failed item retain their effects, and the failed item's own
`error.refused` states whether that item refused before making effects (`true`) or failed during execution (`false`).

## 8. Streams

8.1. **NDJSON framing (Table T8).** When an operation with a `stream` output runs with `--json`, stdout carries Newline
Delimited JSON (NDJSON): one compact UTF-8 JSON line terminated by LF (`\n`) for the `start` item, one line for each
`event` item, and one line for the `end` item (`schema/stream-line.schema.json`, `spec/core.md` 10.1).

8.2. **Exit status and pre-stream refusal.** The process exit status is the exit status of the `end` item's `result`
envelope (`0` when `result.ok` is `true`, `1` when `result.ok` is `false`). If the operation refuses before the stream
begins (`error.refused: true`), it prints a single failure envelope line on stdout (no `start` line) and exits `2`.
Text-mode stream output (without `--json`) is outside the protocol.

## 9. CLI design and catalog rules

Normative at L1, complementing `spec/annex-design.md`.

### 9.1. Command-line design rules

1. **Operands.** The one kind of target object an operation acts on or shows MAY be given a positional `cli.position`
   (`0`, and `1` when two objects have a natural order; `cli.variadic: true` on the last position for one or more
   objects). Context (repository, project, workspace, environment) is never a positional operand; values that modify the
   operation are flag options.
2. **Option names and short flags.** CLI options are lower kebab-case long flags derived from the camelCase argument
   name (2.1.2). A tool SHOULD NOT define single-letter `cli.short` flags other than `-h` and `-V`, and MUST declare in
   `cli.short` every short flag it accepts. Prefix abbreviation of options or command words (`--for-a` for
   `--for-agent`) MUST NOT be accepted.
3. **Value names across groups.** When two groups use the same argument name with different group-scoped meanings
   (`spec/annex-design.md` S1 item 3), their `cli.valueName` placeholders MUST differ (`--group USER_GROUP` vs.
   `--group REPO_GROUP`).
4. **Relative paths.** File-system paths (`valueType: "path"`, `--input <FILE>`, and paths recorded in `meta.context`)
   are resolved and reported relative to the process's current working directory, both on argv and inside `--input`.
5. **Tool-wide options after a group word.** A tool-wide option (an option every operation accepts with one meaning,
   such as `--json` or a shared context option in `tree.arguments` like `--repo`) SHOULD be accepted after a bare group
   word as well, so that `<tool> <group> --repo . --json` refuses with `OPERATION_REQUIRED` rather than `INPUT_INVALID`.

### 9.2. CLI catalog self-description rules

In addition to `spec/annex-design.md` S2, every `schema` catalog with `binding: "cli"` satisfies:

1. **Positions.** Within an operation's full argument set, `cli.position` values (when present) form a contiguous
   sequence `0, 1, …, k − 1`. Only the argument at position `k − 1` may have `cli.variadic: true`, and an argument with
   `cli.position` has `repeatable: true` if and only if `cli.variadic` is `true` (so `Input` derives an array property
   from `repeatable` alone on every binding). An argument with `cli.position` never has `cli.short`, `cli.env`,
   `cli.commaList` or `cli.count`, and its `valueType` is never `boolean`.
2. **Short letters and `cli.env`.** `cli.short` letters are unique within an operation's full argument set (and never
   `h` or `V`).
3. **Counts and booleans.** `cli.count: true` appears only on an argument with `valueType: "integer"`, `required:
   false`, `repeatable: false`, and `cli.position` absent. Neither a `boolean` argument nor an argument with
   `cli.count: true` declares `cli.valueName` or `possibleValues`.
4. **Default values in `cli`.** Default-valued members of `cli` (`variadic: false`, `commaList: false`, `count: false`,
   and `valueName` when equal to the argument name converted to `UPPER_SNAKE_CASE`) are omitted (`spec/core.md`
   12.5.2).
5. **Batches and artifacts.** An operation has an output with `batch: true` if and only if `input.batch` is `true`, and
   `input.maxItems` is present if and only if `input.batch` is `true`; a `destructive` operation never has
   `input.batch: true`. An output has `mediaType` if and only if its `kind` is `"artifact"`.
6. **Comma lists.** An argument with `cli.commaList: true` has `repeatable: true`, `cli.position` absent, `valueType`
   in `["string", "integer", "number", "path", "enum"]`, and cannot admit `,` in any single value: no member of
   `possibleValues` and no element of `default` contains `,`, and for `string` or `path` the argument has a `domain.pattern`
   none of whose literals or character classes admits `,` (such as `^[a-z][a-z0-9-]*$` or `^[^,\n\r]+$`).

## 10. Conformance and checker verification

10.1. **Levels on the CLI.** A CLI tool claims `"ATIP 2.0 CLI L0"`, `"ATIP 2.0 CLI L1"` or `"ATIP 2.0 CLI L2"` as
defined in `spec/core.md` 3.2.

10.2. **What the checker verifies on the CLI** (informative; see `approaches/checker.md`). When invoked with
`atip check --bin <BINARY> --binding cli`, the checker exercises the core checks (`spec/core.md` 3.6) by rendering
steps through 7.4 and additionally verifies:

- the argv grammar of 2.2 (joined and separate long options, `--` operand terminator, short options, repeatable options
  and `cli.commaList`);
- JSON mode detection before `--` despite argv parse errors (3.1.4), and independence from terminal or environment
  variables (3.1.3);
- exactly one compact JSON document and a trailing newline on stdout (4.1), no result or error on stderr (4.2), exit
  statuses 0, 1 and 2 matching `ok` and `error.refused` (6.1), and no interactive prompt when stdin/stdout is a terminal
  (4.4);
- root `--help` first-line pointers to `<tool> schema --json` (L1) and `<tool> skills show` (L2), refusal of
  `--help --json` and `--version --json` with `INPUT_INVALID` after path resolution (5.1.2), and empty stdout on
  text-mode refusals (4.3);
- equivalence of the flag/operand form and the `--input` form on every operation, `INPUT_CONFLICT` when argv and
  `--input` disagree, refusal of control arguments inside `--input` (`CONTROL_IN_DOCUMENT`), and batch preflight and
  execution (`BATCH_INCOMPLETE`) where declared (7).
