name: custom-doc-templates description: Enable coding agents to create custom Handlebars templates for documentation generation and use them to generate professional documentation. Use when users want to create specialized documentation types or customize existing templates. Integrates with the Context-Aware Documentation Generation feature (P023).
Custom Documentation Templates Skill
This skill enables coding agents to create custom Handlebars templates for automated documentation generation and use them to generate professional, spec-traceable documentation for SEA-Forge™ projects.
When to Offer This Skill
Trigger conditions:
- User mentions creating a custom template: "create a template", "new template", "custom doc template"
- User wants specialized documentation: "generate a deployment guide", "create an SLA doc", "write a runbook"
- User mentions customizing existing templates: "modify the README template", "update the architecture template"
- User asks about documentation capabilities: "what docs can you generate?", "how do I customize templates?"
Initial offer: Explain that the agent can help create custom Handlebars templates for any documentation type and use them to generate documentation with context-aware analysis. The process involves:
- Template Design: Define the structure, sections, and data requirements
- Template Creation: Write the Handlebars template with Markdown helpers
- Testing: Validate the template with sample data
- Generation: Use the template to generate documentation for projects
Ask if they want to create a new template or use existing templates to generate documentation.
Mode 1: Create Custom Template
Step 1: Understand Requirements
Ask the user:
- What type of documentation is this? (e.g., Deployment Guide, SLA, Runbook, Migration Guide)
- Who's the target audience?
- What sections should it include?
- What data will be needed? (e.g., project context, specs, architecture, custom metadata)
- Any specific formatting or style requirements?
Step 2: Design Template Structure
Based on their answers, propose a template structure:
Proposed structure for [TEMPLATE TYPE]:
## Sections
1. [Section 1 Name] - [Purpose]
2. [Section 2 Name] - [Purpose]
3. [Section 3 Name] - [Purpose]
...
## Data Requirements
- projectName
- description
- [custom fields...]
## Available Helpers
- {{codeBlock code lang}} - Markdown code blocks
- {{link text url}} - Markdown links
- {{table headers rows}} - Markdown tables
- {{mermaid diagram}} - Mermaid diagrams
- {{heading level text}} - Headings (h1-h6)
Ask if this structure works or if they want to adjust it.
Step 3: Create Template File
Create the Handlebars template file in libs/documentation/templates/[TEMPLATE_NAME].hbs:
# {{projectName}} [Template Type]
## Overview
{{description}}
{{#if customSection1}}
## [Section 1]
{{customSection1}}
{{/if}}
... [rest of template]
## Specification Traceability
| Type | ID | Title |
| --- | --- | --- |
{{#each traceability}}
| {{type}} | {{link id url}} | {{title}} |
{{/each}}
Key Guidelines:
- Use Handlebars syntax:
{{variable}},{{#if condition}},{{#each array}} - Use available helpers for Markdown formatting
- Always include traceability section
- Use semantic HTML structure
- Make sections conditional when appropriate
Step 4: Register Template in Code
Create/update the template registration service:
// In libs/documentation/adapters/src/template-registry.ts
import { HandlebarsTemplateAdapter } from './handlebars-template.adapter';
import * as fs from 'fs/promises';
import * as path from 'path';
export class TemplateRegistry {
private adapter: HandlebarsTemplateAdapter;
constructor() {
this.adapter = new HandlebarsTemplateAdapter();
}
async registerTemplate(templateId: string, templatePath: string): Promise<void> {
const content = await fs.readFile(templatePath, 'utf-8');
await this.adapter.registerFromContent(templateId, templateId.toUpperCase(), content);
}
async loadAllTemplates(): Promise<void> {
const templatesDir = path.join(__dirname, '../../templates');
const files = await fs.readdir(templatesDir);
for (const file of files) {
if (file.endsWith('.hbs')) {
const templateId = file.replace('.hbs', '');
await this.registerTemplate(templateId, path.join(templatesDir, file));
}
}
}
}
Step 5: Create Sample Data
Create a sample data file to test the template:
// sample-data/[template-name].json
{
"projectName": "Example Service",
"description": "A sample microservice...",
"customField1": "...",
"traceability": [
{
"type": "ADR",
"id": "ADR-024",
"title": "Automated Documentation Generation",
"url": "file:///path/to/adr/024.md"
}
]
}
Step 6: Test Template
Test the template rendering:
import { TemplateRegistry } from './template-registry';
import * as fs from 'fs/promises';
const registry = new TemplateRegistry();
await registry.registerTemplate('[template-id]', './templates/[TEMPLATE_NAME].hbs');
const sampleData = JSON.parse(
await fs.readFile('./sample-data/[template-name].json', 'utf-8')
);
const output = await registry.adapter.render('[template-id]', sampleData);
console.log(output);
Review the output with the user and iterate on the template as needed.
Step 7: Document Template Usage
Create documentation for the template in libs/documentation/templates/README.md:
## [Template Name]
**Purpose**: [Brief description]
**Audience**: [Target readers]
**Data Requirements**:
- `projectName` (string) - Name of the project
- `description` (string) - Project description
- [other fields...
]
**Usage**:
```bash
just doc-generate /path/to/project [template-id]
Example Output: See sample-data/[template-name]-example.md
## Mode 2: Generate Documentation from Templates
### Step 1: List Available Templates
Show user available templates:
```bash
# List built-in templates
ls libs/documentation/templates/
# Available templates:
# - README.hbs
# - ARCHITECTURE.hbs
# - API_REFERENCE.hbs
# - [custom templates...]
Step 2: Analyze Project Context
# Enable AST analysis for code structure (optional)
export ENABLE_AST_ANALYSIS=true
# Analyze project context
just context-analyze /path/to/project
This extracts:
- Specifications (SDS, ADR, PRD)
- CALM architecture model
- Code structure (if enabled)
- Dependencies
- Technical stack
Step 3: Prepare Template Data
Create a data preparation script or gather data manually:
// prepare-doc-data.ts
import { SpecAnalyzerAdapter } from '@sea/context-adapters';
import { CalmAnalyzerAdapter } from '@sea/context-adapters';
async function prepareData(projectPath: string) {
const specAnalyzer = new SpecAnalyzerAdapter();
const calmAnalyzer = new CalmAnalyzerAdapter();
const specs = await specAnalyzer.extractSpecs(projectPath);
const architecture = await calmAnalyzer.extractArchitecture(projectPath);
return {
projectName: /* derive from package.json */,
description: /* from README or specs */,
features: /* from SDS files */,
architecture: {
nodes: architecture.nodes,
relationships: architecture.relationships
},
traceability: specs.sdsList.map(sds => ({
type: 'SDS',
id: sds.id,
title: sds.title,
url: `file://${sds.path}`
}))
};
}
Step 4: Generate Documentation
# Generate documentation using template
just doc-generate /path/to/project [template-type]
# Examples:
just doc-generate ./libs/my-service readme
just doc-generate ./libs/my-service architecture
just doc-generate ./libs/my-service deployment-guide
Step 5: Validate Output
# Validate generated documentation
just doc-validate /path/to/project/docs/generated/[type].md
Validation checks:
- Required sections present (POL-DOC-002)
- Traceability links included (POL-DOC-003)
- Template conformance
- Markdown syntax validity
Step 6: Iterate as Needed
If validation fails or output needs adjustment:
- Review validation errors
- Check template data
- Update template or data as needed
- Regenerate
Advanced: Custom Handlebars Helpers
Creating Custom Helpers
If built-in helpers aren't sufficient, create custom ones:
// In HandlebarsTemplateAdapter
Handlebars.registerHelper('customHelper', (arg1: string, arg2: string) => {
// Custom logic
return new Handlebars.SafeString(result);
});
Example: Status Badge Helper
Handlebars.registerHelper('statusBadge', (status: string) => {
const badges = {
'approved': '',
'draft': '',
'deprecated': ''
};
return new Handlebars.SafeString(badges[status] || '');
});
Usage in template:
{{statusBadge status}}
Best Practices
Template Design
- Start Simple: Begin with minimal sections, add complexity as needed
-
Make Sections Conditional: Use
{{#if}}for optional sections - Reuse Components: Create partial templates for common sections
- Include Examples: Show examples of expected output
- Document Data Shape: Clearly specify what data is required
Data Preparation
- Validate Inputs: Check for required fields before rendering
- Provide Defaults: Use sensible defaults for optional fields
- Transform Data: Shape data to match template expectations
- Cache Context: Reuse analyzed context for multiple templates
Quality Assurance
- Test with Real Data: Use actual project data, not just mocks
-
Validate Output: Run
just doc-validateon generated docs - Check Links: Ensure traceability links are valid
- Review Manually: Have humans review generated documentation
Common Templates to Create
Deployment Guide
- Prerequisites
- Configuration
- Deployment steps
- Rollback procedure
- Troubleshooting
Runbook
- Service overview
- Common operations
- Monitoring and alerts
- Incident response
- Escalation procedures
SLA Document
- Service description
- Availability targets
- Performance metrics
- Support levels
- Change management
Migration Guide
- Current state
- Target state
- Migration steps
- Rollback plan
- Known risks
API Changelog
- Version history
- Breaking changes
- New features
- Deprecations
- Migration notes
Troubleshooting
Template Not Rendering
Symptom: Template produces empty or malformed output
Solutions:
- Check data matches template variables
- Verify Handlebars syntax is correct
- Test with minimal template first
- Check for typos in variable names
Missing Traceability Links
Symptom: Traceability section is empty
Solutions:
- Ensure
traceabilityarray is in data - Check spec files have proper frontmatter
- Run
just spec-guardto validate specs - Verify file paths are absolute
Handlebars Syntax Errors
Symptom: Template compilation fails
Solutions:
- Balance all
{{#if}}with{{/if}} - Balance all
{{#each}}with{{/each}} - Escape literal braces:
\{{not_a_variable}} - Check helper syntax matches registration
Integration with P023
This skill leverages the Context-Aware Documentation Generation feature:
- Universal Context Service (SDS-051): Provides context extraction
- Documentation Orchestrator Service (SDS-036): Manages generation workflow
- Template Engine: Handlebars adapter with Markdown helpers
- Feature Flags: Control analysis depth
Just Commands:
-
just doc-generate <project> <type> -
just doc-validate <artifact> -
just context-analyze <project>
Example Session
# User: "I want to create a deployment guide template"
# Agent: [Creates template structure based on requirements]
# Agent: [Writes Handlebars template to libs/documentation/templates/deployment-guide.hbs]
# Agent: [Creates sample data file]
# Agent: [Tests template and shows output]
# User: "Looks good! Now generate one for my-service"
# Agent:
just context-analyze ./libs/my-service
just doc-generate ./libs/my-service deployment-guide
# Agent: [Shows generated deployment-guide.md]
# User: "Perfect!"
Exit Criteria
Template creation is complete when:
- Template file exists in
libs/documentation/templates/ - Template renders correctly with sample data
- Generated output validates successfully
- Documentation for the template is created
Generation is complete when:
- Documentation is generated at expected location
- Validation passes
- Output meets user requirements
chat Comments (0)
Sign in to join the discussion and leave a comment.
Skill Details
Related Skills
Build your own?
Join 12,000+ developers contributing to the Claude ecosystem.
No comments yet. Be the first to share your thoughts!