edawise

deccy CLI Last updated

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

OutcomeExit CodeStreamEnvelope Shape
Success0stdout{"ok":true,"verb":"<verb>", ...facts}
Help (--help --json)0stdout{"lines":["..."],"ok":true}
Failed validate report1stdout{"ok":false,"problems":N,"report":[...],"summary":"invalid N problems","verb":"validate"}
Refusal (error)1stdout{"error":"<reason>","evidence":["..."],"ok":false}

Important distinction for parsers: When "ok": false is 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), validate ran to completion and found problems > 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

  • deccy computes BLAKE3("deccy-id\n" ‖ seed ‖ "\n" ‖ attempt) for attempt = 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. Unset DECCY_ID_SEED completely 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:

  1. 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.
  2. Rationale published before record: When writing a node with prose, deccy writes 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.
  3. Safe removal order: deccy remove pre-flights all checks, unlinks claimed files first, then unlinks the rationale file, and unlinks the record file last. If interrupted, re-running deccy remove <id> finishes cleanly.

5. Exit Codes, Streams, and Broken Pipes

  • Exit code 0: Command succeeded (or validate found 0 problems).
  • Exit code 1: Command refused, validate found problems > 0, or writing to stdout failed with an I/O error other than EPIPE.
  • Human mode streams: Normal output goes to stdout; refusals (deccy: <reason>\n <evidence>) go to stderr.
  • JSON mode streams: Both normal envelopes ({"ok":true,...}) and refusal envelopes ({"ok":false,"error":...}) go to stdout so a caller reading stdout always receives a valid JSON object.
  • Broken pipe (EPIPE): Piping deccy into head or another consumer that closes early never panics and preserves the command’s exit code. If a JSON refusal cannot be written to stdout because the pipe closed, deccy falls back to writing the human refusal to stderr and exits 1.

Written by Edawise