-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathwell_known_clients.py
More file actions
375 lines (346 loc) · 11.9 KB
/
well_known_clients.py
File metadata and controls
375 lines (346 loc) · 11.9 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import getpass
import logging
import os
import platform
import subprocess
import sys
from pathlib import Path
from agent_scan.models import CandidateClient
# Set up logger for this module
logger = logging.getLogger(__name__)
MACOS_WELL_KNOWN_CLIENTS: list[CandidateClient] = [
CandidateClient(
name="windsurf",
client_exists_paths=["~/.codeium"],
mcp_config_paths=["~/.codeium/windsurf/mcp_config.json"],
skills_dir_paths=["~/.codeium/windsurf/skills"],
),
CandidateClient(
name="cursor",
client_exists_paths=["~/.cursor"],
mcp_config_paths=["~/.cursor/mcp.json"],
skills_dir_paths=["~/.cursor/skills"],
),
CandidateClient(
name="vscode",
client_exists_paths=["~/.vscode"],
mcp_config_paths=[
"~/Library/Application Support/Code/User/settings.json",
"~/.vscode/mcp.json",
"~/Library/Application Support/Code/User/mcp.json",
],
skills_dir_paths=["~/.copilot/skills"],
),
CandidateClient(
name="claude",
client_exists_paths=["~/Library/Application Support/Claude"],
mcp_config_paths=["~/Library/Application Support/Claude/claude_desktop_config.json"],
skills_dir_paths=[],
),
CandidateClient(
name="claude code",
client_exists_paths=["~/.claude"],
mcp_config_paths=["~/.claude.json"],
skills_dir_paths=["~/.claude/skills"],
),
CandidateClient(
name="gemini cli",
client_exists_paths=["~/.gemini"],
mcp_config_paths=["~/.gemini/settings.json"],
skills_dir_paths=["~/.gemini/skills"],
),
CandidateClient(
name="openclaw",
client_exists_paths=["~/.clawdbot", "~/.openclaw"],
mcp_config_paths=[],
skills_dir_paths=[
"~/.clawdbot/skills",
"~/.openclaw/skills",
"~/.openclaw/workspace/skills",
".openclaw/skills",
],
),
CandidateClient(
name="amp",
client_exists_paths=["~/.config/agents", ".amp"],
mcp_config_paths=[],
skills_dir_paths=["~/.config/agents/skills", ".amp/skills"],
),
CandidateClient(
name="kiro",
client_exists_paths=["~/.kiro"],
mcp_config_paths=["~/.kiro/settings/mcp.json"],
skills_dir_paths=[],
),
CandidateClient(
name="opencode",
client_exists_paths=["~/.config/opencode"],
mcp_config_paths=[],
skills_dir_paths=[],
),
CandidateClient(
name="antigravity",
client_exists_paths=["~/.gemini/antigravity"],
mcp_config_paths=["~/.gemini/antigravity/mcp_config.json"],
skills_dir_paths=[],
),
CandidateClient(
name="codex",
client_exists_paths=["~/.codex"],
mcp_config_paths=[],
skills_dir_paths=["~/.codex/skills"],
),
CandidateClient(
name="amazon_q",
client_exists_paths=["~/.aws/amazonq"],
mcp_config_paths=[
"~/.aws/amazonq/agents/default.json",
"~/.aws/amazonq/agents/mcp.json",
"~/.aws/amazonq/mcp.json",
],
skills_dir_paths=[],
),
]
LINUX_WELL_KNOWN_CLIENTS: list[CandidateClient] = [
CandidateClient(
name="windsurf",
client_exists_paths=["~/.codeium"],
mcp_config_paths=["~/.codeium/windsurf/mcp_config.json"],
skills_dir_paths=["~/.codeium/windsurf/skills"],
),
CandidateClient(
name="cursor",
client_exists_paths=["~/.cursor"],
mcp_config_paths=["~/.cursor/mcp.json"],
skills_dir_paths=["~/.cursor/skills"],
),
CandidateClient(
name="vscode",
client_exists_paths=["~/.vscode", "~/.config/Code"],
mcp_config_paths=[
"~/.config/Code/User/settings.json",
"~/.vscode/mcp.json",
"~/.config/Code/User/mcp.json",
],
skills_dir_paths=["~/.copilot/skills"],
),
CandidateClient(
name="claude code",
client_exists_paths=["~/.claude"],
mcp_config_paths=["~/.claude.json"],
skills_dir_paths=["~/.claude/skills"],
),
CandidateClient(
name="gemini cli",
client_exists_paths=["~/.gemini"],
mcp_config_paths=["~/.gemini/settings.json"],
skills_dir_paths=["~/.gemini/skills"],
),
CandidateClient(
name="openclaw",
client_exists_paths=["~/.clawdbot", "~/.openclaw"],
mcp_config_paths=[],
skills_dir_paths=[
"~/.clawdbot/skills",
"~/.openclaw/skills",
"~/.openclaw/workspace/skills",
".openclaw/skills",
],
),
CandidateClient(
name="amp",
client_exists_paths=["~/.config/agents", ".amp"],
mcp_config_paths=[],
skills_dir_paths=["~/.config/agents/skills", ".amp/skills"],
),
CandidateClient(
name="kiro",
client_exists_paths=["~/.kiro"],
mcp_config_paths=["~/.kiro/settings/mcp.json"],
skills_dir_paths=[],
),
CandidateClient(
name="opencode",
client_exists_paths=["~/.config/opencode"],
mcp_config_paths=[],
skills_dir_paths=[],
),
CandidateClient(
name="antigravity",
client_exists_paths=["~/.gemini/antigravity"],
mcp_config_paths=["~/.gemini/antigravity/mcp_config.json"],
skills_dir_paths=[],
),
CandidateClient(
name="codex",
client_exists_paths=["~/.codex"],
mcp_config_paths=[],
skills_dir_paths=["~/.codex/skills"],
),
CandidateClient(
name="amazon_q",
client_exists_paths=["~/.aws/amazonq"],
mcp_config_paths=[
"~/.aws/amazonq/agents/default.json",
"~/.aws/amazonq/agents/mcp.json",
"~/.aws/amazonq/mcp.json",
],
skills_dir_paths=[],
),
]
WINDOWS_WELL_KNOWN_CLIENTS: list[CandidateClient] = [
CandidateClient(
name="windsurf",
client_exists_paths=["~/.codeium"],
mcp_config_paths=["~/.codeium/windsurf/mcp_config.json"],
skills_dir_paths=["~/.codeium/windsurf/skills"],
),
CandidateClient(
name="cursor",
client_exists_paths=["~/.cursor"],
mcp_config_paths=["~/.cursor/mcp.json"],
skills_dir_paths=["~/.cursor/skills"],
),
CandidateClient(
name="vscode",
client_exists_paths=["~/.vscode", "~/AppData/Roaming/Code"],
mcp_config_paths=[
"~/AppData/Roaming/Code/User/settings.json",
"~/.vscode/mcp.json",
"~/AppData/Roaming/Code/User/mcp.json",
],
skills_dir_paths=["~/.copilot/skills"],
),
CandidateClient(
name="claude",
client_exists_paths=["~/AppData/Roaming/Claude"],
mcp_config_paths=["~/AppData/Roaming/Claude/claude_desktop_config.json"],
skills_dir_paths=[],
),
CandidateClient(
name="claude code",
client_exists_paths=["~/.claude"],
mcp_config_paths=["~/.claude.json"],
skills_dir_paths=["~/.claude/skills"],
),
CandidateClient(
name="gemini cli",
client_exists_paths=["~/.gemini"],
mcp_config_paths=["~/.gemini/settings.json"],
skills_dir_paths=["~/.gemini/skills"],
),
CandidateClient(
name="openclaw",
client_exists_paths=["~/.clawdbot", "~/.openclaw"],
mcp_config_paths=[],
skills_dir_paths=[
"~/.clawdbot/skills",
"~/.openclaw/skills",
"~/.openclaw/workspace/skills",
".openclaw/skills",
],
),
CandidateClient(
name="amp",
client_exists_paths=["~/.config/agents", ".amp"],
mcp_config_paths=[],
skills_dir_paths=["~/.config/agents/skills", ".amp/skills"],
),
CandidateClient(
name="kiro",
client_exists_paths=["~/.kiro"],
mcp_config_paths=["~/.kiro/settings/mcp.json"],
skills_dir_paths=[],
),
CandidateClient(
name="opencode",
client_exists_paths=["~/.config/opencode"],
mcp_config_paths=[],
skills_dir_paths=[],
),
CandidateClient(
name="antigravity",
client_exists_paths=["~/.gemini/antigravity"],
mcp_config_paths=["~/.gemini/antigravity/mcp_config.json"],
skills_dir_paths=[],
),
]
def get_well_known_clients() -> list[CandidateClient]:
if sys.platform == "linux" or sys.platform == "linux2":
return LINUX_WELL_KNOWN_CLIENTS
elif sys.platform == "darwin":
return MACOS_WELL_KNOWN_CLIENTS
elif sys.platform == "win32":
return WINDOWS_WELL_KNOWN_CLIENTS
else:
return []
def get_client_from_path(path: str) -> str | None:
"""
Returns the client name from a path.
Args:
path (str): The path to get the client from.
Returns:
str: The client name or None if it cannot be guessed from the path.
"""
path = os.path.realpath(os.path.expanduser(path))
for client in get_well_known_clients():
real_paths = [os.path.realpath(os.path.expanduser(p)) for p in client.mcp_config_paths]
if path in real_paths:
return client.name
return None
def get_readable_home_directories(all_users: bool = False) -> list[tuple[Path, str]]:
"""
Retrieve a list of all human user home directories on the machine
that the current process actually has permission to read and traverse.
Logs the access status for each found directory.
Returns a list of (home_directory_path, username) tuples.
"""
if not all_users:
return [(Path.home(), getpass.getuser())]
system = platform.system()
home_dirs: dict[Path, str] = {}
if system in ("Linux", "Darwin"):
import pwd
# macOS usually starts human UIDs at 500, Linux at 1000
uid_threshold = 500 if system == "Darwin" else 1000
for user in pwd.getpwall():
if user.pw_uid >= uid_threshold and user.pw_name != "nobody":
dir_path = Path(user.pw_dir)
if dir_path.is_dir():
# Check for Read (R_OK) and Traverse/Execute (X_OK) permissions
if os.access(dir_path, os.R_OK | os.X_OK):
logger.info(f"Found user '{user.pw_name}' at {dir_path} -> Access: GRANTED")
home_dirs[dir_path] = user.pw_name
else:
logger.info(f"Found user '{user.pw_name}' at {dir_path} -> Access: DENIED")
elif system == "Windows":
try:
cmd = [
"powershell",
"-NoProfile",
"-Command",
"Get-CimInstance Win32_UserProfile | Where-Object { $_.Special -eq $false } | Select-Object -ExpandProperty LocalPath",
]
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
for line in result.stdout.splitlines():
clean_path = line.strip()
if clean_path:
dir_path = Path(clean_path)
if dir_path.is_dir():
# Windows primarily relies on R_OK for basic directory readability
if os.access(dir_path, os.R_OK):
username = dir_path.name
logger.info(f"Found profile at {dir_path} -> Access: GRANTED")
home_dirs[dir_path] = username
else:
logger.info(f"Found profile at {dir_path} -> Access: DENIED")
except (subprocess.CalledProcessError, FileNotFoundError) as e:
logger.error(f"Failed to fetch Windows profiles: {e}")
else:
raise NotImplementedError(f"Unsupported OS: {system}")
return list(home_dirs.items())
def expand_path(path: Path, home_directory: Path | None) -> Path:
if home_directory is None or not str(path).startswith("~"):
return path
suffix = path.parts[1:]
return home_directory / Path(*suffix)