#!/usr/bin/env python3 # /// script # requires-python = ">=3.11" # /// """process_template: fill a template's variables and conditional blocks. Template syntax: {name} a variable; replaced when --var name=value is given, left alone otherwise (unmatched tokens may be runtime tokens such as {project-root} or {agent.name}) {if-X} ... {/if-X} a conditional block; kept when X is in --true, removed whole otherwise. Blocks nest; the innermost is resolved first. Conditionals are resolved before variables, so a variable inside a removed block is never substituted. A marker left after processing means a malformed or mismatched block that the emitted file would carry verbatim: the script exits 3 and names the markers. Usage: process_template.py