-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathconfig.py
More file actions
94 lines (66 loc) · 2.23 KB
/
config.py
File metadata and controls
94 lines (66 loc) · 2.23 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Configuration management for APM."""
import json
import os
from typing import Optional
CONFIG_DIR = os.path.expanduser("~/.apm")
CONFIG_FILE = os.path.join(CONFIG_DIR, "config.json")
_config_cache: Optional[dict] = None
def ensure_config_exists():
"""Ensure the configuration directory and file exist."""
if not os.path.exists(CONFIG_DIR):
os.makedirs(CONFIG_DIR)
if not os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
json.dump({"default_client": "vscode"}, f)
def get_config():
"""Get the current configuration.
Results are cached for the lifetime of the process.
Returns:
dict: Current configuration.
"""
global _config_cache
if _config_cache is not None:
return _config_cache
ensure_config_exists()
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
_config_cache = json.load(f)
return _config_cache
def _invalidate_config_cache():
"""Invalidate the config cache (called after writes)."""
global _config_cache
_config_cache = None
def update_config(updates):
"""Update the configuration with new values.
Args:
updates (dict): Dictionary of configuration values to update.
"""
_invalidate_config_cache()
config = get_config()
config.update(updates)
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
json.dump(config, f, indent=2)
_invalidate_config_cache()
def get_default_client():
"""Get the default MCP client.
Returns:
str: Default MCP client type.
"""
return get_config().get("default_client", "vscode")
def set_default_client(client_type):
"""Set the default MCP client.
Args:
client_type (str): Type of client to set as default.
"""
update_config({"default_client": client_type})
def get_auto_integrate() -> bool:
"""Get the auto-integrate setting.
Returns:
bool: Whether auto-integration is enabled (default: True).
"""
return get_config().get("auto_integrate", True)
def set_auto_integrate(enabled: bool) -> None:
"""Set the auto-integrate setting.
Args:
enabled: Whether to enable auto-integration.
"""
update_config({"auto_integrate": enabled})