Repository navigation
Rewrite workflow generator on Jinja2 templates - #545
Merged
Merged
Conversation
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]>
tend-agent
approved these changes
May 16, 2026
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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the f-string-based workflow generator with Jinja2 templates, swapping
{{/}}for<</>>so GitHub Actions${{ ... }}expressions pass through unchanged. Templates live as.yaml.j2files undergenerator/src/tend/templates/; render functions reduce to aget_template+renderpair.Result:
workflows.pyshrinks from ~1009 → 393 lines. All 230 existing regtest snapshots pass byte-identical — the output contract is unchanged.${{{{ ... }}}}f-string escapes → 0_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 thegenerate_nightly/weekly/review_runstrio (collapsed into_generate_scheduledlambdas inGENERATORS) and three_*_PROMPT_TMPLconstants (inlined as{% set %}blocks)._default_promptmoves toConfig.default_prompt._setup_yamldumps via ruamel.yaml directly instead of hand-rolled field-ordering + plain-scalar-detection.agent_step,permissions,fork_guard_if,fork_guard_prefix,checkout,block_prompt) live inmacros.yaml.j2and are auto-registered as Jinja globals via anisinstance(val, Macro)filter — workflow templates call them without{% from ... import %}headers.packages = ["src/tend"]declaration bundles them automatically (verified viaunzip -l dist/tend-*.whl). Nopyproject.tomldata-file plumbing needed.Adds
jinja2>=3.1.6to runtime deps (joiningclickandruamel.yaml).Test plan
uv run --directory generator pytest— all 242 tests pass byte-identical, including the 230 regtest snapshots that define the output contractpre-commit run --all-files— ruff, ruff-format, actionlint, typos, uv-lock all passuv build --wheel— templates land attend/templates/*.yaml.j2in the wheel🤖 Generated with Claude Code