Skip to main content

Module template

Module template 

Source
Expand description

Prompt-template engine for .harn.prompt assets and the render / render_prompt builtins.

§Surface

{{ name }}                                 interpolation
{{ user.name }} / {{ items[0] }}           nested path access
{{ name | upper | default: "anon" }}       filter pipeline
{{ if expr }}..{{ elif expr }}..{{ else }}..{{ end }}
{{ for x in xs }}..{{ else }}..{{ end }}   else = empty-iterable fallback
{{ for k, v in dict }}..{{ end }}
{{ include "partial.harn.prompt" }}
{{ include "partial.harn.prompt" with { x: name } }}
{{# comment — stripped at parse time #}}
{{ raw }}..literal {{braces}}..{{ endraw }}
{{- x -}}                                  whitespace-trim markers

Back-compat: bare {{ident}} resolves silently to the empty fallthrough (writes back the literal text on miss) — preserving the pre-v2 contract. All new constructs raise TemplateError on parse or evaluation failure.

Structs§

PromptSourceSpan
One byte-range in a rendered prompt mapped back to its source template. Foundation for the prompt-provenance UX (burin-code #93): hover a chunk of the live prompt in the debugger and jump to the .harn.prompt line that produced it.
RegisteredPrompt

Enums§

PromptSpanKind

Functions§

lookup_prompt_consumers
Return every span across every registered prompt that overlaps a template range. Powers the inverse “which rendered ranges consumed this template region?” navigation.
lookup_prompt_span
Resolve an output byte offset to its originating template span. Returns the innermost matching Expr / LegacyBareInterp span when one exists, falling back to broader structural spans (If / For / Include) so a click anywhere in a rendered loop iteration still navigates somewhere useful.
next_prompt_render_ordinal
Produce the next monotonic ordinal for a render-mark. Pipelines invoke the prompt_mark_rendered builtin which calls this to obtain a sequence number without having to know about per-session event counters. The IDE scrubber orders matching consumers by this ordinal when the emitted_at_ms timestamps collide.
prompt_render_indices
Fetch every event index where prompt_id was rendered. Called by the DAP adapter to populate the eventIndices list in the burin/promptConsumers response.
record_prompt_render_index
Record a render event index against a prompt_id (#106). The scrubber’s jump-to-render action walks this map to move the playhead to the AgentEvent where the template was consumed. Stored as a Vec so re-renders of the same prompt id accumulate.
validate_template_syntax
Parse-only validation for lint/preflight. Returns a human-readable error message when the template body is syntactically invalid; Ok(()) when the template would parse. Does not resolve {{ include }} targets — those are validated at render time with their own error reporting.