fix: preserve constitution.md during reinitialization#1553
fix: preserve constitution.md during reinitialization#1553jin-joung wants to merge 1 commit intogithub:mainfrom
Conversation
Moves constitution template from memory/ to templates/ to prevent overwrites when spec-kit is reinitialized with a different AI agent. Changes: - Move memory/constitution.md to templates/constitution-template.md - Update CLI to copy template to memory/ only on first initialization - Update constitution command to reference correct paths with .specify/ prefix - Preserve existing constitution.md when reinitializing project The CLI now checks if .specify/memory/constitution.md exists: - If it exists: preserve it (no overwrite) - If it doesn't exist: copy from .specify/templates/constitution-template.md This allows users to customize their constitution without losing changes when adding support for additional AI agents or reinitializing. Fixes github#1541 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes issue #1541 by relocating the constitution template from memory/ to templates/ to prevent user customizations from being overwritten during project reinitialization. The solution introduces a conditional copy mechanism that only initializes the constitution from the template on first setup.
Changes:
- New constitution template file added in
templates/directory with placeholder tokens for project-specific values - CLI initialization enhanced with
ensure_constitution_from_template()function that preserves existing constitutions - Command documentation updated to reflect the new
.specify/memory/constitution.mdpath convention
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| templates/constitution-template.md | New template file with placeholder tokens for project name, principles, sections, and governance rules |
| templates/commands/constitution.md | Updated all constitution path references to use .specify/ prefix for consistency |
| src/specify_cli/init.py | Added constitution setup function with preservation logic and integrated it into the init workflow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tracker.add("constitution", "Constitution setup") | ||
| tracker.skip("constitution", "existing file preserved") |
There was a problem hiding this comment.
The tracker.add() calls are redundant here since the "constitution" step is already added to the tracker before this function is called (line 1146). The function should just call tracker.skip() directly without the preceding tracker.add() call, similar to how other tracker methods are used throughout the codebase (e.g., lines 1181, 1183). This same issue exists on lines 960, 969, and 975.
Summary
Fixes #1541 by moving the constitution template from
memory/totemplates/to prevent overwrites when spec-kit is reinitialized with a different AI agent.Changes
memory/constitution.md→templates/constitution-template.mdensure_constitution_from_template()function that copies the template to memory only on first initialization.specify/prefix for clarity.specify/memory/constitution.mdexists and preserves itBehavior
The CLI now handles constitution initialization as follows:
constitution-template.mdfrom templates to memoryconstitution.mdin memory (no overwrite)This allows users to customize their constitution without losing changes when adding support for additional AI agents or reinitializing the project.
Testing
Note: Full end-to-end testing on Linux/CI will verify the complete workflow, as there's a pre-existing macOS-specific issue with the package creation script's use of
cp --parents.AI Assistance
This PR was implemented with assistance from Claude Sonnet 4.5 (Claude Code).