Skip to content

feat(generator): switch config surface from TOML to YAML - #454

Merged
max-sixty merged 9 commits into
mainfrom
yaml-config
May 14, 2026
Merged

max-sixty merged 9 commits into
mainfrom
yaml-config

Conversation

@max-sixty

@max-sixty max-sixty commented May 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Move .config/tend.toml → .config/tend.yaml. Alternative to the "__TEND_DELETE__" string sentinel landed in #451 — same goal (reach RFC 7396's null-deletes-key branch from user config), different mechanism. #439 has both for comparison.

YAML has a native null, so the delete-key example becomes:

workflows:
  nightly:
    workflow_extra:
      on:
        schedule: null   # drop the cron, keep workflow_dispatch

The parser is ruamel.yaml (YAML 1.2), not PyYAML — so the usual YAML 1.1 footguns don't bite the config surface:

  • Unquoted on: stays the string "on", not boolean True.
  • Norway problem doesn't apply: yes/no/on/off stay strings; only true/false are booleans.

Scope

  • Config.load reads .config/tend.yaml via ruamel.yaml's safe loader.
  • tend init auto-migrates a legacy .config/tend.toml (verifies parsed structures match via dict equality before swapping). tend check stays read-only and points users at tend init if only .toml is present.
  • Migrated docs/tend.example.toml → docs/tend.example.yaml with a new "delete a generated key with null" example.
  • Removed the __TEND_DELETE__ sentinel + its three tests; added replacement tests for YAML-native null (top-level, nested, missing-key noop), unquoted on: round-trip as string, and Norway-problem strings (NO, off) surviving uncoerced.
  • _apply_extras uses ruamel.yaml with typ="rt" to preserve insertion-order on regen (safe mode sorts mapping keys, which would churn every diff). Flow-mode scalar dumper stays on typ="safe".
  • Migrated every test, tend's own .config/tend.yaml, install-tend, review-reviewers, review-runs, running-tend, CLAUDE.md, README.md, action.yaml, TODO.md. bot_name scrapers in cross-repo lookups now use yq '.bot_name // ""' instead of sed.

Tradeoffs vs the sentinel

  • (+) Native null instead of a magic string.
  • (+) Single config format aligned with the generated workflows.
  • (+) YAML 1.2 via ruamel.yaml — no Norway problem, no on: → True trap.
  • (−) Breaking change for every consumer: .config/tend.toml no longer parses; consumers must rename and translate. Auto-migration in tend init softens this — nightly regen handles it for free — but tend check invocations between bump and nightly hard-error with the migration hint.
  • (−) Extra runtime dep: ruamel.yaml (pure-Python, ~1.3 MB installed) replacing pyyaml (C-extension, ~750 KB installed).

