feat: Add --keep-memory flag to preserve constitution when switching AI agents#1480
feat: Add --keep-memory flag to preserve constitution when switching AI agents#1480nShieldSolo wants to merge 1 commit intogithub:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a --keep-memory flag to the specify init command to address the known issue where switching AI agents overwrites customized memory/constitution.md files. The flag allows users to preserve their existing constitution when re-initializing a project with a different AI assistant.
Changes:
- Added
--keep-memoryflag parameter to theinitcommand - Modified
download_and_extract_templatefunction to accept apreserve_constitutionparameter - Implemented logic to skip overwriting
constitution.mdwhen the flag is active and the file exists - Updated version from 0.0.22 to 0.0.23 and documented the change in CHANGELOG.md
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/specify_cli/init.py | Added --keep-memory flag to init command, added preserve_constitution parameter to download_and_extract_template, and implemented constitution preservation logic |
| pyproject.toml | Bumped version from 0.0.22 to 0.0.23 |
| CHANGELOG.md | Added changelog entry for version 0.0.23 documenting the new --keep-memory flag |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Skip constitution.md if preserve_constitution is True and file exists | ||
| if preserve_constitution and dest_file.exists() and rel_path == Path("constitution.md") and item.name == "memory": |
There was a problem hiding this comment.
The constitution preservation logic is incorrect. When iterating through the extracted template, item represents the .specify directory (not memory), and rel_path would be memory/constitution.md (not just constitution.md). The condition item.name == "memory" will never be true, so the --keep-memory flag won't work. The correct check should be item.name == ".specify" and rel_path == Path("memory/constitution.md") or rel_path == Path("memory") / "constitution.md".
| # Skip constitution.md if preserve_constitution is True and file exists | |
| if preserve_constitution and dest_file.exists() and rel_path == Path("constitution.md") and item.name == "memory": | |
| # Skip memory/constitution.md if preserve_constitution is True and file exists | |
| if preserve_constitution and dest_file.exists() and rel_path == Path("memory") / "constitution.md": |
Summary
Added
--keep-memoryflag tospecify initcommand that preservesmemory/constitution.mdwhen switching between AI agents on an existing project.Problem
When users switch AI assistants (e.g., from Claude to Gemini) using
specify init . --ai gemini, the existingmemory/constitution.mdfile (which may contain customized project-specific constitution) gets overwritten with the template version.Solution
Added
--keep-memoryflag that skips overwritingmemory/constitution.mdif it already exists:specify init . --ai gemini --keep-memory