win-dev-doctor 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- win_dev_doctor/__init__.py +3 -0
- win_dev_doctor/__main__.py +6 -0
- win_dev_doctor/checks/__init__.py +5 -0
- win_dev_doctor/checks/caches.py +149 -0
- win_dev_doctor/checks/defender.py +133 -0
- win_dev_doctor/checks/dev_tools.py +88 -0
- win_dev_doctor/checks/env_vars.py +75 -0
- win_dev_doctor/checks/git_config.py +85 -0
- win_dev_doctor/checks/long_paths.py +61 -0
- win_dev_doctor/checks/path_health.py +120 -0
- win_dev_doctor/checks/ports.py +182 -0
- win_dev_doctor/checks/symlinks.py +69 -0
- win_dev_doctor/checks/wsl.py +71 -0
- win_dev_doctor/cli.py +435 -0
- win_dev_doctor/mcp_server.py +293 -0
- win_dev_doctor/models.py +59 -0
- win_dev_doctor/registry.py +37 -0
- win_dev_doctor-0.2.0.dist-info/METADATA +145 -0
- win_dev_doctor-0.2.0.dist-info/RECORD +22 -0
- win_dev_doctor-0.2.0.dist-info/WHEEL +4 -0
- win_dev_doctor-0.2.0.dist-info/entry_points.txt +3 -0
- win_dev_doctor-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""PATH environment variable diagnostics: missing dirs, duplicates, and binary shadows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from win_dev_doctor.models import BaseCheck, CheckResult, Status
|
|
10
|
+
|
|
11
|
+
WATCHED_BINARIES = (
|
|
12
|
+
"python.exe",
|
|
13
|
+
"python3.exe",
|
|
14
|
+
"pip.exe",
|
|
15
|
+
"node.exe",
|
|
16
|
+
"npm.cmd",
|
|
17
|
+
"git.exe",
|
|
18
|
+
"uv.exe",
|
|
19
|
+
"cargo.exe",
|
|
20
|
+
"go.exe",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(slots=True)
|
|
25
|
+
class PathReport:
|
|
26
|
+
"""Detailed breakdown of the current PATH variable."""
|
|
27
|
+
|
|
28
|
+
entries: list[str] = field(default_factory=list)
|
|
29
|
+
missing: list[str] = field(default_factory=list)
|
|
30
|
+
duplicates: list[str] = field(default_factory=list)
|
|
31
|
+
shadows: dict[str, list[str]] = field(default_factory=dict)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def inspect_path(path_env: str | None = None) -> PathReport:
|
|
35
|
+
"""Inspect PATH entries for missing dirs, duplicates, and shadowed executables."""
|
|
36
|
+
raw = os.environ.get("PATH", "") if path_env is None else path_env
|
|
37
|
+
sep = os.pathsep
|
|
38
|
+
entries = [p.strip().strip('"') for p in raw.split(sep) if p.strip().strip('"')]
|
|
39
|
+
|
|
40
|
+
seen_norm: set[str] = set()
|
|
41
|
+
missing: list[str] = []
|
|
42
|
+
duplicates: list[str] = []
|
|
43
|
+
unique_existing: list[Path] = []
|
|
44
|
+
|
|
45
|
+
for entry in entries:
|
|
46
|
+
expanded = os.path.expandvars(entry)
|
|
47
|
+
norm = os.path.normcase(os.path.normpath(expanded))
|
|
48
|
+
if norm in seen_norm:
|
|
49
|
+
duplicates.append(entry)
|
|
50
|
+
continue
|
|
51
|
+
seen_norm.add(norm)
|
|
52
|
+
|
|
53
|
+
path_obj = Path(expanded)
|
|
54
|
+
if not path_obj.exists():
|
|
55
|
+
missing.append(entry)
|
|
56
|
+
elif path_obj.is_dir():
|
|
57
|
+
unique_existing.append(path_obj)
|
|
58
|
+
|
|
59
|
+
shadows: dict[str, list[str]] = {}
|
|
60
|
+
for binary in WATCHED_BINARIES:
|
|
61
|
+
hits: list[str] = []
|
|
62
|
+
for directory in unique_existing:
|
|
63
|
+
candidate = directory / binary
|
|
64
|
+
if candidate.is_file():
|
|
65
|
+
hits.append(str(candidate))
|
|
66
|
+
if len(hits) > 1:
|
|
67
|
+
shadows[binary] = hits
|
|
68
|
+
|
|
69
|
+
return PathReport(
|
|
70
|
+
entries=entries,
|
|
71
|
+
missing=missing,
|
|
72
|
+
duplicates=duplicates,
|
|
73
|
+
shadows=shadows,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class PathHealthCheck(BaseCheck):
|
|
78
|
+
id = "path"
|
|
79
|
+
name = "PATH Health"
|
|
80
|
+
category = "environment"
|
|
81
|
+
description = "Detect missing folders, duplicate entries, and shadowed dev binaries in PATH."
|
|
82
|
+
order = 10
|
|
83
|
+
|
|
84
|
+
def run(self) -> CheckResult:
|
|
85
|
+
report = inspect_path()
|
|
86
|
+
details: list[str] = []
|
|
87
|
+
|
|
88
|
+
if report.missing:
|
|
89
|
+
details.append(f"Missing directories ({len(report.missing)}): " + ", ".join(report.missing[:5]))
|
|
90
|
+
if report.duplicates:
|
|
91
|
+
dups = ", ".join(report.duplicates[:5])
|
|
92
|
+
details.append(f"Duplicate entries ({len(report.duplicates)}): {dups}")
|
|
93
|
+
for binary, locations in report.shadows.items():
|
|
94
|
+
details.append(f"Multiple `{binary}` found: " + " -> ".join(locations[:3]))
|
|
95
|
+
|
|
96
|
+
issues = len(report.missing) + len(report.duplicates) + len(report.shadows)
|
|
97
|
+
if issues == 0:
|
|
98
|
+
return CheckResult(
|
|
99
|
+
check_id=self.id,
|
|
100
|
+
name=self.name,
|
|
101
|
+
category=self.category,
|
|
102
|
+
status=Status.OK,
|
|
103
|
+
summary=f"{len(report.entries)} PATH entries, all valid and unique",
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
return CheckResult(
|
|
107
|
+
check_id=self.id,
|
|
108
|
+
name=self.name,
|
|
109
|
+
category=self.category,
|
|
110
|
+
status=Status.WARN,
|
|
111
|
+
summary=(
|
|
112
|
+
f"{len(report.missing)} missing, {len(report.duplicates)} duplicates, "
|
|
113
|
+
f"{len(report.shadows)} shadowed binaries"
|
|
114
|
+
),
|
|
115
|
+
details=details,
|
|
116
|
+
fix_hint=(
|
|
117
|
+
"Run `wdd path` for full breakdown and clean unused entries "
|
|
118
|
+
"in System Environment Variables."
|
|
119
|
+
),
|
|
120
|
+
)
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""Inspect listening TCP ports and kill stuck dev-server processes cleanly."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
import psutil
|
|
8
|
+
|
|
9
|
+
from win_dev_doctor.models import BaseCheck, CheckResult, Status
|
|
10
|
+
|
|
11
|
+
COMMON_DEV_PORTS: frozenset[int] = frozenset(
|
|
12
|
+
{
|
|
13
|
+
3000,
|
|
14
|
+
3001,
|
|
15
|
+
4000,
|
|
16
|
+
4200,
|
|
17
|
+
5000,
|
|
18
|
+
5173,
|
|
19
|
+
5174,
|
|
20
|
+
5432,
|
|
21
|
+
6379,
|
|
22
|
+
8000,
|
|
23
|
+
8080,
|
|
24
|
+
8081,
|
|
25
|
+
8888,
|
|
26
|
+
9000,
|
|
27
|
+
27017,
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass(slots=True)
|
|
33
|
+
class PortEntry:
|
|
34
|
+
"""Represents a listening TCP port and its owning process."""
|
|
35
|
+
|
|
36
|
+
port: int
|
|
37
|
+
address: str
|
|
38
|
+
pid: int
|
|
39
|
+
process_name: str
|
|
40
|
+
exe: str
|
|
41
|
+
cmdline: str
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _describe_pid(pid: int) -> tuple[str, str, str]:
|
|
45
|
+
if pid <= 0:
|
|
46
|
+
return ("System", "", "")
|
|
47
|
+
try:
|
|
48
|
+
proc = psutil.Process(pid)
|
|
49
|
+
name = proc.name()
|
|
50
|
+
try:
|
|
51
|
+
exe = proc.exe()
|
|
52
|
+
except (psutil.AccessDenied, psutil.NoSuchProcess, OSError):
|
|
53
|
+
exe = ""
|
|
54
|
+
try:
|
|
55
|
+
cmdline = " ".join(proc.cmdline())
|
|
56
|
+
except (psutil.AccessDenied, psutil.NoSuchProcess, OSError):
|
|
57
|
+
cmdline = ""
|
|
58
|
+
return (name, exe, cmdline)
|
|
59
|
+
except (psutil.NoSuchProcess, psutil.AccessDenied, OSError):
|
|
60
|
+
return ("<unknown>", "", "")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def list_listening_ports(
|
|
64
|
+
*,
|
|
65
|
+
dev_only: bool = False,
|
|
66
|
+
port_filter: int | None = None,
|
|
67
|
+
) -> list[PortEntry]:
|
|
68
|
+
"""Return active TCP LISTEN sockets sorted by port and PID."""
|
|
69
|
+
entries: list[PortEntry] = []
|
|
70
|
+
seen: set[tuple[int, int, str]] = set()
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
connections = psutil.net_connections(kind="tcp")
|
|
74
|
+
except psutil.AccessDenied:
|
|
75
|
+
return []
|
|
76
|
+
|
|
77
|
+
for conn in connections:
|
|
78
|
+
if conn.status != psutil.CONN_LISTEN or not conn.laddr:
|
|
79
|
+
continue
|
|
80
|
+
port = conn.laddr.port
|
|
81
|
+
addr = conn.laddr.ip
|
|
82
|
+
pid = conn.pid or 0
|
|
83
|
+
|
|
84
|
+
if port_filter is not None and port != port_filter:
|
|
85
|
+
continue
|
|
86
|
+
if dev_only and port not in COMMON_DEV_PORTS:
|
|
87
|
+
continue
|
|
88
|
+
|
|
89
|
+
key = (port, pid, addr)
|
|
90
|
+
if key in seen:
|
|
91
|
+
continue
|
|
92
|
+
seen.add(key)
|
|
93
|
+
|
|
94
|
+
name, exe, cmdline = _describe_pid(pid)
|
|
95
|
+
entries.append(
|
|
96
|
+
PortEntry(
|
|
97
|
+
port=port,
|
|
98
|
+
address=addr,
|
|
99
|
+
pid=pid,
|
|
100
|
+
process_name=name,
|
|
101
|
+
exe=exe,
|
|
102
|
+
cmdline=cmdline,
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
entries.sort(key=lambda e: (e.port, e.pid, e.address))
|
|
107
|
+
return entries
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def kill_port(port: int, *, force: bool = False) -> tuple[list[PortEntry], list[str]]:
|
|
111
|
+
"""Terminate all processes listening on `port`.
|
|
112
|
+
|
|
113
|
+
Returns `(killed_entries, error_messages)`.
|
|
114
|
+
"""
|
|
115
|
+
matches = list_listening_ports(port_filter=port)
|
|
116
|
+
if not matches:
|
|
117
|
+
return ([], [])
|
|
118
|
+
|
|
119
|
+
killed: list[PortEntry] = []
|
|
120
|
+
errors: list[str] = []
|
|
121
|
+
handled_pids: set[int] = set()
|
|
122
|
+
|
|
123
|
+
for entry in matches:
|
|
124
|
+
if entry.pid in handled_pids:
|
|
125
|
+
continue
|
|
126
|
+
handled_pids.add(entry.pid)
|
|
127
|
+
|
|
128
|
+
if entry.pid <= 4:
|
|
129
|
+
errors.append(f"Refused to kill protected system PID {entry.pid} ({entry.process_name})")
|
|
130
|
+
continue
|
|
131
|
+
|
|
132
|
+
try:
|
|
133
|
+
proc = psutil.Process(entry.pid)
|
|
134
|
+
if force:
|
|
135
|
+
proc.kill()
|
|
136
|
+
else:
|
|
137
|
+
proc.terminate()
|
|
138
|
+
proc.wait(timeout=3)
|
|
139
|
+
killed.append(entry)
|
|
140
|
+
except psutil.TimeoutExpired:
|
|
141
|
+
try:
|
|
142
|
+
proc.kill()
|
|
143
|
+
proc.wait(timeout=2)
|
|
144
|
+
killed.append(entry)
|
|
145
|
+
except (psutil.NoSuchProcess, psutil.AccessDenied, OSError) as exc:
|
|
146
|
+
errors.append(f"PID {entry.pid} ({entry.process_name}): {exc}")
|
|
147
|
+
except psutil.NoSuchProcess:
|
|
148
|
+
killed.append(entry)
|
|
149
|
+
except (psutil.AccessDenied, OSError) as exc:
|
|
150
|
+
errors.append(f"PID {entry.pid} ({entry.process_name}): {exc}")
|
|
151
|
+
|
|
152
|
+
return (killed, errors)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class DevPortsCheck(BaseCheck):
|
|
156
|
+
id = "ports"
|
|
157
|
+
name = "Active Dev Ports"
|
|
158
|
+
category = "runtime"
|
|
159
|
+
description = "List processes bound to common local development ports (3000, 5173, 8000, 8080, etc.)."
|
|
160
|
+
order = 60
|
|
161
|
+
|
|
162
|
+
def run(self) -> CheckResult:
|
|
163
|
+
dev_ports = list_listening_ports(dev_only=True)
|
|
164
|
+
if not dev_ports:
|
|
165
|
+
return CheckResult(
|
|
166
|
+
check_id=self.id,
|
|
167
|
+
name=self.name,
|
|
168
|
+
category=self.category,
|
|
169
|
+
status=Status.OK,
|
|
170
|
+
summary="No common dev ports currently occupied",
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
details = [f":{p.port} -> {p.process_name} (PID {p.pid})" for p in dev_ports]
|
|
174
|
+
return CheckResult(
|
|
175
|
+
check_id=self.id,
|
|
176
|
+
name=self.name,
|
|
177
|
+
category=self.category,
|
|
178
|
+
status=Status.INFO,
|
|
179
|
+
summary=f"{len(dev_ports)} dev port(s) listening",
|
|
180
|
+
details=details,
|
|
181
|
+
fix_hint="Run `wdd ports` to inspect or `wdd kill <port>` to free a stuck port.",
|
|
182
|
+
)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Check Windows Developer Mode and non-admin symlink creation support."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from win_dev_doctor.models import BaseCheck, CheckResult, Status
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def is_developer_mode_enabled() -> bool | None:
|
|
14
|
+
"""Check if Windows Developer Mode is enabled in registry."""
|
|
15
|
+
if sys.platform != "win32":
|
|
16
|
+
return None
|
|
17
|
+
try:
|
|
18
|
+
import winreg
|
|
19
|
+
|
|
20
|
+
key_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
|
|
21
|
+
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path) as key:
|
|
22
|
+
value, _ = winreg.QueryValueEx(key, "AllowDevelopmentWithoutDevLicense")
|
|
23
|
+
return bool(value == 1)
|
|
24
|
+
except OSError:
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def can_create_symlinks() -> bool:
|
|
29
|
+
"""Test creating a symlink in a temporary directory."""
|
|
30
|
+
try:
|
|
31
|
+
with tempfile.TemporaryDirectory(prefix="wdd-sym-") as tmp:
|
|
32
|
+
target = Path(tmp) / "target.txt"
|
|
33
|
+
link = Path(tmp) / "link.txt"
|
|
34
|
+
target.write_text("ok", encoding="utf-8")
|
|
35
|
+
os.symlink(target, link)
|
|
36
|
+
return link.is_symlink()
|
|
37
|
+
except OSError:
|
|
38
|
+
return False
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class SymlinksCheck(BaseCheck):
|
|
42
|
+
id = "symlinks"
|
|
43
|
+
name = "Developer Mode & Symlinks"
|
|
44
|
+
category = "windows"
|
|
45
|
+
description = "Verify non-admin symlink creation (required by pnpm, uv, git, and monorepos)."
|
|
46
|
+
order = 25
|
|
47
|
+
|
|
48
|
+
def run(self) -> CheckResult:
|
|
49
|
+
dev_mode = is_developer_mode_enabled()
|
|
50
|
+
symlink_ok = can_create_symlinks()
|
|
51
|
+
|
|
52
|
+
if symlink_ok:
|
|
53
|
+
extra = "Developer Mode ON" if dev_mode else "symlink privilege granted"
|
|
54
|
+
return CheckResult(
|
|
55
|
+
check_id=self.id,
|
|
56
|
+
name=self.name,
|
|
57
|
+
category=self.category,
|
|
58
|
+
status=Status.OK,
|
|
59
|
+
summary=f"Symlinks work without elevation ({extra})",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return CheckResult(
|
|
63
|
+
check_id=self.id,
|
|
64
|
+
name=self.name,
|
|
65
|
+
category=self.category,
|
|
66
|
+
status=Status.WARN,
|
|
67
|
+
summary="Cannot create symlinks without Admin (Developer Mode is OFF)",
|
|
68
|
+
fix_hint="Enable Settings -> System -> For developers -> Developer Mode.",
|
|
69
|
+
)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Check Windows Subsystem for Linux (WSL) installation and distros."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import shutil
|
|
6
|
+
import subprocess
|
|
7
|
+
|
|
8
|
+
from win_dev_doctor.models import BaseCheck, CheckResult, Status
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _decode_wsl_output(raw: bytes) -> str:
|
|
12
|
+
if b"\x00" in raw:
|
|
13
|
+
return raw.decode("utf-16-le", errors="ignore").lstrip("\ufeff")
|
|
14
|
+
return raw.decode("utf-8", errors="ignore").lstrip("\ufeff")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def list_wsl_distros() -> list[str] | None:
|
|
18
|
+
"""Return installed WSL distro names, or None if WSL is not installed."""
|
|
19
|
+
wsl_bin = shutil.which("wsl.exe") or shutil.which("wsl")
|
|
20
|
+
if not wsl_bin:
|
|
21
|
+
return None
|
|
22
|
+
try:
|
|
23
|
+
proc = subprocess.run(
|
|
24
|
+
[wsl_bin, "--list", "--quiet"],
|
|
25
|
+
capture_output=True,
|
|
26
|
+
timeout=5,
|
|
27
|
+
check=False,
|
|
28
|
+
)
|
|
29
|
+
if proc.returncode != 0:
|
|
30
|
+
return []
|
|
31
|
+
text = _decode_wsl_output(proc.stdout)
|
|
32
|
+
return [line.strip() for line in text.splitlines() if line.strip()]
|
|
33
|
+
except (OSError, subprocess.SubprocessError):
|
|
34
|
+
return []
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class WslCheck(BaseCheck):
|
|
38
|
+
id = "wsl"
|
|
39
|
+
name = "WSL2 Status"
|
|
40
|
+
category = "windows"
|
|
41
|
+
description = "Check whether WSL is available and list installed Linux distributions."
|
|
42
|
+
order = 50
|
|
43
|
+
|
|
44
|
+
def run(self) -> CheckResult:
|
|
45
|
+
distros = list_wsl_distros()
|
|
46
|
+
if distros is None:
|
|
47
|
+
return CheckResult(
|
|
48
|
+
check_id=self.id,
|
|
49
|
+
name=self.name,
|
|
50
|
+
category=self.category,
|
|
51
|
+
status=Status.INFO,
|
|
52
|
+
summary="WSL not installed",
|
|
53
|
+
fix_hint="Install with `wsl --install` if you need Linux tooling.",
|
|
54
|
+
)
|
|
55
|
+
if not distros:
|
|
56
|
+
return CheckResult(
|
|
57
|
+
check_id=self.id,
|
|
58
|
+
name=self.name,
|
|
59
|
+
category=self.category,
|
|
60
|
+
status=Status.INFO,
|
|
61
|
+
summary="WSL present, but no Linux distros installed",
|
|
62
|
+
fix_hint="Run `wsl --install -d Ubuntu` to add a distro.",
|
|
63
|
+
)
|
|
64
|
+
return CheckResult(
|
|
65
|
+
check_id=self.id,
|
|
66
|
+
name=self.name,
|
|
67
|
+
category=self.category,
|
|
68
|
+
status=Status.OK,
|
|
69
|
+
summary=f"WSL ready with {len(distros)} distro(s): {', '.join(distros[:4])}",
|
|
70
|
+
details=distros,
|
|
71
|
+
)
|