yamled 0.0.14

Format-preserving YAML edits: change what you meant, keep every other byte
Documentation
# yamled

Format-preserving YAML edits for Rust. **A library without a command.** Import
as `yamled`.

This repo's queue is [`tasks.yaml`](tasks.yaml) (`YMD-###`).

## What this crate owns

- A location index over a YAML source: each node's byte range, its key's
  range, the comments it owns, its indentation, and its style (block or flow,
  plain, quoted, folded, or literal).
- Edits applied as byte splices: replace a value, remove a key or item with
  its own comments, insert a key or item at the file's indentation, and move a
  byte range.
- A value writer that follows the file's style, so a caller never decides
  quoting or indentation by hand. Two settings compose: `TextStyle` picks the
  layout of one write (block or one line), and the document's `Quotes`,
  set once with `Document::with_quotes`, picks the quotes every writer uses.
  `Auto` in both means yamled chooses.

Parsing is `granit-parser`; values are read and written through
`serde-saphyr`. Domain rules stay in the caller: which row moves where, what a
field means, and what a ledger forbids.

## Rules

1. **Every byte an edit does not name stays as it was.** A test compares whole
   files instead of values alone.
2. **No edit leaves invalid YAML.** Each edit is proven by parsing the result
   back to the expected value.
3. **A comment belongs to the node below it** when no blank line separates
   them, and a comment on the same line belongs to that line's node.
4. **Spacing is kept, not guessed.** A new sequence item follows the blank
   lines the sequence already has. Only a sequence that does not settle it
   (fewer than two items, or both kinds of gap) uses the caller's `Spacing`.
5. **Pure Rust.** `unsafe_code` is forbidden here, and a dependency that
   carries C or unsafe transpiled code needs a recorded reason.

## Strings and comments

Multiline strings use `indoc!` and `formatdoc!`. No `concat!`, and no escaped
`\n` inside a document. Doc comments carry the why, on the item; no inline
`//` prose in function bodies.

## Release

A human writes `.changeset/*.md` on the same PR that ships the behaviour. Every
changeset is a `patch` bump; do not write `minor` or `major` until the operator
decides otherwise. Never hand-edit a version or `CHANGELOG.md`. Declarations
live in [`.ctl/ver.yaml`](.ctl/ver.yaml). `.github/workflows/release.yml` calls
verctl's reusable release workflow on every push to `main`: it publishes each
version commit not yet released to crates.io, then opens the Version PR on
`verctl/release/main`. Only the operator merges the Version PR, so no release
happens on its own. Bump its pin with the verctl pin in
`mise.release.toml` and the `ver` include in `mise.toml`. `verify` runs
`check:versions`, which fails a pull request that edits a version by hand.

## Checks

```sh
mise run verify
```

`verify` runs, in parallel:

1. Rust: the toolchain pin check, rustfmt, clippy (pedantic, denied) with all
   features and again with none, `cargo test` and the doc-tests, cargo-deny
   licenses, bans, and sources, cargo-machete, and rustdoc on the dated
   nightly with `-D warnings`, as docs.rs builds it.
   These tasks come from the shared `tasks/rust.toml` of the actions
   repository, which `mise.toml` includes by commit; the Copier template
   moves that pin, so change the tasks there instead of here. The template also
   writes `verify` inline in `mise.toml`.
   `check:features` lives in `mise-tasks/check/features.sh`, because it
   names this crate's feature set; the template wrote it once and leaves it
   to this repository.
   Build, lint, and test run on the pinned stable (1.99.0, also
   `rust-version` and `rust-toolchain.toml`); rustfmt and rustdoc run on the
   dated nightly. Bump both pins together.
   Tests run under plain `cargo test`. Measured on Linux and macOS with
   doc-tests included, cargo-nextest was 1.05 to 14 times slower (it starts
   one process per test), and mbx test scheduling or a `RUST_TEST_THREADS`
   cap slowed concurrent runs. Do not reintroduce them without new
   measurements.
2. `check:repo`: taplo for TOML (`.taplo.toml`), rumdl for Markdown
   (`.rumdl.toml`), typos for spelling, actionlint for workflows, and
   `openspec validate --all --strict`.

mise pins every tool, OpenSpec included (`github:Fission-AI/OpenSpec`, its
standalone release binary); do not use a global copy.
Advisories run on CI only (`mise run deny:advisories`). The rust entry in
`mise.toml` routes Cargo through mr-boxington (`mr_boxington = true`), locally
and in CI, where `jdx/mr-boxington-action` restores the build cache.

