#19596: feat(setup): add segment template system with base+overlay architecture
cli
commands
agents
size: XL
## Summary
Add a **template system** that creates pre-configured workspaces by business segment. Instead of starting from scratch every time, users can now run \openclaw setup --template clinic\ (or select interactively) to get a workspace tailored to their industry.
## Architecture
### Base + Overlay pattern
\\\
templates/
├── base/ # Universal files (shared across all segments)
│ ├── AGENTS.md
│ ├── BOOTSTRAP.md
│ ├── CONTATOS.md
│ ├── HEARTBEAT.md
│ ├── MEMORY.md
│ ├── SECURITY.md
│ ├── SOUL.md
│ ├── TOOLS.md
│ ├── docs/guides/ # HANDOVER, HEARTBEAT-GUIDE, MEMORY-SYSTEM, MESSAGING-RULES
│ └── memory/people/ # _TEMPLATE.md for people notes
├── clinic/ # Medical/dental clinic overlay
├── personal/ # Personal use overlay
├── construction/ # Construction company overlay
└── law-firm/ # Law firm overlay
\\\
**Resolution order:** overlay → base → original templates (docs/reference/templates). If a segment doesn't override a file, the base version is used. If base doesn't have it either, the original template system kicks in.
### Available segments
| Segment | Description | Overlay files |
|---------|------------|---------------|
| \clinic\ | Medical/dental clinic | AGENTS, CONTATOS, HEARTBEAT, README, SOUL |
| \personal\ | Personal use | AGENTS, README, SOUL |
| \construction\ | Construction/development company | AGENTS, README, SOUL |
| \law-firm\ | Law firm | AGENTS, README, SOUL |
| \default\ | Original OpenClaw templates | (none — uses docs/reference/templates) |
### Placeholder system
Templates use literal \{{PLACEHOLDERS}}\ (e.g., \{{NOME_IA}}\, \{{NOME_USUARIO}}\, \{{EMPRESA_NOME}}\) that are filled in conversationally during the first session via \BOOTSTRAP.md\. See \ emplates/_template-spec.md\ for the full list.
## Usage
\\\ash
# Interactive selector (when TTY available)
openclaw setup
# Direct segment selection
openclaw setup --template clinic
openclaw setup --template personal
openclaw setup --template construction
openclaw setup --template law-firm
openclaw setup --template default
\\\
## How to extend
1. Create \ emplates/{new-segment}/\ directory
2. Add only the files that differ from base (AGENTS.md, SOUL.md, etc.)
3. Add the segment name to \SEGMENT_TEMPLATES\ array in \src/agents/workspace-templates.ts\
4. Add labels/hints to \SEGMENT_LABELS\ in \src/commands/setup.ts\
## Changes
### Source files (4 modified)
- **\src/agents/workspace-templates.ts\** — New \
esolveSegmentTemplateDir()\ function and \SEGMENT_TEMPLATES\ constant
- **\src/agents/workspace.ts\** — \loadSegmentTemplate()\ with overlay→base→fallback resolution; \copySegmentGuides()\ and \copyPeopleTemplate()\ helpers; segment support in \ensureAgentWorkspace()\
- **\src/cli/program/register.setup.ts\** — \--template\ option on the setup command
- **\src/commands/setup.ts\** — Interactive \@clack/prompts\ segment selector; segment pass-through to workspace creation
### Template files (29 new)
- \ emplates/base/\ — 14 universal files covering agents, security, contacts, memory, guides
- \ emplates/clinic/\ — 5 clinic-specific overrides (most complete segment)
- \ emplates/construction/\, \ emplates/law-firm/\, \ emplates/personal/\ — 3 files each (AGENTS, README, SOUL)
- \ emplates/README.md\ and \ emplates/_template-spec.md\ — Documentation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds a segment template system that allows users to bootstrap workspaces pre-configured for specific business verticals (clinic, personal, construction, law-firm). The implementation uses a clean base+overlay architecture where segment-specific files override universal base templates, with fallback to original templates.
**Key changes:**
- New `resolveSegmentTemplateDir()` function and `loadSegmentTemplate()` with overlay→base→fallback resolution logic
- Interactive segment selector via `@clack/prompts` when running `openclaw setup` in TTY mode
- 29 new template files: 14 universal base files, 5 clinic overlays, and 3 files each for personal/construction/law-firm segments
- Automatic folder structure creation (`memory/`, `docs/guides/`, `reports/`, etc.) for segment-based setups
- Template documentation in `templates/README.md` and `_template-spec.md`
**Issues found:**
- Clinic template references missing guide file `AGENDAMENTO-CLINICA.md` that doesn't exist in the codebase
<h3>Confidence Score: 4/5</h3>
- Safe to merge with one minor issue - missing guide file reference should be addressed
- The implementation is solid with clean separation of concerns, proper error handling, and follows repository conventions. The base+overlay resolution logic is straightforward and the fallback pattern ensures existing functionality isn't broken. The code correctly uses `writeFileIfMissing` to avoid overwriting existing files and properly handles missing templates with try-catch blocks. One broken reference to a non-existent guide file in the clinic template needs to be fixed, but this won't cause runtime errors - just a broken documentation link for users
- templates/clinic/AGENTS.md needs attention for the missing guide reference
<sub>Last reviewed commit: bba2c7c</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#10894: Docs: fix legacy branding, add config reference, expand cron troubl...
by biv0711 · 2026-02-07
70.0%
#20700: docs: add real-world setups and use cases guide
by aiagentswiz · 2026-02-19
69.4%
#21553: fix: resolve workspace template dir in bundled dist/ layout
by echoVic · 2026-02-20
69.2%
#17938: feat(workspace): Add GOALS.md and SOUVENIR.md for behavioral anchors
by ibrahimq21 · 2026-02-16
68.4%
#20130: docs: add awesome-openclaw-agents to Community section
by mergisi · 2026-02-18
68.1%
#2884: fix: Create memory directory and symlink identity files during work...
by webdevtodayjason · 2026-01-27
67.5%
#14016: docs(showcase): add CrewClaw deployment platform
by mergisi · 2026-02-11
67.2%
#20494: Infra: add two-node ops docs and env templates
by kermitv · 2026-02-19
66.8%
#11743: fix: remove redundant file reads from AGENTS.md template
by shogunsea · 2026-02-08
66.8%
#16124: Docs: rewrite Coolify guide for native one-click service
by frankdierolf · 2026-02-14
66.6%