The sentinel approach (#451) keeps TOML and avoids both the breaking change and the new dep at the cost of a magic string in config. Pick your poison.

Test plan

  • cd generator && uv run pytest — 203 passed
  • pre-commit run --all-files — all hooks pass
  • uv run python -m tend init round-trips .config/tend.yaml into the existing .github/workflows/ files (no diff outside pre-existing drift in tend-mention.yaml and the v0.0.17 → v0.0.18 header stamp from the release on main)
  • Delete-key example in docs/tend.example.yaml produces the expected merged workflow — covered by test_null_drops_top_level_key
  • Norway-problem strings survive — covered by test_norway_problem_string_not_coerced
  • Auto-migration verifies parsed structures match before swapping — covered by test_init_auto_migrates_legacy_toml, test_init_does_not_touch_yaml_when_both_exist, test_workflows_from_migrated_config_match_workflows_built_from_toml_dict

🤖 Generated with Claude Code

Move `.config/tend.toml` → `.config/tend.yaml`. YAML has a native `null`
literal, so RFC 7396 Merge Patch's delete-key semantic works directly
in `workflow_extra` / `jobs.<name>` overrides — no string sentinel
needed.

Alternative to the `"__TEND_DELETE__"` sentinel landed in #451. Open
for comparison; #439 has both.

Changes:
- `tend.config.Config.load` reads `.config/tend.yaml` via `yaml.safe_load`.
- Hard error when `.config/tend.toml` exists but `.yaml` doesn't —
  points the user to migrate (no auto-detection or silent fallback).
- `docs/tend.example.toml` → `docs/tend.example.yaml`, with a new
  "delete a generated key with null" example and a YAML quoting tip
  covering the Norway problem (`yes`/`no`/`on`/`off` → boolean).
- `_apply_extras` normalizes a stray `True` key in user-supplied
  `workflow_extra` back to `"on"` so unquoted `on:` in an override
  merges into the workflow's existing trigger block — the same YAML 1.1
  trap that already bit the generated workflows.
- Remove the `__TEND_DELETE__` sentinel and its tests; replaced by
  three new tests that exercise YAML-native `null` at the top level,
  inside a nested job override, and on a missing key (no-op per RFC 7396).
- Migrate all generator tests, tend's own `.config/tend.yaml`, the
  install-tend skill, review-reviewers, review-runs, running-tend,
  DESIGN.md, README.md, CLAUDE.md, and action.yaml. `bot_name` scrapers
  in cross-repo lookups now match `bot_name:` instead of `bot_name =`.

Tradeoffs vs the sentinel approach:
- (+) Native `null` instead of a magic string.
- (+) Single config format aligned with the generated workflows.
- (−) Breaking change for every consumer: `.config/tend.toml` no longer
  parses; consumers must rename and translate (one-off).
- (−) YAML 1.1 footguns surface: unquoted `on:` parses as boolean True,
  and the Norway problem (`NO`/`yes`/`on`) coerces string values
  unexpectedly. Mitigated where it bites the generator; documented in
  `docs/tend.example.yaml` for user-facing values.

Co-Authored-By: Claude <[email protected]>
Switch the runtime dep from `pyyaml` to `ruamel.yaml>=0.18` so the config
surface is YAML 1.2. Drops two PyYAML traps:

- Unquoted `on:` parses as the string `"on"`, not boolean True. The
  `True`-key dance in `_apply_extras` (both for the loaded workflow and
  for `workflow_extra` overrides) is gone.
- Norway problem: `yes`/`no`/`on`/`off` stay strings. The quoting tip in
  `docs/tend.example.yaml` is no longer needed; replaced with a one-line
  "parsed under YAML 1.2" note. New test pins the behavior on a
  prompt/env containing `NO` and `off`.

Block-mode dumper uses `typ="rt"` to preserve insertion order; safe mode
sorts mapping keys alphabetically, which would churn every regen diff.
Flow-mode dumper for inline scalars stays on `typ="safe"`.

Tests import `from tests import _yaml as yaml`, a tiny shim that wraps
ruamel.yaml with a pyyaml-style `safe_load` / `safe_dump` surface, so the
existing `yaml.safe_load(text)` call sites keep working.

Co-Authored-By: Claude <[email protected]>

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One stale .config/tend.toml reference outside the diff: generator/src/tend/checks.py:340 is the repo-secret-allowlist failure message that points the user at secrets.allowed in .config/tend.toml — a file that no longer exists after this PR. Happy to push a one-line fix if you want.

One-shot CLI command for adopters bumping past the config format
cutover. Reads `.config/tend.toml` via stdlib `tomllib`, writes
equivalent YAML, verifies the parsed structures match, then deletes
the TOML. Aborts (leaving both files untouched) if `.config/tend.yaml`
already exists or if the round-trip parse doesn't compare equal —
which would mean the migration lost or changed data.

Equivalence check uses dict equality on the parsed structures. Since
`Config.load` operates on the parsed dict (not the file format), equal
dicts guarantee identical `Config`, and therefore byte-identical
generated workflows. The `test_workflows_from_migrated_config_match_
workflows_built_from_toml_dict` test pins that property end-to-end.

The nightly skill now invokes `uvx tend@latest migrate` before
`uvx tend@latest init` when only `.config/tend.toml` is present, so
the upgrade happens automatically on the next scheduled regen. Git
status / add scope broadened to include `.config/` so the migration
and the regenerated workflows ship in the same PR. `Config.load`'s
error when only `.toml` is present now points users at the command.

Replaced the brittle bot_name sed scrapers in `running-tend` and
`review-reviewers` with `yq '.bot_name // ""'` — handles missing keys
via jq's alternative operator and is robust to quoting/whitespace
variations.

Co-Authored-By: Claude <[email protected]>
max-sixty and others added 2 commits May 13, 2026 12:56
`tend migrate` was a separate CLI command for the one-shot TOML→YAML
upgrade. With auto-migration in `init`, the standalone command is
redundant — drop it.

`tend init` now checks for a legacy `.config/tend.toml` before loading
the config. If only the TOML is present, it runs the verified migration
(parsed-TOML dict must equal parsed-back-YAML dict) and continues into
workflow regeneration. If both files exist, the YAML is canonical and
the TOML is left alone for the operator to review and delete.

`tend check` stays read-only — it errors when only `.toml` is present
and points the user at `tend init`, which handles the upgrade.

The nightly skill drops its explicit `tend migrate` step; `init` does
it transparently. `migrate.py` stays as a helper module called from
`init` (kept separate because tomllib should not leak into the steady-
state config code path).

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	DESIGN.md
max-sixty and others added 2 commits May 13, 2026 15:40
Four references to the old config filename survived the YAML migration:

- README.md:51 linked to docs/tend.example.toml, which was renamed to
  .yaml — the link 404'd
- generator/src/tend/checks.py:340 emitted a `tend check` error message
  pointing users at the wrong filename
- TODO.md:41,62 referenced .toml in unrelated forward-looking sections

Caught by the merge-review pass on #454.

Co-Authored-By: Claude <[email protected]>
…erge

Three round-trip issues in the override path that produced churny diffs on
every regen for consumers using `workflow_extra` or `jobs.<name>`:

- `_deep_merge` did `result = dict(base)`, a shallow copy that discards
  ruamel.yaml's `CommentedMap` style metadata. Switch to `copy.deepcopy`
  so key order, comments, and sequence indentation survive the merge.

- `_YAML_BLOCK` ran on ruamel's default indent (`mapping=2, sequence=2,
  offset=0`), emitting `- uses:` at the same column as `steps:`. The
  hand-rendered templates use 6-space list indent. Set
  `indent(mapping=2, sequence=4, offset=2)` so applied workflows match
  the no-extras shape.

- `_apply_extras` prepended HEADER to the dumped output, but `typ="rt"`
  loads preserve the HEADER comment block from `wf.content` and emit it
  again on dump — producing a duplicate header. Drop the manual prepend;
  let ruamel round-trip the comment block.

Also set `preserve_quotes = True` so explicit double-quoted scalars
(`cron: "17 6 * * *"`) round-trip with their quotes intact.

Add `test_extras_apply_path_regtest` to snapshot the `_apply_extras` path
end-to-end — the existing regtests only covered no-extras workflows, so
all three drift modes above were invisible to the suite.

Caught by the second-pass merge review on #454.

Co-Authored-By: Claude <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner Author

@nedtwigg any thoughts? this solves the null problem, albeit in an obtuse way....

@nedtwigg

Copy link
Copy Markdown

I don't have any preference between TOML and YAML. I haven't adopted yet, hoping to do so sometime between today and Monday, I'll wait for this to settle first :)

@max-sixty

Copy link
Copy Markdown
Owner Author

@tend-agent resolve conflicts

@max-sixty
max-sixty merged commit d704058 into main May 14, 2026
6 checks passed
@max-sixty
max-sixty deleted the yaml-config branch May 14, 2026 19:11
@tend-agent tend-agent mentioned this pull request May 14, 2026
4 of 6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants