Skip to content

Commit a953f32

Browse files
committed
fix: scope network troubleshoot rule to safe diagnostics
1 parent 02d0951 commit a953f32

1 file changed

Lines changed: 79 additions & 89 deletions

File tree

rules/network-troubleshoot.mdc

Lines changed: 79 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,128 @@
11
---
2-
description: Systematic network troubleshooting for developers
2+
description: Systematic, safety-first network troubleshooting for developers
33
globs: **/*
44
alwaysApply: false
55
---
66

77
# Network Troubleshoot
88

9-
You are a network diagnostics expert. Systematically diagnose network issues using read-only methods.
9+
Use this rule as a concise decision guide for developer network failures. Keep diagnostics safe, target-scoped, and read-only. Do not turn this rule into an automated remediation toolkit.
1010

11-
## Safety Rules
11+
## Safety Boundaries
1212

13-
- Prefer read-only diagnostic commands.
14-
- Never print full proxy URLs, tokens, passwords, or credential values. If output must be shared, redact credentials, hosts, and tokens first.
15-
- Never disable TLS verification or skip certificate checks.
16-
- Never change persistent or global npm, pip, git, Docker, shell, or proxy settings without explicit user confirmation.
17-
- Use the failing target host as the default probe target.
18-
- Only probe external services after the user approves the target, unless that service is the failing target.
13+
- Prefer read-only diagnostics and trusted project-provided diagnostic scripts.
14+
- Use the failing host, URL, registry, or service as the default probe target.
15+
- Ask before probing unrelated external services.
16+
- Do not print proxy URLs, credentials, tokens, auth headers, package index URLs, registry hostnames, internal hosts, or raw config values.
17+
- Do not dump local config from npm, pnpm, yarn, pip, Git, Docker, shell, OS proxy, VPN, or certificate stores.
18+
- Do not disable, bypass, or skip TLS or certificate verification.
19+
- Do not change OS networking, DNS, proxy, package manager, Git, Docker, shell, VPN, or trust-store settings without explicit user approval for the exact action.
1920

2021
## Workflow
2122

22-
1. **Collect**: Get error message, target host/port, triggering command, scope, environment
23-
2. **Classify**: Match error pattern to category (see table below)
24-
3. **Diagnose**: Run read-only diagnostic commands for that category
25-
4. **Advise**: Suggest resolution options; wait for user approval before making changes
26-
5. **Verify**: Re-run failed operation to confirm
23+
1. **Collect**: Capture the exact error, failing command, target host/URL/port, OS/shell, proxy/VPN context, and whether the failure affects one target or many.
24+
2. **Classify**: Match the symptom to the most likely category.
25+
3. **Diagnose**: Run only read-only checks scoped to the failing target.
26+
4. **Explain**: Interpret the output before suggesting any fix.
27+
5. **Advise**: Present remediation options as choices and wait for user approval before changing state.
28+
6. **Verify**: Re-run the original failing command or an equivalent target-scoped check.
2729

2830
## Error Classification
2931

30-
| Error Pattern | Category |
32+
| Error Pattern | Likely Category |
3133
|---|---|
32-
| ECONNREFUSED, Connection refused | Connectivity / Port |
33-
| ECONNRESET, Connection reset | Connectivity / Firewall |
34-
| ETIMEDOUT, timed out | Timeout / Routing |
35-
| ENOTFOUND, ERR_NAME_NOT_RESOLVED | DNS |
36-
| EACCES, EPERM | Firewall / Permissions |
37-
| ERR_PROXY_CONNECTION_FAILED | Proxy |
38-
| UNABLE_TO_VERIFY_LEAF_SIGNATURE, CERT_HAS_EXPIRED | SSL/TLS |
39-
| HTTP 403, 407, 502, 503, 504 | HTTP / Proxy |
40-
| npm ERR! network, pip timeout | Package Manager |
41-
| fatal: unable to access (git) | Git / Network |
34+
| `ECONNREFUSED`, `ERR_CONNECTION_REFUSED`, `Connection refused` | Target service or port is not listening |
35+
| `ECONNRESET`, `socket hang up`, `Connection reset` | Connection dropped by target, proxy, firewall, or middlebox |
36+
| `ETIMEDOUT`, `ERR_CONNECTION_TIMED_OUT`, `timed out` | Routing, firewall, proxy, or target availability |
37+
| `ENOTFOUND`, `EAI_NONAME`, `ERR_NAME_NOT_RESOLVED`, `getaddrinfo` | DNS or hostname issue |
38+
| `ERR_PROXY_CONNECTION_FAILED`, proxy tunnel errors, HTTP `407` | Proxy configuration or proxy authentication |
39+
| `UNABLE_TO_VERIFY_LEAF_SIGNATURE`, `CERT_HAS_EXPIRED`, `self signed`, `ERR_CERT_*` | TLS certificate or local trust issue |
40+
| HTTP `403` | Authorization, IP allowlist, CORS, or policy block |
41+
| HTTP `502`, `503`, `504` | Upstream service, gateway, CDN, or transient server issue |
42+
| `npm ERR! network`, package install timeout, `pip` timeout | Package registry, proxy, DNS, or network path issue |
43+
| `fatal: unable to access`, Git fetch/push timeout | Git remote, proxy, DNS, TLS, or network path issue |
4244

43-
## Diagnostic Commands
45+
## Safe Target-Scoped Checks
4446

45-
> On Windows Git Bash: `nc`, `dig`, `traceroute` are unavailable. Use `curl`, `nslookup`, `tracert` instead.
47+
Choose the smallest relevant set. Explain what each command checks before running it.
4648

4749
### Connectivity
50+
4851
```bash
4952
ping -c 4 <target-host> # Linux/macOS
5053
ping -n 4 <target-host> # Windows
51-
curl -v telnet://<target-host>:<port> --connect-timeout 5 # cross-platform port check
52-
nc -zv <target-host> <port> # Linux/macOS only
54+
curl -v telnet://<target-host>:<port> --connect-timeout 5
55+
```
56+
57+
```powershell
58+
Test-NetConnection -ComputerName <target-host> -Port <port>
5359
```
5460

5561
### DNS
62+
5663
```bash
5764
nslookup <target-host>
58-
dig <target-host> # Linux/macOS only
65+
dig <target-host> # Linux/macOS, if available
5966
```
6067

61-
### Proxy (read-only checks only)
68+
```powershell
69+
Resolve-DnsName <target-host>
70+
```
71+
72+
### HTTP
73+
6274
```bash
63-
# Check whether proxy env vars are set (values are redacted)
64-
echo "${HTTP_PROXY:+HTTP_PROXY is set}" "${HTTPS_PROXY:+HTTPS_PROXY is set}" "${ALL_PROXY:+ALL_PROXY is set}"
65-
# Check whether proxy config keys exist — do not paste raw output; redact credentials before sharing
66-
git config --get http.proxy >/dev/null && echo "git http.proxy is set" || echo "git http.proxy is not set"
67-
git config --get https.proxy >/dev/null && echo "git https.proxy is set" || echo "git https.proxy is not set"
68-
npm config get proxy >/dev/null && echo "npm proxy is set" || echo "npm proxy is not set"
69-
npm config get https-proxy >/dev/null && echo "npm https-proxy is set" || echo "npm https-proxy is not set"
75+
curl -vvv -o /dev/null -w "HTTP %{http_code}\nTime: %{time_total}s\nDNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\n" https://<target-host>/<path>
76+
curl -I https://<target-host>/<path>
7077
```
7178

72-
### SSL/TLS
79+
### TLS
80+
7381
```bash
74-
# Linux/macOS only (requires openssl)
7582
openssl s_client -connect <target-host>:443 -showcerts </dev/null
7683
echo | openssl s_client -connect <target-host>:443 2>/dev/null | openssl x509 -noout -dates
77-
curl -vvv https://<target-host> 2>&1 | grep -E "SSL|TLS|certificate|error"
7884
```
85+
7986
```powershell
80-
# Windows PowerShell
81-
try { $req = [Net.HttpWebRequest]::Create("https://<target-host>"); $req.Timeout = 5000; $resp = $req.GetResponse(); $cert = $req.ServicePoint.Certificate; "Cert subject: $($cert.Subject)"; "Cert expires: $($cert.GetExpirationDateString())"; $resp.Close() } catch { "TLS/cert error: $_" }
87+
try {
88+
$req = [Net.HttpWebRequest]::Create("https://<target-host>")
89+
$req.Timeout = 5000
90+
$resp = $req.GetResponse()
91+
$cert = $req.ServicePoint.Certificate
92+
"Cert subject: $($cert.Subject)"
93+
"Cert expires: $($cert.GetExpirationDateString())"
94+
$resp.Close()
95+
} catch {
96+
"TLS/certificate error: $_"
97+
}
8298
```
8399

84-
### HTTP
85-
```bash
86-
curl -vvv -o /dev/null -w "HTTP %{http_code}\nTime: %{time_total}s\nDNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\n" https://<target-host>/<path>
87-
```
100+
### Proxy And Package Managers
88101

89-
### Package Managers (single-key reads only)
90-
```bash
91-
npm config get registry
92-
# Use npm ping only when the failing target is the configured npm registry, or after user approval
93-
npm ping
94-
pip config get global.index-url
95-
```
102+
For proxy, package manager, Git, Docker, and OS network configuration, avoid raw config reads. Report only whether relevant settings appear present when this can be checked without printing values. If the available command would print a URL, token, internal hostname, auth header, or full config value, do not run it.
96103

97-
## Resolution Advisory
104+
Only perform package registry probes when the failed operation already targeted that registry, or after the user approves that exact probe target.
98105

99-
Present resolution options to the user. Do not execute any mutating command without explicit approval.
106+
## User-Approved Remediation Options
100107

101-
| Diagnosis | Advisory |
108+
These are options to discuss with the user, not commands to run automatically.
109+
110+
| Diagnosis | Safe Advice |
102111
|---|---|
103-
| No internet | Check cable/WiFi, restart router, run `ipconfig /renew` |
104-
| DNS fails | Suggest switching DNS, flushing cache, checking `/etc/resolv.conf` |
105-
| Proxy not running | Suggest starting proxy tool and verifying port |
106-
| Target blocked through proxy | Suggest trying different proxy node/protocol |
107-
| SSL cert expired | Renew or replace the certificate; for local development, install a trusted local/dev certificate or update the local trust store. Do not bypass TLS verification. |
108-
| SSL unknown CA | Suggest importing CA to trust store |
109-
| HTTP 407 | Suggest configuring proxy credentials |
110-
| HTTP 403 | Suggest checking API key, IP whitelist, CORS headers |
111-
| HTTP 502/503/504 | Server issue, suggest retry with backoff |
112-
| npm timeout | Suggest alternative registry options (e.g. npmmirror) and ask which to use |
113-
| pip timeout | Suggest alternative index options (e.g. TUNA) and ask which to use |
114-
| git fails | Suggest proxy configuration options and ask which to use |
115-
| docker pull fails | Suggest mirror configuration in `/etc/docker/daemon.json` |
116-
| Gradle/Maven fails | Suggest proxy configuration in respective config files |
112+
| Target service is not listening | Check whether the local or remote service is running and whether the expected port is correct. |
113+
| DNS lookup fails | Check the hostname, hosts-file expectations, DNS service status, or approved DNS changes. |
114+
| Proxy appears required or unavailable | Ask whether the user wants to start or adjust the proxy/VPN, then verify only the approved target. |
115+
| TLS certificate expired | Renew or replace the certificate, fix system time, install a trusted local development CA, or update the trust store. Do not bypass TLS verification. |
116+
| TLS unknown CA | Import the correct CA into the appropriate trust store after the user confirms the source and scope. |
117+
| HTTP `407` | Ask the user to confirm proxy authentication requirements before changing credentials or tool settings. |
118+
| HTTP `403` | Check authentication, API key scope, IP allowlist, CORS policy, or service policy. |
119+
| HTTP `502`/`503`/`504` | Treat as upstream or gateway instability; check status pages when approved and retry with backoff. |
120+
| Package install timeout | Discuss approved registry, proxy, or network-path options without printing or changing stored config values. |
121+
| Git network failure | Discuss approved remote URL, proxy, credential, TLS, or network-path options without changing global Git settings automatically. |
122+
| Docker pull failure | Discuss approved registry mirror, proxy, or daemon settings as a user-approved configuration change. |
117123

118124
## Verification
119125

120-
After applying user-approved changes, re-run the failed command to verify:
121-
```bash
122-
curl -I https://<previously-failing-host>
123-
nslookup <target-host>
124-
```
125-
126-
## Error Quick Reference
127-
128-
- `ECONNREFUSED`: Target not listening on that port
129-
- `ECONNRESET`: Connection dropped — firewall or idle timeout
130-
- `ETIMEDOUT`: No response — network unreachable or firewall block
131-
- `ENOTFOUND` / `EAI_NONAME`: DNS resolution failed
132-
- `EPIPE`: Writing to closed connection
133-
- `ERR_PROXY_CONNECTION_FAILED`: Proxy not running or wrong config
134-
- `CERT_HAS_EXPIRED`: Server certificate expired
135-
- `UNABLE_TO_VERIFY_LEAF_SIGNATURE`: Unknown CA in certificate chain
136-
- `ERR_OSSL_EVP_UNSUPPORTED`: OpenSSL version mismatch — upgrade Node.js
126+
After any user-approved change, verify with the original failing command whenever possible. If a smaller check is needed, keep it scoped to the same failing host, URL, registry, or service.
137127

138-
Always explain what each command does and interpret the output before suggesting fixes.
128+
Always explain what each diagnostic result means before recommending the next step.

0 commit comments

Comments
 (0)