Tests put YAML in `indoc!` blocks. A unit test binds the expected text before
the assertion (`let expected = indoc! {...}; assert_eq!(document.as_str(),
expected);`), so rustfmt keeps it readable. A test of an edit sequence goes in
[`tests/workflows.rs`](tests/workflows.rs): its `Ledger` helper reads each
edited value back through `serde-saphyr`, and an inline `insta` snapshot
records the whole file with each line marked `-`, `+`, or kept. Review a
changed snapshot with `mise run snapshots`.

[`tests/properties.rs`](tests/properties.rs) runs random edit sequences on
generated ledgers with `proptest`, and
[`tests/corpus.rs`](tests/corpus.rs) replaces every scalar of the public
[YAML test suite][yaml-test-suite] with itself. The suite is a git submodule
at `tests/yaml-test-suite`, pinned to a commit of its `data` branch.
`[deps.git-submodule]` in `mise.toml` checks it out before `mise run` or
`mise x` when it is missing or `.gitmodules` changed.

[yaml-test-suite]: https://github.com/yaml/yaml-test-suite

## Copier template

The repository setup comes from the shared Copier template, the private
`victor-software-house/templates` repository (project `rust-crate`): the whole
files `.miserc.toml`, `.envrc`, `mise.dev.toml`, `mise.ci.toml`,
`lefthook.yml`, `committed.toml`, the shared `.sh` tasks in `mise-tasks/`
(`hooks/`, `commit-msg.sh`, `commits.sh`, `check/repo.sh`, `format/`,
`lint/`, `specs.sh`), `rust-toolchain.toml`,
`rustfmt.toml`, `clippy.toml`, and `deny.toml`, plus the settings,
toolchain, and `[task_config]` blocks of `mise.toml` and the `[lints]` tables
of `Cargo.toml`.
`.copier-answers.yml` records its tag and yamled's answers; never edit it by
hand. Take a new tag with
`MISE_ENV=template mise x -- uvx copier@9.18.2 update --defaults`, review
the diff, and fix any conflict markers (`git diff --check`) before
committing. The template owns the layout of its whole files, so
`.taplo.toml` excludes the TOML ones.

Tasks follow one layout. `mise.toml` holds tools, settings, and deps, and
its `[task_config].includes` lists `mise-tasks` first, then the pinned `git::`
catalogs. Every other task is a one-line fragment or a file task in
`mise-tasks/`. Fragment names are not namespaced by file, so each name
carries its prefix (`lint:md` in `lint.toml`).

Local work loads the `dev` profile (`.miserc.toml`): lefthook, committed, and
gitleaks. Every hook command runs with `MISE_ENV=dev,hooks`. Its
`postinstall` hook runs `lefthook install` after every `mise install`, so a
fresh clone gets its git hooks from `mise install`. CI sets `MISE_ENV=ci`
(`ci,release` for release jobs) and never loads `dev`, so no runner installs
hooks.

The Template check, `.github/workflows/template.yml`, calls the shared
`template-check.yml` of the actions repository by commit, which runs
`mise run template:check` with a token from the `vsh-templates-reader`
GitHub App. It fails when the newest tag changes a file besides
`.copier-answers.yml`; a newer tag that renders the same files passes with a
notice. The job is skipped for pull requests from forks. Run the same check
locally with `mise run template:check`. Turn a template piece off with
`mise run template:off <piece>`, which keeps its files.

## Features

`serde` (default) adds the edits that write a value (`replace`, `insert`,
`push`, `insert_item`, and their `_text` forms) and pulls `serde` and
`serde-saphyr`. serde-saphyr comes as the `vsh-serde-saphyr` package:
2.1.1 with two patches, so deserializing never runs the snippet renderer.
Without it the crate needs `granit-parser` alone: the location index,
`remove`, `take`, `put`, `reorder`, and `reindent`. Anything new that
needs a serializer goes under `serde`; `check:features` lints the crate
without it. Dependencies are declared with the features the crate uses,
default features off.

## Git

Conventional commits. lefthook. No `--no-verify`. Branch `type/number-desc`.
Always open a PR; never push to `main`.

## Changes

Plan a behaviour or contract change as an OpenSpec change in
`openspec/changes/<name>/` before writing code. `openspec/config.yaml` holds
this repository's context and rules, and `openspec validate <name>` checks the
change. One change maps to one `tasks.yaml` row.