Skip to content

ProcessReaper

Defined in: src/process-reaper.ts:230

new ProcessReaper(probes?): ProcessReaper

Defined in: src/process-reaper.ts:231

ReaperProbes = defaultProbes

ProcessReaper

detect(s): Leftover[]

Defined in: src/process-reaper.ts:234

Detect surviving leftovers for a session (classes 2 + 3).

string

boolean

string

Leftover[]


reap(leftovers): void

Defined in: src/process-reaper.ts:315

Best-effort terminate each leftover (kill pid / run counter-command).

Leftover[]

void


stopListenersOnPort(worktreePath, port, signal?): number

Defined in: src/process-reaper.ts:292

Signal every process under worktreePath that is currently listening on exactly port, to terminate it. Excludes the shepherd process itself and the claude agent. Returns the count of processes signalled (a signals-SENT count — NOT a death confirmation; a process may ignore the signal or take time to exit). Used by preview stop (idle-stop sends SIGTERM then escalates to SIGKILL; force-stop sends SIGKILL).

SCOPE: only the process actually LISTENING on port is signalled — that is the RAM-heavy bundler/server (Vite/Next/esbuild/node), so the bulk of memory is reclaimed. A lightweight parent WRAPPER that merely spawned it (e.g. npm run dev → vite) is not under this port and may linger holding its own (small) footprint until the agent’s shell reaps it. We deliberately don’t walk the process tree: the wrapper is often the agent’s own backgrounded job, and killing up the tree risks disrupting the agent’s pane/job control — the exact harm the opt-in, agent-idle-gated design avoids.

string

number

Signals = "SIGTERM"

number