diff --git a/apps/server/src/process/Layers/TerminalProcessInspector.ts b/apps/server/src/process/Layers/TerminalProcessInspector.ts index d7023b9c01..7d46ae7a7b 100644 --- a/apps/server/src/process/Layers/TerminalProcessInspector.ts +++ b/apps/server/src/process/Layers/TerminalProcessInspector.ts @@ -175,51 +175,51 @@ const makeTerminalProcessInspector = Effect.gen(function* () { ); }); - const inspect: TerminalProcessInspectorShape["inspect"] = Effect.fn("process.inspect")( - function* (terminalPid: number) { - if (!Number.isInteger(terminalPid) || terminalPid <= 0) { - return { - hasRunningSubprocess: false, - runningPorts: [], - } satisfies TerminalSubprocessActivity; - } + const inspect: TerminalProcessInspectorShape["inspect"] = Effect.fn("process.inspect")(function* ( + terminalPid: number, + ) { + if (!Number.isInteger(terminalPid) || terminalPid <= 0) { + return { + hasRunningSubprocess: false, + runningPorts: [], + } satisfies TerminalSubprocessActivity; + } - if (process.platform === "win32") { - const childPids = yield* collectWindowsChildPids(terminalPid, runInspectorCommand); - const processPidsForPortScan = [terminalPid, ...childPids]; - const runningPorts = yield* checkWindowsListeningPorts(processPidsForPortScan, { - terminalPid, - runCommand: runInspectorCommand, - }); - return { - hasRunningSubprocess: childPids.length > 0 || runningPorts.length > 0, - runningPorts, - } satisfies TerminalSubprocessActivity; - } - - const processFamilyPids = yield* collectPosixProcessFamilyPids( - terminalPid, - runInspectorCommand, - ); - if (processFamilyPids.length === 0) { - return { - hasRunningSubprocess: false, - runningPorts: [], - } satisfies TerminalSubprocessActivity; - } - - const subprocessPids = processFamilyPids.filter((pid: number) => pid !== terminalPid); - const runningPorts = yield* checkPosixListeningPorts(processFamilyPids, { + if (process.platform === "win32") { + const childPids = yield* collectWindowsChildPids(terminalPid, runInspectorCommand); + const processPidsForPortScan = [terminalPid, ...childPids]; + const runningPorts = yield* checkWindowsListeningPorts(processPidsForPortScan, { terminalPid, runCommand: runInspectorCommand, - platform: process.platform, }); return { - hasRunningSubprocess: subprocessPids.length > 0 || runningPorts.length > 0, + hasRunningSubprocess: childPids.length > 0 || runningPorts.length > 0, runningPorts, } satisfies TerminalSubprocessActivity; - }, - ); + } + + const processFamilyPids = yield* collectPosixProcessFamilyPids( + terminalPid, + runInspectorCommand, + ); + if (processFamilyPids.length === 0) { + return { + hasRunningSubprocess: false, + runningPorts: [], + } satisfies TerminalSubprocessActivity; + } + + const subprocessPids = processFamilyPids.filter((pid: number) => pid !== terminalPid); + const runningPorts = yield* checkPosixListeningPorts(processFamilyPids, { + terminalPid, + runCommand: runInspectorCommand, + platform: process.platform, + }); + return { + hasRunningSubprocess: subprocessPids.length > 0 || runningPorts.length > 0, + runningPorts, + } satisfies TerminalSubprocessActivity; + }); return { inspect, diff --git a/apps/server/src/process/Layers/WebPortInspector.ts b/apps/server/src/process/Layers/WebPortInspector.ts index edd75e727b..d58bea836c 100644 --- a/apps/server/src/process/Layers/WebPortInspector.ts +++ b/apps/server/src/process/Layers/WebPortInspector.ts @@ -139,37 +139,37 @@ const makeWebPortInspector = Effect.gen(function* () { ); }); - const inspect: WebPortInspectorShape["inspect"] = Effect.fn("process.inspectWebPort")( - function* (port: number) { - if (!Number.isInteger(port) || port <= 0 || port > 65_535) { - return yield* new WebPortInspectionError({ - port, - host: "127.0.0.1", - detail: "Port must be an integer between 1 and 65535.", - }); - } + const inspect: WebPortInspectorShape["inspect"] = Effect.fn("process.inspectWebPort")(function* ( + port: number, + ) { + if (!Number.isInteger(port) || port <= 0 || port > 65_535) { + return yield* new WebPortInspectionError({ + port, + host: "127.0.0.1", + detail: "Port must be an integer between 1 and 65535.", + }); + } - const ipv4Result = yield* probeWebPortOnHost(port, "127.0.0.1").pipe(Effect.exit); - if (ipv4Result._tag === "Success" && isLikelyWebProbe(ipv4Result.value)) { - return true; - } + const ipv4Result = yield* probeWebPortOnHost(port, "127.0.0.1").pipe(Effect.exit); + if (ipv4Result._tag === "Success" && isLikelyWebProbe(ipv4Result.value)) { + return true; + } - const ipv6Result = yield* probeWebPortOnHost(port, "::1").pipe(Effect.exit); - if (ipv6Result._tag === "Success" && isLikelyWebProbe(ipv6Result.value)) { - return true; - } + const ipv6Result = yield* probeWebPortOnHost(port, "::1").pipe(Effect.exit); + if (ipv6Result._tag === "Success" && isLikelyWebProbe(ipv6Result.value)) { + return true; + } - if (ipv4Result._tag === "Success" || ipv6Result._tag === "Success") { - return false; - } + if (ipv4Result._tag === "Success" || ipv6Result._tag === "Success") { + return false; + } - if (ipv6Result._tag === "Failure") { - return yield* Effect.failCause(ipv6Result.cause); - } + if (ipv6Result._tag === "Failure") { + return yield* Effect.failCause(ipv6Result.cause); + } - return yield* Effect.failCause(ipv4Result.cause); - }, - ); + return yield* Effect.failCause(ipv4Result.cause); + }); return { inspect,