Skip to content

Add smart detection to preserve .specify/ when adding agents#1506

Open
DanielHashmi wants to merge 7 commits intogithub:mainfrom
DanielHashmi:feature/smart-detection
Open

Add smart detection to preserve .specify/ when adding agents#1506
DanielHashmi wants to merge 7 commits intogithub:mainfrom
DanielHashmi:feature/smart-detection

Conversation

@DanielHashmi
Copy link

@DanielHashmi DanielHashmi commented Jan 21, 2026

Smart Detection: Preserve User Work When Adding Agents

Problem

When users initialized a project with one agent and later wanted to add another agent, running specify init again would overwrite the .specify/ directory

Solution

Implement smart detection that automatically detects existing .specify/ directory and preserves user's work by default.

How It Works

  1. Detects if .specify/ directory exists with content
  2. Preserves constitution, specs, and plans automatically
  3. Adds only the new agent-specific directory
  4. Requires --force flag to explicitly overwrite

User Experience

specify init . --ai claude
Work on project...
specify init . --ai copilot
✅ Automatically preserves .specify/, adds .github/ directory
Shows: "Existing project detected - preserving your work"

Key Features

✅ Safe by default - Automatically preserves existing work
✅ Intuitive - Users do what feels natural (just run init again)
✅ Clear feedback - Shows what's being preserved or overwritten
✅ Explicit override - Use --force to reinitialize
✅ Backward compatible - Existing single-agent workflow unchanged

Implementation Details

Code Changes (~100 lines)

Added:

  • preserve_specify parameter to download_and_extract_template() function
  • Logic to skip .specify/ directory during extraction when preserve_specify=True
  • Smart detection in init() function to detect existing .specify/ with content
  • Clear user feedback panels for both scenarios
  • Updated --force flag description

Files Modified:

  • src/specify_cli/init.py (~100 lines added/modified)
  • README.md (updated with examples)

Breaking Changes

None. This is a purely additive feature that improves existing behavior.

AI Assistance

This implementation was developed with assistance from Claude Code, which was utilized for both the technical implementation and the creation of this pull request description.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements smart detection to automatically preserve user work in the .specify/ directory when adding additional AI agents to an existing project. The key change is that running specify init in a directory with an existing .specify/ will now preserve it by default, unless the --force flag is used.

Changes:

  • Added preserve_specify parameter to download_and_extract_template() function to skip .specify/ directory during extraction
  • Implemented smart detection in init() function to detect existing .specify/ directories and set preservation behavior
  • Updated --force flag description to reflect new behavior of forcing reinitialize/overwrite
  • Added clear user feedback panels showing whether .specify/ will be preserved or overwritten
  • Updated README with examples showing the new multi-agent workflow

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/specify_cli/init.py Core implementation of smart detection and preserve_specify logic; updated function signatures and user messaging
README.md Added documentation and examples for the new multi-agent workflow with automatic preservation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mnriem
Copy link
Collaborator

mnriem commented Feb 23, 2026

@DanielHashmi Can you address the review comments?

@DanielHashmi
Copy link
Author

@copilot open a new pull request to apply changes based on the comments in this thread

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@DanielHashmi DanielHashmi requested a review from mnriem as a code owner February 28, 2026 14:21
DanielHashmi and others added 5 commits February 28, 2026 19:21
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update the user-facing init prompts to list "Command templates and workflows" and "Utility scripts and automation" as the items that will be overwritten or preserved in .specify/. This replaces prior references to specifications, implementation plans, and task lists to more accurately reflect the repository contents shown to users during reinitialization or agent addition.
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.

3 participants