Coverage for mcp_bridge/tools/init.py: 0%

1"""

2 Repository bootstrap logic for Stravinsky.

3"""

4

5 import logging

6 from pathlib import Path

7

8 from .templates import CLAUDE_MD_TEMPLATE, SLASH_COMMANDS

9

10 logger = logging.getLogger(__name__)

11

12 def bootstrap_repo(project_path: str | Path | None = None) -> str:

13 """

14 Bootstrap a repository for Stravinsky MCP usage.

15

16 Creates:

17 - .claude/commands/ (with standard slash commands)

18 - Appends/Creates CLAUDE.md

19 """

20 root = Path(project_path or Path.cwd())

21

22 # 1. Setup Slash Commands

23 commands_dir = root / ".claude" / "commands"

24 commands_dir.mkdir(parents=True, exist_ok=True)

25

26 commands_created = 0

27 for filename, content in SLASH_COMMANDS.items():

28 cmd_file = commands_dir / filename

29 if not cmd_file.exists():

30 cmd_file.write_text(content)

31 commands_created += 1

32

33 # 2. Setup CLAUDE.md

34 claude_md = root / "CLAUDE.md"

35 if not claude_md.exists():

36 claude_md.write_text("# Project Notes\n\n" + CLAUDE_MD_TEMPLATE)

37 claude_msg = "Created CLAUDE.md"

38 else:

39 content = claude_md.read_text()

40 if "Stravinsky MCP" not in content:

41 with open(claude_md, "a") as f:

42 f.write("\n\n" + CLAUDE_MD_TEMPLATE)

43 claude_msg = "Updated CLAUDE.md with Stravinsky instructions"

44 else:

45 claude_msg = "CLAUDE.md already configured"

46

47 return (

48 f"✅ Repository Initialized!\n"

49 f"- {claude_msg}\n"

50 f"- Installed {commands_created} new slash commands to .claude/commands/stra/"

51 )