Copy constitution template to memory if it doesn't exist.
(
project_path: Path, tracker: StepTracker | None = None
)
| 31 | |
| 32 | |
| 33 | def ensure_constitution_from_template( |
| 34 | project_path: Path, tracker: StepTracker | None = None |
| 35 | ) -> None: |
| 36 | """Copy constitution template to memory if it doesn't exist.""" |
| 37 | memory_constitution = project_path / ".specify" / "memory" / "constitution.md" |
| 38 | template_constitution = ( |
| 39 | project_path / ".specify" / "templates" / "constitution-template.md" |
| 40 | ) |
| 41 | |
| 42 | if memory_constitution.exists(): |
| 43 | if tracker: |
| 44 | tracker.add("constitution", "Constitution setup") |
| 45 | tracker.skip("constitution", "existing file preserved") |
| 46 | return |
| 47 | |
| 48 | if not template_constitution.exists(): |
| 49 | if tracker: |
| 50 | tracker.add("constitution", "Constitution setup") |
| 51 | tracker.error("constitution", "template not found") |
| 52 | return |
| 53 | |
| 54 | try: |
| 55 | memory_constitution.parent.mkdir(parents=True, exist_ok=True) |
| 56 | shutil.copy2(template_constitution, memory_constitution) |
| 57 | if tracker: |
| 58 | tracker.add("constitution", "Constitution setup") |
| 59 | tracker.complete("constitution", "copied from template") |
| 60 | else: |
| 61 | console.print("[cyan]Initialized constitution from template[/cyan]") |
| 62 | except Exception as e: |
| 63 | if tracker: |
| 64 | tracker.add("constitution", "Constitution setup") |
| 65 | tracker.error("constitution", str(e)) |
| 66 | else: |
| 67 | console.print( |
| 68 | f"[yellow]Warning: Could not initialize constitution: {e}[/yellow]" |
| 69 | ) |
| 70 | |
| 71 | |
| 72 | def register(app: typer.Typer) -> None: |