-
Notifications
You must be signed in to change notification settings - Fork 7
Migrate template system to Jinja2 #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anticomputer
wants to merge
9
commits into
GitHubSecurityLab:main
Choose a base branch
from
anticomputer:anticomputer/jinja-templating
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Migrate template system to Jinja2 #125
anticomputer
wants to merge
9
commits into
GitHubSecurityLab:main
from
anticomputer:anticomputer/jinja-templating
Conversation
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
Replace custom regex-based template preprocessing with Jinja2.
- Add Jinja2 dependency
- Create template_utils.py with loader, env function, and render function
- Replace preprocess_prompt in __main__.py with render_template calls
- Update repeat_prompt logic to use Jinja2
- Update swap_env in env_utils.py for Jinja2
New syntax (YAML files not yet migrated):
- {{ GLOBALS_key }} → {{ globals.key }}
- {{ INPUTS_key }} → {{ inputs.key }}
- {{ RESULT }} → {{ result }}
- {{ env VAR }} → {{ env('VAR') }}
- {{ PROMPTS_path }} → {% include 'path' %}
- Create scripts/migrate_to_jinja2.py for automated migration - Migrate example taskflows and toolbox configs to new syntax - Script supports dry-run mode and recursive directory processing
- Update version validator to accept v1 (deprecated) and v2 - Bump all migrated YAML files to version 2 - Add deprecation warning for v1 files with migration instructions - Version 2 indicates Jinja2 templating syntax
- Fail fast: reject v1 files at load time with clear error message - Update README with breaking change notice - Create MIGRATION.md with comprehensive migration guide - Update GRAMMAR.md examples to use Jinja2 syntax
Skip initial template render when repeat_prompt is enabled since result variable is only available during iteration loop.
2d63570 to
b9e1075
Compare
Comment on lines
+80
to
+94
| env = jinja2.Environment( | ||
| loader=PromptLoader(available_tools), | ||
| # Use same delimiters as custom system | ||
| variable_start_string='{{', | ||
| variable_end_string='}}', | ||
| block_start_string='{%', | ||
| block_end_string='%}', | ||
| # Disable auto-escaping (YAML context doesn't need HTML escaping) | ||
| autoescape=False, | ||
| # Keep whitespace for prompt formatting | ||
| trim_blocks=True, | ||
| lstrip_blocks=True, | ||
| # Raise errors for undefined variables | ||
| undefined=jinja2.StrictUndefined, | ||
| ) |
Check warning
Code scanning / CodeQL
Jinja2 templating with autoescape=False
Using jinja2 templates with autoescape=False can potentially allow XSS attacks.
| """Test loading existing prompt.""" | ||
| available_tools = AvailableTools() | ||
| loader = PromptLoader(available_tools) | ||
| env = jinja2.Environment(loader=loader) |
Check warning
Code scanning / CodeQL
Jinja2 templating with autoescape=False
Using jinja2 templates with autoescape=False can potentially allow XSS attacks.
| """Test error on nonexistent prompt.""" | ||
| available_tools = AvailableTools() | ||
| loader = PromptLoader(available_tools) | ||
| env = jinja2.Environment(loader=loader) |
Check warning
Code scanning / CodeQL
Jinja2 templating with autoescape=False
Using jinja2 templates with autoescape=False can potentially allow XSS attacks.
Fix remaining references to old {{ env VAR }} syntax in README and
example comments. Remove unused pprint/pformat imports.
b9e1075 to
57e49cc
Compare
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.
Replace custom regex-based template preprocessing with Jinja2.
Breaking Change
Version 1 YAML files are no longer supported. Bumped version to 0.1.0.
New syntax:
{{ globals.key }}instead of{{ GLOBALS_key }}{{ inputs.key }}instead of{{ INPUTS_key }}{{ result }}instead of{{ RESULT }}{{ env('VAR') }}instead of{{ env VAR }}{% include 'path' %}instead of{{ PROMPTS_path }}Migration:
See doc/MIGRATION.md for details.
New Capabilities
Jinja2 brings powerful templating features:
Conditionals:
Filters:
Loops:
Changes