Module filters

Module filters 

Source
Expand description

Custom Tera filters for AGPM templates.

This module provides template filters that extend Tera’s functionality for AGPM-specific use cases, such as reading project files, content manipulation, and other template operations.

§Security

All file access is restricted to the project directory with the following protections:

  • Only relative paths are allowed (no absolute paths)
  • Directory traversal outside project root is prevented
  • Only text file types are permitted (.md, .txt, .json, .toml, .yaml)
  • Missing files produce hard errors to fail fast

§Supported File Types

  • Markdown (.md): YAML/TOML frontmatter is automatically stripped
  • JSON (.json): Parsed and pretty-printed
  • Text (.txt): Raw content
  • TOML (.toml): Raw content
  • YAML (.yaml, .yml): Raw content

§Examples

§Basic File Reading

---
agpm.templating: true
---
# Code Review Agent

## Style Guide
{{ 'project/styleguide.md' | content }}

## Best Practices
{{ 'docs/best-practices.txt' | content }}

§Combining with Dependency Content Embedding

Use both content filter and dependency .content fields together:

---
agpm.templating: true
dependencies:
  snippets:
    - path: snippets/rust-patterns.md
      name: rust_patterns
---
# Rust Code Reviewer

## Shared Rust Patterns (versioned, from AGPM)
{{ agpm.deps.snippets.rust_patterns.content }}

## Project-Specific Style Guide (local)
{{ 'project/rust-style.md' | content }}

When to use each:

  • agpm.deps.<type>.<name>.content: Versioned content from AGPM repositories
  • content filter: Project-local files (team docs, company standards)

§Recursive Templates

Project files can themselves contain template syntax:

project/styleguide.md:

# Coding Standards

## Rust-Specific Rules
{{ 'project/rust-style.md' | content }}

## Common Guidelines
{{ 'project/common-style.md' | content }}

The template system will render up to 10 levels of nested references.

Constants§

MAX_RENDER_DEPTH
Maximum nesting depth for recursive template rendering.

Functions§

create_content_filter
Creates a Tera filter function for reading and embedding file content.
read_and_process_content
Reads and processes a project file based on its type.
validate_content_path
Validates a file path for security and correctness.