Scripts

Prompt Build Script Feature 01 - Script

Goal

Build a CLI tool that assembles a final text prompt by:

The system is designed for prompt composition workflows where reusable file groups (e.g., code snippets, docs, context packs) are dynamically injected into a template.


Changes Needed

1. Template Parsing Engine

Add logic to parse a raw template string and split it into ordered tokens of two types:

Rules:

Output structure:

list[tuple[bool, str]]
# (is_include, value)

Where:


2. Mapping File Resolution

Introduce a JSON mapping file with structure:

{
  "root": "/base/path",
  "some_key": [
    "path/or/pattern1",
    "path/or/pattern2"
  ]
}

Behavior:


3. File Group Resolution System

Implement a function to resolve each include key into a block of file contents.

For each mapping entry:

Then:

Output format per file:

# File: <file_path>
<file contents>

Join all file blocks using:

"\n\n"

4. Template Assembly Engine

Core function:

assemble(template_path: Path, mapping_path: Path) -> str

Workflow:

  1. Load template file (UTF-8)
  2. Load mapping JSON
  3. Determine root path:

    • mapping[“root”] if present
    • else mapping file directory
  4. Parse template into tokens
  5. For each token:

    • If literal → append directly
    • If include:

      • fetch mapping entries
      • skip if missing or empty
      • expand via file resolver
      • append expanded content
  6. Return final concatenated string (no extra delimiter between tokens)

5. CLI Interface

Add command-line entrypoint:

python assemble_prompt.py TEMPLATE MAP

Behavior:

xclip -selection clipboard

via:

subprocess.run(..., input=result, text=True, shell=True, check=True)
Copied result to clipboard.

6. Error Handling


Acceptance Criteria