You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: presets/ARCHITECTURE.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,24 @@ The resolution is implemented three times to ensure consistency:
41
41
-**Bash**: `resolve_template()` in `scripts/bash/common.sh`
42
42
-**PowerShell**: `Resolve-Template` in `scripts/powershell/common.ps1`
43
43
44
+
### Composition Strategies
45
+
46
+
Templates, commands, and scripts support a `strategy` field that controls how a preset's content is combined with lower-priority content instead of fully replacing it:
|`prepend`| Places content before lower-priority content (separated by a blank line) | ✓ | ✓ | — |
52
+
|`append`| Places content after lower-priority content (separated by a blank line) | ✓ | ✓ | — |
53
+
|`wrap`| Content contains `{CORE_TEMPLATE}` (templates/commands) or `$CORE_SCRIPT` (scripts) placeholder replaced with lower-priority content | ✓ | ✓ | ✓ |
54
+
55
+
Composition is recursive — multiple composing presets chain. The `PresetResolver.resolve_content()` method walks the full priority stack bottom-up and applies each layer's strategy.
56
+
57
+
Content resolution functions for composition:
58
+
-**Python**: `PresetResolver.resolve_content()` in `src/specify_cli/presets.py`
59
+
-**Bash**: `resolve_template_content()` in `scripts/bash/common.sh`
60
+
-**PowerShell**: `Resolve-TemplateContent` in `scripts/powershell/common.ps1`
61
+
44
62
## Command Registration
45
63
46
64
When a preset is installed with `type: "command"` entries, the `PresetManager` registers them into all detected agent directories using the shared `CommandRegistrar` from `src/specify_cli/agents.py`.
Presets **override**, they don't merge. If two presets both provide `spec-template`, the one with the lowest priority number wins entirely.
64
+
Presets **override by default**, they don't merge. If two presets both provide `spec-template` with the default `replace` strategy, the one with the lowest priority number wins entirely. However, presets can use **composition strategies** to augment rather than replace content.
65
+
66
+
### Composition Strategies
67
+
68
+
Presets can declare a `strategy` per template to control how content is combined:
69
+
70
+
```yaml
71
+
provides:
72
+
templates:
73
+
- type: "template"
74
+
name: "spec-template"
75
+
file: "templates/spec-addendum.md"
76
+
strategy: "append"# adds content after the core template
77
+
```
78
+
79
+
| Strategy | Description |
80
+
|----------|-------------|
81
+
| `replace` (default) | Fully replaces the lower-priority template |
82
+
| `prepend` | Places content **before** the resolved lower-priority template, separated by a blank line |
83
+
| `append` | Places content **after** the resolved lower-priority template, separated by a blank line |
84
+
| `wrap` | Content contains `{CORE_TEMPLATE}` placeholder (or `$CORE_SCRIPT` for scripts) replaced with the lower-priority content |
Multiple composing presets chain recursively. For example, a security preset with `prepend` and a compliance preset with `append` will produce: security header + core content + compliance footer.
65
95
66
96
## Catalog Management
67
97
@@ -108,13 +138,5 @@ See [scaffold/](scaffold/) for a scaffold you can copy to create your own preset
108
138
109
139
The following enhancements are under consideration for future releases:
110
140
111
-
-**Composition strategies** — Allow presets to declare a `strategy` per template instead of the default `replace`:
For artifacts and commands (which are LLM directives), `wrap` would inject preset content before and after the core template using a `{CORE_TEMPLATE}` placeholder. For scripts, `wrap` would run custom logic before/after the core script via a `$CORE_SCRIPT` variable.
120
-
-**Script overrides** — Enable presets to provide alternative versions of core scripts (e.g. `create-new-feature.sh`) for workflow customization. A `strategy: "wrap"` option could allow presets to run custom logic before/after the core script without fully replacing it.
141
+
- **Structural merge strategies** — Parsing Markdown sections for per-section granularity (e.g., "replace only ## Security").
0 commit comments