agent-first-data 0.41.0

Self-describing data and structured CLI contracts for AI agents — field-name suffixes for units and secrets, the afdata CLI for rendering, validation, path guards, and reading or editing structured documents (JSON, TOML, YAML, dotenv, INI, Markdown), plus libraries for Rust, Go, Python, TypeScript, and Bash.
Documentation

Agent-First Data

Self-describing data and structured CLI contracts for AI agents — field-name suffixes for units and secrets, the afdata CLI for rendering, validation, path guards, and reading or editing structured documents (JSON, TOML, YAML, dotenv, INI, Markdown), plus libraries for Rust, Go, Python, TypeScript, and Bash.

Ask your agent: "Use afdata to standardize my project's fields, CLI output, configs, logs, and shell scripts."

The problem: data that leans on a person to explain it

Most data is written for someone who already knows the system. An engineer who knows the codebase reads {"timeout": 5000} as milliseconds. An agent has no such context — seconds or milliseconds? It guesses, and a 5-second timeout silently becomes 83 minutes. The same trap is everywhere: {"price": 1200} gets charged as $1,200 instead of $12.00; {"expires": 1767225600} is treated as an ID instead of a date.

A person would recognize {"api_key": "sk-live-abc123"} as a key and keep it out of the logs. To an agent it is just another string, so it writes the line straight into a log file.

A person at the prompt looks at a variable before deleting it. An agent writes rm -rf "$work_dir/" — quoted, careful-looking — and if work_dir is empty, that line is rm -rf "/". set -u does not catch it, because an empty string is not unset.

None of this is carelessness. Agents take what they are given literally, and the meaning lived somewhere they cannot see — in someone's head, in documentation, in a schema, in a prompt. That copy goes stale, gets lost, or was never written.

What it does: put the meaning where the agent reads it

Agent-First Data moves the meaning into the name, where an agent cannot miss it, and lets the tools check it. Call the field timeout_ms and there is nothing left to guess. Call it api_key_secret and every AFDATA output boundary hides it. Call a path a tmp_path and it is checked before anything is deleted.

It is a convention and toolkit, not a framework — a small set of name endings, the afdata CLI for rendering, validation, path guards, and structured document edits, plus libraries for Rust, Go, Python, TypeScript, and Bash.

  • Names carry meaning. Endings like _ms, _bytes, _secret, _usd_cents, and _percent put units and intent directly into the field name.
  • Deletes check the path first. afdata_remove tmp_path "$dir" refuses an empty, traversing, or out-of-place path before rm ever runs.
  • The same data, rendered for machines or people. The same fields render as JSON or YAML — both keep original keys and types, for machines — or as a single human log line with units formatted for scanning. Secrets are removed in every form.
  • Structured secrets are redacted. Anything ending in _secret is hidden when a structured value passes through an AFDATA redactor or renderer. A _url field keeps its address but scrubs the userinfo password and secret-named query parameters. Legacy secret and URL fields can be protected with exact secret_names and url_names lists.
  • Logging agents can read. Structured logs that follow the same rules, with request-scoped fields.
  • One contract across CLI and languages. The afdata CLI, the sourceable Bash library, and the Rust, Go, Python, and TypeScript libraries share wire behavior and fixtures while keeping idiomatic native shapes.

A quick look

One record — a log event with a timeout, an API key, and a database URL — rendered as JSON, YAML, and plain. Nothing is configured; the field names carry everything.

{"kind":"log","log":{"event":"startup","args":{"timeout_s":30,"api_key_secret":"sk-123"},"db_url":"postgres://user:p@ss@db/app?token_secret=abc"},"trace":{"duration_ms":1280}}

JSON and YAML keep original keys and types (structure-preserving) and only redact secrets:

---
kind: "log"
log:
  args:
    api_key_secret: "***"
    timeout_s: 30
  db_url: "postgres://user:***@db/app?token_secret=***"
  event: "startup"
trace:
  duration_ms: 1280

Plain is the one human renderer — it strips unit suffixes and formats values for scanning:

kind=log log.args.api_key=*** log.args.timeout=30s log.db_url="postgres://user:***@db/app?token_secret=***" log.event=startup trace.duration=1.28s

Supported suffixes

Category Suffixes
Duration _ns, _us, _ms, _s, _minutes, _hours, _days
Timestamps _epoch_ns, _epoch_ms, _epoch_s, _rfc3339
Size _bytes (integer everywhere — config and output alike)
Currency _msats, _sats, _usd_cents, _eur_cents, _jpy, _{code}_cents, _{code}_micro (code is 3–4 ASCII letters)
Strict strings _bcp47, _utc_offset, _rfc3339_date, _rfc3339_time
Other _percent, _secret, _url

