devprobe 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # portprobe
2
+
3
+ Instant port diagnostics for your local dev environment.
4
+
5
+ ## Why
6
+
7
+ Every developer has hit it: you start a server and get `EADDRINUSE`, then spend minutes figuring out what's hogging the port. AI coding agents like Claude Code hit the same wall -- they burn tokens retrying commands and guessing what went wrong.
8
+
9
+ portprobe scans common dev ports in parallel, shows what's listening, which process owns it, and whether it responds to HTTP. One command, zero guesswork.
10
+
11
+ ## Quick start
12
+
13
+ Run without installing:
14
+
15
+ ```bash
16
+ npx portprobe
17
+ ```
18
+
19
+ Or install globally:
20
+
21
+ ```bash
22
+ npm i -g portprobe
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Default scan
28
+
29
+ Scans common dev ports (3000, 3001, 4200, 5000, 5173, 5432, 6379, 8000, 8080, 8443, 9000, 27017) and prints a table:
30
+
31
+ ```bash
32
+ portprobe
33
+ ```
34
+
35
+ ### JSON output
36
+
37
+ Machine-readable output for scripts and AI agents:
38
+
39
+ ```bash
40
+ portprobe --json
41
+ ```
42
+
43
+ ### Single port check
44
+
45
+ Check whether a specific port is in use:
46
+
47
+ ```bash
48
+ portprobe 3000
49
+ ```
50
+
51
+ ### Range scan
52
+
53
+ Scan a custom range of ports:
54
+
55
+ ```bash
56
+ portprobe --range 3000-9000
57
+ ```
58
+
59
+ ### Custom timeout
60
+
61
+ Set the TCP connection timeout in milliseconds (default: 1000):
62
+
63
+ ```bash
64
+ portprobe --timeout 2000
65
+ ```
66
+
67
+ ## Flags
68
+
69
+ | Flag | Description | Default |
70
+ |---|---|---|
71
+ | `[port]` | Check a single port | — |
72
+ | `--json` | Output as JSON | `false` |
73
+ | `--range <from-to>` | Scan a port range (e.g. `3000-9000`) | — |
74
+ | `--timeout <ms>` | Connection timeout in ms | `1000` |
75
+ | `--version` | Show version | — |
76
+ | `--help` | Show help | — |
77
+
78
+ ## AI Agent integration
79
+
80
+ portprobe is designed to work well with AI coding agents. Use `--json` to get structured output that an agent can parse directly:
81
+
82
+ ```bash
83
+ portprobe --json
84
+ ```
85
+
86
+ Returns an array of results:
87
+
88
+ ```json
89
+ [
90
+ {
91
+ "port": 3000,
92
+ "status": "up",
93
+ "pid": 12345,
94
+ "process": "node",
95
+ "latency": 2,
96
+ "protocol": "http"
97
+ },
98
+ {
99
+ "port": 5432,
100
+ "status": "up",
101
+ "pid": 501,
102
+ "process": "postgres",
103
+ "latency": 1,
104
+ "protocol": null
105
+ },
106
+ {
107
+ "port": 8080,
108
+ "status": "free",
109
+ "pid": null,
110
+ "process": null,
111
+ "latency": null,
112
+ "protocol": null
113
+ }
114
+ ]
115
+ ```
116
+
117
+ An agent can run `npx portprobe --json` before starting a dev server to pick an open port or diagnose a conflict without trial and error.
118
+
119
+ ## Platforms
120
+
121
+ - **macOS** — full support (uses `lsof` for process resolution)
122
+ - **Linux** — full support (uses `lsof` for process resolution)
123
+ - **Windows** — best-effort (uses `netstat` for process resolution)
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "../dist/index.js";
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,227 @@
1
+ // src/index.ts
2
+ import { program } from "commander";
3
+
4
+ // src/scanner/tcp.ts
5
+ import net from "net";
6
+ function checkTcp(port, timeout) {
7
+ return new Promise((resolve) => {
8
+ const start = performance.now();
9
+ const socket = new net.Socket();
10
+ socket.setTimeout(timeout);
11
+ socket.on("connect", () => {
12
+ const latency = Math.round(performance.now() - start);
13
+ socket.destroy();
14
+ resolve({ status: "up", latency });
15
+ });
16
+ socket.on("timeout", () => {
17
+ socket.destroy();
18
+ resolve({ status: "timeout", latency: null });
19
+ });
20
+ socket.on("error", (err) => {
21
+ socket.destroy();
22
+ if (err.code === "ECONNREFUSED") {
23
+ resolve({ status: "free", latency: null });
24
+ } else {
25
+ resolve({ status: "free", latency: null });
26
+ }
27
+ });
28
+ socket.connect(port, "127.0.0.1");
29
+ });
30
+ }
31
+
32
+ // src/scanner/process.ts
33
+ import { execFile } from "child_process";
34
+ import { promisify } from "util";
35
+ var execFileAsync = promisify(execFile);
36
+ async function resolveProcess(port) {
37
+ try {
38
+ if (process.platform === "win32") {
39
+ return resolveWindows(port);
40
+ }
41
+ return resolveUnix(port);
42
+ } catch {
43
+ return { pid: null, name: null };
44
+ }
45
+ }
46
+ async function resolveUnix(port) {
47
+ try {
48
+ const { stdout } = await execFileAsync("lsof", [
49
+ "-i",
50
+ `:${port}`,
51
+ "-sTCP:LISTEN",
52
+ "-P",
53
+ "-n",
54
+ "-Fp"
55
+ ]);
56
+ const pidLine = stdout.split("\n").find((l) => l.startsWith("p"));
57
+ if (!pidLine) return { pid: null, name: null };
58
+ const pid = parseInt(pidLine.slice(1), 10);
59
+ const name = await getProcessName(pid);
60
+ return { pid, name };
61
+ } catch {
62
+ return { pid: null, name: null };
63
+ }
64
+ }
65
+ async function resolveWindows(port) {
66
+ try {
67
+ const { stdout } = await execFileAsync("netstat", ["-ano"]);
68
+ const line = stdout.split("\n").find(
69
+ (l) => l.includes(`:${port}`) && l.includes("LISTENING")
70
+ );
71
+ if (!line) return { pid: null, name: null };
72
+ const parts = line.trim().split(/\s+/);
73
+ const pid = parseInt(parts[parts.length - 1], 10);
74
+ const name = await getProcessName(pid);
75
+ return { pid, name };
76
+ } catch {
77
+ return { pid: null, name: null };
78
+ }
79
+ }
80
+ async function getProcessName(pid) {
81
+ try {
82
+ if (process.platform === "win32") {
83
+ const { stdout: stdout2 } = await execFileAsync("tasklist", [
84
+ "/FI",
85
+ `PID eq ${pid}`,
86
+ "/FO",
87
+ "CSV",
88
+ "/NH"
89
+ ]);
90
+ const match = stdout2.match(/"([^"]+)"/);
91
+ return match ? match[1] : null;
92
+ }
93
+ const { stdout } = await execFileAsync("ps", ["-p", String(pid), "-o", "comm="]);
94
+ return stdout.trim().split("/").pop() || null;
95
+ } catch {
96
+ return null;
97
+ }
98
+ }
99
+
100
+ // src/health/http.ts
101
+ import http from "http";
102
+ function checkHttp(port, timeout) {
103
+ return new Promise((resolve) => {
104
+ const start = performance.now();
105
+ const req = http.get(
106
+ { hostname: "127.0.0.1", port, timeout, path: "/" },
107
+ (res) => {
108
+ const latency = Math.round(performance.now() - start);
109
+ res.resume();
110
+ resolve({ protocol: `HTTP ${res.statusCode}`, latency });
111
+ }
112
+ );
113
+ req.on("timeout", () => {
114
+ req.destroy();
115
+ resolve({ protocol: null, latency: null });
116
+ });
117
+ req.on("error", () => {
118
+ resolve({ protocol: null, latency: null });
119
+ });
120
+ });
121
+ }
122
+
123
+ // src/constants.ts
124
+ var DEFAULT_PORTS = [
125
+ 3e3,
126
+ 3001,
127
+ 4200,
128
+ 5e3,
129
+ 5173,
130
+ 5432,
131
+ 6379,
132
+ 8e3,
133
+ 8080,
134
+ 8443,
135
+ 9e3,
136
+ 27017
137
+ ];
138
+ var DEFAULT_TIMEOUT = 1e3;
139
+
140
+ // src/scanner/index.ts
141
+ async function scanPorts(options) {
142
+ const timeout = options.timeout ?? DEFAULT_TIMEOUT;
143
+ const ports = resolvePorts(options);
144
+ const results = await Promise.all(
145
+ ports.map((port) => scanSinglePort(port, timeout))
146
+ );
147
+ return results;
148
+ }
149
+ function resolvePorts(options) {
150
+ if (options.ports && options.ports.length > 0) return options.ports;
151
+ if (options.range) {
152
+ const ports = [];
153
+ for (let p = options.range.from; p <= options.range.to; p++) {
154
+ ports.push(p);
155
+ }
156
+ return ports;
157
+ }
158
+ return [];
159
+ }
160
+ async function scanSinglePort(port, timeout) {
161
+ const tcp = await checkTcp(port, timeout);
162
+ if (tcp.status !== "up") {
163
+ return {
164
+ port,
165
+ status: tcp.status,
166
+ pid: null,
167
+ process: null,
168
+ latency: null,
169
+ protocol: null
170
+ };
171
+ }
172
+ const [proc, httpResult] = await Promise.all([
173
+ resolveProcess(port),
174
+ checkHttp(port, timeout)
175
+ ]);
176
+ return {
177
+ port,
178
+ status: "up",
179
+ pid: proc.pid,
180
+ process: proc.name,
181
+ latency: httpResult.latency ?? tcp.latency,
182
+ protocol: httpResult.protocol ?? "TCP"
183
+ };
184
+ }
185
+
186
+ // src/output/table.ts
187
+ function formatTable(results) {
188
+ const header = " PORT | PID | PROCESS | STATUS | LATENCY | PROTO";
189
+ const sep = "-------|---------|------------------|---------|---------|--------";
190
+ const rows = results.map((r) => {
191
+ const port = String(r.port).padEnd(5);
192
+ const pid = r.pid ? String(r.pid).padEnd(7) : "-".padEnd(7);
193
+ const proc = (r.process ?? "-").padEnd(16);
194
+ const status = r.status === "up" ? "UP".padEnd(7) : "FREE".padEnd(7);
195
+ const latency = r.latency !== null ? `${r.latency}ms`.padEnd(7) : "-".padEnd(7);
196
+ const proto = r.protocol ?? "-";
197
+ return ` ${port} | ${pid} | ${proc} | ${status} | ${latency} | ${proto}`;
198
+ });
199
+ return [header, sep, ...rows].join("\n");
200
+ }
201
+
202
+ // src/output/json.ts
203
+ function formatJson(results) {
204
+ return JSON.stringify({ ports: results }, null, 2);
205
+ }
206
+
207
+ // src/index.ts
208
+ program.name("portprobe").description("Instant diagnostics for your local dev environment").version("0.1.0").argument("[port]", "specific port to check", parseInt).option("--json", "output as JSON (for AI agents)").option("--range <from-to>", "scan port range (e.g. 3000-9000)").option("--timeout <ms>", "connection timeout in ms", parseInt).action(async (port, options) => {
209
+ const timeout = options.timeout ?? DEFAULT_TIMEOUT;
210
+ let ports;
211
+ let range;
212
+ if (port) {
213
+ ports = [port];
214
+ } else if (options.range) {
215
+ const [from, to] = options.range.split("-").map(Number);
216
+ range = { from, to };
217
+ } else {
218
+ ports = DEFAULT_PORTS;
219
+ }
220
+ const results = await scanPorts({ ports, range, timeout });
221
+ if (options.json) {
222
+ console.log(formatJson(results));
223
+ } else {
224
+ console.log(formatTable(results));
225
+ }
226
+ });
227
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "devprobe",
3
+ "version": "0.1.0",
4
+ "description": "Instant diagnostics for your local dev environment",
5
+ "type": "module",
6
+ "bin": {
7
+ "devprobe": "bin/portprobe.js"
8
+ },
9
+ "main": "dist/index.js",
10
+ "scripts": {
11
+ "build": "tsup src/index.ts --format esm --dts --clean",
12
+ "dev": "tsx src/index.ts",
13
+ "test": "vitest run",
14
+ "test:watch": "vitest"
15
+ },
16
+ "keywords": [
17
+ "port",
18
+ "scanner",
19
+ "devtools",
20
+ "cli",
21
+ "diagnostics"
22
+ ],
23
+ "author": "blare",
24
+ "license": "MIT",
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "bin"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/bogdanblare/port.probe.git"
35
+ },
36
+ "homepage": "https://github.com/bogdanblare/port.probe#readme",
37
+ "dependencies": {
38
+ "chalk": "^5.6.2",
39
+ "commander": "^14.0.3"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^25.3.2",
43
+ "tsup": "^8.5.1",
44
+ "tsx": "^4.21.0",
45
+ "typescript": "^5.9.3",
46
+ "vitest": "^4.0.18"
47
+ }
48
+ }