Agent-First Config

Generic dot-path accessor for JSON/TOML/YAML configs, usable both as a Rust library and as a standalone afconfig CLI binary. The library is the primary interface: spores embed it to get getkey/setkey without writing a dispatch table per field. The CLI wraps the same logic for shell scripts and quick one-off edits from any language.

Ask your agent: “Add agent-first-config to my project and use it to read and write my config fields by dot-path.”

Neither form requires the other. Add just the lib features you need (json, toml, yaml, schema), or install the binary with --features cli and never touch Rust at all.

Install

Rust library:

cargo add agent-first-config

CLI binary (all format backends):

cargo add agent-first-config --features cli

Core Features

Lib Usage

use agent_first_config::{Value, get_path, set_path, add_keyed, KeyedList};

let mut config = Value::Object(Default::default());

// Set a simple key (type inferred from shape: "993" → integer)
set_path(&mut config, "imap.port", &["993".to_string()], &[])?;

// Add to a keyed list with a seed template
let keyed = [KeyedList { prefix: "identities", slug_field: "identity" }];
let seed = /* Value::Object with default fields */;
add_keyed(&mut config, "identities", "me", &keyed, Some(&seed),
          &[("email".to_string(), "me@example.com".to_string())])?;

// Traverse by slug or numeric index
let email = get_path(&config, "identities.me.email", &keyed)?;
let step0  = get_path(&config, "steps.0.move_to_mailbox_id", &keyed)?;

CLI Usage

afconfig get    config.json imap.host
afconfig set    config.json imap.port 993
afconfig add    config.json identities support email=support@example.com name="Support"
afconfig remove config.json identities support
afconfig show   config.json

Format is auto-detected from the file extension (.json, .toml, .yaml).

See docs/cli.md for the full CLI reference.

Traversal Rules

Features

FeatureWhat it enables
jsonJSON format (default on)
tomlTOML format-preserving via toml_edit
yamlYAML re-serializing (comments not preserved)
schemaCliSchema trait + markdown/annotated-config rendering
cliafconfig binary (pulls in clap + agent-first-data; enables all formats + schema)

No features enabled = zero format deps (traversal and coercion only).