Fiat suffixes use signed integer units: negative values represent refunds, credits, reversals, or deltas and receive the same Plain currency formatting.

JSON and YAML keep suffixes and raw values; Plain strips duration/size/currency/timestamp suffixes after formatting the value, and never strips _url/_bcp47/_utc_offset/_rfc3339_date/_rfc3339_time.

Redaction boundary

Redaction is decided by field name, never by guessing at values. _secret hides the whole value or subtree; _url keeps the address but scrubs its password and secret-named query parameters. Fields that cannot be renamed are protected by listing them exactly in secret_names or url_names. Free-form strings are not scanned for secrets.

The suffix protects a structured field once it passes through an AFDATA redactor or renderer. It cannot remove a live secret from process argv, shell history, /proc, or third-party logs, so keep secrets out of argv. The full rules, including scoped policies and deliberate reveals, are in the specification.

Deleting files: say what the path is for

An agent writes a lot of Bash, and a deletion is where a wrong guess cannot be taken back. The Bash kit names what a path is supposed to be and checks it before anything is removed:

afdata_remove tmp_path "$work_dir"
afdata_remove path "$out_dir/$name" --under "$out_dir"

An empty value, a .. segment, the filesystem root, your home directory, and the current directory — or any ancestor of those — are always refused. A tmp_path must sit inside the real system temp area, so pointing $TMPDIR elsewhere does not get around it. A refusal stops the script under errexit, and rm never runs.

Files that belong to a person rather than a build go to the trash instead, and afdata_trash refuses rather than deleting when it cannot make the move reversible:

afdata_trash path "$document" --under "$library"

See destructive operands in the Bash kit guide.

Reading and editing config documents

Beyond emitting AFDATA, the library and afdata CLI read and safely edit structured documents — JSON, TOML, YAML, dotenv, and INI — by dot-path:

afdata get config.toml server.port                    # one value as an AFDATA record (secrets redacted)
host=$(afdata value config.toml server.host)          # raw scalar, for shell substitution
afdata set config.toml server.port 8080 --value-type number
afdata set config.toml features.- c                   # append one element to an existing array

Use get when the next step must preserve JSON types and structure; value deliberately turns one scalar into raw shell bytes. set creates missing object parents along the requested dot-path, but refuses to traverse an existing scalar or incompatible container.

Edits are source-preserving and atomic: comments, key order, and the syntax of every untouched value survive, and a write that its own parser would reject fails instead of landing. Values are never guessed — a bare value is always a string, and an exact type is asked for, not inferred. A _secret node stays redacted however you address it. Errors carry stable codes and never quote the document, because an error event is the thing an agent logs.

Markdown is read in an explicitly named mode, never a guessed one: its frontmatter can be edited with the body frozen, and its body is read-only structure with source line ranges that sed, awk, and git diff understand. An array element can be addressed by content instead of position, so an address survives an edit above it. The per-format rules, address grammar, and error recovery are in the skill reference.

afdata value README.md h1.0.paragraph.0.text --input-format markdown  # the synopsis

Flags and exit codes are in docs/cli.md and afdata <command> --help; the error codes and recovery rules are in the skill reference. The Rust library is agent_first_data::document (Document / DocumentFile); its API is described in rust/README.md.

Help an agent can read in one call

afdata --help is a structured result like any other, and it lists every legal shape of a command in full — afdata set --help shows the separate set-value, set-null, and set-secret shapes rather than a flag catalog the agent must solve. One registry generates argv parsing, validation, help, and the CLI reference; the contracts are cli-spec-v1 and cli-help-v2.

Writing AFDATA-style Bash scripts

The CLI embeds a sourceable Bash 3.2+ authoring kit:

#!/usr/bin/env bash
set -euo pipefail
_AFDATA_BASH_SOURCE="$("${AFDATA_BIN:-afdata}" shell bash)"
source /dev/stdin <<<"$_AFDATA_BASH_SOURCE"
unset _AFDATA_BASH_SOURCE

afdata_args_begin "build.sh [OPTIONS] PACKAGE [-- CARGO_ARG ...]"
afdata_args_flag release --release "Build release artifacts"
afdata_args_positional package PACKAGE "Package to build"
afdata_args_rest CARGO_ARG "Arguments forwarded to cargo"
afdata_args_parse "$@"

afdata_log info "Building ${package}"
if [ "$release" = true ]; then
  afdata_run cargo build --release ${AFDATA_ARGS_REST[@]+"${AFDATA_ARGS_REST[@]}"}
else
  afdata_run cargo build ${AFDATA_ARGS_REST[@]+"${AFDATA_ARGS_REST[@]}"}
