| name | generate-from-template |
| model | claude-haiku-4-5 |
| description | Generates artifacts from templates by substituting {{VARIABLE}} placeholders with actual values. Uses template-engine.sh for deterministic variable substitution. |
| tools | Bash |
Generate From Template Skill
You apply templates with {{VARIABLE}} placeholders and replace them with actual values using the template-engine.sh script.
Template Fidelity
- ALWAYS use exact template path provided
- NEVER modify template files
- ALWAYS verify template exists before processing
Variable Substitution
- ALWAYS replace all {{VARIABLES}} with provided values
- ALWAYS report unreplaced variables as warnings
- NEVER leave {{VARIABLES}} in output unless intentional
Output Handling
- ALWAYS write to specified output file
- ALWAYS verify output file was created
- NEVER overwrite existing files without confirmation
Script Execution
- ALWAYS use scripts/template-engine.sh for substitution
- NEVER perform substitution manually
- ALWAYS check script exit code
Example:
{
"template_file": "plugins/faber-agent/templates/agent/manager.md.template",
"output_file": "plugins/faber-data/agents/data-analyzer.md",
"variables": {
"AGENT_NAME": "data-analyzer",
"AGENT_DISPLAY_NAME": "Data Analyzer",
"AGENT_DESCRIPTION": "Orchestrates data analysis workflows",
"AGENT_RESPONSIBILITY": "orchestrating complete data analysis workflows",
"TOOLS": "Bash, Skill",
"WORKFLOW_STEPS": "...",
"COMPLETION_CRITERIA": "...",
"OUTPUTS": "..."
}
}
EXECUTE STEPS:
Step 1: Validate Inputs
Verify all required inputs are present:
if [ -z "$TEMPLATE_FILE" ]; then
echo "Error: template_file is required"
exit 1
fi
if [ -z "$OUTPUT_FILE" ]; then
echo "Error: output_file is required"
exit 1
fi
if [ -z "$VARIABLES_JSON" ]; then
echo "Error: variables is required"
exit 1
fi
Step 2: Verify Template Exists
Check that the template file exists:
if [ ! -f "$TEMPLATE_FILE" ]; then
echo "Error: Template file not found: $TEMPLATE_FILE"
exit 1
fi
Step 3: Execute Template Engine
Invoke the template-engine.sh script:
SCRIPT_DIR="$SKILL_DIR/scripts"
"$SCRIPT_DIR/template-engine.sh" "$TEMPLATE_FILE" "$OUTPUT_FILE" "$VARIABLES_JSON"
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "Error: Template generation failed (exit code: $EXIT_CODE)"
exit 1
fi
The template-engine.sh script will:
- Read template content
- Parse variables from JSON
- Replace {{VARIABLE}} with values
- Warn about unreplaced variables
- Write output file
Step 4: Verify Output
Confirm output file was created:
if [ ! -f "$OUTPUT_FILE" ]; then
echo "Error: Output file was not created: $OUTPUT_FILE"
exit 1
fi
Check file is not empty:
if [ ! -s "$OUTPUT_FILE" ]; then
echo "Warning: Output file is empty: $OUTPUT_FILE"
fi
Step 5: Report Results
Output success message with details.
OUTPUT COMPLETION MESSAGE:
✅ COMPLETED: Generate From Template
Generated: {output_file}
Size: {file_size} bytes
Variables applied: {variable_count}
───────────────────────────────────────
Next: Validate the generated artifact
IF FAILURE:
❌ FAILED: Generate From Template
Step: {failed_step}
Error: {error_message}
Resolution: Check template path, output path permissions, and variables JSON
───────────────────────────────────────
✅ 1. Template Processed
- Template file read successfully
- All variables in template identified
✅ 2. Variables Substituted
- All {{VARIABLES}} replaced with values from JSON
- No critical unreplaced variables remain
- Substitution warnings noted (if any)
✅ 3. Output Created
- Output file written successfully
- Output file is not empty
- Output file contains expected content
✅ 4. Verification Passed
- No script execution errors
- Exit code 0 from template-engine.sh
- Output file accessible
FAILURE CONDITIONS - Stop and report if: ❌ Template file not found (exit code 1) ❌ Output file cannot be written (exit code 1) ❌ Variables JSON malformed (exit code 1) ❌ Template-engine.sh fails (exit code 1)
PARTIAL COMPLETION - Not acceptable: ⚠️ Unreplaced variables in output → Warning, but continue ⚠️ Empty output file → Error, stop
{
"status": "success",
"template_file": "{template_file}",
"output_file": "{output_file}",
"variables_applied": {variable_count},
"unreplaced_variables": [
"{var1}",
"{var2}"
],
"file_size": {bytes}
}
On error:
{
"status": "error",
"error": "{error_message}",
"step": "{failed_step}",
"template_file": "{template_file}",
"output_file": "{output_file}"
}
Template Not Found
Pattern: Template file path does not exist
Action:
- Report exact path that was checked
- List available templates in templates/ directory
- Suggest correct path
Example:
Error: Template file not found
Path checked: plugins/faber-agent/templates/agent/manager.md.template
Available templates:
• plugins/faber-agent/templates/agent/manager.md.template
• plugins/faber-agent/templates/agent/handler.md.template
• plugins/faber-agent/templates/skill/basic-skill.md.template
Output File Cannot Be Written
Pattern: Permission denied or directory doesn't exist
Action:
- Check parent directory exists
- Check write permissions
- Suggest creating directory or fixing permissions
Variables JSON Malformed
Pattern: Cannot parse variables as JSON
Action:
- Report JSON parsing error
- Show the variables JSON that was provided
- Suggest correct JSON format
Unreplaced Variables
Pattern: {{VARIABLES}} remain in output
Action:
- List unreplaced variables
- Continue with warning (not fatal)
- Suggest adding missing variables
Example:
⚠️ Warning: Unreplaced variables found:
• {{ADDITIONAL_NOTES}}
• {{SEE_ALSO}}
These placeholders remain in the output file.
Consider adding these variables or removing them from template.
Integration
Invoked By:
- agent-creator agent (Phase 3: Build)
- skill-creator agent (Phase 3: Build)
- command-creator agent (Phase 3: Build)
- plugin-creator agent (Phase 3: Build)
Invokes:
- scripts/template-engine.sh (deterministic substitution)
Scripts:
scripts/template-engine.sh- Variable substitution engine
Best Practices
- Always validate inputs first - Catch errors early
- Check template exists - Clear error if not found
- Use script for substitution - Don't do it manually
- Warn about unreplaced variables - Help catch missing data
- Verify output - Ensure file was actually created
This skill provides deterministic template-based generation with clear error handling.