Skip to content

feat(presets): Composition strategies (prepend, append, wrap) for templates, commands, and scripts#2133

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-composition-strategies-to-presets
Draft

feat(presets): Composition strategies (prepend, append, wrap) for templates, commands, and scripts#2133
Copilot wants to merge 3 commits intomainfrom
copilot/add-composition-strategies-to-presets

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

Presets can now augment lower-priority templates instead of only fully replacing them. A new optional strategy field in preset.yml controls how content is composed across the priority stack.

provides:
  templates:
    - type: "template"
      name: "spec-template"
      file: "templates/spec-addendum.md"
      strategy: "append"  # new field; default: "replace"
Strategy Behavior Templates Commands Scripts
replace Full replacement (existing default)
prepend Insert before lower-priority content
append Insert after lower-priority content
wrap {CORE_TEMPLATE} / $CORE_SCRIPT placeholder substitution

Multiple composing presets chain recursively (e.g. security prepend + compliance append → header + core + footer).

Python resolver (src/specify_cli/presets.py)

  • VALID_PRESET_STRATEGIES / VALID_SCRIPT_STRATEGIES constants; validation in _validate() rejects prepend/append for scripts
  • PresetResolver._collect_all_layers() — walks full priority stack, reads strategy from each preset manifest
  • PresetResolver.resolve_content() — bottom-up composition across layers
  • PresetManager._register_commands() — composes command content before writing to agent directories

Shell resolvers

  • resolve_template_content() in scripts/bash/common.sh
  • Resolve-TemplateContent in scripts/powershell/common.ps1

CLI

  • specify preset resolve shows composition chain when non-replace strategies are present

Documentation

  • presets/scaffold/preset.yml — strategy field docs and composition examples
  • presets/README.md — composition strategies section; moved implemented items out of future considerations
  • presets/ARCHITECTURE.md — strategy table and content resolution function references

Tests

  • 26 new tests: strategy validation (valid/invalid/script restrictions), resolve_content() for each strategy × type, multi-preset chaining, override precedence, separator behavior, _collect_all_layers() ordering

Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 20:55
… templates, commands, and scripts

- Add strategy field validation in PresetManifest._validate()
- Add VALID_PRESET_STRATEGIES and VALID_SCRIPT_STRATEGIES constants
- Add PresetResolver.resolve_content() for composed content resolution
- Add PresetResolver._collect_all_layers() for full priority stack
- Update _register_commands() to compose before writing
- Update CLI preset resolve command to show composition chain
- Add resolve_template_content() to bash common.sh
- Add Resolve-TemplateContent to PowerShell common.ps1
- Update scaffold preset.yml with strategy documentation
- Update presets/README.md and ARCHITECTURE.md
- Add 26 unit tests covering validation, composition, and chaining

Agent-Logs-Url: https://github.com/github/spec-kit/sessions/c285c51b-f00b-480a-9eb2-ae70e3cbcb72

Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 21:05
and tmpl.get("type") == template_type):
strategy = tmpl.get("strategy", "replace")
break
except PresetValidationError:
…, improve default strategy test

Agent-Logs-Url: https://github.com/github/spec-kit/sessions/c285c51b-f00b-480a-9eb2-ae70e3cbcb72

Co-authored-by: mnriem <15701806+mnriem@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 21:08
Copilot AI changed the title [WIP] Add composition strategies for templates, commands, and scripts feat(presets): Composition strategies (prepend, append, wrap) for templates, commands, and scripts Apr 8, 2026
Copilot AI requested a review from mnriem April 8, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(presets): Composition strategies (prepend, append, wrap) for templates, commands, and scripts

2 participants