← Back to PRs

#19596: feat(setup): add segment template system with base+overlay architecture

by qualiobra open 2026-02-18 00:42 View on GitHub →
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