Skip to content

Commit 12340d7

Browse files
Patrick Roebuckclaude
andcommitted
feat: Add update-config, interactive mode, and project detection
Three optional improvements to enhance user experience: 1. New 'memdocs update-config' command - Update MCP configuration without reinitializing - Useful when templates have been improved - Prompts before overwriting (unless --force) - Shows what was updated with clear messaging Usage: memdocs update-config --mcp memdocs update-config --mcp --force 2. Interactive mode for init - Auto-detects TTY environment - Asks user about MCP setup - Shows helpful context about MCP benefits - Falls back to defaults on Ctrl+C - Can be explicitly enabled/disabled Usage: memdocs init # Auto-detects TTY memdocs init --interactive # Force interactive memdocs init --no-interactive # Force non-interactive 3. Enhanced project detection - Detects project language (Python, JavaScript, Go, Rust, Java, Ruby) - Detects version control (.git) - Detects IDEs (VS Code, JetBrains) - Shows detected language during init - Foundation for future IDE-specific setup Detection logic: Python: setup.py, pyproject.toml JavaScript: package.json Go: go.mod Rust: Cargo.toml Java: pom.xml, build.gradle Ruby: Gemfile Changes: - memdocs/cli_modules/commands/update_config_cmd.py (NEW): - Full update-config command implementation - Interactive confirmation prompts - Clear success messaging - memdocs/cli_modules/commands/init_cmd.py: - Added _detect_project_type() function - Interactive mode with --interactive flag - TTY auto-detection - Shows detected project language - Asks about MCP setup in interactive mode - memdocs/cli.py: - Registered update-config command - memdocs/cli_modules/commands/__init__.py: - Exported update-config command Benefits: - Easier to update configuration after MemDocs upgrades - More guided experience for new users (interactive) - Better understanding of project context - Foundation for future IDE-specific features 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 845e4b7 commit 12340d7

File tree

4 files changed

+213
-5
lines changed

4 files changed

+213
-5
lines changed

memdocs/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
review,
2121
serve,
2222
stats,
23+
update_config,
2324
)
2425

2526
# Import classes that tests need to patch (for backward compatibility)
@@ -43,6 +44,7 @@
4344
"serve",
4445
"stats",
4546
"Summarizer",
47+
"update_config",
4648
]
4749

4850

@@ -62,6 +64,7 @@ def main(ctx: click.Context) -> None:
6264
main.add_command(serve)
6365
main.add_command(doctor)
6466
main.add_command(stats)
67+
main.add_command(update_config)
6568
main.add_command(cleanup)
6669

6770

memdocs/cli_modules/commands/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,16 @@
1010
from memdocs.cli_modules.commands.review_cmd import review
1111
from memdocs.cli_modules.commands.serve_cmd import serve
1212
from memdocs.cli_modules.commands.stats_cmd import stats
13+
from memdocs.cli_modules.commands.update_config_cmd import update_config
1314

14-
__all__ = ["cleanup", "doctor", "export", "init", "query", "review", "serve", "stats"]
15+
__all__ = [
16+
"cleanup",
17+
"doctor",
18+
"export",
19+
"init",
20+
"query",
21+
"review",
22+
"serve",
23+
"stats",
24+
"update_config",
25+
]

memdocs/cli_modules/commands/init_cmd.py

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,55 @@
66
import os
77
import sys
88
from pathlib import Path
9+
from typing import Optional
910

1011
import click
1112

1213
from memdocs import cli_output as out
1314
from memdocs.security import PathValidator
1415

1516

