Skip to content

PM (PromptManager)

PromptManager
"Prompts with superpowers"
Parse YAML front matter from markdown, expand shell references, compose prompts from other files, and render ERB on demand.

PM (PromptManager) treats a prompt file as a composable, parameterized template. Write prompts in markdown with YAML front matter, shell references, and ERB. PM handles the rest.

Key Features

  • YAML Metadata - Parse from markdown strings or files
  • Shell Expansion - $VAR, ${VAR}, $(command); \$ escapes; code fences are skipped
  • ERB Rendering - On-demand rendering with required and default parameters
  • File Includes - Compose prompts from multiple files with a tracked include tree
  • Raw Inserts - Drop any file in verbatim
  • Custom Directives - Blocks or PM::Directive subclasses, callable from ERB
  • Configurable Pipeline - Enable, disable, or lock stages per prompt or globally
  • Typed Errors - A PM::Error hierarchy for everything PM raises
  • Comment Stripping - HTML comments removed before processing
  • Zero runtime dependencies - Ruby 4.0.9+ and its standard library

Processing Pipeline

Every prompt passes through four stages:

graph LR
    A[Strip HTML Comments] --> B[Extract YAML Metadata]
    B --> C[Shell Expansion]
    C --> D["ERB Rendering (on to_s)"]
  1. Strip HTML comments -- <!-- ... --> removed before anything else
  2. Extract YAML metadata -- Front matter between --- fences parsed into PM::Metadata
  3. Shell expansion -- Environment variables and commands expanded (when shell: true)
  4. ERB rendering -- Templates evaluated on demand when to_s is called (when erb: true)

Quick Example

Given a file review.md:

---
title: Code Review
parameters:
  language: ruby
  code: null
---
Review the following <%= language %> code:

<%= code %>

Parse and render:

require 'pm'

parsed = PM.parse('review.md')
puts parsed.metadata.title        #=> "Code Review"
puts parsed.to_s('code' => source) #=> rendered prompt

A word on trust

A prompt file can run Ruby (ERB), run shell commands ($(...)), and read any file (include / insert). Treat prompt files as code and read the Security guide before parsing files you did not write.

Getting Started

Head to Installation to add PM to your project, then follow the Quick Start guide.