-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli_setup.py
More file actions
75 lines (64 loc) · 2.52 KB
/
cli_setup.py
File metadata and controls
75 lines (64 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Auto-setup for `engram setup`. No prompts — detects environment and configures automatically."""
import logging
import os
import sys
from engram.cli_config import (
CONFIG_DIR,
PROVIDER_DEFAULTS,
get_default_config,
load_config,
save_config,
)
from engram.cli_mcp import configure_mcp_servers, detect_agents
from engram.utils.factory import _detect_provider
logger = logging.getLogger(__name__)
def run_setup() -> None:
"""Auto-detect environment and configure. No prompts."""
print("=" * 50)
print(" engram setup (auto-detect)")
print("=" * 50)
config = load_config()
# Auto-detect provider
embedder_provider, llm_provider = _detect_provider()
config["provider"] = embedder_provider
config["auto_configured"] = True
if embedder_provider in ("gemini", "openai"):
defaults = PROVIDER_DEFAULTS.get(embedder_provider, {})
env_var = defaults.get("env_var", f"{embedder_provider.upper()}_API_KEY")
key = os.environ.get(env_var, "")
for alt in defaults.get("alt_env_vars", []):
key = key or os.environ.get(alt, "")
if key:
masked = key[:4] + "..." + key[-4:] if len(key) > 8 else "****"
print(f" Provider detected: {embedder_provider}")
print(f" API key found: {env_var}={masked}")
else:
print(f" Provider detected: {embedder_provider}")
print(f" ! No API key found — set {env_var} for full functionality")
elif embedder_provider == "ollama":
print(" Provider detected: ollama (local)")
print(" Make sure Ollama is running: ollama serve")
else:
print(" Provider detected: simple (hash-based embedder)")
print(" No API key required. In-memory vector store for zero-config.")
# Save config
save_config(config)
print(f"\n Config saved to {os.path.join(CONFIG_DIR, 'config.json')}")
# Auto-configure MCP servers
agents = detect_agents()
if agents:
print(f"\n Detected agents: {', '.join(agents)}")
print(" Configuring MCP servers...")
results = configure_mcp_servers(config)
for agent, status in results.items():
print(f" {agent}: {status}")
else:
print("\n No agents detected. MCP will configure when you install one.")
print("\n" + "=" * 50)
print(" Setup complete!")
print()
print(" Try:")
print(' engram add "User prefers dark mode"')
print(' engram search "preferences"')
print(' engram status')
print("=" * 50)