How I Built a Zero-Dependency {{Variable}} AI Prompt Compiler & Multi-Agent Blueprint Workbench
Managing AI prompts across multiple agents, IDEs, and APIs quickly turns messy when instructions are scattered across copy-pasted text files. To solve this without bloating my stack, I built a zero-dependency {{Variable}} AI Prompt Compiler & Multi-Agent Blueprint Workbench using pure browser ES Mo

Managing AI prompts across multiple agents, IDEs, and APIs quickly turns messy when instructions are scattered across copy-pasted text files. To solve this without bloating my stack, I built a zero-dependency {{Variable}} AI Prompt Compiler & Multi-Agent Blueprint Workbench using pure browser ES Modules.
Here is how the core compiler architecture works under the hood.
Instead of pulling in heavy templating engines like Handlebars or Mustache, a single regular expression handles variable discovery and fallback values cleanly:
const TOKEN_REGEX = / \ { \ { \ s * ( [ a - zA - Z0 - 9_. - ] + ) (?: \ | ( [ ^ } ] * ) )? \ s * \ } \ } / g; export function extractTokens ( template ) { const tokens = new Map ( ); for ( const match of template. matchAll ( TOKEN_REGEX ) ) { const [, key, fallback = "" ] = match; if (! tokens. has ( key ) ) tokens. set ( key, fallback. trim ( ) ); } return tokens; } export function compilePrompt ( template, values = { } ) { return template. replace ( TOKEN_REGEX, ( _, key, fallback = "" ) => { const val = values [ key ]; return val!== undefined && val!== ""? String ( val ): fallback. trim ( ); } ); } Enter fullscreen mode Exit fullscreen mode With syntax like {{target_stack|TypeScript + Node 22}} or {{tone|concise}}, every template self-documents its inputs and falls back gracefully when optional parameters are omitted.
Before sending compiled prompts to an LLM, developers need immediate feedback on context budget. By pairing a lightweight heuristic tokenizer ( Math.ceil(text.length / 4) adjusted for whitespace and code punctuation) with a static pricing table, the workbench calculates real-time input costs across GPT-4.1, Claude Sonnet 4, and Gemini 2.5 Pro:
const MODEL_RATES_PER_1M = { "gpt-4.1": 2.00, "claude-sonnet-4": 3.00, "gemini-2.5-pro": 1.25, }; export function estimateCost ( compiledText, model = "gpt-4.1" ) { const tokens = Math. ceil ( compiledText. trim ( ). length / 4 ); const usd = ( tokens / 1_000_000 ) * ( MODEL_RATES_PER_1M [ model ]?? 2.0 ); return { tokens, usd: Number ( usd. toFixed ( 6 ) ) }; } Enter fullscreen mode Exit fullscreen mode Zero network calls, instant reactivity on every keystroke.
Because the compiled output is plain structured data, exporting to any coding agent ecosystem takes a pure formatter function:
Test your own templates in the Live Interactive Studio Demo or grab the Full 24-Blueprint Commercial Source Pack to deploy production workflows immediately.
If you also work with financial automation or EU/Vietnam XML compliance, check out our companion XML E-Invoice Audit tool ( Live Demo | Source Pack ) built on the same zero-dependency ES Module philosophy.