fi
afdata_result "Build complete"

The helpers handle long-form argument parsing, --help, AFDATA output flags, raw config reads, and structured log/result/error events. afdata_run keeps child stdin/stdout/stderr and TTY interaction untouched; only the Bash script's own lifecycle is structured, with a terminal error on child failure. Use afdata_call when an AFDATA Bash parent invokes an AFDATA Bash child and must remain the sole owner of the final result. See the complete Bash authoring kit guide.

Where to use it: CLI flags, config files, logs, and API responses

  • Building a CLI tool an agent will call — your output is understood correctly the first time, with no extra schema to ship. Results land on stdout and errors on stderr by default, so a shell capture or pipe never mistakes a failure for data; a single --output-to stdout collapses everything onto one stream when a consumer would rather branch on kind.
  • Writing a config file — keys like timeout_s or db_password_secret make settings self-explanatory to whoever edits them, and secrets stay hidden when the config is printed back.
  • Adding logs to a service — the same lines stay readable for a person and parseable for an agent.
  • Designing an API response or event payload — units and sensitivity travel with the data, across every boundary it crosses.
  • Auditing for leaked secrets — one naming rule (_secret) makes redaction automatic instead of case-by-case.

One shared contract across languages

The shared core surface ships in Rust, Go, Python, and TypeScript (each in its own casing):

  • Protocol builders json_result / json_error / json_progress / json_log → .build() → an event; reader decode_protocol_event(text) → a typed decoded event.
  • Output render(value, format, options) — the single value × format × options → string entry point.
  • Redaction redacted_value / redact_url_secrets / redact_urls_in_text for paths that bypass render; output options accept exact legacy secret_names and url_names.
  • CLI primitives cli_parse_output, cli_parse_log_filters, build_cli_error, build_cli_version, and the CliEmitter.

Rust is the reference implementation and adds the CLI registry, typed value sources, error catalogs, contract linting, and a tracing layer; see the Rust API reference. Go, Python, and TypeScript provide emitters and readers, and leave argv parsing to the application. The shared surface is enumerated in spec/api-surface.json.

afdata lint reports contract violations and optional suggestions. For example, {"rows":"1,200"} passes with a representation advisory, while {"total_bytes":"8 MB"} fails its declared byte-count contract. Use --schema for schema declarations and --violations-only for a contract gate.

Adopt it: hand the convention to your coding agent

Agent-First Data is a convention, not a dependency you wire in by hand — and adopting a convention is exactly the kind of work you now hand to an agent. There's even an Agent Skill for exactly that — the convention in a form an agent reads and applies directly. Paste this to your coding agent:

Learn the Agent-First Data convention: read https://agentfirstkit.com/agent-first-data/docs/specification and https://agentfirstkit.com/agent-first-data/docs/agent-skill. Then look at the codebase we're working in and tell me whether adopting the convention would help it — and if so, how: which fields and config keys to rename, and where the output and logging helpers fit.

Install the Libraries

cargo add agent-first-data --no-default-features   # Rust library
pip install agent-first-data     # Python
npm install agent-first-data     # TypeScript
go get github.com/agentfirstkit/agent-first-data/go   # Go

Install the CLI

The afdata CLI delivers formatting, redaction, linting, protocol validation, path guards, structured document reading and editing, Agent Skill management, and the sourceable Bash library from one standalone binary, with no toolchain required:

# prebuilt binary
brew install agentfirstkit/tap/afdata   # macOS / Linux
scoop bucket add agentfirstkit https://github.com/agentfirstkit/scoop-bucket && scoop install afdata   # Windows

# or from crates.io
cargo install agent-first-data

Prebuilt archives are also available from GitHub Releases.

Install the Agent Skill

Install the skill and its offline references where agents look for skills:

afdata skill install
afdata skill status

That writes the standard folders: the shared ~/.agents/skills, which most agents read, plus ~/.claude/skills and ~/.gemini/config/skills. Use --scope workspace for .agents/skills and .claude/skills under the current directory. afdata skill uninstall removes managed installations.

For an agent that reads only a folder of its own, pass that folder, the one that contains the individual skill folders. Qwen Code, for example, reads ~/.qwen/skills:

skills_dir="$HOME/.qwen/skills"
afdata skill install --skills-dir "$skills_dir"
afdata skill status --skills-dir "$skills_dir"
afdata skill validate "$skills_dir/agent-first-data"
afdata skill uninstall --skills-dir "$skills_dir"

Validate an Agent Skill

afdata skill validate checks a SKILL.md against the official metadata constraints with a strict YAML parser. Passing a directory also verifies that its name matches the front-matter name.

afdata skill validate skills/agent-first-data

Docs

License

MIT