JSON & Agent Automation
deccy is designed to be driven reliably by scripts, CI pipelines, and AI coding agents. It provides a single canonical JSON envelope, deterministic ID seeding, non-interactive flags for every write operation, and strict exit-code guarantees.
1. The --json (-j) Envelope Contract
Pass --json or -j either before the verb (deccy --json <verb> ...) or after the verb (deccy <verb> --json ...).
Every JSON response is a single-line, compact canonical JSON object (keys sorted bytewise, no floats, terminated by \n) written to stdout.
Three Outcome Shapes
| Outcome | Exit Code | Stream | Envelope Shape |
|---|---|---|---|
| Success | 0 | stdout | {"ok":true,"verb":"<verb>", ...facts} |
Help (--help --json) | 0 | stdout | {"lines":["..."],"ok":true} |
Failed validate report | 1 | stdout | {"ok":false,"problems":N,"report":[...],"summary":"invalid N problems","verb":"validate"} |
| Refusal (error) | 1 | stdout | {"error":"<reason>","evidence":["..."],"ok":false} |
Important distinction for parsers: When
"ok": falseis returned:
- If
"error"is present, the command was refused (invalid arguments, missing store, ownership conflict, etc.) and no files were modified.- If
"verb": "validate"is present (with no"error"field),validateran to completion and foundproblems > 0. Inspect the"report"array and"problems"count.
Example: Parsing a Refusal in JSON Mode
$ deccy --json show short
{"error":"prefix \"short\" is shorter than 8 characters","evidence":["ids resolve from a prefix of 8 or more characters"],"ok":false}
2. Non-Interactive Workflows for Agents & Scripts
Agents and scripts should avoid interactive prompts ($EDITOR) by using explicit flags:
Writing rationales without $EDITOR
Always pass --rationale <file|-> (-r) on deccy new or --file <file|-> (-f) on deccy rationale:
# Create a decision with rationale from stdin and capture the JSON reply
REPLY=$(printf 'Rationale text\n' | deccy --json new -d -t text -T "Decision title" -r -)
NODE_ID=$(printf '%s' "$REPLY" | jq -r '.id')
# Update a rationale from stdin
printf 'Revised rationale text\n' | deccy --json rationale "$NODE_ID" --file -
Precomputing or verifying file hashes with deccy hash
Instead of re-implementing BLAKE3("deccy-blob\n" || bytes) in external scripts, call deccy hash:
# Bare hex from stdin
DIGEST=$(deccy hash < src/lib.rs)
# Structured JSON for multiple files
deccy --json hash src/lib.rs src/main.rs
3. Deterministic Node IDs with DECCY_ID_SEED
Normally, deccy new draws 128 bits from the OS CSPRNG. For reproducible tests, fixtures, or deterministic agent runs, set the DECCY_ID_SEED environment variable:
export DECCY_ID_SEED="round-1-fixture"
deccy new -d -t text -T "First reproducible node"
How DECCY_ID_SEED works
deccycomputesBLAKE3("deccy-id\n" ‖ seed ‖ "\n" ‖ attempt)forattempt = 0, 1, 2, ...and encodes the first 16 bytes as 32 reverse-hex characters (k..z).- It picks the first candidate ID not already present on disk in
.deccy/nodes/. - Strict validation: Setting
DECCY_ID_SEED=""or to whitespace-only (e.g.DECCY_ID_SEED=" ") or non-UTF-8 bytes refuses immediately rather than silently falling back to random entropy. UnsetDECCY_ID_SEEDcompletely when you want OS randomness.
4. Atomicity and Pre-Flight Guarantees
Every mutating verb (init, new, describe, rationale, claim, link, remove) follows a strict prepare-then-commit discipline:
- Refusals are write-free: All flag parsing, ID prefix resolution, graph loading, ownership checks, cycle checks, and path validations happen before any file is created or modified. If a command refuses, the working directory and
.deccy/remain byte-for-byte unchanged. - Rationale published before record: When writing a node with prose,
deccywrites and syncs the rationale file first, then atomically renames the temporary record file over.deccy/nodes/<id>.json. A reader never sees a record pointing to an unwritten rationale. - Safe removal order:
deccy removepre-flights all checks, unlinks claimed files first, then unlinks the rationale file, and unlinks the record file last. If interrupted, re-runningdeccy remove <id>finishes cleanly.
5. Exit Codes, Streams, and Broken Pipes
- Exit code
0: Command succeeded (orvalidatefound0problems). - Exit code
1: Command refused,validatefoundproblems > 0, or writing to stdout failed with an I/O error other thanEPIPE. - Human mode streams: Normal output goes to
stdout; refusals (deccy: <reason>\n <evidence>) go tostderr. - JSON mode streams: Both normal envelopes (
{"ok":true,...}) and refusal envelopes ({"ok":false,"error":...}) go tostdoutso a caller readingstdoutalways receives a valid JSON object. - Broken pipe (
EPIPE): Pipingdeccyintoheador another consumer that closes early never panics and preserves the command’s exit code. If a JSON refusal cannot be written tostdoutbecause the pipe closed,deccyfalls back to writing the human refusal tostderrand exits1.