Repoburg
Login

Customization: Context Templates

Context templates are the most powerful feature of Repoburg. They give you precise control over the information (the "context") that is sent to the Large Language Model (LLM) with your prompt. By crafting good templates, you can dramatically improve the quality and relevance of the AI's responses.

Key Concepts

  • Dynamic Context: Instead of manually copying and pasting code, you can write templates that dynamically pull in file contents, directory structures, or command outputs.
  • Eta Syntax: Templates are written using the Eta templating engine, which is similar to EJS. It allows you to embed JavaScript and custom helper functions directly within your text.
  • Reusable: Templates are saved and can be reused across different sessions and projects. You can set default templates for when you start a new session or send a follow-up prompt.

Default Template Roles

While you can use any template for any prompt, Repoburg has special "default" slots that you can assign templates to. This automates which template is used in different situations.

  • Default Initial: This template is automatically used for the very first prompt in a new session. It's designed to provide broad, high-level context about the entire project to the AI.

    • Example Use Case: A template that runs tree to show the project structure and rg to include the content of all source code files.
  • Default Follow-up: This template is used for all subsequent prompts within the same session. It's typically more focused than the initial template and may include information about the previous turn.

    • Example Use Case: A template that only includes the content of files specified in ad-hoc context (@file.ts) and a summary of the outcome of the last set of actions.
  • Default Condensed: This is a special template used as the initial template for a follow-up session. When you create a follow-up session, it inherits the context (all files created, edited, or mentioned) from the parent session. This template is designed to present that inherited context concisely.

    • Example Use Case: A template that shows a condensed file tree and lists the content of only the files inherited from the previous session.

The Template Editor

The template editor is divided into three main sections:

  1. File Explorer (Left): A view of your project's file system. You can use this to select files and folders to include in your template's static context definition.
  2. Template Details (Middle): Where you write the actual Eta template code and manage the static context items.
  3. Preview (Bottom of Middle Pane): A button to render the final context string based on your template and selected context, allowing you to see exactly what the LLM will receive.

Template Types

  • Main: A complete template that can be used for an initial or follow-up prompt.
  • Partial: A reusable chunk of template code that can be included within another template. This is useful for defining common sections you want to share across multiple main templates (e.g., a standard header).

Template Variables and Helpers

Within an Eta template, you have access to several variables and helper functions on the it object.

Variables

  • it.user_input: The user's most recent prompt.
  • it.system_prompt: The content of the currently active system prompt.
  • it.user_prev_action: A summary of the outcome of the previous turn's actions.
  • it.context_snippets_content: The combined, rendered output of all Context Snippets (!handle) invoked in the user's prompt.
  • it.adhoc_files_content: The combined content of all files added to the ad-hoc context (@file).
  • it.adhoc_folders_content: The combined content and file tree of all folders added to the ad-hoc context (#folder).

Built-in Helper Functions

You can call special asynchronous functions to pull in dynamic context.

Example:

<%~ await it.tree('.') %>

Here are the available helpers:

  • it.readFile('path/to/file'): Reads the content of a single file and wraps it in markdown code blocks.
  • it.tree('[args]'): Runs the tree command to show a directory structure. Arguments are passed as a string (e.g., -L 2 --gitignore).
  • it.ripGrep('[args]'): Runs rg (ripgrep) to search the codebase. Arguments are passed as a string (e.g., 'searchTerm -g "*.ts"').
  • it.gitDiff('[args]'): Runs git diff to get changes. Arguments are passed as a string (e.g., 'main').
  • it.runCommand('[command]'): Runs a shell command in the project root. Use with caution.
  • it.glob('pattern'): Returns a list of file paths matching a glob pattern (e.g., 'src/**/*.ts').
  • it.include('partial-name', it): Includes a partial template by its name. Note: The second argument it is required to pass the current context down to the partial.

Static Context vs. Dynamic Context

  • Static Context (context_definition): Files and folders you select from the File Explorer are saved as part of the template's definition. Their content is fetched and included automatically when the template is used.
  • Dynamic Context (Helpers): Using helpers like it.readFile within the template content gives you more control over formatting and allows you to build context based on logic within the template itself.