17+
def _detect_project_type(cwd: Path) -> dict[str, any]:
18+
"""Detect project type and return metadata."""
19+
project_info: dict[str, any] = {
20+
"type": "unknown",
21+
"language": None,
22+
"source_dir": None,
23+
"has_git": False,
24+
"has_vscode": False,
25+
"has_jetbrains": False,
26+
}
27+
28+
# Check version control
29+
project_info["has_git"] = (cwd / ".git").exists()
30+
31+
# Check IDEs
32+
project_info["has_vscode"] = (cwd / ".vscode").exists()
33+
project_info["has_jetbrains"] = (cwd / ".idea").exists()
34+
35+
# Detect language and type
36+
if (cwd / "setup.py").exists() or (cwd / "pyproject.toml").exists():
37+
project_info["type"] = "python"
38+
project_info["language"] = "Python"
39+
elif (cwd / "package.json").exists():
40+
project_info["type"] = "javascript"
41+
project_info["language"] = "JavaScript/TypeScript"
42+
elif (cwd / "go.mod").exists():
43+
project_info["type"] = "go"
44+
project_info["language"] = "Go"
45+
elif (cwd / "Cargo.toml").exists():
46+
project_info["type"] = "rust"
47+
project_info["language"] = "Rust"
48+
elif (cwd / "pom.xml").exists() or (cwd / "build.gradle").exists():
49+
project_info["type"] = "java"
50+
project_info["language"] = "Java"
51+
elif (cwd / "Gemfile").exists():
52+
project_info["type"] = "ruby"
53+
project_info["language"] = "Ruby"
54+
55+
return project_info
56+
57+
1658
def _detect_source_directory(cwd: Path) -> str:
1759
"""Detect the main source directory for the project."""
1860
common_dirs = ["src", "lib", "app", "pkg", cwd.name]
@@ -135,16 +177,23 @@ def _setup_mcp_infrastructure(cwd: Path) -> None:
135177
is_flag=True,
136178
help="Skip VS Code MCP auto-start setup",
137179
)
138-
def init(force: bool, no_mcp: bool) -> None:
180+
@click.option(
181+
"--interactive/--no-interactive",
182+
default=None,
183+
help="Interactive mode (auto-detects TTY if not specified)",
184+
)
185+
def init(force: bool, no_mcp: bool, interactive: Optional[bool]) -> None:
139186
"""Initialize MemDocs in the current project.
140187
141188
MCP auto-start is enabled by default for VS Code/Cursor integration.
189+
Interactive mode will ask questions if TTY is available.
142190
143191
Examples:
144192
145-
memdocs init # With MCP (default)
146-
memdocs init --no-mcp # Skip MCP setup
147-
memdocs init --force # Reinitialize
193+
memdocs init # With MCP (default)
194+
memdocs init --no-mcp # Skip MCP setup
195+
memdocs init --force # Reinitialize
196+
memdocs init --interactive # Ask questions
148197
"""
149198
try:
150199
out.print_header("MemDocs Initialization")
@@ -155,6 +204,39 @@ def init(force: bool, no_mcp: bool) -> None:
155204
out.error("Current directory is not writable")
156205
sys.exit(1)
157206

