Agent-First Data v0.40.0: Writes That Read Back, Rules Apart from Advice
Every document write proves the file reads back as the requested value, lint separates contract violations from CLI advisories, native values convert the same way in all four SDKs, plain and YAML output escape every control character, and the CLI primitives match across languages.
An editor that preserves comments and layout writes text, not values. The text it produces is only correct if reading it back gives the value that was asked for, and until now that was assumed rather than checked. This release checks it, and holds the rest of the library to the same standard: a rule is either a deterministic contract or a suggestion, and a value converts one way no matter which SDK carries it.
Every write reads itself back
Before a document edit is installed, the edited source is parsed again and
compared with the requested document. A mismatch refuses the write with
document_write_would_corrupt, names what read back differently, and leaves
the file untouched. That covers edits whose text looks right but means
something else: a TOML number the format cannot hold exactly, an emptied array
of tables, a YAML scalar a reader would retype.
The writes themselves got closer to what a person would have typed:
- YAML strings stay strings for older readers. A value or key that a
YAML 1.1 reader would take as a boolean, null, number or timestamp —
yes,off,~,0x1F,1_000,2024-01-01,1:20— is quoted on every write path, including JSON-typed values. - Comments stay with what they describe. Removing a TOML table or key keeps a genuine file header and never writes it twice. In INI, a comment directly above a section header belongs to that section, by the same blank-line rule TOML uses.
- JSON keeps its layout. Inserts follow the file’s line endings and indentation, and removals leave no stray spaces or blank lines.
- INI reads a UTF-8 BOM and writes it back. JSON and dotenv name the BOM in their parse error instead of reporting line 1, column 1.
- Numeric slugs are never silently indexes. With
--slug-field, a numeric segment that is both an index and another element’s slug isdocument_ambiguous_matchfor every verb, includingaddandremove, andaddrefuses a slug that could never be addressed.addandremovealso accept a slug-addressed parent. - Typed values mean their type.
--value-type boolaccepts onlytrueandfalse.
A replaced file keeps its permissions and, on Unix, its owner and group where
the process may apply them. An owner that cannot be restored becomes the
writer, as with sed -i. A group that cannot be restored refuses the write
when the mode grants that group access, because installing under another group
would hand the contents to that group. Extended attributes and ACLs are not
copied.
Lint: contract violations apart from advisories
Library assertions now check only deterministic contracts. A field named
size_bytes holding "8 MB" violates its declared type. A field named rows
holding "1,200" declares nothing, so it passes. Recognizing that "1,200"
looks like a formatted quantity is a heuristic, and heuristics now live in the
CLI as advisories.
afdata lint reports both, separately. A completed report always has
violations and advisories arrays. With no violations it is a result with
ok: true and exit 0, suggestions included. With any violation it is a
lint_failed error carrying both arrays, at exit 1. --violations-only skips
advisory analysis, and --schema interprets schema property declarations in
the input. Software build identifiers are text, not quantities.
Native values convert one way
Each SDK accepts the values its language naturally produces, and they now become the same JSON in all of them:
- Ill-formed Unicode in keys and values becomes U+FFFD before redaction and rendering.
- Non-finite numbers become
<unsupported:number>; finite integers, floats and decimals stay numbers. - Exceptions use their message, times are UTC RFC 3339, byte sequences are padded Base64.
- Mappings with string or integer keys become objects; any other key type,
and any value without a JSON form, is
<unsupported:TYPE>.
Conversion is per value. In Go, a struct with one NaN field used to become a
single unsupported marker, losing the rest of the payload and any timestamp on
it; now only that field is marked, and struct fields follow encoding/json’s
tag, omitempty, omitzero, ,string and embedding rules. Progress and log
timestamps are stamped on struct payloads too.
Output that stays on one line
Plain output escapes every Unicode control character, plus U+2028 and U+2029,
as \u{XXXX}, so a value from an untrusted source cannot carry a terminal
escape sequence or break a record across lines. YAML escapes U+007F–U+009F and
U+FFFE/U+FFFF, which strict YAML loaders reject, alongside the C0 controls it
already escaped.
Redaction closes two gaps. A relative _url value such as
/cb?code_secret=x gets the same query and fragment redaction as an absolute
URL. Under TraceOnly, a secret name of trace now hides the whole trace
subtree.
The same CLI primitives in every SDK
A closed reader is success in Rust, Go, Python and TypeScript, checked by one
shared end-to-end test. Log filters normalize identically everywhere, error and
version builders return a typed event in all four SDKs, and TypeScript gains
emitResult, emitError, emitProgress and emitLog. A shared fixture pins
these rules for all four test suites.
Smaller fixes
- A read failure has one code,
document_io_failed, acrossget,lint,render,validateandskill validate;read_failedis gone. afdata pathaccepts empty segments.- A TOML or YAML document containing
infornanreports the path holding it rather than a serializer error. afdata emit error --hint ""and an empty event message are refused, like an empty code.is_valid_bcp47readsxandiprefixes case-insensitively and requires a subtag after them.- The generated CLI reference lists public option defaults.
- The Bash kit refuses repeated options with
cli_duplicate_argument, keeps extra positionals in the rest without--, treatsafdata_timeout 0as no limit, validates an inheritedAFDATA_OUTPUTin the script’s own name, and refuses reserved variable names inafdata_mktempandafdata_into.
Breaking changes
- Rust:
LintSeverity,LintOptions::minimum_severity,LintOptions::runtime_valuesandassert_no_lint_findings_with_optionsare gone;lint_valuereturns contract violations only.AtomicStepgainsPreserveOwnership. - CLI:
afdata lint --min-severityis replaced by--violations-only, and the report hasviolationsandadvisories.read_failedis nowdocument_io_failed.--value-type boolis strict. - Go:
BuildCLIErrorisBuildCliError,BuildCliVersionreturns anEvent, andDecodedError.Hintis a*stringso an empty hint is distinct from none (HintIfSomeis new). - Python:
CliEmitter.emittakes only anEvent, no longer a plain dict;render()accepts anEventdirectly. - All SDKs: plain and YAML escaping and native value conversion change as described above.
- Bash kit: a repeated option is an error where the last one used to win.