Skip to content

Rewrite workflow generator on Jinja2 templates - #545

Merged
max-sixty merged 2 commits into
mainfrom
templating-evaluation
May 16, 2026
Merged

max-sixty merged 2 commits into
mainfrom
templating-evaluation

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

Replace the f-string-based workflow generator with Jinja2 templates, swapping {{/}} for <</>> so GitHub Actions ${{ ... }} expressions pass through unchanged. Templates live as .yaml.j2 files under generator/src/tend/templates/; render functions reduce to a get_template + render pair.

Result: workflows.py shrinks from ~1009 → 393 lines. All 230 existing regtest snapshots pass byte-identical — the output contract is unchanged.

  • 32 quadrupled-brace ${{{{ ... }}}} f-string escapes → 0
  • Helpers eliminated: _agent_step, _action_ref, _fork_guard, _permissions, _escape, _render_step, _order_step_fields, _yaml_scalar, _bot_token/_claude_token/_anthropic_api_key/_openai_key/_codex_auth_json, _PLAIN_TOP_LEVEL, _YAML_FLOW, plus the generate_nightly/weekly/review_runs trio (collapsed into _generate_scheduled lambdas in GENERATORS) and three _*_PROMPT_TMPL constants (inlined as {% set %} blocks).
  • _default_prompt moves to Config.default_prompt.
  • _setup_yaml dumps via ruamel.yaml directly instead of hand-rolled field-ordering + plain-scalar-detection.
  • 6 macros (agent_step, permissions, fork_guard_if, fork_guard_prefix, checkout, block_prompt) live in macros.yaml.j2 and are auto-registered as Jinja globals via an isinstance(val, Macro) filter — workflow templates call them without {% from ... import %} headers.
  • Templates ship as package data; hatchling's packages = ["src/tend"] declaration bundles them automatically (verified via unzip -l dist/tend-*.whl). No pyproject.toml data-file plumbing needed.

Adds jinja2>=3.1.6 to runtime deps (joining click and ruamel.yaml).

Test plan

  • uv run --directory generator pytest — all 242 tests pass byte-identical, including the 230 regtest snapshots that define the output contract
  • pre-commit run --all-files — ruff, ruff-format, actionlint, typos, uv-lock all pass
  • uv build --wheel — templates land at tend/templates/*.yaml.j2 in the wheel

🤖 Generated with Claude Code

max-sixty and others added 2 commits May 16, 2026 16:17
Replaces ~80 lines of programmatic YAML construction and 32 quadrupled-brace
`${{{{ ... }}}}` f-string escapes with Jinja templates using custom `<<>>`
variable delimiters so GitHub Actions `${{ ... }}` expressions pass through
unchanged. Templates now read as the YAML they produce.

Helpers eliminated: `_default_prompt` (moved to `Config.default_prompt`),
`_agent_step`, `_action_ref`, `_fork_guard`, `_permissions`, `_escape`,
`_render_step`, `_order_step_fields`, `_yaml_scalar`, `_bot_token`,
`_claude_token`, `_anthropic_api_key`, `_openai_key`, `_codex_auth_json`,
`_PLAIN_TOP_LEVEL`, `_YAML_FLOW`, plus the `generate_nightly`/`weekly`/
`review_runs` trio (collapsed into lambdas over `_generate_scheduled`) and
three `_*_PROMPT_TMPL` constants (inlined as `{% set %}` blocks).

`_setup_yaml` now dumps via ruamel.yaml directly instead of the hand-rolled
field-ordering + plain-scalar-detection logic. Six macros in `_MACROS`
(`agent_step`, `permissions`, `fork_guard_if`, `fork_guard_prefix`,
`checkout`, `block_prompt`) are auto-registered as Jinja globals via an
`isinstance(val, Macro)` filter so new macros don't require boilerplate.

Output is byte-identical: all 230 tests including the regtest snapshot
suite pass unchanged. `workflows.py` shrinks 1009 → 882 lines.

Adds `jinja2>=3.1.6` to runtime deps.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Templates were inlined as triple-quoted strings in `workflows.py`. Moving
them to `src/tend/templates/*.yaml.j2` files gives editor YAML
highlighting (the `.yaml.` infix matches most editors' tail-extension
rules), pulls 500 lines of YAML out of the Python source, and leaves
each render function as a 5-line `get_template` + `render` pair.

The `Environment` switches from `from_string` to a `PackageLoader("tend",
"templates")`. Macros from `macros.yaml.j2` are loaded once at import and
auto-registered as Jinja globals so workflow templates can call
`agent_step(...)` directly without `{% from ... import %}` headers.

No `pyproject.toml` changes needed — hatchling's
`packages = ["src/tend"]` declaration bundles every file under that tree
into the wheel, verified via `unzip -l dist/tend-*.whl`.

`workflows.py` shrinks 893 → 393 lines. All 230 tests pass byte-identical.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit df649cf into main May 16, 2026
6 checks passed
@max-sixty
max-sixty deleted the templating-evaluation branch May 16, 2026 23:21
max-sixty added a commit that referenced this pull request May 16, 2026
Switch the generator to the uv-native PEP 517 backend. uv-build's
defaults (`module-root = "src"`, module name from the normalized project
name) match the existing layout, so no `[tool.uv.build-backend]` block
is needed and the hatch-specific `[tool.hatch.build.targets.wheel]` goes
away.

Verified `uv build --wheel` produces the same six `tend/*.py` modules,
`pytest` is green (242 passed), and a sentinel `src/tend/_sentinel.txt`
shipped in the wheel — so non-Python data files under `src/tend/` are
bundled by default. That matters for the templating-evaluation branch
(#545), which adds `src/tend/templates/*.yaml.j2`; the two PRs will
conflict on `pyproject.toml` at merge time, whichever lands second
rebases.

---------

Co-authored-by: Claude <[email protected]>
@max-sixty max-sixty mentioned this pull request May 17, 2026
3 tasks
max-sixty added a commit that referenced this pull request May 17, 2026
## Summary

Release 0.0.24. 11 PRs since 0.0.23:

- #545 Rewrite the workflow generator on Jinja2 templates
- #546 generator: switch build backend to uv_build
- #544 generator: route install-test through `_apply_extras`
- #535 install-tend: unify on the chain model (admin-gated refs + env
policy pin)
- #537 review-reviewers: migrate to the Codex harness
- #551 debug-tend-run: support Codex session logs; instruct Codex to
read skills in full
- #552 review: stop re-posting "prior thread still applies" on every
push
- #547 fix(stats): stop blacking out the section on transient worker
outage
- #548 site: simplify "currently tending" to a prose repo list
- #549 site: refresh "currently tending" on a 30s timer
- #550 site: refresh Stats and Activity on a timer

#551 and #552 are the reason for cutting now: together they stop the
Codex harness re-posting near-identical "the prior thread still applies"
reviews on every push. The behavior is release-gated, so it only reaches
tend's own dogfooded workflows once 0.0.24 is published and the nightly
regen repins the action ref.

No new breaking changes since 0.0.23 (the `TEND_BOT_TOKEN` rename
shipped in 0.0.23).

## Test plan

- [ ] CI green (test, test-worker, lint)
- [ ] After merge: tag `0.0.24`, PyPI publish (`pypi-release.yaml` on
the tag push), `uvx [email protected] --help` works
- [ ] Regenerate tend's own workflows to `@0.0.24` (separate `chore:
regenerate` PR, after the tag exists)

Co-authored-by: Claude <[email protected]>
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.

2 participants