feat: add template version management #63

Merged
Charon merged 1 commit from feat/template-version-management into main 2026-02-24 13:25:33 +00:00
Member

Summary

  • Add plan_template_versions table that snapshots YAML template content when a plan is created, so future edits to template files never affect existing plans
  • Plans now reference their template version via template_version_id (nullable FK), with version number also stored in metadata
  • Deduplication: identical template content reuses the same version row (matched by SHA-256 hash), so unchanged templates do not accumulate rows
  • New PlanTemplateVersion model with findOrCreateFromTemplate() and historyFor() class methods
  • PlanTemplateService gains getVersionHistory(slug) and getVersion(slug, version) to query stored versions
  • 25 new tests in TemplateVersionManagementTest

Changes

File Change
Migrations/0001_01_01_000006_add_template_versions.php New migration
Models/PlanTemplateVersion.php New model
Models/AgentPlan.php Add template_version_id fillable + relationship
Services/PlanTemplateService.php Snapshot version on create; add history/retrieval methods
tests/Feature/TemplateVersionManagementTest.php New test suite
TODO.md Mark FEAT-003 complete

Test plan

  • TemplateVersionManagementTest -- all 25 cases pass
  • Existing PlanTemplateServiceTest -- no regressions

Closes #35

Generated with Claude Code

## Summary - Add `plan_template_versions` table that snapshots YAML template content when a plan is created, so future edits to template files never affect existing plans - Plans now reference their template version via `template_version_id` (nullable FK), with version number also stored in `metadata` - Deduplication: identical template content reuses the same version row (matched by SHA-256 hash), so unchanged templates do not accumulate rows - New `PlanTemplateVersion` model with `findOrCreateFromTemplate()` and `historyFor()` class methods - `PlanTemplateService` gains `getVersionHistory(slug)` and `getVersion(slug, version)` to query stored versions - 25 new tests in `TemplateVersionManagementTest` ## Changes | File | Change | |------|--------| | `Migrations/0001_01_01_000006_add_template_versions.php` | New migration | | `Models/PlanTemplateVersion.php` | New model | | `Models/AgentPlan.php` | Add `template_version_id` fillable + relationship | | `Services/PlanTemplateService.php` | Snapshot version on create; add history/retrieval methods | | `tests/Feature/TemplateVersionManagementTest.php` | New test suite | | `TODO.md` | Mark FEAT-003 complete | ## Test plan - [ ] `TemplateVersionManagementTest` -- all 25 cases pass - [ ] Existing `PlanTemplateServiceTest` -- no regressions Closes #35 Generated with Claude Code
Clotho added 1 commit 2026-02-23 15:34:29 +00:00
feat: add template version management (#35)
Some checks failed
CI / PHP 8.3 (pull_request) Failing after 3s
CI / PHP 8.4 (pull_request) Failing after 3s
474f96ee5f
Snapshots YAML template content in a new `plan_template_versions` table
whenever a plan is created from a template. Plans reference their version
via `template_version_id` so existing plans are unaffected by future
template file edits.

Key changes:
- Migration 0006: create `plan_template_versions` table (slug, version,
  name, content JSON, content_hash SHA-256); add nullable FK
  `template_version_id` to `agent_plans`
- Model `PlanTemplateVersion`: `findOrCreateFromTemplate()` deduplicates
  identical content by hash; `historyFor()` returns versions newest-first
- `AgentPlan`: add `template_version_id` fillable and `templateVersion()`
  relationship
- `PlanTemplateService::createPlan()`: snapshot raw template before
  variable substitution; store version id and version number in metadata;
  add `getVersionHistory()` and `getVersion()` public methods
- Tests: `TemplateVersionManagementTest` covering model behaviour, plan
  creation snapshotting, deduplication, history ordering, and service
  methods

Closes #35

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Charon force-pushed feat/template-version-management from 474f96ee5f to 0e7b617551 2026-02-24 13:25:23 +00:00 Compare
Charon merged commit 80c778cb08 into main 2026-02-24 13:25:33 +00:00
Charon deleted branch feat/template-version-management 2026-02-24 13:25:33 +00:00
Sign in to join this conversation.
No description provided.