207+
# Detect project info
208+
project_info = _detect_project_type(cwd)
209+
210+
# Show project detection
211+
if project_info["language"]:
212+
out.info(f"Detected: {project_info['language']} project")
213+
214+
# Auto-detect interactive mode based on TTY
215+
if interactive is None:
216+
interactive = sys.stdin.isatty() and sys.stdout.isatty()
217+
218+
# Interactive prompts (only if not already set via flags)
219+
if interactive and not no_mcp:
220+
out.console.print()
221+
out.info("[bold]MCP Integration Setup[/bold]")
222+
out.console.print(
223+
"MCP enables instant AI context in VS Code/Cursor.\n"
224+
"The server auto-starts when you open the project."
225+
)
226+
227+
try:
228+
# Ask about MCP unless --no-mcp was explicitly passed
229+
setup_mcp = click.confirm(
230+
"\nSet up MCP auto-start for VS Code/Cursor?",
231+
default=True,
232+
)
233+
if not setup_mcp:
234+
no_mcp = True
235+
except click.Abort:
236+
out.console.print()
237+
out.info("Using default: MCP enabled")
238+
no_mcp = False
239+
158240
config_path = Path(".memdocs.yml")
159241
docs_dir = Path(".memdocs/docs")
160242
memory_dir = Path(".memdocs/memory")
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
"""
2+
Update-config command - Update MCP configuration without reinitializing.
3+
"""
4+
5+
import sys
6+
from pathlib import Path
7+
8+
import click
9+
10+
from memdocs import cli_output as out
11+
from memdocs.cli_modules.commands.init_cmd import _setup_mcp_infrastructure
12+
13+
14+
@click.command()
15+
@click.option(
16+
"--mcp",
17+
is_flag=True,
18+
help="Update MCP integration (VS Code tasks/settings)",
19+
)
20+
@click.option(
21+
"--force",
22+
is_flag=True,
23+
help="Overwrite existing configuration files",
24+
)
25+
def update_config(mcp: bool, force: bool) -> None:
26+
"""Update MemDocs configuration files.
27+
28+
Useful for updating VS Code tasks, settings, or MCP configuration
29+
when MemDocs templates have been improved or you want to refresh
30+
your setup without reinitializing.
31+
32+
Examples:
33+
34+
memdocs update-config --mcp # Update MCP setup
35+
memdocs update-config --mcp --force # Overwrite existing
36+
"""
37+
try:
38+
out.print_header("MemDocs Configuration Update")
39+
40+
cwd = Path.cwd()
41+
42+
# Check if MemDocs is initialized
43+
config_path = Path(".memdocs.yml")
44+
if not config_path.exists():
45+
out.error("MemDocs not initialized in this directory")
46+
out.info("Run: [cyan]memdocs init[/cyan]")
47+
sys.exit(1)
48+
49+
if not mcp:
50+
out.warning("No update target specified")
51+
out.info("Use [cyan]--mcp[/cyan] to update MCP integration")
52+
out.info("Example: [cyan]memdocs update-config --mcp[/cyan]")
53+
sys.exit(1)
54+
55+
# Update MCP configuration
56+
if mcp:
57+
vscode_dir = cwd / ".vscode"
58+
tasks_file = vscode_dir / "tasks.json"
59+
settings_file = vscode_dir / "settings.json"
60+
61+
# Check if files exist and warn if not forcing
62+
if not force:
63+
if tasks_file.exists() or settings_file.exists():
64+
out.warning("MCP configuration files already exist")
65+
out.info("Use [cyan]--force[/cyan] to overwrite")
66+
out.console.print()
67+
68+
if tasks_file.exists():
69+
out.info(f"Existing: [cyan]{tasks_file}[/cyan]")
70+
if settings_file.exists():
71+
out.info(f"Existing: [cyan]{settings_file}[/cyan]")
72+
73+
try:
74+
response = click.confirm("Overwrite existing files?", default=False)
75+
if not response:
76+
out.info("Update cancelled")
77+
sys.exit(0)
78+
except click.Abort:
79+
out.info("Update cancelled")
80+
sys.exit(0)
81+
82+
# Update MCP infrastructure
83+
out.console.print()
84+
_setup_mcp_infrastructure(cwd)
85+
86+
# Show success message
87+
out.console.print()
88+
out.print_rule("Update Complete", style="green")
89+
out.console.print()
90+
91+
out.panel(
92+
"""[bold green]✓ MCP configuration updated![/bold green]
93+
94+
Your VS Code/Cursor setup has been refreshed with the latest
95+
MemDocs MCP integration templates.
96+
97+
[bold]What's updated:[/bold]
98+
• .vscode/tasks.json - MCP server auto-start task
99+
• .vscode/settings.json - Auto-task execution settings
100+
101+
[bold]Next steps:[/bold]
102+
• Reload VS Code/Cursor: [cyan]Cmd+Shift+P → "Reload Window"[/cyan]
103+
• Verify setup: [cyan]memdocs doctor[/cyan]
104+
• Start server: [cyan]memdocs serve --mcp[/cyan]""",
105+
title="All Set!",
106+
style="green",
107+
)
108+
109+
except Exception as e:
110+
out.console.print()
111+
out.error(f"Configuration update failed: {e}")
112+
sys.exit(1)

0 commit comments

Comments
 (0)