Build a CLI tool that assembles a final text prompt by:
[[key]])xclip)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.
Add logic to parse a raw template string and split it into ordered tokens of two types:
[[key]]Rules:
[[key]] marks an include block[[ appears without a matching ]], raise ValueError("Unclosed include: missing ']]'")Output structure:
list[tuple[bool, str]]
# (is_include, value)
Where:
is_include = False → raw textis_include = True → mapping keyIntroduce a JSON mapping file with structure:
{
"root": "/base/path",
"some_key": [
"path/or/pattern1",
"path/or/pattern2"
]
}
Behavior:
root defines base directory for relative paths (defaults to mapping file directory)Each key maps to a list of file entries:
** recursive matching)Implement a function to resolve each include key into a block of file contents.
For each mapping entry:
root if not absoluteglob(..., recursive=True)If no glob matches:
Then:
Output format per file:
# File: <file_path>
<file contents>
Join all file blocks using:
"\n\n"
Core function:
assemble(template_path: Path, mapping_path: Path) -> str
Workflow:
Determine root path:
For each token:
If include:
Add command-line entrypoint:
python assemble_prompt.py TEMPLATE MAP
Behavior:
assemble()xclip -selection clipboard
via:
subprocess.run(..., input=result, text=True, shell=True, check=True)
Copied result to clipboard.
Exit codes:
0 success1 incorrect usage[[...]] → raise ValueError[[key]] are correctly parsed into text + include tokens in order*, **) are expanded recursively# File: <path> in outputxclip