Stable CLI Contract

This document defines the stable CLI contract for jq-lite.

Anything described here is treated as a compatibility promise: any incompatible change MUST require a major version bump (or an explicit compatibility mode, which is discouraged).

This contract is test-backed and enforced by automated tests.

Goals

Compatibility Guarantee

Exit Codes

jq-lite returns one of the following exit codes:

| Code | Meaning | |------|--------| | 0 | Success | | 1 | -e/--exit-status specified and result is false, null, or empty output | | 2 | Compile error (query / filter parse error) | | 3 | Runtime error (evaluation failed) | | 4 | Input error (failed to read or decode input) | | 5 | Usage error (invalid CLI arguments, invalid --argjson, etc.) |

Notes

stdout / stderr Rules

stdout

stderr

| Category | Prefix | Exit | |----------|--------|------| | Compile | [COMPILE] | 2 | | Runtime | [RUNTIME] | 3 | | Input | [INPUT] | 4 | | Usage | [USAGE] | 5 |

Examples


[COMPILE]unexpected token at ...
[RUNTIME]cannot add number and string at ...
[INPUT]failed to parse JSON input: ...
[USAGE]invalid JSON for --argjson x

-e / --exit-status Semantics

When -e/--exit-status is specified, jq-lite returns:

| Result | Exit | |------|------| | truthy | 0 | | false / null / empty | 1 |

Truthiness Rules (jq-compatible intent)

NOTE:
Current jq-lite behavior treats 0 as falsey.
This is a known deviation and will be fixed in a future release.

--arg, --argjson, and --argfile

--arg name value

--argjson name json

--argfile name file

Broken Pipe (SIGPIPE / EPIPE)

When downstream closes the pipe early:

jq-lite '.' | head

Rationale: This commonly occurs in pipelines and must not break scripts or CI.

Examples

Compile Error

jq-lite '.[
# stderr: [COMPILE]...
# exit: 2

Runtime Error

printf '{"x":"a"}\n' | jq-lite '.x + 1'
# stderr: [RUNTIME]...
# exit: 3

Input Error

printf '{broken}\n' | jq-lite '.'
# stderr: [INPUT]...
# exit: 4

-e falsey result

printf 'false\n' | jq-lite -e '.'
# stdout: false
# exit: 1

Test-backed Guarantee

This contract is enforced by automated tests.

Run locally:

prove -lv t/cli_contract.t

Any change that violates this contract will fail CI.

Known Deviations / TODO

The following items are explicitly tracked and will be improved:

These do not invalidate the stability of the contract itself.

Summary

This file, together with t/cli_contract.t, defines the CLI contract.